improve keyboard handling. fixes #1387

* start a new Conversations by pressing mod+space
* automatically start searching when pressing keys in StartConversationsActivity
* when hitting enter when number of search results == 1 open that conversation
This commit is contained in:
Daniel Gultsch 2016-05-12 18:49:54 +02:00
parent 7113e21a43
commit f4369b29ae
3 changed files with 51 additions and 6 deletions

View File

@ -953,6 +953,9 @@ public class ConversationActivity extends XmppActivity
if (modifier && key == KeyEvent.KEYCODE_TAB && isConversationsOverviewHideable()) { if (modifier && key == KeyEvent.KEYCODE_TAB && isConversationsOverviewHideable()) {
toggleConversationsOverview(); toggleConversationsOverview();
return true; return true;
} else if (modifier && key == KeyEvent.KEYCODE_SPACE) {
startActivity(new Intent(this, StartConversationActivity.class));
return true;
} else if (modifier && key == downKey) { } else if (modifier && key == downKey) {
if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) { if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) {
showConversationsOverview(); showConversationsOverview();

View File

@ -91,7 +91,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private List<String> mKnownHosts; private List<String> mKnownHosts;
private List<String> mKnownConferenceHosts; private List<String> mKnownConferenceHosts;
private Invite mPendingInvite = null; private Invite mPendingInvite = null;
private Menu mOptionsMenu;
private EditText mSearchEditText; private EditText mSearchEditText;
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false); private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
private final int REQUEST_SYNC_CONTACTS = 0x3b28cf; private final int REQUEST_SYNC_CONTACTS = 0x3b28cf;
@ -116,9 +115,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@Override @Override
public boolean onMenuItemActionCollapse(MenuItem item) { public boolean onMenuItemActionCollapse(MenuItem item) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); hideKeyboard();
imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(),
InputMethodManager.HIDE_IMPLICIT_ONLY);
mSearchEditText.setText(""); mSearchEditText.setText("");
filter(null); filter(null);
return true; return true;
@ -169,6 +166,28 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
int count) { int count) {
} }
}; };
private TextView.OnEditorActionListener mSearchDone = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (getActionBar().getSelectedNavigationIndex() == 0) {
if (contacts.size() == 1) {
openConversationForContact((Contact) contacts.get(0));
} else {
hideKeyboard();
mContactsListFragment.getListView().requestFocus();
}
} else {
if (conferences.size() == 1) {
openConversationsForBookmark((Bookmark) conferences.get(0));
} else {
hideKeyboard();
mConferenceListFragment.getListView().requestFocus();
}
}
return true;
}
};
private MenuItem mMenuSearchView; private MenuItem mMenuSearchView;
private ListItemAdapter.OnTagClickedListener mOnTagClickedListener = new ListItemAdapter.OnTagClickedListener() { private ListItemAdapter.OnTagClickedListener mOnTagClickedListener = new ListItemAdapter.OnTagClickedListener() {
@Override @Override
@ -260,6 +279,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
protected void openConversationForContact(int position) { protected void openConversationForContact(int position) {
Contact contact = (Contact) contacts.get(position); Contact contact = (Contact) contacts.get(position);
openConversationForContact(contact);
}
protected void openConversationForContact(Contact contact) {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(), .findOrCreateConversation(contact.getAccount(),
contact.getJid(), false); contact.getJid(), false);
@ -277,6 +300,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
protected void openConversationForBookmark(int position) { protected void openConversationForBookmark(int position) {
Bookmark bookmark = (Bookmark) conferences.get(position); Bookmark bookmark = (Bookmark) conferences.get(position);
openConversationsForBookmark(bookmark);
}
protected void openConversationsForBookmark(Bookmark bookmark) {
Jid jid = bookmark.getJid(); Jid jid = bookmark.getJid();
if (jid == null) { if (jid == null) {
Toast.makeText(this,R.string.invalid_jid,Toast.LENGTH_SHORT).show(); Toast.makeText(this,R.string.invalid_jid,Toast.LENGTH_SHORT).show();
@ -503,7 +530,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
this.mOptionsMenu = menu;
getMenuInflater().inflate(R.menu.start_conversation, menu); getMenuInflater().inflate(R.menu.start_conversation, menu);
MenuItem menuCreateContact = menu.findItem(R.id.action_create_contact); MenuItem menuCreateContact = menu.findItem(R.id.action_create_contact);
MenuItem menuCreateConference = menu.findItem(R.id.action_join_conference); MenuItem menuCreateConference = menu.findItem(R.id.action_join_conference);
@ -515,6 +541,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
mSearchEditText = (EditText) mSearchView mSearchEditText = (EditText) mSearchView
.findViewById(R.id.search_field); .findViewById(R.id.search_field);
mSearchEditText.addTextChangedListener(mSearchTextWatcher); mSearchEditText.addTextChangedListener(mSearchTextWatcher);
mSearchEditText.setOnEditorActionListener(mSearchDone);
if (getActionBar().getSelectedNavigationIndex() == 0) { if (getActionBar().getSelectedNavigationIndex() == 0) {
menuCreateConference.setVisible(false); menuCreateConference.setVisible(false);
} else { } else {
@ -554,12 +581,26 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@Override @Override
public boolean onKeyUp(int keyCode, KeyEvent event) { public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SEARCH && !event.isLongPress()) { if (keyCode == KeyEvent.KEYCODE_SEARCH && !event.isLongPress()) {
mOptionsMenu.findItem(R.id.action_search).expandActionView(); openSearch();
return true; return true;
} }
int c = event.getUnicodeChar();
if (c > 32) {
if (mSearchEditText != null && !mSearchEditText.isFocused()) {
openSearch();
mSearchEditText.append(Character.toString((char) c));
return true;
}
}
return super.onKeyUp(keyCode, event); return super.onKeyUp(keyCode, event);
} }
private void openSearch() {
if (mMenuSearchView != null) {
mMenuSearchView.expandActionView();
}
}
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) { public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) { if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) {

View File

@ -14,6 +14,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="true" android:focusable="true"
android:inputType="textEmailAddress|textNoSuggestions" android:inputType="textEmailAddress|textNoSuggestions"
android:imeOptions="actionSearch"
android:textColor="@color/white" android:textColor="@color/white"
android:textColorHint="@color/white70" android:textColorHint="@color/white70"
android:hint="@string/search_for_contacts_or_groups"/> android:hint="@string/search_for_contacts_or_groups"/>