Example usage for android.animation ArgbEvaluator ArgbEvaluator

List of usage examples for android.animation ArgbEvaluator ArgbEvaluator

Introduction

In this page you can find the example usage for android.animation ArgbEvaluator ArgbEvaluator.

Prototype

ArgbEvaluator

Source Link

Usage

From source file:org.sufficientlysecure.keychain.ui.keyview.ViewKeyActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    /* TODO better error handling? May cause problems when a key is deleted,
     * because the notification triggers faster than the activity closes.
     *///from w  w  w .  java  2 s .c o  m

    // Swap the new cursor in. (The framework will take care of closing the
    // old cursor once we return.)
    switch (loader.getId()) {
    case LOADER_ID_UNIFIED: {
        // Avoid NullPointerExceptions...
        if (data.getCount() == 0) {
            return;
        }

        if (data.moveToFirst()) {
            // get name, email, and comment from USER_ID

            String name = data.getString(INDEX_NAME);

            mCollapsingToolbarLayout.setTitle(name != null ? name : getString(R.string.user_id_no_name));

            mMasterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
            mFingerprint = data.getBlob(INDEX_FINGERPRINT);
            mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
            mHasEncrypt = data.getInt(INDEX_HAS_ENCRYPT) != 0;
            mIsRevoked = data.getInt(INDEX_IS_REVOKED) > 0;
            mIsExpired = data.getInt(INDEX_IS_EXPIRED) != 0;
            mIsSecure = data.getInt(INDEX_IS_SECURE) == 1;
            mIsVerified = data.getInt(INDEX_VERIFIED) > 0;

            // queue showing of the main fragment
            showMainFragment();

            // if the refresh animation isn't playing
            if (!mRotate.hasStarted() && !mRotateSpin.hasStarted()) {
                // re-create options menu based on mIsSecret, mIsVerified
                supportInvalidateOptionsMenu();
                // this is done at the end of the animation otherwise
            }

            AsyncTask<Long, Void, Bitmap> photoTask = new AsyncTask<Long, Void, Bitmap>() {
                protected Bitmap doInBackground(Long... mMasterKeyId) {
                    return new ContactHelper(ViewKeyActivity.this).loadPhotoByMasterKeyId(mMasterKeyId[0],
                            true);
                }

                protected void onPostExecute(Bitmap photo) {
                    if (photo == null) {
                        return;
                    }

                    mPhoto.setImageBitmap(photo);
                    mPhoto.setColorFilter(getResources().getColor(R.color.toolbar_photo_tint),
                            PorterDuff.Mode.SRC_ATOP);
                    mPhotoLayout.setVisibility(View.VISIBLE);
                }
            };

            boolean showStatusText = mIsSecure && !mIsExpired && !mIsRevoked;
            if (showStatusText) {
                mStatusText.setVisibility(View.VISIBLE);

                if (mIsSecret) {
                    mStatusText.setText(R.string.view_key_my_key);
                } else if (mIsVerified) {
                    mStatusText.setText(R.string.view_key_verified);
                } else {
                    mStatusText.setText(R.string.view_key_unverified);
                }
            } else {
                mStatusText.setVisibility(View.GONE);
            }

            // Note: order is important
            int color;
            if (mIsRevoked) {
                mStatusImage.setVisibility(View.VISIBLE);
                KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, State.REVOKED, R.color.icons,
                        true);
                // noinspection deprecation, fix requires api level 23
                color = getResources().getColor(R.color.key_flag_red);

                mActionEncryptFile.setVisibility(View.INVISIBLE);
                mActionEncryptText.setVisibility(View.INVISIBLE);
                hideFab();
                mQrCodeLayout.setVisibility(View.GONE);
            } else if (!mIsSecure) {
                mStatusImage.setVisibility(View.VISIBLE);
                KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, State.INSECURE,
                        R.color.icons, true);
                // noinspection deprecation, fix requires api level 23
                color = getResources().getColor(R.color.key_flag_red);

                mActionEncryptFile.setVisibility(View.INVISIBLE);
                mActionEncryptText.setVisibility(View.INVISIBLE);
                hideFab();
                mQrCodeLayout.setVisibility(View.GONE);
            } else if (mIsExpired) {
                mStatusImage.setVisibility(View.VISIBLE);
                KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, State.EXPIRED, R.color.icons,
                        true);
                // noinspection deprecation, fix requires api level 23
                color = getResources().getColor(R.color.key_flag_red);

                mActionEncryptFile.setVisibility(View.INVISIBLE);
                mActionEncryptText.setVisibility(View.INVISIBLE);
                hideFab();
                mQrCodeLayout.setVisibility(View.GONE);
            } else if (mIsSecret) {
                mStatusImage.setVisibility(View.GONE);
                // noinspection deprecation, fix requires api level 23
                color = getResources().getColor(R.color.key_flag_green);
                // reload qr code only if the fingerprint changed
                if (!Arrays.equals(mFingerprint, mQrCodeLoaded)) {
                    loadQrCode(mFingerprint);
                }
                photoTask.execute(mMasterKeyId);
                mQrCodeLayout.setVisibility(View.VISIBLE);

                // and place leftOf qr code
                //                        RelativeLayout.LayoutParams nameParams = (RelativeLayout.LayoutParams)
                //                                mName.getLayoutParams();
                //                        // remove right margin
                //                        nameParams.setMargins(FormattingUtils.dpToPx(this, 48), 0, 0, 0);
                //                        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                //                            nameParams.setMarginEnd(0);
                //                        }
                //                        nameParams.addRule(RelativeLayout.LEFT_OF, R.id.view_key_qr_code_layout);
                //                        mName.setLayoutParams(nameParams);

                RelativeLayout.LayoutParams statusParams = (RelativeLayout.LayoutParams) mStatusText
                        .getLayoutParams();
                statusParams.setMargins(FormattingUtils.dpToPx(this, 48), 0, 0, 0);
                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    statusParams.setMarginEnd(0);
                }
                statusParams.addRule(RelativeLayout.LEFT_OF, R.id.view_key_qr_code_layout);
                mStatusText.setLayoutParams(statusParams);

                mActionEncryptFile.setVisibility(View.VISIBLE);
                mActionEncryptText.setVisibility(View.VISIBLE);

                showFab();
                // noinspection deprecation (no getDrawable with theme at current minApi level 15!)
                mFab.setImageDrawable(getResources().getDrawable(R.drawable.ic_repeat_white_24dp));
            } else {
                mActionEncryptFile.setVisibility(View.VISIBLE);
                mActionEncryptText.setVisibility(View.VISIBLE);
                mQrCodeLayout.setVisibility(View.GONE);

                if (mIsVerified) {
                    mStatusText.setText(R.string.view_key_verified);
                    mStatusImage.setVisibility(View.VISIBLE);
                    KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, State.VERIFIED,
                            R.color.icons, true);
                    // noinspection deprecation, fix requires api level 23
                    color = getResources().getColor(R.color.key_flag_green);
                    photoTask.execute(mMasterKeyId);

                    hideFab();
                } else {
                    mStatusText.setText(R.string.view_key_unverified);
                    mStatusImage.setVisibility(View.VISIBLE);
                    KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, State.UNVERIFIED,
                            R.color.icons, true);
                    // noinspection deprecation, fix requires api level 23
                    color = getResources().getColor(R.color.key_flag_orange);

                    showFab();
                }
            }

            if (mPreviousColor == 0 || mPreviousColor == color) {
                mAppBarLayout.setBackgroundColor(color);
                mCollapsingToolbarLayout.setContentScrimColor(color);
                mCollapsingToolbarLayout.setStatusBarScrimColor(getStatusBarBackgroundColor(color));
                mPreviousColor = color;
            } else {
                ObjectAnimator colorFade = ObjectAnimator.ofObject(mAppBarLayout, "backgroundColor",
                        new ArgbEvaluator(), mPreviousColor, color);
                mCollapsingToolbarLayout.setContentScrimColor(color);
                mCollapsingToolbarLayout.setStatusBarScrimColor(getStatusBarBackgroundColor(color));

                colorFade.setDuration(1200);
                colorFade.start();
                mPreviousColor = color;
            }

            //noinspection deprecation
            mStatusImage.setAlpha(80);

            break;
        }
    }
    }
}

From source file:com.dish.browser.activity.BrowserActivity.java

private void changeToolbarBackground(Bitmap favicon) {
    Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {
        @Override/*w w w.  j ava2  s .  com*/
        public void onGenerated(Palette palette) {

            // OR with opaque black to remove transparency glitches
            int color = 0xff000000
                    | palette.getVibrantColor(mActivity.getResources().getColor(R.color.primary_color));

            int finalColor; // Lighten up the dark color if it is
            // too dark
            if (isColorTooDark(color)) {
                finalColor = mixTwoColors(mActivity.getResources().getColor(R.color.primary_color), color,
                        0.25f);
            } else {
                finalColor = color;
            }

            ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), mBackground.getColor(),
                    finalColor);

            anim.addUpdateListener(new AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int color = (Integer) animation.getAnimatedValue();
                    mBackground.setColor(color);
                    getWindow().setBackgroundDrawable(mBackground);
                    mToolbarLayout.setBackgroundColor(color);
                }

            });

            anim.setDuration(300);
            anim.start();

        }
    });
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

private void updateStatusBarColor() {
    if (mScroller == null || !CompatUtils.isLollipopCompatible()) {
        return;/*from ww w  . j a  v  a  2 s  . co  m*/
    }
    final int desiredStatusBarColor;
    // Only use a custom status bar color if QuickContacts touches the top of the viewport.
    if (mScroller.getScrollNeededToBeFullScreen() <= 0) {
        desiredStatusBarColor = mStatusBarColor;
    } else {
        desiredStatusBarColor = Color.TRANSPARENT;
    }
    // Animate to the new color.
    final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor",
            getWindow().getStatusBarColor(), desiredStatusBarColor);
    animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION);
    animation.setEvaluator(new ArgbEvaluator());
    animation.start();
}