@@ -152,6 +152,53 @@ private enum PAIRING_STATE {
152152
153153 private BLEPair blePair = null ;
154154
155+ public final static String ACTION_RESET_TO_BLE = "com.samsung.microbit.ACTION_RESET_TO_BLE" ;
156+ public final static String ACTION_PAIR_BEFORE_FLASH = "com.samsung.microbit.ACTION_PAIR_BEFORE_FLASH" ;
157+
158+ private String inAction = null ;
159+
160+ @ Override
161+ protected void onNewIntent (Intent intent ) {
162+ super .onNewIntent (intent );
163+ if (intent != null ) {
164+ handleIncomingIntent (intent );
165+ }
166+ }
167+
168+ private void handleIncomingIntent (Intent intent ) {
169+ inAction = intent .getAction ();
170+ if ( inAction != null ) {
171+ if ( inAction .equals (ACTION_RESET_TO_BLE )) {
172+ resetToBLEStart ();
173+ return ;
174+ }
175+ if ( inAction .equals (ACTION_PAIR_BEFORE_FLASH )) {
176+ pairBeforeFlashStart ();
177+ return ;
178+ }
179+ }
180+ }
181+
182+ private void resetToBLEStart () {
183+ displayScreen (PAIRING_STATE .PAIRING_STATE_TRIPLE );
184+ }
185+
186+ private void resetToBLEFinish ( int resultCode ) {
187+ inAction = null ;
188+ setResult ( resultCode );
189+ finish ();
190+ }
191+
192+ private void pairBeforeFlashStart () {
193+ displayScreen (PAIRING_STATE .PAIRING_STATE_TRIPLE );
194+ }
195+
196+ private void pairBeforeFlashFinish ( int resultCode ) {
197+ inAction = null ;
198+ setResult ( resultCode );
199+ finish ();
200+ }
201+
155202 private BLEPair getBLEPair () {
156203 if ( blePair == null ) {
157204 blePair = new BLEPair ( this );
@@ -427,6 +474,10 @@ private void popupPermissionPairing() {
427474 public void onClick (View v ) {
428475 logi ("======successfulPairingHandler======" );
429476 PopUp .hide ();
477+ if ( inAction .equals (ACTION_PAIR_BEFORE_FLASH )) {
478+ pairBeforeFlashFinish ( RESULT_OK );
479+ return ;
480+ }
430481 displayScreen (PAIRING_STATE .PAIRING_STATE_CONNECT_BUTTON );
431482 }
432483 };
@@ -440,6 +491,10 @@ public void onClick(View v) {
440491 public void onClick (View v ) {
441492 logi ("======failedPairingHandler======" );
442493 PopUp .hide ();
494+ if ( inAction .equals (ACTION_PAIR_BEFORE_FLASH )) {
495+ pairBeforeFlashFinish ( RESULT_CANCELED );
496+ return ;
497+ }
443498 displayScreen (PAIRING_STATE .PAIRING_STATE_STEP_2 );
444499 }
445500 };
@@ -782,8 +837,12 @@ protected void onCreate(Bundle savedInstanceState) {
782837
783838 currentOrientation = getResources ().getConfiguration ().orientation ;
784839
785- // pin view
786- displayScreen (pairingState );
840+ if (savedInstanceState == null && getIntent () != null ) {
841+ handleIncomingIntent (getIntent ());
842+ } else {
843+ // pin view
844+ displayScreen (pairingState );
845+ }
787846 }
788847
789848 @ Override
@@ -1102,26 +1161,18 @@ private void displayScreen(PAIRING_STATE gotoState) {
11021161 newDeviceCode = "" ;
11031162 break ;
11041163
1105- case PAIRING_STATE_TRIPLE : {
1106- GifImageView view = (GifImageView ) findViewById (R .id .pair_tip_step_1_giff );
1107- view .setImageResource (R .drawable .reset_triple );
1108- TextView prompt = (TextView ) findViewById (R .id .pair_tip_step_1_instructions );
1109- prompt .setText (R .string .viewPairTriplePromptText );
1110- prompt .setContentDescription (prompt .getText ());
1111- pairTipView .setVisibility (View .VISIBLE );
1112- view .animate ();
1164+ case PAIRING_STATE_TRIPLE :
1165+ displayScreenTripleOrStep1 (
1166+ R .drawable .reset_triple ,
1167+ R .string .viewPairTriplePromptText );
11131168 break ;
1114- }
1115- case PAIRING_STATE_STEP_1 : {
1116- GifImageView view = (GifImageView ) findViewById (R .id .pair_tip_step_1_giff );
1117- view .setImageResource (R .drawable .how_to_pair_microbit );
1118- TextView prompt = (TextView ) findViewById (R .id .pair_tip_step_1_instructions );
1119- prompt .setText (R .string .connect_tip_text );
1120- prompt .setContentDescription (prompt .getText ());
1121- pairTipView .setVisibility (View .VISIBLE );
1122- view .animate ();
1169+
1170+ case PAIRING_STATE_STEP_1 :
1171+ displayScreenTripleOrStep1 (
1172+ R .drawable .how_to_pair_microbit ,
1173+ R .string .connect_tip_text );
11231174 break ;
1124- }
1175+
11251176 case PAIRING_STATE_STEP_2 :
11261177 newDeviceView .setVisibility (View .VISIBLE );
11271178 findViewById (R .id .cancel_enter_pattern_step_2_btn ).setVisibility (View .VISIBLE );
@@ -1159,6 +1210,27 @@ private void displayScreen(PAIRING_STATE gotoState) {
11591210 logi ("displayScreen End" );
11601211 }
11611212
1213+ private void displayScreenTripleOrStep1 ( int resIdGif , int resIdPrompt )
1214+ {
1215+ if ( inAction .equals (ACTION_RESET_TO_BLE )) {
1216+ TextView title = (TextView ) findViewById (R .id .pairTipTitle );
1217+ title .setText (R .string .connect_tip_title_resetToBLE );
1218+ TextView step = (TextView ) findViewById (R .id .pair_tip_step_1_step );
1219+ step .setText ("" );
1220+ step .setContentDescription ("" );
1221+ }
1222+
1223+ GifImageView gif = (GifImageView ) findViewById (R .id .pair_tip_step_1_giff );
1224+ gif .setImageResource ( resIdGif );
1225+
1226+ TextView prompt = (TextView ) findViewById (R .id .pair_tip_step_1_instructions );
1227+ prompt .setText ( resIdPrompt );
1228+ prompt .setContentDescription (prompt .getText ());
1229+
1230+ pairTipView .setVisibility (View .VISIBLE );
1231+ gif .animate ();
1232+ }
1233+
11621234 /**
11631235 * Starts activity to enable bluetooth.
11641236 */
@@ -1342,6 +1414,10 @@ public void onClick(final View v) {
13421414 // Proceed to Enter Pattern
13431415 case R .id .ok_tip_step_1_btn :
13441416 logi ("onClick() :: ok_tip_screen_one_button" );
1417+ if ( inAction .equals (ACTION_RESET_TO_BLE )) {
1418+ resetToBLEFinish (Activity .RESULT_OK );
1419+ return ;
1420+ }
13451421 displayScreen (PAIRING_STATE .PAIRING_STATE_STEP_2 );
13461422 break ;
13471423
@@ -1358,18 +1434,34 @@ public void onClick(final View v) {
13581434
13591435 case R .id .cancel_tip_step_1_btn :
13601436 logi ("onClick() :: cancel_tip_button" );
1437+ if ( inAction .equals (ACTION_RESET_TO_BLE )) {
1438+ resetToBLEFinish (Activity .RESULT_CANCELED );
1439+ return ;
1440+ }
1441+ if ( inAction .equals (ACTION_PAIR_BEFORE_FLASH )) {
1442+ pairBeforeFlashFinish ( RESULT_CANCELED );
1443+ return ;
1444+ }
13611445 displayScreen (PAIRING_STATE .PAIRING_STATE_CONNECT_BUTTON );
13621446 break ;
13631447
13641448 case R .id .cancel_enter_pattern_step_2_btn :
13651449 logi ("onClick() :: cancel_name_button" );
13661450 stopScanning ();
1451+ if ( inAction .equals (ACTION_PAIR_BEFORE_FLASH )) {
1452+ pairBeforeFlashFinish ( RESULT_CANCELED );
1453+ return ;
1454+ }
13671455 displayScreen (PAIRING_STATE .PAIRING_STATE_CONNECT_BUTTON );
13681456 break ;
13691457
13701458 case R .id .cancel_search_microbit_step_3_btn :
13711459 logi ("onClick() :: cancel_search_button" );
13721460 stopScanning ();
1461+ if ( inAction .equals (ACTION_PAIR_BEFORE_FLASH )) {
1462+ pairBeforeFlashFinish ( RESULT_CANCELED );
1463+ return ;
1464+ }
13731465 displayScreen (PAIRING_STATE .PAIRING_STATE_CONNECT_BUTTON );
13741466 break ;
13751467
@@ -1457,7 +1549,10 @@ private void unPairDevice() {
14571549 private void handleResetAll () {
14581550 Arrays .fill (DEVICE_CODE_ARRAY , 0 );
14591551 stopScanning ();
1460-
1552+ if ( inAction .equals (ACTION_PAIR_BEFORE_FLASH )) {
1553+ pairBeforeFlashFinish ( RESULT_CANCELED );
1554+ return ;
1555+ }
14611556 if (pairingState == PAIRING_STATE .PAIRING_STATE_CONNECT_BUTTON ) {
14621557 finish ();
14631558 } else {
@@ -1516,6 +1611,10 @@ public void onClick(View v) {
15161611 @ Override
15171612 public void onClick (View v ) {
15181613 PopUp .hide ();
1614+ if ( inAction .equals (ACTION_PAIR_BEFORE_FLASH )) {
1615+ pairBeforeFlashFinish ( RESULT_CANCELED );
1616+ return ;
1617+ }
15191618 displayScreen (PAIRING_STATE .PAIRING_STATE_CONNECT_BUTTON );
15201619 }
15211620 });
@@ -1557,9 +1656,6 @@ private void handlePairingSuccessful() {
15571656 }
15581657 }
15591658
1560-
1561-
1562-
15631659 @ Override
15641660 protected void onDestroy () {
15651661 super .onDestroy ();
0 commit comments