mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-15 04:06:31 +00:00
70 lines
No EOL
2.4 KiB
Java
70 lines
No EOL
2.4 KiB
Java
package com.habitrpg.android.habitica.ui.helpers;
|
|
|
|
// https://gist.github.com/lodlock/e3cd12130bad70a098db
|
|
|
|
import android.content.Context;
|
|
import android.support.design.widget.CoordinatorLayout;
|
|
import android.support.design.widget.Snackbar;
|
|
import android.support.v4.view.ViewCompat;
|
|
import android.support.v4.view.ViewPropertyAnimatorListener;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
|
|
import com.github.clans.fab.FloatingActionMenu;
|
|
|
|
import java.util.List;
|
|
|
|
public class FloatingActionMenuBehavior extends CoordinatorLayout.Behavior {
|
|
private float mTranslationY;
|
|
|
|
public FloatingActionMenuBehavior(Context context, AttributeSet attrs) {
|
|
super();
|
|
}
|
|
|
|
@Override
|
|
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
|
|
return dependency instanceof Snackbar.SnackbarLayout;
|
|
}
|
|
|
|
@Override
|
|
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
|
|
if (child instanceof FloatingActionMenu && dependency instanceof Snackbar.SnackbarLayout) {
|
|
this.updateTranslation(parent, child, dependency);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private void updateTranslation(CoordinatorLayout parent, View child, View dependency) {
|
|
float translationY = this.getTranslationY(parent, child);
|
|
if (translationY != this.mTranslationY) {
|
|
ViewCompat.animate(child)
|
|
.cancel();
|
|
if (Math.abs(translationY - this.mTranslationY) == (float) dependency.getHeight()) {
|
|
ViewCompat.animate(child)
|
|
.translationY(translationY)
|
|
.setListener((ViewPropertyAnimatorListener) null);
|
|
} else {
|
|
ViewCompat.setTranslationY(child, translationY);
|
|
}
|
|
|
|
this.mTranslationY = translationY;
|
|
}
|
|
|
|
}
|
|
|
|
private float getTranslationY(CoordinatorLayout parent, View child) {
|
|
float minOffset = 0.0F;
|
|
List dependencies = parent.getDependencies(child);
|
|
int i = 0;
|
|
|
|
for (int z = dependencies.size(); i < z; ++i) {
|
|
View view = (View) dependencies.get(i);
|
|
if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(child, view)) {
|
|
minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - (float) view.getHeight());
|
|
}
|
|
}
|
|
|
|
return minOffset;
|
|
}
|
|
} |