aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java67
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsFragment.java5
-rw-r--r--java/src/com/android/inputmethod/latin/setup/SetupActivity.java11
3 files changed, 73 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
index a6376a54c..88b5032e3 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
@@ -16,9 +16,13 @@
package com.android.inputmethod.dictionarypack;
+import android.app.DownloadManager;
+import android.app.DownloadManager.Query;
import android.content.ContentValues;
import android.content.Context;
+import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
@@ -78,7 +82,8 @@ public class DictionaryDownloadProgressBar extends ProgressBar {
mReporterThread = null;
return;
}
- final UpdaterThread updaterThread = new UpdaterThread(downloadManagerPendingId);
+ final UpdaterThread updaterThread =
+ new UpdaterThread(getContext(), downloadManagerPendingId);
updaterThread.start();
mReporterThread = updaterThread;
} else {
@@ -99,23 +104,75 @@ public class DictionaryDownloadProgressBar extends ProgressBar {
updateReporterThreadRunningStatusAccordingToVisibility();
}
- private static class UpdaterThread extends Thread {
- private final static int REPORT_PERIOD = 1000; // how often to report progress
+ private class UpdaterThread extends Thread {
+ private final static int REPORT_PERIOD = 150; // how often to report progress, in ms
+ final DownloadManager mDownloadManager;
final int mId;
- public UpdaterThread(final int id) {
+ public UpdaterThread(final Context context, final int id) {
super();
+ mDownloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
mId = id;
}
@Override
public void run() {
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;
+ setIndeterminate(true);
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);
}
} catch (InterruptedException e) {
// Do nothing and terminate normally.
}
}
+
+ private class UpdateHelper implements Runnable {
+ private int mProgress;
+ @Override
+ public void run() {
+ setIndeterminate(false);
+ 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);
+ }
+ }
+ }
}
}
diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java
index 830cae9b8..835ef7b46 100644
--- a/java/src/com/android/inputmethod/latin/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java
@@ -420,10 +420,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
// not present or disabled. In this case we need to remove the preference.
getPreferenceScreen().removePreference(userDictionaryPreference);
} else if (localeList.size() <= 1) {
- final Intent intent =
- new Intent(UserDictionaryList.USER_DICTIONARY_SETTINGS_INTENT_ACTION);
- userDictionaryPreference.setTitle(R.string.user_dict_single_settings_title);
- userDictionaryPreference.setIntent(intent);
userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
// If the size of localeList is 0, we don't set the locale parameter in the
// extras. This will be interpreted by the UserDictionarySettings class as
@@ -436,7 +432,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
userDictionaryPreference.getExtras().putString("locale", locale);
}
} else {
- userDictionaryPreference.setTitle(R.string.user_dict_multiple_settings_title);
userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
}
}
diff --git a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
index 651fea6ab..044180bd6 100644
--- a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
+++ b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
@@ -26,6 +26,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.provider.Settings;
+import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -44,6 +45,8 @@ import java.util.ArrayList;
// TODO: Use Fragment to implement welcome screen and setup steps.
public final class SetupActivity extends Activity implements View.OnClickListener {
+ private static final String TAG = SetupActivity.class.getSimpleName();
+
private View mWelcomeScreen;
private View mSetupScreen;
private Uri mWelcomeVideoUri;
@@ -198,6 +201,14 @@ public final class SetupActivity extends Activity implements View.OnClickListene
mWelcomeVideoView.setBackgroundResource(0);
}
});
+ mWelcomeVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
+ @Override
+ public boolean onError(final MediaPlayer mp, final int what, final int extra) {
+ Log.e(TAG, "Playing welcome video causes error: what=" + what + " extra=" + extra);
+ mWelcomeVideoView.setVisibility(View.GONE);
+ return true;
+ }
+ });
mActionStart = findViewById(R.id.setup_start_label);
mActionStart.setOnClickListener(this);