Start SettingsActivity

This commit is contained in:
juloo 2015-08-08 16:47:22 +02:00
parent c29a2a9c9c
commit 153c384990
7 changed files with 108 additions and 48 deletions

View File

@ -23,6 +23,14 @@
android:resource="@xml/method" />
</service>
<activity android:name="SettingsActivity"
android:icon="@drawable/ic_launcher"
android:label="@string/settings_activity_label">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.VIBRATE" />

View File

@ -1,4 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Keyboard 2.0</string>
<string name="settings_activity_label">Keyboard 2.0 Settings</string>
<string name="pref_category_layout">Layout</string>
<string name="pref_category_typing">Typing</string>
<string name="pref_category_vibrate">Vibration</string>
<string name="pref_vibrate_text">Vibration</string>
<string name="pref_vibrate_summary">Enable/Disable vibrations</string>
<string name="pref_vibrate_duration_text">Duration</string>
<string name="pref_vibrate_duration_summary">Change vibrations duration</string>
<string name="pref_category_misc">Other</string>
</resources>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="juloo.keyboard2.SettingsActivity"
android:supportsSwitchingToNextInputMethod="true">
</input-method>

23
res/xml/settings.xml Normal file
View File

@ -0,0 +1,23 @@
<?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 -->
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_typing">
<!-- 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:summary="@string/pref_vibrate_summary"
android:defaultValue="true" />
<!-- Duration (VIBRATE_DURATION) -->
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_misc">
<!-- Keys height (_keyHeight) -->
<!-- Offset height (_marginBottom) -->
</PreferenceCategory>
</PreferenceScreen>

View File

@ -1,35 +1,35 @@
package juloo.keyboard2;
import android.content.SharedPreferences;
import android.inputmethodservice.InputMethodService;
import android.util.Log;
import android.preference.PreferenceManager;
import android.view.KeyEvent;
import android.view.View;
public class Keyboard2 extends InputMethodService
implements SharedPreferences.OnSharedPreferenceChangeListener
{
private KeyboardData _keyboardData; // TODO: settings
private Keyboard2View _inputView = null;
@Override
public void onCreate()
{
super.onCreate();
setKeyboard(R.xml.azerty);
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
_inputView = (Keyboard2View)getLayoutInflater().inflate(R.layout.input, null);
_inputView.reset_prefs(this);
}
@Override
public View onCreateInputView()
{
_inputView = (Keyboard2View)getLayoutInflater().inflate(R.layout.input, null);
_inputView.setKeyboard(this, _keyboardData);
_inputView.reset();
return (_inputView);
}
private void setKeyboard(int res)
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
_keyboardData = new KeyboardData(getResources().getXml(res));
if (_inputView != null)
_inputView.setKeyboard(this, _keyboardData);
_inputView.reset_prefs(this);
}
public void handleKeyUp(KeyValue key, int flags)
@ -38,27 +38,7 @@ public class Keyboard2 extends InputMethodService
return ;
if (key.getEventCode() == KeyValue.EVENT_CONFIG)
{
// TODO improve this shit
final CharSequence layouts[] = new CharSequence[]{"Azerty", "Qwerty"};
final int layout_res[] = new int[]{R.xml.azerty, R.xml.qwerty};
final Keyboard2 self = this;
android.app.AlertDialog dialog = new android.app.AlertDialog.Builder(this)
.setTitle("Change keyboard layout")
.setItems(layouts, new android.content.DialogInterface.OnClickListener()
{
@Override
public void onClick(android.content.DialogInterface dialog, int which)
{
self.setKeyboard(layout_res[which]);
}
})
.create();
android.view.WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.token = _inputView.getWindowToken();
lp.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dialog.show();
// TODO: go to settings activity
}
else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0)
handleMetaKeyUp(key, flags);

View File

@ -1,9 +1,11 @@
package juloo.keyboard2;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.graphics.Paint;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.os.Handler;
@ -18,15 +20,8 @@ public class Keyboard2View extends View
{
private static final float KEY_PER_ROW = 10;
private static final float SUB_VALUE_DIST = 7f; // TODO: settings
private static final boolean VIBRATE_ENABLED = true; // TODO: settings
private static final long VIBRATE_DURATION = 20; // TODO: settings
private static final long VIBRATE_MIN_INTERVAL = 100;
private static final long LONGPRESS_TIMEOUT = 600; // TODO: settings
private static final long LONGPRESS_INTERVAL = 65; // TODO: settings
private Keyboard2 _ime;
private KeyboardData _keyboard;
@ -42,13 +37,19 @@ public class Keyboard2View extends View
private float _horizontalMargin;
private float _marginTop;
private float _marginBottom; // TODO: settings
private float _keyWidth;
private float _keyHeight; // TODO: settings
private float _keyHeight;
private float _keyPadding;
private float _keyBgPadding;
private float _keyRound;
private float _subValueDist = 7f;
private boolean _vibrateEnabled = true;
private long _vibrateDuration = 20;
private long _longPressTimeout = 600;
private long _longPressInterval = 65;
private float _marginBottom;
private Paint _keyBgPaint = new Paint();
private Paint _keyDownBgPaint = new Paint();
private Paint _keyLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
@ -78,13 +79,31 @@ public class Keyboard2View extends View
_keySubLabelPaint.setColor(getResources().getColor(R.color.key_sub_label));
_keySubLabelPaint.setTextSize(getResources().getDimension(R.dimen.sublabel_text_size));
setOnTouchListener(this);
requestLayout();
}
public void setKeyboard(Keyboard2 ime, KeyboardData keyboardData)
public void reset_prefs(Keyboard2 ime)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ime);
_ime = ime;
_keyboard = keyboardData;
_subValueDist = prefs.getFloat("sub_value_dist", _subValueDist);
_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");
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));
}
public void reset()
{
_flags = 0;
requestLayout();
invalidate();
}
@ -147,7 +166,7 @@ public class Keyboard2View extends View
{
moveX -= key.downX;
moveY -= key.downY;
if ((Math.abs(moveX) + Math.abs(moveY)) < SUB_VALUE_DIST)
if ((Math.abs(moveX) + Math.abs(moveY)) < _subValueDist)
newValue = key.key.key0;
else if (moveX < 0)
newValue = (moveY < 0) ? key.key.key1 : key.key.key3;
@ -160,7 +179,7 @@ public class Keyboard2View extends View
if (key.timeoutWhat != -1)
{
_handler.removeMessages(key.timeoutWhat);
_handler.sendEmptyMessageDelayed(key.timeoutWhat, LONGPRESS_TIMEOUT);
_handler.sendEmptyMessageDelayed(key.timeoutWhat, _longPressTimeout);
}
key.value = newValue;
key.flags = newValue.getFlags();
@ -202,7 +221,7 @@ public class Keyboard2View extends View
else
{
int what = _currentWhat++;
_handler.sendEmptyMessageDelayed(what, LONGPRESS_TIMEOUT);
_handler.sendEmptyMessageDelayed(what, _longPressTimeout);
_downKeys.add(new KeyDown(pointerId, key, touchX, touchY, what));
}
vibrate();
@ -258,7 +277,7 @@ public class Keyboard2View extends View
private void vibrate()
{
if (!VIBRATE_ENABLED)
if (!_vibrateEnabled)
return ;
long now = System.currentTimeMillis();
if ((now - _lastVibration) > VIBRATE_MIN_INTERVAL)
@ -266,7 +285,7 @@ public class Keyboard2View extends View
_lastVibration = now;
try
{
_vibratorService.vibrate(VIBRATE_DURATION);
_vibratorService.vibrate(_vibrateDuration);
}
catch (Exception e)
{
@ -284,7 +303,7 @@ public class Keyboard2View extends View
{
if (key.timeoutWhat == msg.what)
{
_handler.sendEmptyMessageDelayed(msg.what, LONGPRESS_INTERVAL);
_handler.sendEmptyMessageDelayed(msg.what, _longPressInterval);
_ime.handleKeyUp(key.value, _flags);
vibrate();
return (true);

View File

@ -0,0 +1,14 @@
package juloo.keyboard2;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class SettingsActivity extends PreferenceActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}