Skip to content

Commit e32052a

Browse files
dnlbainesmicrobit-sam
authored andcommitted
Tell the user that they must always enter 'bluetooth mode' to flash a micro:bit (#2)
* Added a reminder to enter bluetooth mode when flashing * Switched zip extraction to BufferedOutputStream for performance increase * Trigger bluetooth reminder on GATT ERROR instead of every time
1 parent 8c22652 commit e32052a

File tree

12 files changed

+205
-72
lines changed

12 files changed

+205
-72
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@
138138
android:configChanges="orientation|screenSize"
139139
android:label="Help Webview"
140140
android:launchMode="singleTask"
141-
android:screenOrientation="portrait">
142-
>
143-
</activity>
141+
android:screenOrientation="portrait"/>
144142
<activity
145143
android:name=".ui.activity.CameraActivityPermissionChecker"
146144
android:label="@string/title_activity_camera_activity_permission_checker"

app/src/main/java/com/samsung/microbit/ui/PopUp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class PopUp {
4242
public static final int GIFF_ANIMATION_NONE = 0;
4343
public static final int GIFF_ANIMATION_FLASH = 1;
4444
public static final int GIFF_ANIMATION_ERROR = 2;
45-
45+
public static final int GIFF_ANIMATION_PAIRING = 3;
4646

4747
public static final String INTENT_EXTRA_OK_ACTION = "Popup.extra.ok.type";
4848
public static final int OK_ACTION_NONE = 0;

app/src/main/java/com/samsung/microbit/ui/activity/PopUpActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,14 @@ private void setLayout(Intent intent) {
296296
// Regular image disabled
297297
imageIcon.setVisibility(View.GONE);
298298
break;
299+
// Pairing screen
300+
case 3:
301+
// Asset file
302+
gifImageView.setBackgroundResource(R.drawable.how_to_pair_microbit);
303+
gifImageView.setVisibility(View.VISIBLE);
304+
// Regular image disabled
305+
imageIcon.setVisibility(View.GONE);
306+
break;
299307
}
300308
// Set default plain icon
301309
} else {

app/src/main/java/com/samsung/microbit/ui/activity/ProjectActivity.java

Lines changed: 80 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -972,57 +972,62 @@ public void onClick(View v) {
972972
},//override click listener for ok button
973973
null);//pass null to use default listeneronClick
974974
} else {
975-
//TODO Check if the micro:bit is reachable first
976-
if(mProgramToSend == null || mProgramToSend.filePath == null) {
977-
PopUp.show(getString(R.string.internal_error_msg),
978-
"",
979-
R.drawable.error_face, R.drawable.red_btn,
980-
PopUp.GIFF_ANIMATION_ERROR,
981-
PopUp.TYPE_ALERT,
982-
null, null);
983-
return;
984-
}
985-
if(mActivityState == FlashActivityState.FLASH_STATE_FIND_DEVICE
986-
|| mActivityState == FlashActivityState.FLASH_STATE_VERIFY_DEVICE
987-
|| mActivityState == FlashActivityState.FLASH_STATE_WAIT_DEVICE_REBOOT
988-
|| mActivityState == FlashActivityState.FLASH_STATE_INIT_DEVICE
989-
|| mActivityState == FlashActivityState.FLASH_STATE_PROGRESS
990-
991-
) {
992-
// Another download session is in progress.xml
993-
PopUp.show(getString(R.string.multple_flashing_session_msg),
994-
"",
995-
R.drawable.flash_face, R.drawable.blue_btn,
996-
PopUp.GIFF_ANIMATION_FLASH,
997-
PopUp.TYPE_ALERT,
998-
null, null);
999-
return;
1000-
}
1001-
if(mActivityState == FlashActivityState.STATE_ENABLE_BT_INTERNAL_FLASH_REQUEST ||
1002-
mActivityState == FlashActivityState.STATE_ENABLE_BT_EXTERNAL_FLASH_REQUEST) {
1003-
//Check final device from user and start flashing
1004-
PopUp.show(getString(R.string.flash_start_message, currentMicrobit.mName), //message
1005-
getString(R.string.flashing_title), //title
1006-
R.drawable.flash_face, R.drawable.blue_btn, //image icon res id
1007-
PopUp.GIFF_ANIMATION_NONE,
1008-
PopUp.TYPE_CHOICE, //type of popup.
1009-
new View.OnClickListener() {
1010-
@Override
1011-
public void onClick(View v) {
1012-
ConnectedDevice currentMicrobit = BluetoothUtils.getPairedMicrobit(MBApp.getApp());
1013-
PopUp.hide();
1014-
initiateFlashing();
1015-
}
1016-
},//override click listener for ok button
1017-
new View.OnClickListener() {
1018-
@Override
1019-
public void onClick(View v) {
1020-
PopUp.hide();
1021-
}
1022-
});//pass null to use default listeneronClick
1023-
} else {
1024-
initiateFlashing();
1025-
}
975+
flashingChecks();
976+
}
977+
}
978+
979+
private void flashingChecks() {
980+
ConnectedDevice currentMicrobit = BluetoothUtils.getPairedMicrobit(this);
981+
982+
if(mProgramToSend == null || mProgramToSend.filePath == null) {
983+
PopUp.show(getString(R.string.internal_error_msg),
984+
"",
985+
R.drawable.error_face, R.drawable.red_btn,
986+
PopUp.GIFF_ANIMATION_ERROR,
987+
PopUp.TYPE_ALERT,
988+
null, null);
989+
return;
990+
}
991+
if(mActivityState == FlashActivityState.FLASH_STATE_FIND_DEVICE
992+
|| mActivityState == FlashActivityState.FLASH_STATE_VERIFY_DEVICE
993+
|| mActivityState == FlashActivityState.FLASH_STATE_WAIT_DEVICE_REBOOT
994+
|| mActivityState == FlashActivityState.FLASH_STATE_INIT_DEVICE
995+
|| mActivityState == FlashActivityState.FLASH_STATE_PROGRESS
996+
997+
) {
998+
// Another download session is in progress.xml
999+
PopUp.show(getString(R.string.multple_flashing_session_msg),
1000+
"",
1001+
R.drawable.flash_face, R.drawable.blue_btn,
1002+
PopUp.GIFF_ANIMATION_FLASH,
1003+
PopUp.TYPE_ALERT,
1004+
null, null);
1005+
return;
1006+
}
1007+
if(mActivityState == FlashActivityState.STATE_ENABLE_BT_INTERNAL_FLASH_REQUEST ||
1008+
mActivityState == FlashActivityState.STATE_ENABLE_BT_EXTERNAL_FLASH_REQUEST) {
1009+
//Check final device from user and start flashing
1010+
PopUp.show(getString(R.string.flash_start_message, currentMicrobit.mName), //message
1011+
getString(R.string.flashing_title), //title
1012+
R.drawable.flash_face, R.drawable.blue_btn, //image icon res id
1013+
PopUp.GIFF_ANIMATION_NONE,
1014+
PopUp.TYPE_CHOICE, //type of popup.
1015+
new View.OnClickListener() {
1016+
@Override
1017+
public void onClick(View v) {
1018+
ConnectedDevice currentMicrobit = BluetoothUtils.getPairedMicrobit(MBApp.getApp());
1019+
PopUp.hide();
1020+
initiateFlashing();
1021+
}
1022+
},//override click listener for ok button
1023+
new View.OnClickListener() {
1024+
@Override
1025+
public void onClick(View v) {
1026+
PopUp.hide();
1027+
}
1028+
});//pass null to use default listeneronClick
1029+
} else {
1030+
initiateFlashing();
10261031
}
10271032
}
10281033

@@ -1376,14 +1381,31 @@ public void onClick(View v) {
13761381
ProjectActivity.class.getSimpleName(),
13771382
false, mProgramToSend.name, m_HexFileSizeStats,
13781383
m_BinSizeStats, m_MicroBitFirmware);
1379-
PopUp.show(error_message, //message
1380-
getString(R.string.flashing_failed_title), //title
1381-
R.drawable.error_face, R.drawable.red_btn,
1382-
PopUp.GIFF_ANIMATION_ERROR,
1383-
PopUp.TYPE_ALERT, //type of popup.
1384-
popupOkHandler,//override click listener for ok button
1385-
popupOkHandler);//pass null to use default listener
13861384

1385+
//Check for GATT ERROR - prompt user to enter bluetooth mode
1386+
if(errorCode == 0x0085) {
1387+
PopUp.show(getString(R.string.connect_tip_text),
1388+
"Remember to enter bluetooth mode",
1389+
R.drawable.message_face, R.drawable.red_btn,
1390+
PopUp.GIFF_ANIMATION_PAIRING,
1391+
PopUp.TYPE_CHOICE,
1392+
new View.OnClickListener() {
1393+
@Override
1394+
public void onClick(View v) {
1395+
PopUp.hide();
1396+
flashingChecks();
1397+
}
1398+
},
1399+
popupOkHandler);
1400+
} else {
1401+
PopUp.show(error_message, //message
1402+
getString(R.string.flashing_failed_title), //title
1403+
R.drawable.error_face, R.drawable.red_btn,
1404+
PopUp.GIFF_ANIMATION_ERROR,
1405+
PopUp.TYPE_ALERT, //type of popup.
1406+
popupOkHandler,//override click listener for ok button
1407+
popupOkHandler);//pass null to use default listener
1408+
}
13871409
removeReconnectionRunnable();
13881410
} else if(intent.getAction().equals(DfuService.BROADCAST_LOG)) {
13891411
//Only used for Stats at the moment

app/src/main/java/com/samsung/microbit/utils/FileUtils.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.samsung.microbit.MBApp;
88
import com.samsung.microbit.data.constants.FileConstants;
99

10+
import java.io.BufferedOutputStream;
1011
import java.io.File;
1112
import java.io.FileOutputStream;
1213
import java.io.IOException;
@@ -57,10 +58,14 @@ public static boolean installSamples() {
5758
dirChecker(ze.getName());
5859
} else {
5960
FileOutputStream fout = new FileOutputStream(outputDir + File.separator + ze.getName());
60-
for(int c = zin.read(); c != -1; c = zin.read()) {
61-
fout.write(c);
61+
BufferedOutputStream bufout = new BufferedOutputStream(fout);
62+
byte[] buffer = new byte[1024];
63+
int read = 0;
64+
while ((read = zin.read(buffer)) != -1) {
65+
bufout.write(buffer, 0, read);
6266
}
6367
zin.closeEntry();
68+
bufout.close();
6469
fout.close();
6570
}
6671
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
input.onButtonPressed(Button.A, function () {
2+
devices.raiseAlertTo(MesAlertEvent.FindMyPhone)
3+
})
4+
basic.showLeds(`
5+
. . # . .
6+
. # . . .
7+
# # # # #
8+
. # . . .
9+
. . # . .
10+
`)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
let music_player_launched = false
2+
input.onButtonPressed(Button.A, function () {
3+
if (!(music_player_launched)) {
4+
music_player_launched = true
5+
devices.tellRemoteControlTo(MesRemoteControlEvent.play)
6+
basic.showLeds(`
7+
. . # . .
8+
. . . # .
9+
# # # # #
10+
. . . # .
11+
. . # . .
12+
`)
13+
}
14+
})
15+
input.onButtonPressed(Button.B, function () {
16+
if (music_player_launched) {
17+
devices.tellRemoteControlTo(MesRemoteControlEvent.nextTrack)
18+
basic.showLeds(`
19+
. . . . .
20+
. # . # .
21+
# # # # #
22+
. # . # .
23+
. . . . .
24+
`)
25+
}
26+
})
27+
input.onButtonPressed(Button.AB, function () {
28+
basic.showLeds(`
29+
. . # . .
30+
. # . . .
31+
# # # # #
32+
. # . . .
33+
. . # . .
34+
`)
35+
music_player_launched = false
36+
devices.tellRemoteControlTo(MesRemoteControlEvent.stop)
37+
})
38+
music_player_launched = false
39+
basic.showLeds(`
40+
. . # . .
41+
. # . . .
42+
# # # # #
43+
. # . . .
44+
. . # . .
45+
`)

app/src/main/res/raw/samples.zip

-1.42 KB
Binary file not shown.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
let camera_launched = false
2+
input.onButtonPressed(Button.A, function () {
3+
if (!(camera_launched)) {
4+
camera_launched = true
5+
basic.showLeds(`
6+
. . # . .
7+
. . . # .
8+
# # # # #
9+
. . . # .
10+
. . # . .
11+
`)
12+
devices.tellCameraTo(MesCameraEvent.LaunchPhotoMode)
13+
}
14+
})
15+
input.onButtonPressed(Button.B, function () {
16+
if (camera_launched) {
17+
devices.tellCameraTo(MesCameraEvent.TakePhoto)
18+
basic.showLeds(`
19+
. . . . .
20+
. # . # .
21+
# # # # #
22+
. # . # .
23+
. . . . .
24+
`)
25+
}
26+
})
27+
input.onButtonPressed(Button.AB, function () {
28+
camera_launched = false
29+
devices.tellCameraTo(MesCameraEvent.StopPhotoMode)
30+
basic.showLeds(`
31+
. . # . .
32+
. # . . .
33+
# # # # #
34+
. # . . .
35+
. . # . .
36+
`)
37+
})
38+
camera_launched = false
39+
basic.showLeds(`
40+
. . # . .
41+
. # . . .
42+
# # # # #
43+
. # . . .
44+
. . # . .
45+
`)

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
<string name="developed_by">Developed by</string>
2525

2626
<!-- External links -->
27-
<string name="create_code_url" translatable="false">http://microbit.org/code</string>
27+
<string name="create_code_url" translatable="false">https://makecode.microbit.org/</string>
2828
<string name="discover_url" translatable="false">http://microbit.org/</string>
29-
<string name="my_scripts_url" translatable="false">https://www.microbit.co.uk/app/</string>
29+
<string name="my_scripts_url" translatable="false">https://makecode.microbit.org/</string>
3030
<string name="privacy_policy_url" translatable="false">http://microbit.org/privacy</string>
3131
<string name="terms_of_use_url" translatable="false">http://microbit.org/terms-of-use</string>
3232
<string name="about_url" translatable="false">http://microbit.org/about</string>
@@ -165,10 +165,10 @@
165165
<string name="searching_microbit_found_message_one_line">Open your notification drawer and enter your Pin</string>
166166
<string name="desc_searching_microbit_found_message">Open your notification drawer and enter your Pin</string>
167167
<string name="step_connect_tip_text_step_two">Step 2</string>
168-
<string name="connect_tip_text">Hold the A and B buttons, then PRESS RESET</string>
169-
<string name="desc_connect_tip_text">Hold the A and B buttons, then PRESS RESET</string>
168+
<string name="connect_tip_text">Hold the A and B buttons then press and release RESET. Keep holding A and B until the screen fills up</string>
169+
<string name="desc_connect_tip_text">Hold the A and B buttons then press and release RESET. Keep holding A and B until the screen fills up</string>
170170
<string name="desc_connect_tip_text_step">Step one</string>
171-
<string name="connect_tip_text_step_text">Hold the A and B buttons,\nthen PRESS RESET</string>
171+
<string name="connect_tip_text_step_text">Hold the A and B buttons \nthen press and release RESET. \nKeep holding A and B \nuntil the screen fills up</string>
172172
<string name="desc_connect_tip_text_step_two">Step two</string>
173173
<string name="connect_tip_text_step_two_text">When asked, enter your PIP \n(personal identification pattern) </string>
174174
<string name="desc_connect_tip_text_step_two_text">When asked, enter your personal identification pattern </string>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.2.1'
8+
classpath 'com.android.tools.build:gradle:3.4.1'
99
classpath 'com.google.gms:google-services:3.0.0'
1010
}
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Oct 20 14:15:34 BST 2016
1+
#Wed May 22 10:48:32 BST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 commit comments

Comments
 (0)