Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to choose if the QuickActionView shows when the passed view is clicked instead of long pressed #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
public class QuickActionView {

private boolean mShown = false;
private boolean mDoesShowOnClick = false;
private Context mContext;
private OnActionSelectedListener mOnActionSelectedListener;
private OnDismissListener mOnDismissListener;
Expand Down Expand Up @@ -125,7 +126,23 @@ public QuickActionView register(View view) {
RegisteredListener listener = new RegisteredListener();
mRegisteredListeners.put(view, listener);
view.setOnTouchListener(listener);
view.setOnLongClickListener(listener);
if (mDoesShowOnClick) {
view.setOnClickListener(listener);
} else {
view.setOnLongClickListener(listener);
}
return this;
}


/**
* Set if the QuickActionView appears when the passed view is clicked
*
* @param showsOnclick boolean value, indicates if the QuickActionView shows on click instead of long pressed
* @return the QuickActionView
*/
public QuickActionView setDoesShowOnClick(boolean showsOnclick) {
this.mDoesShowOnClick = showsOnclick;
return this;
}

Expand Down Expand Up @@ -950,11 +967,16 @@ private float distance(PointF point, float x, float y) {
/**
* A class to combine a long click listener and a touch listener, to register views with
*/
private class RegisteredListener implements View.OnLongClickListener, View.OnTouchListener {
private class RegisteredListener implements View.OnClickListener, View.OnLongClickListener, View.OnTouchListener {

private float mTouchX;
private float mTouchY;

@Override
public void onClick(View v) {
show(v, new Point((int) mTouchX, (int) mTouchY));
}

@Override
public boolean onLongClick(View v) {
show(v, new Point((int) mTouchX, (int) mTouchY));
Expand Down