From 1e9395542451e476109574783d0b055608436704 Mon Sep 17 00:00:00 2001 From: Martin Williams Date: Mon, 9 Sep 2024 16:47:13 +0100 Subject: [PATCH] External activity failure - change popups to toasts --- .../com/samsung/microbit/ui/FetchPopups.java | 15 +++-- .../java/com/samsung/microbit/ui/UIUtils.java | 57 +++++++++++++------ .../microbit/ui/activity/FetchActivity.java | 4 +- .../microbit/ui/activity/MakeCodeWebView.java | 6 +- .../microbit/ui/activity/PairingActivity.java | 29 ++++++---- .../microbit/ui/activity/ProjectActivity.java | 15 +++-- app/src/main/res/values/strings.xml | 8 +-- 7 files changed, 83 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/com/samsung/microbit/ui/FetchPopups.java b/app/src/main/java/com/samsung/microbit/ui/FetchPopups.java index 6849634..fd91e02 100644 --- a/app/src/main/java/com/samsung/microbit/ui/FetchPopups.java +++ b/app/src/main/java/com/samsung/microbit/ui/FetchPopups.java @@ -60,12 +60,15 @@ public void bluetoothOff() { } public void bluetoothEnableRestricted() { - PopUp.show( mClient.fetchPopupsContext().getString(R.string.this_device_may_have_restrictions_in_place), //message - mClient.fetchPopupsContext().getString(R.string.unable_to_start_activity_to_enable_bluetooth), - R.drawable.error_face, R.drawable.red_btn, - PopUp.GIFF_ANIMATION_ERROR, - PopUp.TYPE_ALERT, - popupClickActivityCancelled, popupClickActivityCancelled); + UIUtils.safelyStartActivityToast( mClient.fetchPopupsContext(), + mClient.fetchPopupsContext().getString(R.string.unable_to_start_activity_to_enable_bluetooth)); + mClient.fetchPopupsCancelled(); +// PopUp.show( mClient.fetchPopupsContext().getString(R.string.this_device_may_have_restrictions_in_place), //message +// mClient.fetchPopupsContext().getString(R.string.unable_to_start_activity_to_enable_bluetooth), +// R.drawable.error_face, R.drawable.red_btn, +// PopUp.GIFF_ANIMATION_ERROR, +// PopUp.TYPE_ALERT, +// popupClickActivityCancelled, popupClickActivityCancelled); } public void bluetoothConnectPermissionError() { diff --git a/app/src/main/java/com/samsung/microbit/ui/UIUtils.java b/app/src/main/java/com/samsung/microbit/ui/UIUtils.java index cfa5144..8c6e1fe 100644 --- a/app/src/main/java/com/samsung/microbit/ui/UIUtils.java +++ b/app/src/main/java/com/samsung/microbit/ui/UIUtils.java @@ -19,6 +19,7 @@ import android.widget.Button; import android.widget.ImageButton; import android.widget.TextView; +import android.widget.Toast; import com.samsung.microbit.R; @@ -278,26 +279,42 @@ public void gifAnimate( @IdRes int id) { } } - public static void safelyStartActivityPopup( String message, String title) { - PopUp.show( message, title, - R.drawable.error_face, - R.drawable.red_btn, - PopUp.GIFF_ANIMATION_ERROR, - PopUp.TYPE_ALERT, - null, - null); +// public static void safelyStartActivityPopup( Context context, String message, String title) { +// PopUp.show( message, title, +// R.drawable.error_face, +// R.drawable.red_btn, +// PopUp.GIFF_ANIMATION_ERROR, +// PopUp.TYPE_ALERT, +// null, +// null); +// } +// +// public static void safelyStartActivityPopup( Context context, String title) { +// safelyStartActivityPopup( context, context.getString(R.string.this_device_may_have_restrictions_in_place), title); +// } +// +// public static void safelyStartActivityPopupGeneric( Context context) { +// safelyStartActivityPopup( context, context.getString(R.string.unable_to_start_activity)); +// } +// +// public static void safelyStartActivityPopupOpenLink( Context context) { +// safelyStartActivityPopup( context, context.getString(R.string.unable_to_open_link)); +// } + public static void safelyStartActivityToast( Context context, String message, String title) { + Toast.makeText( context, title + ".\n" + message, Toast.LENGTH_LONG).show(); } - public static void safelyStartActivityPopup( Context context, String title) { - safelyStartActivityPopup( context.getString(R.string.this_device_may_have_restrictions_in_place), title); + + public static void safelyStartActivityToast( Context context, String title) { + safelyStartActivityToast( context, context.getString(R.string.this_device_may_have_restrictions_in_place), title); } - public static void safelyStartActivityPopupGeneric( Context context) { - safelyStartActivityPopup( context, context.getString(R.string.unable_to_start_activity)); + public static void safelyStartActivityToastGeneric( Context context) { + safelyStartActivityToast( context, context.getString(R.string.unable_to_start_activity)); } - public static void safelyStartActivityPopupOpenLink( Context context) { - safelyStartActivityPopup( context, context.getString(R.string.unable_to_open_link)); + public static void safelyStartActivityToastOpenLink( Context context) { + safelyStartActivityToast( context, context.getString(R.string.unable_to_open_link)); } // Wrap startActivity and startActivityForResult @@ -307,6 +324,11 @@ public static void safelyStartActivityPopupOpenLink( Context context) { // needs to add code similar to the cancel case in onActivityResult public static int safelyStartActivity( Context context, boolean report, Intent intent, boolean forResult, int requestCode, Bundle options) { +// if ( report) { +// safelyStartActivityToastGeneric( context); +// } +// return 4; + int error = 0; ComponentName componentName = intent.resolveActivity( context.getPackageManager()); if ( componentName == null) { @@ -329,9 +351,8 @@ public static int safelyStartActivity( Context context, boolean report, Intent i error = 2; } } - if ( report && error != 0) - { - safelyStartActivityPopupGeneric( context); + if ( report && error != 0) { + safelyStartActivityToastGeneric( context); } return error; } @@ -357,7 +378,7 @@ public static int safelyStartActivityViewURI( Context context, boolean report, U intent.setData( uri); int error = UIUtils.safelyStartActivity( context, false, intent); if ( report && error != 0) { - safelyStartActivityPopupOpenLink( context); + safelyStartActivityToastOpenLink( context); } return error; } diff --git a/app/src/main/java/com/samsung/microbit/ui/activity/FetchActivity.java b/app/src/main/java/com/samsung/microbit/ui/activity/FetchActivity.java index d8454b8..9a01d7c 100644 --- a/app/src/main/java/com/samsung/microbit/ui/activity/FetchActivity.java +++ b/app/src/main/java/com/samsung/microbit/ui/activity/FetchActivity.java @@ -945,7 +945,7 @@ public void onPageFinished(WebView view, String url) { mWebView.setWebChromeClient(new WebChromeClient() { @Override public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { - return onShowFileChooser( webView, filePathCallback, fileChooserParams); + return showFileChooser( webView, filePathCallback, fileChooserParams); } }); //setWebChromeClient @@ -979,7 +979,7 @@ public void onDownloadBase64( String base64, String mimetype) { } } - private boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { + private boolean showFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { mWebFileChooserCallback = filePathCallback; try { Intent intent = fileChooserParams.createIntent(); diff --git a/app/src/main/java/com/samsung/microbit/ui/activity/MakeCodeWebView.java b/app/src/main/java/com/samsung/microbit/ui/activity/MakeCodeWebView.java index 071f002..a995861 100644 --- a/app/src/main/java/com/samsung/microbit/ui/activity/MakeCodeWebView.java +++ b/app/src/main/java/com/samsung/microbit/ui/activity/MakeCodeWebView.java @@ -136,7 +136,7 @@ public void onPageFinished (WebView view, String url) { webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { - return onShowFileChooser( webView, filePathCallback, fileChooserParams); + return showFileChooser( webView, filePathCallback, fileChooserParams); } }); //setWebChromeClient @@ -236,7 +236,7 @@ else if ( !hexName.isEmpty()) { openProjectActivity( hexToWrite); } else { Toast.makeText( MakeCodeWebView.this, - "Saved to FLASH page", Toast.LENGTH_LONG).show(); + "Saved to My Programs page", Toast.LENGTH_LONG).show(); } } } catch ( Exception e) { @@ -261,7 +261,7 @@ else if ( !hexName.isEmpty()) { } // onCreate - private boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { + private boolean showFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { onShowFileChooser_filePathCallback = filePathCallback; try { Intent intent = fileChooserParams.createIntent(); diff --git a/app/src/main/java/com/samsung/microbit/ui/activity/PairingActivity.java b/app/src/main/java/com/samsung/microbit/ui/activity/PairingActivity.java index 20ea2fe..3412a68 100644 --- a/app/src/main/java/com/samsung/microbit/ui/activity/PairingActivity.java +++ b/app/src/main/java/com/samsung/microbit/ui/activity/PairingActivity.java @@ -1205,12 +1205,14 @@ private void enableBluetooth() { if ( error != 0) { //Change state back to Idle setActivityState(PairingActivityState.STATE_IDLE); - PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message - getString(R.string.unable_to_start_activity_to_enable_bluetooth), - R.drawable.error_face, R.drawable.red_btn, - PopUp.GIFF_ANIMATION_ERROR, - PopUp.TYPE_ALERT, - failedPermissionHandler, failedPermissionHandler); + UIUtils.safelyStartActivityToast( this, getString(R.string.unable_to_start_activity_to_enable_bluetooth)); + onFinish( RESULT_CANCELED); +// PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message +// getString(R.string.unable_to_start_activity_to_enable_bluetooth), +// R.drawable.error_face, R.drawable.red_btn, +// PopUp.GIFF_ANIMATION_ERROR, +// PopUp.TYPE_ALERT, +// failedPermissionHandler, failedPermissionHandler); } } @@ -1255,12 +1257,15 @@ public void popupLocationNeeded() { } public void popupLocationRestricted() { - PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message - getString(R.string.unable_to_start_activity_to_enable_location_services), - R.drawable.error_face, R.drawable.red_btn, - PopUp.GIFF_ANIMATION_ERROR, - PopUp.TYPE_ALERT, - failedPermissionHandler, failedPermissionHandler); + UIUtils.safelyStartActivityToast( this, + getString(R.string.unable_to_start_activity_to_enable_location_services)); + onFinish( RESULT_CANCELED); +// PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message +// getString(R.string.unable_to_start_activity_to_enable_location_services), +// R.drawable.error_face, R.drawable.red_btn, +// PopUp.GIFF_ANIMATION_ERROR, +// PopUp.TYPE_ALERT, +// failedPermissionHandler, failedPermissionHandler); } @Override diff --git a/app/src/main/java/com/samsung/microbit/ui/activity/ProjectActivity.java b/app/src/main/java/com/samsung/microbit/ui/activity/ProjectActivity.java index d154817..a752f57 100644 --- a/app/src/main/java/com/samsung/microbit/ui/activity/ProjectActivity.java +++ b/app/src/main/java/com/samsung/microbit/ui/activity/ProjectActivity.java @@ -1087,12 +1087,15 @@ private void enableBluetooth() { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); int error = UIUtils.safelyStartActivityForResult( this, false, enableBtIntent, RequestCodes.REQUEST_ENABLE_BT); if ( error != 0) { - PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message - getString(R.string.unable_to_start_activity_to_enable_bluetooth), - R.drawable.error_face, R.drawable.red_btn, - PopUp.GIFF_ANIMATION_ERROR, - TYPE_ALERT, - popupClickFlashComplete, popupClickFlashComplete); + UIUtils.safelyStartActivityToast( this, + getString(R.string.unable_to_start_activity_to_enable_bluetooth)); + onFlashComplete(); +// PopUp.show( getString(R.string.this_device_may_have_restrictions_in_place), //message +// getString(R.string.unable_to_start_activity_to_enable_bluetooth), +// R.drawable.error_face, R.drawable.red_btn, +// PopUp.GIFF_ANIMATION_ERROR, +// TYPE_ALERT, +// popupClickFlashComplete, popupClickFlashComplete); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8e00f68..c40d535 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -426,9 +426,9 @@ Out of memory Failed to create MY_DATA.HTM Works with micro:bit V2 only - "This device may have restrictions in place." - "Unable to enable Bluetooth" - "Unable to enable Location" - "Unable to start activity" + "This device may be restricted." + "Unable to turn on Bluetooth" + "Unable to turn on Location" + "Unable to start external activity" "Unable to open link"