1 /* 2 * Copyright (C) 2016 The Android Open Source Project 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 19 import android.text.Spannable; 20 import android.text.format.DateUtils; 21 22 public class HistoryItem { 23 24 private long mEvaluatorIndex; 25 /** Date in millis */ 26 private long mTimeInMillis; 27 private Spannable mFormula; 28 29 /** This is true only for the "empty history" view. */ 30 private final boolean mIsEmpty; 31 HistoryItem(long evaluatorIndex, long millis, Spannable formula)32 public HistoryItem(long evaluatorIndex, long millis, Spannable formula) { 33 mEvaluatorIndex = evaluatorIndex; 34 mTimeInMillis = millis; 35 mFormula = formula; 36 mIsEmpty = false; 37 } 38 getEvaluatorIndex()39 public long getEvaluatorIndex() { 40 return mEvaluatorIndex; 41 } 42 HistoryItem()43 public HistoryItem() { 44 mIsEmpty = true; 45 } 46 isEmptyView()47 public boolean isEmptyView() { 48 return mIsEmpty; 49 } 50 51 /** 52 * @return String in format "n days ago" 53 * For n > 7, the date is returned. 54 */ getDateString()55 public CharSequence getDateString() { 56 return DateUtils.getRelativeTimeSpanString(mTimeInMillis, System.currentTimeMillis(), 57 DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); 58 } 59 getTimeInMillis()60 public long getTimeInMillis() { 61 return mTimeInMillis; 62 } 63 getFormula()64 public Spannable getFormula() { 65 return mFormula; 66 } 67 }