Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
11eb13e0
Commit
11eb13e0
authored
14 years ago
by
Ken Wakasa
Browse files
Options
Downloads
Patches
Plain Diff
Avoid disk writes on UI thread.
bug: 3207554 Change-Id: I285691f9e94d989823fcb5c21615ca50cecddff6
parent
3b776b78
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/LatinIMEUtil.java
+61
-41
61 additions, 41 deletions
java/src/com/android/inputmethod/latin/LatinIMEUtil.java
with
61 additions
and
41 deletions
java/src/com/android/inputmethod/latin/LatinIMEUtil.java
+
61
−
41
View file @
11eb13e0
...
...
@@ -21,6 +21,9 @@ import android.view.inputmethod.InputMethodManager;
import
android.content.Context
;
import
android.inputmethodservice.InputMethodService
;
import
android.os.AsyncTask
;
import
android.os.Handler
;
import
android.os.HandlerThread
;
import
android.os.Process
;
import
android.text.format.DateUtils
;
import
android.text.format.Time
;
import
android.util.Log
;
...
...
@@ -172,7 +175,7 @@ public class LatinIMEUtil {
}
}
public
String
getLastString
()
{
StringBu
ff
er
sb
=
new
StringBu
ff
er
();
StringBu
ild
er
sb
=
new
StringBu
ild
er
();
for
(
int
i
=
0
;
i
<
mLength
;
++
i
)
{
char
c
=
mCharBuf
[
normalize
(
mEnd
-
1
-
i
)];
if
(!((
LatinIME
)
mContext
).
isWordSeparator
(
c
))
{
...
...
@@ -247,16 +250,22 @@ public class LatinIMEUtil {
private
static
final
String
FILENAME
=
"log.txt"
;
private
static
final
UsabilityStudyLogUtils
sInstance
=
new
UsabilityStudyLogUtils
();
private
final
Handler
mLoggingHandler
;
private
File
mFile
;
private
File
mDirectory
;
private
InputMethodService
mIms
;
private
PrintWriter
mWriter
;
private
Date
mDate
;
private
SimpleDateFormat
mDateFormat
;
private
final
Date
mDate
;
private
final
SimpleDateFormat
mDateFormat
;
private
UsabilityStudyLogUtils
()
{
mDate
=
new
Date
();
mDateFormat
=
new
SimpleDateFormat
(
"dd MMM HH:mm:ss.SSS"
);
HandlerThread
handlerThread
=
new
HandlerThread
(
"UsabilityStudyLogUtils logging task"
,
Process
.
THREAD_PRIORITY_BACKGROUND
);
handlerThread
.
start
();
mLoggingHandler
=
new
Handler
(
handlerThread
.
getLooper
());
}
public
static
UsabilityStudyLogUtils
getInstance
()
{
...
...
@@ -266,7 +275,6 @@ public class LatinIMEUtil {
public
void
init
(
InputMethodService
ims
)
{
mIms
=
ims
;
mDirectory
=
ims
.
getFilesDir
();
createLogFileIfNotExist
();
}
private
void
createLogFileIfNotExist
()
{
...
...
@@ -301,51 +309,63 @@ public class LatinIMEUtil {
LatinImeLogger
.
onPrintAllUsabilityStudtyLogs
();
}
public
void
write
(
String
log
)
{
createLogFileIfNotExist
();
final
long
currentTime
=
System
.
currentTimeMillis
();
mDate
.
setTime
(
currentTime
);
public
void
write
(
final
String
log
)
{
mLoggingHandler
.
post
(
new
Runnable
()
{
public
void
run
()
{
createLogFileIfNotExist
();
final
long
currentTime
=
System
.
currentTimeMillis
();
mDate
.
setTime
(
currentTime
);
final
String
printString
=
String
.
format
(
"%s\t%d\t%s\n"
,
mDateFormat
.
format
(
mDate
),
currentTime
,
log
);
if
(
LatinImeLogger
.
sDBG
)
{
Log
.
d
(
TAG
,
"Write: "
+
log
);
}
mWriter
.
print
(
printString
);
mWriter
.
flush
();
final
String
printString
=
String
.
format
(
"%s\t%d\t%s\n"
,
mDateFormat
.
format
(
mDate
),
currentTime
,
log
);
if
(
LatinImeLogger
.
sDBG
)
{
Log
.
d
(
TAG
,
"Write: "
+
log
);
}
mWriter
.
print
(
printString
);
}
});
}
public
void
printAll
()
{
StringBuffer
sb
=
new
StringBuffer
();
BufferedReader
br
=
getBufferedReader
();
String
line
;
try
{
while
((
line
=
br
.
readLine
())
!=
null
)
{
sb
.
append
(
'\n'
);
sb
.
append
(
line
);
mLoggingHandler
.
post
(
new
Runnable
()
{
public
void
run
()
{
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
(
TAG
,
"Can't read log file."
);
}
finally
{
if
(
LatinImeLogger
.
sDBG
)
{
Log
.
d
(
TAG
,
"output all logs\n"
+
sb
.
toString
());
}
mIms
.
getCurrentInputConnection
().
commitText
(
sb
.
toString
(),
0
);
try
{
br
.
close
();
}
catch
(
IOException
e
)
{
}
}
}
}
catch
(
IOException
e
)
{
Log
.
e
(
TAG
,
"Can't read log file."
);
}
finally
{
if
(
LatinImeLogger
.
sDBG
)
{
Log
.
d
(
TAG
,
"output all logs\n"
+
sb
.
toString
());
}
mIms
.
getCurrentInputConnection
().
commitText
(
sb
.
toString
(),
0
);
try
{
br
.
close
();
}
catch
(
IOException
e
)
{
}
}
});
}
public
void
clearAll
()
{
if
(
mFile
!=
null
&&
mFile
.
exists
())
{
if
(
LatinImeLogger
.
sDBG
)
{
Log
.
d
(
TAG
,
"Delete log file."
);
mLoggingHandler
.
post
(
new
Runnable
()
{
public
void
run
()
{
if
(
mFile
!=
null
&&
mFile
.
exists
())
{
if
(
LatinImeLogger
.
sDBG
)
{
Log
.
d
(
TAG
,
"Delete log file."
);
}
mFile
.
delete
();
mWriter
.
close
();
}
}
mFile
.
delete
();
mWriter
.
close
();
}
});
}
private
BufferedReader
getBufferedReader
()
{
...
...
@@ -365,7 +385,7 @@ public class LatinIMEUtil {
mFile
.
delete
();
}
}
return
new
PrintWriter
(
new
FileOutputStream
(
mFile
));
return
new
PrintWriter
(
new
FileOutputStream
(
mFile
)
,
true
/* autoFlush */
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment