• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 
17 package com.android.launcher3.util;
18 
19 import android.content.Context;
20 import android.content.Intent.ShortcutIconResource;
21 import android.database.Cursor;
22 import android.graphics.Bitmap;
23 import android.text.TextUtils;
24 
25 import com.android.launcher3.LauncherSettings;
26 import com.android.launcher3.ShortcutInfo;
27 import com.android.launcher3.Utilities;
28 
29 /**
30  * Utility class to load icon from a cursor.
31  */
32 public class CursorIconInfo {
33     public final int iconTypeIndex;
34     public final int iconPackageIndex;
35     public final int iconResourceIndex;
36     public final int iconIndex;
37 
CursorIconInfo(Cursor c)38     public CursorIconInfo(Cursor c) {
39         iconTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_TYPE);
40         iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
41         iconPackageIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_PACKAGE);
42         iconResourceIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_RESOURCE);
43     }
44 
loadIcon(Cursor c, ShortcutInfo info, Context context)45     public Bitmap loadIcon(Cursor c, ShortcutInfo info, Context context) {
46         Bitmap icon = null;
47         int iconType = c.getInt(iconTypeIndex);
48         switch (iconType) {
49         case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
50             String packageName = c.getString(iconPackageIndex);
51             String resourceName = c.getString(iconResourceIndex);
52             if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
53                 info.iconResource = new ShortcutIconResource();
54                 info.iconResource.packageName = packageName;
55                 info.iconResource.resourceName = resourceName;
56                 icon = Utilities.createIconBitmap(packageName, resourceName, context);
57             }
58             if (icon == null) {
59                 // Failed to load from resource, try loading from DB.
60                 icon = Utilities.createIconBitmap(c, iconIndex, context);
61             }
62             break;
63         case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
64             icon = Utilities.createIconBitmap(c, iconIndex, context);
65             info.customIcon = icon != null;
66             break;
67         }
68         return icon;
69     }
70 }
71