From 8b10f96272d0308598591265c28bd20fb2bf7722 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 10 Jan 2018 16:57:54 +0100 Subject: [PATCH] disable copy in password field --- .../ui/ChangePasswordActivity.java | 3 + .../conversations/ui/EditAccountActivity.java | 6 ++ .../ui/widget/DisabledActionModeCallback.java | 56 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 src/main/java/eu/siacs/conversations/ui/widget/DisabledActionModeCallback.java diff --git a/src/main/java/eu/siacs/conversations/ui/ChangePasswordActivity.java b/src/main/java/eu/siacs/conversations/ui/ChangePasswordActivity.java index b51b911c0..3a7db5a2f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ChangePasswordActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ChangePasswordActivity.java @@ -11,6 +11,7 @@ import android.widget.Toast; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.ui.widget.DisabledActionModeCallback; public class ChangePasswordActivity extends XmppActivity implements XmppConnectionService.OnAccountPasswordChanged { @@ -65,7 +66,9 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti this.mChangePasswordButton.setOnClickListener(this.mOnChangePasswordButtonClicked); this.mCurrentPasswordLabel = findViewById(R.id.current_password_label); this.mCurrentPassword = findViewById(R.id.current_password); + this.mCurrentPassword.setCustomSelectionActionModeCallback(new DisabledActionModeCallback()); this.mNewPassword = findViewById(R.id.new_password); + this.mNewPassword.setCustomSelectionActionModeCallback(new DisabledActionModeCallback()); } @Override diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 35feeb7e3..963d221eb 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -55,6 +55,7 @@ import eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; +import eu.siacs.conversations.ui.widget.DisabledActionModeCallback; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.XmppUri; @@ -856,6 +857,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mAccountJid.setEnabled(editable); this.mAccountJid.setFocusable(editable); this.mAccountJid.setFocusableInTouchMode(editable); + if (editable) { + this.mPassword.setCustomSelectionActionModeCallback(null); + } else { + this.mPassword.setCustomSelectionActionModeCallback(new DisabledActionModeCallback()); + } if (!mInitMode) { this.mAvatar.setVisibility(View.VISIBLE); diff --git a/src/main/java/eu/siacs/conversations/ui/widget/DisabledActionModeCallback.java b/src/main/java/eu/siacs/conversations/ui/widget/DisabledActionModeCallback.java new file mode 100644 index 000000000..a3ab4ec63 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/widget/DisabledActionModeCallback.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package eu.siacs.conversations.ui.widget; + +import android.view.ActionMode; +import android.view.Menu; +import android.view.MenuItem; + +public class DisabledActionModeCallback implements ActionMode.Callback { + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + return false; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + + } +}