blob: 548b394588e72b45d798cbb674535683826ec851 [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
19import android.content.Context;
Winson Chungb3347bb2010-08-19 14:51:28 -070020import android.graphics.Bitmap;
Winson Chungb3347bb2010-08-19 14:51:28 -070021import android.util.AttributeSet;
Michael Jurka4c4c0012011-11-15 13:59:13 -080022import android.widget.TextView;
Winson Chungc84001e2010-11-09 12:20:57 -080023
Winson Chungb3347bb2010-08-19 14:51:28 -070024/**
25 * An icon on a PagedView, specifically for items in the launcher's paged view (with compound
26 * drawables on the top).
27 */
Michael Jurka82369a12012-01-12 08:08:38 -080028public class PagedViewIcon extends TextView {
Winson Chungb3347bb2010-08-19 14:51:28 -070029 private static final String TAG = "PagedViewIcon";
30
Michael Jurka0620bec2010-10-25 17:50:09 -070031 private Bitmap mIcon;
Winson Chungb3347bb2010-08-19 14:51:28 -070032
Winson Chungb3347bb2010-08-19 14:51:28 -070033 public PagedViewIcon(Context context) {
34 this(context, null);
35 }
36
37 public PagedViewIcon(Context context, AttributeSet attrs) {
38 this(context, attrs, 0);
39 }
40
41 public PagedViewIcon(Context context, AttributeSet attrs, int defStyle) {
42 super(context, attrs, defStyle);
Michael Jurka8245a862011-02-01 17:53:59 -080043 }
44
Michael Jurka82369a12012-01-12 08:08:38 -080045 public void applyFromApplicationInfo(ApplicationInfo info, boolean scaleUp) {
Michael Jurkac9a96192010-11-01 11:52:08 -070046 mIcon = info.iconBitmap;
Michael Jurka0620bec2010-10-25 17:50:09 -070047 setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null);
Winson Chung241c3b42010-08-25 16:53:03 -070048 setText(info.title);
49 setTag(info);
50 }
Michael Jurkae3517d02012-01-12 07:46:24 -080051
52 protected void drawableStateChanged() {
Michael Jurka621fbe52012-01-17 06:22:10 -080053 setAlpha(isPressed() ? 0.5f : 1f);
Michael Jurkae3517d02012-01-12 07:46:24 -080054 super.drawableStateChanged();
55 }
Winson Chungb3347bb2010-08-19 14:51:28 -070056}