"ui"; /* * @version: 1.0 * @Date: 2021-08-15 15:43:57 * @LastEditTime: 2021-08-15 19:20:02 * @LastEditors: 牙叔 * @Description: BlurMaskFilter * @FilePath: \autojs-test\main.js * @名人名言: 牙叔教程 简单易懂 * @bilibili: 牙叔教程 * @公众号: 牙叔教程 * @QQ群: 747748653 */ //NORMAL: 内外都模糊绘制 //SOLID: 内部正常绘制,外部模糊 //OUTER: 内部不绘制,外部模糊 //INNER: 内部模糊,外部不绘制 engines.all().map((ScriptEngine) => { if (engines.myEngine().toString() !== ScriptEngine.toString()) { ScriptEngine.forceStop(); } }); importClass(android.graphics.Color); importClass(android.graphics.Path); importClass(android.graphics.Paint); importClass(android.graphics.BlurMaskFilter); importClass(android.view.MotionEvent); importClass(android.view.View); (function () { util.extend(CustomView, ui.Widget); function CustomView() { ui.Widget.call(this); let BlurMaskFilterBlurStyle = BlurMaskFilter.Blur.NORMAL; this.defineAttr("BlurMaskFilterBlurStyle", (view, attr, value, defineSetter) => { switch (value) { case "NORMAL": value = BlurMaskFilter.Blur.NORMAL; break; case "SOLID": value = BlurMaskFilter.Blur.SOLID; break; case "OUTER": value = BlurMaskFilter.Blur.OUTER; break; case "INNER": value = BlurMaskFilter.Blur.INNER; break; default: value = BlurMaskFilter.Blur.NORMAL; break; } BlurMaskFilterBlurStyle = value; }); let _radius = 1; let paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.RED); this.render = function () { return JavaAdapter( View, { onMeasure: function (widthMeasureSpec, heightMeasureSpec) { this.setMeasuredDimension(230, 230); }, onDraw: function (canvas) { if (_radius < 1) { _radius = 1; } paint.setMaskFilter(new BlurMaskFilter(_radius, BlurMaskFilterBlurStyle)); this.setLayerType(1, null); canvas.drawRect( 0 + this.getWidth() / 3, 0 + this.getHeight() / 3, (this.getWidth() / 3) * 2, (this.getHeight() / 3) * 2, paint ); }, setRadius: function (radius) { _radius = radius; this.invalidate(); }, }, activity ); }; } ui.registerWidget("custom-view", CustomView); return CustomView; })(); ui.layout( <vertical> <text text="牙叔教程 简单易懂" textSize="28sp" textColor="#fbfbfe" bg="#00afff" w="*" gravity="center"></text> <seekbar id="seekbar" margin="9"></seekbar> <vertical gravity="center_horizontal"> <text text="NORMAL" w="*" gravity="center" margin="6"></text> <custom-view id="customView" BlurMaskFilterBlurStyle="NORMAL" /> <text text="SOLID" w="*" gravity="center" margin="6"></text> <custom-view id="customView1" BlurMaskFilterBlurStyle="SOLID" /> <text text="OUTER" w="*" gravity="center" margin="6"></text> <custom-view id="customView2" BlurMaskFilterBlurStyle="OUTER" /> <text text="INNER" w="*" gravity="center" margin="6"></text> <custom-view id="customView3" BlurMaskFilterBlurStyle="INNER" /> </vertical> </vertical> ); ui.seekbar.setOnSeekBarChangeListener( new android.widget.SeekBar.OnSeekBarChangeListener({ onProgressChanged(seekBar, progress, fromUser) { ui.customView.setRadius(progress); ui.customView1.setRadius(progress); ui.customView2.setRadius(progress); ui.customView3.setRadius(progress); }, }) );
名人名言
思路是最重要的, 其他的百度, bing, stackoverflow, 安卓文档, autojs文档, 最后才是群里问问
--- 牙叔教程
声明
部分内容来自网络
本教程仅用于学习, 禁止用于其他用途