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 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.ContentValues; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 21 | import android.content.Context; |
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; |
| 25 | import android.graphics.drawable.Drawable; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 26 | import android.util.Log; |
| 27 | |
| 28 | import java.util.ArrayList; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 31 | * Represents an app in AllAppsView. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 32 | */ |
| 33 | class ApplicationInfo extends ItemInfo { |
| 34 | |
| 35 | /** |
| 36 | * The application name. |
| 37 | */ |
| 38 | CharSequence title; |
| 39 | |
| 40 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 41 | * A bitmap of the application's text in the bubble. |
| 42 | */ |
| 43 | Bitmap titleBitmap; |
| 44 | |
| 45 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 46 | * The intent used to start the application. |
| 47 | */ |
| 48 | Intent intent; |
| 49 | |
| 50 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 51 | * A bitmap version of the application icon. |
| 52 | */ |
| 53 | Bitmap iconBitmap; |
| 54 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 55 | ComponentName componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 56 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | |
| 58 | ApplicationInfo() { |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 59 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 60 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 61 | |
| 62 | /** |
| 63 | * Must not hold the Context. |
| 64 | */ |
| 65 | public ApplicationInfo(ResolveInfo info, IconCache iconCache) { |
| 66 | this.componentName = new ComponentName( |
| 67 | info.activityInfo.applicationInfo.packageName, |
| 68 | info.activityInfo.name); |
| 69 | |
| 70 | this.container = ItemInfo.NO_ID; |
| 71 | this.setActivity(componentName, |
| 72 | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 73 | |
| 74 | iconCache.getTitleAndIcon(this, info); |
| 75 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 76 | |
| 77 | public ApplicationInfo(ApplicationInfo info) { |
| 78 | super(info); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 79 | componentName = info.componentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 80 | title = info.title.toString(); |
| 81 | intent = new Intent(info.intent); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
| 85 | * 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] | 86 | * 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] | 87 | * |
| 88 | * @param className the class name of the component representing the intent |
| 89 | * @param launchFlags the launch flags |
| 90 | */ |
| 91 | final void setActivity(ComponentName className, int launchFlags) { |
| 92 | intent = new Intent(Intent.ACTION_MAIN); |
| 93 | intent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 94 | intent.setComponent(className); |
| 95 | intent.setFlags(launchFlags); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 96 | itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 100 | public String toString() { |
| 101 | return title.toString(); |
| 102 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 103 | |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 104 | public static void dumpApplicationInfoList(String tag, String label, |
| 105 | ArrayList<ApplicationInfo> list) { |
| 106 | Log.d(tag, label + " size=" + list.size()); |
| 107 | for (ApplicationInfo info: list) { |
| 108 | Log.d(tag, " title=\"" + info.title + "\" titleBitmap=" + info.titleBitmap |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 109 | + " iconBitmap=" + info.iconBitmap); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 110 | } |
| 111 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 112 | |
| 113 | public ShortcutInfo makeShortcut() { |
| 114 | return new ShortcutInfo(this); |
| 115 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 116 | } |