blob: 6a0706f8da9cc0c5a8914c56f2b57e994826338a [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;
Yorke Lee86e21f72014-04-02 16:49:38 -070052import android.view.animation.AccelerateInterpolator;
Andrew Lee2a58ab82014-05-15 02:16:04 -070053import android.view.animation.Animation;
54import android.view.animation.Animation.AnimationListener;
55import android.view.animation.AnimationUtils;
Yorke Lee86e21f72014-04-02 16:49:38 -070056import android.view.animation.DecelerateInterpolator;
57import android.view.animation.Interpolator;
Chiao Cheng94b10b52012-08-17 16:59:12 -070058import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070059import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070060import android.widget.EditText;
Andrew Leea73e1892014-05-13 13:21:16 -070061import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070062import android.widget.PopupMenu;
Yorke Leecc4660d2014-04-24 11:22:57 -070063import android.widget.RelativeLayout;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080064import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070065
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070066import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070067import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070068import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070069import com.android.contacts.common.dialog.ClearFrequentsDialog;
70import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080071import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Andrew Lee4cbc9732014-04-24 14:38:58 -070072import com.android.contacts.common.util.ViewUtil;
Yorke Leec3766332013-07-31 11:13:16 -070073import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070074import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070075import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070076import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070077import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070078import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080079import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070080import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080081import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070082import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070083import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070084import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070085import com.android.dialer.list.RegularSearchFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080086import com.android.dialer.list.RemoveView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070087import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070088import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070089import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070090import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070091import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070092import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070093
Yorke Leec3766332013-07-31 11:13:16 -070094import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080095import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070096
Chiao Cheng94b10b52012-08-17 16:59:12 -070097/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070098 * The dialer tab's title is 'phone', a more common name (see strings.xml).
99 */
Yorke Leec3766332013-07-31 11:13:16 -0700100public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700101 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700102 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800103 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700104 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700105 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700106 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700107 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700108 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700109 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700110 ViewPager.OnPageChangeListener,
111 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700112 private static final String TAG = "DialtactsActivity";
113
Ihab Awad526c0b82014-02-27 12:55:36 -0800114 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700115
Yorke Leef74011e2013-08-02 11:30:30 -0700116 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
117
Chiao Cheng94b10b52012-08-17 16:59:12 -0700118 /** Used to open Call Setting */
119 private static final String PHONE_PACKAGE = "com.android.phone";
120 private static final String CALL_SETTINGS_CLASS_NAME =
121 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700122 /** @see #getCallOrigin() */
123 private static final String CALL_ORIGIN_DIALTACTS =
124 "com.android.dialer.DialtactsActivity";
125
Yorke Leeb207f8a2013-08-29 18:51:06 -0700126 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
127 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700128 private static final String KEY_SEARCH_QUERY = "search_query";
129 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700130 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700131
Yorke Leec3766332013-07-31 11:13:16 -0700132 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
133 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
134 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
135 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700136
Chiao Cheng94b10b52012-08-17 16:59:12 -0700137 /**
138 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
139 */
140 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
141
Yorke Leec3766332013-07-31 11:13:16 -0700142 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700143
Yorke Lee86e21f72014-04-02 16:49:38 -0700144 private static final int ANIMATION_DURATION = 250;
Yorke Lee3cefcc62014-01-16 11:26:46 -0800145
Andrew Lee0c667702014-05-12 14:31:45 -0700146 private RelativeLayout parentLayout;
147
Yorke Leec3766332013-07-31 11:13:16 -0700148 /**
Yorke Leec3766332013-07-31 11:13:16 -0700149 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700150 */
Yorke Leef74011e2013-08-02 11:30:30 -0700151 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700152
153 /**
154 * Fragment for searching phone numbers using the alphanumeric keyboard.
155 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700156 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700157
158 /**
159 * Fragment for searching phone numbers using the dialpad.
160 */
161 private SmartDialSearchFragment mSmartDialSearchFragment;
162
Yorke Leee00c9fe2014-04-12 12:42:06 -0700163 /**
164 * Fragment containing the speed dial list, recents list, and all contacts list.
165 */
166 private ListsFragment mListsFragment;
167
Andrew Leea73e1892014-05-13 13:21:16 -0700168 private View mFloatingActionButtonContainer;
169 private ImageButton mFloatingActionButton;
Yorke Leec3766332013-07-31 11:13:16 -0700170
Yorke Leeb207f8a2013-08-29 18:51:06 -0700171 private boolean mInDialpadSearch;
172 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700173 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700174 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700175 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700176
Yorke Leeef2b7382013-08-09 17:39:25 -0700177 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700178 * The position of the currently selected tab in the attached {@link ListsFragment}.
179 */
180 private int mCurrentTabPosition = 0;
181
182 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700183 * True if the dialpad is only temporarily showing due to being in call
184 */
185 private boolean mInCallDialpadUp;
186
187 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700188 * True when this activity has been launched for the first time.
189 */
Yorke Lee98702de2013-08-06 12:03:32 -0700190 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700191
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700192 /**
193 * Search query to be applied to the SearchView in the ActionBar once
194 * onCreateOptionsMenu has been called.
195 */
196 private String mPendingSearchViewQuery;
197
Yorke Lee53a22302014-04-29 18:13:46 -0700198 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700199 private View mVoiceSearchButton;
Yorke Leeec489fb2014-05-19 15:39:27 -0700200 private SearchEditTextLayout mSearchEditTextLayout;
Andrew Leee74a10e2014-05-16 14:31:40 -0700201
Yorke Lee86e21f72014-04-02 16:49:38 -0700202 /**
203 * View that contains the "Remove" dialog that shows up when the user long presses a contact.
204 * If the user releases a contact when hovering on top of this, the contact is unfavorited and
205 * removed from the speed dial list.
206 */
Yorke Lee28266192014-05-01 10:05:52 -0700207 private View mRemoveViewContainer;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700208
Yorke Lee86e21f72014-04-02 16:49:38 -0700209 final Interpolator hideActionBarInterpolator = new AccelerateInterpolator(1.5f);
210 final Interpolator showActionBarInterpolator = new DecelerateInterpolator(1.5f);
Yorke Leeef2b7382013-08-09 17:39:25 -0700211 private String mSearchQuery;
212
Yorke Leefce269a2013-08-12 11:56:04 -0700213 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700214 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700215 private ActionBarController mActionBarController;
Yorke Leefce269a2013-08-12 11:56:04 -0700216
Andrew Lee2423a2f2014-05-29 14:14:45 -0700217 private int mActionBarHeight;
218 private int mFloatingActionButtonMarginBottom;
219 private int mFloatingActionButtonDialpadMarginBottom;
220
Andrew Leee74a10e2014-05-16 14:31:40 -0700221 private class OptionsPopupMenu extends PopupMenu {
222 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700223 super(context, anchor);
224 }
225
226 @Override
227 public void show() {
228 final Menu menu = getMenu();
229 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700230 clearFrequents.setVisible(mListsFragment != null &&
231 mListsFragment.getSpeedDialFragment() != null &&
232 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700233 super.show();
234 }
235 }
236
Chiao Cheng94b10b52012-08-17 16:59:12 -0700237 /**
Yorke Lee28266192014-05-01 10:05:52 -0700238 * Listener that listens to drag events and sends their x and y coordinates to a
239 * {@link DragDropController}.
240 */
241 private class LayoutOnDragListener implements OnDragListener {
242 @Override
243 public boolean onDrag(View v, DragEvent event) {
244 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
245 mDragDropController.handleDragHovered(v, (int) event.getX(),
246 (int) event.getY());
247 }
248 return true;
249 }
250 }
251
252 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700253 * Listener used to send search queries to the phone search fragment.
254 */
Yorke Lee53a22302014-04-29 18:13:46 -0700255 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700256 @Override
257 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
258 }
Yorke Leec3766332013-07-31 11:13:16 -0700259
Andrew Lee99a570c2014-05-15 14:18:50 -0700260 @Override
261 public void onTextChanged(CharSequence s, int start, int before, int count) {
262 final String newText = s.toString();
263 if (newText.equals(mSearchQuery)) {
264 // If the query hasn't changed (perhaps due to activity being destroyed
265 // and restored, or user launching the same DIAL intent twice), then there is
266 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700267 return;
268 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700269 if (DEBUG) {
270 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700271 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700272 }
Yorke Lee710709d2014-05-29 07:18:42 -0700273 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700274
Andrew Lee90374a72014-05-16 15:01:09 -0700275 // Show search fragment only when the query string is changed to non-empty text.
276 if (!TextUtils.isEmpty(newText)) {
277 // Call enterSearchUi only if we are switching search modes, or showing a search
278 // fragment for the first time.
279 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
280 (!mIsDialpadShown && mInRegularSearch);
281 if (!sameSearchMode) {
282 enterSearchUi(mIsDialpadShown, mSearchQuery);
283 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700284 }
285
286 if (mIsDialpadShown && mSmartDialSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700287 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700288 } else if (mRegularSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700289 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700290 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700291 }
292
293 @Override
294 public void afterTextChanged(Editable s) {
295 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700296 };
297
Andrew Leeb1903842014-05-15 16:11:24 -0700298
299 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700300 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700301 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700302 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700303 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700304 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700305 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700306 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700307 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
308 }
Andrew Leeb1903842014-05-15 16:11:24 -0700309 }
310 };
311
312 /**
313 * If the search term is empty and the user closes the soft keyboard, close the search UI.
314 */
315 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
316 @Override
317 public boolean onKey(View v, int keyCode, KeyEvent event) {
318 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
319 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700320 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700321 }
322 return false;
323 }
324 };
325
Chiao Cheng94b10b52012-08-17 16:59:12 -0700326 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700327 protected void onCreate(Bundle savedInstanceState) {
328 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700329 mFirstLaunch = true;
330
Andrew Lee2423a2f2014-05-29 14:14:45 -0700331 final Resources resources = getResources();
332 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
333 mFloatingActionButtonMarginBottom =
334 resources.getDimensionPixelOffset(R.dimen.floating_action_button_margin_bottom);
335 mFloatingActionButtonDialpadMarginBottom = resources.getDimensionPixelOffset(
336 R.dimen.floating_action_button_dialpad_margin_bottom);
337
Yorke Lee8898cd02013-08-08 10:24:27 -0700338 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800339 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700340
Yorke Lee53a22302014-04-29 18:13:46 -0700341 final ActionBar actionBar = getActionBar();
342 actionBar.setCustomView(R.layout.search_edittext);
343 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700344 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700345
Yorke Lee5253be02014-05-21 18:50:03 -0700346 mActionBarController = new ActionBarController(this,
347 (SearchEditTextLayout) actionBar.getCustomView());
348
Yorke Leeec489fb2014-05-19 15:39:27 -0700349 mSearchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView();
350 mSearchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
Yorke Lee53a22302014-04-29 18:13:46 -0700351
Yorke Leeec489fb2014-05-19 15:39:27 -0700352 mSearchView = (EditText) mSearchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700353 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Yorke Lee11ca39e2014-05-19 20:31:37 -0700354 mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button);
355 mSearchEditTextLayout.findViewById(R.id.search_box_start_search).setOnClickListener(
356 mSearchViewOnClickListener);
357 mSearchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
358 @Override
359 public void onBackButtonClicked() {
360 onBackPressed();
361 }
362 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700363
Yorke Leeec489fb2014-05-19 15:39:27 -0700364 ImageButton optionsMenuButton = (ImageButton) mSearchEditTextLayout.findViewById(
365 R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700366 optionsMenuButton.setOnClickListener(this);
367 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
368 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
369
Yorke Leeef2b7382013-08-09 17:39:25 -0700370 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
371 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700372 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800373 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700374 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800375 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
376 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700377 } else {
378 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700379 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
380 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700381 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700382 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700383 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700384 }
385
Andrew Lee0c667702014-05-12 14:31:45 -0700386 parentLayout = (RelativeLayout) findViewById(R.id.dialtacts_mainlayout);
387 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
388 parentLayout.setOnDragListener(new LayoutOnDragListener());
389
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700390 setupActivityOverlay();
391
Andrew Leea73e1892014-05-13 13:21:16 -0700392 mFloatingActionButtonContainer = findViewById(R.id.floating_action_button_container);
393 ViewUtil.setupFloatingActionButton(mFloatingActionButtonContainer, getResources());
Yorke Lee86e21f72014-04-02 16:49:38 -0700394
Andrew Leea73e1892014-05-13 13:21:16 -0700395 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
396 mFloatingActionButton.setOnClickListener(this);
Ihab Awad526c0b82014-02-27 12:55:36 -0800397
Yorke Lee28266192014-05-01 10:05:52 -0700398 mRemoveViewContainer = findViewById(R.id.remove_view_container);
Yorke Leeb0d19762014-03-05 14:43:28 -0800399
Yorke Lee0baa98b2013-08-22 10:55:16 -0700400 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700401 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700402 }
403
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700404 private void setupActivityOverlay() {
405 final View activityOverlay = findViewById(R.id.activity_overlay);
406 activityOverlay.setOnTouchListener(new OnTouchListener() {
407 @Override
408 public boolean onTouch(View v, MotionEvent event) {
409 if (!mIsDialpadShown) {
410 maybeExitSearchUi();
411 }
412 return false;
413 }
414 });
415 }
416
Chiao Cheng94b10b52012-08-17 16:59:12 -0700417 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700418 protected void onResume() {
419 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700420 if (mFirstLaunch) {
421 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700422 } else if (!phoneIsInUse() && mInCallDialpadUp) {
423 hideDialpadFragment(false, true);
424 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700425 } else if (mShowDialpadOnResume) {
426 showDialpadFragment(false);
427 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700428 }
429 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700430 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700431 mDialerDatabaseHelper.startSmartDialUpdateThread();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700432 }
433
434 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700435 protected void onPause() {
436 if (mClearSearchOnPause) {
437 hideDialpadAndSearchUi();
438 mClearSearchOnPause = false;
439 }
440 super.onPause();
441 }
442
443 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700444 protected void onSaveInstanceState(Bundle outState) {
445 super.onSaveInstanceState(outState);
446 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700447 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
448 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700449 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700450 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700451 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700452 }
453
454 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700455 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700456 if (fragment instanceof DialpadFragment) {
457 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700458 if (!mShowDialpadOnResume) {
459 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
460 transaction.hide(mDialpadFragment);
461 transaction.commit();
462 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700463 } else if (fragment instanceof SmartDialSearchFragment) {
464 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700465 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700466 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700467 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700468 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700469 } else if (fragment instanceof ListsFragment) {
470 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700471 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700472 }
Yorke Leec3766332013-07-31 11:13:16 -0700473 }
474
Alon Albertb453e5b2013-09-10 15:54:23 -0700475 protected void handleMenuSettings() {
476 openTelephonySetting(this);
477 }
478
479 public static void openTelephonySetting(Activity activity) {
480 final Intent settingsIntent = getCallSettingsIntent();
481 activity.startActivity(settingsIntent);
482 }
483
Chiao Cheng94b10b52012-08-17 16:59:12 -0700484 @Override
485 public void onClick(View view) {
486 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700487 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700488 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700489 mInCallDialpadUp = false;
490 showDialpadFragment(true);
491 } else {
492 // Dial button was pressed; tell the Dialpad fragment
493 mDialpadFragment.dialButtonPressed();
494 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700495 break;
Yorke Leec3766332013-07-31 11:13:16 -0700496 case R.id.search_close_button:
497 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700498 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700499 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700500 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700501 }
502 break;
Yorke Leec3766332013-07-31 11:13:16 -0700503 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800504 try {
505 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
506 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
507 } catch (ActivityNotFoundException e) {
508 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
509 Toast.LENGTH_SHORT).show();
510 }
Yorke Leec3766332013-07-31 11:13:16 -0700511 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700512 case R.id.dialtacts_options_menu_button:
513 buildOptionsMenu(view).show();
514 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700515 default: {
516 Log.wtf(TAG, "Unexpected onClick event from " + view);
517 break;
518 }
519 }
520 }
521
Yorke Leec3766332013-07-31 11:13:16 -0700522 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700523 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700524 switch (item.getItemId()) {
525 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700526 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700527 break;
528 case R.id.menu_add_contact:
529 try {
530 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
531 } catch (ActivityNotFoundException e) {
532 Toast toast = Toast.makeText(this,
533 R.string.add_contact_not_available,
534 Toast.LENGTH_SHORT);
535 toast.show();
536 }
537 break;
538 case R.id.menu_import_export:
539 // We hard-code the "contactsAreAvailable" argument because doing it properly would
540 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
541 // now in Dialtacts for (potential) performance reasons. Compare with how it is
542 // done in {@link PeopleActivity}.
543 ImportExportDialogFragment.show(getFragmentManager(), true,
544 DialtactsActivity.class);
545 return true;
546 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700547 ClearFrequentsDialog.show(getFragmentManager());
548 return true;
549 case R.id.menu_call_settings:
550 handleMenuSettings();
551 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700552 }
553 return false;
554 }
555
556 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700557 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
558 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
559 if (resultCode == RESULT_OK) {
560 final ArrayList<String> matches = data.getStringArrayListExtra(
561 RecognizerIntent.EXTRA_RESULTS);
562 if (matches.size() > 0) {
563 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700564 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700565 } else {
566 Log.e(TAG, "Voice search - nothing heard");
567 }
568 } else {
569 Log.e(TAG, "Voice search failed");
570 }
571 }
572 super.onActivityResult(requestCode, resultCode, data);
573 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700574
Andrew Lee2a58ab82014-05-15 02:16:04 -0700575 /**
576 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
577 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
578 * @see #onDialpadShown
579 */
Yorke Leec3766332013-07-31 11:13:16 -0700580 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700581 if (mIsDialpadShown) {
582 return;
583 }
584 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700585 mDialpadFragment.setAnimate(animate);
586
Chiao Cheng94b10b52012-08-17 16:59:12 -0700587 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700588 ft.show(mDialpadFragment);
589 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700590
Yorke Lee5253be02014-05-21 18:50:03 -0700591 mActionBarController.onDialpadUp();
592
Andrew Leeb1903842014-05-15 16:11:24 -0700593 if (!isInSearchUi()) {
594 enterSearchUi(true /* isSmartDial */, mSearchQuery);
595 }
Yorke Leec3766332013-07-31 11:13:16 -0700596 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700597
Andrew Lee2a58ab82014-05-15 02:16:04 -0700598 /**
599 * Callback from child DialpadFragment when the dialpad is shown.
600 */
601 public void onDialpadShown() {
602 updateFloatingActionButton();
603 if (mDialpadFragment.getAnimate()) {
604 Animation slideIn = AnimationUtils.loadAnimation(this, R.anim.slide_in);
605 mDialpadFragment.getView().startAnimation(slideIn);
606 } else {
607 mDialpadFragment.setYFraction(0);
608 }
609
Andrew Lee2a58ab82014-05-15 02:16:04 -0700610 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700611 }
612
613 /**
614 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
615 * a callback after the hide animation ends.
616 * @see #commitDialpadFragmentHide
617 */
Yorke Leeca195042013-09-25 16:29:38 -0700618 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700619 if (mDialpadFragment == null) {
620 return;
621 }
Yorke Leef6673d32013-08-23 15:34:17 -0700622 if (clearDialpad) {
623 mDialpadFragment.clearDialpad();
624 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700625 if (!mIsDialpadShown) {
626 return;
Yorke Leec3766332013-07-31 11:13:16 -0700627 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700628 mIsDialpadShown = false;
629 mDialpadFragment.setAnimate(animate);
630
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700631 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700632 updateFloatingActionButton();
633 if (animate) {
634 Animation slideOut = AnimationUtils.loadAnimation(this, R.anim.slide_out);
Andrew Lee3c14bc32014-05-28 15:43:03 -0700635 slideOut.setAnimationListener(new AnimationListenerAdapter() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700636 @Override
637 public void onAnimationEnd(Animation animation) {
638 commitDialpadFragmentHide();
639 }
640 });
641 mDialpadFragment.getView().startAnimation(slideOut);
642 } else {
643 commitDialpadFragmentHide();
644 }
645
Yorke Lee5253be02014-05-21 18:50:03 -0700646 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700647
Andrew Leed4cde832014-05-16 15:56:48 -0700648 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700649 if (TextUtils.isEmpty(mSearchQuery)) {
650 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700651 }
Andrew Leed4cde832014-05-16 15:56:48 -0700652 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700653 }
654
655 /**
656 * Finishes hiding the dialpad fragment after any animations are completed.
657 */
658 private void commitDialpadFragmentHide() {
659 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700660 ft.hide(mDialpadFragment);
661 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700662 }
663
Andrew Lee2a58ab82014-05-15 02:16:04 -0700664 private void updateSearchFragmentPosition() {
665 int translationValue = mIsDialpadShown ? -mActionBarHeight : 0;
666 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700667 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700668 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700669 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700670 fragment = mRegularSearchFragment;
671 }
672 if (fragment != null && fragment.isVisible()) {
673 fragment.getView().animate().translationY(translationValue)
674 .setInterpolator(hideActionBarInterpolator).setDuration(ANIMATION_DURATION);
675 }
676 }
677
Yorke Lee5253be02014-05-21 18:50:03 -0700678 @Override
679 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700680 return mInDialpadSearch || mInRegularSearch;
681 }
682
Yorke Lee5253be02014-05-21 18:50:03 -0700683 @Override
684 public boolean hasSearchQuery() {
685 return !TextUtils.isEmpty(mSearchQuery);
686 }
687
688 @Override
689 public boolean shouldShowActionBar() {
690 return mListsFragment.shouldShowActionBar();
691 }
692
Yorke Leeb207f8a2013-08-29 18:51:06 -0700693 private void setNotInSearchUi() {
694 mInDialpadSearch = false;
695 mInRegularSearch = false;
696 }
697
Yorke Lee311969c2013-08-26 06:31:11 -0700698 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700699 if (mIsDialpadShown) {
700 hideDialpadFragment(false, true);
701 } else {
702 exitSearchUi();
703 }
Yorke Lee311969c2013-08-26 06:31:11 -0700704 }
705
Yorke Leee00c9fe2014-04-12 12:42:06 -0700706 private void hideInputMethod(View view) {
707 final InputMethodManager imm = (InputMethodManager) getSystemService(
708 Context.INPUT_METHOD_SERVICE);
709 if (imm != null && view != null) {
710 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
711 }
712 }
713
Yorke Lee53a22302014-04-29 18:13:46 -0700714 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700715 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
716 if (canIntentBeHandled(voiceIntent)) {
717 mVoiceSearchButton.setVisibility(View.VISIBLE);
718 mVoiceSearchButton.setOnClickListener(this);
719 } else {
720 mVoiceSearchButton.setVisibility(View.GONE);
721 }
722 }
723
Andrew Leee74a10e2014-05-16 14:31:40 -0700724 private OptionsPopupMenu buildOptionsMenu(View invoker) {
725 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
726 popupMenu.inflate(R.menu.dialtacts_options);
727 popupMenu.setOnMenuItemClickListener(this);
728 return popupMenu;
729 }
730
Yorke Lee86e21f72014-04-02 16:49:38 -0700731 @Override
732 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700733 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700734 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700735 mPendingSearchViewQuery = null;
736 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700737 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700738 }
739
Chiao Cheng94b10b52012-08-17 16:59:12 -0700740 /**
741 * Returns true if the intent is due to hitting the green send key (hardware call button:
742 * KEYCODE_CALL) while in a call.
743 *
744 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700745 * @return true if the intent is due to hitting the green send key while in a call
746 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700747 private boolean isSendKeyWhileInCall(Intent intent) {
748 // If there is a call in progress and the user launched the dialer by hitting the call
749 // button, go straight to the in-call screen.
750 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700751
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700752 if (callKey) {
753 getTelephonyManager().showCallScreen();
754 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700755 }
756
757 return false;
758 }
759
760 /**
761 * Sets the current tab based on the intent's request type
762 *
763 * @param intent Intent that contains information about which tab should be selected
764 */
Yorke Leec3766332013-07-31 11:13:16 -0700765 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700766 // 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 -0700767 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700768 finish();
769 return;
770 }
771
Yorke Lee669b6082013-09-17 15:43:38 -0700772 if (mDialpadFragment != null) {
773 final boolean phoneIsInUse = phoneIsInUse();
774 if (phoneIsInUse || isDialIntent(intent)) {
775 mDialpadFragment.setStartedFromNewIntent(true);
776 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
777 mInCallDialpadUp = true;
778 }
779 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700780 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700781 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700782 }
783
784 @Override
785 public void onNewIntent(Intent newIntent) {
786 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700787 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700788
Chiao Cheng94b10b52012-08-17 16:59:12 -0700789 invalidateOptionsMenu();
790 }
791
792 /** Returns true if the given intent contains a phone number to populate the dialer with */
793 private boolean isDialIntent(Intent intent) {
794 final String action = intent.getAction();
795 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
796 return true;
797 }
798 if (Intent.ACTION_VIEW.equals(action)) {
799 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700800 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700801 return true;
802 }
803 }
804 return false;
805 }
806
807 /**
808 * Returns an appropriate call origin for this Activity. May return null when no call origin
809 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
810 * for remembering the tab in which the user made a phone call, so the external app's DIAL
811 * request should not be counted.)
812 */
813 public String getCallOrigin() {
814 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
815 }
816
Chiao Cheng94b10b52012-08-17 16:59:12 -0700817 /**
Yorke Leec3766332013-07-31 11:13:16 -0700818 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700819 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700820 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700821 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700822 // Weird race condition where fragment is doing work after the activity is destroyed
823 // due to talkback being on (b/10209937). Just return since we can't do any
824 // constructive here.
825 return;
826 }
827
Yorke Leeef2b7382013-08-09 17:39:25 -0700828 if (DEBUG) {
829 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
830 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700831
Yorke Leec3766332013-07-31 11:13:16 -0700832 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700833 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700834 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700835 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700836 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700837 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700838
Yorke Leeb207f8a2013-08-29 18:51:06 -0700839 final String tag;
840 if (smartDialSearch) {
841 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
842 } else {
843 tag = TAG_REGULAR_SEARCH_FRAGMENT;
844 }
845 mInDialpadSearch = smartDialSearch;
846 mInRegularSearch = !smartDialSearch;
847
Andrew Lee752956e2014-05-15 11:43:38 -0700848 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700849 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700850 if (fragment == null) {
851 if (smartDialSearch) {
852 fragment = new SmartDialSearchFragment();
853 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700854 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700855 }
Andrew Leeb1903842014-05-15 16:11:24 -0700856 transaction.add(R.id.dialtacts_frame, fragment, tag);
857 } else {
858 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700859 }
Andrew Leeb1903842014-05-15 16:11:24 -0700860
Yorke Lee86e21f72014-04-02 16:49:38 -0700861 // DialtactsActivity will provide the options menu
862 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700863 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700864 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700865 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700866
867 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700868 }
869
870 /**
Yorke Leec3766332013-07-31 11:13:16 -0700871 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700872 */
Yorke Leec3766332013-07-31 11:13:16 -0700873 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700874 // See related bug in enterSearchUI();
875 if (getFragmentManager().isDestroyed()) {
876 return;
877 }
Andrew Leeb1903842014-05-15 16:11:24 -0700878
Andrew Leeb1903842014-05-15 16:11:24 -0700879 mSearchView.setText(null);
880 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700881 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700882
Andrew Leeb1903842014-05-15 16:11:24 -0700883 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700884 if (mSmartDialSearchFragment != null) {
885 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700886 }
Andrew Leeb1903842014-05-15 16:11:24 -0700887 if (mRegularSearchFragment != null) {
888 transaction.remove(mRegularSearchFragment);
889 }
890 transaction.commit();
891
892 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700893 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700894 }
895
896 /** Returns an Intent to launch Call Settings screen */
897 public static Intent getCallSettingsIntent() {
898 final Intent intent = new Intent(Intent.ACTION_MAIN);
899 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
900 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
901 return intent;
902 }
903
904 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700905 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700906 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700907 if (TextUtils.isEmpty(mSearchQuery)) {
908 exitSearchUi();
909 }
Yorke Leef6673d32013-08-23 15:34:17 -0700910 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700911 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700912 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700913 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700914 } else {
915 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700916 }
Yorke Leec3766332013-07-31 11:13:16 -0700917 }
918
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700919 /**
920 * @return True if the search UI was exited, false otherwise
921 */
922 private boolean maybeExitSearchUi() {
923 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
924 exitSearchUi();
925 hideInputMethod(parentLayout);
926 return true;
927 }
928 return false;
929 }
930
Yorke Leec3766332013-07-31 11:13:16 -0700931 @Override
932 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700933 if (mSmartDialSearchFragment != null) {
934 mSmartDialSearchFragment.setAddToContactNumber(query);
935 }
Yorke Leec3766332013-07-31 11:13:16 -0700936 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
937 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700938
939 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700940 if (DEBUG) {
941 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
942 }
943 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
944 // This callback can happen if the dialpad fragment is recreated because of
945 // activity destruction. In that case, don't update the search view because
946 // that would bring the user back to the search fragment regardless of the
947 // previous state of the application. Instead, just return here and let the
948 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700949 if (!TextUtils.isEmpty(normalizedQuery)) {
950 mPendingSearchViewQuery = normalizedQuery;
951 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700952 return;
953 }
Yorke Lee53a22302014-04-29 18:13:46 -0700954 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700955 }
956 }
Yorke Leec3766332013-07-31 11:13:16 -0700957
958 @Override
959 public void onListFragmentScrollStateChange(int scrollState) {
960 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700961 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700962 hideInputMethod(getCurrentFocus());
963 }
964 }
965
966 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700967 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700968 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700969 // TODO: No-op for now. This should eventually show/hide the actionBar based on
970 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -0700971 }
972
Yorke Lee86e21f72014-04-02 16:49:38 -0700973 @Override
Andrew Leea73e1892014-05-13 13:21:16 -0700974 public void setFloatingActionButtonVisible(boolean visible) {
975 mFloatingActionButtonContainer.setVisibility(visible ? View.VISIBLE : View.GONE);
Yorke Leec3766332013-07-31 11:13:16 -0700976 }
977
978 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700979 // TODO(santoscordon): Replace with a TelecommService method call.
980 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -0700981 }
Yorke Lee8dd62002013-08-08 15:57:20 -0700982
Yorke Leee1424812013-09-04 18:24:48 -0700983 public static Intent getAddNumberToContactIntent(CharSequence text) {
984 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
985 intent.putExtra(Intents.Insert.PHONE, text);
986 intent.setType(Contacts.CONTENT_ITEM_TYPE);
987 return intent;
988 }
989
Yorke Leeda0f9042013-12-05 14:25:51 -0800990 private boolean canIntentBeHandled(Intent intent) {
991 final PackageManager packageManager = getPackageManager();
992 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
993 PackageManager.MATCH_DEFAULT_ONLY);
994 return resolveInfo != null && resolveInfo.size() > 0;
995 }
Yorke Lee3cefcc62014-01-16 11:26:46 -0800996
Yorke Lee6a1461a2014-04-21 16:27:14 -0700997 @Override
998 public void showCallHistory() {
999 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1000 // CONTENT_TYPE, so that we always open our call log from our dialer
1001 final Intent intent = new Intent(this, CallLogActivity.class);
1002 startActivity(intent);
1003 }
1004
Yorke Lee86e21f72014-04-02 16:49:38 -07001005 /**
1006 * Called when the user has long-pressed a contact tile to start a drag operation.
1007 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001008 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001009 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Yorke Lee5253be02014-05-21 18:50:03 -07001010 mActionBarController.slideActionBarUp(true);
Yorke Lee28266192014-05-01 10:05:52 -07001011 mRemoveViewContainer.setVisibility(View.VISIBLE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001012 }
1013
1014 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001015 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1016 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001017
Yorke Lee86e21f72014-04-02 16:49:38 -07001018 /**
1019 * Called when the user has released a contact tile after long-pressing it.
1020 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001021 @Override
1022 public void onDragFinished(int x, int y) {
Yorke Lee5253be02014-05-21 18:50:03 -07001023 mActionBarController.slideActionBarDown(true);
Yorke Lee28266192014-05-01 10:05:52 -07001024 mRemoveViewContainer.setVisibility(View.GONE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001025 }
1026
1027 @Override
1028 public void onDroppedOnRemove() {}
1029
1030 /**
Yorke Leed999b712014-04-23 15:10:58 -07001031 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001032 * once it has been attached to the activity.
1033 */
1034 @Override
1035 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001036 mDragDropController = dragController;
1037 ((RemoveView) findViewById(R.id.remove_view))
1038 .setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001039 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001040
1041 @Override
1042 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001043 // Specify call-origin so that users will see the previous tab instead of
1044 // CallLog screen (search UI will be automatically exited).
1045 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001046 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001047 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001048 }
1049
1050 @Override
1051 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001052 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1053 startActivity(intent);
1054 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001055 }
1056
1057 @Override
1058 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001059 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001060 }
1061
1062 @Override
1063 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001064 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001065 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001066
Yorke Leecc4660d2014-04-24 11:22:57 -07001067 @Override
1068 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
1069
1070 }
1071
1072 @Override
1073 public void onPageSelected(int position) {
1074 mCurrentTabPosition = position;
Yorke Leec61d4542014-05-01 10:43:24 -07001075 // If the dialpad is showing, the floating action button should always be middle aligned.
Andrew Lee2a58ab82014-05-15 02:16:04 -07001076 if (!mIsDialpadShown) {
Yorke Leec61d4542014-05-01 10:43:24 -07001077 alignFloatingActionButtonByTab(mCurrentTabPosition);
1078 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001079 }
1080
1081 @Override
1082 public void onPageScrollStateChanged(int state) {
1083 }
1084
Andrew Lee2a58ab82014-05-15 02:16:04 -07001085 private void updateFloatingActionButton() {
1086 if (mIsDialpadShown) {
1087 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
1088 mFloatingActionButton.setContentDescription(
1089 getResources().getString(R.string.description_dial_button));
Andrew Leec4643f72014-05-15 11:27:39 -07001090 alignFloatingActionButtonMiddle();
Andrew Lee2a58ab82014-05-15 02:16:04 -07001091 } else {
1092 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
1093 mFloatingActionButton.setContentDescription(
1094 getResources().getString(R.string.action_menu_dialpad_button));
Andrew Leec4643f72014-05-15 11:27:39 -07001095 alignFloatingActionButtonByTab(mCurrentTabPosition);
Andrew Lee2a58ab82014-05-15 02:16:04 -07001096 }
1097 }
1098
Yorke Leecc4660d2014-04-24 11:22:57 -07001099 private void alignFloatingActionButtonByTab(int position) {
1100 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL) {
1101 alignFloatingActionButtonMiddle();
1102 } else {
1103 alignFloatingActionButtonRight();
1104 }
1105 }
1106
1107 private void alignFloatingActionButtonRight() {
1108 final RelativeLayout.LayoutParams params =
Andrew Leea73e1892014-05-13 13:21:16 -07001109 (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams();
Yorke Leecc4660d2014-04-24 11:22:57 -07001110 params.removeRule(RelativeLayout.CENTER_HORIZONTAL);
1111 params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Andrew Lee2423a2f2014-05-29 14:14:45 -07001112 updateFloatingActionButtonMargin(params);
Andrew Leea73e1892014-05-13 13:21:16 -07001113 mFloatingActionButtonContainer.setLayoutParams(params);
Yorke Leecc4660d2014-04-24 11:22:57 -07001114 }
1115
1116 private void alignFloatingActionButtonMiddle() {
1117 final RelativeLayout.LayoutParams params =
Andrew Leea73e1892014-05-13 13:21:16 -07001118 (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams();
Yorke Leecc4660d2014-04-24 11:22:57 -07001119 params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
1120 params.addRule(RelativeLayout.CENTER_HORIZONTAL);
Andrew Lee2423a2f2014-05-29 14:14:45 -07001121 updateFloatingActionButtonMargin(params);
Andrew Leea73e1892014-05-13 13:21:16 -07001122 mFloatingActionButtonContainer.setLayoutParams(params);
Yorke Leecc4660d2014-04-24 11:22:57 -07001123 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001124
Andrew Lee2423a2f2014-05-29 14:14:45 -07001125 private void updateFloatingActionButtonMargin(RelativeLayout.LayoutParams params) {
1126 params.setMarginsRelative(
1127 params.getMarginStart(),
1128 params.topMargin,
1129 params.getMarginEnd(),
1130 mIsDialpadShown ?
1131 mFloatingActionButtonDialpadMarginBottom :
1132 mFloatingActionButtonMarginBottom);
1133 }
1134
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001135 private TelephonyManager getTelephonyManager() {
1136 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1137 }
1138
Yorke Lee5253be02014-05-21 18:50:03 -07001139 @Override
1140 public boolean isActionBarShowing() {
1141 return mActionBarController.isActionBarShowing();
1142 }
1143
1144 @Override
1145 public int getActionBarHideOffset() {
1146 return getActionBar().getHideOffset();
1147 }
1148
1149 @Override
1150 public int getActionBarHeight() {
1151 return mActionBarHeight;
1152 }
1153
1154 @Override
1155 public void setActionBarHideOffset(int hideOffset) {
1156 getActionBar().setHideOffset(hideOffset);
1157 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001158}