Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1 | /* |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package com.android.dialer; |
| 18 | |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 19 | import android.animation.LayoutTransition; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 20 | import android.app.ActionBar; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 21 | import android.app.Activity; |
| 22 | import android.app.Fragment; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 23 | import android.app.FragmentTransaction; |
Chiao Cheng | 073b5cf | 2012-12-07 11:36:00 -0800 | [diff] [blame] | 24 | import android.content.ActivityNotFoundException; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
| 28 | import android.content.pm.ResolveInfo; |
Yorke Lee | 33932ff | 2014-04-16 13:34:32 -0700 | [diff] [blame] | 29 | import android.content.res.TypedArray; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 30 | import android.net.Uri; |
| 31 | import android.os.Bundle; |
| 32 | import android.os.RemoteException; |
| 33 | import android.os.ServiceManager; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 34 | import android.provider.ContactsContract.Contacts; |
Yorke Lee | e142481 | 2013-09-04 18:24:48 -0700 | [diff] [blame] | 35 | import android.provider.ContactsContract.Intents; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 36 | import android.speech.RecognizerIntent; |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 37 | import android.support.v4.view.ViewPager; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 38 | import android.telephony.TelephonyManager; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 39 | import android.text.Editable; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 40 | import android.text.TextUtils; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 41 | import android.text.TextWatcher; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 42 | import android.util.Log; |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 43 | import android.view.DragEvent; |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 44 | import android.view.KeyEvent; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 45 | import android.view.Menu; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 46 | import android.view.MenuItem; |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 47 | import android.view.MotionEvent; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 48 | import android.view.View; |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 49 | import android.view.View.OnDragListener; |
Yorke Lee | c7b2a0e | 2014-05-20 17:21:25 -0700 | [diff] [blame] | 50 | import android.view.View.OnTouchListener; |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 51 | import android.view.animation.AccelerateInterpolator; |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 52 | import android.view.animation.Animation; |
| 53 | import android.view.animation.Animation.AnimationListener; |
| 54 | import android.view.animation.AnimationUtils; |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 55 | import android.view.animation.DecelerateInterpolator; |
| 56 | import android.view.animation.Interpolator; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 57 | import android.view.inputmethod.InputMethodManager; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 58 | import android.widget.AbsListView.OnScrollListener; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 59 | import android.widget.EditText; |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 60 | import android.widget.ImageButton; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 61 | import android.widget.PopupMenu; |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 62 | import android.widget.RelativeLayout; |
Chiao Cheng | 073b5cf | 2012-12-07 11:36:00 -0800 | [diff] [blame] | 63 | import android.widget.Toast; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 64 | |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 65 | import com.android.contacts.common.CallUtil; |
Chiao Cheng | 603ff68 | 2012-10-24 15:18:40 -0700 | [diff] [blame] | 66 | import com.android.contacts.common.activity.TransactionSafeActivity; |
Andrew Lee | 3c14bc3 | 2014-05-28 15:43:03 -0700 | [diff] [blame] | 67 | import com.android.contacts.common.animation.AnimationListenerAdapter; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 68 | import com.android.contacts.common.dialog.ClearFrequentsDialog; |
| 69 | import com.android.contacts.common.interactions.ImportExportDialogFragment; |
Chiao Cheng | 8efbcf9 | 2012-12-04 17:43:02 -0800 | [diff] [blame] | 70 | import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; |
Andrew Lee | 4cbc973 | 2014-04-24 14:38:58 -0700 | [diff] [blame] | 71 | import com.android.contacts.common.util.ViewUtil; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 72 | import com.android.dialer.calllog.CallLogActivity; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 73 | import com.android.dialer.database.DialerDatabaseHelper; |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 74 | import com.android.dialer.dialpad.DialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 75 | import com.android.dialer.dialpad.SmartDialNameMatcher; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 76 | import com.android.dialer.dialpad.SmartDialPrefix; |
Chiao Cheng | 1429f1a | 2012-11-01 16:35:28 -0700 | [diff] [blame] | 77 | import com.android.dialer.interactions.PhoneNumberInteraction; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 78 | import com.android.dialer.list.DragDropController; |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 79 | import com.android.dialer.list.ListsFragment; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 80 | import com.android.dialer.list.OnDragDropListener; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 81 | import com.android.dialer.list.OnListFragmentScrolledListener; |
Yorke Lee | d999b71 | 2014-04-23 15:10:58 -0700 | [diff] [blame] | 82 | import com.android.dialer.list.SpeedDialFragment; |
Yorke Lee | efb2d9c | 2014-04-18 14:05:01 -0700 | [diff] [blame] | 83 | import com.android.dialer.list.PhoneFavoriteSquareTileView; |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 84 | import com.android.dialer.list.RegularSearchFragment; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 85 | import com.android.dialer.list.RemoveView; |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 86 | import com.android.dialer.list.SearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 87 | import com.android.dialer.list.SmartDialSearchFragment; |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 88 | import com.android.dialer.widget.ActionBarController; |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 89 | import com.android.dialer.widget.SearchEditTextLayout; |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 90 | import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener; |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 91 | import com.android.dialerbind.DatabaseHelperManager; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 92 | import com.android.internal.telephony.ITelephony; |
| 93 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 94 | import java.util.ArrayList; |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 95 | import java.util.List; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 96 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 97 | /** |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 98 | * The dialer tab's title is 'phone', a more common name (see strings.xml). |
| 99 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 100 | public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener, |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 101 | DialpadFragment.OnDialpadQueryChangedListener, |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 102 | OnListFragmentScrolledListener, |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 103 | DialpadFragment.HostInterface, |
Yorke Lee | 6a1461a | 2014-04-21 16:27:14 -0700 | [diff] [blame] | 104 | ListsFragment.HostInterface, |
Yorke Lee | d999b71 | 2014-04-23 15:10:58 -0700 | [diff] [blame] | 105 | SpeedDialFragment.HostInterface, |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 106 | SearchFragment.HostInterface, |
Andrew Lee | 752956e | 2014-05-15 11:43:38 -0700 | [diff] [blame] | 107 | OnDragDropListener, |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 108 | OnPhoneNumberPickerActionListener, |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 109 | PopupMenu.OnMenuItemClickListener, |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 110 | ViewPager.OnPageChangeListener, |
| 111 | ActionBarController.ActivityUi { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 112 | private static final String TAG = "DialtactsActivity"; |
| 113 | |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 114 | public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 115 | |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 116 | public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences"; |
| 117 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 118 | /** Used to open Call Setting */ |
| 119 | private static final String PHONE_PACKAGE = "com.android.phone"; |
| 120 | private static final String CALL_SETTINGS_CLASS_NAME = |
| 121 | "com.android.phone.CallFeaturesSetting"; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 122 | /** @see #getCallOrigin() */ |
| 123 | private static final String CALL_ORIGIN_DIALTACTS = |
| 124 | "com.android.dialer.DialtactsActivity"; |
| 125 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 126 | private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui"; |
| 127 | private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui"; |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 128 | private static final String KEY_SEARCH_QUERY = "search_query"; |
| 129 | private static final String KEY_FIRST_LAUNCH = "first_launch"; |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 130 | private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown"; |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 131 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 132 | private static final String TAG_DIALPAD_FRAGMENT = "dialpad"; |
| 133 | private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search"; |
| 134 | private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial"; |
| 135 | private static final String TAG_FAVORITES_FRAGMENT = "favorites"; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 136 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}. |
| 139 | */ |
| 140 | private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER"; |
| 141 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 142 | private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 143 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 144 | private static final int ANIMATION_DURATION = 250; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 145 | |
Andrew Lee | 0c66770 | 2014-05-12 14:31:45 -0700 | [diff] [blame] | 146 | private RelativeLayout parentLayout; |
| 147 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 148 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 149 | * Fragment containing the dialpad that slides into view |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 150 | */ |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 151 | private DialpadFragment mDialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * Fragment for searching phone numbers using the alphanumeric keyboard. |
| 155 | */ |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 156 | private RegularSearchFragment mRegularSearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 157 | |
| 158 | /** |
| 159 | * Fragment for searching phone numbers using the dialpad. |
| 160 | */ |
| 161 | private SmartDialSearchFragment mSmartDialSearchFragment; |
| 162 | |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 163 | /** |
| 164 | * Fragment containing the speed dial list, recents list, and all contacts list. |
| 165 | */ |
| 166 | private ListsFragment mListsFragment; |
| 167 | |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 168 | private View mFloatingActionButtonContainer; |
| 169 | private ImageButton mFloatingActionButton; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 170 | |
Yorke Lee | 33932ff | 2014-04-16 13:34:32 -0700 | [diff] [blame] | 171 | private int mActionBarHeight; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 172 | private boolean mInDialpadSearch; |
| 173 | private boolean mInRegularSearch; |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 174 | private boolean mClearSearchOnPause; |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 175 | private boolean mIsDialpadShown; |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 176 | private boolean mShowDialpadOnResume; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 177 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 178 | /** |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 179 | * The position of the currently selected tab in the attached {@link ListsFragment}. |
| 180 | */ |
| 181 | private int mCurrentTabPosition = 0; |
| 182 | |
| 183 | /** |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 184 | * True if the dialpad is only temporarily showing due to being in call |
| 185 | */ |
| 186 | private boolean mInCallDialpadUp; |
| 187 | |
| 188 | /** |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 189 | * True when this activity has been launched for the first time. |
| 190 | */ |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 191 | private boolean mFirstLaunch; |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 192 | |
Yorke Lee | 3c9e7cd | 2014-04-16 11:37:21 -0700 | [diff] [blame] | 193 | /** |
| 194 | * Search query to be applied to the SearchView in the ActionBar once |
| 195 | * onCreateOptionsMenu has been called. |
| 196 | */ |
| 197 | private String mPendingSearchViewQuery; |
| 198 | |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 199 | private EditText mSearchView; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 200 | private View mVoiceSearchButton; |
Yorke Lee | ec489fb | 2014-05-19 15:39:27 -0700 | [diff] [blame] | 201 | private SearchEditTextLayout mSearchEditTextLayout; |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 202 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 203 | /** |
| 204 | * View that contains the "Remove" dialog that shows up when the user long presses a contact. |
| 205 | * If the user releases a contact when hovering on top of this, the contact is unfavorited and |
| 206 | * removed from the speed dial list. |
| 207 | */ |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 208 | private View mRemoveViewContainer; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 209 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 210 | final Interpolator hideActionBarInterpolator = new AccelerateInterpolator(1.5f); |
| 211 | final Interpolator showActionBarInterpolator = new DecelerateInterpolator(1.5f); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 212 | private String mSearchQuery; |
| 213 | |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 214 | private DialerDatabaseHelper mDialerDatabaseHelper; |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 215 | private DragDropController mDragDropController; |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 216 | private ActionBarController mActionBarController; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 217 | |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 218 | private class OptionsPopupMenu extends PopupMenu { |
| 219 | public OptionsPopupMenu(Context context, View anchor) { |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 220 | super(context, anchor); |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void show() { |
| 225 | final Menu menu = getMenu(); |
| 226 | final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents); |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 227 | clearFrequents.setVisible(mListsFragment != null && |
| 228 | mListsFragment.getSpeedDialFragment() != null && |
| 229 | mListsFragment.getSpeedDialFragment().hasFrequents()); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 230 | super.show(); |
| 231 | } |
| 232 | } |
| 233 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 234 | /** |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 235 | * Listener that listens to drag events and sends their x and y coordinates to a |
| 236 | * {@link DragDropController}. |
| 237 | */ |
| 238 | private class LayoutOnDragListener implements OnDragListener { |
| 239 | @Override |
| 240 | public boolean onDrag(View v, DragEvent event) { |
| 241 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
| 242 | mDragDropController.handleDragHovered(v, (int) event.getX(), |
| 243 | (int) event.getY()); |
| 244 | } |
| 245 | return true; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /** |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 250 | * Listener used to send search queries to the phone search fragment. |
| 251 | */ |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 252 | private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() { |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 253 | @Override |
| 254 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 255 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 256 | |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 257 | @Override |
| 258 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 259 | final String newText = s.toString(); |
| 260 | if (newText.equals(mSearchQuery)) { |
| 261 | // If the query hasn't changed (perhaps due to activity being destroyed |
| 262 | // and restored, or user launching the same DIAL intent twice), then there is |
| 263 | // no need to do anything here. |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 264 | return; |
| 265 | } |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 266 | if (DEBUG) { |
| 267 | Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText); |
Yorke Lee | 710709d | 2014-05-29 07:18:42 -0700 | [diff] [blame^] | 268 | Log.d(TAG, "Previous Query: " + mSearchQuery); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 269 | } |
Yorke Lee | 710709d | 2014-05-29 07:18:42 -0700 | [diff] [blame^] | 270 | mSearchQuery = newText; |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 271 | |
Andrew Lee | 90374a7 | 2014-05-16 15:01:09 -0700 | [diff] [blame] | 272 | // Show search fragment only when the query string is changed to non-empty text. |
| 273 | if (!TextUtils.isEmpty(newText)) { |
| 274 | // Call enterSearchUi only if we are switching search modes, or showing a search |
| 275 | // fragment for the first time. |
| 276 | final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) || |
| 277 | (!mIsDialpadShown && mInRegularSearch); |
| 278 | if (!sameSearchMode) { |
| 279 | enterSearchUi(mIsDialpadShown, mSearchQuery); |
| 280 | } |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | if (mIsDialpadShown && mSmartDialSearchFragment != null) { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 284 | mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */); |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 285 | } else if (mRegularSearchFragment != null) { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 286 | mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */); |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 287 | } |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public void afterTextChanged(Editable s) { |
| 292 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 293 | }; |
| 294 | |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 295 | |
| 296 | /** |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 297 | * Open the search UI when the user clicks on the search box. |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 298 | */ |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 299 | private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 300 | @Override |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 301 | public void onClick(View v) { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 302 | if (!isInSearchUi()) { |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 303 | mActionBarController.onSearchBoxTapped(); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 304 | enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString()); |
| 305 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 306 | } |
| 307 | }; |
| 308 | |
| 309 | /** |
| 310 | * If the search term is empty and the user closes the soft keyboard, close the search UI. |
| 311 | */ |
| 312 | private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() { |
| 313 | @Override |
| 314 | public boolean onKey(View v, int keyCode, KeyEvent event) { |
| 315 | if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN && |
| 316 | TextUtils.isEmpty(mSearchView.getText().toString())) { |
Yorke Lee | c7b2a0e | 2014-05-20 17:21:25 -0700 | [diff] [blame] | 317 | maybeExitSearchUi(); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 318 | } |
| 319 | return false; |
| 320 | } |
| 321 | }; |
| 322 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 323 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 324 | protected void onCreate(Bundle savedInstanceState) { |
| 325 | super.onCreate(savedInstanceState); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 326 | mFirstLaunch = true; |
| 327 | |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 328 | setContentView(R.layout.dialtacts_activity); |
Yorke Lee | 9e91bb0 | 2014-03-05 17:50:50 -0800 | [diff] [blame] | 329 | getWindow().setBackgroundDrawable(null); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 330 | |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 331 | final ActionBar actionBar = getActionBar(); |
| 332 | actionBar.setCustomView(R.layout.search_edittext); |
| 333 | actionBar.setDisplayShowCustomEnabled(true); |
Yorke Lee | bcef940 | 2014-05-21 15:33:00 -0700 | [diff] [blame] | 334 | actionBar.setBackgroundDrawable(null); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 335 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 336 | mActionBarController = new ActionBarController(this, |
| 337 | (SearchEditTextLayout) actionBar.getCustomView()); |
| 338 | |
Yorke Lee | ec489fb | 2014-05-19 15:39:27 -0700 | [diff] [blame] | 339 | mSearchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView(); |
| 340 | mSearchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 341 | |
Yorke Lee | ec489fb | 2014-05-19 15:39:27 -0700 | [diff] [blame] | 342 | mSearchView = (EditText) mSearchEditTextLayout.findViewById(R.id.search_view); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 343 | mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 344 | mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button); |
| 345 | mSearchEditTextLayout.findViewById(R.id.search_box_start_search).setOnClickListener( |
| 346 | mSearchViewOnClickListener); |
| 347 | mSearchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() { |
| 348 | @Override |
| 349 | public void onBackButtonClicked() { |
| 350 | onBackPressed(); |
| 351 | } |
| 352 | }); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 353 | |
Yorke Lee | ec489fb | 2014-05-19 15:39:27 -0700 | [diff] [blame] | 354 | ImageButton optionsMenuButton = (ImageButton) mSearchEditTextLayout.findViewById( |
| 355 | R.id.dialtacts_options_menu_button); |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 356 | optionsMenuButton.setOnClickListener(this); |
| 357 | final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton); |
| 358 | optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener()); |
| 359 | |
Yorke Lee | 3443d4a | 2014-05-23 19:30:35 -0700 | [diff] [blame] | 360 | mActionBarHeight = getResources().getDimensionPixelSize(R.dimen.action_bar_height); |
Yorke Lee | 33932ff | 2014-04-16 13:34:32 -0700 | [diff] [blame] | 361 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 362 | // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState |
| 363 | // is null. Otherwise the fragment manager takes care of recreating these fragments. |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 364 | if (savedInstanceState == null) { |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 365 | getFragmentManager().beginTransaction() |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 366 | .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT) |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 367 | .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT) |
| 368 | .commit(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 369 | } else { |
| 370 | mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 371 | mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI); |
| 372 | mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 373 | mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 374 | mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN); |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 375 | mActionBarController.restoreInstanceState(savedInstanceState); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Andrew Lee | 0c66770 | 2014-05-12 14:31:45 -0700 | [diff] [blame] | 378 | parentLayout = (RelativeLayout) findViewById(R.id.dialtacts_mainlayout); |
| 379 | parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING); |
| 380 | parentLayout.setOnDragListener(new LayoutOnDragListener()); |
| 381 | |
Yorke Lee | c7b2a0e | 2014-05-20 17:21:25 -0700 | [diff] [blame] | 382 | setupActivityOverlay(); |
| 383 | |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 384 | mFloatingActionButtonContainer = findViewById(R.id.floating_action_button_container); |
| 385 | ViewUtil.setupFloatingActionButton(mFloatingActionButtonContainer, getResources()); |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 386 | |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 387 | mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button); |
| 388 | mFloatingActionButton.setOnClickListener(this); |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 389 | |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 390 | mRemoveViewContainer = findViewById(R.id.remove_view_container); |
Yorke Lee | b0d1976 | 2014-03-05 14:43:28 -0800 | [diff] [blame] | 391 | |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 392 | mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this); |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 393 | SmartDialPrefix.initializeNanpSettings(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Yorke Lee | c7b2a0e | 2014-05-20 17:21:25 -0700 | [diff] [blame] | 396 | private void setupActivityOverlay() { |
| 397 | final View activityOverlay = findViewById(R.id.activity_overlay); |
| 398 | activityOverlay.setOnTouchListener(new OnTouchListener() { |
| 399 | @Override |
| 400 | public boolean onTouch(View v, MotionEvent event) { |
| 401 | if (!mIsDialpadShown) { |
| 402 | maybeExitSearchUi(); |
| 403 | } |
| 404 | return false; |
| 405 | } |
| 406 | }); |
| 407 | } |
| 408 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 409 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 410 | protected void onResume() { |
| 411 | super.onResume(); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 412 | if (mFirstLaunch) { |
| 413 | displayFragment(getIntent()); |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 414 | } else if (!phoneIsInUse() && mInCallDialpadUp) { |
| 415 | hideDialpadFragment(false, true); |
| 416 | mInCallDialpadUp = false; |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 417 | } else if (mShowDialpadOnResume) { |
| 418 | showDialpadFragment(false); |
| 419 | mShowDialpadOnResume = false; |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 420 | } |
| 421 | mFirstLaunch = false; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 422 | prepareVoiceSearchButton(); |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 423 | mDialerDatabaseHelper.startSmartDialUpdateThread(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | @Override |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 427 | protected void onPause() { |
| 428 | if (mClearSearchOnPause) { |
| 429 | hideDialpadAndSearchUi(); |
| 430 | mClearSearchOnPause = false; |
| 431 | } |
| 432 | super.onPause(); |
| 433 | } |
| 434 | |
| 435 | @Override |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 436 | protected void onSaveInstanceState(Bundle outState) { |
| 437 | super.onSaveInstanceState(outState); |
| 438 | outState.putString(KEY_SEARCH_QUERY, mSearchQuery); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 439 | outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch); |
| 440 | outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 441 | outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch); |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 442 | outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown); |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 443 | mActionBarController.saveInstanceState(outState); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 447 | public void onAttachFragment(Fragment fragment) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 448 | if (fragment instanceof DialpadFragment) { |
| 449 | mDialpadFragment = (DialpadFragment) fragment; |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 450 | if (!mShowDialpadOnResume) { |
| 451 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
| 452 | transaction.hide(mDialpadFragment); |
| 453 | transaction.commit(); |
| 454 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 455 | } else if (fragment instanceof SmartDialSearchFragment) { |
| 456 | mSmartDialSearchFragment = (SmartDialSearchFragment) fragment; |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 457 | mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 458 | } else if (fragment instanceof SearchFragment) { |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 459 | mRegularSearchFragment = (RegularSearchFragment) fragment; |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 460 | mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 461 | } else if (fragment instanceof ListsFragment) { |
| 462 | mListsFragment = (ListsFragment) fragment; |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 463 | mListsFragment.addOnPageChangeListener(this); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 464 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 467 | protected void handleMenuSettings() { |
| 468 | openTelephonySetting(this); |
| 469 | } |
| 470 | |
| 471 | public static void openTelephonySetting(Activity activity) { |
| 472 | final Intent settingsIntent = getCallSettingsIntent(); |
| 473 | activity.startActivity(settingsIntent); |
| 474 | } |
| 475 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 476 | @Override |
| 477 | public void onClick(View view) { |
| 478 | switch (view.getId()) { |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 479 | case R.id.floating_action_button: |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 480 | if (!mIsDialpadShown) { |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 481 | mInCallDialpadUp = false; |
| 482 | showDialpadFragment(true); |
| 483 | } else { |
| 484 | // Dial button was pressed; tell the Dialpad fragment |
| 485 | mDialpadFragment.dialButtonPressed(); |
| 486 | } |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 487 | break; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 488 | case R.id.search_close_button: |
| 489 | // Clear the search field |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 490 | if (!TextUtils.isEmpty(mSearchView.getText())) { |
Yorke Lee | 2eafb7a | 2013-09-10 14:34:01 -0700 | [diff] [blame] | 491 | mDialpadFragment.clearDialpad(); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 492 | mSearchView.setText(null); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 493 | } |
| 494 | break; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 495 | case R.id.voice_search_button: |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 496 | try { |
| 497 | startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), |
| 498 | ACTIVITY_REQUEST_CODE_VOICE_SEARCH); |
| 499 | } catch (ActivityNotFoundException e) { |
| 500 | Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available, |
| 501 | Toast.LENGTH_SHORT).show(); |
| 502 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 503 | break; |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 504 | case R.id.dialtacts_options_menu_button: |
| 505 | buildOptionsMenu(view).show(); |
| 506 | break; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 507 | default: { |
| 508 | Log.wtf(TAG, "Unexpected onClick event from " + view); |
| 509 | break; |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 514 | @Override |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 515 | public boolean onMenuItemClick(MenuItem item) { |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 516 | switch (item.getItemId()) { |
| 517 | case R.id.menu_history: |
Yorke Lee | 6a1461a | 2014-04-21 16:27:14 -0700 | [diff] [blame] | 518 | showCallHistory(); |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 519 | break; |
| 520 | case R.id.menu_add_contact: |
| 521 | try { |
| 522 | startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI)); |
| 523 | } catch (ActivityNotFoundException e) { |
| 524 | Toast toast = Toast.makeText(this, |
| 525 | R.string.add_contact_not_available, |
| 526 | Toast.LENGTH_SHORT); |
| 527 | toast.show(); |
| 528 | } |
| 529 | break; |
| 530 | case R.id.menu_import_export: |
| 531 | // We hard-code the "contactsAreAvailable" argument because doing it properly would |
| 532 | // involve querying a {@link ProviderStatusLoader}, which we don't want to do right |
| 533 | // now in Dialtacts for (potential) performance reasons. Compare with how it is |
| 534 | // done in {@link PeopleActivity}. |
| 535 | ImportExportDialogFragment.show(getFragmentManager(), true, |
| 536 | DialtactsActivity.class); |
| 537 | return true; |
| 538 | case R.id.menu_clear_frequents: |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 539 | ClearFrequentsDialog.show(getFragmentManager()); |
| 540 | return true; |
| 541 | case R.id.menu_call_settings: |
| 542 | handleMenuSettings(); |
| 543 | return true; |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 544 | } |
| 545 | return false; |
| 546 | } |
| 547 | |
| 548 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 549 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 550 | if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) { |
| 551 | if (resultCode == RESULT_OK) { |
| 552 | final ArrayList<String> matches = data.getStringArrayListExtra( |
| 553 | RecognizerIntent.EXTRA_RESULTS); |
| 554 | if (matches.size() > 0) { |
| 555 | final String match = matches.get(0); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 556 | mSearchView.setText(match); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 557 | } else { |
| 558 | Log.e(TAG, "Voice search - nothing heard"); |
| 559 | } |
| 560 | } else { |
| 561 | Log.e(TAG, "Voice search failed"); |
| 562 | } |
| 563 | } |
| 564 | super.onActivityResult(requestCode, resultCode, data); |
| 565 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 566 | |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 567 | /** |
| 568 | * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual |
| 569 | * updates are handled by a callback which is invoked after the dialpad fragment is shown. |
| 570 | * @see #onDialpadShown |
| 571 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 572 | private void showDialpadFragment(boolean animate) { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 573 | if (mIsDialpadShown) { |
| 574 | return; |
| 575 | } |
| 576 | mIsDialpadShown = true; |
Andrew Lee | cdfa6c6 | 2014-05-06 15:33:35 -0700 | [diff] [blame] | 577 | mDialpadFragment.setAnimate(animate); |
| 578 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 579 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 580 | ft.show(mDialpadFragment); |
| 581 | ft.commit(); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 582 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 583 | mActionBarController.onDialpadUp(); |
| 584 | |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 585 | if (!isInSearchUi()) { |
| 586 | enterSearchUi(true /* isSmartDial */, mSearchQuery); |
| 587 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 588 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 589 | |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 590 | /** |
| 591 | * Callback from child DialpadFragment when the dialpad is shown. |
| 592 | */ |
| 593 | public void onDialpadShown() { |
| 594 | updateFloatingActionButton(); |
| 595 | if (mDialpadFragment.getAnimate()) { |
| 596 | Animation slideIn = AnimationUtils.loadAnimation(this, R.anim.slide_in); |
| 597 | mDialpadFragment.getView().startAnimation(slideIn); |
| 598 | } else { |
| 599 | mDialpadFragment.setYFraction(0); |
| 600 | } |
| 601 | |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 602 | updateSearchFragmentPosition(); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | /** |
| 606 | * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in |
| 607 | * a callback after the hide animation ends. |
| 608 | * @see #commitDialpadFragmentHide |
| 609 | */ |
Yorke Lee | ca19504 | 2013-09-25 16:29:38 -0700 | [diff] [blame] | 610 | public void hideDialpadFragment(boolean animate, boolean clearDialpad) { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 611 | if (mDialpadFragment == null) { |
| 612 | return; |
| 613 | } |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 614 | if (clearDialpad) { |
| 615 | mDialpadFragment.clearDialpad(); |
| 616 | } |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 617 | if (!mIsDialpadShown) { |
| 618 | return; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 619 | } |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 620 | mIsDialpadShown = false; |
| 621 | mDialpadFragment.setAnimate(animate); |
| 622 | |
Andrew Lee | dbe9a8c | 2014-05-16 15:18:40 -0700 | [diff] [blame] | 623 | updateSearchFragmentPosition(); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 624 | updateFloatingActionButton(); |
| 625 | if (animate) { |
| 626 | Animation slideOut = AnimationUtils.loadAnimation(this, R.anim.slide_out); |
Andrew Lee | 3c14bc3 | 2014-05-28 15:43:03 -0700 | [diff] [blame] | 627 | slideOut.setAnimationListener(new AnimationListenerAdapter() { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 628 | @Override |
| 629 | public void onAnimationEnd(Animation animation) { |
| 630 | commitDialpadFragmentHide(); |
| 631 | } |
| 632 | }); |
| 633 | mDialpadFragment.getView().startAnimation(slideOut); |
| 634 | } else { |
| 635 | commitDialpadFragmentHide(); |
| 636 | } |
| 637 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 638 | mActionBarController.onDialpadDown(); |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 639 | |
Andrew Lee | d4cde83 | 2014-05-16 15:56:48 -0700 | [diff] [blame] | 640 | if (isInSearchUi()) { |
Andrew Lee | 44e3daf | 2014-05-19 14:28:16 -0700 | [diff] [blame] | 641 | if (TextUtils.isEmpty(mSearchQuery)) { |
| 642 | exitSearchUi(); |
Andrew Lee | 44e3daf | 2014-05-19 14:28:16 -0700 | [diff] [blame] | 643 | } |
Andrew Lee | d4cde83 | 2014-05-16 15:56:48 -0700 | [diff] [blame] | 644 | } |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /** |
| 648 | * Finishes hiding the dialpad fragment after any animations are completed. |
| 649 | */ |
| 650 | private void commitDialpadFragmentHide() { |
| 651 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 652 | ft.hide(mDialpadFragment); |
| 653 | ft.commit(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 656 | private void updateSearchFragmentPosition() { |
| 657 | int translationValue = mIsDialpadShown ? -mActionBarHeight : 0; |
| 658 | SearchFragment fragment = null; |
Andrew Lee | dbe9a8c | 2014-05-16 15:18:40 -0700 | [diff] [blame] | 659 | if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 660 | fragment = mSmartDialSearchFragment; |
Andrew Lee | dbe9a8c | 2014-05-16 15:18:40 -0700 | [diff] [blame] | 661 | } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 662 | fragment = mRegularSearchFragment; |
| 663 | } |
| 664 | if (fragment != null && fragment.isVisible()) { |
| 665 | fragment.getView().animate().translationY(translationValue) |
| 666 | .setInterpolator(hideActionBarInterpolator).setDuration(ANIMATION_DURATION); |
| 667 | } |
| 668 | } |
| 669 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 670 | @Override |
| 671 | public boolean isInSearchUi() { |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 672 | return mInDialpadSearch || mInRegularSearch; |
| 673 | } |
| 674 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 675 | @Override |
| 676 | public boolean hasSearchQuery() { |
| 677 | return !TextUtils.isEmpty(mSearchQuery); |
| 678 | } |
| 679 | |
| 680 | @Override |
| 681 | public boolean shouldShowActionBar() { |
| 682 | return mListsFragment.shouldShowActionBar(); |
| 683 | } |
| 684 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 685 | private void setNotInSearchUi() { |
| 686 | mInDialpadSearch = false; |
| 687 | mInRegularSearch = false; |
| 688 | } |
| 689 | |
Yorke Lee | 311969c | 2013-08-26 06:31:11 -0700 | [diff] [blame] | 690 | private void hideDialpadAndSearchUi() { |
Yorke Lee | 710709d | 2014-05-29 07:18:42 -0700 | [diff] [blame^] | 691 | if (mIsDialpadShown) { |
| 692 | hideDialpadFragment(false, true); |
| 693 | } else { |
| 694 | exitSearchUi(); |
| 695 | } |
Yorke Lee | 311969c | 2013-08-26 06:31:11 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 698 | private void hideInputMethod(View view) { |
| 699 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 700 | Context.INPUT_METHOD_SERVICE); |
| 701 | if (imm != null && view != null) { |
| 702 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0); |
| 703 | } |
| 704 | } |
| 705 | |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 706 | private void prepareVoiceSearchButton() { |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 707 | final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); |
| 708 | if (canIntentBeHandled(voiceIntent)) { |
| 709 | mVoiceSearchButton.setVisibility(View.VISIBLE); |
| 710 | mVoiceSearchButton.setOnClickListener(this); |
| 711 | } else { |
| 712 | mVoiceSearchButton.setVisibility(View.GONE); |
| 713 | } |
| 714 | } |
| 715 | |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 716 | private OptionsPopupMenu buildOptionsMenu(View invoker) { |
| 717 | final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker); |
| 718 | popupMenu.inflate(R.menu.dialtacts_options); |
| 719 | popupMenu.setOnMenuItemClickListener(this); |
| 720 | return popupMenu; |
| 721 | } |
| 722 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 723 | @Override |
| 724 | public boolean onCreateOptionsMenu(Menu menu) { |
Yorke Lee | 3c9e7cd | 2014-04-16 11:37:21 -0700 | [diff] [blame] | 725 | if (mPendingSearchViewQuery != null) { |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 726 | mSearchView.setText(mPendingSearchViewQuery); |
Yorke Lee | 3c9e7cd | 2014-04-16 11:37:21 -0700 | [diff] [blame] | 727 | mPendingSearchViewQuery = null; |
| 728 | } |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 729 | return false; |
Ihab Awad | fb00cb8 | 2014-03-18 16:19:00 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 732 | /** |
| 733 | * Returns true if the intent is due to hitting the green send key (hardware call button: |
| 734 | * KEYCODE_CALL) while in a call. |
| 735 | * |
| 736 | * @param intent the intent that launched this activity |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 737 | * @return true if the intent is due to hitting the green send key while in a call |
| 738 | */ |
Yorke Lee | 62e995c | 2014-03-28 10:02:56 -0700 | [diff] [blame] | 739 | private boolean isSendKeyWhileInCall(Intent intent) { |
| 740 | // If there is a call in progress and the user launched the dialer by hitting the call |
| 741 | // button, go straight to the in-call screen. |
| 742 | final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 743 | |
Yorke Lee | 62e995c | 2014-03-28 10:02:56 -0700 | [diff] [blame] | 744 | try { |
| 745 | ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); |
| 746 | if (callKey && phone != null && phone.showCallScreen()) { |
| 747 | return true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 748 | } |
Yorke Lee | 62e995c | 2014-03-28 10:02:56 -0700 | [diff] [blame] | 749 | } catch (RemoteException e) { |
| 750 | Log.e(TAG, "Failed to handle send while in call", e); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | return false; |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Sets the current tab based on the intent's request type |
| 758 | * |
| 759 | * @param intent Intent that contains information about which tab should be selected |
| 760 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 761 | private void displayFragment(Intent intent) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 762 | // If we got here by hitting send and we're in call forward along to the in-call activity |
Yorke Lee | 62e995c | 2014-03-28 10:02:56 -0700 | [diff] [blame] | 763 | if (isSendKeyWhileInCall(intent)) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 764 | finish(); |
| 765 | return; |
| 766 | } |
| 767 | |
Yorke Lee | 669b608 | 2013-09-17 15:43:38 -0700 | [diff] [blame] | 768 | if (mDialpadFragment != null) { |
| 769 | final boolean phoneIsInUse = phoneIsInUse(); |
| 770 | if (phoneIsInUse || isDialIntent(intent)) { |
| 771 | mDialpadFragment.setStartedFromNewIntent(true); |
| 772 | if (phoneIsInUse && !mDialpadFragment.isVisible()) { |
| 773 | mInCallDialpadUp = true; |
| 774 | } |
| 775 | showDialpadFragment(false); |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 776 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 777 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | @Override |
| 781 | public void onNewIntent(Intent newIntent) { |
| 782 | setIntent(newIntent); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 783 | displayFragment(newIntent); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 784 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 785 | invalidateOptionsMenu(); |
| 786 | } |
| 787 | |
| 788 | /** Returns true if the given intent contains a phone number to populate the dialer with */ |
| 789 | private boolean isDialIntent(Intent intent) { |
| 790 | final String action = intent.getAction(); |
| 791 | if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) { |
| 792 | return true; |
| 793 | } |
| 794 | if (Intent.ACTION_VIEW.equals(action)) { |
| 795 | final Uri data = intent.getData(); |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 796 | if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 797 | return true; |
| 798 | } |
| 799 | } |
| 800 | return false; |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Returns an appropriate call origin for this Activity. May return null when no call origin |
| 805 | * should be used (e.g. when some 3rd party application launched the screen. Call origin is |
| 806 | * for remembering the tab in which the user made a phone call, so the external app's DIAL |
| 807 | * request should not be counted.) |
| 808 | */ |
| 809 | public String getCallOrigin() { |
| 810 | return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null; |
| 811 | } |
| 812 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 813 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 814 | * Shows the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 815 | */ |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 816 | private void enterSearchUi(boolean smartDialSearch, String query) { |
Andrew Lee | 90374a7 | 2014-05-16 15:01:09 -0700 | [diff] [blame] | 817 | if (getFragmentManager().isDestroyed()) { |
Yorke Lee | 34bdf87 | 2013-08-15 14:11:50 -0700 | [diff] [blame] | 818 | // Weird race condition where fragment is doing work after the activity is destroyed |
| 819 | // due to talkback being on (b/10209937). Just return since we can't do any |
| 820 | // constructive here. |
| 821 | return; |
| 822 | } |
| 823 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 824 | if (DEBUG) { |
| 825 | Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch); |
| 826 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 827 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 828 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 829 | if (mInDialpadSearch && mSmartDialSearchFragment != null) { |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 830 | transaction.remove(mSmartDialSearchFragment); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 831 | } else if (mInRegularSearch && mRegularSearchFragment != null) { |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 832 | transaction.remove(mRegularSearchFragment); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 833 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 834 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 835 | final String tag; |
| 836 | if (smartDialSearch) { |
| 837 | tag = TAG_SMARTDIAL_SEARCH_FRAGMENT; |
| 838 | } else { |
| 839 | tag = TAG_REGULAR_SEARCH_FRAGMENT; |
| 840 | } |
| 841 | mInDialpadSearch = smartDialSearch; |
| 842 | mInRegularSearch = !smartDialSearch; |
| 843 | |
Andrew Lee | 752956e | 2014-05-15 11:43:38 -0700 | [diff] [blame] | 844 | SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 845 | transaction.setCustomAnimations(android.R.animator.fade_in, 0); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 846 | if (fragment == null) { |
| 847 | if (smartDialSearch) { |
| 848 | fragment = new SmartDialSearchFragment(); |
| 849 | } else { |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 850 | fragment = new RegularSearchFragment(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 851 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 852 | transaction.add(R.id.dialtacts_frame, fragment, tag); |
| 853 | } else { |
| 854 | transaction.show(fragment); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 855 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 856 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 857 | // DialtactsActivity will provide the options menu |
| 858 | fragment.setHasOptionsMenu(false); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 859 | fragment.setShowEmptyListForNullQuery(true); |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 860 | fragment.setQueryString(query, false /* delaySelection */); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 861 | transaction.commit(); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 862 | |
| 863 | mListsFragment.getView().animate().alpha(0).withLayer(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 867 | * Hides the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 868 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 869 | private void exitSearchUi() { |
Yorke Lee | 3487db7 | 2013-09-26 17:12:06 -0700 | [diff] [blame] | 870 | // See related bug in enterSearchUI(); |
| 871 | if (getFragmentManager().isDestroyed()) { |
| 872 | return; |
| 873 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 874 | |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 875 | mSearchView.setText(null); |
| 876 | mDialpadFragment.clearDialpad(); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 877 | setNotInSearchUi(); |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame] | 878 | |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 879 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 880 | if (mSmartDialSearchFragment != null) { |
| 881 | transaction.remove(mSmartDialSearchFragment); |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame] | 882 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 883 | if (mRegularSearchFragment != null) { |
| 884 | transaction.remove(mRegularSearchFragment); |
| 885 | } |
| 886 | transaction.commit(); |
| 887 | |
| 888 | mListsFragment.getView().animate().alpha(1).withLayer(); |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 889 | mActionBarController.onSearchUiExited(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | /** Returns an Intent to launch Call Settings screen */ |
| 893 | public static Intent getCallSettingsIntent() { |
| 894 | final Intent intent = new Intent(Intent.ACTION_MAIN); |
| 895 | intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME); |
| 896 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 897 | return intent; |
| 898 | } |
| 899 | |
| 900 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 901 | public void onBackPressed() { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 902 | if (mIsDialpadShown) { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 903 | if (TextUtils.isEmpty(mSearchQuery)) { |
| 904 | exitSearchUi(); |
| 905 | } |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 906 | hideDialpadFragment(true, false); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 907 | } else if (isInSearchUi()) { |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 908 | exitSearchUi(); |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 909 | hideInputMethod(parentLayout); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 910 | } else { |
| 911 | super.onBackPressed(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 912 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Yorke Lee | c7b2a0e | 2014-05-20 17:21:25 -0700 | [diff] [blame] | 915 | /** |
| 916 | * @return True if the search UI was exited, false otherwise |
| 917 | */ |
| 918 | private boolean maybeExitSearchUi() { |
| 919 | if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) { |
| 920 | exitSearchUi(); |
| 921 | hideInputMethod(parentLayout); |
| 922 | return true; |
| 923 | } |
| 924 | return false; |
| 925 | } |
| 926 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 927 | @Override |
| 928 | public void onDialpadQueryChanged(String query) { |
Yorke Lee | 4663587 | 2014-04-11 11:20:15 -0700 | [diff] [blame] | 929 | if (mSmartDialSearchFragment != null) { |
| 930 | mSmartDialSearchFragment.setAddToContactNumber(query); |
| 931 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 932 | final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query, |
| 933 | SmartDialNameMatcher.LATIN_SMART_DIAL_MAP); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 934 | |
| 935 | if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 936 | if (DEBUG) { |
| 937 | Log.d(TAG, "onDialpadQueryChanged - new query: " + query); |
| 938 | } |
| 939 | if (mDialpadFragment == null || !mDialpadFragment.isVisible()) { |
| 940 | // This callback can happen if the dialpad fragment is recreated because of |
| 941 | // activity destruction. In that case, don't update the search view because |
| 942 | // that would bring the user back to the search fragment regardless of the |
| 943 | // previous state of the application. Instead, just return here and let the |
| 944 | // fragment manager correctly figure out whatever fragment was last displayed. |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 945 | if (!TextUtils.isEmpty(normalizedQuery)) { |
| 946 | mPendingSearchViewQuery = normalizedQuery; |
| 947 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 948 | return; |
| 949 | } |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 950 | mSearchView.setText(normalizedQuery); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 951 | } |
| 952 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 953 | |
| 954 | @Override |
| 955 | public void onListFragmentScrollStateChange(int scrollState) { |
| 956 | if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 957 | hideDialpadFragment(true, false); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 958 | hideInputMethod(getCurrentFocus()); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | @Override |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 963 | public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount, |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 964 | int totalItemCount) { |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 965 | // TODO: No-op for now. This should eventually show/hide the actionBar based on |
| 966 | // interactions with the ListsFragments. |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 967 | } |
| 968 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 969 | @Override |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 970 | public void setFloatingActionButtonVisible(boolean visible) { |
| 971 | mFloatingActionButtonContainer.setVisibility(visible ? View.VISIBLE : View.GONE); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | private boolean phoneIsInUse() { |
| 975 | final TelephonyManager tm = (TelephonyManager) getSystemService( |
| 976 | Context.TELEPHONY_SERVICE); |
| 977 | return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE; |
| 978 | } |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 979 | |
Yorke Lee | e142481 | 2013-09-04 18:24:48 -0700 | [diff] [blame] | 980 | public static Intent getAddNumberToContactIntent(CharSequence text) { |
| 981 | final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 982 | intent.putExtra(Intents.Insert.PHONE, text); |
| 983 | intent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 984 | return intent; |
| 985 | } |
| 986 | |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 987 | private boolean canIntentBeHandled(Intent intent) { |
| 988 | final PackageManager packageManager = getPackageManager(); |
| 989 | final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, |
| 990 | PackageManager.MATCH_DEFAULT_ONLY); |
| 991 | return resolveInfo != null && resolveInfo.size() > 0; |
| 992 | } |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 993 | |
Yorke Lee | 6a1461a | 2014-04-21 16:27:14 -0700 | [diff] [blame] | 994 | @Override |
| 995 | public void showCallHistory() { |
| 996 | // Use explicit CallLogActivity intent instead of ACTION_VIEW + |
| 997 | // CONTENT_TYPE, so that we always open our call log from our dialer |
| 998 | final Intent intent = new Intent(this, CallLogActivity.class); |
| 999 | startActivity(intent); |
| 1000 | } |
| 1001 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 1002 | /** |
| 1003 | * Called when the user has long-pressed a contact tile to start a drag operation. |
| 1004 | */ |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1005 | @Override |
Yorke Lee | efb2d9c | 2014-04-18 14:05:01 -0700 | [diff] [blame] | 1006 | public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) { |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1007 | mActionBarController.slideActionBarUp(true); |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 1008 | mRemoveViewContainer.setVisibility(View.VISIBLE); |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | @Override |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 1012 | public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) { |
| 1013 | } |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1014 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 1015 | /** |
| 1016 | * Called when the user has released a contact tile after long-pressing it. |
| 1017 | */ |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1018 | @Override |
| 1019 | public void onDragFinished(int x, int y) { |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1020 | mActionBarController.slideActionBarDown(true); |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 1021 | mRemoveViewContainer.setVisibility(View.GONE); |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | @Override |
| 1025 | public void onDroppedOnRemove() {} |
| 1026 | |
| 1027 | /** |
Yorke Lee | d999b71 | 2014-04-23 15:10:58 -0700 | [diff] [blame] | 1028 | * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1029 | * once it has been attached to the activity. |
| 1030 | */ |
| 1031 | @Override |
| 1032 | public void setDragDropController(DragDropController dragController) { |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 1033 | mDragDropController = dragController; |
| 1034 | ((RemoveView) findViewById(R.id.remove_view)) |
| 1035 | .setDragDropController(dragController); |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1036 | } |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1037 | |
| 1038 | @Override |
| 1039 | public void onPickPhoneNumberAction(Uri dataUri) { |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 1040 | // Specify call-origin so that users will see the previous tab instead of |
| 1041 | // CallLog screen (search UI will be automatically exited). |
| 1042 | PhoneNumberInteraction.startInteractionForPhoneCall( |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 1043 | DialtactsActivity.this, dataUri, getCallOrigin()); |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 1044 | mClearSearchOnPause = true; |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | @Override |
| 1048 | public void onCallNumberDirectly(String phoneNumber) { |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 1049 | Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); |
| 1050 | startActivity(intent); |
| 1051 | mClearSearchOnPause = true; |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | @Override |
| 1055 | public void onShortcutIntentCreated(Intent intent) { |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 1056 | Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring."); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | @Override |
| 1060 | public void onHomeInActionBarSelected() { |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 1061 | exitSearchUi(); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1062 | } |
Yorke Lee | 33932ff | 2014-04-16 13:34:32 -0700 | [diff] [blame] | 1063 | |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1064 | @Override |
| 1065 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
| 1066 | |
| 1067 | } |
| 1068 | |
| 1069 | @Override |
| 1070 | public void onPageSelected(int position) { |
| 1071 | mCurrentTabPosition = position; |
Yorke Lee | c61d454 | 2014-05-01 10:43:24 -0700 | [diff] [blame] | 1072 | // If the dialpad is showing, the floating action button should always be middle aligned. |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 1073 | if (!mIsDialpadShown) { |
Yorke Lee | c61d454 | 2014-05-01 10:43:24 -0700 | [diff] [blame] | 1074 | alignFloatingActionButtonByTab(mCurrentTabPosition); |
| 1075 | } |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | @Override |
| 1079 | public void onPageScrollStateChanged(int state) { |
| 1080 | } |
| 1081 | |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 1082 | private void updateFloatingActionButton() { |
| 1083 | if (mIsDialpadShown) { |
| 1084 | mFloatingActionButton.setImageResource(R.drawable.fab_ic_call); |
| 1085 | mFloatingActionButton.setContentDescription( |
| 1086 | getResources().getString(R.string.description_dial_button)); |
Andrew Lee | c4643f7 | 2014-05-15 11:27:39 -0700 | [diff] [blame] | 1087 | alignFloatingActionButtonMiddle(); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 1088 | } else { |
| 1089 | mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial); |
| 1090 | mFloatingActionButton.setContentDescription( |
| 1091 | getResources().getString(R.string.action_menu_dialpad_button)); |
Andrew Lee | c4643f7 | 2014-05-15 11:27:39 -0700 | [diff] [blame] | 1092 | alignFloatingActionButtonByTab(mCurrentTabPosition); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 1093 | } |
| 1094 | } |
| 1095 | |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1096 | private void alignFloatingActionButtonByTab(int position) { |
| 1097 | if (position == ListsFragment.TAB_INDEX_SPEED_DIAL) { |
| 1098 | alignFloatingActionButtonMiddle(); |
| 1099 | } else { |
| 1100 | alignFloatingActionButtonRight(); |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | private void alignFloatingActionButtonRight() { |
| 1105 | final RelativeLayout.LayoutParams params = |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 1106 | (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams(); |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1107 | params.removeRule(RelativeLayout.CENTER_HORIZONTAL); |
| 1108 | params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 1109 | mFloatingActionButtonContainer.setLayoutParams(params); |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | private void alignFloatingActionButtonMiddle() { |
| 1113 | final RelativeLayout.LayoutParams params = |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 1114 | (RelativeLayout.LayoutParams) mFloatingActionButtonContainer.getLayoutParams(); |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1115 | params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT); |
| 1116 | params.addRule(RelativeLayout.CENTER_HORIZONTAL); |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 1117 | mFloatingActionButtonContainer.setLayoutParams(params); |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1118 | } |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 1119 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1120 | @Override |
| 1121 | public boolean isActionBarShowing() { |
| 1122 | return mActionBarController.isActionBarShowing(); |
| 1123 | } |
| 1124 | |
| 1125 | @Override |
| 1126 | public int getActionBarHideOffset() { |
| 1127 | return getActionBar().getHideOffset(); |
| 1128 | } |
| 1129 | |
| 1130 | @Override |
| 1131 | public int getActionBarHeight() { |
| 1132 | return mActionBarHeight; |
| 1133 | } |
| 1134 | |
| 1135 | @Override |
| 1136 | public void setActionBarHideOffset(int hideOffset) { |
| 1137 | getActionBar().setHideOffset(hideOffset); |
| 1138 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1139 | } |