blob: db802c7578f7b1490c348db325ed1e4dbfe74a96 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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 Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
19import android.content.ComponentName;
20import android.content.ContentValues;
21import android.content.Intent;
22import android.graphics.Bitmap;
23import 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 */
29class ApplicationInfo extends ItemInfo {
30
31 /**
32 * The application name.
33 */
34 CharSequence title;
35
36 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040037 * A bitmap of the application's text in the bubble.
38 */
39 Bitmap titleBitmap;
40
41 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042 * The intent used to start the application.
43 */
44 Intent intent;
45
46 /**
47 * The application icon.
48 */
49 Drawable icon;
50
51 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040052 * A bitmap version of the application icon.
53 */
54 Bitmap iconBitmap;
55
56 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057 * 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 Guy73b979d2009-06-09 12:57:21 -070074 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075 }
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 Guy73b979d2009-06-09 12:57:21 -070093 * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094 *
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 Guy73b979d2009-06-09 12:57:21 -0700103 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800104 }
105
106 @Override
107 void onAddToDatabase(ContentValues values) {
108 super.onAddToDatabase(values);
109
110 String titleStr = title != null ? title.toString() : null;
Romain Guy73b979d2009-06-09 12:57:21 -0700111 values.put(LauncherSettings.BaseLauncherColumns.TITLE, titleStr);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800112
Romain Guy1ce1a242009-06-23 17:34:54 -0700113 String uri = intent != null ? intent.toUri(0) : null;
Romain Guy73b979d2009-06-09 12:57:21 -0700114 values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115
116 if (customIcon) {
Romain Guy73b979d2009-06-09 12:57:21 -0700117 values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
118 LauncherSettings.BaseLauncherColumns.ICON_TYPE_BITMAP);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119 Bitmap bitmap = ((FastBitmapDrawable) icon).getBitmap();
120 writeBitmap(values, bitmap);
121 } else {
Romain Guy73b979d2009-06-09 12:57:21 -0700122 values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
123 LauncherSettings.BaseLauncherColumns.ICON_TYPE_RESOURCE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124 if (iconResource != null) {
Romain Guy73b979d2009-06-09 12:57:21 -0700125 values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE,
126 iconResource.packageName);
127 values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE,
128 iconResource.resourceName);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129 }
130 }
131 }
132
133 @Override
134 public String toString() {
135 return title.toString();
136 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400137
138 @Override
139 void unbind() {
140 super.unbind();
141 icon.setCallback(null);
142 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143}