ExactCalculator: Always show toolbar, remove related code
Change-Id: I33c8142047be89ce7de4f9541a6f86b33674d408
diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java
index a46b6d9..7ef58a8 100644
--- a/src/com/android/calculator2/Calculator.java
+++ b/src/com/android/calculator2/Calculator.java
@@ -57,7 +57,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
-import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.motion.widget.MotionLayout;
@@ -125,10 +124,6 @@
*/
private static final String KEY_EVAL_STATE = NAME + "_eval_state";
private static final String KEY_INVERSE_MODE = NAME + "_inverse_mode";
- /**
- * Associated value is an boolean holding the visibility state of the toolbar.
- */
- private static final String KEY_SHOW_TOOLBAR = NAME + "_show_toolbar";
private final ViewTreeObserver.OnPreDrawListener mPreDrawListener =
new ViewTreeObserver.OnPreDrawListener() {
@@ -222,7 +217,6 @@
private CalculatorState mCurrentState;
private Evaluator mEvaluator;
- private CalculatorDisplay mDisplayView;
private TextView mModeView;
private CalculatorFormula mFormulaText;
private CalculatorResult mResultText;
@@ -289,11 +283,6 @@
mEvaluator.clearMain();
}
}
- if (savedInstanceState.getBoolean(KEY_SHOW_TOOLBAR, true)) {
- showAndMaybeHideToolbar();
- } else {
- mDisplayView.hideToolbar();
- }
onInverseToggled(savedInstanceState.getBoolean(KEY_INVERSE_MODE));
// TODO: We're currently not saving and restoring scroll position.
// We probably should. Details may require care to deal with:
@@ -328,16 +317,7 @@
// Hide all default options in the ActionBar.
getSupportActionBar().setDisplayOptions(0);
- // Ensure the toolbar stays visible while the options menu is displayed.
- getSupportActionBar().addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() {
- @Override
- public void onMenuVisibilityChanged(boolean isVisible) {
- mDisplayView.setForceToolbarVisible(isVisible);
- }
- });
-
mMainCalculator = findViewById(R.id.main_calculator);
- mDisplayView = (CalculatorDisplay) findViewById(R.id.display);
mModeView = (TextView) findViewById(R.id.mode);
mFormulaText = (CalculatorFormula) findViewById(R.id.formula);
mResultText = (CalculatorResult) findViewById(R.id.result);
@@ -409,7 +389,6 @@
} else {
mCurrentState = CalculatorState.INPUT;
mEvaluator.clearMain();
- showAndMaybeHideToolbar();
onInverseToggled(false);
}
restoreDisplay();
@@ -418,9 +397,6 @@
@Override
protected void onResume() {
super.onResume();
- if (mDisplayView.isToolbarVisible()) {
- showAndMaybeHideToolbar();
- }
// If HistoryFragment is showing, hide the main Calculator elements from accessibility.
// This is because Talkback does not use visibility as a cue for RelativeLayout elements,
// and RelativeLayout is the base class of DragLayout.
@@ -448,7 +424,6 @@
}
outState.putByteArray(KEY_EVAL_STATE, byteArrayStream.toByteArray());
outState.putBoolean(KEY_INVERSE_MODE, mInverseToggle.isSelected());
- outState.putBoolean(KEY_SHOW_TOOLBAR, mDisplayView.isToolbarVisible());
// We must wait for asynchronous writes to complete, since outState may contain
// references to expressions being written.
mEvaluator.waitForWrites();
@@ -728,29 +703,6 @@
}
}
- /**
- * Show the toolbar.
- * Automatically hide it again if it's not relevant to current formula.
- */
- private void showAndMaybeHideToolbar() {
- final boolean shouldBeVisible =
- mCurrentState == CalculatorState.INPUT && mEvaluator.hasTrigFuncs();
- mDisplayView.showToolbar(!shouldBeVisible);
- }
-
- /**
- * Display or hide the toolbar depending on calculator state.
- */
- private void showOrHideToolbar() {
- final boolean shouldBeVisible =
- mCurrentState == CalculatorState.INPUT && mEvaluator.hasTrigFuncs();
- if (shouldBeVisible) {
- mDisplayView.showToolbar(false);
- } else {
- mDisplayView.hideToolbar();
- }
- }
-
public void onButtonClick(View view) {
// Any animation is ended before we get here.
stopActionModeOrContextMenu();
@@ -785,8 +737,6 @@
// In input mode, we reinterpret already entered trig functions.
mEvaluator.setDegreeMode(mode);
onModeChanged(mode);
- // Show the toolbar to highlight the mode change.
- showAndMaybeHideToolbar();
setState(CalculatorState.INPUT);
mResultText.clear();
if (!haveUnprocessed()) {
@@ -816,7 +766,6 @@
redisplayAfterFormulaChange();
}
}
- showOrHideToolbar();
}
void redisplayFormula() {
@@ -968,7 +917,6 @@
cancelIfEvaluating(true);
announceClearedForAccessibility();
onClearEnd();
- showOrHideToolbar();
}
// Evaluation encountered en error. Display the error.
@@ -1279,12 +1227,10 @@
// There are characters left, but we can't convert them to button presses.
mUnprocessedChars = moreChars.substring(current);
redisplayAfterFormulaChange();
- showOrHideToolbar();
return;
}
mUnprocessedChars = null;
redisplayAfterFormulaChange();
- showOrHideToolbar();
}
private void clearIfNotInputState() {
diff --git a/src/com/android/calculator2/CalculatorDisplay.java b/src/com/android/calculator2/CalculatorDisplay.java
index 9960cb2..9403495 100644
--- a/src/com/android/calculator2/CalculatorDisplay.java
+++ b/src/com/android/calculator2/CalculatorDisplay.java
@@ -17,52 +17,11 @@
package com.android.calculator2;
import android.content.Context;
-import android.transition.Fade;
-import android.transition.Transition;
-import android.transition.TransitionManager;
import android.util.AttributeSet;
-import android.view.GestureDetector;
-import android.view.MotionEvent;
import android.view.View;
-import android.view.accessibility.AccessibilityManager;
import android.widget.LinearLayout;
-import androidx.appcompat.widget.Toolbar;
-
-public class CalculatorDisplay extends LinearLayout
- implements AccessibilityManager.AccessibilityStateChangeListener {
-
- /**
- * The duration in milliseconds after which to hide the toolbar.
- */
- private static final long AUTO_HIDE_DELAY_MILLIS = 3000L;
-
- /**
- * The duration in milliseconds to fade in/out the toolbar.
- */
- private static final long FADE_DURATION = 200L;
-
- private final Runnable mHideToolbarRunnable = new Runnable() {
- @Override
- public void run() {
- // Remove any duplicate callbacks to hide the toolbar.
- removeCallbacks(this);
-
- // Only animate if we have been laid out at least once.
- if (isLaidOut()) {
- TransitionManager.beginDelayedTransition(CalculatorDisplay.this, mTransition);
- }
- mToolbar.setVisibility(View.INVISIBLE);
- }
- };
-
- private final AccessibilityManager mAccessibilityManager;
- private final GestureDetector mTapDetector;
-
- private Toolbar mToolbar;
- private Transition mTransition;
-
- private boolean mForceToolbarVisible;
+public class CalculatorDisplay extends LinearLayout {
public CalculatorDisplay(Context context) {
this(context, null /* attrs */);
@@ -75,129 +34,13 @@
public CalculatorDisplay(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- mAccessibilityManager =
- (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
-
- mTapDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
- @Override
- public boolean onDown(MotionEvent e) {
- // Remove callbacks to hide the toolbar.
- removeCallbacks(mHideToolbarRunnable);
-
- return true;
- }
-
- @Override
- public boolean onSingleTapConfirmed(MotionEvent e) {
- if (mToolbar.getVisibility() != View.VISIBLE) {
- showToolbar(true);
- } else {
- hideToolbar();
- }
-
- return true;
- }
- });
-
// Draw the children in reverse order so that the toolbar is on top.
setChildrenDrawingOrderEnabled(true);
}
@Override
- protected void onFinishInflate() {
- super.onFinishInflate();
-
- mToolbar = (Toolbar) findViewById(R.id.toolbar);
- mTransition = new Fade()
- .setDuration(FADE_DURATION)
- .addTarget(mToolbar);
- }
-
- @Override
protected int getChildDrawingOrder(int childCount, int i) {
// Reverse the normal drawing order.
return (childCount - 1) - i;
}
-
- @Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- mAccessibilityManager.addAccessibilityStateChangeListener(this);
- }
-
- @Override
- protected void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- mAccessibilityManager.removeAccessibilityStateChangeListener(this);
- }
-
- @Override
- public void onAccessibilityStateChanged(boolean enabled) {
- // Always show the toolbar whenever accessibility is enabled.
- showToolbar(true);
- }
-
- @Override
- public boolean onInterceptTouchEvent(MotionEvent event) {
- mTapDetector.onTouchEvent(event);
- return super.onInterceptTouchEvent(event);
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- return mTapDetector.onTouchEvent(event) || super.onTouchEvent(event);
- }
-
- /**
- * Returns {@code true} if the toolbar should remain visible.
- */
- public boolean getForceToolbarVisible() {
- return mForceToolbarVisible || mAccessibilityManager.isEnabled();
- }
-
- /**
- * Forces the toolbar to remain visible.
- *
- * @param forceToolbarVisible {@code true} to keep the toolbar visible
- */
- public void setForceToolbarVisible(boolean forceToolbarVisible) {
- if (mForceToolbarVisible != forceToolbarVisible) {
- mForceToolbarVisible = forceToolbarVisible;
- showToolbar(!forceToolbarVisible);
- }
- }
-
- /**
- * Shows the toolbar.
- * @param autoHide Automatically ide toolbar again after delay
- */
- public void showToolbar(boolean autoHide) {
- // Only animate if we have been laid out at least once.
- if (isLaidOut()) {
- TransitionManager.beginDelayedTransition(this, mTransition);
- }
- mToolbar.setVisibility(View.VISIBLE);
-
- // Remove callbacks to hide the toolbar.
- removeCallbacks(mHideToolbarRunnable);
-
- // Auto hide the toolbar after 3 seconds.
- if (autoHide && !getForceToolbarVisible()) {
- postDelayed(mHideToolbarRunnable, AUTO_HIDE_DELAY_MILLIS);
- }
- }
-
- /**
- * Hides the toolbar.
- */
- public void hideToolbar() {
- if (!getForceToolbarVisible()) {
- removeCallbacks(mHideToolbarRunnable);
- mHideToolbarRunnable.run();
- }
- }
-
- public boolean isToolbarVisible() {
- return mToolbar.getVisibility() == View.VISIBLE;
- }
}