2 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.cyanogenmod.eleven.widgets;
18 import android.content.Context;
19 import android.graphics.Bitmap;
20 import android.graphics.Color;
21 import android.graphics.drawable.BitmapDrawable;
22 import android.graphics.drawable.TransitionDrawable;
23 import android.util.AttributeSet;
24 import android.view.View;
25 import android.widget.FrameLayout;
26 import android.widget.ImageView;
28 import com.cyanogenmod.eleven.R;
29 import com.cyanogenmod.eleven.cache.ImageFetcher;
30 import com.cyanogenmod.eleven.cache.ImageWorker;
32 public class BlurScrimImage extends FrameLayout {
33 private ImageView mImageView;
34 private View mBlurScrim;
36 private boolean mUsingDefaultBlur;
38 public BlurScrimImage(Context context, AttributeSet attrs) {
39 super(context, attrs);
41 mUsingDefaultBlur = true;
45 protected void onFinishInflate() {
46 super.onFinishInflate();
48 mImageView = (ImageView)findViewById(R.id.blurImage);
49 mBlurScrim = findViewById(R.id.blurScrim);
52 public ImageView getImageView() {
57 * Transitions the image to the default state (default blur artwork)
59 public void transitionToDefaultState() {
60 // if we are already showing the default blur and we are transitioning to the default blur
61 // then don't do the transition at all
62 if (mUsingDefaultBlur) {
66 Bitmap blurredBitmap = ((BitmapDrawable) getResources()
67 .getDrawable(R.drawable.default_artwork_blur)).getBitmap();
69 TransitionDrawable imageTransition = ImageWorker.createImageTransitionDrawable(getResources(),
70 mImageView.getDrawable(), blurredBitmap, ImageWorker.FADE_IN_TIME_SLOW, true, true);
72 TransitionDrawable paletteTransition = ImageWorker.createPaletteTransition(this,
76 setTransitionDrawable(imageTransition, paletteTransition);
77 mUsingDefaultBlur = true;
81 * Sets the transition drawable
82 * @param imageTransition the transition for the imageview
83 * @param paletteTransition the transition for the scrim overlay
85 public void setTransitionDrawable(TransitionDrawable imageTransition,
86 TransitionDrawable paletteTransition) {
87 mBlurScrim.setBackground(paletteTransition);
88 mImageView.setImageDrawable(imageTransition);
89 mUsingDefaultBlur = false;
93 * Loads the current artwork into this BlurScrimImage
94 * @param imageFetcher an ImageFetcher instance
96 public void loadBlurImage(ImageFetcher imageFetcher) {
97 imageFetcher.loadCurrentBlurredArtwork(this);