fixed 2522, browsers may be installed while the application is running
This commit is contained in:
@ -1,19 +1,25 @@
|
||||
package net.i2p.android.help;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class Browser implements Comparable<Browser> {
|
||||
public final String packageName;
|
||||
public final CharSequence label;
|
||||
public final Drawable icon;
|
||||
public final boolean isInstalled;
|
||||
public final boolean isKnown;
|
||||
public final boolean isSupported;
|
||||
public final boolean isRecommended;
|
||||
|
||||
private boolean isInstalled;
|
||||
/**
|
||||
* A browser that we don't know about.
|
||||
*
|
||||
@ -80,4 +86,23 @@ public class Browser implements Comparable<Browser> {
|
||||
} else
|
||||
return 2;
|
||||
}
|
||||
|
||||
public boolean isInstalled(Context context){
|
||||
if (isInstalled) {
|
||||
return true;
|
||||
}
|
||||
// Find all installed browsers that listen for ".i2p"
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse("http://stats.i2p"));
|
||||
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
List<ResolveInfo> installedBrowsers = pm.queryIntentActivities(intent, 0);
|
||||
for (ResolveInfo browser : installedBrowsers) {
|
||||
if (browser.activityInfo.packageName.equals(packageName)) {
|
||||
isInstalled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isInstalled;
|
||||
}
|
||||
}
|
||||
|
@ -73,11 +73,15 @@ public class BrowserAdapter extends RecyclerView.Adapter<BrowserAdapter.ViewHold
|
||||
holder.mLabel.setText(browser.label);
|
||||
|
||||
if (browser.isKnown) {
|
||||
if (browser.isRecommended && browser.isInstalled) {
|
||||
if (browser.isRecommended && browser.isInstalled(mCtx)) {
|
||||
holder.mStatus.setImageDrawable(
|
||||
mCtx.getResources().getDrawable(R.drawable.ic_stars_white_24dp));
|
||||
holder.mStatus.setVisibility(View.VISIBLE);
|
||||
} else if (browser.isSupported && !browser.isInstalled) {
|
||||
} else if (browser.isSupported && browser.isInstalled(mCtx)) {
|
||||
holder.mStatus.setImageDrawable(
|
||||
mCtx.getResources().getDrawable(R.drawable.ic_stars_white_24dp));
|
||||
holder.mStatus.setVisibility(View.INVISIBLE);
|
||||
} else if (browser.isSupported && !browser.isInstalled(mCtx)) {
|
||||
holder.mStatus.setImageDrawable(
|
||||
mCtx.getResources().getDrawable(R.drawable.ic_shop_white_24dp));
|
||||
holder.mStatus.setOnClickListener(new View.OnClickListener() {
|
||||
@ -94,7 +98,7 @@ public class BrowserAdapter extends RecyclerView.Adapter<BrowserAdapter.ViewHold
|
||||
}
|
||||
});
|
||||
holder.mStatus.setVisibility(View.VISIBLE);
|
||||
} else if (!browser.isSupported) {
|
||||
} else if (browser.isInstalled(mCtx) && !browser.isSupported) {
|
||||
// Make the icon gray-scale to show it is unsupported
|
||||
ColorMatrix matrix = new ColorMatrix();
|
||||
matrix.setSaturation(0);
|
||||
|
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -121,8 +122,9 @@ public class BrowserListFragment extends Fragment implements
|
||||
intent.setData(Uri.parse("http://stats.i2p"));
|
||||
|
||||
final PackageManager pm = getContext().getPackageManager();
|
||||
List<ResolveInfo> installedBrowsers = pm.queryIntentActivities(intent, 0);
|
||||
Set<ResolveInfo> installedBrowsers = new HashSet<>(pm.queryIntentActivities(intent, 0));
|
||||
|
||||
// Compare installed browsers to supported browsers
|
||||
for (ResolveInfo browser : installedBrowsers) {
|
||||
if (recommended.contains(browser.activityInfo.packageName)) {
|
||||
browsers.add(new Browser(pm, browser, true, true));
|
||||
|
@ -9,7 +9,7 @@
|
||||
<li>Change the value of "network.proxy.http_port" to <code>4444</code>.</li>
|
||||
<li>Change the value of "network.proxy.ssl" to <code>127.0.0.1</code>.</li>
|
||||
<li>Change the value of "network.proxy.ssl_port" to <code>4444</code>.</li>
|
||||
<li>Change the value of "media.peerconnection.ice.proxy_only" to <code>true</code><li>
|
||||
<li>Change the value of "media.peerconnection.ice.proxy_only" to <code>true</code>.</li>
|
||||
<li>You may also wish to install plugins to help manage your browser's
|
||||
default javascript settings, such as NoScript and/or uMatrix, and use
|
||||
Private Browsing to manage your browser's cache.
|
||||
|
@ -9,7 +9,7 @@
|
||||
<li>Change the value of "network.proxy.http_port" to <code>4444</code>.</li>
|
||||
<li>Change the value of "network.proxy.ssl" to <code>127.0.0.1</code>.</li>
|
||||
<li>Change the value of "network.proxy.ssl_port" to <code>4444</code>.</li>
|
||||
<li>Change the value of "media.peerconnection.ice.proxy_only" to <code>true</code><li>
|
||||
<li>Change the value of "media.peerconnection.ice.proxy_only" to <code>true</code>.</li>
|
||||
<li>You may also wish to install plugins to help manage your browser's
|
||||
default javascript settings, such as NoScript and/or uMatrix, and use
|
||||
Private Browsing to manage your browser's cache.
|
||||
|
@ -9,7 +9,7 @@
|
||||
<li>Change the value of "network.proxy.http_port" to <code>4444</code>.</li>
|
||||
<li>Change the value of "network.proxy.ssl" to <code>127.0.0.1</code>.</li>
|
||||
<li>Change the value of "network.proxy.ssl_port" to <code>4444</code>.</li>
|
||||
<li>Change the value of "media.peerconnection.ice.proxy_only" to <code>true</code><li>
|
||||
<li>Change the value of "media.peerconnection.ice.proxy_only" to <code>true</code>.</li>
|
||||
<li>You may also wish to install plugins to help manage your browser's
|
||||
default javascript settings, such as NoScript and/or uMatrix, and use
|
||||
Private Browsing to manage your browser's cache.
|
||||
|
Reference in New Issue
Block a user