From 1a95ab399441cdf3e67d357df43f1ae1c3616ddd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 3 May 2014 22:47:09 -0400 Subject: initial commit --- src/us/minak/DrawingSpaceView.java | 60 +++++++++++++++++++++++++++ src/us/minak/IMEService.java | 33 +++++++++++++++ src/us/minak/IMEView.java | 11 +++++ src/us/minak/OnGestureRecognizedListener.java | 26 ++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 src/us/minak/DrawingSpaceView.java create mode 100644 src/us/minak/IMEService.java create mode 100644 src/us/minak/IMEView.java create mode 100644 src/us/minak/OnGestureRecognizedListener.java (limited to 'src/us') diff --git a/src/us/minak/DrawingSpaceView.java b/src/us/minak/DrawingSpaceView.java new file mode 100644 index 0000000..7f9c3fa --- /dev/null +++ b/src/us/minak/DrawingSpaceView.java @@ -0,0 +1,60 @@ +/* + ******************************************************************************** + * 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.List; + +import android.content.Context; +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; +import android.util.AttributeSet; + +/** + * Represent a space where drawing gestures are performed. + */ +public class DrawingSpaceView extends GestureOverlayView implements OnGesturePerformedListener { + private static final double SCORE_TRESHOLD = 3.0; + private final GestureLibrary mGestureLibrary; + private OnGestureRecognizedListener mOnGestureRecognizedListener; + + public DrawingSpaceView(Context context, AttributeSet attrs) { + super(context, attrs); + mGestureLibrary = GestureLibraries.fromRawResource(context, R.raw.gestures); + mGestureLibrary.load(); + addOnGesturePerformedListener(this); + } + + public void setOnGestureRecognizedListener(OnGestureRecognizedListener onGestureRecognizedListener) { + mOnGestureRecognizedListener = onGestureRecognizedListener; + } + + @Override + public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { + final List predictions = mGestureLibrary.recognize(gesture); + Prediction bestPrediction = null; + if (!predictions.isEmpty()) { + bestPrediction = predictions.get(0); + } + if (mOnGestureRecognizedListener != null && bestPrediction != null) { + if (bestPrediction.score > SCORE_TRESHOLD) { + mOnGestureRecognizedListener.gestureRecognized(bestPrediction.name); + } else { + clear(false); + } + } + } +} diff --git a/src/us/minak/IMEService.java b/src/us/minak/IMEService.java new file mode 100644 index 0000000..ba09656 --- /dev/null +++ b/src/us/minak/IMEService.java @@ -0,0 +1,33 @@ +package us.minak; + +import android.inputmethodservice.InputMethodService; +import android.view.View; +import android.view.inputmethod.EditorInfo; + +public class IMEService extends InputMethodService { + private IMEView imeView; + /** + * Loads the configuration. + */ + @Override + public void onInitializeInterface() { + // TODO + } + + @Override + public View onCreateInputView() { + final IMEView view = (IMEView) getLayoutInflater().inflate(R.layout.ime, null); + + // TODO: there probably needs to be more stuff here + + this.imeView = view; + return view; + } + + /** + * Called to inform the input method that text input has started in an editor. + */ + public void onStartInput(EditorInfo info, boolean restarting) { + // TODO: get characters from this.imeView, and pass them to getCurrentInputConnection().commitText(..., 1); + } +} diff --git a/src/us/minak/IMEView.java b/src/us/minak/IMEView.java new file mode 100644 index 0000000..89d6d0a --- /dev/null +++ b/src/us/minak/IMEView.java @@ -0,0 +1,11 @@ +package us.minak; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.RelativeLayout; + +public class IMEView extends RelativeLayout{ + public IMEView(Context context, AttributeSet attrs) { + super(context, attrs); + } +} 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); +} -- cgit v1.2.3-2-g168b