Add "search mode" to the action bar
- Instead of the search dialog, show the search widget on the action bar. - Launches a new activity for search, but still uses the temporary search code - Search still works only on two-pane. Change-Id: I1d36ad3416c7dff9579cf37e40e49e31c9d99219
This commit is contained in:
parent
78959916e7
commit
0f27632749
|
@ -198,10 +198,6 @@
|
|||
</activity>
|
||||
<activity
|
||||
android:name=".activity.EmailActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.MessageFileView"
|
||||
|
|
|
@ -14,18 +14,11 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!--
|
||||
Custom view set to the action bar on 2-pane.
|
||||
Displays the current mailbox and the unread count.
|
||||
|
||||
layout_width/height are set at runtime using ActionBar.setCustomView()
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginLeft="32dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="@dimen/action_bar_mailbox_name_left_margin"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2011 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!--
|
||||
Custom view set to the action bar.
|
||||
|
||||
layout_width/height are set at runtime using ActionBar.setCustomView()
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="0dip"
|
||||
>
|
||||
<include
|
||||
android:id="@+id/current_mailbox_container"
|
||||
layout="@layout/action_bar_current_mailbox"
|
||||
/>
|
||||
<include
|
||||
android:id="@+id/search_container"
|
||||
layout="@layout/action_bar_search"
|
||||
/>
|
||||
</FrameLayout>
|
|
@ -14,8 +14,17 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
|
||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:label="@string/search_title"
|
||||
android:hint="@string/search_hint"
|
||||
android:icon="@drawable/ic_menu_search_holo_light"
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/search_box_width"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<SearchView
|
||||
android:id="@+id/search_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:iconifiedByDefault="false"
|
||||
/>
|
||||
</FrameLayout>
|
|
@ -65,4 +65,6 @@
|
|||
|
||||
<!-- Username/password entry -->
|
||||
<dimen name="setup_credentials_input_width">340dip</dimen>
|
||||
|
||||
<dimen name="search_box_width">360dip</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -52,6 +52,8 @@
|
|||
<string name="open_action"/>
|
||||
<!-- Do Not Translate. Unused string. -->
|
||||
<string name="dump_settings_action"/>
|
||||
<!-- Do Not Translate. Unused string. -->
|
||||
<string name="search_title"></string>
|
||||
|
||||
<!-- End of deprecated strings. -->
|
||||
<skip />
|
||||
|
@ -1099,11 +1101,12 @@ save attachment.</string>
|
|||
target language. Typical alternatives include "+999" and ">999". [CHAR_LIMIT=4] -->
|
||||
<string name="more_than_999">999+</string>
|
||||
|
||||
<!-- Search title (should be the app name) [CHAR LIMIT=16] -->
|
||||
<string name="search_title">Email</string>
|
||||
<!-- The hint used in the search EditText field [CHAR LIMIT=35] -->
|
||||
<!-- The hint used in the search box when searching all mailboxes [CHAR LIMIT=35] -->
|
||||
<string name="search_hint">Search email</string>
|
||||
|
||||
<!-- The hint used in the search box when searching a single mailbox [CHAR LIMIT=35] -->
|
||||
<string name="search_mailbox_hint">Search <xliff:g example="Inbox">%1$s</xliff:g></string>
|
||||
|
||||
<!-- STOPSHIP Temporary UI DO NOT TRANSLATE-->
|
||||
<!-- In Mailbox setings, label for email check frequency selector -->
|
||||
<string name="mailbox_options_check_frequency_label">Mailbox check frequency</string>
|
||||
|
|
|
@ -28,15 +28,39 @@ import android.content.Context;
|
|||
import android.content.Loader;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Manages the account name and the custom view part on the action bar.
|
||||
*
|
||||
* TODO Show current mailbox name/unread count on the account spinner
|
||||
* -- and remove mMailboxNameContainer.
|
||||
*
|
||||
* TODO Stop using the action bar spinner and create our own spinner as a custom view.
|
||||
* (so we'll be able to just hide it, etc.)
|
||||
*
|
||||
* TODO Update search hint somehow
|
||||
*/
|
||||
public class ActionBarController {
|
||||
private static final String BUNDLE_KEY_MODE = "ActionBarController.BUNDLE_KEY_MODE";
|
||||
|
||||
/**
|
||||
* Constants for {@link #mMode}.
|
||||
*
|
||||
* In {@link #MODE_NORMAL} mode, we don't show the search box.
|
||||
* In {@link #MODE_SEARCH} mode, we do show the search box.
|
||||
* The action bar doesn't really care if the activity is showing search results.
|
||||
* If the activity is showing search results, and the {@link Callback#onSearchExit} is called,
|
||||
* the activity probably wants to close itself, but this class doesn't make the desision.
|
||||
*/
|
||||
private static final int MODE_NORMAL = 0;
|
||||
private static final int MODE_SEARCH = 1;
|
||||
|
||||
private static final int LOADER_ID_ACCOUNT_LIST
|
||||
= EmailActivity.ACTION_BAR_CONTROLLER_LOADER_ID_BASE + 0;
|
||||
|
||||
|
@ -44,9 +68,12 @@ public class ActionBarController {
|
|||
private final LoaderManager mLoaderManager;
|
||||
private final ActionBar mActionBar;
|
||||
|
||||
private final View mActionBarMailboxNameView;
|
||||
private final TextView mActionBarMailboxName;
|
||||
private final TextView mActionBarUnreadCount;
|
||||
private final View mActionBarCustomView;
|
||||
private final View mMailboxNameContainer;
|
||||
private final TextView mMailboxNameView;
|
||||
private final TextView mUnreadCountView;
|
||||
private final View mSearchContainer;
|
||||
private final SearchView mSearchView;
|
||||
|
||||
private final ActionBarNavigationCallback mActionBarNavigationCallback =
|
||||
new ActionBarNavigationCallback();
|
||||
|
@ -56,8 +83,15 @@ public class ActionBarController {
|
|||
/** The current account ID; used to determine if the account has changed. */
|
||||
private long mLastAccountIdForDirtyCheck = Account.NO_ACCOUNT;
|
||||
|
||||
/** Either {@link #MODE_NORMAL} or {@link #MODE_SEARCH}. */
|
||||
private int mMode = MODE_NORMAL;
|
||||
|
||||
public final Callback mCallback;
|
||||
|
||||
public interface SearchContext {
|
||||
public long getTargetMailboxId();
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
/** @return true if an account is selected. */
|
||||
public boolean isAccountSelected();
|
||||
|
@ -97,6 +131,18 @@ public class ActionBarController {
|
|||
|
||||
/** Called when no accounts are found in the database. */
|
||||
public void onNoAccountsFound();
|
||||
|
||||
/**
|
||||
* Called when a search is submitted.
|
||||
*
|
||||
* @param queryTerm query string
|
||||
*/
|
||||
public void onSearchSubmit(String queryTerm);
|
||||
|
||||
/**
|
||||
* Called when the search box is closed.
|
||||
*/
|
||||
public void onSearchExit();
|
||||
}
|
||||
|
||||
public ActionBarController(Context context, LoaderManager loaderManager,
|
||||
|
@ -110,41 +156,121 @@ public class ActionBarController {
|
|||
mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME
|
||||
| ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||
|
||||
// The custom view for the current mailbox and the unread count.
|
||||
// Prepare the custom view
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mActionBarMailboxNameView = inflater.inflate(R.layout.action_bar_current_mailbox, null);
|
||||
mActionBarCustomView = inflater.inflate(R.layout.action_bar_custom_view, null);
|
||||
final ActionBar.LayoutParams customViewLayout = new ActionBar.LayoutParams(
|
||||
ActionBar.LayoutParams.WRAP_CONTENT,
|
||||
ActionBar.LayoutParams.MATCH_PARENT);
|
||||
customViewLayout.setMargins(mContext.getResources().getDimensionPixelSize(
|
||||
R.dimen.action_bar_mailbox_name_left_margin) , 0, 0, 0);
|
||||
mActionBar.setCustomView(mActionBarMailboxNameView, customViewLayout);
|
||||
customViewLayout.setMargins(0 , 0, 0, 0);
|
||||
mActionBar.setCustomView(mActionBarCustomView, customViewLayout);
|
||||
|
||||
mActionBarMailboxName = UiUtilities.getView(mActionBarMailboxNameView, R.id.mailbox_name);
|
||||
mActionBarUnreadCount = UiUtilities.getView(mActionBarMailboxNameView, R.id.unread_count);
|
||||
// Mailbox name / unread count
|
||||
mMailboxNameContainer = UiUtilities.getView(mActionBarCustomView,
|
||||
R.id.current_mailbox_container);
|
||||
mMailboxNameView = UiUtilities.getView(mMailboxNameContainer, R.id.mailbox_name);
|
||||
mUnreadCountView = UiUtilities.getView(mMailboxNameContainer, R.id.unread_count);
|
||||
|
||||
// Search
|
||||
mSearchContainer = UiUtilities.getView(mActionBarCustomView, R.id.search_container);
|
||||
mSearchView = UiUtilities.getView(mSearchContainer, R.id.search_view);
|
||||
mSearchView.setSubmitButtonEnabled(true);
|
||||
mSearchView.setOnQueryTextListener(mOnQueryText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called when the host activity is created.
|
||||
*/
|
||||
/** Must be called from {@link UIControllerBase#onActivityCreated()} */
|
||||
public void onActivityCreated() {
|
||||
loadAccounts();
|
||||
refresh();
|
||||
}
|
||||
|
||||
/** Must be called from {@link UIControllerBase#onActivityDestroy()} */
|
||||
public void onActivityDestroy() {
|
||||
}
|
||||
|
||||
/** Must be called from {@link UIControllerBase#onSaveInstanceState} */
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(BUNDLE_KEY_MODE, mMode);
|
||||
}
|
||||
|
||||
/** Must be called from {@link UIControllerBase#onRestoreInstanceState} */
|
||||
public void onRestoreInstanceState(Bundle savedState) {
|
||||
mMode= savedState.getInt(BUNDLE_KEY_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the search box is shown.
|
||||
*/
|
||||
private boolean isInSearchMode() {
|
||||
return mMode == MODE_SEARCH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the search box.
|
||||
*
|
||||
* @param initialQueryTerm if non-empty, set to the search box.
|
||||
*/
|
||||
public void enterSearchMode(String initialQueryTerm) {
|
||||
if (isInSearchMode()) {
|
||||
return;
|
||||
}
|
||||
if (!TextUtils.isEmpty(initialQueryTerm)) {
|
||||
mSearchView.setQuery(initialQueryTerm, false);
|
||||
}
|
||||
mMode = MODE_SEARCH;
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void exitSearchMode() {
|
||||
if (!isInSearchMode()) {
|
||||
return;
|
||||
}
|
||||
mMode = MODE_NORMAL;
|
||||
refresh();
|
||||
mCallback.onSearchExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the back action.
|
||||
*
|
||||
* @param isSystemBackKey <code>true</code> if the system back key was pressed.
|
||||
* <code>false</code> if it's caused by the "home" icon click on the action bar.
|
||||
*/
|
||||
public boolean onBackPressed(boolean isSystemBackKey) {
|
||||
if (isInSearchMode()) {
|
||||
exitSearchMode();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Refreshes the action bar display. */
|
||||
public void refresh() {
|
||||
mActionBar.setDisplayOptions(mCallback.shouldShowUp()
|
||||
final boolean showUp = isInSearchMode() || mCallback.shouldShowUp();
|
||||
mActionBar.setDisplayOptions(showUp
|
||||
? ActionBar.DISPLAY_HOME_AS_UP : 0, ActionBar.DISPLAY_HOME_AS_UP);
|
||||
|
||||
mActionBarMailboxNameView.setVisibility(mCallback.shouldShowMailboxName()
|
||||
? View.VISIBLE : View.GONE);
|
||||
// TODO In search mode, account spinner should be hidden.
|
||||
// (See also the TODO in the class header -- this methods needs a lot of change.)
|
||||
|
||||
mActionBarMailboxName.setText(mCallback.getCurrentMailboxName());
|
||||
if (isInSearchMode()) {
|
||||
boolean wasVisible = (mSearchView.getVisibility() == View.VISIBLE);
|
||||
mSearchView.setVisibility(View.VISIBLE);
|
||||
if (!wasVisible) {
|
||||
mSearchView.requestFocus();
|
||||
}
|
||||
mMailboxNameContainer.setVisibility(View.GONE);
|
||||
} else {
|
||||
mSearchView.setVisibility(View.GONE);
|
||||
mMailboxNameContainer.setVisibility(mCallback.shouldShowMailboxName()
|
||||
? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
mMailboxNameView.setText(mCallback.getCurrentMailboxName());
|
||||
|
||||
// Note on action bar, we show only "unread count". Some mailboxes such as Outbox don't
|
||||
// have the idea of "unread count", in which case we just omit the count.
|
||||
mActionBarUnreadCount.setText(UiUtilities.getMessageCountForUi(mContext,
|
||||
mUnreadCountView.setText(UiUtilities.getMessageCountForUi(mContext,
|
||||
mCallback.getCurrentMailboxUnreadCount(), true));
|
||||
|
||||
// Update the account list only when the account has changed.
|
||||
|
@ -253,4 +379,20 @@ public class ActionBarController {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private final SearchView.OnQueryTextListener mOnQueryText
|
||||
= new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
// Event not handled. Let the search do the default action.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
mCallback.onSearchSubmit(mSearchView.getQuery().toString());
|
||||
return true; // Event handled.
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import android.app.Activity;
|
|||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.SearchManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
|
@ -62,6 +61,7 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
|
|||
private static final String EXTRA_ACCOUNT_ID = "ACCOUNT_ID";
|
||||
private static final String EXTRA_MAILBOX_ID = "MAILBOX_ID";
|
||||
private static final String EXTRA_MESSAGE_ID = "MESSAGE_ID";
|
||||
private static final String EXTRA_QUERY_STRING = "QUERY_STRING";
|
||||
|
||||
/** Loader IDs starting with this is safe to use from UIControllers. */
|
||||
static final int UI_CONTROLLER_LOADER_ID_BASE = 100;
|
||||
|
@ -139,6 +139,28 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
|
|||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an intent to launch search activity.
|
||||
*
|
||||
* @param accountId ID of the account for the mailbox. Must not be {@link Account#NO_ACCOUNT}.
|
||||
* @param mailboxId ID of the mailbox to search, or {@link Mailbox#NO_MAILBOX} to perform
|
||||
* global search.
|
||||
* @param query query string.
|
||||
*/
|
||||
public static Intent createSearchIntent(Activity fromActivity, long accountId,
|
||||
long mailboxId, String query) {
|
||||
// STOPSHIP temporary search UI
|
||||
if (accountId == Account.NO_ACCOUNT) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
Intent i = IntentUtilities.createRestartAppIntent(fromActivity, EmailActivity.class);
|
||||
i.putExtra(EXTRA_ACCOUNT_ID, accountId);
|
||||
i.putExtra(EXTRA_MAILBOX_ID, mailboxId);
|
||||
i.putExtra(EXTRA_QUERY_STRING, query);
|
||||
i.setAction(Intent.ACTION_SEARCH);
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize {@link #mUIController}.
|
||||
*/
|
||||
|
@ -176,7 +198,7 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
|
|||
mErrorBanner = new BannerController(this, errorMessage, errorBannerHeight);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mUIController.restoreInstanceState(savedInstanceState);
|
||||
mUIController.onRestoreInstanceState(savedInstanceState);
|
||||
} else {
|
||||
// This needs to be done after installRestoredFragments.
|
||||
// See UIControllerTwoPane.preFragmentTransactionCheck()
|
||||
|
@ -235,13 +257,10 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
|
|||
// STOPSHIP Temporary search UI
|
||||
Intent intent = getIntent();
|
||||
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
||||
// TODO Very temporary (e.g. no database access in UI thread)
|
||||
Bundle appData = getIntent().getBundleExtra(SearchManager.APP_DATA);
|
||||
if (appData == null) return; // ??
|
||||
final long accountId = appData.getLong(EXTRA_ACCOUNT_ID);
|
||||
final long mailboxId = appData.getLong(EXTRA_MAILBOX_ID);
|
||||
final String queryString = intent.getStringExtra(SearchManager.QUERY);
|
||||
Log.d(Logging.LOG_TAG, queryString);
|
||||
final long accountId = intent.getLongExtra(EXTRA_ACCOUNT_ID, Account.NO_ACCOUNT);
|
||||
final long mailboxId = intent.getLongExtra(EXTRA_MAILBOX_ID, Mailbox.NO_MAILBOX);
|
||||
final String queryString = intent.getStringExtra(EXTRA_QUERY_STRING);
|
||||
Log.d(Logging.LOG_TAG, "Search: " + queryString);
|
||||
// Switch to search mailbox
|
||||
// TODO How to handle search from within the search mailbox??
|
||||
final Controller controller = Controller.getInstance(mContext);
|
||||
|
@ -346,27 +365,15 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
|
|||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
// STOPSHIP Temporary search/sync options UI
|
||||
// Only show search/sync options for EAS 12.0 and later
|
||||
// STOPSHIP Temporary sync options UI
|
||||
boolean isEas = false;
|
||||
boolean canSearch = false;
|
||||
|
||||
long accountId = mUIController.getActualAccountId();
|
||||
if (accountId > 0) {
|
||||
// Move database operations out of the UI thread
|
||||
if ("eas".equals(Account.getProtocol(mContext, accountId))) {
|
||||
isEas = true;
|
||||
Account account = Account.restoreAccountWithId(mContext, accountId);
|
||||
if (account != null) {
|
||||
// We should set a flag in the account indicating ability to handle search
|
||||
String protocolVersion = account.mProtocolVersion;
|
||||
if (Double.parseDouble(protocolVersion) >= 12.0) {
|
||||
canSearch = true;
|
||||
isEas = "eas".equals(Account.getProtocol(mContext, accountId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Should use an isSearchable call to prevent search on inappropriate accounts/boxes
|
||||
menu.findItem(R.id.search).setVisible(canSearch);
|
||||
|
||||
// Should use an isSyncable call to prevent drafts/outbox from allowing this
|
||||
menu.findItem(R.id.sync_lookback).setVisible(isEas);
|
||||
menu.findItem(R.id.sync_frequency).setVisible(isEas);
|
||||
|
@ -374,13 +381,19 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
|
|||
return mUIController.onPrepareOptionsMenu(getMenuInflater(), menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the search key is pressd.
|
||||
*
|
||||
* Use the below command to emulate the key press on devices without the search key.
|
||||
* adb shell input keyevent 84
|
||||
*/
|
||||
@Override
|
||||
public boolean onSearchRequested() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(EXTRA_ACCOUNT_ID, mUIController.getActualAccountId());
|
||||
bundle.putLong(EXTRA_MAILBOX_ID, mUIController.getSearchMailboxId());
|
||||
startSearch(null, false, bundle, false);
|
||||
return true;
|
||||
if (Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, this + " onSearchRequested");
|
||||
}
|
||||
mUIController.onSearchRequested();
|
||||
return true; // Event handled.
|
||||
}
|
||||
|
||||
// STOPSHIP Set column from user options
|
||||
|
@ -491,9 +504,6 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
|
|||
case R.id.sync_frequency:
|
||||
showDialog(MAILBOX_SYNC_FREQUENCY_DIALOG);
|
||||
return true;
|
||||
case R.id.search:
|
||||
onSearchRequested();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
@ -210,6 +210,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
|||
if (Logging.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, this + " onActivityDestroy");
|
||||
}
|
||||
mActionBarController.onActivityDestroy();
|
||||
mRefreshManager.unregisterListener(mRefreshListener);
|
||||
mTaskTracker.cancellAllInterrupt();
|
||||
}
|
||||
|
@ -223,17 +224,19 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
|||
}
|
||||
outState.putBoolean(BUNDLE_KEY_RESUME_INBOX_LOOKUP, mResumeInboxLookup);
|
||||
outState.putLong(BUNDLE_KEY_INBOX_LOOKUP_ACCOUNT_ID, mInboxLookupAccountId);
|
||||
mActionBarController.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the {@link android.app.Activity#onRestoreInstanceState} callback.
|
||||
*/
|
||||
public void restoreInstanceState(Bundle savedInstanceState) {
|
||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
if (Logging.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, this + " restoreInstanceState");
|
||||
}
|
||||
mResumeInboxLookup = savedInstanceState.getBoolean(BUNDLE_KEY_RESUME_INBOX_LOOKUP);
|
||||
mInboxLookupAccountId = savedInstanceState.getLong(BUNDLE_KEY_INBOX_LOOKUP_ACCOUNT_ID);
|
||||
mActionBarController.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -482,10 +485,25 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
|||
/**
|
||||
* Performs the back action.
|
||||
*
|
||||
* NOTE The method in the base class has precedence. Subclasses overriding this method MUST
|
||||
* call super's method first.
|
||||
*
|
||||
* @param isSystemBackKey <code>true</code> if the system back key was pressed.
|
||||
* <code>false</code> if it's caused by the "home" icon click on the action bar.
|
||||
*/
|
||||
public abstract boolean onBackPressed(boolean isSystemBackKey);
|
||||
public boolean onBackPressed(boolean isSystemBackKey) {
|
||||
if (mActionBarController.onBackPressed(isSystemBackKey)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called from {@link Activity#onSearchRequested()}.
|
||||
*/
|
||||
public void onSearchRequested() {
|
||||
mActionBarController.enterSearchMode(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when the inbox lookup (started by {@link #startInboxLookup}) is finished.
|
||||
|
@ -550,6 +568,11 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
|||
mInboxFinder = null;
|
||||
}
|
||||
|
||||
/** @return true if the search menu option should be enabled. */
|
||||
protected boolean canSearch() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the {@link android.app.Activity#onCreateOptionsMenu} callback.
|
||||
*/
|
||||
|
@ -575,6 +598,29 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
|||
} else {
|
||||
item.setVisible(false);
|
||||
}
|
||||
|
||||
// STOPSHIP Temporary search options code
|
||||
// Only show search/sync options for EAS 12.0 and later
|
||||
boolean canSearch = false;
|
||||
if (canSearch()) {
|
||||
long accountId = getActualAccountId();
|
||||
if (accountId > 0) {
|
||||
// Move database operations out of the UI thread
|
||||
if ("eas".equals(Account.getProtocol(mActivity, accountId))) {
|
||||
Account account = Account.restoreAccountWithId(mActivity, accountId);
|
||||
if (account != null) {
|
||||
// We should set a flag in the account indicating ability to handle search
|
||||
String protocolVersion = account.mProtocolVersion;
|
||||
if (Double.parseDouble(protocolVersion) >= 12.0) {
|
||||
canSearch = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Should use an isSearchable call to prevent search on inappropriate accounts/boxes
|
||||
menu.findItem(R.id.search).setVisible(canSearch);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -596,6 +642,9 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
|||
return true;
|
||||
case R.id.account_settings:
|
||||
return onAccountSettings();
|
||||
case R.id.search:
|
||||
onSearchRequested();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -619,13 +668,6 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* STOPSHIP For experimental UI. Remove this.
|
||||
*
|
||||
* @return mailbox ID which we search for messages.
|
||||
*/
|
||||
public abstract long getSearchMailboxId();
|
||||
|
||||
/**
|
||||
* STOPSHIP For experimental UI. Remove this.
|
||||
*
|
||||
|
|
|
@ -258,6 +258,16 @@ class UIControllerOnePane extends UIControllerBase {
|
|||
Welcome.actionStart(mActivity);
|
||||
mActivity.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchSubmit(String queryTerm) {
|
||||
// STOPSHIP implement search
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchExit() {
|
||||
// STOPSHIP implement search
|
||||
}
|
||||
}
|
||||
|
||||
public UIControllerOnePane(EmailActivity activity) {
|
||||
|
@ -284,8 +294,8 @@ class UIControllerOnePane extends UIControllerBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void restoreInstanceState(Bundle savedInstanceState) {
|
||||
super.restoreInstanceState(savedInstanceState);
|
||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
mPreviousFragment = mActivity.getFragmentManager().getFragment(savedInstanceState,
|
||||
BUNDLE_KEY_PREVIOUS_FRAGMENT);
|
||||
}
|
||||
|
@ -397,6 +407,10 @@ class UIControllerOnePane extends UIControllerBase {
|
|||
// This is VERY important -- no check for DEBUG_LIFECYCLE
|
||||
Log.d(Logging.LOG_TAG, this + " onBackPressed: " + isSystemBackKey);
|
||||
}
|
||||
// Super's method has precedence. Must call it first.
|
||||
if (super.onBackPressed(isSystemBackKey)) {
|
||||
return true;
|
||||
}
|
||||
// If the mailbox list is shown and showing a nested mailbox, let it navigate up first.
|
||||
if (isMailboxListInstalled() && getMailboxListFragment().navigateUp()) {
|
||||
if (DEBUG_FRAGMENTS) {
|
||||
|
@ -644,14 +658,10 @@ class UIControllerOnePane extends UIControllerBase {
|
|||
return Mailbox.NO_MAILBOX;
|
||||
}
|
||||
|
||||
/*
|
||||
* STOPSHIP Remove this -- see the base class method.
|
||||
*/
|
||||
@Override
|
||||
public long getSearchMailboxId() {
|
||||
// Search is still experimental, and doesn't have to work on the phone.
|
||||
Utility.showToast(mActivity, "STOPSHIP: Search not supported on 1 pane");
|
||||
return Mailbox.NO_MAILBOX;
|
||||
@Override protected boolean canSearch() {
|
||||
return false; // STOPSHIP no search on one pane yet
|
||||
// Search is enabled only on the message list. (for now)
|
||||
// return isMessageListInstalled();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -410,14 +410,6 @@ class UIControllerTwoPane extends UIControllerBase implements
|
|||
return getMessageListMailboxId();
|
||||
}
|
||||
|
||||
/*
|
||||
* STOPSHIP Remove this -- see the base class method.
|
||||
*/
|
||||
@Override
|
||||
public long getSearchMailboxId() {
|
||||
return getMessageListMailboxId();
|
||||
}
|
||||
|
||||
private long getMessageId() {
|
||||
return isMessageViewInstalled() ? getMessageViewFragment().getMessageId()
|
||||
: Message.NO_MESSAGE;
|
||||
|
@ -494,8 +486,8 @@ class UIControllerTwoPane extends UIControllerBase implements
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void restoreInstanceState(Bundle savedInstanceState) {
|
||||
super.restoreInstanceState(savedInstanceState);
|
||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -812,14 +804,24 @@ class UIControllerTwoPane extends UIControllerBase implements
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean onBackPressed(boolean isSystemBackKey) {
|
||||
// Super's method has precedence. Must call it first.
|
||||
if (super.onBackPressed(isSystemBackKey)) {
|
||||
return true;
|
||||
}
|
||||
if (mThreePane.onBackPressed(isSystemBackKey)) {
|
||||
return true;
|
||||
} else if (isMailboxListInstalled() && getMailboxListFragment().navigateUp()) {
|
||||
}
|
||||
if (isMailboxListInstalled() && getMailboxListFragment().navigateUp()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override protected boolean canSearch() {
|
||||
// Search is always enabled on two-pane. (if the account supports it)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the "refresh" option item. Opens the settings activity.
|
||||
* TODO used by experimental code in the activity -- otherwise can be private.
|
||||
|
@ -991,5 +993,25 @@ class UIControllerTwoPane extends UIControllerBase implements
|
|||
return leftPaneHidden
|
||||
|| (isMailboxListInstalled() && !getMailboxListFragment().isRoot());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchSubmit(String queryTerm) {
|
||||
// STOPSHIP temporary code
|
||||
final long accountId = getUIAccountId();
|
||||
if (accountId == Account.NO_ACCOUNT) {
|
||||
return; // no account selected.
|
||||
}
|
||||
final long mailboxId = getMessageListMailboxId();
|
||||
|
||||
// TODO global search?
|
||||
|
||||
mActivity.startActivity(EmailActivity.createSearchIntent(
|
||||
mActivity, accountId, mailboxId, queryTerm));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchExit() {
|
||||
// STOPSHIP If the activity is a "search" instance, finish() it.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue