Skip to content

Commit

Permalink
Infer nullity with annotations (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun authored Jan 8, 2020
1 parent c6e02b7 commit ac3a194
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 57 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog for the Mapbox Gestures for Android

## 0.6.0 - January 8, 2020
#### Major changes
- Replace appcompat dependencies with AndroidX [#94](https://github.com/mapbox/mapbox-gestures-android/pull/94)

#### Minor features and bug fixes
- Use NonNull in gesture listener interfaces to improve consumption with the Kotlin programming language [#95](https://github.com/mapbox/mapbox-gestures-android/pull/95)

## 0.5.1 - August 20, 2019
#### Bug fixes
- Fixed a bug where quick-scale was registered during a move gesture that followed a double-tap [#88](https://github.com/mapbox/mapbox-gestures-android/pull/88)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -197,7 +198,7 @@ public boolean onScale(StandardScaleGestureDetector detector) {

androidGesturesManager.setRotateGestureListener(new RotateGestureDetector.SimpleOnRotateGestureListener() {
@Override
public boolean onRotate(RotateGestureDetector detector, float rotationDegreesSinceLast,
public boolean onRotate(@NonNull RotateGestureDetector detector, float rotationDegreesSinceLast,
float rotationDegreesSinceFirst) {
icon.setRotation(icon.getRotation() - rotationDegreesSinceLast);
return true;
Expand Down Expand Up @@ -226,7 +227,7 @@ public boolean onDoubleTap(MotionEvent e) {
new MultiFingerTapGestureDetector.OnMultiFingerTapGestureListener() {

@Override
public boolean onMultiFingerTap(MultiFingerTapGestureDetector detector, int pointersCount) {
public boolean onMultiFingerTap(@NonNull MultiFingerTapGestureDetector detector, int pointersCount) {
if (pointersCount == 2) {
rescaleIcon(0.65f);
}
Expand All @@ -236,7 +237,9 @@ public boolean onMultiFingerTap(MultiFingerTapGestureDetector detector, int poin

androidGesturesManager.setShoveGestureListener(new ShoveGestureDetector.SimpleOnShoveGestureListener() {
@Override
public boolean onShove(ShoveGestureDetector detector, float deltaPixelsSinceLast, float deltaPixelsSinceStart) {
public boolean onShove(@NonNull ShoveGestureDetector detector,
float deltaPixelsSinceLast,
float deltaPixelsSinceStart) {
icon.setRotationX(icon.getRotationX() - deltaPixelsSinceLast);
return true;
}
Expand All @@ -245,7 +248,7 @@ public boolean onShove(ShoveGestureDetector detector, float deltaPixelsSinceLast
androidGesturesManager.setSidewaysShoveGestureListener(
new SidewaysShoveGestureDetector.SimpleOnSidewaysShoveGestureListener() {
@Override
public boolean onSidewaysShove(SidewaysShoveGestureDetector detector, float deltaPixelsSinceLast,
public boolean onSidewaysShove(@NonNull SidewaysShoveGestureDetector detector, float deltaPixelsSinceLast,
float deltaPixelsSinceStart) {
icon.setRotationY(icon.getRotationY() + deltaPixelsSinceLast);
return true;
Expand All @@ -258,19 +261,19 @@ public boolean onSidewaysShove(SidewaysShoveGestureDetector detector, float delt
private final MoveGestureDetector.OnMoveGestureListener onMoveGestureListener =
new MoveGestureDetector.OnMoveGestureListener() {
@Override
public boolean onMoveBegin(MoveGestureDetector detector) {
public boolean onMoveBegin(@NonNull MoveGestureDetector detector) {
return true;
}

@Override
public boolean onMove(MoveGestureDetector detector, float distanceX, float distanceY) {
public boolean onMove(@NonNull MoveGestureDetector detector, float distanceX, float distanceY) {
icon.setTranslationX(icon.getTranslationX() - distanceX);
icon.setTranslationY(icon.getTranslationY() - distanceY);
return true;
}

@Override
public void onMoveEnd(MoveGestureDetector detector, float velocityX, float velocityY) {
public void onMoveEnd(@NonNull MoveGestureDetector detector, float velocityX, float velocityY) {

}
};
Expand Down
4 changes: 3 additions & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ ext {
espresso : '3.2.0',
kotlin : '1.3.41',
appCompat : '1.0.0',
core : '1.0.0'
core : '1.0.0',
annotation : '1.0.0'
]

pluginVersion = [
Expand All @@ -34,6 +35,7 @@ ext {
// support
supportAppcompatV7 : "androidx.appcompat:appcompat:${version.appCompat}",
supportCompat : "androidx.core:core:${version.core}",
annotations : "androidx.annotation:annotation:${version.annotation}",

// timber
timber : "com.jakewharton.timber:timber:${version.timber}",
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation dependenciesList.supportCompat

implementation dependenciesList.annotations
testImplementation dependenciesList.kotlinLib
testImplementation dependenciesList.junit
testImplementation dependenciesList.mockito
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;
import androidx.annotation.UiThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.MotionEvent;
import android.view.WindowManager;

Expand Down Expand Up @@ -37,7 +39,7 @@ protected boolean onTouchEvent(MotionEvent motionEvent) {
return analyze(motionEvent);
}

private boolean analyze(MotionEvent motionEvent) {
private boolean analyze(@Nullable MotionEvent motionEvent) {
if (motionEvent == null) {
return false;
}
Expand All @@ -59,7 +61,7 @@ private boolean analyze(MotionEvent motionEvent) {
return analyzeEvent(motionEvent);
}

protected abstract boolean analyzeEvent(MotionEvent motionEvent);
protected abstract boolean analyzeEvent(@NonNull MotionEvent motionEvent);

protected boolean canExecute(@AndroidGesturesManager.GestureType int invokedGestureType) {
if (listener == null || !isEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface OnMoveGestureListener {
* @return true if you want to receive subsequent {@link #onMove(MoveGestureDetector, float, float)} callbacks,
* false if you want to ignore this gesture.
*/
boolean onMoveBegin(MoveGestureDetector detector);
boolean onMoveBegin(@NonNull MoveGestureDetector detector);

/**
* Called for every move change during the gesture.
Expand All @@ -69,7 +69,7 @@ public interface OnMoveGestureListener {
* @param distanceY Y distance of the focal point in pixel since last call
* @return true if the gesture was handled, false otherwise
*/
boolean onMove(MoveGestureDetector detector, float distanceX, float distanceY);
boolean onMove(@NonNull MoveGestureDetector detector, float distanceX, float distanceY);

/**
* Indicates that the move gesture ended.
Expand All @@ -78,29 +78,29 @@ public interface OnMoveGestureListener {
* @param velocityY velocityY of the gesture in the moment of lifting the fingers
* @param detector this detector
*/
void onMoveEnd(MoveGestureDetector detector, float velocityX, float velocityY);
void onMoveEnd(@NonNull MoveGestureDetector detector, float velocityX, float velocityY);
}

public static class SimpleOnMoveGestureListener implements OnMoveGestureListener {

@Override
public boolean onMoveBegin(MoveGestureDetector detector) {
public boolean onMoveBegin(@NonNull MoveGestureDetector detector) {
return true;
}

@Override
public boolean onMove(MoveGestureDetector detector, float distanceX, float distanceY) {
public boolean onMove(@NonNull MoveGestureDetector detector, float distanceX, float distanceY) {
return false;
}

@Override
public void onMoveEnd(MoveGestureDetector detector, float velocityX, float velocityY) {
public void onMoveEnd(@NonNull MoveGestureDetector detector, float velocityX, float velocityY) {
// No implementation
}
}

@Override
protected boolean analyzeEvent(MotionEvent motionEvent) {
protected boolean analyzeEvent(@NonNull MotionEvent motionEvent) {
switch (motionEvent.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import android.content.Context;
import android.graphics.PointF;
import android.os.Build;

import androidx.annotation.DimenRes;
import androidx.annotation.UiThread;
import androidx.annotation.NonNull;

import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
Expand Down Expand Up @@ -62,7 +65,7 @@ public MultiFingerGesture(Context context, AndroidGesturesManager gesturesManage
}

@Override
protected boolean analyzeEvent(MotionEvent motionEvent) {
protected boolean analyzeEvent(@NonNull MotionEvent motionEvent) {
int action = motionEvent.getActionMasked();

if (action == MotionEvent.ACTION_DOWN) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.mapbox.android.gestures;

import android.content.Context;

import androidx.annotation.DimenRes;
import androidx.annotation.UiThread;
import androidx.annotation.NonNull;

import android.view.MotionEvent;

import java.util.HashMap;
Expand Down Expand Up @@ -34,11 +37,11 @@ public MultiFingerTapGestureDetector(Context context, AndroidGesturesManager ges
}

public interface OnMultiFingerTapGestureListener {
boolean onMultiFingerTap(MultiFingerTapGestureDetector detector, int pointersCount);
boolean onMultiFingerTap(@NonNull MultiFingerTapGestureDetector detector, int pointersCount);
}

@Override
protected boolean analyzeEvent(MotionEvent motionEvent) {
protected boolean analyzeEvent(@NonNull MotionEvent motionEvent) {
super.analyzeEvent(motionEvent);

int action = motionEvent.getActionMasked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ProgressiveGesture(Context context, AndroidGesturesManager gesturesManage
protected abstract Set<Integer> provideHandledTypes();

@Override
protected boolean analyzeEvent(MotionEvent motionEvent) {
protected boolean analyzeEvent(@NonNull MotionEvent motionEvent) {
int action = motionEvent.getActionMasked();
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN
|| action == MotionEvent.ACTION_POINTER_UP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public interface OnRotateGestureListener {
* @return true if you want to receive subsequent {@link #onRotate(RotateGestureDetector, float, float)} callbacks,
* false if you want to ignore this gesture.
*/
boolean onRotateBegin(RotateGestureDetector detector);
boolean onRotateBegin(@NonNull RotateGestureDetector detector);

/**
* Called for every rotation change during the gesture.
Expand All @@ -55,7 +55,9 @@ public interface OnRotateGestureListener {
* @param rotationDegreesSinceFirst rotation change since the start of the gesture
* @return true if the gesture was handled, false otherwise
*/
boolean onRotate(RotateGestureDetector detector, float rotationDegreesSinceLast, float rotationDegreesSinceFirst);
boolean onRotate(@NonNull RotateGestureDetector detector,
float rotationDegreesSinceLast,
float rotationDegreesSinceFirst);

/**
* Indicates that the rotation gesture ended.
Expand All @@ -65,24 +67,27 @@ public interface OnRotateGestureListener {
* @param angularVelocity angularVelocity of the gesture in the moment of lifting the fingers
* @param detector this detector
*/
void onRotateEnd(RotateGestureDetector detector, float velocityX, float velocityY, float angularVelocity);
void onRotateEnd(@NonNull RotateGestureDetector detector, float velocityX, float velocityY, float angularVelocity);
}

public static class SimpleOnRotateGestureListener implements OnRotateGestureListener {

@Override
public boolean onRotateBegin(RotateGestureDetector detector) {
public boolean onRotateBegin(@NonNull RotateGestureDetector detector) {
return true;
}

@Override
public boolean onRotate(RotateGestureDetector detector, float rotationDegreesSinceLast,
public boolean onRotate(@NonNull RotateGestureDetector detector, float rotationDegreesSinceLast,
float rotationDegreesSinceFirst) {
return true;
}

@Override
public void onRotateEnd(RotateGestureDetector detector, float velocityX, float velocityY, float angularVelocity) {
public void onRotateEnd(@NonNull RotateGestureDetector detector,
float velocityX,
float velocityY,
float angularVelocity) {
// No implementation
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface OnShoveGestureListener {
* @return true if you want to receive subsequent {@link #onShove(ShoveGestureDetector, float, float)} callbacks,
* false if you want to ignore this gesture.
*/
boolean onShoveBegin(ShoveGestureDetector detector);
boolean onShoveBegin(@NonNull ShoveGestureDetector detector);

/**
* Called for every shove change during the gesture.
Expand All @@ -57,7 +57,7 @@ public interface OnShoveGestureListener {
* @param deltaPixelsSinceStart pixels delta change since the start of the gesture
* @return true if the gesture was handled, false otherwise
*/
boolean onShove(ShoveGestureDetector detector, float deltaPixelsSinceLast, float deltaPixelsSinceStart);
boolean onShove(@NonNull ShoveGestureDetector detector, float deltaPixelsSinceLast, float deltaPixelsSinceStart);

/**
* Indicates that the shove gesture ended.
Expand All @@ -66,22 +66,24 @@ public interface OnShoveGestureListener {
* @param velocityY velocityY of the gesture in the moment of lifting the fingers
* @param detector this detector
*/
void onShoveEnd(ShoveGestureDetector detector, float velocityX, float velocityY);
void onShoveEnd(@NonNull ShoveGestureDetector detector, float velocityX, float velocityY);
}

public static class SimpleOnShoveGestureListener implements OnShoveGestureListener {
@Override
public boolean onShoveBegin(ShoveGestureDetector detector) {
public boolean onShoveBegin(@NonNull ShoveGestureDetector detector) {
return true;
}

@Override
public boolean onShove(ShoveGestureDetector detector, float deltaPixelsSinceLast, float deltaPixelsSinceStart) {
public boolean onShove(@NonNull ShoveGestureDetector detector,
float deltaPixelsSinceLast,
float deltaPixelsSinceStart) {
return false;
}

@Override
public void onShoveEnd(ShoveGestureDetector detector, float velocityX, float velocityY) {
public void onShoveEnd(@NonNull ShoveGestureDetector detector, float velocityX, float velocityY) {
// No Implementation
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface OnSidewaysShoveGestureListener {
* {@link #onSidewaysShove(SidewaysShoveGestureDetector, float, float)} callbacks,
* false if you want to ignore this gesture.
*/
boolean onSidewaysShoveBegin(SidewaysShoveGestureDetector detector);
boolean onSidewaysShoveBegin(@NonNull SidewaysShoveGestureDetector detector);

/**
* Called for every sideways shove change during the gesture.
Expand All @@ -59,7 +59,7 @@ public interface OnSidewaysShoveGestureListener {
* @param deltaPixelsSinceStart pixels delta change since the start of the gesture
* @return true if the gesture was handled, false otherwise
*/
boolean onSidewaysShove(SidewaysShoveGestureDetector detector, float deltaPixelsSinceLast,
boolean onSidewaysShove(@NonNull SidewaysShoveGestureDetector detector, float deltaPixelsSinceLast,
float deltaPixelsSinceStart);

/**
Expand All @@ -69,23 +69,23 @@ boolean onSidewaysShove(SidewaysShoveGestureDetector detector, float deltaPixels
* @param velocityY velocityY of the gesture in the moment of lifting the fingers
* @param detector this detector
*/
void onSidewaysShoveEnd(SidewaysShoveGestureDetector detector, float velocityX, float velocityY);
void onSidewaysShoveEnd(@NonNull SidewaysShoveGestureDetector detector, float velocityX, float velocityY);
}

public static class SimpleOnSidewaysShoveGestureListener implements OnSidewaysShoveGestureListener {
@Override
public boolean onSidewaysShoveBegin(SidewaysShoveGestureDetector detector) {
public boolean onSidewaysShoveBegin(@NonNull SidewaysShoveGestureDetector detector) {
return true;
}

@Override
public boolean onSidewaysShove(SidewaysShoveGestureDetector detector, float deltaPixelsSinceLast,
public boolean onSidewaysShove(@NonNull SidewaysShoveGestureDetector detector, float deltaPixelsSinceLast,
float deltaPixelsSinceStart) {
return false;
}

@Override
public void onSidewaysShoveEnd(SidewaysShoveGestureDetector detector, float velocityX, float velocityY) {
public void onSidewaysShoveEnd(@NonNull SidewaysShoveGestureDetector detector, float velocityX, float velocityY) {
// No Implementation
}
}
Expand Down
Loading

0 comments on commit ac3a194

Please sign in to comment.