OSDN Git Service

c5cd9aae222c4e6d066ac57c0c82ba23e16cd8df
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / widgets / BlurScrimImage.java
1 /*
2 * Copyright (C) 2014 The CyanogenMod Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package com.cyanogenmod.eleven.widgets;
17
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;
27
28 import com.cyanogenmod.eleven.R;
29 import com.cyanogenmod.eleven.cache.ImageFetcher;
30 import com.cyanogenmod.eleven.cache.ImageWorker;
31
32 public class BlurScrimImage extends FrameLayout {
33     private ImageView mImageView;
34     private View mBlurScrim;
35
36     private boolean mUsingDefaultBlur;
37
38     public BlurScrimImage(Context context, AttributeSet attrs) {
39         super(context, attrs);
40
41         mUsingDefaultBlur = true;
42     }
43
44     @Override
45     protected void onFinishInflate() {
46         super.onFinishInflate();
47
48         mImageView = (ImageView)findViewById(R.id.blurImage);
49         mBlurScrim = findViewById(R.id.blurScrim);
50     }
51
52     public ImageView getImageView() {
53         return mImageView;
54     }
55
56     /**
57      * Transitions the image to the default state (default blur artwork)
58      */
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) {
63             return;
64         }
65
66         Bitmap blurredBitmap = ((BitmapDrawable) getResources()
67                 .getDrawable(R.drawable.default_artwork_blur)).getBitmap();
68
69         TransitionDrawable imageTransition = ImageWorker.createImageTransitionDrawable(getResources(),
70                 mImageView.getDrawable(), blurredBitmap, ImageWorker.FADE_IN_TIME_SLOW, true, true);
71
72         TransitionDrawable paletteTransition = ImageWorker.createPaletteTransition(this,
73                 Color.TRANSPARENT);
74
75
76         setTransitionDrawable(imageTransition, paletteTransition);
77         mUsingDefaultBlur = true;
78     }
79
80     /**
81      * Sets the transition drawable
82      * @param imageTransition the transition for the imageview
83      * @param paletteTransition the transition for the scrim overlay
84      */
85     public void setTransitionDrawable(TransitionDrawable imageTransition,
86                                TransitionDrawable paletteTransition) {
87         mBlurScrim.setBackground(paletteTransition);
88         mImageView.setImageDrawable(imageTransition);
89         mUsingDefaultBlur = false;
90     }
91
92     /**
93      * Loads the current artwork into this BlurScrimImage
94      * @param imageFetcher an ImageFetcher instance
95      */
96     public void loadBlurImage(ImageFetcher imageFetcher) {
97         imageFetcher.loadCurrentBlurredArtwork(this);
98     }
99 }