Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.launcher2; |
| 18 | |
| 19 | import android.content.Context; |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 20 | import android.graphics.Bitmap; |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Michael Jurka | 4c4c001 | 2011-11-15 13:59:13 -0800 | [diff] [blame] | 22 | import android.widget.TextView; |
Winson Chung | c84001e | 2010-11-09 12:20:57 -0800 | [diff] [blame] | 23 | |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 24 | /** |
| 25 | * An icon on a PagedView, specifically for items in the launcher's paged view (with compound |
| 26 | * drawables on the top). |
| 27 | */ |
Michael Jurka | 82369a1 | 2012-01-12 08:08:38 -0800 | [diff] [blame] | 28 | public class PagedViewIcon extends TextView { |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 29 | private static final String TAG = "PagedViewIcon"; |
| 30 | |
Michael Jurka | 0620bec | 2010-10-25 17:50:09 -0700 | [diff] [blame] | 31 | private Bitmap mIcon; |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 32 | |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 33 | 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 Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Michael Jurka | 82369a1 | 2012-01-12 08:08:38 -0800 | [diff] [blame] | 45 | public void applyFromApplicationInfo(ApplicationInfo info, boolean scaleUp) { |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 46 | mIcon = info.iconBitmap; |
Michael Jurka | 0620bec | 2010-10-25 17:50:09 -0700 | [diff] [blame] | 47 | setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null); |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 48 | setText(info.title); |
| 49 | setTag(info); |
| 50 | } |
Michael Jurka | e3517d0 | 2012-01-12 07:46:24 -0800 | [diff] [blame] | 51 | |
| 52 | protected void drawableStateChanged() { |
Michael Jurka | 621fbe5 | 2012-01-17 06:22:10 -0800 | [diff] [blame] | 53 | setAlpha(isPressed() ? 0.5f : 1f); |
Michael Jurka | e3517d0 | 2012-01-12 07:46:24 -0800 | [diff] [blame] | 54 | super.drawableStateChanged(); |
| 55 | } |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 56 | } |