blob: 0fe84e731897b9b39f0d6a90a46291bac78d475e [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;
Joe Onoratobe386092009-11-17 17:32:16 -080024import android.util.Log;
25
26import java.util.ArrayList;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027
28/**
29 * Represents a launchable application. An application is made of a name (or title),
30 * an intent and an icon.
31 */
32class ApplicationInfo extends ItemInfo {
33
34 /**
35 * The application name.
36 */
37 CharSequence title;
38
39 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040040 * A bitmap of the application's text in the bubble.
41 */
42 Bitmap titleBitmap;
43
44 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045 * The intent used to start the application.
46 */
47 Intent intent;
48
49 /**
50 * The application icon.
51 */
52 Drawable icon;
53
54 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040055 * A bitmap version of the application icon.
56 */
57 Bitmap iconBitmap;
58
59 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060 * 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 Guy73b979d2009-06-09 12:57:21 -070077 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078 }
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 Guy73b979d2009-06-09 12:57:21 -070096 * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097 *
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 Guy73b979d2009-06-09 12:57:21 -0700106 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107 }
108
109 @Override
110 void onAddToDatabase(ContentValues values) {
111 super.onAddToDatabase(values);
112
113 String titleStr = title != null ? title.toString() : null;
Romain Guy73b979d2009-06-09 12:57:21 -0700114 values.put(LauncherSettings.BaseLauncherColumns.TITLE, titleStr);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115
Romain Guy1ce1a242009-06-23 17:34:54 -0700116 String uri = intent != null ? intent.toUri(0) : null;
Romain Guy73b979d2009-06-09 12:57:21 -0700117 values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800118
119 if (customIcon) {
Romain Guy73b979d2009-06-09 12:57:21 -0700120 values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
121 LauncherSettings.BaseLauncherColumns.ICON_TYPE_BITMAP);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122 Bitmap bitmap = ((FastBitmapDrawable) icon).getBitmap();
123 writeBitmap(values, bitmap);
124 } else {
Romain Guy73b979d2009-06-09 12:57:21 -0700125 values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
126 LauncherSettings.BaseLauncherColumns.ICON_TYPE_RESOURCE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 if (iconResource != null) {
Romain Guy73b979d2009-06-09 12:57:21 -0700128 values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE,
129 iconResource.packageName);
130 values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE,
131 iconResource.resourceName);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132 }
133 }
134 }
135
136 @Override
137 public String toString() {
138 return title.toString();
139 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400140
141 @Override
142 void unbind() {
143 super.unbind();
144 icon.setCallback(null);
145 }
Joe Onoratobe386092009-11-17 17:32:16 -0800146
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 Project31dd5032009-03-03 19:32:27 -0800157}