The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 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.contacts; |
| 18 | |
Jeff Hamilton | df4b146 | 2010-06-28 10:40:26 -0500 | [diff] [blame] | 19 | import com.android.contacts.activities.ContactsFrontDoor; |
Dmitri Plotnikov | cfa3900 | 2010-07-09 18:05:17 -0700 | [diff] [blame^] | 20 | import com.android.contacts.activities.ContactBrowserActivity; |
Jeff Hamilton | b25c13e | 2009-09-21 09:22:16 -0500 | [diff] [blame] | 21 | import com.android.internal.telephony.ITelephony; |
| 22 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 23 | import android.app.Activity; |
| 24 | import android.app.TabActivity; |
| 25 | import android.content.Intent; |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 26 | import android.content.SharedPreferences; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 27 | import android.net.Uri; |
| 28 | import android.os.Bundle; |
| 29 | import android.os.RemoteException; |
| 30 | import android.os.ServiceManager; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 31 | import android.provider.CallLog.Calls; |
Jeff Hamilton | b25c13e | 2009-09-21 09:22:16 -0500 | [diff] [blame] | 32 | import android.provider.ContactsContract.Intents.UI; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 33 | import android.util.Log; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 34 | import android.view.Window; |
| 35 | import android.widget.TabHost; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 38 | * The dialer activity that has one tab with the virtual 12key |
| 39 | * dialer, a tab with recent calls in it, a tab with the contacts and |
| 40 | * a tab with the favorite. This is the container and the tabs are |
| 41 | * embedded using intents. |
| 42 | * The dialer tab's title is 'phone', a more common name (see strings.xml). |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 43 | */ |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 44 | public class DialtactsActivity extends TabActivity implements TabHost.OnTabChangeListener { |
| 45 | private static final String TAG = "Dailtacts"; |
| 46 | private static final String FAVORITES_ENTRY_COMPONENT = |
| 47 | "com.android.contacts.DialtactsFavoritesEntryActivity"; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 48 | |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 49 | /** Opens the Contacts app in the state the user has last set it to */ |
| 50 | private static final String CONTACTS_LAUNCH_ACTIVITY = |
| 51 | "com.android.contacts.ContactsLaunchActivity"; |
| 52 | |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 53 | private static final int TAB_INDEX_DIALER = 0; |
| 54 | private static final int TAB_INDEX_CALL_LOG = 1; |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 55 | private static final int TAB_INDEX_CONTACTS = 2; |
| 56 | private static final int TAB_INDEX_FAVORITES = 3; |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 57 | |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 58 | static final String EXTRA_IGNORE_STATE = "ignore-state"; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 59 | |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 60 | /** Name of the dialtacts shared preferences */ |
| 61 | static final String PREFS_DIALTACTS = "dialtacts"; |
| 62 | /** If true, when handling the contacts intent the favorites tab will be shown instead */ |
| 63 | static final String PREF_FAVORITES_AS_CONTACTS = "favorites_as_contacts"; |
| 64 | static final boolean PREF_FAVORITES_AS_CONTACTS_DEFAULT = false; |
| 65 | |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 66 | /** Last manually selected tab index */ |
| 67 | private static final String PREF_LAST_MANUALLY_SELECTED_TAB = "last_manually_selected_tab"; |
| 68 | private static final int PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT = TAB_INDEX_DIALER; |
| 69 | |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 70 | private TabHost mTabHost; |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 71 | private String mFilterText; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 72 | private Uri mDialUri; |
| 73 | |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 74 | /** |
| 75 | * The index of the tab that has last been manually selected (the user clicked on a tab). |
| 76 | * This value does not keep track of programmatically set Tabs (e.g. Call Log after a Call) |
| 77 | */ |
| 78 | private int mLastManuallySelectedTab; |
| 79 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 80 | @Override |
| 81 | protected void onCreate(Bundle icicle) { |
| 82 | super.onCreate(icicle); |
| 83 | |
| 84 | final Intent intent = getIntent(); |
| 85 | fixIntent(intent); |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 86 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 87 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
| 88 | setContentView(R.layout.dialer_activity); |
| 89 | |
| 90 | mTabHost = getTabHost(); |
| 91 | mTabHost.setOnTabChangedListener(this); |
| 92 | |
| 93 | // Setup the tabs |
| 94 | setupDialerTab(); |
| 95 | setupCallLogTab(); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 96 | setupContactsTab(); |
| 97 | setupFavoritesTab(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 98 | |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 99 | // Load the last manually loaded tab |
| 100 | final SharedPreferences prefs = getSharedPreferences(PREFS_DIALTACTS, MODE_PRIVATE); |
| 101 | mLastManuallySelectedTab = prefs.getInt(PREF_LAST_MANUALLY_SELECTED_TAB, |
| 102 | PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT); |
| 103 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 104 | setCurrentTab(intent); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 105 | |
Jeff Hamilton | 7fa3cd6 | 2010-06-30 11:36:58 -0500 | [diff] [blame] | 106 | if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction()) |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 107 | && icicle == null) { |
| 108 | setupFilterText(intent); |
| 109 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 112 | @Override |
| 113 | protected void onPause() { |
| 114 | super.onPause(); |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 115 | |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 116 | final int currentTabIndex = mTabHost.getCurrentTab(); |
| 117 | final SharedPreferences.Editor editor = |
| 118 | getSharedPreferences(PREFS_DIALTACTS, MODE_PRIVATE).edit(); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 119 | if (currentTabIndex == TAB_INDEX_CONTACTS || currentTabIndex == TAB_INDEX_FAVORITES) { |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 120 | editor.putBoolean(PREF_FAVORITES_AS_CONTACTS, currentTabIndex == TAB_INDEX_FAVORITES); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 121 | } |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 122 | editor.putInt(PREF_LAST_MANUALLY_SELECTED_TAB, mLastManuallySelectedTab); |
| 123 | |
| 124 | editor.commit(); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 125 | } |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 126 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 127 | private void fixIntent(Intent intent) { |
| 128 | // This should be cleaned up: the call key used to send an Intent |
| 129 | // that just said to go to the recent calls list. It now sends this |
| 130 | // abstract action, but this class hasn't been rewritten to deal with it. |
| 131 | if (Intent.ACTION_CALL_BUTTON.equals(intent.getAction())) { |
| 132 | intent.setDataAndType(Calls.CONTENT_URI, Calls.CONTENT_TYPE); |
| 133 | intent.putExtra("call_key", true); |
| 134 | setIntent(intent); |
| 135 | } |
| 136 | } |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 137 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 138 | private void setupCallLogTab() { |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 139 | // Force the class since overriding tab entries doesn't work |
| 140 | Intent intent = new Intent("com.android.phone.action.RECENT_CALLS"); |
| 141 | intent.setClass(this, RecentCallsListActivity.class); |
| 142 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 143 | mTabHost.addTab(mTabHost.newTabSpec("call_log") |
| 144 | .setIndicator(getString(R.string.recentCallsIconLabel), |
| 145 | getResources().getDrawable(R.drawable.ic_tab_recent)) |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 146 | .setContent(intent)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | private void setupDialerTab() { |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 150 | Intent intent = new Intent("com.android.phone.action.TOUCH_DIALER"); |
| 151 | intent.setClass(this, TwelveKeyDialer.class); |
| 152 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 153 | mTabHost.addTab(mTabHost.newTabSpec("dialer") |
| 154 | .setIndicator(getString(R.string.dialerIconLabel), |
| 155 | getResources().getDrawable(R.drawable.ic_tab_dialer)) |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 156 | .setContent(intent)); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 159 | private void setupContactsTab() { |
| 160 | Intent intent = new Intent(UI.LIST_DEFAULT); |
Dmitri Plotnikov | cfa3900 | 2010-07-09 18:05:17 -0700 | [diff] [blame^] | 161 | intent.setClass(this, ContactBrowserActivity.class); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 162 | |
| 163 | mTabHost.addTab(mTabHost.newTabSpec("contacts") |
| 164 | .setIndicator(getText(R.string.contactsIconLabel), |
| 165 | getResources().getDrawable(R.drawable.ic_tab_contacts)) |
| 166 | .setContent(intent)); |
| 167 | } |
| 168 | |
| 169 | private void setupFavoritesTab() { |
| 170 | Intent intent = new Intent(UI.LIST_STREQUENT_ACTION); |
Dmitri Plotnikov | cfa3900 | 2010-07-09 18:05:17 -0700 | [diff] [blame^] | 171 | intent.setClass(this, ContactBrowserActivity.class); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 172 | |
| 173 | mTabHost.addTab(mTabHost.newTabSpec("favorites") |
| 174 | .setIndicator(getString(R.string.contactsFavoritesLabel), |
| 175 | getResources().getDrawable(R.drawable.ic_tab_starred)) |
| 176 | .setContent(intent)); |
| 177 | } |
| 178 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 179 | /** |
| 180 | * Returns true if the intent is due to hitting the green send key while in a call. |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 181 | * |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 182 | * @param intent the intent that launched this activity |
| 183 | * @param recentCallsRequest true if the intent is requesting to view recent calls |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 184 | * @return true if the intent is due to hitting the green send key while in a call |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 185 | */ |
| 186 | private boolean isSendKeyWhileInCall(final Intent intent, final boolean recentCallsRequest) { |
| 187 | // If there is a call in progress go to the call screen |
| 188 | if (recentCallsRequest) { |
| 189 | final boolean callKey = intent.getBooleanExtra("call_key", false); |
| 190 | |
| 191 | try { |
| 192 | ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); |
| 193 | if (callKey && phone != null && phone.showCallScreen()) { |
| 194 | return true; |
| 195 | } |
| 196 | } catch (RemoteException e) { |
| 197 | Log.e(TAG, "Failed to handle send while in call", e); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return false; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Sets the current tab based on the intent's request type |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 206 | * |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 207 | * @param intent Intent that contains information about which tab should be selected |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 208 | */ |
| 209 | private void setCurrentTab(Intent intent) { |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 210 | // If we got here by hitting send and we're in call forward along to the in-call activity |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 211 | final boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.getType()); |
| 212 | if (isSendKeyWhileInCall(intent, recentCallsRequest)) { |
| 213 | finish(); |
| 214 | return; |
| 215 | } |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 216 | |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 217 | // Dismiss menu provided by any children activities |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 218 | Activity activity = getLocalActivityManager(). |
| 219 | getActivity(mTabHost.getCurrentTabTag()); |
| 220 | if (activity != null) { |
| 221 | activity.closeOptionsMenu(); |
| 222 | } |
| 223 | |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 224 | // Tell the children activities that they should ignore any possible saved |
| 225 | // state and instead reload their state from the parent's intent |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 226 | intent.putExtra(EXTRA_IGNORE_STATE, true); |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 227 | |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 228 | // Remember the old manually selected tab index so that it can be restored if it is |
| 229 | // overwritten by one of the programmatic tab selections |
| 230 | final int savedTabIndex = mLastManuallySelectedTab; |
| 231 | |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 232 | // Choose the tab based on the inbound intent |
Jeff Hamilton | df4b146 | 2010-06-28 10:40:26 -0500 | [diff] [blame] | 233 | if (intent.getBooleanExtra(ContactsFrontDoor.EXTRA_FRONT_DOOR, false)) { |
| 234 | // Launched through the contacts front door, set the proper contacts tab |
| 235 | setContactsTab(); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 236 | } else { |
Jeff Hamilton | df4b146 | 2010-06-28 10:40:26 -0500 | [diff] [blame] | 237 | // Not launched through the front door, look at the component to determine the tab |
| 238 | String componentName = intent.getComponent().getClassName(); |
| 239 | if (getClass().getName().equals(componentName)) { |
| 240 | if (recentCallsRequest) { |
| 241 | mTabHost.setCurrentTab(TAB_INDEX_CALL_LOG); |
| 242 | } else { |
| 243 | mTabHost.setCurrentTab(TAB_INDEX_DIALER); |
| 244 | } |
| 245 | } else if (FAVORITES_ENTRY_COMPONENT.equals(componentName)) { |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 246 | mTabHost.setCurrentTab(TAB_INDEX_FAVORITES); |
Jeff Hamilton | df4b146 | 2010-06-28 10:40:26 -0500 | [diff] [blame] | 247 | } else if (CONTACTS_LAUNCH_ACTIVITY.equals(componentName)) { |
| 248 | mTabHost.setCurrentTab(mLastManuallySelectedTab); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 249 | } else { |
Jeff Hamilton | df4b146 | 2010-06-28 10:40:26 -0500 | [diff] [blame] | 250 | setContactsTab(); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 251 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 252 | } |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 253 | |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 254 | // Restore to the previous manual selection |
| 255 | mLastManuallySelectedTab = savedTabIndex; |
| 256 | |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 257 | // Tell the children activities that they should honor their saved states |
| 258 | // instead of the state from the parent's intent |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 259 | intent.putExtra(EXTRA_IGNORE_STATE, false); |
| 260 | } |
| 261 | |
Jeff Hamilton | df4b146 | 2010-06-28 10:40:26 -0500 | [diff] [blame] | 262 | private void setContactsTab() { |
| 263 | SharedPreferences prefs = getSharedPreferences(PREFS_DIALTACTS, MODE_PRIVATE); |
| 264 | boolean favoritesAsContacts = prefs.getBoolean(PREF_FAVORITES_AS_CONTACTS, |
| 265 | PREF_FAVORITES_AS_CONTACTS_DEFAULT); |
| 266 | if (favoritesAsContacts) { |
| 267 | mTabHost.setCurrentTab(TAB_INDEX_FAVORITES); |
| 268 | } else { |
| 269 | mTabHost.setCurrentTab(TAB_INDEX_CONTACTS); |
| 270 | } |
| 271 | } |
| 272 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 273 | @Override |
| 274 | public void onNewIntent(Intent newIntent) { |
| 275 | setIntent(newIntent); |
| 276 | fixIntent(newIntent); |
| 277 | setCurrentTab(newIntent); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 278 | final String action = newIntent.getAction(); |
Jeff Hamilton | 7fa3cd6 | 2010-06-30 11:36:58 -0500 | [diff] [blame] | 279 | if (UI.FILTER_CONTACTS_ACTION.equals(action)) { |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 280 | setupFilterText(newIntent); |
| 281 | } else if (isDialIntent(newIntent)) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 282 | setupDialUri(newIntent); |
| 283 | } |
| 284 | } |
The Android Open Source Project | 1f62096 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 285 | |
| 286 | /** Returns true if the given intent contains a phone number to populate the dialer with */ |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 287 | private boolean isDialIntent(Intent intent) { |
| 288 | final String action = intent.getAction(); |
| 289 | if (Intent.ACTION_DIAL.equals(action)) { |
| 290 | return true; |
| 291 | } |
| 292 | if (Intent.ACTION_VIEW.equals(action)) { |
| 293 | final Uri data = intent.getData(); |
| 294 | if (data != null && "tel".equals(data.getScheme())) { |
| 295 | return true; |
| 296 | } |
| 297 | } |
| 298 | return false; |
| 299 | } |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 300 | |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 301 | /** |
| 302 | * Retrieves the filter text stored in {@link #setupFilterText(Intent)}. |
| 303 | * This text originally came from a FILTER_CONTACTS_ACTION intent received |
| 304 | * by this activity. The stored text will then be cleared after after this |
| 305 | * method returns. |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 306 | * |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 307 | * @return The stored filter text |
| 308 | */ |
| 309 | public String getAndClearFilterText() { |
| 310 | String filterText = mFilterText; |
| 311 | mFilterText = null; |
| 312 | return filterText; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Stores the filter text associated with a FILTER_CONTACTS_ACTION intent. |
| 317 | * This is so child activities can check if they are supposed to display a filter. |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 318 | * |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 319 | * @param intent The intent received in {@link #onNewIntent(Intent)} |
| 320 | */ |
| 321 | private void setupFilterText(Intent intent) { |
| 322 | // If the intent was relaunched from history, don't apply the filter text. |
| 323 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { |
| 324 | return; |
| 325 | } |
Jeff Hamilton | b25c13e | 2009-09-21 09:22:16 -0500 | [diff] [blame] | 326 | String filter = intent.getStringExtra(UI.FILTER_TEXT_EXTRA_KEY); |
Jeff Hamilton | 9031377 | 2009-07-28 10:20:31 -0500 | [diff] [blame] | 327 | if (filter != null && filter.length() > 0) { |
| 328 | mFilterText = filter; |
| 329 | } |
| 330 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 331 | |
| 332 | /** |
| 333 | * Retrieves the uri stored in {@link #setupDialUri(Intent)}. This uri |
| 334 | * originally came from a dial intent received by this activity. The stored |
| 335 | * uri will then be cleared after after this method returns. |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 336 | * |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 337 | * @return The stored uri |
| 338 | */ |
| 339 | public Uri getAndClearDialUri() { |
| 340 | Uri dialUri = mDialUri; |
| 341 | mDialUri = null; |
| 342 | return dialUri; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Stores the uri associated with a dial intent. This is so child activities can |
| 347 | * check if they are supposed to display new dial info. |
Nicolas Catania | 0883240 | 2009-09-24 09:52:50 -0700 | [diff] [blame] | 348 | * |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 349 | * @param intent The intent received in {@link #onNewIntent(Intent)} |
| 350 | */ |
| 351 | private void setupDialUri(Intent intent) { |
| 352 | // If the intent was relaunched from history, don't reapply the intent. |
| 353 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { |
| 354 | return; |
| 355 | } |
| 356 | mDialUri = intent.getData(); |
| 357 | } |
| 358 | |
| 359 | @Override |
Dianne Hackborn | 242599a | 2009-09-14 21:33:24 -0700 | [diff] [blame] | 360 | public void onBackPressed() { |
| 361 | if (isTaskRoot()) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 362 | // Instead of stopping, simply push this to the back of the stack. |
| 363 | // This is only done when running at the top of the stack; |
| 364 | // otherwise, we have been launched by someone else so need to |
| 365 | // allow the user to go back to the caller. |
| 366 | moveTaskToBack(false); |
Dianne Hackborn | 242599a | 2009-09-14 21:33:24 -0700 | [diff] [blame] | 367 | } else { |
| 368 | super.onBackPressed(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 369 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /** {@inheritDoc} */ |
| 373 | public void onTabChanged(String tabId) { |
| 374 | // Because we're using Activities as our tab children, we trigger |
| 375 | // onWindowFocusChanged() to let them know when they're active. This may |
| 376 | // seem to duplicate the purpose of onResume(), but it's needed because |
| 377 | // onResume() can't reliably check if a keyguard is active. |
| 378 | Activity activity = getLocalActivityManager().getActivity(tabId); |
| 379 | if (activity != null) { |
| 380 | activity.onWindowFocusChanged(true); |
| 381 | } |
Daniel Lehmann | 7675e12 | 2010-04-21 17:31:11 -0700 | [diff] [blame] | 382 | |
| 383 | // Remember this tab index. This function is also called, if the tab is set automatically |
| 384 | // in which case the setter (setCurrentTab) has to set this to its old value afterwards |
| 385 | mLastManuallySelectedTab = mTabHost.getCurrentTab(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 386 | } |
| 387 | } |