From 3291c585e8e79a791afc709c314ce8c8c31d8abe Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 3 Sep 2010 21:41:32 +0000 Subject: [PATCH] Improve Volume navigation settings, fix a bug when a list view is in touch mode. Patch by fiouzy. --- res/values/strings.xml | 4 ++- res/xml/global_preferences.xml | 8 +++-- src/com/fsck/k9/K9.java | 13 ++++++++ src/com/fsck/k9/activity/K9ListActivity.java | 31 +++++++++++++------- src/com/fsck/k9/activity/MessageList.java | 28 +++++++++++++----- src/com/fsck/k9/activity/setup/Prefs.java | 10 ++++--- 6 files changed, 69 insertions(+), 25 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 54a42a73a..7baaf4df9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -835,8 +835,10 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Gestures Accept gesture control - Volume up/down nav + Volume up/down navigation Flip through items using the volume controls + Message view + Various list views Manage \"Back\" button Make \"Back\" always go up a level diff --git a/res/xml/global_preferences.xml b/res/xml/global_preferences.xml index 39c8c3fb5..71e7ea1a7 100644 --- a/res/xml/global_preferences.xml +++ b/res/xml/global_preferences.xml @@ -55,10 +55,14 @@ android:title="@string/gestures_title" android:summary="@string/gestures_summary" /> - + android:summary="@string/volume_navigation_summary" + android:dialogTitle="@string/volume_navigation_title" + android:positiveButtonText="@android:string/ok" + android:negativeButtonText="@android:string/cancel" + /> 0) + int currentPosition = listView.getSelectedItemPosition(); + if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) { - listView.setSelection(listView.getSelectedItemPosition()-1); + currentPosition = listView.getFirstVisiblePosition(); + } + if (currentPosition > 0) + { + listView.setSelection(currentPosition - 1); } return true; } } case KeyEvent.KEYCODE_VOLUME_DOWN: { - ListView listView = getListView(); - if (K9.useVolumeKeysForNavigationEnabled()) + final ListView listView = getListView(); + if (K9.useVolumeKeysForListNavigationEnabled()) { - if (listView.getSelectedItemPosition() < listView.getCount()) + int currentPosition = listView.getSelectedItemPosition(); + if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) { - listView.setSelection(listView.getSelectedItemPosition()+1); + currentPosition = listView.getFirstVisiblePosition(); + } + + if (currentPosition < listView.getCount()) + { + listView.setSelection(currentPosition + 1); } return true; } @@ -84,7 +95,7 @@ public class K9ListActivity extends ListActivity public boolean onKeyUp(int keyCode, KeyEvent event) { // Swallow these events too to avoid the audible notification of a volume change - if (K9.useVolumeKeysForNavigationEnabled()) + if (K9.useVolumeKeysForListNavigationEnabled()) { if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) { diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index b5a077e89..d356a0811 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -690,26 +690,38 @@ public class MessageList // in MessageView, we implement this bit of wrapper code case KeyEvent.KEYCODE_VOLUME_UP: { - if (K9.useVolumeKeysForNavigationEnabled()) + if (K9.useVolumeKeysForListNavigationEnabled()) { - - if (mListView.getSelectedItemPosition() > 0) + int currentPosition = mListView.getSelectedItemPosition(); + if (currentPosition == AdapterView.INVALID_POSITION || mListView.isInTouchMode()) { - mListView.setSelection(mListView.getSelectedItemPosition()-1); + currentPosition = mListView.getFirstVisiblePosition(); + } + if (currentPosition > 0) + { + mListView.setSelection(currentPosition - 1); } return true; } + return false; } case KeyEvent.KEYCODE_VOLUME_DOWN: { - if (K9.useVolumeKeysForNavigationEnabled()) + if (K9.useVolumeKeysForListNavigationEnabled()) { - if (mListView.getSelectedItemPosition() < mListView.getCount()) + int currentPosition = mListView.getSelectedItemPosition(); + if (currentPosition == AdapterView.INVALID_POSITION || mListView.isInTouchMode()) { - mListView.setSelection(mListView.getSelectedItemPosition()+1); + currentPosition = mListView.getFirstVisiblePosition(); + } + + if (currentPosition < mListView.getCount()) + { + mListView.setSelection(currentPosition + 1); } return true; } + return false; } case KeyEvent.KEYCODE_DPAD_LEFT: { @@ -842,7 +854,7 @@ public class MessageList public boolean onKeyUp(int keyCode, KeyEvent event) { // Swallow these events too to avoid the audible notification of a volume change - if (K9.useVolumeKeysForNavigationEnabled()) + if (K9.useVolumeKeysForListNavigationEnabled()) { if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) { diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java index b26a99544..5c698d40a 100644 --- a/src/com/fsck/k9/activity/setup/Prefs.java +++ b/src/com/fsck/k9/activity/setup/Prefs.java @@ -67,7 +67,7 @@ public class Prefs extends K9PreferenceActivity private CheckBoxPreference mDebugLogging; private CheckBoxPreference mSensitiveLogging; private CheckBoxPreference mGestures; - private CheckBoxPreference mVolumeNavigation; + private CheckboxListPreference mVolumeNavigation; private CheckBoxPreference mManageBack; private CheckBoxPreference mStartIntegratedInbox; private CheckBoxPreference mAnimations; @@ -210,8 +210,9 @@ public class Prefs extends K9PreferenceActivity mAnimations.setChecked(K9.showAnimations()); mGestures = (CheckBoxPreference)findPreference(PREFERENCE_GESTURES); mGestures.setChecked(K9.gesturesEnabled()); - mVolumeNavigation = (CheckBoxPreference)findPreference(PREFERENCE_VOLUME_NAVIGATION); - mVolumeNavigation.setChecked(K9.useVolumeKeysForNavigationEnabled()); + mVolumeNavigation = (CheckboxListPreference)findPreference(PREFERENCE_VOLUME_NAVIGATION); + mVolumeNavigation.setItems(new CharSequence[] {getString(R.string.volume_navigation_message), getString(R.string.volume_navigation_list)}); + mVolumeNavigation.setCheckedItems(new boolean[] {K9.useVolumeKeysForNavigationEnabled(), K9.useVolumeKeysForListNavigationEnabled()}); mManageBack = (CheckBoxPreference)findPreference(PREFERENCE_MANAGE_BACK); mManageBack.setChecked(K9.manageBack()); @@ -274,7 +275,8 @@ public class Prefs extends K9PreferenceActivity K9.setAnimations(mAnimations.isChecked()); K9.setGesturesEnabled(mGestures.isChecked()); - K9.setUseVolumeKeysForNavigation(mVolumeNavigation.isChecked()); + K9.setUseVolumeKeysForNavigation(mVolumeNavigation.getCheckedItems()[0]); + K9.setUseVolumeKeysForListNavigation(mVolumeNavigation.getCheckedItems()[1]); K9.setManageBack(mManageBack.isChecked()); K9.setStartIntegratedInbox(mStartIntegratedInbox.isChecked()); K9.setMessageListStars(mStars.isChecked());