OSDN Git Service

Handle same keyphrase for multiple users
[android-x86/frameworks-base.git] / packages / SystemUI / src / com / android / systemui / recents / views / TaskViewThumbnail.java
1 /*
2  * Copyright (C) 2014 The Android Open Source 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
17 package com.android.systemui.recents.views;
18
19 import android.content.Context;
20 import android.graphics.Bitmap;
21 import android.graphics.Rect;
22 import android.util.AttributeSet;
23 import android.view.View;
24 import com.android.systemui.recents.model.Task;
25
26
27 /** The task thumbnail view */
28 public class TaskViewThumbnail extends FixedSizeImageView {
29
30     // Task bar clipping
31     Rect mClipRect = new Rect();
32
33     public TaskViewThumbnail(Context context) {
34         this(context, null);
35     }
36
37     public TaskViewThumbnail(Context context, AttributeSet attrs) {
38         this(context, attrs, 0);
39     }
40
41     public TaskViewThumbnail(Context context, AttributeSet attrs, int defStyleAttr) {
42         this(context, attrs, defStyleAttr, 0);
43     }
44
45     public TaskViewThumbnail(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
46         super(context, attrs, defStyleAttr, defStyleRes);
47         setScaleType(ScaleType.FIT_XY);
48     }
49
50     /** Updates the clip rect based on the given task bar. */
51     void enableTaskBarClip(View taskBar) {
52         int top = (int) Math.max(0, taskBar.getTranslationY() +
53                 taskBar.getMeasuredHeight() - 1);
54         mClipRect.set(0, top, getMeasuredWidth(), getMeasuredHeight());
55         setClipBounds(mClipRect);
56     }
57
58     /** Convenience method to enable task bar clipping as a runnable. */
59     Runnable enableTaskBarClipAsRunnable(final View taskBar) {
60         return new Runnable() {
61             @Override
62             public void run() {
63                 enableTaskBarClip(taskBar);
64             }
65         };
66     }
67
68     /** Disables the task bar clipping. */
69     Runnable disableTaskBarClipAsRunnable() {
70         return new Runnable() {
71             @Override
72             public void run() {
73                 mClipRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
74                 setClipBounds(mClipRect);
75             }
76         };
77     }
78
79     /** Binds the thumbnail view to the screenshot. */
80     boolean bindToScreenshot(Bitmap ss) {
81         if (ss != null) {
82             setImageBitmap(ss);
83             return true;
84         }
85         return false;
86     }
87
88     /** Unbinds the thumbnail view from the screenshot. */
89     void unbindFromScreenshot() {
90         setImageBitmap(null);
91     }
92
93     /** Binds the thumbnail view to the task */
94     void rebindToTask(Task t) {
95         if (t.thumbnail != null) {
96             setImageBitmap(t.thumbnail);
97         }
98     }
99
100     /** Unbinds the thumbnail view from the task */
101     void unbindFromTask() {
102         setImageDrawable(null);
103     }
104 }