(Android) work on IME key detection

works with wiimote IME, but not with standard keyboard IME. hopefully most gamepad IMEs work
This commit is contained in:
ToadKing 2013-01-28 18:20:25 -05:00
parent c838b1359c
commit cffc556fd0
2 changed files with 52 additions and 9 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/key_bind_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent" >
@ -14,13 +15,17 @@
android:text="@string/key_bind_title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
<EditText
android:id="@+id/key_bind_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/key_bind_title"
android:layout_below="@+id/key_bind_title"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
<ListView
android:id="@+id/key_bind_list"
@ -28,7 +33,6 @@
android:layout_height="wrap_content"
android:layout_above="@+id/key_bind_clear"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/key_bind_value"
android:entries="@array/key_bind_values" >

View File

@ -9,14 +9,42 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import org.retroarch.R;
class KeyBindPreference extends DialogPreference implements View.OnKeyListener, AdapterView.OnItemClickListener, View.OnClickListener {
class KeyBindEditText extends EditText
{
KeyBindPreference pref;
public KeyBindEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setBoundPreference(KeyBindPreference pref)
{
this.pref = pref;
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event)
{
Log.i("RetroArch", "key! " + String.valueOf(event.getKeyCode()));
pref.onKey(null, event.getKeyCode(), event);
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
Log.i("RetroArch", "key! " + String.valueOf(event.getKeyCode()));
pref.onKey(null, event.getKeyCode(), event);
return false;
}
}
class KeyBindPreference extends DialogPreference implements View.OnKeyListener, AdapterView.OnItemClickListener, View.OnClickListener, LayoutInflater.Factory {
private int key_bind_code;
TextView keyText;
KeyBindEditText keyText;
private String[] key_labels;
private final int DEFAULT_KEYCODE = 0;
@ -39,9 +67,11 @@ class KeyBindPreference extends DialogPreference implements View.OnKeyListener,
@Override
protected View onCreateDialogView()
{
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).cloneInContext(getContext());
inflater.setFactory(this);
View view = inflater.inflate(R.layout.key_bind_dialog, null);
keyText = (TextView) view.findViewById(R.id.key_bind_value);
keyText = (KeyBindEditText) view.findViewById(R.id.key_bind_value);
keyText.setBoundPreference(this);
view.setOnKeyListener(this);
((ListView) view.findViewById(R.id.key_bind_list)).setOnItemClickListener(this);
((Button) view.findViewById(R.id.key_bind_clear)).setOnClickListener(this);
@ -87,4 +117,13 @@ class KeyBindPreference extends DialogPreference implements View.OnKeyListener,
else
return key_labels[code];
}
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
Log.i("RetroArch", "view name: " + name);
if (name.equals("EditText"))
return new KeyBindEditText(context, attrs);
else
return null;
}
}