diff --git a/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java index 4a2611c76..a4349517e 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java @@ -24,6 +24,7 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.content.Intent; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.security.KeyChain; import android.text.TextUtils; @@ -234,6 +235,10 @@ public class SettingsController extends BaseController { shouldVibrateSwitchPreference.setVisibility(View.GONE); } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + incognitoKeyboardSwitchPreference.setVisibility(View.GONE); + } + if (!TextUtils.isEmpty(getResources().getString(R.string.nc_privacy_url))) { privacyButton.addPreferenceClickListener(view12 -> { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources(). @@ -342,7 +347,9 @@ public class SettingsController extends BaseController { } ((Checkable)screenSecuritySwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsScreenSecured()); - ((Checkable)incognitoKeyboardSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsKeyboardIncognito()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + ((Checkable) incognitoKeyboardSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsKeyboardIncognito()); + } ((Checkable)linkPreviewsSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getAreLinkPreviewsAllowed()); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java index 36a995fa4..a6070b4fb 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java @@ -19,12 +19,17 @@ package com.nextcloud.talk.controllers.base; import android.content.Context; +import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; +import androidx.annotation.RequiresApi; import com.bluelinelabs.conductor.Controller; import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.controllers.AccountVerificationController; @@ -90,6 +95,10 @@ public abstract class BaseController extends ButterKnifeController { @Override protected void onViewBound(@NonNull View view) { super.onViewBound(view); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appPreferences.getIsKeyboardIncognito()) { + disableKeyboardPersonalisedLearning((ViewGroup) view); + } } // Note: This is just a quick demo of how an ActionBar *can* be accessed, not necessarily how it *should* @@ -106,11 +115,12 @@ public abstract class BaseController extends ButterKnifeController { @Override protected void onAttach(@NonNull View view) { + super.onAttach(view); + setTitle(); if (getActionBar() != null) { getActionBar().setDisplayHomeAsUpEnabled(getParentController() != null || getRouter().getBackstackSize() > 1); } - super.onAttach(view); } @Override @@ -141,4 +151,20 @@ public abstract class BaseController extends ButterKnifeController { protected String getTitle() { return null; } + + @RequiresApi(api = Build.VERSION_CODES.O) + private void disableKeyboardPersonalisedLearning(final ViewGroup viewGroup) { + View view; + EditText editText; + + for(int i = 0; i < viewGroup.getChildCount(); i++) { + view = viewGroup.getChildAt(i); + if (view instanceof EditText) { + editText = (EditText) view; + editText.setImeOptions(editText.getImeOptions() | EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING); + } else if (view instanceof ViewGroup) { + disableKeyboardPersonalisedLearning((ViewGroup) view); + } + } + } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java index 81968215e..aabe5812d 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java @@ -223,7 +223,7 @@ public interface AppPreferences { void removeScreenLock(); @KeyByString("incognito_keyboard") - @DefaultValue(R.bool.value_false) + @DefaultValue(R.bool.value_true) boolean getIsKeyboardIncognito(); @KeyByString("incognito_keyboard") diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/MagicUserInputModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/MagicUserInputModule.java index 9c48c9afd..f7c65fa2f 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/MagicUserInputModule.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/MagicUserInputModule.java @@ -22,12 +22,16 @@ package com.nextcloud.talk.utils.preferences; import android.app.Dialog; import android.content.Context; +import android.os.Build; import android.text.InputType; import android.view.LayoutInflater; import android.view.View; +import android.view.inputmethod.EditorInfo; import android.widget.EditText; +import autodagger.AutoInjector; import com.nextcloud.talk.R; +import com.nextcloud.talk.application.NextcloudTalkApplication; import com.yarolegovich.mp.io.StandardUserInputModule; import java.util.ArrayList; @@ -35,16 +39,24 @@ import java.util.List; import androidx.appcompat.app.AlertDialog; +import javax.inject.Inject; + +@AutoInjector(NextcloudTalkApplication.class) public class MagicUserInputModule extends StandardUserInputModule { + @Inject + AppPreferences appPreferences; + private List keysWithIntegerInput = new ArrayList<>(); public MagicUserInputModule(Context context) { super(context); + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); } public MagicUserInputModule(Context context, List keysWithIntegerInput) { super(context); + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); this.keysWithIntegerInput = keysWithIntegerInput; } @@ -55,7 +67,11 @@ public class MagicUserInputModule extends StandardUserInputModule { CharSequence defaultValue, final Listener listener) { final View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittext, null); - final EditText inputField = (EditText) view.findViewById(R.id.mp_text_input); + final EditText inputField = view.findViewById(R.id.mp_text_input); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appPreferences.getIsKeyboardIncognito()) { + inputField.setImeOptions(inputField.getImeOptions() | EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING); + } if (defaultValue != null) { inputField.setText(defaultValue); diff --git a/app/src/main/res/layout/controller_settings.xml b/app/src/main/res/layout/controller_settings.xml index 206c1c149..10631b4dc 100644 --- a/app/src/main/res/layout/controller_settings.xml +++ b/app/src/main/res/layout/controller_settings.xml @@ -162,7 +162,7 @@ android:id="@+id/settings_incognito_keyboard" android:layout_width="match_parent" android:layout_height="wrap_content" - apc:mp_default_value="@bool/value_false" + apc:mp_default_value="@bool/value_true" apc:mp_key="@string/nc_settings_incognito_keyboard_key" apc:mp_summary="@string/nc_settings_incognito_keyboard_desc" apc:mp_title="@string/nc_settings_incognito_keyboard_title" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9b8fe6c22..07d01def4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -96,7 +96,7 @@ Screen security Prevents screenshots in the recents list and inside the app screen_security - Screen security + Incognito keyboard Instructs keyboard to disable personalized learning (without guarantees) incognito_keyboard Show link previews