diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-05 23:43:01 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-05 23:50:13 -0400 |
commit | 15f9095ae8bf3b652de886a28275c71efaab1ac5 (patch) | |
tree | 0700f80dd47576558018cfdaa61664623f500b7d | |
parent | f3af08d258a7ae372192fe38ffb64a489584d554 (diff) |
Transplant in the code from Penboard, just to have something working.
The diff of this commit will likely be helpful.
-rw-r--r-- | AndroidManifest.xml | 7 | ||||
-rw-r--r-- | res/layout/ime.xml | 46 | ||||
-rw-r--r-- | res/layout/symbols.xml | 17 | ||||
-rw-r--r-- | src/us/minak/IMEGestureOverlayView.java | 10 | ||||
-rw-r--r-- | src/us/minak/IMEService.java | 71 | ||||
-rw-r--r-- | src/us/minak/IMESymbolsActivity.java (renamed from src/us/minak/SketchPadActivity.java) | 37 | ||||
-rw-r--r-- | src/us/minak/IMEView.java | 174 | ||||
-rw-r--r-- | src/us/minak/OnBackspacePressedListener.java | 26 | ||||
-rw-r--r-- | src/us/minak/OnCharacterEnteredListener.java | 26 | ||||
-rw-r--r-- | src/us/minak/OnGestureRecognizedListener.java | 26 |
10 files changed, 397 insertions, 43 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b16718d..fe5bd1c 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -42,6 +42,13 @@ android:name="SettingsCreateGestureActivity" android:label="@string/label_create_gesture" /> + <!-- The insert-symbol dialog from Penboard --> + <activity + android:name="IMESymbolsActivity" + android:configChanges="orientation|keyboardHidden" + android:screenOrientation="portrait" + android:theme="@android:style/Theme.Dialog" > + </activity> </application> </manifest> diff --git a/res/layout/ime.xml b/res/layout/ime.xml index 7ef50a1..ddabd0c 100644 --- a/res/layout/ime.xml +++ b/res/layout/ime.xml @@ -3,11 +3,35 @@ android:layout_width="match_parent" android:layout_height="match_parent" > + <LinearLayout + android:id="@+id/left_panel" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:orientation="vertical" > + + <Button + android:id="@+id/symbols_btn" + android:layout_width="85dp" + android:layout_height="85dp" + android:layout_marginBottom="5dp" + android:layout_marginTop="10dp" /> + + <Button + android:id="@+id/shift_btn" + android:layout_width="85dp" + android:layout_height="85dp" + android:layout_marginBottom="10dp" + android:layout_marginTop="5dp" /> + </LinearLayout> + <us.minak.IMEGestureOverlayView android:id="@+id/drawing_space" android:layout_width="wrap_content" android:layout_height="200dp" android:layout_centerInParent="true" + android:layout_toLeftOf="@+id/right_panel" + android:layout_toRightOf="@+id/left_panel" android:fadeDuration="300" android:fadeEnabled="true" android:fadeOffset="200" @@ -17,4 +41,26 @@ android:gestureStrokeSquarenessThreshold="0.0" android:gestureStrokeType="multiple" /> + <LinearLayout + android:id="@+id/right_panel" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:orientation="vertical" > + + <Button + android:id="@+id/backspace_btn" + android:layout_width="85dp" + android:layout_height="85dp" + android:layout_marginBottom="5dp" + android:layout_marginTop="10dp" /> + + <Button + android:id="@+id/space_btn" + android:layout_width="85dp" + android:layout_height="85dp" + android:layout_marginBottom="10dp" + android:layout_marginTop="5dp" /> + </LinearLayout> + </us.minak.IMEView> diff --git a/res/layout/symbols.xml b/res/layout/symbols.xml new file mode 100644 index 0000000..2fa1a71 --- /dev/null +++ b/res/layout/symbols.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="400dp" + android:background="@android:color/transparent" + android:orientation="horizontal" > + + <GridView + android:id="@+id/symbols_gridview" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:columnWidth="40dp" + android:gravity="center" + android:numColumns="auto_fit" + android:stretchMode="columnWidth" /> + +</LinearLayout> diff --git a/src/us/minak/IMEGestureOverlayView.java b/src/us/minak/IMEGestureOverlayView.java index fed2bf1..9d98164 100644 --- a/src/us/minak/IMEGestureOverlayView.java +++ b/src/us/minak/IMEGestureOverlayView.java @@ -28,7 +28,7 @@ import android.util.AttributeSet; public class IMEGestureOverlayView extends GestureOverlayView implements OnGesturePerformedListener { private static final double SCORE_TRESHOLD = 3.0; private final GestureLibrary mGestureLibrary; - private StringReciever mOutput; + private OnGestureRecognizedListener mOnGestureRecognizedListener; public IMEGestureOverlayView(Context context, AttributeSet attrs) { super(context, attrs); @@ -37,8 +37,8 @@ public class IMEGestureOverlayView extends GestureOverlayView implements OnGestu addOnGesturePerformedListener(this); } - public void setOutput(StringReciever output) { - mOutput = output; + public void setOnGestureRecognizedListener(OnGestureRecognizedListener onGestureRecognizedListener) { + mOnGestureRecognizedListener = onGestureRecognizedListener; } @Override @@ -48,9 +48,9 @@ public class IMEGestureOverlayView extends GestureOverlayView implements OnGestu if (!predictions.isEmpty()) { bestPrediction = predictions.get(0); } - if (mOutput != null && bestPrediction != null) { + if (mOnGestureRecognizedListener != null && bestPrediction != null) { if (bestPrediction.score > SCORE_TRESHOLD) { - mOutput.putString(bestPrediction.name); + mOnGestureRecognizedListener.gestureRecognized(bestPrediction.name); } else { clear(false); } diff --git a/src/us/minak/IMEService.java b/src/us/minak/IMEService.java index acbe616..b99859c 100644 --- a/src/us/minak/IMEService.java +++ b/src/us/minak/IMEService.java @@ -1,3 +1,15 @@ +/* + ******************************************************************************** + * Copyright (c) 2012 Samsung Electronics, Inc. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Inc. ("Confidential Information"). You shall not disclose such + * Confidential Information and shall use it only in accordance with the terms + * of the license agreement you entered into with Samsung Electronics. + ******************************************************************************** + */ + package us.minak; import java.util.Queue; @@ -6,39 +18,64 @@ import android.inputmethodservice.InputMethodService; import android.view.View; import android.view.inputmethod.EditorInfo; +/** + * Represent the application input service. + */ public class IMEService extends InputMethodService { - /** - * Loads the configuration. - */ - @Override - public void onInitializeInterface() { - // TODO - } + private IMEView mPenboardView; @Override public View onCreateInputView() { - final IMEView view = (IMEView) getLayoutInflater().inflate(R.layout.ime, null); + final IMEView penboardView = (IMEView) getLayoutInflater().inflate(R.layout.ime, null); - view.setOutput(new StringReciever() { + penboardView.setOnCharacterEnteredListener(new OnCharacterEnteredListener() { @Override - public void putString(String character) { + public void characterEntered(String character) { getCurrentInputConnection().commitText(character, 1); } }); - return view; + penboardView.setOnBackspacePressedListener(new OnBackspacePressedListener() { + @Override + public void backspacePressed(boolean isLongClick) { + if (isLongClick) { + deleteLastWord(); + } else { + getCurrentInputConnection().deleteSurroundingText(1, 0); + } + } + }); + + mPenboardView = penboardView; + return penboardView; } - /** - * Called to inform the input method that text input has started in an editor. - */ - public void onStartInput(EditorInfo info, boolean restarting) { - if (imeView != null) { - final Queue<Character> symbolsQueue = imeView.getSymbolsQueue(); + @Override + public void onStartInput(EditorInfo attribute, boolean restarting) { + if (mPenboardView != null) { + final Queue<Character> symbolsQueue = mPenboardView.getSymbolsQueue(); while (!symbolsQueue.isEmpty()) { final Character character = symbolsQueue.poll(); getCurrentInputConnection().commitText(String.valueOf(character), 1); } } } + + /** + * Deletes one word before the cursor. + */ + private void deleteLastWord() { + final int charactersToGet = 20; + final String splitRegexp = " "; + + // delete trailing spaces + while (getCurrentInputConnection().getTextBeforeCursor(1, 0).toString().equals(splitRegexp)) { + getCurrentInputConnection().deleteSurroundingText(1, 0); + } + + // delete last word letters + final String[] words = getCurrentInputConnection().getTextBeforeCursor(charactersToGet, 0).toString() + .split(splitRegexp); + getCurrentInputConnection().deleteSurroundingText(words[words.length - 1].length(), 0); + } } diff --git a/src/us/minak/SketchPadActivity.java b/src/us/minak/IMESymbolsActivity.java index b415718..39f1849 100644 --- a/src/us/minak/SketchPadActivity.java +++ b/src/us/minak/IMESymbolsActivity.java @@ -1,3 +1,14 @@ +/* + ******************************************************************************** + * Copyright (c) 2012 Samsung Electronics, Inc. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Inc. ("Confidential Information"). You shall not disclose such + * Confidential Information and shall use it only in accordance with the terms + * of the license agreement you entered into with Samsung Electronics. + ******************************************************************************** + */ package us.minak; @@ -8,32 +19,36 @@ import android.support.v4.content.LocalBroadcastManager; import android.view.View; import android.view.Window; import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.GridView; -import android.widget.AdapterView.OnItemClickListener; -public class SketchPadActivity extends Activity { - public static final String INTENT_ACTION = "us.minak.SYMBOL_ENTERED"; +/** + * Represents the window for choosing additional characters. + */ +public class IMESymbolsActivity extends Activity { + public static final String INTENT_ACTION = "com.samsung.penboard.SYMBOL_ENTERED"; public static final String INTENT_EXTRA_NAME = "symbol"; private static final Character[] SYMBOLS = new Character[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', - '@', '#', '$', '%', '^', '&', '*', '(', ')', '`', '-', '=', '~', '_', '+', '[', ']', '\\', '{', '}', '|', - ';', '\'', ':', '\'', ',', '.', '/', '<', '>', '?' }; - + '@', '#', '$', '%', '^', '&', '*', '(', ')', '`', '-', '=', '~', '_', '+', '[', ']', '\\', '{', '}', '|', + ';', '\'', ':', '\'', ',', '.', '/', '<', '>', '?' }; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); - /*setContentView(R.layout.symbols); + setContentView(R.layout.symbols); final GridView gridView = (GridView) findViewById(R.id.symbols_gridview); - final ArrayAdapter<Character> adapter = new ArrayAdapter<Character>(this, android.R.layout.simple_list_item_1, SYMBOLS); + final ArrayAdapter<Character> adapter = new ArrayAdapter<Character>(this, android.R.layout.simple_list_item_1, + SYMBOLS); gridView.setAdapter(adapter); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Intent intent = new Intent(INTENT_ACTION); intent.putExtra(INTENT_EXTRA_NAME, SYMBOLS[position]); - LocalBroadcastManager.getInstance(SketchPadActivity.this).sendBroadcast(intent); + LocalBroadcastManager.getInstance(IMESymbolsActivity.this).sendBroadcast(intent); } - });*/ + }); } -}
\ No newline at end of file +} diff --git a/src/us/minak/IMEView.java b/src/us/minak/IMEView.java index 5c70a48..4a3ec4e 100644 --- a/src/us/minak/IMEView.java +++ b/src/us/minak/IMEView.java @@ -1,42 +1,196 @@ +/* + ******************************************************************************** + * Copyright (c) 2012 Samsung Electronics, Inc. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Inc. ("Confidential Information"). You shall not disclose such + * Confidential Information and shall use it only in accordance with the terms + * of the license agreement you entered into with Samsung Electronics. + ******************************************************************************** + */ + package us.minak; import java.util.LinkedList; +import java.util.Locale; import java.util.Queue; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.support.v4.content.LocalBroadcastManager; import android.util.AttributeSet; +import android.view.View; +import android.widget.Button; import android.widget.RelativeLayout; -public class IMEView extends RelativeLayout{ - private StringReciever mOutput; +/** + * Represents the container for the drawing space and the two side panels. + */ +public class IMEView extends RelativeLayout { private final Context mContext; - private final Queue<Character> mSymbolsQueue = new LinkedList<Character>(); private OnCharacterEnteredListener mOnCharacterEnteredListener; + private OnBackspacePressedListener mOnBackspacePressedListener; + private Button mShiftButton; + private ShiftState mShiftState = ShiftState.OFF; + private final Queue<Character> mSymbolsQueue = new LinkedList<Character>(); + + private enum ShiftState { + OFF, ON, CAPS_LOCK + }; public IMEView(Context context, AttributeSet attrs) { super(context, attrs); + mContext = context; + LocalBroadcastManager.getInstance(mContext).registerReceiver(mBroadcastReceiver, + new IntentFilter(IMESymbolsActivity.INTENT_ACTION)); } @Override protected void onFinishInflate() { IMEGestureOverlayView drawingSpaceView = (IMEGestureOverlayView) findViewById(R.id.drawing_space); - drawingSpaceView.setOutput(new StringReciever() { + drawingSpaceView.setOnGestureRecognizedListener(new OnGestureRecognizedListener() { @Override - public void putString(String character) { enterCharacter(character); } + public void gestureRecognized(String character) { + enterCharacter(character); + } }); + + final Button symbolsButton = (Button) findViewById(R.id.symbols_btn); + symbolsButton.setOnClickListener(mButtonClickListener); + symbolsButton.setOnLongClickListener(mButtonLongClickListener); + + mShiftButton = (Button) findViewById(R.id.shift_btn); + mShiftButton.setOnClickListener(mButtonClickListener); + mShiftButton.setOnLongClickListener(mButtonLongClickListener); + + final Button backspaceButton = (Button) findViewById(R.id.backspace_btn); + backspaceButton.setOnClickListener(mButtonClickListener); + backspaceButton.setOnLongClickListener(mButtonLongClickListener); + + final Button spaceButton = (Button) findViewById(R.id.space_btn); + spaceButton.setOnClickListener(mButtonClickListener); + spaceButton.setOnLongClickListener(mButtonLongClickListener); } - public void setOutput(StringReciever output) { - mOutput = output; + public void setOnCharacterEnteredListener(OnCharacterEnteredListener onCharacterEnteredListener) { + mOnCharacterEnteredListener = onCharacterEnteredListener; } - private void enterCharacter(String character) { - if (mOutput != null) - mOutput.putString(character); + public void setOnBackspacePressedListener(OnBackspacePressedListener onBackspacePressedListener) { + mOnBackspacePressedListener = onBackspacePressedListener; } public Queue<Character> getSymbolsQueue() { return mSymbolsQueue; } + /** + * Receiver for broadcasts coming from the symbols activity. + */ + private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (IMESymbolsActivity.INTENT_ACTION.equals(intent.getAction())) { + mSymbolsQueue.add(intent.getCharExtra(IMESymbolsActivity.INTENT_EXTRA_NAME, '?')); + } + } + }; + + /** + * Listener handling pressing all buttons. + */ + private final OnClickListener mButtonClickListener = new OnClickListener() { + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.symbols_btn: + final Intent intent = new Intent(mContext, IMESymbolsActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); + break; + case R.id.shift_btn: + shift(); + break; + case R.id.backspace_btn: + mOnBackspacePressedListener.backspacePressed(false); + break; + case R.id.space_btn: + mOnCharacterEnteredListener.characterEntered(" "); + break; + default: + throw new IllegalArgumentException(); + } + } + }; + + /** + * Listener handling long pressing all buttons. + */ + private final OnLongClickListener mButtonLongClickListener = new OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + switch (v.getId()) { + case R.id.symbols_btn: + case R.id.shift_btn: + break; + case R.id.backspace_btn: + mOnBackspacePressedListener.backspacePressed(true); + return true; + case R.id.space_btn: + break; + default: + throw new IllegalArgumentException(); + } + + return false; + } + }; + + /** + * Changes shift state to the next one (OFF -> ON -> CAPS LOCK). + */ + private void shift() { + switch (mShiftState) { + case OFF: + mShiftState = ShiftState.ON; + //mShiftButton.setBackgroundResource(R.drawable.shift_on); + break; + case ON: + mShiftState = ShiftState.CAPS_LOCK; + //mShiftButton.setBackgroundResource(R.drawable.shift_caps_lock); + break; + case CAPS_LOCK: + mShiftState = ShiftState.OFF; + //mShiftButton.setBackgroundResource(R.drawable.shift_off); + break; + default: + throw new IllegalArgumentException(); + } + } + + /** + * Passes the given character to the input service. + * + * @param character + * The character to enter + */ + private void enterCharacter(String character) { + switch (mShiftState) { + case OFF: + mOnCharacterEnteredListener.characterEntered(character); + break; + case ON: + mOnCharacterEnteredListener.characterEntered(character.toUpperCase(Locale.ENGLISH)); + shift(); + break; + case CAPS_LOCK: + mOnCharacterEnteredListener.characterEntered(character.toUpperCase(Locale.ENGLISH)); + break; + default: + throw new IllegalArgumentException(); + } + } } diff --git a/src/us/minak/OnBackspacePressedListener.java b/src/us/minak/OnBackspacePressedListener.java new file mode 100644 index 0000000..b4cf974 --- /dev/null +++ b/src/us/minak/OnBackspacePressedListener.java @@ -0,0 +1,26 @@ +/* + ******************************************************************************** + * Copyright (c) 2012 Samsung Electronics, Inc. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Inc. ("Confidential Information"). You shall not disclose such + * Confidential Information and shall use it only in accordance with the terms + * of the license agreement you entered into with Samsung Electronics. + ******************************************************************************** + */ + +package us.minak; + +/** + * A simple interface for handling pressing the backspace button. + */ +public interface OnBackspacePressedListener { + /** + * Invoked when the backspace button is pressed. + * + * @param isLongClick + * if the button is long pressed + */ + void backspacePressed(boolean isLongClick); +} diff --git a/src/us/minak/OnCharacterEnteredListener.java b/src/us/minak/OnCharacterEnteredListener.java new file mode 100644 index 0000000..31b76e9 --- /dev/null +++ b/src/us/minak/OnCharacterEnteredListener.java @@ -0,0 +1,26 @@ +/* + ******************************************************************************** + * Copyright (c) 2012 Samsung Electronics, Inc. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Inc. ("Confidential Information"). You shall not disclose such + * Confidential Information and shall use it only in accordance with the terms + * of the license agreement you entered into with Samsung Electronics. + ******************************************************************************** + */ + +package us.minak; + +/** + * A simple interface for handling entering a character. + */ +public interface OnCharacterEnteredListener { + /** + * Invoked when a character is entered. + * + * @param character + * The entered character + */ + void characterEntered(String character); +} diff --git a/src/us/minak/OnGestureRecognizedListener.java b/src/us/minak/OnGestureRecognizedListener.java new file mode 100644 index 0000000..a30e8b8 --- /dev/null +++ b/src/us/minak/OnGestureRecognizedListener.java @@ -0,0 +1,26 @@ +/* + ******************************************************************************** + * Copyright (c) 2012 Samsung Electronics, Inc. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Inc. ("Confidential Information"). You shall not disclose such + * Confidential Information and shall use it only in accordance with the terms + * of the license agreement you entered into with Samsung Electronics. + ******************************************************************************** + */ + +package us.minak; + +/** + * A simple interface for handling recognizing a gesture. + */ +public interface OnGestureRecognizedListener { + /** + * Invoked when a gesture is recognized. + * + * @param character + * The character represented by the gesture. + */ + void gestureRecognized(String character); +} |