Skip to content

Commit

Permalink
Tweak pairing micro:bit wording and adding a step for pin (#57)
Browse files Browse the repository at this point in the history
- Added enter pin if needed instruction step to pairing flow
- Remove 30 sec warning text
- Tweaked searching for micro:bit text
  • Loading branch information
microbit-grace authored May 14, 2024
1 parent be8e11c commit 30ac80f
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
Expand Down Expand Up @@ -103,6 +102,7 @@ private enum PAIRING_STATE {
PAIRING_STATE_TRIPLE,
PAIRING_STATE_STEP_1,
PAIRING_STATE_STEP_2,
PAIRING_STATE_ENTER_PIN_IF_NEEDED,
PAIRING_STATE_SEARCHING,
PAIRING_STATE_ERROR
}
Expand All @@ -119,6 +119,7 @@ private enum PAIRING_STATE {
LinearLayout pairTipView;
View connectDeviceView;
LinearLayout newDeviceView;
LinearLayout enterPinIfNeededView;
LinearLayout pairSearchView;
LinearLayout bottomPairButton;

Expand Down Expand Up @@ -221,7 +222,6 @@ public void run() {
logi("BLEPairResult " + result);
switch ( result) {
case Found:
updateOnScanFound();
// We need to connect even if bonded, to get resultHardwareVersion
// if ( getBLEPair().resultDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
// logi("scan found device already paired");
Expand All @@ -235,9 +235,6 @@ public void run() {
popupPairingFailed();
}
break;
case Connected:
updateOnConnected();
break;
case Paired:
handlePairingSuccessful();
break;
Expand All @@ -251,6 +248,7 @@ public void run() {
popupPairingFailed();
break;
default:
// Connected and None case are not specifically handled
break;
}
}
Expand All @@ -264,10 +262,6 @@ private void stopScanning() {

private void startScanning() {
logi("###>>>>>>>>>>>>>>>>>>>>> startScanning");

((TextView) findViewById(R.id.search_microbit_step_3_title))
.setText(getString(R.string.searchingTitle));

getBLEPair().startScan();
}

Expand Down Expand Up @@ -690,7 +684,7 @@ private void setupFontStyle() {
nextPairButton.setTypeface(robotoTypeface);


// Step 2 - Enter Pattern
// Enter Pattern
TextView enterPatternTitle = (TextView) findViewById(R.id.enter_pattern_step_2_title);
enterPatternTitle.setTypeface(boldTypeface);

Expand All @@ -706,17 +700,26 @@ private void setupFontStyle() {
Button okEnterPatternButton = (Button) findViewById(R.id.ok_enter_pattern_step_2_btn);
okEnterPatternButton.setTypeface(robotoTypeface);

// Enter pin if needed
TextView enterPinIfNeededTitle = (TextView) findViewById(R.id.enter_pin_if_needed_title);
enterPinIfNeededTitle.setTypeface(boldTypeface);

TextView enterPinIfNeededText = (TextView) findViewById(R.id.enter_pin_if_needed_text);
enterPinIfNeededText.setTypeface(boldTypeface);

// Step 3 - Searching for micro:bit
Button cancelEnterPinIfNeededButton = (Button) findViewById(R.id.cancel_enter_pin_if_needed_btn);
cancelEnterPinIfNeededButton.setTypeface(robotoTypeface);

Button nextEnterPinIfNeededButton = (Button) findViewById(R.id.next_enter_pin_if_needed_btn);
nextEnterPinIfNeededButton.setTypeface(robotoTypeface);

// Searching for micro:bit
TextView searchMicrobitTitle = (TextView) findViewById(R.id.search_microbit_step_3_title);
searchMicrobitTitle.setTypeface(boldTypeface);

TextView stepThreeTitle = (TextView) findViewById(R.id.searching_microbit_step);
stepThreeTitle.setTypeface(boldTypeface);

TextView stepThreeInstructions = (TextView) findViewById(R.id.searching_microbit_step_instructions);
stepThreeInstructions.setTypeface(robotoTypeface);

Button cancelSearchMicroBit = (Button) findViewById(R.id.cancel_search_microbit_step_3_btn);
cancelSearchMicroBit.setTypeface(robotoTypeface);

Expand All @@ -739,6 +742,7 @@ private void initViews() {
pairTipView = (LinearLayout) findViewById(R.id.pairTipView);
connectDeviceView = findViewById(R.id.connectDeviceView);
newDeviceView = (LinearLayout) findViewById(R.id.newDeviceView);
enterPinIfNeededView = (LinearLayout) findViewById(R.id.enterPinIfNeededView);
pairSearchView = (LinearLayout) findViewById(R.id.pairSearchView);

//Setup on click listeners.
Expand All @@ -751,6 +755,9 @@ private void initViews() {
findViewById(R.id.ok_enter_pattern_step_2_btn).setOnClickListener(this);
findViewById(R.id.cancel_enter_pattern_step_2_btn).setOnClickListener(this);

findViewById(R.id.next_enter_pin_if_needed_btn).setOnClickListener(this);
findViewById(R.id.cancel_enter_pin_if_needed_btn).setOnClickListener(this);

findViewById(R.id.cancel_search_microbit_step_3_btn).setOnClickListener(this);

setupFontStyle();
Expand All @@ -764,6 +771,7 @@ private void releaseViews() {
pairTipView = null;
connectDeviceView = null;
newDeviceView = null;
enterPinIfNeededView = null;
pairSearchView = null;
}

Expand Down Expand Up @@ -1053,44 +1061,6 @@ private void updatePairedDeviceCard() {
logi("updatePairedDeviceCard End");
}

private void updateOnScanFound() {
logi("updateOnScanFound");
TextView textView = (TextView) findViewById(R.id.search_microbit_step_3_title);
TextView tvSearchingStep = (TextView) findViewById(R.id.searching_microbit_step);
TextView tvSearchingInstructions = (TextView) findViewById(R.id.searching_microbit_step_instructions);
if (textView != null) {
textView.setText(getString(R.string.searchingTitle));
//findViewById(R.id.searching_progress_spinner).setVisibility(View.GONE);
((GifImageView) findViewById(R.id.searching_microbit_found_giffview))
.setImageResource(R.drawable.emoji_microbit_found);
// if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
// tvSearchingStep.setText(R.string.searching_microbit_found_message_one_line);
// } else {
// tvSearchingStep.setText(R.string.searching_microbit_found_message);
// }
// tvSearchingInstructions.setText(R.string.searching_tip_text_instructions);
}
}

private void updateOnConnected() {
logi("updateOnConnected");
TextView textView = (TextView) findViewById(R.id.search_microbit_step_3_title);
TextView tvSearchingStep = (TextView) findViewById(R.id.searching_microbit_step);
TextView tvSearchingInstructions = (TextView) findViewById(R.id.searching_microbit_step_instructions);
if (textView != null) {
textView.setText(getString(R.string.searchingTitle));
findViewById(R.id.searching_progress_spinner).setVisibility(View.GONE);
((GifImageView) findViewById(R.id.searching_microbit_found_giffview))
.setImageResource(R.drawable.emoji_microbit_found);
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
tvSearchingStep.setText(R.string.searching_microbit_found_message_one_line);
} else {
tvSearchingStep.setText(R.string.searching_microbit_found_message);
}
tvSearchingInstructions.setText(R.string.searching_tip_text_instructions);
}
}

/**
* Displays needed screen according to a pairing state and
* allows to navigate through the connection screens.
Expand All @@ -1102,6 +1072,7 @@ private void displayScreen(PAIRING_STATE gotoState) {
//Reset all screens first
pairTipView.setVisibility(View.GONE);
newDeviceView.setVisibility(View.GONE);
enterPinIfNeededView.setVisibility(View.GONE);
pairSearchView.setVisibility(View.GONE);
connectDeviceView.setVisibility(View.GONE);

Expand Down Expand Up @@ -1148,25 +1119,13 @@ private void displayScreen(PAIRING_STATE gotoState) {
displayLedGrid();
break;

case PAIRING_STATE_ENTER_PIN_IF_NEEDED:
enterPinIfNeededView.setVisibility(View.VISIBLE);
break;

case PAIRING_STATE_SEARCHING:
if(pairSearchView != null) {
pairSearchView.setVisibility(View.VISIBLE);
TextView tvTitle = (TextView) findViewById(R.id.search_microbit_step_3_title);
TextView tvSearchingStep = (TextView) findViewById(R.id.searching_microbit_step);
tvSearchingStep.setContentDescription(tvSearchingStep.getText());
TextView tvSearchingInstructions = (TextView) findViewById(R.id.searching_microbit_step_instructions);
if(tvTitle != null) {
tvTitle.setText(R.string.searchingTitle);
findViewById(R.id.searching_progress_spinner).setVisibility(View.VISIBLE);
((GifImageView) findViewById(R.id.searching_microbit_found_giffview))
.setImageResource(R.drawable.pairing_pin_screen_two);
if(currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
tvSearchingStep.setText(R.string.searching_tip_step_text_one_line);
} else {
tvSearchingStep.setText(R.string.searching_tip_step_text);
}
tvSearchingInstructions.setText(R.string.searching_tip_text_instructions);
}
justPaired = true;
} else {
justPaired = false;
Expand Down Expand Up @@ -1394,6 +1353,11 @@ public void onClick(final View v) {
if(!BluetoothChecker.getInstance().checkBluetoothAndStart()) {
return;
}
displayScreen(PAIRING_STATE.PAIRING_STATE_ENTER_PIN_IF_NEEDED);
break;

case R.id.next_enter_pin_if_needed_btn:
logi("onClick() :: next_enter_pin_if_needed_btn");
startScanning();
displayScreen(PAIRING_STATE.PAIRING_STATE_SEARCHING);
break;
Expand All @@ -1413,6 +1377,12 @@ public void onClick(final View v) {
onFinish( RESULT_CANCELED);
break;

case R.id.cancel_enter_pin_if_needed_btn:
logi("onClick() :: cancel_enter_pin_if_needed_btn");
stopScanning();
onFinish( RESULT_CANCELED);
break;

case R.id.cancel_search_microbit_step_3_btn:
logi("onClick() :: cancel_search_button");
stopScanning();
Expand Down Expand Up @@ -1602,6 +1572,7 @@ protected void onDestroy() {

pairTipView.setVisibility(View.GONE);
newDeviceView.setVisibility(View.GONE);
enterPinIfNeededView.setVisibility(View.GONE);
pairSearchView.setVisibility(View.GONE);
connectDeviceView.setVisibility(View.GONE);

Expand Down Expand Up @@ -1630,9 +1601,14 @@ protected void onDestroy() {
Utils.unbindDrawables(findViewById(R.id.oh_pretty_emoji));
Utils.unbindDrawables(findViewById(R.id.cancel_enter_pattern_step_2_btn));
Utils.unbindDrawables(findViewById(R.id.ok_enter_pattern_step_2_btn));

Utils.unbindDrawables(findViewById(R.id.enter_pin_if_needed_title));
Utils.unbindDrawables(findViewById(R.id.enter_pin_if_needed_text));
Utils.unbindDrawables(findViewById(R.id.cancel_enter_pin_if_needed_btn));
Utils.unbindDrawables(findViewById(R.id.enterPinIfNeededView));

Utils.unbindDrawables(findViewById(R.id.search_microbit_step_3_title));
Utils.unbindDrawables(findViewById(R.id.searching_microbit_step));
Utils.unbindDrawables(findViewById(R.id.searching_microbit_step_instructions));
Utils.unbindDrawables(findViewById(R.id.cancel_search_microbit_step_3_btn));
Utils.unbindDrawables(findViewById(R.id.searching_progress_spinner));

Expand Down
93 changes: 93 additions & 0 deletions app/src/main/res/layout-land/view_enter_pin_if_needed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/enterPinIfNeededView"
style="@style/pairing_step_layout_style"
android:orientation="horizontal"
android:keepScreenOn="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="@dimen/pairing_step_layout_margin"
android:layout_marginBottom="@dimen/pairing_step_layout_margin"
android:baselineAligned="false"
android:layout_marginStart="@dimen/pairing_step_title_and_gif_layout_margin_start">

<RelativeLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">

<!-- Title -->
<TextView
android:id="@+id/enter_pin_if_needed_title"
style="@style/pairing_step_header_style"
android:text="@string/enter_pin_if_needed_title" />

<!--pairing animation-->
<pl.droidsonroids.gif.GifImageView
android:layout_width="@dimen/pairing_step_1_gif_image_width"
android:layout_height="@dimen/pairing_step_1_gif_image_height"
android:layout_below="@id/enter_pin_if_needed_title"
android:src="@drawable/pairing_pin_screen_two" />
</RelativeLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">

<TextView
android:id="@+id/enter_pin_if_needed_text"
style="@style/pairing_step_tip_text_style"
android:textSize="@dimen/pairing_step_title_text_size"
android:text="@string/enter_pin_if_needed_next_text" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="@id/enter_pin_if_needed_text"
android:layout_centerInParent="true">
<TextView
style="@style/pairing_step_tip_text_style"
android:layout_width="@dimen/pairing_step_text_width"
android:textSize="@dimen/pairing_step_tip_instruction_text_size"
android:layout_alignBottom="@id/pairing_step_one_image"
android:text="@string/enter_pin_if_needed_text_one_line" />

<ImageView
android:id="@+id/pairing_step_one_image"
style="@style/pairing_step_image_layout_style"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_person_step_1" />
</RelativeLayout>

<!-- Pairing confirmation buttons-->
<LinearLayout
android:id="@+id/enter_pin_if_needed_confirmation_view"
style="@style/pairing_step_buttons_layout_style"
android:layout_alignParentBottom="true"
android:paddingBottom="0dp">

<Button
android:id="@+id/cancel_enter_pin_if_needed_btn"
style="@style/pairing_step_button_style"
android:layout_marginEnd="@dimen/pairing_step_buttons_space_margin"
android:background="@drawable/cancel_btn"
android:drawableEnd="@drawable/cancel_step_pairing_btn"
android:text="@string/txt_cancel_btn" />

<Button
android:id="@+id/next_enter_pin_if_needed_btn"
style="@style/pairing_step_button_style"
android:layout_marginStart="@dimen/pairing_step_buttons_space_margin"
android:background="@drawable/green_btn"
android:drawableEnd="@drawable/ic_done_black"
android:text="@string/txt_how_to_pair_next_btn" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
3 changes: 1 addition & 2 deletions app/src/main/res/layout-land/view_pairing_searching.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@

<!--pairing animation-->
<pl.droidsonroids.gif.GifImageView
android:id="@+id/searching_microbit_found_giffview"
android:layout_width="@dimen/pairing_step_1_gif_image_width"
android:layout_height="@dimen/pairing_step_1_gif_image_height"
android:layout_below="@id/search_microbit_step_3_title"
android:src="@drawable/pairing_pin_screen_two" />
android:src="@drawable/emoji_searching_microbit" />
</RelativeLayout>

<RelativeLayout
Expand Down
9 changes: 1 addition & 8 deletions app/src/main/res/layout-land/view_pairing_searching_step.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
style="@style/pairing_step_tip_text_style"
android:layout_marginBottom="@dimen/pairing_step_tip_title_margin_bottom"
android:textSize="@dimen/pairing_step_title_text_size"
android:text="@string/searching_tip_step_text_one_line" />
android:text="@string/searching_microbit_one_line" />

<TextView
android:id="@+id/searching_microbit_step_instructions"
android:layout_width="wrap_content"
style="@style/pairing_step_tip_text_style"
android:textSize="@dimen/pairing_step_tip_instruction_text_size"
android:contentDescription="@string/desc_searching_tip_text"
android:text="@string/searching_tip_text_instructions" />
</LinearLayout>
Loading

0 comments on commit 30ac80f

Please sign in to comment.