diff --git a/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java b/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java index 10cf99f..cf1ba0e 100644 --- a/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java +++ b/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.os.Build; +import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; import android.util.Log; @@ -32,7 +33,7 @@ public class ProxyUtils { mI2PHelper = new I2PAndroidHelper(context); } - public static ProxyUtils getInstance(Context context) { + public static ProxyUtils getInstance(@NonNull Context context) { if (mInstance == null) { mInstance = new ProxyUtils(context); } diff --git a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java index c55d4ab..9ce14d7 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java @@ -14,6 +14,7 @@ import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.support.v7.app.AlertDialog; +import android.text.InputFilter; import android.util.Log; import android.util.TypedValue; import android.view.View; @@ -244,6 +245,15 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe View v = mActivity.getLayoutInflater().inflate(R.layout.picker_manual_proxy, null); final EditText eProxyHost = (EditText) v.findViewById(R.id.proxyHost); final EditText eProxyPort = (EditText) v.findViewById(R.id.proxyPort); + + // Limit the number of characters since the port needs to be of type int + // Use input filters to limite the EditText length and determine the max + // length by using length of integer MAX_VALUE + int maxCharacters = Integer.toString(Integer.MAX_VALUE).length(); + InputFilter[] filterArray = new InputFilter[1]; + filterArray[0] = new InputFilter.LengthFilter(maxCharacters - 1); + eProxyPort.setFilters(filterArray); + eProxyHost.setText(mPreferences.getProxyHost()); eProxyPort.setText(Integer.toString(mPreferences.getProxyPort())); @@ -254,13 +264,19 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe @Override public void onClick(DialogInterface dialogInterface, int i) { String proxyHost = eProxyHost.getText().toString(); - int proxyPort = Integer.parseInt(eProxyPort.getText().toString()); + int proxyPort; + try { + // Try/Catch in case the user types an empty string or a number + // larger than max integer + proxyPort = Integer.parseInt(eProxyPort.getText().toString()); + } catch (NumberFormatException ignored) { + proxyPort = mPreferences.getProxyPort(); + } mPreferences.setProxyHost(proxyHost); mPreferences.setProxyPort(proxyPort); proxy.setSummary(proxyHost + ":" + proxyPort); } - }) - .show(); + }).show(); } private void searchDialog() { diff --git a/app/src/main/java/acr/browser/lightning/utils/Utils.java b/app/src/main/java/acr/browser/lightning/utils/Utils.java index 86ae7c6..ef8b30a 100644 --- a/app/src/main/java/acr/browser/lightning/utils/Utils.java +++ b/app/src/main/java/acr/browser/lightning/utils/Utils.java @@ -96,6 +96,8 @@ public final class Utils { } public static String getDomainName(String url) { + if (url == null || url.isEmpty()) return ""; + boolean ssl = url.startsWith(Constants.HTTPS); int index = url.indexOf('/', 8); if (index != -1) { @@ -103,12 +105,13 @@ public final class Utils { } URI uri; - String domain = null; + String domain; try { uri = new URI(url); domain = uri.getHost(); } catch (URISyntaxException e) { e.printStackTrace(); + domain = null; } if (domain == null || domain.isEmpty()) { diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index bb06c15..34e92fc 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -543,12 +543,6 @@ public class LightningView { } } - public void clearCache(boolean disk) { - if (mWebView != null) { - mWebView.clearCache(disk); - } - } - public synchronized void reload() { // Check if configured proxy is available if (mBrowserController.proxyIsNotReady()) { @@ -562,6 +556,8 @@ public class LightningView { } private void cacheFavicon(Bitmap icon) { + if (icon == null) return; + String hash = String.valueOf(Utils.getDomainName(getUrl()).hashCode()); Log.d(Constants.TAG, "Caching icon for " + Utils.getDomainName(getUrl())); FileOutputStream fos = null; @@ -577,8 +573,6 @@ public class LightningView { } } - @SuppressWarnings("deprecation") - @SuppressLint("NewApi") public synchronized void find(String text) { if (mWebView != null) { if (API > 16) {