Implement Seekbar dialog and SingleChoice dialog
This commit is contained in:
parent
ce8a3d9bfb
commit
c8e4008b83
|
@ -9,10 +9,10 @@
|
|||
<item>@string/cached_interpreter</item>
|
||||
<item>@string/jit_arm64_recompiler</item>
|
||||
</string-array>
|
||||
<string-array name="int_emu_cores" translatable="false">
|
||||
<integer-array name="int_emu_cores" translatable="false">
|
||||
<item>0</item>
|
||||
<item>5</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
</integer-array>
|
||||
|
||||
</resources>
|
|
@ -4,15 +4,19 @@ import org.dolphinemu.dolphinemu.model.settings.FloatSetting;
|
|||
import org.dolphinemu.dolphinemu.model.settings.IntSetting;
|
||||
import org.dolphinemu.dolphinemu.model.settings.Setting;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
import org.dolphinemu.dolphinemu.utils.SettingsFile;
|
||||
|
||||
public class SliderSetting extends SettingsItem
|
||||
{
|
||||
private int mMax;
|
||||
|
||||
public SliderSetting(String key, Setting setting, int titleId, int descriptionId, int max)
|
||||
private String mUnits;
|
||||
|
||||
public SliderSetting(String key, Setting setting, int titleId, int descriptionId, int max, String units)
|
||||
{
|
||||
super(key, setting, titleId, descriptionId);
|
||||
mMax = max;
|
||||
mUnits = units;
|
||||
}
|
||||
|
||||
public int getMax()
|
||||
|
@ -32,8 +36,15 @@ public class SliderSetting extends SettingsItem
|
|||
else if (setting instanceof FloatSetting)
|
||||
{
|
||||
FloatSetting floatSetting = (FloatSetting) setting;
|
||||
if (floatSetting.getKey().equals(SettingsFile.KEY_OVERCLOCK_PERCENT))
|
||||
{
|
||||
return Math.round(floatSetting.getValue() * 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Math.round(floatSetting.getValue());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.error("[SliderSetting] Error casting setting type.");
|
||||
|
@ -53,6 +64,11 @@ public class SliderSetting extends SettingsItem
|
|||
setting.setValue(selection);
|
||||
}
|
||||
|
||||
public String getUnits()
|
||||
{
|
||||
return mUnits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package org.dolphinemu.dolphinemu.ui.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.model.settings.FloatSetting;
|
||||
import org.dolphinemu.dolphinemu.model.settings.view.SettingsItem;
|
||||
import org.dolphinemu.dolphinemu.model.settings.view.SingleChoiceSetting;
|
||||
import org.dolphinemu.dolphinemu.model.settings.view.SliderSetting;
|
||||
|
@ -19,15 +24,23 @@ import org.dolphinemu.dolphinemu.ui.settings.viewholder.SingleChoiceViewHolder;
|
|||
import org.dolphinemu.dolphinemu.ui.settings.viewholder.SliderViewHolder;
|
||||
import org.dolphinemu.dolphinemu.ui.settings.viewholder.SubmenuViewHolder;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
import org.dolphinemu.dolphinemu.utils.SettingsFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder>
|
||||
implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener
|
||||
{
|
||||
private SettingsFragmentView mView;
|
||||
private Context mContext;
|
||||
private ArrayList<SettingsItem> mSettings;
|
||||
|
||||
private SettingsItem mClickedItem;
|
||||
private int mSeekbarProgress;
|
||||
|
||||
private AlertDialog mDialog;
|
||||
private TextView mTextSliderValue;
|
||||
|
||||
public SettingsAdapter(SettingsFragmentView view, Context context)
|
||||
{
|
||||
mView = view;
|
||||
|
@ -106,16 +119,155 @@ public class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder>
|
|||
|
||||
public void onSingleChoiceClick(SingleChoiceSetting item)
|
||||
{
|
||||
Toast.makeText(mContext, "Single choice item clicked", Toast.LENGTH_SHORT).show();
|
||||
mClickedItem = item;
|
||||
|
||||
int value = getSelectionForSingleChoiceValue(item);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity());
|
||||
|
||||
builder.setTitle(item.getNameId());
|
||||
builder.setSingleChoiceItems(item.getChoicesId(), value, this);
|
||||
|
||||
mDialog = builder.show();
|
||||
}
|
||||
|
||||
public void onSliderClick(SliderSetting item)
|
||||
{
|
||||
Toast.makeText(mContext, "Slider item clicked", Toast.LENGTH_SHORT).show();
|
||||
mClickedItem = item;
|
||||
mSeekbarProgress = item.getSelectedValue();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity());
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(mView.getActivity());
|
||||
View view = inflater.inflate(R.layout.dialog_seekbar, null);
|
||||
|
||||
builder.setTitle(item.getNameId());
|
||||
builder.setView(view);
|
||||
builder.setPositiveButton(R.string.dialog_seekbar_pos, this);
|
||||
builder.setNegativeButton(R.string.dialog_seekbar_neg, this);
|
||||
mDialog = builder.show();
|
||||
|
||||
mTextSliderValue = (TextView) view.findViewById(R.id.text_value);
|
||||
mTextSliderValue.setText(String.valueOf(mSeekbarProgress));
|
||||
|
||||
TextView units = (TextView) view.findViewById(R.id.text_units);
|
||||
units.setText(item.getUnits());
|
||||
|
||||
SeekBar seekbar = (SeekBar) view.findViewById(R.id.seekbar);
|
||||
|
||||
seekbar.setMax(item.getMax());
|
||||
seekbar.setProgress(mSeekbarProgress);
|
||||
|
||||
seekbar.setOnSeekBarChangeListener(this);
|
||||
}
|
||||
|
||||
public void onSubmenuClick(SubmenuSetting item)
|
||||
{
|
||||
Toast.makeText(mContext, "Submenu item clicked", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
if (mClickedItem instanceof SingleChoiceSetting)
|
||||
{
|
||||
SingleChoiceSetting scSetting = (SingleChoiceSetting) mClickedItem;
|
||||
|
||||
int value = getValueForSingleChoiceSelection(scSetting, which);
|
||||
|
||||
scSetting.setSelectedValue(value);
|
||||
closeDialog();
|
||||
}
|
||||
else if (mClickedItem instanceof SliderSetting)
|
||||
{
|
||||
SliderSetting sliderSetting = (SliderSetting) mClickedItem;
|
||||
if (sliderSetting.getSetting() instanceof FloatSetting)
|
||||
{
|
||||
float value;
|
||||
|
||||
if (sliderSetting.getKey().equals(SettingsFile.KEY_OVERCLOCK_PERCENT))
|
||||
{
|
||||
value = mSeekbarProgress / 100.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (float) mSeekbarProgress;
|
||||
}
|
||||
|
||||
sliderSetting.setSelectedValue(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
sliderSetting.setSelectedValue(mSeekbarProgress);
|
||||
}
|
||||
}
|
||||
|
||||
mClickedItem = null;
|
||||
mSeekbarProgress = -1;
|
||||
}
|
||||
|
||||
public void closeDialog()
|
||||
{
|
||||
if (mDialog != null)
|
||||
{
|
||||
mDialog.dismiss();
|
||||
mDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||
{
|
||||
mSeekbarProgress = progress;
|
||||
mTextSliderValue.setText(String.valueOf(mSeekbarProgress));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
}
|
||||
|
||||
private int getValueForSingleChoiceSelection(SingleChoiceSetting item, int which)
|
||||
{
|
||||
int valuesId = item.getValuesId();
|
||||
|
||||
if (valuesId > 0)
|
||||
{
|
||||
int[] valuesArray = mContext.getResources().getIntArray(valuesId);
|
||||
return valuesArray[which];
|
||||
}
|
||||
else
|
||||
{
|
||||
return which;
|
||||
}
|
||||
}
|
||||
|
||||
private int getSelectionForSingleChoiceValue(SingleChoiceSetting item)
|
||||
{
|
||||
int value = item.getSelectedValue();
|
||||
int valuesId = item.getValuesId();
|
||||
|
||||
if (valuesId > 0)
|
||||
{
|
||||
int[] valuesArray = mContext.getResources().getIntArray(valuesId);
|
||||
for (int index = 0; index < valuesArray.length; index++)
|
||||
{
|
||||
int current = valuesArray[index];
|
||||
if (current == value)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,11 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
|
|||
{
|
||||
super.onDetach();
|
||||
mView = null;
|
||||
|
||||
if (mAdapter != null)
|
||||
{
|
||||
mAdapter.closeDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -97,6 +97,6 @@ public class SettingsFragmentPresenter
|
|||
sl.add(new CheckBoxSetting(overclockEnable.getKey(), overclockEnable, R.string.overclock_enable, R.string.overclock_enable_description));
|
||||
|
||||
Setting overclock = mSettings.get(SettingsFile.SECTION_CORE).getSetting(SettingsFile.KEY_OVERCLOCK_PERCENT);
|
||||
sl.add(new SliderSetting(overclock.getKey(), overclock, R.string.overclock_title, 0, 400));
|
||||
sl.add(new SliderSetting(overclock.getKey(), overclock, R.string.overclock_title, 0, 400, "%"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.dolphinemu.dolphinemu.ui.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import org.dolphinemu.dolphinemu.model.settings.SettingSection;
|
||||
import org.dolphinemu.dolphinemu.model.settings.view.SettingsItem;
|
||||
|
||||
|
@ -13,4 +15,6 @@ public interface SettingsFragmentView
|
|||
void passOptionsToActivity(HashMap<String, SettingSection> settings);
|
||||
|
||||
void showSettingsList(ArrayList<SettingsItem> settingsList);
|
||||
|
||||
Activity getActivity();
|
||||
}
|
||||
|
|
|
@ -1,128 +0,0 @@
|
|||
package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
|
||||
public class SliderPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener, View.OnClickListener
|
||||
{
|
||||
private static final String androidns = "http://schemas.android.com/apk/res/android";
|
||||
|
||||
// SeekBar
|
||||
private int m_max, m_value;
|
||||
private String m_key;
|
||||
private SeekBar m_seekbar;
|
||||
|
||||
// TextView
|
||||
private TextView m_textview;
|
||||
|
||||
public SliderPreference(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
|
||||
// Seekbar values
|
||||
m_value = attrs.getAttributeIntValue(androidns, "defaultValue", 0);
|
||||
m_max = attrs.getAttributeIntValue(androidns, "max", 100);
|
||||
m_key = attrs.getAttributeValue(androidns, "key");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView()
|
||||
{
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.slider_layout, null, false);
|
||||
|
||||
m_seekbar = (SeekBar) layout.findViewById(R.id.sliderSeekBar);
|
||||
m_textview = (TextView) layout.findViewById(R.id.sliderTextView);
|
||||
|
||||
if (shouldPersist())
|
||||
{
|
||||
if (m_key != null && m_key.equals("Overclock"))
|
||||
{
|
||||
Toast.makeText(getContext(), getContext().getString(R.string.overclock_warning),
|
||||
Toast.LENGTH_LONG).show();
|
||||
|
||||
float valueAsFloat = Float.valueOf(getPersistedString(Integer.toString(m_value)));
|
||||
float valueAsPercent = valueAsFloat * 100;
|
||||
|
||||
m_value = Math.round(valueAsPercent);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_value = Integer.valueOf(getPersistedString(Integer.toString(m_value)));
|
||||
}
|
||||
}
|
||||
|
||||
m_seekbar.setMax(m_max);
|
||||
m_seekbar.setProgress(m_value);
|
||||
setProgressText(m_value);
|
||||
m_seekbar.setOnSeekBarChangeListener(this);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
// SeekBar overrides
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seek, int value, boolean fromTouch)
|
||||
{
|
||||
m_value = value;
|
||||
setProgressText(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seek)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seek)
|
||||
{
|
||||
}
|
||||
|
||||
void setProgressText(int value)
|
||||
{
|
||||
m_textview.setText(String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showDialog(Bundle state)
|
||||
{
|
||||
super.showDialog(state);
|
||||
|
||||
Button positiveButton = ((AlertDialog) getDialog()).getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
positiveButton.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if (shouldPersist())
|
||||
{
|
||||
String valueToSave;
|
||||
if (m_key != null && m_key.equals("Overclock"))
|
||||
{
|
||||
float valueAsFloat = m_value / 100.0f;
|
||||
valueToSave = Float.toString(valueAsFloat);
|
||||
}
|
||||
else
|
||||
{
|
||||
valueToSave = Integer.toString(m_seekbar.getProgress());
|
||||
}
|
||||
|
||||
persistString(valueToSave);
|
||||
callChangeListener(m_seekbar.getProgress());
|
||||
}
|
||||
((AlertDialog) getDialog()).dismiss();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/spacing_xlarge"
|
||||
android:layout_marginRight="@dimen/spacing_xlarge"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/text_value"
|
||||
android:layout_marginBottom="@dimen/spacing_xlarge"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="75"
|
||||
android:id="@+id/text_value"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/spacing_xlarge"
|
||||
android:layout_marginBottom="@dimen/spacing_large"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="%"
|
||||
android:id="@+id/text_units"
|
||||
android:layout_alignTop="@+id/text_value"
|
||||
android:layout_toEndOf="@+id/text_value"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:weightSum="1"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<SeekBar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/sliderSeekBar"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Sample Text"
|
||||
android:id="@+id/sliderTextView"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -9,11 +9,11 @@
|
|||
<item>@string/jit64_recompiler</item>
|
||||
<item>@string/jitil_recompiler</item>
|
||||
</string-array>
|
||||
<string-array name="emuCoreValuesX86_64" translatable="false">
|
||||
<integer-array name="emuCoreValuesX86_64" translatable="false">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
</integer-array>
|
||||
|
||||
<!-- CPU core selection - ARM -->
|
||||
<string-array name="emuCoreEntriesARM" translatable="false">
|
||||
|
|
|
@ -334,6 +334,8 @@
|
|||
<string name="preferences_extensions">Extension Bindings</string>
|
||||
<string name="preferences_video">Video Settings</string>
|
||||
<string name="emulation_title">Emulation Activity</string>
|
||||
<string name="dialog_seekbar_pos">OK</string>
|
||||
<string name="dialog_seekbar_neg">Cancel</string>
|
||||
|
||||
<!-- Emulation Menu -->
|
||||
<string name="emulation_toggle_input">Toggle Touch Controls</string>
|
||||
|
|
Loading…
Reference in New Issue