2 * Copyright (C) 2014 The Android Open Source 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.
17 package com.android.systemui.recents.views;
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;
27 /** The task thumbnail view */
28 public class TaskViewThumbnail extends FixedSizeImageView {
31 Rect mClipRect = new Rect();
33 public TaskViewThumbnail(Context context) {
37 public TaskViewThumbnail(Context context, AttributeSet attrs) {
38 this(context, attrs, 0);
41 public TaskViewThumbnail(Context context, AttributeSet attrs, int defStyleAttr) {
42 this(context, attrs, defStyleAttr, 0);
45 public TaskViewThumbnail(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
46 super(context, attrs, defStyleAttr, defStyleRes);
47 setScaleType(ScaleType.FIT_XY);
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);
58 /** Convenience method to enable task bar clipping as a runnable. */
59 Runnable enableTaskBarClipAsRunnable(final View taskBar) {
60 return new Runnable() {
63 enableTaskBarClip(taskBar);
68 /** Disables the task bar clipping. */
69 Runnable disableTaskBarClipAsRunnable() {
70 return new Runnable() {
73 mClipRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
74 setClipBounds(mClipRect);
79 /** Binds the thumbnail view to the screenshot. */
80 boolean bindToScreenshot(Bitmap ss) {
88 /** Unbinds the thumbnail view from the screenshot. */
89 void unbindFromScreenshot() {
93 /** Binds the thumbnail view to the task */
94 void rebindToTask(Task t) {
95 if (t.thumbnail != null) {
96 setImageBitmap(t.thumbnail);
100 /** Unbinds the thumbnail view from the task */
101 void unbindFromTask() {
102 setImageDrawable(null);