blob: 6224d19485b9a9199110f2c57c0ab18435efdc78 [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;
Hugo Hudsonb002f512011-07-15 17:41:12 +010028import com.android.contacts.voicemail.VoicemailPlaybackFragment;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +010029import com.android.contacts.voicemail.VoicemailStatusHelper;
30import com.android.contacts.voicemail.VoicemailStatusHelper.StatusMessage;
31import com.android.contacts.voicemail.VoicemailStatusHelperImpl;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070032
Flavio Lerdad44e83a2011-07-24 23:10:17 +010033import android.app.ActionBar;
Flavio Lerdab184ed62011-08-10 18:17:55 +010034import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080035import android.content.ContentResolver;
36import android.content.ContentUris;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010037import android.content.ContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080038import android.content.Context;
39import android.content.Intent;
40import android.content.res.Resources;
41import android.database.Cursor;
42import android.net.Uri;
Hugo Hudsona2625e42011-08-10 21:13:23 +010043import android.os.AsyncTask;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080044import android.os.Bundle;
45import android.provider.CallLog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080046import android.provider.CallLog.Calls;
Flavio Lerda9cafe472011-06-08 14:06:13 +010047import android.provider.Contacts.Intents.Insert;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +010048import android.provider.ContactsContract.CommonDataKinds.Phone;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070049import android.provider.ContactsContract.Contacts;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010050import android.provider.VoicemailContract.Voicemails;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080051import android.telephony.PhoneNumberUtils;
52import android.telephony.TelephonyManager;
53import android.text.TextUtils;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010054import android.util.Log;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080055import android.view.KeyEvent;
56import android.view.LayoutInflater;
Flavio Lerda94d7bab2011-07-22 16:52:34 +010057import android.view.Menu;
58import android.view.MenuItem;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080059import android.view.View;
Daniel Lehmannd260de42011-08-01 18:08:38 -070060import android.widget.ImageButton;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080061import android.widget.ImageView;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010062import android.widget.ListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080063import android.widget.TextView;
64import android.widget.Toast;
65
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080066import java.util.List;
67
68/**
69 * Displays the details of a specific call log entry.
Flavio Lerda178eeeb2011-07-11 19:51:40 +010070 * <p>
71 * This activity can be either started with the URI of a single call log entry, or with the
72 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080073 */
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010074public class CallDetailActivity extends Activity implements ProximitySensorAware {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080075 private static final String TAG = "CallDetail";
76
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010077 /** The time to wait before enabling the blank the screen due to the proximity sensor. */
78 private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100;
79 /** The time to wait before disabling the blank the screen due to the proximity sensor. */
80 private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500;
81
Hugo Hudson9c747ac2011-08-17 00:23:01 +010082 /** The enumeration of {@link AsyncTask} objects used in this class. */
83 public enum Tasks {
84 MARK_VOICEMAIL_READ,
85 DELETE_VOICEMAIL_AND_FINISH,
86 REMOVE_FROM_CALL_LOG_AND_FINISH,
87 UPDATE_PHONE_CALL_DETAILS,
88 }
89
Flavio Lerda178eeeb2011-07-11 19:51:40 +010090 /** A long array extra containing ids of call log entries to display. */
Hugo Hudsonb002f512011-07-15 17:41:12 +010091 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
92 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
93 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
94 /** If we should immediately start playback of the voicemail, this extra will be set to true. */
95 public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK";
Flavio Lerda178eeeb2011-07-11 19:51:40 +010096
Flavio Lerda9a208cc2011-07-12 21:05:47 +010097 private CallTypeHelper mCallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010098 private PhoneNumberHelper mPhoneNumberHelper;
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010099 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100100 private TextView mHeaderTextView;
Flavio Lerda126a4202011-10-03 11:15:03 +0100101 private View mHeaderOverlayView;
Flavio Lerdafb63c432011-07-07 17:16:53 +0100102 private ImageView mMainActionView;
Daniel Lehmannd260de42011-08-01 18:08:38 -0700103 private ImageButton mMainActionPushLayerView;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100104 private ImageView mContactBackgroundView;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100105 private AsyncTaskExecutor mAsyncTaskExecutor;
Flavio Lerda731f8612011-10-07 15:56:20 +0100106 private ContactInfoHelper mContactInfoHelper;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800107
108 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +0800109 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700110
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800111 /* package */ LayoutInflater mInflater;
112 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100113 /** Helper to load contact photos. */
114 private ContactPhotoManager mContactPhotoManager;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100115 /** Helper to make async queries to content resolver. */
116 private CallDetailActivityQueryHandler mAsyncQueryHandler;
117 /** Helper to get voicemail status messages. */
118 private VoicemailStatusHelper mVoicemailStatusHelper;
119 // Views related to voicemail status message.
120 private View mStatusMessageView;
121 private TextView mStatusMessageText;
122 private TextView mStatusMessageAction;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700123
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100124 /** Whether we should show "edit number before call" in the options menu. */
Flavio Lerda78d081d2011-10-17 14:44:02 +0100125 private boolean mHasEditNumberBeforeCallOption;
126 /** Whether we should show "trash" in the options menu. */
127 private boolean mHasTrashOption;
128 /** Whether we should show "remove from call log" in the options menu. */
129 private boolean mHasRemoveFromCallLogOption;
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100130
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100131 private ProximitySensorManager mProximitySensorManager;
132 private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener();
133
134 /** Listener to changes in the proximity sensor state. */
135 private class ProximitySensorListener implements ProximitySensorManager.Listener {
136 /** Used to show a blank view and hide the action bar. */
137 private final Runnable mBlankRunnable = new Runnable() {
138 @Override
139 public void run() {
140 View blankView = findViewById(R.id.blank);
141 blankView.setVisibility(View.VISIBLE);
142 getActionBar().hide();
143 }
144 };
145 /** Used to remove the blank view and show the action bar. */
146 private final Runnable mUnblankRunnable = new Runnable() {
147 @Override
148 public void run() {
149 View blankView = findViewById(R.id.blank);
150 blankView.setVisibility(View.GONE);
151 getActionBar().show();
152 }
153 };
154
155 @Override
156 public synchronized void onNear() {
157 clearPendingRequests();
158 postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS);
159 }
160
161 @Override
162 public synchronized void onFar() {
163 clearPendingRequests();
164 postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS);
165 }
166
167 /** Removed any delayed requests that may be pending. */
168 public synchronized void clearPendingRequests() {
169 View blankView = findViewById(R.id.blank);
170 blankView.removeCallbacks(mBlankRunnable);
171 blankView.removeCallbacks(mUnblankRunnable);
172 }
173
174 /** Post a {@link Runnable} with a delay on the main thread. */
175 private synchronized void postDelayed(Runnable runnable, long delayMillis) {
176 // Post these instead of executing immediately so that:
177 // - They are guaranteed to be executed on the main thread.
178 // - If the sensor values changes rapidly for some time, the UI will not be
179 // updated immediately.
180 View blankView = findViewById(R.id.blank);
181 blankView.postDelayed(runnable, delayMillis);
182 }
183 }
184
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800185 static final String[] CALL_LOG_PROJECTION = new String[] {
186 CallLog.Calls.DATE,
187 CallLog.Calls.DURATION,
188 CallLog.Calls.NUMBER,
189 CallLog.Calls.TYPE,
Bai Tao09eb04f2010-09-01 15:34:16 +0800190 CallLog.Calls.COUNTRY_ISO,
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100191 CallLog.Calls.GEOCODED_LOCATION,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800192 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700193
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800194 static final int DATE_COLUMN_INDEX = 0;
195 static final int DURATION_COLUMN_INDEX = 1;
196 static final int NUMBER_COLUMN_INDEX = 2;
197 static final int CALL_TYPE_COLUMN_INDEX = 3;
Bai Tao09eb04f2010-09-01 15:34:16 +0800198 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100199 static final int GEOCODED_LOCATION_COLUMN_INDEX = 5;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700200
Flavio Lerdab184ed62011-08-10 18:17:55 +0100201 private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() {
202 @Override
203 public void onClick(View view) {
204 startActivity(((ViewEntry) view.getTag()).primaryIntent);
205 }
206 };
207
208 private final View.OnClickListener mSecondaryActionListener = new View.OnClickListener() {
209 @Override
210 public void onClick(View view) {
211 startActivity(((ViewEntry) view.getTag()).secondaryIntent);
212 }
213 };
214
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800215 @Override
216 protected void onCreate(Bundle icicle) {
217 super.onCreate(icicle);
218
219 setContentView(R.layout.call_detail);
220
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100221 mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800222 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
223 mResources = getResources();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700224
Daniel Lehmann6ecb7322011-08-01 21:39:29 -0700225 mCallTypeHelper = new CallTypeHelper(getResources());
Flavio Lerda0646f272011-10-17 13:58:53 +0100226 mPhoneNumberHelper = new PhoneNumberHelper(mResources);
Flavio Lerda40569562011-07-22 21:51:29 +0100227 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper,
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100228 mPhoneNumberHelper);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100229 mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
230 mAsyncQueryHandler = new CallDetailActivityQueryHandler(this);
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100231 mHeaderTextView = (TextView) findViewById(R.id.header_text);
Flavio Lerda126a4202011-10-03 11:15:03 +0100232 mHeaderOverlayView = findViewById(R.id.photo_text_bar);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100233 mStatusMessageView = findViewById(R.id.voicemail_status);
234 mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message);
235 mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100236 mMainActionView = (ImageView) findViewById(R.id.main_action);
Daniel Lehmannd260de42011-08-01 18:08:38 -0700237 mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100238 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Bai Tao09eb04f2010-09-01 15:34:16 +0800239 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100240 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100241 mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener);
Flavio Lerda731f8612011-10-07 15:56:20 +0100242 mContactInfoHelper = new ContactInfoHelper(this, ContactsUtils.getCurrentCountryIso(this));
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100243 configureActionBar();
Hugo Hudson51ada362011-08-05 14:36:14 +0100244 optionallyHandleVoicemail();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800245 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700246
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800247 @Override
248 public void onResume() {
249 super.onResume();
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100250 updateData(getCallLogEntryUris());
Hugo Hudsonb002f512011-07-15 17:41:12 +0100251 }
252
253 /**
254 * Handle voicemail playback or hide voicemail ui.
255 * <p>
256 * If the Intent used to start this Activity contains the suitable extras, then start voicemail
257 * playback. If it doesn't, then hide the voicemail ui.
258 */
Hugo Hudson757aa552011-07-20 01:15:25 +0100259 private void optionallyHandleVoicemail() {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100260 View voicemailContainer = findViewById(R.id.voicemail_container);
Hugo Hudson157dde12011-07-21 23:28:13 +0100261 if (hasVoicemail()) {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100262 // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri
263 // to play and optionally start the playback.
Hugo Hudson757aa552011-07-20 01:15:25 +0100264 // Do a query to fetch the voicemail status messages.
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100265 VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment();
266 Bundle fragmentArguments = new Bundle();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100267 fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri());
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100268 if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) {
269 fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true);
270 }
271 playbackFragment.setArguments(fragmentArguments);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100272 voicemailContainer.setVisibility(View.VISIBLE);
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100273 getFragmentManager().beginTransaction()
Minh Pham4b25da72011-08-25 13:50:38 -0700274 .add(R.id.voicemail_container, playbackFragment).commitAllowingStateLoss();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100275 mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri());
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100276 markVoicemailAsRead(getVoicemailUri());
Hugo Hudson757aa552011-07-20 01:15:25 +0100277 } else {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100278 // No voicemail uri: hide the status view.
Hugo Hudson757aa552011-07-20 01:15:25 +0100279 mStatusMessageView.setVisibility(View.GONE);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100280 voicemailContainer.setVisibility(View.GONE);
Hugo Hudsonb002f512011-07-15 17:41:12 +0100281 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100282 }
283
Hugo Hudson157dde12011-07-21 23:28:13 +0100284 private boolean hasVoicemail() {
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100285 return getVoicemailUri() != null;
286 }
287
288 private Uri getVoicemailUri() {
289 return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
Hugo Hudson157dde12011-07-21 23:28:13 +0100290 }
291
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100292 private void markVoicemailAsRead(final Uri voicemailUri) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100293 mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100294 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100295 public Void doInBackground(Void... params) {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100296 ContentValues values = new ContentValues();
297 values.put(Voicemails.IS_READ, true);
Flavio Lerda7b9db072011-09-05 13:43:06 +0100298 getContentResolver().update(voicemailUri, values,
299 Voicemails.IS_READ + " = 0", null);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100300 return null;
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100301 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100302 });
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100303 }
304
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100305 /**
306 * Returns the list of URIs to show.
307 * <p>
308 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
309 * a list of ids in the call log added as an extra on the URI.
310 * <p>
311 * If both are available, the data on the intent takes precedence.
312 */
313 private Uri[] getCallLogEntryUris() {
314 Uri uri = getIntent().getData();
315 if (uri != null) {
316 // If there is a data on the intent, it takes precedence over the extra.
317 return new Uri[]{ uri };
318 }
319 long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
320 Uri[] uris = new Uri[ids.length];
321 for (int index = 0; index < ids.length; ++index) {
322 uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]);
323 }
324 return uris;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800325 }
326
327 @Override
328 public boolean onKeyDown(int keyCode, KeyEvent event) {
329 switch (keyCode) {
330 case KeyEvent.KEYCODE_CALL: {
331 // Make sure phone isn't already busy before starting direct call
332 TelephonyManager tm = (TelephonyManager)
333 getSystemService(Context.TELEPHONY_SERVICE);
334 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
335 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
336 Uri.fromParts("tel", mNumber, null));
337 startActivity(callIntent);
338 return true;
339 }
340 }
341 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700342
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800343 return super.onKeyDown(keyCode, event);
344 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700345
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800346 /**
347 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700348 *
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100349 * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800350 */
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100351 private void updateData(final Uri... callUris) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100352 class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> {
Flavio Lerda12592e82011-08-10 15:36:32 +0100353 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100354 public PhoneCallDetails[] doInBackground(Void... params) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100355 // TODO: All phone calls correspond to the same person, so we can make a single
356 // lookup.
357 final int numCalls = callUris.length;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100358 PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
Flavio Lerda12592e82011-08-10 15:36:32 +0100359 try {
360 for (int index = 0; index < numCalls; ++index) {
361 details[index] = getPhoneCallDetailsForUri(callUris[index]);
362 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100363 return details;
Flavio Lerda12592e82011-08-10 15:36:32 +0100364 } catch (IllegalArgumentException e) {
365 // Something went wrong reading in our primary data.
366 Log.w(TAG, "invalid URI starting call details", e);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100367 return null;
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100368 }
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100369 }
370
Flavio Lerda12592e82011-08-10 15:36:32 +0100371 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100372 public void onPostExecute(PhoneCallDetails[] details) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100373 if (details == null) {
374 // Somewhere went wrong: we're going to bail out and show error to users.
375 Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error,
376 Toast.LENGTH_SHORT).show();
377 finish();
378 return;
379 }
380
381 // We know that all calls are from the same number and the same contact, so pick the
382 // first.
383 PhoneCallDetails firstDetails = details[0];
384 mNumber = firstDetails.number.toString();
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100385 final Uri contactUri = firstDetails.contactUri;
Flavio Lerda12592e82011-08-10 15:36:32 +0100386 final Uri photoUri = firstDetails.photoUri;
387
388 // Set the details header, based on the first phone call.
Flavio Lerdad5678d32011-08-28 13:49:56 +0100389 mPhoneCallDetailsHelper.setCallDetailsHeader(mHeaderTextView, firstDetails);
Flavio Lerda12592e82011-08-10 15:36:32 +0100390
391 // Cache the details about the phone number.
392 final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber);
393 final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber);
394 final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber);
395 final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber);
396
397 // Let user view contact details if they exist, otherwise add option to create new
398 // contact from this number.
399 final Intent mainActionIntent;
400 final int mainActionIcon;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100401 final String mainActionDescription;
402
403 final CharSequence nameOrNumber;
404 if (!TextUtils.isEmpty(firstDetails.name)) {
405 nameOrNumber = firstDetails.name;
406 } else {
407 nameOrNumber = firstDetails.number;
408 }
Flavio Lerda12592e82011-08-10 15:36:32 +0100409
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100410 if (contactUri != null) {
411 mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri);
Flavio Lerda12592e82011-08-10 15:36:32 +0100412 mainActionIcon = R.drawable.ic_contacts_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100413 mainActionDescription =
414 getString(R.string.description_view_contact, nameOrNumber);
Flavio Lerda12592e82011-08-10 15:36:32 +0100415 } else if (isVoicemailNumber) {
416 mainActionIntent = null;
417 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100418 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100419 } else if (isSipNumber) {
420 // TODO: This item is currently disabled for SIP addresses, because
421 // the Insert.PHONE extra only works correctly for PSTN numbers.
422 //
423 // To fix this for SIP addresses, we need to:
424 // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if
425 // the current number is a SIP address
426 // - update the contacts UI code to handle Insert.SIP_ADDRESS by
427 // updating the SipAddress field
428 // and then we can remove the "!isSipNumber" check above.
429 mainActionIntent = null;
430 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100431 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100432 } else if (canPlaceCallsTo) {
433 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
434 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
435 mainActionIntent.putExtra(Insert.PHONE, mNumber);
436 mainActionIcon = R.drawable.ic_add_contact_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100437 mainActionDescription = getString(R.string.description_add_contact);
Flavio Lerda12592e82011-08-10 15:36:32 +0100438 } else {
439 // If we cannot call the number, when we probably cannot add it as a contact either.
440 // This is usually the case of private, unknown, or payphone numbers.
441 mainActionIntent = null;
442 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100443 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100444 }
445
446 if (mainActionIntent == null) {
447 mMainActionView.setVisibility(View.INVISIBLE);
448 mMainActionPushLayerView.setVisibility(View.GONE);
Flavio Lerda126a4202011-10-03 11:15:03 +0100449 mHeaderTextView.setVisibility(View.INVISIBLE);
450 mHeaderOverlayView.setVisibility(View.INVISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100451 } else {
452 mMainActionView.setVisibility(View.VISIBLE);
453 mMainActionView.setImageResource(mainActionIcon);
454 mMainActionPushLayerView.setVisibility(View.VISIBLE);
455 mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() {
456 @Override
457 public void onClick(View v) {
458 startActivity(mainActionIntent);
459 }
460 });
Flavio Lerdab184ed62011-08-10 18:17:55 +0100461 mMainActionPushLayerView.setContentDescription(mainActionDescription);
Flavio Lerda126a4202011-10-03 11:15:03 +0100462 mHeaderTextView.setVisibility(View.VISIBLE);
463 mHeaderOverlayView.setVisibility(View.VISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100464 }
465
Flavio Lerda12592e82011-08-10 15:36:32 +0100466 // This action allows to call the number that places the call.
467 if (canPlaceCallsTo) {
468 final CharSequence displayNumber =
469 mPhoneNumberHelper.getDisplayNumber(
470 firstDetails.number, firstDetails.formattedNumber);
471
472 ViewEntry entry = new ViewEntry(
Flavio Lerda4e1d7852011-11-23 15:49:18 +0000473 getString(R.string.menu_callNumber,
474 FormatUtils.forceLeftToRight(displayNumber)),
Flavio Lerdab184ed62011-08-10 18:17:55 +0100475 new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri),
476 getString(R.string.description_call, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100477
478 // Only show a label if the number is shown and it is not a SIP address.
Flavio Lerda35be86e2011-08-12 14:13:22 +0100479 if (!TextUtils.isEmpty(firstDetails.name)
480 && !TextUtils.isEmpty(firstDetails.number)
Flavio Lerda12592e82011-08-10 15:36:32 +0100481 && !PhoneNumberUtils.isUriNumber(firstDetails.number.toString())) {
482 entry.label = Phone.getTypeLabel(mResources, firstDetails.numberType,
483 firstDetails.numberLabel);
484 }
485
486 // The secondary action allows to send an SMS to the number that placed the
487 // call.
488 if (mPhoneNumberHelper.canSendSmsTo(mNumber)) {
Flavio Lerdab184ed62011-08-10 18:17:55 +0100489 entry.setSecondaryAction(
490 R.drawable.ic_text_holo_dark,
Flavio Lerda12592e82011-08-10 15:36:32 +0100491 new Intent(Intent.ACTION_SENDTO,
Flavio Lerdab184ed62011-08-10 18:17:55 +0100492 Uri.fromParts("sms", mNumber, null)),
493 getString(R.string.description_send_text_message, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100494 }
495
Flavio Lerdab184ed62011-08-10 18:17:55 +0100496 configureCallButton(entry);
497 } else {
498 disableCallButton();
Flavio Lerda12592e82011-08-10 15:36:32 +0100499 }
500
Flavio Lerda78d081d2011-10-17 14:44:02 +0100501 mHasEditNumberBeforeCallOption =
502 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
503 mHasTrashOption = hasVoicemail();
504 mHasRemoveFromCallLogOption = !hasVoicemail();
Flavio Lerda599853d2011-09-05 17:50:14 +0100505 invalidateOptionsMenu();
Flavio Lerda12592e82011-08-10 15:36:32 +0100506
Flavio Lerda12592e82011-08-10 15:36:32 +0100507 ListView historyList = (ListView) findViewById(R.id.history);
508 historyList.setAdapter(
509 new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
Flavio Lerdab5a3f5c2011-09-21 19:27:33 +0100510 mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo,
511 findViewById(R.id.controls)));
Flavio Lerdad1333a22011-08-11 16:19:47 +0100512 BackScrollManager.bind(
513 new ScrollableHeader() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100514 private View mControls = findViewById(R.id.controls);
515 private View mPhoto = findViewById(R.id.contact_background_sizer);
516 private View mHeader = findViewById(R.id.photo_text_bar);
517 private View mSeparator = findViewById(R.id.blue_separator);
Flavio Lerdad1333a22011-08-11 16:19:47 +0100518
519 @Override
520 public void setOffset(int offset) {
Flavio Lerda126a4202011-10-03 11:15:03 +0100521 mControls.setY(-offset);
Flavio Lerdad1333a22011-08-11 16:19:47 +0100522 }
523
524 @Override
525 public int getMaximumScrollableHeaderOffset() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100526 // We can scroll the photo out, but we should keep the header if
527 // present.
528 if (mHeader.getVisibility() == View.VISIBLE) {
529 return mPhoto.getHeight() - mHeader.getHeight();
530 } else {
531 // If the header is not present, we should also scroll out the
532 // separator line.
533 return mPhoto.getHeight() + mSeparator.getHeight();
534 }
Flavio Lerdad1333a22011-08-11 16:19:47 +0100535 }
536 },
537 historyList);
Flavio Lerda12592e82011-08-10 15:36:32 +0100538 loadContactPhotos(photoUri);
Flavio Lerda4e63bab2011-08-10 18:26:46 +0100539 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100540 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100541 }
542 mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask());
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100543 }
544
545 /** Return the phone call details for a given call log URI. */
546 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800547 ContentResolver resolver = getContentResolver();
548 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
549 try {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100550 if (callCursor == null || !callCursor.moveToFirst()) {
551 throw new IllegalArgumentException("Cannot find content: " + callUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800552 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100553
554 // Read call log specifics.
555 String number = callCursor.getString(NUMBER_COLUMN_INDEX);
556 long date = callCursor.getLong(DATE_COLUMN_INDEX);
557 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
558 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
559 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100560 final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
561
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100562 if (TextUtils.isEmpty(countryIso)) {
563 countryIso = mDefaultCountryIso;
564 }
565
566 // Formatted phone number.
Flavio Lerda731f8612011-10-07 15:56:20 +0100567 final CharSequence formattedNumber;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100568 // Read contact specifics.
Flavio Lerda731f8612011-10-07 15:56:20 +0100569 final CharSequence nameText;
570 final int numberType;
571 final CharSequence numberLabel;
572 final Uri photoUri;
573 final Uri lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100574 // 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 +0100575 ContactInfo info =
576 mPhoneNumberHelper.canPlaceCallsTo(number)
Flavio Lerda12ea6522011-10-17 14:08:39 +0100577 && !mPhoneNumberHelper.isVoicemailNumber(number)
Flavio Lerda731f8612011-10-07 15:56:20 +0100578 ? mContactInfoHelper.lookupNumber(number, countryIso)
579 : null;
580 if (info == null) {
581 formattedNumber = mPhoneNumberHelper.getDisplayNumber(number, null);
582 nameText = "";
583 numberType = 0;
584 numberLabel = "";
585 photoUri = null;
586 lookupUri = null;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100587 } else {
Flavio Lerda731f8612011-10-07 15:56:20 +0100588 formattedNumber = info.formattedNumber;
589 nameText = info.name;
590 numberType = info.type;
591 numberLabel = info.label;
592 photoUri = info.photoUri;
593 lookupUri = info.lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100594 }
Flavio Lerda731f8612011-10-07 15:56:20 +0100595 return new PhoneCallDetails(number, formattedNumber, countryIso, geocode,
Flavio Lerdacb805e82011-07-18 10:31:44 +0100596 new int[]{ callType }, date, duration,
Flavio Lerda731f8612011-10-07 15:56:20 +0100597 nameText, numberType, numberLabel, lookupUri, photoUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800598 } finally {
599 if (callCursor != null) {
600 callCursor.close();
601 }
602 }
603 }
604
Flavio Lerda9cafe472011-06-08 14:06:13 +0100605 /** Load the contact photos and places them in the corresponding views. */
Daniel Lehmann362654a2011-07-17 14:16:47 -0700606 private void loadContactPhotos(Uri photoUri) {
Daniel Lehmannecfc26c2011-09-12 17:44:35 -0700607 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri, true, true);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100608 }
609
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800610 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100611 public final String text;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100612 public final Intent primaryIntent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100613 /** The description for accessibility of the primary action. */
614 public final String primaryDescription;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100615
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100616 public CharSequence label = null;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100617 /** Icon for the secondary action. */
618 public int secondaryIcon = 0;
619 /** Intent for the secondary action. If not null, an icon must be defined. */
620 public Intent secondaryIntent = null;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100621 /** The description for accessibility of the secondary action. */
622 public String secondaryDescription = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700623
Flavio Lerdab184ed62011-08-10 18:17:55 +0100624 public ViewEntry(String text, Intent intent, String description) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800625 this.text = text;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100626 primaryIntent = intent;
627 primaryDescription = description;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100628 }
629
Flavio Lerdab184ed62011-08-10 18:17:55 +0100630 public void setSecondaryAction(int icon, Intent intent, String description) {
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100631 secondaryIcon = icon;
632 secondaryIntent = intent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100633 secondaryDescription = description;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800634 }
635 }
636
Flavio Lerdab184ed62011-08-10 18:17:55 +0100637 /** Disables the call button area, e.g., for private numbers. */
638 private void disableCallButton() {
639 findViewById(R.id.call_and_sms).setVisibility(View.GONE);
640 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700641
Flavio Lerdab184ed62011-08-10 18:17:55 +0100642 /** Configures the call button area using the given entry. */
643 private void configureCallButton(ViewEntry entry) {
644 View convertView = findViewById(R.id.call_and_sms);
645 convertView.setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100646
Flavio Lerdab184ed62011-08-10 18:17:55 +0100647 ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon);
648 View divider = convertView.findViewById(R.id.call_and_sms_divider);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100649 TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100650
Flavio Lerdab184ed62011-08-10 18:17:55 +0100651 View mainAction = convertView.findViewById(R.id.call_and_sms_main_action);
652 mainAction.setOnClickListener(mPrimaryActionListener);
653 mainAction.setTag(entry);
654 mainAction.setContentDescription(entry.primaryDescription);
655
656 if (entry.secondaryIntent != null) {
657 icon.setOnClickListener(mSecondaryActionListener);
658 icon.setImageResource(entry.secondaryIcon);
659 icon.setVisibility(View.VISIBLE);
660 icon.setTag(entry);
661 icon.setContentDescription(entry.secondaryDescription);
662 divider.setVisibility(View.VISIBLE);
663 } else {
664 icon.setVisibility(View.GONE);
665 divider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800666 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100667 text.setText(entry.text);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700668
Flavio Lerda35be86e2011-08-12 14:13:22 +0100669 TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label);
670 if (TextUtils.isEmpty(entry.label)) {
671 label.setVisibility(View.GONE);
Flavio Lerdab184ed62011-08-10 18:17:55 +0100672 } else {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100673 label.setText(entry.label);
674 label.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800675 }
676 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700677
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100678 protected void updateVoicemailStatusMessage(Cursor statusCursor) {
679 if (statusCursor == null) {
680 mStatusMessageView.setVisibility(View.GONE);
681 return;
682 }
683 final StatusMessage message = getStatusMessage(statusCursor);
684 if (message == null || !message.showInCallDetails()) {
685 mStatusMessageView.setVisibility(View.GONE);
686 return;
687 }
688
689 mStatusMessageView.setVisibility(View.VISIBLE);
690 mStatusMessageText.setText(message.callDetailsMessageId);
691 if (message.actionMessageId != -1) {
692 mStatusMessageAction.setText(message.actionMessageId);
693 }
694 if (message.actionUri != null) {
695 mStatusMessageAction.setClickable(true);
696 mStatusMessageAction.setOnClickListener(new View.OnClickListener() {
697 @Override
698 public void onClick(View v) {
699 startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri));
700 }
701 });
702 } else {
703 mStatusMessageAction.setClickable(false);
704 }
705 }
706
707 private StatusMessage getStatusMessage(Cursor statusCursor) {
708 List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100709 if (messages.size() == 0) {
710 return null;
711 }
712 // There can only be a single status message per source package, so num of messages can
713 // at most be 1.
714 if (messages.size() > 1) {
715 Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." +
716 " Will use the first one.", messages.size()));
717 }
718 return messages.get(0);
719 }
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100720
721 @Override
722 public boolean onCreateOptionsMenu(Menu menu) {
723 getMenuInflater().inflate(R.menu.call_details_options, menu);
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100724 return super.onCreateOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100725 }
726
727 @Override
728 public boolean onPrepareOptionsMenu(Menu menu) {
729 // This action deletes all elements in the group from the call log.
730 // We don't have this action for voicemails, because you can just use the trash button.
Flavio Lerda78d081d2011-10-17 14:44:02 +0100731 menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption);
732 menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption);
733 menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption);
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100734 return super.onPrepareOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100735 }
736
737 @Override
738 public boolean onMenuItemSelected(int featureId, MenuItem item) {
739 switch (item.getItemId()) {
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100740 case android.R.id.home: {
741 onHomeSelected();
742 return true;
743 }
744
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100745 // All the options menu items are handled by onMenu... methods.
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100746 default:
747 throw new IllegalArgumentException();
748 }
749 }
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100750
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100751 public void onMenuRemoveFromCallLog(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100752 final StringBuilder callIds = new StringBuilder();
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100753 for (Uri callUri : getCallLogEntryUris()) {
754 if (callIds.length() != 0) {
755 callIds.append(",");
756 }
757 callIds.append(ContentUris.parseId(callUri));
758 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100759 mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH,
760 new AsyncTask<Void, Void, Void>() {
761 @Override
762 public Void doInBackground(Void... params) {
763 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
764 Calls._ID + " IN (" + callIds + ")", null);
765 return null;
766 }
767
768 @Override
769 public void onPostExecute(Void result) {
770 finish();
771 }
772 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100773 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100774
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100775 public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
776 startActivity(new Intent(Intent.ACTION_DIAL, mPhoneNumberHelper.getCallUri(mNumber)));
777 }
778
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100779 public void onMenuTrashVoicemail(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100780 final Uri voicemailUri = getVoicemailUri();
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100781 mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH,
782 new AsyncTask<Void, Void, Void>() {
783 @Override
784 public Void doInBackground(Void... params) {
785 getContentResolver().delete(voicemailUri, null, null);
786 return null;
787 }
788 @Override
789 public void onPostExecute(Void result) {
790 finish();
791 }
792 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100793 }
794
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100795 private void configureActionBar() {
796 ActionBar actionBar = getActionBar();
797 if (actionBar != null) {
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100798 actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100799 }
800 }
801
802 /** Invoked when the user presses the home button in the action bar. */
803 private void onHomeSelected() {
804 Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI);
805 // This will open the call log even if the detail view has been opened directly.
806 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
807 startActivity(intent);
808 finish();
809 }
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100810
811 @Override
812 protected void onPause() {
813 // Immediately stop the proximity sensor.
814 disableProximitySensor(false);
815 mProximitySensorListener.clearPendingRequests();
816 super.onPause();
817 }
818
819 @Override
820 public void enableProximitySensor() {
821 mProximitySensorManager.enable();
822 }
823
824 @Override
825 public void disableProximitySensor(boolean waitForFarState) {
826 mProximitySensorManager.disable(waitForFarState);
827 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800828}