Skip to content
This repository was archived by the owner on Feb 9, 2023. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void deactivate() {
mIsActivated = false;
mTouchViewMap.clear();
mViewList = null;
mTouchListener = null;
}
}

Expand Down
34 changes: 27 additions & 7 deletions hover/src/main/java/io/mattcarroll/hover/Dragger.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.mattcarroll.hover;

import android.graphics.Point;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.util.Log;
Expand Down Expand Up @@ -48,9 +49,14 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
mOriginalViewPosition = convertCornerToCenter(view, getTouchViewPosition(view));
mCurrentViewPosition = new PointF(mOriginalViewPosition.x, mOriginalViewPosition.y);
mOriginalTouchPosition.set(motionEvent.getRawX(), motionEvent.getRawY());
mTouchListener.onPress();
if (mTouchListener != null) {
mTouchListener.onPress();
}
return true;
case MotionEvent.ACTION_MOVE:
if (mDragListener == null) {
return false;
}
Log.d(TAG, "ACTION_MOVE. motionX: " + motionEvent.getRawX() + ", motionY: " + motionEvent.getRawY());
float dragDeltaX = motionEvent.getRawX() - mOriginalTouchPosition.x;
float dragDeltaY = motionEvent.getRawY() - mOriginalTouchPosition.y;
Expand All @@ -75,8 +81,10 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
Log.d(TAG, "ACTION_UP");
if (!mIsDragging) {
Log.d(TAG, "Reporting as a tap.");
mTouchListener.onTap();
} else {
if (mTouchListener != null) {
mTouchListener.onTap();
}
} else if (mDragListener != null) {
Log.d(TAG, "Reporting as a drag release at: " + mCurrentViewPosition);
mDragListener.onReleasedAt(view, mCurrentViewPosition.x, mCurrentViewPosition.y);
}
Expand All @@ -93,11 +101,23 @@ public Dragger(int mTapTouchSlop) {

public abstract PointF getTouchViewPosition(@NonNull View touchView);

public abstract Point getContainerSize();

public void activate(@NonNull DragListener dragListener, @NonNull List<View> viewList) {
super.activate(dragListener, viewList);
mDragListener = dragListener;
for (View touchView : mTouchViewMap.values()) {
touchView.setOnTouchListener(mDragTouchListener);
if (!mIsActivated) {
super.activate(dragListener, viewList);
mDragListener = dragListener;
for (View touchView : mTouchViewMap.values()) {
touchView.setOnTouchListener(mDragTouchListener);
}
}
}

@Override
public void deactivate() {
if (mIsActivated) {
super.deactivate();
mDragListener = null;
}
}

Expand Down
10 changes: 7 additions & 3 deletions hover/src/main/java/io/mattcarroll/hover/HoverView.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,13 @@ void makeUntouchableInWindow() {
}

public Point getScreenSize() {
final Point screenSize = new Point();
((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(screenSize);
return screenSize;
if (mDragger == null) {
final Point screenSize = new Point();
((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(screenSize);
return screenSize;
} else {
return mDragger.getContainerSize();
}
}

// State of the HoverMenuView that is persisted across configuration change and other brief OS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,13 @@ private void onDroppedByUser() {
} else {
int tabSize = mHoverView.getResources().getDimensionPixelSize(R.dimen.hover_tab_size);
Point screenSize = mHoverView.getScreenSize();
float tabHorizontalPositionPercent = (float) mFloatingTab.getPosition().x / screenSize.x;
final float tabHorizontalPositionPercent = (float) mFloatingTab.getPosition().x / screenSize.x;
final float viewHeightPercent = mFloatingTab.getHeight() / 2f / screenSize.y;
float tabVerticalPosition = (float) mFloatingTab.getPosition().y / screenSize.y;
if (tabVerticalPosition < MIN_TAB_VERTICAL_POSITION) {
tabVerticalPosition = MIN_TAB_VERTICAL_POSITION;
} else if (tabVerticalPosition > MAX_TAB_VERTICAL_POSITION) {
tabVerticalPosition = MAX_TAB_VERTICAL_POSITION;
} else if (tabVerticalPosition > MAX_TAB_VERTICAL_POSITION - viewHeightPercent) {
tabVerticalPosition = MAX_TAB_VERTICAL_POSITION - viewHeightPercent;
}
Log.d(TAG, "Dropped at horizontal " + tabHorizontalPositionPercent + ", vertical " + tabVerticalPosition);
SideDock.SidePosition sidePosition = new SideDock.SidePosition(
Expand All @@ -231,7 +232,9 @@ private void onDroppedByUser() {

private void onTap() {
Log.d(TAG, "Floating tab was tapped.");
mHoverView.notifyOnTap(this);
if (mHoverView != null) {
mHoverView.notifyOnTap(this);
}
}

private void sendToDock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.mattcarroll.hover.view;

import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -61,6 +62,13 @@ public PointF getTouchViewPosition(@NonNull View touchView) {
);
}

@Override
public Point getContainerSize() {
Rect area = new Rect();
mContainer.getGlobalVisibleRect(area);
return new Point(area.right, area.bottom);
}

@Override
public void moveTouchViewTo(@NonNull View touchView, @NonNull PointF cornerPosition) {
touchView.setX(cornerPosition.x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.mattcarroll.hover.window;

import android.content.Context;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -59,6 +60,11 @@ public PointF getTouchViewPosition(@NonNull View touchView) {
return new PointF(mWindowViewController.getViewPosition(touchView));
}

@Override
public Point getContainerSize() {
return mWindowViewController.getWindowSize();
}

@Override
public void moveTouchViewTo(@NonNull View touchView, @NonNull PointF cornerPosition) {
mWindowViewController.moveViewTo(touchView, (int) cornerPosition.x, (int) cornerPosition.y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ public void makeUntouchable(View view) {
mWindowManager.updateViewLayout(view, params);
}

public Point getWindowSize() {
final Point windowSize = new Point();
mWindowManager.getDefaultDisplay().getSize(windowSize);
return new Point(windowSize.x, windowSize.y);
}

}