From e6c1562e1b1131f41a06d9f0cfe64066300d7364 Mon Sep 17 00:00:00 2001 From: HChenX Date: Tue, 11 Jun 2024 12:31:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=20app=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=8E=E9=80=89=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/fragment/sub/AppPicker.java | 91 +++++++++++-------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/sub/AppPicker.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/sub/AppPicker.java index 1217b8eff4..c184062bd4 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/sub/AppPicker.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/sub/AppPicker.java @@ -46,6 +46,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -123,10 +124,10 @@ public void onItemClick(AdapterView parent, View view, int position, long id) switch (modeSelection) { case CALLBACK_MODE -> { mAppSelectCallback.sendMsgToActivity(BitmapUtils.Bitmap2Bytes(appData.icon), - appData.label, - appData.packageName, - appData.versionName + "(" + appData.versionCode + ")", - appData.activityName); + appData.label, + appData.packageName, + appData.versionName + "(" + appData.versionCode + ")", + appData.activityName); requireActivity().finish(); } case LAUNCHER_MODE, APP_OPEN_MODE -> { @@ -143,11 +144,11 @@ public void onItemClick(AdapterView parent, View view, int position, long id) } case INPUT_MODE -> { showEditDialog(appData.label, new EditDialogCallback() { - @Override - public void onInputReceived(String userInput) { - iEditCallback.editCallback(appData.label, appData.packageName, userInput); + @Override + public void onInputReceived(String userInput) { + iEditCallback.editCallback(appData.label, appData.packageName, userInput); + } } - } ); } } @@ -161,17 +162,17 @@ private void showEditDialog(String defaultText, EditDialogCallback callback) { input.setText(defaultText); new AlertDialog.Builder(requireActivity()) - .setTitle(R.string.edit) - .setView(view) - .setPositiveButton(android.R.string.ok, (dialog, which) -> { - String userInput = input.getText().toString(); - callback.onInputReceived(userInput); - dialog.dismiss(); - }) - .setNegativeButton(android.R.string.cancel, (dialog, which) -> { - dialog.dismiss(); - }) - .show(); + .setTitle(R.string.edit) + .setView(view) + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + String userInput = input.getText().toString(); + callback.onInputReceived(userInput); + dialog.dismiss(); + }) + .setNegativeButton(android.R.string.cancel, (dialog, which) -> { + dialog.dismiss(); + }) + .show(); } private void initData() { @@ -183,7 +184,7 @@ public void run() { public void run() { appDataList = getAppInfo(); mAppListAdapter = new AppDataAdapter(requireActivity(), - R.layout.item_app_list, appDataList, key, modeSelection); + R.layout.item_app_list, appDataList, key, modeSelection); mAppListRv.setAdapter(mAppListAdapter); mAmProgress.setVisibility(View.GONE); mAppListRv.setVisibility(View.VISIBLE); @@ -196,26 +197,40 @@ public void run() { public List getAppInfo() { return switch (modeSelection) { case LAUNCHER_MODE, CALLBACK_MODE, INPUT_MODE -> - PackagesUtils.getPackagesByCode(new PackagesUtils.IPackageCode() { - @Override - public List getPackageCodeList(PackageManager pm) { - Intent intent = new Intent(Intent.ACTION_MAIN); - intent.addCategory(Intent.CATEGORY_LAUNCHER); - List resolveInfoList = new ArrayList<>(); - List resolveInfos = pm.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES); - hashMap.clear(); - for (ResolveInfo resolveInfo : resolveInfos) { - Integer added = hashMap.get(resolveInfo.activityInfo.applicationInfo.packageName); - if (added == null || added != 1) { - hashMap.put(resolveInfo.activityInfo.applicationInfo.packageName, 1); - } else { - continue; + PackagesUtils.getPackagesByCode(new PackagesUtils.IPackageCode() { + @Override + public List getPackageCodeList(PackageManager pm) { + Intent intent = new Intent(Intent.ACTION_MAIN); + intent.addCategory(Intent.CATEGORY_LAUNCHER); + List resolveInfoList = new ArrayList<>(); + List resolveInfos = pm.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES); + List resolveInfosHaveNoLauncher = pm.queryIntentActivities(new Intent(Intent.ACTION_MAIN), PackageManager.GET_ACTIVITIES); + if (resolveInfosHaveNoLauncher.size() > resolveInfos.size()) { + Iterator iterator = resolveInfosHaveNoLauncher.iterator(); + while (iterator.hasNext()) { + ResolveInfo info = iterator.next(); + if (resolveInfos.contains(info)) { + continue; + } else { + if (PackagesUtils.isSystem(info.activityInfo.applicationInfo)) { + iterator.remove(); + } + } + } } - resolveInfoList.add(resolveInfo); + hashMap.clear(); + for (ResolveInfo resolveInfo : resolveInfosHaveNoLauncher) { + Integer added = hashMap.get(resolveInfo.activityInfo.applicationInfo.packageName); + if (added == null || added != 1) { + hashMap.put(resolveInfo.activityInfo.applicationInfo.packageName, 1); + } else { + continue; + } + resolveInfoList.add(resolveInfo); + } + return new ArrayList<>(resolveInfoList); } - return new ArrayList<>(resolveInfoList); - } - }); + }); case APP_OPEN_MODE -> PackagesUtils.getOpenWithApps(); default -> new ArrayList<>(); };