blob: 1fac6c8a17aa34f62295102d4bae28a9d37b6042 [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 Lerdad1333a22011-08-11 16:19:47 +010019import com.android.contacts.BackScrollManager.ScrollableHeader;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010020import com.android.contacts.calllog.CallDetailHistoryAdapter;
21import com.android.contacts.calllog.CallTypeHelper;
Flavio Lerda731f8612011-10-07 15:56:20 +010022import com.android.contacts.calllog.ContactInfo;
23import com.android.contacts.calllog.ContactInfoHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010024import com.android.contacts.calllog.PhoneNumberHelper;
Flavio Lerda4e1d7852011-11-23 15:49:18 +000025import com.android.contacts.format.FormatUtils;
Hugo Hudson9c747ac2011-08-17 00:23:01 +010026import com.android.contacts.util.AsyncTaskExecutor;
27import com.android.contacts.util.AsyncTaskExecutors;
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -070028import com.android.contacts.util.ClipboardUtils;
Daisuke Miyakawa499ea322012-01-24 12:45:51 -080029import com.android.contacts.util.Constants;
Hugo Hudsonb002f512011-07-15 17:41:12 +010030import com.android.contacts.voicemail.VoicemailPlaybackFragment;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +010031import com.android.contacts.voicemail.VoicemailStatusHelper;
32import com.android.contacts.voicemail.VoicemailStatusHelper.StatusMessage;
33import com.android.contacts.voicemail.VoicemailStatusHelperImpl;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070034
Flavio Lerdad44e83a2011-07-24 23:10:17 +010035import android.app.ActionBar;
Flavio Lerdab184ed62011-08-10 18:17:55 +010036import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080037import android.content.ContentResolver;
38import android.content.ContentUris;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010039import android.content.ContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080040import android.content.Context;
41import android.content.Intent;
42import android.content.res.Resources;
43import android.database.Cursor;
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -070044import android.graphics.drawable.Drawable;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080045import android.net.Uri;
Hugo Hudsona2625e42011-08-10 21:13:23 +010046import android.os.AsyncTask;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080047import android.os.Bundle;
48import android.provider.CallLog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080049import android.provider.CallLog.Calls;
Flavio Lerda9cafe472011-06-08 14:06:13 +010050import android.provider.Contacts.Intents.Insert;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +010051import android.provider.ContactsContract.CommonDataKinds.Phone;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070052import android.provider.ContactsContract.Contacts;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010053import android.provider.VoicemailContract.Voicemails;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080054import android.telephony.PhoneNumberUtils;
55import android.telephony.TelephonyManager;
56import android.text.TextUtils;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010057import android.util.Log;
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -070058import android.view.ActionMode;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080059import android.view.KeyEvent;
60import android.view.LayoutInflater;
Flavio Lerda94d7bab2011-07-22 16:52:34 +010061import android.view.Menu;
62import android.view.MenuItem;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080063import android.view.View;
Daniel Lehmannd260de42011-08-01 18:08:38 -070064import android.widget.ImageButton;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080065import android.widget.ImageView;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010066import android.widget.ListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080067import android.widget.TextView;
68import android.widget.Toast;
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 Lerda178eeeb2011-07-11 19:51:40 +0100100
Flavio Lerda9a208cc2011-07-12 21:05:47 +0100101 private CallTypeHelper mCallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100102 private PhoneNumberHelper mPhoneNumberHelper;
Flavio Lerdaafb93bb2011-07-05 14:46:10 +0100103 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100104 private TextView mHeaderTextView;
Flavio Lerda126a4202011-10-03 11:15:03 +0100105 private View mHeaderOverlayView;
Flavio Lerdafb63c432011-07-07 17:16:53 +0100106 private ImageView mMainActionView;
Daniel Lehmannd260de42011-08-01 18:08:38 -0700107 private ImageButton mMainActionPushLayerView;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100108 private ImageView mContactBackgroundView;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100109 private AsyncTaskExecutor mAsyncTaskExecutor;
Flavio Lerda731f8612011-10-07 15:56:20 +0100110 private ContactInfoHelper mContactInfoHelper;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800111
112 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +0800113 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700114
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800115 /* package */ LayoutInflater mInflater;
116 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100117 /** Helper to load contact photos. */
118 private ContactPhotoManager mContactPhotoManager;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100119 /** 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 Plotnikovd0d776d2009-08-19 17:38:04 -0700127
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100128 /** Whether we should show "edit number before call" in the options menu. */
Flavio Lerda78d081d2011-10-17 14:44:02 +0100129 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 Lerda94d7bab2011-07-22 16:52:34 +0100134
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100135 private ProximitySensorManager mProximitySensorManager;
136 private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener();
137
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700138 /**
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 Lerdafd1b98b2011-08-24 19:55:15 +0100147 /** 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 Project7aa0e4c2009-03-03 19:32:21 -0800198 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 Tao09eb04f2010-09-01 15:34:16 +0800203 CallLog.Calls.COUNTRY_ISO,
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100204 CallLog.Calls.GEOCODED_LOCATION,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800205 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700206
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800207 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 Tao09eb04f2010-09-01 15:34:16 +0800211 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100212 static final int GEOCODED_LOCATION_COLUMN_INDEX = 5;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700213
Flavio Lerdab184ed62011-08-10 18:17:55 +0100214 private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() {
215 @Override
216 public void onClick(View view) {
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700217 if (finishPhoneNumerSelectedActionModeIfShown()) {
218 return;
219 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100220 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 Onuki5ff2dfc2012-04-19 15:00:20 -0700227 if (finishPhoneNumerSelectedActionModeIfShown()) {
228 return;
229 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100230 startActivity(((ViewEntry) view.getTag()).secondaryIntent);
231 }
232 };
233
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700234 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 Project7aa0e4c2009-03-03 19:32:21 -0800246 @Override
247 protected void onCreate(Bundle icicle) {
248 super.onCreate(icicle);
249
250 setContentView(R.layout.call_detail);
251
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100252 mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800253 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
254 mResources = getResources();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700255
Daniel Lehmann6ecb7322011-08-01 21:39:29 -0700256 mCallTypeHelper = new CallTypeHelper(getResources());
Flavio Lerda0646f272011-10-17 13:58:53 +0100257 mPhoneNumberHelper = new PhoneNumberHelper(mResources);
Flavio Lerda40569562011-07-22 21:51:29 +0100258 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper,
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100259 mPhoneNumberHelper);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100260 mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
261 mAsyncQueryHandler = new CallDetailActivityQueryHandler(this);
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100262 mHeaderTextView = (TextView) findViewById(R.id.header_text);
Flavio Lerda126a4202011-10-03 11:15:03 +0100263 mHeaderOverlayView = findViewById(R.id.photo_text_bar);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100264 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 Lerdafb63c432011-07-07 17:16:53 +0100267 mMainActionView = (ImageView) findViewById(R.id.main_action);
Daniel Lehmannd260de42011-08-01 18:08:38 -0700268 mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100269 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Bai Tao09eb04f2010-09-01 15:34:16 +0800270 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100271 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100272 mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener);
Flavio Lerda731f8612011-10-07 15:56:20 +0100273 mContactInfoHelper = new ContactInfoHelper(this, ContactsUtils.getCurrentCountryIso(this));
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100274 configureActionBar();
Hugo Hudson51ada362011-08-05 14:36:14 +0100275 optionallyHandleVoicemail();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800276 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700277
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800278 @Override
279 public void onResume() {
280 super.onResume();
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100281 updateData(getCallLogEntryUris());
Hugo Hudsonb002f512011-07-15 17:41:12 +0100282 }
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 Hudson757aa552011-07-20 01:15:25 +0100290 private void optionallyHandleVoicemail() {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100291 View voicemailContainer = findViewById(R.id.voicemail_container);
Hugo Hudson157dde12011-07-21 23:28:13 +0100292 if (hasVoicemail()) {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100293 // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri
294 // to play and optionally start the playback.
Hugo Hudson757aa552011-07-20 01:15:25 +0100295 // Do a query to fetch the voicemail status messages.
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100296 VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment();
297 Bundle fragmentArguments = new Bundle();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100298 fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri());
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100299 if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) {
300 fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true);
301 }
302 playbackFragment.setArguments(fragmentArguments);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100303 voicemailContainer.setVisibility(View.VISIBLE);
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100304 getFragmentManager().beginTransaction()
Minh Pham4b25da72011-08-25 13:50:38 -0700305 .add(R.id.voicemail_container, playbackFragment).commitAllowingStateLoss();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100306 mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri());
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100307 markVoicemailAsRead(getVoicemailUri());
Hugo Hudson757aa552011-07-20 01:15:25 +0100308 } else {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100309 // No voicemail uri: hide the status view.
Hugo Hudson757aa552011-07-20 01:15:25 +0100310 mStatusMessageView.setVisibility(View.GONE);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100311 voicemailContainer.setVisibility(View.GONE);
Hugo Hudsonb002f512011-07-15 17:41:12 +0100312 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100313 }
314
Hugo Hudson157dde12011-07-21 23:28:13 +0100315 private boolean hasVoicemail() {
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100316 return getVoicemailUri() != null;
317 }
318
319 private Uri getVoicemailUri() {
320 return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
Hugo Hudson157dde12011-07-21 23:28:13 +0100321 }
322
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100323 private void markVoicemailAsRead(final Uri voicemailUri) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100324 mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100325 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100326 public Void doInBackground(Void... params) {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100327 ContentValues values = new ContentValues();
328 values.put(Voicemails.IS_READ, true);
Flavio Lerda7b9db072011-09-05 13:43:06 +0100329 getContentResolver().update(voicemailUri, values,
330 Voicemails.IS_READ + " = 0", null);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100331 return null;
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100332 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100333 });
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100334 }
335
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100336 /**
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 Project7aa0e4c2009-03-03 19:32:21 -0800356 }
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 Miyakawafadd5e12011-12-01 17:34:18 -0800366 startActivity(ContactsUtils.getCallIntent(
Daisuke Miyakawa499ea322012-01-24 12:45:51 -0800367 Uri.fromParts(Constants.SCHEME_TEL, mNumber, null)));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800368 return true;
369 }
370 }
371 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700372
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800373 return super.onKeyDown(keyCode, event);
374 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700375
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800376 /**
377 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700378 *
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100379 * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800380 */
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100381 private void updateData(final Uri... callUris) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100382 class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> {
Flavio Lerda12592e82011-08-10 15:36:32 +0100383 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100384 public PhoneCallDetails[] doInBackground(Void... params) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100385 // TODO: All phone calls correspond to the same person, so we can make a single
386 // lookup.
387 final int numCalls = callUris.length;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100388 PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
Flavio Lerda12592e82011-08-10 15:36:32 +0100389 try {
390 for (int index = 0; index < numCalls; ++index) {
391 details[index] = getPhoneCallDetailsForUri(callUris[index]);
392 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100393 return details;
Flavio Lerda12592e82011-08-10 15:36:32 +0100394 } catch (IllegalArgumentException e) {
395 // Something went wrong reading in our primary data.
396 Log.w(TAG, "invalid URI starting call details", e);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100397 return null;
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100398 }
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100399 }
400
Flavio Lerda12592e82011-08-10 15:36:32 +0100401 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100402 public void onPostExecute(PhoneCallDetails[] details) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100403 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 Lerda071aa0d2011-08-22 10:26:27 +0100415 final Uri contactUri = firstDetails.contactUri;
Flavio Lerda12592e82011-08-10 15:36:32 +0100416 final Uri photoUri = firstDetails.photoUri;
417
418 // Set the details header, based on the first phone call.
Flavio Lerdad5678d32011-08-28 13:49:56 +0100419 mPhoneCallDetailsHelper.setCallDetailsHeader(mHeaderTextView, firstDetails);
Flavio Lerda12592e82011-08-10 15:36:32 +0100420
421 // Cache the details about the phone number.
Flavio Lerda12592e82011-08-10 15:36:32 +0100422 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 Lerdab184ed62011-08-10 18:17:55 +0100430 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 Lerda12592e82011-08-10 15:36:32 +0100438
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100439 if (contactUri != null) {
440 mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri);
Daisuke Miyakawa3a042e52012-03-07 15:24:37 -0800441 // 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 Lerda12592e82011-08-10 15:36:32 +0100445 mainActionIcon = R.drawable.ic_contacts_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100446 mainActionDescription =
447 getString(R.string.description_view_contact, nameOrNumber);
Flavio Lerda12592e82011-08-10 15:36:32 +0100448 } else if (isVoicemailNumber) {
449 mainActionIntent = null;
450 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100451 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100452 } 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 Lerdab184ed62011-08-10 18:17:55 +0100464 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100465 } 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 Lerdab184ed62011-08-10 18:17:55 +0100470 mainActionDescription = getString(R.string.description_add_contact);
Flavio Lerda12592e82011-08-10 15:36:32 +0100471 } 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 Lerdab184ed62011-08-10 18:17:55 +0100476 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100477 }
478
479 if (mainActionIntent == null) {
480 mMainActionView.setVisibility(View.INVISIBLE);
481 mMainActionPushLayerView.setVisibility(View.GONE);
Flavio Lerda126a4202011-10-03 11:15:03 +0100482 mHeaderTextView.setVisibility(View.INVISIBLE);
483 mHeaderOverlayView.setVisibility(View.INVISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100484 } 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 Lerdab184ed62011-08-10 18:17:55 +0100494 mMainActionPushLayerView.setContentDescription(mainActionDescription);
Flavio Lerda126a4202011-10-03 11:15:03 +0100495 mHeaderTextView.setVisibility(View.VISIBLE);
496 mHeaderOverlayView.setVisibility(View.VISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100497 }
498
Flavio Lerda12592e82011-08-10 15:36:32 +0100499 // 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 Lerda4e1d7852011-11-23 15:49:18 +0000506 getString(R.string.menu_callNumber,
507 FormatUtils.forceLeftToRight(displayNumber)),
Daisuke Miyakawafadd5e12011-12-01 17:34:18 -0800508 ContactsUtils.getCallIntent(mNumber),
509 getString(R.string.description_call, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100510
511 // Only show a label if the number is shown and it is not a SIP address.
Flavio Lerda35be86e2011-08-12 14:13:22 +0100512 if (!TextUtils.isEmpty(firstDetails.name)
513 && !TextUtils.isEmpty(firstDetails.number)
Flavio Lerda12592e82011-08-10 15:36:32 +0100514 && !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 Lerdab184ed62011-08-10 18:17:55 +0100522 entry.setSecondaryAction(
523 R.drawable.ic_text_holo_dark,
Flavio Lerda12592e82011-08-10 15:36:32 +0100524 new Intent(Intent.ACTION_SENDTO,
Flavio Lerdab184ed62011-08-10 18:17:55 +0100525 Uri.fromParts("sms", mNumber, null)),
526 getString(R.string.description_send_text_message, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100527 }
528
Flavio Lerdab184ed62011-08-10 18:17:55 +0100529 configureCallButton(entry);
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700530 mPhoneNumberToCopy = displayNumber;
531 mPhoneNumberLabelToCopy = entry.label;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100532 } else {
533 disableCallButton();
Makoto Onuki5ff2dfc2012-04-19 15:00:20 -0700534 mPhoneNumberToCopy = null;
535 mPhoneNumberLabelToCopy = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100536 }
537
Flavio Lerda78d081d2011-10-17 14:44:02 +0100538 mHasEditNumberBeforeCallOption =
539 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
540 mHasTrashOption = hasVoicemail();
541 mHasRemoveFromCallLogOption = !hasVoicemail();
Flavio Lerda599853d2011-09-05 17:50:14 +0100542 invalidateOptionsMenu();
Flavio Lerda12592e82011-08-10 15:36:32 +0100543
Flavio Lerda12592e82011-08-10 15:36:32 +0100544 ListView historyList = (ListView) findViewById(R.id.history);
545 historyList.setAdapter(
546 new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
Flavio Lerdab5a3f5c2011-09-21 19:27:33 +0100547 mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo,
548 findViewById(R.id.controls)));
Flavio Lerdad1333a22011-08-11 16:19:47 +0100549 BackScrollManager.bind(
550 new ScrollableHeader() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100551 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 Lerdad1333a22011-08-11 16:19:47 +0100555
556 @Override
557 public void setOffset(int offset) {
Flavio Lerda126a4202011-10-03 11:15:03 +0100558 mControls.setY(-offset);
Flavio Lerdad1333a22011-08-11 16:19:47 +0100559 }
560
561 @Override
562 public int getMaximumScrollableHeaderOffset() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100563 // 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 Lerdad1333a22011-08-11 16:19:47 +0100572 }
573 },
574 historyList);
Flavio Lerda12592e82011-08-10 15:36:32 +0100575 loadContactPhotos(photoUri);
Flavio Lerda4e63bab2011-08-10 18:26:46 +0100576 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100577 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100578 }
579 mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask());
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100580 }
581
582 /** Return the phone call details for a given call log URI. */
583 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800584 ContentResolver resolver = getContentResolver();
585 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
586 try {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100587 if (callCursor == null || !callCursor.moveToFirst()) {
588 throw new IllegalArgumentException("Cannot find content: " + callUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800589 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100590
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 Lerda71fc6ec2011-08-09 17:24:29 +0100597 final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
598
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100599 if (TextUtils.isEmpty(countryIso)) {
600 countryIso = mDefaultCountryIso;
601 }
602
603 // Formatted phone number.
Flavio Lerda731f8612011-10-07 15:56:20 +0100604 final CharSequence formattedNumber;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100605 // Read contact specifics.
Flavio Lerda731f8612011-10-07 15:56:20 +0100606 final CharSequence nameText;
607 final int numberType;
608 final CharSequence numberLabel;
609 final Uri photoUri;
610 final Uri lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100611 // 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 +0100612 ContactInfo info =
613 mPhoneNumberHelper.canPlaceCallsTo(number)
Flavio Lerda12ea6522011-10-17 14:08:39 +0100614 && !mPhoneNumberHelper.isVoicemailNumber(number)
Flavio Lerda731f8612011-10-07 15:56:20 +0100615 ? 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 Lerda178eeeb2011-07-11 19:51:40 +0100624 } else {
Flavio Lerda731f8612011-10-07 15:56:20 +0100625 formattedNumber = info.formattedNumber;
626 nameText = info.name;
627 numberType = info.type;
628 numberLabel = info.label;
629 photoUri = info.photoUri;
630 lookupUri = info.lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100631 }
Flavio Lerda731f8612011-10-07 15:56:20 +0100632 return new PhoneCallDetails(number, formattedNumber, countryIso, geocode,
Flavio Lerdacb805e82011-07-18 10:31:44 +0100633 new int[]{ callType }, date, duration,
Flavio Lerda731f8612011-10-07 15:56:20 +0100634 nameText, numberType, numberLabel, lookupUri, photoUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800635 } finally {
636 if (callCursor != null) {
637 callCursor.close();
638 }
639 }
640 }
641
Flavio Lerda9cafe472011-06-08 14:06:13 +0100642 /** Load the contact photos and places them in the corresponding views. */
Daniel Lehmann362654a2011-07-17 14:16:47 -0700643 private void loadContactPhotos(Uri photoUri) {
Daniel Lehmann2f77c852012-03-30 15:25:31 -0700644 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri,
645 mContactBackgroundView.getWidth(), true);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100646 }
647
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800648 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100649 public final String text;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100650 public final Intent primaryIntent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100651 /** The description for accessibility of the primary action. */
652 public final String primaryDescription;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100653
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100654 public CharSequence label = null;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100655 /** 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 Lerdab184ed62011-08-10 18:17:55 +0100659 /** The description for accessibility of the secondary action. */
660 public String secondaryDescription = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700661
Flavio Lerdab184ed62011-08-10 18:17:55 +0100662 public ViewEntry(String text, Intent intent, String description) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800663 this.text = text;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100664 primaryIntent = intent;
665 primaryDescription = description;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100666 }
667
Flavio Lerdab184ed62011-08-10 18:17:55 +0100668 public void setSecondaryAction(int icon, Intent intent, String description) {
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100669 secondaryIcon = icon;
670 secondaryIntent = intent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100671 secondaryDescription = description;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800672 }
673 }
674
Flavio Lerdab184ed62011-08-10 18:17:55 +0100675 /** 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 Plotnikovd0d776d2009-08-19 17:38:04 -0700679
Flavio Lerdab184ed62011-08-10 18:17:55 +0100680 /** 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 Lerda8ebfa3d2011-08-10 14:35:22 +0100684
Flavio Lerdab184ed62011-08-10 18:17:55 +0100685 ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon);
686 View divider = convertView.findViewById(R.id.call_and_sms_divider);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100687 TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100688
Flavio Lerdab184ed62011-08-10 18:17:55 +0100689 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 Onuki5ff2dfc2012-04-19 15:00:20 -0700693 mainAction.setOnLongClickListener(mPrimaryLongClickListener);
Flavio Lerdab184ed62011-08-10 18:17:55 +0100694
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 Project7aa0e4c2009-03-03 19:32:21 -0800705 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100706 text.setText(entry.text);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700707
Flavio Lerda35be86e2011-08-12 14:13:22 +0100708 TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label);
709 if (TextUtils.isEmpty(entry.label)) {
710 label.setVisibility(View.GONE);
Flavio Lerdab184ed62011-08-10 18:17:55 +0100711 } else {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100712 label.setText(entry.label);
713 label.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800714 }
715 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700716
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100717 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 Chatterjee0cb82242011-07-19 19:29:37 +0100748 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 Lerda94d7bab2011-07-22 16:52:34 +0100759
760 @Override
761 public boolean onCreateOptionsMenu(Menu menu) {
762 getMenuInflater().inflate(R.menu.call_details_options, menu);
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100763 return super.onCreateOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100764 }
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 Lerda78d081d2011-10-17 14:44:02 +0100770 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 Hudsonc2f09c32011-07-30 16:31:28 +0100773 return super.onPrepareOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100774 }
775
776 @Override
777 public boolean onMenuItemSelected(int featureId, MenuItem item) {
778 switch (item.getItemId()) {
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100779 case android.R.id.home: {
780 onHomeSelected();
781 return true;
782 }
783
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100784 // All the options menu items are handled by onMenu... methods.
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100785 default:
786 throw new IllegalArgumentException();
787 }
788 }
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100789
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100790 public void onMenuRemoveFromCallLog(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100791 final StringBuilder callIds = new StringBuilder();
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100792 for (Uri callUri : getCallLogEntryUris()) {
793 if (callIds.length() != 0) {
794 callIds.append(",");
795 }
796 callIds.append(ContentUris.parseId(callUri));
797 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100798 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 Hudsonc2f09c32011-07-30 16:31:28 +0100812 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100813
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100814 public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
Daisuke Miyakawafadd5e12011-12-01 17:34:18 -0800815 startActivity(new Intent(Intent.ACTION_DIAL, ContactsUtils.getCallUri(mNumber)));
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100816 }
817
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100818 public void onMenuTrashVoicemail(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100819 final Uri voicemailUri = getVoicemailUri();
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100820 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 Hudsonc2f09c32011-07-30 16:31:28 +0100832 }
833
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100834 private void configureActionBar() {
835 ActionBar actionBar = getActionBar();
836 if (actionBar != null) {
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100837 actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100838 }
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 Lerdafd1b98b2011-08-24 19:55:15 +0100849
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 Onuki5ff2dfc2012-04-19 15:00:20 -0700867
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 Project7aa0e4c2009-03-03 19:32:21 -0800927}