13
13
import android .content .IntentFilter ;
14
14
import android .content .pm .PackageManager ;
15
15
import android .content .res .Configuration ;
16
- import android .graphics .Color ;
17
16
import android .graphics .Typeface ;
18
17
import android .graphics .drawable .Drawable ;
19
18
import android .location .LocationManager ;
@@ -103,6 +102,7 @@ private enum PAIRING_STATE {
103
102
PAIRING_STATE_TRIPLE ,
104
103
PAIRING_STATE_STEP_1 ,
105
104
PAIRING_STATE_STEP_2 ,
105
+ PAIRING_STATE_ENTER_PIN_IF_NEEDED ,
106
106
PAIRING_STATE_SEARCHING ,
107
107
PAIRING_STATE_ERROR
108
108
}
@@ -119,6 +119,7 @@ private enum PAIRING_STATE {
119
119
LinearLayout pairTipView ;
120
120
View connectDeviceView ;
121
121
LinearLayout newDeviceView ;
122
+ LinearLayout enterPinIfNeededView ;
122
123
LinearLayout pairSearchView ;
123
124
LinearLayout bottomPairButton ;
124
125
@@ -221,7 +222,6 @@ public void run() {
221
222
logi ("BLEPairResult " + result );
222
223
switch ( result ) {
223
224
case Found :
224
- updateOnScanFound ();
225
225
// We need to connect even if bonded, to get resultHardwareVersion
226
226
// if ( getBLEPair().resultDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
227
227
// logi("scan found device already paired");
@@ -235,9 +235,6 @@ public void run() {
235
235
popupPairingFailed ();
236
236
}
237
237
break ;
238
- case Connected :
239
- updateOnConnected ();
240
- break ;
241
238
case Paired :
242
239
handlePairingSuccessful ();
243
240
break ;
@@ -251,6 +248,7 @@ public void run() {
251
248
popupPairingFailed ();
252
249
break ;
253
250
default :
251
+ // Connected and None case are not specifically handled
254
252
break ;
255
253
}
256
254
}
@@ -264,10 +262,6 @@ private void stopScanning() {
264
262
265
263
private void startScanning () {
266
264
logi ("###>>>>>>>>>>>>>>>>>>>>> startScanning" );
267
-
268
- ((TextView ) findViewById (R .id .search_microbit_step_3_title ))
269
- .setText (getString (R .string .searchingTitle ));
270
-
271
265
getBLEPair ().startScan ();
272
266
}
273
267
@@ -690,7 +684,7 @@ private void setupFontStyle() {
690
684
nextPairButton .setTypeface (robotoTypeface );
691
685
692
686
693
- // Step 2 - Enter Pattern
687
+ // Enter Pattern
694
688
TextView enterPatternTitle = (TextView ) findViewById (R .id .enter_pattern_step_2_title );
695
689
enterPatternTitle .setTypeface (boldTypeface );
696
690
@@ -706,17 +700,26 @@ private void setupFontStyle() {
706
700
Button okEnterPatternButton = (Button ) findViewById (R .id .ok_enter_pattern_step_2_btn );
707
701
okEnterPatternButton .setTypeface (robotoTypeface );
708
702
703
+ // Enter pin if needed
704
+ TextView enterPinIfNeededTitle = (TextView ) findViewById (R .id .enter_pin_if_needed_title );
705
+ enterPinIfNeededTitle .setTypeface (boldTypeface );
706
+
707
+ TextView enterPinIfNeededText = (TextView ) findViewById (R .id .enter_pin_if_needed_text );
708
+ enterPinIfNeededText .setTypeface (boldTypeface );
709
709
710
- // Step 3 - Searching for micro:bit
710
+ Button cancelEnterPinIfNeededButton = (Button ) findViewById (R .id .cancel_enter_pin_if_needed_btn );
711
+ cancelEnterPinIfNeededButton .setTypeface (robotoTypeface );
712
+
713
+ Button nextEnterPinIfNeededButton = (Button ) findViewById (R .id .next_enter_pin_if_needed_btn );
714
+ nextEnterPinIfNeededButton .setTypeface (robotoTypeface );
715
+
716
+ // Searching for micro:bit
711
717
TextView searchMicrobitTitle = (TextView ) findViewById (R .id .search_microbit_step_3_title );
712
718
searchMicrobitTitle .setTypeface (boldTypeface );
713
719
714
720
TextView stepThreeTitle = (TextView ) findViewById (R .id .searching_microbit_step );
715
721
stepThreeTitle .setTypeface (boldTypeface );
716
722
717
- TextView stepThreeInstructions = (TextView ) findViewById (R .id .searching_microbit_step_instructions );
718
- stepThreeInstructions .setTypeface (robotoTypeface );
719
-
720
723
Button cancelSearchMicroBit = (Button ) findViewById (R .id .cancel_search_microbit_step_3_btn );
721
724
cancelSearchMicroBit .setTypeface (robotoTypeface );
722
725
@@ -739,6 +742,7 @@ private void initViews() {
739
742
pairTipView = (LinearLayout ) findViewById (R .id .pairTipView );
740
743
connectDeviceView = findViewById (R .id .connectDeviceView );
741
744
newDeviceView = (LinearLayout ) findViewById (R .id .newDeviceView );
745
+ enterPinIfNeededView = (LinearLayout ) findViewById (R .id .enterPinIfNeededView );
742
746
pairSearchView = (LinearLayout ) findViewById (R .id .pairSearchView );
743
747
744
748
//Setup on click listeners.
@@ -751,6 +755,9 @@ private void initViews() {
751
755
findViewById (R .id .ok_enter_pattern_step_2_btn ).setOnClickListener (this );
752
756
findViewById (R .id .cancel_enter_pattern_step_2_btn ).setOnClickListener (this );
753
757
758
+ findViewById (R .id .next_enter_pin_if_needed_btn ).setOnClickListener (this );
759
+ findViewById (R .id .cancel_enter_pin_if_needed_btn ).setOnClickListener (this );
760
+
754
761
findViewById (R .id .cancel_search_microbit_step_3_btn ).setOnClickListener (this );
755
762
756
763
setupFontStyle ();
@@ -764,6 +771,7 @@ private void releaseViews() {
764
771
pairTipView = null ;
765
772
connectDeviceView = null ;
766
773
newDeviceView = null ;
774
+ enterPinIfNeededView = null ;
767
775
pairSearchView = null ;
768
776
}
769
777
@@ -1053,44 +1061,6 @@ private void updatePairedDeviceCard() {
1053
1061
logi ("updatePairedDeviceCard End" );
1054
1062
}
1055
1063
1056
- private void updateOnScanFound () {
1057
- logi ("updateOnScanFound" );
1058
- TextView textView = (TextView ) findViewById (R .id .search_microbit_step_3_title );
1059
- TextView tvSearchingStep = (TextView ) findViewById (R .id .searching_microbit_step );
1060
- TextView tvSearchingInstructions = (TextView ) findViewById (R .id .searching_microbit_step_instructions );
1061
- if (textView != null ) {
1062
- textView .setText (getString (R .string .searchingTitle ));
1063
- //findViewById(R.id.searching_progress_spinner).setVisibility(View.GONE);
1064
- ((GifImageView ) findViewById (R .id .searching_microbit_found_giffview ))
1065
- .setImageResource (R .drawable .emoji_microbit_found );
1066
- // if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
1067
- // tvSearchingStep.setText(R.string.searching_microbit_found_message_one_line);
1068
- // } else {
1069
- // tvSearchingStep.setText(R.string.searching_microbit_found_message);
1070
- // }
1071
- // tvSearchingInstructions.setText(R.string.searching_tip_text_instructions);
1072
- }
1073
- }
1074
-
1075
- private void updateOnConnected () {
1076
- logi ("updateOnConnected" );
1077
- TextView textView = (TextView ) findViewById (R .id .search_microbit_step_3_title );
1078
- TextView tvSearchingStep = (TextView ) findViewById (R .id .searching_microbit_step );
1079
- TextView tvSearchingInstructions = (TextView ) findViewById (R .id .searching_microbit_step_instructions );
1080
- if (textView != null ) {
1081
- textView .setText (getString (R .string .searchingTitle ));
1082
- findViewById (R .id .searching_progress_spinner ).setVisibility (View .GONE );
1083
- ((GifImageView ) findViewById (R .id .searching_microbit_found_giffview ))
1084
- .setImageResource (R .drawable .emoji_microbit_found );
1085
- if (currentOrientation == Configuration .ORIENTATION_LANDSCAPE ) {
1086
- tvSearchingStep .setText (R .string .searching_microbit_found_message_one_line );
1087
- } else {
1088
- tvSearchingStep .setText (R .string .searching_microbit_found_message );
1089
- }
1090
- tvSearchingInstructions .setText (R .string .searching_tip_text_instructions );
1091
- }
1092
- }
1093
-
1094
1064
/**
1095
1065
* Displays needed screen according to a pairing state and
1096
1066
* allows to navigate through the connection screens.
@@ -1102,6 +1072,7 @@ private void displayScreen(PAIRING_STATE gotoState) {
1102
1072
//Reset all screens first
1103
1073
pairTipView .setVisibility (View .GONE );
1104
1074
newDeviceView .setVisibility (View .GONE );
1075
+ enterPinIfNeededView .setVisibility (View .GONE );
1105
1076
pairSearchView .setVisibility (View .GONE );
1106
1077
connectDeviceView .setVisibility (View .GONE );
1107
1078
@@ -1148,25 +1119,13 @@ private void displayScreen(PAIRING_STATE gotoState) {
1148
1119
displayLedGrid ();
1149
1120
break ;
1150
1121
1122
+ case PAIRING_STATE_ENTER_PIN_IF_NEEDED :
1123
+ enterPinIfNeededView .setVisibility (View .VISIBLE );
1124
+ break ;
1125
+
1151
1126
case PAIRING_STATE_SEARCHING :
1152
1127
if (pairSearchView != null ) {
1153
1128
pairSearchView .setVisibility (View .VISIBLE );
1154
- TextView tvTitle = (TextView ) findViewById (R .id .search_microbit_step_3_title );
1155
- TextView tvSearchingStep = (TextView ) findViewById (R .id .searching_microbit_step );
1156
- tvSearchingStep .setContentDescription (tvSearchingStep .getText ());
1157
- TextView tvSearchingInstructions = (TextView ) findViewById (R .id .searching_microbit_step_instructions );
1158
- if (tvTitle != null ) {
1159
- tvTitle .setText (R .string .searchingTitle );
1160
- findViewById (R .id .searching_progress_spinner ).setVisibility (View .VISIBLE );
1161
- ((GifImageView ) findViewById (R .id .searching_microbit_found_giffview ))
1162
- .setImageResource (R .drawable .pairing_pin_screen_two );
1163
- if (currentOrientation == Configuration .ORIENTATION_LANDSCAPE ) {
1164
- tvSearchingStep .setText (R .string .searching_tip_step_text_one_line );
1165
- } else {
1166
- tvSearchingStep .setText (R .string .searching_tip_step_text );
1167
- }
1168
- tvSearchingInstructions .setText (R .string .searching_tip_text_instructions );
1169
- }
1170
1129
justPaired = true ;
1171
1130
} else {
1172
1131
justPaired = false ;
@@ -1394,6 +1353,11 @@ public void onClick(final View v) {
1394
1353
if (!BluetoothChecker .getInstance ().checkBluetoothAndStart ()) {
1395
1354
return ;
1396
1355
}
1356
+ displayScreen (PAIRING_STATE .PAIRING_STATE_ENTER_PIN_IF_NEEDED );
1357
+ break ;
1358
+
1359
+ case R .id .next_enter_pin_if_needed_btn :
1360
+ logi ("onClick() :: next_enter_pin_if_needed_btn" );
1397
1361
startScanning ();
1398
1362
displayScreen (PAIRING_STATE .PAIRING_STATE_SEARCHING );
1399
1363
break ;
@@ -1413,6 +1377,12 @@ public void onClick(final View v) {
1413
1377
onFinish ( RESULT_CANCELED );
1414
1378
break ;
1415
1379
1380
+ case R .id .cancel_enter_pin_if_needed_btn :
1381
+ logi ("onClick() :: cancel_enter_pin_if_needed_btn" );
1382
+ stopScanning ();
1383
+ onFinish ( RESULT_CANCELED );
1384
+ break ;
1385
+
1416
1386
case R .id .cancel_search_microbit_step_3_btn :
1417
1387
logi ("onClick() :: cancel_search_button" );
1418
1388
stopScanning ();
@@ -1602,6 +1572,7 @@ protected void onDestroy() {
1602
1572
1603
1573
pairTipView .setVisibility (View .GONE );
1604
1574
newDeviceView .setVisibility (View .GONE );
1575
+ enterPinIfNeededView .setVisibility (View .GONE );
1605
1576
pairSearchView .setVisibility (View .GONE );
1606
1577
connectDeviceView .setVisibility (View .GONE );
1607
1578
@@ -1630,9 +1601,14 @@ protected void onDestroy() {
1630
1601
Utils .unbindDrawables (findViewById (R .id .oh_pretty_emoji ));
1631
1602
Utils .unbindDrawables (findViewById (R .id .cancel_enter_pattern_step_2_btn ));
1632
1603
Utils .unbindDrawables (findViewById (R .id .ok_enter_pattern_step_2_btn ));
1604
+
1605
+ Utils .unbindDrawables (findViewById (R .id .enter_pin_if_needed_title ));
1606
+ Utils .unbindDrawables (findViewById (R .id .enter_pin_if_needed_text ));
1607
+ Utils .unbindDrawables (findViewById (R .id .cancel_enter_pin_if_needed_btn ));
1608
+ Utils .unbindDrawables (findViewById (R .id .enterPinIfNeededView ));
1609
+
1633
1610
Utils .unbindDrawables (findViewById (R .id .search_microbit_step_3_title ));
1634
1611
Utils .unbindDrawables (findViewById (R .id .searching_microbit_step ));
1635
- Utils .unbindDrawables (findViewById (R .id .searching_microbit_step_instructions ));
1636
1612
Utils .unbindDrawables (findViewById (R .id .cancel_search_microbit_step_3_btn ));
1637
1613
Utils .unbindDrawables (findViewById (R .id .searching_progress_spinner ));
1638
1614
0 commit comments