Browse Source

Fixed many code analysis warnings

master
Anthony Restaino 9 years ago
parent
commit
f3b0e46801
  1. 4
      app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java
  2. 4
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  3. 2
      app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java
  4. 3
      app/src/main/java/acr/browser/lightning/constant/HistoryPage.java
  5. 18
      app/src/main/java/acr/browser/lightning/database/BookmarkManager.java
  6. 4
      app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java
  7. 2
      app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java
  8. 4
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  9. 4
      app/src/main/java/acr/browser/lightning/object/SearchAdapter.java
  10. 2
      app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
  11. 8
      app/src/main/java/acr/browser/lightning/reading/ArticleTextExtractor.java
  12. 6
      app/src/main/java/acr/browser/lightning/reading/Converter.java
  13. 6
      app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java
  14. 6
      app/src/main/java/acr/browser/lightning/reading/OutputFormatter.java
  15. 9
      app/src/main/java/acr/browser/lightning/reading/SHelper.java
  16. 2
      app/src/main/java/acr/browser/lightning/utils/AdBlock.java
  17. 4
      app/src/main/java/acr/browser/lightning/utils/IntentUtils.java
  18. 2
      app/src/main/java/acr/browser/lightning/utils/Utils.java
  19. 11
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  20. 2
      app/src/main/res/layout/video_loading_progress.xml

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

@ -21,10 +21,10 @@ import info.guardianproject.netcipher.web.WebkitProxy; @@ -21,10 +21,10 @@ import info.guardianproject.netcipher.web.WebkitProxy;
*/
public class ProxyUtils {
// Helper
private static I2PAndroidHelper mI2PHelper;
private I2PAndroidHelper mI2PHelper;
private static boolean mI2PHelperBound;
private static boolean mI2PProxyInitialized;
private static PreferenceManager mPreferences;
private PreferenceManager mPreferences;
private static ProxyUtils mInstance;
private ProxyUtils(Context context) {

4
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -980,10 +980,12 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -980,10 +980,12 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (mCurrentView != mWebViewList.get(position)) {
mIsNewIntent = false;
showTab(mWebViewList.get(position));
}
}
}
/**
* long click listener for Navigation Drawer
@ -2113,7 +2115,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -2113,7 +2115,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private void buildBookmarkPage(final String folder, final List<HistoryItem> list) {
File bookmarkWebPage;
if (folder == null || folder.length() == 0) {
if (folder == null || folder.isEmpty()) {
bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
} else {
bookmarkWebPage = new File(mActivity.getFilesDir(), folder + '-' + BookmarkPage.FILENAME);

2
app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java

@ -89,7 +89,7 @@ public class ReadingActivity extends AppCompatActivity { @@ -89,7 +89,7 @@ public class ReadingActivity extends AppCompatActivity {
}
}
private float getTextSize(int size) {
private static float getTextSize(int size) {
switch (size) {
case 0:
return XSMALL;

3
app/src/main/java/acr/browser/lightning/constant/HistoryPage.java

@ -36,8 +36,7 @@ public class HistoryPage { @@ -36,8 +36,7 @@ public class HistoryPage {
private static final String END = "</div></body></html>";
public static String getHistoryPage(Context context) {
StringBuilder historyBuilder = new StringBuilder();
historyBuilder.append(HistoryPage.HEADING);
StringBuilder historyBuilder = new StringBuilder(HistoryPage.HEADING);
List<HistoryItem> historyList = getWebHistory(context);
Iterator<HistoryItem> it = historyList.iterator();
HistoryItem helper;

18
app/src/main/java/acr/browser/lightning/database/BookmarkManager.java

@ -38,9 +38,9 @@ public class BookmarkManager { @@ -38,9 +38,9 @@ public class BookmarkManager {
private static final String FOLDER = "folder";
private static final String ORDER = "order";
private static final String FILE_BOOKMARKS = "bookmarks.dat";
private static Set<String> mBookmarkSearchSet = new HashSet<>();
private static final List<HistoryItem> mBookmarkList = new ArrayList<>();
private static String mCurrentFolder = "";
private Set<String> mBookmarkSearchSet = new HashSet<>();
private final List<HistoryItem> mBookmarkList = new ArrayList<>();
private String mCurrentFolder = "";
private static BookmarkManager mInstance;
public static BookmarkManager getInstance(Context context) {
@ -145,7 +145,7 @@ public class BookmarkManager { @@ -145,7 +145,7 @@ public class BookmarkManager {
* @param newName the new name of the folder
*/
public synchronized void renameFolder(@NonNull String oldName, @NonNull String newName) {
if (newName.length() == 0) {
if (newName.isEmpty()) {
return;
}
for (int n = 0; n < mBookmarkList.size(); n++) {
@ -194,11 +194,11 @@ public class BookmarkManager { @@ -194,11 +194,11 @@ public class BookmarkManager {
mBookmarkSearchSet.remove(oldItem.getUrl());
mBookmarkSearchSet.add(newItem.getUrl());
}
if (newItem.getUrl().length() == 0) {
if (newItem.getUrl().isEmpty()) {
deleteBookmark(oldItem);
return;
}
if (newItem.getTitle().length() == 0) {
if (newItem.getTitle().isEmpty()) {
newItem.setTitle(mContext.getString(R.string.untitled));
}
overwriteBookmarks(mBookmarkList);
@ -289,7 +289,7 @@ public class BookmarkManager { @@ -289,7 +289,7 @@ public class BookmarkManager {
*/
public synchronized List<HistoryItem> getBookmarksFromFolder(String folder, boolean sort) {
List<HistoryItem> bookmarks = new ArrayList<>();
if (folder == null || folder.length() == 0) {
if (folder == null || folder.isEmpty()) {
bookmarks.addAll(getFolders(sort));
folder = "";
}
@ -310,7 +310,7 @@ public class BookmarkManager { @@ -310,7 +310,7 @@ public class BookmarkManager {
* @return returns true if you are in the root folder
*/
public boolean isRootFolder() {
return mCurrentFolder.length() == 0;
return mCurrentFolder.isEmpty();
}
/**
@ -318,7 +318,7 @@ public class BookmarkManager { @@ -318,7 +318,7 @@ public class BookmarkManager {
*
* @return a sorted map of all bookmarks, useful for seeing if a bookmark exists
*/
private static Set<String> getBookmarkUrls(List<HistoryItem> list) {
private Set<String> getBookmarkUrls(List<HistoryItem> list) {
Set<String> set = new HashSet<>();
for (int n = 0; n < list.size(); n++) {
if (!mBookmarkList.get(n).isFolder())

4
app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java

@ -50,9 +50,9 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -50,9 +50,9 @@ public class HistoryDatabase extends SQLiteOpenHelper {
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_HISTORY_TABLE = "CREATE TABLE " + TABLE_HISTORY + "(" + KEY_ID
String CREATE_HISTORY_TABLE = "CREATE TABLE " + TABLE_HISTORY + '(' + KEY_ID
+ " INTEGER PRIMARY KEY," + KEY_URL + " TEXT," + KEY_TITLE + " TEXT,"
+ KEY_TIME_VISITED + " INTEGER" + ")";
+ KEY_TIME_VISITED + " INTEGER" + ')';
db.execSQL(CREATE_HISTORY_TABLE);
}

2
app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java

@ -57,7 +57,7 @@ public class FetchUrlMimeType extends Thread { @@ -57,7 +57,7 @@ public class FetchUrlMimeType extends Thread {
try {
URL url = new URL(mUri);
connection = (HttpURLConnection) url.openConnection();
if (mCookies != null && mCookies.length() > 0) {
if (mCookies != null && !mCookies.isEmpty()) {
connection.addRequestProperty("Cookie", mCookies);
connection.setRequestProperty("User-Agent", mUserAgent);
}

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

@ -102,7 +102,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe @@ -102,7 +102,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
int choice = mPreferences.getProxyChoice();
if (choice == Constants.PROXY_MANUAL) {
proxy.setSummary(mPreferences.getProxyHost() + ":" + mPreferences.getProxyPort());
proxy.setSummary(mPreferences.getProxyHost() + ':' + mPreferences.getProxyPort());
} else {
proxy.setSummary(mProxyChoices[choice]);
}
@ -279,7 +279,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe @@ -279,7 +279,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
}
mPreferences.setProxyHost(proxyHost);
mPreferences.setProxyPort(proxyPort);
proxy.setSummary(proxyHost + ":" + proxyPort);
proxy.setSummary(proxyHost + ':' + proxyPort);
}
}).show();
}

4
app/src/main/java/acr/browser/lightning/object/SearchAdapter.java

@ -385,12 +385,12 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -385,12 +385,12 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
return cacheFile;
}
private boolean isNetworkConnected(Context context) {
private static boolean isNetworkConnected(Context context) {
NetworkInfo networkInfo = getActiveNetworkInfo(context);
return networkInfo != null && networkInfo.isConnected();
}
private NetworkInfo getActiveNetworkInfo(Context context) {
private static NetworkInfo getActiveNetworkInfo(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {

2
app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java

@ -60,7 +60,7 @@ public class PreferenceManager { @@ -60,7 +60,7 @@ public class PreferenceManager {
}
private static PreferenceManager mInstance;
private static SharedPreferences mPrefs;
private SharedPreferences mPrefs;
private static final String PREFERENCES = "settings";

8
app/src/main/java/acr/browser/lightning/reading/ArticleTextExtractor.java

@ -66,7 +66,7 @@ public class ArticleTextExtractor { @@ -66,7 +66,7 @@ public class ArticleTextExtractor {
}
public ArticleTextExtractor addUnlikely(String unlikelyMatches) {
return setUnlikely(unlikelyStr + "|" + unlikelyMatches);
return setUnlikely(unlikelyStr + '|' + unlikelyMatches);
}
public ArticleTextExtractor setPositive(String positiveStr) {
@ -76,7 +76,7 @@ public class ArticleTextExtractor { @@ -76,7 +76,7 @@ public class ArticleTextExtractor {
}
public ArticleTextExtractor addPositive(String pos) {
return setPositive(positiveStr + "|" + pos);
return setPositive(positiveStr + '|' + pos);
}
public ArticleTextExtractor setNegative(String negativeStr) {
@ -86,7 +86,7 @@ public class ArticleTextExtractor { @@ -86,7 +86,7 @@ public class ArticleTextExtractor {
}
public ArticleTextExtractor addNegative(String neg) {
setNegative(negativeStr + "|" + neg);
setNegative(negativeStr + '|' + neg);
return this;
}
@ -590,7 +590,7 @@ public class ArticleTextExtractor { @@ -590,7 +590,7 @@ public class ArticleTextExtractor {
continue;
if (counter > 0)
res.append("|");
res.append('|');
res.append(part);
counter++;

6
app/src/main/java/acr/browser/lightning/reading/Converter.java

@ -71,7 +71,7 @@ public class Converter { @@ -71,7 +71,7 @@ public class Converter {
}
// http1.1 says ISO-8859-1 is the default charset
if (charset.length() == 0)
if (charset.isEmpty())
charset = ISO;
return charset;
@ -133,7 +133,7 @@ public class Converter { @@ -133,7 +133,7 @@ public class Converter {
} catch (UnsupportedEncodingException e) {
Log.d(Constants.TAG,
"Using default encoding:" + UTF8 + " problem:" + e.getMessage()
+ " encoding:" + encoding + " " + url);
+ " encoding:" + encoding + ' ' + url);
encoding = UTF8;
}
@ -237,7 +237,7 @@ public class Converter { @@ -237,7 +237,7 @@ public class Converter {
return tmpEnc;
} catch (IOException ex) {
Log.e(Constants.TAG, "Couldn't reset stream to re-read with new encoding "
+ tmpEnc + " " + ex.toString());
+ tmpEnc + ' ' + ex.toString());
}
}
}

6
app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java

@ -74,7 +74,7 @@ public class HtmlFetcher { @@ -74,7 +74,7 @@ public class HtmlFetcher {
}
private String referrer = "https://github.com/karussell/snacktory";
private String userAgent = "Mozilla/5.0 (compatible; Snacktory; +" + referrer + ")";
private String userAgent = "Mozilla/5.0 (compatible; Snacktory; +" + referrer + ')';
private String cacheControl = "max-age=0";
private String language = "en-us";
private String accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
@ -308,9 +308,9 @@ public class HtmlFetcher { @@ -308,9 +308,9 @@ public class HtmlFetcher {
hConn.setInstanceFollowRedirects(true);
String encoding = hConn.getContentEncoding();
InputStream is;
if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
if ("gzip".equalsIgnoreCase(encoding)) {
is = new GZIPInputStream(hConn.getInputStream());
} else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
} else if ("deflate".equalsIgnoreCase(encoding)) {
is = new InflaterInputStream(hConn.getInputStream(), new Inflater(true));
} else {
is = hConn.getInputStream();

6
app/src/main/java/acr/browser/lightning/reading/OutputFormatter.java

@ -138,9 +138,9 @@ public class OutputFormatter { @@ -138,9 +138,9 @@ public class OutputFormatter {
} else if (child instanceof Element) {
Element element = (Element) child;
if (accum.length() > 0 && element.isBlock() && !lastCharIsWhitespace(accum))
accum.append(" ");
accum.append(' ');
else if (element.tagName().equals("br"))
accum.append(" ");
accum.append(' ');
appendTextSkipHidden(element, accum);
}
}
@ -166,6 +166,6 @@ public class OutputFormatter { @@ -166,6 +166,6 @@ public class OutputFormatter {
}
public OutputFormatter appendUnlikelyPattern(String str) {
return setUnlikelyPattern(unlikelyPattern.toString() + "|" + str);
return setUnlikelyPattern(unlikelyPattern.toString() + '|' + str);
}
}

9
app/src/main/java/acr/browser/lightning/reading/SHelper.java

@ -328,12 +328,12 @@ public class SHelper { @@ -328,12 +328,12 @@ public class SHelper {
sb.append(' ');
}
sb.append(root.tagName());
sb.append(":");
sb.append(':');
sb.append(root.ownText());
sb.append("\n");
sb.append('\n');
for (Element el : root.children()) {
sb.append(printNode(el, indentation + 1));
sb.append("\n");
sb.append('\n');
}
return sb.toString();
}
@ -392,8 +392,7 @@ public class SHelper { @@ -392,8 +392,7 @@ public class SHelper {
if (year < 0)
return null;
StringBuilder str = new StringBuilder();
str.append(year);
StringBuilder str = new StringBuilder(year);
if (month < 1)
return str.toString();

2
app/src/main/java/acr/browser/lightning/utils/AdBlock.java

@ -28,7 +28,7 @@ public class AdBlock { @@ -28,7 +28,7 @@ public class AdBlock {
private static final String TAB = "\t";
private static final String SPACE = " ";
private static final String EMPTY = "";
private static final Set<String> mBlockedDomainsList = new HashSet<>();
private final Set<String> mBlockedDomainsList = new HashSet<>();
private boolean mBlockAds;
private static final Locale mLocale = Locale.getDefault();
private static AdBlock mInstance;

4
app/src/main/java/acr/browser/lightning/utils/IntentUtils.java

@ -23,10 +23,10 @@ public class IntentUtils { @@ -23,10 +23,10 @@ public class IntentUtils {
private static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile("(?i)"
+ // switch on case insensitive matching
"("
'('
+ // begin group for schema
"(?:http|https|file):\\/\\/" + "|(?:inline|data|about|javascript):" + "|(?:.*:.*@)"
+ ")" + "(.*)");
+ ')' + "(.*)");
public IntentUtils(BrowserController controller) {
mActivity = controller.getActivity();

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

@ -218,7 +218,7 @@ public final class Utils { @@ -218,7 +218,7 @@ public final class Utils {
public static File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
String imageFileName = "JPEG_" + timeStamp + '_';
File storageDir = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
return File.createTempFile(imageFileName, /* prefix */

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

@ -69,14 +69,14 @@ public class LightningView { @@ -69,14 +69,14 @@ public class LightningView {
private final Title mTitle;
private WebView mWebView;
private boolean mIsIncognitoTab;
private final boolean mIsIncognitoTab;
private BrowserController mBrowserController;
private GestureDetector mGestureDetector;
private final Activity mActivity;
private static String mHomepage;
private static String mDefaultUserAgent;
// TODO fix so that mWebpageBitmap can be static - static changes the icon when switching from light to dark and then back to light
private Bitmap mWebpageBitmap;
private final Bitmap mWebpageBitmap;
private static PreferenceManager mPreferences;
private final AdBlock mAdBlock;
private IntentUtils mIntentUtils;
@ -163,8 +163,7 @@ public class LightningView { @@ -163,8 +163,7 @@ public class LightningView {
* @return the URL to load
*/
private String getHomepage() {
StringBuilder homepageBuilder = new StringBuilder();
homepageBuilder.append(StartPage.HEAD);
StringBuilder homepageBuilder = new StringBuilder(StartPage.HEAD);
String icon;
String searchUrl;
switch (mPreferences.getSearchChoice()) {
@ -440,7 +439,7 @@ public class LightningView { @@ -440,7 +439,7 @@ public class LightningView {
WebSettings settings = mWebView.getSettings();
switch (choice) {
case 1:
if (API > 16) {
if (API >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
settings.setUserAgentString(WebSettings.getDefaultUserAgent(context));
} else {
settings.setUserAgentString(mDefaultUserAgent);
@ -612,7 +611,7 @@ public class LightningView { @@ -612,7 +611,7 @@ public class LightningView {
public synchronized void find(String text) {
if (mWebView != null) {
if (API > 16) {
if (API >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mWebView.findAllAsync(text);
} else {
mWebView.findAll(text);

2
app/src/main/res/layout/video_loading_progress.xml

@ -31,6 +31,6 @@ @@ -31,6 +31,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Loading..." android:textSize="14sp"
android:text="@string/loading" android:textSize="14sp"
android:textColor="?android:attr/textColorPrimary" />
</LinearLayout>
Loading…
Cancel
Save