2 * Copyright (C) 2010 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.internal.policy.impl;
19 import android.content.Context;
20 import android.graphics.Canvas;
21 import android.graphics.Rect;
22 import android.graphics.drawable.Drawable;
23 import android.util.AttributeSet;
24 import android.util.Log;
25 import android.view.Gravity;
26 import android.view.View;
27 import android.widget.LinearLayout;
30 * A vertical linear layout. However, instead of drawing the background
31 * behnd the items, it draws the background outside the items based on the
32 * padding. If there isn't enough room to draw both, it clips the background
33 * instead of the contents.
35 public class RecentApplicationsBackground extends LinearLayout {
36 private static final String TAG = "RecentApplicationsBackground";
38 private boolean mBackgroundSizeChanged;
39 private Drawable mBackground;
40 private Rect mTmp0 = new Rect();
41 private Rect mTmp1 = new Rect();
43 public RecentApplicationsBackground(Context context) {
48 public RecentApplicationsBackground(Context context, AttributeSet attrs) {
49 super(context, attrs);
54 mBackground = getBackground();
55 setBackgroundDrawable(null);
56 setPadding(0, 0, 0, 0);
57 setGravity(Gravity.CENTER);
61 protected boolean setFrame(int left, int top, int right, int bottom) {
62 setWillNotDraw(false);
63 if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) {
64 mBackgroundSizeChanged = true;
66 return super.setFrame(left, top, right, bottom);
70 protected boolean verifyDrawable(Drawable who) {
71 return who == mBackground || super.verifyDrawable(who);
75 protected void drawableStateChanged() {
76 Drawable d = mBackground;
77 if (d != null && d.isStateful()) {
78 d.setState(getDrawableState());
80 super.drawableStateChanged();
84 public void draw(Canvas canvas) {
85 final Drawable background = mBackground;
86 if (background != null) {
87 if (mBackgroundSizeChanged) {
88 mBackgroundSizeChanged = false;
91 mBackground.getPadding(bkg);
93 // This doesn't clamp to this view's bounds, which is what we want,
94 // so that the drawing is clipped.
95 final int top = chld.top - bkg.top;
96 final int bottom = chld.bottom + bkg.bottom;
97 // The background here is a gradient that wants to
98 // extend the full width of the screen (whatever that
102 // This limits the width of the drawable.
103 left = chld.left - bkg.left;
104 right = chld.right + bkg.right;
106 // This expands it to full width.
110 background.setBounds(left, top, right, bottom);
113 mBackground.draw(canvas);
116 android.graphics.Paint p = new android.graphics.Paint();
117 p.setColor(0x88ffff00);
118 canvas.drawRect(background.getBounds(), p);
120 canvas.drawARGB((int)(0.75*0xff), 0, 0, 0);
126 protected void onAttachedToWindow() {
127 super.onAttachedToWindow();
128 mBackground.setCallback(this);
129 setWillNotDraw(false);
133 protected void onDetachedFromWindow() {
134 super.onDetachedFromWindow();
135 mBackground.setCallback(null);
138 private void getChildBounds(Rect r) {
139 r.left = r.top = Integer.MAX_VALUE;
140 r.bottom = r.right = Integer.MIN_VALUE;
141 final int N = getChildCount();
142 for (int i=0; i<N; i++) {
143 View v = getChildAt(i);
144 if (v.getVisibility() == View.VISIBLE) {
145 r.left = Math.min(r.left, v.getLeft());
146 r.top = Math.min(r.top, v.getTop());
147 r.right = Math.max(r.right, v.getRight());
148 r.bottom = Math.max(r.bottom, v.getBottom());