Browse Source

Fixed some bugs

master
Anthony Restaino 9 years ago
parent
commit
4ba7c7c5a3
  1. 3
      app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java
  2. 22
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  3. 5
      app/src/main/java/acr/browser/lightning/utils/Utils.java
  4. 10
      app/src/main/java/acr/browser/lightning/view/LightningView.java

3
app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java

@ -4,6 +4,7 @@ import android.app.Activity; @@ -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 { @@ -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);
}

22
app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

@ -14,6 +14,7 @@ import android.preference.CheckBoxPreference; @@ -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 @@ -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 @@ -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() {

5
app/src/main/java/acr/browser/lightning/utils/Utils.java

@ -96,6 +96,8 @@ public final class Utils { @@ -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 { @@ -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()) {

10
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -543,12 +543,6 @@ public class LightningView { @@ -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 { @@ -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 { @@ -577,8 +573,6 @@ public class LightningView {
}
}
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public synchronized void find(String text) {
if (mWebView != null) {
if (API > 16) {

Loading…
Cancel
Save