Loading java/src/com/android/inputmethod/dictionarypack/DictionaryService.java +2 −2 Original line number Diff line number Diff line Loading @@ -170,7 +170,7 @@ public final class DictionaryService extends Service { checkTimeAndMaybeSetupUpdateAlarm(context); } else if (DictionaryPackConstants.UPDATE_NOW_INTENT_ACTION.equals(intent.getAction())) { // Intent to trigger an update now. UpdateHandler.update(context, false); UpdateHandler.tryUpdate(context, false); } else { UpdateHandler.downloadFinished(context, intent); } Loading Loading @@ -221,7 +221,7 @@ public final class DictionaryService extends Service { */ public static void updateNowIfNotUpdatedInAVeryLongTime(final Context context) { if (!isLastUpdateAtLeastThisOld(context, VERY_LONG_TIME)) return; UpdateHandler.update(context, false); UpdateHandler.tryUpdate(context, false); } /** Loading java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java +20 −5 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceGroup; import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; import android.view.animation.AnimationUtils; Loading Loading @@ -104,10 +105,17 @@ public final class DictionarySettingsFragment extends PreferenceFragment @Override public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { mUpdateNowMenu = menu.add(Menu.NONE, MENU_UPDATE_NOW, 0, R.string.check_for_updates_now); final String metadataUri = MetadataDbHelper.getMetadataUriAsString(getActivity(), mClientId); // We only add the "Refresh" button if we have a non-empty URL to refresh from. If the // URL is empty, of course we can't refresh so it makes no sense to display this. if (!TextUtils.isEmpty(metadataUri)) { mUpdateNowMenu = menu.add(Menu.NONE, MENU_UPDATE_NOW, 0, R.string.check_for_updates_now); mUpdateNowMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); refreshNetworkState(); } } @Override public void onResume() { Loading Loading @@ -353,7 +361,12 @@ public final class DictionarySettingsFragment extends PreferenceFragment new Thread("updateByHand") { @Override public void run() { UpdateHandler.update(activity, true); // We call tryUpdate(), which returns whether we could successfully start an update. // If we couldn't, we'll never receive the end callback, so we stop the loading // animation and return to the previous screen. if (!UpdateHandler.tryUpdate(activity, true)) { stopLoadingAnimation(); } } }.start(); } Loading @@ -368,7 +381,9 @@ public final class DictionarySettingsFragment extends PreferenceFragment private void startLoadingAnimation() { mLoadingView.setVisibility(View.VISIBLE); getView().setVisibility(View.GONE); mUpdateNowMenu.setTitle(R.string.cancel); // We come here when the menu element is pressed so presumably it can't be null. But // better safe than sorry. if (null != mUpdateNowMenu) mUpdateNowMenu.setTitle(R.string.cancel); } private void stopLoadingAnimation() { Loading java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java +7 −3 Original line number Diff line number Diff line Loading @@ -173,14 +173,15 @@ public final class UpdateHandler { * Download latest metadata from the server through DownloadManager for all known clients * @param context The context for retrieving resources * @param updateNow Whether we should update NOW, or respect bandwidth policies * @return true if an update successfully started, false otherwise. */ public static void update(final Context context, final boolean updateNow) { public static boolean tryUpdate(final Context context, final boolean updateNow) { // TODO: loop through all clients instead of only doing the default one. final TreeSet<String> uris = new TreeSet<String>(); final Cursor cursor = MetadataDbHelper.queryClientIds(context); if (null == cursor) return; if (null == cursor) return false; try { if (!cursor.moveToFirst()) return; if (!cursor.moveToFirst()) return false; do { final String clientId = cursor.getString(0); final String metadataUri = Loading @@ -192,6 +193,7 @@ public final class UpdateHandler { } finally { cursor.close(); } boolean started = false; for (final String metadataUri : uris) { if (!TextUtils.isEmpty(metadataUri)) { // If the metadata URI is empty, that means we should never update it at all. Loading @@ -200,8 +202,10 @@ public final class UpdateHandler { // is a bug and it happens anyway, doing nothing is the right thing to do. // For more information, {@see DictionaryProvider#insert(Uri, ContentValues)}. updateClientsWithMetadataUri(context, updateNow, metadataUri); started = true; } } return started; } /** Loading Loading
java/src/com/android/inputmethod/dictionarypack/DictionaryService.java +2 −2 Original line number Diff line number Diff line Loading @@ -170,7 +170,7 @@ public final class DictionaryService extends Service { checkTimeAndMaybeSetupUpdateAlarm(context); } else if (DictionaryPackConstants.UPDATE_NOW_INTENT_ACTION.equals(intent.getAction())) { // Intent to trigger an update now. UpdateHandler.update(context, false); UpdateHandler.tryUpdate(context, false); } else { UpdateHandler.downloadFinished(context, intent); } Loading Loading @@ -221,7 +221,7 @@ public final class DictionaryService extends Service { */ public static void updateNowIfNotUpdatedInAVeryLongTime(final Context context) { if (!isLastUpdateAtLeastThisOld(context, VERY_LONG_TIME)) return; UpdateHandler.update(context, false); UpdateHandler.tryUpdate(context, false); } /** Loading
java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java +20 −5 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceGroup; import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; import android.view.animation.AnimationUtils; Loading Loading @@ -104,10 +105,17 @@ public final class DictionarySettingsFragment extends PreferenceFragment @Override public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { mUpdateNowMenu = menu.add(Menu.NONE, MENU_UPDATE_NOW, 0, R.string.check_for_updates_now); final String metadataUri = MetadataDbHelper.getMetadataUriAsString(getActivity(), mClientId); // We only add the "Refresh" button if we have a non-empty URL to refresh from. If the // URL is empty, of course we can't refresh so it makes no sense to display this. if (!TextUtils.isEmpty(metadataUri)) { mUpdateNowMenu = menu.add(Menu.NONE, MENU_UPDATE_NOW, 0, R.string.check_for_updates_now); mUpdateNowMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); refreshNetworkState(); } } @Override public void onResume() { Loading Loading @@ -353,7 +361,12 @@ public final class DictionarySettingsFragment extends PreferenceFragment new Thread("updateByHand") { @Override public void run() { UpdateHandler.update(activity, true); // We call tryUpdate(), which returns whether we could successfully start an update. // If we couldn't, we'll never receive the end callback, so we stop the loading // animation and return to the previous screen. if (!UpdateHandler.tryUpdate(activity, true)) { stopLoadingAnimation(); } } }.start(); } Loading @@ -368,7 +381,9 @@ public final class DictionarySettingsFragment extends PreferenceFragment private void startLoadingAnimation() { mLoadingView.setVisibility(View.VISIBLE); getView().setVisibility(View.GONE); mUpdateNowMenu.setTitle(R.string.cancel); // We come here when the menu element is pressed so presumably it can't be null. But // better safe than sorry. if (null != mUpdateNowMenu) mUpdateNowMenu.setTitle(R.string.cancel); } private void stopLoadingAnimation() { Loading
java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java +7 −3 Original line number Diff line number Diff line Loading @@ -173,14 +173,15 @@ public final class UpdateHandler { * Download latest metadata from the server through DownloadManager for all known clients * @param context The context for retrieving resources * @param updateNow Whether we should update NOW, or respect bandwidth policies * @return true if an update successfully started, false otherwise. */ public static void update(final Context context, final boolean updateNow) { public static boolean tryUpdate(final Context context, final boolean updateNow) { // TODO: loop through all clients instead of only doing the default one. final TreeSet<String> uris = new TreeSet<String>(); final Cursor cursor = MetadataDbHelper.queryClientIds(context); if (null == cursor) return; if (null == cursor) return false; try { if (!cursor.moveToFirst()) return; if (!cursor.moveToFirst()) return false; do { final String clientId = cursor.getString(0); final String metadataUri = Loading @@ -192,6 +193,7 @@ public final class UpdateHandler { } finally { cursor.close(); } boolean started = false; for (final String metadataUri : uris) { if (!TextUtils.isEmpty(metadataUri)) { // If the metadata URI is empty, that means we should never update it at all. Loading @@ -200,8 +202,10 @@ public final class UpdateHandler { // is a bug and it happens anyway, doing nothing is the right thing to do. // For more information, {@see DictionaryProvider#insert(Uri, ContentValues)}. updateClientsWithMetadataUri(context, updateNow, metadataUri); started = true; } } return started; } /** Loading