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