Browse Source

Null annotations for rest of classes

master
Anthony Restaino 9 years ago
parent
commit
359a252f24
  1. 35
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  2. 3
      app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java
  3. 4
      app/src/main/java/acr/browser/lightning/download/WebAddress.java
  4. 10
      app/src/main/java/acr/browser/lightning/view/AnimatedProgressBar.java

35
app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

@ -12,6 +12,8 @@ import android.content.pm.ResolveInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -54,8 +56,8 @@ public class DownloadHandler {
* @param contentDisposition Content-disposition http header, if present. * @param contentDisposition Content-disposition http header, if present.
* @param mimetype The mimetype of the content reported by the server * @param mimetype The mimetype of the content reported by the server
*/ */
public static void onDownloadStart(Context context, PreferenceManager manager, String url, String userAgent, public static void onDownloadStart(@NonNull Context context, @NonNull PreferenceManager manager, String url, String userAgent,
String contentDisposition, String mimetype) { @Nullable String contentDisposition, String mimetype) {
// if we're dealing wih A/V content that's not explicitly marked // if we're dealing wih A/V content that's not explicitly marked
// for download, check if it's streamable. // for download, check if it's streamable.
if (contentDisposition == null if (contentDisposition == null
@ -95,7 +97,8 @@ public class DownloadHandler {
// This is to work around the fact that java.net.URI throws Exceptions // This is to work around the fact that java.net.URI throws Exceptions
// instead of just encoding URL's properly // instead of just encoding URL's properly
// Helper method for onDownloadStartNoStream // Helper method for onDownloadStartNoStream
private static String encodePath(String path) { @NonNull
private static String encodePath(@NonNull String path) {
char[] chars = path.toCharArray(); char[] chars = path.toCharArray();
boolean needed = false; boolean needed = false;
@ -133,9 +136,9 @@ public class DownloadHandler {
* @param mimetype The mimetype of the content reported by the server * @param mimetype The mimetype of the content reported by the server
*/ */
/* package */ /* package */
private static void onDownloadStartNoStream(final Context context, PreferenceManager preferences, private static void onDownloadStartNoStream(@NonNull final Context context, @NonNull PreferenceManager preferences,
String url, String userAgent, String url, String userAgent,
String contentDisposition, String mimetype) { String contentDisposition, @Nullable String mimetype) {
final Bus eventBus = BrowserApp.getBus(context); final Bus eventBus = BrowserApp.getBus(context);
final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype); final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
@ -190,14 +193,8 @@ public class DownloadHandler {
String location = preferences.getDownloadDirectory(); String location = preferences.getDownloadDirectory();
Uri downloadFolder; Uri downloadFolder;
if (location != null) { location = addNecessarySlashes(location);
location = addNecessarySlashes(location); downloadFolder = Uri.parse(location);
downloadFolder = Uri.parse(location);
} else {
location = addNecessarySlashes(DEFAULT_DOWNLOAD_PATH);
downloadFolder = Uri.parse(location);
preferences.setDownloadDirectory(location);
}
File dir = new File(downloadFolder.getPath()); File dir = new File(downloadFolder.getPath());
if (!dir.isDirectory() && !dir.mkdirs()) { if (!dir.isDirectory() && !dir.mkdirs()) {
@ -264,7 +261,7 @@ public class DownloadHandler {
* @return returns true if the directory can be written to or is in a directory that can * @return returns true if the directory can be written to or is in a directory that can
* be written to. false if there is no write access. * be written to. false if there is no write access.
*/ */
public static boolean isWriteAccessAvailable(String directory) { public static boolean isWriteAccessAvailable(@Nullable String directory) {
if (directory == null || directory.isEmpty()) { if (directory == null || directory.isEmpty()) {
return false; return false;
} }
@ -275,6 +272,7 @@ public class DownloadHandler {
if (!file.exists()) { if (!file.exists()) {
try { try {
if (file.createNewFile()) { if (file.createNewFile()) {
//noinspection ResultOfMethodCallIgnored
file.delete(); file.delete();
} }
return true; return true;
@ -295,7 +293,8 @@ public class DownloadHandler {
* @param directory the directory to find the first existent parent * @param directory the directory to find the first existent parent
* @return the first existent parent * @return the first existent parent
*/ */
private static String getFirstRealParentDirectory(String directory) { @Nullable
private static String getFirstRealParentDirectory(@Nullable String directory) {
while (true) { while (true) {
if (directory == null || directory.isEmpty()) { if (directory == null || directory.isEmpty()) {
return "/"; return "/";
@ -321,10 +320,11 @@ public class DownloadHandler {
} }
} }
private static boolean isWriteAccessAvailable(Uri fileUri) { private static boolean isWriteAccessAvailable(@NonNull Uri fileUri) {
File file = new File(fileUri.getPath()); File file = new File(fileUri.getPath());
try { try {
if (file.createNewFile()) { if (file.createNewFile()) {
//noinspection ResultOfMethodCallIgnored
file.delete(); file.delete();
} }
return true; return true;
@ -333,7 +333,8 @@ public class DownloadHandler {
} }
} }
public static String addNecessarySlashes(String originalPath) { @NonNull
public static String addNecessarySlashes(@Nullable String originalPath) {
if (originalPath == null || originalPath.length() == 0) { if (originalPath == null || originalPath.length() == 0) {
return "/"; return "/";
} }

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

@ -8,6 +8,7 @@ import android.content.Context;
import android.os.Environment; import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.support.annotation.NonNull;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
import android.webkit.URLUtil; import android.webkit.URLUtil;
@ -83,7 +84,7 @@ class FetchUrlMimeType extends Thread {
contentDisposition = contentDispositionHeader; contentDisposition = contentDispositionHeader;
} }
} }
} catch (IllegalArgumentException | IOException ex) { } catch (@NonNull IllegalArgumentException | IOException ex) {
if (connection != null) if (connection != null)
connection.disconnect(); connection.disconnect();
} finally { } finally {

4
app/src/main/java/acr/browser/lightning/download/WebAddress.java

@ -4,6 +4,7 @@
package acr.browser.lightning.download; package acr.browser.lightning.download;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -45,7 +46,7 @@ class WebAddress {
/** /**
* Parses given URI-like string. * Parses given URI-like string.
*/ */
public WebAddress(String address) throws IllegalArgumentException { public WebAddress(@Nullable String address) throws IllegalArgumentException {
if (address == null) { if (address == null) {
throw new IllegalArgumentException("address can't be null"); throw new IllegalArgumentException("address can't be null");
@ -113,6 +114,7 @@ class WebAddress {
} }
} }
@NonNull
@Override @Override
public String toString() { public String toString() {

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

@ -8,6 +8,7 @@ import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.animation.Animation; import android.view.animation.Animation;
@ -39,12 +40,12 @@ public class AnimatedProgressBar extends LinearLayout {
private int mDrawWidth = 0; private int mDrawWidth = 0;
private int mProgressColor; private int mProgressColor;
public AnimatedProgressBar(Context context, AttributeSet attrs) { public AnimatedProgressBar(@NonNull Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
init(context, attrs); init(context, attrs);
} }
public AnimatedProgressBar(Context context, AttributeSet attrs, int defStyleAttr) { public AnimatedProgressBar(@NonNull Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
init(context, attrs); init(context, attrs);
} }
@ -55,7 +56,7 @@ public class AnimatedProgressBar extends LinearLayout {
* @param context is the context passed by the constructor * @param context is the context passed by the constructor
* @param attrs is the attribute set passed by the constructor * @param attrs is the attribute set passed by the constructor
*/ */
private void init(final Context context, AttributeSet attrs) { private void init(@NonNull final Context context, AttributeSet attrs) {
TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AnimatedProgressBar, 0, 0); TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AnimatedProgressBar, 0, 0);
int backgroundColor; int backgroundColor;
try { // Retrieve the style of the progress bar that the user hopefully set try { // Retrieve the style of the progress bar that the user hopefully set
@ -90,7 +91,7 @@ public class AnimatedProgressBar extends LinearLayout {
private final Rect mRect = new Rect(); private final Rect mRect = new Rect();
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(@NonNull Canvas canvas) {
mPaint.setColor(mProgressColor); mPaint.setColor(mProgressColor);
mPaint.setStrokeWidth(10); mPaint.setStrokeWidth(10);
mRect.right = mRect.left + mDrawWidth; mRect.right = mRect.left + mDrawWidth;
@ -209,6 +210,7 @@ public class AnimatedProgressBar extends LinearLayout {
super.onRestoreInstanceState(state); super.onRestoreInstanceState(state);
} }
@NonNull
@Override @Override
protected Parcelable onSaveInstanceState() { protected Parcelable onSaveInstanceState() {

Loading…
Cancel
Save