The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame^] | 19 | import java.util.ArrayList; |
| 20 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 21 | import android.content.ComponentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 22 | import android.content.Intent; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 23 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 27 | /** |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 28 | * Represents an app in AllAppsView. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 29 | */ |
| 30 | class ApplicationInfo extends ItemInfo { |
| 31 | |
| 32 | /** |
| 33 | * The application name. |
| 34 | */ |
| 35 | CharSequence title; |
| 36 | |
| 37 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 38 | * A bitmap of the application's text in the bubble. |
| 39 | */ |
| 40 | Bitmap titleBitmap; |
| 41 | |
| 42 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | * The intent used to start the application. |
| 44 | */ |
| 45 | Intent intent; |
| 46 | |
| 47 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 48 | * A bitmap version of the application icon. |
| 49 | */ |
| 50 | Bitmap iconBitmap; |
| 51 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 52 | ComponentName componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 53 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | |
| 55 | ApplicationInfo() { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 56 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 58 | |
| 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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 73 | |
| 74 | public ApplicationInfo(ApplicationInfo info) { |
| 75 | super(info); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 76 | componentName = info.componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 77 | title = info.title.toString(); |
| 78 | intent = new Intent(info.intent); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Creates the application intent based on a component name and various launch flags. |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 83 | * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 84 | * |
| 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 Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 93 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 97 | public String toString() { |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 98 | return "ApplicationInfo(title=" + title.toString() + ")"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 99 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 100 | |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 101 | 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 Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 106 | + " iconBitmap=" + info.iconBitmap); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 107 | } |
| 108 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 109 | |
| 110 | public ShortcutInfo makeShortcut() { |
| 111 | return new ShortcutInfo(this); |
| 112 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 113 | } |