blob: d4ba6a225b6bf43094b4e6776f394fab5c67554b [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
Yorke Leec3766332013-07-31 11:13:16 -07002 * Copyright (C) 2013 The Android Open Source Project
Chiao Cheng94b10b52012-08-17 16:59:12 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dialer;
18
Yorke Leecc4660d2014-04-24 11:22:57 -070019import android.animation.LayoutTransition;
Yorke Lee53a22302014-04-29 18:13:46 -070020import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.Activity;
22import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080024import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.content.Context;
26import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080027import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Andrew Lee2423a2f2014-05-29 14:14:45 -070029import android.content.res.Resources;
Yorke Lee33932ff2014-04-16 13:34:32 -070030import android.content.res.TypedArray;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.net.Uri;
32import android.os.Bundle;
33import android.os.RemoteException;
34import android.os.ServiceManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070035import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070036import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070037import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070038import android.support.v4.view.ViewPager;
Yorke Leec3766332013-07-31 11:13:16 -070039import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070040import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070041import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070042import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070043import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070044import android.view.DragEvent;
Andrew Leeb1903842014-05-15 16:11:24 -070045import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070046import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070048import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070049import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070050import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070051import android.view.View.OnTouchListener;
Andrew Lee2a58ab82014-05-15 02:16:04 -070052import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070053import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070054import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070055import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070056import android.widget.EditText;
Andrew Leea73e1892014-05-13 13:21:16 -070057import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070058import android.widget.PopupMenu;
Yorke Leecc4660d2014-04-24 11:22:57 -070059import android.widget.RelativeLayout;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080060import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070061
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070062import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070063import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070064import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070065import com.android.contacts.common.dialog.ClearFrequentsDialog;
66import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080067import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Andrew Lee4cbc9732014-04-24 14:38:58 -070068import com.android.contacts.common.util.ViewUtil;
Yorke Leec3766332013-07-31 11:13:16 -070069import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070070import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070071import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070072import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070073import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070074import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080075import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070076import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080077import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070078import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070079import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070080import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070081import com.android.dialer.list.RegularSearchFragment;
82import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070083import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070084import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070085import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070086import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070087import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070088
Yorke Leec3766332013-07-31 11:13:16 -070089import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080090import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070091
Chiao Cheng94b10b52012-08-17 16:59:12 -070092/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070093 * The dialer tab's title is 'phone', a more common name (see strings.xml).
94 */
Yorke Leec3766332013-07-31 11:13:16 -070095public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -070096 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -070097 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -080098 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -070099 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700100 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700101 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700102 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700103 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700104 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700105 ViewPager.OnPageChangeListener,
106 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700107 private static final String TAG = "DialtactsActivity";
108
Ihab Awad526c0b82014-02-27 12:55:36 -0800109 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700110
Yorke Leef74011e2013-08-02 11:30:30 -0700111 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
112
Chiao Cheng94b10b52012-08-17 16:59:12 -0700113 /** Used to open Call Setting */
114 private static final String PHONE_PACKAGE = "com.android.phone";
115 private static final String CALL_SETTINGS_CLASS_NAME =
116 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700117 /** @see #getCallOrigin() */
118 private static final String CALL_ORIGIN_DIALTACTS =
119 "com.android.dialer.DialtactsActivity";
120
Yorke Leeb207f8a2013-08-29 18:51:06 -0700121 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
122 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700123 private static final String KEY_SEARCH_QUERY = "search_query";
124 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700125 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700126
Yorke Leec3766332013-07-31 11:13:16 -0700127 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
128 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
129 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
130 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700131
Chiao Cheng94b10b52012-08-17 16:59:12 -0700132 /**
133 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
134 */
135 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
136
Yorke Leec3766332013-07-31 11:13:16 -0700137 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700138
Andrew Lee0c667702014-05-12 14:31:45 -0700139 private RelativeLayout parentLayout;
140
Yorke Leec3766332013-07-31 11:13:16 -0700141 /**
Yorke Leec3766332013-07-31 11:13:16 -0700142 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700143 */
Yorke Leef74011e2013-08-02 11:30:30 -0700144 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700145
146 /**
147 * Fragment for searching phone numbers using the alphanumeric keyboard.
148 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700149 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700150
151 /**
152 * Fragment for searching phone numbers using the dialpad.
153 */
154 private SmartDialSearchFragment mSmartDialSearchFragment;
155
Yorke Leee00c9fe2014-04-12 12:42:06 -0700156 /**
157 * Fragment containing the speed dial list, recents list, and all contacts list.
158 */
159 private ListsFragment mListsFragment;
160
Andrew Leea73e1892014-05-13 13:21:16 -0700161 private View mFloatingActionButtonContainer;
162 private ImageButton mFloatingActionButton;
Yorke Leec3766332013-07-31 11:13:16 -0700163
Yorke Leeb207f8a2013-08-29 18:51:06 -0700164 private boolean mInDialpadSearch;
165 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700166 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700167 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700168 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700169
Yorke Leeef2b7382013-08-09 17:39:25 -0700170 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700171 * The position of the currently selected tab in the attached {@link ListsFragment}.
172 */
173 private int mCurrentTabPosition = 0;
174
175 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700176 * True if the dialpad is only temporarily showing due to being in call
177 */
178 private boolean mInCallDialpadUp;
179
180 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700181 * True when this activity has been launched for the first time.
182 */
Yorke Lee98702de2013-08-06 12:03:32 -0700183 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700184
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700185 /**
186 * Search query to be applied to the SearchView in the ActionBar once
187 * onCreateOptionsMenu has been called.
188 */
189 private String mPendingSearchViewQuery;
190
Yorke Lee53a22302014-04-29 18:13:46 -0700191 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700192 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700193
Yorke Leeef2b7382013-08-09 17:39:25 -0700194 private String mSearchQuery;
195
Yorke Leefce269a2013-08-12 11:56:04 -0700196 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700197 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700198 private ActionBarController mActionBarController;
Yorke Leefce269a2013-08-12 11:56:04 -0700199
Andrew Lee2423a2f2014-05-29 14:14:45 -0700200 private int mActionBarHeight;
201 private int mFloatingActionButtonMarginBottom;
202 private int mFloatingActionButtonDialpadMarginBottom;
203
Andrew Leee74a10e2014-05-16 14:31:40 -0700204 private class OptionsPopupMenu extends PopupMenu {
205 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700206 super(context, anchor);
207 }
208
209 @Override
210 public void show() {
211 final Menu menu = getMenu();
212 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700213 clearFrequents.setVisible(mListsFragment != null &&
214 mListsFragment.getSpeedDialFragment() != null &&
215 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700216 super.show();
217 }
218 }
219
Chiao Cheng94b10b52012-08-17 16:59:12 -0700220 /**
Yorke Lee28266192014-05-01 10:05:52 -0700221 * Listener that listens to drag events and sends their x and y coordinates to a
222 * {@link DragDropController}.
223 */
224 private class LayoutOnDragListener implements OnDragListener {
225 @Override
226 public boolean onDrag(View v, DragEvent event) {
227 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700228 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700229 }
230 return true;
231 }
232 }
233
234 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700235 * Listener used to send search queries to the phone search fragment.
236 */
Yorke Lee53a22302014-04-29 18:13:46 -0700237 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700238 @Override
239 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
240 }
Yorke Leec3766332013-07-31 11:13:16 -0700241
Andrew Lee99a570c2014-05-15 14:18:50 -0700242 @Override
243 public void onTextChanged(CharSequence s, int start, int before, int count) {
244 final String newText = s.toString();
245 if (newText.equals(mSearchQuery)) {
246 // If the query hasn't changed (perhaps due to activity being destroyed
247 // and restored, or user launching the same DIAL intent twice), then there is
248 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700249 return;
250 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700251 if (DEBUG) {
252 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700253 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700254 }
Yorke Lee710709d2014-05-29 07:18:42 -0700255 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700256
Andrew Lee90374a72014-05-16 15:01:09 -0700257 // Show search fragment only when the query string is changed to non-empty text.
258 if (!TextUtils.isEmpty(newText)) {
259 // Call enterSearchUi only if we are switching search modes, or showing a search
260 // fragment for the first time.
261 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
262 (!mIsDialpadShown && mInRegularSearch);
263 if (!sameSearchMode) {
264 enterSearchUi(mIsDialpadShown, mSearchQuery);
265 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700266 }
267
268 if (mIsDialpadShown && mSmartDialSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700269 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700270 } else if (mRegularSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700271 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700272 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700273 }
274
275 @Override
276 public void afterTextChanged(Editable s) {
277 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700278 };
279
Andrew Leeb1903842014-05-15 16:11:24 -0700280
281 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700282 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700283 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700284 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700285 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700286 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700287 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700288 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700289 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
290 }
Andrew Leeb1903842014-05-15 16:11:24 -0700291 }
292 };
293
294 /**
295 * If the search term is empty and the user closes the soft keyboard, close the search UI.
296 */
297 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
298 @Override
299 public boolean onKey(View v, int keyCode, KeyEvent event) {
300 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
301 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700302 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700303 }
304 return false;
305 }
306 };
307
Chiao Cheng94b10b52012-08-17 16:59:12 -0700308 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700309 protected void onCreate(Bundle savedInstanceState) {
310 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700311 mFirstLaunch = true;
312
Andrew Lee2423a2f2014-05-29 14:14:45 -0700313 final Resources resources = getResources();
314 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
315 mFloatingActionButtonMarginBottom =
316 resources.getDimensionPixelOffset(R.dimen.floating_action_button_margin_bottom);
317 mFloatingActionButtonDialpadMarginBottom = resources.getDimensionPixelOffset(
318 R.dimen.floating_action_button_dialpad_margin_bottom);
319
Yorke Lee8898cd02013-08-08 10:24:27 -0700320 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800321 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700322
Yorke Lee53a22302014-04-29 18:13:46 -0700323 final ActionBar actionBar = getActionBar();
324 actionBar.setCustomView(R.layout.search_edittext);
325 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700326 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700327
Yorke Lee5253be02014-05-21 18:50:03 -0700328 mActionBarController = new ActionBarController(this,
329 (SearchEditTextLayout) actionBar.getCustomView());
330
Yorke Lee53a22302014-04-29 18:13:46 -0700331
Andrew Lee04675a52014-06-05 18:36:20 -0700332 SearchEditTextLayout searchEditTextLayout =
333 (SearchEditTextLayout) actionBar.getCustomView();
334 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
335
336 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700337 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700338 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
339 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
340 .setOnClickListener(mSearchViewOnClickListener);
341 searchEditTextLayout.findViewById(R.id.search_box_start_search)
342 .setOnClickListener(mSearchViewOnClickListener);
343 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700344 @Override
345 public void onBackButtonClicked() {
346 onBackPressed();
347 }
348 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700349
Andrew Lee04675a52014-06-05 18:36:20 -0700350 ImageButton optionsMenuButton =
351 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700352 optionsMenuButton.setOnClickListener(this);
353 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
354 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
355
Yorke Leeef2b7382013-08-09 17:39:25 -0700356 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
357 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700358 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800359 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700360 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800361 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
362 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700363 } else {
364 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700365 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
366 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700367 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700368 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700369 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700370 }
371
Andrew Lee0c667702014-05-12 14:31:45 -0700372 parentLayout = (RelativeLayout) findViewById(R.id.dialtacts_mainlayout);
373 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
374 parentLayout.setOnDragListener(new LayoutOnDragListener());
375
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700376 setupActivityOverlay();
377
Andrew Leea73e1892014-05-13 13:21:16 -0700378 mFloatingActionButtonContainer = findViewById(R.id.floating_action_button_container);
379 ViewUtil.setupFloatingActionButton(mFloatingActionButtonContainer, getResources());
Yorke Lee86e21f72014-04-02 16:49:38 -0700380
Andrew Leea73e1892014-05-13 13:21:16 -0700381 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
382 mFloatingActionButton.setOnClickListener(this);
Ihab Awad526c0b82014-02-27 12:55:36 -0800383
Yorke Lee0baa98b2013-08-22 10:55:16 -0700384 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700385 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700386 }
387
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700388 private void setupActivityOverlay() {
389 final View activityOverlay = findViewById(R.id.activity_overlay);
390 activityOverlay.setOnTouchListener(new OnTouchListener() {
391 @Override
392 public boolean onTouch(View v, MotionEvent event) {
393 if (!mIsDialpadShown) {
394 maybeExitSearchUi();
395 }
396 return false;
397 }
398 });
399 }
400
Chiao Cheng94b10b52012-08-17 16:59:12 -0700401 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700402 protected void onResume() {
403 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700404 if (mFirstLaunch) {
405 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700406 } else if (!phoneIsInUse() && mInCallDialpadUp) {
407 hideDialpadFragment(false, true);
408 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700409 } else if (mShowDialpadOnResume) {
410 showDialpadFragment(false);
411 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700412 }
413 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700414 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700415 mDialerDatabaseHelper.startSmartDialUpdateThread();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700416 }
417
418 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700419 protected void onPause() {
420 if (mClearSearchOnPause) {
421 hideDialpadAndSearchUi();
422 mClearSearchOnPause = false;
423 }
424 super.onPause();
425 }
426
427 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700428 protected void onSaveInstanceState(Bundle outState) {
429 super.onSaveInstanceState(outState);
430 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700431 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
432 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700433 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700434 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700435 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700436 }
437
438 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700439 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700440 if (fragment instanceof DialpadFragment) {
441 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700442 if (!mShowDialpadOnResume) {
443 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
444 transaction.hide(mDialpadFragment);
445 transaction.commit();
446 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700447 } else if (fragment instanceof SmartDialSearchFragment) {
448 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700449 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700450 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700451 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700452 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700453 } else if (fragment instanceof ListsFragment) {
454 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700455 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700456 }
Yorke Leec3766332013-07-31 11:13:16 -0700457 }
458
Alon Albertb453e5b2013-09-10 15:54:23 -0700459 protected void handleMenuSettings() {
460 openTelephonySetting(this);
461 }
462
463 public static void openTelephonySetting(Activity activity) {
464 final Intent settingsIntent = getCallSettingsIntent();
465 activity.startActivity(settingsIntent);
466 }
467
Chiao Cheng94b10b52012-08-17 16:59:12 -0700468 @Override
469 public void onClick(View view) {
470 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700471 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700472 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700473 mInCallDialpadUp = false;
474 showDialpadFragment(true);
475 } else {
476 // Dial button was pressed; tell the Dialpad fragment
477 mDialpadFragment.dialButtonPressed();
478 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700479 break;
Yorke Leec3766332013-07-31 11:13:16 -0700480 case R.id.search_close_button:
481 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700482 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700483 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700484 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700485 }
486 break;
Yorke Leec3766332013-07-31 11:13:16 -0700487 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800488 try {
489 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
490 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
491 } catch (ActivityNotFoundException e) {
492 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
493 Toast.LENGTH_SHORT).show();
494 }
Yorke Leec3766332013-07-31 11:13:16 -0700495 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700496 case R.id.dialtacts_options_menu_button:
497 buildOptionsMenu(view).show();
498 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700499 default: {
500 Log.wtf(TAG, "Unexpected onClick event from " + view);
501 break;
502 }
503 }
504 }
505
Yorke Leec3766332013-07-31 11:13:16 -0700506 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700507 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700508 switch (item.getItemId()) {
509 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700510 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700511 break;
512 case R.id.menu_add_contact:
513 try {
514 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
515 } catch (ActivityNotFoundException e) {
516 Toast toast = Toast.makeText(this,
517 R.string.add_contact_not_available,
518 Toast.LENGTH_SHORT);
519 toast.show();
520 }
521 break;
522 case R.id.menu_import_export:
523 // We hard-code the "contactsAreAvailable" argument because doing it properly would
524 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
525 // now in Dialtacts for (potential) performance reasons. Compare with how it is
526 // done in {@link PeopleActivity}.
527 ImportExportDialogFragment.show(getFragmentManager(), true,
528 DialtactsActivity.class);
529 return true;
530 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700531 ClearFrequentsDialog.show(getFragmentManager());
532 return true;
533 case R.id.menu_call_settings:
534 handleMenuSettings();
535 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700536 }
537 return false;
538 }
539
540 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700541 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
542 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
543 if (resultCode == RESULT_OK) {
544 final ArrayList<String> matches = data.getStringArrayListExtra(
545 RecognizerIntent.EXTRA_RESULTS);
546 if (matches.size() > 0) {
547 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700548 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700549 } else {
550 Log.e(TAG, "Voice search - nothing heard");
551 }
552 } else {
553 Log.e(TAG, "Voice search failed");
554 }
555 }
556 super.onActivityResult(requestCode, resultCode, data);
557 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700558
Andrew Lee2a58ab82014-05-15 02:16:04 -0700559 /**
560 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
561 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
562 * @see #onDialpadShown
563 */
Yorke Leec3766332013-07-31 11:13:16 -0700564 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700565 if (mIsDialpadShown) {
566 return;
567 }
568 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700569 mDialpadFragment.setAnimate(animate);
570
Chiao Cheng94b10b52012-08-17 16:59:12 -0700571 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700572 ft.show(mDialpadFragment);
573 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700574
Yorke Lee5253be02014-05-21 18:50:03 -0700575 mActionBarController.onDialpadUp();
576
Andrew Leeb1903842014-05-15 16:11:24 -0700577 if (!isInSearchUi()) {
578 enterSearchUi(true /* isSmartDial */, mSearchQuery);
579 }
Yorke Leec3766332013-07-31 11:13:16 -0700580 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700581
Andrew Lee2a58ab82014-05-15 02:16:04 -0700582 /**
583 * Callback from child DialpadFragment when the dialpad is shown.
584 */
585 public void onDialpadShown() {
586 updateFloatingActionButton();
587 if (mDialpadFragment.getAnimate()) {
588 Animation slideIn = AnimationUtils.loadAnimation(this, R.anim.slide_in);
589 mDialpadFragment.getView().startAnimation(slideIn);
590 } else {
591 mDialpadFragment.setYFraction(0);
592 }
593
Andrew Lee2a58ab82014-05-15 02:16:04 -0700594 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700595 }
596
597 /**
598 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
599 * a callback after the hide animation ends.
600 * @see #commitDialpadFragmentHide
601 */
Yorke Leeca195042013-09-25 16:29:38 -0700602 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700603 if (mDialpadFragment == null) {
604 return;
605 }
Yorke Leef6673d32013-08-23 15:34:17 -0700606 if (clearDialpad) {
607 mDialpadFragment.clearDialpad();
608 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700609 if (!mIsDialpadShown) {
610 return;
Yorke Leec3766332013-07-31 11:13:16 -0700611 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700612 mIsDialpadShown = false;
613 mDialpadFragment.setAnimate(animate);
614
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700615 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700616 updateFloatingActionButton();
617 if (animate) {
618 Animation slideOut = AnimationUtils.loadAnimation(this, R.anim.slide_out);
Andrew Lee3c14bc32014-05-28 15:43:03 -0700619 slideOut.setAnimationListener(new AnimationListenerAdapter() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700620 @Override
621 public void onAnimationEnd(Animation animation) {
622 commitDialpadFragmentHide();
623 }
624 });
625 mDialpadFragment.getView().startAnimation(slideOut);
626 } else {
627 commitDialpadFragmentHide();
628 }
629
Yorke Lee5253be02014-05-21 18:50:03 -0700630 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700631
Andrew Leed4cde832014-05-16 15:56:48 -0700632 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700633 if (TextUtils.isEmpty(mSearchQuery)) {
634 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700635 }
Andrew Leed4cde832014-05-16 15:56:48 -0700636 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700637 }
638
639 /**
640 * Finishes hiding the dialpad fragment after any animations are completed.
641 */
642 private void commitDialpadFragmentHide() {
643 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700644 ft.hide(mDialpadFragment);
645 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700646 }
647
Andrew Lee2a58ab82014-05-15 02:16:04 -0700648 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700649 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700650 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700651 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700652 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700653 fragment = mRegularSearchFragment;
654 }
655 if (fragment != null && fragment.isVisible()) {
Andrew Lee05b62672014-06-03 14:03:09 -0700656 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700657 }
658 }
659
Yorke Lee5253be02014-05-21 18:50:03 -0700660 @Override
661 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700662 return mInDialpadSearch || mInRegularSearch;
663 }
664
Yorke Lee5253be02014-05-21 18:50:03 -0700665 @Override
666 public boolean hasSearchQuery() {
667 return !TextUtils.isEmpty(mSearchQuery);
668 }
669
670 @Override
671 public boolean shouldShowActionBar() {
672 return mListsFragment.shouldShowActionBar();
673 }
674
Yorke Leeb207f8a2013-08-29 18:51:06 -0700675 private void setNotInSearchUi() {
676 mInDialpadSearch = false;
677 mInRegularSearch = false;
678 }
679
Yorke Lee311969c2013-08-26 06:31:11 -0700680 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700681 if (mIsDialpadShown) {
682 hideDialpadFragment(false, true);
683 } else {
684 exitSearchUi();
685 }
Yorke Lee311969c2013-08-26 06:31:11 -0700686 }
687
Yorke Leee00c9fe2014-04-12 12:42:06 -0700688 private void hideInputMethod(View view) {
689 final InputMethodManager imm = (InputMethodManager) getSystemService(
690 Context.INPUT_METHOD_SERVICE);
691 if (imm != null && view != null) {
692 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
693 }
694 }
695
Yorke Lee53a22302014-04-29 18:13:46 -0700696 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700697 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
698 if (canIntentBeHandled(voiceIntent)) {
699 mVoiceSearchButton.setVisibility(View.VISIBLE);
700 mVoiceSearchButton.setOnClickListener(this);
701 } else {
702 mVoiceSearchButton.setVisibility(View.GONE);
703 }
704 }
705
Andrew Leee74a10e2014-05-16 14:31:40 -0700706 private OptionsPopupMenu buildOptionsMenu(View invoker) {
707 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
708 popupMenu.inflate(R.menu.dialtacts_options);
709 popupMenu.setOnMenuItemClickListener(this);
710 return popupMenu;
711 }
712
Yorke Lee86e21f72014-04-02 16:49:38 -0700713 @Override
714 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700715 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700716 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700717 mPendingSearchViewQuery = null;
718 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700719 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700720 }
721
Chiao Cheng94b10b52012-08-17 16:59:12 -0700722 /**
723 * Returns true if the intent is due to hitting the green send key (hardware call button:
724 * KEYCODE_CALL) while in a call.
725 *
726 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700727 * @return true if the intent is due to hitting the green send key while in a call
728 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700729 private boolean isSendKeyWhileInCall(Intent intent) {
730 // If there is a call in progress and the user launched the dialer by hitting the call
731 // button, go straight to the in-call screen.
732 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700733
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700734 if (callKey) {
735 getTelephonyManager().showCallScreen();
736 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700737 }
738
739 return false;
740 }
741
742 /**
743 * Sets the current tab based on the intent's request type
744 *
745 * @param intent Intent that contains information about which tab should be selected
746 */
Yorke Leec3766332013-07-31 11:13:16 -0700747 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700748 // If we got here by hitting send and we're in call forward along to the in-call activity
Yorke Lee62e995c2014-03-28 10:02:56 -0700749 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700750 finish();
751 return;
752 }
753
Yorke Lee669b6082013-09-17 15:43:38 -0700754 if (mDialpadFragment != null) {
755 final boolean phoneIsInUse = phoneIsInUse();
756 if (phoneIsInUse || isDialIntent(intent)) {
757 mDialpadFragment.setStartedFromNewIntent(true);
758 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
759 mInCallDialpadUp = true;
760 }
761 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700762 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700763 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700764 }
765
766 @Override
767 public void onNewIntent(Intent newIntent) {
768 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700769 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700770
Chiao Cheng94b10b52012-08-17 16:59:12 -0700771 invalidateOptionsMenu();
772 }
773
774 /** Returns true if the given intent contains a phone number to populate the dialer with */
775 private boolean isDialIntent(Intent intent) {
776 final String action = intent.getAction();
777 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
778 return true;
779 }
780 if (Intent.ACTION_VIEW.equals(action)) {
781 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700782 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700783 return true;
784 }
785 }
786 return false;
787 }
788
789 /**
790 * Returns an appropriate call origin for this Activity. May return null when no call origin
791 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
792 * for remembering the tab in which the user made a phone call, so the external app's DIAL
793 * request should not be counted.)
794 */
795 public String getCallOrigin() {
796 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
797 }
798
Chiao Cheng94b10b52012-08-17 16:59:12 -0700799 /**
Yorke Leec3766332013-07-31 11:13:16 -0700800 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700801 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700802 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700803 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700804 // Weird race condition where fragment is doing work after the activity is destroyed
805 // due to talkback being on (b/10209937). Just return since we can't do any
806 // constructive here.
807 return;
808 }
809
Yorke Leeef2b7382013-08-09 17:39:25 -0700810 if (DEBUG) {
811 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
812 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700813
Yorke Leec3766332013-07-31 11:13:16 -0700814 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700815 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700816 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700817 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700818 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700819 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700820
Yorke Leeb207f8a2013-08-29 18:51:06 -0700821 final String tag;
822 if (smartDialSearch) {
823 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
824 } else {
825 tag = TAG_REGULAR_SEARCH_FRAGMENT;
826 }
827 mInDialpadSearch = smartDialSearch;
828 mInRegularSearch = !smartDialSearch;
829
Andrew Lee752956e2014-05-15 11:43:38 -0700830 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700831 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700832 if (fragment == null) {
833 if (smartDialSearch) {
834 fragment = new SmartDialSearchFragment();
835 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700836 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700837 }
Andrew Leeb1903842014-05-15 16:11:24 -0700838 transaction.add(R.id.dialtacts_frame, fragment, tag);
839 } else {
840 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700841 }
Andrew Leeb1903842014-05-15 16:11:24 -0700842
Yorke Lee86e21f72014-04-02 16:49:38 -0700843 // DialtactsActivity will provide the options menu
844 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700845 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700846 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700847 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700848
849 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700850 }
851
852 /**
Yorke Leec3766332013-07-31 11:13:16 -0700853 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700854 */
Yorke Leec3766332013-07-31 11:13:16 -0700855 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700856 // See related bug in enterSearchUI();
857 if (getFragmentManager().isDestroyed()) {
858 return;
859 }
Andrew Leeb1903842014-05-15 16:11:24 -0700860
Andrew Leeb1903842014-05-15 16:11:24 -0700861 mSearchView.setText(null);
862 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700863 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700864
Andrew Leeb1903842014-05-15 16:11:24 -0700865 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700866 if (mSmartDialSearchFragment != null) {
867 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700868 }
Andrew Leeb1903842014-05-15 16:11:24 -0700869 if (mRegularSearchFragment != null) {
870 transaction.remove(mRegularSearchFragment);
871 }
872 transaction.commit();
873
874 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700875 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700876 }
877
878 /** Returns an Intent to launch Call Settings screen */
879 public static Intent getCallSettingsIntent() {
880 final Intent intent = new Intent(Intent.ACTION_MAIN);
881 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
882 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
883 return intent;
884 }
885
886 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700887 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700888 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700889 if (TextUtils.isEmpty(mSearchQuery)) {
890 exitSearchUi();
891 }
Yorke Leef6673d32013-08-23 15:34:17 -0700892 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700893 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700894 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700895 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700896 } else {
897 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700898 }
Yorke Leec3766332013-07-31 11:13:16 -0700899 }
900
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700901 /**
902 * @return True if the search UI was exited, false otherwise
903 */
904 private boolean maybeExitSearchUi() {
905 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
906 exitSearchUi();
907 hideInputMethod(parentLayout);
908 return true;
909 }
910 return false;
911 }
912
Yorke Leec3766332013-07-31 11:13:16 -0700913 @Override
914 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700915 if (mSmartDialSearchFragment != null) {
916 mSmartDialSearchFragment.setAddToContactNumber(query);
917 }
Yorke Leec3766332013-07-31 11:13:16 -0700918 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
919 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700920
921 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700922 if (DEBUG) {
923 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
924 }
925 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
926 // This callback can happen if the dialpad fragment is recreated because of
927 // activity destruction. In that case, don't update the search view because
928 // that would bring the user back to the search fragment regardless of the
929 // previous state of the application. Instead, just return here and let the
930 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700931 if (!TextUtils.isEmpty(normalizedQuery)) {
932 mPendingSearchViewQuery = normalizedQuery;
933 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700934 return;
935 }
Yorke Lee53a22302014-04-29 18:13:46 -0700936 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700937 }
938 }
Yorke Leec3766332013-07-31 11:13:16 -0700939
940 @Override
941 public void onListFragmentScrollStateChange(int scrollState) {
942 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700943 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700944 hideInputMethod(getCurrentFocus());
945 }
946 }
947
948 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700949 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700950 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700951 // TODO: No-op for now. This should eventually show/hide the actionBar based on
952 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -0700953 }
954
Yorke Lee86e21f72014-04-02 16:49:38 -0700955 @Override
Andrew Leea73e1892014-05-13 13:21:16 -0700956 public void setFloatingActionButtonVisible(boolean visible) {
957 mFloatingActionButtonContainer.setVisibility(visible ? View.VISIBLE : View.GONE);
Yorke Leec3766332013-07-31 11:13:16 -0700958 }
959
960 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700961 // TODO(santoscordon): Replace with a TelecommService method call.
962 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -0700963 }
Yorke Lee8dd62002013-08-08 15:57:20 -0700964
Yorke Leee1424812013-09-04 18:24:48 -0700965 public static Intent getAddNumberToContactIntent(CharSequence text) {
966 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
967 intent.putExtra(Intents.Insert.PHONE, text);
968 intent.setType(Contacts.CONTENT_ITEM_TYPE);
969 return intent;
970 }
971
Yorke Leeda0f9042013-12-05 14:25:51 -0800972 private boolean canIntentBeHandled(Intent intent) {
973 final PackageManager packageManager = getPackageManager();
974 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
975 PackageManager.MATCH_DEFAULT_ONLY);
976 return resolveInfo != null && resolveInfo.size() > 0;
977 }
Yorke Lee3cefcc62014-01-16 11:26:46 -0800978
Yorke Lee6a1461a2014-04-21 16:27:14 -0700979 @Override
980 public void showCallHistory() {
981 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
982 // CONTENT_TYPE, so that we always open our call log from our dialer
983 final Intent intent = new Intent(this, CallLogActivity.class);
984 startActivity(intent);
985 }
986
Yorke Lee86e21f72014-04-02 16:49:38 -0700987 /**
988 * Called when the user has long-pressed a contact tile to start a drag operation.
989 */
Yorke Lee3cefcc62014-01-16 11:26:46 -0800990 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -0700991 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -0700992 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -0700993 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -0700994 }
Andrew Lee18963442014-06-06 17:20:13 -0700995 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -0800996 }
997
998 @Override
Yorke Lee28266192014-05-01 10:05:52 -0700999 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1000 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001001
Yorke Lee86e21f72014-04-02 16:49:38 -07001002 /**
1003 * Called when the user has released a contact tile after long-pressing it.
1004 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001005 @Override
1006 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001007 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001008 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001009 }
Andrew Lee18963442014-06-06 17:20:13 -07001010 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001011 }
1012
1013 @Override
1014 public void onDroppedOnRemove() {}
1015
1016 /**
Yorke Leed999b712014-04-23 15:10:58 -07001017 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001018 * once it has been attached to the activity.
1019 */
1020 @Override
1021 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001022 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001023 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001024 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001025
1026 @Override
1027 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001028 // Specify call-origin so that users will see the previous tab instead of
1029 // CallLog screen (search UI will be automatically exited).
1030 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001031 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001032 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001033 }
1034
1035 @Override
1036 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001037 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1038 startActivity(intent);
1039 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001040 }
1041
1042 @Override
1043 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001044 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001045 }
1046
1047 @Override
1048 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001049 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001050 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001051
Yorke Leecc4660d2014-04-24 11:22:57 -07001052 @Override
1053 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
1054
1055 }
1056
1057 @Override
1058 public void onPageSelected(int position) {
1059 mCurrentTabPosition = position;
Yorke Leec61d4542014-05-01 10:43:24 -07001060 // If the dialpad is showing, the floating action button should always be middle aligned.
Andrew Lee2a58ab82014-05-15 02:16:04 -07001061 if (!mIsDialpadShown) {
Yorke Leec61d4542014-05-01 10:43:24 -07001062 alignFloatingActionButtonByTab(mCurrentTabPosition);
1063 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001064 }
1065
1066 @Override
1067 public void onPageScrollStateChanged(int state) {
1068 }
1069
Andrew Lee2a58ab82014-05-15 02:16:04 -07001070 private void updateFloatingActionButton() {
1071 if (mIsDialpadShown) {
1072 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
1073 mFloatingActionButton.setContentDescription(
1074 getResources().getString(R.string.description_dial_button));
Andrew Leec4643f72014-05-15 11:27:39 -07001075 alignFloatingActionButtonMiddle();
Andrew Lee2a58ab82014-05-15 02:16:04 -07001076 } else {
1077 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
1078 mFloatingActionButton.setContentDescription(
1079 getResources().getString(R.string.action_menu_dialpad_button));
Andrew Leec4643f72014-05-15 11:27:39 -07001080 alignFloatingActionButtonByTab(mCurrentTabPosition);
Andrew Lee2a58ab82014-05-15 02:16:04 -07001081 }
1082 }
1083
Yorke Leecc4660d2014-04-24 11:22:57 -07001084 private void alignFloatingActionButtonByTab(int position) {
1085 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL) {
1086 alignFloatingActionButtonMiddle();
1087 } else {
1088 alignFloatingActionButtonRight();
1089 }
1090 }
1091
1092 private void alignFloatingActionButtonRight() {
1093 final RelativeLayout.LayoutParams params =
Andrew Leea73e1892014-05-13 13:21:16 -07001094 (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams();
Yorke Leecc4660d2014-04-24 11:22:57 -07001095 params.removeRule(RelativeLayout.CENTER_HORIZONTAL);
1096 params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Andrew Lee2423a2f2014-05-29 14:14:45 -07001097 updateFloatingActionButtonMargin(params);
Andrew Leea73e1892014-05-13 13:21:16 -07001098 mFloatingActionButtonContainer.setLayoutParams(params);
Yorke Leecc4660d2014-04-24 11:22:57 -07001099 }
1100
1101 private void alignFloatingActionButtonMiddle() {
1102 final RelativeLayout.LayoutParams params =
Andrew Leea73e1892014-05-13 13:21:16 -07001103 (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams();
Yorke Leecc4660d2014-04-24 11:22:57 -07001104 params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
1105 params.addRule(RelativeLayout.CENTER_HORIZONTAL);
Andrew Lee2423a2f2014-05-29 14:14:45 -07001106 updateFloatingActionButtonMargin(params);
Andrew Leea73e1892014-05-13 13:21:16 -07001107 mFloatingActionButtonContainer.setLayoutParams(params);
Yorke Leecc4660d2014-04-24 11:22:57 -07001108 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001109
Andrew Lee2423a2f2014-05-29 14:14:45 -07001110 private void updateFloatingActionButtonMargin(RelativeLayout.LayoutParams params) {
1111 params.setMarginsRelative(
1112 params.getMarginStart(),
1113 params.topMargin,
1114 params.getMarginEnd(),
1115 mIsDialpadShown ?
1116 mFloatingActionButtonDialpadMarginBottom :
1117 mFloatingActionButtonMarginBottom);
1118 }
1119
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001120 private TelephonyManager getTelephonyManager() {
1121 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1122 }
1123
Yorke Lee5253be02014-05-21 18:50:03 -07001124 @Override
1125 public boolean isActionBarShowing() {
1126 return mActionBarController.isActionBarShowing();
1127 }
1128
Andrew Lee05b62672014-06-03 14:03:09 -07001129 public boolean isDialpadShown() {
1130 return mIsDialpadShown;
1131 }
1132
Yorke Lee5253be02014-05-21 18:50:03 -07001133 @Override
1134 public int getActionBarHideOffset() {
1135 return getActionBar().getHideOffset();
1136 }
1137
1138 @Override
1139 public int getActionBarHeight() {
1140 return mActionBarHeight;
1141 }
1142
1143 @Override
1144 public void setActionBarHideOffset(int hideOffset) {
1145 getActionBar().setHideOffset(hideOffset);
1146 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001147}