Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2976d21d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clarify "Clear History" UX." into ub-calculator-euler

parents 6559d35a 532b77ef
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -294,8 +294,8 @@
    <string name="menu_licenses">Open source licenses</string>
    <!-- Menu option to access calculation history. [CHAR_LIMIT=40] -->
    <string name="menu_history">History</string>
    <!-- Menu option to clear calculation history. [CHAR_LIMIT=40] -->
    <string name="menu_clear_history">Clear history</string>
    <!-- Menu option to clear calculation history and memory. [CHAR_LIMIT=40] -->
    <string name="menu_clear_history">Clear</string>

    <!-- Action bar title in history page. [CHAR_LIMIT=40] -->
    <string name="title_history">History</string>
@@ -305,6 +305,11 @@
    <!-- Title for alert dialog when calculation takes too long (timeout). [CHAR_LIMIT=30] -->
    <string name="dialog_timeout">Timeout</string>

    <!--
      Message for alert dialog when user is about to clear history and memory. [CHAR_LIMIT=30]
    -->
    <string name="dialog_clear">Clear history and memory?</string>

    <!-- Title for "current expression" in history page. [CHAR_LIMIT=40] -->
    <string name="title_current_expression">Current Expression</string>
    <!-- Placeholder string when there is no history to be shown. [CHAR_LIMIT=40] -->
+6 −4
Original line number Diff line number Diff line
@@ -62,10 +62,11 @@ public class AlertDialogFragment extends DialogFragment implements DialogInterfa
     * implement AlertDialogFragment.OnClickListener to respond.
     */
    public static void showMessageDialog(Activity activity, @StringRes int title,
            @StringRes int message, @StringRes int positiveButtonLabel) {
            @StringRes int message, @StringRes int positiveButtonLabel, @Nullable String tag) {
        showMessageDialog(activity, title != 0 ? activity.getString(title) : null,
                activity.getString(message),
                positiveButtonLabel != 0 ? activity.getString(positiveButtonLabel) : null);
                positiveButtonLabel != 0 ? activity.getString(positiveButtonLabel) : null,
                tag);
    }

    /**
@@ -78,7 +79,8 @@ public class AlertDialogFragment extends DialogFragment implements DialogInterfa
     * implement AlertDialogFragment.OnClickListener to respond.
     */
    public static void showMessageDialog(Activity activity, @Nullable CharSequence title,
            CharSequence message, @Nullable CharSequence positiveButtonLabel) {
            CharSequence message, @Nullable CharSequence positiveButtonLabel, @Nullable String tag)
    {
        final FragmentManager manager = activity.getFragmentManager();
        if (manager == null || manager.isDestroyed()) {
            return;
@@ -92,7 +94,7 @@ public class AlertDialogFragment extends DialogFragment implements DialogInterfa
        }
        args.putCharSequence(KEY_TITLE, title);
        dialogFragment.setArguments(args);
        dialogFragment.show(manager, null /* tag */);
        dialogFragment.show(manager, tag /* tag */);
    }

    public AlertDialogFragment() {
+17 −3
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.util.Property;
import android.view.ActionMode;
import android.view.KeyCharacterMap;
@@ -1231,8 +1232,21 @@ public class Calculator extends Activity
    @Override
    public void onClick(AlertDialogFragment fragment, int which) {
        if (which == DialogInterface.BUTTON_POSITIVE) {
            if (fragment.getTag() == HistoryFragment.CLEAR_DIALOG_TAG) {
                // TODO: Try to preserve the current, saved, and memory expressions. How should we
                // handle expressions to which they refer?
                // FIXME: This should clearly happen on a background thread.
                mEvaluator.clearEverything();
                // TODO: It's not clear what we should really do here. This is an initial hack.
                // May want to make onClearAnimationEnd() private if/when we fix this.
                onClearAnimationEnd();
                onBackPressed();
            } else if (fragment.getTag() == Evaluator.TIMEOUT_DIALOG_TAG) {
                // Timeout extension request.
                mEvaluator.setLongTimeout();
            } else {
                Log.e(TAG, "Unknown AlertDialogFragment click:" + fragment.getTag());
            }
        }
    }

@@ -1320,7 +1334,7 @@ public class Calculator extends Activity
    }

    private void displayMessage(String title, String message) {
        AlertDialogFragment.showMessageDialog(this, title, message, null);
        AlertDialogFragment.showMessageDialog(this, title, message, null, null /* tag */);
    }

    private void displayFraction() {
+5 −2
Original line number Diff line number Diff line
@@ -99,6 +99,8 @@ public class Evaluator implements CalculatorExpr.ExprResolver {

    private static Evaluator evaluator;

    public static String TIMEOUT_DIALOG_TAG = "timeout";

    public static Evaluator getInstance(Calculator calculator) {
        if (evaluator == null) {
            evaluator = new Evaluator(calculator);
@@ -402,7 +404,7 @@ public class Evaluator implements CalculatorExpr.ExprResolver {
    }

    private void displayCancelledMessage() {
        AlertDialogFragment.showMessageDialog(mActivity, 0, R.string.cancelled, 0);
        AlertDialogFragment.showMessageDialog(mActivity, 0, R.string.cancelled, 0, null);
    }

    // Timeout handling.
@@ -442,7 +444,8 @@ public class Evaluator implements CalculatorExpr.ExprResolver {

    private void displayTimeoutMessage(boolean longTimeout) {
        AlertDialogFragment.showMessageDialog(mActivity, R.string.dialog_timeout,
                R.string.timeout, longTimeout ? 0 : R.string.ok_remove_timeout);
                R.string.timeout, longTimeout ? 0 : R.string.ok_remove_timeout,
                TIMEOUT_DIALOG_TAG);
    }

    public void setLongTimeout() {
+6 −13
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static android.support.v7.widget.RecyclerView.SCROLL_STATE_DRAGGING;
public class HistoryFragment extends Fragment {

    public static final String TAG = "HistoryFragment";
    public static final String CLEAR_DIALOG_TAG = "clear";

    private final DragLayout.DragCallback mDragCallback =
            new DragLayout.DragCallback() {
@@ -112,7 +113,11 @@ public class HistoryFragment extends Fragment {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.menu_clear_history) {
                    clearHistory();
                    final Calculator calculator = (Calculator) getActivity();
                    AlertDialogFragment.showMessageDialog(calculator, "" /* title */,
                            getString(R.string.dialog_clear),
                            getString(R.string.menu_clear_history),
                            CLEAR_DIALOG_TAG);
                    return true;
                }
                return onOptionsItemSelected(item);
@@ -228,18 +233,6 @@ public class HistoryFragment extends Fragment {
        mDragController.initializeController(isResult);
    }

    private void clearHistory() {
        // TODO: Try to preserve the current, saved, and memory expressions. How should we
        // handle expressions to which they refer?
        // FIXME: This should clearly happen on a background thread.
        mEvaluator.clearEverything();
        // TODO: It's not clear what we should really do here. This is an initial hack.
        // May want to make onClearAnimationEnd() private if/when we fix this.
        Calculator calculator = (Calculator) getActivity();
        calculator.onClearAnimationEnd();
        calculator.onBackPressed();
    }

    public boolean stopActionModeOrContextMenu() {
        if (mRecyclerView == null) {
            return false;