blob: d126aff90825ce905b3ac5cc76b1d625808ba267 [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;
Hugo Hudson9c747ac2011-08-17 00:23:01 +010025import com.android.contacts.util.AsyncTaskExecutor;
26import com.android.contacts.util.AsyncTaskExecutors;
Hugo Hudsonb002f512011-07-15 17:41:12 +010027import com.android.contacts.voicemail.VoicemailPlaybackFragment;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +010028import com.android.contacts.voicemail.VoicemailStatusHelper;
29import com.android.contacts.voicemail.VoicemailStatusHelper.StatusMessage;
30import com.android.contacts.voicemail.VoicemailStatusHelperImpl;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070031
Flavio Lerdad44e83a2011-07-24 23:10:17 +010032import android.app.ActionBar;
Flavio Lerdab184ed62011-08-10 18:17:55 +010033import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080034import android.content.ContentResolver;
35import android.content.ContentUris;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010036import android.content.ContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080037import android.content.Context;
38import android.content.Intent;
39import android.content.res.Resources;
40import android.database.Cursor;
41import android.net.Uri;
Hugo Hudsona2625e42011-08-10 21:13:23 +010042import android.os.AsyncTask;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080043import android.os.Bundle;
44import android.provider.CallLog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080045import android.provider.CallLog.Calls;
Flavio Lerda9cafe472011-06-08 14:06:13 +010046import android.provider.Contacts.Intents.Insert;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +010047import android.provider.ContactsContract.CommonDataKinds.Phone;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070048import android.provider.ContactsContract.Contacts;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010049import android.provider.VoicemailContract.Voicemails;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080050import android.telephony.PhoneNumberUtils;
51import android.telephony.TelephonyManager;
52import android.text.TextUtils;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010053import android.util.Log;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080054import android.view.KeyEvent;
55import android.view.LayoutInflater;
Flavio Lerda94d7bab2011-07-22 16:52:34 +010056import android.view.Menu;
57import android.view.MenuItem;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080058import android.view.View;
Daniel Lehmannd260de42011-08-01 18:08:38 -070059import android.widget.ImageButton;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080060import android.widget.ImageView;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010061import android.widget.ListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080062import android.widget.TextView;
63import android.widget.Toast;
64
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080065import java.util.List;
66
67/**
68 * Displays the details of a specific call log entry.
Flavio Lerda178eeeb2011-07-11 19:51:40 +010069 * <p>
70 * This activity can be either started with the URI of a single call log entry, or with the
71 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080072 */
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010073public class CallDetailActivity extends Activity implements ProximitySensorAware {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080074 private static final String TAG = "CallDetail";
75
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010076 /** The time to wait before enabling the blank the screen due to the proximity sensor. */
77 private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100;
78 /** The time to wait before disabling the blank the screen due to the proximity sensor. */
79 private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500;
80
Hugo Hudson9c747ac2011-08-17 00:23:01 +010081 /** The enumeration of {@link AsyncTask} objects used in this class. */
82 public enum Tasks {
83 MARK_VOICEMAIL_READ,
84 DELETE_VOICEMAIL_AND_FINISH,
85 REMOVE_FROM_CALL_LOG_AND_FINISH,
86 UPDATE_PHONE_CALL_DETAILS,
87 }
88
Flavio Lerda178eeeb2011-07-11 19:51:40 +010089 /** A long array extra containing ids of call log entries to display. */
Hugo Hudsonb002f512011-07-15 17:41:12 +010090 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
91 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
92 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
93 /** If we should immediately start playback of the voicemail, this extra will be set to true. */
94 public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK";
Flavio Lerda178eeeb2011-07-11 19:51:40 +010095
Flavio Lerda9a208cc2011-07-12 21:05:47 +010096 private CallTypeHelper mCallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010097 private PhoneNumberHelper mPhoneNumberHelper;
Flavio Lerdaafb93bb2011-07-05 14:46:10 +010098 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerdab88abaa2011-08-02 23:38:36 +010099 private TextView mHeaderTextView;
Flavio Lerda126a4202011-10-03 11:15:03 +0100100 private View mHeaderOverlayView;
Flavio Lerdafb63c432011-07-07 17:16:53 +0100101 private ImageView mMainActionView;
Daniel Lehmannd260de42011-08-01 18:08:38 -0700102 private ImageButton mMainActionPushLayerView;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100103 private ImageView mContactBackgroundView;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100104 private AsyncTaskExecutor mAsyncTaskExecutor;
Flavio Lerda731f8612011-10-07 15:56:20 +0100105 private ContactInfoHelper mContactInfoHelper;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800106
107 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +0800108 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700109
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800110 /* package */ LayoutInflater mInflater;
111 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100112 /** Helper to load contact photos. */
113 private ContactPhotoManager mContactPhotoManager;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100114 /** Helper to make async queries to content resolver. */
115 private CallDetailActivityQueryHandler mAsyncQueryHandler;
116 /** Helper to get voicemail status messages. */
117 private VoicemailStatusHelper mVoicemailStatusHelper;
118 // Views related to voicemail status message.
119 private View mStatusMessageView;
120 private TextView mStatusMessageText;
121 private TextView mStatusMessageAction;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700122
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100123 /** Whether we should show "edit number before call" in the options menu. */
124 private boolean mHasEditNumberBeforeCall;
125
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100126 private ProximitySensorManager mProximitySensorManager;
127 private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener();
128
129 /** Listener to changes in the proximity sensor state. */
130 private class ProximitySensorListener implements ProximitySensorManager.Listener {
131 /** Used to show a blank view and hide the action bar. */
132 private final Runnable mBlankRunnable = new Runnable() {
133 @Override
134 public void run() {
135 View blankView = findViewById(R.id.blank);
136 blankView.setVisibility(View.VISIBLE);
137 getActionBar().hide();
138 }
139 };
140 /** Used to remove the blank view and show the action bar. */
141 private final Runnable mUnblankRunnable = new Runnable() {
142 @Override
143 public void run() {
144 View blankView = findViewById(R.id.blank);
145 blankView.setVisibility(View.GONE);
146 getActionBar().show();
147 }
148 };
149
150 @Override
151 public synchronized void onNear() {
152 clearPendingRequests();
153 postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS);
154 }
155
156 @Override
157 public synchronized void onFar() {
158 clearPendingRequests();
159 postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS);
160 }
161
162 /** Removed any delayed requests that may be pending. */
163 public synchronized void clearPendingRequests() {
164 View blankView = findViewById(R.id.blank);
165 blankView.removeCallbacks(mBlankRunnable);
166 blankView.removeCallbacks(mUnblankRunnable);
167 }
168
169 /** Post a {@link Runnable} with a delay on the main thread. */
170 private synchronized void postDelayed(Runnable runnable, long delayMillis) {
171 // Post these instead of executing immediately so that:
172 // - They are guaranteed to be executed on the main thread.
173 // - If the sensor values changes rapidly for some time, the UI will not be
174 // updated immediately.
175 View blankView = findViewById(R.id.blank);
176 blankView.postDelayed(runnable, delayMillis);
177 }
178 }
179
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800180 static final String[] CALL_LOG_PROJECTION = new String[] {
181 CallLog.Calls.DATE,
182 CallLog.Calls.DURATION,
183 CallLog.Calls.NUMBER,
184 CallLog.Calls.TYPE,
Bai Tao09eb04f2010-09-01 15:34:16 +0800185 CallLog.Calls.COUNTRY_ISO,
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100186 CallLog.Calls.GEOCODED_LOCATION,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800187 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700188
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800189 static final int DATE_COLUMN_INDEX = 0;
190 static final int DURATION_COLUMN_INDEX = 1;
191 static final int NUMBER_COLUMN_INDEX = 2;
192 static final int CALL_TYPE_COLUMN_INDEX = 3;
Bai Tao09eb04f2010-09-01 15:34:16 +0800193 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100194 static final int GEOCODED_LOCATION_COLUMN_INDEX = 5;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700195
Flavio Lerdab184ed62011-08-10 18:17:55 +0100196 private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() {
197 @Override
198 public void onClick(View view) {
199 startActivity(((ViewEntry) view.getTag()).primaryIntent);
200 }
201 };
202
203 private final View.OnClickListener mSecondaryActionListener = new View.OnClickListener() {
204 @Override
205 public void onClick(View view) {
206 startActivity(((ViewEntry) view.getTag()).secondaryIntent);
207 }
208 };
209
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800210 @Override
211 protected void onCreate(Bundle icicle) {
212 super.onCreate(icicle);
213
214 setContentView(R.layout.call_detail);
215
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100216 mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800217 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
218 mResources = getResources();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700219
Daniel Lehmann6ecb7322011-08-01 21:39:29 -0700220 mCallTypeHelper = new CallTypeHelper(getResources());
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100221 mPhoneNumberHelper = new PhoneNumberHelper(mResources, getVoicemailNumber());
Flavio Lerda40569562011-07-22 21:51:29 +0100222 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper,
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100223 mPhoneNumberHelper);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100224 mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
225 mAsyncQueryHandler = new CallDetailActivityQueryHandler(this);
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100226 mHeaderTextView = (TextView) findViewById(R.id.header_text);
Flavio Lerda126a4202011-10-03 11:15:03 +0100227 mHeaderOverlayView = findViewById(R.id.photo_text_bar);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100228 mStatusMessageView = findViewById(R.id.voicemail_status);
229 mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message);
230 mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100231 mMainActionView = (ImageView) findViewById(R.id.main_action);
Daniel Lehmannd260de42011-08-01 18:08:38 -0700232 mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100233 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Bai Tao09eb04f2010-09-01 15:34:16 +0800234 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100235 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100236 mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener);
Flavio Lerda731f8612011-10-07 15:56:20 +0100237 mContactInfoHelper = new ContactInfoHelper(this, ContactsUtils.getCurrentCountryIso(this));
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100238 configureActionBar();
Hugo Hudson51ada362011-08-05 14:36:14 +0100239 optionallyHandleVoicemail();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800240 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700241
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800242 @Override
243 public void onResume() {
244 super.onResume();
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100245 updateData(getCallLogEntryUris());
Hugo Hudsonb002f512011-07-15 17:41:12 +0100246 }
247
248 /**
249 * Handle voicemail playback or hide voicemail ui.
250 * <p>
251 * If the Intent used to start this Activity contains the suitable extras, then start voicemail
252 * playback. If it doesn't, then hide the voicemail ui.
253 */
Hugo Hudson757aa552011-07-20 01:15:25 +0100254 private void optionallyHandleVoicemail() {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100255 View voicemailContainer = findViewById(R.id.voicemail_container);
Hugo Hudson157dde12011-07-21 23:28:13 +0100256 if (hasVoicemail()) {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100257 // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri
258 // to play and optionally start the playback.
Hugo Hudson757aa552011-07-20 01:15:25 +0100259 // Do a query to fetch the voicemail status messages.
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100260 VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment();
261 Bundle fragmentArguments = new Bundle();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100262 fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri());
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100263 if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) {
264 fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true);
265 }
266 playbackFragment.setArguments(fragmentArguments);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100267 voicemailContainer.setVisibility(View.VISIBLE);
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100268 getFragmentManager().beginTransaction()
Minh Pham4b25da72011-08-25 13:50:38 -0700269 .add(R.id.voicemail_container, playbackFragment).commitAllowingStateLoss();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100270 mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri());
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100271 markVoicemailAsRead(getVoicemailUri());
Hugo Hudson757aa552011-07-20 01:15:25 +0100272 } else {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100273 // No voicemail uri: hide the status view.
Hugo Hudson757aa552011-07-20 01:15:25 +0100274 mStatusMessageView.setVisibility(View.GONE);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100275 voicemailContainer.setVisibility(View.GONE);
Hugo Hudsonb002f512011-07-15 17:41:12 +0100276 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100277 }
278
Hugo Hudson157dde12011-07-21 23:28:13 +0100279 private boolean hasVoicemail() {
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100280 return getVoicemailUri() != null;
281 }
282
283 private Uri getVoicemailUri() {
284 return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
Hugo Hudson157dde12011-07-21 23:28:13 +0100285 }
286
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100287 private void markVoicemailAsRead(final Uri voicemailUri) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100288 mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100289 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100290 public Void doInBackground(Void... params) {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100291 ContentValues values = new ContentValues();
292 values.put(Voicemails.IS_READ, true);
Flavio Lerda7b9db072011-09-05 13:43:06 +0100293 getContentResolver().update(voicemailUri, values,
294 Voicemails.IS_READ + " = 0", null);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100295 return null;
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100296 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100297 });
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100298 }
299
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100300 /**
301 * Returns the list of URIs to show.
302 * <p>
303 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
304 * a list of ids in the call log added as an extra on the URI.
305 * <p>
306 * If both are available, the data on the intent takes precedence.
307 */
308 private Uri[] getCallLogEntryUris() {
309 Uri uri = getIntent().getData();
310 if (uri != null) {
311 // If there is a data on the intent, it takes precedence over the extra.
312 return new Uri[]{ uri };
313 }
314 long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
315 Uri[] uris = new Uri[ids.length];
316 for (int index = 0; index < ids.length; ++index) {
317 uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]);
318 }
319 return uris;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800320 }
321
322 @Override
323 public boolean onKeyDown(int keyCode, KeyEvent event) {
324 switch (keyCode) {
325 case KeyEvent.KEYCODE_CALL: {
326 // Make sure phone isn't already busy before starting direct call
327 TelephonyManager tm = (TelephonyManager)
328 getSystemService(Context.TELEPHONY_SERVICE);
329 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
330 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
331 Uri.fromParts("tel", mNumber, null));
332 startActivity(callIntent);
333 return true;
334 }
335 }
336 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700337
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800338 return super.onKeyDown(keyCode, event);
339 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700340
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800341 /**
342 * Update user interface with details of given call.
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700343 *
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100344 * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800345 */
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100346 private void updateData(final Uri... callUris) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100347 class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> {
Flavio Lerda12592e82011-08-10 15:36:32 +0100348 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100349 public PhoneCallDetails[] doInBackground(Void... params) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100350 // TODO: All phone calls correspond to the same person, so we can make a single
351 // lookup.
352 final int numCalls = callUris.length;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100353 PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
Flavio Lerda12592e82011-08-10 15:36:32 +0100354 try {
355 for (int index = 0; index < numCalls; ++index) {
356 details[index] = getPhoneCallDetailsForUri(callUris[index]);
357 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100358 return details;
Flavio Lerda12592e82011-08-10 15:36:32 +0100359 } catch (IllegalArgumentException e) {
360 // Something went wrong reading in our primary data.
361 Log.w(TAG, "invalid URI starting call details", e);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100362 return null;
Flavio Lerdacfff16d2011-07-12 23:54:40 +0100363 }
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100364 }
365
Flavio Lerda12592e82011-08-10 15:36:32 +0100366 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100367 public void onPostExecute(PhoneCallDetails[] details) {
Flavio Lerda12592e82011-08-10 15:36:32 +0100368 if (details == null) {
369 // Somewhere went wrong: we're going to bail out and show error to users.
370 Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error,
371 Toast.LENGTH_SHORT).show();
372 finish();
373 return;
374 }
375
376 // We know that all calls are from the same number and the same contact, so pick the
377 // first.
378 PhoneCallDetails firstDetails = details[0];
379 mNumber = firstDetails.number.toString();
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100380 final Uri contactUri = firstDetails.contactUri;
Flavio Lerda12592e82011-08-10 15:36:32 +0100381 final Uri photoUri = firstDetails.photoUri;
382
383 // Set the details header, based on the first phone call.
Flavio Lerdad5678d32011-08-28 13:49:56 +0100384 mPhoneCallDetailsHelper.setCallDetailsHeader(mHeaderTextView, firstDetails);
Flavio Lerda12592e82011-08-10 15:36:32 +0100385
386 // Cache the details about the phone number.
387 final Uri numberCallUri = mPhoneNumberHelper.getCallUri(mNumber);
388 final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber);
389 final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber);
390 final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber);
391
392 // Let user view contact details if they exist, otherwise add option to create new
393 // contact from this number.
394 final Intent mainActionIntent;
395 final int mainActionIcon;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100396 final String mainActionDescription;
397
398 final CharSequence nameOrNumber;
399 if (!TextUtils.isEmpty(firstDetails.name)) {
400 nameOrNumber = firstDetails.name;
401 } else {
402 nameOrNumber = firstDetails.number;
403 }
Flavio Lerda12592e82011-08-10 15:36:32 +0100404
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100405 if (contactUri != null) {
406 mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri);
Flavio Lerda12592e82011-08-10 15:36:32 +0100407 mainActionIcon = R.drawable.ic_contacts_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100408 mainActionDescription =
409 getString(R.string.description_view_contact, nameOrNumber);
Flavio Lerda12592e82011-08-10 15:36:32 +0100410 } else if (isVoicemailNumber) {
411 mainActionIntent = null;
412 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100413 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100414 } else if (isSipNumber) {
415 // TODO: This item is currently disabled for SIP addresses, because
416 // the Insert.PHONE extra only works correctly for PSTN numbers.
417 //
418 // To fix this for SIP addresses, we need to:
419 // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if
420 // the current number is a SIP address
421 // - update the contacts UI code to handle Insert.SIP_ADDRESS by
422 // updating the SipAddress field
423 // and then we can remove the "!isSipNumber" check above.
424 mainActionIntent = null;
425 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100426 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100427 } else if (canPlaceCallsTo) {
428 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
429 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
430 mainActionIntent.putExtra(Insert.PHONE, mNumber);
431 mainActionIcon = R.drawable.ic_add_contact_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100432 mainActionDescription = getString(R.string.description_add_contact);
Flavio Lerda12592e82011-08-10 15:36:32 +0100433 } else {
434 // If we cannot call the number, when we probably cannot add it as a contact either.
435 // This is usually the case of private, unknown, or payphone numbers.
436 mainActionIntent = null;
437 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100438 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100439 }
440
441 if (mainActionIntent == null) {
442 mMainActionView.setVisibility(View.INVISIBLE);
443 mMainActionPushLayerView.setVisibility(View.GONE);
Flavio Lerda126a4202011-10-03 11:15:03 +0100444 mHeaderTextView.setVisibility(View.INVISIBLE);
445 mHeaderOverlayView.setVisibility(View.INVISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100446 } else {
447 mMainActionView.setVisibility(View.VISIBLE);
448 mMainActionView.setImageResource(mainActionIcon);
449 mMainActionPushLayerView.setVisibility(View.VISIBLE);
450 mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() {
451 @Override
452 public void onClick(View v) {
453 startActivity(mainActionIntent);
454 }
455 });
Flavio Lerdab184ed62011-08-10 18:17:55 +0100456 mMainActionPushLayerView.setContentDescription(mainActionDescription);
Flavio Lerda126a4202011-10-03 11:15:03 +0100457 mHeaderTextView.setVisibility(View.VISIBLE);
458 mHeaderOverlayView.setVisibility(View.VISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100459 }
460
Flavio Lerda12592e82011-08-10 15:36:32 +0100461 // This action allows to call the number that places the call.
462 if (canPlaceCallsTo) {
463 final CharSequence displayNumber =
464 mPhoneNumberHelper.getDisplayNumber(
465 firstDetails.number, firstDetails.formattedNumber);
466
467 ViewEntry entry = new ViewEntry(
468 getString(R.string.menu_callNumber, displayNumber),
Flavio Lerdab184ed62011-08-10 18:17:55 +0100469 new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri),
470 getString(R.string.description_call, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100471
472 // Only show a label if the number is shown and it is not a SIP address.
Flavio Lerda35be86e2011-08-12 14:13:22 +0100473 if (!TextUtils.isEmpty(firstDetails.name)
474 && !TextUtils.isEmpty(firstDetails.number)
Flavio Lerda12592e82011-08-10 15:36:32 +0100475 && !PhoneNumberUtils.isUriNumber(firstDetails.number.toString())) {
476 entry.label = Phone.getTypeLabel(mResources, firstDetails.numberType,
477 firstDetails.numberLabel);
478 }
479
480 // The secondary action allows to send an SMS to the number that placed the
481 // call.
482 if (mPhoneNumberHelper.canSendSmsTo(mNumber)) {
Flavio Lerdab184ed62011-08-10 18:17:55 +0100483 entry.setSecondaryAction(
484 R.drawable.ic_text_holo_dark,
Flavio Lerda12592e82011-08-10 15:36:32 +0100485 new Intent(Intent.ACTION_SENDTO,
Flavio Lerdab184ed62011-08-10 18:17:55 +0100486 Uri.fromParts("sms", mNumber, null)),
487 getString(R.string.description_send_text_message, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100488 }
489
Flavio Lerdab184ed62011-08-10 18:17:55 +0100490 configureCallButton(entry);
491 } else {
492 disableCallButton();
Flavio Lerda12592e82011-08-10 15:36:32 +0100493 }
494
495 mHasEditNumberBeforeCall = canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
Flavio Lerda599853d2011-09-05 17:50:14 +0100496 invalidateOptionsMenu();
Flavio Lerda12592e82011-08-10 15:36:32 +0100497
Flavio Lerda12592e82011-08-10 15:36:32 +0100498 ListView historyList = (ListView) findViewById(R.id.history);
499 historyList.setAdapter(
500 new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
Flavio Lerdab5a3f5c2011-09-21 19:27:33 +0100501 mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo,
502 findViewById(R.id.controls)));
Flavio Lerdad1333a22011-08-11 16:19:47 +0100503 BackScrollManager.bind(
504 new ScrollableHeader() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100505 private View mControls = findViewById(R.id.controls);
506 private View mPhoto = findViewById(R.id.contact_background_sizer);
507 private View mHeader = findViewById(R.id.photo_text_bar);
508 private View mSeparator = findViewById(R.id.blue_separator);
Flavio Lerdad1333a22011-08-11 16:19:47 +0100509
510 @Override
511 public void setOffset(int offset) {
Flavio Lerda126a4202011-10-03 11:15:03 +0100512 mControls.setY(-offset);
Flavio Lerdad1333a22011-08-11 16:19:47 +0100513 }
514
515 @Override
516 public int getMaximumScrollableHeaderOffset() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100517 // We can scroll the photo out, but we should keep the header if
518 // present.
519 if (mHeader.getVisibility() == View.VISIBLE) {
520 return mPhoto.getHeight() - mHeader.getHeight();
521 } else {
522 // If the header is not present, we should also scroll out the
523 // separator line.
524 return mPhoto.getHeight() + mSeparator.getHeight();
525 }
Flavio Lerdad1333a22011-08-11 16:19:47 +0100526 }
527 },
528 historyList);
Flavio Lerda12592e82011-08-10 15:36:32 +0100529 loadContactPhotos(photoUri);
Flavio Lerda4e63bab2011-08-10 18:26:46 +0100530 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100531 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100532 }
533 mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask());
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100534 }
535
536 /** Return the phone call details for a given call log URI. */
537 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800538 ContentResolver resolver = getContentResolver();
539 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
540 try {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100541 if (callCursor == null || !callCursor.moveToFirst()) {
542 throw new IllegalArgumentException("Cannot find content: " + callUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800543 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100544
545 // Read call log specifics.
546 String number = callCursor.getString(NUMBER_COLUMN_INDEX);
547 long date = callCursor.getLong(DATE_COLUMN_INDEX);
548 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
549 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
550 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100551 final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
552
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100553 if (TextUtils.isEmpty(countryIso)) {
554 countryIso = mDefaultCountryIso;
555 }
556
557 // Formatted phone number.
Flavio Lerda731f8612011-10-07 15:56:20 +0100558 final CharSequence formattedNumber;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100559 // Read contact specifics.
Flavio Lerda731f8612011-10-07 15:56:20 +0100560 final CharSequence nameText;
561 final int numberType;
562 final CharSequence numberLabel;
563 final Uri photoUri;
564 final Uri lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100565 // 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 +0100566 ContactInfo info =
567 mPhoneNumberHelper.canPlaceCallsTo(number)
568 ? mContactInfoHelper.lookupNumber(number, countryIso)
569 : null;
570 if (info == null) {
571 formattedNumber = mPhoneNumberHelper.getDisplayNumber(number, null);
572 nameText = "";
573 numberType = 0;
574 numberLabel = "";
575 photoUri = null;
576 lookupUri = null;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100577 } else {
Flavio Lerda731f8612011-10-07 15:56:20 +0100578 formattedNumber = info.formattedNumber;
579 nameText = info.name;
580 numberType = info.type;
581 numberLabel = info.label;
582 photoUri = info.photoUri;
583 lookupUri = info.lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100584 }
Flavio Lerda731f8612011-10-07 15:56:20 +0100585 return new PhoneCallDetails(number, formattedNumber, countryIso, geocode,
Flavio Lerdacb805e82011-07-18 10:31:44 +0100586 new int[]{ callType }, date, duration,
Flavio Lerda731f8612011-10-07 15:56:20 +0100587 nameText, numberType, numberLabel, lookupUri, photoUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800588 } finally {
589 if (callCursor != null) {
590 callCursor.close();
591 }
592 }
593 }
594
Flavio Lerda9cafe472011-06-08 14:06:13 +0100595 /** Load the contact photos and places them in the corresponding views. */
Daniel Lehmann362654a2011-07-17 14:16:47 -0700596 private void loadContactPhotos(Uri photoUri) {
Daniel Lehmannecfc26c2011-09-12 17:44:35 -0700597 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri, true, true);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100598 }
599
Flavio Lerda696e8132011-07-05 19:00:23 +0100600 private String getVoicemailNumber() {
601 TelephonyManager telephonyManager =
602 (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
603 return telephonyManager.getVoiceMailNumber();
604 }
605
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800606 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100607 public final String text;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100608 public final Intent primaryIntent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100609 /** The description for accessibility of the primary action. */
610 public final String primaryDescription;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100611
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100612 public CharSequence label = null;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100613 /** Icon for the secondary action. */
614 public int secondaryIcon = 0;
615 /** Intent for the secondary action. If not null, an icon must be defined. */
616 public Intent secondaryIntent = null;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100617 /** The description for accessibility of the secondary action. */
618 public String secondaryDescription = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700619
Flavio Lerdab184ed62011-08-10 18:17:55 +0100620 public ViewEntry(String text, Intent intent, String description) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800621 this.text = text;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100622 primaryIntent = intent;
623 primaryDescription = description;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100624 }
625
Flavio Lerdab184ed62011-08-10 18:17:55 +0100626 public void setSecondaryAction(int icon, Intent intent, String description) {
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100627 secondaryIcon = icon;
628 secondaryIntent = intent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100629 secondaryDescription = description;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800630 }
631 }
632
Flavio Lerdab184ed62011-08-10 18:17:55 +0100633 /** Disables the call button area, e.g., for private numbers. */
634 private void disableCallButton() {
635 findViewById(R.id.call_and_sms).setVisibility(View.GONE);
636 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700637
Flavio Lerdab184ed62011-08-10 18:17:55 +0100638 /** Configures the call button area using the given entry. */
639 private void configureCallButton(ViewEntry entry) {
640 View convertView = findViewById(R.id.call_and_sms);
641 convertView.setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100642
Flavio Lerdab184ed62011-08-10 18:17:55 +0100643 ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon);
644 View divider = convertView.findViewById(R.id.call_and_sms_divider);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100645 TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100646
Flavio Lerdab184ed62011-08-10 18:17:55 +0100647 View mainAction = convertView.findViewById(R.id.call_and_sms_main_action);
648 mainAction.setOnClickListener(mPrimaryActionListener);
649 mainAction.setTag(entry);
650 mainAction.setContentDescription(entry.primaryDescription);
651
652 if (entry.secondaryIntent != null) {
653 icon.setOnClickListener(mSecondaryActionListener);
654 icon.setImageResource(entry.secondaryIcon);
655 icon.setVisibility(View.VISIBLE);
656 icon.setTag(entry);
657 icon.setContentDescription(entry.secondaryDescription);
658 divider.setVisibility(View.VISIBLE);
659 } else {
660 icon.setVisibility(View.GONE);
661 divider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800662 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100663 text.setText(entry.text);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700664
Flavio Lerda35be86e2011-08-12 14:13:22 +0100665 TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label);
666 if (TextUtils.isEmpty(entry.label)) {
667 label.setVisibility(View.GONE);
Flavio Lerdab184ed62011-08-10 18:17:55 +0100668 } else {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100669 label.setText(entry.label);
670 label.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800671 }
672 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700673
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100674 protected void updateVoicemailStatusMessage(Cursor statusCursor) {
675 if (statusCursor == null) {
676 mStatusMessageView.setVisibility(View.GONE);
677 return;
678 }
679 final StatusMessage message = getStatusMessage(statusCursor);
680 if (message == null || !message.showInCallDetails()) {
681 mStatusMessageView.setVisibility(View.GONE);
682 return;
683 }
684
685 mStatusMessageView.setVisibility(View.VISIBLE);
686 mStatusMessageText.setText(message.callDetailsMessageId);
687 if (message.actionMessageId != -1) {
688 mStatusMessageAction.setText(message.actionMessageId);
689 }
690 if (message.actionUri != null) {
691 mStatusMessageAction.setClickable(true);
692 mStatusMessageAction.setOnClickListener(new View.OnClickListener() {
693 @Override
694 public void onClick(View v) {
695 startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri));
696 }
697 });
698 } else {
699 mStatusMessageAction.setClickable(false);
700 }
701 }
702
703 private StatusMessage getStatusMessage(Cursor statusCursor) {
704 List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100705 if (messages.size() == 0) {
706 return null;
707 }
708 // There can only be a single status message per source package, so num of messages can
709 // at most be 1.
710 if (messages.size() > 1) {
711 Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." +
712 " Will use the first one.", messages.size()));
713 }
714 return messages.get(0);
715 }
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100716
717 @Override
718 public boolean onCreateOptionsMenu(Menu menu) {
719 getMenuInflater().inflate(R.menu.call_details_options, menu);
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100720 return super.onCreateOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100721 }
722
723 @Override
724 public boolean onPrepareOptionsMenu(Menu menu) {
725 // This action deletes all elements in the group from the call log.
726 // We don't have this action for voicemails, because you can just use the trash button.
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100727 menu.findItem(R.id.menu_remove_from_call_log).setVisible(!hasVoicemail());
728 menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCall);
729 menu.findItem(R.id.menu_trash).setVisible(hasVoicemail());
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100730 return super.onPrepareOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100731 }
732
733 @Override
734 public boolean onMenuItemSelected(int featureId, MenuItem item) {
735 switch (item.getItemId()) {
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100736 case android.R.id.home: {
737 onHomeSelected();
738 return true;
739 }
740
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100741 // All the options menu items are handled by onMenu... methods.
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100742 default:
743 throw new IllegalArgumentException();
744 }
745 }
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100746
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100747 public void onMenuRemoveFromCallLog(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100748 final StringBuilder callIds = new StringBuilder();
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100749 for (Uri callUri : getCallLogEntryUris()) {
750 if (callIds.length() != 0) {
751 callIds.append(",");
752 }
753 callIds.append(ContentUris.parseId(callUri));
754 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100755 mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH,
756 new AsyncTask<Void, Void, Void>() {
757 @Override
758 public Void doInBackground(Void... params) {
759 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
760 Calls._ID + " IN (" + callIds + ")", null);
761 return null;
762 }
763
764 @Override
765 public void onPostExecute(Void result) {
766 finish();
767 }
768 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100769 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100770
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100771 public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
772 startActivity(new Intent(Intent.ACTION_DIAL, mPhoneNumberHelper.getCallUri(mNumber)));
773 }
774
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100775 public void onMenuTrashVoicemail(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100776 final Uri voicemailUri = getVoicemailUri();
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100777 mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH,
778 new AsyncTask<Void, Void, Void>() {
779 @Override
780 public Void doInBackground(Void... params) {
781 getContentResolver().delete(voicemailUri, null, null);
782 return null;
783 }
784 @Override
785 public void onPostExecute(Void result) {
786 finish();
787 }
788 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100789 }
790
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100791 private void configureActionBar() {
792 ActionBar actionBar = getActionBar();
793 if (actionBar != null) {
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100794 actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100795 }
796 }
797
798 /** Invoked when the user presses the home button in the action bar. */
799 private void onHomeSelected() {
800 Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI);
801 // This will open the call log even if the detail view has been opened directly.
802 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
803 startActivity(intent);
804 finish();
805 }
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100806
807 @Override
808 protected void onPause() {
809 // Immediately stop the proximity sensor.
810 disableProximitySensor(false);
811 mProximitySensorListener.clearPendingRequests();
812 super.onPause();
813 }
814
815 @Override
816 public void enableProximitySensor() {
817 mProximitySensorManager.enable();
818 }
819
820 @Override
821 public void disableProximitySensor(boolean waitForFarState) {
822 mProximitySensorManager.disable(waitForFarState);
823 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800824}