Auto hide actionbar improvements

pull/212/head
M66B 2 years ago
parent c09d3b4a81
commit be481292cf

@ -20,6 +20,7 @@ package eu.faircode.email;
*/ */
import android.Manifest; import android.Manifest;
import android.animation.Animator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.content.ComponentName; import android.content.ComponentName;
@ -81,6 +82,8 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
private boolean contacts; private boolean contacts;
private List<IKeyPressedListener> keyPressedListeners = new ArrayList<>(); private List<IKeyPressedListener> keyPressedListeners = new ArrayList<>();
private static final long ACTIONBAR_ANIMATION_DURATION = 250L;
@Override @Override
protected void attachBaseContext(Context base) { protected void attachBaseContext(Context base) {
originalContext = base; originalContext = base;
@ -843,15 +846,9 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
public void showActionBar(boolean show) { public void showActionBar(boolean show) {
ViewGroup abv = findViewById(R.id.action_bar); ViewGroup abv = findViewById(R.id.action_bar);
if (abv == null) { if (abv == null)
ActionBar ab = getSupportActionBar();
if (ab == null)
return; return;
if (show)
ab.show();
else
ab.hide();
} else {
if (abShowing == show) if (abShowing == show)
return; return;
abShowing = show; abShowing = show;
@ -859,27 +856,59 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
int height = Helper.getActionBarHeight(this); int height = Helper.getActionBarHeight(this);
int current = abv.getLayoutParams().height; int current = abv.getLayoutParams().height;
int target = (show ? height : 0); int target = (show ? height : 0);
if (abAnimator == null) { Log.i("ActionBar height=" + current + "..." + target);
if (abAnimator != null)
abAnimator.cancel();
abAnimator = ValueAnimator.ofInt(current, target); abAnimator = ValueAnimator.ofInt(current, target);
abAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { abAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override @Override
public void onAnimationUpdate(ValueAnimator anim) { public void onAnimationUpdate(ValueAnimator anim) {
try { try {
abv.getLayoutParams().height = (Integer) anim.getAnimatedValue(); Integer v = (Integer) anim.getAnimatedValue();
Log.i("ActionBar height=" + v);
ViewGroup.LayoutParams lparam = abv.getLayoutParams();
if (lparam.height == v)
Log.i("ActionBar ---");
else {
lparam.height = v;
abv.requestLayout(); abv.requestLayout();
}
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
} }
} }
}); });
} else {
abAnimator.cancel(); abAnimator.addListener(new Animator.AnimatorListener() {
abAnimator.setIntValues(current, target); @Override
public void onAnimationStart(@NonNull Animator animation) {
Log.i("ActionBar start");
} }
abAnimator.setDuration(250L * Math.abs(current - target) / height); @Override
abAnimator.start(); public void onAnimationEnd(@NonNull Animator animation) {
Log.i("ActionBar end");
abAnimator = null;
}
@Override
public void onAnimationCancel(@NonNull Animator animation) {
Log.i("ActionBar cancel");
abAnimator = null;
} }
@Override
public void onAnimationRepeat(@NonNull Animator animation) {
Log.i("ActionBar repeat");
}
});
abAnimator.setDuration(ACTIONBAR_ANIMATION_DURATION * Math.abs(current - target) / height);
abAnimator.start();
} }
Handler getMainHandler() { Handler getMainHandler() {

Loading…
Cancel
Save