This commit is contained in:
2026-09-24 16:25:22 +08:00
commit 7428184f01
1198 changed files with 314515 additions and 0 deletions
+259
View File
@@ -0,0 +1,259 @@
import Context from 'android.content.Context'
import LinearLayout from 'android.widget.LinearLayout';
import ViewGroup from 'android.view.ViewGroup';
import View from 'android.view.View';
import TextView from 'android.widget.TextView';
import ImageView from 'android.widget.ImageView';
import Gravity from 'android.view.Gravity';
import Color from 'android.graphics.Color';
import Activity from 'android.app.Activity';
import { ref} from "vue"
import TextUtils from 'android.text.TextUtils';
import GradientDrawable from 'android.graphics.drawable.GradientDrawable'
import MotionEvent from 'android.view.MotionEvent';
import Typeface from 'android.graphics.Typeface';
import {hexToRgb,getDefaultColor,toFillMarginAr,colorGetHover,colorGetThint} from "../util/xCoreColorUtil.uts"
import {getUid,dp2px} from "../util/xCoreUtil.uts"
import xLinearView from "./linearView.uts";
import xCardView from "./cardView.uts";
import xIcon from "./icon.uts";
import xText from "./text.uts";
class xButton {
view:xLinearView;
textLayer:xText;
iconLayer:xIcon;
bgLayer:xCardView;
wrapLinear:xLinearView;
width:number = 180;
heigth:number = 64;
private _backgroundColor = "primary";
status = 'default';//default,success,warn,danger
type = 'primary';//normal,primary,secondary,dashed,outlin,text
constructor(context : Context){
let boxLinear = new xLinearView(context)
let wrapLinear = new xLinearView(context)
let bgView = new xCardView(context)
let iconView = new xIcon(context)
let laberView = new xText(context)
boxLinear.setLayoutParams(this.width.toInt(),this.heigth.toInt(),0)
boxLinear.setAlign(Gravity.CENTER)
wrapLinear.setLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT,0)
wrapLinear.setAlign(Gravity.CENTER_VERTICAL|Gravity.CENTER)
bgView.setRadius(6);
iconView.setFontColor("white").setFontSize(18)
laberView.setBackgroundColor('transparent').setFontColor("white").setFontSize(16)
laberView.setLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,0)
wrapLinear.append(iconView.getView(),laberView.getView())
bgView.append(wrapLinear.getView() as View)
boxLinear.append(bgView.getView() as View)
this.textLayer = laberView;
this.wrapLinear = wrapLinear;
this.bgLayer = bgView;
this.iconLayer = iconView;
this.view = boxLinear;
this._setBackgroundColor('','up')
bgView.setTouchStart((event : MotionEvent):void=>{
this._setBackgroundColor('','down')
}).setTouchEnd((event : MotionEvent):void=>{
this._setBackgroundColor('','up')
})
}
/**
* type:
* auto:按钮宽度自动为内容宽,w宽度失效。
* block:按钮宽度自动为父级宽,w宽度失效。
* '':空值,取w,h为按钮宽和高。
* 'mini':44,24,10
* 'small':64,32,12
* 'medium':180,64,15
* 'large':220,76,16
*/
setSize(w:number,h:number,type= ''):xButton{
if(type =='auto'){
this.width = w;
this.heigth = h;
this.view.setLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,this.heigth.toInt(),0)
}else if(type =='mini'){
this.heigth = 28;
this.view.setLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,this.heigth.toInt(),0)
// this.bgLayer.setLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,this.heigth.toInt(),0)
this.setFontSize(10)
}else if(type =='small'){
this.width = 64;
this.heigth = 32;
this.view.setLayoutParams(this.width.toInt(),this.heigth.toInt(),0)
}else if(type =='medium'||type==''){
this.width = 180;
this.heigth = 64;
this.view.setLayoutParams(this.width.toInt(),this.heigth.toInt(),0)
}else if(type =='large'){
this.width = 220;
this.heigth = 76;
this.view.setLayoutParams(this.width.toInt(),this.heigth.toInt(),0)
}
return this;
}
//primary,secondary,dashed,outlin,text
setType(str:string):xButton{
this.type = str;
this._setBackgroundColor('','up')
return this;
}
//primary,secondary,dashed,outlin,text
setStatus(str:string):xButton{
this.status = str;
this._setBackgroundColor('','up')
return this;
}
setDisabled(dis:boolean) : xButton{
this.bgLayer.setDisabled(dis);
this._setBackgroundColor("#A5A5A5",'down')
return this;
}
setLabel(str:string):xButton{
let label = this.textLayer as xText;
label.setText(str);
return this;
}
setRadius(radius:number):xButton{
let bgView = this.bgLayer as xCardView;
bgView.setRadius(radius);
return this;
}
setClick(fun?:(event: MotionEvent)=>void) : xButton{
if(typeof fun !== 'undefined'){
this.bgLayer.setClick(fun)
}
return this;
}
setIcon(name:string):xButton{
let iconLayer = this.iconLayer as xIcon;
let label = this.textLayer as xText;
iconLayer.setIcon(name);
label.setPadding([10,0,0,0])
return this;
}
setFontSize(size:number):xButton{
let label = this.textLayer as xText;
let iconLayer = this.iconLayer as xIcon;
label.setFontSize(size.toInt())
iconLayer.setFontSize(size.toInt())
return this;
}
setFontColor(str:string):xButton{
let label = this.textLayer as xText;
let iconLayer = this.iconLayer as xIcon;
label.setFontColor(str)
iconLayer.setFontColor(str)
return this;
}
setBorder(w?:number,colorStr?:string,dashed?:boolean):xButton{
this.bgLayer.setBorder(w,colorStr,dashed)
return this;
}
private _setBackgroundColor(str:string,clickStatus:string):xButton{
let cr = this._backgroundColor;
let fontColor = ""
if(str !=''){
cr = str;
}else{
if(this.status==""||this.status=="default"){
cr = 'primary'
}else if(this.status == 'success'){
cr = 'green'
}else if(this.status == 'warn'){
cr = 'orange'
}else if(this.status == 'danger'){
cr = 'red'
}else if(this.status == 'normal'){
cr = '#D8D8D8'
fontColor = '#333333'
}
}
let lightColor = colorGetThint(cr);
let defaultColor = colorGetHover(cr);
if(clickStatus=='down'){
if(this.type == 'primary' || this.type==""){
this.bgLayer.setBackgroundColor(defaultColor.getString("hover")!);
}else if(this.type == 'secondary'){
this.setFontColor(cr)
this.bgLayer.setBackgroundColor(lightColor.getString("hover")!);
}else if(this.type == 'outline'){
this.setFontColor(cr)
this.bgLayer.setBackgroundColor('transparent');
this.setBorder(1,cr,false)
}else if(this.type == 'dashed'){
this.setFontColor(cr)
this.bgLayer.setBackgroundColor(lightColor.getString("hover")!);
this.setBorder(1,cr,true)
}else if(this.type == 'text'){
this.setFontColor(defaultColor.getString("hover")!)
this.bgLayer.setBackgroundColor('transparent');
}
}else if(clickStatus=='up'){
if(this.type == 'primary' || this.type==""){
this.bgLayer.setBackgroundColor(defaultColor.getString("default")!);
}else if(this.type == 'secondary'){
this.setFontColor(cr)
this.bgLayer.setBackgroundColor(lightColor.getString("default")!);
}else if(this.type == 'outline'){
this.setFontColor(cr)
this.bgLayer.setBackgroundColor('transparent');
this.setBorder(1,cr,false)
}else if(this.type == 'dashed'){
this.setFontColor(cr)
this.bgLayer.setBackgroundColor(lightColor.getString("default")!);
this.setBorder(1,cr,true)
}else if(this.type == 'text'){
this.setFontColor(cr)
this.bgLayer.setBackgroundColor('transparent');
}
}
if(fontColor!=''){
this.setFontColor(fontColor)
}
return this;
}
setBackgroundColor(str:string):xButton{
this.bgLayer.setBackgroundColor(str);
this._backgroundColor = str;
return this;
}
getView():View{
return this.view.getView() as View;
}
}
export default xButton;
@@ -0,0 +1,242 @@
import Context from 'android.content.Context'
import LinearLayout from 'android.widget.LinearLayout';
import RelativeLayout from 'android.widget.RelativeLayout';
import ViewGroup from 'android.view.ViewGroup';
import View from 'android.view.View';
import TextView from 'android.widget.TextView';
import ImageView from 'android.widget.ImageView';
import Gravity from 'android.view.Gravity';
import Color from 'android.graphics.Color';
import Activity from 'android.app.Activity';
// import CardView from 'androidx.cardview.widget.CardView';
import { ref, } from "vue"
import TextUtils from 'android.text.TextUtils';
import GradientDrawable from 'android.graphics.drawable.GradientDrawable'
import MotionEvent from 'android.view.MotionEvent';
import {hexToRgb,getDefaultColor} from "../util/xCoreColorUtil.uts"
import {getUid, dp2px} from "../util/xCoreUtil.uts"
import xView from "./view.uts";
class xCardView extends xView {
override view:any;
bgLayer:xView;
contentView:any
wrap:RelativeLayout
contentParams:LinearLayout.LayoutParams
constructor(context : Context){
super(context);
let box = new LinearLayout(context);
box.setOrientation(LinearLayout.VERTICAL)
box.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
(0).toInt(),
(0).toFloat()
))
let wrap = new RelativeLayout(context);
let content = new LinearLayout(context);
let RLay = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
wrap.setLayoutParams(RLay)
this.bgLayer = new xView(context);
content.setBackground(this.bgLayer.bgView);
content.setClipToOutline(true);
this.contentParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
content.setLayoutParams(this.contentParams)
content.setOrientation(LinearLayout.VERTICAL)
this.contentView = content;
this.wrap =wrap;
wrap.addView(this.bgLayer.getView())
wrap.addView(content as View)
box.addView(wrap as View)
this.view = box;
}
override getView():LinearLayout{
return this.view as LinearLayout;
}
override setBackgroundColor(colorStr : string) : xCardView {
this.bgLayer.setBackgroundColor(colorStr)
return this;
}
override setRadius(radius:any) : xCardView{
this.bgLayer.setRadius(radius)
return this;
}
override setBorder(w?:number,colorStr?:string,dashed?:boolean):xCardView{
this.bgLayer.setBorder(w,colorStr,dashed)
return this;
}
override setHeight(height : number) : xCardView {
console.error("不支持,请通过linerView设置,并将本CardView加入其中来设置高度。")
return this;
}
override setPadding(n:any):xCardView{
let view = this.contentView as ViewGroup;
if(Array.isArray(n)){
let rd = n as number[];
if(rd.length==0){
let rds = 0;
let rdf = dp2px(rds).toInt();
view.setPadding(rdf,rdf,rdf,rdf)
}else if(rd.length==1){
let rdf = dp2px(rd[0]).toInt();
view.setPadding(rdf,rdf,rdf,rdf)
}else if(rd.length==2){
view.setPadding(dp2px(rd[0]).toInt(),dp2px(rd[1]).toInt(),dp2px(rd[0]).toInt(),dp2px(rd[1]).toInt())
}else if(rd.length==3){
let rds = 0;
let rdf = rds.toInt();
view.setPadding(dp2px(rd[0]).toInt(),dp2px(rd[1]).toInt(),dp2px(rd[2]).toInt(),rdf)
}else if(rd.length==4){
view.setPadding(dp2px(rd[0]).toInt(),dp2px(rd[1]).toInt(),dp2px(rd[2]).toInt(),dp2px(rd[3]).toInt())
}
}else{
let rd = n as number;
let rdf = dp2px(rd).toInt();
view.setPadding(rdf,rdf,rdf,rdf)
}
return this;
}
override setDisabled(dis:boolean) : xCardView{
this.bgLayer.setDisabled(dis)
return this;
}
override setSwiper(fun?:(event: MotionEvent,detail?:UTSJSONObject)=>void) : xCardView{
if(typeof fun !== 'undefined'){
this.bgLayer.setSwiper(fun)
}
return this;
}
override setDoubleClick(fun?:(event: MotionEvent)=>void) : xCardView{
if(typeof fun !== 'undefined'){
this.bgLayer.setDoubleClick(fun)
}
return this;
}
override setClick(fun?:(event: MotionEvent)=>void) : xCardView{
if(typeof fun !== 'undefined'){
this.bgLayer.setClick(fun)
}
return this;
}
override setTouchStart(fun?:(event: MotionEvent)=>void) : xCardView{
if(typeof fun !== 'undefined'){
this.bgLayer.setTouchStart(fun)
}
return this;
}
override setTouchMove(fun?:(event: MotionEvent)=>void) : xCardView{
if(typeof fun !== 'undefined'){
this.bgLayer.setTouchMove(fun)
}
return this;
}
override setTouchEnd(fun?:(event: MotionEvent)=>void) : xCardView{
if(typeof fun !== 'undefined'){
this.bgLayer.setTouchEnd(fun)
}
return this;
}
override setTouchCancel(fun?:(event: MotionEvent)=>void) : xCardView{
if(typeof fun !== 'undefined'){
this.bgLayer.setTouchCancel(fun)
}
return this;
}
override setTouchLongPress(fun?:(event: MotionEvent)=>void) : xCardView{
if(typeof fun !== 'undefined'){
this.bgLayer.setTouchCancel(fun)
}
return this;
}
setAlign(cr:Int) : xCardView{
let view = this.contentView as LinearLayout;
view.setGravity(cr)
return this;
}
setLayoutParams(width?:number,height?:number,layouWidth?:number):xCardView{
let view = this.contentView as LinearLayout;
let w = (0).toInt();
let h = ViewGroup.LayoutParams.WRAP_CONTENT;
let flex = (1).toFloat();
if(typeof width =='number'){
let tw = width!;
w = tw.toInt();
}
if(typeof height =='number'){
let th = height!;
h = th.toInt();
}
if(typeof layouWidth =='number'&&layouWidth!=-1){
let tf = layouWidth!;
flex = tf.toFloat();
console.log('null',layouWidth)
let layoutParams_crd = new LinearLayout.LayoutParams(
w,
h,
flex
)
this.contentParams = layoutParams_crd
}else{
console.log('null')
let layoutParams_crd = new LinearLayout.LayoutParams(
w,
h
)
this.contentParams = layoutParams_crd
}
// 未知原因设置这个会闪退。
// view.setLayoutParams(layoutParams_crd);
return this;
}
append(children : View,...args: View[]):xCardView{
let view = this.contentView as ViewGroup;
view.addView(children)
args.forEach((el)=>view.addView(el))
return this;
}
appendChild(children : View):xCardView {
let view = this.contentView as ViewGroup;
view.addView(children)
return this;
}
}
export default xCardView;
+68
View File
@@ -0,0 +1,68 @@
import Context from 'android.content.Context'
import LinearLayout from 'android.widget.LinearLayout';
import ViewGroup from 'android.view.ViewGroup';
import View from 'android.view.View';
import TextView from 'android.widget.TextView';
import ImageView from 'android.widget.ImageView';
import Gravity from 'android.view.Gravity';
import Color from 'android.graphics.Color';
import Activity from 'android.app.Activity';
import { ref} from "vue"
import TextUtils from 'android.text.TextUtils';
import GradientDrawable from 'android.graphics.drawable.GradientDrawable'
import MotionEvent from 'android.view.MotionEvent';
import Typeface from 'android.graphics.Typeface';
import {hexToRgb,getDefaultColor,toFillMarginAr} from "../util/xCoreColorUtil.uts"
import {getUid,dp2px} from "../util/xCoreUtil.uts"
class xIcon {
view:any
constructor(context : Context,name:string=""){
let view = new TextView(context);
let layoutParams_crd = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
view.setGravity(Gravity.CENTER)
view.setLayoutParams(layoutParams_crd);
this.view = view;
this._setCodeStr(name)
}
getView():View{
return this.view as View;
}
setIcon(name:string=""):xIcon{
this._setCodeStr(name)
return this;
}
setFontSize(n:number):xIcon{
let view = this.view as TextView;
view.setTextSize(dp2px(n).toFloat())
return this;
}
setFontColor(str:string):xIcon{
let view = this.view as TextView;
view.setTextColor(Color.parseColor(getDefaultColor(str)))
return this;
}
private _setCodeStr(code:string){
let view = this.view as TextView;
let assetManager = view.getContext()!.getAssets();
let typeface = Typeface.createFromAsset(assetManager, "remixicon.ttf")
view.setTypeface(typeface)
if(!TextUtils.isEmpty(code)){
let codePoint = Integer.parseInt(code, 16);
let charArray = Character.toChars(codePoint);
let text = new String(charArray);
view.setText(text);
}
}
}
export default xIcon;
@@ -0,0 +1,130 @@
import Context from 'android.content.Context'
import LinearLayout from 'android.widget.LinearLayout';
import RelativeLayout from 'android.widget.RelativeLayout';
import ViewGroup from 'android.view.ViewGroup';
import View from 'android.view.View';
import TextView from 'android.widget.TextView';
import ImageView from 'android.widget.ImageView';
import Gravity from 'android.view.Gravity';
import Color from 'android.graphics.Color';
import Activity from 'android.app.Activity';
// import CardView from 'androidx.cardview.widget.CardView';
import { ref, } from "vue"
import TextUtils from 'android.text.TextUtils';
import GradientDrawable from 'android.graphics.drawable.GradientDrawable'
import MotionEvent from 'android.view.MotionEvent';
import {hexToRgb,getDefaultColor} from "../util/xCoreColorUtil.uts"
import {getUid, dp2px} from "../util/xCoreUtil.uts"
import xView from "./view.uts";
class xLinearView extends xView {
override view:any;
contentParams:LinearLayout.LayoutParams
constructor(context : Context){
super(context);
let box = new LinearLayout(context);
this.contentParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
)
box.setLayoutParams(this.contentParams)
this.view = box;
}
override getView():LinearLayout{
return this.view as LinearLayout;
}
override setBackgroundColor(colorStr : string) : xLinearView {
console.error("不支持,请通过cardView设置")
return this;
}
override setRadius(radius:any) : xLinearView{
console.error("不支持,请通过cardView设置")
return this;
}
override setBorder(w?:number,colorStr?:string,dashed?:boolean):xLinearView{
console.error("不支持,请通过cardView设置")
return this;
}
override setHeight(height : number) : xLinearView {
console.error("不支持,请通过linerView设置,并将本CardView加入其中来设置高度。")
return this;
}
//让内容的对齐方向,
//https://developer.android.google.cn/reference/kotlin/android/view/Gravity
//只有tmxTextView,有这个属性。
setAlign(cr:Int) : xLinearView{
let view = this.view as LinearLayout;
view.setGravity(cr)
return this;
}
setLayoutParams(width?:number,height?:number,layouWidth?:number) : xLinearView{
let view = this.view as LinearLayout;
let w = (0).toInt();
let h = ViewGroup.LayoutParams.WRAP_CONTENT;
let flex = (1).toFloat();
if(typeof width =='number'){
w = width!.toInt();
}
if(typeof height =='number'){
h = height!.toInt();
}
if(typeof layouWidth =='number'&&layouWidth!=-1){
let tf = layouWidth!;
flex = tf.toFloat();
console.log('null',layouWidth)
let layoutParams_crd = new LinearLayout.LayoutParams(
w,
h,
flex
)
this.contentParams = layoutParams_crd
}else{
console.log('null')
let layoutParams_crd = new LinearLayout.LayoutParams(
w,
h
)
this.contentParams = layoutParams_crd
}
return this;
}
//内容的排版方向:verticalhorizontal
setLayoutDirection(dir:string) : xLinearView{
let view = this.view as LinearLayout;
if(dir=='VERTICAL'){
view.setOrientation(LinearLayout.VERTICAL)
}else if(dir=='HORIZONTAL'){
view.setOrientation(LinearLayout.HORIZONTAL)
}
return this
}
append(children : View,...args: View[]) : xLinearView {
let view = this.view as ViewGroup;
view.addView(children)
args.forEach((el)=>view.addView(el))
return this;
}
appendChild(children : View) : xLinearView {
let view = this.view as ViewGroup;
view.addView(children)
return this;
}
}
export default xLinearView;
+301
View File
@@ -0,0 +1,301 @@
import Context from 'android.content.Context'
import LinearLayout from 'android.widget.LinearLayout';
import ViewGroup from 'android.view.ViewGroup';
import View from 'android.view.View';
import TextView from 'android.widget.TextView';
import ImageView from 'android.widget.ImageView';
import Gravity from 'android.view.Gravity';
import Color from 'android.graphics.Color';
import Activity from 'android.app.Activity';
// import CardView from 'androidx.cardview.widget.CardView';
import { ref, } from "vue"
import TextUtils from 'android.text.TextUtils';
import GradientDrawable from 'android.graphics.drawable.GradientDrawable'
import MotionEvent from 'android.view.MotionEvent';
import Typeface from 'android.graphics.Typeface';
import {hexToRgb,getDefaultColor,toFillMarginAr} from "../util/xCoreColorUtil.uts"
import {getUid,dp2px} from "../util/xCoreUtil.uts"
import xView from "./view.uts";
class xText extends xView {
override view:any
constructor(context : Context,str:string=""){
super(context);
let view = new TextView(context);
let layoutParams_crd = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
(1).toFloat()
)
view.setText(str);
view.setLayoutParams(layoutParams_crd);
this.bgView = new GradientDrawable();
this.bgView.setShape(0x00000000)
this.bgView.setColor(Color.WHITE)
this.bgView.mutate()
view.setBackground(this.bgView)
this.view = view;
}
override getView():View{
return this.view as View;
}
override setBackgroundColor(colorStr : string) : xText {
this.bgView.mutate()
if(colorStr == 'transparent'){
this.bgView.setColor(Color.TRANSPARENT)
}else{
this.bgView.setColor(Color.parseColor(getDefaultColor(colorStr)))
}
return this;
}
override setBorder(w?:number,colorStr?:string,dashed?:boolean) : xText {
this.bgView.mutate()
let tw:number = 1;
let tcolor = 'transparent';
let tdashed = false;
if(typeof tw !== 'undefined'){
tw = w as number;
}
if(typeof tw !== 'undefined'){
tcolor = colorStr as string;
}
if(typeof dashed !== 'undefined'){
tdashed = dashed as boolean;
}
let colorNum = Color.TRANSPARENT;
if(tcolor != 'transparent'){
colorNum = Color.parseColor(getDefaultColor(tcolor));
}
if(dashed == true){
let dashedWidth = dp2px(6)
let dashedGap = dp2px(4)
this.bgView.setStroke(dp2px(tw).toInt(),colorNum,dashedWidth.toFloat(),dashedGap.toFloat())
}else{
this.bgView.setStroke(dp2px(tw).toInt(),colorNum)
}
return this;
}
override setRadius(radius:any) : xText{
let x =0
let y =0
this.bgView.mutate()
if(Array.isArray(radius)){
let rd = radius as number[];
if(rd.length==0){
let rdfs = 0;
this.bgView.setCornerRadius(dp2px(rdfs).toFloat());
// view.setBackground(this.bgView)
}else if(rd.length==1){
let rdfs = rd[0];
this.bgView.setCornerRadius(dp2px(rdfs).toFloat());
// view.setBackground(this.bgView)
}else if(rd.length==2){
let tl = [
dp2px(rd[0]).toFloat(),dp2px(rd[0]).toFloat(),
dp2px(rd[1]).toFloat(),dp2px(rd[1]).toFloat(),
x.toFloat(),x.toFloat(),
x.toFloat(),x.toFloat()
]
let tlint = tl.toKotlinList().toFloatArray()
this.bgView.setCornerRadii(tlint);
}else if(rd.length==3){
let tl = [
dp2px(rd[0]).toFloat(),dp2px(rd[0]).toFloat(),
dp2px(rd[1]).toFloat(),dp2px(rd[1]).toFloat(),
dp2px(rd[2]).toFloat(),dp2px(rd[2]).toFloat(),
x.toFloat(),x.toFloat()
]
let tlint = tl.toKotlinList().toFloatArray()
this.bgView.setCornerRadii(tlint);
}else if(rd.length==4){
let tl = [
dp2px(rd[0]).toFloat(),dp2px(rd[0]).toFloat(),
dp2px(rd[1]).toFloat(),dp2px(rd[1]).toFloat(),
dp2px(rd[2]).toFloat(),dp2px(rd[2]).toFloat(),
dp2px(rd[3]).toFloat(),dp2px(rd[3]).toFloat(),
]
let tlint = tl.toKotlinList().toFloatArray()
this.bgView.setCornerRadii(tlint);
}
}else{
let rd = radius as number;
this.bgView.setCornerRadius(dp2px(rd).toFloat());
}
return this;
}
setFontSize(n:number):xText{
let view = this.view as TextView;
view.setTextSize(dp2px(n).toFloat())
return this;
}
setFontColor(str:string):xText{
let view = this.view as TextView;
view.setTextColor(Color.parseColor(getDefaultColor(str)))
return this;
}
//是否允许复制。
setTextIsSelectable(isSelectet:boolean):xText{
let view = this.view as TextView;
view.setTextIsSelectable(isSelectet)
return this;
}
//bold,normal,ligth
setFontWeight(str:string):xText{
let view = this.view as TextView;
if(str=='bold'){
view.setTypeface(null,Typeface.BOLD)
}else{
view.setTypeface(null,Typeface.NORMAL)
}
return this;
}
setFontStyle(str:string):xText{
let view = this.view as TextView;
if(str=='italtc'){
view.setTypeface(null,Typeface.ITALIC)
}else if(str=='italtc-bold'){
view.setTypeface(null,Typeface.BOLD_ITALIC)
}
return this;
}
setText(str:string):xText{
let view = this.view as TextView;
view.setText(str)
return this;
}
override setPadding(n:any):xText{
let view = this.view as TextView;
if(Array.isArray(n)){
let rd = n as number[];
if(rd.length==0){
let rds = 0;
let rdf = dp2px(rds).toInt();
view.setPadding(rdf,rdf,rdf,rdf)
}else if(rd.length==1){
let rdf = dp2px(rd[0]).toInt();
view.setPadding(rdf,rdf,rdf,rdf)
}else if(rd.length==2){
view.setPadding(dp2px(rd[0]).toInt(),dp2px(rd[1]).toInt(),dp2px(rd[0]).toInt(),dp2px(rd[1]).toInt())
}else if(rd.length==3){
let rds = 0;
let rdf = rds.toInt();
view.setPadding(dp2px(rd[0]).toInt(),dp2px(rd[1]).toInt(),dp2px(rd[2]).toInt(),rdf)
}else if(rd.length==4){
view.setPadding(dp2px(rd[0]).toInt(),dp2px(rd[1]).toInt(),dp2px(rd[2]).toInt(),dp2px(rd[3]).toInt())
}
}else{
let rd = n as number;
let rdf = dp2px(rd).toInt();
view.setPadding(rdf,rdf,rdf,rdf)
}
return this;
}
//让内容的对齐方向,
//https://developer.android.google.cn/reference/kotlin/android/view/Gravity
//只有xTextView,有这个属性。
setAlign(cr:Int) : xText{
let view = this.view as TextView;
view.setGravity(cr)
return this;
}
//追加文本
//start,end不填写就追加到末尾。
setIcon(code:string,start:number=0,end:number=0) : xText{
let view = this.view as TextView;
let nowText = view.getText().toString();
let assetManager = view.getContext()!.getAssets();
let typeface = Typeface.createFromAsset(assetManager, "remixicon.ttf")
view.setTypeface(typeface)
if(!TextUtils.isEmpty(code)){
let codePoint = Integer.parseInt(code, 16);
let charArray = Character.toChars(codePoint);
let text = new String(charArray);
view.setText(text+" "+nowText);
}
return this;
}
setLayoutParams(width?:number,height?:number,layouWidth?:number) : xText{
let view = this.view as TextView;
let w = (0).toInt();
let h = ViewGroup.LayoutParams.WRAP_CONTENT;
let flex = (1).toFloat();
if(typeof width =='number'){
w = width!.toInt();
}
if(typeof height =='number'){
h = height!.toInt();
}
if(typeof layouWidth =='number'){
flex = layouWidth!.toFloat();
}
let layoutParams_crd = new LinearLayout.LayoutParams(
w,
h,
flex
)
view.setLayoutParams(layoutParams_crd);
return this;
}
setLineHeight(line:number) : xText{
let view = this.view as TextView;
view.setLineHeight(line.toInt())
return this;
}
setLetterSpacing(space:number) : xText{
let view = this.view as TextView;
view.setLineHeight(space.toInt())
return this;
}
setHighlightColor(color:string) : xText{
let view = this.view as TextView;
if(!TextUtils.isEmpty(color)){
view.setHighlightColor(Color.parseColor(getDefaultColor(color)))
}
return this;
}
// 设置文字的省略情况,0表示不显示省略号,数字表示几行显示省略号。
setEllipsis(lines:number=0) : xText{
let view = this.view as TextView;
if(lines>0){
view.setMaxLines(lines.toInt())
view.setEllipsize(TextUtils.TruncateAt.END)
}else{
view.setMaxLines((1).toInt())
view.setEllipsize(null)
}
return this;
}
}
export default xText;
+486
View File
@@ -0,0 +1,486 @@
import Context from 'android.content.Context'
import LinearLayout from 'android.widget.LinearLayout';
import ViewGroup from 'android.view.ViewGroup';
import View from 'android.view.View';
import TextView from 'android.widget.TextView';
import ImageView from 'android.widget.ImageView';
import Gravity from 'android.view.Gravity';
import Color from 'android.graphics.Color';
import Activity from 'android.app.Activity';
// import CardView from 'androidx.cardview.widget.CardView';
import { ref, } from "vue"
import TextUtils from 'android.text.TextUtils';
import GradientDrawable from 'android.graphics.drawable.GradientDrawable'
import MotionEvent from 'android.view.MotionEvent';
import ColorStateList from 'android.content.res.ColorStateList';
import attr from 'android.R.attr'
import {hexToRgb,getDefaultColor} from "../util/xCoreColorUtil.uts"
/**
* 数字转16进制
*/
function toHex(numbers : number) : string {
let i = 0 as number
if (numbers === i) {
return '00';
}
let hex = '';
const hexChars = '0123456789abcdef';
while (numbers > 0) {
const remainder = numbers % 16;
hex = hexChars[remainder] + hex;
numbers = Math.floor(numbers / 16);
}
return hex;
}
/**
* 随机一个uid
* @param rdix 随机因子
* @param length 取的长度
* @param isAddStr 是否限制随机结果中的长度,不允许输出长度
* @returns String
*/
function getUid(rdix = 1, length = 12) : string {
let ix = "";
// #ifndef APP
ix = Math.floor(Math.random() * rdix * Math.floor(Math.random() * Date.now())).toString().substring(0, length);
// #endif
// #ifdef APP
ix = Math.floor(Math.random() * rdix * Math.floor(Math.random() * Date.now())).toString().substring(0, length as Int);
// #endif
return ix;
}
class MyClickListener implements View.OnClickListener {
callbackFun:()=>void;
constructor(cal?:()=>void){
this.callbackFun = cal as ()=>void;
}
override onClick(v?:View):void {
if(typeof this.callbackFun !='underfinde'){
this.callbackFun();
}
}
}
class MyTouchListener implements View.OnTouchListener {
//down,up,move,cancel,longClick
callbackFun:(types:string,event : MotionEvent,detail:UTSJSONObject)=>void;
dubleTime = 0;
tid = 56;
_x = 0;
_y = 0;
// 判断方向的差值
swipe_mindiff = 40
// 滑动时,一定时间内只能触发一次事件。不能连续触发。
tid_siper = 100;
swipeDirection = ""
constructor(call:(types:string,event : MotionEvent,detail?:UTSJSONObject)=>void) {
this.callbackFun = call;
}
override onTouch(view : View, event : MotionEvent) : Boolean {
if(event.action == MotionEvent.ACTION_DOWN ){
this._x = event.getX();
this._y = event.getY();
this.swipeDirection = ""
this.callbackFun('down',event,{});
let difftime = new Date().getTime() - this.dubleTime;
if(difftime >0 && difftime<=300){
this.callbackFun('doubleClick',event ,{});
}
this.dubleTime = new Date().getTime();
clearTimeout(this.tid)
tid = setTimeout(function() {
this.callbackFun('longPress',event,{});
}, 800);
}
if(event.action == MotionEvent.ACTION_UP ){
clearTimeout(this.tid)
this.callbackFun('up',event,{});
if(new Date().getTime() - this.dubleTime > 50){
this.callbackFun('click',event,{});
}
}
if(event.action == MotionEvent.ACTION_CANCEL || event.action== MotionEvent.ACTION_OUTSIDE ){
this.callbackFun('cancel',event,{});
clearTimeout(this.tid)
}
if(event.action == MotionEvent.ACTION_MOVE ){
let x = event.getX();
let y = event.getY();
let deltaX = Math.abs(x - this._x);
let deltaY = Math.abs(y - this._y);
if(deltaX > deltaY && deltaX > this.swipe_mindiff){
this.swipeDirection = (this._x > x) ? "left" : "right";
}else if(deltaY > deltaX && deltaY > this.swipe_mindiff){
this.swipeDirection = (this._y < y) ? "down" : "up";
}
if(this.swipeDirection !=""){
this.callbackFun('swiper',event,{x,y,diffX:deltaX,diffY:deltaY,direction:this.swipeDirection});
}
// this._x = x;
// this._y = y;
this.callbackFun('move',event,{});
clearTimeout(this.tid)
}
return true;
}
}
class xView {
public view : any;
public tagId:string = 'x_view_id_'+getUid();
public bgView:GradientDrawable
private _onclickFun= (_event : MotionEvent):void=>{};
private _onTouchStart= (_event : MotionEvent):void=>{};
private _onTouchEnd= (_event : MotionEvent):void=>{};
private _onTouchCancel= (_event : MotionEvent):void=>{};
private _onTouchMove= (_event : MotionEvent):void=>{};
private _onTouchLongPress= (_event : MotionEvent):void=>{};
private _onTouchDubleClick= (_event : MotionEvent):void=>{};
private _onTouchSwiper= (_event : MotionEvent,detail?:UTSJSONObject):void=>{};
// 设置禁用,不会触发上面的事件。
private _disabled = false;
constructor(context : Context) {
let view = new View(context);
view.setTag(this.tagId)
let layoutParams_crd = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
view.setLayoutParams(layoutParams_crd);
this.bgView = new GradientDrawable();
// let statuesInts= [[attr.state_enabled].toKotlinList().toIntArray(),[attr.state_pressed].toKotlinList().toIntArray(),[-attr.state_enabled].toKotlinList().toIntArray()]
// let statuesColors= [Color.WHITE,Color.RED,Color.RED]
// let states = new ColorStateList(statuesInts.toKotlinList().toTypedArray(),statuesColors.toKotlinList().toIntArray())
this.bgView.setShape(GradientDrawable.RECTANGLE)
this.bgView.setColor(Color.WHITE)
this.bgView.mutate()
view.setBackground(this.bgView)
this.view = view;
// view.setOnClickListener(new MyClickListener(():void=>{
// this._onclickFun()
// }));
view.setOnTouchListener(new MyTouchListener((types:string,event : MotionEvent,detail?:UTSJSONObject):void=>{
if(this._disabled == false){
if(types=='down'){
this._onTouchStart(event)
}
if(types=='up'){
this._onTouchEnd(event);
}
if(types=='click'){
this._onclickFun(event);
}
if(types=='move'){
this._onTouchMove(event)
}
if(types=='cancel'){
this._onTouchCancel(event)
}
if(types=='longPress'){
this._onTouchLongPress(event)
}
if(types=='doubleClick'){
this._onTouchDubleClick(event)
}
if(types=='swiper'){
this._onTouchSwiper(event,detail)
}
}
}));
}
getView():View{
return this.view as View;
}
setDisabled(dis:boolean) : xView{
this._disabled = dis;
return this;
}
/**
* 触发距离是大于50时触发并判断方向
* x,y当前坐标,diffX滑动时距离开始时按下的横向x距离,diffY表示竖向。Direction为方向:left,right,up,dowon
*detail:
*{x,y,diffX,diffY,direction}
*/
setSwiper(fun?:(event: MotionEvent,detail?:UTSJSONObject)=>void) : xView{
if(typeof fun !== 'undefined'){
this._onTouchSwiper = fun;
}
return this;
}
setDoubleClick(fun?:(event: MotionEvent)=>void) : xView{
if(typeof fun !== 'undefined'){
this._onTouchDubleClick = fun;
}
return this;
}
setClick(fun?:(event: MotionEvent)=>void) : xView{
if(typeof fun !== 'undefined'){
this._onclickFun = fun;
}
return this;
}
setTouchStart(fun?:(event: MotionEvent)=>void) : xView{
if(typeof fun !== 'undefined'){
this._onTouchStart = fun;
}
return this;
}
setTouchMove(fun?:(event: MotionEvent)=>void) : xView{
if(typeof fun !== 'undefined'){
this._onTouchMove = fun;
}
return this;
}
setTouchEnd(fun?:(event: MotionEvent)=>void) : xView{
if(typeof fun !== 'undefined'){
this._onTouchEnd = fun;
}
return this;
}
setTouchCancel(fun?:(event: MotionEvent)=>void) : xView{
if(typeof fun !== 'undefined'){
this._onTouchCancel = fun;
}
return this;
}
setTouchLongPress(fun?:(event: MotionEvent)=>void) : xView{
if(typeof fun !== 'undefined'){
this._onTouchLongPress = fun;
}
return this;
}
setBackgroundColor(colorStr : string) : xView {
this.bgView.mutate()
if(colorStr == 'transparent'){
this.bgView.setColor(Color.TRANSPARENT)
}else{
this.bgView.setColor(Color.parseColor(getDefaultColor(colorStr)))
}
return this;
}
setBorder(w?:number,colorStr?:string,dashed?:boolean) : xView {
this.bgView.mutate()
let tw:number = 1;
let tcolor = 'transparent';
let tdashed = false;
if(typeof tw !== 'undefined'){
tw = w as number;
}
if(typeof tw !== 'undefined'){
tcolor = colorStr as string;
}
if(typeof dashed !== 'undefined'){
tdashed = dashed as boolean;
}
let colorNum = Color.TRANSPARENT;
if(tcolor != 'transparent'){
colorNum = Color.parseColor(getDefaultColor(tcolor));
}
if(dashed == true){
let dashedWidth = 8
let dashedGap = 5
this.bgView.setStroke(tw.toInt(),colorNum,dashedWidth.toFloat(),dashedGap.toFloat())
}else{
this.bgView.setStroke(tw.toInt(),colorNum)
}
return this;
}
setMargin(n:any):xView{
let view = this.view as View;
let selfPrams = view.getLayoutParams()
let params = new LinearLayout.LayoutParams(
selfPrams.width,
selfPrams.height
)
if(Array.isArray(n)){
let rd = n as number[];
if(rd.length==0){
let rds = 0;
let rdf = (rds).toInt();
params.setMargins(rdf,rdf,rdf,rdf)
}else if(rd.length==1){
let rdf = (rd[0]).toInt();
params.setMargins(rdf,rdf,rdf,rdf)
}else if(rd.length==2){
let rds = 0;
params.setMargins((rd[0]).toInt(),(rd[1]).toInt(),(rd[0]).toInt(),(rd[1]).toInt())
}else if(rd.length==3){
let rds = 0;
let rdf = rds.toInt();
params.setMargins((rd[0]).toInt(),(rd[1]).toInt(),(rd[2]).toInt(),rdf)
}else if(rd.length==4){
params.setMargins((rd[0]).toInt(),(rd[1]).toInt(),(rd[2]).toInt(),(rd[3]).toInt())
}
}else{
let rd = n as number;
let rdf = (rd).toInt();
params.setMargins(rdf,rdf,rdf,rdf)
}
view.setLayoutParams(params);
return this;
}
setPadding(n:any):xView{
let view = this.view as View;
if(Array.isArray(n)){
let rd = n as number[];
if(rd.length==0){
let rds = 0;
let rdf = (rds).toInt();
view.setPadding(rdf,rdf,rdf,rdf)
}else if(rd.length==1){
let rdf = (rd[0]).toInt();
view.setPadding(rdf,rdf,rdf,rdf)
}else if(rd.length==2){
view.setPadding((rd[0]).toInt(),(rd[1]).toInt(),(rd[0]).toInt(),(rd[1]).toInt())
}else if(rd.length==3){
let rds = 0;
let rdf = rds.toInt();
view.setPadding((rd[0]).toInt(),(rd[1]).toInt(),(rd[2]).toInt(),rdf)
}else if(rd.length==4){
view.setPadding((rd[0]).toInt(),(rd[1]).toInt(),(rd[2]).toInt(),(rd[3]).toInt())
}
}else{
let rd = n as number;
let rdf = (rd).toInt();
view.setPadding(rdf,rdf,rdf,rdf)
}
return this;
}
setRadius(radius:any) : xView{
let x =0
let y =0
this.bgView.mutate()
if(Array.isArray(radius)){
let rd = radius as number[];
if(rd.length==0){
let rdfs = 0;
this.bgView.setCornerRadius((rdfs).toFloat());
// view.setBackground(this.bgView)
}else if(rd.length==1){
let rdfs = rd[0];
this.bgView.setCornerRadius((rdfs).toFloat());
// view.setBackground(this.bgView)
}else if(rd.length==2){
let tl = [
(rd[0]).toFloat(),(rd[0]).toFloat(),
(rd[1]).toFloat(),(rd[1]).toFloat(),
x.toFloat(),x.toFloat(),
x.toFloat(),x.toFloat()
]
let tlint = tl.toKotlinList().toFloatArray()
this.bgView.setCornerRadii(tlint);
}else if(rd.length==3){
let tl = [
(rd[0]).toFloat(),(rd[0]).toFloat(),
(rd[1]).toFloat(),(rd[1]).toFloat(),
(rd[2]).toFloat(),(rd[2]).toFloat(),
x.toFloat(),x.toFloat()
]
let tlint = tl.toKotlinList().toFloatArray()
this.bgView.setCornerRadii(tlint);
}else if(rd.length==4){
let tl = [
(rd[0]).toFloat(),(rd[0]).toFloat(),
(rd[1]).toFloat(),(rd[1]).toFloat(),
(rd[2]).toFloat(),(rd[2]).toFloat(),
(rd[3]).toFloat(),(rd[3]).toFloat(),
]
let tlint = tl.toKotlinList().toFloatArray()
this.bgView.setCornerRadii(tlint);
}
}else{
let rd = radius as number;
this.bgView.setCornerRadius((rd).toFloat());
}
return this;
}
/** 设置当前宽和高为父级的相对宽和高
*w,h有效值为:auto|100%
*/
setSizeBy(w:string="100%",h:string = "auto"){
let view = this.view as View;
let ww = ViewGroup.LayoutParams.MATCH_PARENT;
let hh = ViewGroup.LayoutParams.MATCH_PARENT;
if(w=="auto"){
ww = ViewGroup.LayoutParams.WRAP_CONTENT
}
if(h=="auto"){
hh = ViewGroup.LayoutParams.WRAP_CONTENT
}
let layoutParams_crd = new LinearLayout.LayoutParams(ww,hh)
view.setLayoutParams(layoutParams_crd);
}
setSize(width : number, height : number) : xView {
let view = this.view as View;
let layoutParams_crd = new LinearLayout.LayoutParams(
(width).toInt(),
(height).toInt()
)
view.setLayoutParams(layoutParams_crd);
return this;
}
setWidth(width : number) : xView {
let view = this.view as View;
let lpar = view.getLayoutParams();
let layoutParams_crd = new LinearLayout.LayoutParams(
(width).toInt(),
(lpar.height).toInt(),
)
view.setLayoutParams(layoutParams_crd);
return this;
}
setHeight(height : number) : xView {
let view = this.view as View;
let lpar = view.getLayoutParams();
let layoutParams_crd = new LinearLayout.LayoutParams(
(lpar.width).toInt(),
(height).toInt(),
)
view.setLayoutParams(layoutParams_crd);
return this;
}
}
export default xView;
+17
View File
@@ -0,0 +1,17 @@
import Dialog from "android.app.Dialog"
import Context from 'android.content.Context'
import { UTSAndroid } from "io.dcloud.uts";
import FrameLayout from "android.widget.FrameLayout";
class xOverflay {
static show(){
let d = new Dialog(UTSAndroid.getUniActivity() as Context);
let decorView = UTSAndroid.getUniActivity()!.window.decorView;
let frameContent = decorView.findViewById<FrameLayout>(android.R.id.content) as FrameLayout
// test
d.show();
}
}
export default xOverflay;