blob: 7b00f4fb19ec7e29af4bf8a34b582ad97b2c015e [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
Winson Chungaafa03c2010-06-11 17:34:16 -070019import java.util.ArrayList;
20
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.content.ComponentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080022import android.content.Intent;
Joe Onorato0589f0f2010-02-08 13:44:00 -080023import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024import android.graphics.Bitmap;
Joe Onoratobe386092009-11-17 17:32:16 -080025import android.util.Log;
26
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027/**
Joe Onorato0589f0f2010-02-08 13:44:00 -080028 * Represents an app in AllAppsView.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029 */
30class ApplicationInfo extends ItemInfo {
31
32 /**
33 * The application name.
34 */
35 CharSequence title;
36
37 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040038 * A bitmap of the application's text in the bubble.
39 */
40 Bitmap titleBitmap;
41
42 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043 * The intent used to start the application.
44 */
45 Intent intent;
46
47 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -040048 * A bitmap version of the application icon.
49 */
50 Bitmap iconBitmap;
51
Joe Onorato0589f0f2010-02-08 13:44:00 -080052 ComponentName componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054
55 ApplicationInfo() {
Romain Guy73b979d2009-06-09 12:57:21 -070056 itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080058
59 /**
60 * Must not hold the Context.
61 */
62 public ApplicationInfo(ResolveInfo info, IconCache iconCache) {
63 this.componentName = new ComponentName(
64 info.activityInfo.applicationInfo.packageName,
65 info.activityInfo.name);
66
67 this.container = ItemInfo.NO_ID;
68 this.setActivity(componentName,
69 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
70
71 iconCache.getTitleAndIcon(this, info);
72 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073
74 public ApplicationInfo(ApplicationInfo info) {
75 super(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -080076 componentName = info.componentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077 title = info.title.toString();
78 intent = new Intent(info.intent);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080079 }
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
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097 public String toString() {
Joe Onoratof984e852010-03-25 09:47:45 -070098 return "ApplicationInfo(title=" + title.toString() + ")";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080099 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400100
Joe Onoratobe386092009-11-17 17:32:16 -0800101 public static void dumpApplicationInfoList(String tag, String label,
102 ArrayList<ApplicationInfo> list) {
103 Log.d(tag, label + " size=" + list.size());
104 for (ApplicationInfo info: list) {
105 Log.d(tag, " title=\"" + info.title + "\" titleBitmap=" + info.titleBitmap
Joe Onorato0589f0f2010-02-08 13:44:00 -0800106 + " iconBitmap=" + info.iconBitmap);
Joe Onoratobe386092009-11-17 17:32:16 -0800107 }
108 }
Joe Onorato0589f0f2010-02-08 13:44:00 -0800109
110 public ShortcutInfo makeShortcut() {
111 return new ShortcutInfo(this);
112 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800113}