package com.example.denky.ageis;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import static com.example.denky.ageis.ReferenceString.ANIMATION_DONE;
import static com.example.denky.ageis.ReferenceString.MAIN_URL;
import static com.example.denky.ageis.ReferenceString.TIME_OF_ANIMATION;
/**
* Created by denky on 2017-06-28.
*/
public class AnimateUniverseBar {
public final int VISIBLE_ANIMATE = 1;
public final int INVISIBLE_ANIMATE = 2;
public void animate(LinearLayout bar, CustomizedWebView wv, int behaviour){
switch (behaviour){
case VISIBLE_ANIMATE :
visibleUniverseBar(bar, wv);
break;
case INVISIBLE_ANIMATE :
invisibleUniverseBar(bar, wv);
break;
}
}
private void visibleUniverseBar(LinearLayout bar, CustomizedWebView wv){
ViewGroup.LayoutParams params = bar.getLayoutParams();
params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
bar.setLayoutParams(params);
wv.scrollTo(0,0);
}
private void invisibleUniverseBar(final LinearLayout bar, CustomizedWebView wv){
if(ANIMATION_DONE == true && !wv.getUrl().equals(MAIN_URL) ) {
TranslateAnimation ani = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, //fromY
Animation.RELATIVE_TO_SELF, -1.0f);//toY
ani.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
ANIMATION_DONE = false;
}
@Override
public void onAnimationEnd(Animation animation) {
ViewGroup.LayoutParams params = bar.getLayoutParams();
params.height = 0;
bar.setLayoutParams(params);
ANIMATION_DONE = true;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
ani.setDuration(TIME_OF_ANIMATION);
bar.startAnimation(ani);
}
}
}
댓글