Cleaning up lint warnings and making some performance improvements on string builders
This commit is contained in:
parent
3b75765d92
commit
732d309888
@ -21,10 +21,10 @@ import info.guardianproject.netcipher.web.WebkitProxy;
|
||||
*/
|
||||
public class ProxyUtils {
|
||||
// Helper
|
||||
private I2PAndroidHelper mI2PHelper;
|
||||
private final I2PAndroidHelper mI2PHelper;
|
||||
private static boolean mI2PHelperBound;
|
||||
private static boolean mI2PProxyInitialized;
|
||||
private PreferenceManager mPreferences;
|
||||
private final PreferenceManager mPreferences;
|
||||
private static ProxyUtils mInstance;
|
||||
|
||||
private ProxyUtils(Context context) {
|
||||
@ -191,7 +191,7 @@ public class ProxyUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public int setProxyChoice(int choice, Activity activity) {
|
||||
public static int setProxyChoice(int choice, Activity activity) {
|
||||
switch (choice) {
|
||||
case Constants.PROXY_ORBOT:
|
||||
if (!OrbotHelper.isOrbotInstalled(activity)) {
|
||||
|
@ -1022,7 +1022,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
public void onTrimMemory(int level) {
|
||||
if (level > TRIM_MEMORY_MODERATE && Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
Log.d(Constants.TAG, "Low Memory, Free Memory");
|
||||
for (int n = 0; n < mWebViewList.size(); n++) {
|
||||
for (int n = 0, size = mWebViewList.size(); n < size; n++) {
|
||||
mWebViewList.get(n).freeMemory();
|
||||
}
|
||||
}
|
||||
@ -1164,7 +1164,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
performExitCleanUp();
|
||||
mCurrentView = null;
|
||||
mWebView = null;
|
||||
for (int n = 0; n < mWebViewList.size(); n++) {
|
||||
for (int n = 0, size = mWebViewList.size(); n < size; n++) {
|
||||
if (mWebViewList.get(n) != null) {
|
||||
mWebViewList.get(n).onDestroy();
|
||||
}
|
||||
@ -1225,7 +1225,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
void saveOpenTabs() {
|
||||
if (mPreferences.getRestoreLostTabsEnabled()) {
|
||||
String s = "";
|
||||
for (int n = 0; n < mWebViewList.size(); n++) {
|
||||
for (int n = 0, size = mWebViewList.size(); n < size; n++) {
|
||||
if (!mWebViewList.get(n).getUrl().isEmpty()) {
|
||||
s = s + mWebViewList.get(n).getUrl() + "|$|SEPARATOR|$|";
|
||||
}
|
||||
@ -1270,7 +1270,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
}
|
||||
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext());
|
||||
initializePreferences();
|
||||
for (int n = 0; n < mWebViewList.size(); n++) {
|
||||
for (int n = 0, size = mWebViewList.size(); n < size; n++) {
|
||||
if (mWebViewList.get(n) != null) {
|
||||
mWebViewList.get(n).initializePreferences(null, this);
|
||||
} else {
|
||||
@ -2358,7 +2358,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
super.onReceive(context, intent);
|
||||
boolean isConnected = isConnected(context);
|
||||
Log.d(Constants.TAG, "Network Connected: " + String.valueOf(isConnected));
|
||||
for (int n = 0; n < mWebViewList.size(); n++) {
|
||||
for (int n = 0, size = mWebViewList.size(); n < size; n++) {
|
||||
WebView view = mWebViewList.get(n).getWebView();
|
||||
if (view != null)
|
||||
view.setNetworkAvailable(isConnected);
|
||||
@ -2431,7 +2431,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
/**
|
||||
* This is received when the user edit a bookmark
|
||||
*
|
||||
* @param event
|
||||
* @param event the event that the bookmark has changed
|
||||
*/
|
||||
@Subscribe
|
||||
public void bookmarkChanged(final BookmarkEvents.BookmarkChanged event) {
|
||||
@ -2446,7 +2446,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
/**
|
||||
* Notify the browser that a bookmark was deleted
|
||||
*
|
||||
* @param event
|
||||
* @param event the event that the bookmark has been deleted
|
||||
*/
|
||||
@Subscribe
|
||||
public void bookmarkDeleted(final BookmarkEvents.Deleted event) {
|
||||
|
@ -6,10 +6,7 @@ import android.view.Menu;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.CookieSyncManager;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.bus.BookmarkEvents;
|
||||
import acr.browser.lightning.preference.PreferenceManager;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -21,9 +21,6 @@ import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.constant.Constants;
|
||||
import acr.browser.lightning.preference.PreferenceManager;
|
||||
|
@ -72,7 +72,7 @@ public final class BookmarkPage {
|
||||
final StringBuilder bookmarkBuilder = new StringBuilder(BookmarkPage.HEADING);
|
||||
|
||||
final String folderIconPath = Constants.FILE + CACHE_DIR + "/folder.png";
|
||||
for (int n = 0; n < list.size(); n++) {
|
||||
for (int n = 0, size = list.size(); n < size; n++) {
|
||||
final HistoryItem item = list.get(n);
|
||||
bookmarkBuilder.append(BookmarkPage.PART1);
|
||||
if (item.isFolder()) {
|
||||
|
@ -34,7 +34,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
|
||||
private File[] mFileList;
|
||||
private String[] mFileNameList;
|
||||
private PermissionsManager mPermissionsManager;
|
||||
private static String[] REQUIRED_PERMISSIONS = new String[]{
|
||||
private static final String[] REQUIRED_PERMISSIONS = new String[]{
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
};
|
||||
|
@ -171,7 +171,7 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private float getTextSize(int size) {
|
||||
private static float getTextSize(int size) {
|
||||
switch (size) {
|
||||
case 0:
|
||||
return XSMALL;
|
||||
|
@ -231,10 +231,10 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
|
||||
ProxyUtils utils = ProxyUtils.getInstance(mActivity);
|
||||
switch (choice) {
|
||||
case Constants.PROXY_ORBOT:
|
||||
choice = utils.setProxyChoice(choice, mActivity);
|
||||
choice = ProxyUtils.setProxyChoice(choice, mActivity);
|
||||
break;
|
||||
case Constants.PROXY_I2P:
|
||||
choice = utils.setProxyChoice(choice, mActivity);
|
||||
choice = ProxyUtils.setProxyChoice(choice, mActivity);
|
||||
break;
|
||||
case Constants.PROXY_MANUAL:
|
||||
manualProxyPicker();
|
||||
|
@ -57,7 +57,7 @@ public class PreferenceManager {
|
||||
}
|
||||
|
||||
private static PreferenceManager mInstance;
|
||||
private SharedPreferences mPrefs;
|
||||
private final SharedPreferences mPrefs;
|
||||
|
||||
private static final String PREFERENCES = "settings";
|
||||
|
||||
|
@ -385,16 +385,16 @@ public class ArticleTextExtractor {
|
||||
// System.out.println("date modified element " + elem.toString());
|
||||
}
|
||||
|
||||
if ("".equals(dateStr)) {
|
||||
if (dateStr != null && dateStr.isEmpty()) {
|
||||
dateStr = SHelper.innerTrim(doc.select("meta[name=utime]").attr("content"));
|
||||
}
|
||||
if ("".equals(dateStr)) {
|
||||
if (dateStr != null && dateStr.isEmpty()) {
|
||||
dateStr = SHelper.innerTrim(doc.select("meta[name=pdate]").attr("content"));
|
||||
}
|
||||
if ("".equals(dateStr)) {
|
||||
if (dateStr != null && dateStr.isEmpty()) {
|
||||
dateStr = SHelper.innerTrim(doc.select("meta[property=article:published]").attr("content"));
|
||||
}
|
||||
if ("".equals(dateStr)) {
|
||||
if (dateStr != null && dateStr.isEmpty()) {
|
||||
return parseDate(dateStr);
|
||||
}
|
||||
|
||||
@ -1143,13 +1143,14 @@ public class ArticleTextExtractor {
|
||||
}
|
||||
|
||||
private static String cleanTitle(String title) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
|
||||
// int index = title.lastIndexOf("|");
|
||||
// if (index > 0 && title.length() / 2 < index)
|
||||
// title = title.substring(0, index + 1);
|
||||
|
||||
int counter = 0;
|
||||
String[] strs = title.split("\\|");
|
||||
StringBuilder res = new StringBuilder(strs.length);
|
||||
for (String part : strs) {
|
||||
if (IGNORED_TITLE_PARTS.contains(part.toLowerCase().trim()))
|
||||
continue;
|
||||
|
@ -203,6 +203,7 @@ public class HtmlFetcher {
|
||||
}
|
||||
|
||||
// main workhorse to call externally
|
||||
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
|
||||
public JResult fetchAndExtract(String url, int timeout, boolean resolve,
|
||||
int maxContentSize, boolean forceReload) throws Exception {
|
||||
String originalUrl = url;
|
||||
@ -325,13 +326,13 @@ public class HtmlFetcher {
|
||||
}
|
||||
|
||||
public String fetchAsString(String urlAsString, int timeout)
|
||||
throws MalformedURLException, IOException {
|
||||
throws IOException {
|
||||
return fetchAsString(urlAsString, timeout, true);
|
||||
}
|
||||
|
||||
// main routine to get raw webpage content
|
||||
public String fetchAsString(String urlAsString, int timeout, boolean includeSomeGooseOptions)
|
||||
throws MalformedURLException, IOException {
|
||||
throws IOException {
|
||||
HttpURLConnection hConn = createUrlConnection(urlAsString, timeout, includeSomeGooseOptions);
|
||||
hConn.setInstanceFollowRedirects(true);
|
||||
String encoding = hConn.getContentEncoding();
|
||||
@ -413,7 +414,7 @@ public class HtmlFetcher {
|
||||
* UTF-8 in the Location: header.
|
||||
*/
|
||||
static String encodeUriFromHeader(String badLocation) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder(badLocation.length());
|
||||
|
||||
for (char ch : badLocation.toCharArray()) {
|
||||
if (ch < (char) 128) {
|
||||
@ -428,7 +429,7 @@ public class HtmlFetcher {
|
||||
}
|
||||
|
||||
protected HttpURLConnection createUrlConnection(String urlAsStr, int timeout,
|
||||
boolean includeSomeGooseOptions) throws MalformedURLException, IOException {
|
||||
boolean includeSomeGooseOptions) throws IOException {
|
||||
URL url = new URL(urlAsStr);
|
||||
//using proxy may increase latency
|
||||
HttpURLConnection hConn = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
|
||||
|
@ -72,9 +72,9 @@ public class SHelper {
|
||||
if (str.isEmpty())
|
||||
return "";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder(str.length());
|
||||
boolean previousSpace = false;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
for (int i = 0, length = str.length(); i < length; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c == ' ' || (int) c == 9 || c == '\n') {
|
||||
previousSpace = true;
|
||||
@ -95,7 +95,7 @@ public class SHelper {
|
||||
* invalid encoding character occurs.
|
||||
*/
|
||||
public static String encodingCleanup(String str) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder(str.length());
|
||||
boolean startedWithCorrectString = false;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
@ -301,7 +301,7 @@ public class SHelper {
|
||||
}
|
||||
|
||||
public static String printNode(Element root, int indentation) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder(indentation);
|
||||
for (int i = 0; i < indentation; i++) {
|
||||
sb.append(' ');
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import acr.browser.lightning.constant.Constants;
|
||||
@ -46,7 +45,7 @@ public class DownloadImageTask extends AsyncTask<Void, Void, Bitmap> {
|
||||
// unique path for each url that is bookmarked.
|
||||
final Uri uri = Uri.parse(mUrl);
|
||||
|
||||
final String hash = "" + uri.getHost().hashCode();
|
||||
final String hash = String.valueOf(uri.getHost().hashCode());
|
||||
final File image = new File(mCacheDir, hash + ".png");
|
||||
final Uri urldisplay = Uri.fromParts(uri.getScheme(), uri.getHost(), "favicon.ico");
|
||||
// checks to see if the image exists
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package acr.browser.lightning.utils;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.util.Patterns;
|
||||
import android.webkit.URLUtil;
|
||||
|
||||
@ -28,11 +27,11 @@ import java.util.regex.Pattern;
|
||||
public class UrlUtils {
|
||||
static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile(
|
||||
"(?i)" + // switch on case insensitive matching
|
||||
"(" + // begin group for schema
|
||||
'(' + // begin group for schema
|
||||
"(?:http|https|file):\\/\\/" +
|
||||
"|(?:inline|data|about|javascript):" +
|
||||
"|(?:.*:.*@)" +
|
||||
")" +
|
||||
')' +
|
||||
"(.*)");
|
||||
// Google search
|
||||
public final static String QUERY_PLACE_HOLDER = "%s";
|
||||
|
@ -34,11 +34,8 @@ import android.webkit.URLUtil;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -2,7 +2,6 @@ package acr.browser.lightning.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Browser;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.CookieSyncManager;
|
||||
|
@ -51,7 +51,6 @@ import android.widget.LinearLayout;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@ -95,7 +94,7 @@ public class LightningView {
|
||||
0, 0, -1.0f, 0, 255, // blue
|
||||
0, 0, 0, 1.0f, 0 // alpha
|
||||
};
|
||||
private PermissionsManager mPermissionsManager;
|
||||
private final PermissionsManager mPermissionsManager;
|
||||
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
|
Loading…
Reference in New Issue
Block a user