blob: 498730fdbb20667e920619cdefeda6b10ddcdaea [file] [log] [blame]
Winson Chung604f6df2012-01-12 14:37:57 -08001/*
2 * Copyright (C) 2012 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;
20import android.content.res.TypedArray;
21import android.graphics.Canvas;
22import android.graphics.drawable.Drawable;
23import android.graphics.drawable.StateListDrawable;
24import android.util.AttributeSet;
25import android.view.View;
26import android.widget.ImageView;
27import android.widget.LinearLayout;
28
29import com.android.launcher.R;
30
31public class DrawableStateProxyView extends LinearLayout {
32
33 private View mView;
34 private int mViewId;
35
36 public DrawableStateProxyView(Context context) {
37 this(context, null);
38 }
39
40 public DrawableStateProxyView(Context context, AttributeSet attrs) {
41 this(context, attrs, 0);
42 }
43
44 public DrawableStateProxyView(Context context, AttributeSet attrs, int defStyle) {
45 super(context, attrs, defStyle);
46
47 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawableStateProxyView,
48 defStyle, 0);
49 mViewId = a.getResourceId(R.styleable.DrawableStateProxyView_sourceViewId, -1);
50 a.recycle();
51
52 setFocusable(false);
53 }
54
55 @Override
56 protected void drawableStateChanged() {
57 super.drawableStateChanged();
58
59 if (mView == null) {
60 View parent = (View) getParent();
61 mView = parent.findViewById(mViewId);
62 }
63 mView.setPressed(isPressed());
64 mView.setHovered(isHovered());
65 }
66}