diff --git a/README.md b/README.md index 814582398..ed2194e4d 100644 --- a/README.md +++ b/README.md @@ -45,18 +45,18 @@ Plan / to do: * test whether it works reasonably well in non-latin scripts * ~suggestion fixes, https://github.com/openboard-team/openboard/pull/694, https://github.com/openboard-team/openboard/issues/795, https://github.com/openboard-team/openboard/issues/660~ * ~improve auto-space insertion, https://github.com/openboard-team/openboard/pull/576~ -* emoji prediction/search, either https://github.com/openboard-team/openboard/pull/749 (using emoji dictionaries already possible) +* ~emoji prediction/search, https://github.com/openboard-team/openboard/pull/749 (better use emoji dictionaries, this is more flexible)~ * ~theming, https://github.com/openboard-team/openboard/issues/124~ * ~fix emoji view not themed properly~ * ~fix ABC buttons in emoji and clipboard view have wrong text color~ * fix buttons on long-press action key not themed - * allow adjusting colors without requiring manual reload of keyboard + * allow adjusting colors without requiring manual reload of keyboard * ~delete suggestions, https://github.com/openboard-team/openboard/issues/106~ - * make functionality more discoverable, e.g. add a button to the more suggestions menu + * make functionality more discoverable, e.g. add a button to the _more suggestions_ menu * ~gesture typing, https://github.com/openboard-team/openboard/issues/3~ * ~license issues, require using an external library~ * re-consider preferring lowercase word for typed history in some cases (DictionaryFacilitatorImpl.addWordToUserHistory) -* move _use contacts_ setting from well hidden spell checker settings to _text correction_ settings +* ~move/copy _use contacts_ setting from well hidden spell checker settings to _text correction_ settings~ ----- diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java index ae12c00ec..0efc19624 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/CorrectionSettingsFragment.java @@ -16,6 +16,9 @@ package org.dslul.openboard.inputmethod.latin.settings; +import static org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager.get; + +import android.Manifest; import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -24,8 +27,13 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.preference.Preference; +import android.preference.SwitchPreference; +import android.text.TextUtils; import org.dslul.openboard.inputmethod.latin.R; +import org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager; +import org.dslul.openboard.inputmethod.latin.permissions.PermissionsUtil; +import org.dslul.openboard.inputmethod.latin.spellcheck.AndroidSpellCheckerService; import org.dslul.openboard.inputmethod.latin.userdictionary.UserDictionaryList; import org.dslul.openboard.inputmethod.latin.userdictionary.UserDictionarySettings; @@ -46,11 +54,13 @@ import java.util.TreeSet; * - Next-word suggestions */ public final class CorrectionSettingsFragment extends SubScreenFragment - implements SharedPreferences.OnSharedPreferenceChangeListener { + implements SharedPreferences.OnSharedPreferenceChangeListener, + PermissionsManager.PermissionsResultCallback { private static final boolean DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS = false; private static final boolean USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS = DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS; + private SwitchPreference mLookupContactsPreference; @Override public void onCreate(final Bundle icicle) { @@ -69,19 +79,45 @@ public final class CorrectionSettingsFragment extends SubScreenFragment if (ri == null) { overwriteUserDictionaryPreference(editPersonalDictionary); } + mLookupContactsPreference = (SwitchPreference) findPreference( + AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY); refreshEnabledSettings(); } @Override public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) { + if (TextUtils.equals(key, AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY) + && prefs.getBoolean(key, false) + && !PermissionsUtil.checkAllPermissionsGranted( + getActivity() /* context */, Manifest.permission.READ_CONTACTS) + ) { + get(getActivity() /* context */).requestPermissions(this /* PermissionsResultCallback */, + getActivity() /* activity */, Manifest.permission.READ_CONTACTS); + } refreshEnabledSettings(); } + // contacts and permission stuff from SpellCheckerSettingsFragment + @Override + public void onRequestPermissionsResult(boolean allGranted) { + turnOffLookupContactsIfNoPermission(); + if (allGranted) + mLookupContactsPreference.setChecked(true); + } + + private void turnOffLookupContactsIfNoPermission() { + if (!PermissionsUtil.checkAllPermissionsGranted( + getActivity(), Manifest.permission.READ_CONTACTS)) { + mLookupContactsPreference.setChecked(false); + } + } + private void refreshEnabledSettings() { setPreferenceEnabled(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, Settings.readAutoCorrectEnabled(getSharedPreferences(), getResources())); setPreferenceEnabled(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true)); + turnOffLookupContactsIfNoPermission(); } private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) { diff --git a/app/src/main/res/xml/prefs_screen_correction.xml b/app/src/main/res/xml/prefs_screen_correction.xml index dad968fe0..148a2a3ff 100644 --- a/app/src/main/res/xml/prefs_screen_correction.xml +++ b/app/src/main/res/xml/prefs_screen_correction.xml @@ -82,13 +82,6 @@ android:defaultValue="true" android:persistent="true" /> - - + + + +