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

Commit

Permalink
Merge branch 'release-candidate' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Wei committed Dec 4, 2016
2 parents d9d11b1 + 568d406 commit 9e373c5
Show file tree
Hide file tree
Showing 19 changed files with 2,721 additions and 17 deletions.
1 change: 1 addition & 0 deletions .arcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
],
"arcanist_configuration": "HookConphig",
"phabricator.uri": "http://codereview.cc/",
"repository.callsign": "MDMGESTURESANDROID",
"arc.land.onto.default": "develop",
"arc.feature.start.default": "origin/develop"
}
167 changes: 167 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# 1.0.0

## New features

New gesture recognizers for drag, scale, and rotate.

## Source changes

* [Move gesture recognizers out from direct-manipulation-android into its own repo.](https://github.com/material-motion/gestures-android/commit/25c61043d739ab1440cff59624bb137c9cbd6514) (Mark Wei)

## API changes

Auto-generated by running:

apidiff origin/stable release-candidate android library

## DragGestureRecognizer

*new* class: `DragGestureRecognizer`

*new* constructor: `DragGestureRecognizer()`

*new* field: `int dragSlop`

*new* method: `float getTranslationX()`

*new* method: `float getTranslationY()`

*new* method: `float getUntransformedCentroidX()`

*new* method: `float getUntransformedCentroidY()`

*new* method: `float getVelocityX()`

*new* method: `float getVelocityY()`

*new* method: `boolean onTouchEvent(MotionEvent)`

*new* method: `void setElement(View)`


## GestureRecognizer

*new* abstract class: `GestureRecognizer`

*new* constructor: `GestureRecognizer()`

*new* static final field: `int BEGAN`

*new* static final field: `int CANCELLED`

*new* static final field: `int CHANGED`

*new* static final field: `int POSSIBLE`

*new* static final field: `int RECOGNIZED`

*new* method: `void addStateChangeListener(GestureStateChangeListener)`

*new* final method: `float getCentroidX()`

*new* final method: `float getCentroidY()`

*new* method: `View getElement()`

*new* method: `int getState()`

*new* static method: `void getTransformationMatrix(View, Matrix, Matrix)`

*new* abstract method: `float getUntransformedCentroidX()`

*new* abstract method: `float getUntransformedCentroidY()`

*new* abstract method: `boolean onTouchEvent(MotionEvent)`

*new* method: `void removeStateChangeListener(GestureStateChangeListener)`

*new* method: `void setElement(View)`


## GestureRecognizerState

*new* annotation: `@GestureRecognizerState`


## GestureStateChangeListener

*new* interface: `GestureStateChangeListener`

*new* method: `void onStateChanged(GestureRecognizer)`


## Library

*removed* class: `Library`

*removed* constructor: `Library()`

*removed* static final field: `String LIBRARY_NAME`


## RotateGestureRecognizer

*new* class: `RotateGestureRecognizer`

*new* constructor: `RotateGestureRecognizer()`

*new* field: `float rotateSlop`

*new* method: `float getRotation()`

*new* method: `float getUntransformedCentroidX()`

*new* method: `float getUntransformedCentroidY()`

*new* method: `float getVelocity()`

*new* method: `boolean onTouchEvent(MotionEvent)`

*new* method: `void setElement(View)`


## ScaleGestureRecognizer

*new* class: `ScaleGestureRecognizer`

*new* constructor: `ScaleGestureRecognizer()`

*new* field: `int scaleSlop`

*new* method: `float getScale()`

*new* method: `float getUntransformedCentroidX()`

*new* method: `float getUntransformedCentroidY()`

*new* method: `float getVelocity()`

*new* method: `boolean onTouchEvent(MotionEvent)`

*new* method: `void setElement(View)`


## AccumulationType

*new* annotation: `@AccumulationType`


## SimulatedGestureRecognizer

*new* class: `SimulatedGestureRecognizer`

*new* constructor: `SimulatedGestureRecognizer(View)`

*new* method: `float getUntransformedCentroidX()`

*new* method: `float getUntransformedCentroidY()`

*new* method: `boolean onTouchEvent(MotionEvent)`

*new* method: `void setState(int)`



## Non-source changes

* [Automatic changelog preparation for release.](https://github.com/material-motion/gestures-android/commit/d0a177c370d004378e2d1b417de3f16885a4f344) (Mark Wei)
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ android {

dependencies {
// If you are developing any dependencies locally, also list them in local.dependencies.
compile 'com.android.support:support-compat:24.2.1'

testCompile 'com.google.truth:truth:0.28'
testCompile 'junit:junit:4.12'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* Copyright 2016-present The Material Motion Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.material.motion.gestures;

import android.content.Context;
import android.graphics.PointF;
import android.support.annotation.Nullable;
import android.support.v4.view.MotionEventCompat;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;

import static com.google.android.material.motion.gestures.ValueVelocityTracker.ADDITIVE;

/**
* A gesture recognizer that generates translation events.
*/
public class DragGestureRecognizer extends GestureRecognizer {

/**
* Touch slop for drag. Amount of pixels that the centroid needs to move in either axes.
*/
public int dragSlop = UNSET_SLOP;

private float initialCentroidX;
private float initialCentroidY;
private float currentCentroidX;
private float currentCentroidY;

private ValueVelocityTracker centroidXVelocityTracker;
private ValueVelocityTracker centroidYVelocityTracker;

@Override
public void setElement(@Nullable View element) {
super.setElement(element);

if (element == null) {
return;
}

if (dragSlop == UNSET_SLOP) {
Context context = element.getContext();
this.dragSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}

centroidXVelocityTracker = new ValueVelocityTracker(element.getContext(), ADDITIVE);
centroidYVelocityTracker = new ValueVelocityTracker(element.getContext(), ADDITIVE);
}

public boolean onTouchEvent(MotionEvent event) {
PointF centroid = calculateUntransformedCentroid(event);
float centroidX = centroid.x;
float centroidY = centroid.y;

int action = MotionEventCompat.getActionMasked(event);
if (action == MotionEvent.ACTION_DOWN) {
initialCentroidX = centroidX;
initialCentroidY = centroidY;
currentCentroidX = centroidX;
currentCentroidY = centroidY;

centroidXVelocityTracker.onGestureStart(event, centroidX);
centroidYVelocityTracker.onGestureStart(event, centroidY);

if (dragSlop == 0) {
setState(BEGAN);
}
}
if (action == MotionEvent.ACTION_POINTER_DOWN
|| action == MotionEvent.ACTION_POINTER_UP) {
float adjustX = centroidX - currentCentroidX;
float adjustY = centroidY - currentCentroidY;

initialCentroidX += adjustX;
initialCentroidY += adjustY;
currentCentroidX += adjustX;
currentCentroidY += adjustY;

centroidXVelocityTracker.onGestureAdjust(-adjustX);
centroidYVelocityTracker.onGestureAdjust(-adjustY);
}
if (action == MotionEvent.ACTION_MOVE) {
if (!isInProgress()) {
float deltaX = centroidX - initialCentroidX;
float deltaY = centroidY - initialCentroidY;
if (Math.abs(deltaX) > dragSlop || Math.abs(deltaY) > dragSlop) {
float adjustX = Math.signum(deltaX) * Math.min(Math.abs(deltaX), dragSlop);
float adjustY = Math.signum(deltaY) * Math.min(Math.abs(deltaY), dragSlop);

initialCentroidX += adjustX;
initialCentroidY += adjustY;
currentCentroidX += adjustX;
currentCentroidY += adjustY;

setState(BEGAN);
}
}

if (isInProgress()) {
currentCentroidX = centroidX;
currentCentroidY = centroidY;

setState(CHANGED);
}

centroidXVelocityTracker.onGestureMove(event, centroidX);
centroidYVelocityTracker.onGestureMove(event, centroidY);
}
if (action == MotionEvent.ACTION_UP
|| action == MotionEvent.ACTION_CANCEL) {
initialCentroidX = centroidX;
initialCentroidY = centroidY;
currentCentroidX = centroidX;
currentCentroidY = centroidY;

centroidXVelocityTracker.onGestureEnd(event, centroidX);
centroidYVelocityTracker.onGestureEnd(event, centroidY);

if (isInProgress()) {
if (action == MotionEvent.ACTION_UP) {
setState(RECOGNIZED);
} else {
setState(CANCELLED);
}
}
}

return true;
}

/**
* Returns the translationX of the drag gesture.
* <p>
* This reports the total translation over time since the {@link #BEGAN beginning} of the
* gesture. This is not a delta value from the last {@link #CHANGED update}.
*/
public float getTranslationX() {
return currentCentroidX - initialCentroidX;
}

/**
* Returns the translationY of the drag gesture.
* <p>
* This reports the total translation over time since the {@link #BEGAN beginning} of the
* gesture. This is not a delta value from the last {@link #CHANGED update}.
*/
public float getTranslationY() {
return currentCentroidY - initialCentroidY;
}

/**
* Returns the positional velocityX of the drag gesture.
* <p>
* Only read this when the state is {@link #RECOGNIZED} or {@link #CANCELLED}.
*
* @return The velocity in pixels per second.
*/
public float getVelocityX() {
return centroidXVelocityTracker.getCurrentVelocity();
}

/**
* Returns the positional velocityY of the drag gesture.
* <p>
* Only read this when the state is {@link #RECOGNIZED} or {@link #CANCELLED}.
*
* @return The velocity in pixels per second.
*/
public float getVelocityY() {
return centroidYVelocityTracker.getCurrentVelocity();
}

@Override
public float getUntransformedCentroidX() {
return currentCentroidX;
}

@Override
public float getUntransformedCentroidY() {
return currentCentroidY;
}
}
Loading

0 comments on commit 9e373c5

Please sign in to comment.