Merge pull request #11605 from JosJuice/android-mappings-button

Android: Add a button for accessing controller mappings
This commit is contained in:
Mai 2023-03-02 15:06:47 -05:00 committed by GitHub
commit 6fcec80eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 205 additions and 148 deletions

View File

@ -305,27 +305,15 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
}
@Override
public void onSerialPort1SettingChanged(MenuTag menuTag, int value)
public void onMenuTagAction(@NonNull MenuTag menuTag, int value)
{
mPresenter.onSerialPort1SettingChanged(menuTag, value);
mPresenter.onMenuTagAction(menuTag, value);
}
@Override
public void onGcPadSettingChanged(MenuTag key, int value)
public boolean hasMenuTagActionForValue(@NonNull MenuTag menuTag, int value)
{
mPresenter.onGcPadSettingChanged(key, value);
}
@Override
public void onWiimoteSettingChanged(MenuTag section, int value)
{
mPresenter.onWiimoteSettingChanged(section, value);
}
@Override
public void onExtensionSettingChanged(MenuTag menuTag, int value)
{
mPresenter.onExtensionSettingChanged(menuTag, value);
return mPresenter.hasMenuTagActionForValue(menuTag, value);
}
@Override

View File

@ -5,6 +5,7 @@ package org.dolphinemu.dolphinemu.features.settings.ui;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.core.app.ComponentActivity;
import org.dolphinemu.dolphinemu.R;
@ -128,47 +129,69 @@ public final class SettingsActivityPresenter
return mShouldSave;
}
public void onSerialPort1SettingChanged(MenuTag key, int value)
public void onMenuTagAction(@NonNull MenuTag menuTag, int value)
{
if (value != 0 && value != 255) // Not disabled or dummy
if (menuTag.isSerialPort1Menu())
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_SERIALPORT1_TYPE, value);
mView.showSettingsFragment(key, bundle, true, mGameId);
if (value != 0 && value != 255) // Not disabled or dummy
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_SERIALPORT1_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, mGameId);
}
}
}
public void onGcPadSettingChanged(MenuTag key, int value)
{
if (value != 0) // Not disabled
if (menuTag.isGCPadMenu())
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(key, bundle, true, mGameId);
if (value != 0) // Not disabled
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, mGameId);
}
}
}
public void onWiimoteSettingChanged(MenuTag menuTag, int value)
{
switch (value)
if (menuTag.isWiimoteMenu())
{
case 1:
if (value == 1) // Emulated Wii Remote
{
mView.showSettingsFragment(menuTag, null, true, mGameId);
break;
}
}
case 2:
mView.showToastMessage(mActivity.getString(R.string.make_sure_continuous_scan_enabled));
break;
if (menuTag.isWiimoteExtensionMenu())
{
if (value != 0) // Not disabled
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, mGameId);
}
}
}
public void onExtensionSettingChanged(MenuTag menuTag, int value)
public boolean hasMenuTagActionForValue(@NonNull MenuTag menuTag, int value)
{
if (value != 0) // None
if (menuTag.isSerialPort1Menu())
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, mGameId);
return (value != 0 && value != 255); // Not disabled or dummy
}
if (menuTag.isGCPadMenu())
{
return (value != 0); // Not disabled
}
if (menuTag.isWiimoteMenu())
{
return (value == 1); // Emulated Wii Remote
}
if (menuTag.isWiimoteExtensionMenu())
{
return (value != 0); // Not disabled
}
return false;
}
}

View File

@ -4,6 +4,8 @@ package org.dolphinemu.dolphinemu.features.settings.ui;
import android.os.Bundle;
import androidx.annotation.NonNull;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
/**
@ -59,40 +61,22 @@ public interface SettingsActivityView
void onSettingChanged();
/**
* Called by a containing Fragment to tell the containing Activity that the Serial Port 1 setting
* was modified.
* Called by a containing Fragment to tell the containing Activity that the user wants to open the
* MenuTag associated with a setting.
*
* @param menuTag Identifier for the SerialPort that was modified.
* @param value New setting for the SerialPort.
* @param menuTag The MenuTag of the setting.
* @param value The current value of the setting.
*/
void onSerialPort1SettingChanged(MenuTag menuTag, int value);
void onMenuTagAction(@NonNull MenuTag menuTag, int value);
/**
* Called by a containing Fragment to tell the containing Activity that a GCPad's setting
* was modified.
* Returns whether anything will happen when the user wants to open the MenuTag associated with a
* setting, given the current value of the setting.
*
* @param menuTag Identifier for the GCPad that was modified.
* @param value New setting for the GCPad.
* @param menuTag The MenuTag of the setting.
* @param value The current value of the setting.
*/
void onGcPadSettingChanged(MenuTag menuTag, int value);
/**
* Called by a containing Fragment to tell the containing Activity that a Wiimote's setting
* was modified.
*
* @param menuTag Identifier for Wiimote that was modified.
* @param value New setting for the Wiimote.
*/
void onWiimoteSettingChanged(MenuTag menuTag, int value);
/**
* Called by a containing Fragment to tell the containing Activity that an extension setting
* was modified.
*
* @param menuTag Identifier for the extension that was modified.
* @param value New setting for the extension.
*/
void onExtensionSettingChanged(MenuTag menuTag, int value);
boolean hasMenuTagActionForValue(@NonNull MenuTag menuTag, int value);
/**
* Show loading dialog while loading the settings

View File

@ -467,30 +467,14 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
}
}
private void handleMenuTag(MenuTag menuTag, int value)
public void onMenuTagAction(@NonNull MenuTag menuTag, int value)
{
if (menuTag != null)
{
if (menuTag.isSerialPort1Menu())
{
mView.onSerialPort1SettingChanged(menuTag, value);
}
mView.onMenuTagAction(menuTag, value);
}
if (menuTag.isGCPadMenu())
{
mView.onGcPadSettingChanged(menuTag, value);
}
if (menuTag.isWiimoteMenu())
{
mView.onWiimoteSettingChanged(menuTag, value);
}
if (menuTag.isWiimoteExtensionMenu())
{
mView.onExtensionSettingChanged(menuTag, value);
}
}
public boolean hasMenuTagActionForValue(@NonNull MenuTag menuTag, int value)
{
return mView.hasMenuTagActionForValue(menuTag, value);
}
@Override
@ -504,8 +488,6 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
if (scSetting.getSelectedValue(getSettings()) != value)
mView.onSettingChanged();
handleMenuTag(scSetting.getMenuTag(), value);
scSetting.setSelectedValue(getSettings(), value);
closeDialog();
@ -530,8 +512,6 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
if (!scSetting.getSelectedValue(getSettings()).equals(value))
mView.onSettingChanged();
handleMenuTag(scSetting.getMenuTag(), which);
scSetting.setSelectedValue(getSettings(), value);
closeDialog();

View File

@ -226,27 +226,14 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
}
@Override
public void onSerialPort1SettingChanged(MenuTag menuTag, int value)
public void onMenuTagAction(@NonNull MenuTag menuTag, int value)
{
mActivity.onSerialPort1SettingChanged(menuTag, value);
mActivity.onMenuTagAction(menuTag, value);
}
@Override
public void onGcPadSettingChanged(MenuTag menuTag, int value)
public boolean hasMenuTagActionForValue(@NonNull MenuTag menuTag, int value)
{
mActivity.onGcPadSettingChanged(menuTag, value);
}
@Override
public void onWiimoteSettingChanged(MenuTag menuTag, int value)
{
mActivity.onWiimoteSettingChanged(menuTag, value);
}
@Override
public void onExtensionSettingChanged(MenuTag menuTag, int value)
{
mActivity.onExtensionSettingChanged(menuTag, value);
return mActivity.hasMenuTagActionForValue(menuTag, value);
}
private void setInsets()

View File

@ -2,6 +2,7 @@
package org.dolphinemu.dolphinemu.features.settings.ui;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
@ -72,35 +73,20 @@ public interface SettingsFragmentView
void onSettingChanged();
/**
* Called by a containing Fragment to tell the containing Activity that the Serial Port 1 setting
* was modified.
* Have the fragment tell the containing Activity that the user wants to open the MenuTag
* associated with a setting.
*
* @param menuTag Identifier for the SerialPort that was modified.
* @param value New setting for the SerialPort.
* @param menuTag The MenuTag of the setting.
* @param value The current value of the setting.
*/
void onSerialPort1SettingChanged(MenuTag menuTag, int value);
void onMenuTagAction(@NonNull MenuTag menuTag, int value);
/**
* Have the fragment tell the containing Activity that a GCPad's setting was modified.
* Returns whether anything will happen when the user wants to open the MenuTag associated with a
* setting, given the current value of the setting.
*
* @param menuTag Identifier for the GCPad that was modified.
* @param value New setting for the GCPad.
* @param menuTag The MenuTag of the setting.
* @param value The current value of the setting.
*/
void onGcPadSettingChanged(MenuTag menuTag, int value);
/**
* Have the fragment tell the containing Activity that a Wiimote's setting was modified.
*
* @param menuTag Identifier for Wiimote that was modified.
* @param value New setting for the Wiimote.
*/
void onWiimoteSettingChanged(MenuTag menuTag, int value);
/**
* Have the fragment tell the containing Activity that an extension setting was modified.
*
* @param menuTag Identifier for the extension that was modified.
* @param value New setting for the extension.
*/
void onExtensionSettingChanged(MenuTag menuTag, int value);
boolean hasMenuTagActionForValue(@NonNull MenuTag menuTag, int value);
}

View File

@ -10,12 +10,16 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.dolphinemu.dolphinemu.databinding.ListItemSettingBinding;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.SingleChoiceSettingDynamicDescriptions;
import org.dolphinemu.dolphinemu.features.settings.model.view.StringSingleChoiceSetting;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
import java.util.function.Function;
public final class SingleChoiceViewHolder extends SettingViewHolder
{
private SettingsItem mItem;
@ -35,6 +39,9 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
mBinding.textSettingName.setText(item.getName());
SettingsAdapter adapter = getAdapter();
Settings settings = adapter.getSettings();
if (!TextUtils.isEmpty(item.getDescription()))
{
mBinding.textSettingDescription.setText(item.getDescription());
@ -42,7 +49,7 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
else if (item instanceof SingleChoiceSetting)
{
SingleChoiceSetting setting = (SingleChoiceSetting) item;
int selected = setting.getSelectedValue(getAdapter().getSettings());
int selected = setting.getSelectedValue(settings);
Resources resMgr = mBinding.textSettingDescription.getContext().getResources();
String[] choices = resMgr.getStringArray(setting.getChoicesId());
int[] values = resMgr.getIntArray(setting.getValuesId());
@ -58,7 +65,7 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
{
StringSingleChoiceSetting setting = (StringSingleChoiceSetting) item;
String[] choices = setting.getChoices();
int valueIndex = setting.getSelectedValueIndex(getAdapter().getSettings());
int valueIndex = setting.getSelectedValueIndex(settings);
if (valueIndex != -1)
mBinding.textSettingDescription.setText(choices[valueIndex]);
}
@ -66,7 +73,7 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
{
SingleChoiceSettingDynamicDescriptions setting =
(SingleChoiceSettingDynamicDescriptions) item;
int selected = setting.getSelectedValue(getAdapter().getSettings());
int selected = setting.getSelectedValue(settings);
Resources resMgr = mBinding.textSettingDescription.getContext().getResources();
String[] choices = resMgr.getStringArray(setting.getDescriptionChoicesId());
int[] values = resMgr.getIntArray(setting.getDescriptionValuesId());
@ -79,6 +86,36 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
}
}
MenuTag menuTag = null;
Function<Settings, Integer> getSelectedValue = null;
if (item instanceof SingleChoiceSetting)
{
SingleChoiceSetting setting = (SingleChoiceSetting) item;
menuTag = setting.getMenuTag();
getSelectedValue = setting::getSelectedValue;
}
else if (item instanceof StringSingleChoiceSetting)
{
StringSingleChoiceSetting setting = (StringSingleChoiceSetting) item;
menuTag = setting.getMenuTag();
getSelectedValue = setting::getSelectedValueIndex;
}
if (menuTag != null &&
adapter.hasMenuTagActionForValue(menuTag, getSelectedValue.apply(settings)))
{
mBinding.buttonMoreSettings.setVisibility(View.VISIBLE);
final MenuTag finalMenuTag = menuTag;
final Function<Settings, Integer> finalGetSelectedValue = getSelectedValue;
mBinding.buttonMoreSettings.setOnClickListener((view) ->
adapter.onMenuTagAction(finalMenuTag, finalGetSelectedValue.apply(settings)));
}
else
{
mBinding.buttonMoreSettings.setVisibility(View.GONE);
}
setStyle(mBinding.textSettingName, mItem);
}

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/root"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:nextFocusLeft="@id/button_more_settings">
<TextView
android:id="@+id/text_setting_name"
style="@style/TextAppearance.MaterialComponents.Headline5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="@dimen/spacing_large"
android:layout_marginStart="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_large"
android:textSize="16sp"
android:textAlignment="viewStart"
android:layout_toStartOf="@+id/button_more_settings"
tools:text="Setting Name" />
<TextView
android:id="@+id/text_setting_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignStart="@+id/text_setting_name"
android:layout_below="@+id/text_setting_name"
android:layout_marginBottom="@dimen/spacing_large"
android:layout_marginEnd="@dimen/spacing_large"
android:layout_marginStart="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_small"
android:layout_toStartOf="@+id/button_more_settings"
android:textAlignment="viewStart"
tools:text="@string/overclock_enable_description" />
<Button
android:id="@+id/button_more_settings"
style="?attr/materialIconButtonStyle"
android:contentDescription="@string/more_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/spacing_small"
android:nextFocusRight="@id/root"
android:visibility="gone"
app:icon="@drawable/ic_settings"
app:iconTint="?attr/colorOnPrimaryContainer" />
</RelativeLayout>

View File

@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<RelativeLayout android:id="@+id/root"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:minHeight="72dp">
android:nextFocusRight="@id/button_more_settings">
<TextView
android:id="@+id/text_setting_name"
style="@style/TextAppearance.MaterialComponents.Headline5"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="@dimen/spacing_large"
@ -22,13 +22,13 @@
android:layout_marginTop="@dimen/spacing_large"
android:textSize="16sp"
android:textAlignment="viewStart"
android:layout_toStartOf="@+id/button_more_settings"
tools:text="Setting Name" />
<TextView
android:id="@+id/text_setting_description"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignStart="@+id/text_setting_name"
android:layout_below="@+id/text_setting_name"
@ -36,7 +36,22 @@
android:layout_marginEnd="@dimen/spacing_large"
android:layout_marginStart="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_small"
android:layout_toStartOf="@+id/button_more_settings"
android:textAlignment="viewStart"
tools:text="@string/overclock_enable_description" />
<Button
android:id="@+id/button_more_settings"
style="?attr/materialIconButtonStyle"
android:contentDescription="@string/more_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/spacing_small"
android:nextFocusLeft="@id/root"
android:visibility="gone"
app:icon="@drawable/ic_settings"
app:iconTint="?attr/colorOnPrimaryContainer" />
</RelativeLayout>

View File

@ -478,6 +478,7 @@
<string name="disabled">Disabled</string>
<string name="other">Other</string>
<string name="continue_anyway">Continue Anyway</string>
<string name="more_settings">More Settings</string>
<!-- Game Grid Screen-->
<string name="platform_gamecube">GameCube Games</string>
@ -682,7 +683,6 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="replug_gc_adapter">GameCube Adapter couldn\'t be opened. Please re-plug the device.</string>
<string name="disabled_gc_overlay_notice">GameCube Controller 1 is set to \"None\"</string>
<string name="ignore_warning_alert_messages">Ignore for this session</string>
<string name="make_sure_continuous_scan_enabled">Please make sure Continuous Scanning is enabled in Core Settings.</string>
<!-- UI CPU Core selection -->
<string name="jit_recompiler_x86">JIT Recompiler for x8664 (recommended)</string>