From 6bb9983d58538e632b5170a788fd77a957365bf7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 7 Sep 2015 20:45:21 +0200 Subject: added rotation detection to up/down navigation --- .../conversations/ui/ConversationActivity.java | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index e0824575..4399e7c4 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -20,6 +20,7 @@ import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; +import android.view.Surface; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; @@ -862,19 +863,37 @@ public class ConversationActivity extends XmppActivity @Override public boolean onKeyUp(int key, KeyEvent event) { + int rotation = getWindowManager().getDefaultDisplay().getRotation(); + final int upKey; + final int downKey; + switch(rotation) { + case Surface.ROTATION_90: + upKey = KeyEvent.KEYCODE_DPAD_LEFT; + downKey = KeyEvent.KEYCODE_DPAD_RIGHT; + break; + case Surface.ROTATION_180: + upKey = KeyEvent.KEYCODE_DPAD_DOWN; + downKey = KeyEvent.KEYCODE_DPAD_UP; + break; + case Surface.ROTATION_270: + upKey = KeyEvent.KEYCODE_DPAD_RIGHT; + downKey = KeyEvent.KEYCODE_DPAD_LEFT; + break; + default: + upKey = KeyEvent.KEYCODE_DPAD_UP; + downKey = KeyEvent.KEYCODE_DPAD_DOWN; + } final boolean modifier = event.isCtrlPressed(); - final boolean upKey = key == KeyEvent.KEYCODE_DPAD_UP || key == KeyEvent.KEYCODE_DPAD_LEFT; - final boolean downKey = key == KeyEvent.KEYCODE_DPAD_DOWN || key == KeyEvent.KEYCODE_DPAD_RIGHT; if (modifier && key == KeyEvent.KEYCODE_TAB && isConversationsOverviewHideable()) { toggleConversationsOverview(); return true; - } else if (modifier && downKey) { + } else if (modifier && key == downKey) { if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) { showConversationsOverview();; } selectDownConversation(); return true; - } else if (modifier && upKey) { + } else if (modifier && key == upKey) { if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) { showConversationsOverview();; } -- cgit v1.2.3