summaryrefslogtreecommitdiff
path: root/src/us
diff options
context:
space:
mode:
Diffstat (limited to 'src/us')
-rw-r--r--src/us/minak/IMEGestureOverlayView.java (renamed from src/us/minak/DrawingSpaceView.java)17
-rw-r--r--src/us/minak/IMEService.java14
-rw-r--r--src/us/minak/IMEView.java18
-rw-r--r--src/us/minak/OnCharacterEnteredListener.java5
-rw-r--r--src/us/minak/OnGestureRecognizedListener.java26
-rw-r--r--src/us/minak/SettingsActivity.java249
-rw-r--r--src/us/minak/SettingsCreateGestureActivity.java (renamed from src/us/minak/CreateGestureActivity.java)22
-rw-r--r--src/us/minak/SettingsUtil.java25
-rw-r--r--src/us/minak/StringReciever.java5
9 files changed, 116 insertions, 265 deletions
diff --git a/src/us/minak/DrawingSpaceView.java b/src/us/minak/IMEGestureOverlayView.java
index 7f9c3fa..fed2bf1 100644
--- a/src/us/minak/DrawingSpaceView.java
+++ b/src/us/minak/IMEGestureOverlayView.java
@@ -16,7 +16,6 @@ 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;
@@ -26,20 +25,20 @@ import android.util.AttributeSet;
/**
* Represent a space where drawing gestures are performed.
*/
-public class DrawingSpaceView extends GestureOverlayView implements OnGesturePerformedListener {
+public class IMEGestureOverlayView extends GestureOverlayView implements OnGesturePerformedListener {
private static final double SCORE_TRESHOLD = 3.0;
private final GestureLibrary mGestureLibrary;
- private OnGestureRecognizedListener mOnGestureRecognizedListener;
+ private StringReciever mOutput;
- public DrawingSpaceView(Context context, AttributeSet attrs) {
+ public IMEGestureOverlayView(Context context, AttributeSet attrs) {
super(context, attrs);
- mGestureLibrary = GestureLibraries.fromRawResource(context, R.raw.gestures);
+ mGestureLibrary = SettingsUtil.getGestureLibrary(context);
mGestureLibrary.load();
addOnGesturePerformedListener(this);
}
- public void setOnGestureRecognizedListener(OnGestureRecognizedListener onGestureRecognizedListener) {
- mOnGestureRecognizedListener = onGestureRecognizedListener;
+ public void setOutput(StringReciever output) {
+ mOutput = output;
}
@Override
@@ -49,9 +48,9 @@ public class DrawingSpaceView extends GestureOverlayView implements OnGesturePer
if (!predictions.isEmpty()) {
bestPrediction = predictions.get(0);
}
- if (mOnGestureRecognizedListener != null && bestPrediction != null) {
+ if (mOutput != null && bestPrediction != null) {
if (bestPrediction.score > SCORE_TRESHOLD) {
- mOnGestureRecognizedListener.gestureRecognized(bestPrediction.name);
+ mOutput.putString(bestPrediction.name);
} else {
clear(false);
}
diff --git a/src/us/minak/IMEService.java b/src/us/minak/IMEService.java
index 86c7864..acbe616 100644
--- a/src/us/minak/IMEService.java
+++ b/src/us/minak/IMEService.java
@@ -7,7 +7,6 @@ import android.view.View;
import android.view.inputmethod.EditorInfo;
public class IMEService extends InputMethodService {
- private IMEView imeView;
/**
* Loads the configuration.
*/
@@ -15,22 +14,21 @@ public class IMEService extends InputMethodService {
public void onInitializeInterface() {
// TODO
}
-
+
@Override
public View onCreateInputView() {
final IMEView view = (IMEView) getLayoutInflater().inflate(R.layout.ime, null);
-
- view.setOnCharacterEnteredListener(new OnCharacterEnteredListener() {
+
+ view.setOutput(new StringReciever() {
@Override
- public void characterEntered(String character) {
+ public void putString(String character) {
getCurrentInputConnection().commitText(character, 1);
}
});
-
- this.imeView = view;
+
return view;
}
-
+
/**
* Called to inform the input method that text input has started in an editor.
*/
diff --git a/src/us/minak/IMEView.java b/src/us/minak/IMEView.java
index aefded8..5c70a48 100644
--- a/src/us/minak/IMEView.java
+++ b/src/us/minak/IMEView.java
@@ -8,33 +8,31 @@ import android.util.AttributeSet;
import android.widget.RelativeLayout;
public class IMEView extends RelativeLayout{
+ private StringReciever mOutput;
private final Context mContext;
private final Queue<Character> mSymbolsQueue = new LinkedList<Character>();
private OnCharacterEnteredListener mOnCharacterEnteredListener;
public IMEView(Context context, AttributeSet attrs) {
super(context, attrs);
- mContext = context;
}
@Override
protected void onFinishInflate() {
- DrawingSpaceView drawingSpaceView = (DrawingSpaceView) findViewById(R.id.drawing_space);
- drawingSpaceView.setOnGestureRecognizedListener(new OnGestureRecognizedListener() {
+ IMEGestureOverlayView drawingSpaceView = (IMEGestureOverlayView) findViewById(R.id.drawing_space);
+ drawingSpaceView.setOutput(new StringReciever() {
@Override
- public void gestureRecognized(String character) {
- enterCharacter(character);
- }
-
+ public void putString(String character) { enterCharacter(character); }
});
}
- public void setOnCharacterEnteredListener(OnCharacterEnteredListener onCharacterEnteredListener) {
- mOnCharacterEnteredListener = onCharacterEnteredListener;
+ public void setOutput(StringReciever output) {
+ mOutput = output;
}
private void enterCharacter(String character) {
- mOnCharacterEnteredListener.characterEntered(character);
+ if (mOutput != null)
+ mOutput.putString(character);
}
public Queue<Character> getSymbolsQueue() {
diff --git a/src/us/minak/OnCharacterEnteredListener.java b/src/us/minak/OnCharacterEnteredListener.java
deleted file mode 100644
index 82226b6..0000000
--- a/src/us/minak/OnCharacterEnteredListener.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package us.minak;
-
-public interface OnCharacterEnteredListener {
- void characterEntered(String character);
-} \ No newline at end of file
diff --git a/src/us/minak/OnGestureRecognizedListener.java b/src/us/minak/OnGestureRecognizedListener.java
deleted file mode 100644
index a30e8b8..0000000
--- a/src/us/minak/OnGestureRecognizedListener.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- ********************************************************************************
- * 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);
-}
diff --git a/src/us/minak/SettingsActivity.java b/src/us/minak/SettingsActivity.java
index 30b1e7b..c052e6c 100644
--- a/src/us/minak/SettingsActivity.java
+++ b/src/us/minak/SettingsActivity.java
@@ -16,8 +16,6 @@
package us.minak;
-import android.app.Dialog;
-import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.os.AsyncTask;
@@ -30,15 +28,12 @@ import android.view.ViewGroup;
import android.gesture.Gesture;
import android.gesture.GestureLibrary;
import android.widget.TextView;
-import android.widget.EditText;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.ArrayAdapter;
-import android.content.DialogInterface;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
-import android.text.TextUtils;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.BitmapDrawable;
@@ -47,7 +42,6 @@ import java.util.Map;
import java.util.Collections;
import java.util.HashMap;
import java.util.Comparator;
-import java.util.Set;
public class SettingsActivity extends ListActivity {
private static final int STATUS_SUCCESS = 0;
@@ -55,15 +49,9 @@ public class SettingsActivity extends ListActivity {
private static final int STATUS_NO_STORAGE = 2;
private static final int STATUS_NOT_LOADED = 3;
- private static final int MENU_ID_RENAME = 1;
- private static final int MENU_ID_REMOVE = 2;
-
- private static final int DIALOG_RENAME_GESTURE = 1;
+ private static final int MENU_ID_REMOVE = 1;
private static final int REQUEST_NEW_GESTURE = 1;
-
- // Type: long (id)
- private static final String GESTURES_INFO_ID = "gestures.info_id";
private final Comparator<NamedGesture> mSorter = new Comparator<NamedGesture>() {
public int compare(NamedGesture object1, NamedGesture object2) {
@@ -73,11 +61,9 @@ public class SettingsActivity extends ListActivity {
private GesturesAdapter mAdapter;
private GesturesLoadTask mTask;
- private TextView mEmpty;
+ private TextView mEmptyMessageView;
- private Dialog mRenameDialog;
- private EditText mInput;
- private NamedGesture mCurrentRenameGesture;
+ // Hacky constructor to get 'this' out of scope ///////////////////////////
private SettingsActivity mThis;
public SettingsActivity() {
@@ -85,34 +71,62 @@ public class SettingsActivity extends ListActivity {
mThis = this;
}
+ ///////////////////////////////////////////////////////////////////////////
+
+ private void loadGestures() {
+ if (mTask != null && mTask.getStatus() != GesturesLoadTask.Status.FINISHED) {
+ mTask.cancel(true);
+ }
+ mTask = (GesturesLoadTask) new GesturesLoadTask().execute();
+ }
+
+ private void checkForEmpty() {
+ if (mAdapter.getCount() == 0) {
+ mEmptyMessageView.setText(R.string.gestures_empty);
+ }
+ }
+
+ // Basic life-cycle ///////////////////////////////////////////////////////
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
setContentView(R.layout.gestures_list);
+ setListAdapter(mAdapter = new GesturesAdapter(this));
- mAdapter = new GesturesAdapter(this);
- setListAdapter(mAdapter);
-
- mEmpty = (TextView) findViewById(android.R.id.empty);
+ mEmptyMessageView = (TextView) findViewById(android.R.id.empty);
loadGestures();
registerForContextMenu(getListView());
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ if (mTask != null && mTask.getStatus() != GesturesLoadTask.Status.FINISHED) {
+ mTask.cancel(true);
+ mTask = null;
+ }
+ }
+
+ // The buttons at the bottom //////////////////////////////////////////////
+
+ /** Called by onClick */
public void reloadGestures(View v) {
loadGestures();
}
-
+
+ /** Called by onClick */
public void addGesture(View v) {
- Intent intent = new Intent(this, CreateGestureActivity.class);
+ Intent intent = new Intent(this, SettingsCreateGestureActivity.class);
startActivityForResult(intent, REQUEST_NEW_GESTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
-
+
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_NEW_GESTURE:
@@ -122,70 +136,15 @@ public class SettingsActivity extends ListActivity {
}
}
- private void loadGestures() {
- if (mTask != null && mTask.getStatus() != GesturesLoadTask.Status.FINISHED) {
- mTask.cancel(true);
- }
- mTask = (GesturesLoadTask) new GesturesLoadTask().execute();
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
-
- if (mTask != null && mTask.getStatus() != GesturesLoadTask.Status.FINISHED) {
- mTask.cancel(true);
- mTask = null;
- }
-
- cleanupRenameDialog();
- }
-
- private void checkForEmpty() {
- if (mAdapter.getCount() == 0) {
- mEmpty.setText(R.string.gestures_empty);
- }
- }
+ // Context menu ///////////////////////////////////////////////////////////
@Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
-
- if (mCurrentRenameGesture != null) {
- outState.putLong(GESTURES_INFO_ID, mCurrentRenameGesture.gesture.getID());
- }
- }
-
- @Override
- protected void onRestoreInstanceState(Bundle state) {
- super.onRestoreInstanceState(state);
-
- long id = state.getLong(GESTURES_INFO_ID, -1);
- if (id != -1) {
- final Set<String> entries = SettingsUtil.getGestureLibrary(this).getGestureEntries();
-out: for (String name : entries) {
- for (Gesture gesture : SettingsUtil.getGestureLibrary(this).getGestures(name)) {
- if (gesture.getID() == id) {
- mCurrentRenameGesture = new NamedGesture();
- mCurrentRenameGesture.name = name;
- mCurrentRenameGesture.gesture = gesture;
- break out;
- }
- }
- }
- }
- }
-
- @Override
- public void onCreateContextMenu(ContextMenu menu, View v,
- ContextMenu.ContextMenuInfo menuInfo) {
-
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
- menu.setHeaderTitle(((TextView) info.targetView).getText());
- menu.add(0, MENU_ID_RENAME, 0, R.string.gestures_rename);
+ menu.setHeaderTitle(((TextView) info.targetView).getText());
menu.add(0, MENU_ID_REMOVE, 0, R.string.gestures_delete);
}
@@ -196,115 +155,24 @@ out: for (String name : entries) {
final NamedGesture gesture = (NamedGesture) menuInfo.targetView.getTag();
switch (item.getItemId()) {
- case MENU_ID_RENAME:
- renameGesture(gesture);
- return true;
case MENU_ID_REMOVE:
- deleteGesture(gesture);
- return true;
- }
-
- return super.onContextItemSelected(item);
- }
-
- private void renameGesture(NamedGesture gesture) {
- mCurrentRenameGesture = gesture;
- showDialog(DIALOG_RENAME_GESTURE);
- }
-
- @Override
- protected Dialog onCreateDialog(int id) {
- if (id == DIALOG_RENAME_GESTURE) {
- return createRenameDialog();
- }
- return super.onCreateDialog(id);
- }
+ SettingsUtil.getGestureLibrary(this).removeGesture(gesture.name, gesture.gesture);
+ SettingsUtil.getGestureLibrary(this).save();
- @Override
- protected void onPrepareDialog(int id, Dialog dialog) {
- super.onPrepareDialog(id, dialog);
- if (id == DIALOG_RENAME_GESTURE) {
- mInput.setText(mCurrentRenameGesture.name);
- }
- }
-
- private Dialog createRenameDialog() {
- final View layout = View.inflate(this, R.layout.dialog_rename, null);
- mInput = (EditText) layout.findViewById(R.id.name);
- ((TextView) layout.findViewById(R.id.label)).setText(R.string.gestures_rename_label);
-
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setIcon(0);
- builder.setTitle(getString(R.string.gestures_rename_title));
- builder.setCancelable(true);
- builder.setOnCancelListener(new Dialog.OnCancelListener() {
- public void onCancel(DialogInterface dialog) {
- cleanupRenameDialog();
- }
- });
- builder.setNegativeButton(getString(R.string.cancel_action),
- new Dialog.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- cleanupRenameDialog();
- }
- }
- );
- builder.setPositiveButton(getString(R.string.rename_action),
- new Dialog.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- changeGestureName();
- }
- }
- );
- builder.setView(layout);
- return builder.create();
- }
-
- private void changeGestureName() {
- final String name = mInput.getText().toString();
- if (!TextUtils.isEmpty(name)) {
- final NamedGesture renameGesture = mCurrentRenameGesture;
- final GesturesAdapter adapter = mAdapter;
- final int count = adapter.getCount();
-
- // Simple linear search, there should not be enough items to warrant
- // a more sophisticated search
- for (int i = 0; i < count; i++) {
- final NamedGesture gesture = adapter.getItem(i);
- if (gesture.gesture.getID() == renameGesture.gesture.getID()) {
- SettingsUtil.getGestureLibrary(this).removeGesture(gesture.name, gesture.gesture);
- gesture.name = mInput.getText().toString();
- SettingsUtil.getGestureLibrary(this).addGesture(gesture.name, gesture.gesture);
- break;
- }
- }
+ mAdapter.setNotifyOnChange(false);
+ mAdapter.remove(gesture);
+ mAdapter.sort(mSorter);
+ checkForEmpty();
+ mAdapter.notifyDataSetChanged();
- adapter.notifyDataSetChanged();
+ Toast.makeText(this, R.string.gestures_delete_success, Toast.LENGTH_SHORT).show();
+ return true;
}
- mCurrentRenameGesture = null;
- }
- private void cleanupRenameDialog() {
- if (mRenameDialog != null) {
- mRenameDialog.dismiss();
- mRenameDialog = null;
- }
- mCurrentRenameGesture = null;
+ return super.onContextItemSelected(item);
}
- private void deleteGesture(NamedGesture gesture) {
- SettingsUtil.getGestureLibrary(this).removeGesture(gesture.name, gesture.gesture);
- SettingsUtil.getGestureLibrary(this).save();
-
- final GesturesAdapter adapter = mAdapter;
- adapter.setNotifyOnChange(false);
- adapter.remove(gesture);
- adapter.sort(mSorter);
- checkForEmpty();
- adapter.notifyDataSetChanged();
-
- Toast.makeText(this, R.string.gestures_delete_success, Toast.LENGTH_SHORT).show();
- }
+ ///////////////////////////////////////////////////////////////////////////
private class GesturesLoadTask extends AsyncTask<Void, NamedGesture, Integer> {
private int mThumbnailSize;
@@ -322,8 +190,8 @@ out: for (String name : entries) {
findViewById(R.id.addButton).setEnabled(false);
findViewById(R.id.reloadButton).setEnabled(false);
-
- mAdapter.setNotifyOnChange(false);
+
+ mAdapter.setNotifyOnChange(false);
mAdapter.clear();
}
@@ -379,9 +247,8 @@ out: for (String name : entries) {
if (result == STATUS_NO_STORAGE) {
getListView().setVisibility(View.GONE);
- mEmpty.setVisibility(View.VISIBLE);
- mEmpty.setText(getString(R.string.gestures_error_loading,
- SettingsUtil.getGestureFile(mThis).getAbsolutePath()));
+ mEmptyMessageView.setVisibility(View.VISIBLE);
+ mEmptyMessageView.setText(getString(R.string.gestures_error_loading, SettingsUtil.getGestureFile(mThis).getAbsolutePath()));
} else {
findViewById(R.id.addButton).setEnabled(true);
findViewById(R.id.reloadButton).setEnabled(true);
@@ -406,7 +273,7 @@ out: for (String name : entries) {
}
void addBitmap(Long id, Bitmap bitmap) {
- mThumbnails.put(id, new BitmapDrawable(bitmap));
+ mThumbnails.put(id, new BitmapDrawable(getResources(), bitmap));
}
@Override
diff --git a/src/us/minak/CreateGestureActivity.java b/src/us/minak/SettingsCreateGestureActivity.java
index 19fbc83..64975e0 100644
--- a/src/us/minak/CreateGestureActivity.java
+++ b/src/us/minak/SettingsCreateGestureActivity.java
@@ -18,7 +18,6 @@ package us.minak;
import android.app.Activity;
import android.os.Bundle;
-import android.os.Environment;
import android.view.View;
import android.view.MotionEvent;
import android.gesture.GestureOverlayView;
@@ -27,9 +26,7 @@ import android.gesture.GestureLibrary;
import android.widget.TextView;
import android.widget.Toast;
-import java.io.File;
-
-public class CreateGestureActivity extends Activity {
+public class SettingsCreateGestureActivity extends Activity {
private static final float LENGTH_THRESHOLD = 120.0f;
private Gesture mGesture;
@@ -38,8 +35,8 @@ public class CreateGestureActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
- setContentView(R.layout.create_gesture);
+
+ setContentView(R.layout.gesture_create);
mDoneButton = findViewById(R.id.done);
@@ -50,7 +47,7 @@ public class CreateGestureActivity extends Activity {
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
-
+
if (mGesture != null) {
outState.putParcelable("gesture", mGesture);
}
@@ -59,7 +56,7 @@ public class CreateGestureActivity extends Activity {
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
-
+
mGesture = savedInstanceState.getParcelable("gesture");
if (mGesture != null) {
final GestureOverlayView overlay =
@@ -89,22 +86,21 @@ public class CreateGestureActivity extends Activity {
setResult(RESULT_OK);
- final String path = new File(Environment.getExternalStorageDirectory(),
- "gestures").getAbsolutePath();
+ final String path = SettingsUtil.getGestureFile(this).getAbsolutePath();
Toast.makeText(this, getString(R.string.save_success, path), Toast.LENGTH_LONG).show();
} else {
setResult(RESULT_CANCELED);
}
finish();
-
+
}
-
+
public void cancelGesture(View v) {
setResult(RESULT_CANCELED);
finish();
}
-
+
private class GesturesProcessor implements GestureOverlayView.OnGestureListener {
public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) {
mDoneButton.setEnabled(false);
diff --git a/src/us/minak/SettingsUtil.java b/src/us/minak/SettingsUtil.java
index c3c0603..c043e0b 100644
--- a/src/us/minak/SettingsUtil.java
+++ b/src/us/minak/SettingsUtil.java
@@ -1,20 +1,39 @@
package us.minak;
-import android.content.ContextWrapper;
+import android.content.Context;
import android.gesture.GestureLibrary;
import android.gesture.GestureLibraries;
+
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
public class SettingsUtil {
private static File sGestureFile = null;
private static GestureLibrary sGestureLibrary = null;
- public static File getGestureFile(ContextWrapper context) {
+ public static File getGestureFile(Context context) {
if (sGestureFile == null)
sGestureFile = new File(context.getExternalFilesDir(null), "gestures.ttf");
+ // If the gestures file doesn't exist, copy the default gestures to it
+ if (!sGestureFile.exists()) {
+ try {
+ InputStream in = context.getResources().openRawResource(R.raw.gestures);
+ OutputStream out = new FileOutputStream(sGestureFile);
+ byte[] buf = new byte[1024];
+ int len;
+ while ( (len = in.read(buf, 0, buf.length)) != -1)
+ out.write(buf, 0, len);
+ in.close();
+ out.close();
+ } catch (Exception e) {
+ // TODO: better error handling
+ }
+ }
return sGestureFile;
}
- public static GestureLibrary getGestureLibrary(ContextWrapper context) {
+ public static GestureLibrary getGestureLibrary(Context context) {
if (sGestureLibrary == null)
sGestureLibrary = GestureLibraries.fromFile(getGestureFile(context));
return sGestureLibrary;
diff --git a/src/us/minak/StringReciever.java b/src/us/minak/StringReciever.java
new file mode 100644
index 0000000..2b91da1
--- /dev/null
+++ b/src/us/minak/StringReciever.java
@@ -0,0 +1,5 @@
+package us.minak;
+
+public interface StringReciever {
+ void putString(String character);
+}