2010-08-20 05:35:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 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.inputmethod.latin;
|
|
|
|
|
2011-03-29 01:45:49 +00:00
|
|
|
import android.content.Context;
|
2011-12-08 03:43:40 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
2012-03-21 06:33:55 +00:00
|
|
|
import android.content.res.Resources;
|
2010-11-16 06:52:34 +00:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
2011-12-08 03:43:40 +00:00
|
|
|
import android.net.Uri;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.os.AsyncTask;
|
2012-03-21 06:33:55 +00:00
|
|
|
import android.os.Build;
|
2011-12-08 03:43:40 +00:00
|
|
|
import android.os.Environment;
|
2010-11-18 09:37:46 +00:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.HandlerThread;
|
|
|
|
import android.os.Process;
|
2011-08-19 10:48:48 +00:00
|
|
|
import android.text.TextUtils;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.util.Log;
|
2012-01-20 06:47:22 +00:00
|
|
|
|
2012-03-15 05:56:09 +00:00
|
|
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
|
|
|
|
2010-11-16 06:52:34 +00:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
2011-12-08 03:43:40 +00:00
|
|
|
import java.io.FileInputStream;
|
2010-11-16 06:52:34 +00:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.PrintWriter;
|
2011-12-08 03:43:40 +00:00
|
|
|
import java.nio.channels.FileChannel;
|
2010-11-16 06:52:34 +00:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
2012-03-21 06:33:55 +00:00
|
|
|
import java.util.HashMap;
|
2010-11-16 06:52:34 +00:00
|
|
|
|
2010-12-09 12:06:26 +00:00
|
|
|
public class Utils {
|
2011-02-20 13:04:50 +00:00
|
|
|
private Utils() {
|
2012-03-08 08:07:02 +00:00
|
|
|
// This utility class is not publicly instantiable.
|
2011-02-20 13:04:50 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/**
|
|
|
|
* Cancel an {@link AsyncTask}.
|
|
|
|
*
|
|
|
|
* @param mayInterruptIfRunning <tt>true</tt> if the thread executing this
|
|
|
|
* task should be interrupted; otherwise, in-progress tasks are allowed
|
|
|
|
* to complete.
|
|
|
|
*/
|
|
|
|
public static void cancelTask(AsyncTask<?, ?, ?> task, boolean mayInterruptIfRunning) {
|
|
|
|
if (task != null && task.getStatus() != AsyncTask.Status.FINISHED) {
|
|
|
|
task.cancel(mayInterruptIfRunning);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class GCUtils {
|
2011-02-20 03:54:14 +00:00
|
|
|
private static final String GC_TAG = GCUtils.class.getSimpleName();
|
2010-08-20 05:35:02 +00:00
|
|
|
public static final int GC_TRY_COUNT = 2;
|
|
|
|
// GC_TRY_LOOP_MAX is used for the hard limit of GC wait,
|
|
|
|
// GC_TRY_LOOP_MAX should be greater than GC_TRY_COUNT.
|
|
|
|
public static final int GC_TRY_LOOP_MAX = 5;
|
|
|
|
private static final long GC_INTERVAL = DateUtils.SECOND_IN_MILLIS;
|
|
|
|
private static GCUtils sInstance = new GCUtils();
|
|
|
|
private int mGCTryCount = 0;
|
|
|
|
|
|
|
|
public static GCUtils getInstance() {
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reset() {
|
|
|
|
mGCTryCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean tryGCOrWait(String metaData, Throwable t) {
|
|
|
|
if (mGCTryCount == 0) {
|
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
if (++mGCTryCount > GC_TRY_COUNT) {
|
|
|
|
LatinImeLogger.logOnException(metaData, t);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
Thread.sleep(GC_INTERVAL);
|
|
|
|
return true;
|
|
|
|
} catch (InterruptedException e) {
|
2011-02-20 03:54:14 +00:00
|
|
|
Log.e(GC_TAG, "Sleep was interrupted.");
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.logOnException(metaData, t);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-15 04:37:52 +00:00
|
|
|
|
2010-09-24 06:46:06 +00:00
|
|
|
/* package */ static class RingCharBuffer {
|
|
|
|
private static RingCharBuffer sRingCharBuffer = new RingCharBuffer();
|
|
|
|
private static final char PLACEHOLDER_DELIMITER_CHAR = '\uFFFC';
|
|
|
|
private static final int INVALID_COORDINATE = -2;
|
|
|
|
/* package */ static final int BUFSIZE = 20;
|
2010-11-16 06:52:34 +00:00
|
|
|
private InputMethodService mContext;
|
2010-09-24 06:46:06 +00:00
|
|
|
private boolean mEnabled = false;
|
|
|
|
private int mEnd = 0;
|
|
|
|
/* package */ int mLength = 0;
|
|
|
|
private char[] mCharBuf = new char[BUFSIZE];
|
|
|
|
private int[] mXBuf = new int[BUFSIZE];
|
|
|
|
private int[] mYBuf = new int[BUFSIZE];
|
|
|
|
|
|
|
|
private RingCharBuffer() {
|
2010-12-10 06:24:28 +00:00
|
|
|
// Intentional empty constructor for singleton.
|
2010-09-24 06:46:06 +00:00
|
|
|
}
|
|
|
|
public static RingCharBuffer getInstance() {
|
|
|
|
return sRingCharBuffer;
|
|
|
|
}
|
2010-11-16 06:52:34 +00:00
|
|
|
public static RingCharBuffer init(InputMethodService context, boolean enabled,
|
|
|
|
boolean usabilityStudy) {
|
2010-09-24 06:46:06 +00:00
|
|
|
sRingCharBuffer.mContext = context;
|
2010-11-16 06:52:34 +00:00
|
|
|
sRingCharBuffer.mEnabled = enabled || usabilityStudy;
|
|
|
|
UsabilityStudyLogUtils.getInstance().init(context);
|
2010-09-24 06:46:06 +00:00
|
|
|
return sRingCharBuffer;
|
|
|
|
}
|
2011-10-28 04:31:31 +00:00
|
|
|
private static int normalize(int in) {
|
2010-09-24 06:46:06 +00:00
|
|
|
int ret = in % BUFSIZE;
|
|
|
|
return ret < 0 ? ret + BUFSIZE : ret;
|
|
|
|
}
|
2012-02-22 07:17:54 +00:00
|
|
|
// TODO: accept code points
|
2010-09-24 06:46:06 +00:00
|
|
|
public void push(char c, int x, int y) {
|
|
|
|
if (!mEnabled) return;
|
|
|
|
mCharBuf[mEnd] = c;
|
|
|
|
mXBuf[mEnd] = x;
|
|
|
|
mYBuf[mEnd] = y;
|
|
|
|
mEnd = normalize(mEnd + 1);
|
|
|
|
if (mLength < BUFSIZE) {
|
|
|
|
++mLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public char pop() {
|
|
|
|
if (mLength < 1) {
|
|
|
|
return PLACEHOLDER_DELIMITER_CHAR;
|
|
|
|
} else {
|
|
|
|
mEnd = normalize(mEnd - 1);
|
|
|
|
--mLength;
|
|
|
|
return mCharBuf[mEnd];
|
|
|
|
}
|
|
|
|
}
|
2011-04-06 02:14:20 +00:00
|
|
|
public char getBackwardNthChar(int n) {
|
|
|
|
if (mLength <= n || n < 0) {
|
2010-09-24 06:46:06 +00:00
|
|
|
return PLACEHOLDER_DELIMITER_CHAR;
|
|
|
|
} else {
|
2011-04-06 02:14:20 +00:00
|
|
|
return mCharBuf[normalize(mEnd - n - 1)];
|
2010-09-24 06:46:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
public int getPreviousX(char c, int back) {
|
|
|
|
int index = normalize(mEnd - 2 - back);
|
|
|
|
if (mLength <= back
|
|
|
|
|| Character.toLowerCase(c) != Character.toLowerCase(mCharBuf[index])) {
|
|
|
|
return INVALID_COORDINATE;
|
|
|
|
} else {
|
|
|
|
return mXBuf[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public int getPreviousY(char c, int back) {
|
|
|
|
int index = normalize(mEnd - 2 - back);
|
|
|
|
if (mLength <= back
|
|
|
|
|| Character.toLowerCase(c) != Character.toLowerCase(mCharBuf[index])) {
|
|
|
|
return INVALID_COORDINATE;
|
|
|
|
} else {
|
|
|
|
return mYBuf[index];
|
|
|
|
}
|
|
|
|
}
|
2011-04-06 02:14:20 +00:00
|
|
|
public String getLastWord(int ignoreCharCount) {
|
2010-11-18 09:37:46 +00:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2011-04-06 02:14:20 +00:00
|
|
|
int i = ignoreCharCount;
|
|
|
|
for (; i < mLength; ++i) {
|
|
|
|
char c = mCharBuf[normalize(mEnd - 1 - i)];
|
|
|
|
if (!((LatinIME)mContext).isWordSeparator(c)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (; i < mLength; ++i) {
|
2010-09-24 06:46:06 +00:00
|
|
|
char c = mCharBuf[normalize(mEnd - 1 - i)];
|
|
|
|
if (!((LatinIME)mContext).isWordSeparator(c)) {
|
|
|
|
sb.append(c);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb.reverse().toString();
|
|
|
|
}
|
|
|
|
public void reset() {
|
|
|
|
mLength = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-09-28 03:23:26 +00:00
|
|
|
|
2011-02-10 07:28:42 +00:00
|
|
|
// Get the current stack trace
|
|
|
|
public static String getStackTrace() {
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
try {
|
|
|
|
throw new RuntimeException();
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
StackTraceElement[] frames = e.getStackTrace();
|
|
|
|
// Start at 1 because the first frame is here and we don't care about it
|
|
|
|
for (int j = 1; j < frames.length; ++j) sb.append(frames[j].toString() + "\n");
|
|
|
|
}
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
2010-11-16 06:52:34 +00:00
|
|
|
public static class UsabilityStudyLogUtils {
|
2012-03-22 02:13:33 +00:00
|
|
|
// TODO: remove code duplication with ResearchLog class
|
2011-02-20 13:04:50 +00:00
|
|
|
private static final String USABILITY_TAG = UsabilityStudyLogUtils.class.getSimpleName();
|
2010-11-16 06:52:34 +00:00
|
|
|
private static final String FILENAME = "log.txt";
|
|
|
|
private static final UsabilityStudyLogUtils sInstance =
|
|
|
|
new UsabilityStudyLogUtils();
|
2010-11-18 09:37:46 +00:00
|
|
|
private final Handler mLoggingHandler;
|
2010-11-16 06:52:34 +00:00
|
|
|
private File mFile;
|
|
|
|
private File mDirectory;
|
|
|
|
private InputMethodService mIms;
|
|
|
|
private PrintWriter mWriter;
|
2010-11-18 09:37:46 +00:00
|
|
|
private final Date mDate;
|
|
|
|
private final SimpleDateFormat mDateFormat;
|
2010-11-16 06:52:34 +00:00
|
|
|
|
|
|
|
private UsabilityStudyLogUtils() {
|
|
|
|
mDate = new Date();
|
2012-01-30 03:19:50 +00:00
|
|
|
mDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss.SSSZ");
|
2010-11-18 09:37:46 +00:00
|
|
|
|
|
|
|
HandlerThread handlerThread = new HandlerThread("UsabilityStudyLogUtils logging task",
|
|
|
|
Process.THREAD_PRIORITY_BACKGROUND);
|
|
|
|
handlerThread.start();
|
|
|
|
mLoggingHandler = new Handler(handlerThread.getLooper());
|
2010-11-16 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static UsabilityStudyLogUtils getInstance() {
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init(InputMethodService ims) {
|
|
|
|
mIms = ims;
|
|
|
|
mDirectory = ims.getFilesDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createLogFileIfNotExist() {
|
|
|
|
if ((mFile == null || !mFile.exists())
|
|
|
|
&& (mDirectory != null && mDirectory.exists())) {
|
|
|
|
try {
|
|
|
|
mWriter = getPrintWriter(mDirectory, FILENAME, false);
|
|
|
|
} catch (IOException e) {
|
2011-02-20 13:04:50 +00:00
|
|
|
Log.e(USABILITY_TAG, "Can't create log file.");
|
2010-11-16 06:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 02:13:33 +00:00
|
|
|
public static void writeBackSpace(int x, int y) {
|
|
|
|
UsabilityStudyLogUtils.getInstance().write("<backspace>\t" + x + "\t" + y);
|
Add additional structure to output logs to group entries by optional fields.
The new format has time, time as int, and the new logGroup code
(m=motionEvent, k=key, s=statechange, c=correction)
followed by additional text whose format depends on the logGroup code.
The additional text will be cleaned up in later CL's.
20120321-170548.067+0900 1332317148067 m
[Down]143116235,0,691,378,0.40000004,0.435
20120321-170548.133+0900 1332317148133 m
[Up]143116302,0,691,378,0.40000004,0.435
20120321-170548.146+0900 1332317148146 k <enter> 691 378
20120321-170602.485+0900 1332317162485 s
[onStartInputView]com.socialnmobile.dictapps.notepad.color.note,2131624043,147457,1140850694
20120321-170606.508+0900 1332317166508 m
[Down]143134679,0,40,154,0.4666667,0.64
20120321-170606.567+0900 1332317166567 m
[Move]143134723,0,42,154,0.4666667,0.765
20120321-170606.577+0900 1332317166577 m
[Move]143134746,0,44,154,0.4666667,0.775
20120321-170606.652+0900 1332317166652 m
[Up]143134824,0,44,154,0.4666667,0.775
20120321-170606.662+0900 1332317166662 k A 40 154
20120321-170607.200+0900 1332317167200 m
[Down]143135372,0,411,390,0.53333336,0.585
20120321-170607.311+0900 1332317167311 m
[Up]143135483,0,411,390,0.53333336,0.585
20120321-170607.313+0900 1332317167313 c [----]A
Bug: 6188932
Change-Id: I8694eb9016d8cf0389ef582f6c7d2820aa4d2c92
2012-03-21 08:10:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 02:13:33 +00:00
|
|
|
public void writeChar(char c, int x, int y) {
|
|
|
|
String inputChar = String.valueOf(c);
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
inputChar = "<enter>";
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
inputChar = "<tab>";
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
inputChar = "<space>";
|
|
|
|
break;
|
2012-03-22 02:13:33 +00:00
|
|
|
}
|
2012-03-22 02:13:33 +00:00
|
|
|
UsabilityStudyLogUtils.getInstance().write(inputChar + "\t" + x + "\t" + y);
|
2010-12-28 10:49:43 +00:00
|
|
|
LatinImeLogger.onPrintAllUsabilityStudyLogs();
|
2010-11-16 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 02:13:33 +00:00
|
|
|
public void write(final String log) {
|
2010-11-18 09:37:46 +00:00
|
|
|
mLoggingHandler.post(new Runnable() {
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-11-18 09:37:46 +00:00
|
|
|
public void run() {
|
|
|
|
createLogFileIfNotExist();
|
|
|
|
final long currentTime = System.currentTimeMillis();
|
|
|
|
mDate.setTime(currentTime);
|
2010-11-16 06:52:34 +00:00
|
|
|
|
2012-03-22 02:13:33 +00:00
|
|
|
final String printString = String.format("%s\t%d\t%s\n",
|
|
|
|
mDateFormat.format(mDate), currentTime, log);
|
2010-11-18 09:37:46 +00:00
|
|
|
if (LatinImeLogger.sDBG) {
|
2011-02-20 13:04:50 +00:00
|
|
|
Log.d(USABILITY_TAG, "Write: " + log);
|
2010-11-18 09:37:46 +00:00
|
|
|
}
|
|
|
|
mWriter.print(printString);
|
|
|
|
}
|
|
|
|
});
|
2010-11-16 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 03:43:40 +00:00
|
|
|
private synchronized String getBufferedLogs() {
|
|
|
|
mWriter.flush();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
BufferedReader br = getBufferedReader();
|
|
|
|
String line;
|
|
|
|
try {
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
sb.append('\n');
|
|
|
|
sb.append(line);
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.e(USABILITY_TAG, "Can't read log file.");
|
|
|
|
} finally {
|
|
|
|
if (LatinImeLogger.sDBG) {
|
|
|
|
Log.d(USABILITY_TAG, "Got all buffered logs\n" + sb.toString());
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
br.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
// ignore.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void emailResearcherLogsAll() {
|
2010-11-18 09:37:46 +00:00
|
|
|
mLoggingHandler.post(new Runnable() {
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-11-18 09:37:46 +00:00
|
|
|
public void run() {
|
2011-12-09 15:35:50 +00:00
|
|
|
final Date date = new Date();
|
|
|
|
date.setTime(System.currentTimeMillis());
|
|
|
|
final String currentDateTimeString =
|
|
|
|
new SimpleDateFormat("yyyyMMdd-HHmmssZ").format(date);
|
2011-12-08 03:43:40 +00:00
|
|
|
if (mFile == null) {
|
2011-12-15 10:12:41 +00:00
|
|
|
Log.w(USABILITY_TAG, "No internal log file found.");
|
2011-12-08 03:43:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mIms.checkCallingOrSelfPermission(
|
|
|
|
android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
|
|
!= PackageManager.PERMISSION_GRANTED) {
|
2011-12-15 10:12:41 +00:00
|
|
|
Log.w(USABILITY_TAG, "Doesn't have the permission WRITE_EXTERNAL_STORAGE");
|
2011-12-08 03:43:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-11-18 09:37:46 +00:00
|
|
|
mWriter.flush();
|
2011-12-09 15:35:50 +00:00
|
|
|
final String destPath = Environment.getExternalStorageDirectory()
|
|
|
|
+ "/research-" + currentDateTimeString + ".log";
|
2011-12-08 03:43:40 +00:00
|
|
|
final File destFile = new File(destPath);
|
2010-11-18 09:37:46 +00:00
|
|
|
try {
|
2011-12-08 03:43:40 +00:00
|
|
|
final FileChannel src = (new FileInputStream(mFile)).getChannel();
|
|
|
|
final FileChannel dest = (new FileOutputStream(destFile)).getChannel();
|
|
|
|
src.transferTo(0, src.size(), dest);
|
|
|
|
src.close();
|
|
|
|
dest.close();
|
|
|
|
} catch (FileNotFoundException e1) {
|
2011-12-15 10:12:41 +00:00
|
|
|
Log.w(USABILITY_TAG, e1);
|
2011-12-08 03:43:40 +00:00
|
|
|
return;
|
|
|
|
} catch (IOException e2) {
|
2011-12-15 10:12:41 +00:00
|
|
|
Log.w(USABILITY_TAG, e2);
|
2011-12-08 03:43:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (destFile == null || !destFile.exists()) {
|
2011-12-15 10:12:41 +00:00
|
|
|
Log.w(USABILITY_TAG, "Dest file doesn't exist.");
|
2011-12-08 03:43:40 +00:00
|
|
|
return;
|
2010-11-18 09:37:46 +00:00
|
|
|
}
|
2011-12-08 03:43:40 +00:00
|
|
|
final Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
if (LatinImeLogger.sDBG) {
|
2011-12-15 10:12:41 +00:00
|
|
|
Log.d(USABILITY_TAG, "Destination file URI is " + destFile.toURI());
|
2011-12-08 03:43:40 +00:00
|
|
|
}
|
|
|
|
intent.setType("text/plain");
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + destPath));
|
2011-12-09 15:35:50 +00:00
|
|
|
intent.putExtra(Intent.EXTRA_SUBJECT,
|
|
|
|
"[Research Logs] " + currentDateTimeString);
|
2011-12-08 03:43:40 +00:00
|
|
|
mIms.startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void printAll() {
|
|
|
|
mLoggingHandler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
mIms.getCurrentInputConnection().commitText(getBufferedLogs(), 0);
|
2010-11-16 06:52:34 +00:00
|
|
|
}
|
2010-11-18 09:37:46 +00:00
|
|
|
});
|
2010-11-16 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clearAll() {
|
2010-11-18 09:37:46 +00:00
|
|
|
mLoggingHandler.post(new Runnable() {
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-11-18 09:37:46 +00:00
|
|
|
public void run() {
|
|
|
|
if (mFile != null && mFile.exists()) {
|
|
|
|
if (LatinImeLogger.sDBG) {
|
2011-02-20 13:04:50 +00:00
|
|
|
Log.d(USABILITY_TAG, "Delete log file.");
|
2010-11-18 09:37:46 +00:00
|
|
|
}
|
|
|
|
mFile.delete();
|
|
|
|
mWriter.close();
|
|
|
|
}
|
2010-11-16 06:52:34 +00:00
|
|
|
}
|
2010-11-18 09:37:46 +00:00
|
|
|
});
|
2010-11-16 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private BufferedReader getBufferedReader() {
|
|
|
|
createLogFileIfNotExist();
|
|
|
|
try {
|
|
|
|
return new BufferedReader(new FileReader(mFile));
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private PrintWriter getPrintWriter(
|
|
|
|
File dir, String filename, boolean renew) throws IOException {
|
|
|
|
mFile = new File(dir, filename);
|
|
|
|
if (mFile.exists()) {
|
|
|
|
if (renew) {
|
|
|
|
mFile.delete();
|
|
|
|
}
|
|
|
|
}
|
2010-11-18 09:37:46 +00:00
|
|
|
return new PrintWriter(new FileOutputStream(mFile), true /* autoFlush */);
|
2010-11-16 06:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-20 03:54:14 +00:00
|
|
|
|
2011-03-29 01:45:49 +00:00
|
|
|
public static float getDipScale(Context context) {
|
|
|
|
final float scale = context.getResources().getDisplayMetrics().density;
|
|
|
|
return scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Convert pixel to DIP */
|
|
|
|
public static int dipToPixel(float scale, int dip) {
|
2011-04-26 07:28:56 +00:00
|
|
|
return (int) (dip * scale + 0.5);
|
2011-03-29 01:45:49 +00:00
|
|
|
}
|
2011-04-27 06:43:03 +00:00
|
|
|
|
2011-12-12 07:22:07 +00:00
|
|
|
public static class Stats {
|
|
|
|
public static void onNonSeparator(final char code, final int x,
|
|
|
|
final int y) {
|
|
|
|
RingCharBuffer.getInstance().push(code, x, y);
|
|
|
|
LatinImeLogger.logOnInputChar();
|
|
|
|
}
|
|
|
|
|
2012-02-22 07:17:54 +00:00
|
|
|
public static void onSeparator(final int code, final int x,
|
2011-12-12 07:22:07 +00:00
|
|
|
final int y) {
|
2012-02-22 07:17:54 +00:00
|
|
|
// TODO: accept code points
|
|
|
|
RingCharBuffer.getInstance().push((char)code, x, y);
|
2011-12-12 07:22:07 +00:00
|
|
|
LatinImeLogger.logOnInputSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void onAutoCorrection(final String typedWord, final String correctedWord,
|
|
|
|
final int separatorCode) {
|
|
|
|
if (TextUtils.isEmpty(typedWord)) return;
|
|
|
|
LatinImeLogger.logOnAutoCorrection(typedWord, correctedWord, separatorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void onAutoCorrectionCancellation() {
|
|
|
|
LatinImeLogger.logOnAutoCorrectionCancelled();
|
|
|
|
}
|
|
|
|
}
|
2012-03-15 05:56:09 +00:00
|
|
|
|
|
|
|
public static String getDebugInfo(final SuggestedWords suggestions, final int pos) {
|
|
|
|
if (!LatinImeLogger.sDBG) return null;
|
|
|
|
final SuggestedWordInfo wordInfo = suggestions.getInfo(pos);
|
|
|
|
if (wordInfo == null) return null;
|
|
|
|
final String info = wordInfo.getDebugString();
|
|
|
|
if (TextUtils.isEmpty(info)) return null;
|
|
|
|
return info;
|
|
|
|
}
|
2012-03-21 06:33:55 +00:00
|
|
|
|
|
|
|
private static final String HARDWARE_PREFIX = Build.HARDWARE + ",";
|
|
|
|
private static final HashMap<Integer, String> sDeviceOverrideValueMap =
|
|
|
|
new HashMap<Integer, String>();
|
|
|
|
|
|
|
|
public static String getDeviceOverrideValue(Resources res, int overrideResId, String defValue) {
|
|
|
|
final Integer key = overrideResId;
|
|
|
|
if (!sDeviceOverrideValueMap.containsKey(key)) {
|
|
|
|
String overrideValue = defValue;
|
|
|
|
for (final String element : res.getStringArray(overrideResId)) {
|
|
|
|
if (element.startsWith(HARDWARE_PREFIX)) {
|
|
|
|
overrideValue = element.substring(HARDWARE_PREFIX.length());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sDeviceOverrideValueMap.put(key, overrideValue);
|
|
|
|
}
|
|
|
|
return sDeviceOverrideValueMap.get(key);
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|