Skip to content

Commit 1e93955

Browse files
committed
External activity failure - change popups to toasts
1 parent d7adce9 commit 1e93955

File tree

7 files changed

+83
-51
lines changed

7 files changed

+83
-51
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ public void bluetoothOff() {
6060
}
6161

6262
public void bluetoothEnableRestricted() {
63-
PopUp.show( mClient.fetchPopupsContext().getString(R.string.this_device_may_have_restrictions_in_place), //message
64-
mClient.fetchPopupsContext().getString(R.string.unable_to_start_activity_to_enable_bluetooth),
65-
R.drawable.error_face, R.drawable.red_btn,
66-
PopUp.GIFF_ANIMATION_ERROR,
67-
PopUp.TYPE_ALERT,
68-
popupClickActivityCancelled, popupClickActivityCancelled);
63+
UIUtils.safelyStartActivityToast( mClient.fetchPopupsContext(),
64+
mClient.fetchPopupsContext().getString(R.string.unable_to_start_activity_to_enable_bluetooth));
65+
mClient.fetchPopupsCancelled();
66+
// PopUp.show( mClient.fetchPopupsContext().getString(R.string.this_device_may_have_restrictions_in_place), //message
67+
// mClient.fetchPopupsContext().getString(R.string.unable_to_start_activity_to_enable_bluetooth),
68+
// R.drawable.error_face, R.drawable.red_btn,
69+
// PopUp.GIFF_ANIMATION_ERROR,
70+
// PopUp.TYPE_ALERT,
71+
// popupClickActivityCancelled, popupClickActivityCancelled);
6972
}
7073

7174
public void bluetoothConnectPermissionError() {

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

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.widget.Button;
2020
import android.widget.ImageButton;
2121
import android.widget.TextView;
22+
import android.widget.Toast;
2223

2324
import com.samsung.microbit.R;
2425

@@ -278,26 +279,42 @@ public void gifAnimate( @IdRes int id) {
278279
}
279280
}
280281

281-
public static void safelyStartActivityPopup( String message, String title) {
282-
PopUp.show( message, title,
283-
R.drawable.error_face,
284-
R.drawable.red_btn,
285-
PopUp.GIFF_ANIMATION_ERROR,
286-
PopUp.TYPE_ALERT,
287-
null,
288-
null);
282+
// public static void safelyStartActivityPopup( Context context, String message, String title) {
283+
// PopUp.show( message, title,
284+
// R.drawable.error_face,
285+
// R.drawable.red_btn,
286+
// PopUp.GIFF_ANIMATION_ERROR,
287+
// PopUp.TYPE_ALERT,
288+
// null,
289+
// null);
290+
// }
291+
//
292+
// public static void safelyStartActivityPopup( Context context, String title) {
293+
// safelyStartActivityPopup( context, context.getString(R.string.this_device_may_have_restrictions_in_place), title);
294+
// }
295+
//
296+
// public static void safelyStartActivityPopupGeneric( Context context) {
297+
// safelyStartActivityPopup( context, context.getString(R.string.unable_to_start_activity));
298+
// }
299+
//
300+
// public static void safelyStartActivityPopupOpenLink( Context context) {
301+
// safelyStartActivityPopup( context, context.getString(R.string.unable_to_open_link));
302+
// }
289303

304+
public static void safelyStartActivityToast( Context context, String message, String title) {
305+
Toast.makeText( context, title + ".\n" + message, Toast.LENGTH_LONG).show();
290306
}
291-
public static void safelyStartActivityPopup( Context context, String title) {
292-
safelyStartActivityPopup( context.getString(R.string.this_device_may_have_restrictions_in_place), title);
307+
308+
public static void safelyStartActivityToast( Context context, String title) {
309+
safelyStartActivityToast( context, context.getString(R.string.this_device_may_have_restrictions_in_place), title);
293310
}
294311

295-
public static void safelyStartActivityPopupGeneric( Context context) {
296-
safelyStartActivityPopup( context, context.getString(R.string.unable_to_start_activity));
312+
public static void safelyStartActivityToastGeneric( Context context) {
313+
safelyStartActivityToast( context, context.getString(R.string.unable_to_start_activity));
297314
}
298315

299-
public static void safelyStartActivityPopupOpenLink( Context context) {
300-
safelyStartActivityPopup( context, context.getString(R.string.unable_to_open_link));
316+
public static void safelyStartActivityToastOpenLink( Context context) {
317+
safelyStartActivityToast( context, context.getString(R.string.unable_to_open_link));
301318
}
302319

303320
// Wrap startActivity and startActivityForResult
@@ -307,6 +324,11 @@ public static void safelyStartActivityPopupOpenLink( Context context) {
307324
// needs to add code similar to the cancel case in onActivityResult
308325
public static int safelyStartActivity( Context context, boolean report, Intent intent,
309326
boolean forResult, int requestCode, Bundle options) {
327+
// if ( report) {
328+
// safelyStartActivityToastGeneric( context);
329+
// }
330+
// return 4;
331+
310332
int error = 0;
311333
ComponentName componentName = intent.resolveActivity( context.getPackageManager());
312334
if ( componentName == null) {
@@ -329,9 +351,8 @@ public static int safelyStartActivity( Context context, boolean report, Intent i
329351
error = 2;
330352
}
331353
}
332-
if ( report && error != 0)
333-
{
334-
safelyStartActivityPopupGeneric( context);
354+
if ( report && error != 0) {
355+
safelyStartActivityToastGeneric( context);
335356
}
336357
return error;
337358
}
@@ -357,7 +378,7 @@ public static int safelyStartActivityViewURI( Context context, boolean report, U
357378
intent.setData( uri);
358379
int error = UIUtils.safelyStartActivity( context, false, intent);
359380
if ( report && error != 0) {
360-
safelyStartActivityPopupOpenLink( context);
381+
safelyStartActivityToastOpenLink( context);
361382
}
362383
return error;
363384
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ public void onPageFinished(WebView view, String url) {
945945
mWebView.setWebChromeClient(new WebChromeClient() {
946946
@Override
947947
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
948-
return onShowFileChooser( webView, filePathCallback, fileChooserParams);
948+
return showFileChooser( webView, filePathCallback, fileChooserParams);
949949
}
950950
}); //setWebChromeClient
951951

@@ -979,7 +979,7 @@ public void onDownloadBase64( String base64, String mimetype) {
979979
}
980980
}
981981

982-
private boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
982+
private boolean showFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
983983
mWebFileChooserCallback = filePathCallback;
984984
try {
985985
Intent intent = fileChooserParams.createIntent();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void onPageFinished (WebView view, String url) {
136136
webView.setWebChromeClient(new WebChromeClient() {
137137
@Override
138138
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
139-
return onShowFileChooser( webView, filePathCallback, fileChooserParams);
139+
return showFileChooser( webView, filePathCallback, fileChooserParams);
140140

141141
}
142142
}); //setWebChromeClient
@@ -236,7 +236,7 @@ else if ( !hexName.isEmpty()) {
236236
openProjectActivity( hexToWrite);
237237
} else {
238238
Toast.makeText( MakeCodeWebView.this,
239-
"Saved to FLASH page", Toast.LENGTH_LONG).show();
239+
"Saved to My Programs page", Toast.LENGTH_LONG).show();
240240
}
241241
}
242242
} catch ( Exception e) {
@@ -261,7 +261,7 @@ else if ( !hexName.isEmpty()) {
261261
} // onCreate
262262

263263

264-
private boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
264+
private boolean showFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
265265
onShowFileChooser_filePathCallback = filePathCallback;
266266
try {
267267
Intent intent = fileChooserParams.createIntent();

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,12 +1205,14 @@ private void enableBluetooth() {
12051205
if ( error != 0) {
12061206
//Change state back to Idle
12071207
setActivityState(PairingActivityState.STATE_IDLE);
1208-
PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message
1209-
getString(R.string.unable_to_start_activity_to_enable_bluetooth),
1210-
R.drawable.error_face, R.drawable.red_btn,
1211-
PopUp.GIFF_ANIMATION_ERROR,
1212-
PopUp.TYPE_ALERT,
1213-
failedPermissionHandler, failedPermissionHandler);
1208+
UIUtils.safelyStartActivityToast( this, getString(R.string.unable_to_start_activity_to_enable_bluetooth));
1209+
onFinish( RESULT_CANCELED);
1210+
// PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message
1211+
// getString(R.string.unable_to_start_activity_to_enable_bluetooth),
1212+
// R.drawable.error_face, R.drawable.red_btn,
1213+
// PopUp.GIFF_ANIMATION_ERROR,
1214+
// PopUp.TYPE_ALERT,
1215+
// failedPermissionHandler, failedPermissionHandler);
12141216
}
12151217
}
12161218

@@ -1255,12 +1257,15 @@ public void popupLocationNeeded() {
12551257
}
12561258

12571259
public void popupLocationRestricted() {
1258-
PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message
1259-
getString(R.string.unable_to_start_activity_to_enable_location_services),
1260-
R.drawable.error_face, R.drawable.red_btn,
1261-
PopUp.GIFF_ANIMATION_ERROR,
1262-
PopUp.TYPE_ALERT,
1263-
failedPermissionHandler, failedPermissionHandler);
1260+
UIUtils.safelyStartActivityToast( this,
1261+
getString(R.string.unable_to_start_activity_to_enable_location_services));
1262+
onFinish( RESULT_CANCELED);
1263+
// PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message
1264+
// getString(R.string.unable_to_start_activity_to_enable_location_services),
1265+
// R.drawable.error_face, R.drawable.red_btn,
1266+
// PopUp.GIFF_ANIMATION_ERROR,
1267+
// PopUp.TYPE_ALERT,
1268+
// failedPermissionHandler, failedPermissionHandler);
12641269
}
12651270

12661271
@Override

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,12 +1087,15 @@ private void enableBluetooth() {
10871087
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
10881088
int error = UIUtils.safelyStartActivityForResult( this, false, enableBtIntent, RequestCodes.REQUEST_ENABLE_BT);
10891089
if ( error != 0) {
1090-
PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message
1091-
getString(R.string.unable_to_start_activity_to_enable_bluetooth),
1092-
R.drawable.error_face, R.drawable.red_btn,
1093-
PopUp.GIFF_ANIMATION_ERROR,
1094-
TYPE_ALERT,
1095-
popupClickFlashComplete, popupClickFlashComplete);
1090+
UIUtils.safelyStartActivityToast( this,
1091+
getString(R.string.unable_to_start_activity_to_enable_bluetooth));
1092+
onFlashComplete();
1093+
// PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message
1094+
// getString(R.string.unable_to_start_activity_to_enable_bluetooth),
1095+
// R.drawable.error_face, R.drawable.red_btn,
1096+
// PopUp.GIFF_ANIMATION_ERROR,
1097+
// TYPE_ALERT,
1098+
// popupClickFlashComplete, popupClickFlashComplete);
10961099
}
10971100
}
10981101

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@
426426
<string name="fetch_out_of_memory">Out of memory</string>
427427
<string name="fetch_failed_to_create_my_data_htm">Failed to create MY_DATA.HTM</string>
428428
<string name="fetch_works_with_micro_bit_v2_only">Works with micro:bit V2 only</string>
429-
<string name="this_device_may_have_restrictions_in_place">"This device may have restrictions in place."</string>
430-
<string name="unable_to_start_activity_to_enable_bluetooth">"Unable to enable Bluetooth"</string>
431-
<string name="unable_to_start_activity_to_enable_location_services">"Unable to enable Location"</string>
432-
<string name="unable_to_start_activity">"Unable to start activity"</string>
429+
<string name="this_device_may_have_restrictions_in_place">"This device may be restricted."</string>
430+
<string name="unable_to_start_activity_to_enable_bluetooth">"Unable to turn on Bluetooth"</string>
431+
<string name="unable_to_start_activity_to_enable_location_services">"Unable to turn on Location"</string>
432+
<string name="unable_to_start_activity">"Unable to start external activity"</string>
433433
<string name="unable_to_open_link">"Unable to open link"</string>
434434
</resources>

0 commit comments

Comments
 (0)