Loading java/src/com/android/inputmethod/compat/DownloadManagerCompatUtils.javadeleted 100644 → 0 +0 −38 Original line number Diff line number Diff line /* * Copyright (C) 2013 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.compat; import android.app.DownloadManager; import java.lang.reflect.Method; public final class DownloadManagerCompatUtils { // DownloadManager.Request#setAllowedOverMetered() has been introduced // in API level 16 (Build.VERSION_CODES.JELLY_BEAN). private static final Method METHOD_setAllowedOverMetered = CompatUtils.getMethod( DownloadManager.Request.class, "setAllowedOverMetered", boolean.class); public static DownloadManager.Request setAllowedOverMetered( final DownloadManager.Request request, final boolean allowOverMetered) { return (DownloadManager.Request)CompatUtils.invoke(request, request /* default return value */, METHOD_setAllowedOverMetered, allowOverMetered); } public static final boolean hasSetAllowedOverMetered() { return null != METHOD_setAllowedOverMetered; } } java/src/com/android/inputmethod/dictionarypack/ActionBatch.java +3 −28 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.net.Uri; import android.text.TextUtils; import android.util.Log; import com.android.inputmethod.compat.DownloadManagerCompatUtils; import com.android.inputmethod.latin.BinaryDictionaryFileDumper; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.common.LocaleUtils; Loading Loading @@ -86,7 +85,7 @@ public final class ActionBatch { * Execute this action NOW. * @param context the context to get system services, resources, databases */ public void execute(final Context context); void execute(final Context context); } /** Loading @@ -98,13 +97,10 @@ public final class ActionBatch { private final String mClientId; // The data to download. May not be null. final WordListMetadata mWordList; final boolean mForceStartNow; public StartDownloadAction(final String clientId, final WordListMetadata wordList, final boolean forceStartNow) { public StartDownloadAction(final String clientId, final WordListMetadata wordList) { DebugLogUtils.l("New download action for client ", clientId, " : ", wordList); mClientId = clientId; mWordList = wordList; mForceStartNow = forceStartNow; } @Override Loading Loading @@ -143,28 +139,7 @@ public final class ActionBatch { final Request request = new Request(uri); final Resources res = context.getResources(); if (!mForceStartNow) { if (DownloadManagerCompatUtils.hasSetAllowedOverMetered()) { final boolean allowOverMetered; switch (UpdateHandler.getDownloadOverMeteredSetting(context)) { case UpdateHandler.DOWNLOAD_OVER_METERED_DISALLOWED: // User said no: don't allow. allowOverMetered = false; break; case UpdateHandler.DOWNLOAD_OVER_METERED_ALLOWED: // User said yes: allow. allowOverMetered = true; break; default: // UpdateHandler.DOWNLOAD_OVER_METERED_SETTING_UNKNOWN // Don't know: use the default value from configuration. allowOverMetered = res.getBoolean(R.bool.allow_over_metered); } DownloadManagerCompatUtils.setAllowedOverMetered(request, allowOverMetered); } else { request.setAllowedNetworkTypes(Request.NETWORK_WIFI); } request.setAllowedOverRoaming(res.getBoolean(R.bool.allow_over_roaming)); } // if mForceStartNow, then allow all network types and roaming, which is the default. request.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE); request.setTitle(mWordList.mDescription); request.setNotificationVisibility( res.getBoolean(R.bool.display_notification_for_auto_update) Loading java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java +0 −12 Original line number Diff line number Diff line Loading @@ -22,8 +22,6 @@ import android.content.SharedPreferences; public final class CommonPreferences { private static final String COMMON_PREFERENCES_NAME = "LatinImeDictPrefs"; public static final String PREF_FORCE_DOWNLOAD_DICT = "pref_key_force_download_dict"; public static SharedPreferences getCommonPreferences(final Context context) { return context.getSharedPreferences(COMMON_PREFERENCES_NAME, 0); } Loading @@ -39,14 +37,4 @@ public final class CommonPreferences { editor.putBoolean(id, false); editor.apply(); } public static boolean isForceDownloadDict(Context context) { return getCommonPreferences(context).getBoolean(PREF_FORCE_DOWNLOAD_DICT, false); } public static void setForceDownloadDict(Context context, boolean forceDownload) { SharedPreferences.Editor editor = getCommonPreferences(context).edit(); editor.putBoolean(PREF_FORCE_DOWNLOAD_DICT, forceDownload); editor.apply(); } } java/src/com/android/inputmethod/dictionarypack/DictionaryService.java +7 −12 Original line number Diff line number Diff line Loading @@ -192,27 +192,22 @@ public final class DictionaryService extends Service { } static void dispatchBroadcast(final Context context, final Intent intent) { if (DATE_CHANGED_INTENT_ACTION.equals(intent.getAction())) { // Do not force download dictionaries on date change updates. CommonPreferences.setForceDownloadDict(context, false); final String action = intent.getAction(); if (DATE_CHANGED_INTENT_ACTION.equals(action)) { // This happens when the date of the device changes. This normally happens // at midnight local time, but it may happen if the user changes the date // by hand or something similar happens. checkTimeAndMaybeSetupUpdateAlarm(context); } else if (DictionaryPackConstants.UPDATE_NOW_INTENT_ACTION.equals(intent.getAction())) { } else if (DictionaryPackConstants.UPDATE_NOW_INTENT_ACTION.equals(action)) { // Intent to trigger an update now. UpdateHandler.tryUpdate(context, CommonPreferences.isForceDownloadDict(context)); } else if (DictionaryPackConstants.INIT_AND_UPDATE_NOW_INTENT_ACTION.equals( intent.getAction())) { // Enable force download of dictionaries irrespective of wifi or metered connection. CommonPreferences.setForceDownloadDict(context, true); UpdateHandler.tryUpdate(context); } else if (DictionaryPackConstants.INIT_AND_UPDATE_NOW_INTENT_ACTION.equals(action)) { // Initialize the client Db. final String mClientId = context.getString(R.string.dictionary_pack_client_id); BinaryDictionaryFileDumper.initializeClientRecordHelper(context, mClientId); // Updates the metadata and the download the dictionaries. UpdateHandler.tryUpdate(context, true); UpdateHandler.tryUpdate(context); } else { UpdateHandler.downloadFinished(context, intent); } Loading Loading @@ -263,7 +258,7 @@ public final class DictionaryService extends Service { */ public static void updateNowIfNotUpdatedInAVeryLongTime(final Context context) { if (!isLastUpdateAtLeastThisOld(context, VERY_LONG_TIME_MILLIS)) return; UpdateHandler.tryUpdate(context, CommonPreferences.isForceDownloadDict(context)); UpdateHandler.tryUpdate(context); } /** Loading java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -384,7 +384,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment // 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)) { if (!UpdateHandler.tryUpdate(activity)) { stopLoadingAnimation(); } } Loading Loading
java/src/com/android/inputmethod/compat/DownloadManagerCompatUtils.javadeleted 100644 → 0 +0 −38 Original line number Diff line number Diff line /* * Copyright (C) 2013 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.compat; import android.app.DownloadManager; import java.lang.reflect.Method; public final class DownloadManagerCompatUtils { // DownloadManager.Request#setAllowedOverMetered() has been introduced // in API level 16 (Build.VERSION_CODES.JELLY_BEAN). private static final Method METHOD_setAllowedOverMetered = CompatUtils.getMethod( DownloadManager.Request.class, "setAllowedOverMetered", boolean.class); public static DownloadManager.Request setAllowedOverMetered( final DownloadManager.Request request, final boolean allowOverMetered) { return (DownloadManager.Request)CompatUtils.invoke(request, request /* default return value */, METHOD_setAllowedOverMetered, allowOverMetered); } public static final boolean hasSetAllowedOverMetered() { return null != METHOD_setAllowedOverMetered; } }
java/src/com/android/inputmethod/dictionarypack/ActionBatch.java +3 −28 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.net.Uri; import android.text.TextUtils; import android.util.Log; import com.android.inputmethod.compat.DownloadManagerCompatUtils; import com.android.inputmethod.latin.BinaryDictionaryFileDumper; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.common.LocaleUtils; Loading Loading @@ -86,7 +85,7 @@ public final class ActionBatch { * Execute this action NOW. * @param context the context to get system services, resources, databases */ public void execute(final Context context); void execute(final Context context); } /** Loading @@ -98,13 +97,10 @@ public final class ActionBatch { private final String mClientId; // The data to download. May not be null. final WordListMetadata mWordList; final boolean mForceStartNow; public StartDownloadAction(final String clientId, final WordListMetadata wordList, final boolean forceStartNow) { public StartDownloadAction(final String clientId, final WordListMetadata wordList) { DebugLogUtils.l("New download action for client ", clientId, " : ", wordList); mClientId = clientId; mWordList = wordList; mForceStartNow = forceStartNow; } @Override Loading Loading @@ -143,28 +139,7 @@ public final class ActionBatch { final Request request = new Request(uri); final Resources res = context.getResources(); if (!mForceStartNow) { if (DownloadManagerCompatUtils.hasSetAllowedOverMetered()) { final boolean allowOverMetered; switch (UpdateHandler.getDownloadOverMeteredSetting(context)) { case UpdateHandler.DOWNLOAD_OVER_METERED_DISALLOWED: // User said no: don't allow. allowOverMetered = false; break; case UpdateHandler.DOWNLOAD_OVER_METERED_ALLOWED: // User said yes: allow. allowOverMetered = true; break; default: // UpdateHandler.DOWNLOAD_OVER_METERED_SETTING_UNKNOWN // Don't know: use the default value from configuration. allowOverMetered = res.getBoolean(R.bool.allow_over_metered); } DownloadManagerCompatUtils.setAllowedOverMetered(request, allowOverMetered); } else { request.setAllowedNetworkTypes(Request.NETWORK_WIFI); } request.setAllowedOverRoaming(res.getBoolean(R.bool.allow_over_roaming)); } // if mForceStartNow, then allow all network types and roaming, which is the default. request.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE); request.setTitle(mWordList.mDescription); request.setNotificationVisibility( res.getBoolean(R.bool.display_notification_for_auto_update) Loading
java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java +0 −12 Original line number Diff line number Diff line Loading @@ -22,8 +22,6 @@ import android.content.SharedPreferences; public final class CommonPreferences { private static final String COMMON_PREFERENCES_NAME = "LatinImeDictPrefs"; public static final String PREF_FORCE_DOWNLOAD_DICT = "pref_key_force_download_dict"; public static SharedPreferences getCommonPreferences(final Context context) { return context.getSharedPreferences(COMMON_PREFERENCES_NAME, 0); } Loading @@ -39,14 +37,4 @@ public final class CommonPreferences { editor.putBoolean(id, false); editor.apply(); } public static boolean isForceDownloadDict(Context context) { return getCommonPreferences(context).getBoolean(PREF_FORCE_DOWNLOAD_DICT, false); } public static void setForceDownloadDict(Context context, boolean forceDownload) { SharedPreferences.Editor editor = getCommonPreferences(context).edit(); editor.putBoolean(PREF_FORCE_DOWNLOAD_DICT, forceDownload); editor.apply(); } }
java/src/com/android/inputmethod/dictionarypack/DictionaryService.java +7 −12 Original line number Diff line number Diff line Loading @@ -192,27 +192,22 @@ public final class DictionaryService extends Service { } static void dispatchBroadcast(final Context context, final Intent intent) { if (DATE_CHANGED_INTENT_ACTION.equals(intent.getAction())) { // Do not force download dictionaries on date change updates. CommonPreferences.setForceDownloadDict(context, false); final String action = intent.getAction(); if (DATE_CHANGED_INTENT_ACTION.equals(action)) { // This happens when the date of the device changes. This normally happens // at midnight local time, but it may happen if the user changes the date // by hand or something similar happens. checkTimeAndMaybeSetupUpdateAlarm(context); } else if (DictionaryPackConstants.UPDATE_NOW_INTENT_ACTION.equals(intent.getAction())) { } else if (DictionaryPackConstants.UPDATE_NOW_INTENT_ACTION.equals(action)) { // Intent to trigger an update now. UpdateHandler.tryUpdate(context, CommonPreferences.isForceDownloadDict(context)); } else if (DictionaryPackConstants.INIT_AND_UPDATE_NOW_INTENT_ACTION.equals( intent.getAction())) { // Enable force download of dictionaries irrespective of wifi or metered connection. CommonPreferences.setForceDownloadDict(context, true); UpdateHandler.tryUpdate(context); } else if (DictionaryPackConstants.INIT_AND_UPDATE_NOW_INTENT_ACTION.equals(action)) { // Initialize the client Db. final String mClientId = context.getString(R.string.dictionary_pack_client_id); BinaryDictionaryFileDumper.initializeClientRecordHelper(context, mClientId); // Updates the metadata and the download the dictionaries. UpdateHandler.tryUpdate(context, true); UpdateHandler.tryUpdate(context); } else { UpdateHandler.downloadFinished(context, intent); } Loading Loading @@ -263,7 +258,7 @@ public final class DictionaryService extends Service { */ public static void updateNowIfNotUpdatedInAVeryLongTime(final Context context) { if (!isLastUpdateAtLeastThisOld(context, VERY_LONG_TIME_MILLIS)) return; UpdateHandler.tryUpdate(context, CommonPreferences.isForceDownloadDict(context)); UpdateHandler.tryUpdate(context); } /** Loading
java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -384,7 +384,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment // 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)) { if (!UpdateHandler.tryUpdate(activity)) { stopLoadingAnimation(); } } Loading