forked from extern/Unexpected-Keyboard
SideBarPreference + Continuing settings
This commit is contained in:
parent
fe432fd3ba
commit
6f09c971c0
7
res/values/arrays.xml
Normal file
7
res/values/arrays.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="pref_layout_values">
|
||||
<item>azerty</item>
|
||||
<item>qwerty</item>
|
||||
</string-array>
|
||||
</resources>
|
@ -5,13 +5,21 @@
|
||||
<string name="settings_activity_label">Keyboard 2.0 Settings</string>
|
||||
|
||||
<string name="pref_category_layout">Layout</string>
|
||||
<string name="pref_layout_title">Change keyboard layout</string>
|
||||
<string name="pref_layout_summary">%s</string>
|
||||
<string-array name="pref_layout_entries">
|
||||
<item>Azerty</item>
|
||||
<item>Qwerty</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_category_typing">Typing</string>
|
||||
<string name="pref_preci_title">Precision</string>
|
||||
<string name="pref_preci_summary">Distance of corner values (%spx)</string>
|
||||
|
||||
<string name="pref_category_vibrate">Vibration</string>
|
||||
<string name="pref_vibrate_text">Vibration</string>
|
||||
<string name="pref_vibrate_title">Vibration</string>
|
||||
<string name="pref_vibrate_summary">Enable/Disable vibrations</string>
|
||||
<string name="pref_vibrate_duration_text">Duration</string>
|
||||
<string name="pref_vibrate_duration_title">Duration</string>
|
||||
<string name="pref_vibrate_duration_summary">Change vibrations duration</string>
|
||||
|
||||
<string name="pref_category_misc">Other</string>
|
||||
|
@ -1,23 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory android:title="@string/pref_category_layout">
|
||||
<!-- Keyboard layout -->
|
||||
<ListPreference
|
||||
android:key="keyboard_layout"
|
||||
android:title="@string/pref_layout_title"
|
||||
android:summary="@string/pref_layout_summary"
|
||||
android:defaultValue="azerty"
|
||||
android:entries="@array/pref_layout_entries"
|
||||
android:entryValues="@array/pref_layout_values" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_category_typing">
|
||||
<!-- Precision (SUB_VALUE_DIST) -->
|
||||
<!-- Key repeat timeout (LONGPRESS_TIMEOUT) -->
|
||||
<!-- Key repeat interval (LONGPRESS_INTERVAL) -->
|
||||
<juloo.common.SlideBarPreference
|
||||
android:key="sub_value_dist"
|
||||
android:title="@string/pref_preci_title"
|
||||
android:summary="@string/pref_preci_summary"
|
||||
android:defaultValue="8.0"
|
||||
min="5.0"
|
||||
max="20.0"
|
||||
/>
|
||||
<!-- Precision (sub_value_dist) -->
|
||||
<!-- Key repeat timeout (longpress_timeout) -->
|
||||
<!-- Key repeat interval (longpress_interval) -->
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_category_vibrate">
|
||||
<CheckBoxPreference
|
||||
android:key="vibrate_enabled"
|
||||
android:title="@string/pref_vibrate_text"
|
||||
android:title="@string/pref_vibrate_title"
|
||||
android:summary="@string/pref_vibrate_summary"
|
||||
android:defaultValue="true" />
|
||||
<!-- Duration (VIBRATE_DURATION) -->
|
||||
<!-- Duration (vibrate_duration) -->
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_category_misc">
|
||||
<!-- Keys height (_keyHeight) -->
|
||||
<!-- Offset height (_marginBottom) -->
|
||||
<!-- Offset height (margin_bottom) -->
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
127
srcs/juloo.common/SlideBarPreference.java
Normal file
127
srcs/juloo.common/SlideBarPreference.java
Normal file
@ -0,0 +1,127 @@
|
||||
package juloo.common;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
/*
|
||||
** SideBarPreference
|
||||
** -
|
||||
** Open a dialog showing a seekbar
|
||||
** -
|
||||
** xml attrs:
|
||||
** android:defaultValue Default value (float)
|
||||
** min min value (float)
|
||||
** max max value (float)
|
||||
** -
|
||||
** Summary field allow to show the current value using %f or %s flag
|
||||
*/
|
||||
public class SlideBarPreference extends DialogPreference
|
||||
implements SeekBar.OnSeekBarChangeListener
|
||||
{
|
||||
private static final int SEEKBAR_MAX = 1000;
|
||||
|
||||
private LinearLayout _layout;
|
||||
private TextView _textView;
|
||||
private SeekBar _seekBar;
|
||||
|
||||
private float _min;
|
||||
private float _max;
|
||||
private float _value;
|
||||
|
||||
private String _initialSummary;
|
||||
|
||||
public SlideBarPreference(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
_initialSummary = getSummary().toString();
|
||||
_textView = new TextView(context);
|
||||
_textView.setPadding(48, 40, 48, 40);
|
||||
_seekBar = new SeekBar(context);
|
||||
_seekBar.setOnSeekBarChangeListener(this);
|
||||
_seekBar.setMax(SEEKBAR_MAX);
|
||||
_min = float_of_string(attrs.getAttributeValue(null, "min"));
|
||||
_value = _min;
|
||||
_max = Math.max(1f, float_of_string(attrs.getAttributeValue(null, "max")));
|
||||
_layout = new LinearLayout(getContext());
|
||||
_layout.setOrientation(LinearLayout.VERTICAL);
|
||||
_layout.addView(_textView);
|
||||
_layout.addView(_seekBar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||
{
|
||||
_value = (progress * _max) / SEEKBAR_MAX + _min;
|
||||
updateText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue)
|
||||
{
|
||||
if (restorePersistedValue)
|
||||
{
|
||||
_value = getPersistedFloat(_min);
|
||||
}
|
||||
else
|
||||
{
|
||||
_value = (Float)defaultValue;
|
||||
persistFloat(_value);
|
||||
}
|
||||
_seekBar.setProgress((int)((_value - _min) * SEEKBAR_MAX / _max));
|
||||
updateText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index)
|
||||
{
|
||||
return (a.getFloat(index, _min));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult)
|
||||
{
|
||||
if (positiveResult)
|
||||
persistFloat(_value);
|
||||
}
|
||||
|
||||
protected View onCreateDialogView()
|
||||
{
|
||||
ViewGroup parent = (ViewGroup)_layout.getParent();
|
||||
|
||||
if (parent != null)
|
||||
parent.removeView(_layout);
|
||||
return (_layout);
|
||||
}
|
||||
|
||||
private void updateText()
|
||||
{
|
||||
String f = String.format(_initialSummary, _value);
|
||||
|
||||
_textView.setText(f);
|
||||
setSummary(f);
|
||||
}
|
||||
|
||||
private static float float_of_string(String str)
|
||||
{
|
||||
if (str == null)
|
||||
return (0f);
|
||||
return (Float.parseFloat(str));
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import android.inputmethodservice.InputMethodService;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class Keyboard2 extends InputMethodService
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
@ -25,10 +26,15 @@ public class Keyboard2 extends InputMethodService
|
||||
@Override
|
||||
public View onCreateInputView()
|
||||
{
|
||||
ViewGroup parent = (ViewGroup)_inputView.getParent();
|
||||
|
||||
if (parent != null)
|
||||
parent.removeView(_inputView);
|
||||
_inputView.reset();
|
||||
return (_inputView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
||||
{
|
||||
_inputView.reset_prefs(this);
|
||||
|
@ -86,24 +86,35 @@ public class Keyboard2View extends View
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ime);
|
||||
|
||||
_ime = ime;
|
||||
try
|
||||
{
|
||||
_subValueDist = prefs.getFloat("sub_value_dist", _subValueDist);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_subValueDist = 7.0f;
|
||||
}
|
||||
_vibrateEnabled = prefs.getBoolean("vibrate_enabled", _vibrateEnabled);
|
||||
_vibrateDuration = prefs.getLong("vibrate_duration", _vibrateDuration);
|
||||
_longPressTimeout = prefs.getLong("longpress_timeout", _longPressTimeout);
|
||||
_longPressInterval = prefs.getLong("longpress_interval", _longPressInterval);
|
||||
_marginBottom = prefs.getFloat("margin_bottom", _marginBottom);
|
||||
|
||||
String keyboardLayout = prefs.getString("keyboard_layout", "azerty");
|
||||
String keyboardLayout = prefs.getString("keyboard_layout", null);
|
||||
int xmlRes = 0;
|
||||
|
||||
if (keyboardLayout.equals("azerty")) // TODO change this
|
||||
_keyboard = new KeyboardData(ime.getResources().getXml(R.xml.azerty));
|
||||
else
|
||||
_keyboard = new KeyboardData(ime.getResources().getXml(R.xml.qwerty));
|
||||
if (keyboardLayout != null)
|
||||
xmlRes = ime.getResources().getIdentifier(keyboardLayout, "xml", ime.getPackageName());
|
||||
if (xmlRes == 0)
|
||||
xmlRes = R.xml.azerty;
|
||||
_keyboard = new KeyboardData(ime.getResources().getXml(xmlRes));
|
||||
reset();
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
_flags = 0;
|
||||
_downKeys.clear();
|
||||
requestLayout();
|
||||
invalidate();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user