diff options
author | Romain Guy <romainguy@android.com> | 2009-05-29 14:43:54 -0700 |
---|---|---|
committer | Romain Guy <romainguy@android.com> | 2009-05-29 14:43:54 -0700 |
commit | 0a63716ed0e44f7cd32b81a444429318d42d8f08 (patch) | |
tree | 76387f19e8f6a5ff28b2429396928cb9e2bb98b1 /tests/sketch/src | |
parent | 7a8c437723a50b171d0cd97cb17886b28dffce92 (diff) | |
download | frameworks_base-0a63716ed0e44f7cd32b81a444429318d42d8f08.zip frameworks_base-0a63716ed0e44f7cd32b81a444429318d42d8f08.tar.gz frameworks_base-0a63716ed0e44f7cd32b81a444429318d42d8f08.tar.bz2 |
Modify the base gestures API to use streams instead of files. Adds new wrappers to easily load/save gestures from files, resources, etc. Do the same for the letters recognizer.
Diffstat (limited to 'tests/sketch/src')
3 files changed, 31 insertions, 28 deletions
diff --git a/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java b/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java index 6767de6..7865a5c 100644 --- a/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java +++ b/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java @@ -33,6 +33,7 @@ import android.gesture.Gesture; import android.gesture.GestureOverlayView; import android.gesture.LetterRecognizer; import android.gesture.Prediction; +import android.gesture.LetterRecognizers; import java.util.ArrayList; @@ -57,8 +58,8 @@ public class ContactListGestureOverlay extends Activity { setContentView(R.layout.overlaydemo); // create a letter recognizer - mRecognizer = LetterRecognizer.getLetterRecognizer(this, - LetterRecognizer.RECOGNIZER_LATIN_LOWERCASE); + mRecognizer = LetterRecognizers.fromType(this, + LetterRecognizers.RECOGNIZER_LATIN_LOWERCASE); mOverlay = (GestureOverlayView) findViewById(R.id.overlay); // load the contact list diff --git a/tests/sketch/src/com/android/gesture/example/GestureEntry.java b/tests/sketch/src/com/android/gesture/example/GestureEntry.java index 3f86ed4..8dbec99 100644 --- a/tests/sketch/src/com/android/gesture/example/GestureEntry.java +++ b/tests/sketch/src/com/android/gesture/example/GestureEntry.java @@ -36,9 +36,10 @@ import android.widget.Spinner; import android.widget.AdapterView.OnItemSelectedListener; import android.gesture.Gesture; -import android.gesture.GestureLibrary; import android.gesture.GestureOverlayView; import android.gesture.Prediction; +import android.gesture.GestureLibraries; +import android.gesture.GestureLibrary; import java.io.File; import java.util.ArrayList; @@ -61,7 +62,7 @@ public class GestureEntry extends Activity { private Spinner mRecognitionResult; - private GestureLibrary mGestureLibrary; + private GestureLibrary mGestureStore; private boolean mChangedByRecognizer = false; @@ -71,8 +72,8 @@ public class GestureEntry extends Activity { setContentView(R.layout.demo); // init the gesture library - mGestureLibrary = new GestureLibrary(GESTURE_FILE_NAME); - mGestureLibrary.load(); + mGestureStore = GestureLibraries.fromFile(GESTURE_FILE_NAME); + mGestureStore.load(); // create the spinner for showing the recognition results // the spinner also allows a user to correct a prediction @@ -82,7 +83,7 @@ public class GestureEntry extends Activity { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // correct the recognition result by adding the new example if (!mChangedByRecognizer) { - mGestureLibrary.addGesture(parent.getSelectedItem().toString(), mGesturePad + mGestureStore.addGesture(parent.getSelectedItem().toString(), mGesturePad .getGesture()); } else { mChangedByRecognizer = false; @@ -109,7 +110,7 @@ public class GestureEntry extends Activity { public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) { overlay.clear(false); } - + public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) { } }); @@ -134,7 +135,7 @@ public class GestureEntry extends Activity { .findViewById(R.id.gesturename_edit); String text = edittext.getText().toString().trim(); if (text.length() > 0) { - mGestureLibrary.addGesture(text, mGesturePad.getGesture()); + mGestureStore.addGesture(text, mGesturePad.getGesture()); } } }).setNegativeButton(R.string.newgesture_dialog_cancel, @@ -173,14 +174,14 @@ public class GestureEntry extends Activity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - mGestureLibrary.load(); + mGestureStore.load(); mGesturePad.clear(false); } @Override protected void onPause() { super.onPause(); - mGestureLibrary.save(); + mGestureStore.save(); } @Override @@ -195,12 +196,12 @@ public class GestureEntry extends Activity { if (gesture != null) { outState.putParcelable(PARCEL_KEY, gesture); } - mGestureLibrary.save(); + mGestureStore.save(); } private void recognize(Gesture gesture) { mChangedByRecognizer = true; - ArrayList<Prediction> predictions = mGestureLibrary.recognize(gesture); + ArrayList<Prediction> predictions = mGestureStore.recognize(gesture); ArrayAdapter<Prediction> adapter = new ArrayAdapter<Prediction>(this, android.R.layout.simple_spinner_item, predictions); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); diff --git a/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java b/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java index a561c96..f5bf683 100755 --- a/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java +++ b/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java @@ -28,8 +28,9 @@ import android.widget.Spinner; import android.widget.AdapterView.OnItemSelectedListener; import android.gesture.Gesture; -import android.gesture.GestureLibrary; import android.gesture.GestureOverlayView; +import android.gesture.GestureLibraries; +import android.gesture.GestureLibrary; import java.util.ArrayList; import java.util.Collections; @@ -45,7 +46,7 @@ public class GestureLibViewer extends Activity { private Spinner mGestureCategory; - private GestureLibrary mGesureLibrary; + private GestureLibrary mGesureStore; private ArrayList<Gesture> mGestures; @@ -59,15 +60,15 @@ public class GestureLibViewer extends Activity { String name = (String) mGestureCategory.getSelectedItem(); Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesureLibrary.removeGesture(name, gesture); + mGesureStore.removeGesture(name, gesture); - mGestures = mGesureLibrary.getGestures(name); + mGestures = mGesureStore.getGestures(name); if (mGestures == null) { // delete the entire entry mCurrentGestureIndex = 0; ArrayList<String> list = new ArrayList<String>(); - list.addAll(mGesureLibrary.getGestureEntries()); + list.addAll(mGesureStore.getGestureEntries()); Collections.sort(list); ArrayAdapter<String> adapter = new ArrayAdapter<String>(GestureLibViewer.this, android.R.layout.simple_spinner_item, list); @@ -83,7 +84,7 @@ public class GestureLibViewer extends Activity { } } } - + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -94,19 +95,19 @@ public class GestureLibViewer extends Activity { mGesturePad.setEnabled(false); // init the gesture library - mGesureLibrary = new GestureLibrary(GestureEntry.GESTURE_FILE_NAME); - mGesureLibrary.load(); + mGesureStore = GestureLibraries.fromFile(GestureEntry.GESTURE_FILE_NAME); + mGesureStore.load(); mGestureCategory = (Spinner) findViewById(R.id.spinner); ArrayList<String> list = new ArrayList<String>(); - if (!mGesureLibrary.getGestureEntries().isEmpty()) { - list.addAll(mGesureLibrary.getGestureEntries()); + if (!mGesureStore.getGestureEntries().isEmpty()) { + list.addAll(mGesureStore.getGestureEntries()); Collections.sort(list); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mGestureCategory.setAdapter(adapter); - mGestures = mGesureLibrary.getGestures(list.get(0)); + mGestures = mGesureStore.getGestures(list.get(0)); mCurrentGestureIndex = 0; Gesture gesture = mGestures.get(mCurrentGestureIndex); mGesturePad.setGesture(gesture); @@ -114,7 +115,7 @@ public class GestureLibViewer extends Activity { mGestureCategory.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { - mGestures = mGesureLibrary.getGestures((String) mGestureCategory.getSelectedItem()); + mGestures = mGesureStore.getGestures((String) mGestureCategory.getSelectedItem()); if (!mGestures.isEmpty()) { mCurrentGestureIndex = 0; Gesture gesture = mGestures.get(mCurrentGestureIndex); @@ -160,7 +161,7 @@ public class GestureLibViewer extends Activity { @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { - mGesureLibrary.save(); + mGesureStore.save(); setResult(RESULT_OK); finish(); return true; @@ -172,12 +173,12 @@ public class GestureLibViewer extends Activity { @Override protected void onPause() { super.onPause(); - mGesureLibrary.save(); + mGesureStore.save(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - mGesureLibrary.save(); + mGesureStore.save(); } } |