Commit 3b0a8bcd authored by Grigory Fedorov's avatar Grigory Fedorov

ContactList: contact search in action bar implemented.

parent a2edd876
...@@ -24,17 +24,20 @@ import android.graphics.Bitmap; ...@@ -24,17 +24,20 @@ import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
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;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.SearchView;
import android.widget.Toast; import android.widget.Toast;
import com.xabber.android.data.ActivityManager; import com.xabber.android.data.ActivityManager;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException; import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
...@@ -92,6 +95,7 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -92,6 +95,7 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
* Dialog related values. * Dialog related values.
*/ */
private String sendText; private String sendText;
private SearchView searchView;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
...@@ -255,21 +259,78 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -255,21 +259,78 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
hideKeyboard();
}
private void hideKeyboard() {
if (getCurrentFocus() != null) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.contact_list, menu); getMenuInflater().inflate(R.menu.contact_list, menu);
setUpSearchView(menu);
return true; return true;
} }
private void setUpSearchView(Menu menu) {
searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setQueryHint("Search contact");
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
return true;
}
});
MenuItemCompat.setOnActionExpandListener(menu.findItem(R.id.action_search), new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
searchView.requestFocus();
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).
toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
LogManager.i(this, "onMenuItemActionCollapse");
searchView.setQuery("", true);
searchView.clearFocus();
return true;
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
Fragment fragmentById = getSupportFragmentManager().findFragmentById(R.id.container);
((ContactListFragment) fragmentById).getFilterableAdapter().getFilter().filter(newText);
return true;
}
});
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_search: case R.id.action_search:
search();
searchView.setIconified(false);
return true; return true;
case R.id.action_change_status: case R.id.action_change_status:
startActivity(StatusEditor.createIntent(this)); startActivity(StatusEditor.createIntent(this));
return true; return true;
...@@ -321,8 +382,7 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -321,8 +382,7 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
} }
private ContactListFragment getContactListFragment() { private ContactListFragment getContactListFragment() {
return (ContactListFragment) getSupportFragmentManager() return (ContactListFragment) getSupportFragmentManager().findFragmentByTag(CONTACT_LIST_TAG);
.findFragmentByTag(CONTACT_LIST_TAG);
} }
@Override @Override
...@@ -352,16 +412,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -352,16 +412,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
} }
} }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_SEARCH:
search();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override @Override
public void onContactClick(AbstractContact abstractContact) { public void onContactClick(AbstractContact abstractContact) {
if (ACTION_ROOM_INVITE.equals(action)) { if (ACTION_ROOM_INVITE.equals(action)) {
...@@ -415,16 +465,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -415,16 +465,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
openChat(new BaseEntity(account, user), text); openChat(new BaseEntity(account, user), text);
} }
/**
* Show search dialog.
*/
private void search() {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null)
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED,
0);
}
public static Intent createPersistentIntent(Context context) { public static Intent createPersistentIntent(Context context) {
Intent intent = new Intent(context, ContactList.class); Intent intent = new Intent(context, ContactList.class);
intent.setAction("android.intent.action.MAIN"); intent.setAction("android.intent.action.MAIN");
......
package com.xabber.android.ui; package com.xabber.android.ui;
import java.util.Collection;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
...@@ -18,6 +16,7 @@ import android.widget.AdapterView; ...@@ -18,6 +16,7 @@ import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.Filterable;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
...@@ -42,6 +41,8 @@ import com.xabber.android.ui.helper.ContextMenuHelper; ...@@ -42,6 +41,8 @@ import com.xabber.android.ui.helper.ContextMenuHelper;
import com.xabber.android.ui.preferences.AccountList; import com.xabber.android.ui.preferences.AccountList;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import java.util.Collection;
public class ContactListFragment extends Fragment implements public class ContactListFragment extends Fragment implements
OnAccountChangedListener, OnContactChangedListener, OnAccountChangedListener, OnContactChangedListener,
OnChatChangedListener, OnItemClickListener, OnChatChangedListener, OnItemClickListener,
...@@ -324,6 +325,10 @@ public class ContactListFragment extends Fragment implements ...@@ -324,6 +325,10 @@ public class ContactListFragment extends Fragment implements
return adapter; return adapter;
} }
Filterable getFilterableAdapter() {
return adapter;
}
/** /**
* Scroll contact list to specified account. * Scroll contact list to specified account.
* *
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
android:id="@android:id/list" android:id="@android:id/list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:textFilterEnabled="true" /> />
<RelativeLayout <RelativeLayout
android:id="@+id/info" android:id="@+id/info"
......
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search" <item android:id="@+id/action_search"
android:title="@android:string/search_go" android:title="@android:string/search_go"
app:showAsAction="always" app:showAsAction="always|collapseActionView"
android:orderInCategory="100" android:orderInCategory="100"
android:icon="@drawable/ic_search_white_24dp" android:icon="@drawable/ic_search_white_24dp"
app:actionViewClass="android.widget.SearchView"
/> />
<item android:id="@+id/action_add_contact" <item android:id="@+id/action_add_contact"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"> <resources>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_contact_context_menu.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_contact_context_menu.png -->
<string name="accept_subscription">Разрешить подписку</string> <string name="accept_subscription">Разрешить подписку</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_suggestion.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_suggestion.png -->
...@@ -110,4 +110,6 @@ ...@@ -110,4 +110,6 @@
<string name="show_offline_settings">Отображение контактов не в сети</string> <string name="show_offline_settings">Отображение контактов не в сети</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_boot.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_boot.png -->
<string name="start_at_boot_suggest">Вы хотите запускать Xabber при включении телефона?\nИзменить эту настройку можно в меню "Настройки" → "Настройки подключения" → "Запускать при включении телефона"</string> <string name="start_at_boot_suggest">Вы хотите запускать Xabber при включении телефона?\nИзменить эту настройку можно в меню "Настройки" → "Настройки подключения" → "Запускать при включении телефона"</string>
<string name="contact_search_hint">Поиск контактов</string>
</resources> </resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"> <resources>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_contact_context_menu.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_contact_context_menu.png -->
<string name="accept_subscription">Accept contact</string> <string name="accept_subscription">Accept contact</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_suggestion.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_suggestion.png -->
...@@ -110,4 +110,6 @@ ...@@ -110,4 +110,6 @@
<string name="show_offline_settings">Show offline contacts</string> <string name="show_offline_settings">Show offline contacts</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_boot.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_boot.png -->
<string name="start_at_boot_suggest">Do you want to run Xabber at startup?\nThis can be changed in "Settings" → "Connection settings" → "Run at boot"</string> <string name="start_at_boot_suggest">Do you want to run Xabber at startup?\nThis can be changed in "Settings" → "Connection settings" → "Run at boot"</string>
<string name="contact_search_hint">Search contacts</string>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment