diff options
author | Srinivas Visvanathan <sriniv@google.com> | 2017-01-12 09:57:50 -0800 |
---|---|---|
committer | Srinivas Visvanathan <sriniv@google.com> | 2017-02-02 10:40:48 -0800 |
commit | 6f8e1dbe4629b499128dade1e6d83e37147403c4 (patch) | |
tree | fe90bb2c1ddbd1b8d8bb3f6134082f602e0515f6 | |
parent | 9d763fba7c611d980a7eae7b7f2df0453647d651 (diff) | |
download | platform_packages_apps_Car_Dialer-6f8e1dbe4629b499128dade1e6d83e37147403c4.tar.gz platform_packages_apps_Car_Dialer-6f8e1dbe4629b499128dade1e6d83e37147403c4.tar.bz2 platform_packages_apps_Car_Dialer-6f8e1dbe4629b499128dade1e6d83e37147403c4.zip |
Moving Dialer off CarActivity
- Migrating TelecomActivity to new CarDrawerActivity. Removed
TelecomProxyActivity since it's no longer needed.
- TelecomActivity now produces CarDrawerAdapter subclasses to drive
drawer navigation. It's completely off CarMenu API.
- Modified CallLogListingTask to return a list of CallLogItem's. It now
invokes the provided LoadCompleteListener when its done.
- Updated Dialer fragments impacted by TelecomActivity change.
Bug: 34351310
Test: Manually
Change-Id: I600f4c786a368f485e2f5758c7b133ea7265ba21
-rw-r--r-- | AndroidManifest.xml | 4 | ||||
-rw-r--r-- | src/com/android/car/dialer/CallLogListingTask.java | 172 | ||||
-rw-r--r-- | src/com/android/car/dialer/DialerFragment.java | 50 | ||||
-rw-r--r-- | src/com/android/car/dialer/OngoingCallFragment.java | 208 | ||||
-rw-r--r-- | src/com/android/car/dialer/StrequentsFragment.java | 42 | ||||
-rw-r--r-- | src/com/android/car/dialer/TelecomActivity.java | 266 | ||||
-rw-r--r-- | src/com/android/car/dialer/TelecomProxyActivity.java | 26 |
7 files changed, 279 insertions, 489 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2abe4608..45b46b54 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -31,9 +31,9 @@ android:label="@string/phone_app_name" android:icon="@drawable/ic_app_icon"> - <activity android:name=".TelecomProxyActivity" + <activity android:name=".TelecomActivity" android:launchMode="singleInstance" - android:theme="@android:style/Theme.NoTitleBar" + android:theme="@style/CarDrawerActivityTheme" android:label="@string/phone_app_name" android:exported="true" android:resizeableActivity="true"> diff --git a/src/com/android/car/dialer/CallLogListingTask.java b/src/com/android/car/dialer/CallLogListingTask.java index 6cc04dd3..2300a8a0 100644 --- a/src/com/android/car/dialer/CallLogListingTask.java +++ b/src/com/android/car/dialer/CallLogListingTask.java @@ -15,66 +15,64 @@ */ package com.android.car.dialer; -import com.android.car.apps.common.LetterTileDrawable; -import com.android.car.dialer.telecom.UiCallManager; -import com.android.car.dialer.telecom.PhoneLoader; -import com.android.car.dialer.telecom.TelecomUtils; - import android.content.ContentResolver; import android.content.Context; -import android.content.Intent; -import android.content.Loader; import android.content.res.Resources; import android.database.Cursor; import android.graphics.Bitmap; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; import android.os.AsyncTask; -import android.os.Handler; import android.provider.CallLog; -import android.support.car.app.menu.CarMenu; +import android.support.annotation.NonNull; import android.support.car.ui.CircleBitmapDrawable; -import android.telecom.Call; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.text.format.DateUtils; -import android.util.Log; -import android.view.View; -import android.widget.RemoteViews; + +import com.android.car.apps.common.LetterTileDrawable; +import com.android.car.dialer.telecom.PhoneLoader; +import com.android.car.dialer.telecom.TelecomUtils; import java.util.ArrayList; import java.util.List; -public class CallLogListingTask extends AsyncTask<Void, Void, Void> { - private static final String CALL_TYPE_ICON_ID_PREFIX = "call_type_icon_"; - private static final int MAX_CALL_TYPE_ICONS = 3; +class CallLogListingTask extends AsyncTask<Void, Void, Void> { + static class CallLogItem { + final String mTitle; + final String mText; + final String mNumber; + final Bitmap mIcon; + // TODO: need right icon. + + public CallLogItem(String title, String text, String number, Bitmap icon) { + mTitle = title; + mText = text; + mNumber = number; + mIcon = icon; + } + } + + interface LoadCompleteListener { + void onLoadComplete(List<CallLogItem> items); + } + // Like a constant but needs a context so not static. private final String VOICEMAIL_NUMBER; private Context mContext; - private CarMenu mResult; - private List<CarMenu.Item> mItems = new ArrayList<>(); private Cursor mCursor; - - private CallLogListingTask(Builder builder) { - mContext = builder.mContext; - mResult = builder.mResult; - mCursor = builder.mCursor; + private List<CallLogItem> mItems; + private LoadCompleteListener mListener; + + CallLogListingTask(Context context, Cursor cursor, + @NonNull LoadCompleteListener listener) { + mContext = context; + mCursor = cursor; + mItems = new ArrayList<>(mCursor.getCount()); + mListener = listener; VOICEMAIL_NUMBER = TelecomUtils.getVoicemailNumber(mContext); } - private CarMenu.Item getEmptyItem() { - final int iconColor = mContext.getColor(R.color.car_tint); - Drawable drawable = mContext.getDrawable(R.drawable.ic_list_view_disable); - drawable.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN); - return new CarMenu.Builder(TelecomActivity.CALL_LOG_EMPTY_PLACEHOLDER) - .setTitle(mContext.getString(R.string.recent_calls_empty)) - .setIconFromSnapshot(drawable) - .setIsEmptyPlaceHolder(true) - .build(); - } - private String maybeAppendCount(StringBuilder sb, int count) { if (count > 1) { sb.append(" (").append(count).append(")"); @@ -126,56 +124,6 @@ public class CallLogListingTask extends AsyncTask<Void, Void, Void> { DateUtils.FORMAT_ABBREV_RELATIVE) : null; } - private int getCallTypeDrawableResId(int callType) { - switch (callType) { - case PhoneLoader.INCOMING_TYPE: - return R.drawable.ic_call_received; - case PhoneLoader.OUTGOING_TYPE: - return R.drawable.ic_call_made; - case PhoneLoader.MISSED_TYPE: - return R.drawable.ic_call_missed; - case PhoneLoader.VOICEMAIL_TYPE: - return R.drawable.ic_call_voicemail; - default: - // It is possible for users to end up with calls with unknown call types in their - // call history, possibly due to 3rd party call log implementations (e.g. to - // distinguish between rejected and missed calls). Instead of crashing, just - // assume that all unknown call types are missed calls. - return R.drawable.ic_call_missed; - } - } - - private RemoteViews getCallTypeIcon(Cursor cursor, int count) { - RemoteViews callTypeIconView = new RemoteViews(mContext.getPackageName(), - R.layout.call_type_icons); - int[] callTypes = UiCallManager.getInstance(mContext).getCallTypes(cursor, count); - int icons = Math.min(callTypes.length, MAX_CALL_TYPE_ICONS); - - for (int i = 0; i < icons; i++) { - int viewId = mContext.getResources().getIdentifier( - CALL_TYPE_ICON_ID_PREFIX + i, "id", mContext.getPackageName()); - callTypeIconView.setImageViewResource(viewId, getCallTypeDrawableResId(callTypes[i])); - callTypeIconView.setViewVisibility(viewId, View.VISIBLE); - } - - for (int i = icons; i < MAX_CALL_TYPE_ICONS; i++) { - int viewId = mContext.getResources().getIdentifier( - CALL_TYPE_ICON_ID_PREFIX + i, "id", mContext.getPackageName()); - callTypeIconView.setViewVisibility(viewId, View.GONE); - } - - return callTypeIconView; - } - - public static String getNumberFromCarMenuId(String id) { - // Call log menu item's id is formed by: PHONE_NUMBER + "_" + CURSOR_ID. - return id.substring(0, id.lastIndexOf('_')); - } - - private String makeId(String number, long id) { - return number + "_" + id; - } - @Override protected Void doInBackground(Void... voids) { ContentResolver resolver = mContext.getContentResolver(); @@ -185,7 +133,6 @@ public class CallLogListingTask extends AsyncTask<Void, Void, Void> { int cachedNameColumn = PhoneLoader.getNameColumnIndex(mCursor); int numberColumn = PhoneLoader.getNumberColumnIndex(mCursor); int dateColumn = mCursor.getColumnIndex(CallLog.Calls.DATE); - int rowIdColumn = PhoneLoader.getIdColumnIndex(mCursor); while (mCursor.moveToNext()) { int count = 1; @@ -229,14 +176,11 @@ public class CallLogListingTask extends AsyncTask<Void, Void, Void> { secondaryText.append(relativeDate); } - String id = makeId(number, mCursor.getLong(rowIdColumn)); Bitmap contactImage = getContactImage(mContext, resolver, name, number); - CarMenu.Builder builder = new CarMenu.Builder(id) - .setTitle(name) - .setText(secondaryText.toString()) - .setIcon(contactImage) - .setRemoteViews(getCallTypeIcon(mCursor, count)); - mItems.add(builder.build()); + + CallLogItem item = + new CallLogItem(name, secondaryText.toString(), number, contactImage); + mItems.add(item); // Since we deduplicated count rows, we can move all the way to that row so the // next iteration takes us to the row following the last duplicate row. @@ -250,13 +194,14 @@ public class CallLogListingTask extends AsyncTask<Void, Void, Void> { mCursor.close(); } } - - if (mItems.isEmpty()) { - mItems.add(getEmptyItem()); - } return null; } + @Override + protected void onPostExecute(Void aVoid) { + mListener.onLoadComplete(mItems); + } + /** * Determines if the specified number is actually a URI * (i.e. a SIP address) rather than a regular PSTN phone number, @@ -311,35 +256,4 @@ public class CallLogListingTask extends AsyncTask<Void, Void, Void> { } return values; } - - @Override - protected void onPostExecute(Void unused) { - mResult.sendResult(mItems); - } - - public static class Builder { - private Context mContext; - private String mParentId; - private CarMenu mResult; - private Cursor mCursor; - - public Builder setContext(Context context) { - mContext = context; - return this; - } - - public Builder setResult(CarMenu result) { - mResult = result; - return this; - } - - public Builder setCursor(Cursor cursor) { - mCursor = cursor; - return this; - } - - public CallLogListingTask build() { - return new CallLogListingTask(this); - } - } } diff --git a/src/com/android/car/dialer/DialerFragment.java b/src/com/android/car/dialer/DialerFragment.java index 5b6ce2ba..b3f42ca8 100644 --- a/src/com/android/car/dialer/DialerFragment.java +++ b/src/com/android/car/dialer/DialerFragment.java @@ -111,19 +111,16 @@ public class DialerFragment extends Fragment { Log.d(TAG, "onCreateView"); } - mContext = getTelecomActivity().getContext(); + mContext = getContext(); View view = inflater.inflate(R.layout.dialer_fragment, container, false); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "onCreateView: inflated successfully"); } - view.findViewById(R.id.exit_dialer_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (mBackListener != null) { - mBackListener.onDialerBackClick(); - } + view.findViewById(R.id.exit_dialer_button).setOnClickListener((unusedView) -> { + if (mBackListener != null) { + mBackListener.onDialerBackClick(); } }); @@ -142,27 +139,21 @@ public class DialerFragment extends Fragment { answerCallDrawable.setFabAndStrokeColor(getResources().getColor(R.color.phone_call)); callButton.setBackground(answerCallDrawable); callButton.setVisibility(View.VISIBLE); - callButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "Call button clicked, placing a call: " + mNumber.toString()); - } - - if (!TextUtils.isEmpty(mNumber.toString())) { - getUiCallManager().safePlaceCall(mNumber.toString(), false); - } + callButton.setOnClickListener((unusedView) -> { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Call button clicked, placing a call: " + mNumber.toString()); + } + + if (!TextUtils.isEmpty(mNumber.toString())) { + getUiCallManager().safePlaceCall(mNumber.toString(), false); } }); View deleteButton = view.findViewById(R.id.delete); deleteButton.setVisibility(View.VISIBLE); - deleteButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (mNumber.length() != 0) { - mNumber.deleteCharAt(mNumber.length() - 1); - mNumberView.setText(getFormattedNumber(mNumber.toString())); - } + deleteButton.setOnClickListener((unusedView) -> { + if (mNumber.length() != 0) { + mNumber.deleteCharAt(mNumber.length() - 1); + mNumberView.setText(getFormattedNumber(mNumber.toString())); } }); } @@ -252,12 +243,7 @@ public class DialerFragment extends Fragment { if (mContext != null && mNumberView != null) { setDialNumberInternal(number); } else { - mPendingRunnable = new Runnable() { - @Override - public void run() { - setDialNumberInternal(number); - } - }; + mPendingRunnable = () -> setDialNumberInternal(number); } } @@ -294,10 +280,6 @@ public class DialerFragment extends Fragment { return TelecomUtils.getFormattedNumber(mContext, number); } - private TelecomActivity getTelecomActivity() { - return (TelecomActivity) getHost(); - } - private final CallListener mCallListener = new CallListener() { @Override public void dispatchPhoneKeyEvent(KeyEvent event) { diff --git a/src/com/android/car/dialer/OngoingCallFragment.java b/src/com/android/car/dialer/OngoingCallFragment.java index 394f546e..988812c9 100644 --- a/src/com/android/car/dialer/OngoingCallFragment.java +++ b/src/com/android/car/dialer/OngoingCallFragment.java @@ -110,7 +110,7 @@ public class OngoingCallFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mUiCallManager = UiCallManager.getInstance(getTelecomActivity().getContext()); + mUiCallManager = UiCallManager.getInstance(getContext()); mUiBluetoothMonitor = UiBluetoothMonitor.getInstance(); mHandler = new Handler(); } @@ -183,112 +183,89 @@ public class OngoingCallFragment extends Fragment { setDialPadFocusability(!hasTouch); setInCallControllerFocusability(!hasTouch); - mAnswerCallButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - UiCall call = mUiCallManager.getCallWithState(Call.STATE_RINGING); - if (call == null) { - Log.w(TAG, "There is no incoming call to answer."); - return; - } - mUiCallManager.answerCall(call); + mAnswerCallButton.setOnClickListener((unusedView) -> { + UiCall call = mUiCallManager.getCallWithState(Call.STATE_RINGING); + if (call == null) { + Log.w(TAG, "There is no incoming call to answer."); + return; } + mUiCallManager.answerCall(call); }); - FabDrawable answerCallDrawable = new FabDrawable(getTelecomActivity().getContext()); + Context context = getContext(); + FabDrawable answerCallDrawable = new FabDrawable(context); answerCallDrawable.setFabAndStrokeColor(getResources().getColor(R.color.phone_call)); mAnswerCallButton.setBackground(answerCallDrawable); - mRejectCallButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - UiCall call = mUiCallManager.getCallWithState(Call.STATE_RINGING); - if (call == null) { - Log.w(TAG, "There is no incoming call to reject."); - return; - } - mUiCallManager.rejectCall(call, false, null); + mRejectCallButton.setOnClickListener((unusedView) -> { + UiCall call = mUiCallManager.getCallWithState(Call.STATE_RINGING); + if (call == null) { + Log.w(TAG, "There is no incoming call to reject."); + return; } + mUiCallManager.rejectCall(call, false, null); }); - mEndCallButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - UiCall call = mUiCallManager.getPrimaryCall(); - if (call == null) { - Log.w(TAG, "There is no active call to end."); - return; - } - mUiCallManager.disconnectCall(call); + mEndCallButton.setOnClickListener((unusedView) -> { + UiCall call = mUiCallManager.getPrimaryCall(); + if (call == null) { + Log.w(TAG, "There is no active call to end."); + return; } + mUiCallManager.disconnectCall(call); }); - FabDrawable endCallDrawable = new FabDrawable(getTelecomActivity().getContext()); + FabDrawable endCallDrawable = new FabDrawable(context); endCallDrawable.setFabAndStrokeColor(getResources().getColor(R.color.phone_end_call)); mEndCallButton.setBackground(endCallDrawable); - mUnholdCallButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - UiCall call = mUiCallManager.getPrimaryCall(); - if (call == null) { - Log.w(TAG, "There is no active call to unhold."); - return; - } - mUiCallManager.unholdCall(call); + mUnholdCallButton.setOnClickListener((unusedView) -> { + UiCall call = mUiCallManager.getPrimaryCall(); + if (call == null) { + Log.w(TAG, "There is no active call to unhold."); + return; } + mUiCallManager.unholdCall(call); }); - FabDrawable unholdCallDrawable = new FabDrawable(getTelecomActivity().getContext()); + FabDrawable unholdCallDrawable = new FabDrawable(context); unholdCallDrawable.setFabAndStrokeColor(getResources().getColor(R.color.phone_call)); mUnholdCallButton.setBackground(unholdCallDrawable); - mMuteButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (mUiCallManager.getMuted()) { - mUiCallManager.setMuted(false); - } else { - mUiCallManager.setMuted(true); - } + mMuteButton.setOnClickListener((unusedView) -> { + if (mUiCallManager.getMuted()) { + mUiCallManager.setMuted(false); + } else { + mUiCallManager.setMuted(true); } }); - mSwapButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - UiCall call = mUiCallManager.getPrimaryCall(); - if (call == null) { - Log.w(TAG, "There is no active call to hold."); - return; - } - if (call.getState() == Call.STATE_HOLDING) { - mUiCallManager.unholdCall(call); - } else { - mUiCallManager.holdCall(call); - } + mSwapButton.setOnClickListener((unusedView) -> { + UiCall call = mUiCallManager.getPrimaryCall(); + if (call == null) { + Log.w(TAG, "There is no active call to hold."); + return; + } + if (call.getState() == Call.STATE_HOLDING) { + mUiCallManager.unholdCall(call); + } else { + mUiCallManager.holdCall(call); } }); - mMergeButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - UiCall call = mUiCallManager.getPrimaryCall(); - UiCall secondarycall = mUiCallManager.getSecondaryCall(); - if (call == null || mSecondaryCall == null) { - Log.w(TAG, "There aren't two call to merge."); - return; - } - - mUiCallManager.conference(call, secondarycall); + mMergeButton.setOnClickListener((unusedView) -> { + UiCall call = mUiCallManager.getPrimaryCall(); + UiCall secondarycall = mUiCallManager.getSecondaryCall(); + if (call == null || mSecondaryCall == null) { + Log.w(TAG, "There aren't two call to merge."); + return; } + + mUiCallManager.conference(call, secondarycall); }); - mToggleDialpadButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (mToggleDialpadButton.isActivated()) { - closeDialpad(); - } else { - openDialpad(true /*animate*/); - } + mToggleDialpadButton.setOnClickListener((unusedView) -> { + if (mToggleDialpadButton.isActivated()) { + closeDialpad(); + } else { + openDialpad(true /*animate*/); } }); @@ -345,7 +322,7 @@ public class OngoingCallFragment extends Fragment { // Show the primary contact photo in the large ImageView on the right if there is no // secondary call. Otherwise, show it in the small ImageView that is inside the card. - Context context = getTelecomActivity().getContext(); + Context context = getContext(); final ContentResolver cr = context.getContentResolver(); final String primaryNumber = mPrimaryCall.getNumber(); // Don't reload the image if the number is the same. @@ -406,13 +383,13 @@ public class OngoingCallFragment extends Fragment { mSecondaryCallControls.setVisibility(View.GONE); } - String displayName = TelecomUtils.getDisplayName(getContext(), mPrimaryCall); + String displayName = TelecomUtils.getDisplayName(context, mPrimaryCall); mNameTextView.setText(displayName); mNameTextView.setVisibility(TextUtils.isEmpty(displayName) ? View.GONE : View.VISIBLE); if (mSecondaryCall != null) { mSecondaryNameTextView.setText( - TelecomUtils.getDisplayName(getContext(), mSecondaryCall)); + TelecomUtils.getDisplayName(context, mSecondaryCall)); } switch (mPrimaryCall.getState()) { @@ -554,25 +531,19 @@ public class OngoingCallFragment extends Fragment { .setStartDelay(0) .setDuration(384) .setInterpolator(mAccelerateDecelerateInterpolator) - .withEndAction(new Runnable() { - @Override - public void run() { + .withEndAction(() -> { mEndCallButton.setVisibility(View.INVISIBLE); mEndCallButton.setFocusable(false); - } - }).start(); + }).start(); mMuteButton.animate() .alpha(0) .setStartDelay(0) .setDuration(240) .setInterpolator(mAccelerateDecelerateInterpolator) - .withEndAction(new Runnable() { - @Override - public void run() { + .withEndAction(() -> { mMuteButton.setVisibility(View.INVISIBLE); mMuteButton.setFocusable(false); - } - }).start(); + }).start(); mToggleDialpadButton.animate() .setStartDelay(0) .translationX(-(mEndCallButton.getWidth() + muteButtonLeftMargin @@ -589,9 +560,7 @@ public class OngoingCallFragment extends Fragment { .setDuration(320) .setInterpolator(mAccelerateDecelerateInterpolator) .setStartDelay(240) - .withStartAction(new Runnable() { - @Override - public void run() { + .withStartAction(() -> { mRotaryDialpad.setVisibility(View.VISIBLE); int delay = 0; for (View dialpadView : mDialpadViews) { @@ -604,8 +573,7 @@ public class OngoingCallFragment extends Fragment { .start(); delay += 10; } - } - }).start(); + }).start(); } } @@ -615,7 +583,7 @@ public class OngoingCallFragment extends Fragment { } mToggleDialpadButton.setActivated(false); if (getResources().getBoolean(R.bool.has_touch)) { - Animation anim = new DialpadAnimation(getTelecomActivity().getContext(), true /* reverse */); + Animation anim = new DialpadAnimation(getContext(), true /* reverse */); mDialpadContainer.startAnimation(anim); } else { final int toggleButtonImageOffset = getResources().getDimensionPixelSize( @@ -629,9 +597,7 @@ public class OngoingCallFragment extends Fragment { + muteButtonLeftMargin + toggleButtonImageOffset)) .setDuration(320) .setInterpolator(mAccelerateDecelerateInterpolator) - .withStartAction(new Runnable() { - @Override - public void run() { + .withStartAction(() -> { int delay = 0; for (int i = mDialpadViews.size() - 1; i >= 0; i--) { View dialpadView = mDialpadViews.get(i); @@ -643,15 +609,10 @@ public class OngoingCallFragment extends Fragment { .start(); delay += 10; } - } - }) - .withEndAction(new Runnable() { - @Override - public void run() { + }).withEndAction(() -> { mRotaryDialpad.setVisibility(View.GONE); mRotaryDialpad.setTranslationX(0); - } - }).start(); + }).start(); mToggleDialpadButton.animate() .translationX(0) .setDuration(480) @@ -663,25 +624,19 @@ public class OngoingCallFragment extends Fragment { .setDuration(176) .setInterpolator(mAccelerateDecelerateInterpolator) .setStartDelay(384) - .withStartAction(new Runnable() { - @Override - public void run() { + .withStartAction(() -> { mMuteButton.setVisibility(View.VISIBLE); mMuteButton.setFocusable(true); - } - }).start(); + }).start(); mEndCallButton.animate() .alpha(1) .setDuration(320) .setInterpolator(mAccelerateDecelerateInterpolator) .setStartDelay(240) - .withStartAction(new Runnable() { - @Override - public void run() { + .withStartAction(() -> { mEndCallButton.setVisibility(View.VISIBLE); mEndCallButton.setFocusable(true); - } - }).start(); + }).start(); } } @@ -715,10 +670,6 @@ public class OngoingCallFragment extends Fragment { } } - private TelecomActivity getTelecomActivity() { - return (TelecomActivity) getHost(); - } - private final View.OnTouchListener mDialpadTouchListener = new View.OnTouchListener() { @Override @@ -883,13 +834,8 @@ public class OngoingCallFragment extends Fragment { } }; - private final UiBluetoothMonitor.Listener mBluetoothListener = - new UiBluetoothMonitor.Listener() { - - @Override - public void onStateChanged() { - OngoingCallFragment.this.mIsHfpConnected = - UiBluetoothMonitor.getInstance().isHfpConnected(); - } + private final UiBluetoothMonitor.Listener mBluetoothListener = () -> { + OngoingCallFragment.this.mIsHfpConnected = + UiBluetoothMonitor.getInstance().isHfpConnected(); }; } diff --git a/src/com/android/car/dialer/StrequentsFragment.java b/src/com/android/car/dialer/StrequentsFragment.java index 71e81738..3e744953 100644 --- a/src/com/android/car/dialer/StrequentsFragment.java +++ b/src/com/android/car/dialer/StrequentsFragment.java @@ -73,7 +73,7 @@ public class StrequentsFragment extends Fragment { Log.d(TAG, "onCreateView"); } - mContext = getTelecomActivity().getContext(); + mContext = getContext(); View view = inflater.inflate(R.layout.strequents_fragment, container, false); mListView = (PagedListView) view.findViewById(R.id.list_view); @@ -81,32 +81,26 @@ public class StrequentsFragment extends Fragment { Bundle args = getArguments(); mSpeedialCursorLoader = PhoneLoader.registerCallObserver(PhoneLoader.CALL_TYPE_SPEED_DIAL, - mContext, new Loader.OnLoadCompleteListener<Cursor>() { - @Override - public void onLoadComplete(Loader<Cursor> loader, Cursor cursor) { - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "PhoneLoader: onLoadComplete (CALL_TYPE_SPEED_DIAL)"); - } + mContext, (loader, cursor) -> { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "PhoneLoader: onLoadComplete (CALL_TYPE_SPEED_DIAL)"); + } - onLoadStrequentCursor(cursor); + onLoadStrequentCursor(cursor); - if (mContext != null) { - mListView.setDefaultItemDecoration(new Decoration(mContext)); - } - } - }); + if (mContext != null) { + mListView.setDefaultItemDecoration(new Decoration(mContext)); + } + }); // Get the latest call log from the call logs history. mCallLogCursorLoader = PhoneLoader.registerCallObserver(PhoneLoader.CALL_TYPE_ALL, mContext, - new Loader.OnLoadCompleteListener<Cursor>() { - @Override - public void onLoadComplete(Loader<Cursor> loader, Cursor cursor) { - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "PhoneLoader: onLoadComplete (CALL_TYPE_ALL)"); - } - onLoadCallLogCursor(cursor); - } - }); + (loader, cursor) -> { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "PhoneLoader: onLoadComplete (CALL_TYPE_ALL)"); + } + onLoadCallLogCursor(cursor); + }); ContentResolver contentResolver = mContext.getContentResolver(); contentResolver.registerContentObserver(mSpeedialCursorLoader.getUri(), @@ -226,10 +220,6 @@ public class StrequentsFragment extends Fragment { } }; - private TelecomActivity getTelecomActivity() { - return (TelecomActivity) getHost(); - } - /** * A {@link ContentResolver} that is responsible for reloading the user's starred and frequent * contacts. diff --git a/src/com/android/car/dialer/TelecomActivity.java b/src/com/android/car/dialer/TelecomActivity.java index 55e435ac..a7953f6d 100644 --- a/src/com/android/car/dialer/TelecomActivity.java +++ b/src/com/android/car/dialer/TelecomActivity.java @@ -15,31 +15,26 @@ */ package com.android.car.dialer; -import android.content.Context; import android.content.Intent; -import android.content.Loader; -import android.database.Cursor; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.car.Car; -import android.support.car.app.menu.CarDrawerActivity; -import android.support.car.app.menu.CarMenu; -import android.support.car.app.menu.CarMenuCallbacks; -import android.support.car.app.menu.RootMenu; -import android.support.car.app.menu.compat.CarMenuConstantsComapt; -import android.support.car.input.CarInputManager; import android.support.v4.app.Fragment; import android.telecom.Call; import android.telephony.PhoneNumberUtils; import android.util.Log; + +import com.android.car.app.CarDrawerActivity; +import com.android.car.app.CarDrawerAdapter; +import com.android.car.app.CarDrawerEmptyAdapter; +import com.android.car.app.CarDrawerListAdapter; +import com.android.car.app.DrawerItemViewHolder; import com.android.car.dialer.bluetooth.UiBluetoothMonitor; import com.android.car.dialer.telecom.PhoneLoader; import com.android.car.dialer.telecom.UiCall; import com.android.car.dialer.telecom.UiCallManager; import com.android.car.dialer.telecom.UiCallManager.CallListener; -import java.util.ArrayList; import java.util.List; /** @@ -61,17 +56,8 @@ public class TelecomActivity extends CarDrawerActivity implements private static final String DIALER_BACKSTACK = "DialerBackstack"; private static final String FRAGMENT_CLASS_KEY = "FRAGMENT_CLASS_KEY"; - public static final String CALL_LOG_EMPTY_PLACEHOLDER = "call_log_empty_placeholder"; - private final UiBluetoothMonitor.Listener mBluetoothListener = this::updateCurrentFragment; - public TelecomActivity(Proxy proxy, Context context, Car car) { - super(proxy, context, car); - if (vdebug()) { - Log.d(TAG, "ctor: proxy: " + proxy + ", context: " + context); - } - } - private UiCallManager mUiCallManager; private UiBluetoothMonitor mUiBluetoothMonitor; @@ -92,14 +78,10 @@ public class TelecomActivity extends CarDrawerActivity implements if (vdebug()) { Log.d(TAG, "onCreate"); } - Context context = getContext(); - setLightMode(); - getWindow().getDecorView().setBackgroundColor(context.getColor(R.color.phone_theme)); - setTitle(context.getString(R.string.phone_app_name)); + getWindow().getDecorView().setBackgroundColor(getColor(R.color.phone_theme)); + setTitle(getString(R.string.phone_app_name)); - setCarMenuCallbacks(new TelecomMenuCallbacks()); - - mUiCallManager = UiCallManager.getInstance(context); + mUiCallManager = UiCallManager.getInstance(this); mUiBluetoothMonitor = UiBluetoothMonitor.getInstance(); if (savedInstanceState != null) { @@ -167,7 +149,7 @@ public class TelecomActivity extends CarDrawerActivity implements getSupportFragmentManager().beginTransaction() .setCustomAnimations(enter, exit) - .replace(getFragmentContainerId(), fragment) + .replace(getContentContainerId(), fragment) .commitAllowingStateLoss(); mCurrentFragmentName = fragment.getClass().getSimpleName(); @@ -211,7 +193,7 @@ public class TelecomActivity extends CarDrawerActivity implements break; case Intent.ACTION_DIAL: - String number = PhoneNumberUtils.getNumberFromIntent(intent, getContext()); + String number = PhoneNumberUtils.getNumberFromIntent(intent, this); if (!(mCurrentFragment instanceof NoHfpFragment)) { showDialerWithNumber(number); } @@ -333,7 +315,7 @@ public class TelecomActivity extends CarDrawerActivity implements getSupportFragmentManager().beginTransaction() .setCustomAnimations(R.anim.telecom_slide_in, R.anim.telecom_slide_out, R.anim.telecom_slide_in, R.anim.telecom_slide_out) - .add(getFragmentContainerId(), mDialerFragment) + .add(getContentContainerId(), mDialerFragment) .addToBackStack(DIALER_BACKSTACK) .commitAllowingStateLoss(); @@ -366,16 +348,12 @@ public class TelecomActivity extends CarDrawerActivity implements } private void showNoHfpFragment(int stringResId) { - if (getInputManager().isInputActive()) { - getInputManager().stopInput(); - } - if (mCurrentFragment instanceof NoHfpFragment && stringResId == mLastNoHfpMessageId) { return; } mLastNoHfpMessageId = stringResId; - String errorMessage = getContext().getString(stringResId); + String errorMessage = getString(stringResId); NoHfpFragment frag = new NoHfpFragment(); frag.setErrorMessage(errorMessage); setContentFragment(frag); @@ -432,139 +410,145 @@ public class TelecomActivity extends CarDrawerActivity implements } }; + private void setContentFragment(Fragment fragment) { + getSupportFragmentManager().beginTransaction() + .replace(getContentContainerId(), fragment) + .commit(); + } + private static boolean vdebug() { return Log.isLoggable(TAG, Log.DEBUG); } - private final class TelecomMenuCallbacks extends CarMenuCallbacks { - /** Id for the telecom root menu */ - private static final String ROOT = "TELECOM_MENU_ROOT"; - private static final String VOICE_MAIL = "VOICE_MAIL"; - private static final String DIAL_NUMBER = "DIAL_NUMBER"; - private static final String CALL_HISTORY = "CALL_HISTORY"; - private static final String MISSED_CALLS = "MISSED_CALLS"; + @Override + protected CarDrawerAdapter getRootAdapter() { + return new DialerRootAdapter(); + } + + class CallLogAdapter extends CarDrawerListAdapter { + private final int mTitleResId; + private List<CallLogListingTask.CallLogItem> mItems; + + public CallLogAdapter(int titleResId, List<CallLogListingTask.CallLogItem> items) { + super(true /* useNormalLayout */); + mTitleResId = titleResId; + mItems = items; + } @Override - public RootMenu onGetRoot(Bundle hints) { - return new RootMenu(ROOT); + protected int getActualItemCount() { + return mItems.size(); } @Override - public void onLoadChildren(String parentId, CarMenu result) { - if (vdebug()) { - Log.d(TAG, "onLoadChildren, parentId: " + parentId + ", result: " + result); - } + protected int getTitleResId() { + return mTitleResId; + } - switch (parentId) { - case ROOT: - result.sendResult(generateTelecomRootMenu()); - break; + @Override + public void populateViewHolder(DrawerItemViewHolder holder, int position) { + holder.getTitle().setText(mItems.get(position).mTitle); + holder.getText().setText(mItems.get(position).mText); + holder.getIcon().setImageBitmap(mItems.get(position).mIcon); + } - case CALL_HISTORY: - loadCallHistoryAsync(PhoneLoader.CALL_TYPE_ALL, result, parentId); - break; + @Override + public void onItemClick(int position) { + closeDrawer(); + mUiCallManager.safePlaceCall(mItems.get(position).mNumber, false); + } + } - case MISSED_CALLS: - loadCallHistoryAsync(PhoneLoader.CALL_TYPE_MISSED, result, parentId); - break; + private class DialerRootAdapter extends CarDrawerListAdapter { + private static final int ITEM_DIAL = 0; + private static final int ITEM_CALLLOG_ALL = 1; + private static final int ITEM_CALLLOG_MISSED = 2; + private static final int ITEM_MAX = 3; - default: - throw new IllegalStateException("Shouldn't query on parentId: " + parentId); - } + DialerRootAdapter() { + super(false /* useNormalLayout */); } @Override - public void onItemClicked(String id) { - if (vdebug()) { - Log.d(TAG, "onItemClicked: " + id); - } - - switch (id) { - case VOICE_MAIL: - mUiCallManager.callVoicemail(); - break; + protected int getActualItemCount() { + return ITEM_MAX; + } - case DIAL_NUMBER: - // The dialpad should not be shown if there is an on-going call. - if (!(mCurrentFragment instanceof OngoingCallFragment)) { - showDialer(); - } + @Override + protected int getTitleResId() { + return R.string.phone_app_name; + } + @Override + public void populateViewHolder(DrawerItemViewHolder holder, int position) { + final int iconColor = getResources().getColor(R.color.car_tint); + int textResId, iconResId; + switch (position) { + case ITEM_DIAL: + textResId = R.string.calllog_dial_number; + iconResId = R.drawable.ic_drawer_dialpad; break; - - case CALL_HISTORY: - case MISSED_CALLS: - case CALL_LOG_EMPTY_PLACEHOLDER: - // No-op + case ITEM_CALLLOG_ALL: + textResId = R.string.calllog_all; + iconResId = R.drawable.ic_drawer_history; + break; + case ITEM_CALLLOG_MISSED: + textResId = R.string.calllog_missed; + iconResId = R.drawable.ic_drawer_call_missed; break; - default: - mUiCallManager.safePlaceCall( - CallLogListingTask.getNumberFromCarMenuId(id), false); + Log.wtf(TAG, "Unexpected position: " + position); + return; + } + holder.getTitle().setText(textResId); + Drawable drawable = getDrawable(iconResId); + drawable.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN); + holder.getIcon().setImageDrawable(drawable); + if (position > 0) { + drawable = getDrawable(R.drawable.ic_chevron_right); + drawable.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN); + holder.getRightIcon().setImageDrawable(drawable); } } @Override - public void onCarMenuOpened() { - super.onCarMenuOpened(); - CarInputManager inputManager = getInputManager(); - if (inputManager.isInputActive()) { - inputManager.stopInput(); + public void onItemClick(int position) { + switch (position) { + case ITEM_DIAL: + closeDrawer(); + showDialer(); + break; + case ITEM_CALLLOG_ALL: + loadCallHistoryAsync(PhoneLoader.CALL_TYPE_ALL, R.string.calllog_all); + break; + case ITEM_CALLLOG_MISSED: + loadCallHistoryAsync(PhoneLoader.CALL_TYPE_MISSED, R.string.calllog_missed); + break; + default: + Log.w(TAG, "Invalid position in ROOT menu! " + position); } } + } - private List<CarMenu.Item> generateTelecomRootMenu() { - List<CarMenu.Item> items = new ArrayList<>(); - Context context = getContext(); - final int iconColor = getResources().getColor(R.color.car_tint); - - Drawable drawable = context.getDrawable(R.drawable.ic_drawer_dialpad); - drawable.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN); - items.add(new CarMenu.Builder(DIAL_NUMBER) - .setTitle(getResources().getString(R.string.calllog_dial_number)) - .setIconFromSnapshot(drawable) - .build()); - - drawable = context.getDrawable(R.drawable.ic_drawer_history); - drawable.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN); - items.add(new CarMenu.Builder(CALL_HISTORY) - .setTitle(getResources().getString(R.string.calllog_all)) - .setIconFromSnapshot(drawable) - .setFlags(CarMenuConstantsComapt.MenuItemConstants.FLAG_BROWSABLE) - .build()); - - drawable = context.getDrawable(R.drawable.ic_drawer_call_missed); - drawable.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN); - items.add(new CarMenu.Builder(MISSED_CALLS) - .setTitle(getResources().getString(R.string.calllog_missed)) - .setIconFromSnapshot(drawable) - .setFlags(CarMenuConstantsComapt.MenuItemConstants.FLAG_BROWSABLE) - .build()); - - return items; - } - - private void loadCallHistoryAsync(int callType, CarMenu result, String parentId) { - result.detach(); - - // Warning: much callbackiness! - // First load up the call log cursor using the PhoneLoader so that happens in a - // background thread. TODO: Why isn't PhoneLoader using a LoaderManager? - PhoneLoader.registerCallObserver(callType, getContext(), - new Loader.OnLoadCompleteListener<Cursor>() { - @Override - public void onLoadComplete(Loader<Cursor> cursorLoader, Cursor cursor) { - // This callback runs on the thread that created the loader which is - // the ui thread so spin off another async task because we still need - // to pull together all the data along with the contact photo. - CallLogListingTask query = new CallLogListingTask.Builder() - .setContext(getContext()) - .setCursor(cursor) - .setResult(result) - .build(); - query.execute(); - } - }); - } + private void loadCallHistoryAsync(final int callType, final int titleResId) { + showLoadingProgressBar(true); + // Warning: much callbackiness! + // First load up the call log cursor using the PhoneLoader so that happens in a + // background thread. TODO: Why isn't PhoneLoader using a LoaderManager? + PhoneLoader.registerCallObserver(callType, this, + (loader, data) -> { + // This callback runs on the thread that created the loader which is + // the ui thread so spin off another async task because we still need + // to pull together all the data along with the contact photo. + CallLogListingTask task = new CallLogListingTask(TelecomActivity.this, data, + (items) -> { + showLoadingProgressBar(false); + CarDrawerAdapter adapter = items.size() > 0 + ? new CallLogAdapter(titleResId, items) + : new CarDrawerEmptyAdapter(TelecomActivity.this, titleResId); + switchToAdapter(adapter); + }); + task.execute(); + }); } } diff --git a/src/com/android/car/dialer/TelecomProxyActivity.java b/src/com/android/car/dialer/TelecomProxyActivity.java deleted file mode 100644 index aa0f9e25..00000000 --- a/src/com/android/car/dialer/TelecomProxyActivity.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.car.dialer; - -import android.support.car.app.CarProxyActivity; - - -public class TelecomProxyActivity extends CarProxyActivity { - - public TelecomProxyActivity() { - super(TelecomActivity.class); - } -} |