1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* Copyright (C) 2014 The CyanogenMod 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.
*/
package org.cyanogenmod.themes.provider.util;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
public class IconPreviewGenerator {
private static final ComponentName COMPONENT_DIALER =
new ComponentName("com.android.dialer", "com.android.dialer.DialtactsActivity");
private static final ComponentName COMPONENT_MESSAGING =
new ComponentName("com.android.mms", "com.android.mms.ui.ConversationList");
private static final ComponentName COMPONENT_CAMERANEXT =
new ComponentName("com.cyngn.cameranext", "com.android.camera.CameraLauncher");
private static final ComponentName COMPONENT_CAMERA =
new ComponentName("com.android.camera2", "com.android.camera.CameraLauncher");
private static final ComponentName COMPONENT_BROWSER =
new ComponentName("com.android.browser", "com.android.browser.BrowserActivity");
private static final ComponentName COMPONENT_SETTINGS =
new ComponentName("com.android.settings", "com.android.settings.Settings");
private static final ComponentName COMPONENT_CALENDAR =
new ComponentName("com.android.calendar", "com.android.calendar.AllInOneActivity");
private static final ComponentName COMPONENT_GALERY =
new ComponentName("com.android.gallery3d", "com.android.gallery3d.app.GalleryActivity");
private static final String CAMERA_NEXT_PACKAGE = "com.cyngn.cameranext";
private ComponentName[] mIconComponents;
private Context mContext;
public IconPreviewGenerator(Context context) {
mContext = context;
}
public IconItems generateIconItems(String pkgName) {
IconItems items = new IconItems();
IconPreviewHelper helper = new IconPreviewHelper(mContext, pkgName);
final ComponentName[] components = getIconComponents(mContext);
BitmapDrawable drawable;
drawable = (BitmapDrawable) helper.getIcon(components[0]);
items.icon1 = drawable.getBitmap();
drawable = (BitmapDrawable) helper.getIcon(components[1]);
items.icon2 = drawable.getBitmap();
drawable = (BitmapDrawable) helper.getIcon(components[2]);
items.icon3 = drawable.getBitmap();
return items;
}
private ComponentName[] getIconComponents(Context context) {
if (mIconComponents == null || mIconComponents.length == 0) {
mIconComponents = new ComponentName[]{COMPONENT_DIALER, COMPONENT_MESSAGING,
COMPONENT_CAMERA, COMPONENT_BROWSER};
PackageManager pm = context.getPackageManager();
// if device does not have telephony replace dialer and mms
if (!pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
mIconComponents[0] = COMPONENT_CALENDAR;
mIconComponents[1] = COMPONENT_GALERY;
}
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
mIconComponents[2] = COMPONENT_SETTINGS;
} else {
// decide on which camera icon to use
try {
if (pm.getPackageInfo(CAMERA_NEXT_PACKAGE, 0) != null) {
mIconComponents[2] = COMPONENT_CAMERANEXT;
}
} catch (PackageManager.NameNotFoundException e) {
// default to COMPONENT_CAMERA
}
}
}
return mIconComponents;
}
public class IconItems {
public Bitmap icon1;
public Bitmap icon2;
public Bitmap icon3;
}
}
|