Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 1 | /* |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 2 | * Copyright (C) 2015 The Android Open Source Project |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.calculator2; |
| 18 | |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 19 | import android.content.ClipData; |
| 20 | import android.content.ClipDescription; |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 21 | import android.content.ClipboardManager; |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 23 | import android.text.Layout; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 24 | import android.text.SpannableString; |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 25 | import android.text.Spanned; |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 26 | import android.text.TextPaint; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 27 | import android.text.style.ForegroundColorSpan; |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 28 | import android.util.AttributeSet; |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 29 | import android.view.ActionMode; |
| 30 | import android.view.GestureDetector; |
| 31 | import android.view.Menu; |
| 32 | import android.view.MenuInflater; |
| 33 | import android.view.MenuItem; |
| 34 | import android.view.MotionEvent; |
| 35 | import android.view.View; |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 36 | import android.widget.OverScroller; |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 37 | import android.widget.Toast; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 38 | |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 39 | // A text widget that is "infinitely" scrollable to the right, |
| 40 | // and obtains the text to display via a callback to Logic. |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 41 | public class CalculatorResult extends AlignedTextView { |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 42 | static final int MAX_RIGHT_SCROLL = 10000000; |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 43 | static final int INVALID = MAX_RIGHT_SCROLL + 10000; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 44 | // A larger value is unlikely to avoid running out of space |
| 45 | final OverScroller mScroller; |
| 46 | final GestureDetector mGestureDetector; |
| 47 | class MyTouchListener implements View.OnTouchListener { |
| 48 | @Override |
| 49 | public boolean onTouch(View v, MotionEvent event) { |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 50 | return mGestureDetector.onTouchEvent(event); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | final MyTouchListener mTouchListener = new MyTouchListener(); |
| 54 | private Evaluator mEvaluator; |
| 55 | private boolean mScrollable = false; |
| 56 | // A scrollable result is currently displayed. |
Hans Boehm | 760a9dc | 2015-04-20 10:27:12 -0700 | [diff] [blame] | 57 | private boolean mValid = false; |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 58 | // The result holds something valid; either a a number or an error |
| 59 | // message. |
| 60 | private int mCurrentPos;// Position of right of display relative to decimal point, in pixels. |
| 61 | // Large positive values mean the decimal point is scrolled off the |
| 62 | // left of the display. Zero means decimal point is barely displayed |
| 63 | // on the right. |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 64 | private int mLastPos; // Position already reflected in display. Pixels. |
| 65 | private int mMinPos; // Minimum position before all digits disappear off the right. Pixels. |
| 66 | private int mMaxPos; // Maximum position before we start displaying the infinite |
| 67 | // sequence of trailing zeroes on the right. Pixels. |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 68 | private int mMaxCharPos; // The same, but in characters. |
| 69 | private int mLsd; // Position of least-significant digit in result |
| 70 | // (1 = tenths, -1 = tens), or Integer.MAX_VALUE. |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 71 | private int mLastDisplayedDigit; // Position of last digit actually displayed after adding |
| 72 | // exponent. |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 73 | private final Object mWidthLock = new Object(); |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 74 | // Protects the next two fields. |
| 75 | private int mWidthConstraint = -1; |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 76 | // Our total width in pixels minus space for ellipsis. |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 77 | private float mCharWidth = 1; |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 78 | // Maximum character width. For now we pretend that all characters |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 79 | // have this width. |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 80 | // TODO: We're not really using a fixed width font. But it appears |
| 81 | // to be close enough for the characters we use that the difference |
| 82 | // is not noticeable. |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 83 | private static final int MAX_WIDTH = 100; |
| 84 | // Maximum number of digits displayed |
Hans Boehm | 50ed320 | 2015-06-09 14:35:49 -0700 | [diff] [blame] | 85 | public static final int MAX_LEADING_ZEROES = 6; |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 86 | // Maximum number of leading zeroes after decimal point before we |
| 87 | // switch to scientific notation with negative exponent. |
Hans Boehm | 50ed320 | 2015-06-09 14:35:49 -0700 | [diff] [blame] | 88 | public static final int MAX_TRAILING_ZEROES = 6; |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 89 | // Maximum number of trailing zeroes before the decimal point before |
| 90 | // we switch to scientific notation with positive exponent. |
| 91 | private static final int SCI_NOTATION_EXTRA = 1; |
| 92 | // Extra digits for standard scientific notation. In this case we |
| 93 | // have a deecimal point and no ellipsis. |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 94 | private ActionMode mActionMode; |
| 95 | private final ForegroundColorSpan mExponentColorSpan; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 96 | |
| 97 | public CalculatorResult(Context context, AttributeSet attrs) { |
| 98 | super(context, attrs); |
| 99 | mScroller = new OverScroller(context); |
| 100 | mGestureDetector = new GestureDetector(context, |
| 101 | new GestureDetector.SimpleOnGestureListener() { |
| 102 | @Override |
Justin Klaassen | d48b756 | 2015-04-16 16:51:38 -0700 | [diff] [blame] | 103 | public boolean onDown(MotionEvent e) { |
| 104 | return true; |
| 105 | } |
| 106 | @Override |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 107 | public boolean onFling(MotionEvent e1, MotionEvent e2, |
| 108 | float velocityX, float velocityY) { |
| 109 | if (!mScroller.isFinished()) { |
| 110 | mCurrentPos = mScroller.getFinalX(); |
| 111 | } |
| 112 | mScroller.forceFinished(true); |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 113 | stopActionMode(); |
Hans Boehm | fbcef70 | 2015-04-27 18:07:47 -0700 | [diff] [blame] | 114 | CalculatorResult.this.cancelLongPress(); |
| 115 | // Ignore scrolls of error string, etc. |
| 116 | if (!mScrollable) return true; |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 117 | mScroller.fling(mCurrentPos, 0, - (int) velocityX, 0 /* horizontal only */, |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 118 | mMinPos, mMaxPos, 0, 0); |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 119 | postInvalidateOnAnimation(); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 120 | return true; |
| 121 | } |
| 122 | @Override |
| 123 | public boolean onScroll(MotionEvent e1, MotionEvent e2, |
| 124 | float distanceX, float distanceY) { |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 125 | int distance = (int)distanceX; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 126 | if (!mScroller.isFinished()) { |
| 127 | mCurrentPos = mScroller.getFinalX(); |
| 128 | } |
| 129 | mScroller.forceFinished(true); |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 130 | stopActionMode(); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 131 | CalculatorResult.this.cancelLongPress(); |
| 132 | if (!mScrollable) return true; |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 133 | if (mCurrentPos + distance < mMinPos) { |
| 134 | distance = mMinPos - mCurrentPos; |
| 135 | } else if (mCurrentPos + distance > mMaxPos) { |
| 136 | distance = mMaxPos - mCurrentPos; |
| 137 | } |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 138 | int duration = (int)(e2.getEventTime() - e1.getEventTime()); |
| 139 | if (duration < 1 || duration > 100) duration = 10; |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 140 | mScroller.startScroll(mCurrentPos, 0, distance, 0, (int)duration); |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 141 | postInvalidateOnAnimation(); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 142 | return true; |
| 143 | } |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 144 | @Override |
| 145 | public void onLongPress(MotionEvent e) { |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 146 | if (mValid) { |
| 147 | mActionMode = startActionMode(mCopyActionModeCallback, |
| 148 | ActionMode.TYPE_FLOATING); |
| 149 | } |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 150 | } |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 151 | }); |
| 152 | setOnTouchListener(mTouchListener); |
| 153 | setHorizontallyScrolling(false); // do it ourselves |
| 154 | setCursorVisible(false); |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 155 | mExponentColorSpan = new ForegroundColorSpan( |
| 156 | context.getColor(R.color.display_result_exponent_text_color)); |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 157 | |
| 158 | // Copy ActionMode is triggered explicitly, not through |
| 159 | // setCustomSelectionActionModeCallback. |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void setEvaluator(Evaluator evaluator) { |
| 163 | mEvaluator = evaluator; |
| 164 | } |
| 165 | |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 166 | @Override |
| 167 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 168 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 169 | |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 170 | final TextPaint paint = getPaint(); |
| 171 | final int newWidthConstraint = MeasureSpec.getSize(widthMeasureSpec) |
| 172 | - (getPaddingLeft() + getPaddingRight()) |
| 173 | - (int) Math.ceil(Layout.getDesiredWidth(KeyMaps.ELLIPSIS, paint)); |
| 174 | final float newCharWidth = Layout.getDesiredWidth("\u2007", paint); |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 175 | synchronized(mWidthLock) { |
Hans Boehm | 013969e | 2015-04-13 20:29:47 -0700 | [diff] [blame] | 176 | mWidthConstraint = newWidthConstraint; |
| 177 | mCharWidth = newCharWidth; |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 181 | // Return the length of the exponent representation for the given exponent, in |
| 182 | // characters. |
| 183 | private final int expLen(int exp) { |
| 184 | if (exp == 0) return 0; |
| 185 | return (int)Math.ceil(Math.log10(Math.abs((double)exp))) + (exp >= 0 ? 1 : 2); |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 188 | /** |
| 189 | * Initiate display of a new result. |
| 190 | * The parameters specify various properties of the result. |
| 191 | * @param initPrec Initial display precision computed by evaluator. (1 = tenths digit) |
| 192 | * @param msd Position of most significant digit. Offset from left of string. |
| 193 | Evaluator.INVALID_MSD if unknown. |
| 194 | * @param leastDigPos Position of least significant digit (1 = tenths digit) |
| 195 | * or Integer.MAX_VALUE. |
| 196 | * @param truncatedWholePart Result up to but not including decimal point. |
| 197 | Currently we only use the length. |
| 198 | */ |
| 199 | void displayResult(int initPrec, int msd, int leastDigPos, String truncatedWholePart) { |
| 200 | initPositions(initPrec, msd, leastDigPos, truncatedWholePart); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 201 | redisplay(); |
| 202 | } |
| 203 | |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 204 | /** |
| 205 | * Set up scroll bounds and determine whether the result is scrollable, based on the |
| 206 | * supplied information about the result. |
| 207 | * This is unfortunately complicated because we need to predict whether trailing digits |
| 208 | * will eventually be replaced by an exponent. |
| 209 | * Just appending the exponent during formatting would be simpler, but would produce |
| 210 | * jumpier results during transitions. |
| 211 | */ |
| 212 | private void initPositions(int initPrec, int msd, int leastDigPos, String truncatedWholePart) { |
| 213 | float charWidth; |
| 214 | int maxChars = getMaxChars(); |
| 215 | mLastPos = INVALID; |
| 216 | mLsd = leastDigPos; |
| 217 | synchronized(mWidthLock) { |
| 218 | charWidth = mCharWidth; |
| 219 | } |
| 220 | mCurrentPos = mMinPos = (int) Math.round(initPrec * charWidth); |
| 221 | // Prevent scrolling past initial position, which is calculated to show leading digits. |
| 222 | if (msd == Evaluator.INVALID_MSD) { |
| 223 | // Possible zero value |
| 224 | if (leastDigPos == Integer.MIN_VALUE) { |
| 225 | // Definite zero value. |
| 226 | mMaxPos = mMinPos; |
| 227 | mMaxCharPos = (int) Math.round(mMaxPos/charWidth); |
| 228 | mScrollable = false; |
| 229 | } else { |
| 230 | // May be very small nonzero value. Allow user to find out. |
| 231 | mMaxPos = mMaxCharPos = MAX_RIGHT_SCROLL; |
| 232 | mScrollable = true; |
| 233 | } |
| 234 | return; |
| 235 | } |
| 236 | int wholeLen = truncatedWholePart.length(); |
| 237 | int negative = truncatedWholePart.charAt(0) == '-' ? 1 : 0; |
| 238 | boolean adjustedForExp = false; // Adjusted for normal exponent. |
| 239 | if (msd > wholeLen && msd <= wholeLen + 3) { |
| 240 | // Avoid tiny negative exponent; pretend msd is just to the right of decimal point. |
| 241 | msd = wholeLen - 1; |
| 242 | } |
| 243 | int minCharPos = msd - negative - wholeLen; |
| 244 | // Position of leftmost significant digit relative to dec. point. |
| 245 | // Usually negative. |
| 246 | mMaxCharPos = MAX_RIGHT_SCROLL; // How far does it make sense to scroll right? |
| 247 | // If msd is left of decimal point should logically be |
| 248 | // mMinPos = - (int) Math.ceil(getPaint().measureText(truncatedWholePart)), but |
| 249 | // we eventually translate to a character position by dividing by mCharWidth. |
| 250 | // To avoid rounding issues, we use the analogous computation here. |
| 251 | if (minCharPos > -1 && minCharPos < MAX_LEADING_ZEROES + 2) { |
| 252 | // Small number of leading zeroes, avoid scientific notation. |
| 253 | minCharPos = -1; |
| 254 | } |
| 255 | if (leastDigPos < MAX_RIGHT_SCROLL) { |
| 256 | mMaxCharPos = leastDigPos; |
| 257 | if (mMaxCharPos < -1 && mMaxCharPos > -(MAX_TRAILING_ZEROES + 2)) { |
| 258 | mMaxCharPos = -1; |
| 259 | } |
| 260 | // leastDigPos is positive or negative, never 0. |
| 261 | if (mMaxCharPos < -1) { |
| 262 | // Number entirely to left of decimal point. |
| 263 | // We'll need a positive exponent or displayed zeros to display entire number. |
| 264 | mMaxCharPos = Math.min(-1, mMaxCharPos + expLen(-minCharPos - 1)); |
| 265 | if (mMaxCharPos >= -1) { |
| 266 | // Unlikely; huge exponent. |
| 267 | mMaxCharPos = -1; |
| 268 | } else { |
| 269 | adjustedForExp = true; |
| 270 | } |
| 271 | } else if (minCharPos > -1 || mMaxCharPos >= maxChars) { |
| 272 | // Number either entirely to the right of decimal point, or decimal point not |
| 273 | // visible when scrolled to the right. |
| 274 | // We will need an exponent when looking at the rightmost digit. |
| 275 | // Allow additional scrolling to make room. |
| 276 | mMaxCharPos += expLen(-(minCharPos + 1)); |
| 277 | adjustedForExp = true; |
| 278 | // Assumed an exponent for standard scientific notation for now. |
| 279 | // Adjusted below if necessary. |
| 280 | } |
| 281 | mScrollable = (mMaxCharPos - minCharPos + negative >= maxChars); |
| 282 | if (mScrollable) { |
| 283 | if (adjustedForExp) { |
| 284 | // We may need a slightly larger negative exponent while scrolling. |
| 285 | mMaxCharPos += expLen(-leastDigPos) - expLen(-(minCharPos + 1)); |
| 286 | } |
| 287 | } |
| 288 | mMaxPos = Math.min((int) Math.round(mMaxCharPos * charWidth), MAX_RIGHT_SCROLL); |
| 289 | if (!mScrollable) { |
| 290 | // Position the number consistently with our assumptions to make sure it |
| 291 | // actually fits. |
| 292 | mCurrentPos = mMaxPos; |
| 293 | } |
| 294 | } else { |
| 295 | mMaxPos = mMaxCharPos = MAX_RIGHT_SCROLL; |
| 296 | mScrollable = true; |
| 297 | } |
| 298 | } |
| 299 | |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 300 | void displayError(int resourceId) { |
Hans Boehm | 760a9dc | 2015-04-20 10:27:12 -0700 | [diff] [blame] | 301 | mValid = true; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 302 | mScrollable = false; |
| 303 | setText(resourceId); |
| 304 | } |
| 305 | |
Hans Boehm | 013969e | 2015-04-13 20:29:47 -0700 | [diff] [blame] | 306 | private final int MAX_COPY_SIZE = 1000000; |
| 307 | |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 308 | /* |
| 309 | * Return the most significant digit position in the given string or Evaluator.INVALID_MSD. |
| 310 | * Unlike Evaluator.getMsdPos, we treat a final 1 as significant. |
| 311 | */ |
| 312 | public static int getNaiveMsdPos(String s) { |
| 313 | int len = s.length(); |
| 314 | int nonzeroPos = -1; |
| 315 | for (int i = 0; i < len; ++i) { |
| 316 | char c = s.charAt(i); |
| 317 | if (c != '-' && c != '.' && c != '0') { |
| 318 | return i; |
| 319 | } |
| 320 | } |
| 321 | return Evaluator.INVALID_MSD; |
| 322 | } |
| 323 | |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 324 | // Format a result returned by Evaluator.getString() into a single line containing ellipses |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 325 | // (if appropriate) and an exponent (if appropriate). prec is the value that was passed to |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 326 | // getString and thus identifies the significance of the rightmost digit. |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 327 | // A value of 1 means the rightmost digits corresponds to tenths. |
| 328 | // maxDigs is the maximum number of characters in the result. |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 329 | // We set lastDisplayedDigit[0] to the position of the last digit actually appearing in |
| 330 | // the display. |
| 331 | // If forcePrecision is true, we make sure that the last displayed digit corresponds to |
| 332 | // prec, and allow maxDigs to be exceeded in assing the exponent. |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 333 | // We add two distinct kinds of exponents: |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 334 | // 1) If the final result contains the leading digit we use standard scientific notation. |
| 335 | // 2) If not, we add an exponent corresponding to an interpretation of the final result as |
| 336 | // an integer. |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 337 | // We add an ellipsis on the left if the result was truncated. |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 338 | // We add ellipses and exponents in a way that leaves most digits in the position they |
| 339 | // would have been in had we not done so. |
| 340 | // This minimizes jumps as a result of scrolling. Result is NOT internationalized, |
| 341 | // uses "e" for exponent. |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 342 | public String formatResult(String res, int prec, int maxDigs, boolean truncated, |
| 343 | boolean negative, int lastDisplayedDigit[], boolean forcePrecision) { |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 344 | int msd; // Position of most significant digit in res or indication its outside res. |
| 345 | int minusSpace = negative ? 1 : 0; |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 346 | if (truncated) { |
| 347 | res = KeyMaps.ELLIPSIS + res.substring(1, res.length()); |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 348 | msd = -1; |
| 349 | } else { |
| 350 | msd = getNaiveMsdPos(res); // INVALID_MSD is OK and is treated as large. |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 351 | } |
| 352 | int decIndex = res.indexOf('.'); |
| 353 | int resLen = res.length(); |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 354 | lastDisplayedDigit[0] = prec; |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 355 | if ((decIndex == -1 || msd != Evaluator.INVALID_MSD |
| 356 | && msd - decIndex > MAX_LEADING_ZEROES + 1) && prec != -1) { |
| 357 | // No decimal point displayed, and it's not just to the right of the last digit, |
| 358 | // or we should suppress leading zeroes. |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 359 | // Add an exponent to let the user track which digits are currently displayed. |
| 360 | // This is a bit tricky, since the number of displayed digits affects the displayed |
| 361 | // exponent, which can affect the room we have for mantissa digits. We occasionally |
| 362 | // display one digit too few. This is sometimes unavoidable, but we could |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 363 | // avoid it in more cases. |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 364 | int exp = prec > 0 ? -prec : -prec - 1; |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 365 | // Can be used as TYPE (2) EXPONENT. -1 accounts for decimal point. |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 366 | boolean hasPoint = false; |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 367 | if (msd < maxDigs - 1 && msd >= 0 && |
| 368 | resLen - msd + 1 /* dec. pt. */ + minusSpace <= maxDigs + SCI_NOTATION_EXTRA) { |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 369 | // TYPE (1) EXPONENT computation and transformation: |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 370 | // Leading digit is in display window. Use standard calculator scientific notation |
| 371 | // with one digit to the left of the decimal point. Insert decimal point and |
| 372 | // delete leading zeroes. |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 373 | // We try to keep leading digits roughly in position, and never |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 374 | // lengthen the result by more than SCI_NOTATION_EXTRA. |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 375 | String fraction = res.substring(msd + 1, resLen); |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 376 | res = (negative ? "-" : "") + res.substring(msd, msd + 1) + "." + fraction; |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 377 | exp += resLen - msd - 1; |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 378 | // Original exp was correct for decimal point at right of fraction. |
| 379 | // Adjust by length of fraction. |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 380 | resLen = res.length(); |
| 381 | hasPoint = true; |
| 382 | } |
| 383 | if (exp != 0 || truncated) { |
| 384 | // Actually add the exponent of either type: |
| 385 | String expAsString = Integer.toString(exp); |
| 386 | int expDigits = expAsString.length(); |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 387 | if (!forcePrecision) { |
| 388 | int dropDigits = expDigits + 1; |
| 389 | // Drop digits even if there is room. Otherwise the scrolling gets jumpy. |
| 390 | if (dropDigits >= resLen - 1) { |
| 391 | dropDigits = Math.max(resLen - 2, 0); |
| 392 | // Jumpy is better than no mantissa. Probably impossible anyway. |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 393 | } |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 394 | if (!hasPoint) { |
| 395 | // Special handling for TYPE(2) EXPONENT: |
| 396 | exp += dropDigits; |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 397 | expAsString = Integer.toString(exp); |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 398 | // Adjust for digits we are about to drop to drop to make room for exponent. |
| 399 | // This can affect the room we have for the mantissa. We adjust only for |
| 400 | // positive exponents, when it could otherwise result in a truncated |
| 401 | // displayed result. |
| 402 | if (exp > 0 && expAsString.length() > expDigits) { |
| 403 | // ++expDigits; (dead code) |
| 404 | ++dropDigits; |
| 405 | ++exp; |
| 406 | expAsString = Integer.toString(exp); |
| 407 | // This cannot increase the length a second time. |
| 408 | } |
| 409 | if (prec - dropDigits > mLsd) { |
| 410 | // This can happen if e.g. result = 10^40 + 10^10 |
| 411 | // It turns out we would otherwise display ...10e9 because it takes |
| 412 | // the same amount of space as ...1e10 but shows one more digit. |
| 413 | // But we don't want to display a trailing zero, even if it's free. |
| 414 | ++dropDigits; |
| 415 | ++exp; |
| 416 | expAsString = Integer.toString(exp); |
| 417 | } |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 418 | } |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 419 | res = res.substring(0, resLen - dropDigits); |
| 420 | lastDisplayedDigit[0] -= dropDigits; |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 421 | } |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 422 | res = res + "e" + expAsString; |
| 423 | } // else don't add zero exponent |
| 424 | } |
| 425 | return res; |
| 426 | } |
| 427 | |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 428 | /** |
| 429 | * Get formatted, but not internationalized, result from mEvaluator. |
| 430 | * @param pos requested position (1 = tenths) of last included digit. |
| 431 | * @param maxSize Maximum number of characters (more or less) in result. |
| 432 | * @param lastDisplayedPrec Zeroth entry is set to actual position of last included digit, |
| 433 | * after adjusting for exponent, etc. |
| 434 | * @param forcePrecision Ensure that last included digit is at pos, at the expense |
| 435 | * of treating maxSize as a soft limit. |
| 436 | */ |
| 437 | private String getFormattedResult(int pos, int maxSize, int lastDisplayedDigit[], |
| 438 | boolean forcePrecision) { |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 439 | final boolean truncated[] = new boolean[1]; |
| 440 | final boolean negative[] = new boolean[1]; |
| 441 | final int requested_prec[] = {pos}; |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 442 | final String raw_res = mEvaluator.getString(requested_prec, mMaxCharPos, |
| 443 | maxSize, truncated, negative); |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 444 | return formatResult(raw_res, requested_prec[0], maxSize, truncated[0], negative[0], |
| 445 | lastDisplayedDigit, forcePrecision); |
Hans Boehm | 08e8f32 | 2015-04-21 13:18:38 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 448 | // Return entire result (within reason) up to current displayed precision. |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 449 | public String getFullText() { |
Hans Boehm | 760a9dc | 2015-04-20 10:27:12 -0700 | [diff] [blame] | 450 | if (!mValid) return ""; |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 451 | if (!mScrollable) return getText().toString(); |
Hans Boehm | 013969e | 2015-04-13 20:29:47 -0700 | [diff] [blame] | 452 | int currentCharPos = getCurrentCharPos(); |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 453 | int unused[] = new int[1]; |
| 454 | return KeyMaps.translateResult(getFormattedResult(mLastDisplayedDigit, MAX_COPY_SIZE, |
| 455 | unused, true)); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 456 | } |
| 457 | |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 458 | public boolean fullTextIsExact() { |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 459 | return !mScrollable |
| 460 | || mMaxCharPos == getCurrentCharPos() && mMaxCharPos != MAX_RIGHT_SCROLL; |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 463 | /** |
| 464 | * Return the maximum number of characters that will fit in the result display. |
| 465 | * May be called asynchronously from non-UI thread. |
| 466 | */ |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 467 | int getMaxChars() { |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 468 | int result; |
| 469 | synchronized(mWidthLock) { |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 470 | result = (int) Math.floor(mWidthConstraint / mCharWidth); |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 471 | // We can apparently finish evaluating before onMeasure in CalculatorText has been |
| 472 | // called, in which case we get 0 or -1 as the width constraint. |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 473 | } |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 474 | if (result <= 0) { |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 475 | // Return something conservatively big, to force sufficient evaluation. |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 476 | return MAX_WIDTH; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 477 | } else { |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 478 | // Always allow for the ellipsis character which already accounted for in the width |
| 479 | // constraint. |
| 480 | return result + 1; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 484 | /** |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 485 | * @return {@code true} if the currently displayed result is scrollable |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 486 | */ |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 487 | public boolean isScrollable() { |
| 488 | return mScrollable; |
Hans Boehm | 61568a1 | 2015-05-18 18:25:41 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Hans Boehm | 013969e | 2015-04-13 20:29:47 -0700 | [diff] [blame] | 491 | int getCurrentCharPos() { |
| 492 | synchronized(mWidthLock) { |
Hans Boehm | a0e45f3 | 2015-05-30 13:20:35 -0700 | [diff] [blame] | 493 | return (int) Math.round(mCurrentPos / mCharWidth); |
Hans Boehm | 013969e | 2015-04-13 20:29:47 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 497 | void clear() { |
Hans Boehm | 760a9dc | 2015-04-20 10:27:12 -0700 | [diff] [blame] | 498 | mValid = false; |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 499 | mScrollable = false; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 500 | setText(""); |
| 501 | } |
| 502 | |
| 503 | void redisplay() { |
Hans Boehm | 013969e | 2015-04-13 20:29:47 -0700 | [diff] [blame] | 504 | int currentCharPos = getCurrentCharPos(); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 505 | int maxChars = getMaxChars(); |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 506 | int lastDisplayedDigit[] = new int[1]; |
| 507 | String result = getFormattedResult(currentCharPos, maxChars, lastDisplayedDigit, false); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 508 | int epos = result.indexOf('e'); |
Hans Boehm | 013969e | 2015-04-13 20:29:47 -0700 | [diff] [blame] | 509 | result = KeyMaps.translateResult(result); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 510 | if (epos > 0 && result.indexOf('.') == -1) { |
| 511 | // Gray out exponent if used as position indicator |
| 512 | SpannableString formattedResult = new SpannableString(result); |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 513 | formattedResult.setSpan(mExponentColorSpan, epos, result.length(), |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 514 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 515 | setText(formattedResult); |
| 516 | } else { |
| 517 | setText(result); |
| 518 | } |
Hans Boehm | f6dae11 | 2015-06-18 17:57:50 -0700 | [diff] [blame^] | 519 | mLastDisplayedDigit = lastDisplayedDigit[0]; |
Hans Boehm | 760a9dc | 2015-04-20 10:27:12 -0700 | [diff] [blame] | 520 | mValid = true; |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | @Override |
| 524 | public void computeScroll() { |
| 525 | if (!mScrollable) return; |
| 526 | if (mScroller.computeScrollOffset()) { |
| 527 | mCurrentPos = mScroller.getCurrX(); |
| 528 | if (mCurrentPos != mLastPos) { |
| 529 | mLastPos = mCurrentPos; |
| 530 | redisplay(); |
| 531 | } |
| 532 | if (!mScroller.isFinished()) { |
Justin Klaassen | 4459516 | 2015-05-28 17:55:20 -0700 | [diff] [blame] | 533 | postInvalidateOnAnimation(); |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | } |
| 537 | |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 538 | // Copy support: |
| 539 | |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 540 | private ActionMode.Callback mCopyActionModeCallback = new ActionMode.Callback() { |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 541 | @Override |
| 542 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 543 | MenuInflater inflater = mode.getMenuInflater(); |
| 544 | inflater.inflate(R.menu.copy, menu); |
| 545 | return true; |
| 546 | } |
| 547 | |
| 548 | @Override |
| 549 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 550 | return false; // Return false if nothing is done |
| 551 | } |
| 552 | |
| 553 | @Override |
| 554 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 555 | switch (item.getItemId()) { |
| 556 | case R.id.menu_copy: |
| 557 | copyContent(); |
| 558 | mode.finish(); |
| 559 | return true; |
| 560 | default: |
| 561 | return false; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | @Override |
| 566 | public void onDestroyActionMode(ActionMode mode) { |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 567 | mActionMode = null; |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 568 | } |
| 569 | }; |
| 570 | |
Hans Boehm | 1176f23 | 2015-05-11 16:26:03 -0700 | [diff] [blame] | 571 | public boolean stopActionMode() { |
| 572 | if (mActionMode != null) { |
| 573 | mActionMode.finish(); |
| 574 | return true; |
| 575 | } |
| 576 | return false; |
| 577 | } |
| 578 | |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 579 | private void setPrimaryClip(ClipData clip) { |
| 580 | ClipboardManager clipboard = (ClipboardManager) getContext(). |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 581 | getSystemService(Context.CLIPBOARD_SERVICE); |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 582 | clipboard.setPrimaryClip(clip); |
| 583 | } |
| 584 | |
| 585 | private void copyContent() { |
| 586 | final CharSequence text = getFullText(); |
| 587 | ClipboardManager clipboard = |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 588 | (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); |
| 589 | // We include a tag URI, to allow us to recognize our own results and handle them |
| 590 | // specially. |
| 591 | ClipData.Item newItem = new ClipData.Item(text, null, mEvaluator.capture()); |
| 592 | String[] mimeTypes = new String[] {ClipDescription.MIMETYPE_TEXT_PLAIN}; |
| 593 | ClipData cd = new ClipData("calculator result", mimeTypes, newItem); |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 594 | clipboard.setPrimaryClip(cd); |
Hans Boehm | c01cd7f | 2015-05-12 18:32:19 -0700 | [diff] [blame] | 595 | Toast.makeText(getContext(), R.string.text_copied_toast, Toast.LENGTH_SHORT).show(); |
Hans Boehm | 4a6b7cb | 2015-04-03 18:41:52 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Hans Boehm | 8461495 | 2014-11-25 18:46:17 -0800 | [diff] [blame] | 598 | } |