blob: a40c727b58afa1d971ca821c79448f53ea259d60 [file] [log] [blame]
Winson Chung7d3810d2011-10-07 13:11:56 -07001/*
2 * Copyright (C) 2011 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
17package com.android.launcher2;
18
19import android.content.Context;
Winson Chung62054222011-11-03 13:12:50 -070020import android.content.res.TypedArray;
Winson Chung7d3810d2011-10-07 13:11:56 -070021import android.graphics.Canvas;
Winson Chung62054222011-11-03 13:12:50 -070022import android.graphics.drawable.Drawable;
23import android.graphics.drawable.StateListDrawable;
Winson Chung7d3810d2011-10-07 13:11:56 -070024import android.util.AttributeSet;
Winson Chung62054222011-11-03 13:12:50 -070025import android.widget.ImageView;
Winson Chung7d3810d2011-10-07 13:11:56 -070026import android.widget.LinearLayout;
27
Winson Chung62054222011-11-03 13:12:50 -070028import com.android.launcher.R;
29
Winson Chung7d3810d2011-10-07 13:11:56 -070030public class HolographicLinearLayout extends LinearLayout {
31
32 private final HolographicViewHelper mHolographicHelper;
Winson Chung62054222011-11-03 13:12:50 -070033 private ImageView mImageView;
34 private int mImageViewId;
Winson Chung7d3810d2011-10-07 13:11:56 -070035
36 public HolographicLinearLayout(Context context) {
37 this(context, null);
38 }
39
40 public HolographicLinearLayout(Context context, AttributeSet attrs) {
41 this(context, attrs, 0);
42 }
43
44 public HolographicLinearLayout(Context context, AttributeSet attrs, int defStyle) {
45 super(context, attrs, defStyle);
46
Winson Chung62054222011-11-03 13:12:50 -070047 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HolographicLinearLayout,
48 defStyle, 0);
49 mImageViewId = a.getResourceId(R.styleable.HolographicLinearLayout_sourceImageViewId, -1);
50 a.recycle();
51
Winson Chung7d3810d2011-10-07 13:11:56 -070052 setWillNotDraw(false);
53 mHolographicHelper = new HolographicViewHelper(context);
54 }
55
56 @Override
Winson Chung62054222011-11-03 13:12:50 -070057 protected void drawableStateChanged() {
58 super.drawableStateChanged();
59
60 if (mImageView != null) {
61 Drawable d = mImageView.getDrawable();
62 if (d instanceof StateListDrawable) {
63 StateListDrawable sld = (StateListDrawable) d;
64 sld.setState(getDrawableState());
65 }
66 }
67 }
68
Winson Chungbb185bd2011-11-21 12:31:42 -080069 void invalidatePressedFocusedStates() {
70 mHolographicHelper.invalidatePressedFocusedStates(mImageView);
71 }
72
Winson Chung62054222011-11-03 13:12:50 -070073 @Override
Winson Chung7d3810d2011-10-07 13:11:56 -070074 protected void onDraw(Canvas canvas) {
75 super.onDraw(canvas);
76
77 // One time call to generate the pressed/focused state -- must be called after
78 // measure/layout
Winson Chung62054222011-11-03 13:12:50 -070079 if (mImageView == null) {
80 mImageView = (ImageView) findViewById(mImageViewId);
81 }
82 mHolographicHelper.generatePressedFocusedStates(mImageView);
Winson Chung7d3810d2011-10-07 13:11:56 -070083 }
84}