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