The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Flavio Lerda | d1333a2 | 2011-08-11 16:19:47 +0100 | [diff] [blame] | 19 | import com.android.contacts.BackScrollManager.ScrollableHeader; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 20 | import com.android.contacts.calllog.CallDetailHistoryAdapter; |
| 21 | import com.android.contacts.calllog.CallTypeHelper; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 22 | import com.android.contacts.calllog.PhoneNumberHelper; |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 23 | import com.android.contacts.util.AsyncTaskExecutor; |
| 24 | import com.android.contacts.util.AsyncTaskExecutors; |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 25 | import com.android.contacts.voicemail.VoicemailPlaybackFragment; |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 26 | import com.android.contacts.voicemail.VoicemailStatusHelper; |
| 27 | import com.android.contacts.voicemail.VoicemailStatusHelper.StatusMessage; |
| 28 | import com.android.contacts.voicemail.VoicemailStatusHelperImpl; |
Amith Yamasani | 8bbe2f2 | 2009-03-24 21:24:12 -0700 | [diff] [blame] | 29 | |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 30 | import android.app.ActionBar; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 31 | import android.app.Activity; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 32 | import android.content.ContentResolver; |
| 33 | import android.content.ContentUris; |
Debashish Chatterjee | 0a13900 | 2011-08-02 18:27:11 +0100 | [diff] [blame] | 34 | import android.content.ContentValues; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 35 | import android.content.Context; |
| 36 | import android.content.Intent; |
| 37 | import android.content.res.Resources; |
| 38 | import android.database.Cursor; |
| 39 | import android.net.Uri; |
Hugo Hudson | a2625e4 | 2011-08-10 21:13:23 +0100 | [diff] [blame] | 40 | import android.os.AsyncTask; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.provider.CallLog; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 43 | import android.provider.CallLog.Calls; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 44 | import android.provider.Contacts.Intents.Insert; |
Flavio Lerda | 8ebfa3d | 2011-08-10 14:35:22 +0100 | [diff] [blame] | 45 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 46 | import android.provider.ContactsContract.Contacts; |
| 47 | import android.provider.ContactsContract.PhoneLookup; |
Debashish Chatterjee | 0a13900 | 2011-08-02 18:27:11 +0100 | [diff] [blame] | 48 | import android.provider.VoicemailContract.Voicemails; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 49 | import android.telephony.PhoneNumberUtils; |
| 50 | import android.telephony.TelephonyManager; |
| 51 | import android.text.TextUtils; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 52 | import android.util.Log; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 53 | import android.view.KeyEvent; |
| 54 | import android.view.LayoutInflater; |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 55 | import android.view.Menu; |
| 56 | import android.view.MenuItem; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 57 | import android.view.View; |
Daniel Lehmann | d260de4 | 2011-08-01 18:08:38 -0700 | [diff] [blame] | 58 | import android.widget.ImageButton; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 59 | import android.widget.ImageView; |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 60 | import android.widget.ListView; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 61 | import android.widget.TextView; |
| 62 | import android.widget.Toast; |
| 63 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 64 | import java.util.List; |
| 65 | |
| 66 | /** |
| 67 | * Displays the details of a specific call log entry. |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 68 | * <p> |
| 69 | * This activity can be either started with the URI of a single call log entry, or with the |
| 70 | * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 71 | */ |
Flavio Lerda | fd1b98b | 2011-08-24 19:55:15 +0100 | [diff] [blame] | 72 | public class CallDetailActivity extends Activity implements ProximitySensorAware { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 73 | private static final String TAG = "CallDetail"; |
| 74 | |
Flavio Lerda | fd1b98b | 2011-08-24 19:55:15 +0100 | [diff] [blame] | 75 | /** The time to wait before enabling the blank the screen due to the proximity sensor. */ |
| 76 | private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100; |
| 77 | /** The time to wait before disabling the blank the screen due to the proximity sensor. */ |
| 78 | private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500; |
| 79 | |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 80 | /** The enumeration of {@link AsyncTask} objects used in this class. */ |
| 81 | public enum Tasks { |
| 82 | MARK_VOICEMAIL_READ, |
| 83 | DELETE_VOICEMAIL_AND_FINISH, |
| 84 | REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 85 | UPDATE_PHONE_CALL_DETAILS, |
| 86 | } |
| 87 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 88 | /** A long array extra containing ids of call log entries to display. */ |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 89 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 90 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 91 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
| 92 | /** If we should immediately start playback of the voicemail, this extra will be set to true. */ |
| 93 | public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 94 | |
Flavio Lerda | 9a208cc | 2011-07-12 21:05:47 +0100 | [diff] [blame] | 95 | private CallTypeHelper mCallTypeHelper; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 96 | private PhoneNumberHelper mPhoneNumberHelper; |
Flavio Lerda | afb93bb | 2011-07-05 14:46:10 +0100 | [diff] [blame] | 97 | private PhoneCallDetailsHelper mPhoneCallDetailsHelper; |
Flavio Lerda | b88abaa | 2011-08-02 23:38:36 +0100 | [diff] [blame] | 98 | private TextView mHeaderTextView; |
Flavio Lerda | 126a420 | 2011-10-03 11:15:03 +0100 | [diff] [blame^] | 99 | private View mHeaderOverlayView; |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 100 | private ImageView mMainActionView; |
Daniel Lehmann | d260de4 | 2011-08-01 18:08:38 -0700 | [diff] [blame] | 101 | private ImageButton mMainActionPushLayerView; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 102 | private ImageView mContactBackgroundView; |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 103 | private AsyncTaskExecutor mAsyncTaskExecutor; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 104 | |
| 105 | private String mNumber = null; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 106 | private String mDefaultCountryIso; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 107 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 108 | /* package */ LayoutInflater mInflater; |
| 109 | /* package */ Resources mResources; |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 110 | /** Helper to load contact photos. */ |
| 111 | private ContactPhotoManager mContactPhotoManager; |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 112 | /** Helper to make async queries to content resolver. */ |
| 113 | private CallDetailActivityQueryHandler mAsyncQueryHandler; |
| 114 | /** Helper to get voicemail status messages. */ |
| 115 | private VoicemailStatusHelper mVoicemailStatusHelper; |
| 116 | // Views related to voicemail status message. |
| 117 | private View mStatusMessageView; |
| 118 | private TextView mStatusMessageText; |
| 119 | private TextView mStatusMessageAction; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 120 | |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 121 | /** Whether we should show "edit number before call" in the options menu. */ |
| 122 | private boolean mHasEditNumberBeforeCall; |
| 123 | |
Flavio Lerda | fd1b98b | 2011-08-24 19:55:15 +0100 | [diff] [blame] | 124 | private ProximitySensorManager mProximitySensorManager; |
| 125 | private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener(); |
| 126 | |
| 127 | /** Listener to changes in the proximity sensor state. */ |
| 128 | private class ProximitySensorListener implements ProximitySensorManager.Listener { |
| 129 | /** Used to show a blank view and hide the action bar. */ |
| 130 | private final Runnable mBlankRunnable = new Runnable() { |
| 131 | @Override |
| 132 | public void run() { |
| 133 | View blankView = findViewById(R.id.blank); |
| 134 | blankView.setVisibility(View.VISIBLE); |
| 135 | getActionBar().hide(); |
| 136 | } |
| 137 | }; |
| 138 | /** Used to remove the blank view and show the action bar. */ |
| 139 | private final Runnable mUnblankRunnable = new Runnable() { |
| 140 | @Override |
| 141 | public void run() { |
| 142 | View blankView = findViewById(R.id.blank); |
| 143 | blankView.setVisibility(View.GONE); |
| 144 | getActionBar().show(); |
| 145 | } |
| 146 | }; |
| 147 | |
| 148 | @Override |
| 149 | public synchronized void onNear() { |
| 150 | clearPendingRequests(); |
| 151 | postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS); |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public synchronized void onFar() { |
| 156 | clearPendingRequests(); |
| 157 | postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS); |
| 158 | } |
| 159 | |
| 160 | /** Removed any delayed requests that may be pending. */ |
| 161 | public synchronized void clearPendingRequests() { |
| 162 | View blankView = findViewById(R.id.blank); |
| 163 | blankView.removeCallbacks(mBlankRunnable); |
| 164 | blankView.removeCallbacks(mUnblankRunnable); |
| 165 | } |
| 166 | |
| 167 | /** Post a {@link Runnable} with a delay on the main thread. */ |
| 168 | private synchronized void postDelayed(Runnable runnable, long delayMillis) { |
| 169 | // Post these instead of executing immediately so that: |
| 170 | // - They are guaranteed to be executed on the main thread. |
| 171 | // - If the sensor values changes rapidly for some time, the UI will not be |
| 172 | // updated immediately. |
| 173 | View blankView = findViewById(R.id.blank); |
| 174 | blankView.postDelayed(runnable, delayMillis); |
| 175 | } |
| 176 | } |
| 177 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 178 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 179 | CallLog.Calls.DATE, |
| 180 | CallLog.Calls.DURATION, |
| 181 | CallLog.Calls.NUMBER, |
| 182 | CallLog.Calls.TYPE, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 183 | CallLog.Calls.COUNTRY_ISO, |
Flavio Lerda | 71fc6ec | 2011-08-09 17:24:29 +0100 | [diff] [blame] | 184 | CallLog.Calls.GEOCODED_LOCATION, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 185 | }; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 186 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 187 | static final int DATE_COLUMN_INDEX = 0; |
| 188 | static final int DURATION_COLUMN_INDEX = 1; |
| 189 | static final int NUMBER_COLUMN_INDEX = 2; |
| 190 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 191 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
Flavio Lerda | 71fc6ec | 2011-08-09 17:24:29 +0100 | [diff] [blame] | 192 | static final int GEOCODED_LOCATION_COLUMN_INDEX = 5; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 193 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 194 | static final String[] PHONES_PROJECTION = new String[] { |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 195 | PhoneLookup._ID, |
| 196 | PhoneLookup.DISPLAY_NAME, |
| 197 | PhoneLookup.TYPE, |
| 198 | PhoneLookup.LABEL, |
| 199 | PhoneLookup.NUMBER, |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 200 | PhoneLookup.NORMALIZED_NUMBER, |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 201 | PhoneLookup.PHOTO_URI, |
Flavio Lerda | 071aa0d | 2011-08-22 10:26:27 +0100 | [diff] [blame] | 202 | PhoneLookup.LOOKUP_KEY, |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 203 | }; |
| 204 | static final int COLUMN_INDEX_ID = 0; |
| 205 | static final int COLUMN_INDEX_NAME = 1; |
| 206 | static final int COLUMN_INDEX_TYPE = 2; |
| 207 | static final int COLUMN_INDEX_LABEL = 3; |
| 208 | static final int COLUMN_INDEX_NUMBER = 4; |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 209 | static final int COLUMN_INDEX_NORMALIZED_NUMBER = 5; |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 210 | static final int COLUMN_INDEX_PHOTO_URI = 6; |
Flavio Lerda | 071aa0d | 2011-08-22 10:26:27 +0100 | [diff] [blame] | 211 | static final int COLUMN_INDEX_LOOKUP_KEY = 7; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 212 | |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 213 | private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() { |
| 214 | @Override |
| 215 | public void onClick(View view) { |
| 216 | startActivity(((ViewEntry) view.getTag()).primaryIntent); |
| 217 | } |
| 218 | }; |
| 219 | |
| 220 | private final View.OnClickListener mSecondaryActionListener = new View.OnClickListener() { |
| 221 | @Override |
| 222 | public void onClick(View view) { |
| 223 | startActivity(((ViewEntry) view.getTag()).secondaryIntent); |
| 224 | } |
| 225 | }; |
| 226 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 227 | @Override |
| 228 | protected void onCreate(Bundle icicle) { |
| 229 | super.onCreate(icicle); |
| 230 | |
| 231 | setContentView(R.layout.call_detail); |
| 232 | |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 233 | mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 234 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 235 | mResources = getResources(); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 236 | |
Daniel Lehmann | 6ecb732 | 2011-08-01 21:39:29 -0700 | [diff] [blame] | 237 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 238 | mPhoneNumberHelper = new PhoneNumberHelper(mResources, getVoicemailNumber()); |
Flavio Lerda | 4056956 | 2011-07-22 21:51:29 +0100 | [diff] [blame] | 239 | mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper, |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 240 | mPhoneNumberHelper); |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 241 | mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); |
| 242 | mAsyncQueryHandler = new CallDetailActivityQueryHandler(this); |
Flavio Lerda | b88abaa | 2011-08-02 23:38:36 +0100 | [diff] [blame] | 243 | mHeaderTextView = (TextView) findViewById(R.id.header_text); |
Flavio Lerda | 126a420 | 2011-10-03 11:15:03 +0100 | [diff] [blame^] | 244 | mHeaderOverlayView = findViewById(R.id.photo_text_bar); |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 245 | mStatusMessageView = findViewById(R.id.voicemail_status); |
| 246 | mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message); |
| 247 | mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action); |
Flavio Lerda | fb63c43 | 2011-07-07 17:16:53 +0100 | [diff] [blame] | 248 | mMainActionView = (ImageView) findViewById(R.id.main_action); |
Daniel Lehmann | d260de4 | 2011-08-01 18:08:38 -0700 | [diff] [blame] | 249 | mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 250 | mContactBackgroundView = (ImageView) findViewById(R.id.contact_background); |
Bai Tao | 09eb04f | 2010-09-01 15:34:16 +0800 | [diff] [blame] | 251 | mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 252 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
Flavio Lerda | fd1b98b | 2011-08-24 19:55:15 +0100 | [diff] [blame] | 253 | mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener); |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 254 | configureActionBar(); |
Hugo Hudson | 51ada36 | 2011-08-05 14:36:14 +0100 | [diff] [blame] | 255 | optionallyHandleVoicemail(); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 256 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 257 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 258 | @Override |
| 259 | public void onResume() { |
| 260 | super.onResume(); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 261 | updateData(getCallLogEntryUris()); |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Handle voicemail playback or hide voicemail ui. |
| 266 | * <p> |
| 267 | * If the Intent used to start this Activity contains the suitable extras, then start voicemail |
| 268 | * playback. If it doesn't, then hide the voicemail ui. |
| 269 | */ |
Hugo Hudson | 757aa55 | 2011-07-20 01:15:25 +0100 | [diff] [blame] | 270 | private void optionallyHandleVoicemail() { |
Flavio Lerda | 35be86e | 2011-08-12 14:13:22 +0100 | [diff] [blame] | 271 | View voicemailContainer = findViewById(R.id.voicemail_container); |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 272 | if (hasVoicemail()) { |
Hugo Hudson | a9ad694 | 2011-07-29 17:06:04 +0100 | [diff] [blame] | 273 | // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri |
| 274 | // to play and optionally start the playback. |
Hugo Hudson | 757aa55 | 2011-07-20 01:15:25 +0100 | [diff] [blame] | 275 | // Do a query to fetch the voicemail status messages. |
Hugo Hudson | a9ad694 | 2011-07-29 17:06:04 +0100 | [diff] [blame] | 276 | VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment(); |
| 277 | Bundle fragmentArguments = new Bundle(); |
Hugo Hudson | 7b02fde | 2011-08-02 20:56:48 +0100 | [diff] [blame] | 278 | fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri()); |
Hugo Hudson | a9ad694 | 2011-07-29 17:06:04 +0100 | [diff] [blame] | 279 | if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) { |
| 280 | fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true); |
| 281 | } |
| 282 | playbackFragment.setArguments(fragmentArguments); |
Flavio Lerda | 35be86e | 2011-08-12 14:13:22 +0100 | [diff] [blame] | 283 | voicemailContainer.setVisibility(View.VISIBLE); |
Hugo Hudson | a9ad694 | 2011-07-29 17:06:04 +0100 | [diff] [blame] | 284 | getFragmentManager().beginTransaction() |
Minh Pham | 4b25da7 | 2011-08-25 13:50:38 -0700 | [diff] [blame] | 285 | .add(R.id.voicemail_container, playbackFragment).commitAllowingStateLoss(); |
Hugo Hudson | 7b02fde | 2011-08-02 20:56:48 +0100 | [diff] [blame] | 286 | mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri()); |
Debashish Chatterjee | 0a13900 | 2011-08-02 18:27:11 +0100 | [diff] [blame] | 287 | markVoicemailAsRead(getVoicemailUri()); |
Hugo Hudson | 757aa55 | 2011-07-20 01:15:25 +0100 | [diff] [blame] | 288 | } else { |
Hugo Hudson | a9ad694 | 2011-07-29 17:06:04 +0100 | [diff] [blame] | 289 | // No voicemail uri: hide the status view. |
Hugo Hudson | 757aa55 | 2011-07-20 01:15:25 +0100 | [diff] [blame] | 290 | mStatusMessageView.setVisibility(View.GONE); |
Flavio Lerda | 35be86e | 2011-08-12 14:13:22 +0100 | [diff] [blame] | 291 | voicemailContainer.setVisibility(View.GONE); |
Hugo Hudson | b002f51 | 2011-07-15 17:41:12 +0100 | [diff] [blame] | 292 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 293 | } |
| 294 | |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 295 | private boolean hasVoicemail() { |
Hugo Hudson | 7b02fde | 2011-08-02 20:56:48 +0100 | [diff] [blame] | 296 | return getVoicemailUri() != null; |
| 297 | } |
| 298 | |
| 299 | private Uri getVoicemailUri() { |
| 300 | return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
Hugo Hudson | 157dde1 | 2011-07-21 23:28:13 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Debashish Chatterjee | 0a13900 | 2011-08-02 18:27:11 +0100 | [diff] [blame] | 303 | private void markVoicemailAsRead(final Uri voicemailUri) { |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 304 | mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() { |
Debashish Chatterjee | 0a13900 | 2011-08-02 18:27:11 +0100 | [diff] [blame] | 305 | @Override |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 306 | public Void doInBackground(Void... params) { |
Debashish Chatterjee | 0a13900 | 2011-08-02 18:27:11 +0100 | [diff] [blame] | 307 | ContentValues values = new ContentValues(); |
| 308 | values.put(Voicemails.IS_READ, true); |
| 309 | getContentResolver().update(voicemailUri, values, null, null); |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 310 | return null; |
Debashish Chatterjee | 0a13900 | 2011-08-02 18:27:11 +0100 | [diff] [blame] | 311 | } |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 312 | }); |
Debashish Chatterjee | 0a13900 | 2011-08-02 18:27:11 +0100 | [diff] [blame] | 313 | } |
| 314 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 315 | /** |
| 316 | * Returns the list of URIs to show. |
| 317 | * <p> |
| 318 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 319 | * a list of ids in the call log added as an extra on the URI. |
| 320 | * <p> |
| 321 | * If both are available, the data on the intent takes precedence. |
| 322 | */ |
| 323 | private Uri[] getCallLogEntryUris() { |
| 324 | Uri uri = getIntent().getData(); |
| 325 | if (uri != null) { |
| 326 | // If there is a data on the intent, it takes precedence over the extra. |
| 327 | return new Uri[]{ uri }; |
| 328 | } |
| 329 | long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 330 | Uri[] uris = new Uri[ids.length]; |
| 331 | for (int index = 0; index < ids.length; ++index) { |
| 332 | uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]); |
| 333 | } |
| 334 | return uris; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | @Override |
| 338 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 339 | switch (keyCode) { |
| 340 | case KeyEvent.KEYCODE_CALL: { |
| 341 | // Make sure phone isn't already busy before starting direct call |
| 342 | TelephonyManager tm = (TelephonyManager) |
| 343 | getSystemService(Context.TELEPHONY_SERVICE); |
| 344 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
| 345 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, |
| 346 | Uri.fromParts("tel", mNumber, null)); |
| 347 | startActivity(callIntent); |
| 348 | return true; |
| 349 | } |
| 350 | } |
| 351 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 352 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 353 | return super.onKeyDown(keyCode, event); |
| 354 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 355 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 356 | /** |
| 357 | * Update user interface with details of given call. |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 358 | * |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 359 | * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 360 | */ |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 361 | private void updateData(final Uri... callUris) { |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 362 | class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> { |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 363 | @Override |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 364 | public PhoneCallDetails[] doInBackground(Void... params) { |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 365 | // TODO: All phone calls correspond to the same person, so we can make a single |
| 366 | // lookup. |
| 367 | final int numCalls = callUris.length; |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 368 | PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 369 | try { |
| 370 | for (int index = 0; index < numCalls; ++index) { |
| 371 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 372 | } |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 373 | return details; |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 374 | } catch (IllegalArgumentException e) { |
| 375 | // Something went wrong reading in our primary data. |
| 376 | Log.w(TAG, "invalid URI starting call details", e); |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 377 | return null; |
Flavio Lerda | cfff16d | 2011-07-12 23:54:40 +0100 | [diff] [blame] | 378 | } |
Flavio Lerda | 8ebfa3d | 2011-08-10 14:35:22 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 381 | @Override |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 382 | public void onPostExecute(PhoneCallDetails[] details) { |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 383 | if (details == null) { |
| 384 | // Somewhere went wrong: we're going to bail out and show error to users. |
| 385 | Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error, |
| 386 | Toast.LENGTH_SHORT).show(); |
| 387 | finish(); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | // We know that all calls are from the same number and the same contact, so pick the |
| 392 | // first. |
| 393 | PhoneCallDetails firstDetails = details[0]; |
| 394 | mNumber = firstDetails.number.toString(); |
Flavio Lerda | 071aa0d | 2011-08-22 10:26:27 +0100 | [diff] [blame] | 395 | final Uri contactUri = firstDetails.contactUri; |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 396 | final Uri photoUri = firstDetails.photoUri; |
| 397 | |
| 398 | // Set the details header, based on the first phone call. |
Flavio Lerda | d5678d3 | 2011-08-28 13:49:56 +0100 | [diff] [blame] | 399 | mPhoneCallDetailsHelper.setCallDetailsHeader(mHeaderTextView, firstDetails); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 400 | |
| 401 | // Cache the details about the phone number. |
| 402 | final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber); |
| 403 | final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber); |
| 404 | final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber); |
| 405 | final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber); |
| 406 | |
| 407 | // Let user view contact details if they exist, otherwise add option to create new |
| 408 | // contact from this number. |
| 409 | final Intent mainActionIntent; |
| 410 | final int mainActionIcon; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 411 | final String mainActionDescription; |
| 412 | |
| 413 | final CharSequence nameOrNumber; |
| 414 | if (!TextUtils.isEmpty(firstDetails.name)) { |
| 415 | nameOrNumber = firstDetails.name; |
| 416 | } else { |
| 417 | nameOrNumber = firstDetails.number; |
| 418 | } |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 419 | |
Flavio Lerda | 071aa0d | 2011-08-22 10:26:27 +0100 | [diff] [blame] | 420 | if (contactUri != null) { |
| 421 | mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 422 | mainActionIcon = R.drawable.ic_contacts_holo_dark; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 423 | mainActionDescription = |
| 424 | getString(R.string.description_view_contact, nameOrNumber); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 425 | } else if (isVoicemailNumber) { |
| 426 | mainActionIntent = null; |
| 427 | mainActionIcon = 0; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 428 | mainActionDescription = null; |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 429 | } else if (isSipNumber) { |
| 430 | // TODO: This item is currently disabled for SIP addresses, because |
| 431 | // the Insert.PHONE extra only works correctly for PSTN numbers. |
| 432 | // |
| 433 | // To fix this for SIP addresses, we need to: |
| 434 | // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if |
| 435 | // the current number is a SIP address |
| 436 | // - update the contacts UI code to handle Insert.SIP_ADDRESS by |
| 437 | // updating the SipAddress field |
| 438 | // and then we can remove the "!isSipNumber" check above. |
| 439 | mainActionIntent = null; |
| 440 | mainActionIcon = 0; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 441 | mainActionDescription = null; |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 442 | } else if (canPlaceCallsTo) { |
| 443 | mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 444 | mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 445 | mainActionIntent.putExtra(Insert.PHONE, mNumber); |
| 446 | mainActionIcon = R.drawable.ic_add_contact_holo_dark; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 447 | mainActionDescription = getString(R.string.description_add_contact); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 448 | } else { |
| 449 | // If we cannot call the number, when we probably cannot add it as a contact either. |
| 450 | // This is usually the case of private, unknown, or payphone numbers. |
| 451 | mainActionIntent = null; |
| 452 | mainActionIcon = 0; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 453 | mainActionDescription = null; |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | if (mainActionIntent == null) { |
| 457 | mMainActionView.setVisibility(View.INVISIBLE); |
| 458 | mMainActionPushLayerView.setVisibility(View.GONE); |
Flavio Lerda | 126a420 | 2011-10-03 11:15:03 +0100 | [diff] [blame^] | 459 | mHeaderTextView.setVisibility(View.INVISIBLE); |
| 460 | mHeaderOverlayView.setVisibility(View.INVISIBLE); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 461 | } else { |
| 462 | mMainActionView.setVisibility(View.VISIBLE); |
| 463 | mMainActionView.setImageResource(mainActionIcon); |
| 464 | mMainActionPushLayerView.setVisibility(View.VISIBLE); |
| 465 | mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() { |
| 466 | @Override |
| 467 | public void onClick(View v) { |
| 468 | startActivity(mainActionIntent); |
| 469 | } |
| 470 | }); |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 471 | mMainActionPushLayerView.setContentDescription(mainActionDescription); |
Flavio Lerda | 126a420 | 2011-10-03 11:15:03 +0100 | [diff] [blame^] | 472 | mHeaderTextView.setVisibility(View.VISIBLE); |
| 473 | mHeaderOverlayView.setVisibility(View.VISIBLE); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 474 | } |
| 475 | |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 476 | // This action allows to call the number that places the call. |
| 477 | if (canPlaceCallsTo) { |
| 478 | final CharSequence displayNumber = |
| 479 | mPhoneNumberHelper.getDisplayNumber( |
| 480 | firstDetails.number, firstDetails.formattedNumber); |
| 481 | |
| 482 | ViewEntry entry = new ViewEntry( |
| 483 | getString(R.string.menu_callNumber, displayNumber), |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 484 | new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri), |
| 485 | getString(R.string.description_call, nameOrNumber)); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 486 | |
| 487 | // Only show a label if the number is shown and it is not a SIP address. |
Flavio Lerda | 35be86e | 2011-08-12 14:13:22 +0100 | [diff] [blame] | 488 | if (!TextUtils.isEmpty(firstDetails.name) |
| 489 | && !TextUtils.isEmpty(firstDetails.number) |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 490 | && !PhoneNumberUtils.isUriNumber(firstDetails.number.toString())) { |
| 491 | entry.label = Phone.getTypeLabel(mResources, firstDetails.numberType, |
| 492 | firstDetails.numberLabel); |
| 493 | } |
| 494 | |
| 495 | // The secondary action allows to send an SMS to the number that placed the |
| 496 | // call. |
| 497 | if (mPhoneNumberHelper.canSendSmsTo(mNumber)) { |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 498 | entry.setSecondaryAction( |
| 499 | R.drawable.ic_text_holo_dark, |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 500 | new Intent(Intent.ACTION_SENDTO, |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 501 | Uri.fromParts("sms", mNumber, null)), |
| 502 | getString(R.string.description_send_text_message, nameOrNumber)); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 503 | } |
| 504 | |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 505 | configureCallButton(entry); |
| 506 | } else { |
| 507 | disableCallButton(); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | mHasEditNumberBeforeCall = canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
Flavio Lerda | 599853d | 2011-09-05 17:50:14 +0100 | [diff] [blame] | 511 | invalidateOptionsMenu(); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 512 | |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 513 | ListView historyList = (ListView) findViewById(R.id.history); |
| 514 | historyList.setAdapter( |
| 515 | new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater, |
Flavio Lerda | b5a3f5c | 2011-09-21 19:27:33 +0100 | [diff] [blame] | 516 | mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo, |
| 517 | findViewById(R.id.controls))); |
Flavio Lerda | d1333a2 | 2011-08-11 16:19:47 +0100 | [diff] [blame] | 518 | BackScrollManager.bind( |
| 519 | new ScrollableHeader() { |
Flavio Lerda | 126a420 | 2011-10-03 11:15:03 +0100 | [diff] [blame^] | 520 | private View mControls = findViewById(R.id.controls); |
| 521 | private View mPhoto = findViewById(R.id.contact_background_sizer); |
| 522 | private View mHeader = findViewById(R.id.photo_text_bar); |
| 523 | private View mSeparator = findViewById(R.id.blue_separator); |
Flavio Lerda | d1333a2 | 2011-08-11 16:19:47 +0100 | [diff] [blame] | 524 | |
| 525 | @Override |
| 526 | public void setOffset(int offset) { |
Flavio Lerda | 126a420 | 2011-10-03 11:15:03 +0100 | [diff] [blame^] | 527 | mControls.setY(-offset); |
Flavio Lerda | d1333a2 | 2011-08-11 16:19:47 +0100 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | @Override |
| 531 | public int getMaximumScrollableHeaderOffset() { |
Flavio Lerda | 126a420 | 2011-10-03 11:15:03 +0100 | [diff] [blame^] | 532 | // We can scroll the photo out, but we should keep the header if |
| 533 | // present. |
| 534 | if (mHeader.getVisibility() == View.VISIBLE) { |
| 535 | return mPhoto.getHeight() - mHeader.getHeight(); |
| 536 | } else { |
| 537 | // If the header is not present, we should also scroll out the |
| 538 | // separator line. |
| 539 | return mPhoto.getHeight() + mSeparator.getHeight(); |
| 540 | } |
Flavio Lerda | d1333a2 | 2011-08-11 16:19:47 +0100 | [diff] [blame] | 541 | } |
| 542 | }, |
| 543 | historyList); |
Flavio Lerda | 12592e8 | 2011-08-10 15:36:32 +0100 | [diff] [blame] | 544 | loadContactPhotos(photoUri); |
Flavio Lerda | 4e63bab | 2011-08-10 18:26:46 +0100 | [diff] [blame] | 545 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
Flavio Lerda | 8ebfa3d | 2011-08-10 14:35:22 +0100 | [diff] [blame] | 546 | } |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 547 | } |
| 548 | mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask()); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /** Return the phone call details for a given call log URI. */ |
| 552 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 553 | ContentResolver resolver = getContentResolver(); |
| 554 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 555 | try { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 556 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 557 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 558 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 559 | |
| 560 | // Read call log specifics. |
| 561 | String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 562 | long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 563 | long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 564 | int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
| 565 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
Flavio Lerda | 71fc6ec | 2011-08-09 17:24:29 +0100 | [diff] [blame] | 566 | final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX); |
| 567 | |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 568 | if (TextUtils.isEmpty(countryIso)) { |
| 569 | countryIso = mDefaultCountryIso; |
| 570 | } |
| 571 | |
| 572 | // Formatted phone number. |
| 573 | final CharSequence numberText; |
| 574 | // Read contact specifics. |
| 575 | CharSequence nameText = ""; |
| 576 | int numberType = 0; |
| 577 | CharSequence numberLabel = ""; |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 578 | Uri photoUri = null; |
Flavio Lerda | 071aa0d | 2011-08-22 10:26:27 +0100 | [diff] [blame] | 579 | Uri contactUri = null; |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 580 | // If this is not a regular number, there is no point in looking it up in the contacts. |
| 581 | if (!mPhoneNumberHelper.canPlaceCallsTo(number)) { |
| 582 | numberText = mPhoneNumberHelper.getDisplayNumber(number, null); |
| 583 | } else { |
| 584 | // Perform a reverse-phonebook lookup to find the contact details. |
| 585 | Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, |
| 586 | Uri.encode(number)); |
| 587 | Cursor phonesCursor = resolver.query(phoneUri, PHONES_PROJECTION, null, null, null); |
| 588 | String candidateNumberText = number; |
| 589 | try { |
| 590 | if (phonesCursor != null && phonesCursor.moveToFirst()) { |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 591 | nameText = phonesCursor.getString(COLUMN_INDEX_NAME); |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 592 | String photoUriString = phonesCursor.getString(COLUMN_INDEX_PHOTO_URI); |
| 593 | photoUri = photoUriString == null ? null : Uri.parse(photoUriString); |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 594 | candidateNumberText = PhoneNumberUtils.formatNumber( |
| 595 | phonesCursor.getString(COLUMN_INDEX_NUMBER), |
| 596 | phonesCursor.getString(COLUMN_INDEX_NORMALIZED_NUMBER), |
| 597 | countryIso); |
| 598 | numberType = phonesCursor.getInt(COLUMN_INDEX_TYPE); |
| 599 | numberLabel = phonesCursor.getString(COLUMN_INDEX_LABEL); |
Flavio Lerda | 071aa0d | 2011-08-22 10:26:27 +0100 | [diff] [blame] | 600 | long personId = phonesCursor.getLong(COLUMN_INDEX_ID); |
| 601 | if (personId > 0) { |
| 602 | contactUri = Contacts.getLookupUri(personId, |
| 603 | phonesCursor.getString(COLUMN_INDEX_LOOKUP_KEY)); |
| 604 | } |
Flavio Lerda | 178eeeb | 2011-07-11 19:51:40 +0100 | [diff] [blame] | 605 | } else { |
| 606 | // We could not find this contact in the contacts, just format the phone |
| 607 | // number as best as we can. All the other fields will have their default |
| 608 | // values. |
| 609 | candidateNumberText = |
| 610 | PhoneNumberUtils.formatNumber(number, countryIso); |
| 611 | } |
| 612 | } finally { |
| 613 | if (phonesCursor != null) phonesCursor.close(); |
| 614 | numberText = candidateNumberText; |
| 615 | } |
| 616 | } |
Flavio Lerda | 71fc6ec | 2011-08-09 17:24:29 +0100 | [diff] [blame] | 617 | return new PhoneCallDetails(number, numberText, countryIso, geocode, |
Flavio Lerda | cb805e8 | 2011-07-18 10:31:44 +0100 | [diff] [blame] | 618 | new int[]{ callType }, date, duration, |
Flavio Lerda | 071aa0d | 2011-08-22 10:26:27 +0100 | [diff] [blame] | 619 | nameText, numberType, numberLabel, contactUri, photoUri); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 620 | } finally { |
| 621 | if (callCursor != null) { |
| 622 | callCursor.close(); |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 627 | /** Load the contact photos and places them in the corresponding views. */ |
Daniel Lehmann | 362654a | 2011-07-17 14:16:47 -0700 | [diff] [blame] | 628 | private void loadContactPhotos(Uri photoUri) { |
Daniel Lehmann | ecfc26c | 2011-09-12 17:44:35 -0700 | [diff] [blame] | 629 | mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri, true, true); |
Flavio Lerda | 9cafe47 | 2011-06-08 14:06:13 +0100 | [diff] [blame] | 630 | } |
| 631 | |
Flavio Lerda | 696e813 | 2011-07-05 19:00:23 +0100 | [diff] [blame] | 632 | private String getVoicemailNumber() { |
| 633 | TelephonyManager telephonyManager = |
| 634 | (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 635 | return telephonyManager.getVoiceMailNumber(); |
| 636 | } |
| 637 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 638 | static final class ViewEntry { |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 639 | public final String text; |
Flavio Lerda | 8ebfa3d | 2011-08-10 14:35:22 +0100 | [diff] [blame] | 640 | public final Intent primaryIntent; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 641 | /** The description for accessibility of the primary action. */ |
| 642 | public final String primaryDescription; |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 643 | |
Flavio Lerda | 8ebfa3d | 2011-08-10 14:35:22 +0100 | [diff] [blame] | 644 | public CharSequence label = null; |
Flavio Lerda | 8ebfa3d | 2011-08-10 14:35:22 +0100 | [diff] [blame] | 645 | /** Icon for the secondary action. */ |
| 646 | public int secondaryIcon = 0; |
| 647 | /** Intent for the secondary action. If not null, an icon must be defined. */ |
| 648 | public Intent secondaryIntent = null; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 649 | /** The description for accessibility of the secondary action. */ |
| 650 | public String secondaryDescription = null; |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 651 | |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 652 | public ViewEntry(String text, Intent intent, String description) { |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 653 | this.text = text; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 654 | primaryIntent = intent; |
| 655 | primaryDescription = description; |
Flavio Lerda | a895688 | 2011-07-09 21:34:38 +0100 | [diff] [blame] | 656 | } |
| 657 | |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 658 | public void setSecondaryAction(int icon, Intent intent, String description) { |
Flavio Lerda | 8ebfa3d | 2011-08-10 14:35:22 +0100 | [diff] [blame] | 659 | secondaryIcon = icon; |
| 660 | secondaryIntent = intent; |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 661 | secondaryDescription = description; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 665 | /** Disables the call button area, e.g., for private numbers. */ |
| 666 | private void disableCallButton() { |
| 667 | findViewById(R.id.call_and_sms).setVisibility(View.GONE); |
| 668 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 669 | |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 670 | /** Configures the call button area using the given entry. */ |
| 671 | private void configureCallButton(ViewEntry entry) { |
| 672 | View convertView = findViewById(R.id.call_and_sms); |
| 673 | convertView.setVisibility(View.VISIBLE); |
Flavio Lerda | 8ebfa3d | 2011-08-10 14:35:22 +0100 | [diff] [blame] | 674 | |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 675 | ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon); |
| 676 | View divider = convertView.findViewById(R.id.call_and_sms_divider); |
Flavio Lerda | 35be86e | 2011-08-12 14:13:22 +0100 | [diff] [blame] | 677 | TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text); |
Flavio Lerda | 8ebfa3d | 2011-08-10 14:35:22 +0100 | [diff] [blame] | 678 | |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 679 | View mainAction = convertView.findViewById(R.id.call_and_sms_main_action); |
| 680 | mainAction.setOnClickListener(mPrimaryActionListener); |
| 681 | mainAction.setTag(entry); |
| 682 | mainAction.setContentDescription(entry.primaryDescription); |
| 683 | |
| 684 | if (entry.secondaryIntent != null) { |
| 685 | icon.setOnClickListener(mSecondaryActionListener); |
| 686 | icon.setImageResource(entry.secondaryIcon); |
| 687 | icon.setVisibility(View.VISIBLE); |
| 688 | icon.setTag(entry); |
| 689 | icon.setContentDescription(entry.secondaryDescription); |
| 690 | divider.setVisibility(View.VISIBLE); |
| 691 | } else { |
| 692 | icon.setVisibility(View.GONE); |
| 693 | divider.setVisibility(View.GONE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 694 | } |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 695 | text.setText(entry.text); |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 696 | |
Flavio Lerda | 35be86e | 2011-08-12 14:13:22 +0100 | [diff] [blame] | 697 | TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label); |
| 698 | if (TextUtils.isEmpty(entry.label)) { |
| 699 | label.setVisibility(View.GONE); |
Flavio Lerda | b184ed6 | 2011-08-10 18:17:55 +0100 | [diff] [blame] | 700 | } else { |
Flavio Lerda | 35be86e | 2011-08-12 14:13:22 +0100 | [diff] [blame] | 701 | label.setText(entry.label); |
| 702 | label.setVisibility(View.VISIBLE); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 703 | } |
| 704 | } |
Dmitri Plotnikov | d0d776d | 2009-08-19 17:38:04 -0700 | [diff] [blame] | 705 | |
Debashish Chatterjee | 0cb8224 | 2011-07-19 19:29:37 +0100 | [diff] [blame] | 706 | protected void updateVoicemailStatusMessage(Cursor statusCursor) { |
| 707 | if (statusCursor == null) { |
| 708 | mStatusMessageView.setVisibility(View.GONE); |
| 709 | return; |
| 710 | } |
| 711 | final StatusMessage message = getStatusMessage(statusCursor); |
| 712 | if (message == null || !message.showInCallDetails()) { |
| 713 | mStatusMessageView.setVisibility(View.GONE); |
| 714 | return; |
| 715 | } |
| 716 | |
| 717 | mStatusMessageView.setVisibility(View.VISIBLE); |
| 718 | mStatusMessageText.setText(message.callDetailsMessageId); |
| 719 | if (message.actionMessageId != -1) { |
| 720 | mStatusMessageAction.setText(message.actionMessageId); |
| 721 | } |
| 722 | if (message.actionUri != null) { |
| 723 | mStatusMessageAction.setClickable(true); |
| 724 | mStatusMessageAction.setOnClickListener(new View.OnClickListener() { |
| 725 | @Override |
| 726 | public void onClick(View v) { |
| 727 | startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri)); |
| 728 | } |
| 729 | }); |
| 730 | } else { |
| 731 | mStatusMessageAction.setClickable(false); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | private StatusMessage getStatusMessage(Cursor statusCursor) { |
| 736 | List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor); |
| 737 | Log.d(TAG, "Num status messages: " + messages.size()); |
| 738 | if (messages.size() == 0) { |
| 739 | return null; |
| 740 | } |
| 741 | // There can only be a single status message per source package, so num of messages can |
| 742 | // at most be 1. |
| 743 | if (messages.size() > 1) { |
| 744 | Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." + |
| 745 | " Will use the first one.", messages.size())); |
| 746 | } |
| 747 | return messages.get(0); |
| 748 | } |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 749 | |
| 750 | @Override |
| 751 | public boolean onCreateOptionsMenu(Menu menu) { |
| 752 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 753 | return super.onCreateOptionsMenu(menu); |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | @Override |
| 757 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 758 | // This action deletes all elements in the group from the call log. |
| 759 | // We don't have this action for voicemails, because you can just use the trash button. |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 760 | menu.findItem(R.id.menu_remove_from_call_log).setVisible(!hasVoicemail()); |
| 761 | menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCall); |
| 762 | menu.findItem(R.id.menu_trash).setVisible(hasVoicemail()); |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 763 | return super.onPrepareOptionsMenu(menu); |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | @Override |
| 767 | public boolean onMenuItemSelected(int featureId, MenuItem item) { |
| 768 | switch (item.getItemId()) { |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 769 | case android.R.id.home: { |
| 770 | onHomeSelected(); |
| 771 | return true; |
| 772 | } |
| 773 | |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 774 | // All the options menu items are handled by onMenu... methods. |
Flavio Lerda | 94d7bab | 2011-07-22 16:52:34 +0100 | [diff] [blame] | 775 | default: |
| 776 | throw new IllegalArgumentException(); |
| 777 | } |
| 778 | } |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 779 | |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 780 | public void onMenuRemoveFromCallLog(MenuItem menuItem) { |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 781 | final StringBuilder callIds = new StringBuilder(); |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 782 | for (Uri callUri : getCallLogEntryUris()) { |
| 783 | if (callIds.length() != 0) { |
| 784 | callIds.append(","); |
| 785 | } |
| 786 | callIds.append(ContentUris.parseId(callUri)); |
| 787 | } |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 788 | mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 789 | new AsyncTask<Void, Void, Void>() { |
| 790 | @Override |
| 791 | public Void doInBackground(Void... params) { |
| 792 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 793 | Calls._ID + " IN (" + callIds + ")", null); |
| 794 | return null; |
| 795 | } |
| 796 | |
| 797 | @Override |
| 798 | public void onPostExecute(Void result) { |
| 799 | finish(); |
| 800 | } |
| 801 | }); |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 802 | } |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 803 | |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 804 | public void onMenuEditNumberBeforeCall(MenuItem menuItem) { |
| 805 | startActivity(new Intent(Intent.ACTION_DIAL, mPhoneNumberHelper.getCallUri(mNumber))); |
| 806 | } |
| 807 | |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 808 | public void onMenuTrashVoicemail(MenuItem menuItem) { |
Hugo Hudson | 5bbe25d | 2011-08-03 17:16:42 +0100 | [diff] [blame] | 809 | final Uri voicemailUri = getVoicemailUri(); |
Hugo Hudson | 9c747ac | 2011-08-17 00:23:01 +0100 | [diff] [blame] | 810 | mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH, |
| 811 | new AsyncTask<Void, Void, Void>() { |
| 812 | @Override |
| 813 | public Void doInBackground(Void... params) { |
| 814 | getContentResolver().delete(voicemailUri, null, null); |
| 815 | return null; |
| 816 | } |
| 817 | @Override |
| 818 | public void onPostExecute(Void result) { |
| 819 | finish(); |
| 820 | } |
| 821 | }); |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 822 | } |
| 823 | |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 824 | private void configureActionBar() { |
| 825 | ActionBar actionBar = getActionBar(); |
| 826 | if (actionBar != null) { |
Hugo Hudson | c2f09c3 | 2011-07-30 16:31:28 +0100 | [diff] [blame] | 827 | actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME); |
Flavio Lerda | d44e83a | 2011-07-24 23:10:17 +0100 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
| 831 | /** Invoked when the user presses the home button in the action bar. */ |
| 832 | private void onHomeSelected() { |
| 833 | Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI); |
| 834 | // This will open the call log even if the detail view has been opened directly. |
| 835 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 836 | startActivity(intent); |
| 837 | finish(); |
| 838 | } |
Flavio Lerda | fd1b98b | 2011-08-24 19:55:15 +0100 | [diff] [blame] | 839 | |
| 840 | @Override |
| 841 | protected void onPause() { |
| 842 | // Immediately stop the proximity sensor. |
| 843 | disableProximitySensor(false); |
| 844 | mProximitySensorListener.clearPendingRequests(); |
| 845 | super.onPause(); |
| 846 | } |
| 847 | |
| 848 | @Override |
| 849 | public void enableProximitySensor() { |
| 850 | mProximitySensorManager.enable(); |
| 851 | } |
| 852 | |
| 853 | @Override |
| 854 | public void disableProximitySensor(boolean waitForFarState) { |
| 855 | mProximitySensorManager.disable(waitForFarState); |
| 856 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 857 | } |