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