mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
[Android] Simplify LayoutInflater retrieval for KeyBindPreference.java and SeekbarPreference.java.
Simplify application info retrieval in OverlayActivity.java.
This commit is contained in:
parent
16127e046c
commit
e71bce0cbd
@ -7,7 +7,7 @@ import android.os.Bundle;
|
||||
public final class OverlayActivity extends DirectoryActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
File overlayDir = new File(getBaseContext().getApplicationInfo().dataDir, "overlays");
|
||||
File overlayDir = new File(getApplicationInfo().dataDir, "overlays");
|
||||
if (overlayDir.exists())
|
||||
super.setStartDirectory(overlayDir.getAbsolutePath());
|
||||
|
||||
|
@ -42,15 +42,16 @@ final class KeyBindEditText extends EditText
|
||||
final class KeyBindPreference extends DialogPreference implements View.OnKeyListener, AdapterView.OnItemClickListener, LayoutInflater.Factory {
|
||||
private int key_bind_code;
|
||||
private boolean grabKeyCode = false;
|
||||
KeyBindEditText keyText;
|
||||
private KeyBindEditText keyText;
|
||||
private String[] key_labels;
|
||||
private final int DEFAULT_KEYCODE = 0;
|
||||
private final Context context;
|
||||
|
||||
public KeyBindPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
this.context = context;
|
||||
key_labels = getContext().getResources().getStringArray(R.array.key_bind_values);
|
||||
this.key_labels = getContext().getResources().getStringArray(R.array.key_bind_values);
|
||||
}
|
||||
|
||||
private void setKey(int keyCode, boolean force)
|
||||
@ -62,16 +63,11 @@ final class KeyBindPreference extends DialogPreference implements View.OnKeyList
|
||||
keyText.setText(String.format(context.getString(R.string.current_binding), key_labels[key_bind_code]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView()
|
||||
{
|
||||
LayoutInflater inflater = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).cloneInContext(getContext());
|
||||
LayoutInflater inflater = LayoutInflater.from(context).cloneInContext(getContext());
|
||||
inflater.setFactory(this);
|
||||
View view = inflater.inflate(R.layout.key_bind_dialog, null);
|
||||
keyText = (KeyBindEditText) view.findViewById(R.id.key_bind_value);
|
||||
@ -79,17 +75,17 @@ final class KeyBindPreference extends DialogPreference implements View.OnKeyList
|
||||
view.setOnKeyListener(this);
|
||||
((ListView) view.findViewById(R.id.key_bind_list)).setOnItemClickListener(this);
|
||||
((Button) view.findViewById(R.id.key_bind_clear)).setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
setKey(0, true);
|
||||
}
|
||||
});
|
||||
public void onClick(View v) {
|
||||
setKey(0, true);
|
||||
}
|
||||
});
|
||||
((Button) view.findViewById(R.id.key_bind_detect)).setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
grabKeyCode = true;
|
||||
keyText.setText(R.string.press_key_to_use);
|
||||
keyText.requestFocus();
|
||||
}
|
||||
});
|
||||
public void onClick(View v) {
|
||||
grabKeyCode = true;
|
||||
keyText.setText(R.string.press_key_to_use);
|
||||
keyText.requestFocus();
|
||||
}
|
||||
});
|
||||
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(keyText.getWindowToken(), 0);
|
||||
setKey(getPersistedInt(DEFAULT_KEYCODE), true);
|
||||
@ -98,12 +94,12 @@ final class KeyBindPreference extends DialogPreference implements View.OnKeyList
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
persistInt(key_bind_code);
|
||||
notifyChanged();
|
||||
}
|
||||
if (positiveResult) {
|
||||
persistInt(key_bind_code);
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -121,21 +117,21 @@ final class KeyBindPreference extends DialogPreference implements View.OnKeyList
|
||||
setKey((int)id, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
int code = getPersistedInt(DEFAULT_KEYCODE);
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
int code = getPersistedInt(DEFAULT_KEYCODE);
|
||||
if (code >= key_labels.length)
|
||||
return "";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
@ -11,36 +11,44 @@ import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public final class SeekbarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
|
||||
float seek_value;
|
||||
SeekBar bar;
|
||||
TextView text;
|
||||
|
||||
private float seek_value;
|
||||
private SeekBar bar;
|
||||
private TextView text;
|
||||
private final Context context;
|
||||
|
||||
public SeekbarPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView()
|
||||
{
|
||||
LayoutInflater inflater = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE));
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(R.layout.seek_dialog, null);
|
||||
bar = (SeekBar) view.findViewById(R.id.seekbar_bar);
|
||||
text = (TextView) view.findViewById(R.id.seekbar_text);
|
||||
seek_value = getPersistedFloat(1.0f);
|
||||
this.bar = (SeekBar) view.findViewById(R.id.seekbar_bar);
|
||||
this.text = (TextView) view.findViewById(R.id.seekbar_text);
|
||||
this.seek_value = getPersistedFloat(1.0f);
|
||||
|
||||
// Set initial progress for seek bar and set the listener.
|
||||
int prog = (int) (seek_value * 100);
|
||||
bar.setProgress(prog);
|
||||
text.setText(prog + "%");
|
||||
bar.setOnSeekBarChangeListener(this);
|
||||
this.bar.setProgress(prog);
|
||||
this.text.setText(prog + "%");
|
||||
this.bar.setOnSeekBarChangeListener(this);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
persistFloat(seek_value);
|
||||
}
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
persistFloat(seek_value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user