Skip to content

Update TagFlowLayout.java #55

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

Open
wants to merge 1 commit into
base: master
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
@@ -1,4 +1,4 @@
package com.zhy.view.flowlayout;
package com.koalac.dispatcher.widget;

import android.content.Context;
import android.content.res.TypedArray;
Expand All @@ -11,13 +11,17 @@
import android.view.MotionEvent;
import android.view.View;

import com.koalac.dispatcher.R;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagView;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
* Created by zhy on 15/9/10.
*/



public class TagFlowLayout extends FlowLayout implements TagAdapter.OnDataChangedListener
{
private TagAdapter mTagAdapter;
Expand Down Expand Up @@ -91,6 +95,22 @@ public interface OnTagClickListener

private OnTagClickListener mOnTagClickListener;



public interface OnLongTagClickListener
{
boolean onLongTagClick(View view, int position, FlowLayout parent);
}

private OnLongTagClickListener mOnLongTagClickListener;


public void setOnLongTagClickListener(OnLongTagClickListener onLongTagClickListener) {
mOnLongTagClickListener = onLongTagClickListener;
if (mOnLongTagClickListener != null) setLongClickable(true);

}

public void setOnTagClickListener(OnTagClickListener onTagClickListener)
{
mOnTagClickListener = onTagClickListener;
Expand All @@ -100,13 +120,15 @@ public void setOnTagClickListener(OnTagClickListener onTagClickListener)

public void setAdapter(TagAdapter adapter)
{
//if (mTagAdapter == adapter)
// return;
mTagAdapter = adapter;
mTagAdapter.setOnDataChangedListener(this);
mSelectedView.clear();
changeAdapter();

}

@SuppressWarnings("ResourceType")
private void changeAdapter()
{
removeAllViews();
Expand Down Expand Up @@ -162,7 +184,7 @@ private void changeAdapter()
@Override
public boolean onTouchEvent(MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_UP)
if (event.getAction() == MotionEvent.ACTION_UP||event.getAction() == MotionEvent.ACTION_DOWN)
{
mMotionEvent = MotionEvent.obtain(event);
}
Expand All @@ -172,26 +194,48 @@ public boolean onTouchEvent(MotionEvent event)
@Override
public boolean performClick()
{
if (mMotionEvent == null) return super.performClick();

int x = (int) mMotionEvent.getX();
int y = (int) mMotionEvent.getY();
mMotionEvent = null;
if (mMotionEvent != null&&mMotionEvent.getAction() == MotionEvent.ACTION_UP){
TagView child = getChildByMotionEvent();
int pos = findPosByView(child);
if (child != null)
{
doSelect(child, pos);
if (mOnTagClickListener != null)
{
return mOnTagClickListener.onTagClick(child.getTagView(), pos, this);
}
}
return true;
}
return super.performClick();
}

TagView child = findChild(x, y);
int pos = findPosByView(child);
if (child != null)
{
doSelect(child, pos);
if (mOnTagClickListener != null)
@Override
public boolean performLongClick() {
if (mMotionEvent != null&&mMotionEvent.getAction() == MotionEvent.ACTION_DOWN){
TagView child = getChildByMotionEvent();
int pos = findPosByView(child);
if (child != null)
{
return mOnTagClickListener.onTagClick(child.getTagView(), pos, this);
if (mOnLongTagClickListener != null)
{
return mOnLongTagClickListener.onLongTagClick(child.getTagView(), pos, this);
}
}
return true;
}
return true;
return super.performLongClick();
}


private TagView getChildByMotionEvent() {
int x = (int) mMotionEvent.getX();
int y = (int) mMotionEvent.getY();
mMotionEvent = null;

return findChild(x, y);
}

public void setMaxSelectCount(int count)
{
if (mSelectedView.size() > count)
Expand Down