1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Improve Volume navigation settings, fix a bug when a list view is in

touch mode.

Patch by fiouzy.
This commit is contained in:
Jesse Vincent 2010-09-03 21:41:32 +00:00
parent de31886f44
commit 3291c585e8
6 changed files with 69 additions and 25 deletions

View File

@ -835,8 +835,10 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="gestures_title">Gestures</string>
<string name="gestures_summary">Accept gesture control</string>
<string name="volume_navigation_title">Volume up/down nav</string>
<string name="volume_navigation_title">Volume up/down navigation</string>
<string name="volume_navigation_summary">Flip through items using the volume controls</string>
<string name="volume_navigation_message">Message view</string>
<string name="volume_navigation_list">Various list views</string>
<string name="manage_back_title">Manage \"Back\" button</string>
<string name="manage_back_summary">Make \"Back\" always go up a level</string>

View File

@ -55,10 +55,14 @@
android:title="@string/gestures_title"
android:summary="@string/gestures_summary" />
<CheckBoxPreference
<com.fsck.k9.preferences.CheckboxListPreference
android:key="volumeNavigation"
android:title="@string/volume_navigation_title"
android:summary="@string/volume_navigation_summary" />
android:summary="@string/volume_navigation_summary"
android:dialogTitle="@string/volume_navigation_title"
android:positiveButtonText="@android:string/ok"
android:negativeButtonText="@android:string/cancel"
/>
<CheckBoxPreference
android:key="manage_back"

View File

@ -118,6 +118,7 @@ public class K9 extends Application
private static boolean mGesturesEnabled = true;
private static boolean mUseVolumeKeysForNavigation = false;
private static boolean mUseVolumeKeysForListNavigation = false;
private static boolean mManageBack = false;
private static boolean mStartIntegratedInbox = false;
private static boolean mMeasureAccounts = true;
@ -340,6 +341,7 @@ public class K9 extends Application
editor.putBoolean("animations", mAnimations);
editor.putBoolean("gesturesEnabled", mGesturesEnabled);
editor.putBoolean("useVolumeKeysForNavigation", mUseVolumeKeysForNavigation);
editor.putBoolean("useVolumeKeysForListNavigation", mUseVolumeKeysForListNavigation);
editor.putBoolean("manageBack", mManageBack);
editor.putBoolean("startIntegratedInbox", mStartIntegratedInbox);
editor.putBoolean("measureAccounts", mMeasureAccounts);
@ -377,6 +379,7 @@ public class K9 extends Application
mAnimations = sprefs.getBoolean("animations", true);
mGesturesEnabled = sprefs.getBoolean("gesturesEnabled", true);
mUseVolumeKeysForNavigation = sprefs.getBoolean("useVolumeKeysForNavigation", false);
mUseVolumeKeysForListNavigation = sprefs.getBoolean("useVolumeKeysForListNavigation", false);
mManageBack = sprefs.getBoolean("manageBack", false);
mStartIntegratedInbox = sprefs.getBoolean("startIntegratedInbox", false);
mMeasureAccounts = sprefs.getBoolean("measureAccounts", true);
@ -539,6 +542,16 @@ public class K9 extends Application
mUseVolumeKeysForNavigation = volume;
}
public static boolean useVolumeKeysForListNavigationEnabled()
{
return mUseVolumeKeysForListNavigation;
}
public static void setUseVolumeKeysForListNavigation(boolean enabled)
{
mUseVolumeKeysForListNavigation = enabled;
}
public static boolean manageBack()
{
return mManageBack;

View File

@ -3,6 +3,7 @@ package com.fsck.k9.activity;
import android.app.ListActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.AdapterView;
import android.widget.ListView;
import android.os.Bundle;
import com.fsck.k9.K9;
@ -53,25 +54,35 @@ public class K9ListActivity extends ListActivity
{
case KeyEvent.KEYCODE_VOLUME_UP:
{
ListView listView = getListView();
if (K9.useVolumeKeysForNavigationEnabled())
final ListView listView = getListView();
if (K9.useVolumeKeysForListNavigationEnabled())
{
if (listView.getSelectedItemPosition() > 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))
{

View File

@ -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))
{

View File

@ -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());