summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-02-02 20:38:14 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-02-02 20:38:15 +0000
commit7b5ff1f8893280e2328cea2811a8da2184802ac1 (patch)
tree9dd90838aecaead0297b098c9a5938345d1106a3
parent330419a18bdd405c4882e00c78ffabcd8076995e (diff)
parentbfffafdedddbbd1d6d8d0ab15130753b1b31affc (diff)
downloadandroid_packages_apps_ExactCalculator-7b5ff1f8893280e2328cea2811a8da2184802ac1.tar.gz
android_packages_apps_ExactCalculator-7b5ff1f8893280e2328cea2811a8da2184802ac1.tar.bz2
android_packages_apps_ExactCalculator-7b5ff1f8893280e2328cea2811a8da2184802ac1.zip
Merge "Snapshot display empty state once on creation of HistoryFragment." into ub-calculator-euler
-rw-r--r--src/com/android/calculator2/DragController.java15
-rw-r--r--src/com/android/calculator2/EvaluatorStateUtils.java32
-rw-r--r--src/com/android/calculator2/HistoryAdapter.java9
-rw-r--r--src/com/android/calculator2/HistoryFragment.java21
4 files changed, 31 insertions, 46 deletions
diff --git a/src/com/android/calculator2/DragController.java b/src/com/android/calculator2/DragController.java
index 8810e7d..1716cc9 100644
--- a/src/com/android/calculator2/DragController.java
+++ b/src/com/android/calculator2/DragController.java
@@ -57,6 +57,7 @@ public final class DragController {
private boolean mAnimationInitialized;
private boolean mOneLine;
+ private boolean mIsDisplayEmpty;
private AnimationController mAnimationController;
@@ -66,9 +67,10 @@ public final class DragController {
mEvaluator = evaluator;
}
- public void initializeController(boolean isResult, boolean oneLine) {
+ public void initializeController(boolean isResult, boolean oneLine, boolean isDisplayEmpty) {
mOneLine = oneLine;
- if (EvaluatorStateUtils.isDisplayEmpty(mEvaluator)) {
+ mIsDisplayEmpty = isDisplayEmpty;
+ if (mIsDisplayEmpty) {
// Empty display
mAnimationController = new EmptyAnimationController();
} else if (isResult) {
@@ -107,7 +109,8 @@ public final class DragController {
if (yFraction > 0 && vh != null) {
recyclerView.setVisibility(View.VISIBLE);
}
- if (vh != null && !EvaluatorStateUtils.isDisplayEmpty(mEvaluator)) {
+ if (vh != null && !mIsDisplayEmpty
+ && vh.getItemViewType() == HistoryAdapter.HISTORY_VIEW_TYPE) {
final AlignedTextView formula = vh.getFormula();
final CalculatorResult result = vh.getResult();
final TextView date = vh.getDate();
@@ -157,7 +160,7 @@ public final class DragController {
date.setTranslationY(mAnimationController.getDateTranslationY(yFraction));
divider.setTranslationY(mAnimationController.getDateTranslationY(yFraction));
- } else if (EvaluatorStateUtils.isDisplayEmpty(mEvaluator)) {
+ } else if (mIsDisplayEmpty) {
// There is no current expression but we still need to collect information
// to translate the other viewholders.
if (!mAnimationInitialized) {
@@ -186,9 +189,9 @@ public final class DragController {
/**
* Reset all initialized values.
*/
- public void initializeAnimation(boolean isResult, boolean oneLine) {
+ public void initializeAnimation(boolean isResult, boolean oneLine, boolean isDisplayEmpty) {
mAnimationInitialized = false;
- initializeController(isResult, oneLine);
+ initializeController(isResult, oneLine, isDisplayEmpty);
}
public interface AnimateTextInterface {
diff --git a/src/com/android/calculator2/EvaluatorStateUtils.java b/src/com/android/calculator2/EvaluatorStateUtils.java
deleted file mode 100644
index 2d8eddc..0000000
--- a/src/com/android/calculator2/EvaluatorStateUtils.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * 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.android.calculator2;
-
-/**
- * Utils class to get the state of the passed-in Evaluator.
- */
-
-public class EvaluatorStateUtils {
- public static boolean isDisplayEmpty(Evaluator evaluator) {
- if (evaluator != null) {
- final CalculatorExpr mainExpr = evaluator.getExpr(Evaluator.MAIN_INDEX);
- return mainExpr == null || mainExpr.isEmpty();
- } else {
- return true;
- }
- }
-}
diff --git a/src/com/android/calculator2/HistoryAdapter.java b/src/com/android/calculator2/HistoryAdapter.java
index fe2f2c0..629abe9 100644
--- a/src/com/android/calculator2/HistoryAdapter.java
+++ b/src/com/android/calculator2/HistoryAdapter.java
@@ -34,7 +34,7 @@ public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHold
private static final String TAG = "HistoryAdapter";
private static final int EMPTY_VIEW_TYPE = 0;
- private static final int HISTORY_VIEW_TYPE = 1;
+ public static final int HISTORY_VIEW_TYPE = 1;
private Evaluator mEvaluator;
@@ -44,6 +44,7 @@ public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHold
private boolean mIsResultLayout;
private boolean mIsOneLine;
+ private boolean mIsDisplayEmpty;
public HistoryAdapter(ArrayList<HistoryItem> dataSet) {
mDataSet = dataSet;
@@ -135,12 +136,16 @@ public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHold
mIsOneLine = isOneLine;
}
+ public void setIsDisplayEmpty(boolean isDisplayEmpty) {
+ mIsDisplayEmpty = isDisplayEmpty;
+ }
+
public void setEvaluator(Evaluator evaluator) {
mEvaluator = evaluator;
}
private int getEvaluatorIndex(int position) {
- if (EvaluatorStateUtils.isDisplayEmpty(mEvaluator) || mIsResultLayout) {
+ if (mIsDisplayEmpty || mIsResultLayout) {
return (int) (mEvaluator.getMaxIndex() - position);
} else {
// Account for the additional "Current Expression" with the +1.
diff --git a/src/com/android/calculator2/HistoryFragment.java b/src/com/android/calculator2/HistoryFragment.java
index 7da375d..6847cc9 100644
--- a/src/com/android/calculator2/HistoryFragment.java
+++ b/src/com/android/calculator2/HistoryFragment.java
@@ -47,6 +47,8 @@ public class HistoryFragment extends Fragment implements DragLayout.DragCallback
private ArrayList<HistoryItem> mDataSet = new ArrayList<>();
+ private boolean mIsDisplayEmpty;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -113,13 +115,19 @@ public class HistoryFragment extends Fragment implements DragLayout.DragCallback
final boolean isResultLayout = activity.isResultLayout();
final boolean isOneLine = activity.isOneLine();
- initializeController(isResultLayout, isOneLine);
+ // Snapshot display state here. For the rest of the lifecycle of this current
+ // HistoryFragment, this is what we will consider the display state.
+ // In rare cases, the display state can change after our adapter is initialized.
+ final CalculatorExpr mainExpr = mEvaluator.getExpr(Evaluator.MAIN_INDEX);
+ mIsDisplayEmpty = mainExpr == null || mainExpr.isEmpty();
+
+ initializeController(isResultLayout, isOneLine, mIsDisplayEmpty);
final long maxIndex = mEvaluator.getMaxIndex();
final ArrayList<HistoryItem> newDataSet = new ArrayList<>();
- if (!EvaluatorStateUtils.isDisplayEmpty(mEvaluator) && !isResultLayout) {
+ if (!mIsDisplayEmpty && !isResultLayout) {
// Add the current expression as the first element in the list (the layout is
// reversed and we want the current expression to be the last one in the
// RecyclerView).
@@ -142,7 +150,7 @@ public class HistoryFragment extends Fragment implements DragLayout.DragCallback
mAdapter.setDataSet(mDataSet);
mAdapter.setIsResultLayout(isResultLayout);
mAdapter.setIsOneLine(activity.isOneLine());
-
+ mAdapter.setIsDisplayEmpty(mIsDisplayEmpty);
mAdapter.notifyDataSetChanged();
}
@@ -151,7 +159,8 @@ public class HistoryFragment extends Fragment implements DragLayout.DragCallback
super.onStart();
final Calculator activity = (Calculator) getActivity();
- mDragController.initializeAnimation(activity.isResultLayout(), activity.isOneLine());
+ mDragController.initializeAnimation(activity.isResultLayout(), activity.isOneLine(),
+ mIsDisplayEmpty);
}
@Override
@@ -181,14 +190,14 @@ public class HistoryFragment extends Fragment implements DragLayout.DragCallback
}
}
- private void initializeController(boolean isResult, boolean isOneLine) {
+ private void initializeController(boolean isResult, boolean isOneLine, boolean isDisplayEmpty) {
mDragController.setDisplayFormula(
(CalculatorFormula) getActivity().findViewById(R.id.formula));
mDragController.setDisplayResult(
(CalculatorResult) getActivity().findViewById(R.id.result));
mDragController.setToolbar(getActivity().findViewById(R.id.toolbar));
mDragController.setEvaluator(mEvaluator);
- mDragController.initializeController(isResult, isOneLine);
+ mDragController.initializeController(isResult, isOneLine, isDisplayEmpty);
}
public boolean stopActionModeOrContextMenu() {