Skip to content

Commit

Permalink
优化频道删除
Browse files Browse the repository at this point in the history
  • Loading branch information
chengzhicao committed May 28, 2019
1 parent ecbfded commit 16758e7
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 50 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
29 changes: 0 additions & 29 deletions .idea/codeStyles/Project.xml

This file was deleted.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/markdown-navigator/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ dependencies {

**建议将compileSdkVersion改为28,低于28会出现编译问题**

# v1.0.8说明
> 1. 优化频道删除
# v1.0.7说明
> 1. 修复bug
> 2. 增加获取其他频道内容方法
Expand Down
4 changes: 2 additions & 2 deletions channelview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 2
versionName "1.0.7"
versionCode 3
versionName "1.0.8"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
46 changes: 31 additions & 15 deletions channelview/src/main/java/com/cheng/channel/ChannelView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -203,8 +202,19 @@ public ChannelView(Context context, AttributeSet attrs, int defStyleAttr) {
if (channelFixedCount < 0) {
channelFixedCount = 0;
}
maxAccessDrag = context.getResources().getDisplayMetrics().density * DRAG_THRESHOLD + 0.5f;
}

/**
* 可允许拖拽的阈值(单位为dp)
*/
private final int DRAG_THRESHOLD = 5;

/**
* 触摸频道进行move时,当达到该值时可允许频道拖拽
*/
private float maxAccessDrag;

/**
* 设置固定频道个数
*
Expand Down Expand Up @@ -990,14 +1000,19 @@ private void addChannelView() {
}
}

/**
* 拖拽时距离点击时的最远距离
*/
private double maxDistanceToDownPosition;

@Override
public boolean onTouch(View v, MotionEvent event) {
// //如果点击的是我的频道组中的频道
if (event.getAction() == MotionEvent.ACTION_DOWN) {
downX = event.getRawX();
downY = event.getRawY();
maxDistanceToDownPosition = 0;
downX = dragX = event.getRawX();
downY = dragY = event.getRawY();
if (isEditState) {
Log.i("jfiowejoigwieg", "down");
setTime(v);
}
}
Expand All @@ -1006,41 +1021,41 @@ public boolean onTouch(View v, MotionEvent event) {
//手移动时拖动频道
//请求ScrollView不要拦截MOVE事件,交给TextView处理
requestDisallowInterceptTouchEvent(true);
if (maxDistanceToDownPosition < maxAccessDrag) {
double sqrt = Math.sqrt(Math.pow(event.getRawX() - downX, 2) + Math.pow(event.getRawY() - downY, 2));
if (sqrt > maxDistanceToDownPosition) {
maxDistanceToDownPosition = sqrt;
}
}
channelDrag(v, event);
}
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
Log.i("jfiowejoigwieg", "up...cancel");
if (thread != null && thread.isAlive() && !thread.isInterrupted()) {
thread.interrupt();
}
if (isAccessDrag) {
Log.i("jfiowejoigwieg", "恢复");
ChannelAttr vTag = (ChannelAttr) v.getTag();
v.animate().x(vTag.coordinate.x).y(vTag.coordinate.y).setDuration(DURATION_TIME);
v.setBackgroundResource(channelEditBackground);
((TextView) v).setTextColor(channelNormalTextColor);
isAccessDrag = false;
return true;
return !(maxDistanceToDownPosition < maxAccessDrag);
}
}
}
return false;
}

private void setTime(final View v) {
Log.i("jfiowejoigwieg", "要执行了");
thread = new Thread() {
@Override
public void run() {
try {
Log.i("jfiowejoigwieg", "正在执行");
sleep(MIN_TIME_INTERVAL);
} catch (InterruptedException e) {
Log.i("jfiowejoigwieg", "取消了");
e.printStackTrace();
return;
}
Log.i("jfiowejoigwieg", "有背景了");
Message message = new Message();
message.obj = v;
handler.sendMessage(message);
Expand Down Expand Up @@ -1344,6 +1359,7 @@ private void viewMove(int position, int offSetY) {
}

float downX, downY;
float dragX, dragY;
float moveX, moveY;

/**
Expand All @@ -1352,10 +1368,10 @@ private void viewMove(int position, int offSetY) {
private void channelDrag(View v, MotionEvent event) {
moveX = event.getRawX();
moveY = event.getRawY();
v.setX(v.getX() + (moveX - downX));
v.setY(v.getY() + (moveY - downY));
downX = moveX;
downY = moveY;
v.setX(v.getX() + (moveX - dragX));
v.setY(v.getY() + (moveY - dragY));
dragX = moveX;
dragY = moveY;
ArrayList<View> myChannels = channelGroups.get(0);
ChannelAttr vTag = (ChannelAttr) v.getTag();
int vIndex = myChannels.indexOf(v);
Expand Down

0 comments on commit 16758e7

Please sign in to comment.