diff options
author | Romain Guy <romainguy@android.com> | 2009-06-08 22:36:10 -0700 |
---|---|---|
committer | Romain Guy <romainguy@android.com> | 2009-06-08 23:24:18 -0700 |
commit | f642aa2a44e63aa105bbc6aec59f9bee261986ef (patch) | |
tree | c589f7325332545928fda7a4e846ec43a24b7474 /tests/sketch | |
parent | be19df0a4dcc5c9f2214935cfe6504df18be8697 (diff) | |
download | frameworks_base-f642aa2a44e63aa105bbc6aec59f9bee261986ef.zip frameworks_base-f642aa2a44e63aa105bbc6aec59f9bee261986ef.tar.gz frameworks_base-f642aa2a44e63aa105bbc6aec59f9bee261986ef.tar.bz2 |
Removes gestures from ListView.
Diffstat (limited to 'tests/sketch')
-rw-r--r-- | tests/sketch/Android.mk | 8 | ||||
-rwxr-xr-x | tests/sketch/AndroidManifest.xml | 45 | ||||
-rwxr-xr-x | tests/sketch/res/drawable/icon.png | bin | 3180 -> 0 bytes | |||
-rwxr-xr-x | tests/sketch/res/layout/demo.xml | 35 | ||||
-rwxr-xr-x | tests/sketch/res/layout/gestureviewer.xml | 59 | ||||
-rwxr-xr-x | tests/sketch/res/layout/newgesture_dialog.xml | 34 | ||||
-rw-r--r-- | tests/sketch/res/layout/overlaydemo.xml | 27 | ||||
-rwxr-xr-x | tests/sketch/res/values/strings.xml | 29 | ||||
-rw-r--r-- | tests/sketch/src/com/android/gesture/example/ContactAdapter.java | 100 | ||||
-rw-r--r-- | tests/sketch/src/com/android/gesture/example/ContactItem.java | 34 | ||||
-rw-r--r-- | tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java | 108 | ||||
-rw-r--r-- | tests/sketch/src/com/android/gesture/example/GestureEntry.java | 211 | ||||
-rwxr-xr-x | tests/sketch/src/com/android/gesture/example/GestureLibViewer.java | 184 | ||||
-rw-r--r-- | tests/sketch/tools/Converter.java | 225 |
14 files changed, 0 insertions, 1099 deletions
diff --git a/tests/sketch/Android.mk b/tests/sketch/Android.mk deleted file mode 100644 index 814e370..0000000 --- a/tests/sketch/Android.mk +++ /dev/null @@ -1,8 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := $(call all-subdir-java-files) - -LOCAL_PACKAGE_NAME := Sketch - -include $(BUILD_PACKAGE) diff --git a/tests/sketch/AndroidManifest.xml b/tests/sketch/AndroidManifest.xml deleted file mode 100755 index b8a13f6..0000000 --- a/tests/sketch/AndroidManifest.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2008-2009 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.android.gesture.example"> - - <uses-permission android:name="android.permission.READ_CONTACTS" /> - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> - - <application android:icon="@drawable/icon" android:label="@string/app_name"> - - <activity - android:name="com.android.gesture.example.GestureEntry" - android:label="@string/app_name"> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - - <activity android:name="com.android.gesture.example.GestureLibViewer"/> - - <activity - android:name="com.android.gesture.example.ContactListGestureOverlay" - android:label="@string/overlay_name"> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - - </application> -</manifest> diff --git a/tests/sketch/res/drawable/icon.png b/tests/sketch/res/drawable/icon.png Binary files differdeleted file mode 100755 index 7502484..0000000 --- a/tests/sketch/res/drawable/icon.png +++ /dev/null diff --git a/tests/sketch/res/layout/demo.xml b/tests/sketch/res/layout/demo.xml deleted file mode 100755 index c3a78cf..0000000 --- a/tests/sketch/res/layout/demo.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2009 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent"> - - <Spinner - android:id="@+id/spinner" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:drawSelectorOnTop="true" - android:prompt="@string/recognition_result"/> - - <android.gesture.GestureOverlayView - android:id="@+id/drawingpad" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_weight="1" /> - -</LinearLayout> diff --git a/tests/sketch/res/layout/gestureviewer.xml b/tests/sketch/res/layout/gestureviewer.xml deleted file mode 100755 index e4cca52..0000000 --- a/tests/sketch/res/layout/gestureviewer.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2009 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent"> - - <Spinner - android:id="@+id/spinner" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:drawSelectorOnTop="true" - android:prompt="@string/recognition_result"/> - - <android.gesture.GestureOverlayView - android:id="@+id/drawingpad" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_weight="1" /> - - <LinearLayout - android:orientation="horizontal" - android:layout_width="fill_parent" - android:layout_height="wrap_content"> - <Button - android:id="@+id/previous" - android:text="@string/previous" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1"/> - <Button - android:id="@+id/remove" - android:text="@string/remove" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1"/> - <Button - android:id="@+id/next" - android:text="@string/next" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1"/> - </LinearLayout> - -</LinearLayout> diff --git a/tests/sketch/res/layout/newgesture_dialog.xml b/tests/sketch/res/layout/newgesture_dialog.xml deleted file mode 100755 index 91e7645..0000000 --- a/tests/sketch/res/layout/newgesture_dialog.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2009 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:orientation="vertical"> - - <EditText - android:id="@+id/gesturename_edit" - android:layout_height="wrap_content" - android:layout_width="fill_parent" - android:layout_marginLeft="20dip" - android:layout_marginRight="20dip" - android:scrollHorizontally="true" - android:autoText="false" - android:capitalize="none" - android:gravity="fill_horizontal" - android:textAppearance="?android:attr/textAppearanceMedium" /> - -</LinearLayout> diff --git a/tests/sketch/res/layout/overlaydemo.xml b/tests/sketch/res/layout/overlaydemo.xml deleted file mode 100644 index 4d5a657..0000000 --- a/tests/sketch/res/layout/overlaydemo.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2009 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<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"> - - <ListView - android:id="@+id/list" - android:layout_width="fill_parent" - android:layout_height="fill_parent" /> - -</android.gesture.GestureOverlayView> diff --git a/tests/sketch/res/values/strings.xml b/tests/sketch/res/values/strings.xml deleted file mode 100755 index 42f14da..0000000 --- a/tests/sketch/res/values/strings.xml +++ /dev/null @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2009 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<resources> - <string name="app_name">Gesture Demo</string> - <string name="overlay_name">Overlay Demo</string> - <string name="recognition_result">Recognition Result</string> - <string name="clear">Clear</string> - <string name="newgesture">Add</string> - <string name="viewgesture">View</string> - <string name="newgesture_dialog_ok">OK</string> - <string name="newgesture_dialog_cancel">Cancel</string> - <string name="newgesture_text_entry">Gesture Name</string> - <string name="previous">Previous</string> - <string name="remove">Remove</string> - <string name="next">Next</string> -</resources> diff --git a/tests/sketch/src/com/android/gesture/example/ContactAdapter.java b/tests/sketch/src/com/android/gesture/example/ContactAdapter.java deleted file mode 100644 index 008a972..0000000 --- a/tests/sketch/src/com/android/gesture/example/ContactAdapter.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2008-2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.gesture.example; - -import android.app.Activity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; - -import java.util.ArrayList; - -class ContactAdapter extends ArrayAdapter<ContactItem> { - - private LayoutInflater mInflater; - - public ContactAdapter(Activity activity, ArrayList<ContactItem> contacts) { - super(activity, 0, contacts); - mInflater = activity.getLayoutInflater(); - } - - @Override - public ContactItem getItem(int position) { - return super.getItem(position); - } - - @Override - public long getItemId(int position) { - return getItem(position).itemID; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - final ContactItem info = getItem(position); - - View view = convertView; - if (view == null) { - view = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false); - view.setTag(view.findViewById(android.R.id.text1)); - } - - final TextView textView = (TextView)view.getTag(); - textView.setText(info.toString()); - - return view; - } - - public int search(String query) { - if (query != null && query.length() > 0) { - int start = 0; - int end = getCount() - 1; - int index = binarySearch(query, start, end); - for (index = index - 1; index >= 0; index--) { - String str = getItem(index).toString().toLowerCase(); - if (!str.startsWith(query)) { - return index + 1; - } - if (index == 0) { - return 0; - } - } - return -1; - } else { - return -1; - } - } - - private int binarySearch(String prefix, int start, int end) { - if (start > end) { - return -1; - } - int mid = (start + end) / 2; - String str = getItem(mid).toString().toLowerCase(); - if (prefix.compareTo(str) <= 0) { - if (str.startsWith(prefix)) { - return mid; - } else { - return binarySearch(prefix, start, mid - 1); - } - } else { - return binarySearch(prefix, mid + 1, end); - } - } - -} diff --git a/tests/sketch/src/com/android/gesture/example/ContactItem.java b/tests/sketch/src/com/android/gesture/example/ContactItem.java deleted file mode 100644 index 557c4d9..0000000 --- a/tests/sketch/src/com/android/gesture/example/ContactItem.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2008-2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.gesture.example; - - -class ContactItem { - final String itemName; - - final long itemID; - - public ContactItem(long id, String name) { - itemID = id; - itemName = name; - } - - @Override - public String toString() { - return itemName; - } -} diff --git a/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java b/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java deleted file mode 100644 index 7865a5c..0000000 --- a/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2008-2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.gesture.example; - -import android.app.Activity; -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.Intent; -import android.database.Cursor; -import android.os.Bundle; -import android.provider.Contacts.People; -import android.util.Log; -import android.view.View; -import android.view.Window; -import android.widget.AdapterView; -import android.widget.ListView; - -import android.gesture.Gesture; -import android.gesture.GestureOverlayView; -import android.gesture.LetterRecognizer; -import android.gesture.Prediction; -import android.gesture.LetterRecognizers; - -import java.util.ArrayList; - -public class ContactListGestureOverlay extends Activity { - 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 - }; - - private ContactAdapter mContactAdapter; - - private ListView mContactList; - private LetterRecognizer mRecognizer; - private GestureOverlayView mOverlay; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - setContentView(R.layout.overlaydemo); - - // create a letter recognizer - mRecognizer = LetterRecognizers.fromType(this, - LetterRecognizers.RECOGNIZER_LATIN_LOWERCASE); - mOverlay = (GestureOverlayView) findViewById(R.id.overlay); - - // load the contact list - mContactList = (ListView) findViewById(R.id.list); - registerForContextMenu(mContactList); - mContactList.setTextFilterEnabled(true); - mContactList.setOnItemClickListener(new AdapterView.OnItemClickListener() { - public void onItemClick(AdapterView<?> parent, View v, int position, long id) { - 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); - ArrayList<ContactItem> list = new ArrayList<ContactItem>(); - while (cursor.moveToNext()) { - list.add(new ContactItem(cursor.getLong(0), cursor.getString(1))); - } - mContactAdapter = new ContactAdapter(this, list); - mContactList.setAdapter(mContactAdapter); - - 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(LOG_TAG, "1st Prediction : " + predictions.get(0).name + - " @" + predictions.get(0).score); - Log.v(LOG_TAG, "2nd Prediction : " + predictions.get(1).name + - " @" + predictions.get(1).score); - 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) { - mContactList.setSelection(index); - } - } - } - }); - } -} diff --git a/tests/sketch/src/com/android/gesture/example/GestureEntry.java b/tests/sketch/src/com/android/gesture/example/GestureEntry.java deleted file mode 100644 index 8dbec99..0000000 --- a/tests/sketch/src/com/android/gesture/example/GestureEntry.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (C) 2008-2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.gesture.example; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.graphics.Color; -import android.os.Bundle; -import android.os.Environment; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.MotionEvent; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.Spinner; -import android.widget.AdapterView.OnItemSelectedListener; -import android.gesture.Gesture; - -import android.gesture.GestureOverlayView; -import android.gesture.Prediction; -import android.gesture.GestureLibraries; -import android.gesture.GestureLibrary; - -import java.io.File; -import java.util.ArrayList; - -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"; - - private static final int DIALOG_NEW_ENTRY = 1; - - private static final int NEW_ID = Menu.FIRST; - - private static final int VIEW_ID = Menu.FIRST + 1; - - private GestureOverlayView mGesturePad; - - private Spinner mRecognitionResult; - - private GestureLibrary mGestureStore; - - private boolean mChangedByRecognizer = false; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.demo); - - // init the gesture library - 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 - mRecognitionResult = (Spinner) findViewById(R.id.spinner); - mRecognitionResult.setOnItemSelectedListener(new OnItemSelectedListener() { - - public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { - // correct the recognition result by adding the new example - if (!mChangedByRecognizer) { - mGestureStore.addGesture(parent.getSelectedItem().toString(), mGesturePad - .getGesture()); - } else { - mChangedByRecognizer = false; - } - } - - public void onNothingSelected(AdapterView<?> parent) { - - } - - }); - - // create the area for drawing a gesture - mGesturePad = (GestureOverlayView) findViewById(R.id.drawingpad); - mGesturePad.setBackgroundColor(Color.BLACK); - mGesturePad.addOnGestureListener(new GestureOverlayView.OnGestureListener() { - public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { - recognize(overlay.getGesture()); - } - - public void onGesture(GestureOverlayView overlay, MotionEvent event) { - } - - public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) { - overlay.clear(false); - } - - public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) { - } - }); - - if (savedInstanceState != null) { - Gesture gesture = (Gesture) savedInstanceState.getParcelable(PARCEL_KEY); - if (gesture != null) { - mGesturePad.setGesture(gesture); - } - } - } - - @Override - protected Dialog onCreateDialog(int id) { - LayoutInflater factory = LayoutInflater.from(this); - final View textEntryView = factory.inflate(R.layout.newgesture_dialog, null); - return new AlertDialog.Builder(GestureEntry.this).setTitle( - R.string.newgesture_text_entry).setView(textEntryView).setPositiveButton( - R.string.newgesture_dialog_ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - EditText edittext = (EditText) ((AlertDialog) dialog) - .findViewById(R.id.gesturename_edit); - String text = edittext.getText().toString().trim(); - if (text.length() > 0) { - mGestureStore.addGesture(text, mGesturePad.getGesture()); - } - } - }).setNegativeButton(R.string.newgesture_dialog_cancel, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - } - }).create(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - menu.add(0, NEW_ID, 0, R.string.newgesture).setShortcut('0', 'n').setIcon( - android.R.drawable.ic_menu_add); - menu.add(0, VIEW_ID, 0, R.string.viewgesture).setShortcut('1', 'v').setIcon( - android.R.drawable.ic_menu_view); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case NEW_ID: - if (mGesturePad.getGesture() != null) { - showDialog(DIALOG_NEW_ENTRY); - } - break; - - case VIEW_ID: - startActivityForResult(new Intent(this, GestureLibViewer.class), VIEW_ID); - break; - } - - return super.onOptionsItemSelected(item); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - mGestureStore.load(); - mGesturePad.clear(false); - } - - @Override - protected void onPause() { - super.onPause(); - mGestureStore.save(); - } - - @Override - protected void onPrepareDialog(int id, Dialog dialog) { - super.onPrepareDialog(id, dialog); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - Gesture gesture = mGesturePad.getGesture(); - if (gesture != null) { - outState.putParcelable(PARCEL_KEY, gesture); - } - mGestureStore.save(); - } - - private void recognize(Gesture gesture) { - mChangedByRecognizer = true; - 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); - mRecognitionResult.setAdapter(adapter); - } - -} diff --git a/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java b/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java deleted file mode 100755 index f5bf683..0000000 --- a/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2008-2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.gesture.example; - -import android.app.Activity; -import android.os.Bundle; -import android.view.KeyEvent; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.Spinner; -import android.widget.AdapterView.OnItemSelectedListener; -import android.gesture.Gesture; - -import android.gesture.GestureOverlayView; -import android.gesture.GestureLibraries; -import android.gesture.GestureLibrary; - -import java.util.ArrayList; -import java.util.Collections; - -/** - * GestureLibViewer gives an example on how to browse existing gestures and - * removing unwanted gestures. - */ - -public class GestureLibViewer extends Activity { - - private GestureOverlayView mGesturePad; - - private Spinner mGestureCategory; - - private GestureLibrary mGesureStore; - - private ArrayList<Gesture> mGestures; - - private int mCurrentGestureIndex; - - private class RemoveGestureListener implements OnClickListener { - public void onClick(View v) { - if (mGestures.isEmpty()) { - return; - } - - String name = (String) mGestureCategory.getSelectedItem(); - Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesureStore.removeGesture(name, gesture); - - mGestures = mGesureStore.getGestures(name); - - if (mGestures == null) { - // delete the entire entry - mCurrentGestureIndex = 0; - ArrayList<String> list = new ArrayList<String>(); - list.addAll(mGesureStore.getGestureEntries()); - Collections.sort(list); - ArrayAdapter<String> adapter = new ArrayAdapter<String>(GestureLibViewer.this, - android.R.layout.simple_spinner_item, list); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - mGestureCategory.setAdapter(adapter); - } else { - if (mCurrentGestureIndex > mGestures.size() - 1) { - mCurrentGestureIndex--; - } - gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setGesture(gesture); - mGesturePad.invalidate(); - } - } - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.gestureviewer); - - // create the area for drawing a gesture - mGesturePad = (GestureOverlayView) findViewById(R.id.drawingpad); - mGesturePad.setEnabled(false); - - // init the gesture library - mGesureStore = GestureLibraries.fromFile(GestureEntry.GESTURE_FILE_NAME); - mGesureStore.load(); - - mGestureCategory = (Spinner) findViewById(R.id.spinner); - ArrayList<String> list = new ArrayList<String>(); - 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 = mGesureStore.getGestures(list.get(0)); - mCurrentGestureIndex = 0; - Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setGesture(gesture); - } - - mGestureCategory.setOnItemSelectedListener(new OnItemSelectedListener() { - public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { - mGestures = mGesureStore.getGestures((String) mGestureCategory.getSelectedItem()); - if (!mGestures.isEmpty()) { - mCurrentGestureIndex = 0; - Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setGesture(gesture); - } - mGesturePad.invalidate(); - } - - public void onNothingSelected(AdapterView<?> parent) { - } - - }); - - Button remove = (Button) findViewById(R.id.remove); - remove.setOnClickListener(new RemoveGestureListener()); - - Button next = (Button) findViewById(R.id.next); - next.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - if (mCurrentGestureIndex >= mGestures.size() - 1) { - return; - } - mCurrentGestureIndex++; - Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setGesture(gesture); - mGesturePad.invalidate(); - } - }); - - Button previous = (Button) findViewById(R.id.previous); - previous.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - if (mCurrentGestureIndex >= 1 && !mGestures.isEmpty()) { - mCurrentGestureIndex--; - Gesture gesture = mGestures.get(mCurrentGestureIndex); - mGesturePad.setGesture(gesture); - mGesturePad.invalidate(); - } - } - }); - } - - @Override - public boolean onKeyUp(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - mGesureStore.save(); - setResult(RESULT_OK); - finish(); - return true; - } else { - return false; - } - } - - @Override - protected void onPause() { - super.onPause(); - mGesureStore.save(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mGesureStore.save(); - } -} diff --git a/tests/sketch/tools/Converter.java b/tests/sketch/tools/Converter.java deleted file mode 100644 index 5db2769..0000000 --- a/tests/sketch/tools/Converter.java +++ /dev/null @@ -1,225 +0,0 @@ -import java.io.File; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.Closeable; -import java.io.DataOutputStream; -import java.io.FileOutputStream; -import java.io.DataInputStream; -import java.io.FileInputStream; -import java.io.BufferedInputStream; - -/** - * Converts text-based letter stores to binary-based stores. - */ -public class Converter { - private final File mFile; - private static final short VERSION_NUMBER = 1; - - Converter(File file) { - mFile = file; - } - - private void convert() { - boolean read = false; - - String[] classes = null; - int iCount = 0; - int hCount = 0; - int oCount = 0; - float[][] iWeights = null; - float[][] oWeights = null; - - BufferedReader reader = null; - - try { - reader = new BufferedReader(new FileReader(mFile)); - - long start = System.nanoTime(); - - String line = reader.readLine(); - int startIndex = 0; - int endIndex; - endIndex = line.indexOf(" ", startIndex); - iCount = Integer.parseInt(line.substring(startIndex, endIndex)); - - startIndex = endIndex + 1; - endIndex = line.indexOf(" ", startIndex); - hCount = Integer.parseInt(line.substring(startIndex, endIndex)); - - startIndex = endIndex + 1; - endIndex = line.length(); - oCount = Integer.parseInt(line.substring(startIndex, endIndex)); - - classes = new String[oCount]; - line = reader.readLine(); - startIndex = 0; - - for (int i = 0; i < oCount; i++) { - endIndex = line.indexOf(" ", startIndex); - classes[i] = line.substring(startIndex, endIndex); - startIndex = endIndex + 1; - } - - iWeights = new float[hCount][]; - for (int i = 0; i < hCount; i++) { - iWeights[i] = new float[iCount + 1]; - line = reader.readLine(); - startIndex = 0; - for (int j = 0; j <= iCount; j++) { - endIndex = line.indexOf(" ", startIndex); - iWeights[i][j] = Float.parseFloat(line.substring(startIndex, endIndex)); - startIndex = endIndex + 1; - } - } - - oWeights = new float[oCount][]; - for (int i = 0; i < oCount; i++) { - oWeights[i] = new float[hCount + 1]; - line = reader.readLine(); - startIndex = 0; - for (int j = 0; j <= hCount; j++) { - endIndex = line.indexOf(" ", startIndex); - oWeights[i][j] = Float.parseFloat(line.substring(startIndex, endIndex)); - startIndex = endIndex + 1; - } - } - - long end = System.nanoTime(); - System.out.println("time to read text file = " + - ((end - start) / 1000.0f / 1000.0f) + " ms"); - - read = true; - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - close(reader); - } - - if (read) { - boolean wrote = false; - DataOutputStream out = null; - - try { - out = new DataOutputStream(new FileOutputStream(mFile)); - - out.writeShort(VERSION_NUMBER); - out.writeInt(iCount); - out.writeInt(hCount); - out.writeInt(oCount); - - for (String aClass : classes) { - out.writeUTF(aClass); - } - - for (float[] weights : iWeights) { - for (float weight : weights) { - out.writeFloat(weight); - } - } - - for (float[] weights : oWeights) { - for (float weight : weights) { - out.writeFloat(weight); - } - } - - out.flush(); - - wrote = true; - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - close(out); - } - - if (wrote) { - DataInputStream in = null; - - try { - in = new DataInputStream(new BufferedInputStream(new FileInputStream(mFile))); - - long start = System.nanoTime(); - - in.readShort(); - iCount = in.readInt(); - hCount = in.readInt(); - oCount = in.readInt(); - - classes = new String[oCount]; - for (int i = 0; i < classes.length; i++) { - classes[i] = in.readUTF(); - } - - iWeights = new float[hCount][]; - for (int i = 0; i < iWeights.length; i++) { - iWeights[i] = new float[iCount]; - for (int j = 0; j < iCount; j++) { - iWeights[i][j] = in.readFloat(); - } - } - - oWeights = new float[oCount][]; - for (int i = 0; i < oWeights.length; i++) { - oWeights[i] = new float[hCount]; - for (int j = 0; j < hCount; j++) { - oWeights[i][j] = in.readFloat(); - } - } - - long end = System.nanoTime(); - System.out.println("time to read binary file = " + - ((end - start) / 1000.0f / 1000.0f) + " ms"); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - close(in); - } - } - } - } - - private static void close(Closeable reader) { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public static void main(String[] args) { - String fileName = args[0]; - if (fileName != null) { - File file = new File(fileName); - if (!file.exists()) { - printHelp(fileName); - } else { - new Converter(file).convert(); - } - } else { - printHelp(null); - } - } - - private static void printHelp(String name) { - if (name == null) { - System.out.println("You must specify the name of the file to convert:"); - } else { - System.out.println("The specified file does not exist: " + name); - } - System.out.println("java Converter [filename]"); - System.out.println(""); - System.out.println("\t[filename]\tPath to the file to convert. The file is replaced by " - + "the conversion result."); - } -}
\ No newline at end of file |