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

import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.view.WindowManager;
import android.support.annotation.Nullable;

/**
* {@link HoverViewState} that includes behavior common to all implementations.
*/
abstract class BaseHoverViewState implements HoverViewState {

private HoverView mHoverView;
private boolean mHasControl = false;
protected HoverView mHoverView;

@CallSuper
@Override
public void takeControl(@NonNull HoverView hoverView) {
mHoverView = hoverView;
}

// Only call this if using HoverMenuView directly in a window.
@Override
public void addToWindow() {
if (!mHoverView.mIsAddedToWindow) {
mHoverView.mWindowViewController.addView(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
false,
mHoverView
);

mHoverView.mIsAddedToWindow = true;

if (mHoverView.mIsTouchableInWindow) {
mHoverView.makeTouchableInWindow();
} else {
mHoverView.makeUntouchableInWindow();
}
public void takeControl(@NonNull HoverView hoverView, Runnable onStateChanged) {
if (mHasControl) {
throw new RuntimeException("Cannot take control of a FloatingTab when we already control one.");
}
mHasControl = true;
mHoverView = hoverView;
}

// Only call this if using HoverMenuView directly in a window.
@CallSuper
@Override
public void removeFromWindow() {
if (mHoverView.mIsAddedToWindow) {
mHoverView.mWindowViewController.removeView(mHoverView);
mHoverView.mIsAddedToWindow = false;
public void giveUpControl(@NonNull HoverViewState nextState) {
if (!mHasControl) {
throw new RuntimeException("Cannot give up control of a FloatingTab when we don't have the control");
}
mHasControl = false;
mHoverView = null;
}

@Override
public void makeTouchableInWindow() {
mHoverView.mIsTouchableInWindow = true;
if (mHoverView.mIsAddedToWindow) {
mHoverView.mWindowViewController.makeTouchable(mHoverView);
}
protected final boolean hasControl() {
return mHasControl;
}

@Override
public void makeUntouchableInWindow() {
mHoverView.mIsTouchableInWindow = false;
if (mHoverView.mIsAddedToWindow) {
mHoverView.mWindowViewController.makeUntouchable(mHoverView);
}
public void setMenu(@Nullable HoverMenu menu) {
}
}
Loading