Skip to content

Commit

Permalink
update onClickArcMenu interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dacer committed Nov 20, 2016
1 parent f724ffa commit acdb7d4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ public void onClick(View v) {
}

@Override
public void onClickArcMenu(ArcMenu arcMenu, int viewId) {
Toast.makeText(this, String.format("Click #%s, arcMenu id: %s", viewId, arcMenu.getId()), Toast.LENGTH_SHORT).show();
public void onClickArcMenu(ArcMenu arcMenu, View v, int viewId) {
boolean isInRecyclerView = v.getTag() != null;
if (isInRecyclerView) {
Toast.makeText(this, String.format("Click #%s, arcMenu id: %s, RecyclerView pos: %s",
viewId, arcMenu.getId(), (int)v.getTag()), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, String.format("Click #%s, arcMenu id: %s", viewId, arcMenu.getId()), Toast.LENGTH_SHORT).show();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.mTextView.setText(mDataset[position]);
holder.mTextView.setTag(position);
builder.showOnLongClick(holder.mTextView);
}

Expand Down
12 changes: 6 additions & 6 deletions library/src/main/java/com/hackplan/androidarcmenu/ArcMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class ArcMenu {

public interface OnClickMenuListener {
void onClickArcMenu(ArcMenu arcMenu, int clickedMenuId);
void onClickArcMenu(ArcMenu arcMenu, View v, int clickedMenuId);
}

private Builder builder;
Expand All @@ -32,7 +32,7 @@ public void showOn(View view) {
if (view == null) return;
Rect rect = new Rect();
view.getGlobalVisibleRect(rect);
builder.show(rect.centerX(), rect.centerY());
builder.show(view, rect.centerX(), rect.centerY());
}

public int getId() {
Expand Down Expand Up @@ -112,15 +112,15 @@ public Builder hideOnTouchUp(boolean h) {
return this;
}

private void show(int x, int y) {
arcMenuInterceptLayout.show(arcMenu, x, y,
private void show(View v, int x, int y) {
arcMenuInterceptLayout.show(arcMenu, v, x, y,
btnList, hideOnTouchUp, radius, degree);
}

private View.OnLongClickListener longClickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
show(lastTouchX, lastTouchY);
show(v, lastTouchX, lastTouchY);
return true;
}
};
Expand All @@ -131,7 +131,7 @@ public boolean onLongClick(View v) {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN){
if (onTouchViews.contains(v)) {
show((int) event.getRawX(), (int) event.getRawY());
show(v, (int) event.getRawX(), (int) event.getRawY());
}else {
//Used in onLongClick(View v)
lastTouchX = (int) event.getRawX();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;

import com.hackplan.androidarcmenu.ArcMenu.OnClickMenuListener;
Expand Down Expand Up @@ -35,7 +36,7 @@ private void init() {
childViewParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}

public void show(ArcMenu arcMenu, int x, int y, ArrayList<ArcButton.Builder> btnList,
public void show(ArcMenu arcMenu, View v, int x, int y, ArrayList<ArcButton.Builder> btnList,
boolean hideOnTouchUp, int radius, double degree) {
if (indexOfChild(arcMenuLayout) == -1) {
addView(arcMenuLayout);
Expand All @@ -44,7 +45,7 @@ public void show(ArcMenu arcMenu, int x, int y, ArrayList<ArcButton.Builder> btn
for (ArcButton.Builder builder : btnList) {
arcMenuLayout.addView(builder.getButton(getContext()), childViewParams);
}
arcMenuLayout.show(arcMenu, x, y, hideOnTouchUp, radius, degree);
arcMenuLayout.show(arcMenu, v, x, y, hideOnTouchUp, radius, degree);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ArcMenuLayout extends ViewGroup {
private OnClickMenuListener onClickMenuListener;
private boolean show = false;
private boolean hideOnTouchUp = true;
private View viewForListener;

public ArcMenuLayout(Context context) {
this(context, null);
Expand All @@ -53,12 +54,13 @@ public boolean isShow() {

private ArrayList<PointF> menuPoints = new ArrayList<>();

public void show(ArcMenu arcMenu, int x, int y, boolean hideOnTouchUp,
public void show(ArcMenu arcMenu, View v, int x, int y, boolean hideOnTouchUp,
int radius, double degree) {
if (getChildCount() <= 0) return;
double arcRadians = Math.toRadians(degree);
this.hideOnTouchUp = hideOnTouchUp;
this.arcMenu = arcMenu;
this.viewForListener = v;
show = true;
if (x == mScreenRect.centerX() && y == mScreenRect.centerY()) y += 1;

Expand Down Expand Up @@ -125,7 +127,7 @@ public boolean onTouchEvent(MotionEvent event) {
AnimatorUtils.openMenu(this, lastFocusIndex, animListener);
if (onClickMenuListener != null) {
View clickedView = getChildAt(lastFocusIndex);
onClickMenuListener.onClickArcMenu(arcMenu, (int) clickedView.getTag());
onClickMenuListener.onClickArcMenu(arcMenu, viewForListener, (int) clickedView.getTag());
}
} else if (hideOnTouchUp) {
AnimatorUtils.hideMenu(this, touchPoint);
Expand Down

0 comments on commit acdb7d4

Please sign in to comment.