diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-05 23:39:25 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-05 23:50:13 -0400 |
commit | 718bef72f9f674151580a1babe237fb6fdeb8266 (patch) | |
tree | 2feb02c14ab3cd7a9a173f833e16ea2722403b9f | |
parent | 8b795e605aa2ebfd385ee83b0f1b698435737b47 (diff) |
Whitespace and formatting
-rw-r--r-- | AndroidManifest.xml | 17 | ||||
-rw-r--r-- | res/layout/gesture_create.xml | 51 | ||||
-rw-r--r-- | res/layout/gestures_item.xml | 8 | ||||
-rw-r--r-- | res/layout/ime.xml | 4 | ||||
-rw-r--r-- | res/values-v11/styles.xml | 3 | ||||
-rw-r--r-- | res/values-v14/styles.xml | 3 | ||||
-rw-r--r-- | res/values/colors.xml | 2 | ||||
-rw-r--r-- | res/values/dimens.xml | 2 | ||||
-rw-r--r-- | res/values/strings.xml | 1 | ||||
-rw-r--r-- | res/values/styles.xml | 3 | ||||
-rw-r--r-- | src/us/minak/SettingsActivity.java | 515 | ||||
-rw-r--r-- | src/us/minak/SettingsCreateGestureActivity.java | 192 |
12 files changed, 412 insertions, 389 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index fda3879..b16718d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,3 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="us.minak" android:versionCode="1" @@ -14,17 +15,23 @@ android:theme="@style/AppTheme" > <!-- The main input service --> - <service android:name="IMEService" + <service + android:name="IMEService" android:label="@string/minak_ime_label" - android:permission="android.permission.BIND_INPUT_METHOD"> + android:permission="android.permission.BIND_INPUT_METHOD" > <intent-filter> <action android:name="android.view.InputMethod" /> </intent-filter> - <meta-data android:name="android.view.im" android:resource="@xml/method" /> + + <meta-data + android:name="android.view.im" + android:resource="@xml/method" /> </service> <!-- The settings menu activity --> - <activity android:name=".SettingsActivity" android:label="@string/minak_settings_label"> + <activity + android:name="SettingsActivity" + android:label="@string/minak_settings_label" > <intent-filter> <action android:name="android.intent.action.MAIN" /> </intent-filter> @@ -32,7 +39,7 @@ <!-- The individual gesture editor --> <activity - android:name="CreateGestureActivity" + android:name="SettingsCreateGestureActivity" android:label="@string/label_create_gesture" /> </application> diff --git a/res/layout/gesture_create.xml b/res/layout/gesture_create.xml index 2864bc7..60eccb8 100644 --- a/res/layout/gesture_create.xml +++ b/res/layout/gesture_create.xml @@ -14,75 +14,70 @@ limitations under the License. --> -<LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - - android:orientation="vertical"> + android:orientation="vertical" > <!-- The "Name" bar at the top --> + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> - <!-- The prompt --> + android:orientation="horizontal" > + + <!-- The prompt --> + <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="6dip" - android:text="@string/prompt_gesture_name" android:textAppearance="?android:attr/textAppearanceMedium" /> <!-- The input --> + <EditText android:id="@+id/gesture_name" android:layout_width="0dip" - android:layout_weight="1.0" android:layout_height="wrap_content" + android:layout_weight="1.0" android:inputType="text" - android:maxLength="40" android:singleLine="true" /> - </LinearLayout> <!-- The gesture input --> + <android.gesture.GestureOverlayView android:id="@+id/gestures_overlay" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1.0" - android:gestureStrokeType="multiple" /> - <!-- The "add" and "cancel" buttons --> + <!-- The "add" and "cancel" buttons --> + <LinearLayout style="@android:style/ButtonBar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="horizontal" > <Button android:id="@+id/done" - android:onClick="addGesture" - android:text="@string/button_done" - - android:enabled="false" - + style="?android:attr/buttonBarButtonStyle" android:layout_width="0dip" android:layout_height="wrap_content" - android:layout_weight="1" - style="?android:attr/buttonBarButtonStyle" /> + android:layout_weight="1" + android:enabled="false" + android:onClick="addGesture" + android:text="@string/button_done" /> <Button - android:onClick="cancelGesture" - android:text="@string/button_discard" - + style="?android:attr/buttonBarButtonStyle" android:layout_width="0dip" android:layout_height="wrap_content" - android:layout_weight="1" - style="?android:attr/buttonBarButtonStyle" /> - + android:layout_weight="1" + android:onClick="cancelGesture" + android:text="@string/button_discard" /> </LinearLayout> - + </LinearLayout> diff --git a/res/layout/gestures_item.xml b/res/layout/gestures_item.xml index 36c93b8..1739a19 100644 --- a/res/layout/gestures_item.xml +++ b/res/layout/gestures_item.xml @@ -13,19 +13,15 @@ See the License for the specific language governing permissions and limitations under the License. --> - <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" - + android:drawablePadding="12dip" + android:ellipsize="marquee" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight" - - android:drawablePadding="12dip" android:paddingLeft="6dip" android:paddingRight="6dip" - - android:ellipsize="marquee" android:singleLine="true" android:textAppearance="?android:attr/textAppearanceLarge" /> diff --git a/res/layout/ime.xml b/res/layout/ime.xml index 34bbd6d..7ef50a1 100644 --- a/res/layout/ime.xml +++ b/res/layout/ime.xml @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <us.minak.IMEView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" - android:layout_height="match_parent"> - + android:layout_height="match_parent" > + <us.minak.IMEGestureOverlayView android:id="@+id/drawing_space" android:layout_width="wrap_content" diff --git a/res/values-v11/styles.xml b/res/values-v11/styles.xml index 3c02242..0e7dbb1 100644 --- a/res/values-v11/styles.xml +++ b/res/values-v11/styles.xml @@ -1,4 +1,5 @@ -<resources> +<?xml version="1.0" encoding="utf-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Base application theme for API 11+. This theme completely replaces diff --git a/res/values-v14/styles.xml b/res/values-v14/styles.xml index a91fd03..6f58eb0 100644 --- a/res/values-v14/styles.xml +++ b/res/values-v14/styles.xml @@ -1,4 +1,5 @@ -<resources> +<?xml version="1.0" encoding="utf-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Base application theme for API 14+. This theme completely replaces diff --git a/res/values/colors.xml b/res/values/colors.xml index c180987..ca6e02a 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -1,4 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> -<resources> +<resources xmlns:android="http://schemas.android.com/apk/res/android"> <color name="gesture_color">#FFFFFF00</color> </resources> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 1a6cbca..7a57a2e 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<resources> +<resources xmlns:android="http://schemas.android.com/apk/res/android"> <dimen name="gesture_thumbnail_inset">8dip</dimen> <dimen name="gesture_thumbnail_size">64dip</dimen> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index e6474ea..6cdc831 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,3 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <string name="app_name">Minak</string> diff --git a/res/values/styles.xml b/res/values/styles.xml index 6ce89c7..fcf4c0f 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -1,4 +1,5 @@ -<resources> +<?xml version="1.0" encoding="utf-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Base application theme, dependent on API level. This theme is replaced diff --git a/src/us/minak/SettingsActivity.java b/src/us/minak/SettingsActivity.java index c052e6c..a3dea5c 100644 --- a/src/us/minak/SettingsActivity.java +++ b/src/us/minak/SettingsActivity.java @@ -44,253 +44,270 @@ import java.util.HashMap; import java.util.Comparator; public class SettingsActivity extends ListActivity { - private static final int STATUS_SUCCESS = 0; - private static final int STATUS_CANCELLED = 1; - private static final int STATUS_NO_STORAGE = 2; - private static final int STATUS_NOT_LOADED = 3; - - private static final int MENU_ID_REMOVE = 1; - - private static final int REQUEST_NEW_GESTURE = 1; - - private final Comparator<NamedGesture> mSorter = new Comparator<NamedGesture>() { - public int compare(NamedGesture object1, NamedGesture object2) { - return object1.name.compareTo(object2.name); - } - }; - - private GesturesAdapter mAdapter; - private GesturesLoadTask mTask; - private TextView mEmptyMessageView; - - // Hacky constructor to get 'this' out of scope /////////////////////////// - - private SettingsActivity mThis; - public SettingsActivity() { - super(); - 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)); - - 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, 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: - loadGestures(); - break; - } - } - } - - // Context menu /////////////////////////////////////////////////////////// - - @Override - 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_REMOVE, 0, R.string.gestures_delete); - } - - @Override - public boolean onContextItemSelected(MenuItem item) { - final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) - item.getMenuInfo(); - final NamedGesture gesture = (NamedGesture) menuInfo.targetView.getTag(); - - switch (item.getItemId()) { - case MENU_ID_REMOVE: - SettingsUtil.getGestureLibrary(this).removeGesture(gesture.name, gesture.gesture); - SettingsUtil.getGestureLibrary(this).save(); - - mAdapter.setNotifyOnChange(false); - mAdapter.remove(gesture); - mAdapter.sort(mSorter); - checkForEmpty(); - mAdapter.notifyDataSetChanged(); - - Toast.makeText(this, R.string.gestures_delete_success, Toast.LENGTH_SHORT).show(); - return true; - } - - return super.onContextItemSelected(item); - } - - /////////////////////////////////////////////////////////////////////////// - - private class GesturesLoadTask extends AsyncTask<Void, NamedGesture, Integer> { - private int mThumbnailSize; - private int mThumbnailInset; - private int mPathColor; - - @Override - protected void onPreExecute() { - super.onPreExecute(); - - final Resources resources = getResources(); - mPathColor = resources.getColor(R.color.gesture_color); - mThumbnailInset = (int) resources.getDimension(R.dimen.gesture_thumbnail_inset); - mThumbnailSize = (int) resources.getDimension(R.dimen.gesture_thumbnail_size); - - findViewById(R.id.addButton).setEnabled(false); - findViewById(R.id.reloadButton).setEnabled(false); - - mAdapter.setNotifyOnChange(false); - mAdapter.clear(); - } - - @Override - protected Integer doInBackground(Void... params) { - if (isCancelled()) return STATUS_CANCELLED; - if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { - return STATUS_NO_STORAGE; - } - - final GestureLibrary store = SettingsUtil.getGestureLibrary(mThis); - - if (store.load()) { - for (String name : store.getGestureEntries()) { - if (isCancelled()) break; - - for (Gesture gesture : store.getGestures(name)) { - final Bitmap bitmap = gesture.toBitmap(mThumbnailSize, mThumbnailSize, - mThumbnailInset, mPathColor); - final NamedGesture namedGesture = new NamedGesture(); - namedGesture.gesture = gesture; - namedGesture.name = name; - - mAdapter.addBitmap(namedGesture.gesture.getID(), bitmap); - publishProgress(namedGesture); - } - } - - return STATUS_SUCCESS; - } - - return STATUS_NOT_LOADED; - } - - @Override - protected void onProgressUpdate(NamedGesture... values) { - super.onProgressUpdate(values); - - final GesturesAdapter adapter = mAdapter; - adapter.setNotifyOnChange(false); - - for (NamedGesture gesture : values) { - adapter.add(gesture); - } - - adapter.sort(mSorter); - adapter.notifyDataSetChanged(); - } - - @Override - protected void onPostExecute(Integer result) { - super.onPostExecute(result); - - if (result == STATUS_NO_STORAGE) { - getListView().setVisibility(View.GONE); - 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); - checkForEmpty(); - } - } - } - - static class NamedGesture { - String name; - Gesture gesture; - } - - private class GesturesAdapter extends ArrayAdapter<NamedGesture> { - private final LayoutInflater mInflater; - private final Map<Long, Drawable> mThumbnails = Collections.synchronizedMap( - new HashMap<Long, Drawable>()); - - public GesturesAdapter(Context context) { - super(context, 0); - mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } - - void addBitmap(Long id, Bitmap bitmap) { - mThumbnails.put(id, new BitmapDrawable(getResources(), bitmap)); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - if (convertView == null) { - convertView = mInflater.inflate(R.layout.gestures_item, parent, false); - } - - final NamedGesture gesture = getItem(position); - final TextView label = (TextView) convertView; - - label.setTag(gesture); - label.setText(gesture.name); - label.setCompoundDrawablesWithIntrinsicBounds(mThumbnails.get(gesture.gesture.getID()), - null, null, null); - - return convertView; - } - } + private static final int STATUS_SUCCESS = 0; + private static final int STATUS_CANCELLED = 1; + private static final int STATUS_NO_STORAGE = 2; + private static final int STATUS_NOT_LOADED = 3; + + private static final int MENU_ID_REMOVE = 1; + + private static final int REQUEST_NEW_GESTURE = 1; + + private final Comparator<NamedGesture> mSorter = new Comparator<NamedGesture>() { + public int compare(NamedGesture object1, NamedGesture object2) { + return object1.name.compareTo(object2.name); + } + }; + + private GesturesAdapter mAdapter; + private GesturesLoadTask mTask; + private TextView mEmptyMessageView; + + // Hacky constructor to get 'this' out of scope /////////////////////////// + + private SettingsActivity mThis; + + public SettingsActivity() { + super(); + 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)); + + 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, 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: + loadGestures(); + break; + } + } + } + + // Context menu /////////////////////////////////////////////////////////// + + @Override + 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_REMOVE, 0, R.string.gestures_delete); + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item + .getMenuInfo(); + final NamedGesture gesture = (NamedGesture) menuInfo.targetView + .getTag(); + + switch (item.getItemId()) { + case MENU_ID_REMOVE: + SettingsUtil.getGestureLibrary(this).removeGesture(gesture.name, + gesture.gesture); + SettingsUtil.getGestureLibrary(this).save(); + + mAdapter.setNotifyOnChange(false); + mAdapter.remove(gesture); + mAdapter.sort(mSorter); + checkForEmpty(); + mAdapter.notifyDataSetChanged(); + + Toast.makeText(this, R.string.gestures_delete_success, + Toast.LENGTH_SHORT).show(); + return true; + } + + return super.onContextItemSelected(item); + } + + // ///////////////////////////////////////////////////////////////////////// + + private class GesturesLoadTask extends + AsyncTask<Void, NamedGesture, Integer> { + private int mThumbnailSize; + private int mThumbnailInset; + private int mPathColor; + + @Override + protected void onPreExecute() { + super.onPreExecute(); + + final Resources resources = getResources(); + mPathColor = resources.getColor(R.color.gesture_color); + mThumbnailInset = (int) resources + .getDimension(R.dimen.gesture_thumbnail_inset); + mThumbnailSize = (int) resources + .getDimension(R.dimen.gesture_thumbnail_size); + + findViewById(R.id.addButton).setEnabled(false); + findViewById(R.id.reloadButton).setEnabled(false); + + mAdapter.setNotifyOnChange(false); + mAdapter.clear(); + } + + @Override + protected Integer doInBackground(Void... params) { + if (isCancelled()) + return STATUS_CANCELLED; + if (!Environment.MEDIA_MOUNTED.equals(Environment + .getExternalStorageState())) { + return STATUS_NO_STORAGE; + } + + final GestureLibrary store = SettingsUtil.getGestureLibrary(mThis); + + if (store.load()) { + for (String name : store.getGestureEntries()) { + if (isCancelled()) + break; + + for (Gesture gesture : store.getGestures(name)) { + final Bitmap bitmap = gesture.toBitmap(mThumbnailSize, + mThumbnailSize, mThumbnailInset, mPathColor); + final NamedGesture namedGesture = new NamedGesture(); + namedGesture.gesture = gesture; + namedGesture.name = name; + + mAdapter.addBitmap(namedGesture.gesture.getID(), bitmap); + publishProgress(namedGesture); + } + } + + return STATUS_SUCCESS; + } + + return STATUS_NOT_LOADED; + } + + @Override + protected void onProgressUpdate(NamedGesture... values) { + super.onProgressUpdate(values); + + final GesturesAdapter adapter = mAdapter; + adapter.setNotifyOnChange(false); + + for (NamedGesture gesture : values) { + adapter.add(gesture); + } + + adapter.sort(mSorter); + adapter.notifyDataSetChanged(); + } + + @Override + protected void onPostExecute(Integer result) { + super.onPostExecute(result); + + if (result == STATUS_NO_STORAGE) { + getListView().setVisibility(View.GONE); + 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); + checkForEmpty(); + } + } + } + + static class NamedGesture { + String name; + Gesture gesture; + } + + private class GesturesAdapter extends ArrayAdapter<NamedGesture> { + private final LayoutInflater mInflater; + private final Map<Long, Drawable> mThumbnails = Collections + .synchronizedMap(new HashMap<Long, Drawable>()); + + public GesturesAdapter(Context context) { + super(context, 0); + mInflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + void addBitmap(Long id, Bitmap bitmap) { + mThumbnails.put(id, new BitmapDrawable(getResources(), bitmap)); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = mInflater.inflate(R.layout.gestures_item, parent, + false); + } + + final NamedGesture gesture = getItem(position); + final TextView label = (TextView) convertView; + + label.setTag(gesture); + label.setText(gesture.name); + label.setCompoundDrawablesWithIntrinsicBounds( + mThumbnails.get(gesture.gesture.getID()), null, null, null); + + return convertView; + } + } } diff --git a/src/us/minak/SettingsCreateGestureActivity.java b/src/us/minak/SettingsCreateGestureActivity.java index 64975e0..2e450d0 100644 --- a/src/us/minak/SettingsCreateGestureActivity.java +++ b/src/us/minak/SettingsCreateGestureActivity.java @@ -27,98 +27,102 @@ import android.widget.TextView; import android.widget.Toast; public class SettingsCreateGestureActivity extends Activity { - private static final float LENGTH_THRESHOLD = 120.0f; - - private Gesture mGesture; - private View mDoneButton; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.gesture_create); - - mDoneButton = findViewById(R.id.done); - - GestureOverlayView overlay = (GestureOverlayView) findViewById(R.id.gestures_overlay); - overlay.addOnGestureListener(new GesturesProcessor()); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - - if (mGesture != null) { - outState.putParcelable("gesture", mGesture); - } - } - - @Override - protected void onRestoreInstanceState(Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - - mGesture = savedInstanceState.getParcelable("gesture"); - if (mGesture != null) { - final GestureOverlayView overlay = - (GestureOverlayView) findViewById(R.id.gestures_overlay); - overlay.post(new Runnable() { - public void run() { - overlay.setGesture(mGesture); - } - }); - - mDoneButton.setEnabled(true); - } - } - - public void addGesture(View v) { - if (mGesture != null) { - final TextView input = (TextView) findViewById(R.id.gesture_name); - final CharSequence name = input.getText(); - if (name.length() == 0) { - input.setError(getString(R.string.error_missing_name)); - return; - } - - final GestureLibrary store = SettingsUtil.getGestureLibrary(this); - store.addGesture(name.toString(), mGesture); - store.save(); - - setResult(RESULT_OK); - - 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); - mGesture = null; - } - - public void onGesture(GestureOverlayView overlay, MotionEvent event) { - } - - public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { - mGesture = overlay.getGesture(); - if (mGesture.getLength() < LENGTH_THRESHOLD) { - overlay.clear(false); - } - mDoneButton.setEnabled(true); - } - - public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) { - } - } + private static final float LENGTH_THRESHOLD = 120.0f; + + private Gesture mGesture; + private View mDoneButton; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.gesture_create); + + mDoneButton = findViewById(R.id.done); + + GestureOverlayView overlay = (GestureOverlayView) findViewById(R.id.gestures_overlay); + overlay.addOnGestureListener(new GesturesProcessor()); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + if (mGesture != null) { + outState.putParcelable("gesture", mGesture); + } + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + + mGesture = savedInstanceState.getParcelable("gesture"); + if (mGesture != null) { + final GestureOverlayView overlay = (GestureOverlayView) findViewById(R.id.gestures_overlay); + overlay.post(new Runnable() { + public void run() { + overlay.setGesture(mGesture); + } + }); + + mDoneButton.setEnabled(true); + } + } + + public void addGesture(View v) { + if (mGesture != null) { + final TextView input = (TextView) findViewById(R.id.gesture_name); + final CharSequence name = input.getText(); + if (name.length() == 0) { + input.setError(getString(R.string.error_missing_name)); + return; + } + + final GestureLibrary store = SettingsUtil.getGestureLibrary(this); + store.addGesture(name.toString(), mGesture); + store.save(); + + setResult(RESULT_OK); + + 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); + mGesture = null; + } + + public void onGesture(GestureOverlayView overlay, MotionEvent event) { + } + + public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { + mGesture = overlay.getGesture(); + if (mGesture.getLength() < LENGTH_THRESHOLD) { + overlay.clear(false); + } + mDoneButton.setEnabled(true); + } + + public void onGestureCancelled(GestureOverlayView overlay, + MotionEvent event) { + } + } } |