Android: Clear controller binding by long press on TV
The TV interface can't 'click' the clear button, this gives TV a way to clear
This commit is contained in:
parent
a2b97665bb
commit
51fa5d2fd8
|
@ -11,6 +11,7 @@ import android.view.MotionEvent;
|
||||||
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
|
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
|
||||||
import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper;
|
import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper;
|
||||||
import org.dolphinemu.dolphinemu.utils.Log;
|
import org.dolphinemu.dolphinemu.utils.Log;
|
||||||
|
import org.dolphinemu.dolphinemu.utils.TvUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -45,7 +46,7 @@ public final class MotionAlertDialog extends AlertDialog
|
||||||
Log.debug("[MotionAlertDialog] Received key event: " + event.getAction());
|
Log.debug("[MotionAlertDialog] Received key event: " + event.getAction());
|
||||||
switch (event.getAction())
|
switch (event.getAction())
|
||||||
{
|
{
|
||||||
case KeyEvent.ACTION_DOWN:
|
case KeyEvent.ACTION_UP:
|
||||||
if (!ControllerMappingHelper.shouldKeyBeIgnored(event.getDevice(), keyCode))
|
if (!ControllerMappingHelper.shouldKeyBeIgnored(event.getDevice(), keyCode))
|
||||||
{
|
{
|
||||||
saveKeyInput(event);
|
saveKeyInput(event);
|
||||||
|
@ -58,6 +59,21 @@ public final class MotionAlertDialog extends AlertDialog
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyLongPress(int keyCode, KeyEvent event)
|
||||||
|
{
|
||||||
|
// Option to clear by long back is only needed on the TV interface
|
||||||
|
if (TvUtil.isLeanback(getContext()))
|
||||||
|
{
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK)
|
||||||
|
{
|
||||||
|
clearBinding();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.onKeyLongPress(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(KeyEvent event)
|
public boolean dispatchKeyEvent(KeyEvent event)
|
||||||
{
|
{
|
||||||
|
@ -197,4 +213,14 @@ public final class MotionAlertDialog extends AlertDialog
|
||||||
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clearBinding()
|
||||||
|
{
|
||||||
|
setting.setValue("");
|
||||||
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
editor.remove(setting.getKey());
|
||||||
|
editor.apply();
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="clear">Hold back to clear</string>
|
||||||
|
</resources>
|
Loading…
Reference in New Issue