-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Right-Click Support for Long Click Listeners
-Added right-click support for all existing long click listeners. -Created an OnContextAndLongClickListener interface to handle both context click and long click events consistently. -This interface includes an onAction method to define the common action (context and long click). -The interface ensures that both listeners are set without duplicating code. -Applied the OnContextAndLongClickListener interface to handle right-click and long-click events uniformly.
- Loading branch information
1 parent
5d39605
commit 7553bb8
Showing
7 changed files
with
97 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
AnkiDroid/src/main/java/com/ichi2/anki/OnContextAndLongClickListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*************************************************************************************** | ||
* * | ||
* Copyright (c) 2024 Sanjay Sargam <sargamsanjaykumar@gmail.com> * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify it under * | ||
* the terms of the GNU General Public License as published by the Free Software * | ||
* Foundation; either version 3 of the License, or (at your option) any later * | ||
* version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * | ||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License along with * | ||
* this program. If not, see <http://www.gnu.org/licenses/>. * | ||
****************************************************************************************/ | ||
|
||
package com.ichi2.anki | ||
|
||
import android.view.View | ||
import timber.log.Timber | ||
|
||
/** | ||
* A listener that has the same action for both "context click" (i.e., mostly right-click) and "long click" (i.e., holding the finger on the view). | ||
* | ||
* * Note: In some contexts, a long press (long click) is expected to be informational, whereas a right-click (context click) is expected to be functional. | ||
* * Ensure that using the same action for both is appropriate for your use case. | ||
*/ | ||
fun interface OnContextAndLongClickListener : View.OnContextClickListener, View.OnLongClickListener { | ||
fun onAction(v: View): Boolean | ||
override fun onContextClick(v: View): Boolean { | ||
Timber.i("${this.javaClass}: user context clicked") | ||
return onAction(v) | ||
} | ||
override fun onLongClick(v: View): Boolean { | ||
Timber.i("${this.javaClass}: user long clicked") | ||
return onAction(v) | ||
} | ||
|
||
companion object { | ||
/** | ||
* Ensures [this] gets both a long click and a context click listener. | ||
* @see View.setOnLongClickListener | ||
* @see View.setOnContextClickListener | ||
*/ | ||
fun View.setOnContextAndLongClickListener(listener: OnContextAndLongClickListener?) { | ||
setOnLongClickListener(listener) | ||
setOnContextClickListener(listener) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters