规则编辑列表的项滑动逻辑完成。
This commit is contained in:
parent
3535df8b3e
commit
948141d5a9
@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Wed Mar 05 17:21:57 HKT 2025
|
||||
#Wed Mar 05 12:40:02 GMT 2025
|
||||
stageCount=10
|
||||
libraryProject=
|
||||
baseVersion=1.0
|
||||
publishVersion=1.0.9
|
||||
buildCount=0
|
||||
buildCount=35
|
||||
baseBetaVersion=1.0.10
|
||||
|
@ -25,6 +25,7 @@ import android.widget.LinearLayout;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import cc.winboll.studio.contacts.views.LeftScrollView;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
|
||||
public class PhoneConnectRuleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
@ -62,6 +63,43 @@ public class PhoneConnectRuleAdapter extends RecyclerView.Adapter<RecyclerView.V
|
||||
String szView = model.getRuleText().trim().equals("")?"[NULL]":model.getRuleText();
|
||||
simpleViewHolder.tvRuleText.setText(szView);
|
||||
simpleViewHolder.scrollView.setOnActionListener(new LeftScrollView.OnActionListener(){
|
||||
|
||||
@Override
|
||||
public void onUp() {
|
||||
ArrayList<PhoneConnectRuleModel> list = Rules.getInstance(context).getPhoneBlacRuleBeanList();
|
||||
if(position > 0) {
|
||||
ToastUtils.show("onUp");
|
||||
simpleViewHolder.scrollView.smoothScrollTo(0, 0);
|
||||
// PhoneConnectRuleModel newBean = new PhoneConnectRuleModel();
|
||||
// newBean.setRuleText(list.get(position).getRuleText());
|
||||
// newBean.setIsAllowConnection(list.get(position).isAllowConnection());
|
||||
// newBean.setIsEnable(list.get(position).isEnable());
|
||||
// newBean.setIsSimpleView(list.get(position).isSimpleView());
|
||||
list.add(position - 1, list.get(position));
|
||||
list.remove(position + 1);
|
||||
Rules.getInstance(context).saveRules();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDown() {
|
||||
ArrayList<PhoneConnectRuleModel> list = Rules.getInstance(context).getPhoneBlacRuleBeanList();
|
||||
if(position < list.size() - 1) {
|
||||
ToastUtils.show("onDown");
|
||||
simpleViewHolder.scrollView.smoothScrollTo(0, 0);
|
||||
// PhoneConnectRuleModel newBean = new PhoneConnectRuleModel();
|
||||
// newBean.setRuleText(list.get(position).getRuleText());
|
||||
// newBean.setIsAllowConnection(list.get(position).isAllowConnection());
|
||||
// newBean.setIsEnable(list.get(position).isEnable());
|
||||
// newBean.setIsSimpleView(list.get(position).isSimpleView());
|
||||
list.add(position + 2, list.get(position));
|
||||
list.remove(position);
|
||||
Rules.getInstance(context).saveRules();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEdit() {
|
||||
simpleViewHolder.scrollView.smoothScrollTo(0, 0);
|
||||
|
@ -15,7 +15,6 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import cc.winboll.studio.contacts.R;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import android.util.TypedValue;
|
||||
|
||||
public class LeftScrollView extends HorizontalScrollView {
|
||||
|
||||
@ -26,8 +25,12 @@ public class LeftScrollView extends HorizontalScrollView {
|
||||
private TextView textView;
|
||||
private Button editButton;
|
||||
private Button deleteButton;
|
||||
private float mLastX;
|
||||
private Button upButton;
|
||||
private Button downButton;
|
||||
private float mStartX;
|
||||
private float mEndX;
|
||||
private boolean isScrolling = false;
|
||||
private int nScrollAcceptSize;
|
||||
|
||||
public LeftScrollView(Context context) {
|
||||
super(context);
|
||||
@ -52,6 +55,7 @@ public class LeftScrollView extends HorizontalScrollView {
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) contentLayout.getLayoutParams();
|
||||
layoutParams.width = contentWidth;
|
||||
contentLayout.setLayoutParams(layoutParams);
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
@ -69,6 +73,10 @@ public class LeftScrollView extends HorizontalScrollView {
|
||||
editButton = viewMain.findViewById(R.id.edit_btn);
|
||||
// 创建删除按钮
|
||||
deleteButton = viewMain.findViewById(R.id.delete_btn);
|
||||
// 向上按钮
|
||||
upButton = viewMain.findViewById(R.id.up_btn);
|
||||
// 向下按钮
|
||||
downButton = viewMain.findViewById(R.id.down_btn);
|
||||
|
||||
// 编辑按钮点击事件
|
||||
editButton.setOnClickListener(new OnClickListener() {
|
||||
@ -89,6 +97,25 @@ public class LeftScrollView extends HorizontalScrollView {
|
||||
}
|
||||
}
|
||||
});
|
||||
// 编辑按钮点击事件
|
||||
upButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onActionListener != null) {
|
||||
onActionListener.onUp();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 删除按钮点击事件
|
||||
downButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onActionListener != null) {
|
||||
onActionListener.onDown();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -96,53 +123,40 @@ public class LeftScrollView extends HorizontalScrollView {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
LogUtils.d(TAG, "ACTION_DOWN");
|
||||
mLastX = event.getX();
|
||||
isScrolling = false;
|
||||
mStartX = event.getX();
|
||||
// isScrolling = false;
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
//LogUtils.d(TAG, "ACTION_MOVE");
|
||||
float currentX = event.getX();
|
||||
float deltaX = mLastX - currentX;
|
||||
mLastX = currentX;
|
||||
if (Math.abs(deltaX) > 0) {
|
||||
isScrolling = true;
|
||||
}
|
||||
// float currentX = event.getX();
|
||||
// float deltaX = mStartX - currentX;
|
||||
// //mLastX = currentX;
|
||||
// if (Math.abs(deltaX) > 0) {
|
||||
// isScrolling = true;
|
||||
// }
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
LogUtils.d(TAG, "ACTION_UP");
|
||||
if (isScrolling) {
|
||||
LogUtils.d(TAG, String.format("isScrolling \ngetScrollX() %d\neditButton.getWidth() %d", getScrollX(), editButton.getWidth()));
|
||||
int scrollX = getScrollX();
|
||||
if (scrollX > editButton.getWidth()) {
|
||||
// 获取HorizontalScrollView的子视图
|
||||
View childView = getChildAt(0);
|
||||
if (childView != null) {
|
||||
// 计算需要滑动到最右边的距离
|
||||
int scrollToX = childView.getWidth() - getWidth();
|
||||
// 确保滑动距离不小于0
|
||||
final int scrollToX2 = Math.max(0, scrollToX);
|
||||
// 平滑滑动到最右边
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
smoothScrollTo(scrollToX2, 0);
|
||||
LogUtils.d(TAG, "smoothScrollTo(0, 0);");
|
||||
}
|
||||
});
|
||||
LogUtils.d(TAG, "smoothScrollTo(scrollToX, 0);");
|
||||
if (getScrollX() > 0) {
|
||||
LogUtils.d(TAG, "ACTION_UP");
|
||||
mEndX = event.getX();
|
||||
LogUtils.d(TAG, String.format("mStartX %f, mEndX %f", mStartX, mEndX));
|
||||
if (mEndX < mStartX) {
|
||||
LogUtils.d(TAG, String.format("mEndX >= mStartX \ngetScrollX() %d", getScrollX()));
|
||||
//if (getScrollX() > editButton.getWidth()) {
|
||||
if (Math.abs(mStartX - mEndX) > editButton.getWidth()) {
|
||||
smoothScrollToRight();
|
||||
} else {
|
||||
smoothScrollToLeft();
|
||||
}
|
||||
} else {
|
||||
// 恢复原状
|
||||
// 在手指抬起时,使用 post 方法调用 smoothScrollTo(0, 0)
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
smoothScrollTo(0, 0);
|
||||
LogUtils.d(TAG, "smoothScrollTo(0, 0);");
|
||||
}
|
||||
});
|
||||
//toolLayout.setTranslationX(0);
|
||||
LogUtils.d(TAG, String.format("mEndX >= mStartX \ngetScrollX() %d", getScrollX()));
|
||||
//if (getScrollX() > deleteButton.getWidth()) {
|
||||
if (Math.abs(mEndX - mStartX) > deleteButton.getWidth()) {
|
||||
smoothScrollToLeft();
|
||||
} else {
|
||||
smoothScrollToRight();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -150,6 +164,40 @@ public class LeftScrollView extends HorizontalScrollView {
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
void smoothScrollToRight() {
|
||||
mEndX = 0;
|
||||
mStartX = 0;
|
||||
View childView = getChildAt(0);
|
||||
if (childView != null) {
|
||||
// 计算需要滑动到最右边的距离
|
||||
int scrollToX = childView.getWidth() - getWidth();
|
||||
// 确保滑动距离不小于0
|
||||
final int scrollToX2 = Math.max(0, scrollToX);
|
||||
// 平滑滑动到最右边
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
smoothScrollTo(scrollToX2, 0);
|
||||
LogUtils.d(TAG, "smoothScrollTo(0, 0);");
|
||||
}
|
||||
});
|
||||
LogUtils.d(TAG, "smoothScrollTo(scrollToX, 0);");
|
||||
}
|
||||
}
|
||||
|
||||
void smoothScrollToLeft() {
|
||||
mEndX = 0;
|
||||
mStartX = 0;
|
||||
// 在手指抬起时,使用 post 方法调用 smoothScrollTo(0, 0)
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
smoothScrollTo(0, 0);
|
||||
LogUtils.d(TAG, "smoothScrollTo(0, 0);");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 设置文本内容
|
||||
public void setText(CharSequence text) {
|
||||
textView.setText(text);
|
||||
@ -159,6 +207,8 @@ public class LeftScrollView extends HorizontalScrollView {
|
||||
public interface OnActionListener {
|
||||
void onEdit();
|
||||
void onDelete();
|
||||
void onUp();
|
||||
void onDown();
|
||||
}
|
||||
|
||||
private OnActionListener onActionListener;
|
||||
|
@ -30,7 +30,18 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="编辑"
|
||||
android:background="@color/blue" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/up_btn"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="△"
|
||||
android:background="@color/green" />
|
||||
<Button
|
||||
android:id="@+id/down_btn"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="▽"
|
||||
android:background="@color/green" />
|
||||
<Button
|
||||
android:id="@+id/delete_btn"
|
||||
android:layout_width="80dp"
|
||||
|
@ -5,6 +5,7 @@
|
||||
<color name="colorPrimaryDark">#FF002B57</color>
|
||||
<color name="colorAccent">#FF80BFFF</color>
|
||||
<color name="blue">#FF379AFF</color>
|
||||
<color name="green">#FF69E551</color>
|
||||
<color name="red">#FFE55151</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
<color name="lightgray">#FFE0E0E0</color>
|
||||
|
Loading…
x
Reference in New Issue
Block a user