blob: 7bb215774e292d46748f7d5f5fb8efd390b6b72e [file] [log] [blame]
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -08001/*
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
17package com.android.contacts;
18
Flavio Lerdad44e83a2011-07-24 23:10:17 +010019import android.app.ActionBar;
Flavio Lerdab184ed62011-08-10 18:17:55 +010020import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080021import android.content.ContentResolver;
22import android.content.ContentUris;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010023import android.content.ContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080024import android.content.Context;
25import android.content.Intent;
26import android.content.res.Resources;
27import android.database.Cursor;
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -070028import android.graphics.drawable.Drawable;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080029import android.net.Uri;
Hugo Hudsona2625e42011-08-10 21:13:23 +010030import android.os.AsyncTask;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080031import android.os.Bundle;
32import android.provider.CallLog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080033import android.provider.CallLog.Calls;
Flavio Lerda9cafe472011-06-08 14:06:13 +010034import android.provider.Contacts.Intents.Insert;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +010035import android.provider.ContactsContract.CommonDataKinds.Phone;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070036import android.provider.ContactsContract.Contacts;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010037import android.provider.VoicemailContract.Voicemails;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080038import android.telephony.PhoneNumberUtils;
39import android.telephony.TelephonyManager;
40import android.text.TextUtils;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010041import android.util.Log;
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -070042import android.view.ActionMode;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080043import android.view.KeyEvent;
44import android.view.LayoutInflater;
Flavio Lerda94d7bab2011-07-22 16:52:34 +010045import android.view.Menu;
46import android.view.MenuItem;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080047import android.view.View;
Daniel Lehmannd260de42011-08-01 18:08:38 -070048import android.widget.ImageButton;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080049import android.widget.ImageView;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010050import android.widget.ListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080051import android.widget.TextView;
52import android.widget.Toast;
53
Chiao Chenge0b2f1e2012-06-12 13:07:56 -070054import com.android.contacts.BackScrollManager.ScrollableHeader;
55import com.android.contacts.calllog.CallDetailHistoryAdapter;
56import com.android.contacts.calllog.CallTypeHelper;
57import com.android.contacts.calllog.ContactInfo;
58import com.android.contacts.calllog.ContactInfoHelper;
59import com.android.contacts.calllog.PhoneNumberHelper;
60import com.android.contacts.format.FormatUtils;
61import com.android.contacts.util.AsyncTaskExecutor;
62import com.android.contacts.util.AsyncTaskExecutors;
63import com.android.contacts.util.ClipboardUtils;
64import com.android.contacts.util.Constants;
65import com.android.contacts.voicemail.VoicemailPlaybackFragment;
66import com.android.contacts.voicemail.VoicemailStatusHelper;
67import com.android.contacts.voicemail.VoicemailStatusHelper.StatusMessage;
68import com.android.contacts.voicemail.VoicemailStatusHelperImpl;
69
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080070import java.util.List;
71
72/**
73 * Displays the details of a specific call log entry.
Flavio Lerda178eeeb2011-07-11 19:51:40 +010074 * <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 Project7aa0e4c2009-03-03 19:32:21 -080077 */
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010078public class CallDetailActivity extends Activity implements ProximitySensorAware {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080079 private static final String TAG = "CallDetail";
80
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010081 /** 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 Hudson9c747ac2011-08-17 00:23:01 +010086 /** 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 Lerda178eeeb2011-07-11 19:51:40 +010094 /** A long array extra containing ids of call log entries to display. */
Hugo Hudsonb002f512011-07-15 17:41:12 +010095 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 Lerda66f14602012-05-13 15:38:08 +0100100 /** If the activity was triggered from a notification. */
101 public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100102
Flavio Lerda9a208cc2011-07-12 21:05:47 +0100103 private CallTypeHelper mCallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100104 private PhoneNumberHelper mPhoneNumberHelper;
Flavio Lerdaafb93bb2011-07-05 14:46:10 +0100105 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100106 private TextView mHeaderTextView;
Flavio Lerda126a4202011-10-03 11:15:03 +0100107 private View mHeaderOverlayView;
Flavio Lerdafb63c432011-07-07 17:16:53 +0100108 private ImageView mMainActionView;
Daniel Lehmannd260de42011-08-01 18:08:38 -0700109 private ImageButton mMainActionPushLayerView;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100110 private ImageView mContactBackgroundView;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100111 private AsyncTaskExecutor mAsyncTaskExecutor;
Flavio Lerda731f8612011-10-07 15:56:20 +0100112 private ContactInfoHelper mContactInfoHelper;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800113
114 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +0800115 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700116
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800117 /* package */ LayoutInflater mInflater;
118 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100119 /** Helper to load contact photos. */
120 private ContactPhotoManager mContactPhotoManager;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100121 /** Helper to make async queries to content resolver. */
122 private CallDetailActivityQueryHandler mAsyncQueryHandler;
123 /** Helper to get voicemail status messages. */
124 private VoicemailStatusHelper mVoicemailStatusHelper;
125 // Views related to voicemail status message.
126 private View mStatusMessageView;
127 private TextView mStatusMessageText;
128 private TextView mStatusMessageAction;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700129
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100130 /** Whether we should show "edit number before call" in the options menu. */
Flavio Lerda78d081d2011-10-17 14:44:02 +0100131 private boolean mHasEditNumberBeforeCallOption;
132 /** Whether we should show "trash" in the options menu. */
133 private boolean mHasTrashOption;
134 /** Whether we should show "remove from call log" in the options menu. */
135 private boolean mHasRemoveFromCallLogOption;
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100136
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100137 private ProximitySensorManager mProximitySensorManager;
138 private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener();
139
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700140 /**
141 * The action mode used when the phone number is selected. This will be non-null only when the
142 * phone number is selected.
143 */
144 private ActionMode mPhoneNumberActionMode;
145
146 private CharSequence mPhoneNumberLabelToCopy;
147 private CharSequence mPhoneNumberToCopy;
148
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100149 /** Listener to changes in the proximity sensor state. */
150 private class ProximitySensorListener implements ProximitySensorManager.Listener {
151 /** Used to show a blank view and hide the action bar. */
152 private final Runnable mBlankRunnable = new Runnable() {
153 @Override
154 public void run() {
155 View blankView = findViewById(R.id.blank);
156 blankView.setVisibility(View.VISIBLE);
157 getActionBar().hide();
158 }
159 };
160 /** Used to remove the blank view and show the action bar. */
161 private final Runnable mUnblankRunnable = new Runnable() {
162 @Override
163 public void run() {
164 View blankView = findViewById(R.id.blank);
165 blankView.setVisibility(View.GONE);
166 getActionBar().show();
167 }
168 };
169
170 @Override
171 public synchronized void onNear() {
172 clearPendingRequests();
173 postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS);
174 }
175
176 @Override
177 public synchronized void onFar() {
178 clearPendingRequests();
179 postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS);
180 }
181
182 /** Removed any delayed requests that may be pending. */
183 public synchronized void clearPendingRequests() {
184 View blankView = findViewById(R.id.blank);
185 blankView.removeCallbacks(mBlankRunnable);
186 blankView.removeCallbacks(mUnblankRunnable);
187 }
188
189 /** Post a {@link Runnable} with a delay on the main thread. */
190 private synchronized void postDelayed(Runnable runnable, long delayMillis) {
191 // Post these instead of executing immediately so that:
192 // - They are guaranteed to be executed on the main thread.
193 // - If the sensor values changes rapidly for some time, the UI will not be
194 // updated immediately.
195 View blankView = findViewById(R.id.blank);
196 blankView.postDelayed(runnable, delayMillis);
197 }
198 }
199
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800200 static final String[] CALL_LOG_PROJECTION = new String[] {
201 CallLog.Calls.DATE,
202 CallLog.Calls.DURATION,
203 CallLog.Calls.NUMBER,
204 CallLog.Calls.TYPE,
Bai Tao09eb04f2010-09-01 15:34:16 +0800205 CallLog.Calls.COUNTRY_ISO,
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100206 CallLog.Calls.GEOCODED_LOCATION,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800207 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700208
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800209 static final int DATE_COLUMN_INDEX = 0;
210 static final int DURATION_COLUMN_INDEX = 1;
211 static final int NUMBER_COLUMN_INDEX = 2;
212 static final int CALL_TYPE_COLUMN_INDEX = 3;
Bai Tao09eb04f2010-09-01 15:34:16 +0800213 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100214 static final int GEOCODED_LOCATION_COLUMN_INDEX = 5;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700215
Flavio Lerdab184ed62011-08-10 18:17:55 +0100216 private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() {
217 @Override
218 public void onClick(View view) {
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700219 if (finishPhoneNumerSelectedActionModeIfShown()) {
220 return;
221 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100222 startActivity(((ViewEntry) view.getTag()).primaryIntent);
223 }
224 };
225
226 private final View.OnClickListener mSecondaryActionListener = new View.OnClickListener() {
227 @Override
228 public void onClick(View view) {
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700229 if (finishPhoneNumerSelectedActionModeIfShown()) {
230 return;
231 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100232 startActivity(((ViewEntry) view.getTag()).secondaryIntent);
233 }
234 };
235
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700236 private final View.OnLongClickListener mPrimaryLongClickListener =
237 new View.OnLongClickListener() {
238 @Override
239 public boolean onLongClick(View v) {
240 if (finishPhoneNumerSelectedActionModeIfShown()) {
241 return true;
242 }
243 startPhoneNumberSelectedActionMode(v);
244 return true;
245 }
246 };
247
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800248 @Override
249 protected void onCreate(Bundle icicle) {
250 super.onCreate(icicle);
251
252 setContentView(R.layout.call_detail);
253
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100254 mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800255 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
256 mResources = getResources();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700257
Daniel Lehmann6ecb7322011-08-01 21:39:29 -0700258 mCallTypeHelper = new CallTypeHelper(getResources());
Flavio Lerda0646f272011-10-17 13:58:53 +0100259 mPhoneNumberHelper = new PhoneNumberHelper(mResources);
Flavio Lerda40569562011-07-22 21:51:29 +0100260 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper,
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100261 mPhoneNumberHelper);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100262 mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
263 mAsyncQueryHandler = new CallDetailActivityQueryHandler(this);
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100264 mHeaderTextView = (TextView) findViewById(R.id.header_text);
Flavio Lerda126a4202011-10-03 11:15:03 +0100265 mHeaderOverlayView = findViewById(R.id.photo_text_bar);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100266 mStatusMessageView = findViewById(R.id.voicemail_status);
267 mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message);
268 mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100269 mMainActionView = (ImageView) findViewById(R.id.main_action);
Daniel Lehmannd260de42011-08-01 18:08:38 -0700270 mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100271 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Bai Tao09eb04f2010-09-01 15:34:16 +0800272 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100273 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100274 mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener);
Flavio Lerda731f8612011-10-07 15:56:20 +0100275 mContactInfoHelper = new ContactInfoHelper(this, ContactsUtils.getCurrentCountryIso(this));
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100276 configureActionBar();
Hugo Hudson51ada362011-08-05 14:36:14 +0100277 optionallyHandleVoicemail();
Flavio Lerda66f14602012-05-13 15:38:08 +0100278 if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
279 closeSystemDialogs();
280 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800281 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700282
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800283 @Override
284 public void onResume() {
285 super.onResume();
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100286 updateData(getCallLogEntryUris());
Hugo Hudsonb002f512011-07-15 17:41:12 +0100287 }
288
289 /**
290 * Handle voicemail playback or hide voicemail ui.
291 * <p>
292 * If the Intent used to start this Activity contains the suitable extras, then start voicemail
293 * playback. If it doesn't, then hide the voicemail ui.
294 */
Hugo Hudson757aa552011-07-20 01:15:25 +0100295 private void optionallyHandleVoicemail() {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100296 View voicemailContainer = findViewById(R.id.voicemail_container);
Hugo Hudson157dde12011-07-21 23:28:13 +0100297 if (hasVoicemail()) {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100298 // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri
299 // to play and optionally start the playback.
Hugo Hudson757aa552011-07-20 01:15:25 +0100300 // Do a query to fetch the voicemail status messages.
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100301 VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment();
302 Bundle fragmentArguments = new Bundle();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100303 fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri());
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100304 if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) {
305 fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true);
306 }
307 playbackFragment.setArguments(fragmentArguments);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100308 voicemailContainer.setVisibility(View.VISIBLE);
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100309 getFragmentManager().beginTransaction()
Minh Pham4b25da72011-08-25 13:50:38 -0700310 .add(R.id.voicemail_container, playbackFragment).commitAllowingStateLoss();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100311 mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri());
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100312 markVoicemailAsRead(getVoicemailUri());
Hugo Hudson757aa552011-07-20 01:15:25 +0100313 } else {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100314 // No voicemail uri: hide the status view.
Hugo Hudson757aa552011-07-20 01:15:25 +0100315 mStatusMessageView.setVisibility(View.GONE);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100316 voicemailContainer.setVisibility(View.GONE);
Hugo Hudsonb002f512011-07-15 17:41:12 +0100317 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100318 }
319
Hugo Hudson157dde12011-07-21 23:28:13 +0100320 private boolean hasVoicemail() {
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100321 return getVoicemailUri() != null;
322 }
323
324 private Uri getVoicemailUri() {
325 return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
Hugo Hudson157dde12011-07-21 23:28:13 +0100326 }
327
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100328 private void markVoicemailAsRead(final Uri voicemailUri) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100329 mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100330 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100331 public Void doInBackground(Void... params) {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100332 ContentValues values = new ContentValues();
333 values.put(Voicemails.IS_READ, true);
Flavio Lerda7b9db072011-09-05 13:43:06 +0100334 getContentResolver().update(voicemailUri, values,
335 Voicemails.IS_READ + " = 0", null);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100336 return null;
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100337 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100338 });
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100339 }
340
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100341 /**
342 * Returns the list of URIs to show.
343 * <p>
344 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
345 * a list of ids in the call log added as an extra on the URI.
346 * <p>
347 * If both are available, the data on the intent takes precedence.
348 */
349 private Uri[] getCallLogEntryUris() {
350 Uri uri = getIntent().getData();
351 if (uri != null) {
352 // If there is a data on the intent, it takes precedence over the extra.
353 return new Uri[]{ uri };
354 }
355 long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
356 Uri[] uris = new Uri[ids.length];
357 for (int index = 0; index < ids.length; ++index) {
358 uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]);
359 }
360 return uris;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800361 }
362
363 @Override
364 public boolean onKeyDown(int keyCode, KeyEvent event) {
365 switch (keyCode) {
366 case KeyEvent.KEYCODE_CALL: {
367 // Make sure phone isn't already busy before starting direct call
368 TelephonyManager tm = (TelephonyManager)
369 getSystemService(Context.TELEPHONY_SERVICE);
370 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
Daisuke Miyakawafadd5e12011-12-01 17:34:18 -0800371 startActivity(ContactsUtils.getCallIntent(
Daisuke Miyakawa499ea322012-01-24 12:45:51 -0800372 Uri.fromParts(Constants.SCHEME_TEL, mNumber, null)));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800373 return true;
374 }
375 }
376 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700377
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800378 return super.onKeyDown(keyCode, event);
379 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700380
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800381 /**
382 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700383 *
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100384 * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800385 */
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100386 private void updateData(final Uri... callUris) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100387 class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> {
Flavio Lerda12592e82011-08-10 15:36:32 +0100388 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100389 public PhoneCallDetails[] doInBackground(Void... params) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100390 // TODO: All phone calls correspond to the same person, so we can make a single
391 // lookup.
392 final int numCalls = callUris.length;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100393 PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
Flavio Lerda12592e82011-08-10 15:36:32 +0100394 try {
395 for (int index = 0; index < numCalls; ++index) {
396 details[index] = getPhoneCallDetailsForUri(callUris[index]);
397 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100398 return details;
Flavio Lerda12592e82011-08-10 15:36:32 +0100399 } catch (IllegalArgumentException e) {
400 // Something went wrong reading in our primary data.
401 Log.w(TAG, "invalid URI starting call details", e);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100402 return null;
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100403 }
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100404 }
405
Flavio Lerda12592e82011-08-10 15:36:32 +0100406 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100407 public void onPostExecute(PhoneCallDetails[] details) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100408 if (details == null) {
409 // Somewhere went wrong: we're going to bail out and show error to users.
410 Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error,
411 Toast.LENGTH_SHORT).show();
412 finish();
413 return;
414 }
415
416 // We know that all calls are from the same number and the same contact, so pick the
417 // first.
418 PhoneCallDetails firstDetails = details[0];
419 mNumber = firstDetails.number.toString();
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100420 final Uri contactUri = firstDetails.contactUri;
Flavio Lerda12592e82011-08-10 15:36:32 +0100421 final Uri photoUri = firstDetails.photoUri;
422
423 // Set the details header, based on the first phone call.
Flavio Lerdad5678d32011-08-28 13:49:56 +0100424 mPhoneCallDetailsHelper.setCallDetailsHeader(mHeaderTextView, firstDetails);
Flavio Lerda12592e82011-08-10 15:36:32 +0100425
426 // Cache the details about the phone number.
Flavio Lerda12592e82011-08-10 15:36:32 +0100427 final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber);
428 final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber);
429 final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber);
430
431 // Let user view contact details if they exist, otherwise add option to create new
432 // contact from this number.
433 final Intent mainActionIntent;
434 final int mainActionIcon;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100435 final String mainActionDescription;
436
437 final CharSequence nameOrNumber;
438 if (!TextUtils.isEmpty(firstDetails.name)) {
439 nameOrNumber = firstDetails.name;
440 } else {
441 nameOrNumber = firstDetails.number;
442 }
Flavio Lerda12592e82011-08-10 15:36:32 +0100443
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100444 if (contactUri != null) {
445 mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri);
Daisuke Miyakawa3a042e52012-03-07 15:24:37 -0800446 // This will launch People's detail contact screen, so we probably want to
447 // treat it as a separate People task.
448 mainActionIntent.setFlags(
449 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Flavio Lerda12592e82011-08-10 15:36:32 +0100450 mainActionIcon = R.drawable.ic_contacts_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100451 mainActionDescription =
452 getString(R.string.description_view_contact, nameOrNumber);
Flavio Lerda12592e82011-08-10 15:36:32 +0100453 } else if (isVoicemailNumber) {
454 mainActionIntent = null;
455 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100456 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100457 } else if (isSipNumber) {
458 // TODO: This item is currently disabled for SIP addresses, because
459 // the Insert.PHONE extra only works correctly for PSTN numbers.
460 //
461 // To fix this for SIP addresses, we need to:
462 // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if
463 // the current number is a SIP address
464 // - update the contacts UI code to handle Insert.SIP_ADDRESS by
465 // updating the SipAddress field
466 // and then we can remove the "!isSipNumber" check above.
467 mainActionIntent = null;
468 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100469 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100470 } else if (canPlaceCallsTo) {
471 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
472 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
473 mainActionIntent.putExtra(Insert.PHONE, mNumber);
474 mainActionIcon = R.drawable.ic_add_contact_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100475 mainActionDescription = getString(R.string.description_add_contact);
Flavio Lerda12592e82011-08-10 15:36:32 +0100476 } else {
477 // If we cannot call the number, when we probably cannot add it as a contact either.
478 // This is usually the case of private, unknown, or payphone numbers.
479 mainActionIntent = null;
480 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100481 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100482 }
483
484 if (mainActionIntent == null) {
485 mMainActionView.setVisibility(View.INVISIBLE);
486 mMainActionPushLayerView.setVisibility(View.GONE);
Flavio Lerda126a4202011-10-03 11:15:03 +0100487 mHeaderTextView.setVisibility(View.INVISIBLE);
488 mHeaderOverlayView.setVisibility(View.INVISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100489 } else {
490 mMainActionView.setVisibility(View.VISIBLE);
491 mMainActionView.setImageResource(mainActionIcon);
492 mMainActionPushLayerView.setVisibility(View.VISIBLE);
493 mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() {
494 @Override
495 public void onClick(View v) {
496 startActivity(mainActionIntent);
497 }
498 });
Flavio Lerdab184ed62011-08-10 18:17:55 +0100499 mMainActionPushLayerView.setContentDescription(mainActionDescription);
Flavio Lerda126a4202011-10-03 11:15:03 +0100500 mHeaderTextView.setVisibility(View.VISIBLE);
501 mHeaderOverlayView.setVisibility(View.VISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100502 }
503
Flavio Lerda12592e82011-08-10 15:36:32 +0100504 // This action allows to call the number that places the call.
505 if (canPlaceCallsTo) {
506 final CharSequence displayNumber =
507 mPhoneNumberHelper.getDisplayNumber(
508 firstDetails.number, firstDetails.formattedNumber);
509
510 ViewEntry entry = new ViewEntry(
Flavio Lerda4e1d7852011-11-23 15:49:18 +0000511 getString(R.string.menu_callNumber,
512 FormatUtils.forceLeftToRight(displayNumber)),
Daisuke Miyakawafadd5e12011-12-01 17:34:18 -0800513 ContactsUtils.getCallIntent(mNumber),
514 getString(R.string.description_call, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100515
516 // Only show a label if the number is shown and it is not a SIP address.
Flavio Lerda35be86e2011-08-12 14:13:22 +0100517 if (!TextUtils.isEmpty(firstDetails.name)
518 && !TextUtils.isEmpty(firstDetails.number)
Flavio Lerda12592e82011-08-10 15:36:32 +0100519 && !PhoneNumberUtils.isUriNumber(firstDetails.number.toString())) {
520 entry.label = Phone.getTypeLabel(mResources, firstDetails.numberType,
521 firstDetails.numberLabel);
522 }
523
524 // The secondary action allows to send an SMS to the number that placed the
525 // call.
526 if (mPhoneNumberHelper.canSendSmsTo(mNumber)) {
Flavio Lerdab184ed62011-08-10 18:17:55 +0100527 entry.setSecondaryAction(
528 R.drawable.ic_text_holo_dark,
Flavio Lerda12592e82011-08-10 15:36:32 +0100529 new Intent(Intent.ACTION_SENDTO,
Flavio Lerdab184ed62011-08-10 18:17:55 +0100530 Uri.fromParts("sms", mNumber, null)),
531 getString(R.string.description_send_text_message, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100532 }
533
Flavio Lerdab184ed62011-08-10 18:17:55 +0100534 configureCallButton(entry);
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700535 mPhoneNumberToCopy = displayNumber;
536 mPhoneNumberLabelToCopy = entry.label;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100537 } else {
538 disableCallButton();
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700539 mPhoneNumberToCopy = null;
540 mPhoneNumberLabelToCopy = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100541 }
542
Flavio Lerda78d081d2011-10-17 14:44:02 +0100543 mHasEditNumberBeforeCallOption =
544 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
545 mHasTrashOption = hasVoicemail();
546 mHasRemoveFromCallLogOption = !hasVoicemail();
Flavio Lerda599853d2011-09-05 17:50:14 +0100547 invalidateOptionsMenu();
Flavio Lerda12592e82011-08-10 15:36:32 +0100548
Flavio Lerda12592e82011-08-10 15:36:32 +0100549 ListView historyList = (ListView) findViewById(R.id.history);
550 historyList.setAdapter(
551 new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
Flavio Lerdab5a3f5c2011-09-21 19:27:33 +0100552 mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo,
553 findViewById(R.id.controls)));
Flavio Lerdad1333a22011-08-11 16:19:47 +0100554 BackScrollManager.bind(
555 new ScrollableHeader() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100556 private View mControls = findViewById(R.id.controls);
557 private View mPhoto = findViewById(R.id.contact_background_sizer);
558 private View mHeader = findViewById(R.id.photo_text_bar);
559 private View mSeparator = findViewById(R.id.blue_separator);
Flavio Lerdad1333a22011-08-11 16:19:47 +0100560
561 @Override
562 public void setOffset(int offset) {
Flavio Lerda126a4202011-10-03 11:15:03 +0100563 mControls.setY(-offset);
Flavio Lerdad1333a22011-08-11 16:19:47 +0100564 }
565
566 @Override
567 public int getMaximumScrollableHeaderOffset() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100568 // We can scroll the photo out, but we should keep the header if
569 // present.
570 if (mHeader.getVisibility() == View.VISIBLE) {
571 return mPhoto.getHeight() - mHeader.getHeight();
572 } else {
573 // If the header is not present, we should also scroll out the
574 // separator line.
575 return mPhoto.getHeight() + mSeparator.getHeight();
576 }
Flavio Lerdad1333a22011-08-11 16:19:47 +0100577 }
578 },
579 historyList);
Flavio Lerda12592e82011-08-10 15:36:32 +0100580 loadContactPhotos(photoUri);
Flavio Lerda4e63bab2011-08-10 18:26:46 +0100581 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100582 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100583 }
584 mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask());
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100585 }
586
587 /** Return the phone call details for a given call log URI. */
588 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800589 ContentResolver resolver = getContentResolver();
590 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
591 try {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100592 if (callCursor == null || !callCursor.moveToFirst()) {
593 throw new IllegalArgumentException("Cannot find content: " + callUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800594 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100595
596 // Read call log specifics.
597 String number = callCursor.getString(NUMBER_COLUMN_INDEX);
598 long date = callCursor.getLong(DATE_COLUMN_INDEX);
599 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
600 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
601 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100602 final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
603
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100604 if (TextUtils.isEmpty(countryIso)) {
605 countryIso = mDefaultCountryIso;
606 }
607
608 // Formatted phone number.
Flavio Lerda731f8612011-10-07 15:56:20 +0100609 final CharSequence formattedNumber;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100610 // Read contact specifics.
Flavio Lerda731f8612011-10-07 15:56:20 +0100611 final CharSequence nameText;
612 final int numberType;
613 final CharSequence numberLabel;
614 final Uri photoUri;
615 final Uri lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100616 // If this is not a regular number, there is no point in looking it up in the contacts.
Flavio Lerda731f8612011-10-07 15:56:20 +0100617 ContactInfo info =
618 mPhoneNumberHelper.canPlaceCallsTo(number)
Flavio Lerda12ea6522011-10-17 14:08:39 +0100619 && !mPhoneNumberHelper.isVoicemailNumber(number)
Flavio Lerda731f8612011-10-07 15:56:20 +0100620 ? mContactInfoHelper.lookupNumber(number, countryIso)
621 : null;
622 if (info == null) {
623 formattedNumber = mPhoneNumberHelper.getDisplayNumber(number, null);
624 nameText = "";
625 numberType = 0;
626 numberLabel = "";
627 photoUri = null;
628 lookupUri = null;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100629 } else {
Flavio Lerda731f8612011-10-07 15:56:20 +0100630 formattedNumber = info.formattedNumber;
631 nameText = info.name;
632 numberType = info.type;
633 numberLabel = info.label;
634 photoUri = info.photoUri;
635 lookupUri = info.lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100636 }
Flavio Lerda731f8612011-10-07 15:56:20 +0100637 return new PhoneCallDetails(number, formattedNumber, countryIso, geocode,
Flavio Lerdacb805e82011-07-18 10:31:44 +0100638 new int[]{ callType }, date, duration,
Flavio Lerda731f8612011-10-07 15:56:20 +0100639 nameText, numberType, numberLabel, lookupUri, photoUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800640 } finally {
641 if (callCursor != null) {
642 callCursor.close();
643 }
644 }
645 }
646
Flavio Lerda9cafe472011-06-08 14:06:13 +0100647 /** Load the contact photos and places them in the corresponding views. */
Daniel Lehmann362654a2011-07-17 14:16:47 -0700648 private void loadContactPhotos(Uri photoUri) {
Daniel Lehmann2f77c852012-03-30 15:25:31 -0700649 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri,
650 mContactBackgroundView.getWidth(), true);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100651 }
652
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800653 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100654 public final String text;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100655 public final Intent primaryIntent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100656 /** The description for accessibility of the primary action. */
657 public final String primaryDescription;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100658
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100659 public CharSequence label = null;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100660 /** Icon for the secondary action. */
661 public int secondaryIcon = 0;
662 /** Intent for the secondary action. If not null, an icon must be defined. */
663 public Intent secondaryIntent = null;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100664 /** The description for accessibility of the secondary action. */
665 public String secondaryDescription = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700666
Flavio Lerdab184ed62011-08-10 18:17:55 +0100667 public ViewEntry(String text, Intent intent, String description) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800668 this.text = text;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100669 primaryIntent = intent;
670 primaryDescription = description;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100671 }
672
Flavio Lerdab184ed62011-08-10 18:17:55 +0100673 public void setSecondaryAction(int icon, Intent intent, String description) {
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100674 secondaryIcon = icon;
675 secondaryIntent = intent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100676 secondaryDescription = description;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800677 }
678 }
679
Flavio Lerdab184ed62011-08-10 18:17:55 +0100680 /** Disables the call button area, e.g., for private numbers. */
681 private void disableCallButton() {
682 findViewById(R.id.call_and_sms).setVisibility(View.GONE);
683 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700684
Flavio Lerdab184ed62011-08-10 18:17:55 +0100685 /** Configures the call button area using the given entry. */
686 private void configureCallButton(ViewEntry entry) {
687 View convertView = findViewById(R.id.call_and_sms);
688 convertView.setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100689
Flavio Lerdab184ed62011-08-10 18:17:55 +0100690 ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon);
691 View divider = convertView.findViewById(R.id.call_and_sms_divider);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100692 TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100693
Flavio Lerdab184ed62011-08-10 18:17:55 +0100694 View mainAction = convertView.findViewById(R.id.call_and_sms_main_action);
695 mainAction.setOnClickListener(mPrimaryActionListener);
696 mainAction.setTag(entry);
697 mainAction.setContentDescription(entry.primaryDescription);
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700698 mainAction.setOnLongClickListener(mPrimaryLongClickListener);
Flavio Lerdab184ed62011-08-10 18:17:55 +0100699
700 if (entry.secondaryIntent != null) {
701 icon.setOnClickListener(mSecondaryActionListener);
702 icon.setImageResource(entry.secondaryIcon);
703 icon.setVisibility(View.VISIBLE);
704 icon.setTag(entry);
705 icon.setContentDescription(entry.secondaryDescription);
706 divider.setVisibility(View.VISIBLE);
707 } else {
708 icon.setVisibility(View.GONE);
709 divider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800710 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100711 text.setText(entry.text);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700712
Flavio Lerda35be86e2011-08-12 14:13:22 +0100713 TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label);
714 if (TextUtils.isEmpty(entry.label)) {
715 label.setVisibility(View.GONE);
Flavio Lerdab184ed62011-08-10 18:17:55 +0100716 } else {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100717 label.setText(entry.label);
718 label.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800719 }
720 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700721
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100722 protected void updateVoicemailStatusMessage(Cursor statusCursor) {
723 if (statusCursor == null) {
724 mStatusMessageView.setVisibility(View.GONE);
725 return;
726 }
727 final StatusMessage message = getStatusMessage(statusCursor);
728 if (message == null || !message.showInCallDetails()) {
729 mStatusMessageView.setVisibility(View.GONE);
730 return;
731 }
732
733 mStatusMessageView.setVisibility(View.VISIBLE);
734 mStatusMessageText.setText(message.callDetailsMessageId);
735 if (message.actionMessageId != -1) {
736 mStatusMessageAction.setText(message.actionMessageId);
737 }
738 if (message.actionUri != null) {
739 mStatusMessageAction.setClickable(true);
740 mStatusMessageAction.setOnClickListener(new View.OnClickListener() {
741 @Override
742 public void onClick(View v) {
743 startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri));
744 }
745 });
746 } else {
747 mStatusMessageAction.setClickable(false);
748 }
749 }
750
751 private StatusMessage getStatusMessage(Cursor statusCursor) {
752 List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100753 if (messages.size() == 0) {
754 return null;
755 }
756 // There can only be a single status message per source package, so num of messages can
757 // at most be 1.
758 if (messages.size() > 1) {
759 Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." +
760 " Will use the first one.", messages.size()));
761 }
762 return messages.get(0);
763 }
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100764
765 @Override
766 public boolean onCreateOptionsMenu(Menu menu) {
767 getMenuInflater().inflate(R.menu.call_details_options, menu);
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100768 return super.onCreateOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100769 }
770
771 @Override
772 public boolean onPrepareOptionsMenu(Menu menu) {
773 // This action deletes all elements in the group from the call log.
774 // We don't have this action for voicemails, because you can just use the trash button.
Flavio Lerda78d081d2011-10-17 14:44:02 +0100775 menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption);
776 menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption);
777 menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption);
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100778 return super.onPrepareOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100779 }
780
781 @Override
782 public boolean onMenuItemSelected(int featureId, MenuItem item) {
783 switch (item.getItemId()) {
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100784 case android.R.id.home: {
785 onHomeSelected();
786 return true;
787 }
788
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100789 // All the options menu items are handled by onMenu... methods.
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100790 default:
791 throw new IllegalArgumentException();
792 }
793 }
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100794
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100795 public void onMenuRemoveFromCallLog(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100796 final StringBuilder callIds = new StringBuilder();
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100797 for (Uri callUri : getCallLogEntryUris()) {
798 if (callIds.length() != 0) {
799 callIds.append(",");
800 }
801 callIds.append(ContentUris.parseId(callUri));
802 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100803 mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH,
804 new AsyncTask<Void, Void, Void>() {
805 @Override
806 public Void doInBackground(Void... params) {
807 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
808 Calls._ID + " IN (" + callIds + ")", null);
809 return null;
810 }
811
812 @Override
813 public void onPostExecute(Void result) {
814 finish();
815 }
816 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100817 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100818
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100819 public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
Daisuke Miyakawafadd5e12011-12-01 17:34:18 -0800820 startActivity(new Intent(Intent.ACTION_DIAL, ContactsUtils.getCallUri(mNumber)));
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100821 }
822
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100823 public void onMenuTrashVoicemail(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100824 final Uri voicemailUri = getVoicemailUri();
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100825 mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH,
826 new AsyncTask<Void, Void, Void>() {
827 @Override
828 public Void doInBackground(Void... params) {
829 getContentResolver().delete(voicemailUri, null, null);
830 return null;
831 }
832 @Override
833 public void onPostExecute(Void result) {
834 finish();
835 }
836 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100837 }
838
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100839 private void configureActionBar() {
840 ActionBar actionBar = getActionBar();
841 if (actionBar != null) {
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100842 actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100843 }
844 }
845
846 /** Invoked when the user presses the home button in the action bar. */
847 private void onHomeSelected() {
848 Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI);
849 // This will open the call log even if the detail view has been opened directly.
850 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
851 startActivity(intent);
852 finish();
853 }
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100854
855 @Override
856 protected void onPause() {
857 // Immediately stop the proximity sensor.
858 disableProximitySensor(false);
859 mProximitySensorListener.clearPendingRequests();
860 super.onPause();
861 }
862
863 @Override
864 public void enableProximitySensor() {
865 mProximitySensorManager.enable();
866 }
867
868 @Override
869 public void disableProximitySensor(boolean waitForFarState) {
870 mProximitySensorManager.disable(waitForFarState);
871 }
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700872
873 /**
874 * If the phone number is selected, unselect it and return {@code true}.
875 * Otherwise, just {@code false}.
876 */
877 private boolean finishPhoneNumerSelectedActionModeIfShown() {
878 if (mPhoneNumberActionMode == null) return false;
879 mPhoneNumberActionMode.finish();
880 return true;
881 }
882
883 private void startPhoneNumberSelectedActionMode(View targetView) {
884 mPhoneNumberActionMode = startActionMode(new PhoneNumberActionModeCallback(targetView));
885 }
886
Flavio Lerda66f14602012-05-13 15:38:08 +0100887 private void closeSystemDialogs() {
888 sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
889 }
890
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700891 private class PhoneNumberActionModeCallback implements ActionMode.Callback {
892 private final View mTargetView;
893 private final Drawable mOriginalViewBackground;
894
895 public PhoneNumberActionModeCallback(View targetView) {
896 mTargetView = targetView;
897
898 // Highlight the phone number view. Remember the old background, and put a new one.
899 mOriginalViewBackground = mTargetView.getBackground();
900 mTargetView.setBackgroundColor(getResources().getColor(R.color.item_selected));
901 }
902
903 @Override
904 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
905 if (TextUtils.isEmpty(mPhoneNumberToCopy)) return false;
906
907 getMenuInflater().inflate(R.menu.call_details_cab, menu);
908 return true;
909 }
910
911 @Override
912 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
913 return true;
914 }
915
916 @Override
917 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
918 switch (item.getItemId()) {
919 case R.id.copy_phone_number:
920 ClipboardUtils.copyText(CallDetailActivity.this, mPhoneNumberLabelToCopy,
921 mPhoneNumberToCopy, true);
922 mode.finish(); // Close the CAB
923 return true;
924 }
925 return false;
926 }
927
928 @Override
929 public void onDestroyActionMode(ActionMode mode) {
930 mPhoneNumberActionMode = null;
931
932 // Restore the view background.
933 mTargetView.setBackground(mOriginalViewBackground);
934 }
935 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800936}