diff options
Diffstat (limited to 'src')
9 files changed, 109 insertions, 82 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 6da7c798c..15ba5df16 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -77,8 +77,6 @@ public class CallDetailActivity extends Activity { public static final String EXTRA_CALL_LOG_IDS = "EXTRA_CALL_LOG_IDS"; /** If we are started with a voicemail, we'll find the uri to play with this extra. */ public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI"; - /** If we should immediately start playback of the voicemail, this extra will be set to true. */ - public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK"; /** If the activity was triggered from a notification. */ public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; @@ -97,11 +95,9 @@ public class CallDetailActivity extends Activity { @Override public void onGetCallDetails(PhoneCallDetails[] details) { - Context context = CallDetailActivity.this; - if (details == null) { // Somewhere went wrong: we're going to bail out and show error to users. - Toast.makeText(context, R.string.toast_call_detail_error, + Toast.makeText(mContext, R.string.toast_call_detail_error, Toast.LENGTH_SHORT).show(); finish(); return; @@ -119,9 +115,9 @@ public class CallDetailActivity extends Activity { // Cache the details about the phone number. final boolean canPlaceCallsTo = - PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); - final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(context); - final boolean isVoicemailNumber = + PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); + final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(mContext); + mIsVoicemailNumber = phoneUtils.isVoicemailNumber(accountHandle, mNumber); final boolean isSipNumber = PhoneNumberUtilsWrapper.isSipNumber(mNumber); @@ -144,7 +140,9 @@ public class CallDetailActivity extends Activity { } } - String accountLabel = PhoneAccountUtils.getAccountLabel(context, accountHandle); + mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); + + String accountLabel = PhoneAccountUtils.getAccountLabel(mContext, accountHandle); if (!TextUtils.isEmpty(accountLabel)) { mAccountLabel.setText(accountLabel); mAccountLabel.setVisibility(View.VISIBLE); @@ -153,14 +151,14 @@ public class CallDetailActivity extends Activity { } mHasEditNumberBeforeCallOption = - canPlaceCallsTo && !isSipNumber && !isVoicemailNumber; + canPlaceCallsTo && !isSipNumber && !mIsVoicemailNumber; mHasTrashOption = hasVoicemail(); mHasRemoveFromCallLogOption = !hasVoicemail(); invalidateOptionsMenu(); ListView historyList = (ListView) findViewById(R.id.history); historyList.setAdapter( - new CallDetailHistoryAdapter(context, mInflater, mCallTypeHelper, details)); + new CallDetailHistoryAdapter(mContext, mInflater, mCallTypeHelper, details)); String lookupKey = contactUri == null ? null : ContactInfoHelper.getLookupKeyFromUri(contactUri); @@ -168,7 +166,7 @@ public class CallDetailActivity extends Activity { final boolean isBusiness = mContactInfoHelper.isBusiness(firstDetails.sourceType); final int contactType = - isVoicemailNumber ? ContactPhotoManager.TYPE_VOICEMAIL : + mIsVoicemailNumber ? ContactPhotoManager.TYPE_VOICEMAIL : isBusiness ? ContactPhotoManager.TYPE_BUSINESS : ContactPhotoManager.TYPE_DEFAULT; @@ -201,14 +199,17 @@ public class CallDetailActivity extends Activity { } }; + private Context mContext; private CallTypeHelper mCallTypeHelper; private QuickContactBadge mQuickContactBadge; private TextView mCallerName; private TextView mCallerNumber; private TextView mAccountLabel; + private View mCallButton; private ContactInfoHelper mContactInfoHelper; - private String mNumber = null; + private String mNumber; + private boolean mIsVoicemailNumber; private String mDefaultCountryIso; /* package */ LayoutInflater mInflater; @@ -230,6 +231,8 @@ public class CallDetailActivity extends Activity { protected void onCreate(Bundle icicle) { super.onCreate(icicle); + mContext = this; + setContentView(R.layout.call_detail); mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); @@ -248,6 +251,14 @@ public class CallDetailActivity extends Activity { mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); mContactPhotoManager = ContactPhotoManager.getInstance(this); + mCallButton = (View) findViewById(R.id.call_back_button); + mCallButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mContext.startActivity(IntentUtil.getCallIntent(mNumber)); + } + }); + mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); getActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java index 845f91108..d57d87a81 100644 --- a/src/com/android/dialer/calllog/CallLogFragment.java +++ b/src/com/android/dialer/calllog/CallLogFragment.java @@ -191,6 +191,7 @@ public class CallLogFragment extends Fragment setHasOptionsMenu(true); mVoicemailPlaybackPresenter = new VoicemailPlaybackPresenter(activity, state); + activity.setVolumeControlStream(VoicemailPlaybackPresenter.PLAYBACK_STREAM); } /** Called by the CallLogQueryHandler when the list of calls has been fetched or updated. */ diff --git a/src/com/android/dialer/calllog/GroupingListAdapter.java b/src/com/android/dialer/calllog/GroupingListAdapter.java index 501e88df0..8d3ab4545 100644 --- a/src/com/android/dialer/calllog/GroupingListAdapter.java +++ b/src/com/android/dialer/calllog/GroupingListAdapter.java @@ -253,7 +253,6 @@ abstract class GroupingListAdapter extends RecyclerView.Adapter { * corresponding cursor position. */ public void obtainPositionMetadata(PositionMetadata metadata, int position) { - // If the description object already contains requested information, just return if (metadata.listPosition == position) { return; @@ -433,17 +432,4 @@ abstract class GroupingListAdapter extends RecyclerView.Adapter { return -1; } } - - /** - * Used for setting the cursor without triggering a UI thread update. - */ - @NeededForTesting - public void setCursorForTesting(Cursor cursor) { - if (cursor != null) { - mCursor = cursor; - cursor.registerContentObserver(mChangeObserver); - cursor.registerDataSetObserver(mDataSetObserver); - mRowIdColumnIndex = cursor.getColumnIndexOrThrow("_id"); - } - } } diff --git a/src/com/android/dialer/calllog/IntentProvider.java b/src/com/android/dialer/calllog/IntentProvider.java index d7a35e8ad..a11d00bc2 100644 --- a/src/com/android/dialer/calllog/IntentProvider.java +++ b/src/com/android/dialer/calllog/IntentProvider.java @@ -83,24 +83,6 @@ public abstract class IntentProvider { }; } - public static IntentProvider getPlayVoicemailIntentProvider(final long rowId, - final String voicemailUri) { - return new IntentProvider() { - @Override - public Intent getIntent(Context context) { - Intent intent = new Intent(context, CallDetailActivity.class); - intent.setData(ContentUris.withAppendedId( - Calls.CONTENT_URI_WITH_VOICEMAIL, rowId)); - if (voicemailUri != null) { - intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI, - Uri.parse(voicemailUri)); - } - intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_START_PLAYBACK, true); - return intent; - } - }; - } - public static IntentProvider getSendSmsIntentProvider(final String number) { return new IntentProvider() { @Override @@ -129,7 +111,6 @@ public abstract class IntentProvider { intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI, Uri.parse(voicemailUri)); } - intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_START_PLAYBACK, false); if (extraIds != null && extraIds.length > 0) { intent.putExtra(CallDetailActivity.EXTRA_CALL_LOG_IDS, extraIds); diff --git a/src/com/android/dialer/list/AllContactsFragment.java b/src/com/android/dialer/list/AllContactsFragment.java index eaa5cc808..71c6980f3 100644 --- a/src/com/android/dialer/list/AllContactsFragment.java +++ b/src/com/android/dialer/list/AllContactsFragment.java @@ -16,6 +16,7 @@ package com.android.dialer.list; +import android.content.Loader; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract.CommonDataKinds.Phone; @@ -39,6 +40,8 @@ import com.android.dialer.util.DialerUtils; */ public class AllContactsFragment extends ContactEntryListFragment<ContactEntryListAdapter> { + private View mEmptyListView; + public AllContactsFragment() { setQuickContactEnabled(false); setAdjustSelectionBoundsEnabled(true); @@ -52,10 +55,11 @@ public class AllContactsFragment extends ContactEntryListFragment<ContactEntryLi public void onViewCreated(View view, android.os.Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - View emptyListView = view.findViewById(R.id.empty_list_view); - DialerUtils.configureEmptyListView(emptyListView, R.drawable.empty_contacts, + mEmptyListView = view.findViewById(R.id.empty_list_view); + DialerUtils.configureEmptyListView(mEmptyListView, R.drawable.empty_contacts, R.string.all_contacts_empty, getResources()); - getListView().setEmptyView(emptyListView); + getListView().setEmptyView(mEmptyListView); + mEmptyListView.setVisibility(View.GONE); ViewUtil.addBottomPaddingToListViewForFab(getListView(), getResources()); } @@ -68,6 +72,15 @@ public class AllContactsFragment extends ContactEntryListFragment<ContactEntryLi } @Override + public void onLoadFinished(Loader<Cursor> loader, Cursor data) { + super.onLoadFinished(loader, data); + + if (data.getCount() == 0) { + mEmptyListView.setVisibility(View.VISIBLE); + } + } + + @Override protected ContactEntryListAdapter createListAdapter() { if (!PermissionsUtil.hasContactsPermissions(getActivity())) { return new EmptyContactsListAdapter(getActivity()); diff --git a/src/com/android/dialer/list/DialerPhoneNumberListAdapter.java b/src/com/android/dialer/list/DialerPhoneNumberListAdapter.java index 8a4302319..17c573f1c 100644 --- a/src/com/android/dialer/list/DialerPhoneNumberListAdapter.java +++ b/src/com/android/dialer/list/DialerPhoneNumberListAdapter.java @@ -3,6 +3,8 @@ package com.android.dialer.list; import android.content.Context; import android.content.res.Resources; import android.telephony.PhoneNumberUtils; +import android.text.BidiFormatter; +import android.text.TextDirectionHeuristics; import android.view.View; import android.view.ViewGroup; @@ -36,6 +38,8 @@ public class DialerPhoneNumberListAdapter extends PhoneNumberListAdapter { private final boolean[] mShortcutEnabled = new boolean[SHORTCUT_COUNT]; + private final BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); + public DialerPhoneNumberListAdapter(Context context) { super(context); @@ -141,7 +145,9 @@ public class DialerPhoneNumberListAdapter extends PhoneNumberListAdapter { final String number = getFormattedQueryString(); switch (shortcutType) { case SHORTCUT_DIRECT_CALL: - text = resources.getString(R.string.search_shortcut_call_number, number); + text = resources.getString( + R.string.search_shortcut_call_number, + mBidiFormatter.unicodeWrap(number, TextDirectionHeuristics.LTR)); drawableId = R.drawable.ic_search_phone; break; case SHORTCUT_CREATE_NEW_CONTACT: diff --git a/src/com/android/dialer/settings/SoundSettingsFragment.java b/src/com/android/dialer/settings/SoundSettingsFragment.java index 43297b5e5..c7bb2d361 100644 --- a/src/com/android/dialer/settings/SoundSettingsFragment.java +++ b/src/com/android/dialer/settings/SoundSettingsFragment.java @@ -28,6 +28,7 @@ import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.provider.Settings; +import android.telephony.CarrierConfigManager; import android.telephony.TelephonyManager; import com.android.dialer.R; @@ -208,8 +209,9 @@ public class SoundSettingsFragment extends PreferenceFragment } private boolean shouldHideCarrierSettings() { - int hideCarrierNetworkSetting = Settings.Global.getInt(getActivity().getContentResolver(), - Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, SHOW_CARRIER_SETTINGS); - return hideCarrierNetworkSetting == HIDE_CARRIER_SETTINGS; + CarrierConfigManager configManager = (CarrierConfigManager) getActivity().getSystemService( + Context.CARRIER_CONFIG_SERVICE); + return configManager.getConfig().getBoolean( + CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL); } } diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java index 703004d07..0313f4004 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java @@ -37,6 +37,7 @@ import android.widget.TextView; import com.android.common.io.MoreCloseables; import com.android.dialer.R; +import com.android.dialer.calllog.CallLogAsyncTaskUtil; import com.google.common.base.Preconditions; @@ -124,7 +125,7 @@ public class VoicemailPlaybackLayout extends LinearLayout /** * Handle state changes when the user manipulates the seek bar. */ - private final OnSeekBarChangeListener seekBarChangeListener = new OnSeekBarChangeListener() { + private final OnSeekBarChangeListener mSeekBarChangeListener = new OnSeekBarChangeListener() { @Override public void onStartTrackingTouch(SeekBar seekBar) { if (mPresenter != null) { @@ -148,7 +149,7 @@ public class VoicemailPlaybackLayout extends LinearLayout /** * Click listener to toggle speakerphone. */ - private final View.OnClickListener speakerphoneListener = new View.OnClickListener() { + private final View.OnClickListener mSpeakerphoneListener = new View.OnClickListener() { @Override public void onClick(View v) { if (mPresenter != null) { @@ -160,7 +161,7 @@ public class VoicemailPlaybackLayout extends LinearLayout /** * Click listener to play or pause voicemail playback. */ - private final View.OnClickListener startStopButtonListener = new View.OnClickListener() { + private final View.OnClickListener mStartStopButtonListener = new View.OnClickListener() { @Override public void onClick(View view) { if (mPresenter == null) { @@ -175,6 +176,16 @@ public class VoicemailPlaybackLayout extends LinearLayout } }; + private final View.OnClickListener mDeleteButtonListener = new View.OnClickListener() { + @Override + public void onClick(View view ) { + if (mPresenter == null) { + return; + } + CallLogAsyncTaskUtil.deleteVoicemail(mContext, mPresenter.getVoicemailUri(), null); + } + }; + private Context mContext; private VoicemailPlaybackPresenter mPresenter; @@ -183,6 +194,7 @@ public class VoicemailPlaybackLayout extends LinearLayout private SeekBar mPlaybackSeek; private ImageButton mStartStopButton; private ImageButton mPlaybackSpeakerphone; + private ImageButton mDeleteButton; private TextView mPlaybackPosition; private PositionUpdater mPositionUpdater; @@ -212,11 +224,13 @@ public class VoicemailPlaybackLayout extends LinearLayout mPlaybackSeek = (SeekBar) findViewById(R.id.playback_seek); mStartStopButton = (ImageButton) findViewById(R.id.playback_start_stop); mPlaybackSpeakerphone = (ImageButton) findViewById(R.id.playback_speakerphone); + mDeleteButton = (ImageButton) findViewById(R.id.delete_voicemail); mPlaybackPosition = (TextView) findViewById(R.id.playback_position_text); - mPlaybackSeek.setOnSeekBarChangeListener(seekBarChangeListener); - mStartStopButton.setOnClickListener(startStopButtonListener); - mPlaybackSpeakerphone.setOnClickListener(speakerphoneListener); + mPlaybackSeek.setOnSeekBarChangeListener(mSeekBarChangeListener); + mStartStopButton.setOnClickListener(mStartStopButtonListener); + mPlaybackSpeakerphone.setOnClickListener(mSpeakerphoneListener); + mDeleteButton.setOnClickListener(mDeleteButtonListener); } @Override diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java index 99d2734eb..da2a29cf7 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java @@ -98,7 +98,7 @@ public class VoicemailPlaybackPresenter VoicemailContract.Voicemails.HAS_CONTENT, }; - private static final int PLAYBACK_STREAM = AudioManager.STREAM_VOICE_CALL; + public static final int PLAYBACK_STREAM = AudioManager.STREAM_VOICE_CALL; private static final int NUMBER_OF_THREADS_IN_POOL = 2; // Time to wait for content to be fetched before timing out. private static final long FETCH_CONTENT_TIMEOUT_MS = 20000; @@ -141,11 +141,12 @@ public class VoicemailPlaybackPresenter * This variable is thread-contained, accessed only on the ui thread. */ private FetchResultHandler mFetchResultHandler; + private Handler mHandler = new Handler(); private PowerManager.WakeLock mProximityWakeLock; private AudioManager mAudioManager; - public VoicemailPlaybackPresenter(Activity activity, Bundle savedInstanceState) { - mContext = activity; + public VoicemailPlaybackPresenter(Context context, Bundle savedInstanceState) { + mContext = context; mAsyncTaskExecutor = AsyncTaskExecutors.createAsyncTaskExecutor(); mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); @@ -173,8 +174,6 @@ public class VoicemailPlaybackPresenter mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnErrorListener(this); mMediaPlayer.setOnCompletionListener(this); - - activity.setVolumeControlStream(PLAYBACK_STREAM); } /** @@ -204,7 +203,7 @@ public class VoicemailPlaybackPresenter public void onPause(boolean isFinishing) { // Do not pause for orientation changes. - if (mMediaPlayer.isPlaying() && isFinishing) { + if (mIsPrepared && mMediaPlayer.isPlaying() && isFinishing) { pausePlayback(); } @@ -298,13 +297,12 @@ public class VoicemailPlaybackPresenter * was not available. */ private void requestContent() { - Preconditions.checkState(mFetchResultHandler == null, "mFetchResultHandler should be null"); + if (mFetchResultHandler != null) { + mFetchResultHandler.destroy(); + } - Handler handler = new Handler(); - mFetchResultHandler = new FetchResultHandler(handler); - mContext.getContentResolver().registerContentObserver( - mVoicemailUri, false, mFetchResultHandler); - handler.postDelayed(mFetchResultHandler.getTimeoutRunnable(), FETCH_CONTENT_TIMEOUT_MS); + mFetchResultHandler = new FetchResultHandler(new Handler()); + mFetchResultHandler.registerContentObserver(mVoicemailUri); // Send voicemail fetch request. Intent intent = new Intent(VoicemailContract.ACTION_FETCH_VOICEMAIL, mVoicemailUri); @@ -313,30 +311,37 @@ public class VoicemailPlaybackPresenter @ThreadSafe private class FetchResultHandler extends ContentObserver implements Runnable { - private AtomicBoolean mResultStillPending = new AtomicBoolean(true); - private final Handler mHandler; + private AtomicBoolean mIsWaitingForResult = new AtomicBoolean(true); + private final Handler mFetchResultHandler; public FetchResultHandler(Handler handler) { super(handler); - mHandler = handler; + mFetchResultHandler = handler; } - public Runnable getTimeoutRunnable() { - return this; + public void registerContentObserver(Uri voicemailUri) { + if (mIsWaitingForResult.get()) { + mContext.getContentResolver().registerContentObserver( + voicemailUri, false, this); + mFetchResultHandler.postDelayed(this, FETCH_CONTENT_TIMEOUT_MS); + } } + /** + * Stop waiting for content and notify UI if {@link FETCH_CONTENT_TIMEOUT_MS} has elapsed. + */ @Override public void run() { - if (mResultStillPending.getAndSet(false)) { - mContext.getContentResolver().unregisterContentObserver(FetchResultHandler.this); + if (mIsWaitingForResult.getAndSet(false)) { + mContext.getContentResolver().unregisterContentObserver(this); mView.setFetchContentTimeout(); } } public void destroy() { - if (mResultStillPending.getAndSet(false)) { - mContext.getContentResolver().unregisterContentObserver(FetchResultHandler.this); - mHandler.removeCallbacks(this); + if (mIsWaitingForResult.getAndSet(false)) { + mContext.getContentResolver().unregisterContentObserver(this); + mFetchResultHandler.removeCallbacks(this); } } @@ -352,7 +357,7 @@ public class VoicemailPlaybackPresenter @Override public void onPostExecute(Boolean hasContent) { if (hasContent) { - if (mResultStillPending.getAndSet(false)) { + if (mIsWaitingForResult.getAndSet(false)) { mContext.getContentResolver().unregisterContentObserver( FetchResultHandler.this); prepareToPlayContent(); @@ -556,6 +561,10 @@ public class VoicemailPlaybackPresenter return mAudioManager.isSpeakerphoneOn(); } + public Uri getVoicemailUri() { + return mVoicemailUri; + } + private static synchronized ScheduledExecutorService getScheduledExecutorServiceInstance() { if (mScheduledExecutorService == null) { mScheduledExecutorService = Executors.newScheduledThreadPool(NUMBER_OF_THREADS_IN_POOL); @@ -563,4 +572,8 @@ public class VoicemailPlaybackPresenter return mScheduledExecutorService; } + @VisibleForTesting + public boolean isPlaying() { + return mIsPlaying; + } } |