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;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -88,6 +89,8 @@ public class ConversationActivity extends XmppActivity
private Uri mPendingGeoUri = null; private Uri mPendingGeoUri = null;
private boolean forbidProcessingPendings = false; private boolean forbidProcessingPendings = false;
private boolean conversationWasSelectedByKeyboard = false;
private View mContentView; private View mContentView;
private List<Conversation> conversationList = new ArrayList<>(); private List<Conversation> conversationList = new ArrayList<>();
@ -190,6 +193,7 @@ public class ConversationActivity extends XmppActivity
if (getSelectedConversation() != conversationList.get(position)) { if (getSelectedConversation() != conversationList.get(position)) {
setSelectedConversation(conversationList.get(position)); setSelectedConversation(conversationList.get(position));
ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation()); ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
conversationWasSelectedByKeyboard = false;
} }
hideConversationsOverview(); hideConversationsOverview();
openConversation(); openConversation();
@ -474,7 +478,7 @@ public class ConversationActivity extends XmppActivity
private Intent getInstallApkIntent(final String packageId) { private Intent getInstallApkIntent(final String packageId) {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id="+packageId)); intent.setData(Uri.parse("market://details?id=" + packageId));
if (intent.resolveActivity(getPackageManager()) != null) { if (intent.resolveActivity(getPackageManager()) != null) {
return intent; return intent;
} else { } else {
@ -713,13 +717,13 @@ public class ConversationActivity extends XmppActivity
intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString()); intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString());
switch (menuItem.getItemId()) { switch (menuItem.getItemId()) {
case R.id.scan_fingerprint: case R.id.scan_fingerprint:
intent.putExtra("mode",VerifyOTRActivity.MODE_SCAN_FINGERPRINT); intent.putExtra("mode", VerifyOTRActivity.MODE_SCAN_FINGERPRINT);
break; break;
case R.id.ask_question: case R.id.ask_question:
intent.putExtra("mode",VerifyOTRActivity.MODE_ASK_QUESTION); intent.putExtra("mode", VerifyOTRActivity.MODE_ASK_QUESTION);
break; break;
case R.id.manual_verification: case R.id.manual_verification:
intent.putExtra("mode",VerifyOTRActivity.MODE_MANUAL_VERIFICATION); intent.putExtra("mode", VerifyOTRActivity.MODE_MANUAL_VERIFICATION);
break; break;
} }
startActivity(intent); startActivity(intent);
@ -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 @Override
protected void onNewIntent(final Intent intent) { protected void onNewIntent(final Intent intent) {
if (xmppConnectionServiceBound) { 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(); updateChatMsgHint();
} }
public void setFocusOnInputField() {
mEditMessage.requestFocus();
}
enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE} enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE}
private int getSendButtonImageResource(SendButtonAction action, int status) { private int getSendButtonImageResource(SendButtonAction action, int status) {

View file

@ -47,7 +47,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
if (this.activity instanceof ConversationActivity) { if (this.activity instanceof ConversationActivity) {
View swipeableItem = view.findViewById(R.id.swipeable_item); View swipeableItem = view.findViewById(R.id.swipeable_item);
ConversationActivity a = (ConversationActivity) this.activity; 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); swipeableItem.setBackgroundColor(c);
} }
TextView convName = (TextView) view.findViewById(R.id.conversation_name); TextView convName = (TextView) view.findViewById(R.id.conversation_name);