blob: 4ea9651d572f3abae98ab6492b2d21d9547bad4b [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;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070029import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070030import android.content.res.Resources;
Yorke Lee33932ff2014-04-16 13:34:32 -070031import android.content.res.TypedArray;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.net.Uri;
33import android.os.Bundle;
34import android.os.RemoteException;
35import android.os.ServiceManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070036import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070037import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070038import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070039import android.support.v4.view.ViewPager;
Yorke Leec3766332013-07-31 11:13:16 -070040import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070043import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070044import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070045import android.view.DragEvent;
Andrew Leeb1903842014-05-15 16:11:24 -070046import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070049import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070050import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070051import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070052import android.view.View.OnTouchListener;
Yorke Lee86e21f72014-04-02 16:49:38 -070053import android.view.animation.AccelerateInterpolator;
Andrew Lee2a58ab82014-05-15 02:16:04 -070054import android.view.animation.Animation;
55import android.view.animation.Animation.AnimationListener;
56import android.view.animation.AnimationUtils;
Yorke Lee86e21f72014-04-02 16:49:38 -070057import android.view.animation.DecelerateInterpolator;
58import android.view.animation.Interpolator;
Chiao Cheng94b10b52012-08-17 16:59:12 -070059import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070060import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070061import android.widget.EditText;
Andrew Leea73e1892014-05-13 13:21:16 -070062import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070063import android.widget.PopupMenu;
Yorke Leecc4660d2014-04-24 11:22:57 -070064import android.widget.RelativeLayout;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080065import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070066
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070067import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070068import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070069import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070070import com.android.contacts.common.dialog.ClearFrequentsDialog;
71import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080072import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Andrew Lee4cbc9732014-04-24 14:38:58 -070073import com.android.contacts.common.util.ViewUtil;
Yorke Leec3766332013-07-31 11:13:16 -070074import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070075import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070076import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070077import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070078import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070079import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080080import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070081import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080082import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070083import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070084import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070085import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070086import com.android.dialer.list.RegularSearchFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080087import com.android.dialer.list.RemoveView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070088import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070089import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070090import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070091import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070092import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070093import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070094
Yorke Leec3766332013-07-31 11:13:16 -070095import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080096import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070097
Chiao Cheng94b10b52012-08-17 16:59:12 -070098/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070099 * The dialer tab's title is 'phone', a more common name (see strings.xml).
100 */
Yorke Leec3766332013-07-31 11:13:16 -0700101public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700102 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700103 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800104 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700105 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700106 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700107 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700108 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700109 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700110 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700111 ViewPager.OnPageChangeListener,
112 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700113 private static final String TAG = "DialtactsActivity";
114
Ihab Awad526c0b82014-02-27 12:55:36 -0800115 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700116
Yorke Leef74011e2013-08-02 11:30:30 -0700117 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
118
Chiao Cheng94b10b52012-08-17 16:59:12 -0700119 /** Used to open Call Setting */
120 private static final String PHONE_PACKAGE = "com.android.phone";
121 private static final String CALL_SETTINGS_CLASS_NAME =
122 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700123 /** @see #getCallOrigin() */
124 private static final String CALL_ORIGIN_DIALTACTS =
125 "com.android.dialer.DialtactsActivity";
126
Yorke Leeb207f8a2013-08-29 18:51:06 -0700127 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
128 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700129 private static final String KEY_SEARCH_QUERY = "search_query";
130 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700131 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700132
Yorke Leec3766332013-07-31 11:13:16 -0700133 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
134 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
135 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
136 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700137
Chiao Cheng94b10b52012-08-17 16:59:12 -0700138 /**
139 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
140 */
141 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
142
Yorke Leec3766332013-07-31 11:13:16 -0700143 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700144
Andrew Lee0c667702014-05-12 14:31:45 -0700145 private RelativeLayout parentLayout;
146
Yorke Leec3766332013-07-31 11:13:16 -0700147 /**
Yorke Leec3766332013-07-31 11:13:16 -0700148 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700149 */
Yorke Leef74011e2013-08-02 11:30:30 -0700150 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700151
152 /**
153 * Fragment for searching phone numbers using the alphanumeric keyboard.
154 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700155 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700156
157 /**
158 * Fragment for searching phone numbers using the dialpad.
159 */
160 private SmartDialSearchFragment mSmartDialSearchFragment;
161
Yorke Leee00c9fe2014-04-12 12:42:06 -0700162 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700163 * Animation that slides in.
164 */
165 private Animation mSlideIn;
166
167 /**
168 * Animation that slides out.
169 */
170 private Animation mSlideOut;
171
172 /**
173 * Listener for after slide out animation completes on dialer fragment.
174 */
175 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
176 @Override
177 public void onAnimationEnd(Animation animation) {
178 commitDialpadFragmentHide();
179 }
180 };
181
182 /**
183 * Set to true if the device is in landscape orientation.
184 */
185 private boolean mIsLandscape;
186
187 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700188 * Fragment containing the speed dial list, recents list, and all contacts list.
189 */
190 private ListsFragment mListsFragment;
191
Andrew Leea73e1892014-05-13 13:21:16 -0700192 private View mFloatingActionButtonContainer;
193 private ImageButton mFloatingActionButton;
Yorke Leec3766332013-07-31 11:13:16 -0700194
Yorke Leeb207f8a2013-08-29 18:51:06 -0700195 private boolean mInDialpadSearch;
196 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700197 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700198 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700199 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700200
Yorke Leeef2b7382013-08-09 17:39:25 -0700201 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700202 * The position of the currently selected tab in the attached {@link ListsFragment}.
203 */
204 private int mCurrentTabPosition = 0;
205
206 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700207 * True if the dialpad is only temporarily showing due to being in call
208 */
209 private boolean mInCallDialpadUp;
210
211 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700212 * True when this activity has been launched for the first time.
213 */
Yorke Lee98702de2013-08-06 12:03:32 -0700214 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700215
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700216 /**
217 * Search query to be applied to the SearchView in the ActionBar once
218 * onCreateOptionsMenu has been called.
219 */
220 private String mPendingSearchViewQuery;
221
Yorke Lee53a22302014-04-29 18:13:46 -0700222 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700223 private View mVoiceSearchButton;
Yorke Leeec489fb2014-05-19 15:39:27 -0700224 private SearchEditTextLayout mSearchEditTextLayout;
Andrew Leee74a10e2014-05-16 14:31:40 -0700225
Yorke Lee86e21f72014-04-02 16:49:38 -0700226 /**
227 * View that contains the "Remove" dialog that shows up when the user long presses a contact.
228 * If the user releases a contact when hovering on top of this, the contact is unfavorited and
229 * removed from the speed dial list.
230 */
Yorke Lee28266192014-05-01 10:05:52 -0700231 private View mRemoveViewContainer;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700232
Yorke Leeef2b7382013-08-09 17:39:25 -0700233 private String mSearchQuery;
234
Yorke Leefce269a2013-08-12 11:56:04 -0700235 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700236 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700237 private ActionBarController mActionBarController;
Yorke Leefce269a2013-08-12 11:56:04 -0700238
Andrew Lee2423a2f2014-05-29 14:14:45 -0700239 private int mActionBarHeight;
240 private int mFloatingActionButtonMarginBottom;
241 private int mFloatingActionButtonDialpadMarginBottom;
242
Andrew Leee74a10e2014-05-16 14:31:40 -0700243 private class OptionsPopupMenu extends PopupMenu {
244 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700245 super(context, anchor);
246 }
247
248 @Override
249 public void show() {
250 final Menu menu = getMenu();
251 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700252 clearFrequents.setVisible(mListsFragment != null &&
253 mListsFragment.getSpeedDialFragment() != null &&
254 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700255 super.show();
256 }
257 }
258
Chiao Cheng94b10b52012-08-17 16:59:12 -0700259 /**
Yorke Lee28266192014-05-01 10:05:52 -0700260 * Listener that listens to drag events and sends their x and y coordinates to a
261 * {@link DragDropController}.
262 */
263 private class LayoutOnDragListener implements OnDragListener {
264 @Override
265 public boolean onDrag(View v, DragEvent event) {
266 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
267 mDragDropController.handleDragHovered(v, (int) event.getX(),
268 (int) event.getY());
269 }
270 return true;
271 }
272 }
273
274 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700275 * Listener used to send search queries to the phone search fragment.
276 */
Yorke Lee53a22302014-04-29 18:13:46 -0700277 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700278 @Override
279 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
280 }
Yorke Leec3766332013-07-31 11:13:16 -0700281
Andrew Lee99a570c2014-05-15 14:18:50 -0700282 @Override
283 public void onTextChanged(CharSequence s, int start, int before, int count) {
284 final String newText = s.toString();
285 if (newText.equals(mSearchQuery)) {
286 // If the query hasn't changed (perhaps due to activity being destroyed
287 // and restored, or user launching the same DIAL intent twice), then there is
288 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700289 return;
290 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700291 if (DEBUG) {
292 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700293 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700294 }
Yorke Lee710709d2014-05-29 07:18:42 -0700295 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700296
Andrew Lee90374a72014-05-16 15:01:09 -0700297 // Show search fragment only when the query string is changed to non-empty text.
298 if (!TextUtils.isEmpty(newText)) {
299 // Call enterSearchUi only if we are switching search modes, or showing a search
300 // fragment for the first time.
301 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
302 (!mIsDialpadShown && mInRegularSearch);
303 if (!sameSearchMode) {
304 enterSearchUi(mIsDialpadShown, mSearchQuery);
305 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700306 }
307
308 if (mIsDialpadShown && mSmartDialSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700309 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700310 } else if (mRegularSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700311 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700312 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700313 }
314
315 @Override
316 public void afterTextChanged(Editable s) {
317 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700318 };
319
Andrew Leeb1903842014-05-15 16:11:24 -0700320
321 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700322 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700323 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700324 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700325 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700326 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700327 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700328 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700329 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
330 }
Andrew Leeb1903842014-05-15 16:11:24 -0700331 }
332 };
333
334 /**
335 * If the search term is empty and the user closes the soft keyboard, close the search UI.
336 */
337 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
338 @Override
339 public boolean onKey(View v, int keyCode, KeyEvent event) {
340 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
341 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700342 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700343 }
344 return false;
345 }
346 };
347
Chiao Cheng94b10b52012-08-17 16:59:12 -0700348 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700349 protected void onCreate(Bundle savedInstanceState) {
350 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700351 mFirstLaunch = true;
352
Andrew Lee2423a2f2014-05-29 14:14:45 -0700353 final Resources resources = getResources();
354 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapati1e613802014-06-02 09:41:03 -0700355 mFloatingActionButtonMarginBottom = resources.getDimensionPixelOffset(
356 R.dimen.floating_action_button_margin_bottom);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700357 mFloatingActionButtonDialpadMarginBottom = resources.getDimensionPixelOffset(
358 R.dimen.floating_action_button_dialpad_margin_bottom);
359
Yorke Lee8898cd02013-08-08 10:24:27 -0700360 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800361 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700362
Yorke Lee53a22302014-04-29 18:13:46 -0700363 final ActionBar actionBar = getActionBar();
364 actionBar.setCustomView(R.layout.search_edittext);
365 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700366 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700367
Yorke Lee5253be02014-05-21 18:50:03 -0700368 mActionBarController = new ActionBarController(this,
369 (SearchEditTextLayout) actionBar.getCustomView());
370
Yorke Leeec489fb2014-05-19 15:39:27 -0700371 mSearchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView();
372 mSearchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
Yorke Lee53a22302014-04-29 18:13:46 -0700373
Yorke Leeec489fb2014-05-19 15:39:27 -0700374 mSearchView = (EditText) mSearchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700375 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Yorke Lee11ca39e2014-05-19 20:31:37 -0700376 mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button);
377 mSearchEditTextLayout.findViewById(R.id.search_box_start_search).setOnClickListener(
378 mSearchViewOnClickListener);
379 mSearchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
380 @Override
381 public void onBackButtonClicked() {
382 onBackPressed();
383 }
384 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700385
Yorke Leeec489fb2014-05-19 15:39:27 -0700386 ImageButton optionsMenuButton = (ImageButton) mSearchEditTextLayout.findViewById(
387 R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700388 optionsMenuButton.setOnClickListener(this);
389 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
390 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
391
Yorke Leeef2b7382013-08-09 17:39:25 -0700392 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
393 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700394 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800395 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700396 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800397 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
398 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700399 } else {
400 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700401 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
402 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700403 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700404 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700405 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700406 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700407 mIsLandscape = getResources().getConfiguration().orientation ==
408 Configuration.ORIENTATION_LANDSCAPE;
409
410 mSlideIn = AnimationUtils.loadAnimation(this,
411 mIsLandscape ? R.anim.slide_in_right : R.anim.slide_in);
412 mSlideOut = AnimationUtils.loadAnimation(this,
413 mIsLandscape ? R.anim.slide_out_right : R.anim.slide_out);
414
415 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700416
Andrew Lee0c667702014-05-12 14:31:45 -0700417 parentLayout = (RelativeLayout) findViewById(R.id.dialtacts_mainlayout);
418 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
419 parentLayout.setOnDragListener(new LayoutOnDragListener());
420
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700421 setupActivityOverlay();
422
Andrew Leea73e1892014-05-13 13:21:16 -0700423 mFloatingActionButtonContainer = findViewById(R.id.floating_action_button_container);
424 ViewUtil.setupFloatingActionButton(mFloatingActionButtonContainer, getResources());
Yorke Lee86e21f72014-04-02 16:49:38 -0700425
Andrew Leea73e1892014-05-13 13:21:16 -0700426 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
427 mFloatingActionButton.setOnClickListener(this);
Ihab Awad526c0b82014-02-27 12:55:36 -0800428
Yorke Lee28266192014-05-01 10:05:52 -0700429 mRemoveViewContainer = findViewById(R.id.remove_view_container);
Yorke Leeb0d19762014-03-05 14:43:28 -0800430
Yorke Lee0baa98b2013-08-22 10:55:16 -0700431 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700432 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700433 }
434
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700435 private void setupActivityOverlay() {
436 final View activityOverlay = findViewById(R.id.activity_overlay);
437 activityOverlay.setOnTouchListener(new OnTouchListener() {
438 @Override
439 public boolean onTouch(View v, MotionEvent event) {
440 if (!mIsDialpadShown) {
441 maybeExitSearchUi();
442 }
443 return false;
444 }
445 });
446 }
447
Chiao Cheng94b10b52012-08-17 16:59:12 -0700448 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700449 protected void onResume() {
450 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700451 if (mFirstLaunch) {
452 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700453 } else if (!phoneIsInUse() && mInCallDialpadUp) {
454 hideDialpadFragment(false, true);
455 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700456 } else if (mShowDialpadOnResume) {
457 showDialpadFragment(false);
458 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700459 }
460 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700461 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700462 mDialerDatabaseHelper.startSmartDialUpdateThread();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700463 }
464
465 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700466 protected void onPause() {
467 if (mClearSearchOnPause) {
468 hideDialpadAndSearchUi();
469 mClearSearchOnPause = false;
470 }
471 super.onPause();
472 }
473
474 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700475 protected void onSaveInstanceState(Bundle outState) {
476 super.onSaveInstanceState(outState);
477 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700478 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
479 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700480 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700481 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700482 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700483 }
484
485 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700486 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700487 if (fragment instanceof DialpadFragment) {
488 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700489 if (!mShowDialpadOnResume) {
490 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
491 transaction.hide(mDialpadFragment);
492 transaction.commit();
493 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700494 } else if (fragment instanceof SmartDialSearchFragment) {
495 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700496 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700497 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700498 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700499 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700500 } else if (fragment instanceof ListsFragment) {
501 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700502 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700503 }
Yorke Leec3766332013-07-31 11:13:16 -0700504 }
505
Alon Albertb453e5b2013-09-10 15:54:23 -0700506 protected void handleMenuSettings() {
507 openTelephonySetting(this);
508 }
509
510 public static void openTelephonySetting(Activity activity) {
511 final Intent settingsIntent = getCallSettingsIntent();
512 activity.startActivity(settingsIntent);
513 }
514
Chiao Cheng94b10b52012-08-17 16:59:12 -0700515 @Override
516 public void onClick(View view) {
517 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700518 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700519 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700520 mInCallDialpadUp = false;
521 showDialpadFragment(true);
522 } else {
523 // Dial button was pressed; tell the Dialpad fragment
524 mDialpadFragment.dialButtonPressed();
525 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700526 break;
Yorke Leec3766332013-07-31 11:13:16 -0700527 case R.id.search_close_button:
528 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700529 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700530 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700531 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700532 }
533 break;
Yorke Leec3766332013-07-31 11:13:16 -0700534 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800535 try {
536 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
537 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
538 } catch (ActivityNotFoundException e) {
539 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
540 Toast.LENGTH_SHORT).show();
541 }
Yorke Leec3766332013-07-31 11:13:16 -0700542 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700543 case R.id.dialtacts_options_menu_button:
544 buildOptionsMenu(view).show();
545 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700546 default: {
547 Log.wtf(TAG, "Unexpected onClick event from " + view);
548 break;
549 }
550 }
551 }
552
Yorke Leec3766332013-07-31 11:13:16 -0700553 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700554 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700555 switch (item.getItemId()) {
556 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700557 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700558 break;
559 case R.id.menu_add_contact:
560 try {
561 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
562 } catch (ActivityNotFoundException e) {
563 Toast toast = Toast.makeText(this,
564 R.string.add_contact_not_available,
565 Toast.LENGTH_SHORT);
566 toast.show();
567 }
568 break;
569 case R.id.menu_import_export:
570 // We hard-code the "contactsAreAvailable" argument because doing it properly would
571 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
572 // now in Dialtacts for (potential) performance reasons. Compare with how it is
573 // done in {@link PeopleActivity}.
574 ImportExportDialogFragment.show(getFragmentManager(), true,
575 DialtactsActivity.class);
576 return true;
577 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700578 ClearFrequentsDialog.show(getFragmentManager());
579 return true;
580 case R.id.menu_call_settings:
581 handleMenuSettings();
582 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700583 }
584 return false;
585 }
586
587 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700588 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
589 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
590 if (resultCode == RESULT_OK) {
591 final ArrayList<String> matches = data.getStringArrayListExtra(
592 RecognizerIntent.EXTRA_RESULTS);
593 if (matches.size() > 0) {
594 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700595 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700596 } else {
597 Log.e(TAG, "Voice search - nothing heard");
598 }
599 } else {
600 Log.e(TAG, "Voice search failed");
601 }
602 }
603 super.onActivityResult(requestCode, resultCode, data);
604 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700605
Andrew Lee2a58ab82014-05-15 02:16:04 -0700606 /**
607 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
608 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
609 * @see #onDialpadShown
610 */
Yorke Leec3766332013-07-31 11:13:16 -0700611 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700612 if (mIsDialpadShown) {
613 return;
614 }
615 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700616 mDialpadFragment.setAnimate(animate);
617
Chiao Cheng94b10b52012-08-17 16:59:12 -0700618 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700619 ft.show(mDialpadFragment);
620 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700621
Yorke Lee5253be02014-05-21 18:50:03 -0700622 mActionBarController.onDialpadUp();
623
Andrew Leeb1903842014-05-15 16:11:24 -0700624 if (!isInSearchUi()) {
625 enterSearchUi(true /* isSmartDial */, mSearchQuery);
626 }
Yorke Leec3766332013-07-31 11:13:16 -0700627 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700628
Andrew Lee2a58ab82014-05-15 02:16:04 -0700629 /**
630 * Callback from child DialpadFragment when the dialpad is shown.
631 */
632 public void onDialpadShown() {
633 updateFloatingActionButton();
634 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700635 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700636 } else {
637 mDialpadFragment.setYFraction(0);
638 }
639
Andrew Lee2a58ab82014-05-15 02:16:04 -0700640 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700641 }
642
643 /**
644 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
645 * a callback after the hide animation ends.
646 * @see #commitDialpadFragmentHide
647 */
Yorke Leeca195042013-09-25 16:29:38 -0700648 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700649 if (mDialpadFragment == null) {
650 return;
651 }
Yorke Leef6673d32013-08-23 15:34:17 -0700652 if (clearDialpad) {
653 mDialpadFragment.clearDialpad();
654 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700655 if (!mIsDialpadShown) {
656 return;
Yorke Leec3766332013-07-31 11:13:16 -0700657 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700658 mIsDialpadShown = false;
659 mDialpadFragment.setAnimate(animate);
660
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700661 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700662 updateFloatingActionButton();
663 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700664 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700665 } else {
666 commitDialpadFragmentHide();
667 }
668
Yorke Lee5253be02014-05-21 18:50:03 -0700669 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700670
Andrew Leed4cde832014-05-16 15:56:48 -0700671 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700672 if (TextUtils.isEmpty(mSearchQuery)) {
673 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700674 }
Andrew Leed4cde832014-05-16 15:56:48 -0700675 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700676 }
677
678 /**
679 * Finishes hiding the dialpad fragment after any animations are completed.
680 */
681 private void commitDialpadFragmentHide() {
682 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700683 ft.hide(mDialpadFragment);
684 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700685 }
686
Andrew Lee2a58ab82014-05-15 02:16:04 -0700687 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700688 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700689 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700690 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700691 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700692 fragment = mRegularSearchFragment;
693 }
694 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700695 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700696 }
697 }
698
Yorke Lee5253be02014-05-21 18:50:03 -0700699 @Override
700 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700701 return mInDialpadSearch || mInRegularSearch;
702 }
703
Yorke Lee5253be02014-05-21 18:50:03 -0700704 @Override
705 public boolean hasSearchQuery() {
706 return !TextUtils.isEmpty(mSearchQuery);
707 }
708
709 @Override
710 public boolean shouldShowActionBar() {
711 return mListsFragment.shouldShowActionBar();
712 }
713
Yorke Leeb207f8a2013-08-29 18:51:06 -0700714 private void setNotInSearchUi() {
715 mInDialpadSearch = false;
716 mInRegularSearch = false;
717 }
718
Yorke Lee311969c2013-08-26 06:31:11 -0700719 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700720 if (mIsDialpadShown) {
721 hideDialpadFragment(false, true);
722 } else {
723 exitSearchUi();
724 }
Yorke Lee311969c2013-08-26 06:31:11 -0700725 }
726
Yorke Leee00c9fe2014-04-12 12:42:06 -0700727 private void hideInputMethod(View view) {
728 final InputMethodManager imm = (InputMethodManager) getSystemService(
729 Context.INPUT_METHOD_SERVICE);
730 if (imm != null && view != null) {
731 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
732 }
733 }
734
Yorke Lee53a22302014-04-29 18:13:46 -0700735 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700736 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
737 if (canIntentBeHandled(voiceIntent)) {
738 mVoiceSearchButton.setVisibility(View.VISIBLE);
739 mVoiceSearchButton.setOnClickListener(this);
740 } else {
741 mVoiceSearchButton.setVisibility(View.GONE);
742 }
743 }
744
Andrew Leee74a10e2014-05-16 14:31:40 -0700745 private OptionsPopupMenu buildOptionsMenu(View invoker) {
746 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
747 popupMenu.inflate(R.menu.dialtacts_options);
748 popupMenu.setOnMenuItemClickListener(this);
749 return popupMenu;
750 }
751
Yorke Lee86e21f72014-04-02 16:49:38 -0700752 @Override
753 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700754 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700755 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700756 mPendingSearchViewQuery = null;
757 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700758 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700759 }
760
Chiao Cheng94b10b52012-08-17 16:59:12 -0700761 /**
762 * Returns true if the intent is due to hitting the green send key (hardware call button:
763 * KEYCODE_CALL) while in a call.
764 *
765 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700766 * @return true if the intent is due to hitting the green send key while in a call
767 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700768 private boolean isSendKeyWhileInCall(Intent intent) {
769 // If there is a call in progress and the user launched the dialer by hitting the call
770 // button, go straight to the in-call screen.
771 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700772
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700773 if (callKey) {
774 getTelephonyManager().showCallScreen();
775 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700776 }
777
778 return false;
779 }
780
781 /**
782 * Sets the current tab based on the intent's request type
783 *
784 * @param intent Intent that contains information about which tab should be selected
785 */
Yorke Leec3766332013-07-31 11:13:16 -0700786 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700787 // 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 -0700788 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700789 finish();
790 return;
791 }
792
Yorke Lee669b6082013-09-17 15:43:38 -0700793 if (mDialpadFragment != null) {
794 final boolean phoneIsInUse = phoneIsInUse();
795 if (phoneIsInUse || isDialIntent(intent)) {
796 mDialpadFragment.setStartedFromNewIntent(true);
797 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
798 mInCallDialpadUp = true;
799 }
800 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700801 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700802 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700803 }
804
805 @Override
806 public void onNewIntent(Intent newIntent) {
807 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700808 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700809
Chiao Cheng94b10b52012-08-17 16:59:12 -0700810 invalidateOptionsMenu();
811 }
812
813 /** Returns true if the given intent contains a phone number to populate the dialer with */
814 private boolean isDialIntent(Intent intent) {
815 final String action = intent.getAction();
816 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
817 return true;
818 }
819 if (Intent.ACTION_VIEW.equals(action)) {
820 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700821 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700822 return true;
823 }
824 }
825 return false;
826 }
827
828 /**
829 * Returns an appropriate call origin for this Activity. May return null when no call origin
830 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
831 * for remembering the tab in which the user made a phone call, so the external app's DIAL
832 * request should not be counted.)
833 */
834 public String getCallOrigin() {
835 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
836 }
837
Chiao Cheng94b10b52012-08-17 16:59:12 -0700838 /**
Yorke Leec3766332013-07-31 11:13:16 -0700839 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700840 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700841 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700842 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700843 // Weird race condition where fragment is doing work after the activity is destroyed
844 // due to talkback being on (b/10209937). Just return since we can't do any
845 // constructive here.
846 return;
847 }
848
Yorke Leeef2b7382013-08-09 17:39:25 -0700849 if (DEBUG) {
850 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
851 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700852
Yorke Leec3766332013-07-31 11:13:16 -0700853 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700854 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700855 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700856 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700857 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700858 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700859
Yorke Leeb207f8a2013-08-29 18:51:06 -0700860 final String tag;
861 if (smartDialSearch) {
862 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
863 } else {
864 tag = TAG_REGULAR_SEARCH_FRAGMENT;
865 }
866 mInDialpadSearch = smartDialSearch;
867 mInRegularSearch = !smartDialSearch;
868
Andrew Lee752956e2014-05-15 11:43:38 -0700869 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700870 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700871 if (fragment == null) {
872 if (smartDialSearch) {
873 fragment = new SmartDialSearchFragment();
874 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700875 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700876 }
Andrew Leeb1903842014-05-15 16:11:24 -0700877 transaction.add(R.id.dialtacts_frame, fragment, tag);
878 } else {
879 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700880 }
Andrew Leeb1903842014-05-15 16:11:24 -0700881
Yorke Lee86e21f72014-04-02 16:49:38 -0700882 // DialtactsActivity will provide the options menu
883 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700884 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700885 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700886 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700887
888 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700889 }
890
891 /**
Yorke Leec3766332013-07-31 11:13:16 -0700892 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700893 */
Yorke Leec3766332013-07-31 11:13:16 -0700894 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700895 // See related bug in enterSearchUI();
896 if (getFragmentManager().isDestroyed()) {
897 return;
898 }
Andrew Leeb1903842014-05-15 16:11:24 -0700899
Andrew Leeb1903842014-05-15 16:11:24 -0700900 mSearchView.setText(null);
901 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700902 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700903
Andrew Leeb1903842014-05-15 16:11:24 -0700904 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700905 if (mSmartDialSearchFragment != null) {
906 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700907 }
Andrew Leeb1903842014-05-15 16:11:24 -0700908 if (mRegularSearchFragment != null) {
909 transaction.remove(mRegularSearchFragment);
910 }
911 transaction.commit();
912
913 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700914 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700915 }
916
917 /** Returns an Intent to launch Call Settings screen */
918 public static Intent getCallSettingsIntent() {
919 final Intent intent = new Intent(Intent.ACTION_MAIN);
920 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
921 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
922 return intent;
923 }
924
925 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700926 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700927 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700928 if (TextUtils.isEmpty(mSearchQuery)) {
929 exitSearchUi();
930 }
Yorke Leef6673d32013-08-23 15:34:17 -0700931 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700932 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700933 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700934 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700935 } else {
936 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700937 }
Yorke Leec3766332013-07-31 11:13:16 -0700938 }
939
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700940 /**
941 * @return True if the search UI was exited, false otherwise
942 */
943 private boolean maybeExitSearchUi() {
944 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
945 exitSearchUi();
946 hideInputMethod(parentLayout);
947 return true;
948 }
949 return false;
950 }
951
Yorke Leec3766332013-07-31 11:13:16 -0700952 @Override
953 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700954 if (mSmartDialSearchFragment != null) {
955 mSmartDialSearchFragment.setAddToContactNumber(query);
956 }
Yorke Leec3766332013-07-31 11:13:16 -0700957 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
958 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700959
960 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700961 if (DEBUG) {
962 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
963 }
964 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
965 // This callback can happen if the dialpad fragment is recreated because of
966 // activity destruction. In that case, don't update the search view because
967 // that would bring the user back to the search fragment regardless of the
968 // previous state of the application. Instead, just return here and let the
969 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700970 if (!TextUtils.isEmpty(normalizedQuery)) {
971 mPendingSearchViewQuery = normalizedQuery;
972 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700973 return;
974 }
Yorke Lee53a22302014-04-29 18:13:46 -0700975 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700976 }
977 }
Yorke Leec3766332013-07-31 11:13:16 -0700978
979 @Override
980 public void onListFragmentScrollStateChange(int scrollState) {
981 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700982 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700983 hideInputMethod(getCurrentFocus());
984 }
985 }
986
987 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700988 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700989 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700990 // TODO: No-op for now. This should eventually show/hide the actionBar based on
991 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -0700992 }
993
Yorke Lee86e21f72014-04-02 16:49:38 -0700994 @Override
Andrew Leea73e1892014-05-13 13:21:16 -0700995 public void setFloatingActionButtonVisible(boolean visible) {
996 mFloatingActionButtonContainer.setVisibility(visible ? View.VISIBLE : View.GONE);
Yorke Leec3766332013-07-31 11:13:16 -0700997 }
998
999 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001000 // TODO(santoscordon): Replace with a TelecommService method call.
1001 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001002 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001003
Yorke Leee1424812013-09-04 18:24:48 -07001004 public static Intent getAddNumberToContactIntent(CharSequence text) {
1005 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1006 intent.putExtra(Intents.Insert.PHONE, text);
1007 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1008 return intent;
1009 }
1010
Yorke Leeda0f9042013-12-05 14:25:51 -08001011 private boolean canIntentBeHandled(Intent intent) {
1012 final PackageManager packageManager = getPackageManager();
1013 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1014 PackageManager.MATCH_DEFAULT_ONLY);
1015 return resolveInfo != null && resolveInfo.size() > 0;
1016 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001017
Yorke Lee6a1461a2014-04-21 16:27:14 -07001018 @Override
1019 public void showCallHistory() {
1020 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1021 // CONTENT_TYPE, so that we always open our call log from our dialer
1022 final Intent intent = new Intent(this, CallLogActivity.class);
1023 startActivity(intent);
1024 }
1025
Yorke Lee86e21f72014-04-02 16:49:38 -07001026 /**
1027 * Called when the user has long-pressed a contact tile to start a drag operation.
1028 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001029 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001030 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001031 if (mListsFragment.isPaneOpen()) {
1032 mActionBarController.slideActionBarUp(true);
1033 }
Yorke Lee28266192014-05-01 10:05:52 -07001034 mRemoveViewContainer.setVisibility(View.VISIBLE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001035 }
1036
1037 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001038 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1039 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001040
Yorke Lee86e21f72014-04-02 16:49:38 -07001041 /**
1042 * Called when the user has released a contact tile after long-pressing it.
1043 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001044 @Override
1045 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001046 if (mListsFragment.isPaneOpen()) {
1047 mActionBarController.slideActionBarDown(true);
1048 }
Yorke Lee28266192014-05-01 10:05:52 -07001049 mRemoveViewContainer.setVisibility(View.GONE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001050 }
1051
1052 @Override
1053 public void onDroppedOnRemove() {}
1054
1055 /**
Yorke Leed999b712014-04-23 15:10:58 -07001056 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001057 * once it has been attached to the activity.
1058 */
1059 @Override
1060 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001061 mDragDropController = dragController;
1062 ((RemoveView) findViewById(R.id.remove_view))
1063 .setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001064 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001065
1066 @Override
1067 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001068 // Specify call-origin so that users will see the previous tab instead of
1069 // CallLog screen (search UI will be automatically exited).
1070 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001071 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001072 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001073 }
1074
1075 @Override
1076 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001077 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1078 startActivity(intent);
1079 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001080 }
1081
1082 @Override
1083 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001084 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001085 }
1086
1087 @Override
1088 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001089 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001090 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001091
Yorke Leecc4660d2014-04-24 11:22:57 -07001092 @Override
1093 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
1094
1095 }
1096
1097 @Override
1098 public void onPageSelected(int position) {
1099 mCurrentTabPosition = position;
Yorke Leec61d4542014-05-01 10:43:24 -07001100 // If the dialpad is showing, the floating action button should always be middle aligned.
Andrew Lee2a58ab82014-05-15 02:16:04 -07001101 if (!mIsDialpadShown) {
Yorke Leec61d4542014-05-01 10:43:24 -07001102 alignFloatingActionButtonByTab(mCurrentTabPosition);
1103 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001104 }
1105
1106 @Override
1107 public void onPageScrollStateChanged(int state) {
1108 }
1109
Andrew Lee2a58ab82014-05-15 02:16:04 -07001110 private void updateFloatingActionButton() {
1111 if (mIsDialpadShown) {
1112 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
1113 mFloatingActionButton.setContentDescription(
1114 getResources().getString(R.string.description_dial_button));
Andrew Leec4643f72014-05-15 11:27:39 -07001115 alignFloatingActionButtonMiddle();
Andrew Lee2a58ab82014-05-15 02:16:04 -07001116 } else {
1117 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
1118 mFloatingActionButton.setContentDescription(
1119 getResources().getString(R.string.action_menu_dialpad_button));
Andrew Leec4643f72014-05-15 11:27:39 -07001120 alignFloatingActionButtonByTab(mCurrentTabPosition);
Andrew Lee2a58ab82014-05-15 02:16:04 -07001121 }
1122 }
1123
Yorke Leecc4660d2014-04-24 11:22:57 -07001124 private void alignFloatingActionButtonByTab(int position) {
1125 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL) {
1126 alignFloatingActionButtonMiddle();
1127 } else {
1128 alignFloatingActionButtonRight();
1129 }
1130 }
1131
1132 private void alignFloatingActionButtonRight() {
1133 final RelativeLayout.LayoutParams params =
Andrew Leea73e1892014-05-13 13:21:16 -07001134 (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams();
Yorke Leecc4660d2014-04-24 11:22:57 -07001135 params.removeRule(RelativeLayout.CENTER_HORIZONTAL);
1136 params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Andrew Lee2423a2f2014-05-29 14:14:45 -07001137 updateFloatingActionButtonMargin(params);
Andrew Leea73e1892014-05-13 13:21:16 -07001138 mFloatingActionButtonContainer.setLayoutParams(params);
Yorke Leecc4660d2014-04-24 11:22:57 -07001139 }
1140
1141 private void alignFloatingActionButtonMiddle() {
1142 final RelativeLayout.LayoutParams params =
Andrew Leea73e1892014-05-13 13:21:16 -07001143 (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams();
Yorke Leecc4660d2014-04-24 11:22:57 -07001144 params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
1145 params.addRule(RelativeLayout.CENTER_HORIZONTAL);
Andrew Lee2423a2f2014-05-29 14:14:45 -07001146 updateFloatingActionButtonMargin(params);
Andrew Leea73e1892014-05-13 13:21:16 -07001147 mFloatingActionButtonContainer.setLayoutParams(params);
Yorke Leecc4660d2014-04-24 11:22:57 -07001148 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001149
Andrew Lee2423a2f2014-05-29 14:14:45 -07001150 private void updateFloatingActionButtonMargin(RelativeLayout.LayoutParams params) {
1151 params.setMarginsRelative(
1152 params.getMarginStart(),
1153 params.topMargin,
1154 params.getMarginEnd(),
1155 mIsDialpadShown ?
1156 mFloatingActionButtonDialpadMarginBottom :
1157 mFloatingActionButtonMarginBottom);
1158 }
1159
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001160 private TelephonyManager getTelephonyManager() {
1161 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1162 }
1163
Yorke Lee5253be02014-05-21 18:50:03 -07001164 @Override
1165 public boolean isActionBarShowing() {
1166 return mActionBarController.isActionBarShowing();
1167 }
1168
Andrew Lee9da8fb42014-06-03 14:03:09 -07001169 public boolean isDialpadShown() {
1170 return mIsDialpadShown;
1171 }
1172
Yorke Lee5253be02014-05-21 18:50:03 -07001173 @Override
1174 public int getActionBarHideOffset() {
1175 return getActionBar().getHideOffset();
1176 }
1177
1178 @Override
1179 public int getActionBarHeight() {
1180 return mActionBarHeight;
1181 }
1182
1183 @Override
1184 public void setActionBarHideOffset(int hideOffset) {
1185 getActionBar().setHideOffset(hideOffset);
1186 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001187}