Search in sources :

Example 1 with MaterialPalette

use of com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette in project android_packages_apps_Dialer by LineageOS.

the class ThemeColorManager method updateThemeColors.

private void updateThemeColors(Context context, @Nullable PhoneAccountHandle handle, boolean isSpam) {
    MaterialPalette palette;
    if (isSpam) {
        palette = colorMap.calculatePrimaryAndSecondaryColor(R.color.incall_call_spam_background_color);
        backgroundColorTop = context.getColor(R.color.incall_background_gradient_spam_top);
        backgroundColorMiddle = context.getColor(R.color.incall_background_gradient_spam_middle);
        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);
        backgroundColorBottom = context.getColor(R.color.incall_background_gradient_bottom);
        backgroundColorSolid = context.getColor(R.color.incall_background_multiwindow);
        if (highlightColor != PhoneAccount.NO_HIGHLIGHT_COLOR) {
            // The default background gradient has a subtle alpha. We grab that alpha and apply it to
            // the phone account color.
            backgroundColorTop = applyAlpha(palette.mPrimaryColor, backgroundColorTop);
            backgroundColorMiddle = applyAlpha(palette.mPrimaryColor, backgroundColorMiddle);
            backgroundColorBottom = applyAlpha(palette.mPrimaryColor, backgroundColorBottom);
            backgroundColorSolid = applyAlpha(palette.mPrimaryColor, backgroundColorSolid);
        }
    }
    primaryColor = palette.mPrimaryColor;
    secondaryColor = palette.mSecondaryColor;
}
Also used : ColorInt(android.support.annotation.ColorInt) MaterialPalette(com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette)

Example 2 with MaterialPalette

use of com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette in project packages_apps_Contacts by AOKP.

the class QuickContactActivity method extractAndApplyTintFromPhotoViewAsynchronously.

/**
 * Asynchronously extract the most vibrant color from the PhotoView. Once extracted,
 * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms
 * on a Nexus 5.
 */
private void extractAndApplyTintFromPhotoViewAsynchronously() {
    if (mScroller == null) {
        return;
    }
    final Drawable imageViewDrawable = mPhotoView.getDrawable();
    new AsyncTask<Void, Void, MaterialPalette>() {

        @Override
        protected MaterialPalette doInBackground(Void... params) {
            if (imageViewDrawable instanceof BitmapDrawable && mContactData != null && mContactData.getThumbnailPhotoBinaryData() != null && mContactData.getThumbnailPhotoBinaryData().length > 0) {
                // Perform the color analysis on the thumbnail instead of the full sized
                // image, so that our results will be as similar as possible to the Bugle
                // app.
                final Bitmap bitmap = BitmapFactory.decodeByteArray(mContactData.getThumbnailPhotoBinaryData(), 0, mContactData.getThumbnailPhotoBinaryData().length);
                try {
                    final int primaryColor = colorFromBitmap(bitmap);
                    if (primaryColor != 0) {
                        return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor);
                    }
                } finally {
                    bitmap.recycle();
                }
            }
            if (imageViewDrawable instanceof LetterTileDrawable) {
                final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor();
                return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor);
            }
            return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources());
        }

        @Override
        protected void onPostExecute(MaterialPalette palette) {
            super.onPostExecute(palette);
            if (mHasComputedThemeColor) {
                // a rotation or onNewIntent() is perfectly fine.
                return;
            }
            // color needs to be extracted
            if (imageViewDrawable == mPhotoView.getDrawable()) {
                mHasComputedThemeColor = true;
                setThemeColor(palette);
                // update color and photo in suggestion card
                onAggregationSuggestionChange();
            }
        }
    }.execute();
}
Also used : Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable) LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) MaterialPalette(com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette)

Example 3 with MaterialPalette

use of com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette in project android_packages_apps_Dialer by MoKee.

the class CallCardFragment method setCallState.

@Override
public void setCallState(int state, int videoState, int sessionModificationState, DisconnectCause disconnectCause, String connectionLabel, Drawable callStateIcon, String gatewayNumber, boolean isWifi, boolean isConference, boolean isWaitingForRemoteSide, boolean isWorkCall) {
    boolean isGatewayCall = !TextUtils.isEmpty(gatewayNumber);
    CallStateLabel callStateLabel = getCallStateLabelFromState(state, videoState, sessionModificationState, disconnectCause, connectionLabel, isGatewayCall, isWifi, isConference, isWaitingForRemoteSide, isWorkCall);
    Log.v(this, "setCallState " + callStateLabel.getCallStateLabel());
    Log.v(this, "AutoDismiss " + callStateLabel.isAutoDismissing());
    Log.v(this, "DisconnectCause " + disconnectCause.toString());
    Log.v(this, "gateway " + connectionLabel + gatewayNumber);
    // Check for video state change and update the visibility of the contact photo.  The contact
    // photo is hidden when the incoming video surface is shown.
    // The contact photo visibility can also change in setPrimary().
    boolean showContactPhoto = !VideoCallPresenter.showIncomingVideo(videoState, state);
    mPhotoLarge.setVisibility(showContactPhoto ? View.VISIBLE : View.GONE);
    // Check if the call subject is showing -- if it is, we want to bypass showing the call
    // state.
    boolean isSubjectShowing = mCallSubject.getVisibility() == View.VISIBLE;
    boolean isSubChanged = (callStateIcon != mCallStateIcon.getDrawable());
    if (TextUtils.equals(callStateLabel.getCallStateLabel(), mCallStateLabel.getText()) && !isSubjectShowing && !isSubChanged) {
        // Nothing to do if the labels are the same
        if (state == Call.State.ACTIVE || state == Call.State.CONFERENCED) {
            mCallStateLabel.clearAnimation();
            mCallStateIcon.clearAnimation();
        }
        return;
    }
    if (isSubjectShowing) {
        changeCallStateLabel(null);
        callStateIcon = null;
    } else {
        // Update the call state label and icon.
        setCallStateLabel(callStateLabel);
    }
    if (!TextUtils.isEmpty(callStateLabel.getCallStateLabel())) {
        if (state == Call.State.ACTIVE || state == Call.State.CONFERENCED) {
            mCallStateLabel.clearAnimation();
        } else {
            mCallStateLabel.startAnimation(mPulseAnimation);
        }
    } else {
        mCallStateLabel.clearAnimation();
    }
    if (callStateIcon != null) {
        mCallStateIcon.setVisibility(View.VISIBLE);
        // Invoke setAlpha(float) instead of setAlpha(int) to set the view's alpha. This is
        // needed because the pulse animation operates on the view alpha.
        mCallStateIcon.setAlpha(1.0f);
        mCallStateIcon.setImageDrawable(callStateIcon);
        MaterialPalette themeColors = InCallPresenter.getInstance().getThemeColors();
        if (themeColors != null) {
            // Change the alpha value in the 32 bit color of sim card, because the color of
            // call background changed with the color of sim card.
            // Set the tint mode to SCREEN to avoid the slot number in the sim icon to be
            // covered.
            int stateIconColor = (themeColors.mPrimaryColor & 0x00ffffff) | 0x7f000000;
            mCallStateIcon.setImageTintMode(PorterDuff.Mode.SCREEN);
            mCallStateIcon.setImageTintList(ColorStateList.valueOf(stateIconColor));
            Log.d(this, "Set tint of call state icon to " + stateIconColor);
        }
        if (state == Call.State.ACTIVE || state == Call.State.CONFERENCED || TextUtils.isEmpty(callStateLabel.getCallStateLabel())) {
            mCallStateIcon.clearAnimation();
        } else {
            mCallStateIcon.startAnimation(mPulseAnimation);
        }
        if (callStateIcon instanceof AnimationDrawable) {
            ((AnimationDrawable) callStateIcon).start();
        }
        if (isSubChanged) {
            updateColors();
        }
    } else {
        mCallStateIcon.clearAnimation();
        // Invoke setAlpha(float) instead of setAlpha(int) to set the view's alpha. This is
        // needed because the pulse animation operates on the view alpha.
        mCallStateIcon.setAlpha(0.0f);
        mCallStateIcon.setVisibility(View.GONE);
    }
    mCallStateIcon.requestLayout();
    if (VideoUtils.isVideoCall(videoState) || (state == Call.State.ACTIVE && sessionModificationState == Call.SessionModificationState.WAITING_FOR_RESPONSE)) {
        mCallStateVideoCallIcon.setVisibility(View.VISIBLE);
    } else {
        mCallStateVideoCallIcon.setVisibility(View.GONE);
    }
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) MaterialPalette(com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette)

Example 4 with MaterialPalette

use of com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette in project android_packages_apps_Dialer by MoKee.

the class CallCardFragment method updateColors.

/**
 * Get the overall InCallUI background colors and apply to call card.
 */
public void updateColors() {
    MaterialPalette themeColors = InCallPresenter.getInstance().getThemeColors();
    if (mCurrentThemeColors != null && mCurrentThemeColors.equals(themeColors)) {
        return;
    }
    if (getResources().getBoolean(R.bool.is_layout_landscape)) {
        final GradientDrawable drawable = (GradientDrawable) mPrimaryCallCardContainer.getBackground();
        drawable.setColor(themeColors.mPrimaryColor);
    } else {
        mPrimaryCallCardContainer.setBackgroundColor(themeColors.mPrimaryColor);
    }
    mCallButtonsContainer.setBackgroundColor(themeColors.mPrimaryColor);
    mCallSubject.setTextColor(themeColors.mPrimaryColor);
    mContactContext.setBackgroundColor(themeColors.mPrimaryColor);
    // TODO: set color of message text in call context "recent messages" to be the theme color.
    mCurrentThemeColors = themeColors;
}
Also used : GradientDrawable(android.graphics.drawable.GradientDrawable) MaterialPalette(com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette)

Example 5 with MaterialPalette

use of com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette in project android_packages_apps_Dialer by MoKee.

the class CallButtonFragment method updateColors.

public void updateColors() {
    MaterialPalette themeColors = InCallPresenter.getInstance().getThemeColors();
    if (mCurrentThemeColors != null && mCurrentThemeColors.equals(themeColors)) {
        return;
    }
    CompoundButton[] compoundButtons = { mAudioButton, mMuteButton, mShowDialpadButton, mHoldButton, mSwitchCameraButton, mPauseVideoButton, mCallRecordButton };
    for (CompoundButton button : compoundButtons) {
        // Before applying background color, uncheck the button and re apply the
        // saved checked state after background is changed. This is to fix
        // an issue where button checked state is displayed wrongly after updating colors.
        boolean isChecked = button.isChecked();
        if (isChecked)
            Log.d(this, "updateColors: button:" + button + " is in checked state");
        button.setChecked(false);
        final LayerDrawable layers = (LayerDrawable) button.getBackground();
        final RippleDrawable btnCompoundDrawable = compoundBackgroundDrawable(themeColors);
        layers.setDrawableByLayerId(R.id.compoundBackgroundItem, btnCompoundDrawable);
        button.setChecked(isChecked);
        button.requestLayout();
    }
    ImageButton[] normalButtons = { mSwapButton, mChangeToVideoButton, mChangeToVoiceButton, mAddCallButton, mMergeButton, mBlindTransferButton, mAssuredTransferButton, mConsultativeTransferButton, mOverflowButton };
    for (ImageButton button : normalButtons) {
        final LayerDrawable layers = (LayerDrawable) button.getBackground();
        final RippleDrawable btnDrawable = backgroundDrawable(themeColors);
        layers.setDrawableByLayerId(R.id.backgroundItem, btnDrawable);
        button.requestLayout();
    }
    mCurrentThemeColors = themeColors;
}
Also used : ImageButton(android.widget.ImageButton) LayerDrawable(android.graphics.drawable.LayerDrawable) CompoundButton(android.widget.CompoundButton) MaterialPalette(com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette) RippleDrawable(android.graphics.drawable.RippleDrawable)

Aggregations

MaterialPalette (com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette)5 Bitmap (android.graphics.Bitmap)1 AnimationDrawable (android.graphics.drawable.AnimationDrawable)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1 RippleDrawable (android.graphics.drawable.RippleDrawable)1 ColorInt (android.support.annotation.ColorInt)1 CompoundButton (android.widget.CompoundButton)1 ImageButton (android.widget.ImageButton)1 LetterTileDrawable (com.android.contacts.common.lettertiles.LetterTileDrawable)1