Auto hide actionbar improvements

pull/212/head
M66B 3 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,43 +846,69 @@ 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(); return;
if (ab == null)
return; if (abShowing == show)
if (show) return;
ab.show(); abShowing = show;
else
ab.hide(); int height = Helper.getActionBarHeight(this);
} else { int current = abv.getLayoutParams().height;
if (abShowing == show) int target = (show ? height : 0);
return; Log.i("ActionBar height=" + current + "..." + target);
abShowing = show;
int height = Helper.getActionBarHeight(this); if (abAnimator != null)
int current = abv.getLayoutParams().height; abAnimator.cancel();
int target = (show ? height : 0);
if (abAnimator == null) { 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();
abv.requestLayout(); Log.i("ActionBar height=" + v);
} catch (Throwable ex) { ViewGroup.LayoutParams lparam = abv.getLayoutParams();
Log.e(ex); if (lparam.height == v)
} Log.i("ActionBar ---");
else {
lparam.height = v;
abv.requestLayout();
} }
}); } catch (Throwable ex) {
} else { Log.e(ex);
abAnimator.cancel(); }
abAnimator.setIntValues(current, target);
} }
});
abAnimator.setDuration(250L * Math.abs(current - target) / height); abAnimator.addListener(new Animator.AnimatorListener() {
abAnimator.start(); @Override
} public void onAnimationStart(@NonNull Animator animation) {
Log.i("ActionBar start");
}
@Override
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