am 72c2feb5: Use TimeUnit instead of DateUtils for readability

* commit '72c2feb57369527b5f0d2b89505f94503978b928':
  Use TimeUnit instead of DateUtils for readability
main
Tadashi G. Takaoka 2013-07-05 02:25:08 -07:00 committed by Android Git Automerger
commit c85efa92bf
7 changed files with 25 additions and 23 deletions

View File

@ -22,7 +22,6 @@ import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.IBinder; import android.os.IBinder;
import android.text.format.DateUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@ -30,6 +29,7 @@ import com.android.inputmethod.latin.R;
import java.util.Locale; import java.util.Locale;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit;
/** /**
* Service that handles background tasks for the dictionary provider. * Service that handles background tasks for the dictionary provider.
@ -77,19 +77,19 @@ public final class DictionaryService extends Service {
* How often, in milliseconds, we want to update the metadata. This is a * How often, in milliseconds, we want to update the metadata. This is a
* floor value; actually, it may happen several hours later, or even more. * floor value; actually, it may happen several hours later, or even more.
*/ */
private static final long UPDATE_FREQUENCY = 4 * DateUtils.DAY_IN_MILLIS; private static final long UPDATE_FREQUENCY = TimeUnit.DAYS.toMillis(4);
/** /**
* We are waked around midnight, local time. We want to wake between midnight and 6 am, * We are waked around midnight, local time. We want to wake between midnight and 6 am,
* roughly. So use a random time between 0 and this delay. * roughly. So use a random time between 0 and this delay.
*/ */
private static final int MAX_ALARM_DELAY = 6 * ((int)AlarmManager.INTERVAL_HOUR); private static final int MAX_ALARM_DELAY = (int)TimeUnit.HOURS.toMillis(6);
/** /**
* How long we consider a "very long time". If no update took place in this time, * How long we consider a "very long time". If no update took place in this time,
* the content provider will trigger an update in the background. * the content provider will trigger an update in the background.
*/ */
private static final long VERY_LONG_TIME = 14 * DateUtils.DAY_IN_MILLIS; private static final long VERY_LONG_TIME = TimeUnit.DAYS.toMillis(14);
/** /**
* The last seen start Id. This must be stored because we must only call stopSelfResult() with * The last seen start Id. This must be stored because we must only call stopSelfResult() with

View File

@ -20,7 +20,6 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.text.format.DateUtils;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.AssetFileAddress; import com.android.inputmethod.latin.AssetFileAddress;
@ -35,6 +34,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit;
/** /**
* This class encapsulates the logic for the Latin-IME side of dictionary information management. * This class encapsulates the logic for the Latin-IME side of dictionary information management.
@ -74,8 +74,8 @@ public class DictionaryInfoUtils {
values.put(LOCALE_COLUMN, mLocale.toString()); values.put(LOCALE_COLUMN, mLocale.toString());
values.put(DESCRIPTION_COLUMN, mDescription); values.put(DESCRIPTION_COLUMN, mDescription);
values.put(LOCAL_FILENAME_COLUMN, mFileAddress.mFilename); values.put(LOCAL_FILENAME_COLUMN, mFileAddress.mFilename);
values.put(DATE_COLUMN, values.put(DATE_COLUMN, TimeUnit.MILLISECONDS.toSeconds(
new File(mFileAddress.mFilename).lastModified() / DateUtils.SECOND_IN_MILLIS); new File(mFileAddress.mFilename).lastModified()));
values.put(FILESIZE_COLUMN, mFileAddress.mLength); values.put(FILESIZE_COLUMN, mFileAddress.mLength);
values.put(VERSION_COLUMN, mVersion); values.put(VERSION_COLUMN, mVersion);
return values; return values;

View File

@ -16,9 +16,10 @@
package com.android.inputmethod.latin.utils; package com.android.inputmethod.latin.utils;
import android.text.format.DateUtils;
import android.util.Log; import android.util.Log;
import java.util.concurrent.TimeUnit;
public final class UserHistoryForgettingCurveUtils { public final class UserHistoryForgettingCurveUtils {
private static final String TAG = UserHistoryForgettingCurveUtils.class.getSimpleName(); private static final String TAG = UserHistoryForgettingCurveUtils.class.getSimpleName();
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
@ -27,8 +28,8 @@ public final class UserHistoryForgettingCurveUtils {
private static final int FC_LEVEL_MAX = 3; private static final int FC_LEVEL_MAX = 3;
/* package */ static final int ELAPSED_TIME_MAX = 15; /* package */ static final int ELAPSED_TIME_MAX = 15;
private static final int ELAPSED_TIME_INTERVAL_HOURS = 6; private static final int ELAPSED_TIME_INTERVAL_HOURS = 6;
private static final long ELAPSED_TIME_INTERVAL_MILLIS = ELAPSED_TIME_INTERVAL_HOURS private static final long ELAPSED_TIME_INTERVAL_MILLIS =
* DateUtils.HOUR_IN_MILLIS; TimeUnit.HOURS.toMillis(ELAPSED_TIME_INTERVAL_HOURS);
private static final int HALF_LIFE_HOURS = 48; private static final int HALF_LIFE_HOURS = 48;
private static final int MAX_PUSH_ELAPSED = (FC_LEVEL_MAX + 1) * (ELAPSED_TIME_MAX + 1); private static final int MAX_PUSH_ELAPSED = (FC_LEVEL_MAX + 1) * (ELAPSED_TIME_MAX + 1);

View File

@ -55,7 +55,7 @@ public class ResearchLog {
private static final String TAG = ResearchLog.class.getSimpleName(); private static final String TAG = ResearchLog.class.getSimpleName();
private static final boolean DEBUG = false private static final boolean DEBUG = false
&& ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS_DEBUG; && ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS_DEBUG;
private static final long FLUSH_DELAY_IN_MS = 1000 * 5; private static final long FLUSH_DELAY_IN_MS = TimeUnit.SECONDS.toMillis(5);
/* package */ final ScheduledExecutorService mExecutor; /* package */ final ScheduledExecutorService mExecutor;
/* package */ final File mFile; /* package */ final File mFile;

View File

@ -37,7 +37,6 @@ import android.os.IBinder;
import android.os.SystemClock; import android.os.SystemClock;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -75,6 +74,7 @@ import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern; import java.util.regex.Pattern;
// TODO: Add a unit test for every "logging" method (i.e. that is called from the IME and calls // TODO: Add a unit test for every "logging" method (i.e. that is called from the IME and calls
@ -137,10 +137,10 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private static final int MAX_INPUTVIEW_LENGTH_TO_CAPTURE = 8192; // must be >=1 private static final int MAX_INPUTVIEW_LENGTH_TO_CAPTURE = 8192; // must be >=1
private static final String PREF_RESEARCH_SAVED_CHANNEL = "pref_research_saved_channel"; private static final String PREF_RESEARCH_SAVED_CHANNEL = "pref_research_saved_channel";
private static final long RESEARCHLOG_CLOSE_TIMEOUT_IN_MS = 5 * 1000; private static final long RESEARCHLOG_CLOSE_TIMEOUT_IN_MS = TimeUnit.SECONDS.toMillis(5);
private static final long RESEARCHLOG_ABORT_TIMEOUT_IN_MS = 5 * 1000; private static final long RESEARCHLOG_ABORT_TIMEOUT_IN_MS = TimeUnit.SECONDS.toMillis(5);
private static final long DURATION_BETWEEN_DIR_CLEANUP_IN_MS = DateUtils.DAY_IN_MILLIS; private static final long DURATION_BETWEEN_DIR_CLEANUP_IN_MS = TimeUnit.DAYS.toMillis(1);
private static final long MAX_LOGFILE_AGE_IN_MS = 4 * DateUtils.DAY_IN_MILLIS; private static final long MAX_LOGFILE_AGE_IN_MS = TimeUnit.DAYS.toMillis(4);
private static final ResearchLogger sInstance = new ResearchLogger(); private static final ResearchLogger sInstance = new ResearchLogger();
private static String sAccountType = null; private static String sAccountType = null;
@ -195,7 +195,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
// not performed on text that the user types into the feedback dialog. // not performed on text that the user types into the feedback dialog.
private boolean mInFeedbackDialog = false; private boolean mInFeedbackDialog = false;
private Handler mUserRecordingTimeoutHandler; private Handler mUserRecordingTimeoutHandler;
private static final long USER_RECORDING_TIMEOUT_MS = 30L * DateUtils.SECOND_IN_MILLIS; private static final long USER_RECORDING_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(30);
// Stores a temporary LogUnit while generating a phantom space. Needed because phantom spaces // Stores a temporary LogUnit while generating a phantom space. Needed because phantom spaces
// are issued out-of-order, immediately before the characters generated by other operations that // are issued out-of-order, immediately before the characters generated by other operations that
@ -542,8 +542,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
toast.show(); toast.show();
boolean isLogDeleted = abort(); boolean isLogDeleted = abort();
final long currentTime = System.currentTimeMillis(); final long currentTime = System.currentTimeMillis();
final long resumeTime = currentTime + 1000 * 60 * final long resumeTime = currentTime
SUSPEND_DURATION_IN_MINUTES; + TimeUnit.MINUTES.toMillis(SUSPEND_DURATION_IN_MINUTES);
suspendLoggingUntil(resumeTime); suspendLoggingUntil(resumeTime);
toast.cancel(); toast.cancel();
Toast.makeText(latinIME, R.string.research_notify_logging_suspended, Toast.makeText(latinIME, R.string.research_notify_logging_suspended,
@ -635,7 +635,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
mMotionEventReader.readMotionEventData(mUserRecordingFile); mMotionEventReader.readMotionEventData(mUserRecordingFile);
mReplayer.replay(replayData, null); mReplayer.replay(replayData, null);
} }
}, 1000); }, TimeUnit.SECONDS.toMillis(1));
} }
if (FEEDBACK_DIALOG_SHOULD_PRESERVE_TEXT_FIELD) { if (FEEDBACK_DIALOG_SHOULD_PRESERVE_TEXT_FIELD) {

View File

@ -21,6 +21,8 @@ import android.util.Log;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
import java.util.concurrent.TimeUnit;
public class Statistics { public class Statistics {
private static final String TAG = Statistics.class.getSimpleName(); private static final String TAG = Statistics.class.getSimpleName();
private static final boolean DEBUG = false private static final boolean DEBUG = false
@ -102,8 +104,8 @@ public class Statistics {
// To account for the interruptions when the user's attention is directed elsewhere, times // To account for the interruptions when the user's attention is directed elsewhere, times
// longer than MIN_TYPING_INTERMISSION are not counted when estimating this statistic. // longer than MIN_TYPING_INTERMISSION are not counted when estimating this statistic.
public static final int MIN_TYPING_INTERMISSION = 2 * 1000; // in milliseconds public static final long MIN_TYPING_INTERMISSION = TimeUnit.SECONDS.toMillis(2);
public static final int MIN_DELETION_INTERMISSION = 10 * 1000; // in milliseconds public static final long MIN_DELETION_INTERMISSION = TimeUnit.SECONDS.toMillis(10);
// The last time that a tap was performed // The last time that a tap was performed
private long mLastTapTime; private long mLastTapTime;

View File

@ -34,7 +34,6 @@ public final class UploaderService extends IntentService {
public static final long RUN_INTERVAL = AlarmManager.INTERVAL_HOUR; public static final long RUN_INTERVAL = AlarmManager.INTERVAL_HOUR;
public static final String EXTRA_UPLOAD_UNCONDITIONALLY = UploaderService.class.getName() public static final String EXTRA_UPLOAD_UNCONDITIONALLY = UploaderService.class.getName()
+ ".extra.UPLOAD_UNCONDITIONALLY"; + ".extra.UPLOAD_UNCONDITIONALLY";
protected static final int TIMEOUT_IN_MS = 1000 * 4;
public UploaderService() { public UploaderService() {
super("Research Uploader Service"); super("Research Uploader Service");