Always offer browser for opening links

pull/212/head
M66B 3 years ago
parent 76d1aa22a5
commit bdfedb96f8

@ -342,6 +342,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Package pkg = (Package) parent.getAdapter().getItem(position); Package pkg = (Package) parent.getAdapter().getItem(position);
if (pkg.browser)
prefs.edit() prefs.edit()
.putString("open_with_pkg", pkg.name) .putString("open_with_pkg", pkg.name)
.putBoolean("open_with_tabs", pkg.tabs) .putBoolean("open_with_tabs", pkg.tabs)
@ -613,8 +614,24 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
int flags = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ? 0 : PackageManager.MATCH_ALL); int flags = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ? 0 : PackageManager.MATCH_ALL);
List<ResolveInfo> ris = pm.queryIntentActivities(intent, flags); List<ResolveInfo> ris = pm.queryIntentActivities(intent, flags);
intent.setData(Uri.parse("http://example.com"));
List<ResolveInfo> browsers = pm.queryIntentActivities(intent, flags);
for (ResolveInfo browser : browsers) {
boolean found = false;
for (ResolveInfo ri : ris)
if (Objects.equals(ri.activityInfo.packageName, browser.activityInfo.packageName)) {
found = true;
break;
}
if (!found)
ris.add(browser);
}
for (ResolveInfo ri : ris) { for (ResolveInfo ri : ris) {
Resources res = pm.getResourcesForApplication(ri.activityInfo.applicationInfo); Resources res = pm.getResourcesForApplication(ri.activityInfo.applicationInfo);
Drawable icon; Drawable icon;
try { try {
icon = res.getDrawable(ri.activityInfo.applicationInfo.icon); icon = res.getDrawable(ri.activityInfo.applicationInfo.icon);
@ -626,6 +643,9 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
Log.w(ex); Log.w(ex);
icon = null; icon = null;
} }
if (icon != null)
icon.setBounds(0, 0, dp24, dp24);
CharSequence label; CharSequence label;
try { try {
if (ri.activityInfo.applicationInfo.labelRes == 0) if (ri.activityInfo.applicationInfo.labelRes == 0)
@ -640,13 +660,20 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
Log.w(ex); Log.w(ex);
label = null; label = null;
} }
if (icon != null)
icon.setBounds(0, 0, dp24, dp24); boolean isBrowser = false;
for (ResolveInfo browser : browsers)
if (Objects.equals(ri.activityInfo.packageName, browser.activityInfo.packageName)) {
isBrowser = true;
break;
}
pkgs.add(new Package( pkgs.add(new Package(
icon, icon,
label, label,
ri.activityInfo.packageName, ri.activityInfo.packageName,
false, false,
isBrowser,
ri.activityInfo.applicationInfo.enabled)); ri.activityInfo.applicationInfo.enabled));
try { try {
@ -661,6 +688,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
label, label,
ri.activityInfo.packageName, ri.activityInfo.packageName,
true, true,
isBrowser,
ri.activityInfo.applicationInfo.enabled)); ri.activityInfo.applicationInfo.enabled));
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
@ -678,12 +706,14 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
context.getString(R.string.title_select_app), context.getString(R.string.title_select_app),
"chooser", "chooser",
false, false,
false,
true)); true));
pkgs.add(new Package( pkgs.add(new Package(
android, android,
context.getString(R.string.title_select_app), context.getString(R.string.title_select_app),
"chooser", "chooser",
true, true,
false,
true)); true));
return pkgs; return pkgs;
@ -842,13 +872,15 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
private CharSequence title; private CharSequence title;
private String name; private String name;
private boolean tabs; private boolean tabs;
private boolean browser;
private boolean enabled; private boolean enabled;
public Package(Drawable icon, CharSequence title, String name, boolean tabs, boolean enabled) { public Package(Drawable icon, CharSequence title, String name, boolean tabs, boolean browser, boolean enabled) {
this.icon = icon; this.icon = icon;
this.title = title; this.title = title;
this.name = name; this.name = name;
this.tabs = tabs; this.tabs = tabs;
this.browser = browser;
this.enabled = enabled; this.enabled = enabled;
} }
@ -876,6 +908,8 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
private final List<Package> pkgs; private final List<Package> pkgs;
private final Drawable external; private final Drawable external;
private final Drawable browser; private final Drawable browser;
private final int textColorPrimary;
private final int textColorSecondary;
AdapterPackage(@NonNull Context context, List<Package> pkgs) { AdapterPackage(@NonNull Context context, List<Package> pkgs) {
super(context, 0, pkgs); super(context, 0, pkgs);
@ -887,6 +921,8 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
this.browser = ContextCompat.getDrawable(context, R.drawable.twotone_language_24); this.browser = ContextCompat.getDrawable(context, R.drawable.twotone_language_24);
if (browser != null) if (browser != null)
browser.setBounds(0, 0, browser.getIntrinsicWidth(), browser.getIntrinsicHeight()); browser.setBounds(0, 0, browser.getIntrinsicWidth(), browser.getIntrinsicHeight());
this.textColorPrimary = Helper.resolveColor(context, android.R.attr.textColorPrimary);
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
} }
@NonNull @NonNull
@ -908,6 +944,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
if (pkg != null) { if (pkg != null) {
view.setAlpha(pkg.enabled ? 1f : Helper.LOW_LIGHT); view.setAlpha(pkg.enabled ? 1f : Helper.LOW_LIGHT);
text1.setText(pkg.title == null ? pkg.name : pkg.title.toString()); text1.setText(pkg.title == null ? pkg.name : pkg.title.toString());
text1.setTextColor(pkg.browser ? textColorPrimary : textColorSecondary);
text1.setCompoundDrawablesRelative( text1.setCompoundDrawablesRelative(
pkg.icon == null ? browser : pkg.icon, pkg.icon == null ? browser : pkg.icon,
null, null,

Loading…
Cancel
Save