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