Android: Add "Create mappings for other devices"

This commit is contained in:
JosJuice 2022-10-30 17:20:10 +01:00
parent 2b1dd52750
commit a1cc19f443
8 changed files with 105 additions and 7 deletions

View File

@ -22,20 +22,24 @@ public final class MotionAlertDialog extends AlertDialog
{
private final Activity mActivity;
private final InputMappingControlSetting mSetting;
private final boolean mAllDevices;
private boolean mRunning = false;
/**
* Constructor
*
* @param activity The current {@link Activity}.
* @param setting The setting to show this dialog for.
* @param activity The current {@link Activity}.
* @param setting The setting to show this dialog for.
* @param allDevices Whether to detect inputs from devices other than the configured one.
*/
public MotionAlertDialog(Activity activity, InputMappingControlSetting setting)
public MotionAlertDialog(Activity activity, InputMappingControlSetting setting,
boolean allDevices)
{
super(activity);
mActivity = activity;
mSetting = setting;
mAllDevices = allDevices;
}
@Override
@ -46,7 +50,7 @@ public final class MotionAlertDialog extends AlertDialog
mRunning = true;
new Thread(() ->
{
String result = MappingCommon.detectInput(mSetting.getController(), false);
String result = MappingCommon.detectInput(mSetting.getController(), mAllDevices);
mActivity.runOnUiThread(() ->
{
if (mRunning)

View File

@ -41,15 +41,17 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
private static final String ARG_GAME_ID = "game_id";
private static final String ARG_REVISION = "revision";
private static final String ARG_IS_WII = "is_wii";
private static final String KEY_MAPPING_ALL_DEVICES = "all_devices";
private static final String FRAGMENT_TAG = "settings";
private SettingsActivityPresenter mPresenter;
private AlertDialog dialog;
private CollapsingToolbarLayout mToolbarLayout;
private ActivitySettingsBinding mBinding;
private boolean mMappingAllDevices = false;
public static void launch(Context context, MenuTag menuTag, String gameId, int revision,
boolean isWii)
{
@ -82,6 +84,10 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
{
MainPresenter.skipRescanningLibrary();
}
else
{
mMappingAllDevices = savedInstanceState.getBoolean(KEY_MAPPING_ALL_DEVICES);
}
mBinding = ActivitySettingsBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot());
@ -125,7 +131,10 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
{
// Critical: If super method is not called, rotations will be busted.
super.onSaveInstanceState(outState);
mPresenter.saveState(outState);
outState.putBoolean(KEY_MAPPING_ALL_DEVICES, mMappingAllDevices);
}
@Override
@ -333,6 +342,18 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
mToolbarLayout.setTitle(title);
}
@Override
public void setMappingAllDevices(boolean allDevices)
{
mMappingAllDevices = allDevices;
}
@Override
public boolean isMappingAllDevices()
{
return mMappingAllDevices;
}
private void setInsets()
{
ViewCompat.setOnApplyWindowInsetsListener(mBinding.appbarSettings, (v, windowInsets) ->

View File

@ -97,4 +97,16 @@ public interface SettingsActivityView
* Accesses the material toolbar layout and changes the title
*/
void setToolbarTitle(String title);
/**
* Sets whether the input mapping dialog should detect inputs from all devices,
* not just the device configured for the controller.
*/
void setMappingAllDevices(boolean allDevices);
/**
* Returns whether the input mapping dialog should detect inputs from all devices,
* not just the device configured for the controller.
*/
boolean isMappingAllDevices();
}

View File

@ -312,7 +312,8 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
public void onInputMappingClick(final InputMappingControlSetting item, final int position)
{
final MotionAlertDialog dialog = new MotionAlertDialog(mView.getActivity(), item);
final MotionAlertDialog dialog = new MotionAlertDialog(mView.getActivity(), item,
mView.isMappingAllDevices());
Drawable background = ContextCompat.getDrawable(mContext, R.drawable.dialog_round);
@ColorInt int color = new ElevationOverlayProvider(dialog.getContext()).compositeOverlay(

View File

@ -248,6 +248,18 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
return mActivity.hasMenuTagActionForValue(menuTag, value);
}
@Override
public void setMappingAllDevices(boolean allDevices)
{
mActivity.setMappingAllDevices(allDevices);
}
@Override
public boolean isMappingAllDevices()
{
return mActivity.isMappingAllDevices();
}
private void setInsets()
{
ViewCompat.setOnApplyWindowInsetsListener(mBinding.listSettings, (v, windowInsets) ->

View File

@ -1179,6 +1179,40 @@ public final class SettingsFragmentPresenter
private void addControllerMetaSettings(ArrayList<SettingsItem> sl, EmulatedController controller)
{
sl.add(new InputDeviceSetting(mContext, R.string.input_device, 0, controller));
sl.add(new SwitchSetting(mContext, new AbstractBooleanSetting()
{
@Override
public boolean isOverridden(Settings settings)
{
return false;
}
@Override
public boolean isRuntimeEditable()
{
return true;
}
@Override
public boolean delete(Settings settings)
{
mView.setMappingAllDevices(false);
return true;
}
@Override
public boolean getBoolean(Settings settings)
{
return mView.isMappingAllDevices();
}
@Override
public void setBoolean(Settings settings, boolean newValue)
{
mView.setMappingAllDevices(newValue);
}
}, R.string.input_device_all_devices, R.string.input_device_all_devices_description));
}
/**

View File

@ -89,4 +89,16 @@ public interface SettingsFragmentView
* @param value The current value of the setting.
*/
boolean hasMenuTagActionForValue(@NonNull MenuTag menuTag, int value);
/**
* Sets whether the input mapping dialog should detect inputs from all devices,
* not just the device configured for the controller.
*/
void setMappingAllDevices(boolean allDevices);
/**
* Returns whether the input mapping dialog should detect inputs from all devices,
* not just the device configured for the controller.
*/
boolean isMappingAllDevices();
}

View File

@ -28,6 +28,8 @@
<string name="wiimote_extensions">Extension</string>
<string name="input_device">Device</string>
<string name="input_device_all_devices">Create Mappings for Other Devices</string>
<string name="input_device_all_devices_description">Detects inputs from all devices, not just the selected device.</string>
<string name="input_binding">Input Binding</string>
<string name="input_binding_description">Press or move an input to bind it to %1$s.</string>