Skip to content

Commit

Permalink
Set incall button color to match sim color.
Browse files Browse the repository at this point in the history
This change also add a handy adb command script run before UI integration test.

Bug: 67429956
Test: IncallActivityTest
PiperOrigin-RevId: 173565382
Change-Id: I9b8b957f00a0b7d11dbb7f40e8c9f1dbdb8c3928
  • Loading branch information
wangqi authored and Eric Erfanian committed Oct 26, 2017
1 parent 9b99b22 commit 8d662ca
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 14 deletions.
4 changes: 4 additions & 0 deletions common_fixture_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file runs before emulator integration tests .
# It utilizes adb shell commands to prepare test environment.

setprop log.tag.Dialer VERBOSE
4 changes: 2 additions & 2 deletions java/com/android/incallui/CallButtonPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ private void updateUi(InCallState state, DialerCall call) {
}

if (call != null) {
mInCallButtonUi.updateInCallButtonUiColors();
mInCallButtonUi.updateInCallButtonUiColors(
InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor());
}

final boolean isEnabled =
Expand Down Expand Up @@ -559,5 +560,4 @@ private InCallActivity getActivity() {
}
return null;
}

}
11 changes: 9 additions & 2 deletions java/com/android/incallui/InCallPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,10 @@ public void setUp(
mProximitySensor = proximitySensor;
addListener(mProximitySensor);

mThemeColorManager =
new ThemeColorManager(new InCallUIMaterialColorMapUtils(mContext.getResources()));
if (mThemeColorManager == null) {
mThemeColorManager =
new ThemeColorManager(new InCallUIMaterialColorMapUtils(mContext.getResources()));
}

mCallList = callList;
mExternalCallList = externalCallList;
Expand Down Expand Up @@ -1651,6 +1653,11 @@ public ThemeColorManager getThemeColorManager() {
return mThemeColorManager;
}

@VisibleForTesting
public void setThemeColorManager(ThemeColorManager themeColorManager) {
mThemeColorManager = themeColorManager;
}

/** Called when the foreground call changes. */
public void onForegroundCallChanged(DialerCall newForegroundCall) {
mThemeColorManager.onForegroundCallChanged(mContext, newForegroundCall);
Expand Down
13 changes: 7 additions & 6 deletions java/com/android/incallui/ThemeColorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ public void setPendingPhoneAccountHandle(@Nullable PhoneAccountHandle pendingPho

public void onForegroundCallChanged(Context context, @Nullable DialerCall newForegroundCall) {
if (newForegroundCall == null) {
updateThemeColors(context, pendingPhoneAccountHandle, false);
updateThemeColors(context, getHighlightColor(context, pendingPhoneAccountHandle), false);
} else {
updateThemeColors(context, newForegroundCall.getAccountHandle(), newForegroundCall.isSpam());
updateThemeColors(
context,
getHighlightColor(context, newForegroundCall.getAccountHandle()),
newForegroundCall.isSpam());
}
}

private void updateThemeColors(
Context context, @Nullable PhoneAccountHandle handle, boolean isSpam) {
private void updateThemeColors(Context context, @ColorInt int highlightColor, boolean isSpam) {
MaterialPalette palette;
if (isSpam) {
palette =
Expand All @@ -74,7 +76,6 @@ private void updateThemeColors(
backgroundColorBottom = context.getColor(R.color.incall_background_gradient_spam_bottom);
backgroundColorSolid = context.getColor(R.color.incall_background_multiwindow_spam);
} else {
@ColorInt int highlightColor = getHighlightColor(context, handle);
palette = colorMap.calculatePrimaryAndSecondaryColor(highlightColor);
backgroundColorTop = context.getColor(R.color.incall_background_gradient_top);
backgroundColorMiddle = context.getColor(R.color.incall_background_gradient_middle);
Expand All @@ -95,7 +96,7 @@ private void updateThemeColors(
}

@ColorInt
private static int getHighlightColor(Context context, @Nullable PhoneAccountHandle handle) {
private int getHighlightColor(Context context, @Nullable PhoneAccountHandle handle) {
if (handle != null) {
PhoneAccount account = context.getSystemService(TelecomManager.class).getPhoneAccount(handle);
if (account != null) {
Expand Down
11 changes: 11 additions & 0 deletions java/com/android/incallui/incall/impl/CheckableLabeledButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import android.animation.AnimatorInflater;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.text.TextUtils.TruncateAt;
Expand Down Expand Up @@ -88,6 +91,7 @@ private void init(Context context, AttributeSet attrs) {
iconView.setImageDrawable(icon);
iconView.setImageTintMode(Mode.SRC_IN);
iconView.setImageTintList(getResources().getColorStateList(R.color.incall_button_icon, null));

iconView.setBackground(getResources().getDrawable(R.drawable.incall_button_background, null));
iconView.setDuplicateParentStateEnabled(true);
iconView.setElevation(getResources().getDimension(R.dimen.incall_button_elevation));
Expand Down Expand Up @@ -124,6 +128,13 @@ public void refreshDrawableState() {
labelView.setAlpha(isEnabled() ? 1f : DISABLED_STATE_OPACITY);
}

public void setCheckedColor(@ColorInt int color) {
iconView.setImageTintList(
new ColorStateList(
new int[][] {new int[] {android.R.attr.state_checked}, new int[] {}},
new int[] {color, Color.WHITE}));
}

public void setIconDrawable(@DrawableRes int drawableRes) {
iconView.setImageResource(drawableRes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.android.incallui.incall.impl;

import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.ArraySet;
Expand Down Expand Up @@ -127,6 +128,12 @@ public int updateButtonStates(
return numVisibleButtons;
}

public void updateButtonColor(@ColorInt int color) {
for (CheckableLabeledButton button : buttons) {
button.setCheckedColor(color);
}
}

/** Interface to let the listener know the status of the button grid. */
public interface OnButtonGridCreatedListener {
void onButtonGridCreated(InCallButtonGridFragment inCallButtonGridFragment);
Expand Down
5 changes: 4 additions & 1 deletion java/com/android/incallui/incall/impl/InCallFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
Expand Down Expand Up @@ -476,7 +477,9 @@ && getResources().getInteger(R.integer.incall_num_rows) > 1) {
}

@Override
public void updateInCallButtonUiColors() {}
public void updateInCallButtonUiColors(@ColorInt int color) {
inCallButtonGridFragment.updateButtonColor(color);
}

@Override
public Fragment getInCallButtonUiFragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.android.incallui.incall.protocol;

import android.support.annotation.ColorInt;
import android.support.v4.app.Fragment;
import android.telecom.CallAudioState;

Expand All @@ -42,7 +43,7 @@ public interface InCallButtonUi {
*/
void updateButtonStates();

void updateInCallButtonUiColors();
void updateInCallButtonUiColors(@ColorInt int color);

Fragment getInCallButtonUiFragment();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.graphics.Point;
import android.graphics.drawable.Animatable;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
Expand Down Expand Up @@ -804,7 +805,7 @@ public void updateButtonStates() {
}

@Override
public void updateInCallButtonUiColors() {}
public void updateInCallButtonUiColors(@ColorInt int color) {}

@Override
public Fragment getInCallButtonUiFragment() {
Expand Down
3 changes: 2 additions & 1 deletion java/com/android/incallui/video/impl/VideoCallFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
Expand Down Expand Up @@ -845,7 +846,7 @@ public void updateButtonStates() {
}

@Override
public void updateInCallButtonUiColors() {}
public void updateInCallButtonUiColors(@ColorInt int color) {}

@Override
public Fragment getInCallButtonUiFragment() {
Expand Down

0 comments on commit 8d662ca

Please sign in to comment.