diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-05-24 23:49:58 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-05-24 23:49:58 -0700 |
commit | d35041d869fdc11684797bf318e4484a28fc2be1 (patch) | |
tree | 70daa99cb79d654ff214b7a5a355b7030c0e861b /tests | |
parent | 6a3a2b9d20212d8496744ebdc47a52bd6c670cbb (diff) | |
parent | 82392e84b9bcf618d1c41730ec14fb8dab841990 (diff) | |
download | frameworks_base-d35041d869fdc11684797bf318e4484a28fc2be1.zip frameworks_base-d35041d869fdc11684797bf318e4484a28fc2be1.tar.gz frameworks_base-d35041d869fdc11684797bf318e4484a28fc2be1.tar.bz2 |
am 82392e84: Merge change 2402 into donut
Merge commit '82392e84b9bcf618d1c41730ec14fb8dab841990'
* commit '82392e84b9bcf618d1c41730ec14fb8dab841990':
Cleanup Gestures API and make it easier to use in 3rd party apps. Also fix the events processing in the gestures overlay mechanism. Give better control of the various properties of the overlay through XML attributes.
Diffstat (limited to 'tests')
6 files changed, 42 insertions, 48 deletions
diff --git a/tests/sketch/res/layout/demo.xml b/tests/sketch/res/layout/demo.xml index 2ef291a..c3a78cf 100755 --- a/tests/sketch/res/layout/demo.xml +++ b/tests/sketch/res/layout/demo.xml @@ -17,7 +17,8 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" - android:layout_height="wrap_content"> + android:layout_height="fill_parent"> + <Spinner android:id="@+id/spinner" android:layout_width="fill_parent" @@ -29,6 +30,6 @@ android:id="@+id/drawingpad" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:layout_weight="1"/> + android:layout_weight="1" /> </LinearLayout> diff --git a/tests/sketch/res/layout/gestureviewer.xml b/tests/sketch/res/layout/gestureviewer.xml index 1503736..e4cca52 100755 --- a/tests/sketch/res/layout/gestureviewer.xml +++ b/tests/sketch/res/layout/gestureviewer.xml @@ -17,7 +17,7 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" - android:layout_height="wrap_content"> + android:layout_height="fill_parent"> <Spinner android:id="@+id/spinner" @@ -30,7 +30,7 @@ android:id="@+id/drawingpad" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:layout_weight="1"/> + android:layout_weight="1" /> <LinearLayout android:orientation="horizontal" diff --git a/tests/sketch/res/layout/overlaydemo.xml b/tests/sketch/res/layout/overlaydemo.xml index 75c86ed..4d5a657 100644 --- a/tests/sketch/res/layout/overlaydemo.xml +++ b/tests/sketch/res/layout/overlaydemo.xml @@ -14,7 +14,14 @@ limitations under the License. --> -<ListView xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/list" +<android.gesture.GestureOverlayView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/overlay" android:layout_width="fill_parent" - android:layout_height="fill_parent" /> + android:layout_height="fill_parent"> + + <ListView + android:id="@+id/list" + android:layout_width="fill_parent" + android:layout_height="fill_parent" /> + +</android.gesture.GestureOverlayView> diff --git a/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java b/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java index f3081b7..6767de6 100644 --- a/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java +++ b/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java @@ -25,7 +25,6 @@ import android.os.Bundle; import android.provider.Contacts.People; import android.util.Log; import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.widget.AdapterView; import android.widget.ListView; @@ -34,16 +33,12 @@ import android.gesture.Gesture; import android.gesture.GestureOverlayView; import android.gesture.LetterRecognizer; import android.gesture.Prediction; -import android.gesture.TouchThroughGestureListener; import java.util.ArrayList; public class ContactListGestureOverlay extends Activity { - - private static final String LOGTAG = "ContactListGestureOverlay"; - + private static final String LOG_TAG = "ContactListGestureOverlay"; private static final String SORT_ORDER = People.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; - private static final String[] CONTACTS_PROJECTION = new String[] { People._ID, // 0 People.DISPLAY_NAME, // 1 @@ -51,11 +46,9 @@ public class ContactListGestureOverlay extends Activity { private ContactAdapter mContactAdapter; - private TouchThroughGestureListener mGestureProcessor; - - private LetterRecognizer mRecognizer; - private ListView mContactList; + private LetterRecognizer mRecognizer; + private GestureOverlayView mOverlay; @Override public void onCreate(Bundle savedInstanceState) { @@ -63,10 +56,10 @@ public class ContactListGestureOverlay extends Activity { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.overlaydemo); - setProgressBarIndeterminateVisibility(true); - // create a letter recognizer - mRecognizer = LetterRecognizer.getLetterRecognizer(this, LetterRecognizer.RECOGNIZER_LATIN_LOWERCASE); + mRecognizer = LetterRecognizer.getLetterRecognizer(this, + LetterRecognizer.RECOGNIZER_LATIN_LOWERCASE); + mOverlay = (GestureOverlayView) findViewById(R.id.overlay); // load the contact list mContactList = (ListView) findViewById(R.id.list); @@ -74,13 +67,14 @@ public class ContactListGestureOverlay extends Activity { mContactList.setTextFilterEnabled(true); mContactList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { - if (!mGestureProcessor.isGesturing()) { + if (!mOverlay.isGesturing()) { Intent intent = new Intent(Intent.ACTION_VIEW, ContentUris.withAppendedId( People.CONTENT_URI, id)); startActivity(intent); } } }); + ContentResolver resolver = getContentResolver(); Cursor cursor = resolver.query(People.CONTENT_URI, CONTACTS_PROJECTION, null, null, SORT_ORDER); @@ -91,21 +85,16 @@ public class ContactListGestureOverlay extends Activity { mContactAdapter = new ContactAdapter(this, list); mContactList.setAdapter(mContactAdapter); - setProgressBarIndeterminateVisibility(false); - - // add a gesture overlay on top of the ListView - GestureOverlayView overlay = new GestureOverlayView(this); - mGestureProcessor = new TouchThroughGestureListener(mContactList); - mGestureProcessor.setGestureType(TouchThroughGestureListener.MULTIPLE_STROKE); - mGestureProcessor.addOnGestureActionListener(new TouchThroughGestureListener.OnGesturePerformedListener() { + mOverlay.setGestureStrokeType(GestureOverlayView.GESTURE_STROKE_TYPE_MULTIPLE); + mOverlay.addOnGesturePerformedListener(new GestureOverlayView.OnGesturePerformedListener() { public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { ArrayList<Prediction> predictions = mRecognizer.recognize(gesture); if (!predictions.isEmpty()) { - Log.v(LOGTAG, "1st Prediction : " + predictions.get(0).name + + Log.v(LOG_TAG, "1st Prediction : " + predictions.get(0).name + " @" + predictions.get(0).score); - Log.v(LOGTAG, "2nd Prediction : " + predictions.get(1).name + + Log.v(LOG_TAG, "2nd Prediction : " + predictions.get(1).name + " @" + predictions.get(1).score); - Log.v(LOGTAG, "3rd Prediction : " + predictions.get(2).name + + Log.v(LOG_TAG, "3rd Prediction : " + predictions.get(2).name + " @" + predictions.get(2).score); int index = mContactAdapter.search(predictions.get(0).name); if (index != -1) { @@ -114,9 +103,5 @@ public class ContactListGestureOverlay extends Activity { } } }); - overlay.addOnGestureListener(mGestureProcessor); - ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); - this.addContentView(overlay, params); } } diff --git a/tests/sketch/src/com/android/gesture/example/GestureEntry.java b/tests/sketch/src/com/android/gesture/example/GestureEntry.java index bc2503c..3f86ed4 100644 --- a/tests/sketch/src/com/android/gesture/example/GestureEntry.java +++ b/tests/sketch/src/com/android/gesture/example/GestureEntry.java @@ -47,8 +47,9 @@ public class GestureEntry extends Activity { private static final String PARCEL_KEY = "gesture"; - static final String GESTURE_FILE_NAME = Environment.getExternalStorageDirectory().getAbsolutePath() - + File.separator + "demo_library.gestures"; + static final String GESTURE_FILE_NAME = + Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + + "demo_library.gestures"; private static final int DIALOG_NEW_ENTRY = 1; @@ -82,7 +83,7 @@ public class GestureEntry extends Activity { // correct the recognition result by adding the new example if (!mChangedByRecognizer) { mGestureLibrary.addGesture(parent.getSelectedItem().toString(), mGesturePad - .getCurrentGesture()); + .getGesture()); } else { mChangedByRecognizer = false; } @@ -99,7 +100,7 @@ public class GestureEntry extends Activity { mGesturePad.setBackgroundColor(Color.BLACK); mGesturePad.addOnGestureListener(new GestureOverlayView.OnGestureListener() { public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { - recognize(overlay.getCurrentGesture()); + recognize(overlay.getGesture()); } public void onGesture(GestureOverlayView overlay, MotionEvent event) { @@ -116,7 +117,7 @@ public class GestureEntry extends Activity { if (savedInstanceState != null) { Gesture gesture = (Gesture) savedInstanceState.getParcelable(PARCEL_KEY); if (gesture != null) { - mGesturePad.setCurrentGesture(gesture); + mGesturePad.setGesture(gesture); } } } @@ -133,7 +134,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.getCurrentGesture()); + mGestureLibrary.addGesture(text, mGesturePad.getGesture()); } } }).setNegativeButton(R.string.newgesture_dialog_cancel, @@ -157,7 +158,7 @@ public class GestureEntry extends Activity { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case NEW_ID: - if (mGesturePad.getCurrentGesture() != null) { + if (mGesturePad.getGesture() != null) { showDialog(DIALOG_NEW_ENTRY); } break; @@ -190,7 +191,7 @@ public class GestureEntry extends Activity { @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - Gesture gesture = mGesturePad.getCurrentGesture(); + Gesture gesture = mGesturePad.getGesture(); if (gesture != null) { outState.putParcelable(PARCEL_KEY, gesture); } diff --git a/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java b/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java index aa07e7b..a561c96 100755 --- a/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java +++ b/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java @@ -78,7 +78,7 @@ public class GestureLibViewer extends Activity { mCurrentGestureIndex--; } gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setCurrentGesture(gesture); + mGesturePad.setGesture(gesture); mGesturePad.invalidate(); } } @@ -109,7 +109,7 @@ public class GestureLibViewer extends Activity { mGestures = mGesureLibrary.getGestures(list.get(0)); mCurrentGestureIndex = 0; Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setCurrentGesture(gesture); + mGesturePad.setGesture(gesture); } mGestureCategory.setOnItemSelectedListener(new OnItemSelectedListener() { @@ -118,7 +118,7 @@ public class GestureLibViewer extends Activity { if (!mGestures.isEmpty()) { mCurrentGestureIndex = 0; Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setCurrentGesture(gesture); + mGesturePad.setGesture(gesture); } mGesturePad.invalidate(); } @@ -139,7 +139,7 @@ public class GestureLibViewer extends Activity { } mCurrentGestureIndex++; Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setCurrentGesture(gesture); + mGesturePad.setGesture(gesture); mGesturePad.invalidate(); } }); @@ -150,7 +150,7 @@ public class GestureLibViewer extends Activity { if (mCurrentGestureIndex >= 1 && !mGestures.isEmpty()) { mCurrentGestureIndex--; Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setCurrentGesture(gesture); + mGesturePad.setGesture(gesture); mGesturePad.invalidate(); } } |