Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c77430a

Browse files
committed
fix a little scroll
1 parent 28f58a0 commit c77430a

File tree

6 files changed

+120
-50
lines changed

6 files changed

+120
-50
lines changed

‎Drag-FlowLayout/app/src/main/java/com/heaven7/android/drag/demo/DragFlowLayoutTest.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.os.Bundle;
44
import android.support.annotation.NonNull;
55
import android.support.v7.widget.RecyclerView;
6+
import android.view.MotionEvent;
67
import android.view.View;
78
import android.view.WindowManager;
89
import android.widget.TextView;
@@ -14,7 +15,6 @@
1415
import com.heaven7.android.dragflowlayout.DragFlowLayout;
1516
import com.heaven7.android.dragflowlayout.IDraggable;
1617
import com.heaven7.android.dragflowlayout.IViewObserver;
17-
import com.heaven7.core.util.Logger;
1818

1919
import butterknife.InjectView;
2020
import butterknife.OnClick;
@@ -52,6 +52,12 @@ protected void initView() {
5252
protected void onDeleteSuccess(DragFlowLayout dfl, View child, Object data) {
5353
//删除成功后的处理。
5454
}
55+
56+
@Override
57+
public boolean performClick(DragFlowLayout dragFlowLayout, View child, MotionEvent event, int dragState) {
58+
super.performClick(dragFlowLayout, child, event, dragState);
59+
return true;
60+
}
5561
});
5662
mDragflowLayout.setDragAdapter(new DragAdapter<TestBean>() {
5763
@Override
@@ -81,18 +87,18 @@ public TestBean getData(View itemView) {
8187
mDragflowLayout.setOnDragStateChangeListener(new DragFlowLayout.OnDragStateChangeListener() {
8288
@Override
8389
public void onDragStateChange(DragFlowLayout dfl, int dragState) {
84-
System.out.println("on drag state change : dragState = " + dragState);
90+
// System.out.println("on drag state change : dragState = " + dragState);
8591
}
8692
});
8793
//添加view观察者
8894
mDragflowLayout.addViewObserver(new IViewObserver() {
8995
@Override
9096
public void onAddView(View child, int index) {
91-
Logger.i(TAG, "onAddView", "index = " + index);
97+
// Logger.i(TAG, "onAddView", "index = " + index);
9298
}
9399
@Override
94100
public void onRemoveView(View child, int index) {
95-
Logger.i(TAG, "onRemoveView", "index = " + index);
101+
// Logger.i(TAG, "onRemoveView", "index = " + index);
96102
}
97103
});
98104
}

‎Drag-FlowLayout/build.gradle‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ allprojects {
1919
repositories {
2020
jcenter()
2121
}
22+
23+
//解决生成javadoc失败导致的上传不了bintray, so Disable javadoc check for Bintray upload
24+
tasks.withType(Javadoc) {
25+
// options.addStringOption('Xdoclint:none', '-quiet')
26+
options.addStringOption('X', '-quiet')
27+
options.addStringOption('encoding', 'UTF-8')
28+
}
2229
}
2330

2431
task clean(type: Delete) {

‎Drag-FlowLayout/dragflowlayout/src/main/java/com/heaven7/android/dragflowlayout/ClickToDeleteItemListenerImpl.java‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class ClickToDeleteItemListenerImpl implements DragFlowLayout.OnItemClick
1616

1717
/**
1818
* create ClickToDeleteItemListenerImpl with a delete id.
19+
*
1920
* @param id the view id for delete this item
2021
*/
2122
public ClickToDeleteItemListenerImpl(int id) {
@@ -25,25 +26,27 @@ public ClickToDeleteItemListenerImpl(int id) {
2526
@Override
2627
public boolean performClick(DragFlowLayout dragFlowLayout, View child, MotionEvent event, int dragState) {
2728
//检查是否点击了关闭按钮。点击了就删除
28-
boolean performed = dragState != DragFlowLayout.DRAG_STATE_IDLE && ViewUtils.isViewUnderInScreen(
29-
child.findViewById(mDeleteViewId), (int) event.getRawX(),(int) event.getRawY());
30-
if(performed){
31-
dragFlowLayout.postDelayed(new DeleteRunnable(dragFlowLayout,child), 60);
29+
final View mDeleteView = child.findViewById(mDeleteViewId);
30+
boolean performed = dragState != DragFlowLayout.DRAG_STATE_IDLE && mDeleteView.getVisibility() == View.VISIBLE
31+
&& ViewUtils.isViewUnderInScreen(mDeleteView, (int) event.getRawX(), (int) event.getRawY());
32+
if (performed) {
33+
dragFlowLayout.postDelayed(new DeleteRunnable(dragFlowLayout, child), 60);
3234
}
33-
return performed;
35+
return false;
3436
}
3537

3638
/**
3739
* called when delete success
38-
* @param dfl the DragFlowLayout
40+
*
41+
* @param dfl the DragFlowLayout
3942
* @param child the direct child of DragFlowLayout
40-
* @param data the data from child , from {@link DragAdapter#getData(View)}
43+
* @param data the data from child , from {@link DragAdapter#getData(View)}
4144
*/
42-
protected void onDeleteSuccess(DragFlowLayout dfl, View child, Object data){
45+
protected void onDeleteSuccess(DragFlowLayout dfl, View child, Object data){
4346

4447
}
4548

46-
private class DeleteRunnable implements Runnable{
49+
private class DeleteRunnable implements Runnable{
4750
private final DragFlowLayout mParent;
4851
private final View mChild;
4952

‎Drag-FlowLayout/dragflowlayout/src/main/java/com/heaven7/android/dragflowlayout/DragFlowLayout.java‎

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.annotation.TargetApi;
44
import android.content.Context;
5+
import android.os.Parcel;
56
import android.os.Parcelable;
67
import android.support.annotation.IntDef;
78
import android.support.annotation.NonNull;
@@ -35,13 +36,13 @@ public class DragFlowLayout extends FlowLayout implements IViewManager {
3536

3637
public static final int INVALID_INDXE = -1;
3738
/** the delay of check click event. */
38-
private static final int DELAY_CHECK_CLICK = 130;
39+
private static final int DELAY_CHECK_CLICK = 360;
3940

40-
/** indicate currrent is idle, and can't draggable */
41+
/** indicate current is idle, and can't draggable */
4142
public static final int DRAG_STATE_IDLE = 1;
42-
/** indicate currrent is dragging */
43+
/** indicate current is dragging */
4344
public static final int DRAG_STATE_DRAGGING = 2;
44-
/** indicate currrent is not dragging but can drag */
45+
/** indicate current is not dragging but can drag */
4546
public static final int DRAG_STATE_DRAGGABLE = 3;
4647

4748
@Retention(RetentionPolicy.SOURCE)
@@ -529,7 +530,7 @@ protected void onDetachedFromWindow() {
529530

530531
@Override
531532
protected Parcelable onSaveInstanceState() {
532-
System.err.println("onSaveInstanceState");
533+
System.err.println("onSaveInstanceState");//屏幕旋转也会调用
533534
return super.onSaveInstanceState();
534535
}
535536

@@ -539,6 +540,17 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
539540
return super.onInterceptTouchEvent(ev);
540541
}
541542
sDebugger.i("onInterceptTouchEvent", ev.toString());
543+
switch (ev.getAction()){
544+
case MotionEvent.ACTION_DOWN:
545+
546+
break;
547+
548+
case MotionEvent.ACTION_MOVE:
549+
break;
550+
551+
case MotionEvent.ACTION_UP:
552+
break;
553+
}
542554
return (mIntercepted = mGestureDetector.onTouchEvent(ev));
543555
}*/
544556

@@ -549,9 +561,8 @@ public boolean onTouchEvent(MotionEvent event) {
549561
if(!mDraggable){
550562
return super.onTouchEvent(event);
551563
}
552-
553-
mCancelled = event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP;
554564
final boolean handled = mGestureDetector.onTouchEvent(event);
565+
mCancelled = event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP;
555566
//解决ScrollView嵌套DragFlowLayout时,引起的事件冲突
556567
if(getParent() != null){
557568
getParent().requestDisallowInterceptTouchEvent(mRequestedDisallowIntercept || mDragState != DRAG_STATE_IDLE);
@@ -585,6 +596,40 @@ public void run() {
585596
}
586597
}
587598

599+
protected static class SaveState extends BaseSavedState {
600+
//int mDragState , mDraggable, list data
601+
int mDragState;
602+
boolean mDraggable;
603+
604+
public SaveState(Parcel source) {
605+
super(source);
606+
//TODO
607+
// mNeedIntercept = source.readByte() == 1;
608+
}
609+
610+
public SaveState(Parcelable superState) {
611+
super(superState);
612+
}
613+
614+
@Override
615+
public void writeToParcel(Parcel out, int flags) {
616+
super.writeToParcel(out, flags);
617+
}
618+
619+
public static final Parcelable.Creator<SaveState> CREATOR
620+
= new Parcelable.Creator<SaveState>() {
621+
@Override
622+
public SaveState createFromParcel(Parcel in) {
623+
return new SaveState(in);
624+
}
625+
626+
@Override
627+
public SaveState[] newArray(int size) {
628+
return new SaveState[size];
629+
}
630+
};
631+
}
632+
588633
private static class Item{
589634
int index;
590635
View view;
@@ -704,8 +749,10 @@ public void findDragItem(View touchView) {
704749
}
705750
}
706751
private class GestureListenerImpl extends GestureDetector.SimpleOnGestureListener{
752+
707753
@Override
708754
public boolean onDown(MotionEvent e) {
755+
removeCallbacks(mCheckForDrag);
709756
mTouchChild = findTopChildUnder((int) e.getX(), (int) e.getY());
710757
sDebugger.i("mGestureDetector_onDown","----------------- > after find : mTouchChild = "
711758
+ mTouchChild);
@@ -720,6 +767,7 @@ public boolean onDown(MotionEvent e) {
720767
}
721768
return mTouchChild != null;
722769
}
770+
723771
@Override
724772
public boolean onSingleTapUp(MotionEvent e) {
725773
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);

‎Drag-FlowLayout/dragflowlayout/src/main/java/com/heaven7/android/dragflowlayout/FlowLayout.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class FlowLayout extends ViewGroup {
1919

2020
private static final String TAG = "FlowLayout";
21-
private static final boolean sDebug = true;
21+
private static final boolean sDebug = false;
2222
private int mMaxLine = Integer.MAX_VALUE;
2323
private boolean mHasMoreByMaxLine;
2424

‎Drag-FlowLayout/dragflowlayout/src/main/java/com/heaven7/android/dragflowlayout/FlowLayout2.java‎

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
package com.heaven7.android.dragflowlayout;
22

3-
import android.annotation.TargetApi;
4-
import android.content.Context;
5-
import android.content.res.Configuration;
6-
import android.content.res.TypedArray;
7-
import android.util.AttributeSet;
8-
import android.util.Log;
9-
import android.view.View;
10-
import android.view.ViewGroup;
11-
12-
import java.util.ArrayList;
13-
import java.util.List;
14-
15-
public class FlowLayout2 extends ViewGroup {
3+
/*
4+
class FlowLayout2 extends ViewGroup {
165
176
private static final String TAG = "FlowLayout";
187
@@ -67,10 +56,12 @@ public int getMaxLine(){
6756
return mMaxLine;
6857
}
6958
70-
/**
59+
*/
60+
/**
7161
* has more line by the max line.
7262
* @return true if has more line
73-
*/
63+
*//*
64+
7465
public boolean hasMoreLine(){
7566
return mHasMoreByMaxLine;
7667
}
@@ -107,9 +98,11 @@ protected LayoutParams generateDefaultLayoutParams() {
10798
LayoutParams.WRAP_CONTENT);
10899
}
109100
110-
/**
101+
*/
102+
/**
111103
* 负责设置子控件的测量模式和大小 根据所有子控件设置自己的宽和高
112-
*/
104+
*//*
105+
113106
@Override
114107
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
115108
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -126,13 +119,17 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
126119
// 如果是warp_content情况下,记录宽和高
127120
int maxWidth = 0;
128121
int height = 0;
129-
/**
122+
*/
123+
/**
130124
* 记录每一行的宽度,width不断取最大宽度
131-
*/
125+
*//*
126+
132127
int lineWidth = 0;
133-
/**
128+
*/
129+
/**
134130
* 每一行的高度,累加至height
135-
*/
131+
*//*
132+
136133
int lineHeight = 0;
137134
138135
int childCount = getChildCount();
@@ -151,9 +148,11 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
151148
int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
152149
// 当前子空间实际占据的高度
153150
int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
154-
/**
151+
*/
152+
/**
155153
* 如果加入当前child,则超出最大宽度,则的到目前最大宽度给width,类加height 然后开启新行
156-
*/
154+
*//*
155+
157156
if (lineWidth + childWidth + mHorizontalSpace > sizeWidth) {
158157
// 叠加当前高度,
159158
height += lineHeight;
@@ -191,13 +190,17 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
191190
192191
}
193192
194-
/**
193+
*/
194+
/**
195195
* 存储所有的View,按行记录
196-
*/
196+
*//*
197+
197198
private List<List<View>> mAllViews = new ArrayList<List<View>>();
198-
/**
199+
*/
200+
/**
199201
* 记录每一行的最大高度
200-
*/
202+
*//*
203+
201204
private List<Integer> mLineHeights = new ArrayList<Integer>();
202205
203206
@Override
@@ -229,9 +232,11 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
229232
lineWidth = 0;// 重置行宽
230233
lineViews = new ArrayList<View>();
231234
}
232-
/**
235+
*/
236+
/**
233237
* 如果不需要换行,则累加
234-
*/
238+
*//*
239+
235240
lineWidth += childWidth + lp.leftMargin + lp.rightMargin;
236241
lineHeight = Math.max(lineHeight, childHeight + lp.topMargin
237242
+ lp.bottomMargin);
@@ -286,3 +291,4 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
286291
287292
}
288293
}
294+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /