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
01170ffe
Commit
01170ffe
authored
12 years ago
by
Jean Chalard
Browse files
Options
Downloads
Patches
Plain Diff
[PB13] Actually update the progress bar
Bug: 7600384 Change-Id: Iaa8f3a59243a15d2a01aaf6017ed85c52b6482a6
parent
965329c1
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/dictionarypack/DictionaryDownloadProgressBar.java
+60
-5
60 additions, 5 deletions
...tmethod/dictionarypack/DictionaryDownloadProgressBar.java
with
60 additions
and
5 deletions
java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
+
60
−
5
View file @
01170ffe
...
@@ -16,9 +16,13 @@
...
@@ -16,9 +16,13 @@
package
com.android.inputmethod.dictionarypack
;
package
com.android.inputmethod.dictionarypack
;
import
android.app.DownloadManager
;
import
android.app.DownloadManager.Query
;
import
android.content.ContentValues
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.os.Handler
;
import
android.util.AttributeSet
;
import
android.util.AttributeSet
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.View
;
...
@@ -78,7 +82,8 @@ public class DictionaryDownloadProgressBar extends ProgressBar {
...
@@ -78,7 +82,8 @@ public class DictionaryDownloadProgressBar extends ProgressBar {
mReporterThread
=
null
;
mReporterThread
=
null
;
return
;
return
;
}
}
final
UpdaterThread
updaterThread
=
new
UpdaterThread
(
downloadManagerPendingId
);
final
UpdaterThread
updaterThread
=
new
UpdaterThread
(
getContext
(),
downloadManagerPendingId
);
updaterThread
.
start
();
updaterThread
.
start
();
mReporterThread
=
updaterThread
;
mReporterThread
=
updaterThread
;
}
else
{
}
else
{
...
@@ -99,23 +104,73 @@ public class DictionaryDownloadProgressBar extends ProgressBar {
...
@@ -99,23 +104,73 @@ public class DictionaryDownloadProgressBar extends ProgressBar {
updateReporterThreadRunningStatusAccordingToVisibility
();
updateReporterThreadRunningStatusAccordingToVisibility
();
}
}
private
static
class
UpdaterThread
extends
Thread
{
private
class
UpdaterThread
extends
Thread
{
private
final
static
int
REPORT_PERIOD
=
1000
;
// how often to report progress
private
final
static
int
REPORT_PERIOD
=
150
;
// how often to report progress, in ms
final
DownloadManager
mDownloadManager
;
final
int
mId
;
final
int
mId
;
public
UpdaterThread
(
final
int
id
)
{
public
UpdaterThread
(
final
Context
context
,
final
int
id
)
{
super
();
super
();
mDownloadManager
=
(
DownloadManager
)
context
.
getSystemService
(
Context
.
DOWNLOAD_SERVICE
);
mId
=
id
;
mId
=
id
;
}
}
@Override
@Override
public
void
run
()
{
public
void
run
()
{
try
{
try
{
// TODO: implement the actual query and reporting
// It's almost impossible that mDownloadManager is null (it would mean it has been
// disabled between pressing the 'install' button and displaying the progress
// bar), but just in case.
if
(
null
==
mDownloadManager
)
return
;
final
UpdateHelper
updateHelper
=
new
UpdateHelper
();
final
Query
query
=
new
Query
().
setFilterById
(
mId
);
int
lastProgress
=
0
;
while
(!
isInterrupted
())
{
while
(!
isInterrupted
())
{
final
Cursor
cursor
=
mDownloadManager
.
query
(
query
);
if
(
null
==
cursor
)
{
// Can't contact DownloadManager: this should never happen.
return
;
}
try
{
if
(
cursor
.
moveToNext
())
{
final
int
columnBytesDownloadedSoFar
=
cursor
.
getColumnIndex
(
DownloadManager
.
COLUMN_BYTES_DOWNLOADED_SO_FAR
);
final
int
bytesDownloadedSoFar
=
cursor
.
getInt
(
columnBytesDownloadedSoFar
);
updateHelper
.
setProgressFromAnotherThread
(
bytesDownloadedSoFar
);
}
else
{
// Download has finished and DownloadManager has already been asked to
// clean up the db entry.
updateHelper
.
setProgressFromAnotherThread
(
getMax
());
return
;
}
}
finally
{
cursor
.
close
();
}
Thread
.
sleep
(
REPORT_PERIOD
);
Thread
.
sleep
(
REPORT_PERIOD
);
}
}
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
// Do nothing and terminate normally.
// Do nothing and terminate normally.
}
}
}
}
private
class
UpdateHelper
implements
Runnable
{
private
int
mProgress
;
@Override
public
void
run
()
{
setProgress
(
mProgress
);
}
public
void
setProgressFromAnotherThread
(
final
int
progress
)
{
if
(
mProgress
!=
progress
)
{
mProgress
=
progress
;
// For some unknown reason, setProgress just does not work from a separate
// thread, although the code in ProgressBar looks like it should. Thus, we
// resort to a runnable posted to the handler of the view.
final
Handler
handler
=
getHandler
();
// It's possible to come here before this view has been laid out. If so,
// just ignore the call - it will be updated again later.
if
(
null
==
handler
)
return
;
handler
.
post
(
this
);
}
}
}
}
}
}
}
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