2015-10-29 12:49:40 +01:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
|
|
|
|
class Config
|
|
|
|
{
|
|
|
|
private Keyboard2 _context;
|
|
|
|
|
2021-05-09 00:09:10 +02:00
|
|
|
// From resources
|
2015-10-29 12:49:40 +01:00
|
|
|
public final float marginTop;
|
|
|
|
public final float keyPadding;
|
2021-04-25 00:12:16 +02:00
|
|
|
public final float keyVerticalInterval;
|
|
|
|
public final float keyHorizontalInterval;
|
2015-10-29 12:49:40 +01:00
|
|
|
public final float keyRound;
|
|
|
|
|
2021-05-09 00:09:10 +02:00
|
|
|
// From preferences
|
2021-04-28 00:23:52 +02:00
|
|
|
public int layout; // Or '-1' for the system defaults
|
2015-10-29 12:49:40 +01:00
|
|
|
public float subValueDist;
|
|
|
|
public boolean vibrateEnabled;
|
|
|
|
public long vibrateDuration;
|
|
|
|
public long longPressTimeout;
|
|
|
|
public long longPressInterval;
|
|
|
|
public float marginBottom;
|
|
|
|
public float keyHeight;
|
|
|
|
public float horizontalMargin;
|
2021-04-20 00:34:21 +02:00
|
|
|
public boolean preciseRepeat;
|
2021-04-24 23:22:25 +02:00
|
|
|
public float characterSize; // Ratio
|
2021-05-09 00:09:10 +02:00
|
|
|
public int accents; // Values are R.values.pref_accents_v_*
|
2015-10-29 12:49:40 +01:00
|
|
|
|
2021-05-09 00:09:10 +02:00
|
|
|
// Dynamically set
|
2021-04-18 00:55:31 +02:00
|
|
|
public boolean shouldOfferSwitchingToNextInputMethod;
|
2021-05-09 00:09:10 +02:00
|
|
|
public int accent_flags_to_remove;
|
2021-04-18 00:55:31 +02:00
|
|
|
|
2015-10-29 12:49:40 +01:00
|
|
|
public Config(Keyboard2 context)
|
|
|
|
{
|
|
|
|
Resources res = context.getResources();
|
|
|
|
|
|
|
|
_context = context;
|
|
|
|
// static values
|
|
|
|
marginTop = res.getDimension(R.dimen.margin_top);
|
|
|
|
keyPadding = res.getDimension(R.dimen.key_padding);
|
2021-04-25 00:12:16 +02:00
|
|
|
keyVerticalInterval = res.getDimension(R.dimen.key_vertical_interval);
|
|
|
|
keyHorizontalInterval = res.getDimension(R.dimen.key_horizontal_interval);
|
2015-10-29 12:49:40 +01:00
|
|
|
keyRound = res.getDimension(R.dimen.key_round);
|
|
|
|
// default values
|
2021-04-28 00:23:52 +02:00
|
|
|
layout = -1;
|
2015-10-29 12:49:40 +01:00
|
|
|
subValueDist = 10f;
|
|
|
|
vibrateEnabled = true;
|
|
|
|
vibrateDuration = 20;
|
|
|
|
longPressTimeout = 600;
|
|
|
|
longPressInterval = 65;
|
|
|
|
marginBottom = res.getDimension(R.dimen.margin_bottom);
|
|
|
|
keyHeight = res.getDimension(R.dimen.key_height);
|
|
|
|
horizontalMargin = res.getDimension(R.dimen.horizontal_margin);
|
2021-04-20 00:34:21 +02:00
|
|
|
preciseRepeat = true;
|
2021-04-24 23:22:25 +02:00
|
|
|
characterSize = 1.f;
|
2021-05-09 00:09:10 +02:00
|
|
|
accents = 0;
|
2015-10-29 12:49:40 +01:00
|
|
|
// from prefs
|
|
|
|
refresh();
|
2021-04-18 00:55:31 +02:00
|
|
|
// initialized later
|
|
|
|
shouldOfferSwitchingToNextInputMethod = false;
|
2021-05-09 00:09:10 +02:00
|
|
|
accent_flags_to_remove = 0;
|
2015-10-29 12:49:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Reload prefs
|
|
|
|
*/
|
|
|
|
public void refresh()
|
|
|
|
{
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context);
|
|
|
|
|
2021-04-28 00:23:52 +02:00
|
|
|
layout = layoutId_of_string(prefs.getString("layout", "system"));
|
2015-10-29 12:49:40 +01:00
|
|
|
subValueDist = prefs.getFloat("sub_value_dist", subValueDist);
|
|
|
|
vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled);
|
|
|
|
vibrateDuration = prefs.getInt("vibrate_duration", (int)vibrateDuration);
|
|
|
|
longPressTimeout = prefs.getInt("longpress_timeout", (int)longPressTimeout);
|
|
|
|
longPressInterval = prefs.getInt("longpress_interval", (int)longPressInterval);
|
|
|
|
marginBottom = getDipPref(prefs, "margin_bottom", marginBottom);
|
|
|
|
keyHeight = getDipPref(prefs, "key_height", keyHeight);
|
|
|
|
horizontalMargin = getDipPref(prefs, "horizontal_margin", horizontalMargin);
|
2021-04-20 00:34:21 +02:00
|
|
|
preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat);
|
2021-04-24 23:22:25 +02:00
|
|
|
characterSize = prefs.getFloat("character_size", characterSize);
|
2021-05-09 00:09:10 +02:00
|
|
|
accents = Integer.valueOf(prefs.getString("accents", ""));
|
2015-10-29 12:49:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private float getDipPref(SharedPreferences prefs, String pref_name, float def)
|
|
|
|
{
|
|
|
|
int value = prefs.getInt(pref_name, -1);
|
|
|
|
|
|
|
|
if (value < 0)
|
|
|
|
return (def);
|
|
|
|
return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value,
|
|
|
|
_context.getResources().getDisplayMetrics()));
|
|
|
|
}
|
2021-04-28 00:23:52 +02:00
|
|
|
|
|
|
|
public static int layoutId_of_string(String name)
|
|
|
|
{
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "azerty": return R.xml.azerty;
|
|
|
|
case "qwerty": return R.xml.qwerty;
|
|
|
|
case "system": return -1;
|
|
|
|
default: throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-09 00:09:10 +02:00
|
|
|
/* Used for the accents option. */
|
|
|
|
public static int accentFlag_of_name(String name)
|
|
|
|
{
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "grave": return KeyValue.FLAG_ACCENT1;
|
|
|
|
case "aigu": return KeyValue.FLAG_ACCENT2;
|
|
|
|
case "circonflexe": return KeyValue.FLAG_ACCENT3;
|
|
|
|
case "tilde": return KeyValue.FLAG_ACCENT4;
|
|
|
|
case "cedille": return KeyValue.FLAG_ACCENT5;
|
|
|
|
case "trema": return KeyValue.FLAG_ACCENT6;
|
|
|
|
default: throw new RuntimeException(name);
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 12:49:40 +01:00
|
|
|
}
|