1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"minSdkVersion": "21",
|
||||
"dependencies":[
|
||||
"jp.wasabeef:blurry:4.0.1",
|
||||
"com.github.Dimezis:BlurView:version-2.0.6"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
// import UniversalBlurHelper from 'uts.sdk.modules.utsXdBlur.UniversalBlurHelper';
|
||||
import Color from 'android.graphics.Color';
|
||||
import View from 'android.view.View';
|
||||
|
||||
import Blurry from 'jp.wasabeef.blurry.Blurry'
|
||||
import ViewGroup from "android.view.ViewGroup";
|
||||
import Bitmap from "android.graphics.Bitmap";
|
||||
import ImageView from 'android.widget.ImageView';
|
||||
import Canvas from 'android.graphics.Canvas';
|
||||
|
||||
import BitmapDrawable from "android.graphics.drawable.BitmapDrawable";
|
||||
import { hexToRgb } from '../libs/color.uts'
|
||||
import { ManiWinFloat } from './mainWinFloa.uts'
|
||||
|
||||
export class xModalPage {
|
||||
contentView : View | null = null;
|
||||
rootWin : ManiWinFloat = new ManiWinFloat();
|
||||
constructor() {
|
||||
|
||||
}
|
||||
setView(ele : UniElement | null) {
|
||||
if (ele == null) return;
|
||||
let userView = ele.getAndroidView() as View | null
|
||||
|
||||
|
||||
if (userView == null) return;
|
||||
|
||||
this.contentView = userView;
|
||||
this.rootWin.setContent(userView)
|
||||
}
|
||||
show() {
|
||||
this.rootWin.show()
|
||||
|
||||
}
|
||||
hide() {
|
||||
|
||||
}
|
||||
destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export class xdBlur {
|
||||
$element : UniNativeViewElement;
|
||||
targetView : View | null = null;
|
||||
// bgView:bgBlurView = new bgBlurView(UTSAndroid.getAppContext()!)
|
||||
constructor(element : UniNativeViewElement) {
|
||||
//接收传递过来的UniNativeViewElement
|
||||
this.$element = element;
|
||||
this.bindView();
|
||||
}
|
||||
bindView() {
|
||||
//通过UniElement.getAndroidActivity()获取android平台activity 用于创建view的上下文
|
||||
this.targetView = new View(this.$element.getAndroidActivity()!); //构建原生view
|
||||
// this.targetView = new bgBlurView(this.$element.getAndroidActivity()!); //构建原生view
|
||||
|
||||
// this.targetView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT))
|
||||
|
||||
// //限制原生Button 文案描述不自动大写
|
||||
// this.button?.setAllCaps(false)
|
||||
// //监听原生Button点击事件
|
||||
// this.button?.setOnClickListener(_ => {
|
||||
// const detail = {}
|
||||
// //构建自定义UniNativeViewEvent返回对象
|
||||
// const event = new UniNativeViewEvent("customClick", detail)
|
||||
// //触发原生Button的点击事件
|
||||
// this.$element.dispatchEvent(event)
|
||||
// })
|
||||
//UniNativeViewEvent 绑定 安卓原生view
|
||||
this.$element.bindAndroidView(this.targetView!);
|
||||
}
|
||||
|
||||
|
||||
setFilterBg(blur : number, bgcolor : string, ele : UniElement | null = null) {
|
||||
// let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
|
||||
// this.targetView?.refreshBG(decorView)
|
||||
|
||||
let colorrgba = hexToRgb(bgcolor)
|
||||
let r = (colorrgba?.r ?? 255).toInt()
|
||||
let g = (colorrgba?.g ?? 255).toInt()
|
||||
let b = (colorrgba?.b ?? 255).toInt()
|
||||
let a = ((colorrgba?.a ?? 1) * 255).toInt()
|
||||
let br = (blur / 100 * 25).toFloat()
|
||||
let view = this.targetView!;
|
||||
view.setBackgroundColor(Color.argb(a, r, g, b))
|
||||
let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
|
||||
let context = UTSAndroid.getAppContext()!;
|
||||
|
||||
let bitmap : Bitmap = Blurry.with(context)
|
||||
.radius(br.toInt()) // 模糊度
|
||||
.sampling(8) // 采样
|
||||
.color(Color.argb(a, r, g, b))
|
||||
.capture(decorView) // 捕获背景View
|
||||
.get()
|
||||
let location = new IntArray(2);
|
||||
view.getLocationInWindow(location);
|
||||
let top = (location[1]).toInt()
|
||||
let left = location[0]
|
||||
let okbitm = Bitmap.createBitmap(bitmap, left, top, view.getWidth(), view.getHeight());
|
||||
view.setBackground(new BitmapDrawable(view.getResources(), okbitm));
|
||||
}
|
||||
|
||||
public static setFilterSelfBg(ele : UniElement, bg : UniElement, blur : number, bgcolor : string) {
|
||||
let colorrgba = hexToRgb(bgcolor)
|
||||
let r = (colorrgba?.r ?? 255).toInt()
|
||||
let g = (colorrgba?.g ?? 255).toInt()
|
||||
let b = (colorrgba?.b ?? 255).toInt()
|
||||
let a = ((colorrgba?.a ?? 1) * 255).toInt()
|
||||
let br = (blur / 100 * 25).toFloat()
|
||||
let view = ele.getAndroidView()! as View
|
||||
let viewbg = bg.getAndroidView()! as View
|
||||
let context = UTSAndroid.getAppContext()!;
|
||||
|
||||
let bitmapbg = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
|
||||
let canvas = new Canvas(bitmapbg)
|
||||
view.draw(canvas)
|
||||
|
||||
let imgview = new ImageView(context)
|
||||
Blurry.with(context)
|
||||
.radius(br.toInt())
|
||||
.sampling(8)
|
||||
.color(Color.argb(a, r, g, b))
|
||||
.from(bitmapbg)
|
||||
.into(imgview)
|
||||
|
||||
viewbg.setBackground(imgview.getDrawable());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import LinearLayout from 'android.widget.LinearLayout';
|
||||
import Context from 'android.content.Context'
|
||||
import RelativeLayout from 'android.widget.RelativeLayout';
|
||||
import ViewGroup from 'android.view.ViewGroup';
|
||||
import View from 'android.view.View';
|
||||
import Color from 'android.graphics.Color';
|
||||
import Gravity from 'android.view.Gravity';
|
||||
import GradientDrawable from 'android.graphics.drawable.GradientDrawable';
|
||||
import TextView from 'android.widget.TextView';
|
||||
import Typeface from 'android.graphics.Typeface';
|
||||
import TextUtils from 'android.text.TextUtils';
|
||||
import Uri from 'android.net.Uri';
|
||||
import ObjectAnimator from 'android.animation.ObjectAnimator';
|
||||
import ValueAnimator from 'android.animation.ValueAnimator';
|
||||
import TimeInterpolator from 'android.animation.TimeInterpolator';
|
||||
import MotionEvent from 'android.view.MotionEvent';
|
||||
import { hexToRgb } from "../libs/color.uts"
|
||||
import ViewPropertyAnimator from 'android.view.ViewPropertyAnimator';
|
||||
import ScrollView from 'android.widget.ScrollView';
|
||||
import AccelerateDecelerateInterpolator from 'android.view.animation.AccelerateDecelerateInterpolator';
|
||||
// #ifdef UNI-APP-X
|
||||
import getCurrentPages from 'io.dcloud.uniapp.framework.getCurrentPages';
|
||||
import onReady from 'io.dcloud.uniapp.framework.onReady';
|
||||
import onUnload from 'io.dcloud.uniapp.framework.onUnload';
|
||||
import onShow from 'io.dcloud.uniapp.framework.onShow';
|
||||
import Visibility from 'android.transition.Visibility';
|
||||
// #endif
|
||||
|
||||
|
||||
export class ManiWinFloat {
|
||||
contentView:View|null = null;
|
||||
parentView:LinearLayout|null = null;
|
||||
contentWrap:ScrollView|null = null;
|
||||
constructor(){
|
||||
this._createRootView();
|
||||
}
|
||||
getContext():Context{
|
||||
const context = UTSAndroid.getAppContext()! as Context
|
||||
return context;
|
||||
}
|
||||
getWinRoot():ViewGroup{
|
||||
let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
|
||||
return decorView;
|
||||
}
|
||||
setContent(view:View){
|
||||
this.contentView = view;
|
||||
this.contentWrap?.addView(view)
|
||||
console.log(view)
|
||||
}
|
||||
show(){
|
||||
this.parentView?.setVisibility(View.VISIBLE)
|
||||
}
|
||||
hide(){}
|
||||
destroy(){
|
||||
|
||||
}
|
||||
|
||||
_createRootView(){
|
||||
// 内容容器
|
||||
let container = new LinearLayout(this.getContext());
|
||||
|
||||
let containerLayrPrams = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
container.setLayoutParams(containerLayrPrams)
|
||||
container.setBackgroundColor(Color.GREEN)
|
||||
container.setOrientation(LinearLayout.VERTICAL)
|
||||
// container.setGravity(Gravity.CENTER)
|
||||
container.setVisibility(View.GONE)
|
||||
container.setAlpha((0.3).toFloat())
|
||||
|
||||
// 滚动容器
|
||||
let scroll = new ScrollView(this.getContext())
|
||||
scroll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||
this.contentWrap = scroll;
|
||||
container.addView(scroll)
|
||||
this.parentView = container;
|
||||
this.getWinRoot().addView(this.parentView)
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user