diff options
Diffstat (limited to '')
10 files changed, 97 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java index 5dab8b9e7..478e132b3 100644 --- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java @@ -307,6 +307,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers @Override public boolean onOptionsItemSelected(MenuItem menuItem) { + if (MenuDoubleTabUtil.shouldIgnoreTap()) { + return false; + } switch (menuItem.getItemId()) { case android.R.id.home: finish(); diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index 42d7ab8da..3c33cc733 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -46,6 +46,7 @@ import de.pixart.messenger.services.XmppConnectionService.OnAccountUpdate; import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.IrregularUnicodeDetector; +import de.pixart.messenger.utils.MenuDoubleTabUtil; import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.utils.TimeframeUtils; import de.pixart.messenger.utils.UIHelper; @@ -60,7 +61,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp private Contact contact; private Conversation mConversation; - + ActivityContactDetailsBinding binding; private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() { @Override @@ -107,9 +108,6 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp } } }; - - ActivityContactDetailsBinding binding; - private Jid accountJid; private Jid contactJid; private boolean showDynamicTags = false; @@ -287,6 +285,9 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp @Override public boolean onOptionsItemSelected(final MenuItem menuItem) { + if (MenuDoubleTabUtil.shouldIgnoreTap()) { + return false; + } final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setNegativeButton(getString(R.string.cancel), null); switch (menuItem.getItemId()) { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index b7c2cf4d8..50fea03f7 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -104,6 +104,7 @@ import de.pixart.messenger.ui.util.SendButtonAction; import de.pixart.messenger.ui.util.SendButtonTool; import de.pixart.messenger.ui.widget.EditMessage; import de.pixart.messenger.utils.FileUtils; +import de.pixart.messenger.utils.MenuDoubleTabUtil; import de.pixart.messenger.utils.MessageUtils; import de.pixart.messenger.utils.NickValidityChecker; import de.pixart.messenger.utils.StylingHelper; @@ -1378,7 +1379,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke @Override public boolean onOptionsItemSelected(final MenuItem item) { - if (conversation == null) { + if (MenuDoubleTabUtil.shouldIgnoreTap()) { + return false; + } else if (conversation == null) { return super.onOptionsItemSelected(item); } switch (item.getItemId()) { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java index cb2bfa807..ce6ef842d 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java @@ -84,6 +84,7 @@ import de.pixart.messenger.ui.interfaces.OnConversationsListItemUpdated; import de.pixart.messenger.ui.util.ActivityResult; import de.pixart.messenger.ui.util.PendingItem; import de.pixart.messenger.utils.ExceptionHelper; +import de.pixart.messenger.utils.MenuDoubleTabUtil; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.chatstate.ChatState; @@ -505,6 +506,9 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio @Override public boolean onOptionsItemSelected(MenuItem item) { + if (MenuDoubleTabUtil.shouldIgnoreTap()) { + return false; + } switch (item.getItemId()) { case android.R.id.home: FragmentManager fm = getFragmentManager(); diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 74e2910c6..45d1c8ff1 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -65,6 +65,7 @@ import de.pixart.messenger.ui.adapter.KnownHostsAdapter; import de.pixart.messenger.ui.adapter.PresenceTemplateAdapter; import de.pixart.messenger.ui.util.PendingItem; import de.pixart.messenger.utils.CryptoHelper; +import de.pixart.messenger.utils.MenuDoubleTabUtil; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xml.Element; @@ -788,6 +789,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat @Override public boolean onOptionsItemSelected(final MenuItem item) { + if (MenuDoubleTabUtil.shouldIgnoreTap()) { + return false; + } switch (item.getItemId()) { case R.id.mgmt_account_reconnect: XmppConnection connection = mAccount.getXmppConnection(); diff --git a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java index a5ca8a7b6..b50c77207 100644 --- a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java @@ -31,6 +31,7 @@ import de.pixart.messenger.entities.Account; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.services.XmppConnectionService.OnAccountUpdate; import de.pixart.messenger.ui.adapter.AccountAdapter; +import de.pixart.messenger.utils.MenuDoubleTabUtil; import de.pixart.messenger.xmpp.XmppConnection; import rocks.xmpp.addr.Jid; @@ -188,6 +189,9 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda @Override public boolean onOptionsItemSelected(MenuItem item) { + if (MenuDoubleTabUtil.shouldIgnoreTap()) { + return false; + } switch (item.getItemId()) { case R.id.action_add_account: startActivity(new Intent(getApplicationContext(), diff --git a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java index 7c9318fa5..f752dee5a 100644 --- a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java @@ -26,6 +26,7 @@ import java.util.Locale; import de.pixart.messenger.R; import de.pixart.messenger.services.EmojiService; +import de.pixart.messenger.utils.MenuDoubleTabUtil; import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; @@ -107,6 +108,9 @@ public class ShowLocationActivity extends XmppActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { + if (MenuDoubleTabUtil.shouldIgnoreTap()) { + return false; + } switch (item.getItemId()) { case android.R.id.home: finish(); diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index 26ae3591e..db32a6763 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -70,6 +70,7 @@ import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate; import de.pixart.messenger.ui.adapter.ListItemAdapter; import de.pixart.messenger.ui.interfaces.OnBackendConnected; import de.pixart.messenger.ui.util.PendingItem; +import de.pixart.messenger.utils.MenuDoubleTabUtil; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.XmppConnection; @@ -538,6 +539,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU @Override public boolean onOptionsItemSelected(MenuItem item) { + if (MenuDoubleTabUtil.shouldIgnoreTap()) { + return false; + } switch (item.getItemId()) { case R.id.action_join_conference: showJoinConferenceDialog(null); diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index 112c01cee..a2e938e8f 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -39,10 +39,12 @@ import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; +import android.support.v7.app.AppCompatDelegate; import android.text.InputType; import android.util.DisplayMetrics; import android.util.Log; import android.util.Pair; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -76,6 +78,7 @@ import de.pixart.messenger.services.XmppConnectionService.XmppConnectionBinder; import de.pixart.messenger.ui.util.PresenceSelector; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.ExceptionHelper; +import de.pixart.messenger.utils.MenuDoubleTabUtil; import de.pixart.messenger.xmpp.OnKeyStatusUpdated; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import rocks.xmpp.addr.Jid; @@ -1022,6 +1025,14 @@ public abstract class XmppActivity extends AppCompatActivity { super.onPause(); } + @Override + public boolean onMenuOpened(int id, Menu menu) { + if (id == AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR && menu != null) { + MenuDoubleTabUtil.recordMenuOpen(); + } + return super.onMenuOpened(id, menu); + } + protected void showQrCode() { showQrCode(getShareableUri()); } diff --git a/src/main/java/de/pixart/messenger/utils/MenuDoubleTabUtil.java b/src/main/java/de/pixart/messenger/utils/MenuDoubleTabUtil.java new file mode 100644 index 000000000..0fdb071b0 --- /dev/null +++ b/src/main/java/de/pixart/messenger/utils/MenuDoubleTabUtil.java @@ -0,0 +1,54 @@ +/* + * 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 de.pixart.messenger.utils; + +import android.os.SystemClock; +import android.util.Log; + +import de.pixart.messenger.Config; + +public class MenuDoubleTabUtil { + + private static final int TIMEOUT = 250; + + private static long lastMenuOpenedTimestamp = 0L; + + public static void recordMenuOpen() { + lastMenuOpenedTimestamp = SystemClock.elapsedRealtime(); + } + + public static boolean shouldIgnoreTap() { + boolean ignoreTab = lastMenuOpenedTimestamp + 250 > SystemClock.elapsedRealtime(); + if (ignoreTab) { + Log.d(Config.LOGTAG, "ignoring tab"); + } + return ignoreTab; + } +}
\ No newline at end of file |