mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-26 04:32:25 +02:00
Start SettingsActivity
This commit is contained in:
parent
c29a2a9c9c
commit
153c384990
@ -23,6 +23,14 @@
|
|||||||
android:resource="@xml/method" />
|
android:resource="@xml/method" />
|
||||||
</service>
|
</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>
|
</application>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
@ -1,4 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Keyboard 2.0</string>
|
<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>
|
</resources>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
|
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:settingsActivity="juloo.keyboard2.SettingsActivity"
|
||||||
android:supportsSwitchingToNextInputMethod="true">
|
android:supportsSwitchingToNextInputMethod="true">
|
||||||
</input-method>
|
</input-method>
|
||||||
|
23
res/xml/settings.xml
Normal file
23
res/xml/settings.xml
Normal 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>
|
@ -1,35 +1,35 @@
|
|||||||
package juloo.keyboard2;
|
package juloo.keyboard2;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.inputmethodservice.InputMethodService;
|
import android.inputmethodservice.InputMethodService;
|
||||||
import android.util.Log;
|
import android.preference.PreferenceManager;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
public class Keyboard2 extends InputMethodService
|
public class Keyboard2 extends InputMethodService
|
||||||
|
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||||
{
|
{
|
||||||
private KeyboardData _keyboardData; // TODO: settings
|
|
||||||
private Keyboard2View _inputView = null;
|
private Keyboard2View _inputView = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
{
|
{
|
||||||
super.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
|
@Override
|
||||||
public View onCreateInputView()
|
public View onCreateInputView()
|
||||||
{
|
{
|
||||||
_inputView = (Keyboard2View)getLayoutInflater().inflate(R.layout.input, null);
|
_inputView.reset();
|
||||||
_inputView.setKeyboard(this, _keyboardData);
|
|
||||||
return (_inputView);
|
return (_inputView);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setKeyboard(int res)
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
||||||
{
|
{
|
||||||
_keyboardData = new KeyboardData(getResources().getXml(res));
|
_inputView.reset_prefs(this);
|
||||||
if (_inputView != null)
|
|
||||||
_inputView.setKeyboard(this, _keyboardData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleKeyUp(KeyValue key, int flags)
|
public void handleKeyUp(KeyValue key, int flags)
|
||||||
@ -38,27 +38,7 @@ public class Keyboard2 extends InputMethodService
|
|||||||
return ;
|
return ;
|
||||||
if (key.getEventCode() == KeyValue.EVENT_CONFIG)
|
if (key.getEventCode() == KeyValue.EVENT_CONFIG)
|
||||||
{
|
{
|
||||||
// TODO improve this shit
|
// TODO: go to settings activity
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0)
|
else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0)
|
||||||
handleMetaKeyUp(key, flags);
|
handleMetaKeyUp(key, flags);
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package juloo.keyboard2;
|
package juloo.keyboard2;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.os.Handler;
|
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 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 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 Keyboard2 _ime;
|
||||||
private KeyboardData _keyboard;
|
private KeyboardData _keyboard;
|
||||||
|
|
||||||
@ -42,13 +37,19 @@ public class Keyboard2View extends View
|
|||||||
|
|
||||||
private float _horizontalMargin;
|
private float _horizontalMargin;
|
||||||
private float _marginTop;
|
private float _marginTop;
|
||||||
private float _marginBottom; // TODO: settings
|
|
||||||
private float _keyWidth;
|
private float _keyWidth;
|
||||||
private float _keyHeight; // TODO: settings
|
private float _keyHeight;
|
||||||
private float _keyPadding;
|
private float _keyPadding;
|
||||||
private float _keyBgPadding;
|
private float _keyBgPadding;
|
||||||
private float _keyRound;
|
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 _keyBgPaint = new Paint();
|
||||||
private Paint _keyDownBgPaint = new Paint();
|
private Paint _keyDownBgPaint = new Paint();
|
||||||
private Paint _keyLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
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.setColor(getResources().getColor(R.color.key_sub_label));
|
||||||
_keySubLabelPaint.setTextSize(getResources().getDimension(R.dimen.sublabel_text_size));
|
_keySubLabelPaint.setTextSize(getResources().getDimension(R.dimen.sublabel_text_size));
|
||||||
setOnTouchListener(this);
|
setOnTouchListener(this);
|
||||||
requestLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyboard(Keyboard2 ime, KeyboardData keyboardData)
|
public void reset_prefs(Keyboard2 ime)
|
||||||
{
|
{
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ime);
|
||||||
|
|
||||||
_ime = 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();
|
requestLayout();
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
@ -147,7 +166,7 @@ public class Keyboard2View extends View
|
|||||||
{
|
{
|
||||||
moveX -= key.downX;
|
moveX -= key.downX;
|
||||||
moveY -= key.downY;
|
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;
|
newValue = key.key.key0;
|
||||||
else if (moveX < 0)
|
else if (moveX < 0)
|
||||||
newValue = (moveY < 0) ? key.key.key1 : key.key.key3;
|
newValue = (moveY < 0) ? key.key.key1 : key.key.key3;
|
||||||
@ -160,7 +179,7 @@ public class Keyboard2View extends View
|
|||||||
if (key.timeoutWhat != -1)
|
if (key.timeoutWhat != -1)
|
||||||
{
|
{
|
||||||
_handler.removeMessages(key.timeoutWhat);
|
_handler.removeMessages(key.timeoutWhat);
|
||||||
_handler.sendEmptyMessageDelayed(key.timeoutWhat, LONGPRESS_TIMEOUT);
|
_handler.sendEmptyMessageDelayed(key.timeoutWhat, _longPressTimeout);
|
||||||
}
|
}
|
||||||
key.value = newValue;
|
key.value = newValue;
|
||||||
key.flags = newValue.getFlags();
|
key.flags = newValue.getFlags();
|
||||||
@ -202,7 +221,7 @@ public class Keyboard2View extends View
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int what = _currentWhat++;
|
int what = _currentWhat++;
|
||||||
_handler.sendEmptyMessageDelayed(what, LONGPRESS_TIMEOUT);
|
_handler.sendEmptyMessageDelayed(what, _longPressTimeout);
|
||||||
_downKeys.add(new KeyDown(pointerId, key, touchX, touchY, what));
|
_downKeys.add(new KeyDown(pointerId, key, touchX, touchY, what));
|
||||||
}
|
}
|
||||||
vibrate();
|
vibrate();
|
||||||
@ -258,7 +277,7 @@ public class Keyboard2View extends View
|
|||||||
|
|
||||||
private void vibrate()
|
private void vibrate()
|
||||||
{
|
{
|
||||||
if (!VIBRATE_ENABLED)
|
if (!_vibrateEnabled)
|
||||||
return ;
|
return ;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if ((now - _lastVibration) > VIBRATE_MIN_INTERVAL)
|
if ((now - _lastVibration) > VIBRATE_MIN_INTERVAL)
|
||||||
@ -266,7 +285,7 @@ public class Keyboard2View extends View
|
|||||||
_lastVibration = now;
|
_lastVibration = now;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_vibratorService.vibrate(VIBRATE_DURATION);
|
_vibratorService.vibrate(_vibrateDuration);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -284,7 +303,7 @@ public class Keyboard2View extends View
|
|||||||
{
|
{
|
||||||
if (key.timeoutWhat == msg.what)
|
if (key.timeoutWhat == msg.what)
|
||||||
{
|
{
|
||||||
_handler.sendEmptyMessageDelayed(msg.what, LONGPRESS_INTERVAL);
|
_handler.sendEmptyMessageDelayed(msg.what, _longPressInterval);
|
||||||
_ime.handleKeyUp(key.value, _flags);
|
_ime.handleKeyUp(key.value, _flags);
|
||||||
vibrate();
|
vibrate();
|
||||||
return (true);
|
return (true);
|
||||||
|
14
srcs/juloo.keyboard2/SettingsActivity.java
Normal file
14
srcs/juloo.keyboard2/SettingsActivity.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user