/*
软件作者:https://xuhss.com/oxox/pro
*/
/*
* @Author: 大柒
* @QQ: 531310591@qq.com
* @Date: 2019-07-01 23:41:57
* @Version: Auto.Js Pro
* @Description:
* @LastEditors: 大柒
* @LastEditTime: 2019-07-02 07:28:48
*/
"ui";
importClass(android.animation.ObjectAnimator);
importClass(android.animation.AnimatorSet);
importClass(android.view.animation.BounceInterpolator);
//储存argb颜色 A,R,G,B,值
var colorData = {
A: 0,
R: 0,
G: 0,
B: 0
}
//dp和px之间转换
var scale = context.getResources().getDisplayMetrics().density;
var px2dp = function (px) {
return Math.floor(px / scale + 0.5);
}
var dp2px = function (dp) {
return Math.floor(dp * scale + 0.5);
}
//自定义控件 seekbar拖动条
var seekbarLayout = function () {
util.extend(seekbarLayout, ui.Widget);
function seekbarLayout() {
ui.Widget.call(this);
this.defineAttr("color", (view, attr, value, defineSetter) => {
this.setView(view);
view.btn_seekbar_color.attr("src", value);
view.btn_seekbar_bg_color.attr("src", "#50" + value.replace(/#/g, ""));
view.seekbar_qj.attr("cardBackgroundColor", value);
view.scale_bottom_bg.attr("cardBackgroundColor", value);
view.scale_bottom_bg_left.attr("cardBackgroundColor", value);
view.scale_bottom_bg_right.attr("cardBackgroundColor", value);
view.seekbar_bg.attr("cardBackgroundColor", "#50" + value.replace(/#/g, ""));
view.scale_left_src.attr("tint", value);
view.scale_right_src.attr("tint", value);
view.scale_top_src.attr("tint", value);
});
this.defineAttr("title", (view, attr, value, defineSetter) => {
view.scale_bottom_title.setText(value);
view.title_bg.attr("visibility", "visible");
});
this.defineAttr("subTitle", (view, attr, value, defineSetter) => {
view.scale_top_title.setText(value);
});
this.defineAttr("scaleIconVisibility", (view, attr, value, defineSetter) => {
let e;
value == "true" ? e = "visible" : e = "gone";
view.scale_right.attr("visibility", e);
view.scale_left.attr("visibility", e);
});
this.defineAttr("max", (view, attr, value, defineSetter) => {
this.setMax(value);
})
this.defineAttr("progress", (view, attr, value, defineSetter) => {
view.scale_top_text.setText(value);
this.setProgress(value);
});
this.defineAttr("onClick", (view, name, defineSetter) => {
return this._onClick;
}, (view, name, value, defineSetter) => {
this._onClick = value;
});
//自定义属性
this.defineAttr("progressChanged")
this.defineAttr("view")
this.defineAttr("index")
}
//初始化事件
seekbarLayout.prototype.setView = function (view) {
this.view = view;
//设置默认值为0
this.setIndex(0);
let id = setInterval(() => {
if (view.seekbar_bg.getLeft()) {
clearInterval(id);
//初始化 颜色参数
colorData[view.scale_top_title.text()] = this.index;
colorPreview();
//加载 事件触发
this.OnProgressChanged();
}
}, 5)
}
//设置进度条当前值
seekbarLayout.prototype.setIndex = function (value) {
this.index = value;
}
//设置进度条最大值
seekbarLayout.prototype.setMax = function (value) {
this.view.scale_right_text.setText(value);
this.max = value;
return this.max;
}
//设置进度值
seekbarLayout.prototype.setProgress = function (value) {
let id = setInterval(() => {
if (this.view.seekbar_bg.getLeft()) {
clearInterval(id);
this.left = this.view.seekbar_bg.getLeft() - dp2px(16);
this.right = this.view.seekbar_bg.getRight() - dp2px(16);
this.scale = (this.right - this.left) / this.max;
this.setIndex(value);
this.view.btn_seekbar.setTranslationX(this.scale * value);
this.view.seekbar_qj.attr("width", parseInt(px2dp(this.scale * value)));
}
}, 5);
}
//事件触发
seekbarLayout.prototype.OnProgressChanged = function () {
let view = this.view;
let x = dp2px(32);
let y = dp2px(6);
let left = view.seekbar_bg.getLeft() - dp2px(16);
let right = view.seekbar_bg.getRight() - dp2px(16);
let max = this.max;
let scale = (right - left) / max;
let eventX = 0;
let index = this.index;
let _index = 0;
let onClick = this._onClick;
//读取 subTitle 值 当进度发生改变时 更改colorData对应值 并触发colorPreview()函数
view.btn_seekbar_bg_color.setOnTouchListener(function (_view, event) {
switch (event.getAction()) {
case event.ACTION_DOWN:
//动画
animationY = ObjectAnimator.ofFloat(view.animation_img, "translationY", 0, -y);
animationScaleX = ObjectAnimator.ofFloat(view.btn_seekbar_bg_color, "scaleX", 0.5, 1);
animationScaleY = ObjectAnimator.ofFloat(view.btn_seekbar_bg_color, "scaleY", 0.5, 1);
set = new AnimatorSet();
set.playTogether([animationY, animationScaleX, animationScaleY]);
set.setDuration(200);
set.start();
//按钮半透明背景 透明度设为1
view.btn_seekbar_bg_color.attr("alpha", 1);
return true
case event.ACTION_MOVE:
//手指触摸的X值
eventX = event.getRawX() - x;
if (eventX < left) {
eventX = left;
} else if (right < eventX) {
eventX = right;
};
_index = parseInt(eventX / scale)
//进度发生改变 触发
if (index != _index) {
index = _index;
view.scale_top_text.setText("" + index);
eval(onClick);
};
//设置 进度条指示器位置
view.btn_seekbar.setTranslationX(eventX);
//设置 一级进度条宽度
view.seekbar_qj.attr("width", parseInt(px2dp(eventX)));
return true
case event.ACTION_UP:
//动画
animationY = ObjectAnimator.ofFloat(view.animation_img, "translationY", -y, 0);
animationScaleX = ObjectAnimator.ofFloat(view.btn_seekbar_bg_color, "scaleX", 1, 0.5);
animationScaleY = ObjectAnimator.ofFloat(view.btn_seekbar_bg_color, "scaleY", 1, 0.5);
set = new AnimatorSet();
set.playTogether([animationY, animationScaleX, animationScaleY]);
set.setDuration(200);
set.start();
//定时器 在动画结束后 将半透明按钮背景大小恢复 透明度设为0
setTimeout(() => {
view.btn_seekbar_bg_color.attr("alpha", 0)
view.btn_seekbar_bg_color.setScaleX(1);
view.btn_seekbar_bg_color.setScaleY(1);
}, 250)
return true
}
return true
});
没有合适的资源?快使用搜索试试~ 我知道了~
AutoJs源码-拖动条控件。本资源购买前提醒:本源码都是实际autojs项目模板,安装好autojs直接运行即可打开。1、支持低版本autojs。2、资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!。3、安装过程详见具体资源,不会使用autojs谨慎下载
资源推荐
资源详情
资源评论
收起资源包目录
AutoJs源码-拖动条控件.7z (1个子文件)
AutoJs源码-拖动条控件.js 13KB
共 1 条
- 1
资源评论
[虚幻私塾】
- 粉丝: 327
- 资源: 1559
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功