blob: b0288dc9b6a842a1adc9fa0bb63df46395d9226e [file] [log] [blame]
Winson Chungb3347bb2010-08-19 14:51:28 -07001/*
2 * Copyright (C) 2010 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
Winson Chungcd4bc492010-12-09 18:52:32 -080019import android.animation.ObjectAnimator;
Winson Chungb3347bb2010-08-19 14:51:28 -070020import android.content.Context;
Winson Chung59e1f9a2010-12-21 11:31:54 -080021import android.content.res.Resources;
Winson Chungb3347bb2010-08-19 14:51:28 -070022import android.graphics.Bitmap;
Winson Chungb3347bb2010-08-19 14:51:28 -070023import android.graphics.Canvas;
Winson Chungb3347bb2010-08-19 14:51:28 -070024import android.graphics.Paint;
Winson Chungb3347bb2010-08-19 14:51:28 -070025import android.util.AttributeSet;
Michael Jurka4c4c0012011-11-15 13:59:13 -080026import android.widget.TextView;
Winson Chungc84001e2010-11-09 12:20:57 -080027
Winson Chung63257c12011-05-05 17:06:13 -070028import com.android.launcher.R;
Winson Chung241c3b42010-08-25 16:53:03 -070029
Winson Chungb3347bb2010-08-19 14:51:28 -070030/**
31 * An icon on a PagedView, specifically for items in the launcher's paged view (with compound
32 * drawables on the top).
33 */
Michael Jurka82369a12012-01-12 08:08:38 -080034public class PagedViewIcon extends TextView {
Winson Chungb3347bb2010-08-19 14:51:28 -070035 private static final String TAG = "PagedViewIcon";
36
Michael Jurka0620bec2010-10-25 17:50:09 -070037 private Bitmap mIcon;
Winson Chungb3347bb2010-08-19 14:51:28 -070038
Winson Chungb3347bb2010-08-19 14:51:28 -070039 public PagedViewIcon(Context context) {
40 this(context, null);
41 }
42
43 public PagedViewIcon(Context context, AttributeSet attrs) {
44 this(context, attrs, 0);
45 }
46
47 public PagedViewIcon(Context context, AttributeSet attrs, int defStyle) {
48 super(context, attrs, defStyle);
Michael Jurka8245a862011-02-01 17:53:59 -080049 }
50
Michael Jurka82369a12012-01-12 08:08:38 -080051 public void applyFromApplicationInfo(ApplicationInfo info, boolean scaleUp) {
Michael Jurkac9a96192010-11-01 11:52:08 -070052 mIcon = info.iconBitmap;
Michael Jurka0620bec2010-10-25 17:50:09 -070053 setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null);
Winson Chung241c3b42010-08-25 16:53:03 -070054 setText(info.title);
55 setTag(info);
56 }
Michael Jurkae3517d02012-01-12 07:46:24 -080057
58 protected void drawableStateChanged() {
59 if (isPressed()) {
60 if (getAlpha() != 0.5f) {
61 setAlpha(0.5f);
62 }
63 } else {
64 if (getAlpha() != 1f) {
65 setAlpha(1f);
66 }
67 }
68 super.drawableStateChanged();
69 }
Winson Chungb3347bb2010-08-19 14:51:28 -070070}