mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-31 07:10:14 -05:00
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
@ -1,6 +1,9 @@
|
|||||||
package com.fsck.k9.activity;
|
package com.fsck.k9.activity;
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
|
|
||||||
@ -41,4 +44,51 @@ public class K9ListActivity extends ListActivity
|
|||||||
{
|
{
|
||||||
return mDateFormat;
|
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
|
// Shortcuts that work no matter what is selected
|
||||||
switch (keyCode)
|
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:
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||||
{
|
{
|
||||||
if (mBatchButtonArea.hasFocus())
|
if (mBatchButtonArea.hasFocus())
|
||||||
@ -804,6 +829,21 @@ public class MessageList
|
|||||||
return result;
|
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)
|
private void onOpenMessage(MessageInfoHolder message)
|
||||||
{
|
{
|
||||||
if (message.folder.name.equals(message.message.getFolder().getAccount().getDraftsFolderName()))
|
if (message.folder.name.equals(message.message.getFolder().getAccount().getDraftsFolderName()))
|
||||||
|
@ -215,6 +215,22 @@ public class MessageView extends K9Activity implements OnClickListener
|
|||||||
{
|
{
|
||||||
switch (keyCode)
|
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_LEFT:
|
||||||
case KeyEvent.KEYCODE_SHIFT_RIGHT:
|
case KeyEvent.KEYCODE_SHIFT_RIGHT:
|
||||||
{
|
{
|
||||||
@ -336,6 +352,20 @@ public class MessageView extends K9Activity implements OnClickListener
|
|||||||
return super.onKeyDown(keyCode, event);
|
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
|
class MessageViewHandler extends Handler
|
||||||
{
|
{
|
||||||
public void progress(final boolean progress)
|
public void progress(final boolean progress)
|
||||||
|
Loading…
Reference in New Issue
Block a user