1313import android .content .IntentFilter ;
1414import android .content .pm .PackageManager ;
1515import android .content .res .Configuration ;
16- import android .graphics .Color ;
1716import android .graphics .Typeface ;
1817import android .graphics .drawable .Drawable ;
1918import android .location .LocationManager ;
@@ -103,6 +102,7 @@ private enum PAIRING_STATE {
103102 PAIRING_STATE_TRIPLE ,
104103 PAIRING_STATE_STEP_1 ,
105104 PAIRING_STATE_STEP_2 ,
105+ PAIRING_STATE_ENTER_PIN_IF_NEEDED ,
106106 PAIRING_STATE_SEARCHING ,
107107 PAIRING_STATE_ERROR
108108 }
@@ -119,6 +119,7 @@ private enum PAIRING_STATE {
119119 LinearLayout pairTipView ;
120120 View connectDeviceView ;
121121 LinearLayout newDeviceView ;
122+ LinearLayout enterPinIfNeededView ;
122123 LinearLayout pairSearchView ;
123124 LinearLayout bottomPairButton ;
124125
@@ -221,7 +222,6 @@ public void run() {
221222 logi ("BLEPairResult " + result );
222223 switch ( result ) {
223224 case Found :
224- updateOnScanFound ();
225225// We need to connect even if bonded, to get resultHardwareVersion
226226// if ( getBLEPair().resultDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
227227// logi("scan found device already paired");
@@ -235,9 +235,6 @@ public void run() {
235235 popupPairingFailed ();
236236 }
237237 break ;
238- case Connected :
239- updateOnConnected ();
240- break ;
241238 case Paired :
242239 handlePairingSuccessful ();
243240 break ;
@@ -251,6 +248,7 @@ public void run() {
251248 popupPairingFailed ();
252249 break ;
253250 default :
251+ // Connected and None case are not specifically handled
254252 break ;
255253 }
256254 }
@@ -264,10 +262,6 @@ private void stopScanning() {
264262
265263 private void startScanning () {
266264 logi ("###>>>>>>>>>>>>>>>>>>>>> startScanning" );
267-
268- ((TextView ) findViewById (R .id .search_microbit_step_3_title ))
269- .setText (getString (R .string .searchingTitle ));
270-
271265 getBLEPair ().startScan ();
272266 }
273267
@@ -690,7 +684,7 @@ private void setupFontStyle() {
690684 nextPairButton .setTypeface (robotoTypeface );
691685
692686
693- // Step 2 - Enter Pattern
687+ // Enter Pattern
694688 TextView enterPatternTitle = (TextView ) findViewById (R .id .enter_pattern_step_2_title );
695689 enterPatternTitle .setTypeface (boldTypeface );
696690
@@ -706,17 +700,26 @@ private void setupFontStyle() {
706700 Button okEnterPatternButton = (Button ) findViewById (R .id .ok_enter_pattern_step_2_btn );
707701 okEnterPatternButton .setTypeface (robotoTypeface );
708702
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 );
709709
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
711717 TextView searchMicrobitTitle = (TextView ) findViewById (R .id .search_microbit_step_3_title );
712718 searchMicrobitTitle .setTypeface (boldTypeface );
713719
714720 TextView stepThreeTitle = (TextView ) findViewById (R .id .searching_microbit_step );
715721 stepThreeTitle .setTypeface (boldTypeface );
716722
717- TextView stepThreeInstructions = (TextView ) findViewById (R .id .searching_microbit_step_instructions );
718- stepThreeInstructions .setTypeface (robotoTypeface );
719-
720723 Button cancelSearchMicroBit = (Button ) findViewById (R .id .cancel_search_microbit_step_3_btn );
721724 cancelSearchMicroBit .setTypeface (robotoTypeface );
722725
@@ -739,6 +742,7 @@ private void initViews() {
739742 pairTipView = (LinearLayout ) findViewById (R .id .pairTipView );
740743 connectDeviceView = findViewById (R .id .connectDeviceView );
741744 newDeviceView = (LinearLayout ) findViewById (R .id .newDeviceView );
745+ enterPinIfNeededView = (LinearLayout ) findViewById (R .id .enterPinIfNeededView );
742746 pairSearchView = (LinearLayout ) findViewById (R .id .pairSearchView );
743747
744748 //Setup on click listeners.
@@ -751,6 +755,9 @@ private void initViews() {
751755 findViewById (R .id .ok_enter_pattern_step_2_btn ).setOnClickListener (this );
752756 findViewById (R .id .cancel_enter_pattern_step_2_btn ).setOnClickListener (this );
753757
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+
754761 findViewById (R .id .cancel_search_microbit_step_3_btn ).setOnClickListener (this );
755762
756763 setupFontStyle ();
@@ -764,6 +771,7 @@ private void releaseViews() {
764771 pairTipView = null ;
765772 connectDeviceView = null ;
766773 newDeviceView = null ;
774+ enterPinIfNeededView = null ;
767775 pairSearchView = null ;
768776 }
769777
@@ -1053,44 +1061,6 @@ private void updatePairedDeviceCard() {
10531061 logi ("updatePairedDeviceCard End" );
10541062 }
10551063
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-
10941064 /**
10951065 * Displays needed screen according to a pairing state and
10961066 * allows to navigate through the connection screens.
@@ -1102,6 +1072,7 @@ private void displayScreen(PAIRING_STATE gotoState) {
11021072 //Reset all screens first
11031073 pairTipView .setVisibility (View .GONE );
11041074 newDeviceView .setVisibility (View .GONE );
1075+ enterPinIfNeededView .setVisibility (View .GONE );
11051076 pairSearchView .setVisibility (View .GONE );
11061077 connectDeviceView .setVisibility (View .GONE );
11071078
@@ -1148,25 +1119,13 @@ private void displayScreen(PAIRING_STATE gotoState) {
11481119 displayLedGrid ();
11491120 break ;
11501121
1122+ case PAIRING_STATE_ENTER_PIN_IF_NEEDED :
1123+ enterPinIfNeededView .setVisibility (View .VISIBLE );
1124+ break ;
1125+
11511126 case PAIRING_STATE_SEARCHING :
11521127 if (pairSearchView != null ) {
11531128 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- }
11701129 justPaired = true ;
11711130 } else {
11721131 justPaired = false ;
@@ -1394,6 +1353,11 @@ public void onClick(final View v) {
13941353 if (!BluetoothChecker .getInstance ().checkBluetoothAndStart ()) {
13951354 return ;
13961355 }
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" );
13971361 startScanning ();
13981362 displayScreen (PAIRING_STATE .PAIRING_STATE_SEARCHING );
13991363 break ;
@@ -1413,6 +1377,12 @@ public void onClick(final View v) {
14131377 onFinish ( RESULT_CANCELED );
14141378 break ;
14151379
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+
14161386 case R .id .cancel_search_microbit_step_3_btn :
14171387 logi ("onClick() :: cancel_search_button" );
14181388 stopScanning ();
@@ -1602,6 +1572,7 @@ protected void onDestroy() {
16021572
16031573 pairTipView .setVisibility (View .GONE );
16041574 newDeviceView .setVisibility (View .GONE );
1575+ enterPinIfNeededView .setVisibility (View .GONE );
16051576 pairSearchView .setVisibility (View .GONE );
16061577 connectDeviceView .setVisibility (View .GONE );
16071578
@@ -1630,9 +1601,14 @@ protected void onDestroy() {
16301601 Utils .unbindDrawables (findViewById (R .id .oh_pretty_emoji ));
16311602 Utils .unbindDrawables (findViewById (R .id .cancel_enter_pattern_step_2_btn ));
16321603 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+
16331610 Utils .unbindDrawables (findViewById (R .id .search_microbit_step_3_title ));
16341611 Utils .unbindDrawables (findViewById (R .id .searching_microbit_step ));
1635- Utils .unbindDrawables (findViewById (R .id .searching_microbit_step_instructions ));
16361612 Utils .unbindDrawables (findViewById (R .id .cancel_search_microbit_step_3_btn ));
16371613 Utils .unbindDrawables (findViewById (R .id .searching_progress_spinner ));
16381614
0 commit comments