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
18 changes: 5 additions & 13 deletions hover/src/main/java/io/mattcarroll/hover/BaseTouchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
}
};

private final HoverFrameLayout.OnPositionChangeListener mOnLayoutChangeListener = new HoverFrameLayout.OnPositionChangeListener() {
private final View.OnLayoutChangeListener mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
@Override
public void onPositionChange(@NonNull View view) {
public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
moveTouchViewTo(mTouchViewMap.get(view.getTag()), new PointF(view.getX(), view.getY()));
}

@Override
public void onDockChange(@NonNull Dock dock) {

}
};

public abstract View createTouchView(@NonNull Rect rect);
Expand All @@ -72,10 +67,9 @@ public void activate(@NonNull TouchListener touchListener, @NonNull List<View> v
View touchView = createTouchView(rect);
moveTouchViewTo(touchView, new PointF(view.getX(), view.getY()));
touchView.setOnTouchListener(mDragTouchListener);
touchView.setTag(tag);
mTouchViewMap.put(tag, touchView);
if (view instanceof HoverFrameLayout) {
((HoverFrameLayout) view).addOnPositionChangeListener(mOnLayoutChangeListener);
}
view.addOnLayoutChangeListener(mOnLayoutChangeListener);
}
updateTouchControlViewAppearance();
}
Expand All @@ -86,9 +80,7 @@ public void deactivate() {
Log.d(TAG, "Deactivating.");
for (View view : mViewList) {
view.setOnTouchListener(null);
if (view instanceof HoverFrameLayout) {
((HoverFrameLayout) view).removeOnPositionChangeListener(mOnLayoutChangeListener);
}
view.removeOnLayoutChangeListener(mOnLayoutChangeListener);
}

for (View touchView : mTouchViewMap.values()) {
Expand Down
3 changes: 1 addition & 2 deletions hover/src/main/java/io/mattcarroll/hover/ContentDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public void onGlobalLayout() {

private final FloatingTab.OnPositionChangeListener mOnTabPositionChangeListener = new FloatingTab.OnPositionChangeListener() {
@Override
public void onPositionChange(@NonNull View view) {
final Point position = new Point((int) view.getX() + (view.getWidth() / 2), (int) view.getY() + (view.getHeight() / 2));
public void onPositionChange(@NonNull Point position) {
Log.d(TAG, mSelectedTab + " tab moved to " + position);
updateTabSelectorPosition();

Expand Down
15 changes: 9 additions & 6 deletions hover/src/main/java/io/mattcarroll/hover/Dragger.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
// Dragging just started
Log.d(TAG, "MOVE Start Drag.");
mIsDragging = true;
mDragListener.onDragStart(mCurrentViewPosition.x, mCurrentViewPosition.y);
mDragListener.onDragStart(view, mCurrentViewPosition.x, mCurrentViewPosition.y);
} else {
mDragListener.onDragTo(mCurrentViewPosition.x, mCurrentViewPosition.y);
mDragListener.onDragTo(view, mCurrentViewPosition.x, mCurrentViewPosition.y);
}
}

Expand All @@ -78,7 +78,7 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
mTouchListener.onTap();
} else {
Log.d(TAG, "Reporting as a drag release at: " + mCurrentViewPosition);
mDragListener.onReleasedAt(mCurrentViewPosition.x, mCurrentViewPosition.y);
mDragListener.onReleasedAt(view, mCurrentViewPosition.x, mCurrentViewPosition.y);
}
return true;
default:
Expand Down Expand Up @@ -125,25 +125,28 @@ public interface DragListener extends TouchListener {
/**
* The user has begun dragging.
*
* @param view the view that is being dragged
* @param x x-coordinate of the user's drag start (in the parent View's coordinate space)
* @param y y-coordiante of the user's drag start (in the parent View's coordinate space)
*/
void onDragStart(float x, float y);
void onDragStart(View view, float x, float y);

/**
* The user has dragged to the given coordinates.
*
* @param view the view that is being dragged
* @param x x-coordinate of the user's drag (in the parent View's coordinate space)
* @param y y-coordiante of the user's drag (in the parent View's coordinate space)
*/
void onDragTo(float x, float y);
void onDragTo(View view, float x, float y);

/**
* The user has stopped touching the drag area.
*
* @param view the view that is being dragged
* @param x x-coordinate of the user's release (in the parent View's coordinate space)
* @param y y-coordiante of the user's release (in the parent View's coordinate space)
*/
void onReleasedAt(float x, float y);
void onReleasedAt(View view, float x, float y);
}
}
43 changes: 37 additions & 6 deletions hover/src/main/java/io/mattcarroll/hover/FloatingTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import android.view.animation.OvershootInterpolator;
import android.widget.FrameLayout;

import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

/**
* {@code FloatingTab} is the cornerstone of a {@link HoverView}. When a {@code HoverView} is
* collapsed, it is reduced to a single {@code FloatingTab} that the user can drag and drop. When
Expand All @@ -42,7 +45,7 @@
*
* {@code FloatingTab}s position themselves based on their center.
*/
class FloatingTab extends HoverFrameLayout {
class FloatingTab extends FrameLayout {

private static final String TAG = "FloatingTab";
private static final int APPEARING_ANIMATION_DURATION = 300;
Expand All @@ -51,11 +54,12 @@ class FloatingTab extends HoverFrameLayout {
private int mTabSize;
private View mTabView;
private Dock mDock;
private final Set<OnPositionChangeListener> mOnPositionChangeListeners = new CopyOnWriteArraySet<>();

private final OnLayoutChangeListener mOnLayoutChangeListener = new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
notifyListenersOfPositionChange(FloatingTab.this);
notifyListenersOfPositionChange();
}
};

Expand Down Expand Up @@ -225,7 +229,7 @@ public Point getDockPosition() {

public void setDock(@NonNull Dock dock) {
mDock = dock;
notifyListenersOfDockChange(mDock);
notifyListenersOfDockChange();
}

public void dock() {
Expand Down Expand Up @@ -255,7 +259,7 @@ public void onAnimationEnd(Animator animation) {
if (null != onDocked) {
onDocked.run();
}
notifyListenersOfPositionChange(FloatingTab.this);
notifyListenersOfPositionChange();
}

@Override
Expand All @@ -268,7 +272,7 @@ public void onAnimationRepeat(Animator animation) { }
xAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
notifyListenersOfPositionChange(FloatingTab.this);
notifyListenersOfPositionChange();
}
});
}
Expand All @@ -281,7 +285,7 @@ public void moveTo(@NonNull Point floatPosition) {
Point cornerPosition = convertCenterToCorner(floatPosition);
setX(cornerPosition.x);
setY(cornerPosition.y);
notifyListenersOfPositionChange(FloatingTab.this);
notifyListenersOfPositionChange();
}

private Point convertCenterToCorner(@NonNull Point centerPosition) {
Expand All @@ -291,9 +295,36 @@ private Point convertCenterToCorner(@NonNull Point centerPosition) {
);
}

public void addOnPositionChangeListener(@Nullable OnPositionChangeListener listener) {
mOnPositionChangeListeners.add(listener);
}

public void removeOnPositionChangeListener(@NonNull OnPositionChangeListener listener) {
mOnPositionChangeListeners.remove(listener);
}

private void notifyListenersOfPositionChange() {
Point position = getPosition();
for (OnPositionChangeListener listener : mOnPositionChangeListeners) {
listener.onPositionChange(position);
}
}

private void notifyListenersOfDockChange() {
for (OnPositionChangeListener listener : mOnPositionChangeListeners) {
listener.onDockChange(mDock);
}
}

// This method is declared in this class simply to make it clear that its part of our public
// contract and not just an inherited method.
public void setOnClickListener(@Nullable View.OnClickListener onClickListener) {
super.setOnClickListener(onClickListener);
}

public interface OnPositionChangeListener {
void onPositionChange(@NonNull Point tabPosition);

void onDockChange(@NonNull Dock dock);
}
}
61 changes: 0 additions & 61 deletions hover/src/main/java/io/mattcarroll/hover/HoverFrameLayout.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private void onDocked() {
mHoverView.notifyOnDocked(this);
}

protected void moveTabTo(@NonNull Point position) {
protected void moveTabTo(View touchView, @NonNull Point position) {
mFloatingTab.moveTo(position);
}

Expand Down Expand Up @@ -349,17 +349,17 @@ protected FloatingTabDragListener(@NonNull HoverViewStateCollapsed owner) {
}

@Override
public void onDragStart(float x, float y) {
public void onDragStart(View touchView, float x, float y) {
mOwner.onPickedUpByUser();
}

@Override
public void onDragTo(float x, float y) {
mOwner.moveTabTo(new Point((int) x, (int) y));
public void onDragTo(View touchView, float x, float y) {
mOwner.moveTabTo(touchView, new Point((int) x, (int) y));
}

@Override
public void onReleasedAt(float x, float y) {
public void onReleasedAt(View touchView, float x, float y) {
mOwner.onDroppedByUser();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ public void giveUpControl(@NonNull final HoverViewState nextState) {
}

@Override
protected void moveTabTo(@NonNull Point position) {
protected void moveTabTo(View touchView, @NonNull Point position) {
if (mHoverView == null) {
return;
}

final int floatingTabOffset = mMessageView.getWidth() / 2;
if (mHoverView.mCollapsedDock.sidePosition().getSide() == SideDock.SidePosition.RIGHT) {
if (touchView.getTag() != null && touchView.getTag().equals(mFloatingTab.getTag())) {
mFloatingTab.moveTo(position);
} else if (mHoverView.mCollapsedDock.sidePosition().getSide() == SideDock.SidePosition.RIGHT) {
mFloatingTab.moveTo(new Point(position.x + floatingTabOffset, position.y));
} else {
mFloatingTab.moveTo(new Point(position.x - floatingTabOffset, position.y));
Expand Down
2 changes: 1 addition & 1 deletion hover/src/main/java/io/mattcarroll/hover/TabChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TabChain {

private final FloatingTab.OnPositionChangeListener mOnPredecessorPositionChange = new FloatingTab.OnPositionChangeListener() {
@Override
public void onPositionChange(@NonNull View view) {
public void onPositionChange(@NonNull Point position) {
// No-op. We only care when our predecessor's dock changes.
}

Expand Down
10 changes: 4 additions & 6 deletions hover/src/main/java/io/mattcarroll/hover/TabMessageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;

public class TabMessageView extends HoverFrameLayout {
public class TabMessageView extends FrameLayout {
private static final String TAG = "TabMessageView";

private final FloatingTab mFloatingTab;
private SideDock mSideDock;
private View mMessageView;

private final OnPositionChangeListener mOnTabPositionChangeListener = new OnPositionChangeListener() {
private final FloatingTab.OnPositionChangeListener mOnTabPositionChangeListener = new FloatingTab.OnPositionChangeListener() {
@Override
public void onPositionChange(@NonNull View view) {
final Point position = mFloatingTab.getPosition();
public void onPositionChange(@NonNull Point position) {
Log.d(TAG, mFloatingTab + " tab moved to " + position);
final float tabSizeHalf = mFloatingTab.getTabSize() / 2f;
if (mSideDock != null && mSideDock.sidePosition().getSide() == SideDock.SidePosition.RIGHT) {
Expand All @@ -32,7 +32,6 @@ public void onPositionChange(@NonNull View view) {
setX(position.x + tabSizeHalf);
setY(position.y - tabSizeHalf);
}
notifyListenersOfPositionChange(TabMessageView.this);
}

@Override
Expand All @@ -43,7 +42,6 @@ public void onDockChange(@NonNull Dock dock) {
appear(sideDock, null);
}
}
notifyListenersOfDockChange(dock);
}
};

Expand Down