|
1 | 1 | package com.oasisfeng.nevo.xposed; |
2 | 2 |
|
3 | 3 | import android.app.Activity; |
4 | | -import android.content.Context; |
5 | | -import android.content.Intent; |
6 | | -import android.content.pm.PackageInfo; |
7 | | -import android.content.pm.PackageManager; |
8 | | -import android.graphics.drawable.Icon; |
9 | | -import android.net.Uri; |
| 4 | +import android.app.Fragment; |
| 5 | +import android.app.FragmentManager; |
10 | 6 | import android.os.Bundle; |
11 | 7 | import android.util.Log; |
12 | | -import android.view.View; |
13 | | -import android.view.ViewGroup; |
14 | | -import android.widget.BaseAdapter; |
15 | | -import android.widget.ImageView; |
16 | | -import android.widget.ListView; |
17 | | -import android.widget.TextView; |
18 | 8 |
|
19 | 9 | import java.util.List; |
20 | 10 |
|
21 | | -import top.trumeet.common.cache.IconCache; |
22 | | - |
23 | | -import com.oasisfeng.nevo.decorators.media.ColorUtil; |
24 | | - |
25 | 11 | public class MainActivity extends Activity { |
26 | | - private static final String NOTIFICATION_ICON = "mipush_notification"; |
27 | | - private static final String NOTIFICATION_SMALL_ICON = "mipush_small_notification"; |
28 | | - |
29 | | - private ListView listView; |
30 | | - private IconCache cache; |
31 | 12 |
|
32 | 13 | @Override |
33 | 14 | protected void onCreate(Bundle savedInstanceState) { |
34 | 15 | super.onCreate(savedInstanceState); |
35 | | - listView = new ListView(this); |
36 | | - cache = IconCache.getInstance(); |
37 | | - final PackageManager manager = getPackageManager(); |
38 | | - final List<PackageInfo> packages = manager.getInstalledPackages(0); |
39 | | - listView.setAdapter(new BaseAdapter() { |
40 | | - @Override |
41 | | - public int getCount() { |
42 | | - return packages.size(); |
43 | | - } |
44 | | - |
45 | | - @Override |
46 | | - public PackageInfo getItem(int position) { |
47 | | - return packages.get(position); |
48 | | - } |
49 | | - |
50 | | - @Override |
51 | | - public long getItemId(int position) { |
52 | | - return packages.get(position).hashCode(); |
53 | | - } |
54 | | - |
55 | | - @Override |
56 | | - public View getView(int position, View convertView, ViewGroup parent) { |
57 | | - View view = null; |
58 | | - |
59 | | - // 如果convertView不为空则复用 |
60 | | - if (convertView == null) { |
61 | | - view = View.inflate(MainActivity.this, R.layout.app_info, null); |
62 | | - }else { |
63 | | - view = convertView; |
64 | | - } |
65 | | - |
66 | | - PackageInfo info = getItem(position); |
67 | | - // applicationLabel |
68 | | - TextView appName = (TextView) view.findViewById(R.id.appName); |
69 | | - appName.setText(manager.getApplicationLabel(info.applicationInfo)); |
70 | | - // applicationIcon |
71 | | - ImageView appIcon = (ImageView) view.findViewById(R.id.appIcon); |
72 | | - appIcon.setImageDrawable(manager.getApplicationIcon(info.applicationInfo)); |
73 | | - // applicationLogo |
74 | | - ImageView appLogo = (ImageView) view.findViewById(R.id.appLogo); |
75 | | - appLogo.setImageDrawable(manager.getApplicationLogo(info.applicationInfo)); |
76 | | - // smallIcon |
77 | | - ImageView smallIcon = (ImageView) view.findViewById(R.id.smallIcon); |
78 | | - ImageView gen = (ImageView) view.findViewById(R.id.gen); |
79 | | - try { |
80 | | - final Context context = createPackageContext(info.packageName, 0); |
81 | | - int iconId; |
82 | | - if ((iconId = context.getResources().getIdentifier(NOTIFICATION_SMALL_ICON, "drawable", info.packageName)) != 0) // has icon |
83 | | - smallIcon.setImageIcon(Icon.createWithResource(info.packageName, iconId)); |
84 | | - else if ((iconId = context.getResources().getIdentifier(NOTIFICATION_ICON, "drawable", info.packageName)) != 0) |
85 | | - smallIcon.setImageIcon(Icon.createWithResource(info.packageName, iconId)); |
86 | | - else |
87 | | - smallIcon.setImageIcon(null); |
88 | | - Icon iconCache = cache.getIconCache(context, info.packageName, (ctx, b) -> Icon.createWithBitmap(b)); |
89 | | - if (iconCache != null) { |
90 | | - gen.setImageIcon(iconCache); |
91 | | - gen.setColorFilter(cache.getAppColor(context, info.packageName, (ctx, b) -> ColorUtil.getColor(b)[0])); |
92 | | - } |
93 | | - } catch (IllegalArgumentException | PackageManager.NameNotFoundException ign) { Log.d("inspect", "ex " + info.packageName);} |
94 | | - return view; |
95 | | - } |
96 | | - }); |
97 | | - setContentView(listView); |
| 16 | + setContentView(R.layout.activity_main); |
| 17 | + getFragmentManager() |
| 18 | + .beginTransaction() |
| 19 | + .add(R.id.main_fragment, new MainPreference()) |
| 20 | + .commit(); |
98 | 21 | } |
99 | 22 |
|
100 | 23 | } |
0 commit comments