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
6 changes: 3 additions & 3 deletions hover/src/main/java/io/mattcarroll/hover/Dragger.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.mattcarroll.hover;

import android.graphics.Point;
import android.graphics.Rect;
import android.support.annotation.NonNull;

/**
Expand All @@ -26,9 +26,9 @@ public interface Dragger {
/**
* Starts reporting user drag behavior given a drag area represented by {@code controlBounds}.
* @param dragListener listener that receives information about drag behavior
* @param dragStartCenterPosition initial touch point to start dragging
* @param rect Rect area to be draggable
*/
void activate(@NonNull DragListener dragListener, @NonNull Point dragStartCenterPosition);
void activate(@NonNull DragListener dragListener, @NonNull Rect rect);

/**
* Stops monitoring and reporting user drag behavior.
Expand Down
4 changes: 0 additions & 4 deletions hover/src/main/java/io/mattcarroll/hover/HoverView.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ public static HoverView createForWindow(@NonNull Context context,
@NonNull
private static Dragger createWindowDragger(@NonNull Context context,
@NonNull WindowViewController windowViewController) {
int touchDiameter = context.getResources().getDimensionPixelSize(R.dimen.hover_exit_radius);
int slop = ViewConfiguration.get(context).getScaledTouchSlop();
return new InWindowDragger(
context,
windowViewController,
touchDiameter,
slop
);
}
Expand Down Expand Up @@ -120,11 +118,9 @@ public HoverView(@NonNull Context context, @Nullable AttributeSet attrs) {

@NonNull
private Dragger createInViewDragger(@NonNull Context context) {
int touchDiameter = context.getResources().getDimensionPixelSize(R.dimen.hover_exit_radius);
int slop = ViewConfiguration.get(context).getScaledTouchSlop();
return new InViewDragger(
this,
touchDiameter,
slop
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.mattcarroll.hover;

import android.graphics.Point;
import android.graphics.Rect;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -44,13 +45,13 @@ class HoverViewStateCollapsed extends BaseHoverViewState {
private static final long ALPHA_IDLE_MILLIS = 5000;

protected HoverView mHoverView;
private FloatingTab mFloatingTab;
protected FloatingTab mFloatingTab;
private HoverMenu.Section mSelectedSection;
private int mSelectedSectionIndex = -1;
private boolean mHasControl = false;
private boolean mIsCollapsed = false;
private boolean mIsDocked = false;
private Dragger.DragListener mDragListener;
protected Dragger.DragListener mDragListener;
private Listener mListener;
private Handler mHandler = new Handler();
private Runnable mAlphaChanger = new Runnable() {
Expand Down Expand Up @@ -371,15 +372,17 @@ private void onDocked() {
}
}

private void moveTabTo(@NonNull Point position) {
protected void moveTabTo(@NonNull Point position) {
mFloatingTab.moveTo(position);
}

private void activateDragger() {
mHoverView.mDragger.activate(mDragListener, mFloatingTab.getPosition());
protected void activateDragger() {
final Rect visibleRect = new Rect();
mFloatingTab.getGlobalVisibleRect(visibleRect);
mHoverView.mDragger.activate(mDragListener, visibleRect);
}

private void deactivateDragger() {
protected void deactivateDragger() {
mHoverView.mDragger.deactivate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.mattcarroll.hover;

import android.graphics.Point;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.util.Log;

Expand All @@ -26,13 +28,15 @@
class HoverViewStatePreviewed extends HoverViewStateCollapsed {

private static final String TAG = "HoverViewStatePreviewed";
private TabMessageView mMessageView;

@Override
public void takeControl(@NonNull HoverView hoverView) {
super.takeControl(hoverView);
mHoverView.mState = this;
mHoverView.notifyListenersPreviewing();
mHoverView.mScreen.showTabContentView(mHoverView.mSelectedSectionId, mHoverView.mCollapsedDock, new Runnable() {
mMessageView = mHoverView.mScreen.getTabMessageView(mHoverView.mSelectedSectionId);
mMessageView.appear(mHoverView.mCollapsedDock, new Runnable() {
@Override
public void run() {
mHoverView.notifyListenersPreviewed();
Expand All @@ -43,9 +47,9 @@ public void run() {
@Override
protected void changeState(@NonNull final HoverViewState nextState) {
if (nextState instanceof HoverViewStateCollapsed) {
mHoverView.mScreen.hideTabContentView(mHoverView.mSelectedSectionId, true);
mMessageView.disappear(true);
} else {
mHoverView.mScreen.hideTabContentView(mHoverView.mSelectedSectionId, false);
mMessageView.disappear(false);
}
super.changeState(nextState);
}
Expand All @@ -59,4 +63,25 @@ public void preview() {
public void collapse() {
changeState(mHoverView.mCollapsed);
}

@Override
protected void moveTabTo(@NonNull Point position) {
final int floatingTabOffset = mMessageView.getWidth() / 2;
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));
}
}

@Override
protected void activateDragger() {
final Rect tabRect = new Rect();
final Rect messageRect = new Rect();
mFloatingTab.getGlobalVisibleRect(tabRect);
mMessageView.getGlobalVisibleRect(messageRect);
tabRect.union(messageRect);

mHoverView.mDragger.activate(mDragListener, tabRect);
}
}
13 changes: 2 additions & 11 deletions hover/src/main/java/io/mattcarroll/hover/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,7 @@ public ShadeView getShadeView() {
return mShadeView;
}

public void showTabContentView(final HoverMenu.SectionId sectionId, final SideDock dock, final Runnable onAppeared) {
if (getChainedTab(sectionId) != null && mTabMessageViews.get(sectionId.toString()) != null) {
mTabMessageViews.get(sectionId.toString()).appear(dock, onAppeared);
}
}

public void hideTabContentView(final HoverMenu.SectionId sectionId, final boolean withAnimation) {
final TabMessageView tabMessageView = mTabMessageViews.get(sectionId.toString());
if (tabMessageView != null) {
tabMessageView.disappear(withAnimation);
}
public TabMessageView getTabMessageView(final HoverMenu.SectionId sectionId) {
return mTabMessageViews.get(sectionId.toString());
}
}
26 changes: 13 additions & 13 deletions hover/src/main/java/io/mattcarroll/hover/view/InViewDragger.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.mattcarroll.hover.view;

import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.MotionEvent;
Expand All @@ -34,7 +34,6 @@ public class InViewDragger implements Dragger {
private static final String TAG = "InViewDragger";

private final ViewGroup mContainer;
private final int mTouchAreaDiameter;
private final int mTapTouchSlop;
private boolean mIsActivated;
private boolean mIsDragging;
Expand Down Expand Up @@ -98,9 +97,8 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
}
};

public InViewDragger(@NonNull ViewGroup container, int touchAreaDiameter, int touchSlop) {
public InViewDragger(@NonNull ViewGroup container, int touchSlop) {
mContainer = container;
mTouchAreaDiameter = touchAreaDiameter;
mTapTouchSlop = touchSlop;
}

Expand All @@ -111,12 +109,12 @@ public void enableDebugMode(boolean isDebugMode) {
}

@Override
public void activate(@NonNull DragListener dragListener, @NonNull Point dragStartCenterPosition) {
public void activate(@NonNull DragListener dragListener, @NonNull Rect rect) {
if (!mIsActivated) {
Log.d(TAG, "Activating.");
mIsActivated = true;
mDragListener = dragListener;
createTouchControlView(dragStartCenterPosition);
createTouchControlView(rect);
}
}

Expand All @@ -129,14 +127,16 @@ public void deactivate() {
}
}

private void createTouchControlView(@NonNull Point dragStartCenterPosition) {
private void createTouchControlView(@NonNull Rect rect) {
mDragView = new View(mContainer.getContext());
mDragView.setId(R.id.hover_drag_view);
mDragView.setLayoutParams(new ViewGroup.LayoutParams(mTouchAreaDiameter, mTouchAreaDiameter));
final int width = rect.right - rect.left;
final int height = rect.bottom - rect.top;
mDragView.setLayoutParams(new ViewGroup.LayoutParams(width, height));
mDragView.setOnTouchListener(mDragTouchListener);
mContainer.addView(mDragView);

moveDragViewTo(new PointF(dragStartCenterPosition.x, dragStartCenterPosition.y));
moveDragViewTo(new PointF((rect.right + rect.left) / 2, (rect.bottom + rect.top) / 2));
updateTouchControlViewAppearance();
}

Expand Down Expand Up @@ -179,15 +179,15 @@ private void moveDragViewTo(PointF centerPosition) {

private PointF convertCornerToCenter(@NonNull PointF cornerPosition) {
return new PointF(
cornerPosition.x + (mTouchAreaDiameter / 2),
cornerPosition.y + (mTouchAreaDiameter / 2)
cornerPosition.x + (mDragView.getWidth() / 2),
cornerPosition.y + (mDragView.getHeight() / 2)
);
}

private PointF convertCenterToCorner(@NonNull PointF centerPosition) {
return new PointF(
centerPosition.x - (mTouchAreaDiameter / 2),
centerPosition.y - (mTouchAreaDiameter / 2)
centerPosition.x - (mDragView.getWidth() / 2),
centerPosition.y - (mDragView.getHeight() / 2)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.content.Context;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.MotionEvent;
Expand All @@ -34,7 +35,6 @@ public class InWindowDragger implements Dragger {

private final Context mContext;
private final WindowViewController mWindowViewController;
private final int mTouchAreaDiameter;
private final float mTapTouchSlop;
private View mDragView;
private Dragger.DragListener mDragListener;
Expand Down Expand Up @@ -108,24 +108,24 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
*/
public InWindowDragger(@NonNull Context context,
@NonNull WindowViewController windowViewController,
int touchAreaDiameter,
float tapTouchSlop) {
mContext = context;
mWindowViewController = windowViewController;
mTouchAreaDiameter = touchAreaDiameter;
mTapTouchSlop = tapTouchSlop;
}

public void activate(@NonNull DragListener dragListener, @NonNull Point dragStartCenterPosition) {
@Override
public void activate(@NonNull DragListener dragListener, @NonNull Rect rect) {
if (!mIsActivated) {
Log.d(TAG, "Activating.");
createTouchControlView(dragStartCenterPosition);
createTouchControlView(rect);
mDragListener = dragListener;
mDragView.setOnTouchListener(mDragTouchListener);
mIsActivated = true;
}
}

@Override
public void deactivate() {
if (mIsActivated) {
Log.d(TAG, "Deactivating.");
Expand All @@ -141,11 +141,12 @@ public void enableDebugMode(boolean isDebugMode) {
updateTouchControlViewAppearance();
}

private void createTouchControlView(@NonNull final Point dragStartCenterPosition) {
// TODO: define dimen size
private void createTouchControlView(@NonNull Rect rect) {
mDragView = new View(mContext);
mWindowViewController.addView(mTouchAreaDiameter, mTouchAreaDiameter, true, mDragView);
mWindowViewController.moveViewTo(mDragView, dragStartCenterPosition.x - (mTouchAreaDiameter / 2), dragStartCenterPosition.y - (mTouchAreaDiameter / 2));
final int width = rect.right - rect.left;
final int height = rect.bottom - rect.top;
mWindowViewController.addView(width, height, true, mDragView);
mWindowViewController.moveViewTo(mDragView, rect.left, rect.top);
mDragView.setOnTouchListener(mDragTouchListener);

updateTouchControlViewAppearance();
Expand Down