Skip to content

Commit

Permalink
bugfix for vibration
Browse files Browse the repository at this point in the history
  • Loading branch information
Xlythe committed Nov 13, 2016
1 parent 0f0074a commit 0a719db
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion floating-view/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.1.1"
versionName "1.1.2"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class FloatingView extends Service implements OnTouchListener {

private static final int MARGIN_VIEW = 20;
private static final int MARGIN_VERTICAL = 5;
private static final int MARGIN_HORIZONTAL = -20;
private static final int MARGIN_HORIZONTAL = -10;
private static final int VIBRATION = 25;
private static final int DELETE_ANIM_DURATION = 300;

Expand All @@ -59,6 +59,8 @@ public abstract class FloatingView extends Service implements OnTouchListener {
private float mOrigY;
private boolean mDragged;
private int mIconSize;
private final Point mStartingPositionPoint = new Point();
private final Point mOpenPositionPoint = new Point();

// View variables
private ViewGroup mRootView;
Expand All @@ -80,10 +82,11 @@ public abstract class FloatingView extends Service implements OnTouchListener {
private LimitedQueue<Float> mDeltaXArray;
private LimitedQueue<Float> mDeltaYArray;
private AnimationTask mAnimationTask;
private final Point mIconPositionInDeleteModePoint = new Point();

// Open/Close variables
private boolean mIsViewOpen = false;
private Point mWiggle = new Point(0, 0);
private final Point mWiggle = new Point(0, 0);
private boolean mEnableWiggle = false;

// Close logic
Expand Down Expand Up @@ -311,12 +314,7 @@ public void run() {
}
}
if (isDeleteMode(x, y)) {
if (!mIsInDeleteMode) animateToDeleteBoxCenter(new AnimationFinishedListener() {
@Override
public void onAnimationFinished() {
mDontVibrate = true;
}
});
if (!mIsInDeleteMode) animateToDeleteBoxCenter();
} else if (isDeleteMode() && !mIsAnimationLocked) {
mIsInDeleteMode = false;
if (mAnimationTask != null) {
Expand Down Expand Up @@ -437,12 +435,7 @@ public void onAnimationFinished() {
mEnableWiggle = true;

if (isDeleteMode()) {
if (!mIsInDeleteMode) animateToDeleteBoxCenter(new AnimationFinishedListener() {
@Override
public void onAnimationFinished() {
mDontVibrate = true;
}
});
if (!mIsInDeleteMode) animateToDeleteBoxCenter();
}
}
});
Expand Down Expand Up @@ -538,6 +531,7 @@ private void vibrate() {
private void stop(boolean animate) {
if (mIsBeingDestroyed) return;
mIsBeingDestroyed = true;
mDontVibrate = true;

if (animate) {
animateToDeleteBoxCenter(new AnimationFinishedListener() {
Expand Down Expand Up @@ -566,11 +560,16 @@ public void onAnimationFinished() {
}

private Point calculatorIconPositionInDeleteMode() {
return new Point(mWiggle.x + getScreenWidth() / 2 - mDraggableIcon.getWidth() / 2,
mWiggle.y + mRootView.getHeight() - DELETE_BOX_HEIGHT / 2 - mDraggableIcon.getHeight() / 2 + MAGIC_OFFSET);
mIconPositionInDeleteModePoint.x = mWiggle.x + getScreenWidth() / 2 - mDraggableIcon.getWidth() / 2;
mIconPositionInDeleteModePoint.y = mWiggle.y + mRootView.getHeight() - DELETE_BOX_HEIGHT / 2 - mDraggableIcon.getHeight() / 2 + MAGIC_OFFSET;
return mIconPositionInDeleteModePoint;
}

private void animateToDeleteBoxCenter(final AnimationFinishedListener l) {
private void animateToDeleteBoxCenter() {
animateToDeleteBoxCenter(null);
}

private void animateToDeleteBoxCenter(@Nullable final AnimationFinishedListener l) {
if (mIsAnimationLocked || mRootView == null || mDraggableIcon == null)
return;
mIsInDeleteMode = true;
Expand Down Expand Up @@ -598,7 +597,9 @@ public float getTranslationY(float percent) {
@Override
public void onAnimationFinished() {
mIsAnimatingToDeleteMode = false;
l.onAnimationFinished();
if (l != null) {
l.onAnimationFinished();
}
}
});
mAnimationTask.run();
Expand All @@ -607,10 +608,10 @@ public void onAnimationFinished() {
}

private void calculateWiggle(int x, int y) {
Point closeIcon = new Point(getScreenWidth() / 2, mRootView.getHeight() - DELETE_BOX_HEIGHT / 2);
int wiggleX = (x - closeIcon.x) / 10;
int wiggleY = Math.max(-1 * DELETE_BOX_HEIGHT / 8, (y - closeIcon.y) / 10);
mWiggle = new Point(wiggleX, wiggleY);
int closeIconX = getScreenWidth() / 2;
int closeIconY = mRootView.getHeight() - DELETE_BOX_HEIGHT / 2;
mWiggle.x = (x - closeIconX) / 10;
mWiggle.y = Math.max(-1 * DELETE_BOX_HEIGHT / 8, (y - closeIconY) / 10);
}

public void open() {
Expand Down Expand Up @@ -653,14 +654,18 @@ public void onReceive(Context context, Intent intent) {
* Returns the x,y coordinate of the top right corner of the icon when first launched
*/
protected Point getStartingPosition() {
return new Point(getIconHorizontalMargin(), STARTING_POINT_Y);
mStartingPositionPoint.x = getIconHorizontalMargin();
mStartingPositionPoint.y = STARTING_POINT_Y;
return mStartingPositionPoint;
}

/**
* Returns the x,y coordinate of the top right corner of the icon when opened
*/
protected Point getOpenPosition() {
return new Point(getScreenWidth() - mDraggableIcon.getWidth() - getMargin(), STARTING_POINT_Y);
mOpenPositionPoint.x = getScreenWidth() - mDraggableIcon.getWidth() - getMargin();
mOpenPositionPoint.y = STARTING_POINT_Y;
return mOpenPositionPoint;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bintray.libraryName=FloatingView

bintray.groupId=com.xlythe
bintray.artifact=floating-view
bintray.libraryVersion=1.1.1
bintray.libraryVersion=1.1.2

bintray.libraryDescription='A library for creating floating views in Android'

Expand Down

0 comments on commit 0a719db

Please sign in to comment.