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