mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-25 00:33:24 +01:00
Initial commit
This commit is contained in:
commit
90167a986b
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
build.xml
|
||||
local.properties
|
||||
proguard-project.txt
|
||||
bin/*
|
||||
gen/*
|
20
AndroidManifest.xml
Normal file
20
AndroidManifest.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="juloo.keyboard2"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@drawable/ic_launcher">
|
||||
|
||||
<service android:name="Keyboard2"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_INPUT_METHOD">
|
||||
<intent-filter>
|
||||
<action android:name="android.view.InputMethod" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.view.im"
|
||||
android:resource="@xml/method" />
|
||||
</service>
|
||||
|
||||
</application>
|
||||
</manifest>
|
18
ant.properties
Normal file
18
ant.properties
Normal file
@ -0,0 +1,18 @@
|
||||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked into Version Control Systems, as it is
|
||||
# integral to the build system of your project.
|
||||
|
||||
# This file is only used by the Ant script.
|
||||
|
||||
# You can use this to override default values such as
|
||||
# 'source.dir' for the location of your java source folder and
|
||||
# 'out.dir' for the location of your output folder.
|
||||
source.dir=srcs
|
||||
|
||||
# You can also use it define how the release builds are signed by declaring
|
||||
# the following properties:
|
||||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
|
14
project.properties
Normal file
14
project.properties
Normal file
@ -0,0 +1,14 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-22
|
BIN
res/drawable-hdpi/ic_launcher.png
Normal file
BIN
res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
BIN
res/drawable-ldpi/ic_launcher.png
Normal file
BIN
res/drawable-ldpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
res/drawable-mdpi/ic_launcher.png
Normal file
BIN
res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
BIN
res/drawable-xhdpi/ic_launcher.png
Normal file
BIN
res/drawable-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
8
res/layout/input.xml
Normal file
8
res/layout/input.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<juloo.keyboard2.Keyboard2View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/keyboard2"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/bg"
|
||||
/>
|
7
res/values/colors.xml
Normal file
7
res/values/colors.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item name="bg" type="color">#111111</item>
|
||||
<item name="key_bg" type="color">#303030</item>
|
||||
<item name="key_down_bg" type="color">#000000</item>
|
||||
<item name="key_label" type="color">#BFBFBF</item>
|
||||
</resources>
|
5
res/values/strings.xml
Normal file
5
res/values/strings.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Keyboard 2.0</string>
|
||||
<string name="lol">lol</string>
|
||||
</resources>
|
39
res/xml/azerty.xml
Normal file
39
res/xml/azerty.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<keyboard>
|
||||
<row>
|
||||
<key key0="a" key2="1" />
|
||||
<key key0="z" key2="2" />
|
||||
<key key0="e" key2="3" />
|
||||
<key key0="r" key2="4" />
|
||||
<key key0="t" key2="5" />
|
||||
<key key0="y" key2="6" />
|
||||
<key key0="u" key2="7" />
|
||||
<key key0="i" key2="8" />
|
||||
<key key0="o" key2="9" />
|
||||
<key key0="p" key2="0" />
|
||||
</row>
|
||||
<row>
|
||||
<key key0="q" />
|
||||
<key key0="s" />
|
||||
<key key0="d" />
|
||||
<key key0="f" />
|
||||
<key key0="g" />
|
||||
<key key0="h" />
|
||||
<key key0="j" />
|
||||
<key key0="k" />
|
||||
<key key0="l" />
|
||||
<key key0="m" />
|
||||
</row>
|
||||
<row>
|
||||
<key key0="w" />
|
||||
<key key0="x" />
|
||||
<key key0="c" />
|
||||
<key key0="v" />
|
||||
<key key0="b" />
|
||||
<key key0="n" />
|
||||
</row>
|
||||
<row>
|
||||
<key width="4.0" key0="space" />
|
||||
<key width="1.5" key0="enter" />
|
||||
</row>
|
||||
</keyboard>
|
10
res/xml/method.xml
Normal file
10
res/xml/method.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:supportsSwitchingToNextInputMethod="true">
|
||||
<subtype
|
||||
android:label="@string/lol"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:imeSubtypeLocale="en_US"
|
||||
android:imeSubtypeMode="keyboard"
|
||||
/>
|
||||
</input-method>
|
76
srcs/juloo.keyboard2/KeyValue.java
Normal file
76
srcs/juloo.keyboard2/KeyValue.java
Normal file
@ -0,0 +1,76 @@
|
||||
package juloo.keyboard2;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import java.util.HashMap;
|
||||
|
||||
enum KeyValue
|
||||
{
|
||||
KEY_A("a", 'a'),
|
||||
KEY_B("b", 'b'),
|
||||
KEY_C("c", 'c'),
|
||||
KEY_D("d", 'd'),
|
||||
KEY_E("e", 'e'),
|
||||
KEY_F("f", 'f'),
|
||||
KEY_G("g", 'g'),
|
||||
KEY_H("h", 'h'),
|
||||
KEY_I("i", 'i'),
|
||||
KEY_J("j", 'j'),
|
||||
KEY_K("k", 'k'),
|
||||
KEY_L("l", 'l'),
|
||||
KEY_M("m", 'm'),
|
||||
KEY_N("n", 'n'),
|
||||
KEY_O("o", 'o'),
|
||||
KEY_P("p", 'p'),
|
||||
KEY_Q("q", 'q'),
|
||||
KEY_R("r", 'r'),
|
||||
KEY_S("s", 's'),
|
||||
KEY_T("t", 't'),
|
||||
KEY_U("u", 'u'),
|
||||
KEY_V("v", 'v'),
|
||||
KEY_W("w", 'w'),
|
||||
KEY_X("x", 'x'),
|
||||
KEY_Y("y", 'y'),
|
||||
KEY_Z("z", 'z'),
|
||||
KEY_0("0", '0'),
|
||||
KEY_1("1", '1'),
|
||||
KEY_2("2", '2'),
|
||||
KEY_3("3", '3'),
|
||||
KEY_4("4", '4'),
|
||||
KEY_5("5", '5'),
|
||||
KEY_6("6", '6'),
|
||||
KEY_7("7", '7'),
|
||||
KEY_8("8", '8'),
|
||||
KEY_9("9", '9');
|
||||
|
||||
private String _name;
|
||||
private char _char;
|
||||
|
||||
private KeyValue(String name, char c)
|
||||
{
|
||||
_name = name;
|
||||
_char = c;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return (_name);
|
||||
}
|
||||
|
||||
public char getChar()
|
||||
{
|
||||
return (_char);
|
||||
}
|
||||
|
||||
private static HashMap<String, KeyValue> keys = new HashMap<String, KeyValue>();
|
||||
|
||||
static
|
||||
{
|
||||
for (KeyValue k : KeyValue.values())
|
||||
keys.put(k.getName(), k);
|
||||
}
|
||||
|
||||
public static KeyValue getKeyByName(String name)
|
||||
{
|
||||
return (KeyValue.keys.get(name));
|
||||
}
|
||||
}
|
25
srcs/juloo.keyboard2/Keyboard2.java
Normal file
25
srcs/juloo.keyboard2/Keyboard2.java
Normal file
@ -0,0 +1,25 @@
|
||||
package juloo.keyboard2;
|
||||
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
public class Keyboard2 extends InputMethodService
|
||||
{
|
||||
public static final String TAG = "Keyboard_2.0";
|
||||
|
||||
private Keyboard2View _inputView;
|
||||
|
||||
@Override
|
||||
public View onCreateInputView()
|
||||
{
|
||||
_inputView = (Keyboard2View)getLayoutInflater().inflate(R.layout.input, null);
|
||||
_inputView.loadKeyboard(R.xml.azerty);
|
||||
return (_inputView);
|
||||
}
|
||||
|
||||
public static void log(String str)
|
||||
{
|
||||
Log.d(TAG, str);
|
||||
}
|
||||
}
|
276
srcs/juloo.keyboard2/Keyboard2View.java
Normal file
276
srcs/juloo.keyboard2/Keyboard2View.java
Normal file
@ -0,0 +1,276 @@
|
||||
package juloo.keyboard2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Keyboard2View extends View
|
||||
implements View.OnTouchListener
|
||||
{
|
||||
private static final float KEY_PER_ROW = 10;
|
||||
private static final float KEY_MARGIN_DPI = 2;
|
||||
private static final float KEY_PADDING_DPI = 6;
|
||||
private static final float KEY_HEIGHT_DPI = 40;
|
||||
private static final float KEY_LABEL_DPI = 16;
|
||||
private static final float KEY_SUBLABEL_DPI = 12;
|
||||
|
||||
private ArrayList<Row> _rows;
|
||||
|
||||
private float _keyWidth;
|
||||
private float _keyHeight;
|
||||
private float _keyMargin;
|
||||
private float _keyPadding;
|
||||
|
||||
private Paint _keyBgPaint;
|
||||
private Paint _keyDownBgPaint;
|
||||
private Paint _keyLabelPaint;
|
||||
private Paint _keySubLabelPaint;
|
||||
|
||||
public Keyboard2View(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
_rows = null;
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
_keyMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, KEY_MARGIN_DPI, dm);
|
||||
_keyHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, KEY_HEIGHT_DPI, dm);
|
||||
_keyPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, KEY_PADDING_DPI, dm);
|
||||
_keyWidth = (dm.widthPixels - _keyMargin) / KEY_PER_ROW - _keyMargin;
|
||||
_keyBgPaint = new Paint();
|
||||
_keyBgPaint.setColor(getResources().getColor(R.color.key_bg));
|
||||
_keyDownBgPaint = new Paint();
|
||||
_keyDownBgPaint.setColor(getResources().getColor(R.color.key_down_bg));
|
||||
_keyLabelPaint = new Paint();
|
||||
_keyLabelPaint.setColor(getResources().getColor(R.color.key_label));
|
||||
_keyLabelPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, KEY_LABEL_DPI, dm));
|
||||
_keyLabelPaint.setTextAlign(Paint.Align.CENTER);
|
||||
_keySubLabelPaint = new Paint();
|
||||
_keySubLabelPaint.setColor(getResources().getColor(R.color.key_label));
|
||||
_keySubLabelPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, KEY_SUBLABEL_DPI, dm));
|
||||
_keySubLabelPaint.setTextAlign(Paint.Align.CENTER);
|
||||
setOnTouchListener(this);
|
||||
}
|
||||
|
||||
public void loadKeyboard(int res)
|
||||
{
|
||||
XmlResourceParser parser = getContext().getResources().getXml(res);
|
||||
ArrayList<Row> rows = new ArrayList<Row>();
|
||||
|
||||
try
|
||||
{
|
||||
int status;
|
||||
|
||||
while (parser.next() != XmlResourceParser.START_TAG)
|
||||
continue ;
|
||||
if (!parser.getName().equals("keyboard"))
|
||||
throw new Exception("Unknow tag: " + parser.getName());
|
||||
while ((status = parser.next()) != XmlResourceParser.END_DOCUMENT)
|
||||
{
|
||||
if (status == XmlResourceParser.START_TAG)
|
||||
{
|
||||
String tag = parser.getName();
|
||||
if (tag.equals("row"))
|
||||
rows.add(new Row(parser, _keyWidth, _keyMargin));
|
||||
else
|
||||
throw new Exception("Unknow keyboard tag: " + tag);
|
||||
}
|
||||
}
|
||||
_rows = rows;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event)
|
||||
{
|
||||
String log;
|
||||
|
||||
log = "Action: ";
|
||||
switch (event.getAction())
|
||||
{
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
log += "NEW POINTER DOWN";
|
||||
break ;
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
log += "NEW POINTER UP";
|
||||
break ;
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
log += "DOWN";
|
||||
break ;
|
||||
case MotionEvent.ACTION_UP:
|
||||
log += "UP";
|
||||
break ;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
log += "MOVE";
|
||||
break ;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
log += "CANCEL";
|
||||
break ;
|
||||
default:
|
||||
log += "UNKNOW";
|
||||
break ;
|
||||
}
|
||||
for (int p = 0; p < event.getPointerCount(); p++)
|
||||
{
|
||||
log += ", P#";
|
||||
log += String.valueOf(p);
|
||||
log += ": ";
|
||||
log += String.valueOf(event.getX(p));
|
||||
log += "/";
|
||||
log += String.valueOf(event.getY(p));
|
||||
}
|
||||
Keyboard2.log(log);
|
||||
return (true);
|
||||
}
|
||||
|
||||
private Key getKeyAt(float at_x, float at_y)
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
|
||||
y = _keyMargin;
|
||||
for (Row row : _rows)
|
||||
{
|
||||
x = (KEY_PER_ROW * (_keyMargin + _keyWidth) - _keyMargin - row.getWidth()) / 2 + _keyMargin;
|
||||
for (Key k : row)
|
||||
{
|
||||
float keyW = _keyWidth * k.width;
|
||||
if (at_x >= x && at_x < (x + keyW)
|
||||
&& at_y >= y && at_y < (y + _keyHeight))
|
||||
return (k);
|
||||
x += keyW + _keyMargin;
|
||||
}
|
||||
y += _keyHeight + _keyMargin;
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeasure(int wSpec, int hSpec)
|
||||
{
|
||||
int height;
|
||||
|
||||
if (_rows == null)
|
||||
height = 0;
|
||||
else
|
||||
height = (int)((_keyHeight + _keyMargin) * (float)_rows.size() + _keyMargin);
|
||||
setMeasuredDimension(MeasureSpec.getSize(wSpec), height);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas)
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
|
||||
if (_rows == null)
|
||||
return ;
|
||||
y = _keyMargin;
|
||||
for (Row row : _rows)
|
||||
{
|
||||
x = (KEY_PER_ROW * (_keyMargin + _keyWidth) - _keyMargin - row.getWidth()) / 2 + _keyMargin;
|
||||
for (Key k : row)
|
||||
{
|
||||
float keyW = _keyWidth * k.width;
|
||||
if (k.down)
|
||||
canvas.drawRect(x, y, x + keyW, y + _keyHeight, _keyBgPaint);
|
||||
else
|
||||
canvas.drawRect(x, y, x + keyW, y + _keyHeight, _keyDownBgPaint);
|
||||
if (k.key0 != null)
|
||||
canvas.drawText(new char[]{k.key0.getChar()}, 0, 1,
|
||||
keyW / 2 + x, (_keyHeight + _keyLabelPaint.getTextSize()) / 2 + y, _keyLabelPaint);
|
||||
if (k.key1 != null)
|
||||
canvas.drawText(new char[]{k.key1.getChar()}, 0, 1,
|
||||
x + _keyPadding, y + _keyPadding, _keySubLabelPaint);
|
||||
if (k.key2 != null)
|
||||
canvas.drawText(new char[]{k.key2.getChar()}, 0, 1,
|
||||
x + keyW - _keyPadding, y + _keyPadding, _keySubLabelPaint);
|
||||
if (k.key3 != null)
|
||||
canvas.drawText(new char[]{k.key3.getChar()}, 0, 1,
|
||||
x + _keyPadding, y + _keyHeight - _keyPadding, _keySubLabelPaint);
|
||||
if (k.key4 != null)
|
||||
canvas.drawText(new char[]{k.key4.getChar()}, 0, 1,
|
||||
x + keyW - _keyPadding, y + _keyHeight - _keyPadding, _keySubLabelPaint);
|
||||
x += keyW + _keyMargin;
|
||||
}
|
||||
y += _keyHeight + _keyMargin;
|
||||
}
|
||||
}
|
||||
|
||||
private class Row extends ArrayList<Key>
|
||||
{
|
||||
private float _width;
|
||||
|
||||
public Row(XmlResourceParser parser, float keyWidth, float keyMargin) throws Exception
|
||||
{
|
||||
super();
|
||||
|
||||
int status;
|
||||
_width = 0;
|
||||
while ((status = parser.next()) != XmlResourceParser.END_TAG)
|
||||
{
|
||||
if (status == XmlResourceParser.START_TAG)
|
||||
{
|
||||
String tag = parser.getName();
|
||||
if (tag.equals("key"))
|
||||
{
|
||||
Key k = new Key(parser);
|
||||
if (_width != 0f)
|
||||
_width += keyMargin;
|
||||
_width += keyWidth * k.width;
|
||||
add(k);
|
||||
}
|
||||
else
|
||||
throw new Exception("Unknow row tag: " + tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float getWidth()
|
||||
{
|
||||
return (_width);
|
||||
}
|
||||
}
|
||||
|
||||
private class Key
|
||||
{
|
||||
public KeyValue key0;
|
||||
public KeyValue key1;
|
||||
public KeyValue key2;
|
||||
public KeyValue key3;
|
||||
public KeyValue key4;
|
||||
|
||||
public float width;
|
||||
|
||||
public boolean down;
|
||||
|
||||
public Key(XmlResourceParser parser) throws Exception
|
||||
{
|
||||
down = false;
|
||||
key0 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key0"));
|
||||
key1 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key1"));
|
||||
key2 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key2"));
|
||||
key3 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key3"));
|
||||
key4 = KeyValue.getKeyByName(parser.getAttributeValue(null, "key4"));
|
||||
try
|
||||
{
|
||||
width = parser.getAttributeFloatValue(null, "width", 1f);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
width = 1f;
|
||||
}
|
||||
while (parser.next() != XmlResourceParser.END_TAG)
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user