Skip to content
This repository was archived by the owner on Feb 9, 2023. It is now read-only.
Merged
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 @@ -16,6 +16,7 @@
package io.mattcarroll.hover;

import android.graphics.Point;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.util.ListUpdateCallback;
Expand All @@ -40,6 +41,7 @@ class HoverViewStateCollapsed extends BaseHoverViewState {
private static final String TAG = "HoverViewStateCollapsed";
private static final float MIN_TAB_VERTICAL_POSITION = 0.0f;
private static final float MAX_TAB_VERTICAL_POSITION = 1.0f;
private static final long ALPHA_IDLE_MILLIS = 5000;

protected HoverView mHoverView;
private FloatingTab mFloatingTab;
Expand All @@ -50,6 +52,15 @@ class HoverViewStateCollapsed extends BaseHoverViewState {
private boolean mIsDocked = false;
private Dragger.DragListener mDragListener;
private Listener mListener;
private Handler mHandler = new Handler();
private Runnable mAlphaChanger = new Runnable() {
@Override
public void run() {
if (!(mHoverView.mState instanceof HoverViewStatePreviewed) && mHoverView.mState instanceof HoverViewStateCollapsed) {
mHoverView.setAlpha(0.5f);
}
}
};

private final View.OnLayoutChangeListener mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
@Override
Expand Down Expand Up @@ -128,6 +139,8 @@ public void run() {
if (null != mHoverView.mMenu) {
listenForMenuChanges();
}

scheduleHoverViewAlphaChange();
}

@Override
Expand Down Expand Up @@ -156,6 +169,8 @@ protected void changeState(@NonNull HoverViewState nextState) {
throw new RuntimeException("Cannot give control to another HoverMenuController when we don't have the HoverTab.");
}

restoreHoverViewAlphaValue();

mFloatingTab.removeOnLayoutChangeListener(mOnLayoutChangeListener);

if (null != mHoverView.mMenu) {
Expand Down Expand Up @@ -254,6 +269,7 @@ private void onPickedUpByUser() {
if (null != mListener) {
mListener.onDragStart();
}
restoreHoverViewAlphaValue();
}

private void onDroppedByUser() {
Expand Down Expand Up @@ -340,6 +356,7 @@ private void onDocked() {
Log.d(TAG, "Docked. Activating dragger.");
mIsDocked = true;
activateDragger();
scheduleHoverViewAlphaChange();

// We consider ourselves having gone from "collapsing" to "collapsed" upon the very first dock.
boolean didJustCollapse = !mIsCollapsed;
Expand All @@ -366,6 +383,15 @@ private void deactivateDragger() {
mHoverView.mDragger.deactivate();
}

private void scheduleHoverViewAlphaChange() {
mHandler.postDelayed(mAlphaChanger, ALPHA_IDLE_MILLIS);
}

protected void restoreHoverViewAlphaValue() {
mHandler.removeCallbacks(mAlphaChanger);
mHoverView.setAlpha(1f);
}

public interface Listener {
void onCollapsing();

Expand Down