blob: 912f04edcd272bc310297a551bcb355024534e8c [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 /**
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 Guy73b979d2009-06-09 12:57:21 -070064 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065 }
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 Guy73b979d2009-06-09 12:57:21 -070083 * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080084 *
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 Guy73b979d2009-06-09 12:57:21 -070093 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094 }
95
96 @Override
97 void onAddToDatabase(ContentValues values) {
98 super.onAddToDatabase(values);
99
100 String titleStr = title != null ? title.toString() : null;
Romain Guy73b979d2009-06-09 12:57:21 -0700101 values.put(LauncherSettings.BaseLauncherColumns.TITLE, titleStr);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800102
Romain Guy1ce1a242009-06-23 17:34:54 -0700103 String uri = intent != null ? intent.toUri(0) : null;
Romain Guy73b979d2009-06-09 12:57:21 -0700104 values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800105
106 if (customIcon) {
Romain Guy73b979d2009-06-09 12:57:21 -0700107 values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
108 LauncherSettings.BaseLauncherColumns.ICON_TYPE_BITMAP);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800109 Bitmap bitmap = ((FastBitmapDrawable) icon).getBitmap();
110 writeBitmap(values, bitmap);
111 } else {
Romain Guy73b979d2009-06-09 12:57:21 -0700112 values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
113 LauncherSettings.BaseLauncherColumns.ICON_TYPE_RESOURCE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800114 if (iconResource != null) {
Romain Guy73b979d2009-06-09 12:57:21 -0700115 values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE,
116 iconResource.packageName);
117 values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE,
118 iconResource.resourceName);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119 }
120 }
121 }
122
123 @Override
124 public String toString() {
125 return title.toString();
126 }
127}