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