2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-30 13:37:37 -07:00
|
|
|
package com.android.launcher2;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
2009-11-17 17:32:16 -08:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents a launchable application. An application is made of a name (or title),
|
|
|
|
|
* an intent and an icon.
|
|
|
|
|
*/
|
|
|
|
|
class ApplicationInfo extends ItemInfo {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The application name.
|
|
|
|
|
*/
|
|
|
|
|
CharSequence title;
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/**
|
|
|
|
|
* A bitmap of the application's text in the bubble.
|
|
|
|
|
*/
|
|
|
|
|
Bitmap titleBitmap;
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* The intent used to start the application.
|
|
|
|
|
*/
|
|
|
|
|
Intent intent;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The application icon.
|
|
|
|
|
*/
|
|
|
|
|
Drawable icon;
|
|
|
|
|
|
2009-08-17 11:03:03 -04:00
|
|
|
/**
|
|
|
|
|
* A bitmap version of the application icon.
|
|
|
|
|
*/
|
|
|
|
|
Bitmap iconBitmap;
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* When set to true, indicates that the icon has been resized.
|
|
|
|
|
*/
|
|
|
|
|
boolean filtered;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates whether the icon comes from an application's resource (if false)
|
|
|
|
|
* or from a custom Bitmap (if true.)
|
|
|
|
|
*/
|
|
|
|
|
boolean customIcon;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If isShortcut=true and customIcon=false, this contains a reference to the
|
|
|
|
|
* shortcut icon as an application's resource.
|
|
|
|
|
*/
|
|
|
|
|
Intent.ShortcutIconResource iconResource;
|
|
|
|
|
|
|
|
|
|
ApplicationInfo() {
|
2009-06-09 12:57:21 -07:00
|
|
|
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ApplicationInfo(ApplicationInfo info) {
|
|
|
|
|
super(info);
|
|
|
|
|
title = info.title.toString();
|
|
|
|
|
intent = new Intent(info.intent);
|
|
|
|
|
if (info.iconResource != null) {
|
|
|
|
|
iconResource = new Intent.ShortcutIconResource();
|
|
|
|
|
iconResource.packageName = info.iconResource.packageName;
|
|
|
|
|
iconResource.resourceName = info.iconResource.resourceName;
|
|
|
|
|
}
|
|
|
|
|
icon = info.icon;
|
|
|
|
|
filtered = info.filtered;
|
|
|
|
|
customIcon = info.customIcon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates the application intent based on a component name and various launch flags.
|
2009-06-09 12:57:21 -07:00
|
|
|
* Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
|
2009-03-03 19:32:27 -08:00
|
|
|
*
|
|
|
|
|
* @param className the class name of the component representing the intent
|
|
|
|
|
* @param launchFlags the launch flags
|
|
|
|
|
*/
|
|
|
|
|
final void setActivity(ComponentName className, int launchFlags) {
|
|
|
|
|
intent = new Intent(Intent.ACTION_MAIN);
|
|
|
|
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
|
|
|
intent.setComponent(className);
|
|
|
|
|
intent.setFlags(launchFlags);
|
2009-06-09 12:57:21 -07:00
|
|
|
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
void onAddToDatabase(ContentValues values) {
|
|
|
|
|
super.onAddToDatabase(values);
|
|
|
|
|
|
|
|
|
|
String titleStr = title != null ? title.toString() : null;
|
2009-06-09 12:57:21 -07:00
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.TITLE, titleStr);
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2009-06-23 17:34:54 -07:00
|
|
|
String uri = intent != null ? intent.toUri(0) : null;
|
2009-06-09 12:57:21 -07:00
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri);
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
if (customIcon) {
|
2009-06-09 12:57:21 -07:00
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
|
|
|
|
|
LauncherSettings.BaseLauncherColumns.ICON_TYPE_BITMAP);
|
2009-03-03 19:32:27 -08:00
|
|
|
Bitmap bitmap = ((FastBitmapDrawable) icon).getBitmap();
|
|
|
|
|
writeBitmap(values, bitmap);
|
|
|
|
|
} else {
|
2009-06-09 12:57:21 -07:00
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
|
|
|
|
|
LauncherSettings.BaseLauncherColumns.ICON_TYPE_RESOURCE);
|
2009-03-03 19:32:27 -08:00
|
|
|
if (iconResource != null) {
|
2009-06-09 12:57:21 -07:00
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE,
|
|
|
|
|
iconResource.packageName);
|
|
|
|
|
values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE,
|
|
|
|
|
iconResource.resourceName);
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
return title.toString();
|
|
|
|
|
}
|
2009-08-17 11:03:03 -04:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
void unbind() {
|
|
|
|
|
super.unbind();
|
|
|
|
|
icon.setCallback(null);
|
|
|
|
|
}
|
2009-11-17 17:32:16 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void dumpApplicationInfoList(String tag, String label,
|
|
|
|
|
ArrayList<ApplicationInfo> list) {
|
|
|
|
|
Log.d(tag, label + " size=" + list.size());
|
|
|
|
|
for (ApplicationInfo info: list) {
|
|
|
|
|
Log.d(tag, " title=\"" + info.title + "\" titleBitmap=" + info.titleBitmap
|
|
|
|
|
+ " icon=" + info.icon + " iconBitmap=" + info.iconBitmap
|
|
|
|
|
+ " filtered=" + info.filtered + " customIcon=" + info.customIcon);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|