blob: 428e2e8f83123e78e0e66d58d6ffa9bc3c54d6db [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;
Daisuke Miyakawa499ea322012-01-24 12:45:51 -080028import com.android.contacts.util.Constants;
Hugo Hudsonb002f512011-07-15 17:41:12 +010029import com.android.contacts.voicemail.VoicemailPlaybackFragment;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +010030import com.android.contacts.voicemail.VoicemailStatusHelper;
31import com.android.contacts.voicemail.VoicemailStatusHelper.StatusMessage;
32import com.android.contacts.voicemail.VoicemailStatusHelperImpl;
Amith Yamasani8bbe2f22009-03-24 21:24:12 -070033
Flavio Lerdad44e83a2011-07-24 23:10:17 +010034import android.app.ActionBar;
Flavio Lerdab184ed62011-08-10 18:17:55 +010035import android.app.Activity;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080036import android.content.ContentResolver;
37import android.content.ContentUris;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010038import android.content.ContentValues;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080039import android.content.Context;
40import android.content.Intent;
41import android.content.res.Resources;
42import android.database.Cursor;
43import android.net.Uri;
Hugo Hudsona2625e42011-08-10 21:13:23 +010044import android.os.AsyncTask;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080045import android.os.Bundle;
46import android.provider.CallLog;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080047import android.provider.CallLog.Calls;
Flavio Lerda9cafe472011-06-08 14:06:13 +010048import android.provider.Contacts.Intents.Insert;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +010049import android.provider.ContactsContract.CommonDataKinds.Phone;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -070050import android.provider.ContactsContract.Contacts;
Debashish Chatterjee0a139002011-08-02 18:27:11 +010051import android.provider.VoicemailContract.Voicemails;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080052import android.telephony.PhoneNumberUtils;
53import android.telephony.TelephonyManager;
54import android.text.TextUtils;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010055import android.util.Log;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080056import android.view.KeyEvent;
57import android.view.LayoutInflater;
Flavio Lerda94d7bab2011-07-22 16:52:34 +010058import android.view.Menu;
59import android.view.MenuItem;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080060import android.view.View;
Daniel Lehmannd260de42011-08-01 18:08:38 -070061import android.widget.ImageButton;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080062import android.widget.ImageView;
Flavio Lerda9a208cc2011-07-12 21:05:47 +010063import android.widget.ListView;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080064import android.widget.TextView;
65import android.widget.Toast;
66
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080067import java.util.List;
68
69/**
70 * Displays the details of a specific call log entry.
Flavio Lerda178eeeb2011-07-11 19:51:40 +010071 * <p>
72 * This activity can be either started with the URI of a single call log entry, or with the
73 * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries.
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080074 */
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010075public class CallDetailActivity extends Activity implements ProximitySensorAware {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -080076 private static final String TAG = "CallDetail";
77
Flavio Lerdafd1b98b2011-08-24 19:55:15 +010078 /** The time to wait before enabling the blank the screen due to the proximity sensor. */
79 private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100;
80 /** The time to wait before disabling the blank the screen due to the proximity sensor. */
81 private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500;
82
Hugo Hudson9c747ac2011-08-17 00:23:01 +010083 /** The enumeration of {@link AsyncTask} objects used in this class. */
84 public enum Tasks {
85 MARK_VOICEMAIL_READ,
86 DELETE_VOICEMAIL_AND_FINISH,
87 REMOVE_FROM_CALL_LOG_AND_FINISH,
88 UPDATE_PHONE_CALL_DETAILS,
89 }
90
Flavio Lerda178eeeb2011-07-11 19:51:40 +010091 /** A long array extra containing ids of call log entries to display. */
Hugo Hudsonb002f512011-07-15 17:41:12 +010092 public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS";
93 /** If we are started with a voicemail, we'll find the uri to play with this extra. */
94 public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
95 /** If we should immediately start playback of the voicemail, this extra will be set to true. */
96 public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK";
Flavio Lerda178eeeb2011-07-11 19:51:40 +010097
Flavio Lerda9a208cc2011-07-12 21:05:47 +010098 private CallTypeHelper mCallTypeHelper;
Flavio Lerda178eeeb2011-07-11 19:51:40 +010099 private PhoneNumberHelper mPhoneNumberHelper;
Flavio Lerdaafb93bb2011-07-05 14:46:10 +0100100 private PhoneCallDetailsHelper mPhoneCallDetailsHelper;
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100101 private TextView mHeaderTextView;
Flavio Lerda126a4202011-10-03 11:15:03 +0100102 private View mHeaderOverlayView;
Flavio Lerdafb63c432011-07-07 17:16:53 +0100103 private ImageView mMainActionView;
Daniel Lehmannd260de42011-08-01 18:08:38 -0700104 private ImageButton mMainActionPushLayerView;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100105 private ImageView mContactBackgroundView;
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100106 private AsyncTaskExecutor mAsyncTaskExecutor;
Flavio Lerda731f8612011-10-07 15:56:20 +0100107 private ContactInfoHelper mContactInfoHelper;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800108
109 private String mNumber = null;
Bai Tao09eb04f2010-09-01 15:34:16 +0800110 private String mDefaultCountryIso;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700111
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800112 /* package */ LayoutInflater mInflater;
113 /* package */ Resources mResources;
Flavio Lerda9cafe472011-06-08 14:06:13 +0100114 /** Helper to load contact photos. */
115 private ContactPhotoManager mContactPhotoManager;
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100116 /** Helper to make async queries to content resolver. */
117 private CallDetailActivityQueryHandler mAsyncQueryHandler;
118 /** Helper to get voicemail status messages. */
119 private VoicemailStatusHelper mVoicemailStatusHelper;
120 // Views related to voicemail status message.
121 private View mStatusMessageView;
122 private TextView mStatusMessageText;
123 private TextView mStatusMessageAction;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700124
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100125 /** Whether we should show "edit number before call" in the options menu. */
Flavio Lerda78d081d2011-10-17 14:44:02 +0100126 private boolean mHasEditNumberBeforeCallOption;
127 /** Whether we should show "trash" in the options menu. */
128 private boolean mHasTrashOption;
129 /** Whether we should show "remove from call log" in the options menu. */
130 private boolean mHasRemoveFromCallLogOption;
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100131
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100132 private ProximitySensorManager mProximitySensorManager;
133 private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener();
134
135 /** Listener to changes in the proximity sensor state. */
136 private class ProximitySensorListener implements ProximitySensorManager.Listener {
137 /** Used to show a blank view and hide the action bar. */
138 private final Runnable mBlankRunnable = new Runnable() {
139 @Override
140 public void run() {
141 View blankView = findViewById(R.id.blank);
142 blankView.setVisibility(View.VISIBLE);
143 getActionBar().hide();
144 }
145 };
146 /** Used to remove the blank view and show the action bar. */
147 private final Runnable mUnblankRunnable = new Runnable() {
148 @Override
149 public void run() {
150 View blankView = findViewById(R.id.blank);
151 blankView.setVisibility(View.GONE);
152 getActionBar().show();
153 }
154 };
155
156 @Override
157 public synchronized void onNear() {
158 clearPendingRequests();
159 postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS);
160 }
161
162 @Override
163 public synchronized void onFar() {
164 clearPendingRequests();
165 postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS);
166 }
167
168 /** Removed any delayed requests that may be pending. */
169 public synchronized void clearPendingRequests() {
170 View blankView = findViewById(R.id.blank);
171 blankView.removeCallbacks(mBlankRunnable);
172 blankView.removeCallbacks(mUnblankRunnable);
173 }
174
175 /** Post a {@link Runnable} with a delay on the main thread. */
176 private synchronized void postDelayed(Runnable runnable, long delayMillis) {
177 // Post these instead of executing immediately so that:
178 // - They are guaranteed to be executed on the main thread.
179 // - If the sensor values changes rapidly for some time, the UI will not be
180 // updated immediately.
181 View blankView = findViewById(R.id.blank);
182 blankView.postDelayed(runnable, delayMillis);
183 }
184 }
185
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800186 static final String[] CALL_LOG_PROJECTION = new String[] {
187 CallLog.Calls.DATE,
188 CallLog.Calls.DURATION,
189 CallLog.Calls.NUMBER,
190 CallLog.Calls.TYPE,
Bai Tao09eb04f2010-09-01 15:34:16 +0800191 CallLog.Calls.COUNTRY_ISO,
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100192 CallLog.Calls.GEOCODED_LOCATION,
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800193 };
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700194
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800195 static final int DATE_COLUMN_INDEX = 0;
196 static final int DURATION_COLUMN_INDEX = 1;
197 static final int NUMBER_COLUMN_INDEX = 2;
198 static final int CALL_TYPE_COLUMN_INDEX = 3;
Bai Tao09eb04f2010-09-01 15:34:16 +0800199 static final int COUNTRY_ISO_COLUMN_INDEX = 4;
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100200 static final int GEOCODED_LOCATION_COLUMN_INDEX = 5;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700201
Flavio Lerdab184ed62011-08-10 18:17:55 +0100202 private final View.OnClickListener mPrimaryActionListener = new View.OnClickListener() {
203 @Override
204 public void onClick(View view) {
205 startActivity(((ViewEntry) view.getTag()).primaryIntent);
206 }
207 };
208
209 private final View.OnClickListener mSecondaryActionListener = new View.OnClickListener() {
210 @Override
211 public void onClick(View view) {
212 startActivity(((ViewEntry) view.getTag()).secondaryIntent);
213 }
214 };
215
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800216 @Override
217 protected void onCreate(Bundle icicle) {
218 super.onCreate(icicle);
219
220 setContentView(R.layout.call_detail);
221
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100222 mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800223 mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
224 mResources = getResources();
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700225
Daniel Lehmann6ecb7322011-08-01 21:39:29 -0700226 mCallTypeHelper = new CallTypeHelper(getResources());
Flavio Lerda0646f272011-10-17 13:58:53 +0100227 mPhoneNumberHelper = new PhoneNumberHelper(mResources);
Flavio Lerda40569562011-07-22 21:51:29 +0100228 mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper,
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100229 mPhoneNumberHelper);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100230 mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
231 mAsyncQueryHandler = new CallDetailActivityQueryHandler(this);
Flavio Lerdab88abaa2011-08-02 23:38:36 +0100232 mHeaderTextView = (TextView) findViewById(R.id.header_text);
Flavio Lerda126a4202011-10-03 11:15:03 +0100233 mHeaderOverlayView = findViewById(R.id.photo_text_bar);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100234 mStatusMessageView = findViewById(R.id.voicemail_status);
235 mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message);
236 mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action);
Flavio Lerdafb63c432011-07-07 17:16:53 +0100237 mMainActionView = (ImageView) findViewById(R.id.main_action);
Daniel Lehmannd260de42011-08-01 18:08:38 -0700238 mMainActionPushLayerView = (ImageButton) findViewById(R.id.main_action_push_layer);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100239 mContactBackgroundView = (ImageView) findViewById(R.id.contact_background);
Bai Tao09eb04f2010-09-01 15:34:16 +0800240 mDefaultCountryIso = ContactsUtils.getCurrentCountryIso(this);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100241 mContactPhotoManager = ContactPhotoManager.getInstance(this);
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100242 mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener);
Flavio Lerda731f8612011-10-07 15:56:20 +0100243 mContactInfoHelper = new ContactInfoHelper(this, ContactsUtils.getCurrentCountryIso(this));
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100244 configureActionBar();
Hugo Hudson51ada362011-08-05 14:36:14 +0100245 optionallyHandleVoicemail();
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800246 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700247
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800248 @Override
249 public void onResume() {
250 super.onResume();
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100251 updateData(getCallLogEntryUris());
Hugo Hudsonb002f512011-07-15 17:41:12 +0100252 }
253
254 /**
255 * Handle voicemail playback or hide voicemail ui.
256 * <p>
257 * If the Intent used to start this Activity contains the suitable extras, then start voicemail
258 * playback. If it doesn't, then hide the voicemail ui.
259 */
Hugo Hudson757aa552011-07-20 01:15:25 +0100260 private void optionallyHandleVoicemail() {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100261 View voicemailContainer = findViewById(R.id.voicemail_container);
Hugo Hudson157dde12011-07-21 23:28:13 +0100262 if (hasVoicemail()) {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100263 // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri
264 // to play and optionally start the playback.
Hugo Hudson757aa552011-07-20 01:15:25 +0100265 // Do a query to fetch the voicemail status messages.
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100266 VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment();
267 Bundle fragmentArguments = new Bundle();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100268 fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri());
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100269 if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) {
270 fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true);
271 }
272 playbackFragment.setArguments(fragmentArguments);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100273 voicemailContainer.setVisibility(View.VISIBLE);
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100274 getFragmentManager().beginTransaction()
Minh Pham4b25da72011-08-25 13:50:38 -0700275 .add(R.id.voicemail_container, playbackFragment).commitAllowingStateLoss();
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100276 mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri());
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100277 markVoicemailAsRead(getVoicemailUri());
Hugo Hudson757aa552011-07-20 01:15:25 +0100278 } else {
Hugo Hudsona9ad6942011-07-29 17:06:04 +0100279 // No voicemail uri: hide the status view.
Hugo Hudson757aa552011-07-20 01:15:25 +0100280 mStatusMessageView.setVisibility(View.GONE);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100281 voicemailContainer.setVisibility(View.GONE);
Hugo Hudsonb002f512011-07-15 17:41:12 +0100282 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100283 }
284
Hugo Hudson157dde12011-07-21 23:28:13 +0100285 private boolean hasVoicemail() {
Hugo Hudson7b02fde2011-08-02 20:56:48 +0100286 return getVoicemailUri() != null;
287 }
288
289 private Uri getVoicemailUri() {
290 return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
Hugo Hudson157dde12011-07-21 23:28:13 +0100291 }
292
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100293 private void markVoicemailAsRead(final Uri voicemailUri) {
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100294 mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100295 @Override
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100296 public Void doInBackground(Void... params) {
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100297 ContentValues values = new ContentValues();
298 values.put(Voicemails.IS_READ, true);
Flavio Lerda7b9db072011-09-05 13:43:06 +0100299 getContentResolver().update(voicemailUri, values,
300 Voicemails.IS_READ + " = 0", null);
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100301 return null;
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100302 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100303 });
Debashish Chatterjee0a139002011-08-02 18:27:11 +0100304 }
305
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100306 /**
307 * Returns the list of URIs to show.
308 * <p>
309 * There are two ways the URIs can be provided to the activity: as the data on the intent, or as
310 * a list of ids in the call log added as an extra on the URI.
311 * <p>
312 * If both are available, the data on the intent takes precedence.
313 */
314 private Uri[] getCallLogEntryUris() {
315 Uri uri = getIntent().getData();
316 if (uri != null) {
317 // If there is a data on the intent, it takes precedence over the extra.
318 return new Uri[]{ uri };
319 }
320 long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS);
321 Uri[] uris = new Uri[ids.length];
322 for (int index = 0; index < ids.length; ++index) {
323 uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]);
324 }
325 return uris;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800326 }
327
328 @Override
329 public boolean onKeyDown(int keyCode, KeyEvent event) {
330 switch (keyCode) {
331 case KeyEvent.KEYCODE_CALL: {
332 // Make sure phone isn't already busy before starting direct call
333 TelephonyManager tm = (TelephonyManager)
334 getSystemService(Context.TELEPHONY_SERVICE);
335 if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
Daisuke Miyakawafadd5e12011-12-01 17:34:18 -0800336 startActivity(ContactsUtils.getCallIntent(
Daisuke Miyakawa499ea322012-01-24 12:45:51 -0800337 Uri.fromParts(Constants.SCHEME_TEL, mNumber, null)));
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800338 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.
Flavio Lerda12592e82011-08-10 15:36:32 +0100392 final boolean canPlaceCallsTo = mPhoneNumberHelper.canPlaceCallsTo(mNumber);
393 final boolean isVoicemailNumber = mPhoneNumberHelper.isVoicemailNumber(mNumber);
394 final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber);
395
396 // Let user view contact details if they exist, otherwise add option to create new
397 // contact from this number.
398 final Intent mainActionIntent;
399 final int mainActionIcon;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100400 final String mainActionDescription;
401
402 final CharSequence nameOrNumber;
403 if (!TextUtils.isEmpty(firstDetails.name)) {
404 nameOrNumber = firstDetails.name;
405 } else {
406 nameOrNumber = firstDetails.number;
407 }
Flavio Lerda12592e82011-08-10 15:36:32 +0100408
Flavio Lerda071aa0d2011-08-22 10:26:27 +0100409 if (contactUri != null) {
410 mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri);
Flavio Lerda12592e82011-08-10 15:36:32 +0100411 mainActionIcon = R.drawable.ic_contacts_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100412 mainActionDescription =
413 getString(R.string.description_view_contact, nameOrNumber);
Flavio Lerda12592e82011-08-10 15:36:32 +0100414 } else if (isVoicemailNumber) {
415 mainActionIntent = null;
416 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100417 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100418 } else if (isSipNumber) {
419 // TODO: This item is currently disabled for SIP addresses, because
420 // the Insert.PHONE extra only works correctly for PSTN numbers.
421 //
422 // To fix this for SIP addresses, we need to:
423 // - define ContactsContract.Intents.Insert.SIP_ADDRESS, and use it here if
424 // the current number is a SIP address
425 // - update the contacts UI code to handle Insert.SIP_ADDRESS by
426 // updating the SipAddress field
427 // and then we can remove the "!isSipNumber" check above.
428 mainActionIntent = null;
429 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100430 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100431 } else if (canPlaceCallsTo) {
432 mainActionIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
433 mainActionIntent.setType(Contacts.CONTENT_ITEM_TYPE);
434 mainActionIntent.putExtra(Insert.PHONE, mNumber);
435 mainActionIcon = R.drawable.ic_add_contact_holo_dark;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100436 mainActionDescription = getString(R.string.description_add_contact);
Flavio Lerda12592e82011-08-10 15:36:32 +0100437 } else {
438 // If we cannot call the number, when we probably cannot add it as a contact either.
439 // This is usually the case of private, unknown, or payphone numbers.
440 mainActionIntent = null;
441 mainActionIcon = 0;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100442 mainActionDescription = null;
Flavio Lerda12592e82011-08-10 15:36:32 +0100443 }
444
445 if (mainActionIntent == null) {
446 mMainActionView.setVisibility(View.INVISIBLE);
447 mMainActionPushLayerView.setVisibility(View.GONE);
Flavio Lerda126a4202011-10-03 11:15:03 +0100448 mHeaderTextView.setVisibility(View.INVISIBLE);
449 mHeaderOverlayView.setVisibility(View.INVISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100450 } else {
451 mMainActionView.setVisibility(View.VISIBLE);
452 mMainActionView.setImageResource(mainActionIcon);
453 mMainActionPushLayerView.setVisibility(View.VISIBLE);
454 mMainActionPushLayerView.setOnClickListener(new View.OnClickListener() {
455 @Override
456 public void onClick(View v) {
457 startActivity(mainActionIntent);
458 }
459 });
Flavio Lerdab184ed62011-08-10 18:17:55 +0100460 mMainActionPushLayerView.setContentDescription(mainActionDescription);
Flavio Lerda126a4202011-10-03 11:15:03 +0100461 mHeaderTextView.setVisibility(View.VISIBLE);
462 mHeaderOverlayView.setVisibility(View.VISIBLE);
Flavio Lerda12592e82011-08-10 15:36:32 +0100463 }
464
Flavio Lerda12592e82011-08-10 15:36:32 +0100465 // This action allows to call the number that places the call.
466 if (canPlaceCallsTo) {
467 final CharSequence displayNumber =
468 mPhoneNumberHelper.getDisplayNumber(
469 firstDetails.number, firstDetails.formattedNumber);
470
471 ViewEntry entry = new ViewEntry(
Flavio Lerda4e1d7852011-11-23 15:49:18 +0000472 getString(R.string.menu_callNumber,
473 FormatUtils.forceLeftToRight(displayNumber)),
Daisuke Miyakawafadd5e12011-12-01 17:34:18 -0800474 ContactsUtils.getCallIntent(mNumber),
475 getString(R.string.description_call, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100476
477 // Only show a label if the number is shown and it is not a SIP address.
Flavio Lerda35be86e2011-08-12 14:13:22 +0100478 if (!TextUtils.isEmpty(firstDetails.name)
479 && !TextUtils.isEmpty(firstDetails.number)
Flavio Lerda12592e82011-08-10 15:36:32 +0100480 && !PhoneNumberUtils.isUriNumber(firstDetails.number.toString())) {
481 entry.label = Phone.getTypeLabel(mResources, firstDetails.numberType,
482 firstDetails.numberLabel);
483 }
484
485 // The secondary action allows to send an SMS to the number that placed the
486 // call.
487 if (mPhoneNumberHelper.canSendSmsTo(mNumber)) {
Flavio Lerdab184ed62011-08-10 18:17:55 +0100488 entry.setSecondaryAction(
489 R.drawable.ic_text_holo_dark,
Flavio Lerda12592e82011-08-10 15:36:32 +0100490 new Intent(Intent.ACTION_SENDTO,
Flavio Lerdab184ed62011-08-10 18:17:55 +0100491 Uri.fromParts("sms", mNumber, null)),
492 getString(R.string.description_send_text_message, nameOrNumber));
Flavio Lerda12592e82011-08-10 15:36:32 +0100493 }
494
Flavio Lerdab184ed62011-08-10 18:17:55 +0100495 configureCallButton(entry);
496 } else {
497 disableCallButton();
Flavio Lerda12592e82011-08-10 15:36:32 +0100498 }
499
Flavio Lerda78d081d2011-10-17 14:44:02 +0100500 mHasEditNumberBeforeCallOption =
501 canPlaceCallsTo && !isSipNumber && !isVoicemailNumber;
502 mHasTrashOption = hasVoicemail();
503 mHasRemoveFromCallLogOption = !hasVoicemail();
Flavio Lerda599853d2011-09-05 17:50:14 +0100504 invalidateOptionsMenu();
Flavio Lerda12592e82011-08-10 15:36:32 +0100505
Flavio Lerda12592e82011-08-10 15:36:32 +0100506 ListView historyList = (ListView) findViewById(R.id.history);
507 historyList.setAdapter(
508 new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
Flavio Lerdab5a3f5c2011-09-21 19:27:33 +0100509 mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo,
510 findViewById(R.id.controls)));
Flavio Lerdad1333a22011-08-11 16:19:47 +0100511 BackScrollManager.bind(
512 new ScrollableHeader() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100513 private View mControls = findViewById(R.id.controls);
514 private View mPhoto = findViewById(R.id.contact_background_sizer);
515 private View mHeader = findViewById(R.id.photo_text_bar);
516 private View mSeparator = findViewById(R.id.blue_separator);
Flavio Lerdad1333a22011-08-11 16:19:47 +0100517
518 @Override
519 public void setOffset(int offset) {
Flavio Lerda126a4202011-10-03 11:15:03 +0100520 mControls.setY(-offset);
Flavio Lerdad1333a22011-08-11 16:19:47 +0100521 }
522
523 @Override
524 public int getMaximumScrollableHeaderOffset() {
Flavio Lerda126a4202011-10-03 11:15:03 +0100525 // We can scroll the photo out, but we should keep the header if
526 // present.
527 if (mHeader.getVisibility() == View.VISIBLE) {
528 return mPhoto.getHeight() - mHeader.getHeight();
529 } else {
530 // If the header is not present, we should also scroll out the
531 // separator line.
532 return mPhoto.getHeight() + mSeparator.getHeight();
533 }
Flavio Lerdad1333a22011-08-11 16:19:47 +0100534 }
535 },
536 historyList);
Flavio Lerda12592e82011-08-10 15:36:32 +0100537 loadContactPhotos(photoUri);
Flavio Lerda4e63bab2011-08-10 18:26:46 +0100538 findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100539 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100540 }
541 mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask());
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100542 }
543
544 /** Return the phone call details for a given call log URI. */
545 private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800546 ContentResolver resolver = getContentResolver();
547 Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
548 try {
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100549 if (callCursor == null || !callCursor.moveToFirst()) {
550 throw new IllegalArgumentException("Cannot find content: " + callUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800551 }
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100552
553 // Read call log specifics.
554 String number = callCursor.getString(NUMBER_COLUMN_INDEX);
555 long date = callCursor.getLong(DATE_COLUMN_INDEX);
556 long duration = callCursor.getLong(DURATION_COLUMN_INDEX);
557 int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX);
558 String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX);
Flavio Lerda71fc6ec2011-08-09 17:24:29 +0100559 final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
560
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100561 if (TextUtils.isEmpty(countryIso)) {
562 countryIso = mDefaultCountryIso;
563 }
564
565 // Formatted phone number.
Flavio Lerda731f8612011-10-07 15:56:20 +0100566 final CharSequence formattedNumber;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100567 // Read contact specifics.
Flavio Lerda731f8612011-10-07 15:56:20 +0100568 final CharSequence nameText;
569 final int numberType;
570 final CharSequence numberLabel;
571 final Uri photoUri;
572 final Uri lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100573 // 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 +0100574 ContactInfo info =
575 mPhoneNumberHelper.canPlaceCallsTo(number)
Flavio Lerda12ea6522011-10-17 14:08:39 +0100576 && !mPhoneNumberHelper.isVoicemailNumber(number)
Flavio Lerda731f8612011-10-07 15:56:20 +0100577 ? mContactInfoHelper.lookupNumber(number, countryIso)
578 : null;
579 if (info == null) {
580 formattedNumber = mPhoneNumberHelper.getDisplayNumber(number, null);
581 nameText = "";
582 numberType = 0;
583 numberLabel = "";
584 photoUri = null;
585 lookupUri = null;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100586 } else {
Flavio Lerda731f8612011-10-07 15:56:20 +0100587 formattedNumber = info.formattedNumber;
588 nameText = info.name;
589 numberType = info.type;
590 numberLabel = info.label;
591 photoUri = info.photoUri;
592 lookupUri = info.lookupUri;
Flavio Lerda178eeeb2011-07-11 19:51:40 +0100593 }
Flavio Lerda731f8612011-10-07 15:56:20 +0100594 return new PhoneCallDetails(number, formattedNumber, countryIso, geocode,
Flavio Lerdacb805e82011-07-18 10:31:44 +0100595 new int[]{ callType }, date, duration,
Flavio Lerda731f8612011-10-07 15:56:20 +0100596 nameText, numberType, numberLabel, lookupUri, photoUri);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800597 } finally {
598 if (callCursor != null) {
599 callCursor.close();
600 }
601 }
602 }
603
Flavio Lerda9cafe472011-06-08 14:06:13 +0100604 /** Load the contact photos and places them in the corresponding views. */
Daniel Lehmann362654a2011-07-17 14:16:47 -0700605 private void loadContactPhotos(Uri photoUri) {
Daniel Lehmannecfc26c2011-09-12 17:44:35 -0700606 mContactPhotoManager.loadPhoto(mContactBackgroundView, photoUri, true, true);
Flavio Lerda9cafe472011-06-08 14:06:13 +0100607 }
608
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800609 static final class ViewEntry {
Flavio Lerdaa8956882011-07-09 21:34:38 +0100610 public final String text;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100611 public final Intent primaryIntent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100612 /** The description for accessibility of the primary action. */
613 public final String primaryDescription;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100614
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100615 public CharSequence label = null;
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100616 /** Icon for the secondary action. */
617 public int secondaryIcon = 0;
618 /** Intent for the secondary action. If not null, an icon must be defined. */
619 public Intent secondaryIntent = null;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100620 /** The description for accessibility of the secondary action. */
621 public String secondaryDescription = null;
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700622
Flavio Lerdab184ed62011-08-10 18:17:55 +0100623 public ViewEntry(String text, Intent intent, String description) {
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800624 this.text = text;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100625 primaryIntent = intent;
626 primaryDescription = description;
Flavio Lerdaa8956882011-07-09 21:34:38 +0100627 }
628
Flavio Lerdab184ed62011-08-10 18:17:55 +0100629 public void setSecondaryAction(int icon, Intent intent, String description) {
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100630 secondaryIcon = icon;
631 secondaryIntent = intent;
Flavio Lerdab184ed62011-08-10 18:17:55 +0100632 secondaryDescription = description;
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800633 }
634 }
635
Flavio Lerdab184ed62011-08-10 18:17:55 +0100636 /** Disables the call button area, e.g., for private numbers. */
637 private void disableCallButton() {
638 findViewById(R.id.call_and_sms).setVisibility(View.GONE);
639 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700640
Flavio Lerdab184ed62011-08-10 18:17:55 +0100641 /** Configures the call button area using the given entry. */
642 private void configureCallButton(ViewEntry entry) {
643 View convertView = findViewById(R.id.call_and_sms);
644 convertView.setVisibility(View.VISIBLE);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100645
Flavio Lerdab184ed62011-08-10 18:17:55 +0100646 ImageView icon = (ImageView) convertView.findViewById(R.id.call_and_sms_icon);
647 View divider = convertView.findViewById(R.id.call_and_sms_divider);
Flavio Lerda35be86e2011-08-12 14:13:22 +0100648 TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text);
Flavio Lerda8ebfa3d2011-08-10 14:35:22 +0100649
Flavio Lerdab184ed62011-08-10 18:17:55 +0100650 View mainAction = convertView.findViewById(R.id.call_and_sms_main_action);
651 mainAction.setOnClickListener(mPrimaryActionListener);
652 mainAction.setTag(entry);
653 mainAction.setContentDescription(entry.primaryDescription);
654
655 if (entry.secondaryIntent != null) {
656 icon.setOnClickListener(mSecondaryActionListener);
657 icon.setImageResource(entry.secondaryIcon);
658 icon.setVisibility(View.VISIBLE);
659 icon.setTag(entry);
660 icon.setContentDescription(entry.secondaryDescription);
661 divider.setVisibility(View.VISIBLE);
662 } else {
663 icon.setVisibility(View.GONE);
664 divider.setVisibility(View.GONE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800665 }
Flavio Lerdab184ed62011-08-10 18:17:55 +0100666 text.setText(entry.text);
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700667
Flavio Lerda35be86e2011-08-12 14:13:22 +0100668 TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label);
669 if (TextUtils.isEmpty(entry.label)) {
670 label.setVisibility(View.GONE);
Flavio Lerdab184ed62011-08-10 18:17:55 +0100671 } else {
Flavio Lerda35be86e2011-08-12 14:13:22 +0100672 label.setText(entry.label);
673 label.setVisibility(View.VISIBLE);
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800674 }
675 }
Dmitri Plotnikovd0d776d2009-08-19 17:38:04 -0700676
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100677 protected void updateVoicemailStatusMessage(Cursor statusCursor) {
678 if (statusCursor == null) {
679 mStatusMessageView.setVisibility(View.GONE);
680 return;
681 }
682 final StatusMessage message = getStatusMessage(statusCursor);
683 if (message == null || !message.showInCallDetails()) {
684 mStatusMessageView.setVisibility(View.GONE);
685 return;
686 }
687
688 mStatusMessageView.setVisibility(View.VISIBLE);
689 mStatusMessageText.setText(message.callDetailsMessageId);
690 if (message.actionMessageId != -1) {
691 mStatusMessageAction.setText(message.actionMessageId);
692 }
693 if (message.actionUri != null) {
694 mStatusMessageAction.setClickable(true);
695 mStatusMessageAction.setOnClickListener(new View.OnClickListener() {
696 @Override
697 public void onClick(View v) {
698 startActivity(new Intent(Intent.ACTION_VIEW, message.actionUri));
699 }
700 });
701 } else {
702 mStatusMessageAction.setClickable(false);
703 }
704 }
705
706 private StatusMessage getStatusMessage(Cursor statusCursor) {
707 List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor);
Debashish Chatterjee0cb82242011-07-19 19:29:37 +0100708 if (messages.size() == 0) {
709 return null;
710 }
711 // There can only be a single status message per source package, so num of messages can
712 // at most be 1.
713 if (messages.size() > 1) {
714 Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." +
715 " Will use the first one.", messages.size()));
716 }
717 return messages.get(0);
718 }
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100719
720 @Override
721 public boolean onCreateOptionsMenu(Menu menu) {
722 getMenuInflater().inflate(R.menu.call_details_options, menu);
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100723 return super.onCreateOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100724 }
725
726 @Override
727 public boolean onPrepareOptionsMenu(Menu menu) {
728 // This action deletes all elements in the group from the call log.
729 // We don't have this action for voicemails, because you can just use the trash button.
Flavio Lerda78d081d2011-10-17 14:44:02 +0100730 menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption);
731 menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption);
732 menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption);
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100733 return super.onPrepareOptionsMenu(menu);
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100734 }
735
736 @Override
737 public boolean onMenuItemSelected(int featureId, MenuItem item) {
738 switch (item.getItemId()) {
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100739 case android.R.id.home: {
740 onHomeSelected();
741 return true;
742 }
743
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100744 // All the options menu items are handled by onMenu... methods.
Flavio Lerda94d7bab2011-07-22 16:52:34 +0100745 default:
746 throw new IllegalArgumentException();
747 }
748 }
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100749
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100750 public void onMenuRemoveFromCallLog(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100751 final StringBuilder callIds = new StringBuilder();
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100752 for (Uri callUri : getCallLogEntryUris()) {
753 if (callIds.length() != 0) {
754 callIds.append(",");
755 }
756 callIds.append(ContentUris.parseId(callUri));
757 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100758 mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH,
759 new AsyncTask<Void, Void, Void>() {
760 @Override
761 public Void doInBackground(Void... params) {
762 getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
763 Calls._ID + " IN (" + callIds + ")", null);
764 return null;
765 }
766
767 @Override
768 public void onPostExecute(Void result) {
769 finish();
770 }
771 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100772 }
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100773
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100774 public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
Daisuke Miyakawafadd5e12011-12-01 17:34:18 -0800775 startActivity(new Intent(Intent.ACTION_DIAL, ContactsUtils.getCallUri(mNumber)));
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100776 }
777
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100778 public void onMenuTrashVoicemail(MenuItem menuItem) {
Hugo Hudson5bbe25d2011-08-03 17:16:42 +0100779 final Uri voicemailUri = getVoicemailUri();
Hugo Hudson9c747ac2011-08-17 00:23:01 +0100780 mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH,
781 new AsyncTask<Void, Void, Void>() {
782 @Override
783 public Void doInBackground(Void... params) {
784 getContentResolver().delete(voicemailUri, null, null);
785 return null;
786 }
787 @Override
788 public void onPostExecute(Void result) {
789 finish();
790 }
791 });
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100792 }
793
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100794 private void configureActionBar() {
795 ActionBar actionBar = getActionBar();
796 if (actionBar != null) {
Hugo Hudsonc2f09c32011-07-30 16:31:28 +0100797 actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
Flavio Lerdad44e83a2011-07-24 23:10:17 +0100798 }
799 }
800
801 /** Invoked when the user presses the home button in the action bar. */
802 private void onHomeSelected() {
803 Intent intent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI);
804 // This will open the call log even if the detail view has been opened directly.
805 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
806 startActivity(intent);
807 finish();
808 }
Flavio Lerdafd1b98b2011-08-24 19:55:15 +0100809
810 @Override
811 protected void onPause() {
812 // Immediately stop the proximity sensor.
813 disableProximitySensor(false);
814 mProximitySensorListener.clearPendingRequests();
815 super.onPause();
816 }
817
818 @Override
819 public void enableProximitySensor() {
820 mProximitySensorManager.enable();
821 }
822
823 @Override
824 public void disableProximitySensor(boolean waitForFarState) {
825 mProximitySensorManager.disable(waitForFarState);
826 }
The Android Open Source Project7aa0e4c2009-03-03 19:32:21 -0800827}