Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get focusx and focusy #32

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
jobs:
build:
docker:
- image: circleci/android:api-28-alpha # gcloud is baked into this image
steps:
- checkout
- run:
name: Build debug APK and release APK
command: |
./gradlew build
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Android Gesture Detectors Framework
===================================

[![CircleCI](https://circleci.com/gh/mariopce/android-gesture-detectors/tree/master.svg?style=svg)](https://circleci.com/gh/mariopce/android-gesture-detectors/tree/master)

Introduction
------------

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.3.0'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=1.0
VERSION_CODE=2
VERSION_CODE=3
GROUP=com.almeros.android-gesture-detectors

POM_DESCRIPTION=Gesture detector framework for multitouch handling on Android, based on Android's ScaleGestureDetector
Expand All @@ -15,7 +15,7 @@ POM_DEVELOPER_NAME=Almeros Thies

ANDROID_MIN_SDK=8
ANDROID_TARGET_SDK=21
ANDROID_COMPILE_SDK=21
ANDROID_BUILD_TOOLS_VERSION=25.0.0
ANDROID_COMPILE_SDK=28
ANDROID_BUILD_TOOLS_VERSION=28.0.3

org.gradle.jvmargs=-Xmx1536M
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
10 changes: 0 additions & 10 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.almeros.android.multitouch">

<uses-configuration android:reqTouchScreen="finger" />

mariopce marked this conversation as resolved.
Show resolved Hide resolved
<uses-feature
android:name="android.hardware.touchscreen"
android:required="true" />
<uses-feature
android:name="android.hardware.touchscreen.multitouch"
android:required="true" />


<application/>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ protected void handleInProgressEvent(int actionCode, MotionEvent event){
// a certain limit. This can help filter shaky data as a
// finger is lifted.
if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD) {
determineFocusPoint(event);
final boolean updatePrevious = mListener.onRotate(this);
if (updatePrevious) {
mPrevEvent.recycle();
Expand All @@ -155,7 +156,6 @@ protected void resetState() {
mSloppyGesture = false;
}


/**
* Return the rotation difference from the previous rotate event to the current
* event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ protected void handleInProgressEvent(int actionCode, MotionEvent event){
// finger is lifted. Also check that shove is meaningful.
if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD
&& Math.abs(getShovePixelsDelta()) > 0.5f) {
determineFocusPoint(event);
final boolean updatePrevious = mListener.onShove(this);
if (updatePrevious) {
mPrevEvent.recycle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

Expand Down Expand Up @@ -36,10 +35,12 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector {
protected float mPrevFingerDiffY;
protected float mCurrFingerDiffX;
protected float mCurrFingerDiffY;

protected float mFocusX;
protected float mFocusY;

private float mCurrLen;
private float mPrevLen;

public TwoFingerGestureDetector(Context context) {
super(context);

Expand Down Expand Up @@ -92,7 +93,7 @@ public float getCurrentSpan() {
if (mCurrLen == -1) {
final float cvx = mCurrFingerDiffX;
final float cvy = mCurrFingerDiffY;
mCurrLen = FloatMath.sqrt(cvx*cvx + cvy*cvy);
mCurrLen = (float) Math.sqrt(cvx*cvx + cvy*cvy);
mariopce marked this conversation as resolved.
Show resolved Hide resolved
}
return mCurrLen;
}
Expand All @@ -107,23 +108,45 @@ public float getPreviousSpan() {
if (mPrevLen == -1) {
final float pvx = mPrevFingerDiffX;
final float pvy = mPrevFingerDiffY;
mPrevLen = FloatMath.sqrt(pvx*pvx + pvy*pvy);
mPrevLen = (float) Math.sqrt(pvx*pvx + pvy*pvy);
}
return mPrevLen;
}


/**
* Get gesture focus X point.
* @return focus X point of gesture.
*/
public float getFocusX() {
return mFocusX;
}


/**
* Get gesture focus Y point.
* @return focus Y point of gesture.
*/
public float getFocusY() {
return mFocusY;
}

/**
* Calculate focus point for gesture.
* @param curr current motion event used to calculate focus point.
*/
protected void determineFocusPoint(MotionEvent curr) {
mFocusX = (curr.getX(0) + curr.getX(1)) * 0.5f;
mFocusY = (curr.getY(0) + curr.getY(1)) * 0.5f;
}

/**
* MotionEvent has no getRawX(int) method; simulate it pending future API approval.
* @param event
* @param pointerIndex
* @return
*/
protected static float getRawX(MotionEvent event, int pointerIndex) {
float offset = event.getX() - event.getRawX();
if(pointerIndex < event.getPointerCount()){
return event.getX(pointerIndex) + offset;
}
return 0f;
return event.getRawX();
}

/**
Expand All @@ -133,11 +156,7 @@ protected static float getRawX(MotionEvent event, int pointerIndex) {
* @return
*/
protected static float getRawY(MotionEvent event, int pointerIndex) {
float offset = event.getY() - event.getRawY();
if(pointerIndex < event.getPointerCount()){
return event.getY(pointerIndex) + offset;
}
return 0f;
return event.getRawY();
}

/**
Expand Down