Skip to content

Commit

Permalink
External activity failure - change popups to toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
martinwork committed Sep 9, 2024
1 parent d7adce9 commit 1e93955
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 51 deletions.
15 changes: 9 additions & 6 deletions app/src/main/java/com/samsung/microbit/ui/FetchPopups.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
57 changes: 39 additions & 18 deletions app/src/main/java/com/samsung/microbit/ui/UIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ public void onPageFinished(WebView view, String url) {
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
return onShowFileChooser( webView, filePathCallback, fileChooserParams);
return showFileChooser( webView, filePathCallback, fileChooserParams);
}
}); //setWebChromeClient

Expand Down Expand Up @@ -979,7 +979,7 @@ public void onDownloadBase64( String base64, String mimetype) {
}
}

private boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
private boolean showFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
mWebFileChooserCallback = filePathCallback;
try {
Intent intent = fileChooserParams.createIntent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void onPageFinished (WebView view, String url) {
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
return onShowFileChooser( webView, filePathCallback, fileChooserParams);
return showFileChooser( webView, filePathCallback, fileChooserParams);

}
}); //setWebChromeClient
Expand Down Expand Up @@ -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) {
Expand All @@ -261,7 +261,7 @@ else if ( !hexName.isEmpty()) {
} // onCreate


private boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
private boolean showFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
onShowFileChooser_filePathCallback = filePathCallback;
try {
Intent intent = fileChooserParams.createIntent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@
<string name="fetch_out_of_memory">Out of memory</string>
<string name="fetch_failed_to_create_my_data_htm">Failed to create MY_DATA.HTM</string>
<string name="fetch_works_with_micro_bit_v2_only">Works with micro:bit V2 only</string>
<string name="this_device_may_have_restrictions_in_place">"This device may have restrictions in place."</string>
<string name="unable_to_start_activity_to_enable_bluetooth">"Unable to enable Bluetooth"</string>
<string name="unable_to_start_activity_to_enable_location_services">"Unable to enable Location"</string>
<string name="unable_to_start_activity">"Unable to start activity"</string>
<string name="this_device_may_have_restrictions_in_place">"This device may be restricted."</string>
<string name="unable_to_start_activity_to_enable_bluetooth">"Unable to turn on Bluetooth"</string>
<string name="unable_to_start_activity_to_enable_location_services">"Unable to turn on Location"</string>
<string name="unable_to_start_activity">"Unable to start external activity"</string>
<string name="unable_to_open_link">"Unable to open link"</string>
</resources>

0 comments on commit 1e93955

Please sign in to comment.