diff --git a/hover/src/main/java/io/mattcarroll/hover/BaseTouchController.java b/hover/src/main/java/io/mattcarroll/hover/BaseTouchController.java index e69bde4..8f3cbed 100644 --- a/hover/src/main/java/io/mattcarroll/hover/BaseTouchController.java +++ b/hover/src/main/java/io/mattcarroll/hover/BaseTouchController.java @@ -7,13 +7,18 @@ import android.view.MotionEvent; import android.view.View; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public abstract class BaseTouchController { private static final String TAG = "BaseTouchController"; - protected View mTouchView; + protected Map mTouchViewMap = new HashMap<>(); protected TouchListener mTouchListener; protected boolean mIsActivated; private boolean mIsDebugMode; + private List mViewList; private View.OnTouchListener mDragTouchListener = new View.OnTouchListener() { @Override @@ -33,21 +38,45 @@ public boolean onTouch(View view, MotionEvent motionEvent) { } }; + private final HoverFrameLayout.OnPositionChangeListener mOnLayoutChangeListener = new HoverFrameLayout.OnPositionChangeListener() { + @Override + public void onPositionChange(@NonNull View view) { + 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); public abstract void destroyTouchView(@NonNull View touchView); public abstract void moveTouchViewTo(@NonNull View touchView, @NonNull PointF position); - public void activate(@NonNull TouchListener touchListener, @NonNull Rect rect) { + public void activate(@NonNull TouchListener touchListener, @NonNull List viewList) { if (!mIsActivated) { Log.d(TAG, "Activating."); mIsActivated = true; mTouchListener = touchListener; - mTouchView = createTouchView(rect); - moveTouchViewTo(mTouchView, new PointF(rect.left, rect.top)); - mTouchView.setOnTouchListener(mDragTouchListener); - + mViewList = viewList; + mTouchViewMap.clear(); + for (int i = 0; i < mViewList.size(); i++) { + View view = mViewList.get(i); + String tag = "view" + i; + view.setTag(tag); + Rect rect = new Rect(); + view.getDrawingRect(rect); + View touchView = createTouchView(rect); + moveTouchViewTo(touchView, new PointF(view.getX(), view.getY())); + touchView.setOnTouchListener(mDragTouchListener); + mTouchViewMap.put(tag, touchView); + if (view instanceof HoverFrameLayout) { + ((HoverFrameLayout) view).addOnPositionChangeListener(mOnLayoutChangeListener); + } + } updateTouchControlViewAppearance(); } } @@ -55,10 +84,20 @@ public void activate(@NonNull TouchListener touchListener, @NonNull Rect rect) { public void deactivate() { if (mIsActivated) { Log.d(TAG, "Deactivating."); - mTouchView.setOnTouchListener(null); - destroyTouchView(mTouchView); + for (View view : mViewList) { + view.setOnTouchListener(null); + if (view instanceof HoverFrameLayout) { + ((HoverFrameLayout) view).removeOnPositionChangeListener(mOnLayoutChangeListener); + } + } + + for (View touchView : mTouchViewMap.values()) { + destroyTouchView(touchView); + } + mIsActivated = false; - mTouchView = null; + mTouchViewMap.clear(); + mViewList = null; } } @@ -68,11 +107,13 @@ public void enableDebugMode(boolean isDebugMode) { } private void updateTouchControlViewAppearance() { - if (null != mTouchView) { - if (mIsDebugMode) { - mTouchView.setBackgroundColor(0x44FF0000); - } else { - mTouchView.setBackgroundColor(0x00000000); + for (View touchView : mTouchViewMap.values()) { + if (null != touchView) { + if (mIsDebugMode) { + touchView.setBackgroundColor(0x44FF0000); + } else { + touchView.setBackgroundColor(0x00000000); + } } } } diff --git a/hover/src/main/java/io/mattcarroll/hover/ContentDisplay.java b/hover/src/main/java/io/mattcarroll/hover/ContentDisplay.java index 553d38d..bc89049 100644 --- a/hover/src/main/java/io/mattcarroll/hover/ContentDisplay.java +++ b/hover/src/main/java/io/mattcarroll/hover/ContentDisplay.java @@ -62,7 +62,8 @@ public void onGlobalLayout() { private final FloatingTab.OnPositionChangeListener mOnTabPositionChangeListener = new FloatingTab.OnPositionChangeListener() { @Override - public void onPositionChange(@NonNull Point position) { + public void onPositionChange(@NonNull View view) { + final Point position = new Point((int) view.getX() + (view.getWidth() / 2), (int) view.getY() + (view.getHeight() / 2)); Log.d(TAG, mSelectedTab + " tab moved to " + position); updateTabSelectorPosition(); diff --git a/hover/src/main/java/io/mattcarroll/hover/Dragger.java b/hover/src/main/java/io/mattcarroll/hover/Dragger.java index e163cb2..81965bf 100644 --- a/hover/src/main/java/io/mattcarroll/hover/Dragger.java +++ b/hover/src/main/java/io/mattcarroll/hover/Dragger.java @@ -16,12 +16,13 @@ package io.mattcarroll.hover; import android.graphics.PointF; -import android.graphics.Rect; import android.support.annotation.NonNull; import android.util.Log; import android.view.MotionEvent; import android.view.View; +import java.util.List; + /** * Reports user drag behavior on the screen to a {@link DragListener}. */ @@ -44,7 +45,7 @@ public boolean onTouch(View view, MotionEvent motionEvent) { Log.d(TAG, "ACTION_DOWN"); mIsDragging = false; - mOriginalViewPosition = convertCornerToCenter(getTouchViewPosition(mTouchView)); + mOriginalViewPosition = convertCornerToCenter(view, getTouchViewPosition(view)); mCurrentViewPosition = new PointF(mOriginalViewPosition.x, mOriginalViewPosition.y); mOriginalTouchPosition.set(motionEvent.getRawX(), motionEvent.getRawY()); mTouchListener.onPress(); @@ -65,8 +66,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) { mIsDragging = true; mDragListener.onDragStart(mCurrentViewPosition.x, mCurrentViewPosition.y); } else { - PointF cornerPosition = convertCenterToCorner(mCurrentViewPosition); - moveTouchViewTo(mTouchView, cornerPosition); mDragListener.onDragTo(mCurrentViewPosition.x, mCurrentViewPosition.y); } } @@ -94,10 +93,12 @@ public Dragger(int mTapTouchSlop) { public abstract PointF getTouchViewPosition(@NonNull View touchView); - public void activate(@NonNull DragListener dragListener, @NonNull Rect rect) { - super.activate(dragListener, rect); + public void activate(@NonNull DragListener dragListener, @NonNull List viewList) { + super.activate(dragListener, viewList); mDragListener = dragListener; - mTouchView.setOnTouchListener(mDragTouchListener); + for (View touchView : mTouchViewMap.values()) { + touchView.setOnTouchListener(mDragTouchListener); + } } private boolean isTouchWithinSlopOfOriginalTouch(float dx, float dy) { @@ -106,17 +107,17 @@ private boolean isTouchWithinSlopOfOriginalTouch(float dx, float dy) { return distance < mTapTouchSlop; } - private PointF convertCornerToCenter(@NonNull PointF cornerPosition) { + private PointF convertCornerToCenter(View touchView, @NonNull PointF cornerPosition) { return new PointF( - cornerPosition.x + (mTouchView.getWidth() / 2f), - cornerPosition.y + (mTouchView.getHeight() / 2f) + cornerPosition.x + (touchView.getWidth() / 2f), + cornerPosition.y + (touchView.getHeight() / 2f) ); } - private PointF convertCenterToCorner(@NonNull PointF centerPosition) { + private PointF convertCenterToCorner(View touchView, @NonNull PointF centerPosition) { return new PointF( - centerPosition.x - (mTouchView.getWidth() / 2f), - centerPosition.y - (mTouchView.getHeight() / 2f) + centerPosition.x - (touchView.getWidth() / 2f), + centerPosition.y - (touchView.getHeight() / 2f) ); } diff --git a/hover/src/main/java/io/mattcarroll/hover/FloatingTab.java b/hover/src/main/java/io/mattcarroll/hover/FloatingTab.java index 784a857..edc55ad 100644 --- a/hover/src/main/java/io/mattcarroll/hover/FloatingTab.java +++ b/hover/src/main/java/io/mattcarroll/hover/FloatingTab.java @@ -30,9 +30,6 @@ 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 @@ -45,7 +42,7 @@ * * {@code FloatingTab}s position themselves based on their center. */ -class FloatingTab extends FrameLayout { +class FloatingTab extends HoverFrameLayout { private static final String TAG = "FloatingTab"; private static final int APPEARING_ANIMATION_DURATION = 300; @@ -54,12 +51,11 @@ class FloatingTab extends FrameLayout { private int mTabSize; private View mTabView; private Dock mDock; - private final Set 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(); + notifyListenersOfPositionChange(FloatingTab.this); } }; @@ -229,7 +225,7 @@ public Point getDockPosition() { public void setDock(@NonNull Dock dock) { mDock = dock; - notifyListenersOfDockChange(); + notifyListenersOfDockChange(mDock); } public void dock() { @@ -259,7 +255,7 @@ public void onAnimationEnd(Animator animation) { if (null != onDocked) { onDocked.run(); } - notifyListenersOfPositionChange(); + notifyListenersOfPositionChange(FloatingTab.this); } @Override @@ -272,7 +268,7 @@ public void onAnimationRepeat(Animator animation) { } xAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { - notifyListenersOfPositionChange(); + notifyListenersOfPositionChange(FloatingTab.this); } }); } @@ -285,7 +281,7 @@ public void moveTo(@NonNull Point floatPosition) { Point cornerPosition = convertCenterToCorner(floatPosition); setX(cornerPosition.x); setY(cornerPosition.y); - notifyListenersOfPositionChange(); + notifyListenersOfPositionChange(FloatingTab.this); } private Point convertCenterToCorner(@NonNull Point centerPosition) { @@ -295,36 +291,9 @@ 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); - } } diff --git a/hover/src/main/java/io/mattcarroll/hover/HoverFrameLayout.java b/hover/src/main/java/io/mattcarroll/hover/HoverFrameLayout.java new file mode 100644 index 0000000..0e6dfc4 --- /dev/null +++ b/hover/src/main/java/io/mattcarroll/hover/HoverFrameLayout.java @@ -0,0 +1,61 @@ +package io.mattcarroll.hover; + +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.view.View; +import android.widget.FrameLayout; + +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; + +class HoverFrameLayout extends FrameLayout { + + private final Set mOnPositionChangeListeners = new CopyOnWriteArraySet<>(); + + public HoverFrameLayout(@NonNull Context context) { + super(context); + } + + public HoverFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public HoverFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public HoverFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public void addOnPositionChangeListener(@Nullable OnPositionChangeListener listener) { + mOnPositionChangeListeners.add(listener); + } + + public void removeOnPositionChangeListener(@NonNull OnPositionChangeListener listener) { + mOnPositionChangeListeners.remove(listener); + } + + protected void notifyListenersOfPositionChange(View view) { + for (OnPositionChangeListener listener : mOnPositionChangeListeners) { + listener.onPositionChange(view); + } + } + + protected void notifyListenersOfDockChange(Dock dock) { + for (OnPositionChangeListener listener : mOnPositionChangeListeners) { + listener.onDockChange(dock); + } + } + + interface OnPositionChangeListener { + void onPositionChange(@NonNull View view); + + void onDockChange(@NonNull Dock dock); + } +} diff --git a/hover/src/main/java/io/mattcarroll/hover/HoverView.java b/hover/src/main/java/io/mattcarroll/hover/HoverView.java index 972abc3..3d721f6 100644 --- a/hover/src/main/java/io/mattcarroll/hover/HoverView.java +++ b/hover/src/main/java/io/mattcarroll/hover/HoverView.java @@ -18,6 +18,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.TypedArray; +import android.graphics.Point; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; @@ -413,6 +414,12 @@ void makeUntouchableInWindow() { } } + public Point getScreenSize() { + final Point screenSize = new Point(); + ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(screenSize); + return screenSize; + } + // State of the HoverMenuView that is persisted across configuration change and other brief OS // interruptions. This state is written/read when HoverMenuView's onSaveInstanceState() and // onRestoreInstanceState() are called. diff --git a/hover/src/main/java/io/mattcarroll/hover/HoverViewStateAnchored.java b/hover/src/main/java/io/mattcarroll/hover/HoverViewStateAnchored.java index a1a0518..7a6a6bf 100644 --- a/hover/src/main/java/io/mattcarroll/hover/HoverViewStateAnchored.java +++ b/hover/src/main/java/io/mattcarroll/hover/HoverViewStateAnchored.java @@ -1,9 +1,11 @@ package io.mattcarroll.hover; import android.graphics.Point; -import android.graphics.Rect; import android.support.annotation.NonNull; import android.util.Log; +import android.view.View; + +import java.util.ArrayList; class HoverViewStateAnchored extends BaseHoverViewState { @@ -23,7 +25,7 @@ public void onTap() { }; @Override - public void takeControl(@NonNull HoverView hoverView, final Runnable onStateChanged) { + public void takeControl(@NonNull final HoverView hoverView, final Runnable onStateChanged) { super.takeControl(hoverView, onStateChanged); Log.d(TAG, "Taking control."); mHoverView.makeUntouchableInWindow(); @@ -40,11 +42,10 @@ public void takeControl(@NonNull HoverView hoverView, final Runnable onStateChan mSelectedTab.shrink(); mSelectedTab.setSelected(true); - final int anchorMargin = hoverView.getContext().getResources().getDimensionPixelSize(R.dimen.hover_tab_anchor_margin) + (mSelectedTab.getTabSize() / 2); - final Point anchorPoint = new Point( - mHoverView.mScreen.getWidth() - anchorMargin, - mHoverView.mScreen.getHeight() - anchorMargin - ); + final int anchorMarginX = hoverView.getContext().getResources().getDimensionPixelSize(R.dimen.hover_tab_anchor_margin_x) + (mSelectedTab.getTabSize() / 2); + final int anchorMarginY = hoverView.getContext().getResources().getDimensionPixelSize(R.dimen.hover_tab_anchor_margin_y) + (mSelectedTab.getTabSize() / 2); + final Point anchorPoint = mHoverView.getScreenSize(); + anchorPoint.offset(-anchorMarginX, -anchorMarginY); mSelectedTab.setDock(new PositionDock(anchorPoint)); mSelectedTab.dock(new Runnable() { @Override @@ -68,9 +69,9 @@ public void giveUpControl(@NonNull HoverViewState nextState) { } private void activateTouchController() { - final Rect visibleRect = new Rect(); - mSelectedTab.getGlobalVisibleRect(visibleRect); - mHoverView.mDragger.activate(mTouchListener, visibleRect); + final ArrayList list = new ArrayList<>(); + list.add(mSelectedTab); + mHoverView.mDragger.activate(mTouchListener, list); } private void deactivateTouchController() { diff --git a/hover/src/main/java/io/mattcarroll/hover/HoverViewStateCollapsed.java b/hover/src/main/java/io/mattcarroll/hover/HoverViewStateCollapsed.java index 519f05e..5b03922 100644 --- a/hover/src/main/java/io/mattcarroll/hover/HoverViewStateCollapsed.java +++ b/hover/src/main/java/io/mattcarroll/hover/HoverViewStateCollapsed.java @@ -16,7 +16,6 @@ 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; @@ -24,6 +23,8 @@ import android.util.Log; import android.view.View; +import java.util.ArrayList; + import static android.view.View.GONE; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; @@ -62,7 +63,7 @@ public void run() { }; private Runnable mOnStateChanged; - private final View.OnLayoutChangeListener mOnLayoutChangeListener = new View.OnLayoutChangeListener() { + protected final View.OnLayoutChangeListener mOnLayoutChangeListener = new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (hasControl() && mIsDocked) { @@ -110,9 +111,16 @@ public void run() { if (wasFloatingTabVisible) { sendToDock(); } else { - mFloatingTab.appear(null); moveToDock(); - onDocked(); + mFloatingTab.appear(new Runnable() { + @Override + public void run() { + if (!hasControl()) { + return; + } + onDocked(); + } + }); } } }); @@ -218,7 +226,7 @@ private void onDroppedByUser() { mHoverView.close(); } else { int tabSize = mHoverView.getResources().getDimensionPixelSize(R.dimen.hover_tab_size); - Point screenSize = new Point(mHoverView.mScreen.getWidth(), mHoverView.mScreen.getHeight()); + Point screenSize = mHoverView.getScreenSize(); float tabHorizontalPositionPercent = (float) mFloatingTab.getPosition().x / screenSize.x; float tabVerticalPosition = (float) mFloatingTab.getPosition().y / screenSize.y; if (tabVerticalPosition < MIN_TAB_VERTICAL_POSITION) { @@ -266,7 +274,7 @@ public void run() { private void moveToDock() { Log.d(TAG, "Moving floating tag to dock."); Point dockPosition = mHoverView.mCollapsedDock.sidePosition().calculateDockPosition( - new Point(mHoverView.mScreen.getWidth(), mHoverView.mScreen.getHeight()), + mHoverView.getScreenSize(), mFloatingTab.getTabSize() ); mFloatingTab.moveTo(dockPosition); @@ -306,9 +314,9 @@ protected void moveTabTo(@NonNull Point position) { } protected void activateDragger() { - final Rect visibleRect = new Rect(); - mFloatingTab.getGlobalVisibleRect(visibleRect); - mHoverView.mDragger.activate(mDragListener, visibleRect); + ArrayList list = new ArrayList<>(); + list.add(mFloatingTab); + mHoverView.mDragger.activate(mDragListener, list); } protected void deactivateDragger() { diff --git a/hover/src/main/java/io/mattcarroll/hover/HoverViewStateExpanded.java b/hover/src/main/java/io/mattcarroll/hover/HoverViewStateExpanded.java index 483639a..7472693 100644 --- a/hover/src/main/java/io/mattcarroll/hover/HoverViewStateExpanded.java +++ b/hover/src/main/java/io/mattcarroll/hover/HoverViewStateExpanded.java @@ -79,7 +79,7 @@ public void takeControl(@NonNull HoverView hoverView, Runnable onStateChanged) { mHoverView.makeTouchableInWindow(); mHoverView.requestFocus(); // For handling hardware back button presses. mDock = new Point( - mHoverView.mScreen.getWidth() - ANCHOR_TAB_X_OFFSET_IN_PX, + mHoverView.getScreenSize().x - ANCHOR_TAB_X_OFFSET_IN_PX, ANCHOR_TAB_Y_OFFSET_IN_PX ); if (null != mHoverView.mMenu) { diff --git a/hover/src/main/java/io/mattcarroll/hover/HoverViewStatePreviewed.java b/hover/src/main/java/io/mattcarroll/hover/HoverViewStatePreviewed.java index f777b21..78e104d 100644 --- a/hover/src/main/java/io/mattcarroll/hover/HoverViewStatePreviewed.java +++ b/hover/src/main/java/io/mattcarroll/hover/HoverViewStatePreviewed.java @@ -16,9 +16,11 @@ package io.mattcarroll.hover; import android.graphics.Point; -import android.graphics.Rect; import android.support.annotation.NonNull; import android.util.Log; +import android.view.View; + +import java.util.ArrayList; /** * {@link HoverViewState} that operates the {@link HoverView} when it is closed. Closed means that @@ -38,6 +40,9 @@ public void takeControl(@NonNull HoverView hoverView, final Runnable onStateChan mMessageView.appear(mHoverView.mCollapsedDock, new Runnable() { @Override public void run() { + if (!hasControl()) { + return; + } onStateChanged.run(); } }); @@ -56,6 +61,10 @@ public void giveUpControl(@NonNull final HoverViewState nextState) { @Override protected void moveTabTo(@NonNull Point position) { + if (mHoverView == null) { + return; + } + final int floatingTabOffset = mMessageView.getWidth() / 2; if (mHoverView.mCollapsedDock.sidePosition().getSide() == SideDock.SidePosition.RIGHT) { mFloatingTab.moveTo(new Point(position.x + floatingTabOffset, position.y)); @@ -66,13 +75,10 @@ protected void moveTabTo(@NonNull Point position) { @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); + final ArrayList list = new ArrayList<>(); + list.add(mFloatingTab); + list.add(mMessageView); + mHoverView.mDragger.activate(mDragListener, list); } @Override diff --git a/hover/src/main/java/io/mattcarroll/hover/Screen.java b/hover/src/main/java/io/mattcarroll/hover/Screen.java index e186ba0..a9bbcea 100644 --- a/hover/src/main/java/io/mattcarroll/hover/Screen.java +++ b/hover/src/main/java/io/mattcarroll/hover/Screen.java @@ -76,14 +76,6 @@ public void enableDrugMode(boolean debugMode) { } } - public int getWidth() { - return mContainer.getWidth(); - } - - public int getHeight() { - return mContainer.getHeight(); - } - @NonNull public FloatingTab createChainedTab(@NonNull HoverMenu.Section section) { String tabId = section.getId().toString(); diff --git a/hover/src/main/java/io/mattcarroll/hover/SideDock.java b/hover/src/main/java/io/mattcarroll/hover/SideDock.java index 0d55ac3..978cbe9 100644 --- a/hover/src/main/java/io/mattcarroll/hover/SideDock.java +++ b/hover/src/main/java/io/mattcarroll/hover/SideDock.java @@ -19,7 +19,6 @@ import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.util.Log; -import android.view.ViewGroup; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -33,12 +32,12 @@ public class SideDock extends Dock { private static final String TAG = "SideDock"; - private ViewGroup mContainerView; + private HoverView mHoverView; private int mTabSize; private SidePosition mSidePosition; - SideDock(@NonNull ViewGroup containerView, int tabSize, @NonNull SidePosition sidePosition) { - mContainerView = containerView; + SideDock(@NonNull HoverView hoverView, int tabSize, @NonNull SidePosition sidePosition) { + mHoverView = hoverView; mTabSize = tabSize; mSidePosition = sidePosition; } @@ -46,8 +45,7 @@ public class SideDock extends Dock { @NonNull @Override public Point position() { - Point screenSize = new Point(mContainerView.getWidth(), mContainerView.getHeight()); - return mSidePosition.calculateDockPosition(screenSize, mTabSize); + return mSidePosition.calculateDockPosition(mHoverView.getScreenSize(), mTabSize); } @NonNull diff --git a/hover/src/main/java/io/mattcarroll/hover/TabChain.java b/hover/src/main/java/io/mattcarroll/hover/TabChain.java index 7c53a45..5221056 100644 --- a/hover/src/main/java/io/mattcarroll/hover/TabChain.java +++ b/hover/src/main/java/io/mattcarroll/hover/TabChain.java @@ -40,7 +40,7 @@ class TabChain { private final FloatingTab.OnPositionChangeListener mOnPredecessorPositionChange = new FloatingTab.OnPositionChangeListener() { @Override - public void onPositionChange(@NonNull Point position) { + public void onPositionChange(@NonNull View view) { // No-op. We only care when our predecessor's dock changes. } diff --git a/hover/src/main/java/io/mattcarroll/hover/TabMessageView.java b/hover/src/main/java/io/mattcarroll/hover/TabMessageView.java index 49502a2..acd7668 100644 --- a/hover/src/main/java/io/mattcarroll/hover/TabMessageView.java +++ b/hover/src/main/java/io/mattcarroll/hover/TabMessageView.java @@ -11,25 +11,27 @@ import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.TranslateAnimation; -import android.widget.FrameLayout; -public class TabMessageView extends FrameLayout { +public class TabMessageView extends HoverFrameLayout { private static final String TAG = "TabMessageView"; private final FloatingTab mFloatingTab; private SideDock mSideDock; - private final FloatingTab.OnPositionChangeListener mOnTabPositionChangeListener = new FloatingTab.OnPositionChangeListener() { + private final OnPositionChangeListener mOnTabPositionChangeListener = new OnPositionChangeListener() { @Override - public void onPositionChange(@NonNull Point position) { + public void onPositionChange(@NonNull View view) { + final Point position = mFloatingTab.getPosition(); Log.d(TAG, mFloatingTab + " tab moved to " + position); + final float tabSizeHalf = mFloatingTab.getTabSize() / 2f; if (mSideDock != null && mSideDock.sidePosition().getSide() == SideDock.SidePosition.RIGHT) { - setX(position.x - (mFloatingTab.getTabSize() / 2) - getWidth()); - setY(position.y - (mFloatingTab.getTabSize() / 2)); + setX(position.x - tabSizeHalf - getWidth()); + setY(position.y - tabSizeHalf); } else { - setX(position.x + (mFloatingTab.getTabSize() / 2)); - setY(position.y - (mFloatingTab.getTabSize() / 2)); + setX(position.x + tabSizeHalf); + setY(position.y - tabSizeHalf); } + notifyListenersOfPositionChange(TabMessageView.this); } @Override @@ -40,6 +42,7 @@ public void onDockChange(@NonNull Dock dock) { appear(sideDock, null); } } + notifyListenersOfDockChange(dock); } }; diff --git a/hover/src/main/java/io/mattcarroll/hover/view/InViewDragger.java b/hover/src/main/java/io/mattcarroll/hover/view/InViewDragger.java index ce0e528..f24215f 100644 --- a/hover/src/main/java/io/mattcarroll/hover/view/InViewDragger.java +++ b/hover/src/main/java/io/mattcarroll/hover/view/InViewDragger.java @@ -62,8 +62,8 @@ public PointF getTouchViewPosition(@NonNull View touchView) { } @Override - public void moveTouchViewTo(@NonNull View touchView, @NonNull PointF position) { - touchView.setX(position.x); - touchView.setY(position.y); + public void moveTouchViewTo(@NonNull View touchView, @NonNull PointF cornerPosition) { + touchView.setX(cornerPosition.x); + touchView.setY(cornerPosition.y); } } diff --git a/hover/src/main/java/io/mattcarroll/hover/window/InWindowDragger.java b/hover/src/main/java/io/mattcarroll/hover/window/InWindowDragger.java index d65759f..030f11e 100755 --- a/hover/src/main/java/io/mattcarroll/hover/window/InWindowDragger.java +++ b/hover/src/main/java/io/mattcarroll/hover/window/InWindowDragger.java @@ -60,7 +60,7 @@ public PointF getTouchViewPosition(@NonNull View touchView) { } @Override - public void moveTouchViewTo(@NonNull View touchView, @NonNull PointF position) { - mWindowViewController.moveViewTo(touchView, (int) position.x, (int) position.y); + public void moveTouchViewTo(@NonNull View touchView, @NonNull PointF cornerPosition) { + mWindowViewController.moveViewTo(touchView, (int) cornerPosition.x, (int) cornerPosition.y); } } diff --git a/hover/src/main/res/values/dimens.xml b/hover/src/main/res/values/dimens.xml index d0eaac0..8e9f9ac 100755 --- a/hover/src/main/res/values/dimens.xml +++ b/hover/src/main/res/values/dimens.xml @@ -1,7 +1,8 @@ 72dp 48dp - 12dp + 12dp + 32dp 8dp 7dp 40dp