diff options
| author | Charles Lombardo <clombardo169@gmail.com> | 2022-06-04 00:47:48 -0400 |
|---|---|---|
| committer | Charles Lombardo <clombardo169@gmail.com> | 2022-08-31 18:01:15 -0400 |
| commit | 940a38f172c987c84eddd60d9c5bfff72f4449d7 (patch) | |
| tree | 1559371308277de61f72b090ee3a99c422202b9d /Source/Android/app/src/main/java | |
| parent | 9195e1a9b8a629d89d786f4f3c1cfb46f4e2eb24 (diff) | |
Android: App redesign with multi-theme system
Diffstat (limited to 'Source/Android/app/src/main/java')
36 files changed, 783 insertions, 560 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java index 4678a798e4..e2ee9ae353 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java @@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.fragments.ConvertFragment; +import org.dolphinemu.dolphinemu.utils.ThemeHelper; public class ConvertActivity extends AppCompatActivity { @@ -25,6 +26,8 @@ public class ConvertActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { + ThemeHelper.setTheme(this); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_convert); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 89bb84f75e..969d1ca3f1 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -19,14 +19,12 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; -import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.IntDef; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.PopupMenu; import androidx.fragment.app.Fragment; @@ -48,12 +46,14 @@ import org.dolphinemu.dolphinemu.fragments.SaveLoadStateFragment; import org.dolphinemu.dolphinemu.overlay.InputOverlay; import org.dolphinemu.dolphinemu.overlay.InputOverlayPointer; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; +import org.dolphinemu.dolphinemu.ui.main.ThemeProvider; import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner; import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; import org.dolphinemu.dolphinemu.utils.IniFile; import org.dolphinemu.dolphinemu.utils.MotionListener; import org.dolphinemu.dolphinemu.utils.Rumble; +import org.dolphinemu.dolphinemu.utils.ThemeHelper; import java.io.File; import java.lang.annotation.Retention; @@ -61,7 +61,11 @@ import java.util.List; import static java.lang.annotation.RetentionPolicy.SOURCE; -public final class EmulationActivity extends AppCompatActivity +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.slider.LabelFormatter; +import com.google.android.material.slider.Slider; + +public final class EmulationActivity extends AppCompatActivity implements ThemeProvider { private static final String BACKSTACK_NAME_MENU = "menu"; private static final String BACKSTACK_NAME_SUBMENU = "submenu"; @@ -74,6 +78,8 @@ public final class EmulationActivity extends AppCompatActivity private Settings mSettings; + private int mThemeId; + private boolean mMenuVisible; private static boolean sIgnoreLaunchRequests = false; @@ -193,25 +199,27 @@ public final class EmulationActivity extends AppCompatActivity !FileBrowserHelper.isPathEmptyOrValid(StringSetting.MAIN_LOAD_PATH) || !FileBrowserHelper.isPathEmptyOrValid(StringSetting.MAIN_RESOURCEPACK_PATH)) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setMessage(R.string.unavailable_paths); - builder.setPositiveButton(R.string.yes, (dialogInterface, i) -> - SettingsActivity.launch(activity, MenuTag.CONFIG_PATHS)); - builder.setNeutralButton(R.string.continue_anyway, (dialogInterface, i) -> - continueCallback.run()); - builder.show(); + new MaterialAlertDialogBuilder(activity) + .setMessage(R.string.unavailable_paths) + .setPositiveButton(R.string.yes, + (dialogInterface, i) -> SettingsActivity.launch(activity, + MenuTag.CONFIG_PATHS)) + .setNeutralButton(R.string.continue_anyway, + (dialogInterface, i) -> continueCallback.run()) + .show(); } else if (!FileBrowserHelper.isPathEmptyOrValid(StringSetting.MAIN_WII_SD_CARD_IMAGE_PATH) || !FileBrowserHelper.isPathEmptyOrValid( StringSetting.MAIN_WII_SD_CARD_SYNC_FOLDER_PATH)) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setMessage(R.string.unavailable_paths); - builder.setPositiveButton(R.string.yes, (dialogInterface, i) -> - SettingsActivity.launch(activity, MenuTag.CONFIG_WII)); - builder.setNeutralButton(R.string.continue_anyway, (dialogInterface, i) -> - continueCallback.run()); - builder.show(); + new MaterialAlertDialogBuilder(activity) + .setMessage(R.string.unavailable_paths) + .setPositiveButton(R.string.yes, + (dialogInterface, i) -> SettingsActivity.launch(activity, + MenuTag.CONFIG_WII)) + .setNeutralButton(R.string.continue_anyway, + (dialogInterface, i) -> continueCallback.run()) + .show(); } else { @@ -295,6 +303,8 @@ public final class EmulationActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { + ThemeHelper.setTheme(this); + super.onCreate(savedInstanceState); MainPresenter.skipRescanningLibrary(); @@ -382,6 +392,8 @@ public final class EmulationActivity extends AppCompatActivity @Override protected void onResume() { + ThemeHelper.setCorrectTheme(this); + super.onResume(); // Only android 9+ support this feature. @@ -816,8 +828,8 @@ public final class EmulationActivity extends AppCompatActivity private void toggleControls() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.emulation_toggle_controls); + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this) + .setTitle(R.string.emulation_toggle_controls); int currentController = InputOverlay.getConfiguredControllerType(this); @@ -873,17 +885,14 @@ public final class EmulationActivity extends AppCompatActivity } builder.setNeutralButton(R.string.emulation_toggle_all, - (dialogInterface, i) -> mEmulationFragment.toggleInputOverlayVisibility(mSettings)); - builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> - mEmulationFragment.refreshInputOverlay()); - - builder.show(); + (dialogInterface, i) -> mEmulationFragment.toggleInputOverlayVisibility(mSettings)) + .setPositiveButton(R.string.ok, (dialogInterface, i) -> + mEmulationFragment.refreshInputOverlay()) + .show(); } public void chooseDoubleTapButton() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - int currentValue = IntSetting.MAIN_DOUBLE_TAP_BUTTON.getInt(mSettings); int buttonList = InputOverlay.getConfiguredControllerType(this) == @@ -900,14 +909,13 @@ public final class EmulationActivity extends AppCompatActivity } } - builder.setSingleChoiceItems(buttonList, checkedItem, - (DialogInterface dialog, int which) -> IntSetting.MAIN_DOUBLE_TAP_BUTTON - .setInt(mSettings, InputOverlayPointer.DOUBLE_TAP_OPTIONS.get(which))); - - builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> - mEmulationFragment.initInputPointer()); - - builder.show(); + new MaterialAlertDialogBuilder(this) + .setSingleChoiceItems(buttonList, checkedItem, + (DialogInterface dialog, int which) -> IntSetting.MAIN_DOUBLE_TAP_BUTTON.setInt( + mSettings, InputOverlayPointer.DOUBLE_TAP_OPTIONS.get(which))) + .setPositiveButton(R.string.ok, + (dialogInterface, i) -> mEmulationFragment.initInputPointer()) + .show(); } private void adjustScale() @@ -915,130 +923,96 @@ public final class EmulationActivity extends AppCompatActivity LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.dialog_input_adjust, null); - final SeekBar scaleSeekbar = view.findViewById(R.id.input_scale_seekbar); + final Slider scaleSlider = view.findViewById(R.id.input_scale_slider); final TextView scaleValue = view.findViewById(R.id.input_scale_value); - - scaleSeekbar.setMax(150); - scaleSeekbar.setProgress(IntSetting.MAIN_CONTROL_SCALE.getInt(mSettings)); - scaleSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() - { - public void onStartTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) - { - scaleValue.setText((progress + 50) + "%"); - } - - public void onStopTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - }); - - scaleValue.setText((scaleSeekbar.getProgress() + 50) + "%"); + scaleSlider.setValueTo(150); + scaleSlider.setValue(IntSetting.MAIN_CONTROL_SCALE.getInt(mSettings)); + scaleSlider.setStepSize(1); + scaleSlider.addOnChangeListener( + (slider, progress, fromUser) -> scaleValue.setText(((int) progress + 50) + "%")); + scaleValue.setText(((int) scaleSlider.getValue() + 50) + "%"); // alpha - final SeekBar seekbarOpacity = view.findViewById(R.id.input_opacity_seekbar); + final Slider sliderOpacity = view.findViewById(R.id.input_opacity_slider); final TextView valueOpacity = view.findViewById(R.id.input_opacity_value); - - seekbarOpacity.setMax(100); - seekbarOpacity.setProgress(IntSetting.MAIN_CONTROL_OPACITY.getInt(mSettings)); - seekbarOpacity.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() - { - public void onStartTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) - { - valueOpacity.setText(progress + "%"); - } - - public void onStopTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - }); - valueOpacity.setText(seekbarOpacity.getProgress() + "%"); - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.emulation_control_adjustments); - builder.setView(view); - builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> - { - IntSetting.MAIN_CONTROL_SCALE.setInt(mSettings, scaleSeekbar.getProgress()); - IntSetting.MAIN_CONTROL_OPACITY.setInt(mSettings, seekbarOpacity.getProgress()); - mEmulationFragment.refreshInputOverlay(); - }); - builder.setNeutralButton(R.string.default_values, (dialogInterface, i) -> - { - IntSetting.MAIN_CONTROL_SCALE.delete(mSettings); - IntSetting.MAIN_CONTROL_OPACITY.delete(mSettings); - mEmulationFragment.refreshInputOverlay(); - }); - - builder.show(); + sliderOpacity.setValueTo(100); + sliderOpacity.setValue(IntSetting.MAIN_CONTROL_OPACITY.getInt(mSettings)); + sliderOpacity.setStepSize(1); + sliderOpacity.addOnChangeListener( + (slider, progress, fromUser) -> valueOpacity.setText(((int) progress) + "%")); + valueOpacity.setText(((int) sliderOpacity.getValue()) + "%"); + + + new MaterialAlertDialogBuilder(this) + .setTitle(R.string.emulation_control_adjustments) + .setView(view) + .setPositiveButton(R.string.ok, (dialog, which) -> + { + IntSetting.MAIN_CONTROL_SCALE.setInt(mSettings, (int) scaleSlider.getValue()); + IntSetting.MAIN_CONTROL_OPACITY.setInt(mSettings, (int) sliderOpacity.getValue()); + mEmulationFragment.refreshInputOverlay(); + }) + .setNeutralButton(R.string.default_values, (dialog, which) -> + { + IntSetting.MAIN_CONTROL_SCALE.delete(mSettings); + IntSetting.MAIN_CONTROL_OPACITY.delete(mSettings); + mEmulationFragment.refreshInputOverlay(); + }) + .show(); } private void chooseController() { final SharedPreferences.Editor editor = mPreferences.edit(); - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.emulation_choose_controller); - builder.setSingleChoiceItems(R.array.controllersEntries, - InputOverlay.getConfiguredControllerType(this), - (dialog, indexSelected) -> + new MaterialAlertDialogBuilder(this) + .setTitle(R.string.emulation_choose_controller) + .setSingleChoiceItems(R.array.controllersEntries, + InputOverlay.getConfiguredControllerType(this), + (dialog, indexSelected) -> + { + editor.putInt("wiiController", indexSelected); + + updateWiimoteNewController(indexSelected, this); + NativeLibrary.ReloadWiimoteConfig(); + }) + .setPositiveButton(R.string.ok, (dialogInterface, i) -> { - editor.putInt("wiiController", indexSelected); - - updateWiimoteNewController(indexSelected, this); - NativeLibrary.ReloadWiimoteConfig(); - }); - builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> - { - editor.apply(); - mEmulationFragment.refreshInputOverlay(); - }); - - builder.show(); + editor.apply(); + mEmulationFragment.refreshInputOverlay(); + }) + .show(); } private void showMotionControlsOptions() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.emulation_motion_controls); - builder.setSingleChoiceItems(R.array.motionControlsEntries, - IntSetting.MAIN_MOTION_CONTROLS.getInt(mSettings), - (dialog, indexSelected) -> - { - IntSetting.MAIN_MOTION_CONTROLS.setInt(mSettings, indexSelected); - - updateMotionListener(); - - updateWiimoteNewImuIr(indexSelected); - NativeLibrary.ReloadWiimoteConfig(); - }); - builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> dialogInterface.dismiss()); - - builder.show(); + new MaterialAlertDialogBuilder(this) + .setTitle(R.string.emulation_motion_controls) + .setSingleChoiceItems(R.array.motionControlsEntries, + IntSetting.MAIN_MOTION_CONTROLS.getInt(mSettings), + (dialog, indexSelected) -> + { + IntSetting.MAIN_MOTION_CONTROLS.setInt(mSettings, indexSelected); + + updateMotionListener(); + + updateWiimoteNewImuIr(indexSelected); + NativeLibrary.ReloadWiimoteConfig(); + }) + .setPositiveButton(R.string.ok, (dialogInterface, i) -> dialogInterface.dismiss()) + .show(); } private void setIRMode() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.emulation_ir_mode); - builder.setSingleChoiceItems(R.array.irModeEntries, - IntSetting.MAIN_IR_MODE.getInt(mSettings), - (dialog, indexSelected) -> - IntSetting.MAIN_IR_MODE.setInt(mSettings, indexSelected)); - builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> - mEmulationFragment.refreshOverlayPointer(mSettings)); - - builder.show(); + new MaterialAlertDialogBuilder(this) + .setTitle(R.string.emulation_ir_mode) + .setSingleChoiceItems(R.array.irModeEntries, + IntSetting.MAIN_IR_MODE.getInt(mSettings), + (dialog, indexSelected) -> + IntSetting.MAIN_IR_MODE.setInt(mSettings, indexSelected)) + .setPositiveButton(R.string.ok, (dialogInterface, i) -> + mEmulationFragment.refreshOverlayPointer(mSettings)) + .show(); } private void setIRSensitivity() @@ -1054,59 +1028,30 @@ public final class EmulationActivity extends AppCompatActivity TextView text_slider_value_pitch = view.findViewById(R.id.text_ir_pitch); TextView units = view.findViewById(R.id.text_ir_pitch_units); - SeekBar seekbar_pitch = view.findViewById(R.id.seekbar_pitch); + Slider slider_pitch = view.findViewById(R.id.slider_pitch); text_slider_value_pitch.setText(String.valueOf(ir_pitch)); units.setText(getString(R.string.pitch)); - seekbar_pitch.setMax(100); - seekbar_pitch.setProgress(ir_pitch); - seekbar_pitch.setKeyProgressIncrement(5); - seekbar_pitch.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() - { - @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) - { - text_slider_value_pitch.setText(String.valueOf(progress)); - } - - @Override public void onStartTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - - @Override public void onStopTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - }); + slider_pitch.setValueTo(100); + slider_pitch.setValue(ir_pitch); + slider_pitch.setStepSize(1); + slider_pitch.addOnChangeListener( + (slider, progress, fromUser) -> text_slider_value_pitch.setText( + String.valueOf((int) progress))); int ir_yaw = ini.getInt(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_YAW, 25); TextView text_slider_value_yaw = view.findViewById(R.id.text_ir_yaw); TextView units_yaw = view.findViewById(R.id.text_ir_yaw_units); - SeekBar seekbar_yaw = view.findViewById(R.id.seekbar_width); + Slider seekbar_yaw = view.findViewById(R.id.slider_width); text_slider_value_yaw.setText(String.valueOf(ir_yaw)); units_yaw.setText(getString(R.string.yaw)); - seekbar_yaw.setMax(100); - seekbar_yaw.setProgress(ir_yaw); - seekbar_yaw.setKeyProgressIncrement(5); - seekbar_yaw.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() - { - @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) - { - text_slider_value_yaw.setText(String.valueOf(progress)); - } - - @Override public void onStartTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - - @Override public void onStopTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - }); + seekbar_yaw.setValueTo(100); + seekbar_yaw.setValue(ir_yaw); + seekbar_yaw.setStepSize(1); + seekbar_yaw.addOnChangeListener((slider, progress, fromUser) -> text_slider_value_yaw.setText( + String.valueOf((int) progress))); int ir_vertical_offset = @@ -1114,71 +1059,52 @@ public final class EmulationActivity extends AppCompatActivity TextView text_slider_value_vertical_offset = view.findViewById(R.id.text_ir_vertical_offset); TextView units_vertical_offset = view.findViewById(R.id.text_ir_vertical_offset_units); - SeekBar seekbar_vertical_offset = view.findViewById(R.id.seekbar_vertical_offset); + Slider seekbar_vertical_offset = view.findViewById(R.id.slider_vertical_offset); text_slider_value_vertical_offset.setText(String.valueOf(ir_vertical_offset)); units_vertical_offset.setText(getString(R.string.vertical_offset)); - seekbar_vertical_offset.setMax(100); - seekbar_vertical_offset.setProgress(ir_vertical_offset); - seekbar_vertical_offset.setKeyProgressIncrement(5); - seekbar_vertical_offset.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() - { - @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) - { - text_slider_value_vertical_offset.setText(String.valueOf(progress)); - } - - @Override public void onStartTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - - @Override public void onStopTrackingTouch(SeekBar seekBar) - { - // Do nothing - } - }); + seekbar_vertical_offset.setValueTo(100); + seekbar_vertical_offset.setValue(ir_vertical_offset); + seekbar_vertical_offset.setStepSize(1); + seekbar_vertical_offset.addOnChangeListener( + (slider, progress, fromUser) -> text_slider_value_vertical_offset.setText( + String.valueOf((int) progress))); + + new MaterialAlertDialogBuilder(this) + .setTitle(getString(R.string.emulation_ir_sensitivity)) + .setView(view) + .setPositiveButton(R.string.ok, (dialogInterface, i) -> + { + ini.setString(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_PITCH, + text_slider_value_pitch.getText().toString()); + ini.setString(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_YAW, + text_slider_value_yaw.getText().toString()); + ini.setString(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_VERTICAL_OFFSET, + text_slider_value_vertical_offset.getText().toString()); + ini.save(file); - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.emulation_ir_sensitivity)); - builder.setView(view); - builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> - { - ini.setString(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_PITCH, - text_slider_value_pitch.getText().toString()); - ini.setString(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_YAW, - text_slider_value_yaw.getText().toString()); - ini.setString(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_VERTICAL_OFFSET, - text_slider_value_vertical_offset.getText().toString()); - ini.save(file); - - NativeLibrary.ReloadWiimoteConfig(); - }); - builder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> - { - // Do nothing - }); - builder.setNeutralButton(R.string.default_values, (dialogInterface, i) -> - { - ini.deleteKey(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_PITCH); - ini.deleteKey(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_YAW); - ini.deleteKey(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_VERTICAL_OFFSET); - ini.save(file); + NativeLibrary.ReloadWiimoteConfig(); + }) + .setNegativeButton(R.string.cancel, null) + .setNeutralButton(R.string.default_values, (dialogInterface, i) -> + { + ini.deleteKey(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_PITCH); + ini.deleteKey(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_YAW); + ini.deleteKey(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_VERTICAL_OFFSET); + ini.save(file); - NativeLibrary.ReloadWiimoteConfig(); - }); - builder.show(); + NativeLibrary.ReloadWiimoteConfig(); + }) + .show(); } private void resetOverlay() { - new AlertDialog.Builder(this) + new MaterialAlertDialogBuilder(this) .setTitle(getString(R.string.emulation_touch_overlay_reset)) - .setPositiveButton(R.string.yes, (dialogInterface, i) -> - mEmulationFragment.resetInputOverlay()) - .setNegativeButton(R.string.cancel, (dialogInterface, i) -> - { - }) + .setPositiveButton(R.string.yes, + (dialogInterface, i) -> mEmulationFragment.resetInputOverlay()) + .setNegativeButton(R.string.cancel, null) .show(); } @@ -1300,4 +1226,17 @@ public final class EmulationActivity extends AppCompatActivity { mEmulationFragment.initInputPointer(); } + + @Override + public void setTheme(int themeId) + { + super.setTheme(themeId); + this.mThemeId = themeId; + } + + @Override + public int getThemeId() + { + return mThemeId; + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java index 0ab446a67d..fddbad7e28 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java @@ -14,12 +14,15 @@ import android.widget.Button; import android.widget.TextView; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; import org.dolphinemu.dolphinemu.utils.Log; +import org.dolphinemu.dolphinemu.utils.ThemeHelper; import org.dolphinemu.dolphinemu.utils.ThreadUtil; import java.io.File; @@ -50,6 +53,8 @@ public class UserDataActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { + ThemeHelper.setTheme(this); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_data); @@ -80,7 +85,8 @@ public class UserDataActivity extends AppCompatActivity buttonExportUserData.setOnClickListener(view -> exportUserData()); - // show up button + Toolbar tb = findViewById(R.id.toolbar_user_data); + setSupportActionBar(tb); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } @@ -100,26 +106,25 @@ public class UserDataActivity extends AppCompatActivity { Uri uri = data.getData(); - AlertDialog.Builder builder = new AlertDialog.Builder(this); - - builder.setMessage(R.string.user_data_import_warning); - builder.setNegativeButton(R.string.no, (dialog, i) -> dialog.dismiss()); - builder.setPositiveButton(R.string.yes, (dialog, i) -> - { - dialog.dismiss(); - - ThreadUtil.runOnThreadAndShowResult(this, R.string.import_in_progress, - R.string.do_not_close_app, () -> getResources().getString(importUserData(uri)), - (dialogInterface) -> - { - if (sMustRestartApp) - { - System.exit(0); - } - }); - }); - - builder.show(); + new MaterialAlertDialogBuilder(this) + .setMessage(R.string.user_data_import_warning) + .setNegativeButton(R.string.no, (dialog, i) -> dialog.dismiss()) + .setPositiveButton(R.string.yes, (dialog, i) -> + { + dialog.dismiss(); + + ThreadUtil.runOnThreadAndShowResult(this, R.string.import_in_progress, + R.string.do_not_close_app, + () -> getResources().getString(importUserData(uri)), + (dialogInterface) -> + { + if (sMustRestartApp) + { + System.exit(0); + } + }); + }) + .show(); } else if (requestCode == REQUEST_CODE_EXPORT && resultCode == Activity.RESULT_OK) { @@ -148,7 +153,7 @@ public class UserDataActivity extends AppCompatActivity { // Activity not found. Perhaps it was removed by the OEM, or by some new Android version // that didn't exist at the time of writing. Not much we can do other than tell the user - new AlertDialog.Builder(this) + new MaterialAlertDialogBuilder(this) .setMessage(R.string.user_data_open_system_file_manager_failed) .setPositiveButton(R.string.ok, null) .show(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/PlatformPagerAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/PlatformPagerAdapter.java index b0541a57ec..e8d97e3fb2 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/PlatformPagerAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/PlatformPagerAdapter.java @@ -62,7 +62,8 @@ public class PlatformPagerAdapter extends FragmentPagerAdapter // Apparently a workaround for TabLayout not supporting icons. // TODO: This workaround will eventually not be necessary; switch to more legit methods when that is the case // TODO: Also remove additional hax from styles.xml - Drawable drawable = mContext.getResources().getDrawable(TAB_ICONS[position]); + Drawable drawable = + mContext.getResources().getDrawable(TAB_ICONS[position], mContext.getTheme()); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java index b8ba6fcbb2..69cf5ef280 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java @@ -6,9 +6,10 @@ import android.app.Dialog; import android.os.Bundle; import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.EmulationActivity; @@ -47,7 +48,7 @@ public final class AlertMessage extends DialogFragment boolean isWarning = requireArguments().getBoolean(ARG_IS_WARNING); setCancelable(false); - AlertDialog.Builder builder = new AlertDialog.Builder(emulationActivity) + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(emulationActivity) .setTitle(title) .setMessage(message); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GameDetailsDialog.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GameDetailsDialog.java index 2b1bf87bee..4da860ddc4 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GameDetailsDialog.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GameDetailsDialog.java @@ -9,9 +9,10 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.model.GameFile; @@ -38,7 +39,6 @@ public final class GameDetailsDialog extends DialogFragment { GameFile gameFile = GameFileCacheManager.addOrGet(getArguments().getString(ARG_GAME_PATH)); - AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()); ViewGroup contents = (ViewGroup) getActivity().getLayoutInflater() .inflate(R.layout.dialog_game_details, null); @@ -116,7 +116,8 @@ public final class GameDetailsDialog extends DialogFragment PicassoUtils.loadGameBanner(banner, gameFile); - builder.setView(contents); - return builder.create(); + return new MaterialAlertDialogBuilder(requireActivity()) + .setView(contents) + .create(); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java index 0c9b16cb01..339434e8e3 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GamePropertiesDialog.java @@ -8,9 +8,10 @@ import android.os.Bundle; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.DolphinApplication; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.ConvertActivity; @@ -117,16 +118,16 @@ public class GamePropertiesDialog extends DialogFragment itemsBuilder.add(R.string.properties_clear_game_settings, (dialog, i) -> clearGameSettingsWithConfirmation(gameId)); - AlertDialog.Builder builder = new AlertDialog.Builder(requireContext()); + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()) + .setTitle(requireContext() + .getString(R.string.preferences_game_properties_with_game_id, gameId)); itemsBuilder.applyToBuilder(builder); - builder.setTitle(requireContext() - .getString(R.string.preferences_game_properties_with_game_id, gameId)); return builder.create(); } private void clearGameSettingsWithConfirmation(String gameId) { - new AlertDialog.Builder(requireContext()) + new MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.properties_clear_game_settings) .setMessage(R.string.properties_clear_game_settings_confirmation) .setPositiveButton(R.string.yes, (dialog, i) -> clearGameSettings(gameId)) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java index b0316f94cc..72c44cd58a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java @@ -3,13 +3,29 @@ package org.dolphinemu.dolphinemu.dialogs; import android.content.Context; +import android.content.res.ColorStateList; +import android.content.res.Resources; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.util.TypedValue; import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; +import androidx.annotation.AttrRes; import androidx.annotation.NonNull; +import androidx.annotation.StyleRes; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.view.ContextThemeWrapper; +import androidx.core.view.ViewCompat; +import com.google.android.material.color.MaterialColors; +import com.google.android.material.dialog.MaterialDialogs; +import com.google.android.material.resources.MaterialAttributes; +import com.google.android.material.shape.MaterialShapeDrawable; + +import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting; import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter; import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper; @@ -18,12 +34,20 @@ import org.dolphinemu.dolphinemu.utils.Log; import java.util.ArrayList; import java.util.List; +import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap; + /** * {@link AlertDialog} derivative that listens for * motion events from controllers and joysticks. */ public final class MotionAlertDialog extends AlertDialog { + @AttrRes private static final int DEF_STYLE_ATTR = R.attr.alertDialogStyle; + @StyleRes private static final int DEF_STYLE_RES = R.style.MaterialAlertDialog_MaterialComponents; + + @AttrRes + private static final int MATERIAL_ALERT_DIALOG_THEME_OVERLAY = R.attr.materialAlertDialogTheme; + // The selected input preference private final InputBindingSetting setting; private final ArrayList<Float> mPreviousValues = new ArrayList<>(); @@ -39,10 +63,63 @@ public final class MotionAlertDialog extends AlertDialog */ public MotionAlertDialog(Context context, InputBindingSetting setting, SettingsAdapter adapter) { - super(context); + super(createMaterialAlertDialogThemedContext(context)); this.setting = setting; mAdapter = adapter; + + // Using code from MaterialAlertDialogBuilder allows us to nearly perfectly recreate its look + context = getContext(); + Resources.Theme theme = context.getTheme(); + + int surfaceColor = + MaterialColors.getColor(context, R.attr.colorSurface, getClass().getCanonicalName()); + MaterialShapeDrawable materialShapeDrawable = + new MaterialShapeDrawable(context, null, R.attr.alertDialogStyle, + R.style.MaterialAlertDialog_MaterialComponents); + materialShapeDrawable.initializeElevationOverlay(context); + materialShapeDrawable.setFillColor(ColorStateList.valueOf(surfaceColor)); + materialShapeDrawable.setElevation(ViewCompat.getElevation(this.getWindow().getDecorView())); + this.getWindow().setBackgroundDrawable(materialShapeDrawable); + + Rect backgroundInsets = + MaterialDialogs.getDialogBackgroundInsets(context, R.attr.alertDialogStyle, + R.style.MaterialAlertDialog_MaterialComponents); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + { + TypedValue dialogCornerRadiusValue = new TypedValue(); + theme.resolveAttribute(android.R.attr.dialogCornerRadius, dialogCornerRadiusValue, true); + float dialogCornerRadius = + dialogCornerRadiusValue.getDimension(context.getResources().getDisplayMetrics()); + if (dialogCornerRadiusValue.type == TypedValue.TYPE_DIMENSION && dialogCornerRadius >= 0) + { + materialShapeDrawable.setCornerSize(dialogCornerRadius); + } + } + Drawable insetDrawable = MaterialDialogs.insetDrawable(materialShapeDrawable, backgroundInsets); + this.getWindow().setBackgroundDrawable(insetDrawable); + } + + private static Context createMaterialAlertDialogThemedContext(@NonNull Context context) + { + int themeOverlayId = getMaterialAlertDialogThemeOverlay(context); + Context themedContext = wrap(context, null, DEF_STYLE_ATTR, DEF_STYLE_RES); + if (themeOverlayId == 0) + { + return themedContext; + } + return new ContextThemeWrapper(themedContext, themeOverlayId); + } + + private static int getMaterialAlertDialogThemeOverlay(@NonNull Context context) + { + TypedValue materialAlertDialogThemeOverlay = + MaterialAttributes.resolve(context, MATERIAL_ALERT_DIALOG_THEME_OVERLAY); + if (materialAlertDialogThemeOverlay == null) + { + return 0; + } + return materialAlertDialogThemeOverlay.data; } public boolean onKeyEvent(int keyCode, KeyEvent event) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatDetailsFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatDetailsFragment.java index 9c207996bb..f08b04abec 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatDetailsFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatDetailsFragment.java @@ -7,16 +7,17 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.EditText; import android.widget.ScrollView; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.cheats.model.Cheat; import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel; @@ -25,14 +26,14 @@ public class CheatDetailsFragment extends Fragment { private View mRoot; private ScrollView mScrollView; - private TextView mLabelName; - private EditText mEditName; - private TextView mLabelCreator; - private EditText mEditCreator; - private TextView mLabelNotes; - private EditText mEditNotes; - private TextView mLabelCode; - private EditText mEditCode; + private TextInputLayout mEditNameLayout; + private TextInputEditText mEditName; + private TextInputLayout mEditCreatorLayout; + private TextInputEditText mEditCreator; + private TextInputLayout mEditNotesLayout; + private TextInputEditText mEditNotes; + private TextInputLayout mEditCodeLayout; + private TextInputEditText mEditCode; private Button mButtonDelete; private Button mButtonEdit; private Button mButtonCancel; @@ -54,14 +55,14 @@ public class CheatDetailsFragment extends Fragment { mRoot = view.findViewById(R.id.root); mScrollView = view.findViewById(R.id.scroll_view); - mLabelName = view.findViewById(R.id.label_name); - mEditName = view.findViewById(R.id.edit_name); - mLabelCreator = view.findViewById(R.id.label_creator); - mEditCreator = view.findViewById(R.id.edit_creator); - mLabelNotes = view.findViewById(R.id.label_notes); - mEditNotes = view.findViewById(R.id.edit_notes); - mLabelCode = view.findViewById(R.id.label_code); - mEditCode = view.findViewById(R.id.edit_code); + mEditNameLayout = view.findViewById(R.id.edit_name); + mEditName = view.findViewById(R.id.edit_name_input); + mEditCreatorLayout = view.findViewById(R.id.edit_creator); + mEditCreator = view.findViewById(R.id.edit_creator_input); + mEditNotesLayout = view.findViewById(R.id.edit_notes); + mEditNotes = view.findViewById(R.id.edit_notes_input); + mEditCodeLayout = view.findViewById(R.id.edit_code); + mEditCode = view.findViewById(R.id.edit_code_input); mButtonDelete = view.findViewById(R.id.button_delete); mButtonEdit = view.findViewById(R.id.button_edit); mButtonCancel = view.findViewById(R.id.button_cancel); @@ -84,18 +85,17 @@ public class CheatDetailsFragment extends Fragment private void clearEditErrors() { - mEditName.setError(null); - mEditCode.setError(null); + mEditNameLayout.setError(null); + mEditCodeLayout.setError(null); } private void onDeleteClicked(View view) { - AlertDialog.Builder builder = - new AlertDialog.Builder(requireContext()); - builder.setMessage(getString(R.string.cheats_delete_confirmation, mCheat.getName())); - builder.setPositiveButton(R.string.yes, (dialog, i) -> mViewModel.deleteSelectedCheat()); - builder.setNegativeButton(R.string.no, null); - builder.show(); + new MaterialAlertDialogBuilder(requireContext()) + .setMessage(getString(R.string.cheats_delete_confirmation, mCheat.getName())) + .setPositiveButton(R.string.yes, (dialog, i) -> mViewModel.deleteSelectedCheat()) + .setNegativeButton(R.string.no, null) + .show(); } private void onEditClicked(View view) @@ -134,19 +134,19 @@ public class CheatDetailsFragment extends Fragment mButtonEdit.requestFocus(); break; case Cheat.TRY_SET_FAIL_NO_NAME: - mEditName.setError(getString(R.string.cheats_error_no_name)); - mScrollView.smoothScrollTo(0, mLabelName.getTop()); + mEditNameLayout.setError(getString(R.string.cheats_error_no_name)); + mScrollView.smoothScrollTo(0, mEditName.getTop()); break; case Cheat.TRY_SET_FAIL_NO_CODE_LINES: - mEditCode.setError(getString(R.string.cheats_error_no_code_lines)); + mEditCodeLayout.setError(getString(R.string.cheats_error_no_code_lines)); mScrollView.smoothScrollTo(0, mEditCode.getBottom()); break; case Cheat.TRY_SET_FAIL_CODE_MIXED_ENCRYPTION: - mEditCode.setError(getString(R.string.cheats_error_mixed_encryption)); + mEditCodeLayout.setError(getString(R.string.cheats_error_mixed_encryption)); mScrollView.smoothScrollTo(0, mEditCode.getBottom()); break; default: - mEditCode.setError(getString(R.string.cheats_error_on_line, result)); + mEditCodeLayout.setError(getString(R.string.cheats_error_on_line, result)); mScrollView.smoothScrollTo(0, mEditCode.getBottom()); break; } @@ -161,12 +161,9 @@ public class CheatDetailsFragment extends Fragment int creatorVisibility = cheat != null && cheat.supportsCreator() ? View.VISIBLE : View.GONE; int notesVisibility = cheat != null && cheat.supportsNotes() ? View.VISIBLE : View.GONE; int codeVisibility = cheat != null && cheat.supportsCode() ? View.VISIBLE : View.GONE; - mLabelCreator.setVisibility(creatorVisibility); - mEditCreator.setVisibility(creatorVisibility); - mLabelNotes.setVisibility(notesVisibility); - mEditNotes.setVisibility(notesVisibility); - mLabelCode.setVisibility(codeVisibility); - mEditCode.setVisibility(codeVisibility); + mEditCreatorLayout.setVisibility(creatorVisibility); + mEditNotesLayout.setVisibility(notesVisibility); + mEditCodeLayout.setVisibility(codeVisibility); boolean userDefined = cheat != null && cheat.getUserDefined(); mButtonDelete.setEnabled(userDefined); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsActivity.java index b3bb5cb0cd..c89aea45dc 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsActivity.java @@ -13,10 +13,13 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.core.view.ViewCompat; import androidx.lifecycle.ViewModelProvider; import androidx.slidingpanelayout.widget.SlidingPaneLayout; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.cheats.model.Cheat; import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel; @@ -24,6 +27,7 @@ import org.dolphinemu.dolphinemu.features.cheats.model.GeckoCheat; import org.dolphinemu.dolphinemu.features.settings.model.Settings; import org.dolphinemu.dolphinemu.ui.TwoPaneOnBackPressedCallback; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; +import org.dolphinemu.dolphinemu.utils.ThemeHelper; public class CheatsActivity extends AppCompatActivity implements SlidingPaneLayout.PanelSlideListener @@ -60,6 +64,8 @@ public class CheatsActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { + ThemeHelper.setTheme(this); + super.onCreate(savedInstanceState); MainPresenter.skipRescanningLibrary(); @@ -94,7 +100,8 @@ public class CheatsActivity extends AppCompatActivity mViewModel.getOpenDetailsViewEvent().observe(this, this::openDetailsView); - // show up button + Toolbar tb = findViewById(R.id.toolbar_cheats); + setSupportActionBar(tb); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } @@ -191,10 +198,10 @@ public class CheatsActivity extends AppCompatActivity public void downloadGeckoCodes() { - AlertDialog progressDialog = new AlertDialog.Builder(this).create(); - progressDialog.setTitle(R.string.cheats_downloading); - progressDialog.setCancelable(false); - progressDialog.show(); + AlertDialog progressDialog = new MaterialAlertDialogBuilder(this) + .setMessage(R.string.cheats_downloading) + .setCancelable(false) + .show(); new Thread(() -> { @@ -206,14 +213,14 @@ public class CheatsActivity extends AppCompatActivity if (codes == null) { - new AlertDialog.Builder(this) + new MaterialAlertDialogBuilder(this) .setMessage(getString(R.string.cheats_download_failed)) .setPositiveButton(R.string.ok, null) .show(); } else if (codes.length == 0) { - new AlertDialog.Builder(this) + new MaterialAlertDialogBuilder(this) .setMessage(getString(R.string.cheats_download_empty)) .setPositiveButton(R.string.ok, null) .show(); @@ -223,7 +230,7 @@ public class CheatsActivity extends AppCompatActivity int cheatsAdded = mViewModel.addDownloadedGeckoCodes(codes); String message = getString(R.string.cheats_download_succeeded, codes.length, cheatsAdded); - new AlertDialog.Builder(this) + new MaterialAlertDialogBuilder(this) .setMessage(message) .setPositiveButton(R.string.ok, null) .show(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/riivolution/ui/RiivolutionBootActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/riivolution/ui/RiivolutionBootActivity.java index 7509aaf37a..4cc014d646 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/riivolution/ui/RiivolutionBootActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/riivolution/ui/RiivolutionBootActivity.java @@ -17,6 +17,7 @@ import org.dolphinemu.dolphinemu.activities.EmulationActivity; import org.dolphinemu.dolphinemu.features.riivolution.model.RiivolutionPatches; import org.dolphinemu.dolphinemu.features.settings.model.StringSetting; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; +import org.dolphinemu.dolphinemu.utils.ThemeHelper; public class RiivolutionBootActivity extends AppCompatActivity { @@ -41,6 +42,8 @@ public class RiivolutionBootActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { + ThemeHelper.setTheme(this); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_riivolution_boot); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java index a06c4f8d61..8685c20a90 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java @@ -33,6 +33,7 @@ public enum IntSetting implements AbstractIntSetting MAIN_CONTROL_OPACITY(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "ControlOpacity", 65), MAIN_EMULATION_ORIENTATION(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "EmulationOrientation", ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE), + MAIN_INTERFACE_THEME(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "InterfaceTheme", 0), MAIN_LAST_PLATFORM_TAB(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "LastPlatformTab", 0), MAIN_MOTION_CONTROLS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "MotionControls", 1), MAIN_IR_MODE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "IRMode", diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java index 8f3d587b3f..1139688418 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java @@ -2,7 +2,6 @@ package org.dolphinemu.dolphinemu.features.settings.ui; -import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -15,13 +14,18 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModelProvider; +import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; +import org.dolphinemu.dolphinemu.utils.ThemeHelper; import java.util.Set; @@ -34,7 +38,9 @@ public final class SettingsActivity extends AppCompatActivity implements Setting private static final String FRAGMENT_TAG = "settings"; private SettingsActivityPresenter mPresenter; - private ProgressDialog dialog; + private AlertDialog dialog; + + private CollapsingToolbarLayout mToolbarLayout; public static void launch(Context context, MenuTag menuTag, String gameId, int revision, boolean isWii) @@ -58,6 +64,8 @@ public final class SettingsActivity extends AppCompatActivity implements Setting @Override protected void onCreate(Bundle savedInstanceState) { + ThemeHelper.setTheme(this); + super.onCreate(savedInstanceState); // If we came here from the game list, we don't want to rescan when returning to the game list. @@ -80,7 +88,9 @@ public final class SettingsActivity extends AppCompatActivity implements Setting mPresenter = new SettingsActivityPresenter(this, getSettings()); mPresenter.onCreate(savedInstanceState, menuTag, gameID, revision, isWii, this); - // show up button + Toolbar tb = findViewById(R.id.toolbar_settings); + mToolbarLayout = findViewById(R.id.toolbar_settings_layout); + setSupportActionBar(tb); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } @@ -211,11 +221,12 @@ public final class SettingsActivity extends AppCompatActivity implements Setting { if (dialog == null) { - dialog = new ProgressDialog(this); - dialog.setMessage(getString(R.string.load_settings)); - dialog.setIndeterminate(true); + dialog = new MaterialAlertDialogBuilder(this) + .setTitle(getString(R.string.load_settings)) + .setView(getLayoutInflater().inflate(R.layout.dialog_indeterminate_progress, null, + false)) + .create(); } - dialog.show(); } @@ -228,7 +239,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting @Override public void showGameIniJunkDeletionQuestion() { - new AlertDialog.Builder(this) + new MaterialAlertDialogBuilder(this) .setTitle(getString(R.string.game_ini_junk_title)) .setMessage(getString(R.string.game_ini_junk_question)) .setPositiveButton(R.string.yes, (dialogInterface, i) -> mPresenter.clearSettings()) @@ -312,4 +323,9 @@ public final class SettingsActivity extends AppCompatActivity implements Setting { return (SettingsFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG); } + + public void setToolbarTitle(String title) + { + mToolbarLayout.setTitle(title); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java index b1b5ec8bd6..da14f5c5cb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivityView.java @@ -108,4 +108,9 @@ public interface SettingsActivityView * Tell the user that there is junk in the game INI and ask if they want to delete the whole file. */ void showGameIniJunkDeletionQuestion(); + + /** + * Accesses the material toolbar layout and changes the title + */ + void setToolbarTitle(String title); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java index 893773dbd0..d8ceb5ba29 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java @@ -10,13 +10,16 @@ import android.provider.DocumentsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.EditText; -import android.widget.SeekBar; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.slider.Slider; +import com.google.android.material.textfield.TextInputEditText; + import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.dialogs.MotionAlertDialog; import org.dolphinemu.dolphinemu.features.settings.model.Settings; @@ -56,7 +59,7 @@ import java.io.RandomAccessFile; import java.util.ArrayList; public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder> - implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener + implements DialogInterface.OnClickListener, Slider.OnChangeListener { private final SettingsFragmentView mView; private final Context mContext; @@ -64,7 +67,6 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde private SettingsItem mClickedItem; private int mClickedPosition; - private int mSeekbarMinValue; private int mSeekbarProgress; private AlertDialog mDialog; @@ -204,28 +206,27 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde { LayoutInflater inflater = LayoutInflater.from(mContext); - AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.DolphinDialogBase); View dialogView = inflater.inflate(R.layout.dialog_input_string, null); - EditText input = (EditText) dialogView.findViewById(R.id.input); + TextInputEditText input = dialogView.findViewById(R.id.input); input.setText(item.getSelectedValue(getSettings())); - builder.setView(dialogView); - builder.setMessage(item.getDescription()); - builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> - { - String editTextInput = input.getText().toString(); - - if (!item.getSelectedValue(mView.getSettings()).equals(editTextInput)) - { - notifyItemChanged(position); - mView.onSettingChanged(); - } + mDialog = new MaterialAlertDialogBuilder(mView.getActivity()) + .setView(dialogView) + .setMessage(item.getDescription()) + .setPositiveButton(R.string.ok, (dialogInterface, i) -> + { + String editTextInput = input.getText().toString(); - item.setSelectedValue(mView.getSettings(), editTextInput); - }); - builder.setNegativeButton(R.string.cancel, null); + if (!item.getSelectedValue(mView.getSettings()).equals(editTextInput)) + { + notifyItemChanged(position); + mView.onSettingChanged(); + } - mDialog = builder.show(); + item.setSelectedValue(mView.getSettings(), editTextInput); + }) + .setNegativeButton(R.string.cancel, null) + .show(); } public void onSingleChoiceClick(SingleChoiceSetting item, int position) @@ -235,12 +236,10 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde int value = getSelectionForSingleChoiceValue(item); - AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity()); - - builder.setTitle(item.getName()); - builder.setSingleChoiceItems(item.getChoicesId(), value, this); - - mDialog = builder.show(); + mDialog = new MaterialAlertDialogBuilder(mView.getActivity()) + .setTitle(item.getName()) + .setSingleChoiceItems(item.getChoicesId(), value, this) + .show(); } public void onStringSingleChoiceClick(StringSingleChoiceSetting item, int position) @@ -248,13 +247,11 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde mClickedItem = item; mClickedPosition = position; - AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity()); - - builder.setTitle(item.getName()); - builder.setSingleChoiceItems(item.getChoices(), item.getSelectedValueIndex(getSettings()), - this); - - mDialog = builder.show(); + mDialog = new MaterialAlertDialogBuilder(mView.getActivity()) + .setTitle(item.getName()) + .setSingleChoiceItems(item.getChoices(), item.getSelectedValueIndex(getSettings()), + this) + .show(); } public void onSingleChoiceDynamicDescriptionsClick(SingleChoiceSettingDynamicDescriptions item, @@ -265,29 +262,26 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde int value = getSelectionForSingleChoiceDynamicDescriptionsValue(item); - AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity()); - - builder.setTitle(item.getName()); - builder.setSingleChoiceItems(item.getChoicesId(), value, this); - - mDialog = builder.show(); + mDialog = new MaterialAlertDialogBuilder(mView.getActivity()) + .setTitle(item.getName()) + .setSingleChoiceItems(item.getChoicesId(), value, this) + .show(); } public void onSliderClick(SliderSetting item, int position) { mClickedItem = item; mClickedPosition = position; - mSeekbarMinValue = item.getMin(); mSeekbarProgress = item.getSelectedValue(getSettings()); - AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity()); LayoutInflater inflater = LayoutInflater.from(mView.getActivity()); - View view = inflater.inflate(R.layout.dialog_seekbar, null); + View view = inflater.inflate(R.layout.dialog_slider, null); - builder.setTitle(item.getName()); - builder.setView(view); - builder.setPositiveButton(R.string.ok, this); - mDialog = builder.show(); + mDialog = new MaterialAlertDialogBuilder(mView.getActivity()) + .setTitle(item.getName()) + .setView(view) + .setPositiveButton(R.string.ok, this) + .show(); mTextSliderValue = view.findViewById(R.id.text_value); mTextSliderValue.setText(String.valueOf(mSeekbarProgress)); @@ -295,16 +289,12 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde TextView units = view.findViewById(R.id.text_units); units.setText(item.getUnits()); - SeekBar seekbar = view.findViewById(R.id.seekbar); - - // TODO: Once we require API 26, uncomment this line and remove the mSeekbarMinValue variable - //seekbar.setMin(item.getMin()); - - seekbar.setMax(item.getMax() - mSeekbarMinValue); - seekbar.setProgress(mSeekbarProgress - mSeekbarMinValue); - seekbar.setKeyProgressIncrement(5); - - seekbar.setOnSeekBarChangeListener(this); + Slider slider = view.findViewById(R.id.slider); + slider.setValueFrom(item.getMin()); + slider.setValueTo(item.getMax()); + slider.setValue(mSeekbarProgress); + slider.setStepSize(1); + slider.addOnChangeListener(this); } public void onSubmenuClick(SubmenuSetting item) @@ -339,10 +329,10 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde if (!PermissionsHandler.isExternalStorageLegacy()) { - AlertDialog.Builder builder = new AlertDialog.Builder(mContext); - builder.setMessage(R.string.path_not_changeable_scoped_storage); - builder.setPositiveButton(R.string.ok, (dialog, i) -> dialog.dismiss()); - builder.show(); + new MaterialAlertDialogBuilder(mContext) + .setMessage(R.string.path_not_changeable_scoped_storage) + .setPositiveButton(R.string.ok, (dialog, i) -> dialog.dismiss()) + .show(); } else { @@ -509,22 +499,12 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde } @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) + public void onValueChange(@NonNull Slider slider, float progress, boolean fromUser) { - mSeekbarProgress = progress + mSeekbarMinValue; + mSeekbarProgress = (int) progress; mTextSliderValue.setText(String.valueOf(mSeekbarProgress)); } - @Override - public void onStartTrackingTouch(SeekBar seekBar) - { - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) - { - } - private int getValueForSingleChoiceSelection(SingleChoiceSetting item, int which) { int valuesId = item.getValuesId(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java index dfb92caf84..86a5650de5 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java @@ -127,7 +127,7 @@ public final class SettingsFragment extends Fragment implements SettingsFragment if (titles.containsKey(menuTag)) { - getActivity().setTitle(titles.get(menuTag)); + mActivity.setToolbarTitle(getString(titles.get(menuTag))); } LinearLayoutManager manager = new LinearLayoutManager(getActivity()); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index 38976684d6..9a95b83afb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -43,6 +43,7 @@ import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; import org.dolphinemu.dolphinemu.utils.BooleanSupplier; import org.dolphinemu.dolphinemu.utils.EGLHelper; +import org.dolphinemu.dolphinemu.utils.ThemeHelper; import org.dolphinemu.dolphinemu.utils.ThreadUtil; import org.dolphinemu.dolphinemu.utils.WiiUtils; @@ -323,6 +324,50 @@ public final class SettingsFragmentPresenter R.string.download_game_covers, 0)); sl.add(new CheckBoxSetting(mContext, BooleanSetting.MAIN_SHOW_GAME_TITLES, R.string.show_titles_in_game_list, R.string.show_titles_in_game_list_description)); + + AbstractIntSetting appTheme = new AbstractIntSetting() + { + @Override public boolean isOverridden(Settings settings) + { + return IntSetting.MAIN_INTERFACE_THEME.isOverridden(settings); + } + + @Override public boolean isRuntimeEditable() + { + // This only affects app UI + return true; + } + + @Override public boolean delete(Settings settings) + { + ThemeHelper.deleteThemeKey(mView.getActivity()); + return IntSetting.MAIN_INTERFACE_THEME.delete(settings); + } + + @Override public int getInt(Settings settings) + { + return IntSetting.MAIN_INTERFACE_THEME.getInt(settings); + } + + @Override public void setInt(Settings settings, int newValue) + { + ThemeHelper.saveTheme(mView.getActivity(), newValue); + IntSetting.MAIN_INTERFACE_THEME.setInt(settings, newValue); + mView.getActivity().recreate(); + } + }; + + // If a Monet theme is run on a device below API 31, the app will crash + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) + { + sl.add(new SingleChoiceSetting(mContext, appTheme, R.string.change_theme, 0, + R.array.themeEntriesA12, R.array.themeValuesA12)); + } + else + { + sl.add(new SingleChoiceSetting(mContext, appTheme, R.string.change_theme, 0, + R.array.themeEntries, R.array.themeValues)); + } } private void addAudioSettings(ArrayList<SettingsItem> sl) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/HeaderHyperLinkViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/HeaderHyperLinkViewHolder.java index 8a30e34fff..c3abf79c24 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/HeaderHyperLinkViewHolder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/HeaderHyperLinkViewHolder.java @@ -6,7 +6,7 @@ import android.content.Context; import android.text.method.LinkMovementMethod; import android.view.View; -import androidx.core.content.ContextCompat; +import com.google.android.material.color.MaterialColors; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; @@ -27,7 +27,8 @@ public final class HeaderHyperLinkViewHolder extends HeaderViewHolder public void bind(SettingsItem item) { super.bind(item); + mHeaderName.setMovementMethod(LinkMovementMethod.getInstance()); - mHeaderName.setLinkTextColor(ContextCompat.getColor(mContext, R.color.dolphin_blue_secondary)); + mHeaderName.setLinkTextColor(MaterialColors.getColor(itemView, R.attr.colorTertiary)); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.java index cecc88fd21..8d7966ab14 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/RunRunnableViewHolder.java @@ -8,7 +8,8 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; + +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.settings.model.view.RunRunnable; @@ -54,19 +55,16 @@ public final class RunRunnableViewHolder extends SettingViewHolder if (alertTextID > 0) { - AlertDialog.Builder builder = new AlertDialog.Builder(mContext) + new MaterialAlertDialogBuilder(mContext) .setTitle(mItem.getName()) - .setMessage(alertTextID); - - builder + .setMessage(alertTextID) .setPositiveButton(R.string.ok, (dialog, whichButton) -> { runRunnable(); dialog.dismiss(); }) - .setNegativeButton(R.string.cancel, (dialog, whichButton) -> dialog.dismiss()); - - builder.show(); + .setNegativeButton(R.string.cancel, (dialog, whichButton) -> dialog.dismiss()) + .show(); } else { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SettingViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SettingViewHolder.java index a82a7cdb0a..634c75c223 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SettingViewHolder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SettingViewHolder.java @@ -10,9 +10,10 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.DolphinApplication; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; @@ -96,10 +97,8 @@ public abstract class SettingViewHolder extends RecyclerView.ViewHolder Context context = clicked.getContext(); - AlertDialog.Builder builder = new AlertDialog.Builder(context) - .setMessage(R.string.setting_clear_confirm); - - builder + new MaterialAlertDialogBuilder(context) + .setMessage(R.string.setting_clear_confirm) .setPositiveButton(R.string.ok, (dialog, whichButton) -> { getAdapter().clearSetting(item, getBindingAdapterPosition()); @@ -107,9 +106,8 @@ public abstract class SettingViewHolder extends RecyclerView.ViewHolder Toast.makeText(context, R.string.setting_cleared, Toast.LENGTH_SHORT).show(); dialog.dismiss(); }) - .setNegativeButton(R.string.cancel, (dialog, whichButton) -> dialog.dismiss()); - - builder.show(); + .setNegativeButton(R.string.cancel, (dialog, whichButton) -> dialog.dismiss()) + .show(); return true; } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateRegionSelectDialogFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateRegionSelectDialogFragment.java index d5bc94b11c..7184c7ba39 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateRegionSelectDialogFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateRegionSelectDialogFragment.java @@ -7,10 +7,11 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; import androidx.lifecycle.ViewModelProvider; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.R; public class OnlineUpdateRegionSelectDialogFragment extends DialogFragment @@ -23,7 +24,7 @@ public class OnlineUpdateRegionSelectDialogFragment extends DialogFragment R.string.japan), getString(R.string.korea), getString(R.string.united_states)}; int checkedItem = -1; - return new AlertDialog.Builder(requireContext()) + return new MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.region_select_title) .setSingleChoiceItems(items, checkedItem, (dialog, which) -> { @@ -35,8 +36,6 @@ public class OnlineUpdateRegionSelectDialogFragment extends DialogFragment new SystemUpdateProgressBarDialogFragment(); progressBarFragment .show(getParentFragmentManager(), "OnlineUpdateProgressBarDialogFragment"); - progressBarFragment.setCancelable(false); - dismiss(); }) .create(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemMenuNotInstalledDialogFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemMenuNotInstalledDialogFragment.java index 9acf238042..671750e1d6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemMenuNotInstalledDialogFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemMenuNotInstalledDialogFragment.java @@ -5,10 +5,11 @@ package org.dolphinemu.dolphinemu.features.sysupdate.ui; import android.app.Dialog; import android.os.Bundle; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentManager; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.R; public class SystemMenuNotInstalledDialogFragment extends DialogFragment @@ -16,7 +17,7 @@ public class SystemMenuNotInstalledDialogFragment extends DialogFragment @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - return new AlertDialog.Builder(requireContext()) + return new MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.system_menu_not_installed_title) .setMessage(R.string.system_menu_not_installed_message) .setPositiveButton(R.string.yes, (dialog, which) -> @@ -27,10 +28,7 @@ public class SystemMenuNotInstalledDialogFragment extends DialogFragment dialogFragment.show(fragmentManager, "OnlineUpdateRegionSelectDialogFragment"); dismiss(); }) - .setNegativeButton(R.string.no, (dialog, which) -> - { - dismiss(); - }) + .setNegativeButton(R.string.no, (dialog, which) -> dismiss()) .create(); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java index 2cb520552a..152e1aca64 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java @@ -3,15 +3,20 @@ package org.dolphinemu.dolphinemu.features.sysupdate.ui; import android.app.Dialog; -import android.app.ProgressDialog; import android.content.pm.ActivityInfo; import android.os.Bundle; +import android.view.View; +import android.widget.Button; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; import androidx.lifecycle.ViewModelProvider; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.progressindicator.LinearProgressIndicator; + import org.dolphinemu.dolphinemu.R; public class SystemUpdateProgressBarDialogFragment extends DialogFragment @@ -28,28 +33,20 @@ public class SystemUpdateProgressBarDialogFragment extends DialogFragment SystemUpdateViewModel viewModel = new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class); - ProgressDialog progressDialog = new ProgressDialog(requireContext()); - progressDialog.setTitle(getString(R.string.updating)); + View dialogView = getLayoutInflater().inflate(R.layout.dialog_progress, null, false); + LinearProgressIndicator progressBar = dialogView.findViewById(R.id.update_progress); + // We need to set the message to something here, otherwise the text will not appear when we set it later. - progressDialog.setMessage(""); - progressDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.cancel), (dialog, i) -> - { - }); - progressDialog.setOnShowListener((dialogInterface) -> - { - // By default, the ProgressDialog will immediately dismiss itself upon a button being pressed. - // Setting the OnClickListener again after the dialog is shown overrides this behavior. - progressDialog.getButton(Dialog.BUTTON_NEGATIVE).setOnClickListener((view) -> - { - viewModel.setCanceled(); - }); - }); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + AlertDialog progressDialog = new MaterialAlertDialogBuilder(requireContext()) + .setTitle(getString(R.string.updating)) + .setMessage("") + .setNegativeButton(getString(R.string.cancel), null) + .setView(dialogView) + .setCancelable(false) + .create(); - viewModel.getProgressData().observe(this, (@Nullable Integer progress) -> - { - progressDialog.setProgress(progress.intValue()); - }); + viewModel.getProgressData() + .observe(this, (@Nullable Integer progress) -> progressBar.setProgress(progress)); viewModel.getTotalData().observe(this, (@Nullable Integer total) -> { @@ -58,13 +55,11 @@ public class SystemUpdateProgressBarDialogFragment extends DialogFragment return; } - progressDialog.setMax(total.intValue()); + progressBar.setMax(total); }); - viewModel.getTitleIdData().observe(this, (@Nullable Long titleId) -> - { - progressDialog.setMessage(getString(R.string.updating_message, titleId)); - }); + viewModel.getTitleIdData().observe(this, (@Nullable Long titleId) -> progressDialog.setMessage( + getString(R.string.updating_message, titleId))); viewModel.getResultData().observe(this, (@Nullable Integer result) -> { @@ -88,4 +83,17 @@ public class SystemUpdateProgressBarDialogFragment extends DialogFragment } return progressDialog; } + + // By default, the ProgressDialog will immediately dismiss itself upon a button being pressed. + // Setting the OnClickListener again after the dialog is shown overrides this behavior. + @Override + public void onResume() + { + super.onResume(); + AlertDialog alertDialog = (AlertDialog) getDialog(); + SystemUpdateViewModel viewModel = + new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class); + Button negativeButton = alertDialog.getButton(Dialog.BUTTON_NEGATIVE); + negativeButton.setOnClickListener(v -> viewModel.setCanceled()); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateResultFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateResultFragment.java index 292aadbd7e..a8e638ad90 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateResultFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateResultFragment.java @@ -6,10 +6,11 @@ import android.app.Dialog; import android.os.Bundle; import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; import androidx.lifecycle.ViewModelProvider; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.utils.WiiUtils; @@ -88,13 +89,10 @@ public class SystemUpdateResultFragment extends DialogFragment throw new IllegalStateException("Unexpected value: " + mResult); } - return new AlertDialog.Builder(requireContext()) + return new MaterialAlertDialogBuilder(requireContext()) .setTitle(title) .setMessage(message) - .setPositiveButton(R.string.ok, (dialog, which) -> - { - dismiss(); - }) + .setPositiveButton(R.string.ok, (dialog, which) -> dismiss()) .create(); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/ConvertFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/ConvertFragment.java index dbae87c437..0225f118a3 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/ConvertFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/ConvertFragment.java @@ -3,7 +3,6 @@ package org.dolphinemu.dolphinemu.fragments; import android.app.Activity; -import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.os.Build; @@ -22,6 +21,9 @@ import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.progressindicator.LinearProgressIndicator; + import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.model.GameFile; @@ -361,12 +363,11 @@ public class ConvertFragment extends Fragment implements View.OnClickListener return () -> { Context context = requireContext(); - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setMessage(warning_text) + new MaterialAlertDialogBuilder(context) + .setMessage(warning_text) .setPositiveButton(R.string.yes, (dialog, i) -> action.run()) - .setNegativeButton(R.string.no, null); - AlertDialog alert = builder.create(); - alert.show(); + .setNegativeButton(R.string.no, null) + .show(); }; } @@ -422,20 +423,16 @@ public class ConvertFragment extends Fragment implements View.OnClickListener mCanceled = false; - // For some reason, setting R.style.DolphinDialogBase as the theme here gives us white text - // on a white background when the device is set to dark mode, so let's not set a theme. - ProgressDialog progressDialog = new ProgressDialog(context); - - progressDialog.setTitle(R.string.convert_converting); - - progressDialog.setIndeterminate(false); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setMax(PROGRESS_RESOLUTION); + View dialogView = getLayoutInflater().inflate(R.layout.dialog_progress, null, false); + LinearProgressIndicator progressBar = dialogView.findViewById(R.id.update_progress); + progressBar.setMax(PROGRESS_RESOLUTION); - progressDialog.setCancelable(true); - progressDialog.setOnCancelListener((dialog) -> mCanceled = true); - - progressDialog.show(); + AlertDialog progressDialog = new MaterialAlertDialogBuilder(context) + .setTitle(R.string.convert_converting) + .setOnCancelListener((dialog) -> mCanceled = true) + .setNegativeButton(getString(R.string.cancel), (dialog, i) -> dialog.dismiss()) + .setView(dialogView) + .show(); mThread = new Thread(() -> { @@ -447,9 +444,8 @@ public class ConvertFragment extends Fragment implements View.OnClickListener requireActivity().runOnUiThread(() -> { progressDialog.setMessage(text); - progressDialog.setProgress((int) (completion * PROGRESS_RESOLUTION)); + progressBar.setProgress((int) (completion * PROGRESS_RESOLUTION)); }); - return !mCanceled; }); @@ -459,7 +455,7 @@ public class ConvertFragment extends Fragment implements View.OnClickListener { progressDialog.dismiss(); - AlertDialog.Builder builder = new AlertDialog.Builder(context); + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context); if (success) { builder.setMessage(R.string.convert_success_message) @@ -475,8 +471,7 @@ public class ConvertFragment extends Fragment implements View.OnClickListener builder.setMessage(R.string.convert_failure_message) .setPositiveButton(R.string.ok, (dialog, i) -> dialog.dismiss()); } - AlertDialog alert = builder.create(); - alert.show(); + builder.show(); }); } }); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index 4954a4cf90..7f472632ce 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -37,6 +37,7 @@ import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; import org.dolphinemu.dolphinemu.utils.PermissionsHandler; import org.dolphinemu.dolphinemu.utils.StartupHandler; +import org.dolphinemu.dolphinemu.utils.ThemeHelper; import org.dolphinemu.dolphinemu.utils.WiiUtils; /** @@ -44,13 +45,15 @@ import org.dolphinemu.dolphinemu.utils.WiiUtils; * individually display a grid of available games for each Fragment, in a tabbed layout. */ public final class MainActivity extends AppCompatActivity - implements MainView, SwipeRefreshLayout.OnRefreshListener + implements MainView, SwipeRefreshLayout.OnRefreshListener, ThemeProvider { private ViewPager mViewPager; private Toolbar mToolbar; private TabLayout mTabLayout; private FloatingActionButton mFab; + private int mThemeId; + private final MainPresenter mPresenter = new MainPresenter(this, this); @Override @@ -60,6 +63,8 @@ public final class MainActivity extends AppCompatActivity splashScreen.setKeepOnScreenCondition( () -> !DirectoryInitialization.areDolphinDirectoriesReady()); + ThemeHelper.setTheme(this); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -74,7 +79,10 @@ public final class MainActivity extends AppCompatActivity // Stuff in this block only happens when this activity is newly created (i.e. not a rotation) if (savedInstanceState == null) + { StartupHandler.HandleInit(this); + new AfterDirectoryInitializationRunner().runWithLifecycle(this, this::checkTheme); + } if (!DirectoryInitialization.isWaitingForWriteAccess(this)) { @@ -86,6 +94,8 @@ public final class MainActivity extends AppCompatActivity @Override protected void onResume() { + ThemeHelper.setCorrectTheme(this); + super.onResume(); if (DirectoryInitialization.shouldStart(this)) @@ -355,4 +365,22 @@ public final class MainActivity extends AppCompatActivity showGames(); GameFileCacheManager.startLoad(this); } + + @Override + public void setTheme(int themeId) + { + super.setTheme(themeId); + this.mThemeId = themeId; + } + + @Override + public int getThemeId() + { + return mThemeId; + } + + private void checkTheme() + { + ThemeHelper.setCorrectTheme(this); + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java index b34ffff66c..382dbc274d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java @@ -7,11 +7,12 @@ import android.content.Intent; import android.net.Uri; import androidx.activity.ComponentActivity; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.BuildConfig; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.EmulationActivity; @@ -171,11 +172,12 @@ public final class MainPresenter if (Arrays.stream(childNames).noneMatch((name) -> FileBrowserHelper.GAME_EXTENSIONS.contains( FileBrowserHelper.getExtension(name, false)))) { - AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); - builder.setMessage(mActivity.getString(R.string.wrong_file_extension_in_directory, - FileBrowserHelper.setToSortedDelimitedString(FileBrowserHelper.GAME_EXTENSIONS))); - builder.setPositiveButton(R.string.ok, null); - builder.show(); + new MaterialAlertDialogBuilder(mActivity) + .setMessage(mActivity.getString(R.string.wrong_file_extension_in_directory, + FileBrowserHelper.setToSortedDelimitedString( + FileBrowserHelper.GAME_EXTENSIONS))) + .setPositiveButton(R.string.ok, null) + .show(); } ContentResolver contentResolver = mActivity.getContentResolver(); @@ -209,13 +211,12 @@ public final class MainPresenter { mActivity.runOnUiThread(() -> { - AlertDialog.Builder builder = - new AlertDialog.Builder(mActivity); - builder.setMessage(R.string.wii_save_exists); - builder.setCancelable(false); - builder.setPositiveButton(R.string.yes, (dialog, i) -> canOverwriteFuture.complete(true)); - builder.setNegativeButton(R.string.no, (dialog, i) -> canOverwriteFuture.complete(false)); - builder.show(); + new MaterialAlertDialogBuilder(mActivity) + .setMessage(R.string.wii_save_exists) + .setCancelable(false) + .setPositiveButton(R.string.yes, (dialog, i) -> canOverwriteFuture.complete(true)) + .setNegativeButton(R.string.no, (dialog, i) -> canOverwriteFuture.complete(false)) + .show(); }); try @@ -255,26 +256,23 @@ public final class MainPresenter public void importNANDBin(String path) { - AlertDialog.Builder builder = - new AlertDialog.Builder(mActivity); - - builder.setMessage(R.string.nand_import_warning); - builder.setNegativeButton(R.string.no, (dialog, i) -> dialog.dismiss()); - builder.setPositiveButton(R.string.yes, (dialog, i) -> - { - dialog.dismiss(); - - ThreadUtil.runOnThreadAndShowResult(mActivity, R.string.import_in_progress, - R.string.do_not_close_app, () -> - { - // ImportNANDBin unfortunately doesn't provide any result value... - // It does however show a panic alert if something goes wrong. - WiiUtils.importNANDBin(path); - return null; - }); - }); - - builder.show(); + new MaterialAlertDialogBuilder(mActivity) + .setMessage(R.string.nand_import_warning) + .setNegativeButton(R.string.no, (dialog, i) -> dialog.dismiss()) + .setPositiveButton(R.string.yes, (dialog, i) -> + { + dialog.dismiss(); + + ThreadUtil.runOnThreadAndShowResult(mActivity, R.string.import_in_progress, + R.string.do_not_close_app, () -> + { + // ImportNANDBin unfortunately doesn't provide any result value... + // It does however show a panic alert if something goes wrong. + WiiUtils.importNANDBin(path); + return null; + }); + }) + .show(); } public static void skipRescanningLibrary() diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/ThemeProvider.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/ThemeProvider.java new file mode 100644 index 0000000000..1be137f33e --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/ThemeProvider.java @@ -0,0 +1,9 @@ +package org.dolphinemu.dolphinemu.ui.main; + +public interface ThemeProvider +{ + /** + * Provides theme ID by overriding an activity's 'setTheme' method and returning that result + */ + int getThemeId(); +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java index 8e9c96442c..4b2b22de33 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java @@ -6,7 +6,6 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; -import android.util.TypedValue; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; @@ -121,10 +120,6 @@ public final class TvMainActivity extends FragmentActivity { mSwipeRefresh = findViewById(R.id.swipe_refresh); - TypedValue typedValue = new TypedValue(); - getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); - mSwipeRefresh.setColorSchemeColors(typedValue.data); - mSwipeRefresh.setOnRefreshListener(this); setRefreshing(GameFileCacheManager.isLoadingOrRescanning()); @@ -138,7 +133,7 @@ public final class TvMainActivity extends FragmentActivity // Set display parameters for the BrowseFragment mBrowseFragment.setHeadersState(BrowseSupportFragment.HEADERS_ENABLED); - mBrowseFragment.setBrandColor(ContextCompat.getColor(this, R.color.dolphin_blue_secondary)); + mBrowseFragment.setBrandColor(ContextCompat.getColor(this, R.color.dolphin_blue)); buildRowsAdapter(); mBrowseFragment.setOnItemViewClickedListener( @@ -364,7 +359,7 @@ public final class TvMainActivity extends FragmentActivity ArrayObjectAdapter rowItems = new ArrayObjectAdapter(new SettingsRowPresenter()); rowItems.add(new TvSettingsItem(R.id.menu_settings, - R.drawable.ic_settings, + R.drawable.ic_settings_tv, R.string.grid_menu_settings)); rowItems.add(new TvSettingsItem(R.id.button_add_directory, @@ -372,31 +367,31 @@ public final class TvMainActivity extends FragmentActivity R.string.add_directory_title)); rowItems.add(new TvSettingsItem(R.id.menu_refresh, - R.drawable.ic_refresh, + R.drawable.ic_refresh_tv, R.string.grid_menu_refresh)); rowItems.add(new TvSettingsItem(R.id.menu_open_file, - R.drawable.ic_play, + R.drawable.ic_play_tv, R.string.grid_menu_open_file)); rowItems.add(new TvSettingsItem(R.id.menu_install_wad, - R.drawable.ic_folder, + R.drawable.ic_folder_tv, R.string.grid_menu_install_wad)); rowItems.add(new TvSettingsItem(R.id.menu_load_wii_system_menu, - R.drawable.ic_folder, + R.drawable.ic_folder_tv, R.string.grid_menu_load_wii_system_menu)); rowItems.add(new TvSettingsItem(R.id.menu_import_wii_save, - R.drawable.ic_folder, + R.drawable.ic_folder_tv, R.string.grid_menu_import_wii_save)); rowItems.add(new TvSettingsItem(R.id.menu_import_nand_backup, - R.drawable.ic_folder, + R.drawable.ic_folder_tv, R.string.grid_menu_import_nand_backup)); rowItems.add(new TvSettingsItem(R.id.menu_online_system_update, - R.drawable.ic_folder, + R.drawable.ic_folder_tv, R.string.grid_menu_online_system_update)); // Create a header for this row. diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java index feb08adfcd..8cebf28645 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java @@ -3,7 +3,6 @@ package org.dolphinemu.dolphinemu.ui.platform; import android.os.Bundle; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -15,6 +14,8 @@ import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import com.google.android.material.color.MaterialColors; + import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.adapters.GameAdapter; import org.dolphinemu.dolphinemu.services.GameFileCacheManager; @@ -62,9 +63,10 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(), columns); mAdapter = new GameAdapter(); - TypedValue typedValue = new TypedValue(); - requireActivity().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); - mSwipeRefresh.setColorSchemeColors(typedValue.data); + // Set theme color to the refresh animation's background + mSwipeRefresh.setProgressBackgroundColorSchemeColor( + MaterialColors.getColor(mSwipeRefresh, R.attr.colorSurfaceVariant)); + mSwipeRefresh.setColorSchemeColors(MaterialColors.getColor(mSwipeRefresh, R.attr.colorPrimary)); mSwipeRefresh.setOnRefreshListener(mOnRefreshListener); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AlertDialogItemsBuilder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AlertDialogItemsBuilder.java index 8a357ff7a2..503e543d72 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AlertDialogItemsBuilder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AlertDialogItemsBuilder.java @@ -5,7 +5,7 @@ package org.dolphinemu.dolphinemu.utils; import android.content.Context; import android.content.DialogInterface.OnClickListener; -import androidx.appcompat.app.AlertDialog; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import java.util.ArrayList; @@ -33,7 +33,7 @@ public class AlertDialogItemsBuilder mListeners.add(listener); } - public void applyToBuilder(AlertDialog.Builder builder) + public void applyToBuilder(MaterialAlertDialogBuilder builder) { CharSequence[] labels = new CharSequence[mLabels.size()]; labels = mLabels.toArray(labels); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java index a39a52267b..961620213a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java @@ -6,10 +6,10 @@ import android.content.Context; import android.os.Build; import androidx.annotation.Keep; -import androidx.appcompat.app.AlertDialog; import com.android.volley.Request; import com.android.volley.toolbox.StringRequest; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.dolphinemu.dolphinemu.DolphinApplication; import org.dolphinemu.dolphinemu.R; @@ -36,17 +36,11 @@ public class Analytics private static void showMessage(Context context) { - new AlertDialog.Builder(context) + new MaterialAlertDialogBuilder(context) .setTitle(context.getString(R.string.analytics)) .setMessage(context.getString(R.string.analytics_desc)) - .setPositiveButton(R.string.yes, (dialogInterface, i) -> - { - firstAnalyticsAdd(true); - }) - .setNegativeButton(R.string.no, (dialogInterface, i) -> - { - firstAnalyticsAdd(false); - }) + .setPositiveButton(R.string.yes, (dialogInterface, i) -> firstAnalyticsAdd(true)) + .setNegativeButton(R.string.no, (dialogInterface, i) -> firstAnalyticsAdd(false)) .show(); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java index 6f8ec2c805..7810b5c607 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java @@ -20,6 +20,7 @@ import androidx.lifecycle.MutableLiveData; import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.EmulationActivity; +import org.dolphinemu.dolphinemu.features.settings.model.IntSetting; import java.io.File; import java.io.FileOutputStream; @@ -77,6 +78,15 @@ public final class DirectoryInitialization areDirectoriesAvailable = true; + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + if (IntSetting.MAIN_INTERFACE_THEME.getIntGlobal() != + preferences.getInt(ThemeHelper.CURRENT_THEME, ThemeHelper.DEFAULT)) + { + preferences.edit() + .putInt(ThemeHelper.CURRENT_THEME, IntSetting.MAIN_INTERFACE_THEME.getIntGlobal()) + .apply(); + } + if (wiimoteIniWritten) { // This has to be done after calling NativeLibrary.Initialize(), diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/FileBrowserHelper.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/FileBrowserHelper.java index 6924fd65ea..6b9b0d7614 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/FileBrowserHelper.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/FileBrowserHelper.java @@ -8,9 +8,9 @@ import android.net.Uri; import android.os.Environment; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.FragmentActivity; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.nononsenseapps.filepicker.FilePickerActivity; import com.nononsenseapps.filepicker.Utils; @@ -119,7 +119,7 @@ public final class FileBrowserHelper setToSortedDelimitedString(validExtensions)); } - new AlertDialog.Builder(context) + new MaterialAlertDialogBuilder(context) .setMessage(message) .setPositiveButton(R.string.yes, (dialogInterface, i) -> runnable.run()) .setNegativeButton(R.string.no, null) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThemeHelper.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThemeHelper.java new file mode 100644 index 0000000000..5cc4f5b4ec --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThemeHelper.java @@ -0,0 +1,107 @@ +package org.dolphinemu.dolphinemu.utils; + +import android.app.Activity; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Build; +import android.preference.PreferenceManager; + +import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.ui.main.ThemeProvider; + +public class ThemeHelper +{ + public static final String CURRENT_THEME = "current_theme"; + + public static final int DEFAULT = 0; + public static final int MONET = 1; + public static final int MATERIAL_DEFAULT = 2; + public static final int GREEN = 3; + public static final int PINK = 4; + + public static void setTheme(Activity activity) + { + // We have to use shared preferences in addition to Dolphin's settings to guarantee that the + // requested theme id is ready before the onCreate method of any given Activity. + SharedPreferences preferences = + PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext()); + switch (preferences.getInt(CURRENT_THEME, DEFAULT)) + { + case DEFAULT: + activity.setTheme(R.style.Theme_Dolphin_Main); + activity.getWindow() + .setStatusBarColor(activity.getResources().getColor(R.color.dolphin_surface)); + break; + + case MONET: + activity.setTheme(R.style.Theme_Dolphin_Main_MaterialYou); + int currentNightMode = activity.getResources().getConfiguration().uiMode & + Configuration.UI_MODE_NIGHT_MASK; + switch (currentNightMode) + { + case Configuration.UI_MODE_NIGHT_NO: + activity.getWindow().setStatusBarColor( + activity.getResources().getColor(R.color.m3_sys_color_dynamic_light_surface)); + break; + case Configuration.UI_MODE_NIGHT_YES: + activity.getWindow().setStatusBarColor( + activity.getResources().getColor(R.color.m3_sys_color_dynamic_dark_surface)); + break; + } + break; + + case MATERIAL_DEFAULT: + activity.setTheme(R.style.Theme_Dolphin_Main_Material); + activity.getWindow() + .setStatusBarColor(activity.getResources().getColor(R.color.dolphin_surface)); + break; + + case GREEN: + activity.setTheme(R.style.Theme_Dolphin_Main_Green); + activity.getWindow() + .setStatusBarColor(activity.getResources().getColor(R.color.green_surface)); + break; + + case PINK: + activity.setTheme(R.style.Theme_Dolphin_Main_Pink); + activity.getWindow() + .setStatusBarColor(activity.getResources().getColor(R.color.pink_surface)); + break; + } + + // Since the top app bar matches the color of the status bar, devices below API 23 have to get a + // black status bar since their icons do not adapt based on background color + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) + { + activity.getWindow() + .setStatusBarColor(activity.getResources().getColor(android.R.color.black)); + } + } + + public static void saveTheme(Activity activity, int themeValue) + { + SharedPreferences preferences = + PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext()); + preferences.edit().putInt(CURRENT_THEME, themeValue).apply(); + } + + public static void deleteThemeKey(Activity activity) + { + SharedPreferences preferences = + PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext()); + preferences.edit().remove(CURRENT_THEME).apply(); + activity.setTheme(R.style.Theme_Dolphin_Main); + activity.recreate(); + } + + public static void setCorrectTheme(Activity activity) + { + int currentTheme = ((ThemeProvider) activity).getThemeId(); + setTheme(activity); + + if (currentTheme != ((ThemeProvider) activity).getThemeId()) + { + activity.recreate(); + } + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThreadUtil.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThreadUtil.java index 8c2dcb7673..2321c6a5d6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThreadUtil.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThreadUtil.java @@ -10,6 +10,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import org.dolphinemu.dolphinemu.R; import java.util.function.Supplier; @@ -27,12 +29,14 @@ public class ThreadUtil @Nullable DialogInterface.OnDismissListener onResultDismiss) { Resources resources = activity.getResources(); - AlertDialog progressDialog = new AlertDialog.Builder(activity) + AlertDialog progressDialog = new MaterialAlertDialogBuilder(activity) + .setTitle(progressTitle) + .setCancelable(false) .create(); - progressDialog.setTitle(progressTitle); + if (progressMessage != 0) progressDialog.setMessage(resources.getString(progressMessage)); - progressDialog.setCancelable(false); + progressDialog.show(); new Thread(() -> @@ -44,12 +48,11 @@ public class ThreadUtil if (result != null) { - AlertDialog.Builder builder = - new AlertDialog.Builder(activity); - builder.setMessage(result); - builder.setPositiveButton(R.string.ok, (dialog, i) -> dialog.dismiss()); - builder.setOnDismissListener(onResultDismiss); - builder.show(); + new MaterialAlertDialogBuilder(activity) + .setMessage(result) + .setPositiveButton(R.string.ok, (dialog, i) -> dialog.dismiss()) + .setOnDismissListener(onResultDismiss) + .show(); } }); }, resources.getString(progressTitle)).start(); |
