mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
Updated BottomBarBehavior
This commit is contained in:
parent
d6b1641854
commit
ec3de5c320
2 changed files with 36 additions and 82 deletions
|
@ -1,102 +1,56 @@
|
|||
/*
|
||||
* Copyright (C) 2015 takahirom
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.github.dfa.diaspora_android.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.ViewPropertyAnimatorListener;
|
||||
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 21.06.16.
|
||||
*/
|
||||
public class BottomBarBehavior extends CoordinatorLayout.Behavior<LinearLayout> {
|
||||
private static final FastOutSlowInInterpolator INTERPOLATOR = new FastOutSlowInInterpolator();
|
||||
private boolean mIsAnimatingOut = false;
|
||||
|
||||
private int defaultDependencyTop = -1;
|
||||
|
||||
public BottomBarBehavior(Context context, AttributeSet attrs) {
|
||||
super();
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final LinearLayout child,
|
||||
final View directTargetChild, final View target, final int nestedScrollAxes) {
|
||||
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
|
||||
|| super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
|
||||
public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) {
|
||||
return dependency instanceof AppBarLayout;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final LinearLayout child,
|
||||
final View target, final int dxConsumed, final int dyConsumed,
|
||||
final int dxUnconsumed, final int dyUnconsumed) {
|
||||
|
||||
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
|
||||
if (dyConsumed < 0 && !this.mIsAnimatingOut && child.getVisibility() == View.VISIBLE) {
|
||||
// User scrolled down and the FAB is currently visible -> hide the FAB
|
||||
animateOut(child);
|
||||
} else if (dyConsumed > 0 && child.getVisibility() != View.VISIBLE) {
|
||||
// User scrolled up and the FAB is currently not visible -> show the FAB
|
||||
animateIn(child);
|
||||
public boolean onDependentViewChanged(CoordinatorLayout parent, LinearLayout child, View dependency) {
|
||||
if (defaultDependencyTop == -1) {
|
||||
defaultDependencyTop = dependency.getTop();
|
||||
}
|
||||
Log.d("BOTTOMBAR", "c.h"+child.getHeight()+" c.top"+child.getTop()
|
||||
+" c.tran_y"+child.getTranslationY()
|
||||
+" d.h"+dependency.getHeight()+" d.top"+dependency.getTop()
|
||||
+"d.tran_y"+dependency.getTranslationY());
|
||||
if(dependency.getTop()<0)
|
||||
child.setTranslationY(-dependency.getTop() + defaultDependencyTop);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void animateOut(final LinearLayout linearLayout) {
|
||||
if (Build.VERSION.SDK_INT >= 14) {
|
||||
ViewCompat.animate(linearLayout).translationY(168F).alpha(0.0F).setInterpolator(INTERPOLATOR).withLayer()
|
||||
.setListener(new ViewPropertyAnimatorListener() {
|
||||
public void onAnimationStart(View view) {
|
||||
BottomBarBehavior.this.mIsAnimatingOut = true;
|
||||
}
|
||||
|
||||
public void onAnimationCancel(View view) {
|
||||
BottomBarBehavior.this.mIsAnimatingOut = false;
|
||||
}
|
||||
|
||||
public void onAnimationEnd(View view) {
|
||||
BottomBarBehavior.this.mIsAnimatingOut = false;
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
}).start();
|
||||
} else {
|
||||
Animation anim = AnimationUtils.loadAnimation(linearLayout.getContext(), R.anim.bottom_bar_up);
|
||||
anim.setInterpolator(INTERPOLATOR);
|
||||
anim.setDuration(200L);
|
||||
anim.setAnimationListener(new Animation.AnimationListener() {
|
||||
public void onAnimationStart(Animation animation) {
|
||||
BottomBarBehavior.this.mIsAnimatingOut = true;
|
||||
}
|
||||
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
BottomBarBehavior.this.mIsAnimatingOut = false;
|
||||
linearLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(final Animation animation) {
|
||||
}
|
||||
});
|
||||
linearLayout.startAnimation(anim);
|
||||
}
|
||||
}
|
||||
|
||||
private void animateIn(LinearLayout linearLayout) {
|
||||
linearLayout.setVisibility(View.VISIBLE);
|
||||
if (Build.VERSION.SDK_INT >= 14) {
|
||||
ViewCompat.animate(linearLayout).translationY(0).scaleX(1.0F).scaleY(1.0F).alpha(1.0F)
|
||||
.setInterpolator(INTERPOLATOR).withLayer().setListener(null)
|
||||
.start();
|
||||
} else {
|
||||
Animation anim = AnimationUtils.loadAnimation(linearLayout.getContext(), R.anim.bottom_bar_down);
|
||||
anim.setDuration(200L);
|
||||
anim.setInterpolator(INTERPOLATOR);
|
||||
linearLayout.startAnimation(anim);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,11 +11,11 @@
|
|||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<com.github.dfa.diaspora_android.ui.ContextMenuWebView
|
||||
android:id="@+id/webView"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
|
|
Loading…
Reference in a new issue