@@ -100,6 +100,7 @@ public class LiveLoggerActivity extends AppCompatActivity {
100100 public static List <LogEntryBase > logDataEntries = new ArrayList <LogEntryBase >();
101101 public static int RECORDID = 0 ;
102102 public static boolean logDataFeedConfigured = false ;
103+ public static ScrollView logScrollView ;
103104 public static SpinnerAdapter spinnerRButtonAdapter ;
104105 public static SpinnerAdapter spinnerRButtonLongAdapter ;
105106 public static SpinnerAdapter spinnerLButtonAdapter ;
@@ -137,6 +138,26 @@ public static void appendNewLog(LogEntryBase logEntry) {
137138 }
138139 logDataFeed .addView (logEntry .getLayoutContainer ());
139140 logDataEntries .add (logEntry );
141+ if (logEntry instanceof LogEntryMetadataRecord ) { // switch to the log tab to display the results:
142+ Log .i (TAG , String .format ("LogEntryMetaData record height: %d" , logEntry .getLayoutContainer ().getHeight ()));
143+ TabLayout tabLayout = (TabLayout ) LiveLoggerActivity .runningActivity .findViewById (R .id .tab_layout );
144+ tabLayout .getTabAt (TAB_LOG ).select ();
145+ if (logScrollView != null ) {
146+ logScrollView .postDelayed (new Runnable () {
147+ @ Override
148+ public void run () {
149+ ScrollView logScroller = (ScrollView ) LiveLoggerActivity .runningActivity .findViewById (R .id .log_scroll_view );
150+ //int bottomEltHeight = LiveLoggerActivity.logDataFeed.getChildAt(LiveLoggerActivity.logDataFeed.getChildCount() - 1).getHeight();
151+ LinearLayout lastLogElt = (LinearLayout ) logDataFeed .getChildAt (logDataFeed .getChildCount () - 1 );
152+ lastLogElt .measure (View .MeasureSpec .UNSPECIFIED , View .MeasureSpec .UNSPECIFIED );
153+ int bottomEltHeight = lastLogElt .getMeasuredHeight ();
154+ Log .i (TAG , String .format ("ScrollView bottom element height = %d + getBottom() = %d" , bottomEltHeight , logScroller .getBottom ()));
155+ logScroller .scrollTo (0 , logScroller .getBottom () + bottomEltHeight );
156+ //logScroller.fullScroll(View.FOCUS_DOWN);
157+ }
158+ }, 250 );
159+ }
160+ }
140161 }
141162
142163 /**
@@ -202,8 +223,8 @@ public void uncaughtException(Thread thread, Throwable ex) {
202223 protected void onCreate (Bundle savedInstanceState ) {
203224
204225 // fix bug where the tabs are blank when the application is relaunched:
205- super .onCreate (savedInstanceState ); // should fix most of the crashes in the ANR report on Play Store
206226 if (runningActivity == null || !isTaskRoot ()) {
227+ super .onCreate (savedInstanceState ); // should fix most of the crashes in the ANR report on Play Store
207228 if (!BuildConfig .DEBUG ) {
208229 Log .w (TAG , "Loading crashlytics" );
209230 Fabric .with (this , new Crashlytics ());
@@ -585,7 +606,11 @@ public static String getSettingFromDevice(UsbSerialDevice cmPort, String query,
585606 break ;
586607 }
587608 }
588- return ChameleonIO .DEVICE_RESPONSE [0 ];
609+ String retValue = ChameleonIO .DEVICE_RESPONSE [0 ];
610+ if (retValue .equals ("201:INVALID COMMAND USAGE" )) {
611+ retValue += " (Are you in READER mode?)" ;
612+ }
613+ return retValue ;
589614 }
590615
591616 /**
@@ -981,7 +1006,7 @@ else if(createCmd.equals("SEND") || createCmd.equals("SEND_RAW")) {
9811006 appendNewLog (LogEntryMetadataRecord .createDefaultEventRecord ("ERROR" , "Input to send to card must be a _single hexadecimal_ byte!" ));
9821007 return ;
9831008 }
984- msgParam = "Card Response (if any): " + getSettingFromDevice (serialPort , createCmd + " " + bytesToSend );
1009+ msgParam = "Card Response (if any): \n " + getSettingFromDevice (serialPort , createCmd + " " + bytesToSend );
9851010 }
9861011 else if (createCmd .equals ("AUTOCAL" )) {
9871012 msgParam = getSettingFromDevice (serialPort , "AUTOCALIBRATE" );
@@ -1600,9 +1625,15 @@ else if(action.equals("RANDOM")) {
16001625
16011626 public void actionButtonSendAPDU (View view ) {
16021627 String apduCmd = ApduUtils .apduTransceiveCmd .assembleAPDUString ();
1603- String chameleonCmd = "SEND " + apduCmd ;
1604- String respData = getSettingFromDevice (serialPort , chameleonCmd );
1605- String logMsg = String .format ("Sent %s as %s ... \n Response: %s" , ApduUtils .apduTransceiveCmd .apduCmdDesc , apduCmd , respData );
1628+ String logMsg = String .format ("Sent %s as %s ... \n " , ApduUtils .apduTransceiveCmd .apduCmdDesc , apduCmd );
1629+ for (int b = 0 ; b < apduCmd .length (); b += 2 ) {
1630+ String apduByte = apduCmd .substring (b , b + 2 );
1631+ String chameleonCmd = "SEND_RAW " + apduByte ;
1632+ String respData = getSettingFromDevice (serialPort , chameleonCmd );
1633+ logMsg += String .format (" %s => Response: %s" , apduByte , respData );
1634+ if (b + 2 < apduCmd .length ())
1635+ logMsg += "\n " ;
1636+ }
16061637 appendNewLog (LogEntryMetadataRecord .createDefaultEventRecord ("APDU" , logMsg ));
16071638 }
16081639
0 commit comments