Add Volume button navigation in MessageView, MessageList and all
K9ListActivity subclasses. The MessageView code is a patch from paulkilroy@gmail.com. Fixes Issue 2112
This commit is contained in:
parent
0f1a1baa89
commit
65f0d22355
3 changed files with 120 additions and 0 deletions
|
@ -1,6 +1,9 @@
|
|||
package com.fsck.k9.activity;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.ListView;
|
||||
import android.os.Bundle;
|
||||
import com.fsck.k9.K9;
|
||||
|
||||
|
@ -41,4 +44,51 @@ public class K9ListActivity extends ListActivity
|
|||
{
|
||||
return mDateFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
// Shortcuts that work no matter what is selected
|
||||
switch (keyCode)
|
||||
{
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
{
|
||||
ListView listView = getListView();
|
||||
if(K9.useVolumeKeysForNavigationEnabled())
|
||||
{
|
||||
|
||||
if (listView.getSelectedItemPosition() > 0) {
|
||||
listView.setSelection(listView.getSelectedItemPosition()-1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
{
|
||||
ListView listView = getListView();
|
||||
if(K9.useVolumeKeysForNavigationEnabled())
|
||||
{
|
||||
if (listView.getSelectedItemPosition() < listView.getCount()) {
|
||||
listView.setSelection(listView.getSelectedItemPosition()+1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event)
|
||||
{
|
||||
// Swallow these events too to avoid the audible notification of a volume change
|
||||
if(K9.useVolumeKeysForNavigationEnabled()) {
|
||||
if((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Swallowed key up.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onKeyUp(keyCode,event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -675,6 +675,31 @@ public class MessageList
|
|||
// Shortcuts that work no matter what is selected
|
||||
switch (keyCode)
|
||||
{
|
||||
|
||||
// messagelist is actually a K9Activity, not a K9ListActivity
|
||||
// This saddens me greatly, but to support volume key navigation
|
||||
// in MessageView, we implement this bit of wrapper code
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
{
|
||||
if(K9.useVolumeKeysForNavigationEnabled())
|
||||
{
|
||||
|
||||
if (mListView.getSelectedItemPosition() > 0) {
|
||||
mListView.setSelection(mListView.getSelectedItemPosition()-1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
{
|
||||
if(K9.useVolumeKeysForNavigationEnabled())
|
||||
{
|
||||
if (mListView.getSelectedItemPosition() < mListView.getCount()) {
|
||||
mListView.setSelection(mListView.getSelectedItemPosition()+1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||
{
|
||||
if (mBatchButtonArea.hasFocus())
|
||||
|
@ -804,6 +829,21 @@ public class MessageList
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event)
|
||||
{
|
||||
// Swallow these events too to avoid the audible notification of a volume change
|
||||
if(K9.useVolumeKeysForNavigationEnabled()) {
|
||||
if((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Swallowed key up.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onKeyUp(keyCode,event);
|
||||
}
|
||||
|
||||
|
||||
private void onOpenMessage(MessageInfoHolder message)
|
||||
{
|
||||
if (message.folder.name.equals(message.message.getFolder().getAccount().getDraftsFolderName()))
|
||||
|
|
|
@ -215,6 +215,22 @@ public class MessageView extends K9Activity implements OnClickListener
|
|||
{
|
||||
switch (keyCode)
|
||||
{
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
{
|
||||
if(K9.useVolumeKeysForNavigationEnabled())
|
||||
{
|
||||
onPrevious(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
{
|
||||
if(K9.useVolumeKeysForNavigationEnabled())
|
||||
{
|
||||
onNext(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case KeyEvent.KEYCODE_SHIFT_LEFT:
|
||||
case KeyEvent.KEYCODE_SHIFT_RIGHT:
|
||||
{
|
||||
|
@ -336,6 +352,20 @@ public class MessageView extends K9Activity implements OnClickListener
|
|||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event)
|
||||
{
|
||||
// Swallow these events too to avoid the audible notification of a volume change
|
||||
if(K9.useVolumeKeysForNavigationEnabled()) {
|
||||
if((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "Swallowed key up.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onKeyUp(keyCode,event);
|
||||
}
|
||||
|
||||
class MessageViewHandler extends Handler
|
||||
{
|
||||
public void progress(final boolean progress)
|
||||
|
|
Loading…
Reference in a new issue