1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-17 21:32:26 -05:00

Switch to using the action bar for folder searches.

Eliminate the old-style search dialog box.
This commit is contained in:
Joe Steele 2012-11-27 22:43:14 -05:00
parent 1ea9502844
commit d7cb89880a
2 changed files with 25 additions and 102 deletions

View File

@ -3,8 +3,9 @@
<item
android:id="@+id/filter_folders"
android:icon="?attr/iconActionSearchFolder"
android:showAsAction="always"
android:title="@string/filter_folders_action"/>
android:showAsAction="always|collapseActionView"
android:title="@string/filter_folders_action"
android:actionViewClass="com.actionbarsherlock.widget.SearchView"/>
<item
android:id="@+id/check_mail"
android:alphabeticShortcut="r"

View File

@ -6,17 +6,12 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextMenu;
@ -30,7 +25,6 @@ import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.LinearLayout;
@ -44,6 +38,7 @@ import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.SearchView;
import com.fsck.k9.Account;
import com.fsck.k9.Account.FolderMode;
import com.fsck.k9.AccountStats;
@ -52,7 +47,6 @@ import com.fsck.k9.FontSizes;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.FolderList.FolderListAdapter.FolderListFilter;
import com.fsck.k9.activity.misc.ActionBarNavigationSpinner;
import com.fsck.k9.activity.setup.AccountSettings;
import com.fsck.k9.activity.setup.FolderSettings;
@ -79,11 +73,6 @@ import de.cketti.library.changelog.ChangeLog;
*/
public class FolderList extends K9ListActivity implements OnNavigationListener {
/*
* Constants for showDialog() etc.
*/
private static final int DIALOG_FIND_FOLDER = 2;
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_INITIAL_FOLDER = "initialFolder";
@ -493,14 +482,6 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
}
/**
* Show an alert with an input-field for a filter-expression.
* Filter {@link #mAdapter} with the user-input.
*/
private void onEnterFilter() {
showDialog(DIALOG_FIND_FOLDER);
}
private void onEditPrefs() {
Prefs.actionPrefs(this);
}
@ -581,11 +562,6 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
return true;
case R.id.filter_folders:
onEnterFilter();
return true;
case R.id.account_settings:
onEditAccount();
@ -643,9 +619,30 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.folder_list_option, menu);
mRefreshMenuItem = menu.findItem(R.id.check_mail);
configureFolderSearchView(menu);
return true;
}
private void configureFolderSearchView(Menu menu) {
final MenuItem folderMenuItem = menu.findItem(R.id.filter_folders);
final SearchView folderSearchView = (SearchView) folderMenuItem.getActionView();
folderSearchView.setQueryHint(getString(R.string.folder_list_filter_hint));
folderSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
folderMenuItem.collapseActionView();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
mAdapter.getFilter().filter(newText);
return true;
}
});
}
@Override public boolean onContextItemSelected(android.view.MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item .getMenuInfo();
FolderInfoHolder folder = (FolderInfoHolder) mAdapter.getItem(info.position);
@ -667,81 +664,6 @@ public class FolderList extends K9ListActivity implements OnNavigationListener {
private FolderInfoHolder mSelectedContextFolder = null;
@Override
public Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_FIND_FOLDER: {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.filter_folders_action);
final EditText input = new EditText(this);
input.setId(R.id.filter_folders);
input.setHint(R.string.folder_list_filter_hint);
input.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mAdapter.getFilter().filter(input.getText());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
/* not used */
}
@Override
public void afterTextChanged(Editable s) {
/* not used */
}
});
builder.setView(input);
builder.setPositiveButton(getString(R.string.okay_action),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
mAdapter.getFilter().filter(value);
}
});
builder.setNegativeButton(getString(R.string.cancel_action),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
mAdapter.getFilter().filter(null);
}
});
return builder.create();
}
}
return super.onCreateDialog(id);
}
@Override
public void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DIALOG_FIND_FOLDER: {
AlertDialog alertDialog = (AlertDialog) dialog;
EditText input = (EditText) alertDialog.findViewById(R.id.filter_folders);
// Populate the EditText with the current search term
FolderListFilter filter = (FolderListFilter) mAdapter.getFilter();
input.setText(filter.getSearchTerm());
// Place the cursor at the end of the text
input.setSelection(input.getText().length());
break;
}
default: {
super.onPrepareDialog(id, dialog);
}
}
}
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;