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