Skip to content

Tell the user that they must always enter 'bluetooth mode' to flash a micro:bit #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@
android:configChanges="orientation|screenSize"
android:label="Help Webview"
android:launchMode="singleTask"
android:screenOrientation="portrait">
>
</activity>
android:screenOrientation="portrait"/>
<activity
android:name=".ui.activity.CameraActivityPermissionChecker"
android:label="@string/title_activity_camera_activity_permission_checker"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/samsung/microbit/ui/PopUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class PopUp {
public static final int GIFF_ANIMATION_NONE = 0;
public static final int GIFF_ANIMATION_FLASH = 1;
public static final int GIFF_ANIMATION_ERROR = 2;

public static final int GIFF_ANIMATION_PAIRING = 3;

public static final String INTENT_EXTRA_OK_ACTION = "Popup.extra.ok.type";
public static final int OK_ACTION_NONE = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ private void setLayout(Intent intent) {
// Regular image disabled
imageIcon.setVisibility(View.GONE);
break;
// Pairing screen
case 3:
// Asset file
gifImageView.setBackgroundResource(R.drawable.how_to_pair_microbit);
gifImageView.setVisibility(View.VISIBLE);
// Regular image disabled
imageIcon.setVisibility(View.GONE);
break;
}
// Set default plain icon
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,57 +972,62 @@ public void onClick(View v) {
},//override click listener for ok button
null);//pass null to use default listeneronClick
} else {
//TODO Check if the micro:bit is reachable first
if(mProgramToSend == null || mProgramToSend.filePath == null) {
PopUp.show(getString(R.string.internal_error_msg),
"",
R.drawable.error_face, R.drawable.red_btn,
PopUp.GIFF_ANIMATION_ERROR,
PopUp.TYPE_ALERT,
null, null);
return;
}
if(mActivityState == FlashActivityState.FLASH_STATE_FIND_DEVICE
|| mActivityState == FlashActivityState.FLASH_STATE_VERIFY_DEVICE
|| mActivityState == FlashActivityState.FLASH_STATE_WAIT_DEVICE_REBOOT
|| mActivityState == FlashActivityState.FLASH_STATE_INIT_DEVICE
|| mActivityState == FlashActivityState.FLASH_STATE_PROGRESS

) {
// Another download session is in progress.xml
PopUp.show(getString(R.string.multple_flashing_session_msg),
"",
R.drawable.flash_face, R.drawable.blue_btn,
PopUp.GIFF_ANIMATION_FLASH,
PopUp.TYPE_ALERT,
null, null);
return;
}
if(mActivityState == FlashActivityState.STATE_ENABLE_BT_INTERNAL_FLASH_REQUEST ||
mActivityState == FlashActivityState.STATE_ENABLE_BT_EXTERNAL_FLASH_REQUEST) {
//Check final device from user and start flashing
PopUp.show(getString(R.string.flash_start_message, currentMicrobit.mName), //message
getString(R.string.flashing_title), //title
R.drawable.flash_face, R.drawable.blue_btn, //image icon res id
PopUp.GIFF_ANIMATION_NONE,
PopUp.TYPE_CHOICE, //type of popup.
new View.OnClickListener() {
@Override
public void onClick(View v) {
ConnectedDevice currentMicrobit = BluetoothUtils.getPairedMicrobit(MBApp.getApp());
PopUp.hide();
initiateFlashing();
}
},//override click listener for ok button
new View.OnClickListener() {
@Override
public void onClick(View v) {
PopUp.hide();
}
});//pass null to use default listeneronClick
} else {
initiateFlashing();
}
flashingChecks();
}
}

private void flashingChecks() {
ConnectedDevice currentMicrobit = BluetoothUtils.getPairedMicrobit(this);

if(mProgramToSend == null || mProgramToSend.filePath == null) {
PopUp.show(getString(R.string.internal_error_msg),
"",
R.drawable.error_face, R.drawable.red_btn,
PopUp.GIFF_ANIMATION_ERROR,
PopUp.TYPE_ALERT,
null, null);
return;
}
if(mActivityState == FlashActivityState.FLASH_STATE_FIND_DEVICE
|| mActivityState == FlashActivityState.FLASH_STATE_VERIFY_DEVICE
|| mActivityState == FlashActivityState.FLASH_STATE_WAIT_DEVICE_REBOOT
|| mActivityState == FlashActivityState.FLASH_STATE_INIT_DEVICE
|| mActivityState == FlashActivityState.FLASH_STATE_PROGRESS

) {
// Another download session is in progress.xml
PopUp.show(getString(R.string.multple_flashing_session_msg),
"",
R.drawable.flash_face, R.drawable.blue_btn,
PopUp.GIFF_ANIMATION_FLASH,
PopUp.TYPE_ALERT,
null, null);
return;
}
if(mActivityState == FlashActivityState.STATE_ENABLE_BT_INTERNAL_FLASH_REQUEST ||
mActivityState == FlashActivityState.STATE_ENABLE_BT_EXTERNAL_FLASH_REQUEST) {
//Check final device from user and start flashing
PopUp.show(getString(R.string.flash_start_message, currentMicrobit.mName), //message
getString(R.string.flashing_title), //title
R.drawable.flash_face, R.drawable.blue_btn, //image icon res id
PopUp.GIFF_ANIMATION_NONE,
PopUp.TYPE_CHOICE, //type of popup.
new View.OnClickListener() {
@Override
public void onClick(View v) {
ConnectedDevice currentMicrobit = BluetoothUtils.getPairedMicrobit(MBApp.getApp());
PopUp.hide();
initiateFlashing();
}
},//override click listener for ok button
new View.OnClickListener() {
@Override
public void onClick(View v) {
PopUp.hide();
}
});//pass null to use default listeneronClick
} else {
initiateFlashing();
}
}

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

//Check for GATT ERROR - prompt user to enter bluetooth mode
if(errorCode == 0x0085) {
PopUp.show(getString(R.string.connect_tip_text),
"Remember to enter bluetooth mode",
R.drawable.message_face, R.drawable.red_btn,
PopUp.GIFF_ANIMATION_PAIRING,
PopUp.TYPE_CHOICE,
new View.OnClickListener() {
@Override
public void onClick(View v) {
PopUp.hide();
flashingChecks();
}
},
popupOkHandler);
} else {
PopUp.show(error_message, //message
getString(R.string.flashing_failed_title), //title
R.drawable.error_face, R.drawable.red_btn,
PopUp.GIFF_ANIMATION_ERROR,
PopUp.TYPE_ALERT, //type of popup.
popupOkHandler,//override click listener for ok button
popupOkHandler);//pass null to use default listener
}
removeReconnectionRunnable();
} else if(intent.getAction().equals(DfuService.BROADCAST_LOG)) {
//Only used for Stats at the moment
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/samsung/microbit/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.samsung.microbit.MBApp;
import com.samsung.microbit.data.constants.FileConstants;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -57,10 +58,14 @@ public static boolean installSamples() {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(outputDir + File.separator + ze.getName());
for(int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
BufferedOutputStream bufout = new BufferedOutputStream(fout);
byte[] buffer = new byte[1024];
int read = 0;
while ((read = zin.read(buffer)) != -1) {
bufout.write(buffer, 0, read);
}
zin.closeEntry();
bufout.close();
fout.close();
}
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/raw/find_my_phone_sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
input.onButtonPressed(Button.A, function () {
devices.raiseAlertTo(MesAlertEvent.FindMyPhone)
})
basic.showLeds(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .
`)
45 changes: 45 additions & 0 deletions app/src/main/res/raw/music_remote_sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let music_player_launched = false
input.onButtonPressed(Button.A, function () {
if (!(music_player_launched)) {
music_player_launched = true
devices.tellRemoteControlTo(MesRemoteControlEvent.play)
basic.showLeds(`
. . # . .
. . . # .
# # # # #
. . . # .
. . # . .
`)
}
})
input.onButtonPressed(Button.B, function () {
if (music_player_launched) {
devices.tellRemoteControlTo(MesRemoteControlEvent.nextTrack)
basic.showLeds(`
. . . . .
. # . # .
# # # # #
. # . # .
. . . . .
`)
}
})
input.onButtonPressed(Button.AB, function () {
basic.showLeds(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .
`)
music_player_launched = false
devices.tellRemoteControlTo(MesRemoteControlEvent.stop)
})
music_player_launched = false
basic.showLeds(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .
`)
Binary file modified app/src/main/res/raw/samples.zip
Binary file not shown.
45 changes: 45 additions & 0 deletions app/src/main/res/raw/selfie_remote_sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let camera_launched = false
input.onButtonPressed(Button.A, function () {
if (!(camera_launched)) {
camera_launched = true
basic.showLeds(`
. . # . .
. . . # .
# # # # #
. . . # .
. . # . .
`)
devices.tellCameraTo(MesCameraEvent.LaunchPhotoMode)
}
})
input.onButtonPressed(Button.B, function () {
if (camera_launched) {
devices.tellCameraTo(MesCameraEvent.TakePhoto)
basic.showLeds(`
. . . . .
. # . # .
# # # # #
. # . # .
. . . . .
`)
}
})
input.onButtonPressed(Button.AB, function () {
camera_launched = false
devices.tellCameraTo(MesCameraEvent.StopPhotoMode)
basic.showLeds(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .
`)
})
camera_launched = false
basic.showLeds(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .
`)
10 changes: 5 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
<string name="developed_by">Developed by</string>

<!-- External links -->
<string name="create_code_url" translatable="false">http://microbit.org/code</string>
<string name="create_code_url" translatable="false">https://makecode.microbit.org/</string>
<string name="discover_url" translatable="false">http://microbit.org/</string>
<string name="my_scripts_url" translatable="false">https://www.microbit.co.uk/app/</string>
<string name="my_scripts_url" translatable="false">https://makecode.microbit.org/</string>
<string name="privacy_policy_url" translatable="false">http://microbit.org/privacy</string>
<string name="terms_of_use_url" translatable="false">http://microbit.org/terms-of-use</string>
<string name="about_url" translatable="false">http://microbit.org/about</string>
Expand Down Expand Up @@ -165,10 +165,10 @@
<string name="searching_microbit_found_message_one_line">Open your notification drawer and enter your Pin</string>
<string name="desc_searching_microbit_found_message">Open your notification drawer and enter your Pin</string>
<string name="step_connect_tip_text_step_two">Step 2</string>
<string name="connect_tip_text">Hold the A and B buttons, then PRESS RESET</string>
<string name="desc_connect_tip_text">Hold the A and B buttons, then PRESS RESET</string>
<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>
<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>
<string name="desc_connect_tip_text_step">Step one</string>
<string name="connect_tip_text_step_text">Hold the A and B buttons,\nthen PRESS RESET</string>
<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>
<string name="desc_connect_tip_text_step_two">Step two</string>
<string name="connect_tip_text_step_two_text">When asked, enter your PIP \n(personal identification pattern) </string>
<string name="desc_connect_tip_text_step_two_text">When asked, enter your personal identification pattern </string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:3.0.0'
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Oct 20 14:15:34 BST 2016
#Wed May 22 10:48:32 BST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip