Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.dialer; |
| 18 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.ContentUris; |
| 22 | import android.content.ContentValues; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.res.Resources; |
| 26 | import android.database.Cursor; |
Nancy Chen | 87ba489 | 2014-06-11 17:56:07 -0700 | [diff] [blame] | 27 | import android.graphics.drawable.Drawable; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 28 | import android.net.Uri; |
| 29 | import android.os.AsyncTask; |
| 30 | import android.os.Bundle; |
| 31 | import android.provider.CallLog; |
| 32 | import android.provider.CallLog.Calls; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 33 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 34 | import android.provider.VoicemailContract.Voicemails; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 35 | import android.telephony.TelephonyManager; |
| 36 | import android.text.TextUtils; |
| 37 | import android.util.Log; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 38 | import android.view.KeyEvent; |
| 39 | import android.view.LayoutInflater; |
| 40 | import android.view.Menu; |
| 41 | import android.view.MenuItem; |
| 42 | import android.view.View; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 43 | import android.widget.ListView; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 44 | import android.widget.QuickContactBadge; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 45 | import android.widget.TextView; |
| 46 | import android.widget.Toast; |
| 47 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 48 | import com.android.contacts.common.ContactPhotoManager; |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 49 | import com.android.contacts.common.CallUtil; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 50 | import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 51 | import com.android.contacts.common.GeoUtil; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 52 | import com.android.dialer.calllog.CallDetailHistoryAdapter; |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 53 | import com.android.dialer.calllog.CallLogQuery; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 54 | import com.android.dialer.calllog.CallTypeHelper; |
| 55 | import com.android.dialer.calllog.ContactInfo; |
| 56 | import com.android.dialer.calllog.ContactInfoHelper; |
Yorke Lee | 24ec319 | 2013-11-19 13:52:45 -0800 | [diff] [blame] | 57 | import com.android.dialer.calllog.PhoneNumberDisplayHelper; |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 58 | import com.android.dialer.calllog.PhoneNumberUtilsWrapper; |
Chiao Cheng | 9119704 | 2012-08-24 14:19:37 -0700 | [diff] [blame] | 59 | import com.android.dialer.util.AsyncTaskExecutor; |
| 60 | import com.android.dialer.util.AsyncTaskExecutors; |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 61 | import com.android.dialer.util.DialerUtils; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 62 | import com.android.dialer.voicemail.VoicemailPlaybackFragment; |
| 63 | import com.android.dialer.voicemail.VoicemailStatusHelper; |
| 64 | import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage; |
| 65 | import com.android.dialer.voicemail.VoicemailStatusHelperImpl; |
| 66 | |
| 67 | import java.util.List; |
| 68 | |
| 69 | /** |
| 70 | * Displays the details of a specific call log entry. |
| 71 | * <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. |
| 74 | */ |
| 75 | public class CallDetailActivity extends Activity implements ProximitySensorAware { |
| 76 | private static final String TAG = "CallDetail"; |
| 77 | |
Yorke Lee | 0345944 | 2013-10-30 18:29:32 -0700 | [diff] [blame] | 78 | private static final int LOADER_ID = 0; |
| 79 | private static final String BUNDLE_CONTACT_URI_EXTRA = "contact_uri_extra"; |
| 80 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 81 | private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A'; |
| 82 | private static final char POP_DIRECTIONAL_FORMATTING = '\u202C'; |
| 83 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 84 | /** The time to wait before enabling the blank the screen due to the proximity sensor. */ |
| 85 | private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100; |
| 86 | /** The time to wait before disabling the blank the screen due to the proximity sensor. */ |
| 87 | private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500; |
| 88 | |
| 89 | /** The enumeration of {@link AsyncTask} objects used in this class. */ |
| 90 | public enum Tasks { |
| 91 | MARK_VOICEMAIL_READ, |
| 92 | DELETE_VOICEMAIL_AND_FINISH, |
| 93 | REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 94 | UPDATE_PHONE_CALL_DETAILS, |
| 95 | } |
| 96 | |
| 97 | /** A long array extra containing ids of call log entries to display. */ |
| 98 | public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; |
| 99 | /** If we are started with a voicemail, we'll find the uri to play with this extra. */ |
| 100 | public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; |
| 101 | /** If we should immediately start playback of the voicemail, this extra will be set to true. */ |
| 102 | public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; |
| 103 | /** If the activity was triggered from a notification. */ |
| 104 | public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; |
| 105 | |
| 106 | private CallTypeHelper mCallTypeHelper; |
Yorke Lee | 24ec319 | 2013-11-19 13:52:45 -0800 | [diff] [blame] | 107 | private PhoneNumberDisplayHelper mPhoneNumberHelper; |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 108 | private QuickContactBadge mQuickContactBadge; |
| 109 | private TextView mCallerName; |
| 110 | private TextView mCallerNumber; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 111 | private AsyncTaskExecutor mAsyncTaskExecutor; |
| 112 | private ContactInfoHelper mContactInfoHelper; |
| 113 | |
| 114 | private String mNumber = null; |
| 115 | private String mDefaultCountryIso; |
| 116 | |
| 117 | /* package */ LayoutInflater mInflater; |
| 118 | /* package */ Resources mResources; |
| 119 | /** Helper to load contact photos. */ |
| 120 | private ContactPhotoManager mContactPhotoManager; |
| 121 | /** Helper to make async queries to content resolver. */ |
| 122 | private CallDetailActivityQueryHandler mAsyncQueryHandler; |
| 123 | /** Helper to get voicemail status messages. */ |
| 124 | private VoicemailStatusHelper mVoicemailStatusHelper; |
| 125 | // Views related to voicemail status message. |
| 126 | private View mStatusMessageView; |
| 127 | private TextView mStatusMessageText; |
| 128 | private TextView mStatusMessageAction; |
| 129 | |
| 130 | /** Whether we should show "edit number before call" in the options menu. */ |
| 131 | private boolean mHasEditNumberBeforeCallOption; |
| 132 | /** Whether we should show "trash" in the options menu. */ |
| 133 | private boolean mHasTrashOption; |
| 134 | /** Whether we should show "remove from call log" in the options menu. */ |
| 135 | private boolean mHasRemoveFromCallLogOption; |
| 136 | |
| 137 | private ProximitySensorManager mProximitySensorManager; |
| 138 | private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener(); |
| 139 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 140 | /** Listener to changes in the proximity sensor state. */ |
| 141 | private class ProximitySensorListener implements ProximitySensorManager.Listener { |
| 142 | /** Used to show a blank view and hide the action bar. */ |
| 143 | private final Runnable mBlankRunnable = new Runnable() { |
| 144 | @Override |
| 145 | public void run() { |
| 146 | View blankView = findViewById(R.id.blank); |
| 147 | blankView.setVisibility(View.VISIBLE); |
| 148 | getActionBar().hide(); |
| 149 | } |
| 150 | }; |
| 151 | /** Used to remove the blank view and show the action bar. */ |
| 152 | private final Runnable mUnblankRunnable = new Runnable() { |
| 153 | @Override |
| 154 | public void run() { |
| 155 | View blankView = findViewById(R.id.blank); |
| 156 | blankView.setVisibility(View.GONE); |
| 157 | getActionBar().show(); |
| 158 | } |
| 159 | }; |
| 160 | |
| 161 | @Override |
| 162 | public synchronized void onNear() { |
| 163 | clearPendingRequests(); |
| 164 | postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public synchronized void onFar() { |
| 169 | clearPendingRequests(); |
| 170 | postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS); |
| 171 | } |
| 172 | |
| 173 | /** Removed any delayed requests that may be pending. */ |
| 174 | public synchronized void clearPendingRequests() { |
| 175 | View blankView = findViewById(R.id.blank); |
| 176 | blankView.removeCallbacks(mBlankRunnable); |
| 177 | blankView.removeCallbacks(mUnblankRunnable); |
| 178 | } |
| 179 | |
| 180 | /** Post a {@link Runnable} with a delay on the main thread. */ |
| 181 | private synchronized void postDelayed(Runnable runnable, long delayMillis) { |
| 182 | // Post these instead of executing immediately so that: |
| 183 | // - They are guaranteed to be executed on the main thread. |
| 184 | // - If the sensor values changes rapidly for some time, the UI will not be |
| 185 | // updated immediately. |
| 186 | View blankView = findViewById(R.id.blank); |
| 187 | blankView.postDelayed(runnable, delayMillis); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | static final String[] CALL_LOG_PROJECTION = new String[] { |
| 192 | CallLog.Calls.DATE, |
| 193 | CallLog.Calls.DURATION, |
| 194 | CallLog.Calls.NUMBER, |
| 195 | CallLog.Calls.TYPE, |
| 196 | CallLog.Calls.COUNTRY_ISO, |
| 197 | CallLog.Calls.GEOCODED_LOCATION, |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 198 | CallLog.Calls.NUMBER_PRESENTATION, |
Ihab Awad | c8daf20 | 2014-07-02 14:03:28 -0700 | [diff] [blame] | 199 | CallLog.Calls.PHONE_ACCOUNT_COMPONENT_NAME, |
| 200 | CallLog.Calls.PHONE_ACCOUNT_ID, |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 201 | CallLog.Calls.FEATURES, |
| 202 | CallLog.Calls.DATA_USAGE |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | static final int DATE_COLUMN_INDEX = 0; |
| 206 | static final int DURATION_COLUMN_INDEX = 1; |
| 207 | static final int NUMBER_COLUMN_INDEX = 2; |
| 208 | static final int CALL_TYPE_COLUMN_INDEX = 3; |
| 209 | static final int COUNTRY_ISO_COLUMN_INDEX = 4; |
| 210 | static final int GEOCODED_LOCATION_COLUMN_INDEX = 5; |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 211 | static final int NUMBER_PRESENTATION_COLUMN_INDEX = 6; |
Ihab Awad | 1d1bd0d | 2014-06-30 21:24:01 -0700 | [diff] [blame] | 212 | static final int ACCOUNT_COMPONENT_NAME = 7; |
| 213 | static final int ACCOUNT_ID = 8; |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 214 | static final int FEATURES = 9; |
| 215 | static final int DATA_USAGE = 10; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 216 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 217 | @Override |
| 218 | protected void onCreate(Bundle icicle) { |
| 219 | super.onCreate(icicle); |
| 220 | |
| 221 | setContentView(R.layout.call_detail); |
| 222 | |
| 223 | mAsyncTaskExecutor = AsyncTaskExecutors.createThreadPoolExecutor(); |
| 224 | mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); |
| 225 | mResources = getResources(); |
| 226 | |
| 227 | mCallTypeHelper = new CallTypeHelper(getResources()); |
Yorke Lee | 24ec319 | 2013-11-19 13:52:45 -0800 | [diff] [blame] | 228 | mPhoneNumberHelper = new PhoneNumberDisplayHelper(mResources); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 229 | mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); |
| 230 | mAsyncQueryHandler = new CallDetailActivityQueryHandler(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 231 | mStatusMessageView = findViewById(R.id.voicemail_status); |
| 232 | mStatusMessageText = (TextView) findViewById(R.id.voicemail_status_message); |
| 233 | mStatusMessageAction = (TextView) findViewById(R.id.voicemail_status_action); |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 234 | mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo); |
| 235 | mQuickContactBadge.setOverlay(null); |
| 236 | mCallerName = (TextView) findViewById(R.id.caller_name); |
| 237 | mCallerNumber = (TextView) findViewById(R.id.caller_number); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 238 | mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 239 | mContactPhotoManager = ContactPhotoManager.getInstance(this); |
| 240 | mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener); |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 241 | mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); |
Chiao Cheng | adb742c | 2013-10-07 17:46:25 -0700 | [diff] [blame] | 242 | getActionBar().setDisplayHomeAsUpEnabled(true); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 243 | optionallyHandleVoicemail(); |
| 244 | if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) { |
| 245 | closeSystemDialogs(); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | @Override |
| 250 | public void onResume() { |
| 251 | super.onResume(); |
| 252 | updateData(getCallLogEntryUris()); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Handle voicemail playback or hide voicemail ui. |
| 257 | * <p> |
| 258 | * If the Intent used to start this Activity contains the suitable extras, then start voicemail |
| 259 | * playback. If it doesn't, then hide the voicemail ui. |
| 260 | */ |
| 261 | private void optionallyHandleVoicemail() { |
| 262 | View voicemailContainer = findViewById(R.id.voicemail_container); |
| 263 | if (hasVoicemail()) { |
| 264 | // Has voicemail: add the voicemail fragment. Add suitable arguments to set the uri |
| 265 | // to play and optionally start the playback. |
| 266 | // Do a query to fetch the voicemail status messages. |
| 267 | VoicemailPlaybackFragment playbackFragment = new VoicemailPlaybackFragment(); |
| 268 | Bundle fragmentArguments = new Bundle(); |
| 269 | fragmentArguments.putParcelable(EXTRA_VOICEMAIL_URI, getVoicemailUri()); |
| 270 | if (getIntent().getBooleanExtra(EXTRA_VOICEMAIL_START_PLAYBACK, false)) { |
| 271 | fragmentArguments.putBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, true); |
| 272 | } |
| 273 | playbackFragment.setArguments(fragmentArguments); |
| 274 | voicemailContainer.setVisibility(View.VISIBLE); |
| 275 | getFragmentManager().beginTransaction() |
Yorke Lee | aa536fd | 2013-07-29 11:31:04 -0700 | [diff] [blame] | 276 | .add(R.id.voicemail_container, playbackFragment) |
| 277 | .commitAllowingStateLoss(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 278 | mAsyncQueryHandler.startVoicemailStatusQuery(getVoicemailUri()); |
| 279 | markVoicemailAsRead(getVoicemailUri()); |
| 280 | } else { |
| 281 | // No voicemail uri: hide the status view. |
| 282 | mStatusMessageView.setVisibility(View.GONE); |
| 283 | voicemailContainer.setVisibility(View.GONE); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | private boolean hasVoicemail() { |
| 288 | return getVoicemailUri() != null; |
| 289 | } |
| 290 | |
| 291 | private Uri getVoicemailUri() { |
| 292 | return getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI); |
| 293 | } |
| 294 | |
| 295 | private void markVoicemailAsRead(final Uri voicemailUri) { |
| 296 | mAsyncTaskExecutor.submit(Tasks.MARK_VOICEMAIL_READ, new AsyncTask<Void, Void, Void>() { |
| 297 | @Override |
| 298 | public Void doInBackground(Void... params) { |
| 299 | ContentValues values = new ContentValues(); |
| 300 | values.put(Voicemails.IS_READ, true); |
| 301 | getContentResolver().update(voicemailUri, values, |
| 302 | Voicemails.IS_READ + " = 0", null); |
| 303 | return null; |
| 304 | } |
| 305 | }); |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Returns the list of URIs to show. |
| 310 | * <p> |
| 311 | * There are two ways the URIs can be provided to the activity: as the data on the intent, or as |
| 312 | * a list of ids in the call log added as an extra on the URI. |
| 313 | * <p> |
| 314 | * If both are available, the data on the intent takes precedence. |
| 315 | */ |
| 316 | private Uri[] getCallLogEntryUris() { |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 317 | final Uri uri = getIntent().getData(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 318 | if (uri != null) { |
| 319 | // If there is a data on the intent, it takes precedence over the extra. |
| 320 | return new Uri[]{ uri }; |
| 321 | } |
Jay Shrauner | 757bdd3 | 2014-05-28 10:13:40 -0700 | [diff] [blame] | 322 | final long[] ids = getIntent().getLongArrayExtra(EXTRA_CALL_LOG_IDS); |
| 323 | final int numIds = ids == null ? 0 : ids.length; |
| 324 | final Uri[] uris = new Uri[numIds]; |
| 325 | for (int index = 0; index < numIds; ++index) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 326 | uris[index] = ContentUris.withAppendedId(Calls.CONTENT_URI_WITH_VOICEMAIL, ids[index]); |
| 327 | } |
| 328 | return uris; |
| 329 | } |
| 330 | |
| 331 | @Override |
| 332 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 333 | switch (keyCode) { |
| 334 | case KeyEvent.KEYCODE_CALL: { |
| 335 | // Make sure phone isn't already busy before starting direct call |
| 336 | TelephonyManager tm = (TelephonyManager) |
| 337 | getSystemService(Context.TELEPHONY_SERVICE); |
| 338 | if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 339 | DialerUtils.startActivityWithErrorToast(this, |
| 340 | CallUtil.getCallIntent(Uri.fromParts(CallUtil.SCHEME_TEL, mNumber, |
Nancy Chen | 87ba489 | 2014-06-11 17:56:07 -0700 | [diff] [blame] | 341 | null)), R.string.call_not_available); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 342 | return true; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | return super.onKeyDown(keyCode, event); |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Update user interface with details of given call. |
| 352 | * |
| 353 | * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed |
| 354 | */ |
| 355 | private void updateData(final Uri... callUris) { |
| 356 | class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> { |
| 357 | @Override |
| 358 | public PhoneCallDetails[] doInBackground(Void... params) { |
| 359 | // TODO: All phone calls correspond to the same person, so we can make a single |
| 360 | // lookup. |
| 361 | final int numCalls = callUris.length; |
| 362 | PhoneCallDetails[] details = new PhoneCallDetails[numCalls]; |
| 363 | try { |
| 364 | for (int index = 0; index < numCalls; ++index) { |
| 365 | details[index] = getPhoneCallDetailsForUri(callUris[index]); |
| 366 | } |
| 367 | return details; |
| 368 | } catch (IllegalArgumentException e) { |
| 369 | // Something went wrong reading in our primary data. |
| 370 | Log.w(TAG, "invalid URI starting call details", e); |
| 371 | return null; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public void onPostExecute(PhoneCallDetails[] details) { |
| 377 | if (details == null) { |
| 378 | // Somewhere went wrong: we're going to bail out and show error to users. |
| 379 | Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error, |
| 380 | Toast.LENGTH_SHORT).show(); |
| 381 | finish(); |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | // We know that all calls are from the same number and the same contact, so pick the |
| 386 | // first. |
| 387 | PhoneCallDetails firstDetails = details[0]; |
| 388 | mNumber = firstDetails.number.toString(); |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 389 | final int numberPresentation = firstDetails.numberPresentation; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 390 | final Uri contactUri = firstDetails.contactUri; |
| 391 | final Uri photoUri = firstDetails.photoUri; |
| 392 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 393 | // Cache the details about the phone number. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 394 | final boolean canPlaceCallsTo = |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 395 | PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); |
| 396 | final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(); |
| 397 | final boolean isVoicemailNumber = phoneUtils.isVoicemailNumber(mNumber); |
| 398 | final boolean isSipNumber = phoneUtils.isSipNumber(mNumber); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 399 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 400 | final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 401 | |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 402 | final CharSequence displayNumber = |
| 403 | mPhoneNumberHelper.getDisplayNumber( |
| 404 | firstDetails.number, |
| 405 | firstDetails.numberPresentation, |
| 406 | firstDetails.formattedNumber); |
| 407 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 408 | if (!TextUtils.isEmpty(firstDetails.name)) { |
| 409 | mCallerName.setText(firstDetails.name); |
| 410 | mCallerNumber.setText(callLocationOrType + " " + displayNumber); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 411 | } else { |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 412 | mCallerName.setText(displayNumber); |
| 413 | if (!TextUtils.isEmpty(callLocationOrType)) { |
| 414 | mCallerNumber.setText(callLocationOrType); |
| 415 | mCallerNumber.setVisibility(View.VISIBLE); |
| 416 | } else { |
| 417 | mCallerNumber.setVisibility(View.GONE); |
| 418 | } |
| 419 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | mHasEditNumberBeforeCallOption = |
| 423 | canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; |
| 424 | mHasTrashOption = hasVoicemail(); |
| 425 | mHasRemoveFromCallLogOption = !hasVoicemail(); |
| 426 | invalidateOptionsMenu(); |
| 427 | |
| 428 | ListView historyList = (ListView) findViewById(R.id.history); |
| 429 | historyList.setAdapter( |
| 430 | new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater, |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 431 | mCallTypeHelper, details)); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 432 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 433 | String lookupKey = contactUri == null ? null |
| 434 | : ContactInfoHelper.getLookupKeyFromUri(contactUri); |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 435 | |
| 436 | final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); |
| 437 | |
| 438 | final int contactType = |
| 439 | isVoicemailNumber? ContactPhotoManager.TYPE_VOICEMAIL : |
| 440 | isBusiness ? ContactPhotoManager.TYPE_BUSINESS : |
| 441 | ContactPhotoManager.TYPE_DEFAULT; |
| 442 | |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 443 | String nameForDefaultImage; |
| 444 | if (TextUtils.isEmpty(firstDetails.name)) { |
| 445 | nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(firstDetails.number, |
| 446 | firstDetails.numberPresentation, |
| 447 | firstDetails.formattedNumber).toString(); |
| 448 | } else { |
| 449 | nameForDefaultImage = firstDetails.name.toString(); |
| 450 | } |
| 451 | |
| 452 | loadContactPhotos( |
| 453 | contactUri, photoUri, nameForDefaultImage, lookupKey, contactType); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 454 | findViewById(R.id.call_detail).setVisibility(View.VISIBLE); |
| 455 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 456 | |
| 457 | /** |
| 458 | * Determines the location geocode text for a call, or the phone number type |
| 459 | * (if available). |
| 460 | * |
| 461 | * @param details The call details. |
| 462 | * @return The phone number type or location. |
| 463 | */ |
| 464 | private CharSequence getNumberTypeOrLocation(PhoneCallDetails details) { |
| 465 | if (!TextUtils.isEmpty(details.name)) { |
| 466 | return Phone.getTypeLabel(mResources, details.numberType, |
| 467 | details.numberLabel); |
| 468 | } else { |
| 469 | return details.geocode; |
| 470 | } |
| 471 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 472 | } |
| 473 | mAsyncTaskExecutor.submit(Tasks.UPDATE_PHONE_CALL_DETAILS, new UpdateContactDetailsTask()); |
| 474 | } |
| 475 | |
| 476 | /** Return the phone call details for a given call log URI. */ |
| 477 | private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) { |
| 478 | ContentResolver resolver = getContentResolver(); |
| 479 | Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null); |
| 480 | try { |
| 481 | if (callCursor == null || !callCursor.moveToFirst()) { |
| 482 | throw new IllegalArgumentException("Cannot find content: " + callUri); |
| 483 | } |
| 484 | |
| 485 | // Read call log specifics. |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 486 | final String number = callCursor.getString(NUMBER_COLUMN_INDEX); |
| 487 | final int numberPresentation = callCursor.getInt( |
| 488 | NUMBER_PRESENTATION_COLUMN_INDEX); |
| 489 | final long date = callCursor.getLong(DATE_COLUMN_INDEX); |
| 490 | final long duration = callCursor.getLong(DURATION_COLUMN_INDEX); |
| 491 | final int callType = callCursor.getInt(CALL_TYPE_COLUMN_INDEX); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 492 | String countryIso = callCursor.getString(COUNTRY_ISO_COLUMN_INDEX); |
| 493 | final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX); |
Ihab Awad | 1d1bd0d | 2014-06-30 21:24:01 -0700 | [diff] [blame] | 494 | final Drawable accountIcon = getAccountIcon(callCursor); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 495 | |
| 496 | if (TextUtils.isEmpty(countryIso)) { |
| 497 | countryIso = mDefaultCountryIso; |
| 498 | } |
| 499 | |
| 500 | // Formatted phone number. |
| 501 | final CharSequence formattedNumber; |
| 502 | // Read contact specifics. |
| 503 | final CharSequence nameText; |
| 504 | final int numberType; |
| 505 | final CharSequence numberLabel; |
| 506 | final Uri photoUri; |
| 507 | final Uri lookupUri; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 508 | int sourceType; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 509 | // If this is not a regular number, there is no point in looking it up in the contacts. |
| 510 | ContactInfo info = |
Chiao Cheng | fb0a934 | 2013-09-13 17:27:42 -0700 | [diff] [blame] | 511 | PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) |
Yorke Lee | 1a7c196 | 2013-09-20 16:04:34 -0700 | [diff] [blame] | 512 | && !new PhoneNumberUtilsWrapper().isVoicemailNumber(number) |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 513 | ? mContactInfoHelper.lookupNumber(number, countryIso) |
| 514 | : null; |
| 515 | if (info == null) { |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 516 | formattedNumber = mPhoneNumberHelper.getDisplayNumber(number, |
| 517 | numberPresentation, null); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 518 | nameText = ""; |
| 519 | numberType = 0; |
| 520 | numberLabel = ""; |
| 521 | photoUri = null; |
| 522 | lookupUri = null; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 523 | sourceType = 0; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 524 | } else { |
| 525 | formattedNumber = info.formattedNumber; |
| 526 | nameText = info.name; |
| 527 | numberType = info.type; |
| 528 | numberLabel = info.label; |
| 529 | photoUri = info.photoUri; |
| 530 | lookupUri = info.lookupUri; |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 531 | sourceType = info.sourceType; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 532 | } |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 533 | final int features = callCursor.getInt(FEATURES); |
| 534 | Long dataUsage = null; |
| 535 | if (!callCursor.isNull(DATA_USAGE)) { |
| 536 | dataUsage = callCursor.getLong(DATA_USAGE); |
| 537 | } |
Jay Shrauner | 719a7ad | 2013-05-30 15:41:13 -0700 | [diff] [blame] | 538 | return new PhoneCallDetails(number, numberPresentation, |
| 539 | formattedNumber, countryIso, geocode, |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 540 | new int[]{ callType }, date, duration, |
Nancy Chen | 87ba489 | 2014-06-11 17:56:07 -0700 | [diff] [blame] | 541 | nameText, numberType, numberLabel, lookupUri, photoUri, sourceType, |
Tyler Gunn | 8b0e858 | 2014-07-10 12:28:43 -0700 | [diff] [blame] | 542 | accountIcon, features, dataUsage); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 543 | } finally { |
| 544 | if (callCursor != null) { |
| 545 | callCursor.close(); |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
Nancy Chen | 87ba489 | 2014-06-11 17:56:07 -0700 | [diff] [blame] | 550 | /** |
Ihab Awad | 1d1bd0d | 2014-06-30 21:24:01 -0700 | [diff] [blame] | 551 | * Generate account object from data in Telecomm database |
Nancy Chen | 87ba489 | 2014-06-11 17:56:07 -0700 | [diff] [blame] | 552 | */ |
Ihab Awad | 1d1bd0d | 2014-06-30 21:24:01 -0700 | [diff] [blame] | 553 | private Drawable getAccountIcon(Cursor c) { |
| 554 | final String component_name = c.getString(ACCOUNT_COMPONENT_NAME); |
| 555 | final String account_id = c.getString(ACCOUNT_ID); |
Nancy Chen | 87ba489 | 2014-06-11 17:56:07 -0700 | [diff] [blame] | 556 | |
| 557 | // TODO: actually pull data from the database |
| 558 | return null; |
| 559 | } |
| 560 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 561 | /** Load the contact photos and places them in the corresponding views. */ |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 562 | private void loadContactPhotos(Uri contactUri, Uri photoUri, String displayName, |
| 563 | String lookupKey, int contactType) { |
| 564 | |
Yorke Lee | 56cb0ef | 2014-02-21 10:02:18 -0800 | [diff] [blame] | 565 | final DefaultImageRequest request = new DefaultImageRequest(displayName, lookupKey, |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 566 | contactType, true /* isCircular */); |
| 567 | |
| 568 | mQuickContactBadge.assignContactUri(contactUri); |
| 569 | mQuickContactBadge.setContentDescription( |
| 570 | mResources.getString(R.string.description_contact_details, displayName)); |
| 571 | |
| 572 | mContactPhotoManager.loadDirectoryPhoto(mQuickContactBadge, photoUri, |
| 573 | false /* darkTheme */, true /* isCircular */, request); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | static final class ViewEntry { |
| 577 | public final String text; |
| 578 | public final Intent primaryIntent; |
| 579 | /** The description for accessibility of the primary action. */ |
| 580 | public final String primaryDescription; |
| 581 | |
| 582 | public CharSequence label = null; |
| 583 | /** Icon for the secondary action. */ |
| 584 | public int secondaryIcon = 0; |
| 585 | /** Intent for the secondary action. If not null, an icon must be defined. */ |
| 586 | public Intent secondaryIntent = null; |
| 587 | /** The description for accessibility of the secondary action. */ |
| 588 | public String secondaryDescription = null; |
| 589 | |
| 590 | public ViewEntry(String text, Intent intent, String description) { |
| 591 | this.text = text; |
| 592 | primaryIntent = intent; |
| 593 | primaryDescription = description; |
| 594 | } |
| 595 | |
| 596 | public void setSecondaryAction(int icon, Intent intent, String description) { |
| 597 | secondaryIcon = icon; |
| 598 | secondaryIntent = intent; |
| 599 | secondaryDescription = description; |
| 600 | } |
| 601 | } |
| 602 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 603 | protected void updateVoicemailStatusMessage(Cursor statusCursor) { |
| 604 | if (statusCursor == null) { |
| 605 | mStatusMessageView.setVisibility(View.GONE); |
| 606 | return; |
| 607 | } |
| 608 | final StatusMessage message = getStatusMessage(statusCursor); |
| 609 | if (message == null || !message.showInCallDetails()) { |
| 610 | mStatusMessageView.setVisibility(View.GONE); |
| 611 | return; |
| 612 | } |
| 613 | |
| 614 | mStatusMessageView.setVisibility(View.VISIBLE); |
| 615 | mStatusMessageText.setText(message.callDetailsMessageId); |
| 616 | if (message.actionMessageId != -1) { |
| 617 | mStatusMessageAction.setText(message.actionMessageId); |
| 618 | } |
| 619 | if (message.actionUri != null) { |
| 620 | mStatusMessageAction.setClickable(true); |
| 621 | mStatusMessageAction.setOnClickListener(new View.OnClickListener() { |
| 622 | @Override |
| 623 | public void onClick(View v) { |
Yorke Lee | 3921359 | 2014-04-07 15:39:48 -0700 | [diff] [blame] | 624 | DialerUtils.startActivityWithErrorToast(CallDetailActivity.this, |
| 625 | new Intent(Intent.ACTION_VIEW, message.actionUri)); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 626 | } |
| 627 | }); |
| 628 | } else { |
| 629 | mStatusMessageAction.setClickable(false); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | private StatusMessage getStatusMessage(Cursor statusCursor) { |
| 634 | List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages(statusCursor); |
| 635 | if (messages.size() == 0) { |
| 636 | return null; |
| 637 | } |
| 638 | // There can only be a single status message per source package, so num of messages can |
| 639 | // at most be 1. |
| 640 | if (messages.size() > 1) { |
| 641 | Log.w(TAG, String.format("Expected 1, found (%d) num of status messages." + |
| 642 | " Will use the first one.", messages.size())); |
| 643 | } |
| 644 | return messages.get(0); |
| 645 | } |
| 646 | |
| 647 | @Override |
| 648 | public boolean onCreateOptionsMenu(Menu menu) { |
| 649 | getMenuInflater().inflate(R.menu.call_details_options, menu); |
| 650 | return super.onCreateOptionsMenu(menu); |
| 651 | } |
| 652 | |
| 653 | @Override |
| 654 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 655 | // This action deletes all elements in the group from the call log. |
| 656 | // We don't have this action for voicemails, because you can just use the trash button. |
| 657 | menu.findItem(R.id.menu_remove_from_call_log).setVisible(mHasRemoveFromCallLogOption); |
| 658 | menu.findItem(R.id.menu_edit_number_before_call).setVisible(mHasEditNumberBeforeCallOption); |
| 659 | menu.findItem(R.id.menu_trash).setVisible(mHasTrashOption); |
| 660 | return super.onPrepareOptionsMenu(menu); |
| 661 | } |
| 662 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 663 | public void onMenuRemoveFromCallLog(MenuItem menuItem) { |
| 664 | final StringBuilder callIds = new StringBuilder(); |
| 665 | for (Uri callUri : getCallLogEntryUris()) { |
| 666 | if (callIds.length() != 0) { |
| 667 | callIds.append(","); |
| 668 | } |
| 669 | callIds.append(ContentUris.parseId(callUri)); |
| 670 | } |
| 671 | mAsyncTaskExecutor.submit(Tasks.REMOVE_FROM_CALL_LOG_AND_FINISH, |
| 672 | new AsyncTask<Void, Void, Void>() { |
| 673 | @Override |
| 674 | public Void doInBackground(Void... params) { |
| 675 | getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL, |
| 676 | Calls._ID + " IN (" + callIds + ")", null); |
| 677 | return null; |
| 678 | } |
| 679 | |
| 680 | @Override |
| 681 | public void onPostExecute(Void result) { |
| 682 | finish(); |
| 683 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 684 | } |
| 685 | ); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | public void onMenuEditNumberBeforeCall(MenuItem menuItem) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 689 | startActivity(new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber))); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | public void onMenuTrashVoicemail(MenuItem menuItem) { |
| 693 | final Uri voicemailUri = getVoicemailUri(); |
| 694 | mAsyncTaskExecutor.submit(Tasks.DELETE_VOICEMAIL_AND_FINISH, |
| 695 | new AsyncTask<Void, Void, Void>() { |
| 696 | @Override |
| 697 | public Void doInBackground(Void... params) { |
| 698 | getContentResolver().delete(voicemailUri, null, null); |
| 699 | return null; |
| 700 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 701 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 702 | @Override |
| 703 | public void onPostExecute(Void result) { |
| 704 | finish(); |
| 705 | } |
Tyler Gunn | 18164c8 | 2014-06-09 10:20:57 -0700 | [diff] [blame] | 706 | } |
| 707 | ); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | @Override |
| 711 | protected void onPause() { |
| 712 | // Immediately stop the proximity sensor. |
| 713 | disableProximitySensor(false); |
| 714 | mProximitySensorListener.clearPendingRequests(); |
| 715 | super.onPause(); |
| 716 | } |
| 717 | |
| 718 | @Override |
| 719 | public void enableProximitySensor() { |
| 720 | mProximitySensorManager.enable(); |
| 721 | } |
| 722 | |
| 723 | @Override |
| 724 | public void disableProximitySensor(boolean waitForFarState) { |
| 725 | mProximitySensorManager.disable(waitForFarState); |
| 726 | } |
| 727 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 728 | private void closeSystemDialogs() { |
| 729 | sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 730 | } |
| 731 | |
Chiao Cheng | 35071c0 | 2012-10-15 18:36:24 -0700 | [diff] [blame] | 732 | /** Returns the given text, forced to be left-to-right. */ |
| 733 | private static CharSequence forceLeftToRight(CharSequence text) { |
| 734 | StringBuilder sb = new StringBuilder(); |
| 735 | sb.append(LEFT_TO_RIGHT_EMBEDDING); |
| 736 | sb.append(text); |
| 737 | sb.append(POP_DIRECTIONAL_FORMATTING); |
| 738 | return sb.toString(); |
| 739 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 740 | } |