added some key binding

* ctrl + tab will open the conversations overview (when available)
* ctrl + up / down will navigate between conversations
This commit is contained in:
Daniel Gultsch 2015-09-07 15:46:22 +02:00
parent 88cdd03f0f
commit 6308dcfdd4
3 changed files with 87 additions and 5 deletions

View file

@ -17,6 +17,7 @@ import android.provider.MediaStore;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -88,6 +89,8 @@ public class ConversationActivity extends XmppActivity
private Uri mPendingGeoUri = null;
private boolean forbidProcessingPendings = false;
private boolean conversationWasSelectedByKeyboard = false;
private View mContentView;
private List<Conversation> conversationList = new ArrayList<>();
@ -190,6 +193,7 @@ public class ConversationActivity extends XmppActivity
if (getSelectedConversation() != conversationList.get(position)) {
setSelectedConversation(conversationList.get(position));
ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
conversationWasSelectedByKeyboard = false;
}
hideConversationsOverview();
openConversation();
@ -856,6 +860,76 @@ public class ConversationActivity extends XmppActivity
}
}
@Override
public boolean onKeyUp(int key, KeyEvent event) {
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) {
if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) {
showConversationsOverview();;
}
selectDownConversation();
return true;
} else if (modifier && upKey) {
if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) {
showConversationsOverview();;
}
selectUpConversation();
return true;
} else {
return super.onKeyUp(key, event);
}
}
private void toggleConversationsOverview() {
if (isConversationsOverviewVisable()) {
hideConversationsOverview();
if (mConversationFragment != null) {
mConversationFragment.setFocusOnInputField();
}
} else {
showConversationsOverview();
}
}
private void selectUpConversation() {
Log.d(Config.LOGTAG,"select up conversation");
if (this.mSelectedConversation != null) {
int index = this.conversationList.indexOf(this.mSelectedConversation);
if (index > 0) {
int next = index - 1;
this.conversationWasSelectedByKeyboard = true;
setSelectedConversation(this.conversationList.get(next));
this.mConversationFragment.reInit(getSelectedConversation());
if (next > listView.getLastVisiblePosition() -1 || next < listView.getFirstVisiblePosition() + 1) {
this.listView.setSelection(next);
}
openConversation();
}
}
}
private void selectDownConversation() {
Log.d(Config.LOGTAG, "select down conversation");
if (this.mSelectedConversation != null) {
int index = this.conversationList.indexOf(this.mSelectedConversation);
if (index != -1 && index < this.conversationList.size() - 1) {
int next = index + 1;
this.conversationWasSelectedByKeyboard = true;
setSelectedConversation(this.conversationList.get(next));
this.mConversationFragment.reInit(getSelectedConversation());
if (next > listView.getLastVisiblePosition() -1 || next < listView.getFirstVisiblePosition() + 1) {
this.listView.setSelection(next);
}
openConversation();
}
}
}
@Override
protected void onNewIntent(final Intent intent) {
if (xmppConnectionServiceBound) {
@ -1349,4 +1423,8 @@ public class ConversationActivity extends XmppActivity
}
});
}
public boolean highlightSelectedConversations() {
return !isConversationsOverviewHideable() || this.conversationWasSelectedByKeyboard;
}
}

View file

@ -857,6 +857,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
updateChatMsgHint();
}
public void setFocusOnInputField() {
mEditMessage.requestFocus();
}
enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE}
private int getSendButtonImageResource(SendButtonAction action, int status) {

View file

@ -47,7 +47,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
if (this.activity instanceof ConversationActivity) {
View swipeableItem = view.findViewById(R.id.swipeable_item);
ConversationActivity a = (ConversationActivity) this.activity;
int c = !a.isConversationsOverviewHideable() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor();
int c = a.highlightSelectedConversations() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor();
swipeableItem.setBackgroundColor(c);
}
TextView convName = (TextView) view.findViewById(R.id.conversation_name);