提高百分比拉动进度条与ViewPager兼容度
This commit is contained in:
parent
334da43001
commit
4756226a56
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Mar 09 11:30:17 HKT 2025
|
#Sun Mar 09 05:43:05 GMT 2025
|
||||||
stageCount=9
|
stageCount=9
|
||||||
libraryProject=libaes
|
libraryProject=libaes
|
||||||
baseVersion=7.6
|
baseVersion=7.6
|
||||||
publishVersion=7.6.8
|
publishVersion=7.6.8
|
||||||
buildCount=0
|
buildCount=24
|
||||||
baseBetaVersion=7.6.9
|
baseBetaVersion=7.6.9
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Mar 09 11:30:09 HKT 2025
|
#Sun Mar 09 05:43:05 GMT 2025
|
||||||
stageCount=9
|
stageCount=9
|
||||||
libraryProject=libaes
|
libraryProject=libaes
|
||||||
baseVersion=7.6
|
baseVersion=7.6
|
||||||
publishVersion=7.6.8
|
publishVersion=7.6.8
|
||||||
buildCount=0
|
buildCount=24
|
||||||
baseBetaVersion=7.6.9
|
baseBetaVersion=7.6.9
|
||||||
|
@ -192,7 +192,7 @@ public class TestViewPageFragment extends Fragment implements ViewPager.OnPageCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initAOHPCTCSeekBar() {
|
void initAOHPCTCSeekBar() {
|
||||||
AOHPCTCSeekBar seekbar = mView.findViewById(R.id.fragmentviewpageAOHPCTCSeekBar1);
|
AOHPCTCSeekBar seekbar = views.get(3).findViewById(R.id.fragmentviewpageAOHPCTCSeekBar1);
|
||||||
seekbar.setThumb(getActivity().getDrawable(R.drawable.ic_launcher));
|
seekbar.setThumb(getActivity().getDrawable(R.drawable.ic_launcher));
|
||||||
//seekbar.setThumbOffset(200);
|
//seekbar.setThumbOffset(200);
|
||||||
//seekbar.setThumbOffset(1);
|
//seekbar.setThumbOffset(1);
|
||||||
@ -207,7 +207,7 @@ public class TestViewPageFragment extends Fragment implements ViewPager.OnPageCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initAOHPCTCSeekBar2() {
|
void initAOHPCTCSeekBar2() {
|
||||||
AOHPCTCSeekBar seekbar = mView.findViewById(R.id.fragmentviewpageAOHPCTCSeekBar2);
|
AOHPCTCSeekBar seekbar = views.get(3).findViewById(R.id.fragmentviewpageAOHPCTCSeekBar2);
|
||||||
seekbar.setThumb(getActivity().getDrawable(R.drawable.ic_call));
|
seekbar.setThumb(getActivity().getDrawable(R.drawable.ic_call));
|
||||||
//seekbar.setThumbOffset(200);
|
//seekbar.setThumbOffset(200);
|
||||||
//seekbar.setThumbOffset(1);
|
//seekbar.setThumbOffset(1);
|
||||||
|
@ -16,24 +16,16 @@ public class AOHPCTCSeekBar extends SeekBar {
|
|||||||
|
|
||||||
public static final String TAG = "AOHPCTCSeekBar";
|
public static final String TAG = "AOHPCTCSeekBar";
|
||||||
|
|
||||||
Context mContext;
|
volatile int thumbWidth = 1;
|
||||||
|
volatile int progressBarWidth = 1;
|
||||||
int thumbWidth = 1;
|
|
||||||
int progressBarWidth = 1;
|
|
||||||
// 设置按钮模糊右边边缘像素
|
// 设置按钮模糊右边边缘像素
|
||||||
int blurRightDP = 1;
|
volatile int blurRightDP = 1;
|
||||||
|
// 是否从起点拉动的标志
|
||||||
|
volatile boolean isStartSeek = false;
|
||||||
|
|
||||||
// 可开始拉动的起始位置(百分比值)
|
|
||||||
//static final int ENABLE_POST_PERCENT_X = 20;
|
|
||||||
//int seekablePosition;
|
|
||||||
// 最小拉动值,滑块拉动值要超过这个值,确定事件才会提交。
|
|
||||||
//static final int TO_MIN_VALUE = 15;
|
|
||||||
// 外部接口对象,确定事件提交会调用该对象的方法
|
// 外部接口对象,确定事件提交会调用该对象的方法
|
||||||
OnOHPCListener mOnOHPCListener;
|
OnOHPCListener mOnOHPCListener;
|
||||||
// 是否从起点拉动的标志
|
|
||||||
boolean mIsStartTo = false;
|
|
||||||
// 拉动的滑动值
|
|
||||||
int mnTo = 0;
|
|
||||||
|
|
||||||
public void setBlurRightDP(int blurRight) {
|
public void setBlurRightDP(int blurRight) {
|
||||||
this.blurRightDP = blurRight;
|
this.blurRightDP = blurRight;
|
||||||
@ -55,24 +47,6 @@ public class AOHPCTCSeekBar extends SeekBar {
|
|||||||
public AOHPCTCSeekBar(Context context, AttributeSet attrs) {
|
public AOHPCTCSeekBar(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
initView(context);
|
initView(context);
|
||||||
|
|
||||||
//LogUtils.d(TAG, "AOHPCTCSeekBar(...)");
|
|
||||||
|
|
||||||
// 获得TypedArray
|
|
||||||
//TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AToolbar);
|
|
||||||
// 获得attrs.xml里面的属性值,格式为:名称_属性名,后面是默认值
|
|
||||||
//int colorBackgroud = a.getColor(R.styleable.ACard_backgroudColor, context.getColor(R.color.colorACardBackgroung));
|
|
||||||
//int centerColor = a.getColor(R.styleable.AToolbar_centerColor, context.getColor(R.color.colorAToolbarCenterColor));
|
|
||||||
//int endColor = a.getColor(R.styleable.AToolbar_endColor, context.getColor(R.color.colorAToolbarEndColor));
|
|
||||||
//float tSize = a.getDimension(R.styleable.CustomView_tSize, 35);
|
|
||||||
//p.setColor(tColor);
|
|
||||||
//p.setTextSize(tSize);
|
|
||||||
//Drawable drawable = context.getDrawable(R.drawable.frame_atoolbar);
|
|
||||||
|
|
||||||
//setBackground(context.getDrawable(R.drawable.acard_frame_main));
|
|
||||||
|
|
||||||
// 返回一个绑定资源结束的信号给资源
|
|
||||||
//a.recycle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AOHPCTCSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
public AOHPCTCSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
@ -81,110 +55,55 @@ public class AOHPCTCSeekBar extends SeekBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initView(Context context) {
|
void initView(Context context) {
|
||||||
LogUtils.d(TAG, "initView(...)");
|
|
||||||
mContext = context;
|
|
||||||
// Drawable thumbDrawable = getThumb();
|
|
||||||
// if (thumbDrawable!= null) {
|
|
||||||
// int iconWidth = thumbDrawable.getIntrinsicWidth();
|
|
||||||
// LogUtils.d(TAG, String.format("iconWidth %d", iconWidth));
|
|
||||||
// seekablePosition = iconWidth;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onFinishInflate() {
|
|
||||||
super.onFinishInflate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
//LogUtils.d(TAG, "ACTION_DOWN");
|
getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
// 有效的拖动起始位置(ENABLE_POST_PERCENT_X)%
|
|
||||||
//int nEnablePostX = ((getRight() - getLeft()) * ENABLE_POST_PERCENT_X / 100) + getLeft();
|
|
||||||
//int nEnablePostX = ((getRight() - getLeft()) * seekablePosition / 100) + getLeft();
|
|
||||||
/*LogUtils.d(TAG, "event.getX() is " + Float.toString(event.getX()));
|
|
||||||
LogUtils.d(TAG, String.format("thumbWidth %d progressBarWidth %d", thumbWidth, progressBarWidth));
|
|
||||||
LogUtils.d(TAG, String.format("mIsStartTo %s", mIsStartTo));
|
|
||||||
*/
|
|
||||||
if (thumbWidth + blurRightDP > event.getX() && event.getX() > 0) {
|
if (thumbWidth + blurRightDP > event.getX() && event.getX() > 0) {
|
||||||
mIsStartTo = true;
|
isStartSeek = true;
|
||||||
return true;
|
|
||||||
//return super.dispatchTouchEvent(event);
|
|
||||||
}
|
}
|
||||||
// if (!mIsStartTo) {
|
|
||||||
// resetView();
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||||
//LogUtils.d(TAG, "ACTION_MOVE");
|
if (isStartSeek) {
|
||||||
/*LogUtils.d(TAG, "event.getX() is " + Float.toString(event.getX()));
|
super.dispatchTouchEvent(event);
|
||||||
LogUtils.d(TAG, String.format("thumbWidth %d progressBarWidth %d", thumbWidth, progressBarWidth));
|
|
||||||
LogUtils.d(TAG, String.format("mIsStartTo %s", mIsStartTo));
|
|
||||||
*/
|
|
||||||
if (mIsStartTo) {
|
|
||||||
return super.dispatchTouchEvent(event);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else if (event.getAction() == MotionEvent.ACTION_UP
|
} else if (event.getAction() == MotionEvent.ACTION_UP
|
||||||
|| event.getAction() == MotionEvent.ACTION_CANCEL) {
|
|| event.getAction() == MotionEvent.ACTION_CANCEL) {
|
||||||
//LogUtils.d(TAG, Integer.toString(getProgress()));
|
getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
// 提交100%确定事件
|
|
||||||
// if (getProgress() == progressBarWidth) {
|
|
||||||
// //((getProgress() == 100) && (mnTo > TO_MIN_VALUE)) {
|
|
||||||
// //LogUtils.d(TAG, "Commit mnTo is " + Integer.toString(mnTo));
|
|
||||||
// mOnOHPCListener.onOHPCommit();
|
|
||||||
// resetView();
|
|
||||||
// //return true;
|
|
||||||
// } else {
|
|
||||||
// resetView();
|
|
||||||
// mIsStartTo = false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
if (getProgress() == progressBarWidth) {
|
if (getProgress() == progressBarWidth) {
|
||||||
mOnOHPCListener.onOHPCommit();
|
mOnOHPCListener.onOHPCommit();
|
||||||
}
|
}
|
||||||
mIsStartTo = false;
|
|
||||||
resetView();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//LogUtils.d(TAG, "dispatchTouchEvent End");
|
|
||||||
return super.dispatchTouchEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重置控件状态
|
// 重置控件状态
|
||||||
//
|
|
||||||
void resetView() {
|
|
||||||
setProgress(0);
|
setProgress(0);
|
||||||
mnTo = 0;
|
isStartSeek = false;
|
||||||
mIsStartTo = false;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
int height = MeasureSpec.getSize(heightMeasureSpec);
|
//int height = MeasureSpec.getSize(heightMeasureSpec);
|
||||||
LogUtils.d(TAG, String.format("width %d height %d", width, height));
|
//LogUtils.d(TAG, String.format("width %d height %d", width, height));
|
||||||
|
|
||||||
// 使用width和height进行后续操作
|
// 获取SeekBar的图标宽度
|
||||||
|
|
||||||
// 获取SeekBar的图标
|
|
||||||
Drawable thumbDrawable = getThumb();
|
Drawable thumbDrawable = getThumb();
|
||||||
if (thumbDrawable != null) {
|
if (thumbDrawable != null) {
|
||||||
// 获取图标宽度
|
// 获取图标宽度
|
||||||
thumbWidth = thumbDrawable.getIntrinsicWidth();
|
thumbWidth = thumbDrawable.getIntrinsicWidth();
|
||||||
// 获取进度条宽度
|
}
|
||||||
progressBarWidth = width;//getWidth();// - getPaddingLeft() - getPaddingRight();
|
|
||||||
// 计算百分比
|
|
||||||
//float percentage = (float) thumbWidth / progressBarWidth * 100;
|
|
||||||
LogUtils.d(TAG, String.format("thumbWidth %d progressBarWidth %d", thumbWidth, progressBarWidth));
|
|
||||||
//LogUtils.d(TAG, String.format("Thumb width / ProgressBar width percentage: %f", percentage));
|
|
||||||
|
|
||||||
//seekablePosition = (int)percentage;
|
// 获取进度条宽度
|
||||||
|
progressBarWidth = width;
|
||||||
|
|
||||||
|
//LogUtils.d(TAG, String.format("thumbWidth %d progressBarWidth %d", thumbWidth, progressBarWidth));
|
||||||
|
|
||||||
|
// 设置图标位置
|
||||||
setThumbOffset(0);
|
setThumbOffset(0);
|
||||||
|
// 设置进度条刻度
|
||||||
setMax(progressBarWidth);
|
setMax(progressBarWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -12,26 +12,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="AOHPCTCSeekBar"/>
|
android:text="AOHPCTCSeekBar"/>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center">
|
|
||||||
|
|
||||||
<cc.winboll.studio.libaes.views.AOHPCTCSeekBar
|
|
||||||
android:layout_width="300dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/fragmentviewpageAOHPCTCSeekBar1"
|
|
||||||
android:padding="10dp"/>
|
|
||||||
|
|
||||||
<cc.winboll.studio.libaes.views.AOHPCTCSeekBar
|
|
||||||
android:layout_width="300dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/fragmentviewpageAOHPCTCSeekBar2"
|
|
||||||
android:padding="10dp"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<androidx.viewpager.widget.ViewPager
|
<androidx.viewpager.widget.ViewPager
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
@ -11,6 +11,25 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="AOHPCTCSeekBar"/>
|
android:text="AOHPCTCSeekBar"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<cc.winboll.studio.libaes.views.AOHPCTCSeekBar
|
||||||
|
android:layout_width="300dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/fragmentviewpageAOHPCTCSeekBar1"
|
||||||
|
android:padding="10dp"/>
|
||||||
|
|
||||||
|
<cc.winboll.studio.libaes.views.AOHPCTCSeekBar
|
||||||
|
android:layout_width="300dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/fragmentviewpageAOHPCTCSeekBar2"
|
||||||
|
android:padding="10dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user