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