Android: Add "Create mappings for other devices"
This commit is contained in:
parent
2b1dd52750
commit
a1cc19f443
|
@ -22,6 +22,7 @@ public final class MotionAlertDialog extends AlertDialog
|
||||||
{
|
{
|
||||||
private final Activity mActivity;
|
private final Activity mActivity;
|
||||||
private final InputMappingControlSetting mSetting;
|
private final InputMappingControlSetting mSetting;
|
||||||
|
private final boolean mAllDevices;
|
||||||
private boolean mRunning = false;
|
private boolean mRunning = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,13 +30,16 @@ public final class MotionAlertDialog extends AlertDialog
|
||||||
*
|
*
|
||||||
* @param activity The current {@link Activity}.
|
* @param activity The current {@link Activity}.
|
||||||
* @param setting The setting to show this dialog for.
|
* @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);
|
super(activity);
|
||||||
|
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mSetting = setting;
|
mSetting = setting;
|
||||||
|
mAllDevices = allDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,7 +50,7 @@ public final class MotionAlertDialog extends AlertDialog
|
||||||
mRunning = true;
|
mRunning = true;
|
||||||
new Thread(() ->
|
new Thread(() ->
|
||||||
{
|
{
|
||||||
String result = MappingCommon.detectInput(mSetting.getController(), false);
|
String result = MappingCommon.detectInput(mSetting.getController(), mAllDevices);
|
||||||
mActivity.runOnUiThread(() ->
|
mActivity.runOnUiThread(() ->
|
||||||
{
|
{
|
||||||
if (mRunning)
|
if (mRunning)
|
||||||
|
|
|
@ -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_GAME_ID = "game_id";
|
||||||
private static final String ARG_REVISION = "revision";
|
private static final String ARG_REVISION = "revision";
|
||||||
private static final String ARG_IS_WII = "is_wii";
|
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 static final String FRAGMENT_TAG = "settings";
|
||||||
|
|
||||||
private SettingsActivityPresenter mPresenter;
|
private SettingsActivityPresenter mPresenter;
|
||||||
|
|
||||||
private AlertDialog dialog;
|
private AlertDialog dialog;
|
||||||
|
|
||||||
private CollapsingToolbarLayout mToolbarLayout;
|
private CollapsingToolbarLayout mToolbarLayout;
|
||||||
|
|
||||||
private ActivitySettingsBinding mBinding;
|
private ActivitySettingsBinding mBinding;
|
||||||
|
|
||||||
|
private boolean mMappingAllDevices = false;
|
||||||
|
|
||||||
public static void launch(Context context, MenuTag menuTag, String gameId, int revision,
|
public static void launch(Context context, MenuTag menuTag, String gameId, int revision,
|
||||||
boolean isWii)
|
boolean isWii)
|
||||||
{
|
{
|
||||||
|
@ -82,6 +84,10 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
|
||||||
{
|
{
|
||||||
MainPresenter.skipRescanningLibrary();
|
MainPresenter.skipRescanningLibrary();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mMappingAllDevices = savedInstanceState.getBoolean(KEY_MAPPING_ALL_DEVICES);
|
||||||
|
}
|
||||||
|
|
||||||
mBinding = ActivitySettingsBinding.inflate(getLayoutInflater());
|
mBinding = ActivitySettingsBinding.inflate(getLayoutInflater());
|
||||||
setContentView(mBinding.getRoot());
|
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.
|
// Critical: If super method is not called, rotations will be busted.
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
mPresenter.saveState(outState);
|
mPresenter.saveState(outState);
|
||||||
|
|
||||||
|
outState.putBoolean(KEY_MAPPING_ALL_DEVICES, mMappingAllDevices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -333,6 +342,18 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
|
||||||
mToolbarLayout.setTitle(title);
|
mToolbarLayout.setTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMappingAllDevices(boolean allDevices)
|
||||||
|
{
|
||||||
|
mMappingAllDevices = allDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMappingAllDevices()
|
||||||
|
{
|
||||||
|
return mMappingAllDevices;
|
||||||
|
}
|
||||||
|
|
||||||
private void setInsets()
|
private void setInsets()
|
||||||
{
|
{
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(mBinding.appbarSettings, (v, windowInsets) ->
|
ViewCompat.setOnApplyWindowInsetsListener(mBinding.appbarSettings, (v, windowInsets) ->
|
||||||
|
|
|
@ -97,4 +97,16 @@ public interface SettingsActivityView
|
||||||
* Accesses the material toolbar layout and changes the title
|
* Accesses the material toolbar layout and changes the title
|
||||||
*/
|
*/
|
||||||
void setToolbarTitle(String 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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,7 +312,8 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
||||||
|
|
||||||
public void onInputMappingClick(final InputMappingControlSetting item, final int position)
|
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);
|
Drawable background = ContextCompat.getDrawable(mContext, R.drawable.dialog_round);
|
||||||
@ColorInt int color = new ElevationOverlayProvider(dialog.getContext()).compositeOverlay(
|
@ColorInt int color = new ElevationOverlayProvider(dialog.getContext()).compositeOverlay(
|
||||||
|
|
|
@ -248,6 +248,18 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
|
||||||
return mActivity.hasMenuTagActionForValue(menuTag, value);
|
return mActivity.hasMenuTagActionForValue(menuTag, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMappingAllDevices(boolean allDevices)
|
||||||
|
{
|
||||||
|
mActivity.setMappingAllDevices(allDevices);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMappingAllDevices()
|
||||||
|
{
|
||||||
|
return mActivity.isMappingAllDevices();
|
||||||
|
}
|
||||||
|
|
||||||
private void setInsets()
|
private void setInsets()
|
||||||
{
|
{
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(mBinding.listSettings, (v, windowInsets) ->
|
ViewCompat.setOnApplyWindowInsetsListener(mBinding.listSettings, (v, windowInsets) ->
|
||||||
|
|
|
@ -1179,6 +1179,40 @@ public final class SettingsFragmentPresenter
|
||||||
private void addControllerMetaSettings(ArrayList<SettingsItem> sl, EmulatedController controller)
|
private void addControllerMetaSettings(ArrayList<SettingsItem> sl, EmulatedController controller)
|
||||||
{
|
{
|
||||||
sl.add(new InputDeviceSetting(mContext, R.string.input_device, 0, 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -89,4 +89,16 @@ public interface SettingsFragmentView
|
||||||
* @param value The current value of the setting.
|
* @param value The current value of the setting.
|
||||||
*/
|
*/
|
||||||
boolean hasMenuTagActionForValue(@NonNull MenuTag menuTag, int value);
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
<string name="wiimote_extensions">Extension</string>
|
<string name="wiimote_extensions">Extension</string>
|
||||||
|
|
||||||
<string name="input_device">Device</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">Input Binding</string>
|
||||||
<string name="input_binding_description">Press or move an input to bind it to %1$s.</string>
|
<string name="input_binding_description">Press or move an input to bind it to %1$s.</string>
|
||||||
|
|
Loading…
Reference in New Issue