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