am 847735fd: Merge "Skeleton code for user dictionary sync"
* commit '847735fdfacfda3fda0e3a1370a35896832cb8bb': Skeleton code for user dictionary syncmain
commit
0856be7993
|
@ -16,9 +16,11 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin.accounts;
|
package com.android.inputmethod.latin.accounts;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for retrieving accounts that may be used for login.
|
* Utility class for retrieving accounts that may be used for login.
|
||||||
|
@ -37,4 +39,9 @@ public class LoginAccountUtils {
|
||||||
public static String[] getAccountsForLogin(final Context context) {
|
public static String[] getAccountsForLogin(final Context context) {
|
||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static Account getCurrentAccount(final Context context) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,4 +42,9 @@ public final class ProductionFlags {
|
||||||
* When {@code false}, account sign-in in keyboard is not yet ready to be enabled.
|
* When {@code false}, account sign-in in keyboard is not yet ready to be enabled.
|
||||||
*/
|
*/
|
||||||
public static final boolean ENABLE_ACCOUNT_SIGN_IN = false;
|
public static final boolean ENABLE_ACCOUNT_SIGN_IN = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When {@code true}, personal dictionary sync feature is ready to be enabled.
|
||||||
|
*/
|
||||||
|
public static final boolean ENABLE_PERSONAL_DICTIONARY_SYNC = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2014 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.latin.sync;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.concurrent.GuardedBy;
|
||||||
|
|
||||||
|
public class BeanstalkManager {
|
||||||
|
private static final Object sLock = new Object();
|
||||||
|
|
||||||
|
@GuardedBy("sLock")
|
||||||
|
private static BeanstalkManager sInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the singleton instance of {@link BeanstalkManager}.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static BeanstalkManager getInstance(Context context) {
|
||||||
|
synchronized(sLock) {
|
||||||
|
if (sInstance == null) {
|
||||||
|
sInstance = new BeanstalkManager(context.getApplicationContext());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BeanstalkManager(final Context context) {
|
||||||
|
// Intentional private constructor for singleton.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCreate() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestSync() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDestroy() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,6 +56,10 @@
|
||||||
<!-- Option for enabling or disabling the split keyboard layout. [CHAR LIMIT=65]-->
|
<!-- Option for enabling or disabling the split keyboard layout. [CHAR LIMIT=65]-->
|
||||||
<string name="enable_split_keyboard">Enable split keyboard</string>
|
<string name="enable_split_keyboard">Enable split keyboard</string>
|
||||||
|
|
||||||
|
<string name="sync_now_title" translatable="false">Sync Now</string>
|
||||||
|
<string name="sync_now_summary" translatable="false">Sync your personal dictionary</string>
|
||||||
|
<string name="sync_now_summary_disabled_signed_out" translatable="false">Select an account to enable sync</string>
|
||||||
|
|
||||||
<!-- Option name for including other IMEs in the language switch list [CHAR LIMIT=30] -->
|
<!-- Option name for including other IMEs in the language switch list [CHAR LIMIT=30] -->
|
||||||
<string name="include_other_imes_in_language_switch_list">Switch to other input methods</string>
|
<string name="include_other_imes_in_language_switch_list">Switch to other input methods</string>
|
||||||
<!-- Option summary for including other IMEs in the language switch list [CHAR LIMIT=65] -->
|
<!-- Option summary for including other IMEs in the language switch list [CHAR LIMIT=65] -->
|
||||||
|
|
|
@ -34,4 +34,9 @@
|
||||||
android:summary="@string/enable_metrics_logging_summary"
|
android:summary="@string/enable_metrics_logging_summary"
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:persistent="true" />
|
android:persistent="true" />
|
||||||
|
|
||||||
|
<!-- This preference (acts like a button) enables the user to initiate an one time sync. -->
|
||||||
|
<Preference android:key="pref_beanstalk"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/sync_now_title" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
|
@ -85,6 +85,7 @@ import com.android.inputmethod.latin.settings.SettingsActivity;
|
||||||
import com.android.inputmethod.latin.settings.SettingsValues;
|
import com.android.inputmethod.latin.settings.SettingsValues;
|
||||||
import com.android.inputmethod.latin.suggestions.SuggestionStripView;
|
import com.android.inputmethod.latin.suggestions.SuggestionStripView;
|
||||||
import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor;
|
import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor;
|
||||||
|
import com.android.inputmethod.latin.sync.BeanstalkManager;
|
||||||
import com.android.inputmethod.latin.touchinputconsumer.GestureConsumer;
|
import com.android.inputmethod.latin.touchinputconsumer.GestureConsumer;
|
||||||
import com.android.inputmethod.latin.utils.ApplicationUtils;
|
import com.android.inputmethod.latin.utils.ApplicationUtils;
|
||||||
import com.android.inputmethod.latin.utils.CapsModeUtils;
|
import com.android.inputmethod.latin.utils.CapsModeUtils;
|
||||||
|
@ -557,6 +558,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
AudioAndHapticFeedbackManager.init(this);
|
AudioAndHapticFeedbackManager.init(this);
|
||||||
AccessibilityUtils.init(this);
|
AccessibilityUtils.init(this);
|
||||||
mStatsUtilsManager.onCreate(this /* context */);
|
mStatsUtilsManager.onCreate(this /* context */);
|
||||||
|
BeanstalkManager.getInstance(this /* context */).onCreate();
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
mHandler.onCreate();
|
mHandler.onCreate();
|
||||||
|
@ -704,6 +706,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
unregisterReceiver(mDictionaryPackInstallReceiver);
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
||||||
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
||||||
mStatsUtilsManager.onDestroy();
|
mStatsUtilsManager.onDestroy();
|
||||||
|
BeanstalkManager.getInstance(this /* context */).onDestroy();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.SubtypeSwitcher;
|
import com.android.inputmethod.latin.SubtypeSwitcher;
|
||||||
import com.android.inputmethod.latin.accounts.LoginAccountUtils;
|
import com.android.inputmethod.latin.accounts.LoginAccountUtils;
|
||||||
import com.android.inputmethod.latin.define.ProductionFlags;
|
import com.android.inputmethod.latin.define.ProductionFlags;
|
||||||
|
import com.android.inputmethod.latin.sync.BeanstalkManager;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -42,14 +43,17 @@ import javax.annotation.Nullable;
|
||||||
* <li> Account selection/management for IME
|
* <li> Account selection/management for IME
|
||||||
* <li> TODO: Sync preferences
|
* <li> TODO: Sync preferences
|
||||||
* <li> TODO: Privacy preferences
|
* <li> TODO: Privacy preferences
|
||||||
|
* <li> Sync now
|
||||||
*/
|
*/
|
||||||
public final class AccountsSettingsFragment extends SubScreenFragment {
|
public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
static final String PREF_ACCCOUNT_SWITCHER = "account_switcher";
|
static final String PREF_ACCCOUNT_SWITCHER = "account_switcher";
|
||||||
|
static final String PREF_SYNC_NOW = "pref_beanstalk";
|
||||||
|
|
||||||
private final DialogInterface.OnClickListener mAccountSelectedListener =
|
private final DialogInterface.OnClickListener mAccountSelectedListener =
|
||||||
new AccountSelectedListener();
|
new AccountSelectedListener();
|
||||||
private final DialogInterface.OnClickListener mAccountSignedOutListener =
|
private final DialogInterface.OnClickListener mAccountSignedOutListener =
|
||||||
new AccountSignedOutListener();
|
new AccountSignedOutListener();
|
||||||
|
private final Preference.OnPreferenceClickListener mSyncNowListener = new SyncNowListener();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle icicle) {
|
public void onCreate(final Bundle icicle) {
|
||||||
|
@ -75,21 +79,39 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
} else {
|
} else {
|
||||||
removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
|
removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
|
||||||
|
removePreference(PREF_SYNC_NOW);
|
||||||
|
} else {
|
||||||
|
final Preference syncNowPreference = findPreference(PREF_SYNC_NOW);
|
||||||
|
if (syncNowPreference != null) {
|
||||||
|
syncNowPreference.setOnPreferenceClickListener(mSyncNowListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
refreshAccountSelection();
|
refreshUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
|
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
|
||||||
// TODO: Look at the preference that changed before refreshing the view.
|
// TODO: Look at the preference that changed before refreshing the view.
|
||||||
|
refreshUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshUi() {
|
||||||
refreshAccountSelection();
|
refreshAccountSelection();
|
||||||
|
refreshSyncNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshAccountSelection() {
|
private void refreshAccountSelection() {
|
||||||
|
if (!ProductionFlags.ENABLE_ACCOUNT_SIGN_IN) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final String currentAccount = getCurrentlySelectedAccount();
|
final String currentAccount = getCurrentlySelectedAccount();
|
||||||
final Preference accountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
|
final Preference accountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
|
||||||
if (currentAccount == null) {
|
if (currentAccount == null) {
|
||||||
|
@ -119,6 +141,29 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
// depend on an account.
|
// depend on an account.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refreshes the "Sync Now" feature
|
||||||
|
*/
|
||||||
|
private void refreshSyncNow() {
|
||||||
|
if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Preference syncNowPreference = findPreference(PREF_SYNC_NOW);
|
||||||
|
if (syncNowPreference == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String currentAccount = getCurrentlySelectedAccount();
|
||||||
|
if (currentAccount == null) {
|
||||||
|
syncNowPreference.setEnabled(false);
|
||||||
|
syncNowPreference.setSummary(R.string.sync_now_summary);
|
||||||
|
} else {
|
||||||
|
syncNowPreference.setEnabled(true);
|
||||||
|
syncNowPreference.setSummary(R.string.sync_now_summary_disabled_signed_out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String getCurrentlySelectedAccount() {
|
private String getCurrentlySelectedAccount() {
|
||||||
return getSharedPreferences().getString(Settings.PREF_ACCOUNT_NAME, null);
|
return getSharedPreferences().getString(Settings.PREF_ACCOUNT_NAME, null);
|
||||||
|
@ -190,4 +235,15 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener that initates the process of sync in the background.
|
||||||
|
*/
|
||||||
|
class SyncNowListener implements Preference.OnPreferenceClickListener {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(final Preference preference) {
|
||||||
|
BeanstalkManager.getInstance(getActivity() /* context */).requestSync();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue