-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Use DialogFragment for AlertMessage
- Loading branch information
Showing
7 changed files
with
148 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.dolphinemu.dolphinemu.dialogs; | ||
|
||
import android.app.Dialog; | ||
import android.os.Bundle; | ||
|
||
import org.dolphinemu.dolphinemu.NativeLibrary; | ||
import org.dolphinemu.dolphinemu.R; | ||
import org.dolphinemu.dolphinemu.activities.EmulationActivity; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AlertDialog; | ||
import androidx.fragment.app.DialogFragment; | ||
|
||
public final class AlertMessage extends DialogFragment | ||
{ | ||
private static boolean sAlertResult = false; | ||
private static final String ARG_TITLE = "title"; | ||
private static final String ARG_MESSAGE = "message"; | ||
private static final String ARG_YES_NO = "yesNo"; | ||
|
||
public static AlertMessage newInstance(String title, String message, boolean yesNo) | ||
{ | ||
AlertMessage fragment = new AlertMessage(); | ||
|
||
Bundle args = new Bundle(); | ||
args.putString(ARG_TITLE, title); | ||
args.putString(ARG_MESSAGE, message); | ||
args.putBoolean(ARG_YES_NO, yesNo); | ||
fragment.setArguments(args); | ||
|
||
return fragment; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Dialog onCreateDialog(Bundle savedInstanceState) | ||
{ | ||
final EmulationActivity emulationActivity = NativeLibrary.getEmulationActivity(); | ||
String title = requireArguments().getString(ARG_TITLE); | ||
String message = requireArguments().getString(ARG_MESSAGE); | ||
boolean yesNo = requireArguments().getBoolean(ARG_YES_NO); | ||
setCancelable(false); | ||
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(emulationActivity, | ||
R.style.DolphinDialogBase) | ||
.setTitle(title) | ||
.setMessage(message); | ||
|
||
// If not yes/no dialog just have one button that dismisses modal, | ||
// otherwise have a yes and no button that sets sAlertResult accordingly. | ||
if (!yesNo) | ||
{ | ||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> | ||
{ | ||
dialog.dismiss(); | ||
NativeLibrary.NotifyAlertMessageLock(); | ||
}); | ||
} | ||
else | ||
{ | ||
builder.setPositiveButton(android.R.string.yes, (dialog, which) -> | ||
{ | ||
sAlertResult = true; | ||
dialog.dismiss(); | ||
NativeLibrary.NotifyAlertMessageLock(); | ||
}) | ||
.setNegativeButton(android.R.string.no, (dialog, which) -> | ||
{ | ||
sAlertResult = false; | ||
dialog.dismiss(); | ||
NativeLibrary.NotifyAlertMessageLock(); | ||
}); | ||
} | ||
return builder.create(); | ||
} | ||
|
||
public static boolean GetAlertResult() | ||
{ | ||
return sAlertResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters