summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavisLWebb <davislwebb@ymail.com>2014-05-04 20:14:25 -0400
committerDavisLWebb <davislwebb@ymail.com>2014-05-04 20:14:25 -0400
commite7eb3afbbb9ede50d9af36486d31c76058aeb5fd (patch)
tree592b09b135ffcc886e0e8e0d40d136354f7cdc4a
parente5ce76cc030792de5a53dc8aad3b214ab2f6538b (diff)
MY BRANCH
-rw-r--r--.settings/org.eclipse.jdt.core.prefs4
-rw-r--r--src/us/minak/Minak.java66
-rw-r--r--src/us/minak/MinakView.java180
-rw-r--r--src/us/minak/OnBackspacePressedListener.java14
-rw-r--r--src/us/minak/OnCharacterEnteredListener.java13
-rw-r--r--src/us/minak/SketchpadView.java~50
-rw-r--r--src/us/minak/SymbolsActivity.java43
7 files changed, 370 insertions, 0 deletions
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..b080d2d
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/src/us/minak/Minak.java b/src/us/minak/Minak.java
new file mode 100644
index 0000000..af2736f
--- /dev/null
+++ b/src/us/minak/Minak.java
@@ -0,0 +1,66 @@
+package us.minak;
+
+import android.inputmethodservice.InputMethodService;
+import java.util.Queue;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
+
+
+public class Minak extends InputMethodService {
+ private MinakView m_minak_view;
+
+ @Override
+ public View onCreateInputView() {
+ final MinakView minak_view = (MinakView) getLayoutInflater().inflate(R.layout.minak, null);
+
+ minak_view.setOnCharacterEnteredListener(new OnCharacterEnteredListener() {
+ @Override
+ public void characterEntered(String character) {
+ getCurrentInputConnection().commitText(character, 1);
+ }
+ });
+
+ minak_view.setOnBackspacePressedListener(new OnBackspacePressedListener() {
+ @Override
+ public void backspacePressed(boolean isLongClick) {
+ if (isLongClick) {
+ deleteLastWord();
+ } else {
+ getCurrentInputConnection().deleteSurroundingText(1, 0);
+ }
+ }
+ });
+
+ m_minak_view = minak_view;
+ return minak_view;
+ }
+
+ @Override
+ public void onStartInput(EditorInfo attribute, boolean restarting) {
+ if (m_minak_view != null) {
+ final Queue<Character> symbolsQueue = m_minak_view.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/MinakView.java b/src/us/minak/MinakView.java
new file mode 100644
index 0000000..fe8cd25
--- /dev/null
+++ b/src/us/minak/MinakView.java
@@ -0,0 +1,180 @@
+package us.minak;
+
+import android.content.Context;
+import android.widget.Button;
+import android.widget.RelativeLayout;
+import android.util.AttributeSet;
+import android.support.v4.content.LocalBroadcastManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.BroadcastReceiver;
+
+import java.util.*;
+
+public class MinakView extends RelativeLayout {
+ private final Context mContext;
+ 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 MinakView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mContext = context;
+ LocalBroadcastManager.getInstance(mContext).registerReceiver(mBroadcastReceiver,
+ new IntentFilter(SymbolsActivity.INTENT_ACTION));
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ DrawingSpaceView drawingSpaceView = (DrawingSpaceView) findViewById(R.id.drawing_space);
+ drawingSpaceView.setOnGestureRecognizedListener(new OnGestureRecognizedListener() {
+ @Override
+ 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 setOnCharacterEnteredListener(OnCharacterEnteredListener onCharacterEnteredListener) {
+ mOnCharacterEnteredListener = onCharacterEnteredListener;
+ }
+
+ 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 (SymbolsActivity.INTENT_ACTION.equals(intent.getAction())) {
+ mSymbolsQueue.add(intent.getCharExtra(SymbolsActivity.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, SymbolsActivity.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();
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/us/minak/OnBackspacePressedListener.java b/src/us/minak/OnBackspacePressedListener.java
new file mode 100644
index 0000000..8e22d13
--- /dev/null
+++ b/src/us/minak/OnBackspacePressedListener.java
@@ -0,0 +1,14 @@
+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..feaf451
--- /dev/null
+++ b/src/us/minak/OnCharacterEnteredListener.java
@@ -0,0 +1,13 @@
+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/SketchpadView.java~ b/src/us/minak/SketchpadView.java~
new file mode 100644
index 0000000..55d69fd
--- /dev/null
+++ b/src/us/minak/SketchpadView.java~
@@ -0,0 +1,50 @@
+import java.util.List;
+
+import android.gesture.Gesture;
+import android.gesture.GestureLibraries;
+import android.gesture.GestureLibrary;
+import android.gesture.GestureOverlayView;
+import android.gesture.GestureOverlayView.OnGesturePerformedListener;
+import android.gesture.Prediction;
+
+public class SketchpadView extends GestureOverlayView implements OnGesturePerformedListener{
+ //Setting score thresh hold
+ private static final double score_threshold = 3.0;
+ //loads gesture library
+ private final GestureLibrary gestureLib;
+ //used to capture drawn gestures
+ private onGestureRecognizedListener gestureRecognizer;
+
+ public SketchpadView (){
+ //not sure what to add here
+ }
+
+ public void setOnGestureRecognizedListener(OnGestureRecognizedListener onGestureRecognizedListener) {
+ gestureRecognizer = onGestureRecognizedListener;
+ }
+
+ @Override
+ public void onGesturePerformed(GestureOverlayView view, Gesture gesture){
+ //create list of predicted characters to be entered
+ List<Prediction> predictions = gestureLib.recognize(gesture);
+ Prediction bestPrediction = null;
+ //if we have a prediction
+ if(!predictions.isEmpty()){
+ //I believe that this just blidnly adds a predicted character without any checks
+ //we need to see if there is a way to actual get the best prediction
+ //if this lists them based on the best, then fuck me and ignore this/delete this
+ bestPrediction = predictions.get(0);
+ }
+ //if we have a gesture and a decent prediction
+ if(gestureRecognizer != null && bestPrediction != null){
+ //if the prediction is good enough
+ if(bestPrediction.score > score_threshold){
+ //we recognize it
+ gestureRecognizer.gestureRecognized(bestPrediction.name);
+ }else{
+ //why?
+ clear(false);
+ }
+ }
+ }
+}
diff --git a/src/us/minak/SymbolsActivity.java b/src/us/minak/SymbolsActivity.java
new file mode 100644
index 0000000..3480fa4
--- /dev/null
+++ b/src/us/minak/SymbolsActivity.java
@@ -0,0 +1,43 @@
+package us.minak;
+
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+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;
+
+/**
+ * Represents the window for choosing additional characters.
+ */
+public class SymbolsActivity 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);
+ 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);
+ 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(SymbolsActivity.this).sendBroadcast(intent);
+ }
+ });
+ }
+}