ApplicationInfo.java revision be38609f875f9b9374ceaf723135c0a624637fcb
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 17package com.android.launcher2; 18 19import android.content.ComponentName; 20import android.content.ContentValues; 21import android.content.Intent; 22import android.graphics.Bitmap; 23import android.graphics.drawable.Drawable; 24import android.util.Log; 25 26import java.util.ArrayList; 27 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 /** 40 * A bitmap of the application's text in the bubble. 41 */ 42 Bitmap titleBitmap; 43 44 /** 45 * The intent used to start the application. 46 */ 47 Intent intent; 48 49 /** 50 * The application icon. 51 */ 52 Drawable icon; 53 54 /** 55 * A bitmap version of the application icon. 56 */ 57 Bitmap iconBitmap; 58 59 /** 60 * 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() { 77 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; 78 } 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. 96 * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}. 97 * 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); 106 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION; 107 } 108 109 @Override 110 void onAddToDatabase(ContentValues values) { 111 super.onAddToDatabase(values); 112 113 String titleStr = title != null ? title.toString() : null; 114 values.put(LauncherSettings.BaseLauncherColumns.TITLE, titleStr); 115 116 String uri = intent != null ? intent.toUri(0) : null; 117 values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri); 118 119 if (customIcon) { 120 values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE, 121 LauncherSettings.BaseLauncherColumns.ICON_TYPE_BITMAP); 122 Bitmap bitmap = ((FastBitmapDrawable) icon).getBitmap(); 123 writeBitmap(values, bitmap); 124 } else { 125 values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE, 126 LauncherSettings.BaseLauncherColumns.ICON_TYPE_RESOURCE); 127 if (iconResource != null) { 128 values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE, 129 iconResource.packageName); 130 values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE, 131 iconResource.resourceName); 132 } 133 } 134 } 135 136 @Override 137 public String toString() { 138 return title.toString(); 139 } 140 141 @Override 142 void unbind() { 143 super.unbind(); 144 icon.setCallback(null); 145 } 146 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 } 157} 158