diff --git a/Source/Android/app/src/arm_64/res/values/arrays.xml b/Source/Android/app/src/arm_64/res/values/arrays.xml index 8f2ed0edff..fb98aa63da 100644 --- a/Source/Android/app/src/arm_64/res/values/arrays.xml +++ b/Source/Android/app/src/arm_64/res/values/arrays.xml @@ -9,10 +9,10 @@ @string/cached_interpreter @string/jit_arm64_recompiler - + 0 5 4 - + \ No newline at end of file diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SliderSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SliderSetting.java index 4194753f52..685ba5aa69 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SliderSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SliderSetting.java @@ -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,7 +36,14 @@ public class SliderSetting extends SettingsItem else if (setting instanceof FloatSetting) { FloatSetting floatSetting = (FloatSetting) setting; - return Math.round(floatSetting.getValue()); + if (floatSetting.getKey().equals(SettingsFile.KEY_OVERCLOCK_PERCENT)) + { + return Math.round(floatSetting.getValue() * 100); + } + else + { + return Math.round(floatSetting.getValue()); + } } else { @@ -53,6 +64,11 @@ public class SliderSetting extends SettingsItem setting.setValue(selection); } + public String getUnits() + { + return mUnits; + } + @Override public int getType() { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java index 8d8272d2f7..f386fc94df 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java @@ -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 + implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener { private SettingsFragmentView mView; private Context mContext; private ArrayList 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 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; + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragment.java index 3d4817f3fc..a612233789 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragment.java @@ -77,6 +77,11 @@ public final class SettingsFragment extends Fragment implements SettingsFragment { super.onDetach(); mView = null; + + if (mAdapter != null) + { + mAdapter.closeDialog(); + } } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentPresenter.java index d0bc5a36f9..b53d7517f9 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentPresenter.java @@ -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, "%")); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentView.java index 5f0f366ef7..cef3d73dff 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragmentView.java @@ -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 settings); void showSettingsList(ArrayList settingsList); + + Activity getActivity(); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SliderPreference.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SliderPreference.java deleted file mode 100644 index da896cf590..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SliderPreference.java +++ /dev/null @@ -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(); - } -} diff --git a/Source/Android/app/src/main/res/layout/dialog_seekbar.xml b/Source/Android/app/src/main/res/layout/dialog_seekbar.xml new file mode 100644 index 0000000000..4d81af8d81 --- /dev/null +++ b/Source/Android/app/src/main/res/layout/dialog_seekbar.xml @@ -0,0 +1,37 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Source/Android/app/src/main/res/layout/slider_layout.xml b/Source/Android/app/src/main/res/layout/slider_layout.xml deleted file mode 100644 index a667ff6489..0000000000 --- a/Source/Android/app/src/main/res/layout/slider_layout.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Source/Android/app/src/main/res/values/arrays.xml b/Source/Android/app/src/main/res/values/arrays.xml index cf812c87e9..5017b8e3ec 100644 --- a/Source/Android/app/src/main/res/values/arrays.xml +++ b/Source/Android/app/src/main/res/values/arrays.xml @@ -9,11 +9,11 @@ @string/jit64_recompiler @string/jitil_recompiler - + 0 1 2 - + diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 7819de79cc..e4fae28f1f 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -334,6 +334,8 @@ Extension Bindings Video Settings Emulation Activity + OK + Cancel Toggle Touch Controls