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

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

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

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

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

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

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

Loading…
Cancel
Save