Skip to content

Commit

Permalink
Android: Add "Ignore for this session" to Warning AlertMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebola16 committed Sep 12, 2020
1 parent 6b4561c commit 68dbc30
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public static native void SetMotionSensorsEnabled(boolean accelerometerEnabled,
public static native String FormatSize(long bytes, int decimals);

public static boolean displayAlertMsg(final String caption, final String text,
final boolean yesNo)
final boolean yesNo, final boolean isWarning)
{
Log.error("[NativeLibrary] Alert: " + text);
final EmulationActivity emulationActivity = sEmulationActivity.get();
Expand All @@ -444,6 +444,10 @@ public static boolean displayAlertMsg(final String caption, final String text,
{
Log.warning("[NativeLibrary] EmulationActivity is null, can't do panic alert.");
}
else if (emulationActivity.isIgnoringWarnings() && isWarning)
{
return true;
}
else
{
// AlertMessages while the core is booting will deadlock when WaitUntilDoneBooting is called.
Expand All @@ -459,8 +463,9 @@ public static boolean displayAlertMsg(final String caption, final String text,
{
sIsShowingAlertMessage = true;

emulationActivity.runOnUiThread(() -> AlertMessage.newInstance(caption, text, yesNo)
.show(emulationActivity.getSupportFragmentManager(), "AlertMessage"));
emulationActivity.runOnUiThread(
() -> AlertMessage.newInstance(caption, text, yesNo, isWarning)
.show(emulationActivity.getSupportFragmentManager(), "AlertMessage"));

// Wait for the lock to notify that it is complete.
synchronized (sAlertMessageLock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ public final class EmulationActivity extends AppCompatActivity
private String mSelectedGameId;
private int mPlatform;
private String[] mPaths;
private boolean mIgnoreWarnings;
private static boolean sUserPausedEmulation;

public static final String EXTRA_SELECTED_GAMES = "SelectedGames";
public static final String EXTRA_SELECTED_TITLE = "SelectedTitle";
public static final String EXTRA_SELECTED_GAMEID = "SelectedGameId";
public static final String EXTRA_PLATFORM = "Platform";
public static final String EXTRA_IGNORE_WARNINGS = "IgnoreWarnings";
public static final String EXTRA_USER_PAUSED_EMULATION = "sUserPausedEmulation";

@Retention(SOURCE)
Expand Down Expand Up @@ -263,6 +265,7 @@ protected void onCreate(Bundle savedInstanceState)
mSelectedTitle = gameToEmulate.getStringExtra(EXTRA_SELECTED_TITLE);
mSelectedGameId = gameToEmulate.getStringExtra(EXTRA_SELECTED_GAMEID);
mPlatform = gameToEmulate.getIntExtra(EXTRA_PLATFORM, 0);
mIgnoreWarnings = gameToEmulate.getBooleanExtra(EXTRA_IGNORE_WARNINGS, false);
sUserPausedEmulation = gameToEmulate.getBooleanExtra(EXTRA_USER_PAUSED_EMULATION, false);
activityRecreated = false;
Toast.makeText(this, getString(R.string.emulation_menu_help), Toast.LENGTH_LONG).show();
Expand Down Expand Up @@ -318,6 +321,7 @@ protected void onSaveInstanceState(@NonNull Bundle outState)
outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle);
outState.putString(EXTRA_SELECTED_GAMEID, mSelectedGameId);
outState.putInt(EXTRA_PLATFORM, mPlatform);
outState.putBoolean(EXTRA_USER_PAUSED_EMULATION, mIgnoreWarnings);
outState.putBoolean(EXTRA_USER_PAUSED_EMULATION, sUserPausedEmulation);
super.onSaveInstanceState(outState);
}
Expand All @@ -328,6 +332,7 @@ protected void restoreState(Bundle savedInstanceState)
mSelectedTitle = savedInstanceState.getString(EXTRA_SELECTED_TITLE);
mSelectedGameId = savedInstanceState.getString(EXTRA_SELECTED_GAMEID);
mPlatform = savedInstanceState.getInt(EXTRA_PLATFORM);
mIgnoreWarnings = savedInstanceState.getBoolean(EXTRA_IGNORE_WARNINGS);
sUserPausedEmulation = savedInstanceState.getBoolean(EXTRA_USER_PAUSED_EMULATION);
}

Expand Down Expand Up @@ -647,6 +652,16 @@ public void handleMenuAction(@MenuAction int menuAction)
}
}

public boolean isIgnoringWarnings()
{
return mIgnoreWarnings;
}

public void setIgnoreWarnings(boolean value)
{
mIgnoreWarnings = value;
}

public static boolean getHasUserPausedEmulation()
{
return sUserPausedEmulation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ public final class AlertMessage extends DialogFragment
private static final String ARG_TITLE = "title";
private static final String ARG_MESSAGE = "message";
private static final String ARG_YES_NO = "yesNo";
private static final String ARG_IS_WARNING = "isWarning";

public static AlertMessage newInstance(String title, String message, boolean yesNo)
public static AlertMessage newInstance(String title, String message, boolean yesNo,
boolean isWarning)
{
AlertMessage fragment = new AlertMessage();

Bundle args = new Bundle();
args.putString(ARG_TITLE, title);
args.putString(ARG_MESSAGE, message);
args.putBoolean(ARG_YES_NO, yesNo);
args.putBoolean(ARG_IS_WARNING, isWarning);
fragment.setArguments(args);

return fragment;
Expand All @@ -39,6 +42,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
String title = requireArguments().getString(ARG_TITLE);
String message = requireArguments().getString(ARG_MESSAGE);
boolean yesNo = requireArguments().getBoolean(ARG_YES_NO);
boolean isWarning = requireArguments().getBoolean(ARG_IS_WARNING);
setCancelable(false);

AlertDialog.Builder builder = new AlertDialog.Builder(emulationActivity,
Expand Down Expand Up @@ -71,6 +75,17 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
NativeLibrary.NotifyAlertMessageLock();
});
}

if (isWarning)
{
builder.setNeutralButton(R.string.ignore_warning_alert_messages, (dialog, which) ->
{
emulationActivity.setIgnoreWarnings(true);
dialog.dismiss();
NativeLibrary.NotifyAlertMessageLock();
});
}

return builder.create();
}

Expand Down
1 change: 1 addition & 0 deletions Source/Android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,6 @@
<string name="slider_setting_value">%1$d%2$s</string>
<string name="disc_number">Disc %1$d</string>
<string name="disabled_gc_overlay_notice">GameCube Controller 1 is set to \"None\"</string>
<string name="ignore_warning_alert_messages">Ignore for this session</string>

</resources>
2 changes: 1 addition & 1 deletion Source/Android/jni/AndroidCommon/IDCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
const jclass native_library_class = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary");
s_native_library_class = reinterpret_cast<jclass>(env->NewGlobalRef(native_library_class));
s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg",
"(Ljava/lang/String;Ljava/lang/String;Z)Z");
"(Ljava/lang/String;Ljava/lang/String;ZZ)Z");
s_do_rumble = env->GetStaticMethodID(s_native_library_class, "rumble", "(ID)V");
s_get_update_touch_pointer =
env->GetStaticMethodID(s_native_library_class, "updateTouchPointer", "()V");
Expand Down
4 changes: 2 additions & 2 deletions Source/Android/jni/MainAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ void Host_TitleChanged()
{
}

static bool MsgAlert(const char* caption, const char* text, bool yes_no, Common::MsgType /*style*/)
static bool MsgAlert(const char* caption, const char* text, bool yes_no, Common::MsgType style)
{
JNIEnv* env = IDCache::GetEnvForThread();

// Execute the Java method.
jboolean result = env->CallStaticBooleanMethod(
IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(), ToJString(env, caption),
ToJString(env, text), yes_no ? JNI_TRUE : JNI_FALSE);
ToJString(env, text), yes_no ? JNI_TRUE : JNI_FALSE, style == Common::MsgType::Warning);

return result != JNI_FALSE;
}
Expand Down

0 comments on commit 68dbc30

Please sign in to comment.