text
stringlengths
30
1.67M
<s> package org . metawatch . manager ; import android . content . Context ; import android . graphics . Bitmap ; public class Application { public static void startAppMode ( ) { MetaWatchService . WatchModes . APPLICATION = true ; } public static void stopAppMode ( Context context ) { exitApp ( context ) ; } public static void updateAppMode ( Context context ) { MetaWatchService . WatchModes . APPLICATION = true ; if ( MetaWatchService . WatchModes . APPLICATION == true ) { if ( MetaWatchService . watchState < MetaWatchService . WatchStates . APPLICATION ) MetaWatchService . watchState = MetaWatchService . WatchStates . APPLICATION ; if ( MetaWatchService . watchState == MetaWatchService . WatchStates . APPLICATION ) { Bitmap bitmap = Protocol . createTextBitmap ( context , "<STR_LIT>" ) ; Protocol . sendLcdBitmap ( bitmap , MetaWatchService . WatchBuffers . APPLICATION ) ; Protocol . updateDisplay ( MetaWatchService . WatchBuffers . APPLICATION ) ; } } } public static void updateAppMode ( Context context , Bitmap bitmap ) { MetaWatchService . WatchModes . APPLICATION = true ; if ( MetaWatchService . WatchModes . APPLICATION == true ) { if ( MetaWatchService . watchState < MetaWatchService . WatchStates . APPLICATION ) MetaWatchService . watchState = MetaWatchService . WatchStates . APPLICATION ; if ( MetaWatchService . watchState == MetaWatchService . WatchStates . APPLICATION ) { Protocol . sendLcdBitmap ( bitmap , MetaWatchService . WatchBuffers . APPLICATION ) ; Protocol . updateDisplay ( MetaWatchService . WatchBuffers . APPLICATION ) ; } } } public static void updateAppMode ( Context context , int [ ] array ) { MetaWatchService . WatchModes . APPLICATION = true ; if ( MetaWatchService . WatchModes . APPLICATION == true ) { if ( MetaWatchService . watchState < MetaWatchService . WatchStates . APPLICATION ) MetaWatchService . watchState = MetaWatchService . WatchStates . APPLICATION ; if ( MetaWatchService . watchState == MetaWatchService . WatchStates . APPLICATION ) { Protocol . sendLcdArray ( array , MetaWatchService . WatchBuffers . APPLICATION ) ; Protocol . updateDisplay ( MetaWatchService . WatchBuffers . APPLICATION ) ; } } } public static void updateAppMode ( Context context , byte [ ] buffer ) { MetaWatchService . WatchModes . APPLICATION = true ; if ( MetaWatchService . WatchModes . APPLICATION == true ) { if ( MetaWatchService . watchState < MetaWatchService . WatchStates . APPLICATION ) MetaWatchService . watchState = MetaWatchService . WatchStates . APPLICATION ; if ( MetaWatchService . watchState == MetaWatchService . WatchStates . APPLICATION ) { Protocol . sendLcdBuffer ( buffer , MetaWatchService . WatchBuffers . APPLICATION ) ; Protocol . updateDisplay ( MetaWatchService . WatchBuffers . APPLICATION ) ; } } } public static void toApp ( ) { MetaWatchService . watchState = MetaWatchService . WatchStates . APPLICATION ; Protocol . updateDisplay ( MetaWatchService . WatchBuffers . APPLICATION ) ; } public static void exitApp ( Context context ) { MetaWatchService . WatchModes . APPLICATION = false ; if ( MetaWatchService . WatchModes . IDLE == true ) { Idle . toIdle ( context ) ; } } } </s>
<s> package org . metawatch . manager ; import android . app . Activity ; import android . content . Intent ; import android . graphics . BitmapFactory ; import android . os . Bundle ; import android . util . Log ; public class ImageViewer extends Activity { @ Override protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; Intent i = getIntent ( ) ; Log . d ( MetaWatch . TAG , "<STR_LIT>" + i . getAction ( ) ) ; Log . d ( MetaWatch . TAG , "<STR_LIT>" + i . getData ( ) . getPath ( ) ) ; Application . updateAppMode ( this , BitmapFactory . decodeFile ( i . getData ( ) . getPath ( ) ) ) ; finish ( ) ; } } </s>
<s> package org . metawatch . manager ; import org . metawatch . manager . MetaWatchService . Preferences ; import org . metawatch . manager . MetaWatchService . WatchType ; import org . metawatch . manager . Notification . VibratePattern ; import android . content . Context ; import android . graphics . Bitmap ; import android . graphics . Canvas ; import android . graphics . Color ; import android . graphics . Paint ; import android . graphics . Typeface ; public class NotificationBuilder { public static final class FontSize { public static final int SMALL = <NUM_LIT:1> ; public static final int MEDIUM = <NUM_LIT:2> ; public static final int LARGE = <NUM_LIT:3> ; } public static void createSMS ( Context context , String number , String text ) { String name = Utils . getContactNameFromNumber ( context , number ) ; if ( MetaWatchService . watchType == WatchType . DIGITAL ) { Bitmap bitmap = smartLines ( context , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , name } ) ; Notification . addBitmapNotification ( context , bitmap , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , <NUM_LIT> ) ; Notification . addTextNotification ( context , text , new VibratePattern ( false , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , Notification . notificationTimeout ) ; } else { byte [ ] scroll = new byte [ <NUM_LIT> ] ; int len = Protocol . createOled2linesLong ( context , text , scroll ) ; Notification . addOledNotification ( context , Protocol . createOled1line ( context , "<STR_LIT>" , "<STR_LIT>" ) , Protocol . createOled2lines ( context , name , text ) , scroll , len , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) ; } } public static void createK9 ( Context context , String sender , String subject ) { if ( MetaWatchService . watchType == WatchType . DIGITAL ) { Bitmap bitmap = smartLines ( context , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , sender , subject } ) ; Notification . addBitmapNotification ( context , bitmap , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , Notification . notificationTimeout ) ; } else { Notification . addOledNotification ( context , Protocol . createOled1line ( context , "<STR_LIT>" , "<STR_LIT>" ) , Protocol . createOled2lines ( context , sender , subject ) , null , <NUM_LIT:0> , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) ; } } public static void createGmail ( Context context , String sender , String email , String subject , String snippet ) { if ( MetaWatchService . watchType == WatchType . DIGITAL ) { Bitmap bitmap = smartLines ( context , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , sender , email , subject } ) ; Notification . addBitmapNotification ( context , bitmap , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , Notification . notificationTimeout ) ; Notification . addTextNotification ( context , snippet , new VibratePattern ( false , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , Notification . notificationTimeout ) ; } else { Notification . addOledNotification ( context , Protocol . createOled2lines ( context , "<STR_LIT>" + sender , email ) , Protocol . createOled2lines ( context , subject , snippet ) , null , <NUM_LIT:0> , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) ; } } public static void createGmailBlank ( Context context , String recipient ) { if ( MetaWatchService . watchType == WatchType . DIGITAL ) { Bitmap bitmap = smartLines ( context , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , recipient } ) ; Notification . addBitmapNotification ( context , bitmap , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , Notification . notificationTimeout ) ; } else { Notification . addOledNotification ( context , Protocol . createOled1line ( context , "<STR_LIT>" , "<STR_LIT>" ) , Protocol . createOled1line ( context , null , recipient ) , null , <NUM_LIT:0> , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) ; } } public static void createAlarm ( Context context ) { if ( MetaWatchService . watchType == WatchType . DIGITAL ) { Bitmap bitmap = smartLines ( context , "<STR_LIT>" , new String [ ] { "<STR_LIT>" } ) ; Notification . addBitmapNotification ( context , bitmap , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , Notification . notificationTimeout ) ; } else { Notification . addOledNotification ( context , Protocol . createOled1line ( context , "<STR_LIT>" , "<STR_LIT>" ) , Protocol . createOled1line ( context , null , "<STR_LIT>" ) , null , <NUM_LIT:0> , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) ; } } public static void createMusic ( Context context , String artist , String track ) { if ( MetaWatchService . watchType == WatchType . DIGITAL ) { Bitmap bitmap = smartLines ( context , "<STR_LIT>" , new String [ ] { track , artist } ) ; Notification . addBitmapNotification ( context , bitmap , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> ) , Notification . notificationTimeout ) ; } else { Notification . addOledNotification ( context , Protocol . createOled1line ( context , "<STR_LIT>" , artist ) , Protocol . createOled1line ( context , null , track ) , null , <NUM_LIT:0> , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) ; } } static Bitmap smartLines ( Context context , String iconPath , String [ ] lines ) { String font = null ; int size = <NUM_LIT:8> ; int realSize = <NUM_LIT:7> ; switch ( Preferences . fontSize ) { case FontSize . SMALL : font = "<STR_LIT>" ; realSize = <NUM_LIT:5> ; break ; case FontSize . MEDIUM : font = "<STR_LIT>" ; realSize = <NUM_LIT:7> ; break ; case FontSize . LARGE : font = "<STR_LIT>" ; realSize = <NUM_LIT:11> ; size = <NUM_LIT:16> ; break ; } Bitmap bitmap = Bitmap . createBitmap ( <NUM_LIT> , <NUM_LIT> , Bitmap . Config . RGB_565 ) ; Canvas canvas = new Canvas ( bitmap ) ; Paint paint = new Paint ( ) ; paint . setColor ( Color . BLACK ) ; paint . setTextSize ( size ) ; Typeface typeface = Typeface . createFromAsset ( context . getAssets ( ) , font ) ; paint . setTypeface ( typeface ) ; canvas . drawColor ( Color . WHITE ) ; Bitmap icon = Utils . loadBitmapFromAssets ( context , iconPath ) ; int spaceForItem = <NUM_LIT> / ( <NUM_LIT:1> + lines . length ) ; canvas . drawBitmap ( icon , <NUM_LIT> / <NUM_LIT:2> - icon . getWidth ( ) / <NUM_LIT:2> , spaceForItem / <NUM_LIT:2> - icon . getHeight ( ) / <NUM_LIT:2> , paint ) ; for ( int i = <NUM_LIT:0> ; i < lines . length ; i ++ ) { int x = ( int ) ( <NUM_LIT> / <NUM_LIT:2> - paint . measureText ( lines [ i ] ) / <NUM_LIT:2> ) ; if ( x < <NUM_LIT:0> ) x = <NUM_LIT:0> ; int y = spaceForItem * ( i + <NUM_LIT:1> ) + spaceForItem / <NUM_LIT:2> + realSize / <NUM_LIT:2> ; canvas . drawText ( lines [ i ] , x , y , paint ) ; } return bitmap ; } } </s>
<s> package org . metawatch . manager ; import java . util . ArrayList ; import org . metawatch . manager . MetaWatchService . WatchType ; import android . content . Context ; import android . graphics . Bitmap ; import android . util . Log ; public class Notification { static NotificationType lastNotification = null ; public static ArrayList < NotificationType > notificationQueue = new ArrayList < Notification . NotificationType > ( ) ; public static boolean isSending = false ; public static final int notificationTimeout = <NUM_LIT> ; public static Object scrollRequest = new Object ( ) ; public static class NotificationType { Bitmap bitmap ; int [ ] array ; byte [ ] buffer ; byte [ ] oledTop ; byte [ ] oledBottom ; byte [ ] oledScroll ; int scrollLength ; int timeout ; VibratePattern vibratePattern ; } public static class VibratePattern { boolean vibrate = false ; int on ; int off ; int cycles ; public VibratePattern ( boolean vibrate , int on , int off , int cycles ) { this . vibrate = vibrate ; this . on = on ; this . off = off ; this . cycles = cycles ; } } public static void processNotificationQueue ( final Context context ) { if ( isSending ) return ; else isSending = true ; Thread thread = new Thread ( ) { public void run ( ) { if ( notificationQueue . size ( ) > <NUM_LIT:0> ) { MetaWatchService . watchState = MetaWatchService . WatchStates . NOTIFICATION ; MetaWatchService . WatchModes . NOTIFICATION = true ; } while ( notificationQueue . size ( ) > <NUM_LIT:0> ) { NotificationType notification = notificationQueue . get ( <NUM_LIT:0> ) ; if ( MetaWatchService . watchType == WatchType . DIGITAL ) { if ( notification . bitmap != null ) Protocol . sendLcdBitmap ( notification . bitmap , MetaWatchService . WatchBuffers . NOTIFICATION ) ; else if ( notification . array != null ) Protocol . sendLcdArray ( notification . array , MetaWatchService . WatchBuffers . NOTIFICATION ) ; else if ( notification . buffer != null ) Protocol . sendLcdBuffer ( notification . buffer , MetaWatchService . WatchBuffers . NOTIFICATION ) ; Protocol . updateDisplay ( <NUM_LIT:2> ) ; if ( notification . vibratePattern . vibrate ) Protocol . vibrate ( notification . vibratePattern . on , notification . vibratePattern . off , notification . vibratePattern . cycles ) ; Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; } else { Protocol . sendOledDisplay ( notification . oledTop , true , false ) ; Protocol . sendOledDisplay ( notification . oledBottom , false , false ) ; if ( notification . vibratePattern . vibrate ) Protocol . vibrate ( notification . vibratePattern . on , notification . vibratePattern . off , notification . vibratePattern . cycles ) ; if ( notification . oledScroll != null ) { if ( notification . scrollLength < <NUM_LIT:1> ) return ; if ( notification . scrollLength >= <NUM_LIT> ) { Protocol . sendOledBufferPart ( notification . oledScroll , <NUM_LIT:0> , <NUM_LIT> , true , false ) ; for ( int i = <NUM_LIT> ; i < notification . scrollLength ; i += <NUM_LIT> ) { try { synchronized ( Notification . scrollRequest ) { Notification . scrollRequest . wait ( <NUM_LIT> ) ; } } catch ( InterruptedException e ) { } if ( i + <NUM_LIT> >= notification . scrollLength ) Protocol . sendOledBufferPart ( notification . oledScroll , i , <NUM_LIT> , false , true ) ; else Protocol . sendOledBufferPart ( notification . oledScroll , i , <NUM_LIT> , false , false ) ; } try { synchronized ( Notification . scrollRequest ) { Notification . scrollRequest . wait ( <NUM_LIT> ) ; } } catch ( InterruptedException e ) { } } else { int len = notification . scrollLength / <NUM_LIT:20> + <NUM_LIT:1> ; Protocol . sendOledBufferPart ( notification . oledScroll , <NUM_LIT:0> , len * <NUM_LIT:20> , true , true ) ; } } } MetaWatchService . nap ( notification . timeout ) ; if ( MetaWatchService . WatchModes . CALL == true ) { isSending = false ; return ; } notificationQueue . remove ( <NUM_LIT:0> ) ; } isSending = false ; exitNotification ( context ) ; } } ; thread . start ( ) ; } public static void addTextNotification ( Context context , String text , VibratePattern vibratePattern , int timeout ) { NotificationType notification = new NotificationType ( ) ; notification . bitmap = Protocol . createTextBitmap ( context , text ) ; notification . timeout = timeout ; if ( vibratePattern == null ) notification . vibratePattern = new VibratePattern ( false , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; else notification . vibratePattern = vibratePattern ; notificationQueue . add ( notification ) ; lastNotification = notification ; processNotificationQueue ( context ) ; } public static void addBitmapNotification ( Context context , Bitmap bitmap , VibratePattern vibratePattern , int timeout ) { NotificationType notification = new NotificationType ( ) ; notification . bitmap = bitmap ; notification . timeout = timeout ; if ( vibratePattern == null ) notification . vibratePattern = new VibratePattern ( false , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; else notification . vibratePattern = vibratePattern ; notificationQueue . add ( notification ) ; lastNotification = notification ; processNotificationQueue ( context ) ; } public static void addArrayNotification ( Context context , int [ ] array , VibratePattern vibratePattern ) { NotificationType notification = new NotificationType ( ) ; notification . array = array ; notification . timeout = notificationTimeout ; if ( vibratePattern == null ) notification . vibratePattern = new VibratePattern ( false , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; else notification . vibratePattern = vibratePattern ; notificationQueue . add ( notification ) ; lastNotification = notification ; processNotificationQueue ( context ) ; } public static void addBufferNotification ( Context context , byte [ ] buffer , VibratePattern vibratePattern ) { NotificationType notification = new NotificationType ( ) ; notification . buffer = buffer ; notification . timeout = notificationTimeout ; if ( vibratePattern == null ) notification . vibratePattern = new VibratePattern ( false , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; else notification . vibratePattern = vibratePattern ; notificationQueue . add ( notification ) ; lastNotification = notification ; processNotificationQueue ( context ) ; } public static void addOledNotification ( Context context , byte [ ] top , byte [ ] bottom , byte [ ] scroll , int scrollLength , VibratePattern vibratePattern ) { NotificationType notification = new NotificationType ( ) ; notification . oledTop = top ; notification . oledBottom = bottom ; notification . oledScroll = scroll ; notification . scrollLength = scrollLength ; notification . timeout = notificationTimeout ; if ( vibratePattern == null ) notification . vibratePattern = new VibratePattern ( false , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; else notification . vibratePattern = vibratePattern ; notificationQueue . add ( notification ) ; lastNotification = notification ; processNotificationQueue ( context ) ; } public static void toNotification ( Context context ) { MetaWatchService . watchState = MetaWatchService . WatchStates . NOTIFICATION ; MetaWatchService . WatchModes . NOTIFICATION = true ; processNotificationQueue ( context ) ; } public static void exitNotification ( Context context ) { MetaWatchService . WatchModes . NOTIFICATION = false ; if ( MetaWatchService . WatchModes . CALL == true ) return ; else if ( MetaWatchService . WatchModes . APPLICATION == true ) Application . toApp ( ) ; else if ( MetaWatchService . WatchModes . IDLE == true ) Idle . toIdle ( context ) ; } public static void replay ( Context context ) { if ( lastNotification != null ) { lastNotification . vibratePattern . vibrate = false ; notificationQueue . add ( lastNotification ) ; toNotification ( context ) ; } } } </s>
<s> package org . metawatch . manager ; import org . metawatch . manager . Monitors . WeatherData ; import android . content . Context ; import android . graphics . Bitmap ; import android . graphics . Canvas ; import android . graphics . Color ; import android . graphics . Paint ; import android . graphics . Typeface ; import android . text . StaticLayout ; import android . text . TextPaint ; public class Idle { public static byte [ ] overridenButtons = null ; static Bitmap createLcdIdle ( Context context ) { Bitmap bitmap = Bitmap . createBitmap ( <NUM_LIT> , <NUM_LIT> , Bitmap . Config . RGB_565 ) ; Canvas canvas = new Canvas ( bitmap ) ; Paint paintSmall = new Paint ( ) ; paintSmall . setColor ( Color . BLACK ) ; paintSmall . setTextSize ( <NUM_LIT:8> ) ; Typeface typefaceSmall = Typeface . createFromAsset ( context . getAssets ( ) , "<STR_LIT>" ) ; paintSmall . setTypeface ( typefaceSmall ) ; Paint paintLarge = new Paint ( ) ; paintLarge . setColor ( Color . BLACK ) ; paintLarge . setTextSize ( <NUM_LIT:16> ) ; Typeface typefaceLarge = Typeface . createFromAsset ( context . getAssets ( ) , "<STR_LIT>" ) ; paintLarge . setTypeface ( typefaceLarge ) ; canvas . drawColor ( Color . WHITE ) ; canvas = drawLine ( canvas , <NUM_LIT:32> ) ; if ( WeatherData . received ) { canvas . save ( ) ; TextPaint paint = new TextPaint ( paintSmall ) ; StaticLayout layout = new StaticLayout ( WeatherData . condition , paint , <NUM_LIT> , android . text . Layout . Alignment . ALIGN_NORMAL , <NUM_LIT> , <NUM_LIT:0> , false ) ; canvas . translate ( <NUM_LIT:3> , <NUM_LIT> ) ; layout . draw ( canvas ) ; canvas . restore ( ) ; Bitmap image = Utils . loadBitmapFromAssets ( context , WeatherData . icon ) ; canvas . drawBitmap ( image , <NUM_LIT> , <NUM_LIT> , null ) ; canvas . drawText ( WeatherData . temp , <NUM_LIT> , <NUM_LIT> , paintLarge ) ; canvas . drawText ( WeatherData . tempHigh , <NUM_LIT> , <NUM_LIT> , paintSmall ) ; canvas . drawText ( WeatherData . tempLow , <NUM_LIT> , <NUM_LIT> , paintSmall ) ; canvas . drawText ( WeatherData . city , <NUM_LIT:3> , <NUM_LIT> , paintSmall ) ; } else { canvas . drawText ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , paintSmall ) ; } canvas = drawLine ( canvas , <NUM_LIT> ) ; int rows = <NUM_LIT:3> ; for ( int i = <NUM_LIT:0> ; i < rows ; i ++ ) { int slotSpace = <NUM_LIT> / rows ; int slotX = slotSpace / <NUM_LIT:2> - <NUM_LIT:12> ; int iconX = slotSpace * i + slotX ; switch ( i ) { case <NUM_LIT:0> : canvas . drawBitmap ( Utils . loadBitmapFromAssets ( context , "<STR_LIT>" ) , iconX , <NUM_LIT> , null ) ; break ; case <NUM_LIT:1> : canvas . drawBitmap ( Utils . loadBitmapFromAssets ( context , "<STR_LIT>" ) , iconX , <NUM_LIT> , null ) ; break ; case <NUM_LIT:2> : canvas . drawBitmap ( Utils . loadBitmapFromAssets ( context , "<STR_LIT>" ) , iconX , <NUM_LIT> , null ) ; break ; } } for ( int i = <NUM_LIT:0> ; i < rows ; i ++ ) { String count = "<STR_LIT>" ; switch ( i ) { case <NUM_LIT:0> : count = Integer . toString ( Utils . getMissedCallsCount ( context ) ) ; break ; case <NUM_LIT:1> : count = Integer . toString ( Utils . getUnreadSmsCount ( context ) ) ; break ; case <NUM_LIT:2> : if ( Utils . isGmailAccessSupported ( context ) ) count = Integer . toString ( Utils . getUnreadGmailCount ( context , Utils . getGoogleAccountName ( context ) , "<STR_LIT>" ) ) ; else count = Integer . toString ( Monitors . getGmailUnreadCount ( ) ) ; break ; } int slotSpace = <NUM_LIT> / rows ; int slotX = ( int ) ( slotSpace / <NUM_LIT:2> - paintSmall . measureText ( count ) / <NUM_LIT:2> ) ; int countX = slotSpace * i + slotX ; canvas . drawText ( count , countX , <NUM_LIT> , paintSmall ) ; } return bitmap ; } public static Canvas drawLine ( Canvas canvas , int y ) { Paint paint = new Paint ( ) ; paint . setColor ( Color . BLACK ) ; int left = <NUM_LIT:3> ; for ( int i = <NUM_LIT:0> + left ; i < <NUM_LIT> - left ; i += <NUM_LIT:3> ) canvas . drawLine ( i , y , i + <NUM_LIT:2> , y , paint ) ; return canvas ; } public static void sendLcdIdle ( Context context ) { Bitmap bitmap = createLcdIdle ( context ) ; Protocol . sendLcdBitmap ( bitmap , MetaWatchService . WatchBuffers . IDLE ) ; Protocol . updateDisplay ( <NUM_LIT:0> ) ; } public static boolean toIdle ( Context context ) { MetaWatchService . WatchModes . IDLE = true ; MetaWatchService . watchState = MetaWatchService . WatchStates . IDLE ; sendLcdIdle ( context ) ; return true ; } public static void updateLcdIdle ( Context context ) { if ( MetaWatchService . watchState == MetaWatchService . WatchStates . IDLE ) sendLcdIdle ( context ) ; } public static boolean isIdleButtonOverriden ( byte button ) { if ( overridenButtons != null ) for ( int i = <NUM_LIT:0> ; i < overridenButtons . length ; i ++ ) if ( overridenButtons [ i ] == button ) return true ; return false ; } } </s>
<s> package org . metawatch . manager ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . metawatch . manager . MetaWatchService . Preferences ; import android . accounts . Account ; import android . accounts . AccountManager ; import android . content . ContentResolver ; import android . content . Context ; import android . database . ContentObserver ; import android . database . Cursor ; import android . net . Uri ; import android . util . Log ; public class GmailMonitor { Context context ; MyContentObserver contentObserver = new MyContentObserver ( ) ; ContentResolver contentResolver ; public static String account = "<STR_LIT>" ; public static int lastUnreadGmailCount = <NUM_LIT:0> ; public GmailMonitor ( Context ctx ) { super ( ) ; context = ctx ; } public void startMonitor ( ) { try { AccountManager mgr = AccountManager . get ( context ) ; Account [ ] accts = mgr . getAccounts ( ) ; final int count = accts . length ; Account acct = null ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { acct = accts [ i ] ; if ( acct . type . equals ( "<STR_LIT>" ) ) { account = acct . name ; break ; } } Uri uri = Uri . parse ( "<STR_LIT>" + account ) ; contentResolver = context . getContentResolver ( ) ; contentResolver . registerContentObserver ( uri , true , contentObserver ) ; } catch ( Exception x ) { Log . d ( MetaWatch . TAG , x . toString ( ) ) ; } } private class MyContentObserver extends ContentObserver { public MyContentObserver ( ) { super ( null ) ; } @ Override public void onChange ( boolean selfChange ) { super . onChange ( selfChange ) ; Log . d ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( Preferences . notifyGmail ) { int currentGmailUnreadCount = getUnreadGmailCount ( account , "<STR_LIT>" ) ; if ( currentGmailUnreadCount > lastUnreadGmailCount ) { Log . d ( "<STR_LIT>" , Integer . toString ( currentGmailUnreadCount ) + "<STR_LIT>" + Integer . toString ( lastUnreadGmailCount ) ) ; sendUnreadGmail ( account ) ; } lastUnreadGmailCount = currentGmailUnreadCount ; } } } public int getUnreadGmailCount ( String account , String label ) { try { int nameColumn = <NUM_LIT:0> ; Cursor c = context . getContentResolver ( ) . query ( Uri . parse ( "<STR_LIT>" + account ) , null , null , null , null ) ; c . moveToFirst ( ) ; for ( int i = <NUM_LIT:0> ; i < c . getColumnCount ( ) ; i ++ ) if ( c . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) { nameColumn = i ; break ; } while ( true ) { if ( c . getString ( nameColumn ) . equals ( label ) ) for ( int i = <NUM_LIT:0> ; i < c . getColumnCount ( ) ; i ++ ) { if ( c . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) { return Integer . parseInt ( c . getString ( i ) ) ; } } c . moveToNext ( ) ; if ( c . isLast ( ) ) { break ; } } } catch ( Exception x ) { } return <NUM_LIT:0> ; } void sendUnreadGmail ( String account ) { try { int nameColumn = <NUM_LIT:0> ; String id = "<STR_LIT>" ; String convId = "<STR_LIT>" ; double maxDate = <NUM_LIT:0> ; Cursor c = context . getContentResolver ( ) . query ( Uri . parse ( "<STR_LIT>" + account ) , null , null , null , null ) ; c . moveToFirst ( ) ; for ( int i = <NUM_LIT:0> ; i < c . getColumnCount ( ) ; i ++ ) if ( c . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) nameColumn = i ; while ( true ) { if ( c . getString ( nameColumn ) . equals ( "<STR_LIT>" ) ) for ( int i = <NUM_LIT:0> ; i < c . getColumnCount ( ) ; i ++ ) { if ( c . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) { id = c . getString ( i ) ; } } if ( c . isLast ( ) ) break ; c . moveToNext ( ) ; } Cursor c2 = context . getContentResolver ( ) . query ( Uri . parse ( "<STR_LIT>" + account ) , null , null , null , null ) ; c2 . moveToLast ( ) ; for ( int i = <NUM_LIT:0> ; i < c2 . getColumnCount ( ) ; i ++ ) if ( c2 . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) nameColumn = i ; while ( true ) { if ( c2 . getString ( nameColumn ) . indexOf ( id ) >= <NUM_LIT:0> ) for ( int i = <NUM_LIT:0> ; i < c2 . getColumnCount ( ) ; i ++ ) { if ( c2 . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) convId = c2 . getString ( i ) ; } if ( c2 . isFirst ( ) ) break ; c2 . moveToPrevious ( ) ; } maxDate = <NUM_LIT:0> ; int colConvId = <NUM_LIT:0> ; int colSub = <NUM_LIT:0> ; int colFrom = <NUM_LIT:0> ; int colRcv = <NUM_LIT:0> ; String subject = "<STR_LIT>" ; String sender = "<STR_LIT>" ; String snippet = "<STR_LIT>" ; Cursor c3 = context . getContentResolver ( ) . query ( Uri . parse ( "<STR_LIT>" + account + "<STR_LIT:/>" + convId + "<STR_LIT>" ) , null , null , null , null ) ; c3 . moveToFirst ( ) ; for ( int i = <NUM_LIT:0> ; i < c3 . getColumnCount ( ) ; i ++ ) { if ( c3 . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) colConvId = i ; if ( c3 . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) colSub = i ; if ( c3 . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) colFrom = i ; if ( c3 . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) colRcv = i ; } while ( true ) { if ( c3 . getString ( colConvId ) . indexOf ( convId ) >= <NUM_LIT:0> ) { double thisDate = Double . parseDouble ( c3 . getString ( colRcv ) ) ; if ( thisDate > maxDate ) { subject = c3 . getString ( colSub ) ; sender = c3 . getString ( colFrom ) ; snippet = c3 . getString ( c3 . getColumnIndex ( "<STR_LIT>" ) ) ; maxDate = thisDate ; } } if ( c3 . isLast ( ) ) break ; c3 . moveToNext ( ) ; } Pattern pattern = Pattern . compile ( "<STR_LIT>" ) ; Matcher matcher = pattern . matcher ( sender ) ; matcher . find ( ) ; String senderName = matcher . group ( <NUM_LIT:1> ) . replace ( "<STR_LIT:\">" , "<STR_LIT>" ) ; String senderMail = matcher . group ( <NUM_LIT:2> ) . replace ( "<STR_LIT:<>" , "<STR_LIT>" ) . replace ( "<STR_LIT:>>" , "<STR_LIT>" ) ; NotificationBuilder . createGmail ( context , senderName , senderMail , subject , snippet ) ; } catch ( Exception x ) { } } } </s>
<s> package org . metawatch . manager ; public enum Message { InvalidMessage ( <NUM_LIT:0x00> ) , GetDeviceType ( <NUM_LIT> ) , GetDeviceTypeResponse ( <NUM_LIT> ) , GetInfoString ( <NUM_LIT> ) , GetInfoStringResponse ( <NUM_LIT> ) , DiagnosticLoopback ( <NUM_LIT> ) , EnterShippingModeMsg ( <NUM_LIT> ) , SoftwareResetMsg ( <NUM_LIT> ) , ConnectionTimeoutMsg ( <NUM_LIT> ) , TurnRadioOnMsg ( <NUM_LIT> ) , TurnRadioOffMsg ( <NUM_LIT> ) , SppReserved ( <NUM_LIT> ) , PariringControlMsg ( <NUM_LIT> ) , EnterSniffModeMsg ( <NUM_LIT> ) , xxReEnterSniffModeMsg ( <NUM_LIT> ) , LinkAlarmMsg ( <NUM_LIT> ) , OledWriteBufferMsg ( <NUM_LIT> ) , OledConfigureModeMsg ( <NUM_LIT> ) , OledChangeModeMsg ( <NUM_LIT> ) , OledWriteScrollBufferMsg ( <NUM_LIT> ) , OledScrollMsg ( <NUM_LIT> ) , OledShowIdleBufferMsg ( <NUM_LIT> ) , OledCrownMenuMsg ( <NUM_LIT> ) , OledCrownMenuButtonMsg ( <NUM_LIT> ) , AdvanceWatchHandsMsg ( <NUM_LIT> ) , SetVibrateMode ( <NUM_LIT> ) , SetRealTimeClock ( <NUM_LIT> ) , GetRealTimeClock ( <NUM_LIT> ) , GetRealTimeClockResponse ( <NUM_LIT> ) , NvalOperationMsg ( <NUM_LIT> ) , NvalOperationResponseMsg ( <NUM_LIT> ) , StatusChangeEvent ( <NUM_LIT> ) , ButtonEventMsg ( <NUM_LIT> ) , GeneralPurposePhoneMsg ( <NUM_LIT> ) , GeneralPurposeWatchMsg ( <NUM_LIT> ) , WriteBuffer ( <NUM_LIT> ) , ConfigureMode ( <NUM_LIT> ) , ConfigureIdleBufferSize ( <NUM_LIT> ) , UpdateDisplay ( <NUM_LIT> ) , LoadTemplate ( <NUM_LIT> ) , UpdateMyDisplaySram ( <NUM_LIT> ) , EnableButtonMsg ( <NUM_LIT> ) , DisableButtonMsg ( <NUM_LIT> ) , ReadButtonConfigMsg ( <NUM_LIT> ) , ReadButtonConfigResponse ( <NUM_LIT> ) , UpdateMyDisplayLcd ( <NUM_LIT> ) , BatteryChargeControl ( <NUM_LIT> ) , BatteryConfigMsg ( <NUM_LIT> ) , LowBatteryWarningMsgHost ( <NUM_LIT> ) , LowBatteryBtOffMsgHost ( <NUM_LIT> ) , ReadBatteryVoltageMsg ( <NUM_LIT> ) , ReadBatteryVoltageResponse ( <NUM_LIT> ) , ReadLightSensorMsg ( <NUM_LIT> ) , ReadLightSensorResponse ( <NUM_LIT> ) , LowBatteryWarningMsg ( <NUM_LIT> ) , LowBatteryBtOffMsg ( <NUM_LIT> ) , IdleUpdate ( <NUM_LIT> ) , xxxInitialIdleUpdate ( <NUM_LIT> ) , WatchDrawnScreenTimeout ( <NUM_LIT> ) , ClearLcdSpecial ( <NUM_LIT> ) , WriteLcd ( <NUM_LIT> ) , ClearLcd ( <NUM_LIT> ) , ChangeModeMsg ( <NUM_LIT> ) , ModeTimeoutMsg ( <NUM_LIT> ) , WatchStatusMsg ( <NUM_LIT> ) , MenuModeMsg ( <NUM_LIT> ) , BarCode ( <NUM_LIT> ) , ListPairedDevicesMsg ( <NUM_LIT> ) , ConnectionStateChangeMsg ( <NUM_LIT> ) , ModifyTimeMsg ( <NUM_LIT> ) , MenuButtonMsg ( <NUM_LIT> ) , ToggleSecondsMsg ( <NUM_LIT> ) , SplashTimeoutMsg ( <NUM_LIT> ) , LedChange ( <NUM_LIT> ) , QueryMemoryMsg ( <NUM_LIT> ) , AccelerometerSteps ( <NUM_LIT> ) , AccelerometerRawData ( <NUM_LIT> ) ; public byte msg ; static public final byte start = <NUM_LIT> ; Message ( int msg ) { this . msg = ( byte ) msg ; } } ; </s>
<s> package org . metawatch . manager ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Method ; import java . util . UUID ; import android . app . NotificationManager ; import android . app . PendingIntent ; import android . app . Service ; import android . bluetooth . BluetoothAdapter ; import android . bluetooth . BluetoothDevice ; import android . bluetooth . BluetoothSocket ; import android . content . Context ; import android . content . Intent ; import android . content . SharedPreferences ; import android . content . SharedPreferences . Editor ; import android . media . AudioManager ; import android . os . Handler ; import android . os . IBinder ; import android . os . Looper ; import android . os . Message ; import android . os . PowerManager ; import android . preference . PreferenceManager ; import android . telephony . TelephonyManager ; import android . util . Log ; import android . widget . RemoteViews ; import android . widget . Toast ; public class MetaWatchService extends Service { Context context ; public static BluetoothAdapter bluetoothAdapter ; BluetoothSocket bluetoothSocket ; static InputStream inputStream ; static OutputStream outputStream ; TelephonyManager telephonyManager ; AudioManager audioManager ; NotificationManager notificationManager ; RemoteViews remoteViews ; android . app . Notification notification ; public static PowerManager powerManger ; public static PowerManager . WakeLock wakeLock ; static int connectionState ; public static int watchType ; public static int watchState ; public static TestSmsLoop testSmsLoop ; final class ConnectionState { static final int DISCONNECTED = <NUM_LIT:0> ; static final int CONNECTING = <NUM_LIT:1> ; static final int CONNECTED = <NUM_LIT:2> ; static final int DISCONNECTING = <NUM_LIT:3> ; } final class WatchBuffers { static final int IDLE = <NUM_LIT:0> ; static final int APPLICATION = <NUM_LIT:1> ; static final int NOTIFICATION = <NUM_LIT:2> ; } final class WatchStates { static final int OFF = <NUM_LIT:0> ; static final int IDLE = <NUM_LIT:1> ; static final int APPLICATION = <NUM_LIT:2> ; static final int NOTIFICATION = <NUM_LIT:3> ; static final int CALL = <NUM_LIT:3> ; } static class WatchModes { public static boolean IDLE = false ; public static boolean APPLICATION = false ; public static boolean NOTIFICATION = false ; public static boolean CALL = false ; } static class Preferences { public static boolean startOnBoot = false ; public static boolean notifyCall = true ; public static boolean notifySMS = true ; public static boolean notifyGmail = true ; public static boolean notifyK9 = true ; public static boolean notifyAlarm = true ; public static boolean notifyMusic = true ; public static String watchMacAddress = "<STR_LIT>" ; public static int packetWait = <NUM_LIT:10> ; public static boolean skipSDP = false ; public static boolean invertLCD = false ; public static String weatherCity = "<STR_LIT>" ; public static boolean weatherCelsius = false ; public static int fontSize = <NUM_LIT:2> ; public static int smsLoopInterval = <NUM_LIT:15> ; public static boolean idleMusicControls = false ; public static boolean idleReplay = false ; } final class WatchType { static final int ANALOG = <NUM_LIT:1> ; static final int DIGITAL = <NUM_LIT:2> ; } @ Override public IBinder onBind ( Intent intent ) { return null ; } public static void loadPreferences ( Context context ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; Preferences . startOnBoot = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . startOnBoot ) ; Preferences . notifyCall = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . notifyCall ) ; Preferences . notifySMS = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . notifySMS ) ; Preferences . notifyGmail = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . notifyGmail ) ; Preferences . notifyK9 = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . notifyK9 ) ; Preferences . notifyAlarm = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . notifyAlarm ) ; Preferences . notifyMusic = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . notifyMusic ) ; Preferences . watchMacAddress = sharedPreferences . getString ( "<STR_LIT>" , Preferences . watchMacAddress ) ; Preferences . skipSDP = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . skipSDP ) ; Preferences . invertLCD = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . invertLCD ) ; Preferences . weatherCity = sharedPreferences . getString ( "<STR_LIT>" , Preferences . weatherCity ) ; Preferences . weatherCelsius = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . weatherCelsius ) ; Preferences . idleMusicControls = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . idleMusicControls ) ; Preferences . idleReplay = sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . idleReplay ) ; try { Preferences . fontSize = Integer . valueOf ( sharedPreferences . getString ( "<STR_LIT>" , Integer . toString ( Preferences . fontSize ) ) ) ; Preferences . packetWait = Integer . valueOf ( sharedPreferences . getString ( "<STR_LIT>" , Integer . toString ( Preferences . packetWait ) ) ) ; Preferences . smsLoopInterval = Integer . valueOf ( sharedPreferences . getString ( "<STR_LIT>" , Integer . toString ( Preferences . smsLoopInterval ) ) ) ; } catch ( NumberFormatException e ) { } } public static void saveMac ( Context context , String mac ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; Editor editor = sharedPreferences . edit ( ) ; editor . putString ( "<STR_LIT>" , mac ) ; editor . commit ( ) ; } public void createNotification ( ) { notification = new android . app . Notification ( R . drawable . disconnected_large , null , System . currentTimeMillis ( ) ) ; notification . flags |= android . app . Notification . FLAG_ONGOING_EVENT ; remoteViews = new RemoteViews ( getPackageName ( ) , R . layout . notification ) ; remoteViews . setImageViewResource ( R . id . image , R . drawable . disconnected ) ; remoteViews . setTextViewText ( R . id . text , "<STR_LIT>" ) ; notification . contentView = remoteViews ; Intent notificationIntent = new Intent ( this , MetaWatch . class ) ; PendingIntent contentIntent = PendingIntent . getActivity ( this , <NUM_LIT:0> , notificationIntent , <NUM_LIT:0> ) ; notification . contentIntent = contentIntent ; startForeground ( <NUM_LIT:1> , notification ) ; } public void updateNotification ( boolean connected ) { if ( connected ) { notification . icon = R . drawable . connected ; remoteViews . setImageViewResource ( R . id . image , R . drawable . connected_large ) ; } else { notification . icon = R . drawable . disconnected ; remoteViews . setImageViewResource ( R . id . image , R . drawable . disconnected_large ) ; } startForeground ( <NUM_LIT:1> , notification ) ; } public void removeNotification ( ) { stopForeground ( true ) ; } @ Override public void onCreate ( ) { super . onCreate ( ) ; context = this ; createNotification ( ) ; connectionState = ConnectionState . CONNECTING ; watchState = WatchStates . OFF ; watchType = WatchType . DIGITAL ; if ( bluetoothAdapter == null ) bluetoothAdapter = BluetoothAdapter . getDefaultAdapter ( ) ; powerManger = ( PowerManager ) getSystemService ( Context . POWER_SERVICE ) ; wakeLock = powerManger . newWakeLock ( PowerManager . PARTIAL_WAKE_LOCK , "<STR_LIT>" ) ; audioManager = ( AudioManager ) getSystemService ( Context . AUDIO_SERVICE ) ; Monitors . start ( this , telephonyManager ) ; start ( ) ; } @ Override public void onDestroy ( ) { disconnectExit ( ) ; super . onDestroy ( ) ; Monitors . stop ( ) ; removeNotification ( ) ; } void connect ( Context context ) { try { Log . d ( MetaWatch . TAG , "<STR_LIT>" + Preferences . watchMacAddress ) ; if ( Preferences . watchMacAddress . equals ( "<STR_LIT>" ) ) loadPreferences ( context ) ; BluetoothDevice bluetoothDevice = bluetoothAdapter . getRemoteDevice ( Preferences . watchMacAddress ) ; if ( Preferences . skipSDP ) { Method method = bluetoothDevice . getClass ( ) . getMethod ( "<STR_LIT>" , new Class [ ] { int . class } ) ; bluetoothSocket = ( BluetoothSocket ) method . invoke ( bluetoothDevice , <NUM_LIT:1> ) ; } else { UUID uuid = UUID . fromString ( "<STR_LIT>" ) ; bluetoothSocket = bluetoothDevice . createRfcommSocketToServiceRecord ( uuid ) ; } bluetoothSocket . connect ( ) ; inputStream = bluetoothSocket . getInputStream ( ) ; outputStream = bluetoothSocket . getOutputStream ( ) ; connectionState = ConnectionState . CONNECTED ; updateNotification ( true ) ; Protocol . sendRtcNow ( context ) ; Protocol . getDeviceType ( ) ; } catch ( IOException ioexception ) { Log . d ( MetaWatch . TAG , ioexception . toString ( ) ) ; sendToast ( ioexception . toString ( ) ) ; } catch ( SecurityException e ) { Log . d ( MetaWatch . TAG , e . toString ( ) ) ; } catch ( NoSuchMethodException e ) { Log . d ( MetaWatch . TAG , e . toString ( ) ) ; } catch ( IllegalArgumentException e ) { Log . d ( MetaWatch . TAG , e . toString ( ) ) ; } catch ( IllegalAccessException e ) { Log . d ( MetaWatch . TAG , e . toString ( ) ) ; } catch ( InvocationTargetException e ) { Log . d ( MetaWatch . TAG , e . toString ( ) ) ; } } public void sendToast ( String text ) { Message m = new Message ( ) ; m . what = <NUM_LIT:1> ; m . obj = text ; messageHandler . sendMessage ( m ) ; } private Handler messageHandler = new Handler ( ) { @ Override public void handleMessage ( Message msg ) { switch ( msg . what ) { case <NUM_LIT:1> : Toast . makeText ( context , ( CharSequence ) msg . obj , Toast . LENGTH_SHORT ) . show ( ) ; break ; } } } ; void disconnect ( ) { try { if ( outputStream != null ) outputStream . close ( ) ; } catch ( IOException e ) { } try { if ( inputStream != null ) inputStream . close ( ) ; } catch ( IOException e ) { } try { if ( bluetoothSocket != null ) bluetoothSocket . close ( ) ; } catch ( IOException e ) { } } void disconnectExit ( ) { connectionState = ConnectionState . DISCONNECTING ; disconnect ( ) ; } public static void nap ( long time ) { try { Thread . sleep ( time ) ; } catch ( InterruptedException e ) { } } void start ( ) { Thread thread = new Thread ( ) { public void run ( ) { boolean run = true ; Looper . prepare ( ) ; while ( run ) { switch ( connectionState ) { case ConnectionState . DISCONNECTED : Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; break ; case ConnectionState . CONNECTING : Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; updateNotification ( false ) ; connect ( context ) ; nap ( <NUM_LIT> ) ; break ; case ConnectionState . CONNECTED : Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; readFromDevice ( ) ; break ; case ConnectionState . DISCONNECTING : Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; run = false ; break ; } } } } ; thread . start ( ) ; } void readFromDevice ( ) { try { byte [ ] bytes = new byte [ <NUM_LIT> ] ; Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; inputStream . read ( bytes ) ; wakeLock . acquire ( <NUM_LIT> ) ; String str = "<STR_LIT>" ; int len = ( bytes [ <NUM_LIT:1> ] & <NUM_LIT> ) ; Log . d ( MetaWatch . TAG , "<STR_LIT>" + len ) ; for ( int i = <NUM_LIT:0> ; i < len ; i ++ ) { str += "<STR_LIT>" + Integer . toString ( ( bytes [ i ] & <NUM_LIT> ) + <NUM_LIT> , <NUM_LIT:16> ) . substring ( <NUM_LIT:1> ) + "<STR_LIT:U+002CU+0020>" ; } Log . d ( MetaWatch . TAG , str ) ; switch ( bytes [ <NUM_LIT:2> ] ) { case <NUM_LIT> : Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; break ; case <NUM_LIT> : Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; break ; case <NUM_LIT> : Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; break ; } if ( bytes [ <NUM_LIT:2> ] == <NUM_LIT> ) { if ( bytes [ <NUM_LIT:4> ] == <NUM_LIT> ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; synchronized ( Notification . scrollRequest ) { Notification . scrollRequest . notify ( ) ; } } if ( bytes [ <NUM_LIT:4> ] == <NUM_LIT> ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; } } if ( bytes [ <NUM_LIT:2> ] == <NUM_LIT> ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; pressedButton ( bytes [ <NUM_LIT:3> ] ) ; } if ( bytes [ <NUM_LIT:2> ] == <NUM_LIT> ) { if ( bytes [ <NUM_LIT:4> ] == <NUM_LIT:1> || bytes [ <NUM_LIT:4> ] == <NUM_LIT:4> ) { watchType = WatchType . ANALOG ; } else { watchType = WatchType . DIGITAL ; if ( Preferences . idleMusicControls ) Protocol . enableMediaButtons ( ) ; if ( Preferences . idleReplay ) Protocol . enableReplayButton ( ) ; Protocol . configureMode ( ) ; Idle . toIdle ( this ) ; Idle . updateLcdIdle ( this ) ; Protocol . queryNvalTime ( ) ; } } } catch ( IOException e ) { wakeLock . acquire ( <NUM_LIT> ) ; if ( connectionState != ConnectionState . DISCONNECTING ) connectionState = ConnectionState . CONNECTING ; } } void pressedButton ( byte button ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" + Byte . toString ( button ) ) ; switch ( watchState ) { case WatchStates . IDLE : { switch ( button ) { case MediaControl . VOLUME_UP : MediaControl . volumeUp ( audioManager ) ; break ; case MediaControl . VOLUME_DOWN : MediaControl . volumeDown ( audioManager ) ; break ; case MediaControl . NEXT : MediaControl . next ( this ) ; break ; case MediaControl . PREVIOUS : MediaControl . previous ( this ) ; break ; case MediaControl . TOGGLE : MediaControl . togglePause ( this ) ; break ; case Protocol . REPLAY : Notification . replay ( this ) ; break ; } } break ; case WatchStates . APPLICATION : broadcastButton ( button , watchState ) ; break ; case WatchStates . NOTIFICATION : break ; } } void broadcastButton ( byte button , int state ) { Intent intent = new Intent ( "<STR_LIT>" ) ; intent . putExtra ( "<STR_LIT>" , button ) ; switch ( state ) { case WatchStates . IDLE : intent . putExtra ( "<STR_LIT>" , "<STR_LIT>" ) ; break ; case WatchStates . APPLICATION : intent . putExtra ( "<STR_LIT>" , "<STR_LIT>" ) ; break ; } sendBroadcast ( intent ) ; } } </s>
<s> package org . metawatch . manager ; import android . content . Context ; public class TestSmsLoop implements Runnable { Context context ; boolean runLoop ; public TestSmsLoop ( Context context ) { this . context = context ; } public void run ( ) { runLoop = true ; for ( int i = <NUM_LIT:1> ; runLoop ; i ++ ) { NotificationBuilder . createSMS ( context , "<STR_LIT>" , "<STR_LIT>" + i ) ; try { Thread . sleep ( MetaWatchService . Preferences . smsLoopInterval * <NUM_LIT:1000> ) ; } catch ( InterruptedException e ) { } } } public void stop ( ) { runLoop = false ; } } </s>
<s> package org . metawatch . manager ; import org . metawatch . manager . MetaWatchService . Preferences ; import android . content . BroadcastReceiver ; import android . content . Context ; import android . content . Intent ; import android . content . SharedPreferences ; import android . preference . PreferenceManager ; public class BootUpReceiver extends BroadcastReceiver { @ Override public void onReceive ( Context context , Intent intent ) { SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; if ( sharedPreferences . getBoolean ( "<STR_LIT>" , Preferences . startOnBoot ) ) { context . startService ( new Intent ( context , MetaWatchService . class ) ) ; } } } </s>
<s> package org . metawatch . manager ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Calendar ; import java . util . Date ; import org . metawatch . manager . MetaWatchService . Preferences ; import org . metawatch . manager . NotificationBuilder . FontSize ; import android . content . Context ; import android . graphics . Bitmap ; import android . graphics . Canvas ; import android . graphics . Color ; import android . graphics . Paint ; import android . graphics . Typeface ; import android . text . StaticLayout ; import android . text . TextPaint ; import android . text . format . DateFormat ; import android . util . Log ; public class Protocol { public static final byte REPLAY = <NUM_LIT:30> ; public static ArrayList < byte [ ] > sendQueue = new ArrayList < byte [ ] > ( ) ; public static boolean isSending = false ; public static void sendLcdBitmap ( Bitmap bitmap , int bufferType ) { int pixelArray [ ] = new int [ <NUM_LIT> * <NUM_LIT> ] ; bitmap . getPixels ( pixelArray , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ; sendLcdArray ( pixelArray , bufferType ) ; } static void sendLcdArray ( int [ ] pixelArray , int bufferType ) { byte send [ ] = new byte [ <NUM_LIT> ] ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) { int p [ ] = new int [ <NUM_LIT:8> ] ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:8> ; j ++ ) { if ( pixelArray [ i * <NUM_LIT:8> + j ] == Color . WHITE ) p [ j ] = <NUM_LIT:0> ; else p [ j ] = <NUM_LIT:1> ; } send [ i ] = ( byte ) ( p [ <NUM_LIT:7> ] * <NUM_LIT> + p [ <NUM_LIT:6> ] * <NUM_LIT> + p [ <NUM_LIT:5> ] * <NUM_LIT:32> + p [ <NUM_LIT:4> ] * <NUM_LIT:16> + p [ <NUM_LIT:3> ] * <NUM_LIT:8> + p [ <NUM_LIT:2> ] * <NUM_LIT:4> + p [ <NUM_LIT:1> ] * <NUM_LIT:2> + p [ <NUM_LIT:0> ] * <NUM_LIT:1> ) ; } sendLcdBuffer ( send , bufferType ) ; } static void sendLcdBuffer ( byte [ ] buffer , int bufferType ) { if ( MetaWatchService . connectionState != MetaWatchService . ConnectionState . CONNECTED ) return ; int i = <NUM_LIT:0> ; if ( bufferType == MetaWatchService . WatchBuffers . IDLE ) i = <NUM_LIT:30> ; for ( ; i < <NUM_LIT> ; i += <NUM_LIT:2> ) { byte [ ] bytes = new byte [ <NUM_LIT:30> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . WriteBuffer . msg ; bytes [ <NUM_LIT:3> ] = ( byte ) bufferType ; bytes [ <NUM_LIT:4> ] = ( byte ) i ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:12> ; j ++ ) bytes [ j + <NUM_LIT:5> ] = buffer [ i * <NUM_LIT:12> + j ] ; bytes [ <NUM_LIT:4> + <NUM_LIT> ] = ( byte ) ( i + <NUM_LIT:1> ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:12> ; j ++ ) bytes [ j + <NUM_LIT:5> + <NUM_LIT> ] = buffer [ i * <NUM_LIT:12> + j + <NUM_LIT:12> ] ; sendQueue . add ( bytes ) ; } processSendQueue ( ) ; } public static void processSendQueue ( ) { if ( isSending ) return ; else isSending = true ; Thread thread = new Thread ( ) { public void run ( ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; while ( sendQueue . size ( ) > <NUM_LIT:0> ) { try { send ( sendQueue . get ( <NUM_LIT:0> ) ) ; sendQueue . remove ( <NUM_LIT:0> ) ; Thread . sleep ( Preferences . packetWait ) ; } catch ( IOException e ) { sendQueue . clear ( ) ; } catch ( InterruptedException e ) { } } Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; isSending = false ; } } ; thread . start ( ) ; } public static void send ( byte [ ] bytes ) throws IOException , NullPointerException { if ( bytes == null ) return ; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; byteArrayOutputStream . write ( bytes ) ; byteArrayOutputStream . write ( crc ( bytes ) ) ; String str = "<STR_LIT>" ; byte [ ] b = byteArrayOutputStream . toByteArray ( ) ; for ( int i = <NUM_LIT:0> ; i < b . length ; i ++ ) { str += "<STR_LIT>" + Integer . toString ( ( b [ i ] & <NUM_LIT> ) + <NUM_LIT> , <NUM_LIT:16> ) . substring ( <NUM_LIT:1> ) + "<STR_LIT:U+002CU+0020>" ; } Log . d ( MetaWatch . TAG , str ) ; if ( MetaWatchService . outputStream == null ) throw new IOException ( "<STR_LIT>" ) ; MetaWatchService . outputStream . write ( byteArrayOutputStream . toByteArray ( ) ) ; MetaWatchService . outputStream . flush ( ) ; } public static void sendAdvanceHands ( ) { try { Date date = new Date ( ) ; Calendar calendar = Calendar . getInstance ( ) ; calendar . setTime ( date ) ; int hour = calendar . get ( Calendar . HOUR ) ; int minute = calendar . get ( Calendar . MINUTE ) ; int second = calendar . get ( Calendar . SECOND ) ; byte [ ] bytes = new byte [ <NUM_LIT:7> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = <NUM_LIT:9> ; bytes [ <NUM_LIT:2> ] = Message . AdvanceWatchHandsMsg . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT> ; bytes [ <NUM_LIT:4> ] = ( byte ) hour ; bytes [ <NUM_LIT:5> ] = ( byte ) minute ; bytes [ <NUM_LIT:6> ] = ( byte ) second ; } catch ( Exception x ) { } } public static void sendRtcNow ( Context context ) { try { boolean isMMDD = true ; char [ ] ch = DateFormat . getDateFormatOrder ( context ) ; for ( int i = <NUM_LIT:0> ; i < ch . length ; i ++ ) { if ( ch [ i ] == DateFormat . DATE ) { isMMDD = false ; break ; } if ( ch [ i ] == DateFormat . MONTH ) { isMMDD = true ; break ; } } Date date = new Date ( ) ; Calendar calendar = Calendar . getInstance ( ) ; calendar . setTime ( date ) ; int year = calendar . get ( Calendar . YEAR ) ; byte [ ] bytes = new byte [ <NUM_LIT> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . SetRealTimeClock . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT:0x00> ; bytes [ <NUM_LIT:4> ] = ( byte ) ( year / <NUM_LIT> ) ; bytes [ <NUM_LIT:5> ] = ( byte ) ( year % <NUM_LIT> ) ; bytes [ <NUM_LIT:6> ] = ( byte ) ( calendar . get ( Calendar . MONTH ) + <NUM_LIT:1> ) ; bytes [ <NUM_LIT:7> ] = ( byte ) calendar . get ( Calendar . DAY_OF_MONTH ) ; bytes [ <NUM_LIT:8> ] = ( byte ) ( calendar . get ( Calendar . DAY_OF_WEEK ) - <NUM_LIT:1> ) ; bytes [ <NUM_LIT:9> ] = ( byte ) calendar . get ( Calendar . HOUR_OF_DAY ) ; bytes [ <NUM_LIT:10> ] = ( byte ) calendar . get ( Calendar . MINUTE ) ; bytes [ <NUM_LIT:11> ] = ( byte ) calendar . get ( Calendar . SECOND ) ; if ( DateFormat . is24HourFormat ( context ) ) bytes [ <NUM_LIT:12> ] = ( byte ) <NUM_LIT:1> ; else bytes [ <NUM_LIT:12> ] = ( byte ) <NUM_LIT:0> ; if ( isMMDD ) bytes [ <NUM_LIT> ] = ( byte ) <NUM_LIT:0> ; else bytes [ <NUM_LIT> ] = ( byte ) <NUM_LIT:1> ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } catch ( Exception x ) { } } public static byte [ ] crc ( byte [ ] bytes ) { byte [ ] result = new byte [ <NUM_LIT:2> ] ; short crc = ( short ) <NUM_LIT> ; for ( int j = <NUM_LIT:0> ; j < bytes . length ; j ++ ) { byte c = bytes [ j ] ; for ( int i = <NUM_LIT:7> ; i >= <NUM_LIT:0> ; i -- ) { boolean c15 = ( ( crc > > <NUM_LIT:15> & <NUM_LIT:1> ) == <NUM_LIT:1> ) ; boolean bit = ( ( c > > ( <NUM_LIT:7> - i ) & <NUM_LIT:1> ) == <NUM_LIT:1> ) ; crc <<= <NUM_LIT:1> ; if ( c15 ^ bit ) crc ^= <NUM_LIT> ; } } int crc2 = crc - <NUM_LIT> ; result [ <NUM_LIT:0> ] = ( byte ) ( crc2 % <NUM_LIT> ) ; result [ <NUM_LIT:1> ] = ( byte ) ( crc2 / <NUM_LIT> ) ; return result ; } public static Bitmap createTextBitmap ( Context context , String text ) { String font = null ; int size = <NUM_LIT:8> ; switch ( Preferences . fontSize ) { case FontSize . SMALL : font = "<STR_LIT>" ; break ; case FontSize . MEDIUM : font = "<STR_LIT>" ; break ; case FontSize . LARGE : font = "<STR_LIT>" ; size = <NUM_LIT:16> ; break ; } Bitmap bitmap = Bitmap . createBitmap ( <NUM_LIT> , <NUM_LIT> , Bitmap . Config . RGB_565 ) ; Canvas canvas = new Canvas ( bitmap ) ; Paint paint = new Paint ( ) ; paint . setColor ( Color . BLACK ) ; paint . setTextSize ( size ) ; Typeface typeface = Typeface . createFromAsset ( context . getAssets ( ) , font ) ; paint . setTypeface ( typeface ) ; canvas . drawColor ( Color . WHITE ) ; canvas = breakText ( canvas , text , paint , <NUM_LIT:0> , <NUM_LIT:0> ) ; return bitmap ; } public static Canvas breakText ( Canvas canvas , String text , Paint pen , int x , int y ) { TextPaint textPaint = new TextPaint ( pen ) ; StaticLayout staticLayout = new StaticLayout ( text , textPaint , <NUM_LIT> , android . text . Layout . Alignment . ALIGN_NORMAL , <NUM_LIT> , <NUM_LIT:0> , false ) ; canvas . translate ( x , y ) ; staticLayout . draw ( canvas ) ; return canvas ; } public static void loadTemplate ( int mode ) { byte [ ] bytes = new byte [ <NUM_LIT:5> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . LoadTemplate . msg ; bytes [ <NUM_LIT:3> ] = ( byte ) mode ; bytes [ <NUM_LIT:4> ] = ( byte ) <NUM_LIT:0> ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void activateBuffer ( int mode ) { byte [ ] bytes = new byte [ <NUM_LIT:4> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . ConfigureIdleBufferSize . msg ; bytes [ <NUM_LIT:3> ] = ( byte ) mode ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void updateDisplay ( int bufferType ) { byte [ ] bytes = new byte [ <NUM_LIT:4> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . UpdateDisplay . msg ; bytes [ <NUM_LIT:3> ] = ( byte ) ( bufferType + <NUM_LIT:16> ) ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void vibrate ( int on , int off , int cycles ) { byte [ ] bytes = new byte [ <NUM_LIT:10> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = <NUM_LIT:12> ; bytes [ <NUM_LIT:2> ] = Message . SetVibrateMode . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT:0x00> ; bytes [ <NUM_LIT:4> ] = <NUM_LIT> ; bytes [ <NUM_LIT:5> ] = ( byte ) ( on % <NUM_LIT> ) ; bytes [ <NUM_LIT:6> ] = ( byte ) ( on / <NUM_LIT> ) ; bytes [ <NUM_LIT:7> ] = ( byte ) ( off % <NUM_LIT> ) ; bytes [ <NUM_LIT:8> ] = ( byte ) ( off / <NUM_LIT> ) ; bytes [ <NUM_LIT:9> ] = ( byte ) cycles ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void writeBuffer ( ) { byte [ ] bytes = new byte [ <NUM_LIT> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . WriteBuffer . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT:0> ; bytes [ <NUM_LIT:4> ] = <NUM_LIT:31> ; bytes [ <NUM_LIT:5> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT:6> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT:7> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT:8> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT:9> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT:10> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT:11> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT:12> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT:15> ] = <NUM_LIT:15> ; bytes [ <NUM_LIT:16> ] = <NUM_LIT:15> ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void enableButton ( int button , int type , int code ) { byte [ ] bytes = new byte [ <NUM_LIT:9> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . EnableButtonMsg . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT:0> ; bytes [ <NUM_LIT:4> ] = <NUM_LIT:0> ; bytes [ <NUM_LIT:5> ] = ( byte ) button ; bytes [ <NUM_LIT:6> ] = ( byte ) type ; bytes [ <NUM_LIT:7> ] = <NUM_LIT> ; bytes [ <NUM_LIT:8> ] = ( byte ) code ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void disableButton ( int button , int type ) { byte [ ] bytes = new byte [ <NUM_LIT:7> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . DisableButtonMsg . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT:0> ; bytes [ <NUM_LIT:4> ] = <NUM_LIT:0> ; bytes [ <NUM_LIT:5> ] = ( byte ) button ; bytes [ <NUM_LIT:6> ] = ( byte ) type ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void enableReplayButton ( ) { enableButton ( <NUM_LIT:1> , <NUM_LIT:0> , REPLAY ) ; } public static void disableReplayButton ( ) { disableButton ( <NUM_LIT:1> , <NUM_LIT:0> ) ; } public static void enableMediaButtons ( ) { enableButton ( <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:0> ) ; enableButton ( <NUM_LIT:3> , <NUM_LIT:1> , MediaControl . VOLUME_DOWN ) ; enableButton ( <NUM_LIT:3> , <NUM_LIT:2> , MediaControl . PREVIOUS ) ; enableButton ( <NUM_LIT:5> , <NUM_LIT:0> , MediaControl . TOGGLE ) ; enableButton ( <NUM_LIT:6> , <NUM_LIT:0> , <NUM_LIT:0> ) ; enableButton ( <NUM_LIT:6> , <NUM_LIT:1> , MediaControl . VOLUME_UP ) ; enableButton ( <NUM_LIT:6> , <NUM_LIT:2> , MediaControl . NEXT ) ; } public static void disableMediaButtons ( ) { disableButton ( <NUM_LIT:3> , <NUM_LIT:0> ) ; disableButton ( <NUM_LIT:3> , <NUM_LIT:1> ) ; disableButton ( <NUM_LIT:3> , <NUM_LIT:2> ) ; disableButton ( <NUM_LIT:5> , <NUM_LIT:0> ) ; disableButton ( <NUM_LIT:6> , <NUM_LIT:0> ) ; disableButton ( <NUM_LIT:6> , <NUM_LIT:1> ) ; disableButton ( <NUM_LIT:6> , <NUM_LIT:2> ) ; } public static void readButtonConfiguration ( ) { byte [ ] bytes = new byte [ <NUM_LIT:9> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . ReadButtonConfigMsg . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT:0> ; bytes [ <NUM_LIT:4> ] = <NUM_LIT:0> ; bytes [ <NUM_LIT:5> ] = <NUM_LIT:1> ; bytes [ <NUM_LIT:6> ] = <NUM_LIT:2> ; bytes [ <NUM_LIT:7> ] = <NUM_LIT> ; bytes [ <NUM_LIT:8> ] = <NUM_LIT:0> ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void configureMode ( ) { byte [ ] bytes = new byte [ <NUM_LIT:6> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . ConfigureMode . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT:0> ; bytes [ <NUM_LIT:4> ] = <NUM_LIT:10> ; bytes [ <NUM_LIT:5> ] = ( byte ) ( MetaWatchService . Preferences . invertLCD ? <NUM_LIT:1> : <NUM_LIT:0> ) ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void getDeviceType ( ) { byte [ ] bytes = new byte [ <NUM_LIT:4> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . GetDeviceType . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT:0> ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void queryNvalTime ( ) { byte [ ] bytes = new byte [ <NUM_LIT:7> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . NvalOperationMsg . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT> ; bytes [ <NUM_LIT:4> ] = <NUM_LIT> ; bytes [ <NUM_LIT:5> ] = <NUM_LIT> ; bytes [ <NUM_LIT:6> ] = <NUM_LIT> ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void setNvalTime ( boolean militaryTime ) { byte [ ] bytes = new byte [ <NUM_LIT:8> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . NvalOperationMsg . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT> ; bytes [ <NUM_LIT:4> ] = <NUM_LIT> ; bytes [ <NUM_LIT:5> ] = <NUM_LIT> ; bytes [ <NUM_LIT:6> ] = <NUM_LIT> ; if ( militaryTime ) bytes [ <NUM_LIT:7> ] = <NUM_LIT> ; else bytes [ <NUM_LIT:7> ] = <NUM_LIT:0x00> ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void test ( Context context ) { sendOledDisplay ( createOled1line ( context , null , "<STR_LIT>" ) , true , false ) ; sendOledDisplay ( createOled2lines ( context , "<STR_LIT>" , "<STR_LIT>" ) , false , true ) ; byte [ ] display = new byte [ <NUM_LIT> ] ; createOled2linesLong ( context , "<STR_LIT>" , display ) ; sendOledBufferPart ( display , <NUM_LIT:0> , <NUM_LIT> , true , true ) ; } public static byte [ ] createOled1line ( Context context , String icon , String line ) { int offset = <NUM_LIT:0> ; if ( icon != null ) offset += <NUM_LIT> ; Bitmap image = Bitmap . createBitmap ( <NUM_LIT> , <NUM_LIT:16> , Bitmap . Config . RGB_565 ) ; Canvas canvas = new Canvas ( image ) ; Paint paint = new Paint ( ) ; paint . setColor ( Color . BLACK ) ; paint . setTextSize ( <NUM_LIT:16> ) ; Typeface typeface = Typeface . createFromAsset ( context . getAssets ( ) , "<STR_LIT>" ) ; paint . setTypeface ( typeface ) ; canvas . drawColor ( Color . WHITE ) ; canvas . drawText ( line , offset , <NUM_LIT> , paint ) ; if ( icon != null ) { canvas . drawBitmap ( Utils . loadBitmapFromAssets ( context , icon ) , <NUM_LIT:0> , <NUM_LIT:0> , null ) ; } int poleInt [ ] = new int [ <NUM_LIT:16> * <NUM_LIT> ] ; image . getPixels ( poleInt , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:16> ) ; byte [ ] display = new byte [ <NUM_LIT> ] ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) { boolean [ ] column = new boolean [ <NUM_LIT:8> ] ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:8> ; j ++ ) { if ( i < <NUM_LIT> ) { if ( poleInt [ <NUM_LIT> * j + i ] == Color . WHITE ) column [ j ] = false ; else column [ j ] = true ; } else { if ( poleInt [ <NUM_LIT> * <NUM_LIT:8> + <NUM_LIT> * j + i - <NUM_LIT> ] == Color . WHITE ) column [ j ] = false ; else column [ j ] = true ; } } for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:8> ; j ++ ) { if ( column [ j ] ) display [ i ] += Math . pow ( <NUM_LIT:2> , j ) ; } } return display ; } public static byte [ ] createOled2lines ( Context context , String line1 , String line2 ) { int offset = <NUM_LIT:0> ; Bitmap image = Bitmap . createBitmap ( <NUM_LIT> , <NUM_LIT:16> , Bitmap . Config . RGB_565 ) ; Canvas canvas = new Canvas ( image ) ; Paint paint = new Paint ( ) ; paint . setColor ( Color . BLACK ) ; paint . setTextSize ( <NUM_LIT:8> ) ; Typeface typeface = Typeface . createFromAsset ( context . getAssets ( ) , "<STR_LIT>" ) ; paint . setTypeface ( typeface ) ; canvas . drawColor ( Color . WHITE ) ; canvas . drawText ( line1 , offset , <NUM_LIT:7> , paint ) ; canvas . drawText ( line2 , offset , <NUM_LIT:15> , paint ) ; int poleInt [ ] = new int [ <NUM_LIT:16> * <NUM_LIT> ] ; image . getPixels ( poleInt , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:16> ) ; byte [ ] display = new byte [ <NUM_LIT> ] ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) { boolean [ ] column = new boolean [ <NUM_LIT:8> ] ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:8> ; j ++ ) { if ( i < <NUM_LIT> ) { if ( poleInt [ <NUM_LIT> * j + i ] == Color . WHITE ) column [ j ] = false ; else column [ j ] = true ; } else { if ( poleInt [ <NUM_LIT> * <NUM_LIT:8> + <NUM_LIT> * j + i - <NUM_LIT> ] == Color . WHITE ) column [ j ] = false ; else column [ j ] = true ; } } for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:8> ; j ++ ) { if ( column [ j ] ) display [ i ] += Math . pow ( <NUM_LIT:2> , j ) ; } } return display ; } public static int createOled2linesLong ( Context context , String line , byte [ ] display ) { int offset = <NUM_LIT:0> - <NUM_LIT> ; final int width = <NUM_LIT> ; Bitmap image = Bitmap . createBitmap ( width , <NUM_LIT:8> , Bitmap . Config . RGB_565 ) ; Canvas canvas = new Canvas ( image ) ; Paint paint = new Paint ( ) ; paint . setColor ( Color . BLACK ) ; paint . setTextSize ( <NUM_LIT:8> ) ; Typeface typeface = Typeface . createFromAsset ( context . getAssets ( ) , "<STR_LIT>" ) ; paint . setTypeface ( typeface ) ; canvas . drawColor ( Color . WHITE ) ; canvas . drawText ( line , offset , <NUM_LIT:7> , paint ) ; int poleInt [ ] = new int [ <NUM_LIT:8> * width ] ; image . getPixels ( poleInt , <NUM_LIT:0> , width , <NUM_LIT:0> , <NUM_LIT:0> , width , <NUM_LIT:8> ) ; for ( int i = <NUM_LIT:0> ; i < width ; i ++ ) { boolean [ ] column = new boolean [ <NUM_LIT:8> ] ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:8> ; j ++ ) { if ( poleInt [ width * j + i ] == Color . WHITE ) column [ j ] = false ; else column [ j ] = true ; } for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:8> ; j ++ ) { if ( column [ j ] ) display [ i ] += Math . pow ( <NUM_LIT:2> , j ) ; } } int len = ( int ) paint . measureText ( line ) ; return ( int ) paint . measureText ( line ) - <NUM_LIT> ; } public static void sendOledDisplay ( byte [ ] display , boolean top , boolean scroll ) { try { byte [ ] bytes ; for ( int a = <NUM_LIT:0> ; a < <NUM_LIT> ; a += <NUM_LIT:20> ) { bytes = new byte [ <NUM_LIT> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . OledWriteBufferMsg . msg ; if ( scroll ) bytes [ <NUM_LIT:3> ] = ( byte ) <NUM_LIT> ; else bytes [ <NUM_LIT:3> ] = <NUM_LIT> ; if ( top ) bytes [ <NUM_LIT:4> ] = <NUM_LIT:0x00> ; else bytes [ <NUM_LIT:4> ] = <NUM_LIT> ; bytes [ <NUM_LIT:5> ] = ( byte ) a ; bytes [ <NUM_LIT:6> ] = <NUM_LIT> ; System . arraycopy ( display , a , bytes , <NUM_LIT:7> , <NUM_LIT:20> ) ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } updateOledNotification ( top , scroll ) ; } catch ( Exception x ) { } } public static void updateOledNotification ( boolean top , boolean scroll ) { byte [ ] bytes = new byte [ <NUM_LIT:7> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . OledWriteBufferMsg . msg ; if ( scroll ) bytes [ <NUM_LIT:3> ] = ( byte ) <NUM_LIT> ; else bytes [ <NUM_LIT:3> ] = <NUM_LIT> ; if ( top ) bytes [ <NUM_LIT:4> ] = <NUM_LIT:0x00> ; else bytes [ <NUM_LIT:4> ] = <NUM_LIT> ; bytes [ <NUM_LIT:5> ] = <NUM_LIT:0x00> ; bytes [ <NUM_LIT:6> ] = <NUM_LIT:0x00> ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void updateOledsNotification ( ) { updateOledNotification ( true , false ) ; updateOledNotification ( false , false ) ; } public static void sendOledBuffer ( boolean startScroll ) { byte [ ] bytes = new byte [ <NUM_LIT> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . OledWriteScrollBufferMsg . msg ; if ( startScroll ) bytes [ <NUM_LIT:3> ] = <NUM_LIT> ; else bytes [ <NUM_LIT:3> ] = <NUM_LIT:0x00> ; bytes [ <NUM_LIT:4> ] = <NUM_LIT:20> ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:20> ; i ++ ) bytes [ <NUM_LIT:5> + i ] = ( byte ) <NUM_LIT> ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } public static void sendOledBufferPart ( byte [ ] display , int start , int length , boolean startScroll , boolean last ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" + start + "<STR_LIT>" + length ) ; for ( int j = start ; j < start + length ; j += <NUM_LIT:20> ) { byte [ ] bytes = new byte [ <NUM_LIT> ] ; bytes [ <NUM_LIT:0> ] = Message . start ; bytes [ <NUM_LIT:1> ] = ( byte ) ( bytes . length + <NUM_LIT:2> ) ; bytes [ <NUM_LIT:2> ] = Message . OledWriteScrollBufferMsg . msg ; bytes [ <NUM_LIT:3> ] = <NUM_LIT:0x00> ; if ( j + <NUM_LIT:20> >= start + length ) { if ( startScroll ) bytes [ <NUM_LIT:3> ] = <NUM_LIT> ; if ( last ) bytes [ <NUM_LIT:3> ] = <NUM_LIT> ; if ( startScroll && last ) bytes [ <NUM_LIT:3> ] = <NUM_LIT> ; } bytes [ <NUM_LIT:4> ] = <NUM_LIT:20> ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:20> ; i ++ ) bytes [ <NUM_LIT:5> + i ] = display [ j + i ] ; sendQueue . add ( bytes ) ; processSendQueue ( ) ; } } } </s>
<s> package org . metawatch . manager ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Set ; import android . app . Activity ; import android . app . ProgressDialog ; import android . bluetooth . BluetoothAdapter ; import android . bluetooth . BluetoothDevice ; import android . content . BroadcastReceiver ; import android . content . Context ; import android . content . DialogInterface ; import android . content . DialogInterface . OnCancelListener ; import android . content . Intent ; import android . content . IntentFilter ; import android . os . Bundle ; import android . os . Handler ; import android . os . Message ; import android . util . Log ; import android . view . View ; import android . widget . AdapterView ; import android . widget . AdapterView . OnItemClickListener ; import android . widget . ListView ; import android . widget . SimpleAdapter ; import android . widget . Toast ; public class DeviceSelection extends Activity { class Receiver extends BroadcastReceiver { @ Override public void onReceive ( Context context , Intent intent ) { if ( intent . getAction ( ) . equals ( BluetoothAdapter . ACTION_DISCOVERY_FINISHED ) ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; pdWait . dismiss ( ) ; if ( list . size ( ) == <NUM_LIT:0> ) { sendToast ( "<STR_LIT>" ) ; finish ( ) ; } } if ( intent . getAction ( ) . equals ( BluetoothDevice . ACTION_FOUND ) ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; BluetoothDevice device = intent . getParcelableExtra ( BluetoothDevice . EXTRA_DEVICE ) ; if ( device . getBondState ( ) == BluetoothDevice . BOND_BONDED ) return ; String deviceName = device . getName ( ) ; String deviceMac = device . getAddress ( ) ; addToList ( deviceMac , deviceName ) ; } } } ProgressDialog pdWait = null ; Context context ; ListView listView ; List < Map < String , String > > list = new ArrayList < Map < String , String > > ( ) ; @ Override protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; context = this ; pdWait = ProgressDialog . show ( this , "<STR_LIT>" , "<STR_LIT>" ) ; pdWait . setCancelable ( true ) ; pdWait . setOnCancelListener ( new OnCancelListener ( ) { public void onCancel ( DialogInterface dialog ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; if ( MetaWatchService . bluetoothAdapter . isDiscovering ( ) ) MetaWatchService . bluetoothAdapter . cancelDiscovery ( ) ; finish ( ) ; } } ) ; pdWait . show ( ) ; setContentView ( R . layout . device_selection ) ; listView = ( ListView ) findViewById ( android . R . id . list ) ; listView . setOnItemClickListener ( new OnItemClickListener ( ) { public void onItemClick ( AdapterView < ? > arg0 , View arg1 , int arg2 , long arg3 ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" + arg2 ) ; Map < String , String > map = list . get ( arg2 ) ; String mac = map . get ( "<STR_LIT>" ) ; Log . d ( MetaWatch . TAG , "<STR_LIT>" + mac ) ; MetaWatchService . Preferences . watchMacAddress = mac ; MetaWatchService . saveMac ( context , mac ) ; sendToast ( "<STR_LIT>" ) ; finish ( ) ; } } ) ; if ( MetaWatchService . bluetoothAdapter == null ) MetaWatchService . bluetoothAdapter = BluetoothAdapter . getDefaultAdapter ( ) ; Set < BluetoothDevice > pairedDevices = MetaWatchService . bluetoothAdapter . getBondedDevices ( ) ; if ( pairedDevices . size ( ) > <NUM_LIT:0> ) { for ( BluetoothDevice device : pairedDevices ) { addToList ( device . getAddress ( ) , device . getName ( ) ) ; } } Receiver receiver = new Receiver ( ) ; IntentFilter intentFilter = new IntentFilter ( BluetoothAdapter . ACTION_DISCOVERY_FINISHED ) ; intentFilter . addAction ( BluetoothDevice . ACTION_FOUND ) ; registerReceiver ( receiver , intentFilter ) ; MetaWatchService . bluetoothAdapter . startDiscovery ( ) ; } void addToList ( String mac , String name ) { Map < String , String > map = new HashMap < String , String > ( ) ; map . put ( "<STR_LIT>" , mac ) ; map . put ( "<STR_LIT:name>" , name ) ; list . add ( map ) ; displayList ( ) ; } void displayList ( ) { listView . setAdapter ( new SimpleAdapter ( this , list , R . layout . list_item , new String [ ] { "<STR_LIT:name>" , "<STR_LIT>" } , new int [ ] { R . id . text1 , R . id . text2 } ) ) ; } public void sendToast ( String text ) { Message m = new Message ( ) ; m . what = <NUM_LIT:1> ; m . obj = text ; messageHandler . sendMessage ( m ) ; } private Handler messageHandler = new Handler ( ) { @ Override public void handleMessage ( Message msg ) { switch ( msg . what ) { case <NUM_LIT:1> : Toast . makeText ( context , ( CharSequence ) msg . obj , Toast . LENGTH_SHORT ) . show ( ) ; break ; } } } ; @ Override protected void onDestroy ( ) { super . onDestroy ( ) ; } } </s>
<s> package org . metawatch . manager ; import android . content . Context ; import android . telephony . PhoneStateListener ; import android . telephony . TelephonyManager ; class CallStateListener extends PhoneStateListener { Context context ; public CallStateListener ( Context ctx ) { super ( ) ; context = ctx ; } @ Override public void onCallStateChanged ( int state , String incomingNumber ) { super . onCallStateChanged ( state , incomingNumber ) ; if ( ! MetaWatchService . Preferences . notifyCall ) return ; if ( incomingNumber == null ) incomingNumber = "<STR_LIT>" ; switch ( state ) { case TelephonyManager . CALL_STATE_RINGING : Call . startCall ( context , incomingNumber ) ; break ; case TelephonyManager . CALL_STATE_IDLE : Call . endCall ( context ) ; break ; case TelephonyManager . CALL_STATE_OFFHOOK : Call . endCall ( context ) ; break ; } } } </s>
<s> package org . metawatch . manager ; import org . metawatch . manager . MetaWatchService . WatchType ; import org . metawatch . manager . Notification . VibratePattern ; import android . app . Activity ; import android . content . Context ; import android . os . Bundle ; import android . view . Menu ; import android . view . MenuInflater ; import android . view . MenuItem ; public class Test extends Activity { @ Override protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; setTitle ( getString ( R . string . app_name ) + "<STR_LIT:U+0020-U+0020>" + getString ( R . string . activitiy_title_tests ) ) ; } @ Override public boolean onCreateOptionsMenu ( Menu menu ) { MenuInflater inflater = getMenuInflater ( ) ; inflater . inflate ( R . menu . test , menu ) ; return true ; } @ Override public boolean onOptionsItemSelected ( MenuItem item ) { switch ( item . getItemId ( ) ) { case R . id . notification : if ( MetaWatchService . watchType == WatchType . DIGITAL ) Notification . addTextNotification ( this , "<STR_LIT>" , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , Notification . notificationTimeout ) ; else Notification . addOledNotification ( this , Protocol . createOled2lines ( this , "<STR_LIT>" , "<STR_LIT>" ) , Protocol . createOled2lines ( this , "<STR_LIT>" , "<STR_LIT>" ) , null , <NUM_LIT:0> , null ) ; return true ; case R . id . application_start : if ( MetaWatchService . watchType == WatchType . DIGITAL ) Application . startAppMode ( ) ; return true ; case R . id . sms_start : startSmsTestLoop ( this ) ; return true ; case R . id . sms_stop : stopSmsTestLoop ( ) ; return true ; case R . id . application_update : if ( MetaWatchService . watchType == WatchType . DIGITAL ) Application . updateAppMode ( this ) ; return true ; case R . id . application_stop : if ( MetaWatchService . watchType == WatchType . DIGITAL ) Application . stopAppMode ( this ) ; return true ; case R . id . sms : NotificationBuilder . createSMS ( this , "<STR_LIT>" , "<STR_LIT>" ) ; return true ; case R . id . k9 : NotificationBuilder . createK9 ( this , "<STR_LIT>" , "<STR_LIT>" ) ; return true ; case R . id . alarm : NotificationBuilder . createAlarm ( this ) ; return true ; case R . id . music : NotificationBuilder . createMusic ( this , "<STR_LIT>" , "<STR_LIT>" ) ; return true ; case R . id . call_start : Call . startCall ( this , "<STR_LIT>" ) ; return true ; case R . id . call_stop : Call . endCall ( this ) ; return true ; case R . id . vibrate : Protocol . vibrate ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ; return true ; case R . id . set_rtc : Protocol . sendRtcNow ( this ) ; return true ; case R . id . load_template : if ( MetaWatchService . watchType == WatchType . DIGITAL ) Protocol . loadTemplate ( <NUM_LIT:0> ) ; return true ; case R . id . activate_buffer : if ( MetaWatchService . watchType == WatchType . DIGITAL ) Protocol . activateBuffer ( <NUM_LIT:0> ) ; return true ; case R . id . update_display : if ( MetaWatchService . watchType == WatchType . DIGITAL ) Protocol . updateDisplay ( <NUM_LIT:0> ) ; return true ; case R . id . write_bufer : if ( MetaWatchService . watchType == WatchType . DIGITAL ) Protocol . writeBuffer ( ) ; return true ; case R . id . test : { Protocol . setNvalTime ( true ) ; } return true ; default : return super . onOptionsItemSelected ( item ) ; } } void startSmsTestLoop ( final Context context ) { if ( MetaWatchService . testSmsLoop != null ) MetaWatchService . testSmsLoop . stop ( ) ; MetaWatchService . testSmsLoop = new TestSmsLoop ( context ) ; Thread thread = new Thread ( MetaWatchService . testSmsLoop ) ; thread . start ( ) ; } void stopSmsTestLoop ( ) { MetaWatchService . testSmsLoop . stop ( ) ; } } </s>
<s> package org . metawatch . manager ; import android . content . Context ; import android . content . Intent ; import android . os . Bundle ; import android . preference . EditTextPreference ; import android . preference . Preference ; import android . preference . Preference . OnPreferenceClickListener ; import android . preference . PreferenceActivity ; import android . preference . PreferenceScreen ; import android . util . Log ; public class Settings extends PreferenceActivity { Context context ; PreferenceScreen preferenceScreen ; Preference discovery ; EditTextPreference editTextMac ; @ Override protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; context = this ; setTitle ( getString ( R . string . app_name ) + "<STR_LIT:U+0020-U+0020>" + getString ( R . string . activitiy_title_settings ) ) ; addPreferencesFromResource ( R . layout . settings ) ; preferenceScreen = getPreferenceScreen ( ) ; } @ Override protected void onStart ( ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; editTextMac = ( EditTextPreference ) preferenceScreen . findPreference ( "<STR_LIT>" ) ; editTextMac . setText ( MetaWatchService . Preferences . watchMacAddress ) ; discovery = preferenceScreen . findPreference ( "<STR_LIT>" ) ; discovery . setOnPreferenceClickListener ( new OnPreferenceClickListener ( ) { public boolean onPreferenceClick ( Preference arg0 ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; startActivity ( new Intent ( context , DeviceSelection . class ) ) ; return false ; } } ) ; super . onStart ( ) ; } } </s>
<s> package org . metawatch . manager ; import android . content . BroadcastReceiver ; import android . content . Context ; import android . content . Intent ; import android . os . Bundle ; import android . telephony . SmsMessage ; import android . util . Log ; public class IntentReceiver extends BroadcastReceiver { @ Override public void onReceive ( Context context , Intent intent ) { String action = intent . getAction ( ) ; if ( action . equals ( "<STR_LIT>" ) ) { if ( ! MetaWatchService . Preferences . notifyGmail ) return ; if ( ! Utils . isGmailAccessSupported ( context ) ) { String recipient = "<STR_LIT>" ; Bundle bundle = intent . getExtras ( ) ; if ( bundle . containsKey ( "<STR_LIT>" ) ) recipient = bundle . getString ( "<STR_LIT>" ) ; Log . d ( MetaWatch . TAG , "<STR_LIT>" + recipient + "<STR_LIT::U+0020>" + bundle . getInt ( "<STR_LIT:count>" ) ) ; int count = bundle . getInt ( "<STR_LIT:count>" ) ; Monitors . updateGmailUnreadCount ( recipient , count ) ; if ( count > <NUM_LIT:0> ) NotificationBuilder . createGmailBlank ( context , recipient ) ; else Idle . updateLcdIdle ( context ) ; return ; } } if ( action . equals ( "<STR_LIT>" ) ) { if ( ! MetaWatchService . Preferences . notifySMS ) return ; Bundle bundle = intent . getExtras ( ) ; if ( bundle . containsKey ( "<STR_LIT>" ) ) { Object [ ] pdus = ( Object [ ] ) bundle . get ( "<STR_LIT>" ) ; SmsMessage [ ] smsMessage = new SmsMessage [ pdus . length ] ; for ( int i = <NUM_LIT:0> ; i < smsMessage . length ; i ++ ) { smsMessage [ i ] = SmsMessage . createFromPdu ( ( byte [ ] ) pdus [ i ] ) ; String number = smsMessage [ i ] . getOriginatingAddress ( ) ; String body = smsMessage [ i ] . getDisplayMessageBody ( ) ; NotificationBuilder . createSMS ( context , number , body ) ; } } return ; } if ( action . equals ( "<STR_LIT>" ) ) { if ( ! MetaWatchService . Preferences . notifyK9 ) return ; Bundle bundle = intent . getExtras ( ) ; String subject = bundle . getString ( "<STR_LIT>" ) ; String sender = bundle . getString ( "<STR_LIT>" ) ; NotificationBuilder . createK9 ( context , sender , subject ) ; return ; } if ( action . equals ( "<STR_LIT>" ) || action . equals ( "<STR_LIT>" ) || action . equals ( "<STR_LIT>" ) || action . equals ( "<STR_LIT>" ) ) { if ( ! MetaWatchService . Preferences . notifyAlarm ) return ; NotificationBuilder . createAlarm ( context ) ; return ; } if ( intent . getAction ( ) . equals ( "<STR_LIT>" ) || intent . getAction ( ) . equals ( "<STR_LIT>" ) ) { if ( ! MetaWatchService . Preferences . notifyMusic ) return ; String artist = "<STR_LIT>" ; String track = "<STR_LIT>" ; if ( intent . hasExtra ( "<STR_LIT>" ) ) artist = intent . getStringExtra ( "<STR_LIT>" ) ; if ( intent . hasExtra ( "<STR_LIT>" ) ) track = intent . getStringExtra ( "<STR_LIT>" ) ; NotificationBuilder . createMusic ( context , artist , track ) ; return ; } } } </s>
<s> package org . metawatch . manager ; import android . content . BroadcastReceiver ; import android . content . Context ; import android . content . Intent ; import android . util . Log ; public class AlarmReceiver extends BroadcastReceiver { @ Override public void onReceive ( Context context , Intent intent ) { Log . d ( MetaWatch . TAG , "<STR_LIT>" + intent . toString ( ) ) ; if ( intent . hasExtra ( "<STR_LIT>" ) ) { Monitors . updateWeatherData ( context ) ; return ; } } } </s>
<s> package org . metawatch . manager ; import java . net . URL ; import java . util . Hashtable ; import javax . xml . parsers . SAXParser ; import javax . xml . parsers . SAXParserFactory ; import org . anddev . android . weatherforecast . weather . GoogleWeatherHandler ; import org . anddev . android . weatherforecast . weather . WeatherCurrentCondition ; import org . anddev . android . weatherforecast . weather . WeatherForecastCondition ; import org . anddev . android . weatherforecast . weather . WeatherSet ; import org . anddev . android . weatherforecast . weather . WeatherUtils ; import org . metawatch . manager . MetaWatchService . Preferences ; import org . xml . sax . InputSource ; import org . xml . sax . XMLReader ; import android . app . AlarmManager ; import android . app . PendingIntent ; import android . content . ContentResolver ; import android . content . Context ; import android . content . Intent ; import android . database . ContentObserver ; import android . net . Uri ; import android . telephony . PhoneStateListener ; import android . telephony . TelephonyManager ; import android . util . Log ; public class Monitors { public static AlarmManager alarmManager ; public static Intent intent ; public static PendingIntent sender ; static GmailMonitor gmailMonitor ; private static ContentObserverMessages contentObserverMessages ; static ContentResolver contentResolverMessages ; private static ContentObserverCalls contentObserverCalls ; static ContentResolver contentResolverCalls ; static Hashtable < String , Integer > gmailUnreadCounts = new Hashtable < String , Integer > ( ) ; public static class WeatherData { public static boolean received = false ; public static String icon ; public static String tempHigh ; public static String tempLow ; public static String temp ; public static String condition ; public static String city ; } public static void updateGmailUnreadCount ( String account , int count ) { gmailUnreadCounts . put ( account , count ) ; } public static int getGmailUnreadCount ( ) { int count = <NUM_LIT:0> ; for ( int i : gmailUnreadCounts . values ( ) ) count += i ; return count ; } public static void start ( Context context , TelephonyManager telephonyManager ) { updateWeatherData ( context ) ; CallStateListener phoneListener = new CallStateListener ( context ) ; telephonyManager = ( TelephonyManager ) context . getSystemService ( Context . TELEPHONY_SERVICE ) ; int phoneEvents = PhoneStateListener . LISTEN_CALL_STATE ; telephonyManager . listen ( phoneListener , phoneEvents ) ; if ( Utils . isGmailAccessSupported ( context ) ) { gmailMonitor = new GmailMonitor ( context ) ; gmailMonitor . startMonitor ( ) ; } try { contentObserverMessages = new ContentObserverMessages ( context ) ; Uri uri = Uri . parse ( "<STR_LIT>" ) ; contentResolverMessages = context . getContentResolver ( ) ; contentResolverMessages . registerContentObserver ( uri , true , contentObserverMessages ) ; } catch ( Exception x ) { } try { contentObserverCalls = new ContentObserverCalls ( context ) ; contentResolverCalls = context . getContentResolver ( ) ; contentResolverCalls . registerContentObserver ( android . provider . CallLog . Calls . CONTENT_URI , true , contentObserverCalls ) ; } catch ( Exception x ) { } startAlarmTicker ( context ) ; } public static void stop ( ) { contentResolverMessages . unregisterContentObserver ( contentObserverMessages ) ; stopAlarmTicker ( ) ; } public static void updateWeatherData ( Context context ) { try { URL url ; String queryString = "<STR_LIT>" + Preferences . weatherCity ; url = new URL ( queryString . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) ) ; SAXParserFactory spf = SAXParserFactory . newInstance ( ) ; SAXParser sp = spf . newSAXParser ( ) ; XMLReader xr = sp . getXMLReader ( ) ; GoogleWeatherHandler gwh = new GoogleWeatherHandler ( ) ; xr . setContentHandler ( gwh ) ; InputSource src = new InputSource ( url . openStream ( ) ) ; src . setEncoding ( "<STR_LIT>" ) ; xr . parse ( src ) ; WeatherSet ws = gwh . getWeatherSet ( ) ; WeatherCurrentCondition wcc = ws . getWeatherCurrentCondition ( ) ; WeatherForecastCondition wfc = ws . getWeatherForecastConditions ( ) . get ( <NUM_LIT:0> ) ; WeatherData . city = Preferences . weatherCity ; String cond = wcc . getCondition ( ) ; String temp ; if ( Preferences . weatherCelsius ) { WeatherData . tempHigh = "<STR_LIT>" + Integer . toString ( wfc . getTempMaxCelsius ( ) ) ; WeatherData . tempLow = "<STR_LIT>" + Integer . toString ( wfc . getTempMinCelsius ( ) ) ; temp = Integer . toString ( wcc . getTempCelcius ( ) ) + ( char ) <NUM_LIT> + "<STR_LIT:C>" ; } else { WeatherData . tempHigh = "<STR_LIT>" + Integer . toString ( WeatherUtils . celsiusToFahrenheit ( wfc . getTempMaxCelsius ( ) ) ) ; WeatherData . tempLow = "<STR_LIT>" + Integer . toString ( WeatherUtils . celsiusToFahrenheit ( wfc . getTempMinCelsius ( ) ) ) ; temp = Integer . toString ( wcc . getTempFahrenheit ( ) ) + ( char ) <NUM_LIT> + "<STR_LIT:F>" ; } WeatherData . condition = cond ; WeatherData . temp = temp ; cond = cond . toLowerCase ( ) ; if ( cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) ) WeatherData . icon = "<STR_LIT>" ; else if ( cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) ) WeatherData . icon = "<STR_LIT>" ; else if ( cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) ) WeatherData . icon = "<STR_LIT>" ; else if ( cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) ) WeatherData . icon = "<STR_LIT>" ; else if ( cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) || cond . equals ( "<STR_LIT>" ) ) WeatherData . icon = "<STR_LIT>" ; else WeatherData . icon = "<STR_LIT>" ; WeatherData . received = true ; Idle . updateLcdIdle ( context ) ; } catch ( Exception e ) { Log . e ( MetaWatch . TAG , e . toString ( ) ) ; } } static void startAlarmTicker ( Context context ) { alarmManager = ( AlarmManager ) context . getSystemService ( Context . ALARM_SERVICE ) ; intent = new Intent ( context , AlarmReceiver . class ) ; intent . putExtra ( "<STR_LIT>" , "<STR_LIT>" ) ; sender = PendingIntent . getBroadcast ( context , <NUM_LIT:1> , intent , PendingIntent . FLAG_UPDATE_CURRENT ) ; alarmManager . setRepeating ( AlarmManager . RTC_WAKEUP , <NUM_LIT:0> , <NUM_LIT:30> * <NUM_LIT> * <NUM_LIT:1000> , sender ) ; } static void stopAlarmTicker ( ) { alarmManager . cancel ( sender ) ; } private static class ContentObserverMessages extends ContentObserver { Context context ; public ContentObserverMessages ( Context context ) { super ( null ) ; this . context = context ; } @ Override public void onChange ( boolean selfChange ) { super . onChange ( selfChange ) ; Idle . updateLcdIdle ( context ) ; } } private static class ContentObserverCalls extends ContentObserver { Context context ; public ContentObserverCalls ( Context context ) { super ( null ) ; this . context = context ; } @ Override public void onChange ( boolean selfChange ) { super . onChange ( selfChange ) ; Log . d ( MetaWatch . TAG , "<STR_LIT>" ) ; Idle . updateLcdIdle ( context ) ; } } } </s>
<s> package org . metawatch . manager ; import org . metawatch . manager . MetaWatchService . WatchType ; public class CallVibrate implements Runnable { public void run ( ) { while ( Call . isRinging ) { Protocol . vibrate ( <NUM_LIT:1000> , <NUM_LIT:0> , <NUM_LIT:1> ) ; if ( MetaWatchService . watchType == WatchType . DIGITAL ) Protocol . updateDisplay ( <NUM_LIT:2> ) ; else Protocol . updateOledsNotification ( ) ; try { Thread . sleep ( <NUM_LIT> ) ; } catch ( InterruptedException e ) { } } } } </s>
<s> package org . metawatch . manager ; import android . content . Context ; import android . content . Intent ; import android . media . AudioManager ; public class MediaControl { final static byte VOLUME_UP = <NUM_LIT:10> ; final static byte VOLUME_DOWN = <NUM_LIT:11> ; final static byte NEXT = <NUM_LIT:15> ; final static byte PREVIOUS = <NUM_LIT:16> ; final static byte TOGGLE = <NUM_LIT:20> ; public static void next ( Context context ) { context . sendBroadcast ( new Intent ( "<STR_LIT>" ) ) ; } public static void previous ( Context context ) { context . sendBroadcast ( new Intent ( "<STR_LIT>" ) ) ; } public static void togglePause ( Context context ) { context . sendBroadcast ( new Intent ( "<STR_LIT>" ) ) ; } public static void volumeDown ( AudioManager audioManager ) { audioManager . adjustStreamVolume ( AudioManager . STREAM_MUSIC , AudioManager . ADJUST_LOWER , <NUM_LIT:0> ) ; } public static void volumeUp ( AudioManager audioManager ) { audioManager . adjustStreamVolume ( AudioManager . STREAM_MUSIC , AudioManager . ADJUST_RAISE , <NUM_LIT:0> ) ; } } </s>
<s> package org . metawatch . manager ; import org . metawatch . manager . MetaWatchService . WatchType ; import org . metawatch . manager . Notification . VibratePattern ; import android . content . Context ; import android . graphics . Bitmap ; public class Call { public static boolean isRinging = false ; public static void startCall ( Context context , String number ) { toCall ( ) ; isRinging = true ; Bitmap bitmap ; String name = Utils . getContactNameFromNumber ( context , number ) ; if ( name . equals ( number ) ) bitmap = NotificationBuilder . smartLines ( context , "<STR_LIT>" , new String [ ] { number } ) ; else bitmap = NotificationBuilder . smartLines ( context , "<STR_LIT>" , new String [ ] { number , name } ) ; if ( MetaWatchService . watchType == WatchType . DIGITAL ) { Protocol . sendLcdBitmap ( bitmap , MetaWatchService . WatchBuffers . NOTIFICATION ) ; Protocol . updateDisplay ( <NUM_LIT:2> ) ; } else { Notification . addOledNotification ( context , Protocol . createOled1line ( context , "<STR_LIT>" , "<STR_LIT>" ) , Protocol . createOled1line ( context , null , name ) , null , <NUM_LIT:0> , new VibratePattern ( true , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) ; } Thread ringer = new Thread ( new CallVibrate ( ) ) ; ringer . start ( ) ; } public static void endCall ( Context context ) { isRinging = false ; exitCall ( context ) ; } static void toCall ( ) { MetaWatchService . watchState = MetaWatchService . WatchStates . CALL ; MetaWatchService . WatchModes . CALL = true ; } static void exitCall ( Context context ) { MetaWatchService . WatchModes . CALL = false ; if ( MetaWatchService . WatchModes . NOTIFICATION == true ) Notification . toNotification ( context ) ; else if ( MetaWatchService . WatchModes . APPLICATION == true ) Application . toApp ( ) ; else if ( MetaWatchService . WatchModes . IDLE == true ) Idle . toIdle ( context ) ; } } </s>
<s> package org . metawatch . manager ; import java . io . IOException ; import java . io . InputStream ; import android . accounts . Account ; import android . accounts . AccountManager ; import android . content . Context ; import android . content . pm . PackageInfo ; import android . content . pm . PackageManager ; import android . content . pm . PackageManager . NameNotFoundException ; import android . database . Cursor ; import android . graphics . Bitmap ; import android . graphics . BitmapFactory ; import android . net . Uri ; import android . provider . CallLog ; import android . provider . ContactsContract . PhoneLookup ; import android . util . Log ; public class Utils { public static String getContactNameFromNumber ( Context context , String number ) { if ( number . equals ( "<STR_LIT>" ) ) return "<STR_LIT>" ; String [ ] projection = new String [ ] { PhoneLookup . DISPLAY_NAME , PhoneLookup . NUMBER } ; Uri contactUri = Uri . withAppendedPath ( PhoneLookup . CONTENT_FILTER_URI , Uri . encode ( number ) ) ; Cursor c = context . getContentResolver ( ) . query ( contactUri , projection , null , null , null ) ; if ( c . moveToFirst ( ) ) { String name = c . getString ( c . getColumnIndex ( PhoneLookup . DISPLAY_NAME ) ) ; if ( name . length ( ) > <NUM_LIT:0> ) return name ; else return number ; } return number ; } public static int getUnreadSmsCount ( Context context ) { int count = <NUM_LIT:0> ; Cursor cursor = context . getContentResolver ( ) . query ( Uri . withAppendedPath ( Uri . parse ( "<STR_LIT>" ) , "<STR_LIT>" ) , new String [ ] { "<STR_LIT>" } , "<STR_LIT>" , null , null ) ; if ( cursor != null ) { try { count = cursor . getCount ( ) ; } finally { cursor . close ( ) ; } } return count ; } public static int getMissedCallsCount ( Context context ) { int missed = <NUM_LIT:0> ; try { Cursor cursor = context . getContentResolver ( ) . query ( android . provider . CallLog . Calls . CONTENT_URI , null , null , null , null ) ; cursor . moveToFirst ( ) ; while ( true ) { if ( cursor . getInt ( cursor . getColumnIndex ( CallLog . Calls . TYPE ) ) == <NUM_LIT:3> ) missed += cursor . getInt ( cursor . getColumnIndex ( CallLog . Calls . NEW ) ) ; if ( cursor . isLast ( ) ) break ; cursor . moveToNext ( ) ; } } catch ( Exception x ) { } return missed ; } public static int getUnreadGmailCount ( Context context , String account , String label ) { try { int nameColumn = <NUM_LIT:0> ; Cursor c = context . getContentResolver ( ) . query ( Uri . parse ( "<STR_LIT>" + account ) , null , null , null , null ) ; c . moveToFirst ( ) ; for ( int i = <NUM_LIT:0> ; i < c . getColumnCount ( ) ; i ++ ) if ( c . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) { nameColumn = i ; break ; } while ( true ) { if ( c . getString ( nameColumn ) . equals ( label ) ) for ( int i = <NUM_LIT:0> ; i < c . getColumnCount ( ) ; i ++ ) { if ( c . getColumnName ( i ) . equals ( "<STR_LIT>" ) ) { return Integer . parseInt ( c . getString ( i ) ) ; } } c . moveToNext ( ) ; if ( c . isLast ( ) ) { break ; } } } catch ( Exception x ) { Log . d ( MetaWatch . TAG , x . toString ( ) ) ; } return <NUM_LIT:0> ; } public static String getGoogleAccountName ( Context context ) { AccountManager accountManager = AccountManager . get ( context ) ; Account [ ] accounts = accountManager . getAccounts ( ) ; int count = accounts . length ; Account account = null ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { account = accounts [ i ] ; if ( account . type . equals ( "<STR_LIT>" ) ) { return account . name ; } } return "<STR_LIT>" ; } public static Bitmap loadBitmapFromAssets ( Context context , String path ) { try { InputStream inputStream = context . getAssets ( ) . open ( path ) ; Bitmap bitmap = BitmapFactory . decodeStream ( inputStream ) ; inputStream . close ( ) ; return bitmap ; } catch ( IOException e ) { return null ; } } public static String getVersion ( Context context ) { try { PackageManager packageManager = context . getPackageManager ( ) ; PackageInfo packageInfo = packageManager . getPackageInfo ( context . getPackageName ( ) , <NUM_LIT:0> ) ; return packageInfo . versionName ; } catch ( NameNotFoundException e ) { } return "<STR_LIT:unknown>" ; } public static boolean isGmailAccessSupported ( Context context ) { try { PackageManager packageManager = context . getPackageManager ( ) ; PackageInfo packageInfo = packageManager . getPackageInfo ( "<STR_LIT>" , <NUM_LIT:0> ) ; if ( packageInfo . versionCode < <NUM_LIT> ) return true ; } catch ( NameNotFoundException e ) { } return false ; } } </s>
<s> package org . anddev . android . weatherforecast . weather ; import java . util . ArrayList ; public class WeatherSet { private WeatherCurrentCondition myCurrentCondition = null ; private ArrayList < WeatherForecastCondition > myForecastConditions = new ArrayList < WeatherForecastCondition > ( <NUM_LIT:4> ) ; public WeatherCurrentCondition getWeatherCurrentCondition ( ) { return myCurrentCondition ; } public void setWeatherCurrentCondition ( WeatherCurrentCondition myCurrentWeather ) { this . myCurrentCondition = myCurrentWeather ; } public ArrayList < WeatherForecastCondition > getWeatherForecastConditions ( ) { return this . myForecastConditions ; } public WeatherForecastCondition getLastWeatherForecastCondition ( ) { return this . myForecastConditions . get ( this . myForecastConditions . size ( ) - <NUM_LIT:1> ) ; } } </s>
<s> package org . anddev . android . weatherforecast . weather ; import org . xml . sax . Attributes ; import org . xml . sax . SAXException ; import org . xml . sax . helpers . DefaultHandler ; public class GoogleWeatherHandler extends DefaultHandler { @ SuppressWarnings ( "<STR_LIT:unused>" ) private String city = "<STR_LIT>" ; private WeatherSet myWeatherSet = null ; @ SuppressWarnings ( "<STR_LIT:unused>" ) private boolean in_forecast_information = false ; private boolean in_current_conditions = false ; private boolean in_forecast_conditions = false ; private boolean usingSITemperature = false ; public WeatherSet getWeatherSet ( ) { return this . myWeatherSet ; } @ Override public void startDocument ( ) throws SAXException { this . myWeatherSet = new WeatherSet ( ) ; } @ Override public void endDocument ( ) throws SAXException { } @ Override public void startElement ( String namespaceURI , String localName , String qName , Attributes atts ) throws SAXException { if ( localName . equals ( "<STR_LIT>" ) ) { this . in_forecast_information = true ; } else if ( localName . equals ( "<STR_LIT>" ) ) { this . myWeatherSet . setWeatherCurrentCondition ( new WeatherCurrentCondition ( ) ) ; this . in_current_conditions = true ; } else if ( localName . equals ( "<STR_LIT>" ) ) { this . myWeatherSet . getWeatherForecastConditions ( ) . add ( new WeatherForecastCondition ( ) ) ; this . in_forecast_conditions = true ; } else { String dataAttribute = atts . getValue ( "<STR_LIT:data>" ) ; if ( localName . equals ( "<STR_LIT>" ) ) { this . city = dataAttribute ; } else if ( localName . equals ( "<STR_LIT>" ) ) { } else if ( localName . equals ( "<STR_LIT>" ) ) { } else if ( localName . equals ( "<STR_LIT>" ) ) { } else if ( localName . equals ( "<STR_LIT>" ) ) { } else if ( localName . equals ( "<STR_LIT>" ) ) { } else if ( localName . equals ( "<STR_LIT>" ) ) { if ( dataAttribute . equals ( "<STR_LIT>" ) ) this . usingSITemperature = true ; } else if ( localName . equals ( "<STR_LIT>" ) ) { if ( this . in_current_conditions ) { this . myWeatherSet . getWeatherCurrentCondition ( ) . setDayofWeek ( dataAttribute ) ; } else if ( this . in_forecast_conditions ) { this . myWeatherSet . getLastWeatherForecastCondition ( ) . setDayofWeek ( dataAttribute ) ; } } else if ( localName . equals ( "<STR_LIT>" ) ) { if ( this . in_current_conditions ) { this . myWeatherSet . getWeatherCurrentCondition ( ) . setIconURL ( dataAttribute ) ; } else if ( this . in_forecast_conditions ) { this . myWeatherSet . getLastWeatherForecastCondition ( ) . setIconURL ( dataAttribute ) ; } } else if ( localName . equals ( "<STR_LIT>" ) ) { if ( this . in_current_conditions ) { this . myWeatherSet . getWeatherCurrentCondition ( ) . setCondition ( dataAttribute ) ; } else if ( this . in_forecast_conditions ) { this . myWeatherSet . getLastWeatherForecastCondition ( ) . setCondition ( dataAttribute ) ; } } else if ( localName . equals ( "<STR_LIT>" ) ) { this . myWeatherSet . getWeatherCurrentCondition ( ) . setTempFahrenheit ( Integer . parseInt ( dataAttribute ) ) ; } else if ( localName . equals ( "<STR_LIT>" ) ) { this . myWeatherSet . getWeatherCurrentCondition ( ) . setTempCelcius ( Integer . parseInt ( dataAttribute ) ) ; } else if ( localName . equals ( "<STR_LIT>" ) ) { this . myWeatherSet . getWeatherCurrentCondition ( ) . setHumidity ( dataAttribute ) ; } else if ( localName . equals ( "<STR_LIT>" ) ) { this . myWeatherSet . getWeatherCurrentCondition ( ) . setWindCondition ( dataAttribute ) ; } else if ( localName . equals ( "<STR_LIT>" ) ) { int temp = Integer . parseInt ( dataAttribute ) ; if ( this . usingSITemperature ) { this . myWeatherSet . getLastWeatherForecastCondition ( ) . setTempMinCelsius ( temp ) ; } else { this . myWeatherSet . getLastWeatherForecastCondition ( ) . setTempMinCelsius ( WeatherUtils . fahrenheitToCelsius ( temp ) ) ; } } else if ( localName . equals ( "<STR_LIT>" ) ) { int temp = Integer . parseInt ( dataAttribute ) ; if ( this . usingSITemperature ) { this . myWeatherSet . getLastWeatherForecastCondition ( ) . setTempMaxCelsius ( temp ) ; } else { this . myWeatherSet . getLastWeatherForecastCondition ( ) . setTempMaxCelsius ( WeatherUtils . fahrenheitToCelsius ( temp ) ) ; } } } } @ Override public void endElement ( String namespaceURI , String localName , String qName ) throws SAXException { if ( localName . equals ( "<STR_LIT>" ) ) { this . in_forecast_information = false ; } else if ( localName . equals ( "<STR_LIT>" ) ) { this . in_current_conditions = false ; } else if ( localName . equals ( "<STR_LIT>" ) ) { this . in_forecast_conditions = false ; } } @ Override public void characters ( char ch [ ] , int start , int length ) { } } </s>
<s> package org . anddev . android . weatherforecast . weather ; public class WeatherForecastCondition { private String dayofWeek = null ; private Integer tempMin = null ; private Integer tempMax = null ; private String iconURL = null ; private String condition = null ; public WeatherForecastCondition ( ) { } public String getDayofWeek ( ) { return dayofWeek ; } public void setDayofWeek ( String dayofWeek ) { this . dayofWeek = dayofWeek ; } public Integer getTempMinCelsius ( ) { return tempMin ; } public void setTempMinCelsius ( Integer tempMin ) { this . tempMin = tempMin ; } public Integer getTempMaxCelsius ( ) { return tempMax ; } public void setTempMaxCelsius ( Integer tempMax ) { this . tempMax = tempMax ; } public String getIconURL ( ) { return iconURL ; } public void setIconURL ( String iconURL ) { this . iconURL = iconURL ; } public String getCondition ( ) { return condition ; } public void setCondition ( String condition ) { this . condition = condition ; } } </s>
<s> package org . anddev . android . weatherforecast . weather ; public class WeatherUtils { public static int fahrenheitToCelsius ( int tFahrenheit ) { return ( int ) ( ( <NUM_LIT> / <NUM_LIT> ) * ( tFahrenheit - <NUM_LIT:32> ) ) ; } public static int celsiusToFahrenheit ( int tCelsius ) { return ( int ) ( ( <NUM_LIT> / <NUM_LIT> ) * tCelsius + <NUM_LIT:32> ) ; } } </s>
<s> package org . anddev . android . weatherforecast . weather ; public class WeatherCurrentCondition { private String dayofWeek = null ; private Integer tempCelcius = null ; private Integer tempFahrenheit = null ; private String iconURL = null ; private String condition = null ; private String windCondition = null ; private String humidity = null ; private String city = null ; public WeatherCurrentCondition ( ) { } public String getCity ( ) { return this . city ; } public String getDayofWeek ( ) { return this . dayofWeek ; } public void setDayofWeek ( String dayofWeek ) { this . dayofWeek = dayofWeek ; } public Integer getTempCelcius ( ) { return this . tempCelcius ; } public void setTempCelcius ( Integer temp ) { this . tempCelcius = temp ; } public Integer getTempFahrenheit ( ) { return this . tempFahrenheit ; } public void setTempFahrenheit ( Integer temp ) { this . tempFahrenheit = temp ; } public String getIconURL ( ) { return this . iconURL ; } public void setCity ( String city ) { this . city = city ; } public void setIconURL ( String iconURL ) { this . iconURL = iconURL ; } public String getCondition ( ) { return this . condition ; } public void setCondition ( String condition ) { this . condition = condition ; } public String getWindCondition ( ) { return this . windCondition ; } public void setWindCondition ( String windCondition ) { this . windCondition = windCondition ; } public String getHumidity ( ) { return this . humidity ; } public void setHumidity ( String humidity ) { this . humidity = humidity ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . ByteArrayOutputStream ; import java . util . ArrayList ; import java . util . List ; import org . apache . http . HttpResponse ; import org . apache . http . NameValuePair ; import org . apache . http . client . entity . UrlEncodedFormEntity ; import org . apache . http . client . methods . HttpPost ; import org . apache . http . client . params . ClientPNames ; import org . apache . http . client . params . CookiePolicy ; import org . apache . http . impl . client . DefaultHttpClient ; import org . apache . http . message . BasicNameValuePair ; import cx . ath . dekosuke . ftbt . R . id ; import android . content . Context ; import android . util . AttributeSet ; import android . util . Log ; import android . view . View ; import android . view . View . OnClickListener ; import android . widget . Button ; import android . widget . LinearLayout ; import android . widget . TextView ; public class PostView extends LinearLayout { public PostView ( Context context ) { this ( context , null ) ; } public PostView ( Context context , AttributeSet attrs ) { super ( context , attrs ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . content . Context ; import android . content . SharedPreferences ; import android . content . SharedPreferences . Editor ; import android . os . Bundle ; import android . preference . PreferenceActivity ; import android . preference . PreferenceManager ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Iterator ; import java . io . IOException ; import android . util . Log ; public class FocusedSettings { private static final String OPT_KEYWORDS = "<STR_LIT>" ; public static ArrayList < String > get ( Context context ) throws IOException { ArrayList < String > keywords = new ArrayList < String > ( ) ; try { if ( SDCard . existSeriarized ( OPT_KEYWORDS ) ) { keywords = ( ArrayList < String > ) SDCard . getSerialized ( OPT_KEYWORDS ) . readObject ( ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return keywords ; } public static void set ( Context context , ArrayList < String > futabaBBSs ) throws IOException { SDCard . setSerialized ( OPT_KEYWORDS , futabaBBSs ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . app . Activity ; import android . os . Bundle ; import android . view . Display ; import android . view . KeyEvent ; import android . view . View ; import android . view . WindowManager ; import android . widget . AdapterView ; import android . widget . ArrayAdapter ; import android . widget . ListView ; import android . widget . Toast ; import android . util . Log ; import android . content . Context ; import android . content . Intent ; import android . content . SharedPreferences ; import android . app . ProgressDialog ; import java . lang . Thread ; import android . os . Handler ; import android . os . Message ; import android . preference . PreferenceManager ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . TreeMap ; import cx . ath . dekosuke . ftbt . R . id ; public class FutabaBBSMenu extends Activity implements Runnable { private ProgressDialog waitDialog ; private Thread thread ; public FutabaBBSMenuAdapter adapter = null ; public boolean initial_loading = true ; private ListView listView ; String mode ; @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; try { Intent intent = getIntent ( ) ; mode = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; setWait ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public void setWait ( ) { waitDialog = new ProgressDialog ( this ) ; waitDialog . setMessage ( this . getString ( R . string . loading ) ) ; waitDialog . setProgressStyle ( ProgressDialog . STYLE_SPINNER ) ; waitDialog . show ( ) ; thread = new Thread ( this ) ; thread . start ( ) ; } public void run ( ) { try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( InterruptedException e ) { } handler . sendEmptyMessage ( <NUM_LIT:0> ) ; } private Handler handler = new Handler ( ) { public void handleMessage ( Message msg ) { try { loading ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ; private void loading ( ) { try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( this ) ; boolean dispCensored = preferences . getBoolean ( getString ( R . string . dispcensored ) , false ) ; setContentView ( R . layout . bbsmenu ) ; Intent intent = getIntent ( ) ; ArrayList < FutabaBBSContent > BBSs = new ArrayList < FutabaBBSContent > ( ) ; if ( mode == null || mode . equals ( "<STR_LIT:all>" ) ) { FutabaBBSMenuParser parser = new FutabaBBSMenuParser ( "<STR_LIT>" ) ; parser . setDisplayCensored ( dispCensored ) ; parser . parse ( ) ; if ( ! parser . network_ok ) { if ( parser . cache_ok ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } else { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } } BBSs = parser . getBBSs ( ) ; if ( initial_loading ) { initial_loading = false ; ftbt parent_activity = ( ftbt ) this . getParent ( ) ; ArrayList < FutabaBBSContent > BBSs_faved = parent_activity . favoriteBBSs ; HashSet < String > BBS_urls = new HashSet < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < BBSs_faved . size ( ) ; i ++ ) { BBS_urls . add ( BBSs_faved . get ( i ) . url ) ; } for ( int i = <NUM_LIT:0> ; i < BBSs . size ( ) ; i ++ ) { if ( BBS_urls . contains ( BBSs . get ( i ) . url ) ) { BBSs . get ( i ) . faved = true ; } } } } else { ftbt parent_activity = ( ftbt ) this . getParent ( ) ; BBSs = parent_activity . favoriteBBSs ; } adapter = new FutabaBBSMenuAdapter ( this , R . layout . futaba_bbs_row , BBSs ) ; listView = ( ListView ) findViewById ( id . listview ) ; listView . setAdapter ( adapter ) ; FLog . d ( "<STR_LIT:start>" ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } waitDialog . dismiss ( ) ; } public void transSetting ( FutabaBBSContent item ) { Intent intent = new Intent ( ) ; FLog . d ( item . url ) ; intent . putExtra ( "<STR_LIT>" , item . url ) ; intent . putExtra ( "<STR_LIT>" , item . name ) ; intent . putExtra ( "<STR_LIT>" , "<STR_LIT>" ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; } @ Override protected void onResume ( ) { super . onResume ( ) ; try { if ( mode . equals ( "<STR_LIT>" ) ) { ftbt parent_activity = ( ftbt ) this . getParent ( ) ; if ( adapter != null ) { adapter . items = parent_activity . favoriteBBSs ; adapter . notifyDataSetChanged ( ) ; } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } FLog . d ( "<STR_LIT>" ) ; } public boolean dispatchKeyEvent ( KeyEvent event ) { FLog . d ( "<STR_LIT>" + event . getAction ( ) ) ; int action = event . getAction ( ) ; int keyCode = event . getKeyCode ( ) ; if ( keyCode == KeyEvent . KEYCODE_VOLUME_DOWN ) { if ( action == KeyEvent . ACTION_UP ) { FLog . d ( "<STR_LIT>" + listView . getFirstVisiblePosition ( ) ) ; int topPositionY = listView . getChildAt ( <NUM_LIT:0> ) . getTop ( ) ; WindowManager wm = ( WindowManager ) getSystemService ( Context . WINDOW_SERVICE ) ; Display disp = wm . getDefaultDisplay ( ) ; int height = disp . getHeight ( ) ; listView . setSelectionFromTop ( listView . getFirstVisiblePosition ( ) , topPositionY - ( height - <NUM_LIT> ) ) ; } return true ; } else if ( keyCode == KeyEvent . KEYCODE_VOLUME_UP ) { if ( action == KeyEvent . ACTION_UP ) { int topPositionY = listView . getChildAt ( <NUM_LIT:0> ) . getTop ( ) ; WindowManager wm = ( WindowManager ) getSystemService ( Context . WINDOW_SERVICE ) ; Display disp = wm . getDefaultDisplay ( ) ; int height = disp . getHeight ( ) ; listView . setSelectionFromTop ( listView . getFirstVisiblePosition ( ) , topPositionY + ( height - <NUM_LIT> ) ) ; } return true ; } return super . dispatchKeyEvent ( event ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . security . MessageDigest ; import android . util . Log ; class FutabaCrypt { public static String createDigest ( String source ) { MessageDigest md ; try { md = MessageDigest . getInstance ( "<STR_LIT>" ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; return "<STR_LIT>" ; } byte [ ] data = source . getBytes ( ) ; md . update ( data ) ; byte [ ] digest = md . digest ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = <NUM_LIT:0> ; i < digest . length ; i ++ ) { sb . append ( Integer . toHexString ( <NUM_LIT> & digest [ i ] ) ) ; } if ( FutabaCrypt . isHTMLName ( source ) ) { return sb . toString ( ) + "<STR_LIT>" ; } return sb . toString ( ) ; } public static boolean isHTMLName ( String str ) { String last_str = str . substring ( Math . max ( <NUM_LIT:0> , str . length ( ) - <NUM_LIT:4> ) ) ; boolean is_html = last_str . equals ( "<STR_LIT>" ) || last_str . equals ( "<STR_LIT>" ) || str . contains ( "<STR_LIT>" ) ; return is_html ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . net . URLEncoder ; import java . util . ArrayList ; import android . webkit . MimeTypeMap ; public class StringUtil { static String safeCut ( String str , int length ) { if ( str . length ( ) > length ) { return str . substring ( <NUM_LIT:0> , length ) + "<STR_LIT:...>" ; } return str ; } static String safeCutNoDot ( String str , int length ) { if ( str . length ( ) > length ) { return str . substring ( <NUM_LIT:0> , length ) ; } return str ; } static String [ ] nonBlankSplit ( String str , String [ ] addition ) { String [ ] elems = str . split ( "<STR_LIT:n>" ) ; ArrayList < String > filtered_elems = new ArrayList < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < elems . length ; ++ i ) { if ( elems [ i ] . length ( ) > <NUM_LIT:0> ) { filtered_elems . add ( elems [ i ] ) ; } } if ( elems . length > <NUM_LIT:1> ) { for ( int i = <NUM_LIT:0> ; i < addition . length ; ++ i ) { filtered_elems . add ( addition [ i ] ) ; } } return ( String [ ] ) filtered_elems . toArray ( new String [ <NUM_LIT:0> ] ) ; } static String quote ( String str ) { String ret = "<STR_LIT>" ; String [ ] elems = str . split ( "<STR_LIT:n>" ) ; ArrayList < String > filtered_elems = new ArrayList < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < elems . length ; ++ i ) { if ( elems [ i ] . length ( ) > <NUM_LIT:0> ) { ret += "<STR_LIT:>>" + elems [ i ] . trim ( ) + "<STR_LIT:n>" ; } } return ret ; } static String [ ] queryNormalize ( String str ) { String temp = normalize ( str ) ; String [ ] splits = temp . split ( "<STR_LIT>" ) ; ArrayList < String > splits_tmp = new ArrayList < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < splits . length ; ++ i ) { if ( splits [ i ] . length ( ) > <NUM_LIT:0> ) { String elem = splits [ i ] . replaceAll ( "<STR_LIT:<>" , "<STR_LIT>" ) ; elem = elem . replaceAll ( "<STR_LIT:>>" , "<STR_LIT>" ) ; elem = elem . replaceAll ( "<STR_LIT:\">" , "<STR_LIT>" ) ; splits_tmp . add ( elem ) ; } } return ( String [ ] ) splits_tmp . toArray ( new String [ <NUM_LIT:0> ] ) ; } static String [ ] querySplit ( String str ) { String [ ] splits = str . split ( "<STR_LIT>" ) ; ArrayList < String > splits_tmp = new ArrayList < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < splits . length ; ++ i ) { if ( splits [ i ] . length ( ) > <NUM_LIT:0> ) { String elem = splits [ i ] . replaceAll ( "<STR_LIT:<>" , "<STR_LIT>" ) ; elem = elem . replaceAll ( "<STR_LIT:>>" , "<STR_LIT>" ) ; elem = elem . replaceAll ( "<STR_LIT:\">" , "<STR_LIT>" ) ; splits_tmp . add ( elem ) ; } } return ( String [ ] ) splits_tmp . toArray ( new String [ <NUM_LIT:0> ] ) ; } static boolean isQueryMatch ( String str , String [ ] query ) { String temp = normalize ( str ) ; for ( int i = <NUM_LIT:0> ; i < query . length ; ++ i ) { if ( ! temp . contains ( query [ i ] ) ) { return false ; } } return true ; } static boolean isQueryMatchOr ( String str , String [ ] query , boolean doNormalize ) { String temp = str ; if ( doNormalize ) { temp = normalize ( temp ) ; } for ( int i = <NUM_LIT:0> ; i < query . length ; ++ i ) { if ( temp . contains ( query [ i ] ) ) { return true ; } } return false ; } private static String zenkakuToHankaku ( String value ) { StringBuilder sb = new StringBuilder ( value ) ; for ( int i = <NUM_LIT:0> ; i < sb . length ( ) ; i ++ ) { int c = ( int ) sb . charAt ( i ) ; if ( ( c >= <NUM_LIT> && c <= <NUM_LIT> ) || ( c >= <NUM_LIT> && c <= <NUM_LIT> ) || ( c >= <NUM_LIT> && c <= <NUM_LIT> ) ) { sb . setCharAt ( i , ( char ) ( c - <NUM_LIT> ) ) ; } } value = sb . toString ( ) ; return value ; } public static String zenkakuHiraganaToZenkakuKatakana ( String s ) { StringBuffer sb = new StringBuffer ( s ) ; for ( int i = <NUM_LIT:0> ; i < sb . length ( ) ; i ++ ) { char c = sb . charAt ( i ) ; if ( c >= '<STR_LIT>' && c <= '<STR_LIT>' ) { sb . setCharAt ( i , ( char ) ( c - '<STR_LIT>' + '<STR_LIT>' ) ) ; } else if ( c == '<STR_LIT>' ) { sb . setCharAt ( i , '<STR_LIT>' ) ; } else if ( c == '<STR_LIT>' ) { sb . setCharAt ( i , '<STR_LIT>' ) ; } else if ( c == '<STR_LIT>' ) { sb . setCharAt ( i , '<STR_LIT>' ) ; sb . insert ( i + <NUM_LIT:1> , '<STR_LIT>' ) ; i ++ ; } } return sb . toString ( ) ; } static String normalize ( String str ) { String temp = str . toLowerCase ( ) ; temp = zenkakuToHankaku ( temp ) ; temp = zenkakuHiraganaToZenkakuKatakana ( temp ) ; return temp ; } public static String getMIMEType ( String targetFile ) { String url = URLEncoder . encode ( targetFile ) ; String extention = MimeTypeMap . getFileExtensionFromUrl ( url ) ; String mtype = "<STR_LIT>" ; extention = extention . toLowerCase ( ) ; mtype = MimeTypeMap . getSingleton ( ) . getMimeTypeFromExtension ( extention ) ; if ( mtype == null ) { String PLANETEXT = "<STR_LIT:text/plain>" ; if ( ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) || ( targetFile . endsWith ( "<STR_LIT>" ) ) ) mtype = PLANETEXT ; } if ( mtype == null ) mtype = "<STR_LIT>" ; return mtype ; } static boolean validateFocusWord ( String word ) throws Exception { String [ ] splits = word . split ( "<STR_LIT>" ) ; if ( splits . length > <NUM_LIT:1> ) { throw new Exception ( "<STR_LIT>" ) ; } splits = word . split ( "<STR_LIT:n>" ) ; if ( splits . length > <NUM_LIT:1> ) { throw new Exception ( "<STR_LIT>" ) ; } if ( word . equals ( "<STR_LIT>" ) ) { throw new Exception ( "<STR_LIT>" ) ; } if ( word . length ( ) > <NUM_LIT:10> ) { throw new Exception ( "<STR_LIT>" ) ; } return true ; } static boolean focusWordMatched ( String text , ArrayList < String > focuswords ) { for ( int i = <NUM_LIT:0> ; i < focuswords . size ( ) ; ++ i ) { if ( text . contains ( focuswords . get ( i ) ) ) { return true ; } } return false ; } static String highlightFocusWordMatched ( String text , ArrayList < String > focuswords ) { for ( int i = <NUM_LIT:0> ; i < focuswords . size ( ) ; ++ i ) { String fword = focuswords . get ( i ) ; if ( text . contains ( fword ) ) { return text . replace ( fword , "<STR_LIT>" + fword + "<STR_LIT>" ) ; } } return text ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import android . content . Context ; import android . util . Log ; public class PostParser { private static Pattern tagPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern honbunPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; public String parse ( Context context , String str ) { FLog . d ( "<STR_LIT>" + str ) ; try { Matcher mc = honbunPattern . matcher ( str ) ; mc . find ( ) ; return removeTag ( mc . group ( <NUM_LIT:1> ) ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return "<STR_LIT>" ; } public static String removeTag ( String str ) { return tagPattern . matcher ( str ) . replaceAll ( "<STR_LIT>" ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import android . content . Context ; import android . util . Log ; public class DelpostParser { private static Pattern tagPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern honbunPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; public String parse ( Context context , String str ) { FLog . d ( "<STR_LIT>" + str ) ; try { Matcher mc = honbunPattern . matcher ( str ) ; mc . find ( ) ; return removeTag ( mc . group ( <NUM_LIT:1> ) ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return "<STR_LIT>" ; } public static String removeTag ( String str ) { return tagPattern . matcher ( str ) . replaceAll ( "<STR_LIT>" ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; public class FutabaStatus { public String userName ; public String title ; public String text ; public String name ; public String datestr ; public String mailTo ; public int id ; public String imgURL ; public String bigImgURL ; public int width ; public int height ; public String endTime ; public boolean deleted ; FutabaStatus ( ) { userName = "<STR_LIT>" ; title = "<STR_LIT>" ; text = "<STR_LIT>" ; mailTo = "<STR_LIT>" ; id = <NUM_LIT:0> ; width = <NUM_LIT:0> ; height = <NUM_LIT:0> ; endTime = "<STR_LIT>" ; deleted = false ; } public static FutabaStatus createBlank ( ) { FutabaStatus st = new FutabaStatus ( ) ; st . id = - <NUM_LIT:1> ; return st ; } public static FutabaStatus createEndTime ( String str ) { FutabaStatus st = new FutabaStatus ( ) ; st . id = - <NUM_LIT:2> ; st . text = "<STR_LIT>" + str + "<STR_LIT>" ; return st ; } public static boolean isBlank ( FutabaStatus st ) { return st . id == - <NUM_LIT:1> ; } public static boolean isEndTime ( FutabaStatus st ) { return st . id == - <NUM_LIT:2> ; } public String toString ( ) { return "<STR_LIT>" + userName + "<STR_LIT>" + title + "<STR_LIT>" + text + "<STR_LIT>" + name + "<STR_LIT>" + datestr + "<STR_LIT>" + mailTo + "<STR_LIT>" + id + "<STR_LIT>" + imgURL + "<STR_LIT>" + bigImgURL + "<STR_LIT>" + width + "<STR_LIT>" + height ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . app . Activity ; import android . os . Bundle ; import android . widget . LinearLayout ; public class DummyTab extends Activity { @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; LinearLayout linearLayout = new LinearLayout ( this ) ; setContentView ( linearLayout ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . util . ArrayList ; import android . view . Gravity ; import android . view . View ; import android . view . ViewGroup . LayoutParams ; import android . widget . Button ; import android . widget . LinearLayout ; import android . widget . TextView ; import android . widget . Toast ; import android . graphics . Typeface ; import android . view . ViewGroup ; import android . widget . ArrayAdapter ; import android . content . ContentResolver ; import android . content . ContentValues ; import android . content . Context ; import android . content . SharedPreferences ; import android . view . LayoutInflater ; import android . text . Html ; import android . util . Log ; import android . os . AsyncTask ; import android . preference . PreferenceManager ; import android . provider . MediaStore . Images ; import android . content . Intent ; import java . io . InputStream ; import java . net . URL ; import java . io . ByteArrayOutputStream ; import java . io . BufferedOutputStream ; import java . io . File ; import java . io . IOException ; import java . io . BufferedInputStream ; import java . io . OutputStream ; import java . net . HttpURLConnection ; import android . graphics . Bitmap ; import android . graphics . BitmapFactory ; import android . graphics . Color ; import android . widget . ImageView ; import android . view . WindowManager ; import android . content . Context ; import android . view . Display ; import java . lang . Thread ; public class FutabaThreadAdapter extends ArrayAdapter { public ArrayList items ; private LayoutInflater inflater ; private int width ; private int height ; public String [ ] searchQueries ; public int shioriPosition = <NUM_LIT:0> ; public FutabaThreadAdapter ( Context context , int textViewResourceId , ArrayList items ) { super ( context , textViewResourceId , items ) ; this . items = items ; this . inflater = ( LayoutInflater ) context . getSystemService ( Context . LAYOUT_INFLATER_SERVICE ) ; WindowManager wm = ( ( WindowManager ) context . getSystemService ( Context . WINDOW_SERVICE ) ) ; Display display = wm . getDefaultDisplay ( ) ; width = display . getWidth ( ) ; height = display . getHeight ( ) ; } @ Override public View getView ( int position , View convertView , ViewGroup parent ) { View view = convertView ; try { if ( view == null ) { view = inflater . inflate ( StateMan . getThreadRowResourceId ( getContext ( ) ) , null ) ; } FutabaThread activity = ( FutabaThread ) getContext ( ) ; FutabaStatus item = ( FutabaStatus ) items . get ( position ) ; if ( item != null ) { TextView title = ( TextView ) view . findViewById ( R . id . title ) ; title . setTextSize ( StateMan . getDescFontSize ( getContext ( ) ) ) ; TextView bottomtext = ( TextView ) view . findViewById ( R . id . bottomtext ) ; bottomtext . setTextSize ( StateMan . getDescFontSize ( getContext ( ) ) ) ; TextView text = ( TextView ) view . findViewById ( R . id . maintext ) ; bottomtext . setTextSize ( StateMan . getMainFontSize ( getContext ( ) ) ) ; LinearLayout iif = ( LinearLayout ) view . findViewById ( R . id . imageinnerframe ) ; iif . setVisibility ( View . GONE ) ; if ( FutabaStatus . isBlank ( item ) ) { ImageView iv = ( ImageView ) view . findViewById ( R . id . image ) ; iv . setImageBitmap ( null ) ; text . setText ( "<STR_LIT>" ) ; text . setGravity ( Gravity . CENTER ) ; title . setVisibility ( View . GONE ) ; bottomtext . setVisibility ( View . GONE ) ; bottomtext . setText ( "<STR_LIT>" ) ; view . setBackgroundColor ( Color . parseColor ( "<STR_LIT>" ) ) ; Button saveButton = ( Button ) view . findViewById ( R . id . savebutton ) ; saveButton . setVisibility ( View . GONE ) ; } else if ( FutabaStatus . isEndTime ( item ) ) { ImageView iv = ( ImageView ) view . findViewById ( R . id . image ) ; iv . setImageBitmap ( null ) ; String text_html = item . text ; CharSequence cs = Html . fromHtml ( text_html ) ; text . setText ( cs ) ; text . setGravity ( Gravity . CENTER ) ; title . setVisibility ( View . GONE ) ; bottomtext . setVisibility ( View . GONE ) ; bottomtext . setText ( "<STR_LIT>" ) ; view . setBackgroundColor ( Color . parseColor ( "<STR_LIT>" ) ) ; Button saveButton = ( Button ) view . findViewById ( R . id . savebutton ) ; saveButton . setVisibility ( View . GONE ) ; } else { String title_base = item . title ; if ( item . name != null ) { title_base += "<STR_LIT>" + item . name + "<STR_LIT>" ; if ( item . mailTo != null && ! item . mailTo . equals ( "<STR_LIT>" ) ) { title_base += "<STR_LIT>" + item . mailTo + "<STR_LIT>" ; } if ( item . imgURL != null ) { File imgFile = new File ( item . bigImgURL ) ; title_base += "<STR_LIT>" + imgFile . getName ( ) + "<STR_LIT>" ; } if ( activity . currentSize != <NUM_LIT:0> && position >= activity . prevSize ) { title_base += "<STR_LIT>" ; if ( position != <NUM_LIT:0> ) { title_base = "<STR_LIT>" + ( position - <NUM_LIT:1> ) + "<STR_LIT>" + title_base ; } } else { if ( position != <NUM_LIT:0> ) { title_base = "<STR_LIT>" + position + "<STR_LIT>" + title_base ; } } } else { if ( position != <NUM_LIT:0> ) { title_base = "<STR_LIT>" + position + "<STR_LIT>" + title_base ; } if ( item . mailTo != null && ! item . mailTo . equals ( "<STR_LIT>" ) ) { title_base += "<STR_LIT>" + item . mailTo + "<STR_LIT>" ; } } CharSequence cs_title = Html . fromHtml ( title_base ) ; title . setText ( cs_title ) ; text . setTextSize ( StateMan . getMainFontSize ( getContext ( ) ) ) ; bottomtext . setTextSize ( StateMan . getDescFontSize ( getContext ( ) ) ) ; if ( item . datestr != null ) { bottomtext . setText ( item . datestr + "<STR_LIT>" + item . id ) ; } if ( position == <NUM_LIT:0> ) { view . setBackgroundColor ( Color . rgb ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT> ) ) ; } else { if ( item . id != <NUM_LIT:0> && item . id == shioriPosition ) { setShioriStatus ( view ) ; } else { view . setBackgroundColor ( Color . rgb ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; } } text . setGravity ( Gravity . LEFT ) ; title . setVisibility ( View . VISIBLE ) ; bottomtext . setVisibility ( View . VISIBLE ) ; Bitmap bm = null ; LinearLayout imageframe = ( LinearLayout ) view . findViewById ( R . id . imageframe ) ; Button saveButton = ( Button ) view . findViewById ( R . id . savebutton ) ; ImageView iv = ( ImageView ) view . findViewById ( R . id . image ) ; iv . setImageBitmap ( bm ) ; try { if ( item . imgURL != null ) { iv . setTag ( item . bigImgURL ) ; bm = Bitmap . createBitmap ( item . width , item . height , Bitmap . Config . ALPHA_8 ) ; iv . setImageBitmap ( bm ) ; ImageGetTask task = new ImageGetTask ( view ) ; SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( getContext ( ) ) ; boolean enableSaveButton = preferences . getBoolean ( getContext ( ) . getString ( R . string . enablesavebutton ) , false ) ; if ( enableSaveButton ) { saveButton . setVisibility ( View . VISIBLE ) ; } else { saveButton . setVisibility ( View . GONE ) ; } view . setLongClickable ( true ) ; iif . setVisibility ( View . VISIBLE ) ; if ( ! StateMan . getVerticalThreadRow ( getContext ( ) ) ) { final float dip2pxscale = getContext ( ) . getResources ( ) . getDisplayMetrics ( ) . density ; int imageRectWidth = Math . max ( ( int ) ( dip2pxscale * <NUM_LIT> ) , item . width ) + ( int ) ( dip2pxscale * <NUM_LIT> ) ; iif . setLayoutParams ( createParam ( imageRectWidth , LayoutParams . FILL_PARENT ) ) ; } task . execute ( item . imgURL ) ; } else { iv . setTag ( null ) ; iif . setVisibility ( View . GONE ) ; saveButton . setVisibility ( View . GONE ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } if ( text != null ) { String text_html = item . text ; text_html = addHighlight ( text_html ) ; CharSequence cs = Html . fromHtml ( text_html ) ; text . setText ( cs ) ; } } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return view ; } private LinearLayout . LayoutParams createParam ( int width , int height ) { return new LinearLayout . LayoutParams ( width , height ) ; } void setShioriStatus ( View view ) { view . setBackgroundColor ( Color . parseColor ( "<STR_LIT>" ) ) ; TextView bottomText = ( TextView ) view . findViewById ( R . id . bottomtext ) ; String bottomTextStr = "<STR_LIT>" + bottomText . getText ( ) . toString ( ) ; bottomText . setText ( bottomTextStr ) ; } static int getSmlImageWidth ( Bitmap bm , int width , int height ) { float s_x = Math . max ( <NUM_LIT:1.0f> , ( float ) bm . getWidth ( ) * <NUM_LIT> / ( float ) width ) ; float s_y = Math . max ( <NUM_LIT:1.0f> , ( float ) bm . getHeight ( ) * <NUM_LIT> / ( float ) height ) ; float scale = Math . max ( s_x , s_y ) ; return ( int ) ( bm . getWidth ( ) / scale ) ; } static int getSmlImageHeight ( Bitmap bm , int width , int height ) { float s_x = Math . max ( <NUM_LIT:1.0f> , ( float ) bm . getWidth ( ) * <NUM_LIT> / ( float ) width ) ; float s_y = Math . max ( <NUM_LIT:1.0f> , ( float ) bm . getHeight ( ) * <NUM_LIT> / ( float ) height ) ; float scale = Math . max ( s_x , s_y ) ; return ( int ) ( bm . getHeight ( ) / scale ) ; } class ImageGetTask extends AsyncTask < String , Void , Bitmap > { private ImageView image ; private Button saveButton ; private String tag ; public ImageGetTask ( View view ) { image = ( ImageView ) view . findViewById ( R . id . image ) ; saveButton = ( Button ) view . findViewById ( R . id . savebutton ) ; if ( image == null ) { FLog . d ( "<STR_LIT>" ) ; } tag = image . getTag ( ) . toString ( ) ; } @ Override protected Bitmap doInBackground ( String ... urls ) { Bitmap bm = ImageCache . getImage ( urls [ <NUM_LIT:0> ] ) ; FLog . d ( "<STR_LIT>" ) ; if ( bm == null ) { try { ImageCache . setImage ( urls [ <NUM_LIT:0> ] ) ; bm = ImageCache . getImage ( urls [ <NUM_LIT:0> ] ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; FLog . d ( "<STR_LIT>" + urls [ <NUM_LIT:0> ] ) ; try { Thread . sleep ( <NUM_LIT:1> * <NUM_LIT:1000> ) ; } catch ( Exception e2 ) { FLog . d ( "<STR_LIT:message>" , e2 ) ; } } finally { } } return bm ; } @ Override protected void onPostExecute ( Bitmap result ) { try { if ( image != null && tag . equals ( image . getTag ( ) ) ) { if ( result == null ) { TextView screenName = ( TextView ) image . findViewById ( R . id . title ) ; if ( screenName != null ) { screenName . setText ( "<STR_LIT>" ) ; } return ; } image . setImageBitmap ( result ) ; image . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { try { FLog . d ( "<STR_LIT>" ) ; Intent intent = new Intent ( ) ; FutabaThread activity = ( FutabaThread ) getContext ( ) ; intent . putExtra ( "<STR_LIT>" , activity . getImageURLs ( ) ) ; intent . putExtra ( "<STR_LIT>" , activity . getThumbURLs ( ) ) ; intent . putExtra ( "<STR_LIT>" , tag ) ; intent . setClassName ( activity . getPackageName ( ) , activity . getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; activity . startActivityForResult ( intent , activity . TO_IMAGECATALOG ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ) ; saveButton . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { try { FutabaThread fthread = ( FutabaThread ) v . getContext ( ) ; fthread . saveImage ( tag ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } public String addHighlight ( String title ) { if ( searchQueries != null ) { for ( int i = <NUM_LIT:0> ; i < searchQueries . length ; ++ i ) { String searchQuery = searchQueries [ i ] ; title = title . replaceAll ( searchQuery , "<STR_LIT>" + searchQuery + "<STR_LIT>" ) ; FLog . d ( "<STR_LIT>" + searchQuery ) ; FLog . d ( "<STR_LIT>" + title ) ; } } return title ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . util . ArrayList ; import android . app . AlertDialog ; import android . app . LocalActivityManager ; import android . app . ProgressDialog ; import android . app . TabActivity ; import android . content . Context ; import android . content . DialogInterface ; import android . content . Intent ; import android . content . SharedPreferences ; import android . graphics . Color ; import android . net . Uri ; import android . os . Bundle ; import android . os . Environment ; import android . os . Handler ; import android . os . Message ; import android . preference . PreferenceManager ; import android . util . Log ; import android . view . LayoutInflater ; import android . view . Menu ; import android . view . MenuInflater ; import android . view . MenuItem ; import android . view . View ; import android . view . Window ; import android . view . WindowManager ; import android . widget . FrameLayout ; import android . widget . ImageView ; import android . widget . TabHost ; import android . widget . TextView ; import android . widget . Toast ; import android . widget . TabHost . TabSpec ; import cx . ath . dekosuke . ftbt . R . id ; public class ftbt extends TabActivity implements Runnable { public ArrayList < FutabaBBSContent > favoriteBBSs = new ArrayList < FutabaBBSContent > ( ) ; private boolean doCacheCheck = false ; ProgressDialog waitDialog ; Thread thread ; TabHost tabs ; final int ON_SETTING = <NUM_LIT> ; public void myStart ( ) { tabs = getTabHost ( ) ; TabSpec tab00 = tabs . newTabSpec ( "<STR_LIT>" ) ; View v1 = new MyView ( this , "<STR_LIT>" ) ; tab00 . setIndicator ( v1 ) ; Intent intent = new Intent ( ) . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; tab00 . setContent ( intent ) ; tabs . addTab ( tab00 ) ; } @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; if ( getResources ( ) . getBoolean ( R . bool . avoidsleep ) ) { Window window = getWindow ( ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ; } myStart ( ) ; setWait ( ) ; } public void setWait ( ) { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( this ) ; Boolean checkCache = preferences . getBoolean ( "<STR_LIT>" , false ) ; if ( checkCache ) { AlertDialog . Builder builder = new AlertDialog . Builder ( this ) ; builder . setMessage ( "<STR_LIT>" ) . setCancelable ( true ) . setPositiveButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { doCacheCheck = true ; setWait2 ( ) ; } } ) . setNegativeButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { doCacheCheck = false ; setWait2 ( ) ; } } ) ; builder . create ( ) . show ( ) ; } else { doCacheCheck = true ; setWait2 ( ) ; } } public void setWait2 ( ) { if ( doCacheCheck ) { waitDialog = new ProgressDialog ( this ) ; waitDialog . setMessage ( "<STR_LIT>" ) ; waitDialog . setProgressStyle ( ProgressDialog . STYLE_SPINNER ) ; waitDialog . show ( ) ; } thread = new Thread ( this ) ; thread . start ( ) ; } public void run ( ) { try { Thread . sleep ( <NUM_LIT:100> ) ; if ( doCacheCheck ) { FLog . d ( "<STR_LIT>" ) ; checkCache ( ) ; } else { FLog . d ( "<STR_LIT>" ) ; } } catch ( InterruptedException e ) { } handler . sendEmptyMessage ( <NUM_LIT:0> ) ; } private Handler handler = new Handler ( ) { public void handleMessage ( Message msg ) { FLog . d ( "<STR_LIT>" + msg ) ; try { if ( doCacheCheck ) { try { waitDialog . dismiss ( ) ; Thread . sleep ( <NUM_LIT:100> ) ; } catch ( InterruptedException e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } loading ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ; public void checkCache ( ) { try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( this ) ; int cacheSize = Integer . parseInt ( preferences . getString ( getString ( R . string . cachesize ) , "<STR_LIT:5>" ) ) ; FLog . d ( "<STR_LIT>" + cacheSize ) ; SDCard . limitCache ( cacheSize ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } FLog . d ( "<STR_LIT>" ) ; } public void loading ( ) { try { SDCard . setCacheDir ( this ) ; SDCard . setSaveDir ( this ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } if ( ! SDCard . isSDCardMounted ( ) ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } try { String saveDir = SDCard . getSaveDir ( ) ; if ( saveDir == null ) { throw new Exception ( "<STR_LIT>" ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; if ( waitDialog != null ) { waitDialog . dismiss ( ) ; } Toast . makeText ( this , "<STR_LIT>" + SDCard . saveDir + "<STR_LIT>" + "<STR_LIT>" + Environment . getExternalStorageDirectory ( ) + "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; return ; } Intent intent ; try { tabs . getTabWidget ( ) . getChildAt ( <NUM_LIT:0> ) . setVisibility ( View . GONE ) ; int tabNum = tabs . getTabWidget ( ) . getChildCount ( ) ; favoriteBBSs = new ArrayList < FutabaBBSContent > ( ) ; FLog . d ( "<STR_LIT>" + favoriteBBSs ) ; favoriteBBSs = FavoriteSettings . getFavorites ( this ) ; intent = new Intent ( ) . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; intent . putExtra ( "<STR_LIT>" , "<STR_LIT:all>" ) ; TabSpec tab01 = tabs . newTabSpec ( "<STR_LIT>" ) ; View v1 = new MyView ( this , "<STR_LIT>" ) ; tab01 . setIndicator ( v1 ) ; tab01 . setContent ( intent ) ; tabs . addTab ( tab01 ) ; intent = new Intent ( ) . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; intent . putExtra ( "<STR_LIT>" , "<STR_LIT>" ) ; TabSpec tab02 = tabs . newTabSpec ( "<STR_LIT>" ) ; View v2 = new MyView ( this , "<STR_LIT>" ) ; tab02 . setIndicator ( v2 ) ; tab02 . setContent ( intent ) ; tabs . addTab ( tab02 ) ; if ( favoriteBBSs . size ( ) > <NUM_LIT:0> ) { tabs . setCurrentTab ( <NUM_LIT:2> ) ; } else { tabs . setCurrentTab ( <NUM_LIT:1> ) ; } setTitle ( "<STR_LIT>" + getString ( R . string . app_name ) ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } FLog . d ( "<STR_LIT>" ) ; } public void addFavoriteBBSs ( FutabaBBSContent bbs ) { FLog . d ( "<STR_LIT>" + favoriteBBSs . toString ( ) ) ; try { if ( favoriteBBSs . indexOf ( bbs ) == - <NUM_LIT:1> ) { FLog . d ( "<STR_LIT>" + bbs . toString ( ) ) ; favoriteBBSs . add ( bbs ) ; FavoriteSettings . setFavorites ( this , favoriteBBSs ) ; } else { FLog . d ( "<STR_LIT>" ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public void removeFavoriteBBSs ( FutabaBBSContent bbs ) { try { favoriteBBSs . remove ( bbs ) ; FavoriteSettings . setFavorites ( this , favoriteBBSs ) ; FLog . d ( "<STR_LIT>" + bbs . toString ( ) ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } @ Override public boolean onCreateOptionsMenu ( Menu menu ) { super . onCreateOptionsMenu ( menu ) ; MenuInflater inflater = getMenuInflater ( ) ; inflater . inflate ( R . menu . menu_bbsmenu , menu ) ; return true ; } @ Override public boolean onOptionsItemSelected ( MenuItem item ) { Intent intent ; switch ( item . getItemId ( ) ) { case R . id . settings : intent = new Intent ( ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivityForResult ( intent , ON_SETTING ) ; return true ; case R . id . about : Uri uri = Uri . parse ( getString ( R . string . helpurl ) ) ; intent = new Intent ( Intent . ACTION_VIEW , uri ) ; intent . setClassName ( "<STR_LIT>" , "<STR_LIT>" ) ; try { startActivity ( intent ) ; } catch ( android . content . ActivityNotFoundException ex ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } return true ; } return false ; } private class MyView extends FrameLayout { private LayoutInflater inflater ; public MyView ( Context context ) { super ( context ) ; inflater = LayoutInflater . from ( context ) ; } public MyView ( Context context , String title ) { this ( context ) ; try { View v = inflater . inflate ( R . layout . tabwidget , null ) ; TextView tv = ( TextView ) v . findViewById ( R . id . text ) ; tv . setText ( title ) ; addView ( v ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } protected void onActivityResult ( int requestCode , int resultCode , Intent data ) { FLog . d ( "<STR_LIT>" ) ; if ( requestCode == ON_SETTING ) { } } @ Override public void onResume ( ) { super . onResume ( ) ; FLog . d ( "<STR_LIT>" ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; public class ImageUpdateGallery { } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . util . ArrayList ; import java . util . Calendar ; import java . util . TreeSet ; import android . app . Activity ; import android . content . Intent ; import android . content . SharedPreferences ; import android . view . View ; import android . widget . TextView ; import android . graphics . Typeface ; import android . view . ViewGroup ; import android . widget . ArrayAdapter ; import android . content . Context ; import android . view . LayoutInflater ; import android . text . Html ; import android . util . Log ; import android . os . AsyncTask ; import android . preference . PreferenceManager ; import android . view . View . OnClickListener ; import android . widget . AdapterView ; import android . widget . CheckBox ; import android . widget . CompoundButton ; import android . widget . CompoundButton . OnCheckedChangeListener ; import android . widget . ListView ; import java . io . InputStream ; import java . net . URL ; import cx . ath . dekosuke . ftbt . R . id ; import android . graphics . Bitmap ; import android . graphics . BitmapFactory ; import android . graphics . Color ; import android . widget . ImageView ; import android . view . WindowManager ; import android . content . Context ; import android . view . Display ; public class CatalogAdapter extends ArrayAdapter { public ArrayList < FutabaThreadContent > items ; private LayoutInflater inflater ; private Context context ; private TreeSet < Integer > checkedSet = new TreeSet < Integer > ( ) ; private int width ; private int height ; public CatalogAdapter ( Context context , int textViewResourceId , ArrayList items ) { super ( context , textViewResourceId , items ) ; this . items = ( ArrayList < FutabaThreadContent > ) items ; this . context = context ; this . inflater = ( LayoutInflater ) context . getSystemService ( Context . LAYOUT_INFLATER_SERVICE ) ; WindowManager wm = ( ( WindowManager ) context . getSystemService ( Context . WINDOW_SERVICE ) ) ; Display display = wm . getDefaultDisplay ( ) ; width = display . getWidth ( ) ; height = display . getHeight ( ) ; } @ Override public View getView ( int position , View convertView , ViewGroup parent ) { View view = convertView ; if ( view == null ) { view = inflater . inflate ( R . layout . futaba_catalog_row , null ) ; } try { final FutabaThreadContent item = ( FutabaThreadContent ) items . get ( position ) ; final String threadNum = "<STR_LIT>" + item . threadNum ; TextView text = ( TextView ) view . findViewById ( R . id . bottomtext ) ; CheckBox checkbox = ( CheckBox ) view . findViewById ( R . id . checkbox ) ; TextView nonclickableblank = ( TextView ) view . findViewById ( id . nonclickableblank ) ; TextView resNum = ( TextView ) view . findViewById ( R . id . resnum ) ; TextView BBSName = ( TextView ) view . findViewById ( R . id . bbsname ) ; ImageView iv = ( ImageView ) view . findViewById ( R . id . image ) ; Bitmap bm = null ; iv . setImageBitmap ( bm ) ; iv . setVisibility ( View . VISIBLE ) ; if ( FutabaThreadContent . isMenu1 ( item ) ) { text . setTextSize ( StateMan . getDescFontSize ( getContext ( ) ) ) ; text . setTextColor ( Color . parseColor ( "<STR_LIT>" ) ) ; text . setText ( "<STR_LIT>" ) ; view . setBackgroundColor ( Color . parseColor ( "<STR_LIT>" ) ) ; checkbox . setVisibility ( View . GONE ) ; nonclickableblank . setVisibility ( View . GONE ) ; resNum . setVisibility ( View . GONE ) ; BBSName . setVisibility ( View . GONE ) ; iv . setVisibility ( View . GONE ) ; view . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { } } ) ; return view ; } else if ( FutabaThreadContent . isMenu2 ( item ) ) { text . setTextSize ( StateMan . getDescFontSize ( getContext ( ) ) ) ; text . setTextColor ( Color . parseColor ( "<STR_LIT>" ) ) ; text . setText ( "<STR_LIT>" ) ; view . setBackgroundColor ( Color . parseColor ( "<STR_LIT>" ) ) ; checkbox . setVisibility ( View . GONE ) ; nonclickableblank . setVisibility ( View . GONE ) ; resNum . setVisibility ( View . GONE ) ; BBSName . setVisibility ( View . GONE ) ; iv . setVisibility ( View . GONE ) ; view . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { } } ) ; return view ; } text . setTextColor ( Color . parseColor ( "<STR_LIT>" ) ) ; resNum . setVisibility ( View . VISIBLE ) ; if ( true ) { view . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { FLog . d ( "<STR_LIT>" ) ; Intent intent = new Intent ( ) ; Catalog activity = ( Catalog ) getContext ( ) ; try { FutabaThreadContent thread = item ; if ( ! activity . mode . equals ( "<STR_LIT>" ) ) { thread . baseUrl = activity . baseUrl ; } Calendar calendar = Calendar . getInstance ( ) ; thread . lastAccessed = calendar . getTimeInMillis ( ) ; HistoryManager man = new HistoryManager ( ) ; man . Load ( ) ; int maxHistoryNum = <NUM_LIT:20> ; try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( activity ) ; maxHistoryNum = Integer . parseInt ( preferences . getString ( activity . getString ( R . string . historynum ) , "<STR_LIT>" ) ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } FLog . d ( "<STR_LIT>" + maxHistoryNum ) ; FLog . d ( "<STR_LIT>" + thread . toString ( ) ) ; man . addThread ( thread , maxHistoryNum ) ; man . Save ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } if ( ! activity . mode . equals ( "<STR_LIT>" ) ) { String baseUrl = activity . baseUrl ; intent . putExtra ( "<STR_LIT>" , baseUrl ) ; intent . putExtra ( "<STR_LIT>" , activity . BBSName ) ; FLog . d ( "<STR_LIT>" ) ; } else { String baseUrl = item . baseUrl ; intent . putExtra ( "<STR_LIT>" , baseUrl ) ; intent . putExtra ( "<STR_LIT>" , item . BBSName ) ; FLog . d ( "<STR_LIT>" ) ; } intent . putExtra ( "<STR_LIT>" , threadNum ) ; intent . setClassName ( activity . getPackageName ( ) , activity . getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; activity . startActivity ( intent ) ; } } ) ; } Catalog activity = ( Catalog ) getContext ( ) ; final int pos = position ; if ( item != null ) { text . setTextSize ( StateMan . getMainFontSize ( getContext ( ) ) ) ; String mainText = item . text ; if ( ! activity . mode . equals ( "<STR_LIT>" ) ) { mainText = StringUtil . highlightFocusWordMatched ( mainText , activity . focusWords ) ; try { FutabaThreadContent prevThread = activity . man . get ( item . threadNum ) ; int diffResNum = Integer . parseInt ( item . resNum ) - Integer . parseInt ( prevThread . resNum ) ; resNum . setText ( Html . fromHtml ( item . resNum + "<STR_LIT>" + "<STR_LIT>" + Math . max ( <NUM_LIT:0> , diffResNum ) + "<STR_LIT>" ) ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT>" + item . threadNum + "<STR_LIT>" ) ; resNum . setText ( item . resNum + "<STR_LIT>" ) ; } } else { resNum . setText ( item . resNum + "<STR_LIT>" ) ; } if ( item . text != null ) { CharSequence cs = Html . fromHtml ( mainText ) ; text . setText ( cs ) ; } resNum . setTextSize ( StateMan . getDescFontSize ( getContext ( ) ) ) ; BBSName . setTextSize ( StateMan . getDescFontSize ( getContext ( ) ) ) ; nonclickableblank . setTextSize ( StateMan . getDescFontSize ( getContext ( ) ) ) ; if ( activity . mode . equals ( "<STR_LIT>" ) ) { BBSName . setText ( "<STR_LIT:(>" + item . BBSName + "<STR_LIT:)>" ) ; view . setBackgroundColor ( Color . parseColor ( "<STR_LIT>" ) ) ; checkbox . setChecked ( item . isChecked ) ; checkbox . setOnCheckedChangeListener ( new OnCheckedChangeListener ( ) { public void onCheckedChanged ( CompoundButton buttonView , boolean isChecked ) { FLog . d ( "<STR_LIT>" + buttonView . isShown ( ) ) ; FLog . d ( "<STR_LIT>" + pos + "<STR_LIT>" + isChecked ) ; if ( buttonView . isShown ( ) ) { items . get ( pos ) . isChecked = isChecked ; } } } ) ; } else { view . setBackgroundColor ( Color . parseColor ( "<STR_LIT>" ) ) ; checkbox . setVisibility ( View . GONE ) ; nonclickableblank . setVisibility ( View . GONE ) ; } bm = Bitmap . createBitmap ( <NUM_LIT> , <NUM_LIT> , Bitmap . Config . ALPHA_8 ) ; iv . setImageBitmap ( bm ) ; try { if ( item . imgURL != null ) { iv . setTag ( item . imgURL ) ; ImageGetTask task = new ImageGetTask ( iv ) ; task . execute ( item . imgURL ) ; } else { } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return view ; } static Object lock_id = new Object ( ) ; static int LastTaskID = - <NUM_LIT:1> ; class ImageGetTask extends AsyncTask < String , Void , Bitmap > { private ImageView image ; private String tag ; private int id ; public ImageGetTask ( ImageView _image ) { image = _image ; tag = _image . getTag ( ) . toString ( ) ; synchronized ( CatalogAdapter . lock_id ) { CatalogAdapter . LastTaskID += <NUM_LIT:1> ; id = CatalogAdapter . LastTaskID ; } } @ Override protected Bitmap doInBackground ( String ... urls ) { Bitmap bm = null ; try { bm = ImageCache . getImage ( urls [ <NUM_LIT:0> ] ) ; if ( bm == null ) { ImageCache . setImage ( urls [ <NUM_LIT:0> ] ) ; bm = ImageCache . getImage ( urls [ <NUM_LIT:0> ] ) ; } bm = ImageResizer . ResizeWideToSquare ( bm ) ; } catch ( Exception e ) { FLog . d ( e . toString ( ) ) ; } return bm ; } @ Override protected void onPostExecute ( Bitmap result ) { if ( result != null && image != null && tag . equals ( image . getTag ( ) . toString ( ) ) ) { image . setImageBitmap ( result ) ; } } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . ByteArrayOutputStream ; import java . io . File ; import java . nio . charset . Charset ; import java . util . ArrayList ; import java . util . List ; import org . apache . http . HttpResponse ; import org . apache . http . NameValuePair ; import org . apache . http . client . entity . UrlEncodedFormEntity ; import org . apache . http . client . methods . HttpGet ; import org . apache . http . client . methods . HttpPost ; import org . apache . http . client . params . ClientPNames ; import org . apache . http . client . params . CookiePolicy ; import org . apache . http . cookie . Cookie ; import org . apache . http . entity . mime . HttpMultipartMode ; import org . apache . http . entity . mime . MultipartEntity ; import org . apache . http . entity . mime . content . FileBody ; import org . apache . http . entity . mime . content . StringBody ; import org . apache . http . impl . client . DefaultHttpClient ; import org . apache . http . message . BasicNameValuePair ; import android . app . AlertDialog ; import android . content . DialogInterface ; import android . content . DialogInterface . OnClickListener ; import android . content . DialogInterface . OnMultiChoiceClickListener ; import android . content . Intent ; import android . database . Cursor ; import android . provider . MediaStore ; import android . text . InputType ; import android . util . Log ; import android . view . View ; import android . widget . AdapterView ; import android . widget . EditText ; import android . widget . TextView ; import android . widget . Toast ; public class FutabaThreadOnLongClickListener implements AdapterView . OnItemLongClickListener , OnClickListener { public int chosen = <NUM_LIT:0> ; public int currentPosition = <NUM_LIT:0> ; FutabaThread fthread = null ; public boolean onItemLongClick ( AdapterView < ? > arg0 , View view , int arg2 , long arg3 ) { if ( view == null ) { FLog . d ( "<STR_LIT>" ) ; return false ; } fthread = ( FutabaThread ) view . getContext ( ) ; FLog . d ( "<STR_LIT>" + arg2 + "<STR_LIT>" + arg3 ) ; AlertDialog . Builder dlg ; dlg = new AlertDialog . Builder ( fthread ) ; dlg . setTitle ( "<STR_LIT>" ) ; String [ ] strs_temp = null ; FutabaStatus item = ( FutabaStatus ) fthread . adapter . items . get ( arg2 ) ; if ( arg2 == <NUM_LIT:0> ) { String [ ] temp = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; strs_temp = temp ; } else if ( item != null && item . id != fthread . adapter . shioriPosition ) { String [ ] temp = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; strs_temp = temp ; } else { String [ ] temp = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; strs_temp = temp ; } if ( arg2 < <NUM_LIT:0> || arg2 >= fthread . adapter . items . size ( ) || FutabaStatus . isBlank ( ( FutabaStatus ) ( fthread . adapter . items . get ( arg2 ) ) ) ) { return false ; } currentPosition = arg2 ; final String [ ] strs = strs_temp ; final View view_f = view ; dlg . setSingleChoiceItems ( strs , <NUM_LIT:0> , this ) ; dlg . setPositiveButton ( "<STR_LIT:OK>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { FLog . d ( "<STR_LIT>" + id + "<STR_LIT>" + chosen ) ; if ( chosen == <NUM_LIT:0> ) { processDeleteDialog ( view_f ) ; } else if ( chosen == <NUM_LIT:1> ) { processQuoteDialog ( view_f ) ; } else if ( chosen == <NUM_LIT:2> ) { processShareDialog ( view_f ) ; } else if ( chosen == <NUM_LIT:3> ) { modifyShiori ( view_f ) ; } } } ) ; dlg . setNegativeButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { } } ) ; dlg . show ( ) ; return false ; } public void onClick ( DialogInterface dialog , int which ) { chosen = which ; } public void processQuoteDialog ( View view ) { chosen = <NUM_LIT:0> ; TextView text = ( TextView ) view . findViewById ( R . id . maintext ) ; if ( text != null ) { String [ ] addition = { } ; final String strs_all = text . getText ( ) . toString ( ) ; final String [ ] strs = StringUtil . nonBlankSplit ( strs_all , addition ) ; final boolean [ ] quoteFlags = new boolean [ strs . length ] ; AlertDialog . Builder dlg ; dlg = new AlertDialog . Builder ( fthread ) ; dlg . setTitle ( "<STR_LIT>" ) ; dlg . setCancelable ( true ) ; dlg . setMultiChoiceItems ( strs , quoteFlags , new DialogInterface . OnMultiChoiceClickListener ( ) { public void onClick ( DialogInterface dialog , int which , boolean isChecked ) { quoteFlags [ which ] = isChecked ; } } ) . setPositiveButton ( "<STR_LIT:OK>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int whichButton ) { String text = "<STR_LIT>" ; for ( int i = <NUM_LIT:0> ; i < quoteFlags . length ; ++ i ) { if ( quoteFlags [ i ] ) { text += strs [ i ] + "<STR_LIT:n>" ; } } { Intent intent = new Intent ( ) ; intent . putExtra ( "<STR_LIT>" , fthread . baseURL ) ; intent . putExtra ( "<STR_LIT>" , fthread . threadNum ) ; intent . setClassName ( fthread . getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; intent . putExtra ( "<STR_LIT>" , StringUtil . quote ( text ) ) ; try { fthread . startActivity ( intent ) ; } catch ( android . content . ActivityNotFoundException ex ) { FLog . d ( "<STR_LIT>" ) ; } } } } ) . setNegativeButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int whichButton ) { } } ) . show ( ) ; } } public void processShareDialog ( View view ) { chosen = <NUM_LIT:0> ; TextView text = ( TextView ) view . findViewById ( R . id . maintext ) ; if ( text != null ) { String [ ] addition = { } ; final String strs_all = text . getText ( ) . toString ( ) ; final String [ ] strs = StringUtil . nonBlankSplit ( strs_all , addition ) ; final boolean [ ] quoteFlags = new boolean [ strs . length ] ; AlertDialog . Builder dlg ; dlg = new AlertDialog . Builder ( fthread ) ; dlg . setTitle ( "<STR_LIT>" ) ; dlg . setCancelable ( true ) ; dlg . setMultiChoiceItems ( strs , quoteFlags , new DialogInterface . OnMultiChoiceClickListener ( ) { public void onClick ( DialogInterface dialog , int which , boolean isChecked ) { quoteFlags [ which ] = isChecked ; } } ) . setPositiveButton ( "<STR_LIT:OK>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int whichButton ) { String text = "<STR_LIT>" ; for ( int i = <NUM_LIT:0> ; i < quoteFlags . length ; ++ i ) { if ( quoteFlags [ i ] ) { text += strs [ i ] + "<STR_LIT:n>" ; } } { Intent intent = new Intent ( Intent . ACTION_SEND ) ; intent . setType ( "<STR_LIT:text/plain>" ) ; intent . putExtra ( Intent . EXTRA_TEXT , StringUtil . quote ( text ) ) ; try { fthread . startActivity ( intent ) ; } catch ( android . content . ActivityNotFoundException ex ) { FLog . d ( "<STR_LIT>" ) ; } } } } ) . setNegativeButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int whichButton ) { } } ) . show ( ) ; } } public void processDeleteDialog ( View view ) { AlertDialog . Builder dlg ; dlg = new AlertDialog . Builder ( fthread ) ; dlg . setTitle ( "<STR_LIT>" ) ; EditText editText = new EditText ( fthread ) ; editText . setInputType ( InputType . TYPE_CLASS_NUMBER ) ; TextView bottomtext = ( TextView ) view . findViewById ( R . id . bottomtext ) ; String [ ] splits = bottomtext . getText ( ) . toString ( ) . split ( "<STR_LIT>" ) ; final String resNum = splits [ splits . length - <NUM_LIT:1> ] ; final EditText editText_f = editText ; dlg . setView ( editText ) ; dlg . setPositiveButton ( "<STR_LIT:OK>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { FLog . d ( "<STR_LIT>" + editText_f . getText ( ) ) ; deletePost ( resNum , editText_f . getText ( ) . toString ( ) ) ; } } ) ; dlg . setNegativeButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { } } ) ; dlg . show ( ) ; } public void deletePost ( String resNum , String deletekey ) { try { FLog . d ( "<STR_LIT>" ) ; DefaultHttpClient httpClient ; httpClient = new DefaultHttpClient ( ) ; FutabaCookieManager . loadCookie ( httpClient ) ; httpClient . getParams ( ) . setParameter ( ClientPNames . COOKIE_POLICY , CookiePolicy . BROWSER_COMPATIBILITY ) ; httpClient . getParams ( ) . setParameter ( "<STR_LIT>" , <NUM_LIT> ) ; httpClient . getParams ( ) . setParameter ( "<STR_LIT>" , <NUM_LIT> ) ; try { { List < Cookie > cookies = httpClient . getCookieStore ( ) . getCookies ( ) ; if ( cookies . isEmpty ( ) ) { FLog . d ( "<STR_LIT>" ) ; } else { for ( int i = <NUM_LIT:0> ; i < cookies . size ( ) ; i ++ ) { FLog . d ( "<STR_LIT>" + cookies . get ( i ) . toString ( ) ) ; } } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } FLog . d ( "<STR_LIT>" + deletekey ) ; FLog . d ( "<STR_LIT>" + resNum ) ; String urlStr = fthread . baseURL + "<STR_LIT>" ; HttpPost httppost = new HttpPost ( urlStr ) ; List < NameValuePair > nameValuePair = new ArrayList < NameValuePair > ( <NUM_LIT:3> ) ; nameValuePair . add ( new BasicNameValuePair ( "<STR_LIT>" , "<STR_LIT>" ) ) ; nameValuePair . add ( new BasicNameValuePair ( resNum , "<STR_LIT>" ) ) ; nameValuePair . add ( new BasicNameValuePair ( "<STR_LIT>" , deletekey ) ) ; httppost . setEntity ( new UrlEncodedFormEntity ( nameValuePair ) ) ; httppost . addHeader ( "<STR_LIT>" , fthread . threadURL ) ; HttpResponse response = httpClient . execute ( httppost ) ; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; response . getEntity ( ) . writeTo ( byteArrayOutputStream ) ; String retData = byteArrayOutputStream . toString ( "<STR_LIT>" ) ; FLog . v ( "<STR_LIT>" + retData ) ; FLog . d ( "<STR_LIT>" ) ; DelpostParser parser = new DelpostParser ( ) ; String contents = parser . parse ( fthread , retData ) ; if ( ! contents . equals ( "<STR_LIT>" ) ) { Toast . makeText ( fthread , contents , Toast . LENGTH_LONG ) . show ( ) ; } else { Toast . makeText ( fthread , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public void modifyShiori ( View view ) { FutabaStatus item = ( FutabaStatus ) fthread . adapter . items . get ( currentPosition ) ; if ( item . id == fthread . adapter . shioriPosition ) { fthread . removeShiori ( currentPosition ) ; } else { fthread . registerShiori ( currentPosition ) ; } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . File ; import java . util . ArrayList ; import android . app . Activity ; import android . app . AlertDialog ; import android . content . Context ; import android . content . DialogInterface ; public class DirectorySelectDialog extends Activity implements DialogInterface . OnClickListener { private Context mContext ; private ArrayList < File > mDirectoryList ; private onDirectoryListDialogListener mListenner ; public DirectorySelectDialog ( Context context ) { mContext = context ; mDirectoryList = new ArrayList < File > ( ) ; } public void onClick ( DialogInterface dialog , int which ) { if ( ( null != mDirectoryList ) && ( null != mListenner ) ) { File file = mDirectoryList . get ( which ) ; show ( file . getAbsolutePath ( ) , file . getPath ( ) ) ; } } public void show ( final String path , String title ) { try { File [ ] mDirectories = new File ( path ) . listFiles ( ) ; if ( null == mDirectories && null != mListenner ) { mListenner . onClickFileList ( null ) ; } else { mDirectoryList . clear ( ) ; ArrayList < String > viewList = new ArrayList < String > ( ) ; for ( File file : mDirectories ) { if ( file . isDirectory ( ) ) { viewList . add ( file . getName ( ) + "<STR_LIT:/>" ) ; mDirectoryList . add ( file ) ; } } AlertDialog . Builder alertDialogBuilder = new AlertDialog . Builder ( mContext ) ; alertDialogBuilder . setTitle ( title ) ; alertDialogBuilder . setItems ( viewList . toArray ( new String [ <NUM_LIT:0> ] ) , this ) ; alertDialogBuilder . setPositiveButton ( mContext . getString ( R . string . ok ) , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int which ) { mListenner . onClickFileList ( path ) ; } } ) ; alertDialogBuilder . setNegativeButton ( mContext . getString ( R . string . cancel ) , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int which ) { mListenner . onClickFileList ( null ) ; } } ) ; alertDialogBuilder . show ( ) ; } } catch ( SecurityException e ) { e . printStackTrace ( ) ; } } public void setOnFileListDialogListener ( onDirectoryListDialogListener listener ) { mListenner = listener ; } public interface onDirectoryListDialogListener { public void onClickFileList ( String path ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . File ; import java . net . URL ; import java . util . ArrayList ; import cx . ath . dekosuke . ftbt . R . id ; import android . app . Activity ; import android . content . ContentResolver ; import android . content . ContentValues ; import android . content . Intent ; import android . graphics . Color ; import android . media . MediaScannerConnection ; import android . net . Uri ; import android . os . Bundle ; import android . provider . MediaStore . Images ; import android . util . Log ; import android . view . Menu ; import android . view . MenuInflater ; import android . view . MenuItem ; import android . view . View ; import android . view . ViewGroup ; import android . view . Window ; import android . view . WindowManager ; import android . widget . ArrayAdapter ; import android . widget . Button ; import android . widget . Gallery ; import android . widget . LinearLayout ; import android . widget . ListView ; import android . widget . TextView ; import android . widget . Toast ; public class ImageCatalog extends Activity { Toast toast = null ; String myImageURL = null ; ArrayList < String > imgURLs = new ArrayList < String > ( ) ; ArrayList < String > thumbURLs = new ArrayList < String > ( ) ; @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; if ( getResources ( ) . getBoolean ( R . bool . avoidsleep ) ) { Window window = getWindow ( ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ; } try { setTitle ( "<STR_LIT>" + getString ( R . string . app_name ) ) ; FLog . d ( "<STR_LIT>" ) ; Intent intent = getIntent ( ) ; FLog . d ( "<STR_LIT>" ) ; imgURLs = ( ArrayList < String > ) intent . getSerializableExtra ( "<STR_LIT>" ) ; thumbURLs = ( ArrayList < String > ) intent . getSerializableExtra ( "<STR_LIT>" ) ; FLog . d ( "<STR_LIT>" + imgURLs . size ( ) ) ; myImageURL = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; FLog . d ( myImageURL ) ; CircleList . clear ( ) ; for ( int i = <NUM_LIT:0> ; i < imgURLs . size ( ) ; i ++ ) { String imgURL = imgURLs . get ( i ) ; CircleList . add ( imgURL ) ; if ( imgURL . equals ( myImageURL ) ) { CircleList . moveToLast ( ) ; } } setContentView ( R . layout . imagegallery ) ; Button download = ( Button ) findViewById ( id . down_btn ) ; download . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { try { String imgFile = CircleList . get ( ) ; File file = new File ( imgFile ) ; File saved_file = ImageCache . saveImage ( imgFile ) ; if ( saved_file != null ) { if ( toast != null ) { toast . cancel ( ) ; } toast = Toast . makeText ( v . getContext ( ) , saved_file . getAbsolutePath ( ) + "<STR_LIT>" , Toast . LENGTH_SHORT ) ; toast . show ( ) ; String mimeType = StringUtil . getMIMEType ( saved_file . getName ( ) ) ; FLog . d ( "<STR_LIT>" + saved_file . getName ( ) ) ; FLog . d ( "<STR_LIT>" + mimeType ) ; ContentResolver contentResolver = getContentResolver ( ) ; ContentValues values = new ContentValues ( <NUM_LIT:7> ) ; values . put ( Images . Media . TITLE , saved_file . getName ( ) ) ; values . put ( Images . Media . DISPLAY_NAME , saved_file . getName ( ) ) ; values . put ( Images . Media . DATE_TAKEN , System . currentTimeMillis ( ) ) ; values . put ( Images . Media . MIME_TYPE , mimeType ) ; values . put ( Images . Media . ORIENTATION , <NUM_LIT:0> ) ; values . put ( Images . Media . DATA , saved_file . getPath ( ) ) ; values . put ( Images . Media . SIZE , saved_file . length ( ) ) ; contentResolver . insert ( Images . Media . EXTERNAL_CONTENT_URI , values ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ) ; Button prev = ( Button ) findViewById ( id . prev_btn ) ; prev . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { try { ImageCatalogSingleView imageview = ( ImageCatalogSingleView ) findViewById ( id . image ) ; imageview . clearImage ( ) ; moveImage ( - <NUM_LIT:1> ) ; imageview . setImage ( ) ; setReturnImage ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ) ; Button next = ( Button ) findViewById ( id . next_btn ) ; next . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { try { ImageCatalogSingleView imageview = ( ImageCatalogSingleView ) findViewById ( id . image ) ; imageview . clearImage ( ) ; moveImage ( + <NUM_LIT:1> ) ; imageview . setImage ( ) ; setReturnImage ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ) ; Button rotate = ( Button ) findViewById ( id . rotate_btn ) ; rotate . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { try { ImageCatalogSingleView imageview = ( ImageCatalogSingleView ) findViewById ( id . image ) ; imageview . rotateImage ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ) ; Button gridview = ( Button ) findViewById ( id . gridview_btn ) ; gridview . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { try { FLog . d ( "<STR_LIT>" ) ; Intent intent = new Intent ( ) ; intent . putExtra ( "<STR_LIT>" , CircleList . pos ( ) ) ; intent . putExtra ( "<STR_LIT>" , imgURLs ) ; intent . putExtra ( "<STR_LIT>" , thumbURLs ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ) ; gridview . setVisibility ( View . GONE ) ; try { String className = getCallingActivity ( ) . getClassName ( ) ; FLog . d ( "<STR_LIT>" + className ) ; if ( className . equals ( "<STR_LIT>" ) ) { gridview . setVisibility ( View . VISIBLE ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } moveImage ( <NUM_LIT:0> ) ; setReturnImage ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public void moveImage ( int num ) { CircleList . move ( num ) ; TextView imagenum = ( TextView ) findViewById ( id . imagenum ) ; imagenum . setText ( "<STR_LIT>" + ( <NUM_LIT:1> + CircleList . pos ( ) ) + "<STR_LIT:/>" + CircleList . size ( ) ) ; } public void setReturnImage ( ) { Intent ret_i = new Intent ( ) ; ret_i . putExtra ( "<STR_LIT>" , CircleList . get ( ) ) ; setResult ( RESULT_OK , ret_i ) ; } private LinearLayout . LayoutParams createParam ( int w , int h ) { return new LinearLayout . LayoutParams ( w , h ) ; } @ Override public void onDestroy ( ) { ImageCatalogSingleView imageview = ( ImageCatalogSingleView ) findViewById ( id . image ) ; imageview . clearImage ( ) ; FLog . d ( "<STR_LIT>" ) ; super . onDestroy ( ) ; } @ Override public boolean onCreateOptionsMenu ( Menu menu ) { super . onCreateOptionsMenu ( menu ) ; MenuInflater inflater = getMenuInflater ( ) ; inflater . inflate ( R . menu . menu_imagecatalog , menu ) ; return true ; } @ Override public boolean onOptionsItemSelected ( MenuItem item ) { Intent intent ; switch ( item . getItemId ( ) ) { case R . id . share : intent = new Intent ( Intent . ACTION_SEND ) ; intent . setType ( "<STR_LIT:text/plain>" ) ; intent . putExtra ( Intent . EXTRA_TEXT , CircleList . get ( ) ) ; try { startActivityForResult ( intent , <NUM_LIT:0> ) ; } catch ( android . content . ActivityNotFoundException ex ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } return true ; case R . id . view : intent = new Intent ( Intent . ACTION_VIEW , Uri . parse ( CircleList . get ( ) ) ) ; try { startActivityForResult ( intent , <NUM_LIT:0> ) ; } catch ( android . content . ActivityNotFoundException ex ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } return true ; case R . id . settings : intent = new Intent ( ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; return true ; case R . id . about : Uri uri = Uri . parse ( getString ( R . string . helpurl ) ) ; intent = new Intent ( Intent . ACTION_VIEW , uri ) ; intent . setClassName ( "<STR_LIT>" , "<STR_LIT>" ) ; try { startActivity ( intent ) ; } catch ( android . content . ActivityNotFoundException ex ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } return true ; } return false ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . graphics . Bitmap ; import java . lang . Math ; import android . util . Log ; import android . graphics . Matrix ; public class ImageResizer { public static Bitmap ResizeWideToSquare ( Bitmap bmp ) { int width = bmp . getWidth ( ) ; int height = bmp . getHeight ( ) ; int size = Math . max ( width , height ) ; int pixels [ ] = new int [ width * height ] ; bmp . getPixels ( pixels , <NUM_LIT:0> , width , <NUM_LIT:0> , <NUM_LIT:0> , width , height ) ; Bitmap ret = Bitmap . createBitmap ( size , size , Bitmap . Config . ARGB_8888 ) ; if ( width > height ) { ret . setPixels ( pixels , <NUM_LIT:0> , width , <NUM_LIT:0> , ( width - height ) / <NUM_LIT:2> , width , height ) ; } else { ret . setPixels ( pixels , <NUM_LIT:0> , width , ( height - width ) / <NUM_LIT:2> , <NUM_LIT:0> , width , height ) ; } return ret ; } public static Bitmap ResizeCutToSquare ( Bitmap bmp ) { int width = bmp . getWidth ( ) ; int height = bmp . getHeight ( ) ; int size = Math . min ( width , height ) ; int pixels [ ] = new int [ size * size ] ; int stride = Math . max ( width , height ) ; bmp . getPixels ( pixels , <NUM_LIT:0> , size , Math . max ( <NUM_LIT:0> , ( width - height ) / <NUM_LIT:2> ) , Math . max ( <NUM_LIT:0> , ( height - width ) / <NUM_LIT:2> ) , size , size ) ; Bitmap ret = Bitmap . createBitmap ( size , size , Bitmap . Config . ARGB_8888 ) ; ret . setPixels ( pixels , <NUM_LIT:0> , size , <NUM_LIT:0> , <NUM_LIT:0> , size , size ) ; return ret ; } public static Bitmap ResizeCenter ( Bitmap bmp , int size ) { Bitmap temp = ResizeCutToSquare ( bmp ) ; return Bitmap . createScaledBitmap ( temp , size , size , true ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . app . Activity ; import android . app . AlertDialog ; import android . app . ListActivity ; import android . net . Uri ; import android . os . Bundle ; import android . view . Display ; import android . view . KeyEvent ; import android . view . Menu ; import android . view . MenuInflater ; import android . view . MenuItem ; import android . view . Window ; import android . view . WindowManager ; import android . content . Context ; import android . content . DialogInterface ; import android . content . Intent ; import android . content . SharedPreferences ; import android . webkit . CookieSyncManager ; import android . widget . AdapterView ; import android . widget . CheckBox ; import android . widget . EditText ; import android . widget . ImageButton ; import android . widget . LinearLayout ; import android . widget . ListView ; import android . widget . TextView ; import android . widget . Toast ; import android . view . View . OnClickListener ; import android . content . Intent ; import android . util . Log ; import android . view . View ; import android . view . inputmethod . InputMethodManager ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . TreeSet ; import org . apache . http . HttpEntity ; import org . apache . http . HttpResponse ; import org . apache . http . client . HttpClient ; import org . apache . http . client . methods . HttpGet ; import org . apache . http . impl . client . DefaultHttpClient ; import org . apache . http . params . HttpConnectionParams ; import org . apache . http . params . HttpParams ; import org . apache . http . protocol . BasicHttpContext ; import org . apache . http . protocol . DefaultedHttpContext ; import org . apache . http . protocol . HttpContext ; import android . app . ProgressDialog ; import java . lang . Thread ; import java . net . UnknownHostException ; import android . os . Handler ; import android . os . Message ; import android . preference . PreferenceManager ; import android . widget . Button ; import cx . ath . dekosuke . ftbt . R . id ; public class Catalog extends Activity implements OnClickListener , Runnable { private ArrayList < FutabaThreadContent > fthreads = new ArrayList < FutabaThreadContent > ( ) ; private CatalogParser parser ; private CatalogAdapter adapter = null ; public String baseUrl = "<STR_LIT>" ; private String catalogURL ; private ProgressDialog waitDialog ; private Thread thread ; private int sortType = <NUM_LIT:0> ; public String BBSName = "<STR_LIT>" ; private ListView listView ; public ArrayList < String > focusWords = new ArrayList < String > ( ) ; public String mode ; int position = <NUM_LIT:0> ; boolean onCreateEnd = false ; HistoryManager man = new HistoryManager ( ) ; @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; FLog . d ( "<STR_LIT>" ) ; CookieSyncManager . createInstance ( this ) ; CookieSyncManager . getInstance ( ) . startSync ( ) ; if ( getResources ( ) . getBoolean ( R . bool . avoidsleep ) ) { Window window = getWindow ( ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ; } setWait ( ) ; } @ Override protected void onResume ( ) { super . onResume ( ) ; CookieSyncManager . getInstance ( ) . stopSync ( ) ; try { FLog . d ( "<STR_LIT>" ) ; if ( adapter != null ) { adapter . notifyDataSetChanged ( ) ; } if ( onCreateEnd && mode . equals ( "<STR_LIT>" ) ) { if ( adapter != null ) { setWait ( ) ; } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } @ Override protected void onPause ( ) { super . onPause ( ) ; System . gc ( ) ; CookieSyncManager . getInstance ( ) . sync ( ) ; } public void setWait ( ) { if ( waitDialog != null ) { waitDialog . dismiss ( ) ; } waitDialog = new ProgressDialog ( this ) ; waitDialog . setMessage ( this . getString ( R . string . loading ) ) ; waitDialog . setProgressStyle ( ProgressDialog . STYLE_SPINNER ) ; waitDialog . show ( ) ; try { sortType = StateMan . getSortParam ( this ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } thread = new Thread ( this ) ; thread . start ( ) ; } public void run ( ) { try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( InterruptedException e ) { } handler . sendEmptyMessage ( <NUM_LIT:0> ) ; } private Handler handler = new Handler ( ) { public void handleMessage ( Message msg ) { try { loading ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ; final Handler handler2 = new Handler ( ) ; private void loading ( ) { Intent intent = getIntent ( ) ; baseUrl = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; BBSName = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; mode = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; catalogURL = baseUrl + "<STR_LIT>" ; setContentView ( R . layout . futaba_catalog ) ; listView = ( ListView ) findViewById ( id . cataloglistview ) ; try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( this ) ; boolean fastScrollEnabled = preferences . getBoolean ( "<STR_LIT>" , false ) ; listView . setFastScrollEnabled ( fastScrollEnabled ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } adapter = new CatalogAdapter ( this , R . layout . futaba_catalog_row , ( ArrayList < FutabaThreadContent > ) fthreads . clone ( ) ) ; if ( ! mode . equals ( "<STR_LIT>" ) ) { Button historyDeleteButton = ( Button ) findViewById ( id . delete_btn ) ; historyDeleteButton . setVisibility ( View . GONE ) ; } else { Button reloadButton = ( Button ) findViewById ( id . reload_btn ) ; reloadButton . setVisibility ( View . GONE ) ; Button historyButton = ( Button ) findViewById ( id . history_btn ) ; historyButton . setVisibility ( View . GONE ) ; Button sortTypeButton = ( Button ) findViewById ( id . sorttype_btn ) ; sortTypeButton . setVisibility ( View . GONE ) ; } EditText searchWord = ( EditText ) findViewById ( R . id . searchinput ) ; searchWord . setOnKeyListener ( new View . OnKeyListener ( ) { public boolean onKey ( View v , int keyCode , KeyEvent event ) { FLog . d ( "<STR_LIT>" + event ) ; if ( event . getAction ( ) == KeyEvent . ACTION_DOWN && keyCode == KeyEvent . KEYCODE_ENTER ) { return true ; } if ( event . getAction ( ) == KeyEvent . ACTION_UP && keyCode == KeyEvent . KEYCODE_ENTER ) { EditText word = ( EditText ) findViewById ( R . id . searchinput ) ; Catalog activity = ( Catalog ) v . getContext ( ) ; activity . onClickSearchButton ( v ) ; return false ; } return false ; } } ) ; Button btn = new Button ( this ) ; btn . setText ( "<STR_LIT>" ) ; btn . setVisibility ( View . INVISIBLE ) ; listView . setAdapter ( adapter ) ; LinearLayout searchBar = ( LinearLayout ) findViewById ( id . search_bar ) ; searchBar . setVisibility ( View . GONE ) ; new Thread ( new FutabaCatalogContentGetter ( ) ) . start ( ) ; } private LinearLayout . LayoutParams createParam ( int w , int h ) { return new LinearLayout . LayoutParams ( w , h ) ; } private class FutabaCatalogContentGetter extends Thread { @ Override public void run ( ) { try { fthreads = new ArrayList < FutabaThreadContent > ( ) ; parser = new CatalogParser ( ) ; String title_text = "<STR_LIT>" ; String toast_text = "<STR_LIT>" ; if ( ! mode . equals ( "<STR_LIT>" ) ) { String catalogHtml = "<STR_LIT>" ; Boolean network_ok = true ; Boolean cache_ok = true ; try { catalogHtml = CatalogHtmlReader . Read ( catalogURL , adapter . getContext ( ) , sortType ) ; network_ok = true ; } catch ( UnknownHostException e ) { FLog . d ( "<STR_LIT>" ) ; network_ok = false ; if ( SDCard . cacheExist ( FutabaCrypt . createDigest ( catalogURL ) ) ) { FLog . d ( "<STR_LIT>" + FutabaCrypt . createDigest ( catalogURL ) ) ; catalogHtml = SDCard . loadTextCache ( FutabaCrypt . createDigest ( catalogURL ) ) ; } else { FLog . d ( "<STR_LIT>" + FutabaCrypt . createDigest ( catalogURL ) + "<STR_LIT>" ) ; cache_ok = false ; } } catch ( Exception e ) { network_ok = false ; if ( SDCard . cacheExist ( FutabaCrypt . createDigest ( catalogURL ) ) ) { FLog . d ( "<STR_LIT>" + FutabaCrypt . createDigest ( catalogURL ) ) ; catalogHtml = SDCard . loadTextCache ( FutabaCrypt . createDigest ( catalogURL ) ) ; } else { FLog . d ( "<STR_LIT>" + FutabaCrypt . createDigest ( catalogURL ) + "<STR_LIT>" ) ; cache_ok = false ; } FLog . d ( "<STR_LIT:message>" , e ) ; } if ( ! network_ok ) { if ( cache_ok ) { toast_text = "<STR_LIT>" ; } else { toast_text = "<STR_LIT>" ; } } if ( network_ok || cache_ok ) { FLog . d ( "<STR_LIT>" + network_ok + "<STR_LIT>" + cache_ok + "<STR_LIT>" + catalogHtml . length ( ) ) ; if ( catalogHtml . length ( ) > <NUM_LIT> ) { parser . parse ( catalogHtml ) ; fthreads = parser . getThreads ( ) ; } else { toast_text = "<STR_LIT>" ; } } for ( int i = <NUM_LIT:0> ; i < fthreads . size ( ) ; ++ i ) { fthreads . get ( i ) . BBSName = BBSName ; } man . Load ( ) ; title_text = BBSName + "<STR_LIT>" + getString ( R . string . app_name ) ; } else { man . Load ( ) ; fthreads = man . getThreadsArray ( ) ; title_text = "<STR_LIT>" + getString ( R . string . app_name ) ; } focusWords = FocusedSettings . get ( adapter . getContext ( ) ) ; adapter . items . clear ( ) ; if ( ! mode . equals ( "<STR_LIT>" ) && focusWords . size ( ) > <NUM_LIT:0> ) { adapter . items . add ( FutabaThreadContent . createMenu1 ( ) ) ; Iterator < FutabaThreadContent > iterator = fthreads . iterator ( ) ; while ( iterator . hasNext ( ) ) { FutabaThreadContent athread = iterator . next ( ) ; if ( StringUtil . focusWordMatched ( athread . text , focusWords ) ) { adapter . items . add ( athread ) ; } } adapter . items . add ( FutabaThreadContent . createMenu2 ( ) ) ; iterator = fthreads . iterator ( ) ; while ( iterator . hasNext ( ) ) { FutabaThreadContent athread = iterator . next ( ) ; if ( ! StringUtil . focusWordMatched ( athread . text , focusWords ) ) { adapter . items . add ( athread ) ; } } } else { Iterator < FutabaThreadContent > iterator = fthreads . iterator ( ) ; while ( iterator . hasNext ( ) ) { FutabaThreadContent athread = iterator . next ( ) ; adapter . items . add ( athread ) ; } } final String title_text_f = title_text ; final String toast_text_f = toast_text ; handler2 . post ( new Runnable ( ) { public void run ( ) { if ( ! toast_text_f . equals ( "<STR_LIT>" ) ) { Toast . makeText ( adapter . getContext ( ) , toast_text_f , Toast . LENGTH_SHORT ) . show ( ) ; } setTitle ( title_text_f ) ; waitDialog . dismiss ( ) ; adapter . notifyDataSetChanged ( ) ; listView . invalidateViews ( ) ; } } ) ; onCreateEnd = true ; } catch ( Exception e ) { FLog . i ( "<STR_LIT:message>" , e ) ; } } } public void onClickReloadBtn ( View v ) { FLog . d ( "<STR_LIT>" ) ; ListView listView = ( ListView ) findViewById ( id . cataloglistview ) ; position = listView . getFirstVisiblePosition ( ) ; setWait ( ) ; } public void onClickHistoryBtn ( View v ) { Intent intent = new Intent ( ) ; intent . putExtra ( "<STR_LIT>" , baseUrl ) ; intent . putExtra ( "<STR_LIT>" , BBSName ) ; intent . putExtra ( "<STR_LIT>" , "<STR_LIT>" ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; } private int delete_option = <NUM_LIT:0> ; final int DELETE_CHECKED = <NUM_LIT:0> ; final int DELETE_NONCHECKED = <NUM_LIT:1> ; final int DELETE_ALL = <NUM_LIT:2> ; public void onClickDeleteBtn ( View v ) { if ( adapter . items . size ( ) != fthreads . size ( ) ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; return ; } delete_option = <NUM_LIT:0> ; final CharSequence [ ] items = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; AlertDialog . Builder dlg ; dlg = new AlertDialog . Builder ( Catalog . this ) ; dlg . setTitle ( "<STR_LIT>" ) ; dlg . setCancelable ( true ) ; dlg . setSingleChoiceItems ( items , <NUM_LIT:0> , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int item ) { Catalog . this . delete_option = item ; } } ) ; dlg . setPositiveButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { Catalog . this . deleteThreads ( ) ; } } ) ; dlg . setNegativeButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { } } ) ; dlg . show ( ) ; } public void deleteThreads ( ) { try { ListView listView = ( ListView ) findViewById ( id . cataloglistview ) ; if ( delete_option == DELETE_ALL ) { adapter . items . clear ( ) ; } else { if ( delete_option == DELETE_CHECKED ) { for ( int i = adapter . items . size ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; -- i ) { if ( adapter . items . get ( i ) . isChecked ) { adapter . items . remove ( i ) ; } else { adapter . items . get ( i ) . isChecked = false ; } } } else { for ( int i = adapter . items . size ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; -- i ) { if ( ! adapter . items . get ( i ) . isChecked ) { adapter . items . remove ( i ) ; } else { adapter . items . get ( i ) . isChecked = false ; } } } } HistoryManager man = new HistoryManager ( ) ; man . set ( adapter . items ) ; man . Save ( ) ; fthreads = ( ArrayList < FutabaThreadContent > ) adapter . items . clone ( ) ; adapter . notifyDataSetChanged ( ) ; listView . invalidateViews ( ) ; } catch ( Exception e ) { FLog . i ( "<STR_LIT:message>" , e ) ; } } public void onClick ( View v ) { FLog . d ( "<STR_LIT>" ) ; } @ Override public void onDestroy ( ) { FLog . d ( "<STR_LIT>" ) ; System . gc ( ) ; super . onDestroy ( ) ; } @ Override public boolean onCreateOptionsMenu ( Menu menu ) { super . onCreateOptionsMenu ( menu ) ; MenuInflater inflater = getMenuInflater ( ) ; inflater . inflate ( R . menu . menu_catalog , menu ) ; return true ; } public void onClickPostBtn ( View v ) { Intent intent = new Intent ( ) ; intent . putExtra ( "<STR_LIT>" , baseUrl ) ; intent . putExtra ( "<STR_LIT>" , <NUM_LIT:0> ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; } public void onClickSortTypeBtn ( View v ) { final String [ ] strs = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; AlertDialog . Builder dlg ; final Catalog catalog = this ; dlg = new AlertDialog . Builder ( this ) ; dlg . setTitle ( "<STR_LIT>" ) ; dlg . setCancelable ( true ) ; dlg . setSingleChoiceItems ( strs , sortType , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int item ) { sortType = item ; } } ) ; dlg . setPositiveButton ( "<STR_LIT:OK>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { FLog . d ( "<STR_LIT>" + sortType ) ; if ( sortType >= <NUM_LIT:0> && sortType < strs . length ) { StateMan . setSortParam ( catalog , sortType ) ; catalog . onClickReloadBtn ( null ) ; } } } ) ; dlg . setNegativeButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { } } ) ; dlg . show ( ) ; } @ Override public boolean onOptionsItemSelected ( MenuItem item ) { Intent intent ; switch ( item . getItemId ( ) ) { case R . id . post : onClickPostBtn ( null ) ; return true ; case R . id . share : intent = new Intent ( Intent . ACTION_SEND ) ; intent . setType ( "<STR_LIT:text/plain>" ) ; intent . putExtra ( Intent . EXTRA_TEXT , baseUrl ) ; try { startActivityForResult ( intent , <NUM_LIT:0> ) ; } catch ( android . content . ActivityNotFoundException ex ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } return true ; case R . id . search : LinearLayout searchBar = ( LinearLayout ) findViewById ( id . search_bar ) ; if ( searchBar . getVisibility ( ) == View . GONE ) { searchBar . setVisibility ( View . VISIBLE ) ; } else { searchBar . setVisibility ( View . GONE ) ; } return true ; case R . id . settings : intent = new Intent ( ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; return true ; case R . id . about : Uri uri = Uri . parse ( getString ( R . string . helpurl ) ) ; intent = new Intent ( Intent . ACTION_VIEW , uri ) ; intent . setClassName ( "<STR_LIT>" , "<STR_LIT>" ) ; try { startActivity ( intent ) ; } catch ( android . content . ActivityNotFoundException ex ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } return true ; case R . id . focusword : intent = new Intent ( ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; return true ; } return false ; } public void onClickSearchButton ( View v ) { FLog . d ( "<STR_LIT>" + fthreads . size ( ) ) ; if ( true ) { EditText searchEdit = ( EditText ) findViewById ( id . searchinput ) ; String searchText = searchEdit . getText ( ) . toString ( ) ; String [ ] query = StringUtil . queryNormalize ( searchText ) ; adapter . items . clear ( ) ; try { ArrayList < String > focusWords = FocusedSettings . get ( this ) ; adapter . items . clear ( ) ; if ( ! mode . equals ( "<STR_LIT>" ) && focusWords . size ( ) > <NUM_LIT:0> ) { adapter . items . add ( FutabaThreadContent . createMenu1 ( ) ) ; Iterator < FutabaThreadContent > iterator = fthreads . iterator ( ) ; while ( iterator . hasNext ( ) ) { FutabaThreadContent athread = iterator . next ( ) ; if ( StringUtil . isQueryMatch ( athread . text , query ) && StringUtil . focusWordMatched ( athread . text , focusWords ) ) { adapter . items . add ( athread ) ; } } adapter . items . add ( FutabaThreadContent . createMenu2 ( ) ) ; iterator = fthreads . iterator ( ) ; while ( iterator . hasNext ( ) ) { FutabaThreadContent athread = iterator . next ( ) ; if ( StringUtil . isQueryMatch ( athread . text , query ) && ! StringUtil . focusWordMatched ( athread . text , focusWords ) ) { adapter . items . add ( athread ) ; } } } else { Iterator < FutabaThreadContent > iterator = fthreads . iterator ( ) ; while ( iterator . hasNext ( ) ) { FutabaThreadContent athread = iterator . next ( ) ; if ( StringUtil . isQueryMatch ( athread . text , query ) ) { adapter . items . add ( athread ) ; } } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } int itemnum = adapter . items . size ( ) ; if ( ! mode . equals ( "<STR_LIT>" ) && focusWords . size ( ) > <NUM_LIT:0> ) { itemnum -= <NUM_LIT:2> ; } adapter . notifyDataSetChanged ( ) ; LinearLayout searchBar = ( LinearLayout ) findViewById ( id . search_bar ) ; String toastText = "<STR_LIT>" + fthreads . size ( ) + "<STR_LIT>" + itemnum + "<STR_LIT>" ; if ( fthreads . size ( ) == itemnum ) { toastText = "<STR_LIT>" ; } else if ( itemnum == <NUM_LIT:0> ) { toastText = "<STR_LIT>" ; } Toast . makeText ( this , toastText , Toast . LENGTH_SHORT ) . show ( ) ; InputMethodManager imm = ( InputMethodManager ) getSystemService ( INPUT_METHOD_SERVICE ) ; imm . hideSoftInputFromWindow ( v . getWindowToken ( ) , <NUM_LIT:0> ) ; } } public void onClickSearchHideButton ( View v ) { LinearLayout searchBar = ( LinearLayout ) findViewById ( id . search_bar ) ; searchBar . setVisibility ( View . GONE ) ; InputMethodManager imm = ( InputMethodManager ) getSystemService ( INPUT_METHOD_SERVICE ) ; imm . hideSoftInputFromWindow ( v . getWindowToken ( ) , <NUM_LIT:0> ) ; } public boolean onSearchRequested ( ) { LinearLayout searchBar = ( LinearLayout ) findViewById ( id . search_bar ) ; if ( searchBar . getVisibility ( ) == View . GONE ) { searchBar . setVisibility ( View . VISIBLE ) ; } else { searchBar . setVisibility ( View . GONE ) ; InputMethodManager imm = ( InputMethodManager ) getSystemService ( INPUT_METHOD_SERVICE ) ; imm . hideSoftInputFromWindow ( getCurrentFocus ( ) . getWindowToken ( ) , <NUM_LIT:0> ) ; } return false ; } public boolean dispatchKeyEvent ( KeyEvent event ) { FLog . d ( "<STR_LIT>" + event . getAction ( ) ) ; int action = event . getAction ( ) ; int keyCode = event . getKeyCode ( ) ; if ( keyCode == KeyEvent . KEYCODE_VOLUME_DOWN ) { if ( action == KeyEvent . ACTION_UP ) { FLog . d ( "<STR_LIT>" + listView . getFirstVisiblePosition ( ) ) ; int topPositionY = listView . getChildAt ( <NUM_LIT:0> ) . getTop ( ) ; WindowManager wm = ( WindowManager ) getSystemService ( Context . WINDOW_SERVICE ) ; Display disp = wm . getDefaultDisplay ( ) ; int height = disp . getHeight ( ) ; listView . setSelectionFromTop ( listView . getFirstVisiblePosition ( ) , topPositionY - ( height - <NUM_LIT> ) ) ; } return true ; } else if ( keyCode == KeyEvent . KEYCODE_VOLUME_UP ) { if ( action == KeyEvent . ACTION_UP ) { int topPositionY = listView . getChildAt ( <NUM_LIT:0> ) . getTop ( ) ; WindowManager wm = ( WindowManager ) getSystemService ( Context . WINDOW_SERVICE ) ; Display disp = wm . getDefaultDisplay ( ) ; int height = disp . getHeight ( ) ; listView . setSelectionFromTop ( listView . getFirstVisiblePosition ( ) , topPositionY + ( height - <NUM_LIT> ) ) ; } return true ; } return super . dispatchKeyEvent ( event ) ; } @ Override public void onStop ( ) { FLog . d ( "<STR_LIT>" ) ; super . onStop ( ) ; System . gc ( ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . Serializable ; import android . util . Log ; public class FutabaBBSContent implements Serializable { private static final long serialVersionUID = <NUM_LIT:1L> ; public String url ; public String name ; public boolean faved ; public FutabaBBSContent ( ) { } public FutabaBBSContent ( String s ) { String [ ] elems = s . split ( "<STR_LIT>" ) ; url = elems [ <NUM_LIT:0> ] ; name = elems [ <NUM_LIT:1> ] ; faved = false ; } public String toString ( ) { return url + "<STR_LIT>" + name ; } public boolean equals ( Object obj ) { FutabaBBSContent rhs = ( FutabaBBSContent ) obj ; return ( url . equals ( rhs . url ) ) && ( name . equals ( rhs . name ) ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . content . Context ; import android . content . SharedPreferences ; import android . content . SharedPreferences . Editor ; import android . os . Bundle ; import android . preference . PreferenceActivity ; import android . preference . PreferenceManager ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Iterator ; import java . io . IOException ; import android . util . Log ; public class FavoriteSettings { private static final String OPT_FAVORITES = "<STR_LIT>" ; public static ArrayList < FutabaBBSContent > getFavorites ( Context context ) throws IOException { ArrayList < FutabaBBSContent > bbss = new ArrayList < FutabaBBSContent > ( ) ; try { if ( SDCard . existSeriarized ( OPT_FAVORITES ) ) { bbss = ( ArrayList < FutabaBBSContent > ) SDCard . getSerialized ( OPT_FAVORITES ) . readObject ( ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return bbss ; } public static void setFavorites ( Context context , ArrayList < FutabaBBSContent > futabaBBSs ) throws IOException { SDCard . setSerialized ( OPT_FAVORITES , futabaBBSs ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . util . Log ; public class FLog { static final boolean use_log = false ; static public int d ( String msg ) { if ( use_log ) { return Log . d ( "<STR_LIT>" , msg ) ; } else { return - <NUM_LIT:1> ; } } static public int d ( String msg , Throwable tr ) { if ( use_log ) { return Log . d ( "<STR_LIT>" , msg , tr ) ; } else { return - <NUM_LIT:1> ; } } static public int e ( String msg ) { if ( use_log ) { return Log . e ( "<STR_LIT>" , msg ) ; } else { return - <NUM_LIT:1> ; } } static public int e ( String msg , Throwable tr ) { if ( use_log ) { return Log . e ( "<STR_LIT>" , msg , tr ) ; } else { return - <NUM_LIT:1> ; } } static public int i ( String msg ) { if ( use_log ) { return Log . i ( "<STR_LIT>" , msg ) ; } else { return - <NUM_LIT:1> ; } } static public int i ( String msg , Throwable tr ) { if ( use_log ) { return Log . i ( "<STR_LIT>" , msg , tr ) ; } else { return - <NUM_LIT:1> ; } } static public int w ( String msg ) { if ( use_log ) { return Log . w ( "<STR_LIT>" , msg ) ; } else { return - <NUM_LIT:1> ; } } static public int w ( String msg , Throwable tr ) { if ( use_log ) { return Log . w ( "<STR_LIT>" , msg , tr ) ; } else { return - <NUM_LIT:1> ; } } static public int v ( String msg ) { if ( use_log ) { return Log . v ( "<STR_LIT>" , msg ) ; } else { return - <NUM_LIT:1> ; } } static public int v ( String msg , Throwable tr ) { if ( use_log ) { return Log . v ( "<STR_LIT>" , msg , tr ) ; } else { return - <NUM_LIT:1> ; } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . util . ArrayList ; class CircleList { private static ArrayList < String > list = new ArrayList < String > ( ) ; private static int pointer = - <NUM_LIT:1> ; public static void add ( String str ) { list . add ( str ) ; if ( pointer == - <NUM_LIT:1> ) { pointer = <NUM_LIT:0> ; } } public static String get ( ) { return list . get ( pointer ) ; } public static void set ( int i ) { pointer = i ; } public static void move ( int i ) { pointer += i ; pointer = ( pointer + list . size ( ) ) % list . size ( ) ; } public static void moveToZero ( ) { pointer = <NUM_LIT:0> ; } public static void moveToLast ( ) { pointer = list . size ( ) - <NUM_LIT:1> ; } public static int pos ( ) { return pointer ; } public static int size ( ) { return list . size ( ) ; } public static void clear ( ) { list = new ArrayList < String > ( ) ; pointer = - <NUM_LIT:1> ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . IOException ; import java . io . StringReader ; import java . io . ByteArrayOutputStream ; import java . util . List ; import java . util . ArrayList ; import android . util . Log ; import android . webkit . CookieManager ; import android . webkit . CookieSyncManager ; import android . content . Context ; import java . util . regex . Pattern ; import java . util . regex . Matcher ; import org . apache . http . impl . client . DefaultHttpClient ; import org . apache . http . HttpStatus ; import org . apache . http . client . methods . HttpGet ; import org . apache . http . client . methods . HttpPost ; import org . apache . http . client . params . ClientPNames ; import org . apache . http . client . params . CookiePolicy ; import org . apache . http . NameValuePair ; import org . apache . http . HttpResponse ; import org . apache . http . message . BasicNameValuePair ; import org . apache . http . client . entity . UrlEncodedFormEntity ; public class CatalogParser { private ArrayList < FutabaThreadContent > fthreads ; public CatalogParser ( ) { fthreads = new ArrayList < FutabaThreadContent > ( ) ; } public void parse ( String catalogHtml ) { try { Pattern honbunPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern resPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern textPattern = Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" , Pattern . DOTALL ) ; Pattern imgPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern threadNumPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern tagPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Matcher mc = honbunPattern . matcher ( catalogHtml ) ; mc . find ( ) ; mc . find ( ) ; String honbun = mc . group ( <NUM_LIT:0> ) ; Matcher mcRes = resPattern . matcher ( honbun ) ; while ( mcRes . find ( ) ) { Matcher mcText = textPattern . matcher ( mcRes . group ( <NUM_LIT:1> ) ) ; mcText . find ( ) ; FutabaThreadContent thread = new FutabaThreadContent ( ) ; String text = mcText . group ( <NUM_LIT:1> ) ; String resNum = mcText . group ( <NUM_LIT:2> ) ; thread . text = text ; thread . resNum = resNum ; Matcher mcThreadNum = threadNumPattern . matcher ( mcRes . group ( <NUM_LIT:1> ) ) ; mcThreadNum . find ( ) ; String threadNum = mcThreadNum . group ( <NUM_LIT:1> ) ; thread . threadNum = Integer . parseInt ( threadNum ) ; Matcher mcImg = imgPattern . matcher ( mcRes . group ( <NUM_LIT:1> ) ) ; if ( mcImg . find ( ) ) { thread . imgURL = mcImg . group ( <NUM_LIT:1> ) ; } fthreads . add ( thread ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT>" , e ) ; throw new RuntimeException ( e ) ; } } public ArrayList < FutabaThreadContent > getThreads ( ) { return fthreads ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . IOException ; import java . io . StringReader ; import java . util . ArrayList ; import java . net . URL ; import android . util . Log ; import android . util . Xml ; import org . xmlpull . v1 . XmlPullParser ; import org . xmlpull . v1 . XmlPullParserException ; import org . xmlpull . v1 . XmlPullParserFactory ; import java . util . regex . Pattern ; import java . util . regex . Matcher ; public class FutabaThreadParser { private static final String FORMTAG = "<STR_LIT>" ; private static final String BLOCKQUOTETAG = "<STR_LIT>" ; private static final String TABLETAG = "<STR_LIT>" ; private static final String IMGTAG = "<STR_LIT>" ; private static final String SRCTAG = "<STR_LIT:src>" ; private String urlStr ; private String title ; private String titleImgURL ; private ArrayList < FutabaStatus > statuses ; private static Pattern tagPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; public FutabaThreadParser ( ) { title = "<STR_LIT>" ; statuses = new ArrayList < FutabaStatus > ( ) ; } private Pattern mailToPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; public void parse ( String allData , boolean anonymous , boolean showdeleted ) { try { Pattern honbunPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern resPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern textAttrPattern = Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , Pattern . DOTALL ) ; Pattern imgTextAttrPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern textPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern imgPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern thumbPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Pattern endTimePattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Matcher mc = honbunPattern . matcher ( allData ) ; mc . find ( ) ; mc . find ( ) ; String honbun = mc . group ( <NUM_LIT:0> ) ; FutabaStatus statusTop = new FutabaStatus ( ) ; Matcher mcImg = thumbPattern . matcher ( honbun ) ; if ( mcImg . find ( ) ) { statusTop . imgURL = mcImg . group ( <NUM_LIT:1> ) ; statusTop . width = Integer . parseInt ( mcImg . group ( <NUM_LIT:2> ) ) ; statusTop . height = Integer . parseInt ( mcImg . group ( <NUM_LIT:3> ) ) ; } Matcher mcBigImg = imgPattern . matcher ( honbun ) ; if ( mcBigImg . find ( ) ) { statusTop . bigImgURL = mcBigImg . group ( <NUM_LIT:1> ) ; } Matcher mcText = textPattern . matcher ( honbun ) ; mcText . find ( ) ; if ( ! anonymous ) { Matcher mcTextAttr = textAttrPattern . matcher ( honbun ) ; if ( mcTextAttr . find ( ) ) { statusTop . title = mcTextAttr . group ( <NUM_LIT:1> ) ; statusTop . name = normalize ( mcTextAttr . group ( <NUM_LIT:2> ) ) ; statusTop . datestr = mcTextAttr . group ( <NUM_LIT:3> ) ; statusTop . id = Integer . parseInt ( mcTextAttr . group ( <NUM_LIT:4> ) ) ; } } else { Matcher mcTextAttr = imgTextAttrPattern . matcher ( honbun ) ; if ( mcTextAttr . find ( ) ) { statusTop . datestr = normalize ( mcTextAttr . group ( <NUM_LIT:1> ) ) ; statusTop . mailTo = extractMailTo ( mcTextAttr . group ( <NUM_LIT:1> ) ) ; statusTop . id = Integer . parseInt ( mcTextAttr . group ( <NUM_LIT:2> ) ) ; } } String text = mcText . group ( <NUM_LIT:1> ) ; statusTop . text = text ; Matcher mcEndTime = endTimePattern . matcher ( honbun ) ; if ( mcEndTime . find ( ) ) { statusTop . endTime = mcEndTime . group ( <NUM_LIT:1> ) ; } else { FLog . d ( "<STR_LIT>" ) ; } statuses . add ( statusTop ) ; Matcher mcRes = resPattern . matcher ( honbun ) ; while ( mcRes . find ( ) ) { FutabaStatus status = new FutabaStatus ( ) ; mcText = textPattern . matcher ( mcRes . group ( <NUM_LIT:2> ) ) ; mcText . find ( ) ; if ( ! anonymous ) { Matcher mcTextAttr = textAttrPattern . matcher ( mcRes . group ( <NUM_LIT:2> ) ) ; if ( mcTextAttr . find ( ) ) { status . title = mcTextAttr . group ( <NUM_LIT:1> ) ; status . name = normalize ( mcTextAttr . group ( <NUM_LIT:2> ) ) ; status . mailTo = extractMailTo ( mcTextAttr . group ( <NUM_LIT:2> ) ) ; status . datestr = mcTextAttr . group ( <NUM_LIT:3> ) ; status . id = Integer . parseInt ( mcTextAttr . group ( <NUM_LIT:4> ) ) ; } } else { Matcher mcTextAttr = imgTextAttrPattern . matcher ( mcRes . group ( <NUM_LIT:2> ) ) ; if ( mcTextAttr . find ( ) ) { status . datestr = normalize ( mcTextAttr . group ( <NUM_LIT:1> ) ) ; status . mailTo = extractMailTo ( mcTextAttr . group ( <NUM_LIT:1> ) ) ; if ( ! status . mailTo . equals ( "<STR_LIT>" ) ) { FLog . d ( "<STR_LIT>" + status . mailTo ) ; } status . id = Integer . parseInt ( mcTextAttr . group ( <NUM_LIT:2> ) ) ; } } text = mcText . group ( <NUM_LIT:1> ) ; status . text = text ; mcImg = thumbPattern . matcher ( mcRes . group ( <NUM_LIT:2> ) ) ; if ( mcImg . find ( ) ) { status . imgURL = mcImg . group ( <NUM_LIT:1> ) ; status . width = Integer . parseInt ( mcImg . group ( <NUM_LIT:2> ) ) ; status . height = Integer . parseInt ( mcImg . group ( <NUM_LIT:3> ) ) ; } mcBigImg = imgPattern . matcher ( mcRes . group ( <NUM_LIT:2> ) ) ; if ( mcBigImg . find ( ) ) { status . bigImgURL = mcBigImg . group ( <NUM_LIT:1> ) ; } status . deleted = mcRes . group ( <NUM_LIT:1> ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ; statuses . add ( status ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT>" , e ) ; } } private String normalize ( String text ) { text = text . replaceAll ( "<STR_LIT>" , "<STR_LIT:n>" ) ; text = tagPattern . matcher ( text ) . replaceAll ( "<STR_LIT>" ) ; text = text . replaceAll ( "<STR_LIT>" , "<STR_LIT:>>" ) ; return text ; } private String extractMailTo ( String name ) { Matcher mailTo = mailToPattern . matcher ( name ) ; if ( mailTo . find ( ) ) { return mailTo . group ( <NUM_LIT:1> ) ; } return "<STR_LIT>" ; } public void addStatus ( XmlPullParser parser ) { String text = "<STR_LIT>" ; String imgURL = "<STR_LIT>" ; try { int eventType = parser . next ( ) ; while ( eventType != XmlPullParser . END_DOCUMENT ) { String name = null ; switch ( eventType ) { case XmlPullParser . START_TAG : name = parser . getName ( ) ; if ( name . equalsIgnoreCase ( BLOCKQUOTETAG ) ) { text = parser . getText ( ) ; } else if ( name . equalsIgnoreCase ( IMGTAG ) ) { imgURL = getAttributeByName ( parser , SRCTAG ) ; } break ; case XmlPullParser . END_TAG : name = parser . getName ( ) ; if ( name . equalsIgnoreCase ( TABLETAG ) ) { FutabaStatus status = new FutabaStatus ( ) ; status . text = text ; status . imgURL = imgURL ; statuses . add ( status ) ; return ; } break ; } eventType = parser . next ( ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public String getAttributeByName ( XmlPullParser parser , String nameArg ) { for ( int i = <NUM_LIT:0> ; i < parser . getAttributeCount ( ) ; ++ i ) { String name = parser . getAttributeName ( i ) ; if ( nameArg . equalsIgnoreCase ( name ) ) { return parser . getAttributeValue ( i ) ; } } return "<STR_LIT>" ; } public ArrayList < FutabaStatus > getStatuses ( ) { return statuses ; } public String getTitle ( int num ) { if ( statuses . size ( ) > <NUM_LIT:0> ) { String text = statuses . get ( <NUM_LIT:0> ) . text ; text = tagPattern . matcher ( text ) . replaceAll ( "<STR_LIT>" ) ; if ( text . length ( ) > num ) { return text . substring ( <NUM_LIT:0> , Math . min ( text . length ( ) , num ) ) + "<STR_LIT:...>" ; } else { return text . substring ( <NUM_LIT:0> , Math . min ( text . length ( ) , num ) ) ; } } return "<STR_LIT>" ; } public static String removeTag ( String str ) { return tagPattern . matcher ( str ) . replaceAll ( "<STR_LIT>" ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . File ; import java . util . ArrayList ; import android . app . Activity ; import android . app . ProgressDialog ; import android . content . Context ; import android . content . Intent ; import android . content . SharedPreferences ; import android . content . res . Configuration ; import android . graphics . Color ; import android . net . Uri ; import android . os . Bundle ; import android . os . Handler ; import android . os . Message ; import android . preference . PreferenceManager ; import android . view . Display ; import android . view . KeyEvent ; import android . view . Menu ; import android . view . MenuInflater ; import android . view . MenuItem ; import android . view . View ; import android . view . Window ; import android . view . WindowManager ; import android . view . View . OnClickListener ; import android . view . ViewGroup ; import android . widget . ArrayAdapter ; import android . widget . Button ; import android . widget . GridView ; import android . widget . LinearLayout ; import android . widget . ListView ; import android . widget . TextView ; import android . widget . Toast ; import cx . ath . dekosuke . ftbt . R . id ; public class ThumbGrid extends Activity implements Runnable { private ProgressDialog waitDialog ; private Thread thread ; public ArrayList < String > thumbURLs = new ArrayList < String > ( ) ; public ArrayList < String > imgURLs = new ArrayList < String > ( ) ; public int startPos = <NUM_LIT:0> ; private int width ; private int height ; public String baseUrl = "<STR_LIT>" ; private String catalogURL ; private String BBSName = "<STR_LIT>" ; private GridView grid ; @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; if ( getResources ( ) . getBoolean ( R . bool . avoidsleep ) ) { Window window = getWindow ( ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ; } try { setTitle ( "<STR_LIT>" + getString ( R . string . app_name ) ) ; Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; System . gc ( ) ; FLog . d ( "<STR_LIT>" ) ; Intent intent = getIntent ( ) ; thumbURLs = ( ArrayList < String > ) intent . getSerializableExtra ( "<STR_LIT>" ) ; imgURLs = ( ArrayList < String > ) intent . getSerializableExtra ( "<STR_LIT>" ) ; startPos = ( Integer ) intent . getSerializableExtra ( "<STR_LIT>" ) ; WindowManager wm = ( WindowManager ) getSystemService ( Context . WINDOW_SERVICE ) ; Display display = wm . getDefaultDisplay ( ) ; width = display . getWidth ( ) ; height = display . getHeight ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } setWait ( ) ; } public void setWait ( ) { waitDialog = new ProgressDialog ( this ) ; waitDialog . setMessage ( this . getString ( R . string . loading ) ) ; waitDialog . setProgressStyle ( ProgressDialog . STYLE_SPINNER ) ; waitDialog . show ( ) ; thread = new Thread ( this ) ; thread . start ( ) ; } public void run ( ) { try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( InterruptedException e ) { } handler . sendEmptyMessage ( <NUM_LIT:0> ) ; } private Handler handler = new Handler ( ) { public void handleMessage ( Message msg ) { try { loading ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ; final Handler handler2 = new Handler ( ) ; private final int FP = ViewGroup . LayoutParams . FILL_PARENT ; private final int WC = ViewGroup . LayoutParams . WRAP_CONTENT ; private void loading ( ) { setContentView ( R . layout . thumbgrid ) ; TextView imagenum = ( TextView ) findViewById ( id . imagenum ) ; imagenum . setText ( "<STR_LIT>" + thumbURLs . size ( ) + "<STR_LIT>" ) ; grid = ( GridView ) findViewById ( id . gridview ) ; try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( this ) ; boolean fastScrollEnabled = preferences . getBoolean ( "<STR_LIT>" , false ) ; grid . setFastScrollEnabled ( fastScrollEnabled ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } if ( width < height ) { grid . setNumColumns ( <NUM_LIT:3> ) ; } else { grid . setNumColumns ( <NUM_LIT:5> ) ; } ThumbGridAdapter adapter = new ThumbGridAdapter ( this , R . layout . thumbgridelement , thumbURLs ) ; grid . setAdapter ( adapter ) ; grid . setSmoothScrollbarEnabled ( true ) ; grid . setVerticalScrollBarEnabled ( true ) ; grid . setSelection ( startPos ) ; grid . setDrawingCacheEnabled ( true ) ; waitDialog . dismiss ( ) ; } public void onConfigurationChanged ( Configuration newConfig ) { super . onConfigurationChanged ( newConfig ) ; WindowManager wm = ( WindowManager ) getSystemService ( Context . WINDOW_SERVICE ) ; Display display = wm . getDefaultDisplay ( ) ; width = display . getWidth ( ) ; height = display . getHeight ( ) ; if ( width < height ) { grid . setNumColumns ( <NUM_LIT:3> ) ; } else { grid . setNumColumns ( <NUM_LIT:5> ) ; } System . gc ( ) ; } private LinearLayout . LayoutParams createParam ( int w , int h ) { return new LinearLayout . LayoutParams ( w , h ) ; } @ Override public boolean onCreateOptionsMenu ( Menu menu ) { super . onCreateOptionsMenu ( menu ) ; MenuInflater inflater = getMenuInflater ( ) ; inflater . inflate ( R . menu . menu_gridview , menu ) ; return true ; } @ Override public boolean onOptionsItemSelected ( MenuItem item ) { Intent intent ; switch ( item . getItemId ( ) ) { case R . id . post : return true ; case R . id . settings : intent = new Intent ( ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; return true ; case R . id . about : Uri uri = Uri . parse ( getString ( R . string . helpurl ) ) ; intent = new Intent ( Intent . ACTION_VIEW , uri ) ; intent . setClassName ( "<STR_LIT>" , "<STR_LIT>" ) ; try { startActivity ( intent ) ; } catch ( android . content . ActivityNotFoundException ex ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } return true ; } return false ; } @ Override public void onPause ( ) { FLog . d ( "<STR_LIT>" ) ; super . onPause ( ) ; System . gc ( ) ; } @ Override public void onStop ( ) { FLog . d ( "<STR_LIT>" ) ; super . onStop ( ) ; System . gc ( ) ; } @ Override public void onDestroy ( ) { FLog . d ( "<STR_LIT>" ) ; super . onDestroy ( ) ; System . gc ( ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . IOException ; import java . io . StringReader ; import java . util . ArrayList ; import java . net . URL ; import android . content . SharedPreferences ; import android . preference . PreferenceManager ; import android . util . Log ; import android . widget . Toast ; import java . util . regex . Pattern ; import java . util . regex . Matcher ; public class FutabaBBSMenuParser { private ArrayList < FutabaBBSContent > BBSs ; private String urlStr ; public boolean network_ok ; public boolean cache_ok ; public boolean display_censored = false ; public FutabaBBSMenuParser ( String urlStr ) { this . urlStr = urlStr ; BBSs = new ArrayList < FutabaBBSContent > ( ) ; network_ok = true ; cache_ok = true ; } public void setDisplayCensored ( boolean bool ) { display_censored = bool ; } public void parse ( ) { try { Pattern BBSPattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; String allData = "<STR_LIT>" ; try { SDCard . saveFromURL ( FutabaCrypt . createDigest ( urlStr ) , new URL ( urlStr ) , true ) ; allData = SDCard . loadTextCache ( FutabaCrypt . createDigest ( urlStr ) ) ; network_ok = true ; } catch ( Exception e ) { FLog . d ( "<STR_LIT>" ) ; network_ok = false ; if ( SDCard . cacheExist ( FutabaCrypt . createDigest ( urlStr ) ) ) { FLog . d ( "<STR_LIT>" ) ; allData = SDCard . loadTextCache ( FutabaCrypt . createDigest ( urlStr ) ) ; } else { cache_ok = false ; } } Matcher mcBBS = BBSPattern . matcher ( allData ) ; while ( mcBBS . find ( ) ) { FutabaBBSContent bbs = new FutabaBBSContent ( ) ; bbs . url = mcBBS . group ( <NUM_LIT:1> ) ; bbs . name = mcBBS . group ( <NUM_LIT:2> ) ; if ( bbs . name . equals ( "<STR_LIT>" ) ) { if ( bbs . url . contains ( "<STR_LIT>" ) ) { bbs . name = "<STR_LIT>" ; FutabaBBSContent img_bbs = new FutabaBBSContent ( ) ; img_bbs . name = "<STR_LIT>" ; img_bbs . url = "<STR_LIT>" ; BBSs . add ( img_bbs ) ; } else if ( bbs . url . contains ( "<STR_LIT>" ) ) { bbs . name = "<STR_LIT>" ; FutabaBBSContent dat_bbs = new FutabaBBSContent ( ) ; dat_bbs . name = "<STR_LIT>" ; dat_bbs . url = "<STR_LIT>" ; BBSs . add ( dat_bbs ) ; } else if ( bbs . url . contains ( "<STR_LIT>" ) ) { bbs . name = "<STR_LIT>" ; } } if ( bbs . name . equals ( "<STR_LIT>" ) && display_censored ) { FutabaBBSContent other_bbs = new FutabaBBSContent ( ) ; other_bbs . name = "<STR_LIT>" ; other_bbs . url = "<STR_LIT>" ; BBSs . add ( other_bbs ) ; other_bbs = new FutabaBBSContent ( ) ; other_bbs . name = "<STR_LIT>" ; other_bbs . url = "<STR_LIT>" ; BBSs . add ( other_bbs ) ; other_bbs = new FutabaBBSContent ( ) ; other_bbs . name = "<STR_LIT>" ; other_bbs . url = "<STR_LIT>" ; BBSs . add ( other_bbs ) ; } if ( bbs . name . equals ( "<STR_LIT>" ) ) { FutabaBBSContent dat_bbs = new FutabaBBSContent ( ) ; dat_bbs . name = "<STR_LIT>" ; dat_bbs . url = "<STR_LIT>" ; BBSs . add ( dat_bbs ) ; } BBSs . add ( bbs ) ; } FutabaBBSContent rayout_bbs = new FutabaBBSContent ( ) ; rayout_bbs . name = "<STR_LIT>" ; rayout_bbs . url = "<STR_LIT>" ; BBSs . add ( rayout_bbs ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT>" , e ) ; } } public ArrayList < FutabaBBSContent > getBBSs ( ) { return BBSs ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . app . ProgressDialog ; import android . content . Context ; import android . graphics . Bitmap ; import android . graphics . Matrix ; import android . graphics . PointF ; import android . graphics . Rect ; import android . os . AsyncTask ; import android . os . Handler ; import android . os . Message ; import android . util . AttributeSet ; import android . util . FloatMath ; import android . util . Log ; import android . view . Display ; import android . view . GestureDetector . OnGestureListener ; import android . view . GestureDetector . SimpleOnGestureListener ; import android . view . MotionEvent ; import android . view . View ; import android . view . WindowManager ; import android . view . View . OnTouchListener ; import android . widget . ImageView ; import android . widget . Toast ; import java . lang . Math ; import android . view . GestureDetector ; class ImageCatalogSingleView extends ImageView implements Runnable { private static final int NONE = <NUM_LIT:0> ; private static final int DRAG = <NUM_LIT:1> ; private static final int ZOOM = <NUM_LIT:2> ; private Matrix matrix = new Matrix ( ) ; private int mode = NONE ; private PointF middle = new PointF ( ) ; private Matrix moveMatrix = new Matrix ( ) ; private float initLength = <NUM_LIT:1> ; private MotionEvent prevEvent ; private float mx = <NUM_LIT> ; private int width = <NUM_LIT:100> ; private int height = <NUM_LIT:100> ; private Bitmap bm = null ; private float bx ; private float by ; public ProgressDialog waitDialog ; private Thread thread ; private PointF point = null ; private PointF p1 = new PointF ( ) ; private PointF p2 = new PointF ( ) ; private int point_side = <NUM_LIT:1> ; private boolean rotated = false ; private GestureDetector gestureDetector ; public ImageCatalogSingleView ( Context context ) { this ( context , null , <NUM_LIT:0> ) ; } public ImageCatalogSingleView ( Context context , AttributeSet attrs ) { this ( context , attrs , <NUM_LIT:0> ) ; } @ Override protected void onSizeChanged ( int w , int h , int oldw , int oldh ) { width = w ; height = h ; clearImage ( ) ; setImage ( ) ; } public void clearImage ( ) { try { super . setImageBitmap ( null ) ; if ( bm != null ) { int size = bm . getWidth ( ) * bm . getHeight ( ) ; bm = null ; if ( true ) { FLog . d ( "<STR_LIT>" ) ; System . gc ( ) ; } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public ImageCatalogSingleView ( Context context , AttributeSet attrs , int defStyle ) { super ( context , attrs , defStyle ) ; try { matrix = new Matrix ( ) ; matrix . setScale ( <NUM_LIT:1> , <NUM_LIT:1> ) ; bx = by = <NUM_LIT:0> ; setEnabled ( true ) ; setClickable ( true ) ; this . setScaleType ( ScaleType . MATRIX ) ; setImage ( ) ; this . gestureDetector = new GestureDetector ( context , simpleOnGestureListener ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } @ Override public boolean onTouchEvent ( MotionEvent event ) { onTouch ( event ) ; gestureDetector . onTouchEvent ( event ) ; return true ; } public boolean onTouch ( MotionEvent event ) { try { ImageCatalog activity = ( ImageCatalog ) getContext ( ) ; switch ( event . getAction ( ) ) { case MotionEvent . ACTION_DOWN : case MotionEvent . ACTION_POINTER_1_DOWN : mode = DRAG ; p1 . set ( event . getX ( ) , event . getY ( ) ) ; moveMatrix . set ( matrix ) ; break ; case MotionEvent . ACTION_UP : case MotionEvent . ACTION_POINTER_2_UP : point = null ; mode = NONE ; break ; case MotionEvent . ACTION_POINTER_2_DOWN : p2 . set ( event . getX ( ) , event . getY ( ) ) ; initLength = getLength ( event ) ; if ( true ) { FLog . d ( "<STR_LIT>" ) ; moveMatrix . set ( matrix ) ; mode = ZOOM ; } break ; case MotionEvent . ACTION_MOVE : float ex = event . getX ( ) ; float ey = event . getY ( ) ; float d1_sq = ( p1 . x - ex ) * ( p1 . x - ex ) + ( p1 . y - ey ) * ( p1 . y - ey ) ; float d2_sq = ( p2 . x - ex ) * ( p2 . x - ex ) + ( p2 . y - ey ) * ( p2 . y - ey ) ; int near_side ; if ( d1_sq < d2_sq ) { if ( point == null ) { point = new PointF ( ex , ey ) ; point_side = <NUM_LIT:1> ; } p1 = new PointF ( ex , ey ) ; near_side = <NUM_LIT:1> ; } else { if ( point == null ) { point = new PointF ( ex , ey ) ; point_side = <NUM_LIT:2> ; } p2 = new PointF ( ex , ey ) ; near_side = <NUM_LIT:2> ; } float d2 = ( ex - point . x ) * ( ex - point . x ) + ( ey - point . y ) * ( ey - point . y ) ; if ( d2 > <NUM_LIT> * <NUM_LIT> && ( point_side != near_side ) ) { break ; } if ( d2 > <NUM_LIT> * <NUM_LIT> && mode == ZOOM ) { break ; } switch ( mode ) { case DRAG : matrix . set ( moveMatrix ) ; move ( <NUM_LIT:1.0f> * ( ex - point . x ) , <NUM_LIT> * ( ey - point . y ) ) ; setImageMatrix ( matrix ) ; break ; case ZOOM : if ( mode == ZOOM ) { float currentLength = getLength ( event ) ; middle = getMiddle ( event , middle ) ; if ( true ) { matrix . set ( moveMatrix ) ; float scale = filter ( matrix , currentLength / initLength ) ; zoomImage ( ( float ) Math . pow ( scale , <NUM_LIT> ) , middle . x , middle . y ) ; setImageMatrix ( matrix ) ; } break ; } break ; } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return false ; } private void move ( float dx , float dy ) { float [ ] values = new float [ <NUM_LIT:9> ] ; matrix . getValues ( values ) ; values [ Matrix . MTRANS_X ] += dx ; values [ Matrix . MTRANS_Y ] += dy ; matrix . setValues ( values ) ; } public void rotateImage ( ) { FLog . d ( "<STR_LIT>" ) ; matrix . postRotate ( <NUM_LIT> , width / <NUM_LIT:2> , height / <NUM_LIT:2> ) ; setImageMatrix ( matrix ) ; rotated = ! rotated ; zoomImage ( <NUM_LIT:1> , width / <NUM_LIT:2> , height / <NUM_LIT:2> ) ; } public void zoomImage ( float scale , float mx , float my ) { float [ ] values = new float [ <NUM_LIT:9> ] ; matrix . getValues ( values ) ; float currentScale = <NUM_LIT> ; if ( ! rotated ) { currentScale = Math . abs ( values [ Matrix . MSCALE_X ] ) ; } else { currentScale = Math . abs ( values [ Matrix . MSKEW_X ] ) ; } float postScale = currentScale * scale ; FLog . d ( "<STR_LIT>" + currentScale + "<STR_LIT>" + scale ) ; float minScale = <NUM_LIT> ; if ( ! rotated ) { minScale = Math . min ( ( float ) width / ( float ) bm . getWidth ( ) , ( float ) height / ( float ) bm . getHeight ( ) ) ; } else { minScale = Math . min ( ( float ) height / ( float ) bm . getWidth ( ) , ( float ) width / ( float ) bm . getHeight ( ) ) ; } minScale = Math . min ( minScale , <NUM_LIT> ) ; FLog . d ( "<STR_LIT>" + minScale ) ; if ( postScale < minScale ) { scale = minScale / currentScale ; } matrix . postScale ( scale , scale , mx , my ) ; bx = bm . getWidth ( ) * postScale ; by = bm . getHeight ( ) * postScale ; setImageMatrix ( matrix ) ; } public boolean onDoubleTap ( MotionEvent e ) { FLog . d ( "<STR_LIT>" ) ; return false ; } public void zoomImageToWindow ( ) { if ( bm . getWidth ( ) < width && bm . getHeight ( ) < height ) { matrix . setScale ( <NUM_LIT> , <NUM_LIT> ) ; bx = bm . getWidth ( ) ; by = bm . getHeight ( ) ; } else { float scale = Math . min ( ( float ) width / ( float ) bm . getWidth ( ) , ( float ) height / ( float ) bm . getHeight ( ) ) ; FLog . d ( "<STR_LIT>" + scale ) ; matrix . setScale ( scale , scale ) ; bx = bm . getWidth ( ) * scale ; by = bm . getHeight ( ) * scale ; } float [ ] values = new float [ <NUM_LIT:9> ] ; matrix . getValues ( values ) ; values [ Matrix . MTRANS_X ] = ( width - bx ) / <NUM_LIT:2> ; values [ Matrix . MTRANS_Y ] = ( height - by ) / <NUM_LIT:2> ; matrix . setValues ( values ) ; } public void setImageBitmap ( Bitmap bm ) { super . setImageBitmap ( bm ) ; this . bm = bm ; rotated = false ; matrix . set ( moveMatrix ) ; zoomImageToWindow ( ) ; FLog . d ( "<STR_LIT>" + bx + "<STR_LIT>" + by ) ; setImageMatrix ( matrix ) ; } private float filter ( Matrix m , float s ) { return ( float ) Math . max ( s , <NUM_LIT> ) ; } private float getLength ( MotionEvent e ) { float xx = e . getX ( <NUM_LIT:1> ) - e . getX ( <NUM_LIT:0> ) ; float yy = e . getY ( <NUM_LIT:1> ) - e . getY ( <NUM_LIT:0> ) ; return FloatMath . sqrt ( xx * xx + yy * yy ) ; } private PointF getMiddle ( MotionEvent e , PointF p ) { float x = e . getX ( <NUM_LIT:0> ) + e . getX ( <NUM_LIT:1> ) ; float y = e . getY ( <NUM_LIT:0> ) + e . getY ( <NUM_LIT:1> ) ; p . set ( x / <NUM_LIT:2> , y / <NUM_LIT:2> ) ; return p ; } public void setImage ( ) { if ( waitDialog != null ) { dismissWaitDialog ( ) ; } waitDialog = new ProgressDialog ( getContext ( ) ) ; waitDialog . setMessage ( "<STR_LIT>" ) ; waitDialog . setProgressStyle ( ProgressDialog . STYLE_SPINNER ) ; waitDialog . show ( ) ; thread = new Thread ( this ) ; thread . start ( ) ; } public void run ( ) { try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( InterruptedException e ) { } handler . sendEmptyMessage ( <NUM_LIT:0> ) ; } private Handler handler = new Handler ( ) { public void handleMessage ( Message msg ) { try { loading ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ; private void loading ( ) { try { String imgFile = CircleList . get ( ) ; setTag ( imgFile ) ; Bitmap bmp = ImageCache . getImage ( imgFile ) ; if ( bmp == null ) { ImageGetTask task = new ImageGetTask ( this ) ; task . execute ( imgFile ) ; } else { setImageBitmap ( bmp ) ; dismissWaitDialog ( ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } void dismissWaitDialog ( ) { try { waitDialog . dismiss ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } static int LastTaskID = - <NUM_LIT:1> ; static Object lock = new Object ( ) ; class ImageGetTask extends AsyncTask < String , Void , String > { private ImageCatalogSingleView image ; private String tag ; private int id ; public ImageGetTask ( ImageCatalogSingleView _image ) { image = _image ; tag = image . getTag ( ) . toString ( ) ; synchronized ( ImageCatalogSingleView . lock ) { ImageCatalogSingleView . LastTaskID += <NUM_LIT:1> ; id = ImageCatalogSingleView . LastTaskID ; } FLog . d ( "<STR_LIT>" + id + "<STR_LIT>" ) ; } @ Override protected String doInBackground ( String ... urls ) { try { FLog . d ( "<STR_LIT>" + urls [ <NUM_LIT:0> ] ) ; ImageCache . getImage ( urls [ <NUM_LIT:0> ] ) ; if ( ImageCache . getImage ( urls [ <NUM_LIT:0> ] ) == null ) { boolean network_result = ImageCache . setImage ( urls [ <NUM_LIT:0> ] ) ; if ( ! network_result ) { return "<STR_LIT>" ; } return urls [ <NUM_LIT:0> ] ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return "<STR_LIT>" ; } @ Override protected void onPostExecute ( String url ) { try { if ( image != null && ! url . equals ( "<STR_LIT>" ) && tag != null & tag . equals ( image . getTag ( ) ) ) { try { Bitmap bmp = ImageCache . getImage ( url ) ; image . setImageBitmap ( bmp ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } else { Toast . makeText ( getContext ( ) , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } dismissWaitDialog ( ) ; FLog . d ( "<STR_LIT>" + id + "<STR_LIT>" ) ; } @ Override protected void onCancelled ( ) { FLog . d ( "<STR_LIT>" + id ) ; } } private final SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener ( ) { @ Override public boolean onDoubleTap ( MotionEvent event ) { FLog . d ( "<STR_LIT>" ) ; return super . onDoubleTap ( event ) ; } @ Override public boolean onDoubleTapEvent ( MotionEvent event ) { FLog . d ( "<STR_LIT>" ) ; switch ( event . getAction ( ) ) { case MotionEvent . ACTION_UP : case MotionEvent . ACTION_POINTER_2_UP : middle = getMiddle ( event , middle ) ; if ( true ) { matrix . set ( moveMatrix ) ; zoomImage ( <NUM_LIT> , middle . x , middle . y ) ; setImageMatrix ( matrix ) ; } break ; } return super . onDoubleTapEvent ( event ) ; } @ Override public boolean onDown ( MotionEvent event ) { FLog . d ( "<STR_LIT>" ) ; return super . onDown ( event ) ; } @ Override public boolean onFling ( MotionEvent event1 , MotionEvent event2 , float velocityX , float velocityY ) { FLog . d ( "<STR_LIT>" ) ; return super . onFling ( event1 , event2 , velocityX , velocityY ) ; } @ Override public void onLongPress ( MotionEvent event ) { FLog . d ( "<STR_LIT>" ) ; super . onLongPress ( event ) ; } @ Override public boolean onScroll ( MotionEvent event1 , MotionEvent event2 , float distanceX , float distanceY ) { FLog . d ( "<STR_LIT>" ) ; return super . onScroll ( event1 , event2 , distanceX , distanceY ) ; } @ Override public void onShowPress ( MotionEvent event ) { FLog . d ( "<STR_LIT>" ) ; super . onShowPress ( event ) ; } @ Override public boolean onSingleTapConfirmed ( MotionEvent event ) { FLog . d ( "<STR_LIT>" ) ; return super . onSingleTapConfirmed ( event ) ; } @ Override public boolean onSingleTapUp ( MotionEvent event ) { FLog . d ( "<STR_LIT>" ) ; return super . onSingleTapUp ( event ) ; } } ; } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . IOException ; import java . util . ArrayList ; import cx . ath . dekosuke . ftbt . R . id ; import android . app . Activity ; import android . os . Bundle ; import android . view . KeyEvent ; import android . view . View ; import android . view . Window ; import android . view . WindowManager ; import android . view . WindowManager . LayoutParams ; import android . view . inputmethod . InputMethodManager ; import android . widget . EditText ; import android . widget . ListView ; import android . widget . Toast ; public class FocusEdit extends Activity { ArrayList < String > words = new ArrayList < String > ( ) ; FocusEditAdapter adapter ; @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; if ( getResources ( ) . getBoolean ( R . bool . avoidsleep ) ) { Window window = getWindow ( ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ; } this . getWindow ( ) . setSoftInputMode ( LayoutParams . SOFT_INPUT_STATE_ALWAYS_HIDDEN ) ; setContentView ( R . layout . focuswords ) ; ListView listView = ( ListView ) findViewById ( id . listview ) ; EditText text_e = ( EditText ) findViewById ( id . newword ) ; text_e . setOnKeyListener ( new View . OnKeyListener ( ) { public boolean onKey ( View v , int keyCode , KeyEvent event ) { if ( event . getAction ( ) == KeyEvent . ACTION_DOWN && keyCode == KeyEvent . KEYCODE_ENTER ) { return true ; } if ( event . getAction ( ) == KeyEvent . ACTION_UP && keyCode == KeyEvent . KEYCODE_ENTER ) { FocusEdit activity = ( FocusEdit ) v . getContext ( ) ; activity . onClickRegNewWordButton ( v ) ; return false ; } return false ; } } ) ; try { words = FocusedSettings . get ( this ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } adapter = new FocusEditAdapter ( this , R . layout . focuswords_row , words ) ; listView . setAdapter ( adapter ) ; setTitle ( "<STR_LIT>" + "<STR_LIT:U+0020-U+0020>" + getString ( R . string . app_name ) ) ; } public void onClickRegNewWordButton ( View v ) { EditText text_e = ( EditText ) findViewById ( id . newword ) ; String text = text_e . getText ( ) . toString ( ) ; try { StringUtil . validateFocusWord ( text ) ; } catch ( Exception e ) { FLog . d ( e . getMessage ( ) ) ; if ( e . getMessage ( ) . equals ( "<STR_LIT>" ) ) { } else if ( e . getMessage ( ) . equals ( "<STR_LIT>" ) ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } else if ( e . getMessage ( ) . equals ( "<STR_LIT>" ) ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } else if ( e . getMessage ( ) . equals ( "<STR_LIT>" ) ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } else { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } return ; } for ( int i = <NUM_LIT:0> ; i < adapter . items . size ( ) ; ++ i ) { if ( adapter . items . get ( i ) . equals ( text ) ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; return ; } } adapter . addLast ( text ) ; text_e . setText ( "<STR_LIT>" ) ; Toast . makeText ( this , "<STR_LIT>" + text + "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . util . ArrayList ; import java . util . Calendar ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashMap ; import android . content . Context ; import android . content . SharedPreferences ; import android . graphics . Bitmap ; import android . util . Log ; import android . media . MediaScannerConnection ; import android . os . Environment ; import android . os . StatFs ; import android . preference . PreferenceManager ; import java . io . File ; import java . io . BufferedOutputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . OutputStream ; import java . io . InputStream ; import java . io . IOException ; import java . io . ObjectOutputStream ; import java . io . FileInputStream ; import java . io . ObjectInputStream ; import java . net . HttpURLConnection ; import java . net . URL ; import android . graphics . BitmapFactory ; public class SDCard { public static String cacheDir = null ; public static String saveDir = null ; public static boolean isSDCardMounted ( ) { FLog . d ( "<STR_LIT>" + Environment . getExternalStorageState ( ) ) ; return Environment . getExternalStorageState ( ) . equals ( Environment . MEDIA_MOUNTED ) ; } public static boolean setAntiCacheDir ( Context context ) { try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; Boolean innerCache = preferences . getBoolean ( "<STR_LIT>" , false ) ; if ( ! innerCache ) { cacheDir = context . getFilesDir ( ) . getPath ( ) ; } else { cacheDir = null ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; return false ; } return true ; } public static boolean setCacheDir ( Context context ) { try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; Boolean innerCache = preferences . getBoolean ( "<STR_LIT>" , false ) ; if ( innerCache ) { cacheDir = context . getFilesDir ( ) . getPath ( ) ; } else { cacheDir = null ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; return false ; } return true ; } public static void copyCacheSetting ( Context context ) { setAntiCacheDir ( context ) ; File fbin = new File ( getCacheDir ( ) + "<STR_LIT>" ) ; fbin . mkdir ( ) ; String newFile = getCacheDir ( ) + "<STR_LIT>" ; setCacheDir ( context ) ; fbin = new File ( getCacheDir ( ) + "<STR_LIT>" ) ; fbin . mkdir ( ) ; String oldFile = getCacheDir ( ) + "<STR_LIT>" ; FLog . d ( "<STR_LIT>" + oldFile + "<STR_LIT>" + newFile ) ; InputStream input = null ; OutputStream output = null ; File dstFile = new File ( newFile ) ; try { input = new FileInputStream ( new File ( oldFile ) ) ; output = new FileOutputStream ( dstFile ) ; int DEFAULT_BUFFER_SIZE = <NUM_LIT> * <NUM_LIT:4> ; byte [ ] buffer = new byte [ DEFAULT_BUFFER_SIZE ] ; int n = <NUM_LIT:0> ; while ( - <NUM_LIT:1> != ( n = input . read ( buffer ) ) ) { output . write ( buffer , <NUM_LIT:0> , n ) ; } input . close ( ) ; output . close ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public static boolean setSaveDir ( Context context ) { try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; saveDir = preferences . getString ( "<STR_LIT>" , null ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; return false ; } return true ; } public static String getBaseDir ( ) { String sdcard_dir = Environment . getExternalStorageDirectory ( ) . getPath ( ) ; return sdcard_dir ; } public static boolean isUsableDirectory ( File file ) { return file . exists ( ) && file . isDirectory ( ) && file . canWrite ( ) ; } public static String getCacheDir ( ) { String base_dir = getBaseDir ( ) + "<STR_LIT>" ; if ( cacheDir != null ) { base_dir = cacheDir + "<STR_LIT:/>" ; } String cacheDir = base_dir ; File file = new File ( cacheDir ) ; file . mkdir ( ) ; if ( ! isUsableDirectory ( file ) ) { return null ; } return cacheDir ; } public static String getSaveDir ( ) { String base_dir = getBaseDir ( ) + "<STR_LIT>" ; if ( saveDir != null ) { base_dir = saveDir + "<STR_LIT:/>" ; } FLog . d ( "<STR_LIT>" + base_dir ) ; String saveDir = base_dir ; File file = new File ( saveDir ) ; file . mkdir ( ) ; if ( ! isUsableDirectory ( file ) ) { return null ; } return saveDir ; } public static String getThreadDir ( String threadName ) { String saveDir = getSaveDir ( ) ; String threadDir = saveDir + threadName + "<STR_LIT:/>" ; File file = new File ( threadDir ) ; file . mkdir ( ) ; return threadDir ; } public static String getSeriarizedDir ( ) { String cacheDir = getCacheDir ( ) ; String seriarizedDir = cacheDir + "<STR_LIT>" ; File file = new File ( seriarizedDir ) ; file . mkdir ( ) ; return seriarizedDir ; } public static void saveBin ( String name , byte [ ] bytes , boolean isCache ) { String filename ; if ( ! isCache ) { filename = getSaveDir ( ) + name ; } else { filename = getCacheDir ( ) + name ; } FLog . d ( "<STR_LIT>" + bytes . length ) ; File file = new File ( filename ) ; FLog . d ( filename ) ; file . getParentFile ( ) . mkdir ( ) ; try { BufferedOutputStream fos = new BufferedOutputStream ( new FileOutputStream ( file ) ) ; fos . write ( bytes ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT>" + name ) ; } } public static void saveFromURL ( String name , URL url , boolean isCache ) throws IOException { try { String filename ; if ( ! isCache ) { filename = getSaveDir ( ) + name ; } else { filename = getCacheDir ( ) + name ; } HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ( ) ; if ( ! String . valueOf ( conn . getResponseCode ( ) ) . startsWith ( "<STR_LIT:2>" ) ) { throw new IOException ( "<STR_LIT>" + conn . getResponseCode ( ) ) ; } FLog . d ( "<STR_LIT>" + conn . getResponseCode ( ) ) ; InputStream is = conn . getInputStream ( ) ; File file = new File ( filename ) ; file . getParentFile ( ) . mkdir ( ) ; OutputStream fos = new FileOutputStream ( filename ) ; byte [ ] buf = new byte [ <NUM_LIT> ] ; int len = <NUM_LIT:0> ; while ( ( len = is . read ( buf ) ) > <NUM_LIT:0> ) { fos . write ( buf , <NUM_LIT:0> , len ) ; } fos . flush ( ) ; is . close ( ) ; fos . close ( ) ; } catch ( IOException e ) { throw new IOException ( e . toString ( ) ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT>" + name ) ; } } public static String loadTextCache ( String name ) throws IOException { String sdcard_dir = Environment . getExternalStorageDirectory ( ) . getPath ( ) ; String filename = getCacheDir ( ) + name ; File file = new File ( filename ) ; return FileToString . fileToString ( file , "<STR_LIT>" ) ; } public static Bitmap loadBitmapCache ( String name ) { String sdcard_dir = Environment . getExternalStorageDirectory ( ) . getPath ( ) ; String filename = getCacheDir ( ) + name ; File file = new File ( filename ) ; return BitmapFactory . decodeFile ( filename ) ; } public static boolean cacheExist ( String name ) { String sdcard_dir = Environment . getExternalStorageDirectory ( ) . getPath ( ) ; String filename = getCacheDir ( ) + name ; File file = new File ( filename ) ; return file . exists ( ) ; } public static File copyCacheToFile ( String urlhash , String url ) throws IOException { String srcfilename = getCacheDir ( ) + urlhash ; String dstfilename = getSaveDir ( ) + url ; InputStream input = null ; OutputStream output = null ; File dstFile = new File ( dstfilename ) ; input = new FileInputStream ( new File ( srcfilename ) ) ; output = new FileOutputStream ( dstFile ) ; int DEFAULT_BUFFER_SIZE = <NUM_LIT> * <NUM_LIT:4> ; byte [ ] buffer = new byte [ DEFAULT_BUFFER_SIZE ] ; int n = <NUM_LIT:0> ; while ( - <NUM_LIT:1> != ( n = input . read ( buffer ) ) ) { output . write ( buffer , <NUM_LIT:0> , n ) ; } input . close ( ) ; output . close ( ) ; return dstFile ; } public static boolean savedImageToThreadExist ( String fileName , String threadName ) { String dstfilename = getThreadDir ( threadName ) + fileName ; File file = new File ( dstfilename ) ; return file . exists ( ) ; } public static File copyCacheToThreadFile ( String urlhash , String url , String threadName ) throws IOException { String srcfilename = getCacheDir ( ) + urlhash ; String dstfilename = getThreadDir ( threadName ) + url ; InputStream input = null ; OutputStream output = null ; File dstFile = new File ( dstfilename ) ; input = new FileInputStream ( new File ( srcfilename ) ) ; output = new FileOutputStream ( dstFile ) ; int DEFAULT_BUFFER_SIZE = <NUM_LIT> * <NUM_LIT:4> ; byte [ ] buffer = new byte [ DEFAULT_BUFFER_SIZE ] ; int n = <NUM_LIT:0> ; while ( - <NUM_LIT:1> != ( n = input . read ( buffer ) ) ) { output . write ( buffer , <NUM_LIT:0> , n ) ; } input . close ( ) ; output . close ( ) ; return dstFile ; } static Comparator comparator = new Comparator ( ) { public int compare ( Object o1 , Object o2 ) { final long additional_days = <NUM_LIT:3> * <NUM_LIT:24> * <NUM_LIT> * <NUM_LIT:1000> ; File f1 = ( File ) o1 ; File f2 = ( File ) o2 ; long f1_lastmodified = f1 . lastModified ( ) ; if ( FutabaCrypt . isHTMLName ( f1 . toString ( ) ) ) { f1_lastmodified += additional_days ; } long f2_lastmodified = f2 . lastModified ( ) ; if ( FutabaCrypt . isHTMLName ( f2 . toString ( ) ) ) { f2_lastmodified += additional_days ; } return ( int ) ( f2_lastmodified - f1_lastmodified ) ; } } ; public static void limitCache ( int num ) { File cache_dir = new File ( getCacheDir ( ) ) ; File [ ] files = cache_dir . listFiles ( ) ; ArrayList list = new ArrayList ( ) ; for ( int i = <NUM_LIT:0> ; i < files . length ; i ++ ) { list . add ( files [ i ] ) ; } Collections . sort ( list , comparator ) ; int sizeSum = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < list . size ( ) ; i ++ ) { File f = ( File ) list . get ( i ) ; FLog . d ( f . toString ( ) + "<STR_LIT>" + f . lastModified ( ) ) ; if ( f . isDirectory ( ) ) { } else { sizeSum += f . length ( ) ; if ( sizeSum > num * <NUM_LIT> ) { f . delete ( ) ; FLog . d ( "<STR_LIT>" + f . getName ( ) ) ; } } } } static private void deleteDir ( File f ) { if ( f . exists ( ) == false ) { return ; } if ( f . isFile ( ) ) { f . delete ( ) ; } if ( f . isDirectory ( ) ) { File [ ] files = f . listFiles ( ) ; for ( int i = <NUM_LIT:0> ; i < files . length ; i ++ ) { deleteDir ( files [ i ] ) ; } f . delete ( ) ; } } static private String toCalendarString ( File f ) { Calendar cal = Calendar . getInstance ( ) ; cal . setTimeInMillis ( f . lastModified ( ) ) ; int y = cal . get ( Calendar . YEAR ) ; int m = cal . get ( Calendar . MONTH ) ; int day = cal . get ( Calendar . DAY_OF_MONTH ) ; return String . valueOf ( y ) + "<STR_LIT:->" + String . valueOf ( m + <NUM_LIT:1> ) + "<STR_LIT:->" + String . valueOf ( day ) ; } public static boolean existSeriarized ( String name ) { String filename = getCacheDir ( ) + "<STR_LIT>" + name ; File file = new File ( filename ) ; return file . exists ( ) ; } static public ObjectInputStream getSerialized ( String name ) throws IOException { String filename = getSeriarizedDir ( ) + name ; File file = new File ( filename ) ; file . getParentFile ( ) . mkdir ( ) ; FileInputStream inFile = new FileInputStream ( filename ) ; ObjectInputStream inObject = new ObjectInputStream ( inFile ) ; return inObject ; } static public void setSerialized ( String name , Object object ) throws IOException { String filename = getSeriarizedDir ( ) + name ; FileOutputStream outFile = new FileOutputStream ( filename ) ; File file = new File ( filename ) ; file . getParentFile ( ) . mkdir ( ) ; ObjectOutputStream outObject = new ObjectOutputStream ( outFile ) ; outObject . writeObject ( object ) ; } public static boolean isMountedExSD ( ) { return Environment . MEDIA_MOUNTED . equals ( Environment . MEDIA_MOUNTED ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . File ; import android . app . AlertDialog ; import android . content . Context ; import android . content . DialogInterface ; import android . content . SharedPreferences ; import android . os . Environment ; import android . preference . DialogPreference ; import android . util . AttributeSet ; import android . view . View ; import android . widget . Toast ; import cx . ath . dekosuke . ftbt . DirectorySelectDialog . onDirectoryListDialogListener ; public class DirectorySelectDialogPreference extends DialogPreference implements DirectorySelectDialog . onDirectoryListDialogListener { DirectorySelectDialog dlg ; onDirectoryListDialogListener listener ; public DirectorySelectDialogPreference ( Context context , AttributeSet attrs ) { super ( context , attrs ) ; } @ Override protected void onBindView ( View view ) { SharedPreferences pref = getSharedPreferences ( ) ; super . onBindView ( view ) ; } @ Override protected void onClick ( ) { File externalStorage = new File ( "<STR_LIT:/>" ) ; dlg = new DirectorySelectDialog ( getContext ( ) ) ; dlg . setOnFileListDialogListener ( ( onDirectoryListDialogListener ) this ) ; dlg . show ( externalStorage . getAbsolutePath ( ) , externalStorage . getPath ( ) ) ; } public void addListener ( onDirectoryListDialogListener listener ) { this . listener = listener ; } public void changePreference ( String path ) { SharedPreferences . Editor editor = getEditor ( ) ; editor . putString ( getKey ( ) , path ) ; FLog . d ( "<STR_LIT>" + getKey ( ) + "<STR_LIT>" + path ) ; editor . commit ( ) ; notifyChanged ( ) ; Toast . makeText ( getContext ( ) , "<STR_LIT>" + path + "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; if ( this . listener != null ) { this . listener . onClickFileList ( path ) ; } } public void onClickFileList ( String path ) { if ( null != path ) { if ( ! SDCard . isUsableDirectory ( new File ( path ) ) ) { Toast . makeText ( getContext ( ) , "<STR_LIT>" + path + "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; FLog . d ( "<STR_LIT>" ) ; return ; } else { final String path_f = path ; AlertDialog . Builder builder = new AlertDialog . Builder ( getContext ( ) ) ; builder . setMessage ( "<STR_LIT>" + "<STR_LIT>" ) . setCancelable ( true ) . setPositiveButton ( "<STR_LIT:OK>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { changePreference ( path_f ) ; } } ) . setNegativeButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { dialog . cancel ( ) ; } } ) ; builder . create ( ) . show ( ) ; } } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . File ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . Iterator ; import java . util . LinkedHashMap ; import java . util . TreeMap ; import android . app . Activity ; import android . content . SharedPreferences ; import android . graphics . Bitmap ; import android . os . Bundle ; import android . preference . PreferenceManager ; import android . util . Log ; public class HistoryManager { private final String OPT_HISTORY = "<STR_LIT>" ; private LinkedHashMap < Integer , FutabaThreadContent > threads = new LinkedHashMap < Integer , FutabaThreadContent > ( ) ; public void clear ( ) { threads = new LinkedHashMap < Integer , FutabaThreadContent > ( ) ; } public FutabaThreadContent get ( int threadNum ) throws Exception { if ( ! threads . containsKey ( threadNum ) ) { throw new Exception ( "<STR_LIT>" + threadNum + "<STR_LIT>" ) ; } return threads . get ( threadNum ) ; } public boolean exist ( int threadNum ) { return threads . containsKey ( threadNum ) ; } public int size ( ) { return threads . size ( ) ; } public void addThread ( FutabaThreadContent thread , int maxHistoryNum ) { FLog . d ( "<STR_LIT>" + thread . threadNum ) ; if ( ! threads . containsKey ( thread . threadNum ) ) { threads . put ( thread . threadNum , thread ) ; } else { FutabaThreadContent currentThread = threads . get ( thread . threadNum ) ; thread . pointAt = currentThread . pointAt ; thread . seeAt = currentThread . seeAt ; threads . remove ( thread . threadNum ) ; threads . put ( thread . threadNum , thread ) ; } FLog . d ( "<STR_LIT>" + maxHistoryNum ) ; if ( threads . size ( ) > maxHistoryNum ) { for ( Object key : threads . keySet ( ) ) { threads . remove ( key ) ; break ; } } } public void updateThread ( FutabaThreadContent thread_a ) throws Exception { if ( ! threads . containsKey ( thread_a . threadNum ) ) { throw new Exception ( "<STR_LIT>" ) ; } else { FutabaThreadContent thread = threads . get ( thread_a . threadNum ) ; if ( Integer . parseInt ( thread_a . resNum ) != <NUM_LIT:0> ) { thread . resNum = thread_a . resNum ; } if ( thread_a . pointAt != <NUM_LIT:0> ) { thread . pointAt = thread_a . pointAt ; } if ( thread_a . seeAt != <NUM_LIT:0> ) { FLog . d ( "<STR_LIT>" + thread_a . seeAt ) ; thread . seeAt = thread_a . seeAt ; } threads . put ( thread . threadNum , thread ) ; } } public void updateThreadRemoveShiori ( FutabaThreadContent thread_a ) throws Exception { if ( ! threads . containsKey ( thread_a . threadNum ) ) { throw new Exception ( "<STR_LIT>" ) ; } else { FutabaThreadContent thread = threads . get ( thread_a . threadNum ) ; thread . pointAt = <NUM_LIT:0> ; threads . put ( thread . threadNum , thread ) ; } } public void removeThread ( FutabaThreadContent thread ) { if ( threads . containsKey ( thread . threadNum ) ) { threads . remove ( thread . threadNum ) ; } else { } } public boolean Save ( ) { try { SDCard . setSerialized ( OPT_HISTORY , threads ) ; } catch ( Exception e ) { return false ; } return true ; } public void Load ( ) { try { if ( SDCard . existSeriarized ( OPT_HISTORY ) ) { threads = ( LinkedHashMap < Integer , FutabaThreadContent > ) SDCard . getSerialized ( OPT_HISTORY ) . readObject ( ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public void set ( ArrayList < FutabaThreadContent > threads_array ) { clear ( ) ; for ( int i = <NUM_LIT:0> ; i < threads_array . size ( ) ; ++ i ) { addThread ( threads_array . get ( i ) , <NUM_LIT> ) ; } } public ArrayList < FutabaThreadContent > getThreadsArray ( ) { ArrayList < FutabaThreadContent > threads_array = new ArrayList < FutabaThreadContent > ( ) ; Iterator it = threads . keySet ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { threads_array . add ( threads . get ( it . next ( ) ) ) ; } ArrayList < FutabaThreadContent > threads_array_rev = new ArrayList < FutabaThreadContent > ( ) ; for ( int i = threads_array . size ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; -- i ) { threads_array_rev . add ( threads_array . get ( i ) ) ; } return threads_array_rev ; } static Comparator comparator = new Comparator ( ) { public int compare ( Object o1 , Object o2 ) { FutabaThreadContent f1 = ( FutabaThreadContent ) o1 ; FutabaThreadContent f2 = ( FutabaThreadContent ) o2 ; return ( int ) ( f2 . lastAccessed - f1 . lastAccessed ) ; } } ; } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . InputStream ; import java . net . HttpURLConnection ; import java . util . ArrayList ; import cx . ath . dekosuke . ftbt . FutabaThreadAdapter . ImageGetTask ; import android . content . Context ; import android . content . Intent ; import android . graphics . Bitmap ; import android . graphics . Matrix ; import android . os . AsyncTask ; import android . view . Display ; import android . view . LayoutInflater ; import android . view . View ; import android . view . ViewGroup ; import android . view . WindowManager ; import android . widget . ArrayAdapter ; import android . widget . ImageView ; import android . widget . TextView ; import android . widget . ImageView . ScaleType ; public class ThumbGridAdapter extends ArrayAdapter { ArrayList < String > urls ; private LayoutInflater inflater ; private int width ; private int height ; private int itemSize ; public ThumbGridAdapter ( Context context , int textViewResourceId , ArrayList items ) { super ( context , textViewResourceId , items ) ; this . urls = items ; this . inflater = ( LayoutInflater ) context . getSystemService ( Context . LAYOUT_INFLATER_SERVICE ) ; WindowManager wm = ( ( WindowManager ) context . getSystemService ( Context . WINDOW_SERVICE ) ) ; Display display = wm . getDefaultDisplay ( ) ; width = display . getWidth ( ) ; height = display . getHeight ( ) ; itemSize = width / <NUM_LIT:3> - <NUM_LIT:10> ; } @ Override public View getView ( int position , View convertView , ViewGroup parent ) { View view = convertView ; try { if ( view == null ) { view = inflater . inflate ( R . layout . thumbgridelement , null ) ; } String url = ( String ) urls . get ( position ) ; if ( url != null ) { try { ImageView iv = ( ImageView ) view . findViewById ( R . id . image ) ; iv . setTag ( "<STR_LIT>" + position ) ; Bitmap bm = Bitmap . createBitmap ( itemSize , itemSize , Bitmap . Config . ALPHA_8 ) ; iv . setImageBitmap ( bm ) ; ImageGetTask task = new ImageGetTask ( iv ) ; task . execute ( url ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return view ; } class ImageGetTask extends AsyncTask < String , Void , Bitmap > { private ImageView image ; private String tag ; public ImageGetTask ( ImageView _image ) { image = _image ; if ( _image == null ) { FLog . d ( "<STR_LIT>" ) ; } tag = image . getTag ( ) . toString ( ) ; FLog . d ( "<STR_LIT>" + tag ) ; } @ Override protected Bitmap doInBackground ( String ... urls ) { Bitmap bm = ImageCache . getImage ( urls [ <NUM_LIT:0> ] + "<STR_LIT>" ) ; if ( bm == null ) { bm = ImageCache . getImage ( urls [ <NUM_LIT:0> ] ) ; if ( bm == null ) { FLog . d ( "<STR_LIT>" ) ; try { ImageCache . setImage ( urls [ <NUM_LIT:0> ] ) ; bm = ImageCache . getImage ( urls [ <NUM_LIT:0> ] ) ; bm = ImageResizer . ResizeCenter ( bm , itemSize ) ; ImageCache . setImageFromBitmap ( urls [ <NUM_LIT:0> ] + "<STR_LIT>" , bm ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; FLog . d ( "<STR_LIT>" + urls [ <NUM_LIT:0> ] ) ; try { Thread . sleep ( <NUM_LIT:1> * <NUM_LIT:1000> ) ; } catch ( Exception e2 ) { FLog . d ( "<STR_LIT:message>" , e2 ) ; } } finally { } } else { FLog . d ( "<STR_LIT>" ) ; bm = ImageResizer . ResizeCenter ( bm , itemSize ) ; ImageCache . setImageFromBitmap ( urls [ <NUM_LIT:0> ] + "<STR_LIT>" , bm ) ; } } else { FLog . d ( "<STR_LIT>" ) ; } return bm ; } @ Override protected void onPostExecute ( Bitmap result ) { try { if ( image != null && tag . equals ( image . getTag ( ) ) ) { if ( result == null ) { return ; } image . setImageBitmap ( result ) ; if ( true ) { image . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { try { FLog . d ( "<STR_LIT>" ) ; Intent intent = new Intent ( ) ; ThumbGrid activity = ( ThumbGrid ) getContext ( ) ; intent . putExtra ( "<STR_LIT>" , activity . imgURLs ) ; intent . putExtra ( "<STR_LIT>" , activity . thumbURLs ) ; intent . putExtra ( "<STR_LIT>" , activity . imgURLs . get ( Integer . parseInt ( tag ) ) ) ; intent . setClassName ( activity . getPackageName ( ) , activity . getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; activity . startActivity ( intent ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ) ; } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import cx . ath . dekosuke . ftbt . DirectorySelectDialog . onDirectoryListDialogListener ; import android . os . Bundle ; import android . preference . CheckBoxPreference ; import android . preference . EditTextPreference ; import android . preference . Preference ; import android . preference . PreferenceActivity ; import android . util . Log ; import android . widget . Toast ; import android . preference . Preference . OnPreferenceChangeListener ; public class PrefSetting extends PreferenceActivity { @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; addPreferencesFromResource ( R . xml . prefsetting ) ; try { EditTextPreference etp = ( EditTextPreference ) this . findPreference ( getString ( R . string . cachesize ) ) ; etp . setOnPreferenceChangeListener ( new OnPreferenceChangeListener ( ) { public boolean onPreferenceChange ( Preference preference , Object newValue ) { return CacheSizeChange ( preference , newValue ) ; } } ) ; EditTextPreference etp_hist = ( EditTextPreference ) this . findPreference ( getString ( R . string . historynum ) ) ; etp_hist . setOnPreferenceChangeListener ( new OnPreferenceChangeListener ( ) { public boolean onPreferenceChange ( Preference preference , Object newValue ) { return HistorySizeChange ( preference , newValue ) ; } } ) ; EditTextPreference etp_threadStrNum = ( EditTextPreference ) this . findPreference ( "<STR_LIT>" ) ; etp_threadStrNum . setOnPreferenceChangeListener ( new OnPreferenceChangeListener ( ) { public boolean onPreferenceChange ( Preference preference , Object newValue ) { return ThreadStrNumChange ( preference , newValue ) ; } } ) ; EditTextPreference etp_delkey = ( EditTextPreference ) this . findPreference ( getString ( R . string . deletekey ) ) ; etp_delkey . setOnPreferenceChangeListener ( new OnPreferenceChangeListener ( ) { public boolean onPreferenceChange ( Preference preference , Object newValue ) { return DeleteKeyChange ( preference , newValue ) ; } } ) ; final DirectorySelectDialogPreference savedir = ( DirectorySelectDialogPreference ) this . findPreference ( "<STR_LIT>" ) ; String saveSummaryFooter = "<STR_LIT>" ; if ( SDCard . saveDir != null ) { saveSummaryFooter += "<STR_LIT>" + SDCard . saveDir + "<STR_LIT:\">" ; } savedir . setSummary ( getString ( R . string . savedirsummary ) + saveSummaryFooter ) ; savedir . addListener ( new onDirectoryListDialogListener ( ) { public void onClickFileList ( String path ) { savedir . setSummary ( path ) ; } } ) ; CheckBoxPreference innerCache = ( CheckBoxPreference ) this . findPreference ( "<STR_LIT>" ) ; innerCache . setSummary ( R . string . innerCacheSummary ) ; innerCache . setOnPreferenceChangeListener ( new OnPreferenceChangeListener ( ) { public boolean onPreferenceChange ( Preference preference , Object newValue ) { return InnerCacheChange ( preference , newValue ) ; } } ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } private boolean CacheSizeChange ( Preference preference , Object newValue ) { String input = newValue . toString ( ) ; try { if ( input != null && Integer . parseInt ( input ) > <NUM_LIT:0> && Integer . parseInt ( input ) > <NUM_LIT:4> && Integer . parseInt ( input ) <= <NUM_LIT:1000> ) { preference . setSummary ( input ) ; return true ; } else { } } catch ( Exception e ) { } Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; return false ; } private boolean HistorySizeChange ( Preference preference , Object newValue ) { String input = newValue . toString ( ) ; try { if ( input != null && Integer . parseInt ( input ) >= <NUM_LIT:0> && Integer . parseInt ( input ) <= <NUM_LIT:100> ) { preference . setSummary ( input ) ; return true ; } else { } } catch ( Exception e ) { } Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; return false ; } private boolean ThreadStrNumChange ( Preference preference , Object newValue ) { String input = newValue . toString ( ) ; try { if ( input != null && Integer . parseInt ( input ) >= <NUM_LIT:4> && Integer . parseInt ( input ) <= <NUM_LIT> ) { preference . setSummary ( input ) ; return true ; } else { } } catch ( Exception e ) { } Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; return false ; } private boolean DeleteKeyChange ( Preference preference , Object newValue ) { String input = newValue . toString ( ) ; try { if ( input != null && input . length ( ) <= <NUM_LIT:8> ) { preference . setSummary ( input ) ; return true ; } else { } } catch ( Exception e ) { } Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; return false ; } private boolean InnerCacheChange ( Preference preference , Object newValue ) { String input = newValue . toString ( ) ; FLog . d ( "<STR_LIT>" + newValue ) ; try { if ( input != null ) { FLog . d ( "<STR_LIT>" + input ) ; SDCard . copyCacheSetting ( this ) ; return true ; } else { } } catch ( Exception e ) { } return false ; } private boolean SaveDirChange ( Preference preference , Object newValue ) { String input = newValue . toString ( ) ; try { if ( input != null ) { SDCard . setSaveDir ( this ) ; return true ; } else { } } catch ( Exception e ) { } return false ; } private String getDirFooter ( ) { return "<STR_LIT>" + SDCard . getBaseDir ( ) + "<STR_LIT>" ; } @ Override public void onDestroy ( ) { FLog . d ( "<STR_LIT>" ) ; super . onDestroy ( ) ; try { SDCard . setCacheDir ( this ) ; SDCard . setSaveDir ( this ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . app . Activity ; import android . app . AlertDialog ; import android . app . ListActivity ; import android . net . Uri ; import android . os . Bundle ; import android . view . Display ; import android . view . KeyEvent ; import android . view . Menu ; import android . view . MenuInflater ; import android . view . MenuItem ; import android . view . Window ; import android . view . WindowManager ; import android . content . ContentResolver ; import android . content . ContentValues ; import android . content . Context ; import android . content . DialogInterface ; import android . content . Intent ; import android . content . SharedPreferences ; import android . content . res . Configuration ; import android . graphics . Bitmap ; import android . util . Log ; import java . io . BufferedReader ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . text . SimpleDateFormat ; import java . util . ArrayList ; import java . util . Date ; import java . util . Iterator ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . apache . http . HttpEntity ; import org . apache . http . HttpResponse ; import org . apache . http . client . HttpClient ; import org . apache . http . client . methods . HttpGet ; import org . apache . http . impl . client . DefaultHttpClient ; import org . apache . http . params . HttpConnectionParams ; import org . apache . http . params . HttpParams ; import org . apache . http . protocol . BasicHttpContext ; import org . apache . http . protocol . DefaultedHttpContext ; import org . apache . http . protocol . HttpContext ; import android . app . ProgressDialog ; import java . lang . Thread ; import java . net . HttpURLConnection ; import java . net . URL ; import java . net . UnknownHostException ; import android . os . AsyncTask ; import android . os . Handler ; import android . os . Message ; import android . preference . PreferenceManager ; import android . provider . MediaStore . Images ; import android . widget . AdapterView ; import android . widget . Button ; import android . widget . EditText ; import android . widget . ImageButton ; import android . widget . ImageView ; import android . widget . LinearLayout ; import android . widget . ListView ; import android . widget . TextView ; import android . widget . Toast ; import android . view . View ; import android . view . inputmethod . InputMethodManager ; import cx . ath . dekosuke . ftbt . FutabaThreadAdapter . ImageGetTask ; import cx . ath . dekosuke . ftbt . R . id ; public class FutabaThread extends Activity implements Runnable { public ArrayList < FutabaStatus > statuses = null ; public FutabaThreadAdapter adapter = null ; public String threadURL = null ; public String baseURL = null ; public String BBSName = null ; public int threadNum ; public Toast toast ; private ProgressDialog waitDialog ; private Thread thread ; private boolean showDeletedRes = false ; private ListView listView ; int position = <NUM_LIT:0> ; int positionY = <NUM_LIT:0> ; int currentSize = <NUM_LIT:0> ; int prevSize = <NUM_LIT:0> ; final int TO_IMAGECATALOG = <NUM_LIT:0> ; final int TO_POST = <NUM_LIT:1> ; private int itemLongClick_chosen = <NUM_LIT:0> ; @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; if ( getResources ( ) . getBoolean ( R . bool . avoidsleep ) ) { Window window = getWindow ( ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ; } try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( this ) ; showDeletedRes = preferences . getBoolean ( getString ( R . string . showdeletedres ) , false ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } Intent intent = getIntent ( ) ; String superFutabaLinkURL = intent . getDataString ( ) ; if ( superFutabaLinkURL != null ) { FLog . d ( "<STR_LIT>" + superFutabaLinkURL ) ; Pattern baseURLpattern = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; Matcher threadm = baseURLpattern . matcher ( superFutabaLinkURL ) ; if ( threadm . find ( ) ) { baseURL = threadm . group ( <NUM_LIT:1> ) ; threadNum = Integer . parseInt ( threadm . group ( <NUM_LIT:2> ) ) ; BBSName = "<STR_LIT>" ; threadURL = baseURL + "<STR_LIT>" + threadNum + "<STR_LIT>" ; FLog . d ( "<STR_LIT>" + threadURL ) ; } else { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } } else { baseURL = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; threadNum = Integer . parseInt ( ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ) ; BBSName = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; try { HistoryManager man = new HistoryManager ( ) ; man . Load ( ) ; FutabaThreadContent thread ; thread = man . get ( threadNum ) ; FLog . d ( "<STR_LIT>" + thread . seeAt ) ; position = thread . seeAt ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } threadURL = baseURL + "<STR_LIT>" + threadNum + "<STR_LIT>" ; } statuses = new ArrayList < FutabaStatus > ( ) ; setContentView ( R . layout . futaba_thread ) ; listView = ( ListView ) findViewById ( id . threadlistview ) ; adapter = new FutabaThreadAdapter ( this , StateMan . getThreadRowResourceId ( this ) , statuses ) ; listView . setAdapter ( adapter ) ; listView . setOnItemLongClickListener ( new FutabaThreadOnLongClickListener ( ) ) ; try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( this ) ; boolean fastScrollEnabled = preferences . getBoolean ( "<STR_LIT>" , false ) ; listView . setFastScrollEnabled ( fastScrollEnabled ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } setWait ( ) ; } public void setWait ( ) { if ( waitDialog != null ) { waitDialog . dismiss ( ) ; } waitDialog = new ProgressDialog ( this ) ; waitDialog . setMessage ( this . getString ( R . string . loading ) ) ; waitDialog . setProgressStyle ( ProgressDialog . STYLE_SPINNER ) ; waitDialog . show ( ) ; thread = new Thread ( this ) ; thread . start ( ) ; } public void run ( ) { try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( InterruptedException e ) { } handler . sendEmptyMessage ( <NUM_LIT:0> ) ; } private Handler handler = new Handler ( ) { public void handleMessage ( Message msg ) { try { loading ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ; final Handler handler2 = new Handler ( ) ; final Handler handler3 = new Handler ( ) ; private void loading ( ) { LinearLayout searchBar = ( LinearLayout ) findViewById ( id . search_bar ) ; EditText searchWord = ( EditText ) findViewById ( R . id . searchinput ) ; searchWord . setOnKeyListener ( new View . OnKeyListener ( ) { public boolean onKey ( View v , int keyCode , KeyEvent event ) { FLog . d ( "<STR_LIT>" + event ) ; if ( event . getAction ( ) == KeyEvent . ACTION_DOWN && keyCode == KeyEvent . KEYCODE_ENTER ) { return true ; } if ( event . getAction ( ) == KeyEvent . ACTION_UP && keyCode == KeyEvent . KEYCODE_ENTER ) { EditText word = ( EditText ) findViewById ( R . id . searchinput ) ; FutabaThread activity = ( FutabaThread ) v . getContext ( ) ; activity . onClickSearchButton ( v ) ; return false ; } return false ; } } ) ; searchBar . setVisibility ( View . GONE ) ; FutabaThreadContentGetter getterThread = new FutabaThreadContentGetter ( ) ; getterThread . start ( ) ; } public ArrayList < String > getImageURLs ( ) { Iterator iterator = statuses . iterator ( ) ; int i = <NUM_LIT:0> ; ArrayList < String > list = new ArrayList < String > ( ) ; while ( iterator . hasNext ( ) ) { FutabaStatus status = ( FutabaStatus ) iterator . next ( ) ; if ( status . bigImgURL != null ) { FLog . d ( "<STR_LIT>" + status . bigImgURL ) ; list . add ( status . bigImgURL ) ; } i ++ ; } return list ; } public ArrayList < String > getThumbURLs ( ) { Iterator iterator = statuses . iterator ( ) ; int i = <NUM_LIT:0> ; ArrayList < String > list = new ArrayList < String > ( ) ; while ( iterator . hasNext ( ) ) { FutabaStatus status = ( FutabaStatus ) iterator . next ( ) ; if ( status . imgURL != null ) { FLog . d ( "<STR_LIT>" + status . imgURL ) ; list . add ( status . imgURL ) ; } i ++ ; } return list ; } public void onClickReloadBtn ( View v ) { try { FLog . d ( "<STR_LIT>" ) ; position = listView . getFirstVisiblePosition ( ) ; positionY = listView . getChildAt ( <NUM_LIT:0> ) . getTop ( ) ; ; FLog . d ( "<STR_LIT>" + position ) ; setWait ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public void onClickGoTopBtn ( View v ) { listView . setSelection ( <NUM_LIT:0> ) ; } public void onClickGridViewBtn ( View v ) { FLog . d ( "<STR_LIT>" ) ; Intent intent = new Intent ( ) ; ArrayList < String > thumbURLs = getThumbURLs ( ) ; if ( thumbURLs . size ( ) == <NUM_LIT:0> ) { return ; } int pos = listView . getFirstVisiblePosition ( ) ; int imagepos = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i <= pos ; ++ i ) { FutabaStatus status = ( FutabaStatus ) adapter . items . get ( i ) ; if ( status . imgURL != null && ! status . imgURL . equals ( "<STR_LIT>" ) ) { imagepos ++ ; } } imagepos = Math . max ( <NUM_LIT:0> , imagepos - <NUM_LIT:1> ) ; intent . putExtra ( "<STR_LIT>" , imagepos ) ; intent . putExtra ( "<STR_LIT>" , getImageURLs ( ) ) ; intent . putExtra ( "<STR_LIT>" , thumbURLs ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; } public void onClickGoBottomBtn ( View v ) { listView . setSelection ( listView . getCount ( ) - <NUM_LIT:1> ) ; } public void onClickGoBtn ( View v ) { WindowManager wm = ( WindowManager ) getSystemService ( Context . WINDOW_SERVICE ) ; Display display = wm . getDefaultDisplay ( ) ; } public void onClickPostBtn ( View v ) { Intent intent = new Intent ( ) ; intent . putExtra ( "<STR_LIT>" , baseURL ) ; intent . putExtra ( "<STR_LIT>" , threadNum ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivityForResult ( intent , TO_POST ) ; } @ Override public boolean onCreateOptionsMenu ( Menu menu ) { super . onCreateOptionsMenu ( menu ) ; MenuInflater inflater = getMenuInflater ( ) ; inflater . inflate ( R . menu . menu_thread , menu ) ; return true ; } public void registerShiori ( int position ) { try { if ( position == <NUM_LIT:0> ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } else { FutabaStatus item = ( FutabaStatus ) adapter . items . get ( position ) ; if ( FutabaStatus . isBlank ( item ) ) { position += <NUM_LIT:1> ; item = ( FutabaStatus ) adapter . items . get ( position ) ; } HistoryManager man = new HistoryManager ( ) ; man . Load ( ) ; FutabaThreadContent thread = new FutabaThreadContent ( ) ; thread . pointAt = item . id ; thread . threadNum = threadNum ; FLog . d ( thread . toString ( ) ) ; man . updateThread ( thread ) ; man . Save ( ) ; View view = listView . getChildAt ( <NUM_LIT:0> ) ; adapter . shioriPosition = item . id ; adapter . setShioriStatus ( view ) ; adapter . notifyDataSetChanged ( ) ; listView . invalidate ( ) ; Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public void removeShiori ( int position ) { try { HistoryManager man = new HistoryManager ( ) ; man . Load ( ) ; FutabaThreadContent thread = new FutabaThreadContent ( ) ; thread . pointAt = - <NUM_LIT:1> ; thread . threadNum = threadNum ; FLog . d ( thread . toString ( ) ) ; man . updateThreadRemoveShiori ( thread ) ; man . Save ( ) ; View view = listView . getChildAt ( <NUM_LIT:0> ) ; adapter . shioriPosition = <NUM_LIT:0> ; adapter . notifyDataSetChanged ( ) ; listView . invalidate ( ) ; Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public void searchShiori ( ) { try { HistoryManager man = new HistoryManager ( ) ; man . Load ( ) ; FutabaThreadContent thread = man . get ( threadNum ) ; int position = thread . pointAt ; if ( position == <NUM_LIT:0> ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } else { int i = <NUM_LIT:0> ; for ( i = <NUM_LIT:0> ; i < adapter . items . size ( ) ; ++ i ) { FutabaStatus status = ( FutabaStatus ) adapter . items . get ( i ) ; if ( status . id == position ) { listView . setSelection ( i ) ; Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; break ; } } if ( i == adapter . items . size ( ) ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } } @ Override public boolean onOptionsItemSelected ( MenuItem item ) { Intent intent ; switch ( item . getItemId ( ) ) { case R . id . search : LinearLayout searchBar = ( LinearLayout ) findViewById ( id . search_bar ) ; if ( searchBar . getVisibility ( ) == View . GONE ) { searchBar . setVisibility ( View . VISIBLE ) ; } else { searchBar . setVisibility ( View . GONE ) ; } return true ; case R . id . download : saveAll ( ) ; return true ; case R . id . post : onClickPostBtn ( null ) ; return true ; case R . id . possave : { int position = listView . getFirstVisiblePosition ( ) ; registerShiori ( position ) ; } return true ; case R . id . posload : searchShiori ( ) ; return true ; case R . id . share : intent = new Intent ( Intent . ACTION_SEND ) ; intent . setType ( "<STR_LIT:text/plain>" ) ; intent . putExtra ( Intent . EXTRA_TEXT , threadURL ) ; try { startActivityForResult ( intent , <NUM_LIT:0> ) ; } catch ( android . content . ActivityNotFoundException ex ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } return true ; case R . id . settings : intent = new Intent ( ) ; intent . setClassName ( getPackageName ( ) , getClass ( ) . getPackage ( ) . getName ( ) + "<STR_LIT>" ) ; startActivity ( intent ) ; return true ; case R . id . about : Uri uri = Uri . parse ( getString ( R . string . helpurl ) ) ; intent = new Intent ( Intent . ACTION_VIEW , uri ) ; intent . setClassName ( "<STR_LIT>" , "<STR_LIT>" ) ; try { startActivity ( intent ) ; } catch ( android . content . ActivityNotFoundException ex ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } return true ; } return false ; } public void saveAll ( ) { if ( waitDialog != null ) { waitDialog . dismiss ( ) ; } waitDialog = new ProgressDialog ( this ) ; waitDialog . setMessage ( this . getString ( R . string . loading ) ) ; waitDialog . setProgressStyle ( ProgressDialog . STYLE_SPINNER ) ; waitDialog . show ( ) ; ArrayList < String > imgURLs = getImageURLs ( ) ; imgURLs . add ( threadURL ) ; FutabaThreadAllImageRetriever getterThread = new FutabaThreadAllImageRetriever ( ) ; getterThread . setImageURLs ( imgURLs ) ; getterThread . start ( ) ; } private class FutabaThreadAllImageRetriever extends Thread { private ArrayList < String > imgURLs ; public void setImageURLs ( ArrayList < String > imgURLs ) { this . imgURLs = imgURLs ; } @ Override public void run ( ) { int saveItemNum = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < imgURLs . size ( ) ; ++ i ) { if ( ! waitDialog . isShowing ( ) ) { return ; } final int current = i ; try { final String imgURL = imgURLs . get ( i ) ; String threadName = "<STR_LIT>" ; if ( false && statuses . size ( ) != <NUM_LIT:0> ) { FutabaStatus status = statuses . get ( <NUM_LIT:0> ) ; Date date = new Date ( ) ; SimpleDateFormat sdf1 = new SimpleDateFormat ( "<STR_LIT>" ) ; threadName = "<STR_LIT>" + BBSName + "<STR_LIT:_>" + sdf1 . format ( date ) + "<STR_LIT>" + threadNum ; } else { threadName = "<STR_LIT>" + BBSName + "<STR_LIT>" + threadNum ; } FLog . d ( "<STR_LIT>" + imgURL ) ; File file = new File ( imgURL ) ; if ( ! imgURL . contains ( "<STR_LIT>" ) && SDCard . savedImageToThreadExist ( file . getName ( ) , threadName ) ) { continue ; } File saved_file = ImageCache . saveImageToThread ( imgURL , threadName ) ; if ( saved_file == null ) { ImageCache . setImage ( imgURL ) ; saved_file = ImageCache . saveImageToThread ( imgURL , threadName ) ; } if ( saved_file != null ) { saveItemNum += <NUM_LIT:1> ; } final File saved_file_f = saved_file ; handler3 . post ( new Runnable ( ) { public void run ( ) { if ( saved_file_f != null ) { waitDialog . setMessage ( "<STR_LIT>" + saved_file_f + "<STR_LIT>" + ( current + <NUM_LIT:1> ) + "<STR_LIT:/>" + imgURLs . size ( ) + "<STR_LIT:)>" ) ; String mimeType = StringUtil . getMIMEType ( saved_file_f . getName ( ) ) ; FLog . d ( "<STR_LIT>" + saved_file_f . getName ( ) ) ; FLog . d ( "<STR_LIT>" + mimeType ) ; ContentResolver contentResolver = getContentResolver ( ) ; ContentValues values = new ContentValues ( <NUM_LIT:7> ) ; values . put ( Images . Media . TITLE , saved_file_f . getName ( ) ) ; values . put ( Images . Media . DISPLAY_NAME , saved_file_f . getName ( ) ) ; values . put ( Images . Media . DATE_TAKEN , System . currentTimeMillis ( ) ) ; values . put ( Images . Media . MIME_TYPE , mimeType ) ; values . put ( Images . Media . ORIENTATION , <NUM_LIT:0> ) ; values . put ( Images . Media . DATA , saved_file_f . getPath ( ) ) ; values . put ( Images . Media . SIZE , saved_file_f . length ( ) ) ; contentResolver . insert ( Images . Media . EXTERNAL_CONTENT_URI , values ) ; } else { if ( toast != null ) { toast . cancel ( ) ; } toast . makeText ( adapter . getContext ( ) , "<STR_LIT>" + imgURL + "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } } } ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } final int saveItemNum_f = saveItemNum ; handler3 . post ( new Runnable ( ) { public void run ( ) { waitDialog . dismiss ( ) ; if ( toast != null ) { toast . cancel ( ) ; } toast . makeText ( adapter . getContext ( ) , "<STR_LIT>" + saveItemNum_f + "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } } ) ; System . gc ( ) ; } } protected void onActivityResult ( int requestCode , int resultCode , Intent intent ) { try { FLog . d ( "<STR_LIT>" + requestCode ) ; if ( requestCode == TO_IMAGECATALOG ) { String imgURL = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < statuses . size ( ) ; ++ i ) { if ( imgURL . equals ( statuses . get ( i ) . bigImgURL ) ) { listView . setSelection ( Math . min ( i , listView . getCount ( ) ) ) ; break ; } } } else if ( requestCode == TO_POST ) { String posted = "<STR_LIT>" ; try { posted = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; } catch ( Exception e ) { } if ( ! posted . equals ( "<STR_LIT>" ) ) { this . onClickReloadBtn ( null ) ; } } else { FLog . d ( "<STR_LIT>" ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } private boolean isAnonymousThread ( String url ) { return url . contains ( "<STR_LIT>" ) || url . contains ( "<STR_LIT>" ) || url . contains ( "<STR_LIT>" ) || url . contains ( "<STR_LIT>" ) ; } private class FutabaThreadContentGetter extends Thread { @ Override public void run ( ) { try { boolean anonymous = false ; if ( isAnonymousThread ( baseURL ) ) { anonymous = true ; } currentSize = prevSize = <NUM_LIT:0> ; String toast_text = "<STR_LIT>" ; Boolean network_ok = true ; Boolean cache_ok = true ; FutabaThreadParser cacheParser = new FutabaThreadParser ( ) ; FutabaThreadParser webParser = new FutabaThreadParser ( ) ; if ( SDCard . cacheExist ( FutabaCrypt . createDigest ( threadURL ) ) ) { String cacheThreadHtml = SDCard . loadTextCache ( FutabaCrypt . createDigest ( threadURL ) ) ; cacheParser . parse ( cacheThreadHtml , anonymous , showDeletedRes ) ; FLog . d ( "<STR_LIT>" + threadURL ) ; } else { cache_ok = false ; FLog . d ( "<STR_LIT>" + threadURL ) ; } String threadHtml = "<STR_LIT>" ; try { SDCard . saveFromURL ( FutabaCrypt . createDigest ( threadURL ) , new URL ( threadURL ) , true ) ; String webThreadHtml = SDCard . loadTextCache ( FutabaCrypt . createDigest ( threadURL ) ) ; webParser . parse ( webThreadHtml , anonymous , showDeletedRes ) ; if ( cache_ok ) { try { HistoryManager man = new HistoryManager ( ) ; FutabaThreadContent thread = new FutabaThreadContent ( ) ; thread . threadNum = threadNum ; thread . resNum = "<STR_LIT>" + Math . max ( <NUM_LIT:0> , webParser . getStatuses ( ) . size ( ) - <NUM_LIT:1> ) ; man . Load ( ) ; man . updateThread ( thread ) ; man . Save ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } network_ok = true ; } catch ( IOException e ) { network_ok = false ; String cause = "<STR_LIT>" ; if ( e . toString ( ) . contains ( "<STR_LIT>" ) ) { cause = "<STR_LIT>" ; } if ( cache_ok ) { toast_text = cause + "<STR_LIT>" ; } else { toast_text = cause ; } } catch ( Exception e ) { network_ok = false ; FLog . d ( "<STR_LIT:message>" , e ) ; if ( cache_ok ) { toast_text = "<STR_LIT>" ; } else { toast_text = "<STR_LIT>" ; } } HistoryManager man = new HistoryManager ( ) ; man . Load ( ) ; if ( ( ! network_ok ) && ( ! cache_ok ) ) { FutabaThreadContent thread = new FutabaThreadContent ( ) ; thread . threadNum = threadNum ; FLog . d ( "<STR_LIT>" + thread . toString ( ) ) ; man . removeThread ( thread ) ; man . Save ( ) ; } try { FutabaThreadContent thisThread = man . get ( threadNum ) ; adapter . shioriPosition = thisThread . pointAt ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } ArrayList < FutabaStatus > statuses = new ArrayList < FutabaStatus > ( ) ; if ( network_ok ) { statuses = webParser . getStatuses ( ) ; int num = webParser . getStatuses ( ) . size ( ) ; currentSize = num ; if ( cache_ok ) { num -= cacheParser . getStatuses ( ) . size ( ) ; prevSize = cacheParser . getStatuses ( ) . size ( ) ; if ( num < <NUM_LIT:0> ) { FLog . d ( "<STR_LIT>" + currentSize + "<STR_LIT>" + prevSize ) ; toast_text = "<STR_LIT>" + Math . max ( num , <NUM_LIT:0> ) + "<STR_LIT>" ; } else { toast_text = "<STR_LIT>" + num + "<STR_LIT>" ; } } else { toast_text = "<STR_LIT>" + Math . max ( num - <NUM_LIT:1> , <NUM_LIT:0> ) + "<STR_LIT>" ; currentSize = prevSize = num ; } } else if ( cache_ok ) { statuses = cacheParser . getStatuses ( ) ; } FLog . d ( "<STR_LIT>" + statuses . size ( ) ) ; FutabaThreadParser parser = webParser ; if ( ! network_ok ) { parser = cacheParser ; } final String title = parser . getTitle ( <NUM_LIT:20> ) + "<STR_LIT:U+0020-U+0020>" + getString ( R . string . app_name ) ; final String toast_text_f = toast_text ; final ArrayList < FutabaStatus > statuses_ref = statuses ; final int prevSize_ref = prevSize ; handler2 . post ( new Runnable ( ) { public void run ( ) { adapter . items . clear ( ) ; for ( int i = <NUM_LIT:0> ; i < statuses_ref . size ( ) ; ++ i ) { if ( i != <NUM_LIT:0> && i == prevSize_ref ) { adapter . items . add ( FutabaStatus . createBlank ( ) ) ; } adapter . items . add ( statuses_ref . get ( i ) ) ; if ( i == statuses_ref . size ( ) - <NUM_LIT:1> && ! statuses_ref . get ( <NUM_LIT:0> ) . endTime . equals ( "<STR_LIT>" ) ) { adapter . items . add ( FutabaStatus . createEndTime ( statuses_ref . get ( <NUM_LIT:0> ) . endTime ) ) ; } } try { if ( waitDialog != null ) { waitDialog . dismiss ( ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } Toast . makeText ( adapter . getContext ( ) , toast_text_f , Toast . LENGTH_SHORT ) . show ( ) ; setTitle ( title ) ; adapter . notifyDataSetChanged ( ) ; listView . invalidate ( ) ; if ( position != <NUM_LIT:0> ) { listView . setSelectionFromTop ( Math . min ( position , listView . getCount ( ) ) , positionY ) ; } } } ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } public void saveImage ( String imgURL ) { if ( this . toast != null ) { this . toast . cancel ( ) ; } this . toast = Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) ; this . toast . show ( ) ; FutabaThreadImageRetriever getterThread = new FutabaThreadImageRetriever ( ) ; getterThread . setImageURL ( imgURL ) ; getterThread . start ( ) ; } private class FutabaThreadImageRetriever extends Thread { private String imgURL ; public void setImageURL ( String imgURL ) { this . imgURL = imgURL ; } @ Override public void run ( ) { try { String imgFile = imgURL ; FLog . d ( "<STR_LIT>" + imgURL ) ; File file = new File ( imgFile ) ; File saved_file = ImageCache . saveImage ( imgFile ) ; if ( saved_file == null ) { ImageCache . setImage ( imgFile ) ; saved_file = ImageCache . saveImage ( imgFile ) ; } final File saved_file_f = saved_file ; handler3 . post ( new Runnable ( ) { public void run ( ) { FutabaThread fthread = ( FutabaThread ) adapter . getContext ( ) ; if ( saved_file_f != null ) { if ( fthread . toast != null ) { fthread . toast . cancel ( ) ; } fthread . toast = Toast . makeText ( fthread , saved_file_f . getAbsolutePath ( ) + "<STR_LIT>" , Toast . LENGTH_SHORT ) ; fthread . toast . show ( ) ; String mimeType = StringUtil . getMIMEType ( saved_file_f . getName ( ) ) ; FLog . d ( "<STR_LIT>" + saved_file_f . getName ( ) ) ; FLog . d ( "<STR_LIT>" + mimeType ) ; ContentResolver contentResolver = getContentResolver ( ) ; ContentValues values = new ContentValues ( <NUM_LIT:7> ) ; values . put ( Images . Media . TITLE , saved_file_f . getName ( ) ) ; values . put ( Images . Media . DISPLAY_NAME , saved_file_f . getName ( ) ) ; values . put ( Images . Media . DATE_TAKEN , System . currentTimeMillis ( ) ) ; values . put ( Images . Media . MIME_TYPE , mimeType ) ; values . put ( Images . Media . ORIENTATION , <NUM_LIT:0> ) ; values . put ( Images . Media . DATA , saved_file_f . getPath ( ) ) ; values . put ( Images . Media . SIZE , saved_file_f . length ( ) ) ; contentResolver . insert ( Images . Media . EXTERNAL_CONTENT_URI , values ) ; } else { if ( fthread . toast != null ) { fthread . toast . cancel ( ) ; } fthread . toast = Toast . makeText ( fthread , "<STR_LIT>" , Toast . LENGTH_SHORT ) ; fthread . toast . show ( ) ; } } } ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } waitDialog . dismiss ( ) ; } } public void onClickSearchButton ( View v ) { FLog . d ( "<STR_LIT>" ) ; if ( true ) { EditText searchEdit = ( EditText ) findViewById ( id . searchinput ) ; String searchText = searchEdit . getText ( ) . toString ( ) ; String [ ] queries = StringUtil . querySplit ( searchText ) ; adapter . searchQueries = queries ; boolean found = false ; for ( int i = listView . getFirstVisiblePosition ( ) + <NUM_LIT:1> ; i < statuses . size ( ) ; ++ i ) { String text = statuses . get ( i ) . text ; if ( StringUtil . isQueryMatchOr ( text , queries , false ) ) { listView . setSelection ( i ) ; found = true ; break ; } } if ( ! found ) { for ( int i = <NUM_LIT:0> ; i < Math . min ( listView . getFirstVisiblePosition ( ) + <NUM_LIT:1> , statuses . size ( ) ) ; ++ i ) { String text = statuses . get ( i ) . text ; if ( StringUtil . isQueryMatchOr ( text , queries , false ) ) { listView . setSelection ( i ) ; found = true ; if ( true ) { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } break ; } } } if ( ! found ) { Toast . makeText ( this , "<STR_LIT>" + searchText + "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } InputMethodManager imm = ( InputMethodManager ) getSystemService ( INPUT_METHOD_SERVICE ) ; imm . hideSoftInputFromWindow ( v . getWindowToken ( ) , <NUM_LIT:0> ) ; } } public void onClickSearchHideButton ( View v ) { LinearLayout searchBar = ( LinearLayout ) findViewById ( id . search_bar ) ; searchBar . setVisibility ( View . GONE ) ; InputMethodManager imm = ( InputMethodManager ) getSystemService ( INPUT_METHOD_SERVICE ) ; imm . hideSoftInputFromWindow ( v . getWindowToken ( ) , <NUM_LIT:0> ) ; } public boolean onSearchRequested ( ) { FLog . d ( "<STR_LIT>" ) ; if ( true ) { LinearLayout searchBar = ( LinearLayout ) findViewById ( id . search_bar ) ; if ( searchBar . getVisibility ( ) == View . GONE ) { searchBar . setVisibility ( View . VISIBLE ) ; } else { searchBar . setVisibility ( View . GONE ) ; InputMethodManager imm = ( InputMethodManager ) getSystemService ( INPUT_METHOD_SERVICE ) ; imm . hideSoftInputFromWindow ( getCurrentFocus ( ) . getWindowToken ( ) , <NUM_LIT:0> ) ; } } return false ; } @ Override public void onPause ( ) { super . onPause ( ) ; int seeAt = listView . getFirstVisiblePosition ( ) ; try { HistoryManager man = new HistoryManager ( ) ; man . Load ( ) ; FutabaThreadContent thread = new FutabaThreadContent ( ) ; thread . seeAt = seeAt ; thread . threadNum = threadNum ; FLog . d ( "<STR_LIT>" + seeAt ) ; man . updateThread ( thread ) ; man . Save ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } public boolean dispatchKeyEvent ( KeyEvent event ) { FLog . d ( "<STR_LIT>" + event . getAction ( ) ) ; int action = event . getAction ( ) ; int keyCode = event . getKeyCode ( ) ; if ( keyCode == KeyEvent . KEYCODE_VOLUME_DOWN ) { if ( action == KeyEvent . ACTION_UP ) { FLog . d ( "<STR_LIT>" + listView . getFirstVisiblePosition ( ) ) ; int topPositionY = listView . getChildAt ( <NUM_LIT:0> ) . getTop ( ) ; WindowManager wm = ( WindowManager ) getSystemService ( Context . WINDOW_SERVICE ) ; Display disp = wm . getDefaultDisplay ( ) ; int height = disp . getHeight ( ) ; listView . setSelectionFromTop ( listView . getFirstVisiblePosition ( ) , topPositionY - ( height - <NUM_LIT> ) ) ; } return true ; } else if ( keyCode == KeyEvent . KEYCODE_VOLUME_UP ) { if ( action == KeyEvent . ACTION_UP ) { int topPositionY = listView . getChildAt ( <NUM_LIT:0> ) . getTop ( ) ; WindowManager wm = ( WindowManager ) getSystemService ( Context . WINDOW_SERVICE ) ; Display disp = wm . getDefaultDisplay ( ) ; int height = disp . getHeight ( ) ; listView . setSelectionFromTop ( listView . getFirstVisiblePosition ( ) , topPositionY + ( height - <NUM_LIT> ) ) ; } return true ; } return super . dispatchKeyEvent ( event ) ; } @ Override public void onConfigurationChanged ( Configuration newConfig ) { super . onConfigurationChanged ( newConfig ) ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import org . apache . http . client . CookieStore ; import org . apache . http . cookie . Cookie ; import org . apache . http . impl . client . DefaultHttpClient ; import android . util . Log ; import java . util . List ; public class FutabaCookieManager { static List < Cookie > data = null ; public static void saveCookie ( DefaultHttpClient httpClient ) { data = httpClient . getCookieStore ( ) . getCookies ( ) ; } public static void loadCookie ( DefaultHttpClient httpClient ) { if ( data != null ) { FLog . d ( "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < data . size ( ) ; i ++ ) { FLog . d ( "<STR_LIT>" + data . get ( i ) . toString ( ) ) ; httpClient . getCookieStore ( ) . addCookie ( data . get ( i ) ) ; } } } public static void PrintCookie ( ) { if ( data == null || data . isEmpty ( ) ) { FLog . d ( "<STR_LIT>" ) ; } else { FLog . d ( "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < data . size ( ) ; i ++ ) { FLog . d ( "<STR_LIT>" + data . get ( i ) . toString ( ) ) ; } } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . util . HashMap ; import android . app . Activity ; import android . graphics . Bitmap ; import android . util . Log ; import java . util . Iterator ; import java . io . ByteArrayOutputStream ; import java . io . File ; import java . net . URL ; public class ImageCache { public static Bitmap getImage ( String url ) { String urlHash = FutabaCrypt . createDigest ( url ) ; try { if ( SDCard . cacheExist ( urlHash ) ) { return SDCard . loadBitmapCache ( urlHash ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return null ; } private static byte [ ] bmp2data ( Bitmap src , Bitmap . CompressFormat format , int quality ) { ByteArrayOutputStream os = new ByteArrayOutputStream ( ) ; src . compress ( format , quality , os ) ; return os . toByteArray ( ) ; } public static boolean setImage ( String url ) { String urlHash = FutabaCrypt . createDigest ( url ) ; try { SDCard . saveFromURL ( urlHash , new URL ( url ) , true ) ; return true ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return false ; } public static boolean setImageFromBitmap ( String url , Bitmap bmp ) { String urlHash = FutabaCrypt . createDigest ( url ) ; byte [ ] bytes = bmp2data ( bmp , Bitmap . CompressFormat . PNG , <NUM_LIT:100> ) ; try { SDCard . saveBin ( urlHash , bytes , true ) ; return true ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return false ; } public static File saveImage ( String url ) { String urlHash = FutabaCrypt . createDigest ( url ) ; File file = new File ( url ) ; if ( SDCard . cacheExist ( urlHash ) ) { try { return SDCard . copyCacheToFile ( urlHash , file . getName ( ) ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } else { } return null ; } public static File saveImageToThread ( String url , String threadName ) { String urlHash = FutabaCrypt . createDigest ( url ) ; File file = new File ( url ) ; if ( SDCard . cacheExist ( urlHash ) ) { try { return SDCard . copyCacheToThreadFile ( urlHash , file . getName ( ) , threadName ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } else { } return null ; } public static void GC ( ) { } } </s>
<s> package cx . ath . dekosuke . ftbt ; import android . content . Context ; import android . content . SharedPreferences ; import android . content . SharedPreferences . Editor ; import android . preference . PreferenceManager ; public class StateMan { private final static String PREFNAME = "<STR_LIT>" ; private final static String SORTKEY = "<STR_LIT>" ; public static int getSortParam ( Context context ) { SharedPreferences pref = context . getSharedPreferences ( PREFNAME , Context . MODE_PRIVATE ) ; int sorttype = pref . getInt ( SORTKEY , <NUM_LIT:0> ) ; return sorttype ; } public static void setSortParam ( Context context , int i ) { SharedPreferences pref = context . getSharedPreferences ( PREFNAME , Context . MODE_PRIVATE ) ; Editor e = pref . edit ( ) ; e . putInt ( SORTKEY , i ) ; e . commit ( ) ; } private static int getFontSizeSetting ( Context context ) { int fontSizeSetting = <NUM_LIT:0> ; try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; fontSizeSetting = Integer . parseInt ( preferences . getString ( "<STR_LIT>" , "<STR_LIT:0>" ) ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; return <NUM_LIT:0> ; } return fontSizeSetting ; } public static float getMainFontSize ( Context context ) { int fontSizeSetting = getFontSizeSetting ( context ) ; return <NUM_LIT> + fontSizeSetting ; } public static float getDescFontSize ( Context context ) { int fontSizeSetting = getFontSizeSetting ( context ) ; return <NUM_LIT> + fontSizeSetting ; } public static float getBBSFontSize ( Context context ) { int fontSizeSetting = getFontSizeSetting ( context ) ; return <NUM_LIT> + fontSizeSetting * <NUM_LIT> ; } public static float getBBSDescFontSize ( Context context ) { int fontSizeSetting = getFontSizeSetting ( context ) ; return <NUM_LIT> + fontSizeSetting * <NUM_LIT> ; } public static float getTabFontSize ( Context context ) { int fontSizeSetting = getFontSizeSetting ( context ) ; return <NUM_LIT> + fontSizeSetting ; } public static boolean getVerticalThreadRow ( Context context ) { boolean verticalThreadRow = false ; try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; verticalThreadRow = ! preferences . getBoolean ( "<STR_LIT>" , false ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; return false ; } FLog . d ( "<STR_LIT>" + verticalThreadRow ) ; return verticalThreadRow ; } public static int getThreadRowResourceId ( Context context ) { if ( getVerticalThreadRow ( context ) ) { return R . layout . futaba_thread_row ; } else { return R . layout . futaba_thread_row_yoko ; } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . util . ArrayList ; import android . view . View ; import android . widget . AdapterView ; import android . widget . Button ; import android . widget . LinearLayout ; import android . widget . ListView ; import android . widget . TextView ; import android . widget . Toast ; import android . graphics . Typeface ; import android . view . ViewGroup ; import android . widget . ArrayAdapter ; import android . content . Context ; import android . view . LayoutInflater ; import android . util . Log ; import android . os . AsyncTask ; import android . content . Intent ; import java . io . InputStream ; import java . net . URL ; import java . io . ByteArrayOutputStream ; import java . io . BufferedOutputStream ; import java . io . IOException ; import java . io . BufferedInputStream ; import java . io . OutputStream ; import java . net . HttpURLConnection ; import android . graphics . Bitmap ; import android . graphics . BitmapFactory ; import android . widget . ImageView ; import android . view . WindowManager ; import android . content . Context ; import android . view . Display ; import java . lang . Thread ; public class FutabaBBSMenuAdapter extends ArrayAdapter { public ArrayList items ; private LayoutInflater inflater ; public FutabaBBSMenuAdapter ( Context context , int textViewResourceId , ArrayList items ) { super ( context , textViewResourceId , items ) ; try { this . items = items ; this . inflater = ( LayoutInflater ) context . getSystemService ( Context . LAYOUT_INFLATER_SERVICE ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } @ Override public View getView ( int position , View convertView , ViewGroup parent ) { View view = convertView ; try { if ( view == null ) { view = inflater . inflate ( R . layout . futaba_bbs_row , null ) ; } final FutabaBBSContent item = ( FutabaBBSContent ) items . get ( position ) ; if ( item != null ) { TextView url = ( TextView ) view . findViewById ( R . id . url ) ; url . setTextSize ( StateMan . getBBSDescFontSize ( getContext ( ) ) ) ; url . setText ( item . url ) ; TextView name = ( TextView ) view . findViewById ( R . id . name ) ; name . setTextSize ( StateMan . getBBSFontSize ( getContext ( ) ) ) ; name . setText ( item . name ) ; final Button buttonFavorite = ( Button ) view . findViewById ( R . id . favorite_btn ) ; final FutabaBBSMenu activity = ( FutabaBBSMenu ) getContext ( ) ; if ( true ) { if ( ! item . faved ) { buttonFavorite . setBackgroundDrawable ( getContext ( ) . getResources ( ) . getDrawable ( R . drawable . star_big_off ) ) ; } else { buttonFavorite . setBackgroundDrawable ( getContext ( ) . getResources ( ) . getDrawable ( R . drawable . star_big_on ) ) ; } } else { buttonFavorite . setVisibility ( View . GONE ) ; } final ViewGroup view_parent = parent ; buttonFavorite . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { if ( activity . mode . equals ( "<STR_LIT:all>" ) ) { if ( ! item . faved ) { ftbt ftbt_top = ( ftbt ) activity . getParent ( ) ; item . faved = true ; ftbt_top . addFavoriteBBSs ( item ) ; FutabaBBSMenu activity = ( FutabaBBSMenu ) getContext ( ) ; activity . adapter . notifyDataSetChanged ( ) ; Toast . makeText ( activity , item . name + "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } else { ftbt ftbt_top = ( ftbt ) activity . getParent ( ) ; item . faved = false ; ftbt_top . removeFavoriteBBSs ( item ) ; Toast . makeText ( activity , item . name + "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } } else { ftbt ftbt_top = ( ftbt ) activity . getParent ( ) ; item . faved = false ; ftbt_top . removeFavoriteBBSs ( item ) ; Toast . makeText ( activity , item . name + "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; } view_parent . invalidate ( ) ; notifyDataSetChanged ( ) ; } } ) ; LinearLayout ll_main = ( LinearLayout ) view . findViewById ( R . id . ll_main ) ; ll_main . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { FLog . d ( "<STR_LIT>" ) ; FutabaBBSMenu activity = ( FutabaBBSMenu ) getContext ( ) ; activity . transSetting ( item ) ; } } ) ; } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } return view ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStreamReader ; import android . util . Log ; public class FileToString { public static String fileToString ( File file , String encoding ) throws IOException { BufferedReader br = null ; try { br = new BufferedReader ( new InputStreamReader ( new FileInputStream ( file ) , encoding ) ) ; StringBuffer sb = new StringBuffer ( ) ; int c ; while ( ( c = br . read ( ) ) != - <NUM_LIT:1> ) { sb . append ( ( char ) c ) ; } return sb . toString ( ) ; } finally { br . close ( ) ; } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . IOException ; import java . util . ArrayList ; import android . content . Context ; import android . view . LayoutInflater ; import android . view . View ; import android . view . ViewGroup ; import android . widget . ArrayAdapter ; import android . widget . Button ; import android . widget . TextView ; import android . widget . Toast ; public class FocusEditAdapter extends ArrayAdapter { public ArrayList < String > items ; private LayoutInflater inflater ; private Context context ; public FocusEditAdapter ( Context context , int textViewResourceId , ArrayList items ) { super ( context , textViewResourceId , items ) ; this . items = ( ArrayList < String > ) items ; this . context = context ; this . inflater = ( LayoutInflater ) context . getSystemService ( Context . LAYOUT_INFLATER_SERVICE ) ; } @ Override public View getView ( int position , View convertView , ViewGroup parent ) { View view = convertView ; if ( view == null ) { view = inflater . inflate ( R . layout . focuswords_row , null ) ; } final String item = ( String ) items . get ( position ) ; view = inflater . inflate ( R . layout . focuswords_row , null ) ; TextView word_v = ( TextView ) view . findViewById ( R . id . word ) ; word_v . setText ( item ) ; final FocusEditAdapter adapter = this ; final int position_f = position ; Button delWordButton = ( Button ) view . findViewById ( R . id . delword ) ; delWordButton . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { try { adapter . deleteAt ( position_f ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ) ; return view ; } public void deleteAt ( int position ) { String text = this . items . get ( position ) ; this . items . remove ( position ) ; notifyDataSetChanged ( ) ; try { FocusedSettings . set ( getContext ( ) , this . items ) ; } catch ( IOException e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } Toast . makeText ( getContext ( ) , "<STR_LIT>" + text + "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } public void addLast ( String elem ) { this . items . add ( elem ) ; this . notifyDataSetChanged ( ) ; try { FocusedSettings . set ( getContext ( ) , this . items ) ; } catch ( IOException e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . Serializable ; public class FutabaThreadContent implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; public String userName ; public String title ; public String text ; public String mailTo ; public int id ; public String imgURL ; public int threadNum ; public int threadNumPrev ; public String baseUrl ; public String resNum ; public String BBSName ; public int pointAt ; public int seeAt ; public long lastAccessed ; public boolean isChecked = false ; FutabaThreadContent ( ) { userName = "<STR_LIT>" ; title = "<STR_LIT>" ; text = "<STR_LIT>" ; mailTo = "<STR_LIT>" ; id = <NUM_LIT:0> ; resNum = "<STR_LIT>" ; BBSName = "<STR_LIT>" ; baseUrl = "<STR_LIT>" ; resNum = "<STR_LIT:0>" ; lastAccessed = <NUM_LIT:0> ; pointAt = <NUM_LIT:0> ; seeAt = <NUM_LIT:0> ; } public String toString ( ) { return "<STR_LIT>" + userName + "<STR_LIT>" + title + "<STR_LIT>" + text + "<STR_LIT>" + mailTo + "<STR_LIT>" + id + "<STR_LIT>" + imgURL + "<STR_LIT>" + threadNum + "<STR_LIT>" + baseUrl + "<STR_LIT>" + resNum + "<STR_LIT>" + BBSName + "<STR_LIT>" + lastAccessed + "<STR_LIT>" + isChecked + "<STR_LIT>" + pointAt ; } public static FutabaThreadContent createBlank ( ) { FutabaThreadContent st = new FutabaThreadContent ( ) ; st . id = - <NUM_LIT:1> ; return st ; } public static boolean isBlank ( FutabaThreadContent thread ) { return thread . id == - <NUM_LIT:1> ; } public static FutabaThreadContent createMenu1 ( ) { FutabaThreadContent st = new FutabaThreadContent ( ) ; st . text = "<STR_LIT>" ; st . id = - <NUM_LIT:2> ; return st ; } public static FutabaThreadContent createMenu2 ( ) { FutabaThreadContent st = new FutabaThreadContent ( ) ; st . text = "<STR_LIT>" ; st . id = - <NUM_LIT:3> ; return st ; } public static boolean isMenu1 ( FutabaThreadContent st ) { return st . id == - <NUM_LIT:2> ; } public static boolean isMenu2 ( FutabaThreadContent st ) { return st . id == - <NUM_LIT:3> ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . io . UnsupportedEncodingException ; import java . util . ArrayList ; import java . util . List ; import org . apache . http . HttpResponse ; import org . apache . http . HttpStatus ; import org . apache . http . NameValuePair ; import org . apache . http . client . ClientProtocolException ; import org . apache . http . client . entity . UrlEncodedFormEntity ; import org . apache . http . client . methods . HttpGet ; import org . apache . http . client . methods . HttpPost ; import org . apache . http . client . params . ClientPNames ; import org . apache . http . client . params . CookiePolicy ; import org . apache . http . impl . client . DefaultHttpClient ; import org . apache . http . message . BasicNameValuePair ; import android . content . Context ; import android . content . SharedPreferences ; import android . preference . PreferenceManager ; import android . util . Log ; import android . webkit . CookieManager ; public class CatalogHtmlReader { public static String Read ( String urlStr , Context context , int sortType ) throws Exception { CookieManager . getInstance ( ) . setAcceptCookie ( true ) ; CookieManager . getInstance ( ) . removeExpiredCookie ( ) ; int catalogX = <NUM_LIT:10> ; int catalogY = <NUM_LIT:5> ; String threadStrNum = "<STR_LIT>" ; try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( context ) ; int temp = Integer . parseInt ( preferences . getString ( "<STR_LIT>" , "<STR_LIT>" ) ) ; catalogX = temp / <NUM_LIT:5> ; threadStrNum = preferences . getString ( "<STR_LIT>" , "<STR_LIT>" ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } DefaultHttpClient httpClient ; httpClient = new DefaultHttpClient ( ) ; FutabaCookieManager . loadCookie ( httpClient ) ; httpClient . getParams ( ) . setParameter ( ClientPNames . COOKIE_POLICY , CookiePolicy . BROWSER_COMPATIBILITY ) ; httpClient . getParams ( ) . setParameter ( "<STR_LIT>" , <NUM_LIT> ) ; httpClient . getParams ( ) . setParameter ( "<STR_LIT>" , <NUM_LIT> ) ; HttpPost httppost = new HttpPost ( urlStr ) ; List < NameValuePair > nameValuePair = new ArrayList < NameValuePair > ( <NUM_LIT:4> ) ; nameValuePair . add ( new BasicNameValuePair ( "<STR_LIT>" , "<STR_LIT>" ) ) ; nameValuePair . add ( new BasicNameValuePair ( "<STR_LIT>" , String . valueOf ( catalogX ) ) ) ; nameValuePair . add ( new BasicNameValuePair ( "<STR_LIT>" , String . valueOf ( catalogY ) ) ) ; nameValuePair . add ( new BasicNameValuePair ( "<STR_LIT>" , threadStrNum ) ) ; String urlStrAppend = urlStr + "<STR_LIT>" ; if ( sortType > <NUM_LIT:0> && sortType < <NUM_LIT:5> ) { urlStrAppend += "<STR_LIT>" + sortType ; } String data = null ; httppost . setEntity ( new UrlEncodedFormEntity ( nameValuePair ) ) ; HttpResponse response = httpClient . execute ( httppost ) ; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; response . getEntity ( ) . writeTo ( byteArrayOutputStream ) ; HttpGet httpget = new HttpGet ( urlStrAppend ) ; HttpResponse httpResponse = null ; httpResponse = httpClient . execute ( httpget ) ; FutabaCookieManager . saveCookie ( httpClient ) ; int status = httpResponse . getStatusLine ( ) . getStatusCode ( ) ; if ( HttpStatus . SC_OK == status ) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; httpResponse . getEntity ( ) . writeTo ( outputStream ) ; SDCard . saveBin ( FutabaCrypt . createDigest ( urlStr ) , outputStream . toByteArray ( ) , true ) ; data = outputStream . toString ( "<STR_LIT>" ) ; } else { FLog . d ( "<STR_LIT>" + status ) ; throw new Exception ( "<STR_LIT>" ) ; } return data ; } } </s>
<s> package cx . ath . dekosuke . ftbt ; import java . io . ByteArrayOutputStream ; import java . io . File ; import java . io . InputStream ; import java . net . URI ; import java . net . URL ; import java . nio . charset . Charset ; import java . util . ArrayList ; import java . util . List ; import org . apache . http . Header ; import org . apache . http . HttpResponse ; import org . apache . http . NameValuePair ; import org . apache . http . client . CookieStore ; import org . apache . http . client . entity . UrlEncodedFormEntity ; import org . apache . http . client . methods . HttpGet ; import org . apache . http . client . methods . HttpPost ; import org . apache . http . client . params . ClientPNames ; import org . apache . http . client . params . CookiePolicy ; import org . apache . http . cookie . Cookie ; import org . apache . http . impl . client . DefaultHttpClient ; import org . apache . http . message . BasicNameValuePair ; import cx . ath . dekosuke . ftbt . R . id ; import android . app . Activity ; import android . app . AlertDialog ; import android . app . ProgressDialog ; import android . content . DialogInterface ; import android . content . Intent ; import android . content . SharedPreferences ; import android . database . Cursor ; import android . graphics . Bitmap ; import android . graphics . BitmapFactory ; import android . graphics . Color ; import android . net . Uri ; import android . os . Bundle ; import android . os . Handler ; import android . os . Message ; import android . preference . PreferenceManager ; import android . provider . MediaStore ; import android . util . Log ; import android . view . View ; import android . view . Window ; import android . view . WindowManager ; import android . webkit . CookieManager ; import android . webkit . CookieSyncManager ; import android . widget . Button ; import android . widget . EditText ; import android . widget . TableLayout ; import android . widget . TextView ; import android . widget . Toast ; import org . apache . http . entity . mime . HttpMultipartMode ; import org . apache . http . entity . mime . MultipartEntity ; import org . apache . http . entity . mime . content . FileBody ; import org . apache . http . entity . mime . content . StringBody ; public class Post extends Activity implements Runnable { public String urlStr ; public int threadNum ; public String threadURL ; public String postText ; ProgressDialog waitDialog ; Thread thread ; final int REQUEST_IMAGEPICK_CONSTANT = <NUM_LIT> ; Uri imageContent = null ; boolean newthread = false ; @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; if ( getResources ( ) . getBoolean ( R . bool . avoidsleep ) ) { Window window = getWindow ( ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ; } try { FLog . d ( "<STR_LIT>" ) ; Intent intent = getIntent ( ) ; String baseURL = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; threadNum = ( Integer ) intent . getSerializableExtra ( "<STR_LIT>" ) ; postText = ( String ) intent . getSerializableExtra ( "<STR_LIT>" ) ; if ( threadNum == <NUM_LIT:0> ) { newthread = true ; } if ( newthread ) { threadURL = baseURL ; } else { threadURL = baseURL + threadNum ; } urlStr = baseURL + "<STR_LIT>" ; setContentView ( R . layout . post ) ; TextView titleText = ( TextView ) findViewById ( id . titletext ) ; if ( newthread ) { titleText . setText ( "<STR_LIT>" ) ; } EditText comment_v = ( EditText ) findViewById ( id . comment ) ; if ( postText != null ) { comment_v . setText ( postText ) ; comment_v . setSelection ( postText . length ( ) ) ; } String deleteKey = "<STR_LIT>" ; try { SharedPreferences preferences = PreferenceManager . getDefaultSharedPreferences ( this ) ; deleteKey = preferences . getString ( getString ( R . string . deletekey ) , "<STR_LIT>" ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } if ( ! deleteKey . equals ( "<STR_LIT>" ) ) { TextView deleteKey_v = ( TextView ) findViewById ( id . deletekey ) ; deleteKey_v . setText ( deleteKey ) ; } FLog . d ( "<STR_LIT>" + deleteKey ) ; Button postbutton = ( Button ) findViewById ( id . postbutton ) ; postbutton . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { onClickPostButton ( v ) ; } } ) ; Button imgchoosebutton = ( Button ) findViewById ( id . imgchoosebutton ) ; imgchoosebutton . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { onClickImageChooseButton ( v ) ; } } ) ; CookieSyncManager . createInstance ( this ) ; CookieSyncManager . getInstance ( ) . startSync ( ) ; FutabaCookieManager . PrintCookie ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } @ Override protected void onResume ( ) { super . onResume ( ) ; CookieSyncManager . getInstance ( ) . stopSync ( ) ; } @ Override protected void onPause ( ) { super . onPause ( ) ; CookieSyncManager . getInstance ( ) . sync ( ) ; } public void setWait ( ) { waitDialog = new ProgressDialog ( this ) ; waitDialog . setMessage ( this . getString ( R . string . loading ) ) ; waitDialog . setProgressStyle ( ProgressDialog . STYLE_SPINNER ) ; waitDialog . show ( ) ; thread = new Thread ( this ) ; thread . start ( ) ; } public void run ( ) { try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( InterruptedException e ) { } handler . sendEmptyMessage ( <NUM_LIT:0> ) ; } private Handler handler = new Handler ( ) { public void handleMessage ( Message msg ) { try { loading ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } } ; public void onClickPostButton ( View v ) { AlertDialog . Builder dlg ; dlg = new AlertDialog . Builder ( Post . this ) ; dlg . setTitle ( "<STR_LIT>" ) ; dlg . setCancelable ( true ) ; dlg . setMessage ( "<STR_LIT>" ) ; dlg . setPositiveButton ( "<STR_LIT:OK>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { Post . this . setWait ( ) ; } } ) ; dlg . setNegativeButton ( "<STR_LIT>" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int id ) { } } ) ; dlg . show ( ) ; } public void onClickImageChooseButton ( View v ) { Intent intent = new Intent ( Intent . ACTION_PICK ) ; intent . setType ( "<STR_LIT>" ) ; startActivityForResult ( intent , REQUEST_IMAGEPICK_CONSTANT ) ; } protected void onActivityResult ( int requestCode , int resultCode , Intent data ) { if ( resultCode == RESULT_OK && requestCode == REQUEST_IMAGEPICK_CONSTANT ) { Toast . makeText ( this , "<STR_LIT>" + data . getData ( ) , Toast . LENGTH_SHORT ) . show ( ) ; imageContent = data . getData ( ) ; Button imgchoosebutton = ( Button ) findViewById ( id . imgchoosebutton ) ; imgchoosebutton . setVisibility ( View . GONE ) ; TextView imgchoosenotify = ( TextView ) findViewById ( id . imgchoosenotify ) ; imgchoosenotify . setText ( "<STR_LIT>" + imageContent . toString ( ) ) ; imgchoosenotify . setTextColor ( Color . RED ) ; } } private void loading ( ) { TextView name_v = ( TextView ) findViewById ( id . name ) ; String name = name_v . getText ( ) . toString ( ) ; TextView email_v = ( TextView ) findViewById ( id . email ) ; String email = email_v . getText ( ) . toString ( ) ; TextView comment_v = ( TextView ) findViewById ( id . comment ) ; String comment = comment_v . getText ( ) . toString ( ) ; TextView deletekey_v = ( TextView ) findViewById ( id . deletekey ) ; String deletekey = deletekey_v . getText ( ) . toString ( ) ; FLog . d ( "<STR_LIT>" + threadNum ) ; FLog . d ( "<STR_LIT>" + urlStr ) ; FLog . d ( "<STR_LIT>" + comment ) ; FLog . d ( "<STR_LIT>" + deletekey ) ; FLog . d ( "<STR_LIT>" + email ) ; FLog . d ( "<STR_LIT>" + name ) ; FLog . d ( "<STR_LIT>" + threadURL ) ; if ( false ) { return ; } try { FLog . d ( "<STR_LIT>" ) ; DefaultHttpClient httpClient ; httpClient = new DefaultHttpClient ( ) ; FutabaCookieManager . loadCookie ( httpClient ) ; httpClient . getParams ( ) . setParameter ( ClientPNames . COOKIE_POLICY , CookiePolicy . BROWSER_COMPATIBILITY ) ; httpClient . getParams ( ) . setParameter ( "<STR_LIT>" , <NUM_LIT> ) ; httpClient . getParams ( ) . setParameter ( "<STR_LIT>" , <NUM_LIT> ) ; try { { List < Cookie > cookies = httpClient . getCookieStore ( ) . getCookies ( ) ; if ( true ) { FLog . d ( "<STR_LIT>" ) ; Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_SHORT ) . show ( ) ; HttpGet httpGet = new HttpGet ( urlStr ) ; HttpResponse httpResponse = null ; httpResponse = httpClient . execute ( httpGet ) ; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; httpResponse . getEntity ( ) . writeTo ( byteArrayOutputStream ) ; String retData = byteArrayOutputStream . toString ( "<STR_LIT>" ) ; FutabaCookieManager . saveCookie ( httpClient ) ; FLog . d ( retData ) ; FLog . d ( "<STR_LIT>" ) ; try { Thread . sleep ( <NUM_LIT> ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } } else { for ( int i = <NUM_LIT:0> ; i < cookies . size ( ) ; i ++ ) { FLog . d ( "<STR_LIT>" + cookies . get ( i ) . toString ( ) ) ; } } } } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } HttpPost httppost = new HttpPost ( urlStr ) ; if ( false ) { } MultipartEntity entity = new MultipartEntity ( HttpMultipartMode . BROWSER_COMPATIBLE ) ; Charset sjisCharset = Charset . forName ( "<STR_LIT>" ) ; entity . addPart ( "<STR_LIT:email>" , new StringBody ( email , sjisCharset ) ) ; entity . addPart ( "<STR_LIT:name>" , new StringBody ( name , sjisCharset ) ) ; entity . addPart ( "<STR_LIT>" , new StringBody ( "<STR_LIT>" ) ) ; if ( ! newthread ) { entity . addPart ( "<STR_LIT>" , new StringBody ( "<STR_LIT>" + threadNum ) ) ; } entity . addPart ( "<STR_LIT>" , new StringBody ( comment , sjisCharset ) ) ; entity . addPart ( "<STR_LIT>" , new StringBody ( "<STR_LIT>" ) ) ; entity . addPart ( "<STR_LIT>" , new StringBody ( deletekey ) ) ; if ( imageContent != null ) { FLog . d ( "<STR_LIT>" + imageContent ) ; FLog . d ( "<STR_LIT>" + imageContent . getPath ( ) ) ; Cursor c = getContentResolver ( ) . query ( imageContent , null , null , null , null ) ; c . moveToFirst ( ) ; String filename = c . getString ( c . getColumnIndex ( MediaStore . MediaColumns . DATA ) ) ; FLog . d ( "<STR_LIT>" + filename ) ; FileBody fileBody = new FileBody ( new File ( filename ) ) ; entity . addPart ( "<STR_LIT>" , fileBody ) ; } httppost . setEntity ( entity ) ; httppost . addHeader ( "<STR_LIT>" , threadURL ) ; HttpResponse response = httpClient . execute ( httppost ) ; FutabaCookieManager . saveCookie ( httpClient ) ; ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream ( ) ; response . getEntity ( ) . writeTo ( byteArrayOutputStream2 ) ; String retData2 = byteArrayOutputStream2 . toString ( "<STR_LIT>" ) ; Log . v ( "<STR_LIT>" , retData2 ) ; FLog . d ( "<STR_LIT>" ) ; PostParser parser = new PostParser ( ) ; String contents = parser . parse ( this , retData2 ) ; if ( ! contents . equals ( "<STR_LIT>" ) ) { Toast . makeText ( this , contents , Toast . LENGTH_LONG ) . show ( ) ; } else { Toast . makeText ( this , "<STR_LIT>" , Toast . LENGTH_LONG ) . show ( ) ; } setOnReturn ( ) ; } catch ( Exception e ) { FLog . d ( "<STR_LIT:message>" , e ) ; } waitDialog . dismiss ( ) ; finish ( ) ; } public void setOnReturn ( ) { Intent ret_i = new Intent ( ) ; ret_i . putExtra ( "<STR_LIT>" , "<STR_LIT:true>" ) ; setResult ( RESULT_OK , ret_i ) ; } } </s>
<s> import java . net . URL ; import java . util . ArrayList ; import java . util . Map ; import java . util . HashMap ; import com . shotgunsoftware . * ; class UpdateExample { public static void main ( String [ ] args ) { try { URL u = new URL ( "<STR_LIT>" ) ; Shotgun s = new Shotgun ( u , "<STR_LIT>" , "<STR_LIT>" ) ; HashMap asset = new HashMap ( ) ; asset . put ( "<STR_LIT:type>" , "<STR_LIT>" ) ; asset . put ( "<STR_LIT:id>" , new Integer ( <NUM_LIT> ) ) ; ArrayList l = new ArrayList ( ) ; l . add ( asset ) ; HashMap data = new HashMap ( ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , l ) ; HashMap modes = new HashMap ( ) ; modes . put ( "<STR_LIT>" , "<STR_LIT>" ) ; UpdateRequest ur = new UpdateRequest ( "<STR_LIT>" , new Integer ( <NUM_LIT> ) ) ; ur . setData ( data ) ; ur . setMultiEntityUpdateModes ( modes ) ; Map r = s . update ( ur ) ; Object [ ] assets = ( Object [ ] ) r . get ( "<STR_LIT>" ) ; System . out . println ( java . util . Arrays . toString ( assets ) ) ; modes . put ( "<STR_LIT>" , "<STR_LIT>" ) ; r = s . update ( ur ) ; assets = ( Object [ ] ) r . get ( "<STR_LIT>" ) ; System . out . println ( java . util . Arrays . toString ( assets ) ) ; modes . put ( "<STR_LIT>" , "<STR_LIT>" ) ; r = s . update ( ur ) ; assets = ( Object [ ] ) r . get ( "<STR_LIT>" ) ; System . out . println ( java . util . Arrays . toString ( assets ) ) ; HashMap parents = new HashMap ( ) ; parents . put ( "<STR_LIT>" , asset ) ; data = new HashMap ( ) ; data . put ( "<STR_LIT>" , "<STR_LIT:test>" ) ; ur = new UpdateRequest ( "<STR_LIT>" , new Integer ( <NUM_LIT> ) ) ; ur . setData ( data ) ; ur . setMultiEntityParents ( parents ) ; r = s . update ( ur ) ; System . out . println ( r ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } } } </s>
<s> import java . net . URL ; import java . util . List ; import com . shotgunsoftware . * ; class FindExample { public static void main ( String [ ] args ) { try { URL u = new URL ( "<STR_LIT>" ) ; Shotgun s = new Shotgun ( u , "<STR_LIT>" , "<STR_LIT>" ) ; FindRequest fr = new FindRequest ( "<STR_LIT>" ) ; fr . setFields ( new String [ ] { "<STR_LIT:code>" , "<STR_LIT>" } ) ; Condition descCond = new Condition ( "<STR_LIT:description>" , "<STR_LIT>" , new Object [ ] { null } ) ; fr . setCondition ( descCond ) ; fr . setSort ( new Sort ( "<STR_LIT:code>" , false ) ) ; List recs = s . find ( fr ) ; System . out . println ( "<STR_LIT>" + recs . size ( ) + "<STR_LIT>" ) ; Condition statusCond = new Condition ( "<STR_LIT>" , "<STR_LIT>" , new Object [ ] { "<STR_LIT>" } ) ; ConditionGroup cg = new ConditionGroup ( ) ; cg . addCondition ( descCond ) ; cg . addCondition ( statusCond ) ; fr . setConditions ( cg ) ; recs = s . find ( fr ) ; System . out . println ( "<STR_LIT>" + recs . size ( ) + "<STR_LIT>" ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } } } </s>
<s> import java . net . URL ; import java . util . Map ; import java . util . HashMap ; import com . shotgunsoftware . * ; class CreateDeleteExample { public static void main ( String [ ] args ) { try { URL u = new URL ( "<STR_LIT>" ) ; Shotgun s = new Shotgun ( u , "<STR_LIT>" , "<STR_LIT>" ) ; HashMap asset = new HashMap ( ) ; asset . put ( "<STR_LIT:type>" , "<STR_LIT>" ) ; asset . put ( "<STR_LIT:id>" , new Integer ( <NUM_LIT> ) ) ; HashMap step = new HashMap ( ) ; step . put ( "<STR_LIT:type>" , "<STR_LIT>" ) ; step . put ( "<STR_LIT:id>" , new Integer ( <NUM_LIT:10> ) ) ; HashMap project = new HashMap ( ) ; project . put ( "<STR_LIT:type>" , "<STR_LIT>" ) ; project . put ( "<STR_LIT:id>" , new Integer ( <NUM_LIT> ) ) ; HashMap data = new HashMap ( ) ; data . put ( "<STR_LIT:content>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , asset ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , step ) ; data . put ( "<STR_LIT>" , project ) ; CreateRequest cr = new CreateRequest ( "<STR_LIT>" ) ; cr . setData ( data ) ; Map r = s . create ( cr ) ; Integer id = ( Integer ) r . get ( "<STR_LIT:id>" ) ; System . out . println ( "<STR_LIT>" + id . toString ( ) ) ; System . out . println ( r ) ; DeleteRequest dr = new DeleteRequest ( "<STR_LIT>" , id ) ; boolean didDelete = s . delete ( dr ) ; if ( didDelete ) { System . out . println ( "<STR_LIT>" + id . toString ( ) ) ; } didDelete = s . delete ( dr ) ; if ( ! didDelete ) { System . out . println ( "<STR_LIT>" + id . toString ( ) + "<STR_LIT>" ) ; } } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } } } </s>
<s> package com . shotgunsoftware ; import java . util . Map ; import java . util . HashMap ; public class UpdateRequest { String entityType ; Integer entityId ; Map data ; Map multiEntityUpdateModes ; Map multiEntityParents ; public UpdateRequest ( String entityType , Integer entityId ) { this . entityType = entityType ; this . entityId = entityId ; this . data = new HashMap ( ) ; this . multiEntityUpdateModes = new HashMap ( ) ; this . multiEntityParents = new HashMap ( ) ; } public void setData ( Map data ) { this . data = data ; } public void setMultiEntityUpdateModes ( Map modes ) { this . multiEntityUpdateModes = modes ; } public void setMultiEntityParents ( Map parents ) { this . multiEntityParents = parents ; } } </s>
<s> package com . shotgunsoftware ; public class Sort { String fieldName ; boolean ascending ; public Sort ( String fieldName ) { this ( fieldName , true ) ; } public Sort ( String fieldName , boolean ascending ) { this . fieldName = fieldName ; this . ascending = ascending ; } } </s>
<s> package com . shotgunsoftware ; import java . net . URL ; import java . util . List ; import java . util . ArrayList ; import java . util . Map ; import java . util . Map . Entry ; import java . util . HashMap ; import java . util . Iterator ; import org . apache . xmlrpc . client . * ; import org . apache . xmlrpc . common . * ; import org . apache . xmlrpc . parser . * ; import org . apache . xmlrpc . serializer . NullSerializer ; import org . apache . ws . commons . util . NamespaceContextImpl ; import org . apache . xmlrpc . XmlRpcException ; public class Shotgun { private Map auth ; private XmlRpcClient client ; public Shotgun ( URL url , String script_name , String script_key ) { this . auth = new HashMap ( ) ; this . auth . put ( "<STR_LIT>" , script_name ) ; this . auth . put ( "<STR_LIT>" , script_key ) ; XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl ( ) ; config . setServerURL ( url ) ; config . setEnabledForExtensions ( true ) ; this . client = new XmlRpcClient ( ) ; client . setConfig ( config ) ; client . setTypeFactory ( new MyTypeFactory ( client ) ) ; } public List find ( FindRequest fr ) throws XmlRpcException { HashMap req = new HashMap ( ) ; req . put ( "<STR_LIT:type>" , fr . entityType ) ; req . put ( "<STR_LIT>" , fr . returnFields ) ; req . put ( "<STR_LIT>" , fr . conditions . toHash ( ) ) ; List sorts = new ArrayList ( ) ; for ( int i = <NUM_LIT:0> ; i < fr . sorts . length ; i ++ ) { Map sort = new HashMap ( ) ; sort . put ( "<STR_LIT>" , fr . sorts [ i ] . fieldName ) ; sort . put ( "<STR_LIT>" , fr . sorts [ i ] . ascending ? "<STR_LIT>" : "<STR_LIT>" ) ; sorts . add ( sort ) ; } if ( fr . sorts != null ) req . put ( "<STR_LIT>" , sorts ) ; int currentPage = <NUM_LIT:1> ; HashMap paging = new HashMap ( ) ; paging . put ( "<STR_LIT>" , new Integer ( <NUM_LIT> ) ) ; paging . put ( "<STR_LIT>" , new Integer ( currentPage ) ) ; req . put ( "<STR_LIT>" , paging ) ; Object [ ] params = new Object [ ] { this . auth , req } ; boolean done = false ; List records = new ArrayList ( ) ; while ( ! done ) { Map response = ( Map ) this . client . execute ( "<STR_LIT>" , params ) ; Map result = ( Map ) response . get ( "<STR_LIT>" ) ; Map pagingInfo = ( Map ) result . get ( "<STR_LIT>" ) ; Object [ ] entities = ( Object [ ] ) result . get ( "<STR_LIT>" ) ; Integer entityCount = ( Integer ) pagingInfo . get ( "<STR_LIT>" ) ; records . addAll ( java . util . Arrays . asList ( entities ) ) ; if ( records . size ( ) == entityCount . intValue ( ) ) { done = true ; } else { paging . put ( "<STR_LIT>" , new Integer ( ++ currentPage ) ) ; } } return records ; } public Map create ( CreateRequest cr ) throws XmlRpcException { HashMap req = new HashMap ( ) ; req . put ( "<STR_LIT:type>" , cr . entityType ) ; List fields = new ArrayList ( ) ; for ( Iterator iter = cr . data . entrySet ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { Entry e = ( Entry ) iter . next ( ) ; HashMap rf = new HashMap ( ) ; rf . put ( "<STR_LIT>" , e . getKey ( ) ) ; rf . put ( "<STR_LIT:value>" , e . getValue ( ) ) ; fields . add ( rf ) ; } req . put ( "<STR_LIT>" , fields ) ; Object [ ] params = new Object [ ] { this . auth , req } ; Map response = ( Map ) this . client . execute ( "<STR_LIT>" , params ) ; Map results = ( Map ) response . get ( "<STR_LIT>" ) ; return results ; } public Map update ( UpdateRequest ur ) throws XmlRpcException { HashMap req = new HashMap ( ) ; req . put ( "<STR_LIT:type>" , ur . entityType ) ; req . put ( "<STR_LIT:id>" , ur . entityId ) ; List fields = new ArrayList ( ) ; for ( Iterator iter = ur . data . entrySet ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { Entry e = ( Entry ) iter . next ( ) ; HashMap rf = new HashMap ( ) ; String key = ( String ) e . getKey ( ) ; rf . put ( "<STR_LIT>" , key ) ; rf . put ( "<STR_LIT:value>" , e . getValue ( ) ) ; if ( ur . multiEntityUpdateModes . containsKey ( key ) ) { rf . put ( "<STR_LIT>" , ur . multiEntityUpdateModes . get ( key ) ) ; } if ( ur . multiEntityParents . containsKey ( key ) ) { rf . put ( "<STR_LIT>" , ur . multiEntityParents . get ( key ) ) ; } fields . add ( rf ) ; } req . put ( "<STR_LIT>" , fields ) ; Object [ ] params = new Object [ ] { this . auth , req } ; Map response = ( Map ) this . client . execute ( "<STR_LIT>" , params ) ; Map results = ( Map ) response . get ( "<STR_LIT>" ) ; return results ; } public boolean delete ( DeleteRequest dr ) throws XmlRpcException { HashMap req = new HashMap ( ) ; req . put ( "<STR_LIT:type>" , dr . entityType ) ; req . put ( "<STR_LIT:id>" , dr . entityId ) ; Object [ ] params = new Object [ ] { this . auth , req } ; Map response = ( Map ) this . client . execute ( "<STR_LIT>" , params ) ; Boolean didDelete = ( Boolean ) response . get ( "<STR_LIT>" ) ; return ( didDelete . equals ( Boolean . TRUE ) ) ; } class MyTypeFactory extends TypeFactoryImpl { public MyTypeFactory ( XmlRpcController pController ) { super ( pController ) ; } public TypeParser getParser ( XmlRpcStreamConfig pConfig , NamespaceContextImpl pContext , String pURI , String pLocalName ) { if ( "<STR_LIT>" . equals ( pURI ) && NullSerializer . NIL_TAG . equals ( pLocalName ) ) { return new NullParser ( ) ; } else { return super . getParser ( pConfig , pContext , pURI , pLocalName ) ; } } } } </s>
<s> package com . shotgunsoftware ; import java . util . Map ; interface ConditionInterface { Map toHash ( ) ; } </s>
<s> package com . shotgunsoftware ; public class DeleteRequest { String entityType ; Integer entityId ; public DeleteRequest ( String entityType , Integer entityId ) { this . entityType = entityType ; this . entityId = entityId ; } } </s>
<s> package com . shotgunsoftware ; import java . util . Iterator ; import java . util . List ; import java . util . ArrayList ; import java . util . Map ; import java . util . HashMap ; public class ConditionGroup implements ConditionInterface { boolean isAndGroup ; List children ; public ConditionGroup ( ) { this ( true ) ; } public ConditionGroup ( boolean isAndGroup ) { this . isAndGroup = isAndGroup ; this . children = new ArrayList ( ) ; } public void addCondition ( Condition c ) { children . add ( c ) ; } public void addConditionGroup ( ConditionGroup cg ) { children . add ( cg ) ; } public Map toHash ( ) { Map h = new HashMap ( ) ; List l = new ArrayList ( ) ; for ( Iterator iter = children . iterator ( ) ; iter . hasNext ( ) ; ) { ConditionInterface ci = ( ConditionInterface ) iter . next ( ) ; l . add ( ci . toHash ( ) ) ; } h . put ( "<STR_LIT>" , this . isAndGroup ? "<STR_LIT>" : "<STR_LIT>" ) ; h . put ( "<STR_LIT>" , l ) ; return h ; } } </s>
<s> package com . shotgunsoftware ; import java . util . Map ; import java . util . HashMap ; public class Condition implements ConditionInterface { String path ; String relation ; Object [ ] values ; public Condition ( String path , String relation , Object [ ] values ) { this . path = path ; this . relation = relation ; this . values = values ; } public Map toHash ( ) { Map h = new HashMap ( ) ; h . put ( "<STR_LIT:path>" , this . path ) ; h . put ( "<STR_LIT>" , this . relation ) ; h . put ( "<STR_LIT>" , this . values ) ; return h ; } } </s>
<s> package com . shotgunsoftware ; public class FindRequest { String entityType ; String [ ] returnFields ; Sort [ ] sorts ; ConditionGroup conditions ; public FindRequest ( String entityType ) { this . entityType = entityType ; this . sorts = new Sort [ ] { } ; this . conditions = new ConditionGroup ( ) ; } public void setFields ( String fields [ ] ) { this . returnFields = fields ; } public void setCondition ( Condition c ) { this . conditions = new ConditionGroup ( ) ; this . conditions . addCondition ( c ) ; } public void setConditions ( ConditionGroup cg ) { this . conditions = cg ; } public void setSort ( Sort sort ) { this . sorts = new Sort [ ] { sort } ; } public void setSorts ( Sort [ ] sorts ) { this . sorts = sorts ; } } </s>
<s> package com . shotgunsoftware ; import java . util . Map ; import java . util . HashMap ; public class CreateRequest { String entityType ; Map data ; public CreateRequest ( String entityType ) { this . entityType = entityType ; this . data = new HashMap ( ) ; } public void setData ( Map data ) { this . data = data ; } } </s>
<s> package biz . sawatzki . phoneload ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . net . HttpURLConnection ; import java . net . URL ; import android . util . Log ; import com . phonegap . api . PluginResult ; import com . phonegap . FileUtils ; public class FileDownloadThread extends Thread { private static final String LOG_TAG = "<STR_LIT>" ; private String source , target , callbackId ; private PhoneLoad fileTransfer ; private boolean stopRequested = false ; public FileDownloadThread ( PhoneLoad fileTransfer , String source , String target , String callbackId ) { this . source = source ; this . target = target ; this . callbackId = callbackId ; this . fileTransfer = fileTransfer ; } @ Override public void run ( ) { try { download ( source , target , callbackId ) ; } catch ( IOException e ) { fileTransfer . error ( "<STR_LIT>" , callbackId ) ; } } public void requestStop ( ) { stopRequested = true ; } public void download ( String source , String target , String callbackId ) throws IOException { try { FileDownloadResult result = new FileDownloadResult ( ) ; File file = new File ( target ) ; file . getParentFile ( ) . mkdirs ( ) ; URL url = new URL ( source ) ; HttpURLConnection connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . setRequestMethod ( "<STR_LIT:GET>" ) ; connection . setDoOutput ( true ) ; connection . connect ( ) ; Log . d ( LOG_TAG , "<STR_LIT>" + url ) ; result . setResponseCode ( connection . getResponseCode ( ) ) ; result . setBytesTotal ( connection . getContentLength ( ) ) ; InputStream inputStream = connection . getInputStream ( ) ; byte [ ] buffer = new byte [ <NUM_LIT> ] ; int bytesRead = <NUM_LIT:0> ; long totalBytes = <NUM_LIT:0> ; FileOutputStream outputStream = new FileOutputStream ( file ) ; bytesRead = inputStream . read ( buffer ) ; PluginResult progress ; long lastTime = <NUM_LIT:0> ; long curTime = <NUM_LIT:0> ; while ( bytesRead > <NUM_LIT:0> ) { outputStream . write ( buffer , <NUM_LIT:0> , bytesRead ) ; totalBytes += bytesRead ; result . setBytesReceived ( totalBytes ) ; bytesRead = inputStream . read ( buffer ) ; curTime = System . currentTimeMillis ( ) ; if ( ( bytesRead == <NUM_LIT:0> ) || ( curTime > ( lastTime + <NUM_LIT> ) ) ) { progress = new PluginResult ( PluginResult . Status . OK , result . toJSONObject ( ) , FileDownloadResult . CAST_CODE ) ; progress . setKeepCallback ( true ) ; fileTransfer . success ( progress , callbackId ) ; lastTime = curTime ; } if ( stopRequested ) { fileTransfer . error ( "<STR_LIT>" , callbackId ) ; return ; } } inputStream . close ( ) ; connection . disconnect ( ) ; outputStream . close ( ) ; Log . d ( LOG_TAG , "<STR_LIT>" + target ) ; FileUtils fileUtil = new FileUtils ( ) ; result . setFileEntry ( fileUtil . getEntry ( file ) ) ; result . setCompleted ( ) ; PluginResult pluginResult = new PluginResult ( PluginResult . Status . OK , result . toJSONObject ( ) , FileDownloadResult . CAST_CODE ) ; fileTransfer . success ( pluginResult , callbackId ) ; } catch ( Exception e ) { Log . d ( LOG_TAG , e . getMessage ( ) , e ) ; throw new IOException ( "<STR_LIT>" ) ; } } } </s>
<s> package biz . sawatzki . phoneload ; import org . json . JSONException ; import org . json . JSONObject ; public class FileUploadResult extends FileTransferResult { private long bytesSent = <NUM_LIT:0> ; private String response = null ; public long getBytesSent ( ) { return bytesSent ; } public void setBytesSent ( long bytes ) { this . bytesSent = bytes ; } public String getResponse ( ) { return response ; } public void setResponse ( String response ) { this . response = response ; } public JSONObject toJSONObject ( ) throws JSONException { return new JSONObject ( "<STR_LIT>" + bytesSent + "<STR_LIT>" + getResponseCode ( ) + "<STR_LIT>" + JSONObject . quote ( response ) + "<STR_LIT:}>" ) ; } } </s>
<s> package biz . sawatzki . phoneload ; import org . json . JSONException ; import org . json . JSONObject ; public class FileTransferResult { private int responseCode = - <NUM_LIT:1> ; public int getResponseCode ( ) { return responseCode ; } public void setResponseCode ( int responseCode ) { this . responseCode = responseCode ; } } </s>
<s> package biz . sawatzki . phoneload ; import java . io . DataInputStream ; import java . io . DataOutputStream ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . net . HttpURLConnection ; import java . net . URL ; import java . security . cert . CertificateException ; import java . security . cert . X509Certificate ; import java . util . Iterator ; import javax . net . ssl . HostnameVerifier ; import javax . net . ssl . HttpsURLConnection ; import javax . net . ssl . SSLContext ; import javax . net . ssl . SSLException ; import javax . net . ssl . SSLSession ; import javax . net . ssl . SSLSocketFactory ; import javax . net . ssl . TrustManager ; import javax . net . ssl . X509TrustManager ; import org . json . JSONArray ; import org . json . JSONException ; import org . json . JSONObject ; import android . net . Uri ; import android . util . Log ; import android . webkit . CookieManager ; import com . phonegap . api . Plugin ; import com . phonegap . api . PluginResult ; import java . util . HashMap ; import com . phonegap . FileUtils ; public class PhoneLoad extends Plugin { private static final String LOG_TAG = "<STR_LIT>" ; private static final String LINE_START = "<STR_LIT:-->" ; private static final String LINE_END = "<STR_LIT>" ; private static final String BOUNDRY = "<STR_LIT>" ; public static int FILE_NOT_FOUND_ERR = <NUM_LIT:1> ; public static int INVALID_URL_ERR = <NUM_LIT:2> ; public static int CONNECTION_ERR = <NUM_LIT:3> ; private SSLSocketFactory defaultSSLSocketFactory = null ; private HostnameVerifier defaultHostnameVerifier = null ; private HashMap < String , FileDownloadThread > downloadWorkers ; public PhoneLoad ( ) { super ( ) ; downloadWorkers = new HashMap < String , FileDownloadThread > ( ) ; } @ Override public PluginResult execute ( String action , JSONArray args , String callbackId ) { String source = null ; String target = null ; String id = null ; if ( action . equals ( "<STR_LIT>" ) || action . equals ( "<STR_LIT>" ) ) { try { source = args . getString ( <NUM_LIT:0> ) ; target = args . getString ( <NUM_LIT:1> ) ; if ( args . length ( ) > <NUM_LIT:2> ) id = args . getString ( <NUM_LIT:2> ) ; } catch ( JSONException e ) { Log . d ( LOG_TAG , "<STR_LIT>" ) ; return new PluginResult ( PluginResult . Status . JSON_EXCEPTION , "<STR_LIT>" ) ; } } else if ( action . equals ( "<STR_LIT>" ) ) { try { id = args . getString ( <NUM_LIT:0> ) ; } catch ( JSONException e ) { Log . d ( LOG_TAG , "<STR_LIT>" ) ; return new PluginResult ( PluginResult . Status . JSON_EXCEPTION , "<STR_LIT>" ) ; } } try { if ( action . equals ( "<STR_LIT>" ) ) { String fileKey = null ; String fileName = null ; String mimeType = null ; fileKey = getArgument ( args , <NUM_LIT:2> , "<STR_LIT:file>" ) ; fileName = getArgument ( args , <NUM_LIT:3> , "<STR_LIT>" ) ; mimeType = getArgument ( args , <NUM_LIT:4> , "<STR_LIT>" ) ; JSONObject params = args . optJSONObject ( <NUM_LIT:5> ) ; boolean trustEveryone = args . optBoolean ( <NUM_LIT:6> ) ; boolean chunkedMode = args . optBoolean ( <NUM_LIT:7> ) ; FileUploadResult r = upload ( source , target , fileKey , fileName , mimeType , params , trustEveryone , chunkedMode ) ; Log . d ( LOG_TAG , "<STR_LIT>" ) ; return new PluginResult ( PluginResult . Status . OK , r . toJSONObject ( ) ) ; } else if ( action . equals ( "<STR_LIT>" ) ) { Log . d ( LOG_TAG , "<STR_LIT>" ) ; FileDownloadThread t = new FileDownloadThread ( this , source , target , callbackId ) ; downloadWorkers . put ( id , t ) ; t . start ( ) ; PluginResult result = new PluginResult ( PluginResult . Status . NO_RESULT ) ; result . setKeepCallback ( true ) ; return result ; } else if ( action . equals ( "<STR_LIT>" ) ) { if ( id != null ) { FileDownloadThread t = downloadWorkers . get ( id ) ; if ( t != null ) { t . requestStop ( ) ; try { t . join ( ) ; } catch ( InterruptedException e ) { } } Log . d ( LOG_TAG , "<STR_LIT>" ) ; } return new PluginResult ( PluginResult . Status . OK ) ; } else { return new PluginResult ( PluginResult . Status . INVALID_ACTION ) ; } } catch ( FileNotFoundException e ) { Log . e ( LOG_TAG , e . getMessage ( ) , e ) ; JSONObject error = createFileTransferError ( FILE_NOT_FOUND_ERR , source , target ) ; return new PluginResult ( PluginResult . Status . IO_EXCEPTION , error ) ; } catch ( IllegalArgumentException e ) { Log . e ( LOG_TAG , e . getMessage ( ) , e ) ; JSONObject error = createFileTransferError ( INVALID_URL_ERR , source , target ) ; return new PluginResult ( PluginResult . Status . IO_EXCEPTION , error ) ; } catch ( SSLException e ) { Log . e ( LOG_TAG , e . getMessage ( ) , e ) ; Log . d ( LOG_TAG , "<STR_LIT>" ) ; JSONObject error = createFileTransferError ( CONNECTION_ERR , source , target ) ; return new PluginResult ( PluginResult . Status . IO_EXCEPTION , error ) ; } catch ( IOException e ) { Log . e ( LOG_TAG , e . getMessage ( ) , e ) ; JSONObject error = createFileTransferError ( CONNECTION_ERR , source , target ) ; return new PluginResult ( PluginResult . Status . IO_EXCEPTION , error ) ; } catch ( JSONException e ) { Log . e ( LOG_TAG , e . getMessage ( ) , e ) ; return new PluginResult ( PluginResult . Status . JSON_EXCEPTION ) ; } } final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier ( ) { public boolean verify ( String hostname , SSLSession session ) { return true ; } } ; private void trustAllHosts ( ) { TrustManager [ ] trustAllCerts = new TrustManager [ ] { new X509TrustManager ( ) { public java . security . cert . X509Certificate [ ] getAcceptedIssuers ( ) { return new java . security . cert . X509Certificate [ ] { } ; } public void checkClientTrusted ( X509Certificate [ ] chain , String authType ) throws CertificateException { } public void checkServerTrusted ( X509Certificate [ ] chain , String authType ) throws CertificateException { } } } ; try { defaultSSLSocketFactory = HttpsURLConnection . getDefaultSSLSocketFactory ( ) ; SSLContext sc = SSLContext . getInstance ( "<STR_LIT>" ) ; sc . init ( null , trustAllCerts , new java . security . SecureRandom ( ) ) ; HttpsURLConnection . setDefaultSSLSocketFactory ( sc . getSocketFactory ( ) ) ; } catch ( Exception e ) { Log . e ( LOG_TAG , e . getMessage ( ) , e ) ; } } private JSONObject createFileTransferError ( int errorCode , String source , String target ) { JSONObject error = null ; try { error = new JSONObject ( ) ; error . put ( "<STR_LIT:code>" , errorCode ) ; error . put ( "<STR_LIT:source>" , source ) ; error . put ( "<STR_LIT:target>" , target ) ; } catch ( JSONException e ) { Log . e ( LOG_TAG , e . getMessage ( ) , e ) ; } return error ; } private String getArgument ( JSONArray args , int position , String defaultString ) { String arg = defaultString ; if ( args . length ( ) >= position ) { arg = args . optString ( position ) ; if ( arg == null || "<STR_LIT:null>" . equals ( arg ) ) { arg = defaultString ; } } return arg ; } public FileUploadResult upload ( String file , String server , final String fileKey , final String fileName , final String mimeType , JSONObject params , boolean trustEveryone , boolean chunkedMode ) throws IOException , SSLException { FileUploadResult result = new FileUploadResult ( ) ; InputStream fileInputStream = getPathFromUri ( file ) ; HttpURLConnection conn = null ; DataOutputStream dos = null ; int bytesRead , bytesAvailable , bufferSize ; long totalBytes ; byte [ ] buffer ; int maxBufferSize = <NUM_LIT> ; URL url = new URL ( server ) ; if ( url . getProtocol ( ) . toLowerCase ( ) . equals ( "<STR_LIT>" ) ) { if ( ! trustEveryone ) { conn = ( HttpsURLConnection ) url . openConnection ( ) ; } else { trustAllHosts ( ) ; HttpsURLConnection https = ( HttpsURLConnection ) url . openConnection ( ) ; defaultHostnameVerifier = https . getHostnameVerifier ( ) ; https . setHostnameVerifier ( DO_NOT_VERIFY ) ; conn = https ; } } else { conn = ( HttpURLConnection ) url . openConnection ( ) ; } conn . setDoInput ( true ) ; conn . setDoOutput ( true ) ; conn . setUseCaches ( false ) ; conn . setRequestMethod ( "<STR_LIT:POST>" ) ; conn . setRequestProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; conn . setRequestProperty ( "<STR_LIT:Content-Type>" , "<STR_LIT>" + BOUNDRY ) ; String cookie = CookieManager . getInstance ( ) . getCookie ( server ) ; if ( cookie != null ) { conn . setRequestProperty ( "<STR_LIT>" , cookie ) ; } if ( chunkedMode ) { conn . setChunkedStreamingMode ( maxBufferSize ) ; } dos = new DataOutputStream ( conn . getOutputStream ( ) ) ; try { for ( Iterator iter = params . keys ( ) ; iter . hasNext ( ) ; ) { Object key = iter . next ( ) ; dos . writeBytes ( LINE_START + BOUNDRY + LINE_END ) ; dos . writeBytes ( "<STR_LIT>" + key . toString ( ) + "<STR_LIT>" ) ; dos . writeBytes ( LINE_END + LINE_END ) ; dos . write ( params . getString ( key . toString ( ) ) . getBytes ( ) ) ; dos . writeBytes ( LINE_END ) ; } } catch ( JSONException e ) { Log . e ( LOG_TAG , e . getMessage ( ) , e ) ; } dos . writeBytes ( LINE_START + BOUNDRY + LINE_END ) ; dos . writeBytes ( "<STR_LIT>" + fileKey + "<STR_LIT>" + "<STR_LIT>" + fileName + "<STR_LIT:\">" + LINE_END ) ; dos . writeBytes ( "<STR_LIT>" + mimeType + LINE_END ) ; dos . writeBytes ( LINE_END ) ; bytesAvailable = fileInputStream . available ( ) ; bufferSize = Math . min ( bytesAvailable , maxBufferSize ) ; buffer = new byte [ bufferSize ] ; bytesRead = fileInputStream . read ( buffer , <NUM_LIT:0> , bufferSize ) ; totalBytes = <NUM_LIT:0> ; while ( bytesRead > <NUM_LIT:0> ) { totalBytes += bytesRead ; result . setBytesSent ( totalBytes ) ; dos . write ( buffer , <NUM_LIT:0> , bufferSize ) ; bytesAvailable = fileInputStream . available ( ) ; bufferSize = Math . min ( bytesAvailable , maxBufferSize ) ; bytesRead = fileInputStream . read ( buffer , <NUM_LIT:0> , bufferSize ) ; } dos . writeBytes ( LINE_END ) ; dos . writeBytes ( LINE_START + BOUNDRY + LINE_START + LINE_END ) ; fileInputStream . close ( ) ; dos . flush ( ) ; dos . close ( ) ; StringBuffer responseString = new StringBuffer ( "<STR_LIT>" ) ; DataInputStream inStream ; try { inStream = new DataInputStream ( conn . getInputStream ( ) ) ; } catch ( FileNotFoundException e ) { throw new IOException ( "<STR_LIT>" ) ; } String line ; while ( ( line = inStream . readLine ( ) ) != null ) { responseString . append ( line ) ; } Log . d ( LOG_TAG , "<STR_LIT>" ) ; Log . d ( LOG_TAG , responseString . toString ( ) ) ; result . setResponseCode ( conn . getResponseCode ( ) ) ; result . setResponse ( responseString . toString ( ) ) ; inStream . close ( ) ; conn . disconnect ( ) ; if ( trustEveryone && url . getProtocol ( ) . toLowerCase ( ) . equals ( "<STR_LIT>" ) ) { ( ( HttpsURLConnection ) conn ) . setHostnameVerifier ( defaultHostnameVerifier ) ; HttpsURLConnection . setDefaultSSLSocketFactory ( defaultSSLSocketFactory ) ; } return result ; } public FileDownloadResult download ( String source , String target , String callbackId ) throws IOException { try { FileDownloadResult result = new FileDownloadResult ( ) ; File file = new File ( target ) ; file . getParentFile ( ) . mkdirs ( ) ; URL url = new URL ( source ) ; HttpURLConnection connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . setRequestMethod ( "<STR_LIT:GET>" ) ; connection . setDoOutput ( true ) ; connection . connect ( ) ; Log . d ( LOG_TAG , "<STR_LIT>" + url ) ; result . setResponseCode ( connection . getResponseCode ( ) ) ; result . setBytesTotal ( connection . getContentLength ( ) ) ; InputStream inputStream = connection . getInputStream ( ) ; byte [ ] buffer = new byte [ <NUM_LIT> ] ; int bytesRead = <NUM_LIT:0> ; long totalBytes = <NUM_LIT:0> ; FileOutputStream outputStream = new FileOutputStream ( file ) ; bytesRead = inputStream . read ( buffer ) ; PluginResult progress ; long lastTime = <NUM_LIT:0> ; long curTime = <NUM_LIT:0> ; while ( bytesRead > <NUM_LIT:0> ) { outputStream . write ( buffer , <NUM_LIT:0> , bytesRead ) ; totalBytes += bytesRead ; result . setBytesReceived ( totalBytes ) ; bytesRead = inputStream . read ( buffer ) ; curTime = System . currentTimeMillis ( ) ; if ( ( bytesRead == <NUM_LIT:0> ) || ( curTime > ( lastTime + <NUM_LIT> ) ) ) { progress = new PluginResult ( PluginResult . Status . OK , result . toJSONObject ( ) , FileDownloadResult . CAST_CODE ) ; progress . setKeepCallback ( true ) ; success ( progress , callbackId ) ; lastTime = curTime ; } } inputStream . close ( ) ; connection . disconnect ( ) ; outputStream . close ( ) ; Log . d ( LOG_TAG , "<STR_LIT>" + target ) ; FileUtils fileUtil = new FileUtils ( ) ; result . setFileEntry ( fileUtil . getEntry ( file ) ) ; result . setCompleted ( ) ; return result ; } catch ( Exception e ) { Log . d ( LOG_TAG , e . getMessage ( ) , e ) ; throw new IOException ( "<STR_LIT>" ) ; } } private InputStream getPathFromUri ( String path ) throws FileNotFoundException { if ( path . startsWith ( "<STR_LIT>" ) ) { Uri uri = Uri . parse ( path ) ; return ctx . getContentResolver ( ) . openInputStream ( uri ) ; } else if ( path . startsWith ( "<STR_LIT>" ) ) { return new FileInputStream ( path . substring ( <NUM_LIT:7> ) ) ; } else { return new FileInputStream ( path ) ; } } } </s>
<s> package biz . sawatzki . phoneload ; import org . json . JSONException ; import org . json . JSONObject ; public class FileDownloadResult extends FileTransferResult { public static final String CAST_CODE = "<STR_LIT>" ; private long bytesReceived = <NUM_LIT:0> ; private long bytesTotal = <NUM_LIT:0> ; private JSONObject fileEntry ; private boolean completed = false ; public long getBytesReceived ( ) { return bytesReceived ; } public void setBytesReceived ( long bytes ) { this . bytesReceived = bytes ; } public long getBytesTotal ( ) { return bytesTotal ; } public void setBytesTotal ( long bytes ) { this . bytesTotal = bytes ; } public boolean getCompleted ( ) { return completed ; } public void setCompleted ( ) { this . completed = true ; } public double getPercentCompleted ( ) { if ( bytesTotal > <NUM_LIT:0> ) return new Double ( bytesReceived ) / new Double ( bytesTotal ) * <NUM_LIT> ; else return - <NUM_LIT:1> ; } public JSONObject getFileEntry ( ) { return fileEntry ; } public void setFileEntry ( JSONObject entry ) { this . fileEntry = entry ; } public JSONObject toJSONObject ( ) throws JSONException { JSONObject result = new JSONObject ( ) ; result . put ( "<STR_LIT>" , getBytesReceived ( ) ) ; result . put ( "<STR_LIT>" , getBytesTotal ( ) ) ; result . put ( "<STR_LIT>" , getPercentCompleted ( ) ) ; result . put ( "<STR_LIT>" , getResponseCode ( ) ) ; result . put ( "<STR_LIT>" , getCompleted ( ) ) ; if ( fileEntry != null ) result . put ( "<STR_LIT>" , fileEntry . toString ( ) ) ; return result ; } } </s>
<s> package org . payments4j . spi . payflowpro ; import org . apache . http . HttpEntity ; import org . apache . http . client . HttpClient ; import org . apache . http . client . methods . HttpPost ; import org . apache . http . util . EntityUtils ; import org . junit . Before ; import org . junit . Test ; import org . junit . runner . RunWith ; import org . mockito . ArgumentCaptor ; import org . mockito . Mock ; import org . mockito . runners . MockitoJUnitRunner ; import org . payments4j . core . TransactionResponse ; import org . payments4j . model . CreditCard ; import org . payments4j . model . CreditCardBuilder ; import org . payments4j . model . Money ; import org . payments4j . model . MoneyBuilder ; import java . io . IOException ; import java . util . Locale ; import static org . fest . assertions . Assertions . assertThat ; import static org . mockito . Mockito . verify ; import static org . mockito . Mockito . when ; import static org . payments4j . model . CreditCard . Type . MASTER_CARD ; @ RunWith ( MockitoJUnitRunner . class ) public class PayFlowProPaymentGatewayTest { private static final String USERNAME = "<STR_LIT>" ; private static final String PASSWORD = "<STR_LIT>" ; private PayFlowProPaymentGateway_ForTest gateway ; private Money money ; private CreditCard creditCard ; @ Mock private HttpPost mockHttpPost ; @ Mock private HttpClient mockHttpClient ; private TransactionResponse transactionResponse ; @ Before public void setUp ( ) throws Exception { gateway = new PayFlowProPaymentGateway_ForTest ( USERNAME , PASSWORD ) ; gateway . setTest ( true ) ; money = new MoneyBuilder ( ) . withAmount ( "<STR_LIT:10>" ) . withCurrency ( Locale . US ) . build ( ) ; creditCard = new CreditCardBuilder ( ) . withNumber ( "<STR_LIT>" ) . withFirstName ( "<STR_LIT>" ) . withLastName ( "<STR_LIT>" ) . withMonth ( "<STR_LIT>" ) . withYear ( "<STR_LIT>" ) . withType ( MASTER_CARD ) . withSecurityCode ( "<STR_LIT:123>" ) . build ( ) ; transactionResponse = new TransactionResponse ( ) ; transactionResponse . setCode ( <NUM_LIT:0> ) ; transactionResponse . setAuthorizationId ( "<STR_LIT:123>" ) ; transactionResponse . setReasonCode ( <NUM_LIT:0> ) ; transactionResponse . setMessage ( "<STR_LIT>" ) ; when ( mockHttpClient . execute ( mockHttpPost , new PayFlowResponseHandler ( ) ) ) . thenReturn ( transactionResponse ) ; } @ Test public void testPurchase ( ) throws Exception { TransactionResponse response = gateway . purchase ( money , creditCard , null ) ; assertThatParamListEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; assertThat ( response ) . isEqualTo ( transactionResponse ) ; } @ Test public void testAuthorize ( ) throws Exception { TransactionResponse response = gateway . authorize ( money , creditCard , null ) ; assertThatParamListEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; assertThat ( response ) . isEqualTo ( transactionResponse ) ; } @ Test public void testCapture ( ) throws Exception { TransactionResponse response = gateway . capture ( money , "<STR_LIT>" , null ) ; assertThatParamListEquals ( "<STR_LIT>" + "<STR_LIT>" ) ; assertThat ( response ) . isEqualTo ( transactionResponse ) ; } @ Test public void testRevert ( ) throws Exception { TransactionResponse response = gateway . revert ( "<STR_LIT>" , null ) ; assertThatParamListEquals ( "<STR_LIT>" + "<STR_LIT>" ) ; assertThat ( response ) . isEqualTo ( transactionResponse ) ; } @ Test public void testCredit ( ) throws Exception { TransactionResponse response = gateway . credit ( money , "<STR_LIT>" , null ) ; assertThatParamListEquals ( "<STR_LIT>" + "<STR_LIT>" ) ; assertThat ( response ) . isEqualTo ( transactionResponse ) ; } private void assertThatParamListEquals ( String paramsList ) throws IOException { ArgumentCaptor < HttpEntity > entityArgumentCaptor = ArgumentCaptor . forClass ( HttpEntity . class ) ; verify ( mockHttpPost ) . setEntity ( entityArgumentCaptor . capture ( ) ) ; HttpEntity entity = entityArgumentCaptor . getValue ( ) ; assertThat ( EntityUtils . toString ( entity ) ) . isEqualTo ( paramsList ) ; } private class PayFlowProPaymentGateway_ForTest extends PayFlowProPaymentGateway { public PayFlowProPaymentGateway_ForTest ( String username , String password ) { super ( username , password ) ; } @ Override HttpPost buildHttpPost ( String url ) { assertThat ( url ) . isEqualTo ( TEST_HOST_ADDRESS ) ; return mockHttpPost ; } @ Override HttpClient buildHttpClient ( ) { return mockHttpClient ; } } } </s>
<s> package org . payments4j . spi . payflowpro ; import org . payments4j . core . PaymentGateway ; import org . payments4j . test . spi . AbstractBasePaymentGatewayIntegrationTest ; public class PayFlowProPaymentGatewayIntegrationTest extends AbstractBasePaymentGatewayIntegrationTest { @ Override protected PaymentGateway buildGateway ( ) { PayFlowProPaymentGateway gateway = new PayFlowProPaymentGateway ( credentials . getProperty ( "<STR_LIT>" ) , credentials . getProperty ( "<STR_LIT>" ) ) ; gateway . setTest ( true ) ; return gateway ; } } </s>
<s> package org . payments4j . spi . payflowpro ; import org . apache . http . HttpResponse ; import org . apache . http . HttpVersion ; import org . apache . http . entity . StringEntity ; import org . apache . http . message . BasicHttpResponse ; import org . apache . http . message . BasicStatusLine ; import org . junit . Test ; import org . payments4j . core . TransactionResponse ; import java . io . UnsupportedEncodingException ; import static org . fest . assertions . Assertions . assertThat ; public class PayFlowResponseHandlerTest { @ Test public void testHandleResponse ( ) throws Exception { TransactionResponse expectedTransaction = buildExpectedTransactionResponse ( <NUM_LIT:0> , "<STR_LIT>" , true ) ; HttpResponse httpResponse = buildHttpResponse ( "<STR_LIT>" ) ; PayFlowResponseHandler handler = new PayFlowResponseHandler ( ) ; TransactionResponse transactionResponse = handler . handleResponse ( httpResponse ) ; assertThat ( transactionResponse ) . isEqualTo ( expectedTransaction ) ; } @ Test public void testHandleResponse_Failed ( ) throws Exception { TransactionResponse expectedTransaction = buildExpectedTransactionResponse ( <NUM_LIT:4> , "<STR_LIT>" , false ) ; HttpResponse httpResponse = buildHttpResponse ( "<STR_LIT>" ) ; PayFlowResponseHandler handler = new PayFlowResponseHandler ( ) ; TransactionResponse transactionResponse = handler . handleResponse ( httpResponse ) ; assertThat ( transactionResponse ) . isEqualTo ( expectedTransaction ) ; } private TransactionResponse buildExpectedTransactionResponse ( int code , String message , boolean successful ) { TransactionResponse expectedTransaction = new TransactionResponse ( ) ; expectedTransaction . setCode ( code ) ; expectedTransaction . setAuthorizationId ( "<STR_LIT:123>" ) ; expectedTransaction . setReasonCode ( code ) ; expectedTransaction . setMessage ( message ) ; expectedTransaction . setSuccessful ( successful ) ; return expectedTransaction ; } private HttpResponse buildHttpResponse ( String responseString ) throws UnsupportedEncodingException { HttpResponse httpResponse = new BasicHttpResponse ( new BasicStatusLine ( HttpVersion . HTTP_1_1 , <NUM_LIT> , "<STR_LIT>" ) , null , null ) ; httpResponse . setEntity ( new StringEntity ( responseString ) ) ; httpResponse . setStatusCode ( <NUM_LIT> ) ; return httpResponse ; } } </s>
<s> package org . payments4j . spi . payflowpro . converter ; import org . junit . Test ; import org . payments4j . spi . payflowpro . Pair ; import java . util . List ; import static org . fest . assertions . Assertions . assertThat ; public abstract class AbstractBaseConverterTest { @ Test public void testToParamsList ( ) throws Exception { AbstractBaseConverter converter = buildConverter ( ) ; List < Pair > params = converter . toParamsList ( ) ; assertThat ( params ) . containsOnly ( ( Object [ ] ) expectedParams ( ) ) ; } protected abstract Pair [ ] expectedParams ( ) ; protected abstract AbstractBaseConverter buildConverter ( ) ; } </s>
<s> package org . payments4j . spi . payflowpro . converter ; import org . payments4j . model . CreditCard ; import org . payments4j . model . CreditCardBuilder ; import org . payments4j . spi . payflowpro . Pair ; import static org . payments4j . model . CreditCard . Type . MASTER_CARD ; public class CreditCardConverterTest extends AbstractBaseConverterTest { @ Override protected Pair [ ] expectedParams ( ) { return new Pair [ ] { new Pair ( "<STR_LIT>" , "<STR_LIT>" ) , new Pair ( "<STR_LIT>" , "<STR_LIT>" ) , new Pair ( "<STR_LIT>" , "<STR_LIT>" ) , new Pair ( "<STR_LIT>" , "<STR_LIT>" ) , new Pair ( "<STR_LIT>" , "<STR_LIT:123>" ) , new Pair ( "<STR_LIT>" , "<STR_LIT:C>" ) } ; } @ Override protected AbstractBaseConverter buildConverter ( ) { CreditCard creditCard = new CreditCardBuilder ( ) . withNumber ( "<STR_LIT>" ) . withFirstName ( "<STR_LIT>" ) . withLastName ( "<STR_LIT>" ) . withMonth ( "<STR_LIT>" ) . withYear ( "<STR_LIT>" ) . withType ( MASTER_CARD ) . withSecurityCode ( "<STR_LIT:123>" ) . build ( ) ; return new CreditCardConverter ( creditCard ) ; } } </s>
<s> package org . payments4j . spi . payflowpro . converter ; import org . payments4j . model . Money ; import org . payments4j . model . MoneyBuilder ; import org . payments4j . spi . payflowpro . Pair ; import java . util . Locale ; public class MoneyConverterTest extends AbstractBaseConverterTest { @ Override protected AbstractBaseConverter buildConverter ( ) { Money money = new MoneyBuilder ( ) . withAmount ( "<STR_LIT:10>" ) . withCurrency ( Locale . US ) . build ( ) ; return new MoneyConverter ( money ) ; } protected Pair [ ] expectedParams ( ) { return new Pair [ ] { new Pair ( "<STR_LIT>" , "<STR_LIT>" ) , new Pair ( "<STR_LIT>" , "<STR_LIT>" ) , } ; } } </s>
<s> package org . payments4j . spi . payflowpro . converter ; import org . payments4j . spi . payflowpro . Pair ; public class CredentialsConverterTest extends AbstractBaseConverterTest { @ Override protected AbstractBaseConverter buildConverter ( ) { return new CredentialsConverter ( "<STR_LIT>" , "<STR_LIT>" ) ; } @ Override protected Pair [ ] expectedParams ( ) { return new Pair [ ] { new Pair ( "<STR_LIT>" , "<STR_LIT>" ) , new Pair ( "<STR_LIT>" , "<STR_LIT>" ) , new Pair ( "<STR_LIT>" , "<STR_LIT>" ) , new Pair ( "<STR_LIT>" , "<STR_LIT>" ) } ; } } </s>
<s> package org . payments4j . spi . payflowpro ; import com . google . common . base . Joiner ; import org . apache . http . client . HttpClient ; import org . apache . http . client . methods . HttpPost ; import org . apache . http . entity . StringEntity ; import org . apache . http . impl . client . DefaultHttpClient ; import org . payments4j . core . AbstractPaymentGateway ; import org . payments4j . core . TransactionResponse ; import org . payments4j . model . CreditCard ; import org . payments4j . model . Money ; import org . payments4j . spi . payflowpro . converter . AbstractBaseConverter ; import org . payments4j . spi . payflowpro . converter . CredentialsConverter ; import org . payments4j . spi . payflowpro . converter . CreditCardConverter ; import org . payments4j . spi . payflowpro . converter . MoneyConverter ; import java . io . IOException ; import java . io . UnsupportedEncodingException ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; public class PayFlowProPaymentGateway extends AbstractPaymentGateway { public static final String HOST_ADDRESS = "<STR_LIT>" ; public static final String TEST_HOST_ADDRESS = "<STR_LIT>" ; private CredentialsConverter credentialsConverter ; private boolean test ; public PayFlowProPaymentGateway ( String username , String password ) { this . credentialsConverter = new CredentialsConverter ( username , password ) ; } @ Override public TransactionResponse doPurchase ( Money money , CreditCard creditCard , Map < String , Object > options ) { List < Pair > paramsList = buildParamList ( new MoneyConverter ( money ) , new CreditCardConverter ( creditCard ) , credentialsConverter ) ; return executeTransaction ( paramsList , "<STR_LIT:S>" ) ; } @ Override public TransactionResponse doAuthorize ( Money money , CreditCard creditCard , Map < String , Object > options ) { List < Pair > paramsList = buildParamList ( new MoneyConverter ( money ) , new CreditCardConverter ( creditCard ) , credentialsConverter ) ; return executeTransaction ( paramsList , "<STR_LIT:A>" ) ; } @ Override public TransactionResponse doCapture ( Money money , String authorizationId , Map < String , Object > options ) { List < Pair > paramsList = buildParamList ( new MoneyConverter ( money ) , credentialsConverter ) ; paramsList . add ( new Pair ( "<STR_LIT>" , authorizationId ) ) ; return executeTransaction ( paramsList , "<STR_LIT:D>" ) ; } @ Override public TransactionResponse doRevert ( String transactionId , Map < String , Object > options ) { List < Pair > paramsList = buildParamList ( credentialsConverter ) ; paramsList . add ( new Pair ( "<STR_LIT>" , transactionId ) ) ; return executeTransaction ( paramsList , "<STR_LIT>" ) ; } @ Override public TransactionResponse doCredit ( Money money , String transactionId , Map < String , Object > options ) { List < Pair > paramsList = buildParamList ( credentialsConverter ) ; paramsList . add ( new Pair ( "<STR_LIT>" , transactionId ) ) ; return executeTransaction ( paramsList , "<STR_LIT:C>" ) ; } @ Override public TransactionResponse doRecurring ( Money money , CreditCard creditCard , Map < String , Object > options ) { throw new UnsupportedOperationException ( ) ; } @ Override public TransactionResponse doStoreCreditCard ( CreditCard creditCard , Map < String , Object > options ) { throw new UnsupportedOperationException ( ) ; } @ Override public TransactionResponse doEvictCreditCard ( String creditCardId , Map < String , Object > options ) { throw new UnsupportedOperationException ( ) ; } @ Override public boolean supportsPurchase ( ) { return true ; } @ Override public boolean supportsAuthorize ( ) { return true ; } @ Override public boolean supportsCapture ( ) { return true ; } @ Override public boolean supportsRevert ( ) { return true ; } @ Override public boolean supportsCredit ( ) { return true ; } @ Override public boolean supportsStoreCreditCard ( ) { return false ; } @ Override public boolean supportsEvictCreditCard ( ) { return false ; } @ Override public void setTest ( boolean test ) { this . test = test ; } private TransactionResponse executeTransaction ( List < Pair > paramsList , String transactionType ) { HttpPost post = buildHttpPost ( test ? TEST_HOST_ADDRESS : HOST_ADDRESS ) ; paramsList . add ( new Pair ( "<STR_LIT>" , "<STR_LIT>" ) ) ; paramsList . add ( new Pair ( "<STR_LIT>" , transactionType ) ) ; post . setEntity ( toStringEntity ( paramsList ) ) ; try { HttpClient httpClient = buildHttpClient ( ) ; return httpClient . execute ( post , new PayFlowResponseHandler ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return null ; } private List < Pair > buildParamList ( AbstractBaseConverter ... converters ) { List < Pair > paramsList = new ArrayList < Pair > ( ) ; for ( AbstractBaseConverter converter : converters ) { paramsList . addAll ( converter . toParamsList ( ) ) ; } return paramsList ; } private StringEntity toStringEntity ( List < Pair > paramsList ) { String params = Joiner . on ( "<STR_LIT:&>" ) . join ( paramsList ) ; try { return new StringEntity ( params , "<STR_LIT:UTF-8>" ) ; } catch ( UnsupportedEncodingException e ) { return null ; } } HttpClient buildHttpClient ( ) { return new DefaultHttpClient ( ) ; } HttpPost buildHttpPost ( String url ) { return new HttpPost ( url ) ; } } </s>
<s> package org . payments4j . spi . payflowpro ; import com . google . common . collect . ImmutableMultimap ; import com . google . common . collect . Multimap ; import org . apache . commons . beanutils . ConvertUtils ; import org . apache . commons . beanutils . PropertyUtils ; import org . apache . commons . beanutils . WrapDynaBean ; import org . apache . http . HttpResponse ; import org . apache . http . client . ClientProtocolException ; import org . apache . http . client . ResponseHandler ; import org . apache . http . impl . client . BasicResponseHandler ; import org . payments4j . core . TransactionResponse ; import java . io . IOException ; import java . lang . reflect . InvocationTargetException ; import java . util . Collection ; public class PayFlowResponseHandler implements ResponseHandler < TransactionResponse > { private static final Multimap < String , String > nameToProperty = new ImmutableMultimap . Builder < String , String > ( ) . putAll ( "<STR_LIT>" , "<STR_LIT>" ) . putAll ( "<STR_LIT>" , "<STR_LIT:code>" , "<STR_LIT>" ) . putAll ( "<STR_LIT>" , "<STR_LIT:message>" ) . build ( ) ; @ Override public TransactionResponse handleResponse ( HttpResponse response ) throws ClientProtocolException , IOException { BasicResponseHandler basicResponseHandler = new BasicResponseHandler ( ) ; String responseString = basicResponseHandler . handleResponse ( response ) ; TransactionResponse transactionResponse = buildTransactionResponse ( responseString ) ; if ( transactionResponse . getCode ( ) == <NUM_LIT:0> ) { transactionResponse . setSuccessful ( true ) ; } return transactionResponse ; } private TransactionResponse buildTransactionResponse ( String responseString ) { TransactionResponse transactionResponse = new TransactionResponse ( ) ; WrapDynaBean dynaBean = new WrapDynaBean ( transactionResponse ) ; String [ ] pairs = responseString . split ( "<STR_LIT:&>" ) ; for ( String pair : pairs ) { String [ ] parts = pair . split ( "<STR_LIT:=>" ) ; setProperties ( dynaBean , parts [ <NUM_LIT:0> ] , parts [ <NUM_LIT:1> ] ) ; } return ( TransactionResponse ) dynaBean . getInstance ( ) ; } private void setProperties ( WrapDynaBean dynaBean , String name , String value ) { Collection < String > properties = nameToProperty . get ( name ) ; if ( properties != null && ! properties . isEmpty ( ) ) { for ( String property : properties ) { try { Class propertyType = PropertyUtils . getPropertyType ( dynaBean . getInstance ( ) , property ) ; if ( propertyType == String . class ) { dynaBean . set ( property , value ) ; } else { dynaBean . set ( property , ConvertUtils . convert ( value , propertyType ) ) ; } } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } catch ( NoSuchMethodException e ) { e . printStackTrace ( ) ; } } } } @ Override public boolean equals ( Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } return true ; } @ Override public int hashCode ( ) { return nameToProperty . hashCode ( ) ; } } </s>
<s> package org . payments4j . spi . payflowpro ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . apache . commons . lang . builder . HashCodeBuilder ; import static java . lang . String . format ; public class Pair { private String name ; private String value ; public Pair ( String name , String value ) { this . name = name ; this . value = value ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public String getValue ( ) { return value ; } public void setValue ( String value ) { this . value = value ; } @ Override public int hashCode ( ) { return new HashCodeBuilder ( ) . append ( this . name ) . append ( this . value ) . toHashCode ( ) ; } @ Override public boolean equals ( Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } Pair that = ( Pair ) o ; return new EqualsBuilder ( ) . append ( this . name , that . name ) . append ( this . value , that . value ) . isEquals ( ) ; } @ Override public String toString ( ) { return format ( "<STR_LIT>" , name , value . length ( ) , value ) ; } } </s>
<s> package org . payments4j . spi . payflowpro . converter ; import org . payments4j . model . CreditCard ; import org . payments4j . spi . payflowpro . Pair ; import java . util . ArrayList ; import java . util . List ; import static java . lang . String . format ; public class CreditCardConverter extends AbstractBaseConverter { private CreditCard creditCard ; public CreditCardConverter ( CreditCard creditCard ) { this . creditCard = creditCard ; } public List < Pair > toParamsList ( ) { List < Pair > params = new ArrayList < Pair > ( ) ; addPair ( params , "<STR_LIT>" , creditCard . getNumber ( ) ) ; addPair ( params , "<STR_LIT>" , format ( "<STR_LIT>" , creditCard . getMonth ( ) , creditCard . getYear ( ) . substring ( <NUM_LIT:2> ) ) ) ; addPair ( params , "<STR_LIT>" , creditCard . getSecurityCode ( ) ) ; addPair ( params , "<STR_LIT>" , creditCard . getFirstName ( ) ) ; addPair ( params , "<STR_LIT>" , creditCard . getLastName ( ) ) ; addPair ( params , "<STR_LIT>" , "<STR_LIT:C>" ) ; return params ; } } </s>
<s> package org . payments4j . spi . payflowpro . converter ; import org . payments4j . spi . payflowpro . Pair ; import java . util . List ; public abstract class AbstractBaseConverter { public abstract List < Pair > toParamsList ( ) ; protected void addPair ( List < Pair > params , String name , String value ) { if ( value != null ) { params . add ( new Pair ( name , value ) ) ; } } } </s>
<s> package org . payments4j . spi . payflowpro . converter ; import org . payments4j . model . Money ; import org . payments4j . spi . payflowpro . Pair ; import java . util . ArrayList ; import java . util . List ; import static java . lang . String . format ; public class MoneyConverter extends AbstractBaseConverter { private Money money ; public MoneyConverter ( Money money ) { this . money = money ; } public List < Pair > toParamsList ( ) { List < Pair > params = new ArrayList < Pair > ( ) ; addPair ( params , "<STR_LIT>" , format ( "<STR_LIT>" , money . getAmount ( ) ) ) ; addPair ( params , "<STR_LIT>" , money . getCurrency ( ) . getCurrencyCode ( ) ) ; return params ; } } </s>