Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - infer nullity
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Oct 12, 2018
1 parent a436fd2 commit 6177427
Show file tree
Hide file tree
Showing 131 changed files with 1,375 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public final class Mapbox {
private static Mapbox INSTANCE;

private Context context;
@Nullable
private String accessToken;
private Boolean connected;
@Nullable
private TelemetryDefinition telemetry;

/**
Expand All @@ -47,6 +49,7 @@ public final class Mapbox {
* @param accessToken Mapbox access token
* @return the single instance of Mapbox
*/
@NonNull
@UiThread
public static synchronized Mapbox getInstance(@NonNull Context context, @Nullable String accessToken) {
ThreadUtils.checkThread("Mapbox");
Expand Down Expand Up @@ -171,7 +174,7 @@ private static void validateMapbox() {
* @param accessToken the access token to validate
* @return true is valid, false otherwise
*/
static boolean isAccessTokenValid(String accessToken) {
static boolean isAccessTokenValid(@Nullable String accessToken) {
if (accessToken == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.support.annotation.NonNull;

import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;

Expand Down Expand Up @@ -121,11 +122,11 @@ public int compareTo(@NonNull Annotation annotation) {
* @return returns true both id's match else returns false.
*/
@Override
public boolean equals(Object object) {
public boolean equals(@Nullable Object object) {
if (this == object) {
return true;
}
if (object == null || !(object instanceof Annotation)) {
if (!(object instanceof Annotation)) {
return false;
}
Annotation that = (Annotation) object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.support.annotation.Keep;

import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.ArrayList;
Expand All @@ -27,6 +28,7 @@ protected BasePointCollection() {
*
* @return A {@link List} of points.
*/
@NonNull
public List<LatLng> getPoints() {
return new ArrayList<>(points);
}
Expand All @@ -37,7 +39,7 @@ public List<LatLng> getPoints() {
*
* @param points A {@link List} of {@link LatLng} points making up the polyline.
*/
public void setPoints(List<LatLng> points) {
public void setPoints(@NonNull List<LatLng> points) {
this.points = new ArrayList<>(points);
update();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;

class Bubble extends Drawable {

@NonNull
private RectF rect;
private float arrowWidth;
private float arrowHeight;
private float arrowPosition;
private float cornersRadius;
@NonNull
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private float strokeWidth;
private Paint strokePaint;
private Path strokePath;
@NonNull
private Path path = new Path();

Bubble(RectF rect, ArrowDirection arrowDirection, float arrowWidth, float arrowHeight, float arrowPosition,
float cornersRadius, int bubbleColor, float strokeWidth, int strokeColor) {
Bubble(@NonNull RectF rect, @NonNull ArrowDirection arrowDirection, float arrowWidth, float arrowHeight,
float arrowPosition, float cornersRadius, int bubbleColor, float strokeWidth, int strokeColor) {
this.rect = rect;
this.arrowWidth = arrowWidth;
this.arrowHeight = arrowHeight;
Expand All @@ -49,7 +53,7 @@ protected void onBoundsChange(Rect bounds) {
}

@Override
public void draw(Canvas canvas) {
public void draw(@NonNull Canvas canvas) {
if (strokeWidth > 0) {
canvas.drawPath(strokePath, strokePaint);
}
Expand Down Expand Up @@ -81,7 +85,7 @@ public int getIntrinsicHeight() {
return (int) rect.height();
}

private void initPath(ArrowDirection arrowDirection, Path path, float strokeWidth) {
private void initPath(@NonNull ArrowDirection arrowDirection, @NonNull Path path, float strokeWidth) {
switch (arrowDirection.getValue()) {
case ArrowDirection.LEFT:
if (cornersRadius <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.RectF;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.LinearLayout;
Expand All @@ -17,6 +18,7 @@
public class BubbleLayout extends LinearLayout {

public static final float DEFAULT_STROKE_WIDTH = -1;
@NonNull
private ArrowDirection arrowDirection;
private float arrowWidth;
private float arrowHeight;
Expand All @@ -32,7 +34,7 @@ public class BubbleLayout extends LinearLayout {
*
* @param context The context used to inflate this bubble layout
*/
public BubbleLayout(Context context) {
public BubbleLayout(@NonNull Context context) {
this(context, null, 0);
}

Expand All @@ -42,7 +44,7 @@ public BubbleLayout(Context context) {
* @param context The context used to inflate this bubble layout
* @param attrs The attribute set to initialise this bubble layout from
*/
public BubbleLayout(Context context, AttributeSet attrs) {
public BubbleLayout(@NonNull Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

Expand All @@ -53,7 +55,7 @@ public BubbleLayout(Context context, AttributeSet attrs) {
* @param attrs The attribute set to initialise this bubble layout from
* @param defStyleAttr The default style to apply this bubble layout with
*/
public BubbleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
public BubbleLayout(@NonNull Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.mapbox_BubbleLayout);
Expand Down Expand Up @@ -84,7 +86,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}

@Override
protected void dispatchDraw(Canvas canvas) {
protected void dispatchDraw(@NonNull Canvas canvas) {
if (bubble != null) {
bubble.draw(canvas);
}
Expand All @@ -111,7 +113,8 @@ public ArrowDirection getArrowDirection() {
* @param arrowDirection The direction of the arrow
* @return this
*/
public BubbleLayout setArrowDirection(ArrowDirection arrowDirection) {
@NonNull
public BubbleLayout setArrowDirection(@NonNull ArrowDirection arrowDirection) {
resetPadding();
this.arrowDirection = arrowDirection;
initPadding();
Expand All @@ -133,6 +136,7 @@ public float getArrowWidth() {
* @param arrowWidth The width of the arrow
* @return this
*/
@NonNull
public BubbleLayout setArrowWidth(float arrowWidth) {
resetPadding();
this.arrowWidth = arrowWidth;
Expand All @@ -155,6 +159,7 @@ public float getArrowHeight() {
* @param arrowHeight The height of the arrow
* @return this
*/
@NonNull
public BubbleLayout setArrowHeight(float arrowHeight) {
resetPadding();
this.arrowHeight = arrowHeight;
Expand All @@ -177,6 +182,7 @@ public float getArrowPosition() {
* @param arrowPosition The arrow position
* @return this
*/
@NonNull
public BubbleLayout setArrowPosition(float arrowPosition) {
resetPadding();
this.arrowPosition = arrowPosition;
Expand All @@ -199,6 +205,7 @@ public float getCornersRadius() {
* @param cornersRadius The corner radius
* @return this
*/
@NonNull
public BubbleLayout setCornersRadius(float cornersRadius) {
this.cornersRadius = cornersRadius;
requestLayout();
Expand All @@ -220,6 +227,7 @@ public int getBubbleColor() {
* @param bubbleColor The buble color
* @return this
*/
@NonNull
public BubbleLayout setBubbleColor(int bubbleColor) {
this.bubbleColor = bubbleColor;
requestLayout();
Expand All @@ -241,6 +249,7 @@ public float getStrokeWidth() {
* @param strokeWidth The stroke width
* @return this
*/
@NonNull
public BubbleLayout setStrokeWidth(float strokeWidth) {
resetPadding();
this.strokeWidth = strokeWidth;
Expand All @@ -263,6 +272,7 @@ public int getStrokeColor() {
* @param strokeColor The stroke color
* @return this
*/
@NonNull
public BubbleLayout setStrokeColor(int strokeColor) {
this.strokeColor = strokeColor;
requestLayout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class BubblePopupHelper {

@NonNull
static PopupWindow create(@NonNull Context context, @NonNull BubbleLayout bubbleLayout) {
PopupWindow popupWindow = new PopupWindow(context);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mapbox.mapboxsdk.annotations;

import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -69,6 +71,7 @@ public float getScale() {
*
* @return the bytes of the bitmap
*/
@NonNull
public byte[] toBytes() {
if (mBitmap == null) {
throw new IllegalStateException("Required to set a Icon before calling toBytes");
Expand All @@ -85,7 +88,7 @@ public byte[] toBytes() {
* @return True if the icon being passed in matches this icon object. Else, false.
*/
@Override
public boolean equals(Object object) {
public boolean equals(@Nullable Object object) {
if (this == object) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.graphics.PointF;
import android.os.Build;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -47,17 +49,17 @@ public class InfoWindow {
@LayoutRes
private int layoutRes;

InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) {
InfoWindow(@NonNull MapView mapView, int layoutResId, @NonNull MapboxMap mapboxMap) {
layoutRes = layoutResId;
View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false);
initialize(view, mapboxMap);
}

InfoWindow(View view, MapboxMap mapboxMap) {
InfoWindow(@NonNull View view, @NonNull MapboxMap mapboxMap) {
initialize(view, mapboxMap);
}

private void initialize(View view, MapboxMap mapboxMap) {
private void initialize(@NonNull View view, @NonNull MapboxMap mapboxMap) {
this.mapboxMap = new WeakReference<>(mapboxMap);
isVisible = false;
this.view = new WeakReference<>(view);
Expand Down Expand Up @@ -116,7 +118,8 @@ private void closeInfoWindow() {
* the view from the object position.
* @return this {@link InfoWindow}.
*/
InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offsetX, int offsetY) {
@NonNull
InfoWindow open(@NonNull MapView mapView, Marker boundMarker, @NonNull LatLng position, int offsetX, int offsetY) {
setBoundMarker(boundMarker);

MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
Expand Down Expand Up @@ -213,6 +216,7 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset
*
* @return This {@link InfoWindow}
*/
@NonNull
InfoWindow close() {
MapboxMap mapboxMap = this.mapboxMap.get();
if (isVisible && mapboxMap != null) {
Expand All @@ -239,7 +243,7 @@ InfoWindow close() {
*
* @param overlayItem the tapped overlay item
*/
void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView) {
void adaptDefaultMarker(@NonNull Marker overlayItem, MapboxMap mapboxMap, @NonNull MapView mapView) {
View view = this.view.get();
if (view == null) {
view = LayoutInflater.from(mapView.getContext()).inflate(layoutRes, mapView, false);
Expand All @@ -265,11 +269,13 @@ void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView
}
}

@NonNull
InfoWindow setBoundMarker(Marker boundMarker) {
this.boundMarker = new WeakReference<>(boundMarker);
return this;
}

@Nullable
Marker getBoundMarker() {
if (boundMarker == null) {
return null;
Expand Down Expand Up @@ -307,6 +313,7 @@ void onContentUpdate() {
}
}

@Nullable
private final ViewTreeObserver.OnGlobalLayoutListener contentUpdateListener =
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
Expand All @@ -329,6 +336,7 @@ public void onGlobalLayout() {
*
* @return This {@link InfoWindow}'s current View.
*/
@Nullable
public View getView() {
return view != null ? view.get() : null;
}
Expand Down
Loading

0 comments on commit 6177427

Please sign in to comment.