blob: f2f49c1ae27d38ad8d844cdda42f6ec00f5b370b [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
Yorke Lee86e21f72014-04-02 16:49:38 -0700145 private static final int ANIMATION_DURATION = 250;
Yorke Lee3cefcc62014-01-16 11:26:46 -0800146
Andrew Lee0c667702014-05-12 14:31:45 -0700147 private RelativeLayout parentLayout;
148
Yorke Leec3766332013-07-31 11:13:16 -0700149 /**
Yorke Leec3766332013-07-31 11:13:16 -0700150 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700151 */
Yorke Leef74011e2013-08-02 11:30:30 -0700152 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700153
154 /**
155 * Fragment for searching phone numbers using the alphanumeric keyboard.
156 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700157 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700158
159 /**
160 * Fragment for searching phone numbers using the dialpad.
161 */
162 private SmartDialSearchFragment mSmartDialSearchFragment;
163
Yorke Leee00c9fe2014-04-12 12:42:06 -0700164 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700165 * Animation that slides in.
166 */
167 private Animation mSlideIn;
168
169 /**
170 * Animation that slides out.
171 */
172 private Animation mSlideOut;
173
174 /**
175 * Listener for after slide out animation completes on dialer fragment.
176 */
177 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
178 @Override
179 public void onAnimationEnd(Animation animation) {
180 commitDialpadFragmentHide();
181 }
182 };
183
184 /**
185 * Set to true if the device is in landscape orientation.
186 */
187 private boolean mIsLandscape;
188
189 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700190 * Fragment containing the speed dial list, recents list, and all contacts list.
191 */
192 private ListsFragment mListsFragment;
193
Andrew Leea73e1892014-05-13 13:21:16 -0700194 private View mFloatingActionButtonContainer;
195 private ImageButton mFloatingActionButton;
Yorke Leec3766332013-07-31 11:13:16 -0700196
Yorke Leeb207f8a2013-08-29 18:51:06 -0700197 private boolean mInDialpadSearch;
198 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700199 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700200 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700201 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700202
Yorke Leeef2b7382013-08-09 17:39:25 -0700203 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700204 * The position of the currently selected tab in the attached {@link ListsFragment}.
205 */
206 private int mCurrentTabPosition = 0;
207
208 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700209 * True if the dialpad is only temporarily showing due to being in call
210 */
211 private boolean mInCallDialpadUp;
212
213 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700214 * True when this activity has been launched for the first time.
215 */
Yorke Lee98702de2013-08-06 12:03:32 -0700216 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700217
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700218 /**
219 * Search query to be applied to the SearchView in the ActionBar once
220 * onCreateOptionsMenu has been called.
221 */
222 private String mPendingSearchViewQuery;
223
Yorke Lee53a22302014-04-29 18:13:46 -0700224 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700225 private View mVoiceSearchButton;
Yorke Leeec489fb2014-05-19 15:39:27 -0700226 private SearchEditTextLayout mSearchEditTextLayout;
Andrew Leee74a10e2014-05-16 14:31:40 -0700227
Yorke Lee86e21f72014-04-02 16:49:38 -0700228 /**
229 * View that contains the "Remove" dialog that shows up when the user long presses a contact.
230 * If the user releases a contact when hovering on top of this, the contact is unfavorited and
231 * removed from the speed dial list.
232 */
Yorke Lee28266192014-05-01 10:05:52 -0700233 private View mRemoveViewContainer;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700234
Yorke Lee86e21f72014-04-02 16:49:38 -0700235 final Interpolator hideActionBarInterpolator = new AccelerateInterpolator(1.5f);
236 final Interpolator showActionBarInterpolator = new DecelerateInterpolator(1.5f);
Yorke Leeef2b7382013-08-09 17:39:25 -0700237 private String mSearchQuery;
238
Yorke Leefce269a2013-08-12 11:56:04 -0700239 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700240 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700241 private ActionBarController mActionBarController;
Yorke Leefce269a2013-08-12 11:56:04 -0700242
Andrew Lee2423a2f2014-05-29 14:14:45 -0700243 private int mActionBarHeight;
244 private int mFloatingActionButtonMarginBottom;
245 private int mFloatingActionButtonDialpadMarginBottom;
246
Andrew Leee74a10e2014-05-16 14:31:40 -0700247 private class OptionsPopupMenu extends PopupMenu {
248 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700249 super(context, anchor);
250 }
251
252 @Override
253 public void show() {
254 final Menu menu = getMenu();
255 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700256 clearFrequents.setVisible(mListsFragment != null &&
257 mListsFragment.getSpeedDialFragment() != null &&
258 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700259 super.show();
260 }
261 }
262
Chiao Cheng94b10b52012-08-17 16:59:12 -0700263 /**
Yorke Lee28266192014-05-01 10:05:52 -0700264 * Listener that listens to drag events and sends their x and y coordinates to a
265 * {@link DragDropController}.
266 */
267 private class LayoutOnDragListener implements OnDragListener {
268 @Override
269 public boolean onDrag(View v, DragEvent event) {
270 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
271 mDragDropController.handleDragHovered(v, (int) event.getX(),
272 (int) event.getY());
273 }
274 return true;
275 }
276 }
277
278 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700279 * Listener used to send search queries to the phone search fragment.
280 */
Yorke Lee53a22302014-04-29 18:13:46 -0700281 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700282 @Override
283 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
284 }
Yorke Leec3766332013-07-31 11:13:16 -0700285
Andrew Lee99a570c2014-05-15 14:18:50 -0700286 @Override
287 public void onTextChanged(CharSequence s, int start, int before, int count) {
288 final String newText = s.toString();
289 if (newText.equals(mSearchQuery)) {
290 // If the query hasn't changed (perhaps due to activity being destroyed
291 // and restored, or user launching the same DIAL intent twice), then there is
292 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700293 return;
294 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700295 if (DEBUG) {
296 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700297 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700298 }
Yorke Lee710709d2014-05-29 07:18:42 -0700299 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700300
Andrew Lee90374a72014-05-16 15:01:09 -0700301 // Show search fragment only when the query string is changed to non-empty text.
302 if (!TextUtils.isEmpty(newText)) {
303 // Call enterSearchUi only if we are switching search modes, or showing a search
304 // fragment for the first time.
305 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
306 (!mIsDialpadShown && mInRegularSearch);
307 if (!sameSearchMode) {
308 enterSearchUi(mIsDialpadShown, mSearchQuery);
309 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700310 }
311
312 if (mIsDialpadShown && mSmartDialSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700313 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700314 } else if (mRegularSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700315 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700316 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700317 }
318
319 @Override
320 public void afterTextChanged(Editable s) {
321 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700322 };
323
Andrew Leeb1903842014-05-15 16:11:24 -0700324
325 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700326 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700327 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700328 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700329 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700330 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700331 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700332 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700333 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
334 }
Andrew Leeb1903842014-05-15 16:11:24 -0700335 }
336 };
337
338 /**
339 * If the search term is empty and the user closes the soft keyboard, close the search UI.
340 */
341 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
342 @Override
343 public boolean onKey(View v, int keyCode, KeyEvent event) {
344 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
345 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700346 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700347 }
348 return false;
349 }
350 };
351
Chiao Cheng94b10b52012-08-17 16:59:12 -0700352 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700353 protected void onCreate(Bundle savedInstanceState) {
354 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700355 mFirstLaunch = true;
356
Andrew Lee2423a2f2014-05-29 14:14:45 -0700357 final Resources resources = getResources();
358 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapati1e613802014-06-02 09:41:03 -0700359 mFloatingActionButtonMarginBottom = resources.getDimensionPixelOffset(
360 R.dimen.floating_action_button_margin_bottom);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700361 mFloatingActionButtonDialpadMarginBottom = resources.getDimensionPixelOffset(
362 R.dimen.floating_action_button_dialpad_margin_bottom);
363
Yorke Lee8898cd02013-08-08 10:24:27 -0700364 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800365 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700366
Yorke Lee53a22302014-04-29 18:13:46 -0700367 final ActionBar actionBar = getActionBar();
368 actionBar.setCustomView(R.layout.search_edittext);
369 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700370 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700371
Yorke Lee5253be02014-05-21 18:50:03 -0700372 mActionBarController = new ActionBarController(this,
373 (SearchEditTextLayout) actionBar.getCustomView());
374
Yorke Leeec489fb2014-05-19 15:39:27 -0700375 mSearchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView();
376 mSearchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
Yorke Lee53a22302014-04-29 18:13:46 -0700377
Yorke Leeec489fb2014-05-19 15:39:27 -0700378 mSearchView = (EditText) mSearchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700379 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Yorke Lee11ca39e2014-05-19 20:31:37 -0700380 mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button);
381 mSearchEditTextLayout.findViewById(R.id.search_box_start_search).setOnClickListener(
382 mSearchViewOnClickListener);
383 mSearchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
384 @Override
385 public void onBackButtonClicked() {
386 onBackPressed();
387 }
388 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700389
Yorke Leeec489fb2014-05-19 15:39:27 -0700390 ImageButton optionsMenuButton = (ImageButton) mSearchEditTextLayout.findViewById(
391 R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700392 optionsMenuButton.setOnClickListener(this);
393 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
394 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
395
Yorke Leeef2b7382013-08-09 17:39:25 -0700396 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
397 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700398 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800399 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700400 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800401 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
402 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700403 } else {
404 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700405 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
406 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700407 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700408 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700409 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700410 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700411 mIsLandscape = getResources().getConfiguration().orientation ==
412 Configuration.ORIENTATION_LANDSCAPE;
413
414 mSlideIn = AnimationUtils.loadAnimation(this,
415 mIsLandscape ? R.anim.slide_in_right : R.anim.slide_in);
416 mSlideOut = AnimationUtils.loadAnimation(this,
417 mIsLandscape ? R.anim.slide_out_right : R.anim.slide_out);
418
419 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700420
Andrew Lee0c667702014-05-12 14:31:45 -0700421 parentLayout = (RelativeLayout) findViewById(R.id.dialtacts_mainlayout);
422 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
423 parentLayout.setOnDragListener(new LayoutOnDragListener());
424
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700425 setupActivityOverlay();
426
Andrew Leea73e1892014-05-13 13:21:16 -0700427 mFloatingActionButtonContainer = findViewById(R.id.floating_action_button_container);
428 ViewUtil.setupFloatingActionButton(mFloatingActionButtonContainer, getResources());
Yorke Lee86e21f72014-04-02 16:49:38 -0700429
Andrew Leea73e1892014-05-13 13:21:16 -0700430 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
431 mFloatingActionButton.setOnClickListener(this);
Ihab Awad526c0b82014-02-27 12:55:36 -0800432
Yorke Lee28266192014-05-01 10:05:52 -0700433 mRemoveViewContainer = findViewById(R.id.remove_view_container);
Yorke Leeb0d19762014-03-05 14:43:28 -0800434
Yorke Lee0baa98b2013-08-22 10:55:16 -0700435 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700436 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700437 }
438
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700439 private void setupActivityOverlay() {
440 final View activityOverlay = findViewById(R.id.activity_overlay);
441 activityOverlay.setOnTouchListener(new OnTouchListener() {
442 @Override
443 public boolean onTouch(View v, MotionEvent event) {
444 if (!mIsDialpadShown) {
445 maybeExitSearchUi();
446 }
447 return false;
448 }
449 });
450 }
451
Chiao Cheng94b10b52012-08-17 16:59:12 -0700452 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700453 protected void onResume() {
454 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700455 if (mFirstLaunch) {
456 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700457 } else if (!phoneIsInUse() && mInCallDialpadUp) {
458 hideDialpadFragment(false, true);
459 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700460 } else if (mShowDialpadOnResume) {
461 showDialpadFragment(false);
462 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700463 }
464 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700465 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700466 mDialerDatabaseHelper.startSmartDialUpdateThread();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700467 }
468
469 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700470 protected void onPause() {
471 if (mClearSearchOnPause) {
472 hideDialpadAndSearchUi();
473 mClearSearchOnPause = false;
474 }
475 super.onPause();
476 }
477
478 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700479 protected void onSaveInstanceState(Bundle outState) {
480 super.onSaveInstanceState(outState);
481 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700482 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
483 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700484 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700485 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700486 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700487 }
488
489 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700490 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700491 if (fragment instanceof DialpadFragment) {
492 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700493 if (!mShowDialpadOnResume) {
494 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
495 transaction.hide(mDialpadFragment);
496 transaction.commit();
497 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700498 } else if (fragment instanceof SmartDialSearchFragment) {
499 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700500 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700501 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700502 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700503 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700504 } else if (fragment instanceof ListsFragment) {
505 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700506 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700507 }
Yorke Leec3766332013-07-31 11:13:16 -0700508 }
509
Alon Albertb453e5b2013-09-10 15:54:23 -0700510 protected void handleMenuSettings() {
511 openTelephonySetting(this);
512 }
513
514 public static void openTelephonySetting(Activity activity) {
515 final Intent settingsIntent = getCallSettingsIntent();
516 activity.startActivity(settingsIntent);
517 }
518
Chiao Cheng94b10b52012-08-17 16:59:12 -0700519 @Override
520 public void onClick(View view) {
521 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700522 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700523 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700524 mInCallDialpadUp = false;
525 showDialpadFragment(true);
526 } else {
527 // Dial button was pressed; tell the Dialpad fragment
528 mDialpadFragment.dialButtonPressed();
529 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700530 break;
Yorke Leec3766332013-07-31 11:13:16 -0700531 case R.id.search_close_button:
532 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700533 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700534 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700535 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700536 }
537 break;
Yorke Leec3766332013-07-31 11:13:16 -0700538 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800539 try {
540 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
541 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
542 } catch (ActivityNotFoundException e) {
543 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
544 Toast.LENGTH_SHORT).show();
545 }
Yorke Leec3766332013-07-31 11:13:16 -0700546 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700547 case R.id.dialtacts_options_menu_button:
548 buildOptionsMenu(view).show();
549 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700550 default: {
551 Log.wtf(TAG, "Unexpected onClick event from " + view);
552 break;
553 }
554 }
555 }
556
Yorke Leec3766332013-07-31 11:13:16 -0700557 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700558 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700559 switch (item.getItemId()) {
560 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700561 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700562 break;
563 case R.id.menu_add_contact:
564 try {
565 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
566 } catch (ActivityNotFoundException e) {
567 Toast toast = Toast.makeText(this,
568 R.string.add_contact_not_available,
569 Toast.LENGTH_SHORT);
570 toast.show();
571 }
572 break;
573 case R.id.menu_import_export:
574 // We hard-code the "contactsAreAvailable" argument because doing it properly would
575 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
576 // now in Dialtacts for (potential) performance reasons. Compare with how it is
577 // done in {@link PeopleActivity}.
578 ImportExportDialogFragment.show(getFragmentManager(), true,
579 DialtactsActivity.class);
580 return true;
581 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700582 ClearFrequentsDialog.show(getFragmentManager());
583 return true;
584 case R.id.menu_call_settings:
585 handleMenuSettings();
586 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700587 }
588 return false;
589 }
590
591 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700592 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
593 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
594 if (resultCode == RESULT_OK) {
595 final ArrayList<String> matches = data.getStringArrayListExtra(
596 RecognizerIntent.EXTRA_RESULTS);
597 if (matches.size() > 0) {
598 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700599 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700600 } else {
601 Log.e(TAG, "Voice search - nothing heard");
602 }
603 } else {
604 Log.e(TAG, "Voice search failed");
605 }
606 }
607 super.onActivityResult(requestCode, resultCode, data);
608 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700609
Andrew Lee2a58ab82014-05-15 02:16:04 -0700610 /**
611 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
612 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
613 * @see #onDialpadShown
614 */
Yorke Leec3766332013-07-31 11:13:16 -0700615 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700616 if (mIsDialpadShown) {
617 return;
618 }
619 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700620 mDialpadFragment.setAnimate(animate);
621
Chiao Cheng94b10b52012-08-17 16:59:12 -0700622 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700623 ft.show(mDialpadFragment);
624 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700625
Yorke Lee5253be02014-05-21 18:50:03 -0700626 mActionBarController.onDialpadUp();
627
Andrew Leeb1903842014-05-15 16:11:24 -0700628 if (!isInSearchUi()) {
629 enterSearchUi(true /* isSmartDial */, mSearchQuery);
630 }
Yorke Leec3766332013-07-31 11:13:16 -0700631 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700632
Andrew Lee2a58ab82014-05-15 02:16:04 -0700633 /**
634 * Callback from child DialpadFragment when the dialpad is shown.
635 */
636 public void onDialpadShown() {
637 updateFloatingActionButton();
638 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700639 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700640 } else {
641 mDialpadFragment.setYFraction(0);
642 }
643
Andrew Lee2a58ab82014-05-15 02:16:04 -0700644 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700645 }
646
647 /**
648 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
649 * a callback after the hide animation ends.
650 * @see #commitDialpadFragmentHide
651 */
Yorke Leeca195042013-09-25 16:29:38 -0700652 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700653 if (mDialpadFragment == null) {
654 return;
655 }
Yorke Leef6673d32013-08-23 15:34:17 -0700656 if (clearDialpad) {
657 mDialpadFragment.clearDialpad();
658 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700659 if (!mIsDialpadShown) {
660 return;
Yorke Leec3766332013-07-31 11:13:16 -0700661 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700662 mIsDialpadShown = false;
663 mDialpadFragment.setAnimate(animate);
664
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700665 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700666 updateFloatingActionButton();
667 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700668 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700669 } else {
670 commitDialpadFragmentHide();
671 }
672
Yorke Lee5253be02014-05-21 18:50:03 -0700673 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700674
Andrew Leed4cde832014-05-16 15:56:48 -0700675 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700676 if (TextUtils.isEmpty(mSearchQuery)) {
677 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700678 }
Andrew Leed4cde832014-05-16 15:56:48 -0700679 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700680 }
681
682 /**
683 * Finishes hiding the dialpad fragment after any animations are completed.
684 */
685 private void commitDialpadFragmentHide() {
686 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700687 ft.hide(mDialpadFragment);
688 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700689 }
690
Andrew Lee2a58ab82014-05-15 02:16:04 -0700691 private void updateSearchFragmentPosition() {
Sai Cheemalapati1e613802014-06-02 09:41:03 -0700692 int startTranslationValue = mIsDialpadShown ? mActionBarHeight : 0;
693 int endTranslationValue = mIsDialpadShown ? 0 : mActionBarHeight;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700694 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700695 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700696 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700697 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700698 fragment = mRegularSearchFragment;
699 }
700 if (fragment != null && fragment.isVisible()) {
Sai Cheemalapati1e613802014-06-02 09:41:03 -0700701 fragment.getListView().setTranslationY(startTranslationValue);
702 fragment.getListView().animate().translationY(endTranslationValue)
703 .setInterpolator(hideActionBarInterpolator)
704 .setDuration(ANIMATION_DURATION)
705 .start();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 }
707 }
708
Yorke Lee5253be02014-05-21 18:50:03 -0700709 @Override
710 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700711 return mInDialpadSearch || mInRegularSearch;
712 }
713
Yorke Lee5253be02014-05-21 18:50:03 -0700714 @Override
715 public boolean hasSearchQuery() {
716 return !TextUtils.isEmpty(mSearchQuery);
717 }
718
719 @Override
720 public boolean shouldShowActionBar() {
721 return mListsFragment.shouldShowActionBar();
722 }
723
Yorke Leeb207f8a2013-08-29 18:51:06 -0700724 private void setNotInSearchUi() {
725 mInDialpadSearch = false;
726 mInRegularSearch = false;
727 }
728
Yorke Lee311969c2013-08-26 06:31:11 -0700729 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700730 if (mIsDialpadShown) {
731 hideDialpadFragment(false, true);
732 } else {
733 exitSearchUi();
734 }
Yorke Lee311969c2013-08-26 06:31:11 -0700735 }
736
Yorke Leee00c9fe2014-04-12 12:42:06 -0700737 private void hideInputMethod(View view) {
738 final InputMethodManager imm = (InputMethodManager) getSystemService(
739 Context.INPUT_METHOD_SERVICE);
740 if (imm != null && view != null) {
741 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
742 }
743 }
744
Yorke Lee53a22302014-04-29 18:13:46 -0700745 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700746 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
747 if (canIntentBeHandled(voiceIntent)) {
748 mVoiceSearchButton.setVisibility(View.VISIBLE);
749 mVoiceSearchButton.setOnClickListener(this);
750 } else {
751 mVoiceSearchButton.setVisibility(View.GONE);
752 }
753 }
754
Andrew Leee74a10e2014-05-16 14:31:40 -0700755 private OptionsPopupMenu buildOptionsMenu(View invoker) {
756 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
757 popupMenu.inflate(R.menu.dialtacts_options);
758 popupMenu.setOnMenuItemClickListener(this);
759 return popupMenu;
760 }
761
Yorke Lee86e21f72014-04-02 16:49:38 -0700762 @Override
763 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700764 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700765 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700766 mPendingSearchViewQuery = null;
767 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700768 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700769 }
770
Chiao Cheng94b10b52012-08-17 16:59:12 -0700771 /**
772 * Returns true if the intent is due to hitting the green send key (hardware call button:
773 * KEYCODE_CALL) while in a call.
774 *
775 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700776 * @return true if the intent is due to hitting the green send key while in a call
777 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700778 private boolean isSendKeyWhileInCall(Intent intent) {
779 // If there is a call in progress and the user launched the dialer by hitting the call
780 // button, go straight to the in-call screen.
781 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700782
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700783 if (callKey) {
784 getTelephonyManager().showCallScreen();
785 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700786 }
787
788 return false;
789 }
790
791 /**
792 * Sets the current tab based on the intent's request type
793 *
794 * @param intent Intent that contains information about which tab should be selected
795 */
Yorke Leec3766332013-07-31 11:13:16 -0700796 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700797 // 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 -0700798 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700799 finish();
800 return;
801 }
802
Yorke Lee669b6082013-09-17 15:43:38 -0700803 if (mDialpadFragment != null) {
804 final boolean phoneIsInUse = phoneIsInUse();
805 if (phoneIsInUse || isDialIntent(intent)) {
806 mDialpadFragment.setStartedFromNewIntent(true);
807 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
808 mInCallDialpadUp = true;
809 }
810 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700811 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700812 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700813 }
814
815 @Override
816 public void onNewIntent(Intent newIntent) {
817 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700818 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700819
Chiao Cheng94b10b52012-08-17 16:59:12 -0700820 invalidateOptionsMenu();
821 }
822
823 /** Returns true if the given intent contains a phone number to populate the dialer with */
824 private boolean isDialIntent(Intent intent) {
825 final String action = intent.getAction();
826 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
827 return true;
828 }
829 if (Intent.ACTION_VIEW.equals(action)) {
830 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700831 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700832 return true;
833 }
834 }
835 return false;
836 }
837
838 /**
839 * Returns an appropriate call origin for this Activity. May return null when no call origin
840 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
841 * for remembering the tab in which the user made a phone call, so the external app's DIAL
842 * request should not be counted.)
843 */
844 public String getCallOrigin() {
845 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
846 }
847
Chiao Cheng94b10b52012-08-17 16:59:12 -0700848 /**
Yorke Leec3766332013-07-31 11:13:16 -0700849 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700850 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700851 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700852 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700853 // Weird race condition where fragment is doing work after the activity is destroyed
854 // due to talkback being on (b/10209937). Just return since we can't do any
855 // constructive here.
856 return;
857 }
858
Yorke Leeef2b7382013-08-09 17:39:25 -0700859 if (DEBUG) {
860 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
861 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700862
Yorke Leec3766332013-07-31 11:13:16 -0700863 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700864 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700865 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700866 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700867 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700868 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700869
Yorke Leeb207f8a2013-08-29 18:51:06 -0700870 final String tag;
871 if (smartDialSearch) {
872 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
873 } else {
874 tag = TAG_REGULAR_SEARCH_FRAGMENT;
875 }
876 mInDialpadSearch = smartDialSearch;
877 mInRegularSearch = !smartDialSearch;
878
Andrew Lee752956e2014-05-15 11:43:38 -0700879 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700880 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700881 if (fragment == null) {
882 if (smartDialSearch) {
883 fragment = new SmartDialSearchFragment();
884 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700885 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700886 }
Andrew Leeb1903842014-05-15 16:11:24 -0700887 transaction.add(R.id.dialtacts_frame, fragment, tag);
888 } else {
889 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700890 }
Andrew Leeb1903842014-05-15 16:11:24 -0700891
Yorke Lee86e21f72014-04-02 16:49:38 -0700892 // DialtactsActivity will provide the options menu
893 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700894 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700895 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700896 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700897
898 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700899 }
900
901 /**
Yorke Leec3766332013-07-31 11:13:16 -0700902 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700903 */
Yorke Leec3766332013-07-31 11:13:16 -0700904 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700905 // See related bug in enterSearchUI();
906 if (getFragmentManager().isDestroyed()) {
907 return;
908 }
Andrew Leeb1903842014-05-15 16:11:24 -0700909
Andrew Leeb1903842014-05-15 16:11:24 -0700910 mSearchView.setText(null);
911 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700912 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700913
Andrew Leeb1903842014-05-15 16:11:24 -0700914 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700915 if (mSmartDialSearchFragment != null) {
916 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700917 }
Andrew Leeb1903842014-05-15 16:11:24 -0700918 if (mRegularSearchFragment != null) {
919 transaction.remove(mRegularSearchFragment);
920 }
921 transaction.commit();
922
923 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700924 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700925 }
926
927 /** Returns an Intent to launch Call Settings screen */
928 public static Intent getCallSettingsIntent() {
929 final Intent intent = new Intent(Intent.ACTION_MAIN);
930 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
931 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
932 return intent;
933 }
934
935 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700936 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700937 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700938 if (TextUtils.isEmpty(mSearchQuery)) {
939 exitSearchUi();
940 }
Yorke Leef6673d32013-08-23 15:34:17 -0700941 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700942 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700943 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700944 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700945 } else {
946 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700947 }
Yorke Leec3766332013-07-31 11:13:16 -0700948 }
949
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700950 /**
951 * @return True if the search UI was exited, false otherwise
952 */
953 private boolean maybeExitSearchUi() {
954 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
955 exitSearchUi();
956 hideInputMethod(parentLayout);
957 return true;
958 }
959 return false;
960 }
961
Yorke Leec3766332013-07-31 11:13:16 -0700962 @Override
963 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700964 if (mSmartDialSearchFragment != null) {
965 mSmartDialSearchFragment.setAddToContactNumber(query);
966 }
Yorke Leec3766332013-07-31 11:13:16 -0700967 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
968 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700969
970 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700971 if (DEBUG) {
972 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
973 }
974 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
975 // This callback can happen if the dialpad fragment is recreated because of
976 // activity destruction. In that case, don't update the search view because
977 // that would bring the user back to the search fragment regardless of the
978 // previous state of the application. Instead, just return here and let the
979 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700980 if (!TextUtils.isEmpty(normalizedQuery)) {
981 mPendingSearchViewQuery = normalizedQuery;
982 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700983 return;
984 }
Yorke Lee53a22302014-04-29 18:13:46 -0700985 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700986 }
987 }
Yorke Leec3766332013-07-31 11:13:16 -0700988
989 @Override
990 public void onListFragmentScrollStateChange(int scrollState) {
991 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700992 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700993 hideInputMethod(getCurrentFocus());
994 }
995 }
996
997 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700998 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700999 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001000 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1001 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001002 }
1003
Yorke Lee86e21f72014-04-02 16:49:38 -07001004 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001005 public void setFloatingActionButtonVisible(boolean visible) {
1006 mFloatingActionButtonContainer.setVisibility(visible ? View.VISIBLE : View.GONE);
Yorke Leec3766332013-07-31 11:13:16 -07001007 }
1008
1009 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001010 // TODO(santoscordon): Replace with a TelecommService method call.
1011 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001012 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001013
Yorke Leee1424812013-09-04 18:24:48 -07001014 public static Intent getAddNumberToContactIntent(CharSequence text) {
1015 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1016 intent.putExtra(Intents.Insert.PHONE, text);
1017 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1018 return intent;
1019 }
1020
Yorke Leeda0f9042013-12-05 14:25:51 -08001021 private boolean canIntentBeHandled(Intent intent) {
1022 final PackageManager packageManager = getPackageManager();
1023 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1024 PackageManager.MATCH_DEFAULT_ONLY);
1025 return resolveInfo != null && resolveInfo.size() > 0;
1026 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001027
Yorke Lee6a1461a2014-04-21 16:27:14 -07001028 @Override
1029 public void showCallHistory() {
1030 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1031 // CONTENT_TYPE, so that we always open our call log from our dialer
1032 final Intent intent = new Intent(this, CallLogActivity.class);
1033 startActivity(intent);
1034 }
1035
Yorke Lee86e21f72014-04-02 16:49:38 -07001036 /**
1037 * Called when the user has long-pressed a contact tile to start a drag operation.
1038 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001039 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001040 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001041 if (mListsFragment.isPaneOpen()) {
1042 mActionBarController.slideActionBarUp(true);
1043 }
Yorke Lee28266192014-05-01 10:05:52 -07001044 mRemoveViewContainer.setVisibility(View.VISIBLE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001045 }
1046
1047 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001048 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1049 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001050
Yorke Lee86e21f72014-04-02 16:49:38 -07001051 /**
1052 * Called when the user has released a contact tile after long-pressing it.
1053 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001054 @Override
1055 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001056 if (mListsFragment.isPaneOpen()) {
1057 mActionBarController.slideActionBarDown(true);
1058 }
Yorke Lee28266192014-05-01 10:05:52 -07001059 mRemoveViewContainer.setVisibility(View.GONE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001060 }
1061
1062 @Override
1063 public void onDroppedOnRemove() {}
1064
1065 /**
Yorke Leed999b712014-04-23 15:10:58 -07001066 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001067 * once it has been attached to the activity.
1068 */
1069 @Override
1070 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001071 mDragDropController = dragController;
1072 ((RemoveView) findViewById(R.id.remove_view))
1073 .setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001074 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001075
1076 @Override
1077 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001078 // Specify call-origin so that users will see the previous tab instead of
1079 // CallLog screen (search UI will be automatically exited).
1080 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001081 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001082 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001083 }
1084
1085 @Override
1086 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001087 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1088 startActivity(intent);
1089 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001090 }
1091
1092 @Override
1093 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001094 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001095 }
1096
1097 @Override
1098 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001099 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001100 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001101
Yorke Leecc4660d2014-04-24 11:22:57 -07001102 @Override
1103 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
1104
1105 }
1106
1107 @Override
1108 public void onPageSelected(int position) {
1109 mCurrentTabPosition = position;
Yorke Leec61d4542014-05-01 10:43:24 -07001110 // If the dialpad is showing, the floating action button should always be middle aligned.
Andrew Lee2a58ab82014-05-15 02:16:04 -07001111 if (!mIsDialpadShown) {
Yorke Leec61d4542014-05-01 10:43:24 -07001112 alignFloatingActionButtonByTab(mCurrentTabPosition);
1113 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001114 }
1115
1116 @Override
1117 public void onPageScrollStateChanged(int state) {
1118 }
1119
Andrew Lee2a58ab82014-05-15 02:16:04 -07001120 private void updateFloatingActionButton() {
1121 if (mIsDialpadShown) {
1122 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
1123 mFloatingActionButton.setContentDescription(
1124 getResources().getString(R.string.description_dial_button));
Andrew Leec4643f72014-05-15 11:27:39 -07001125 alignFloatingActionButtonMiddle();
Andrew Lee2a58ab82014-05-15 02:16:04 -07001126 } else {
1127 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
1128 mFloatingActionButton.setContentDescription(
1129 getResources().getString(R.string.action_menu_dialpad_button));
Andrew Leec4643f72014-05-15 11:27:39 -07001130 alignFloatingActionButtonByTab(mCurrentTabPosition);
Andrew Lee2a58ab82014-05-15 02:16:04 -07001131 }
1132 }
1133
Yorke Leecc4660d2014-04-24 11:22:57 -07001134 private void alignFloatingActionButtonByTab(int position) {
1135 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL) {
1136 alignFloatingActionButtonMiddle();
1137 } else {
1138 alignFloatingActionButtonRight();
1139 }
1140 }
1141
1142 private void alignFloatingActionButtonRight() {
1143 final RelativeLayout.LayoutParams params =
Andrew Leea73e1892014-05-13 13:21:16 -07001144 (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams();
Yorke Leecc4660d2014-04-24 11:22:57 -07001145 params.removeRule(RelativeLayout.CENTER_HORIZONTAL);
1146 params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Andrew Lee2423a2f2014-05-29 14:14:45 -07001147 updateFloatingActionButtonMargin(params);
Andrew Leea73e1892014-05-13 13:21:16 -07001148 mFloatingActionButtonContainer.setLayoutParams(params);
Yorke Leecc4660d2014-04-24 11:22:57 -07001149 }
1150
1151 private void alignFloatingActionButtonMiddle() {
1152 final RelativeLayout.LayoutParams params =
Andrew Leea73e1892014-05-13 13:21:16 -07001153 (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams();
Yorke Leecc4660d2014-04-24 11:22:57 -07001154 params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
1155 params.addRule(RelativeLayout.CENTER_HORIZONTAL);
Andrew Lee2423a2f2014-05-29 14:14:45 -07001156 updateFloatingActionButtonMargin(params);
Andrew Leea73e1892014-05-13 13:21:16 -07001157 mFloatingActionButtonContainer.setLayoutParams(params);
Yorke Leecc4660d2014-04-24 11:22:57 -07001158 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001159
Andrew Lee2423a2f2014-05-29 14:14:45 -07001160 private void updateFloatingActionButtonMargin(RelativeLayout.LayoutParams params) {
1161 params.setMarginsRelative(
1162 params.getMarginStart(),
1163 params.topMargin,
1164 params.getMarginEnd(),
1165 mIsDialpadShown ?
1166 mFloatingActionButtonDialpadMarginBottom :
1167 mFloatingActionButtonMarginBottom);
1168 }
1169
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001170 private TelephonyManager getTelephonyManager() {
1171 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1172 }
1173
Yorke Lee5253be02014-05-21 18:50:03 -07001174 @Override
1175 public boolean isActionBarShowing() {
1176 return mActionBarController.isActionBarShowing();
1177 }
1178
1179 @Override
1180 public int getActionBarHideOffset() {
1181 return getActionBar().getHideOffset();
1182 }
1183
1184 @Override
1185 public int getActionBarHeight() {
1186 return mActionBarHeight;
1187 }
1188
1189 @Override
1190 public void setActionBarHideOffset(int hideOffset) {
1191 getActionBar().setHideOffset(hideOffset);
1192 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001193}