The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.ContentValues; |
| 21 | import android.content.Intent; |
| 22 | import android.graphics.Bitmap; |
| 23 | import android.graphics.drawable.Drawable; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame^] | 24 | import android.util.Log; |
| 25 | |
| 26 | import java.util.ArrayList; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Represents a launchable application. An application is made of a name (or title), |
| 30 | * an intent and an icon. |
| 31 | */ |
| 32 | class ApplicationInfo extends ItemInfo { |
| 33 | |
| 34 | /** |
| 35 | * The application name. |
| 36 | */ |
| 37 | CharSequence title; |
| 38 | |
| 39 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 40 | * A bitmap of the application's text in the bubble. |
| 41 | */ |
| 42 | Bitmap titleBitmap; |
| 43 | |
| 44 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 45 | * The intent used to start the application. |
| 46 | */ |
| 47 | Intent intent; |
| 48 | |
| 49 | /** |
| 50 | * The application icon. |
| 51 | */ |
| 52 | Drawable icon; |
| 53 | |
| 54 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 55 | * A bitmap version of the application icon. |
| 56 | */ |
| 57 | Bitmap iconBitmap; |
| 58 | |
| 59 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 60 | * When set to true, indicates that the icon has been resized. |
| 61 | */ |
| 62 | boolean filtered; |
| 63 | |
| 64 | /** |
| 65 | * Indicates whether the icon comes from an application's resource (if false) |
| 66 | * or from a custom Bitmap (if true.) |
| 67 | */ |
| 68 | boolean customIcon; |
| 69 | |
| 70 | /** |
| 71 | * If isShortcut=true and customIcon=false, this contains a reference to the |
| 72 | * shortcut icon as an application's resource. |
| 73 | */ |
| 74 | Intent.ShortcutIconResource iconResource; |
| 75 | |
| 76 | ApplicationInfo() { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 77 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | public ApplicationInfo(ApplicationInfo info) { |
| 81 | super(info); |
| 82 | title = info.title.toString(); |
| 83 | intent = new Intent(info.intent); |
| 84 | if (info.iconResource != null) { |
| 85 | iconResource = new Intent.ShortcutIconResource(); |
| 86 | iconResource.packageName = info.iconResource.packageName; |
| 87 | iconResource.resourceName = info.iconResource.resourceName; |
| 88 | } |
| 89 | icon = info.icon; |
| 90 | filtered = info.filtered; |
| 91 | customIcon = info.customIcon; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Creates the application intent based on a component name and various launch flags. |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 96 | * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 97 | * |
| 98 | * @param className the class name of the component representing the intent |
| 99 | * @param launchFlags the launch flags |
| 100 | */ |
| 101 | final void setActivity(ComponentName className, int launchFlags) { |
| 102 | intent = new Intent(Intent.ACTION_MAIN); |
| 103 | intent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 104 | intent.setComponent(className); |
| 105 | intent.setFlags(launchFlags); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 106 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
| 110 | void onAddToDatabase(ContentValues values) { |
| 111 | super.onAddToDatabase(values); |
| 112 | |
| 113 | String titleStr = title != null ? title.toString() : null; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 114 | values.put(LauncherSettings.BaseLauncherColumns.TITLE, titleStr); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 115 | |
Romain Guy | 1ce1a24 | 2009-06-23 17:34:54 -0700 | [diff] [blame] | 116 | String uri = intent != null ? intent.toUri(0) : null; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 117 | values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 118 | |
| 119 | if (customIcon) { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 120 | values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE, |
| 121 | LauncherSettings.BaseLauncherColumns.ICON_TYPE_BITMAP); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 122 | Bitmap bitmap = ((FastBitmapDrawable) icon).getBitmap(); |
| 123 | writeBitmap(values, bitmap); |
| 124 | } else { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 125 | values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE, |
| 126 | LauncherSettings.BaseLauncherColumns.ICON_TYPE_RESOURCE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 127 | if (iconResource != null) { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 128 | values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE, |
| 129 | iconResource.packageName); |
| 130 | values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE, |
| 131 | iconResource.resourceName); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public String toString() { |
| 138 | return title.toString(); |
| 139 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 140 | |
| 141 | @Override |
| 142 | void unbind() { |
| 143 | super.unbind(); |
| 144 | icon.setCallback(null); |
| 145 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame^] | 146 | |
| 147 | |
| 148 | public static void dumpApplicationInfoList(String tag, String label, |
| 149 | ArrayList<ApplicationInfo> list) { |
| 150 | Log.d(tag, label + " size=" + list.size()); |
| 151 | for (ApplicationInfo info: list) { |
| 152 | Log.d(tag, " title=\"" + info.title + "\" titleBitmap=" + info.titleBitmap |
| 153 | + " icon=" + info.icon + " iconBitmap=" + info.iconBitmap |
| 154 | + " filtered=" + info.filtered + " customIcon=" + info.customIcon); |
| 155 | } |
| 156 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 157 | } |