1
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 9.5 KiB |
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"minSdkVersion": "21",
|
||||
"dependencies":[
|
||||
"com.facebook.fresco:drawee:3.1.3"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
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 { XRUN_START_LOGO_OPTS, RGBA } from "../interface.uts"
|
||||
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 FrameLayout from 'android.widget.FrameLayout';
|
||||
|
||||
import Fresco from 'com.facebook.fresco.Fresco';
|
||||
// import DraweeController from 'com.facebook.drawee.interfaces.DraweeController';
|
||||
import SimpleDraweeView from 'com.facebook.drawee.view.SimpleDraweeView';
|
||||
import File from 'java.io.File';
|
||||
import WindowManager from 'android.view.WindowManager';
|
||||
import WindowManagerWrapper from 'com.dcloud.android.widget.toast.SafeToastContext.WindowManagerWrapper';
|
||||
import Build from 'android.os.Build';
|
||||
import BitmapFactory from "android.graphics.BitmapFactory";
|
||||
import Bitmap from 'android.graphics.Bitmap';
|
||||
import ImageView from 'android.widget.ImageView';
|
||||
// import ImageRequest from 'com.facebook.imagepipeline.request.ImageRequest';
|
||||
// import ImageRequestBuilder from 'com.facebook.imagepipeline.request.ImageRequestBuilder';
|
||||
|
||||
|
||||
let maskerDom : null | RelativeLayout = null;
|
||||
let maskDomId = 686
|
||||
let tid = 0
|
||||
let isClsoing = false
|
||||
function px2dp(n : number) : number {
|
||||
const mets = UTSAndroid.getAppContext()!.resources!.getDisplayMetrics()
|
||||
return mets.density * n
|
||||
}
|
||||
|
||||
export function hideRunLogo() {
|
||||
let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
|
||||
let mk = decorView.findViewById<View>((maskDomId).toInt())
|
||||
if (mk != null) {
|
||||
decorView.removeView(mk)
|
||||
}
|
||||
}
|
||||
function rgbToColorNumber(rgba : RGBA) : Int {
|
||||
return Color.argb((rgba.a * 255).toInt(), rgba!.r.toInt(), rgba!.g.toInt(), rgba!.b.toInt())
|
||||
}
|
||||
|
||||
export function showRunLogo(opts : XRUN_START_LOGO_OPTS) {
|
||||
|
||||
const context = UTSAndroid.getAppContext()! as Context
|
||||
|
||||
let win = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager;
|
||||
|
||||
|
||||
|
||||
|
||||
let decorView = UTSAndroid.getUniActivity()!.window.decorView as ViewGroup
|
||||
let config : XRUN_START_LOGO_OPTS = opts!
|
||||
|
||||
try {
|
||||
let mk = decorView.findViewById<View | null>((maskDomId).toInt())
|
||||
if (mk != null) {
|
||||
decorView.removeView(mk!)
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
//TODO handle the exception
|
||||
}
|
||||
if (isClsoing) return;
|
||||
let bgColor = rgbToColorNumber(hexToRgb(config.bgColor)!);
|
||||
let logoBgcolor = rgbToColorNumber(hexToRgb(config.logoBgColor)!);
|
||||
let fontColor = rgbToColorNumber(hexToRgb(config.fontColor)!);
|
||||
|
||||
let maskerDom = new RelativeLayout(context)
|
||||
let maskerDomLayrPrams = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
|
||||
maskerDom.setLayoutParams(maskerDomLayrPrams)
|
||||
maskerDom.setBackgroundColor(bgColor)
|
||||
maskerDom.setId((maskDomId).toInt())
|
||||
|
||||
//创建一个容器用来在底部显示.
|
||||
|
||||
let container = new LinearLayout(context);
|
||||
container.setOrientation(LinearLayout.VERTICAL)
|
||||
container.setGravity(Gravity.CENTER)
|
||||
let containerLayrPrams = new RelativeLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
containerLayrPrams.addRule(RelativeLayout.CENTER_HORIZONTAL)
|
||||
containerLayrPrams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
|
||||
let containerPadding = px2dp(80).toInt();
|
||||
container.setPadding(0, 0, 0, containerPadding)
|
||||
container.setLayoutParams(containerLayrPrams)
|
||||
|
||||
// 创建一个logo容器
|
||||
let logoBox = new LinearLayout(context)
|
||||
logoBox.setBottom(px2dp(16).toInt())
|
||||
let wpxlogoBox_w = px2dp(config.width + config.logoPadding).toInt();
|
||||
let wpxlogoBox_h = px2dp(config.height + config.logoPadding).toInt();
|
||||
logoBox.setGravity(Gravity.CENTER)
|
||||
|
||||
// 设置圆角背景
|
||||
let bg = new GradientDrawable()
|
||||
bg.setColor(logoBgcolor)
|
||||
bg.setCornerRadius((px2dp(config.round)).toFloat())
|
||||
logoBox.setClipToOutline(true)
|
||||
logoBox.setBackground(bg)
|
||||
logoBox.setLayoutParams(new LinearLayout.LayoutParams(wpxlogoBox_w, wpxlogoBox_h))
|
||||
|
||||
function loadImageFromAssets(fname : string) : Bitmap|null{
|
||||
let bitmap : Bitmap | null = null
|
||||
try {
|
||||
let assetManager = UTSAndroid.getAppContext()!.getAssets()
|
||||
let inputStream = assetManager.open(fname)
|
||||
bitmap = BitmapFactory.decodeStream(inputStream)
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
return bitmap
|
||||
}
|
||||
|
||||
// 创建图片显示logo;
|
||||
let img = new ImageView(context)
|
||||
img.setImageBitmap(loadImageFromAssets(config.logo))
|
||||
img.setLayoutParams(new FrameLayout.LayoutParams(px2dp(config.width).toInt(), px2dp(config.height).toInt()))
|
||||
logoBox.addView(img)
|
||||
|
||||
//底部的版权.
|
||||
let titleDiv = new TextView(context)
|
||||
// let titleDivheight = px2dp(titleHeight).toInt();
|
||||
titleDiv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
titleDiv.setGravity(Gravity.CENTER)
|
||||
titleDiv.setTextSize((config.fontSize).toFloat())
|
||||
titleDiv.setTextColor(fontColor)
|
||||
titleDiv.setText(config.rightText)
|
||||
let titleDivPadding = px2dp(8).toInt();
|
||||
titleDiv.setPadding(0, titleDivPadding, 0, 0)
|
||||
|
||||
container.addView(logoBox)
|
||||
container.addView(titleDiv)
|
||||
maskerDom.addView(container)
|
||||
decorView.addView(maskerDom!)
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.5 KiB |
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"x_runstart_logo": "./lib/x_runstart_logo.har"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { XRUN_START_LOGO_OPTS} from "../interface.uts"
|
||||
import { x_showRunLogo,x_hideRunLogo } from "x_runstart_logo";
|
||||
|
||||
export function hideRunLogo() {
|
||||
x_hideRunLogo(UTSHarmony.getCurrentWindow()!.getUIContext())
|
||||
}
|
||||
|
||||
export function showRunLogo(opts : XRUN_START_LOGO_OPTS) {
|
||||
x_showRunLogo(UTSHarmony.getCurrentWindow()!.getUIContext(),opts)
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.5 KiB |
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "12"
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { XRUN_START_LOGO_OPTS, RGBA } from "../interface.uts"
|
||||
import { UIView, UIViewController, NSLayoutConstraint, UIScrollView, NSLineBreakMode,UIWindow, UIFont, UILabel, UITapGestureRecognizer, UIImageView, UIImage } from 'UIKit';
|
||||
import { CGRect, CGPoint, CGFloat } from 'CoreFoundation';
|
||||
import { Alignment } from 'SwiftUI';
|
||||
import { UInt32, KeyPath } from 'Swift';
|
||||
import { NSString, URL, URLSession } from 'Foundation';
|
||||
import { CABasicAnimation, CAAnimationDelegate, CAAnimation } from 'QuartzCore';
|
||||
import { Selector } from "ObjectiveC";
|
||||
|
||||
let maskerDom : null | UIView = null;
|
||||
let tid = 0
|
||||
|
||||
export function hideRunLogo() {
|
||||
if (maskerDom != null) {
|
||||
maskerDom!.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
export function showRunLogo(opts : XRUN_START_LOGO_OPTS) {
|
||||
let nowwindow = UTSiOS.getKeyWindow() as UIWindow
|
||||
let rootUIview = nowwindow.rootViewController as UIViewController|null
|
||||
|
||||
if (maskerDom != null) {
|
||||
clearTimeout(tid)
|
||||
maskerDom!.removeFromSuperview()
|
||||
}
|
||||
let parent = UTSiOS.getCurrentViewController() as UIViewController;
|
||||
if(rootUIview!=null){
|
||||
parent = rootUIview!;
|
||||
}
|
||||
let parentView = parent.view as UIView
|
||||
|
||||
let config : XRUN_START_LOGO_OPTS = opts
|
||||
|
||||
maskerDom = new UIView()
|
||||
|
||||
if (maskerDom == null) return;
|
||||
let cg = parentView.frame as CGRect
|
||||
maskerDom!.frame = cg
|
||||
maskerDom!.backgroundColor = UTSiOS.colorWithString(config.bgColor)
|
||||
|
||||
// 添加标题
|
||||
let titleDiv = new UILabel();
|
||||
titleDiv.textColor = UTSiOS.colorWithString(config.fontColor)
|
||||
titleDiv.text = new String(config.rightText)
|
||||
titleDiv.font = UIFont.systemFont(ofSize = new CGFloat(config.fontSize))
|
||||
titleDiv.textAlignment = NSTextAlignment.center
|
||||
maskerDom!.addSubview(titleDiv)
|
||||
titleDiv.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
// 顶部约束
|
||||
// titleDiv.topAnchor.constraint(equalTo = content.topAnchor, constant = 0),
|
||||
titleDiv.bottomAnchor.constraint(equalTo = maskerDom!.bottomAnchor, constant = -80),
|
||||
// contextText.widthAnchor.constraint(equalToConstant = new CGFloat((width!-32))),
|
||||
// 左侧约束
|
||||
titleDiv.leadingAnchor.constraint(equalTo = maskerDom!.leadingAnchor, constant = 16),
|
||||
// 右侧约束
|
||||
titleDiv.trailingAnchor.constraint(equalTo = maskerDom!.safeAreaLayoutGuide.trailingAnchor, constant = -16)
|
||||
])
|
||||
|
||||
// 内容外框。
|
||||
let container = new UIView();
|
||||
container.layer.cornerRadius = new CGFloat(config.round)
|
||||
container.layer.masksToBounds = true;
|
||||
container.backgroundColor = UTSiOS.colorWithString(config.logoBgColor)
|
||||
container.translatesAutoresizingMaskIntoConstraints = false
|
||||
// container.frame = new CGRect(x = 0, y = 0, width = (config.width+config.logoPadding).toInt(), height = (config.height+config.round).toInt())
|
||||
maskerDom!.addSubview(container)
|
||||
NSLayoutConstraint.activate([
|
||||
container.bottomAnchor.constraint(equalTo = titleDiv.topAnchor, constant = -12),
|
||||
container.centerXAnchor.constraint(equalTo = maskerDom!.centerXAnchor),
|
||||
container.widthAnchor.constraint(equalToConstant = new CGFloat(config.width + config.logoPadding)),
|
||||
container.heightAnchor.constraint(equalToConstant = new CGFloat(config.height + config.logoPadding))
|
||||
])
|
||||
|
||||
// 图片.
|
||||
let img = new UIImageView()
|
||||
|
||||
let imgTop = (config.logoPadding/2).toInt()
|
||||
img.frame = new CGRect(x = imgTop, y = imgTop, width = (config.width).toInt(), height = (config.height).toInt())
|
||||
img.image = new UIImage(named = config.logo)
|
||||
|
||||
container.addSubview(img)
|
||||
parentView.addSubview(maskerDom!)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
export type RGBA = { r : number, g : number, b : number, a : number }
|
||||
export type XRUN_START_LOGO_OPTS = {
|
||||
/** 启动界面背景色,不能使用颜色名称 */
|
||||
bgColor:string,
|
||||
/** logo图片名称 */
|
||||
logo:string,
|
||||
/** logo宽 */
|
||||
width:number,
|
||||
/** logo高 */
|
||||
height:number,
|
||||
/** logo容器圆角 */
|
||||
round:number,
|
||||
/** logo容器背景,不能使用颜色名称 */
|
||||
logoBgColor:string,
|
||||
/** logo下方文字 */
|
||||
rightText:string,
|
||||
/** 文字字号 */
|
||||
fontSize:number,
|
||||
/** 文字颜色,不能使用颜色名称 */
|
||||
fontColor:string,
|
||||
/** logo容器的padding */
|
||||
logoPadding:number
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { RGBA } from "../interface";
|
||||
export function hexToRgb(sColors : string) : RGBA | null {
|
||||
if (sColors == "") {
|
||||
return null
|
||||
}
|
||||
let reg = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/;
|
||||
let sColor : string = sColors.toLowerCase();
|
||||
|
||||
if (sColor != '' && reg.test(sColor)) {
|
||||
if (sColor.length == 4) {
|
||||
let sColorNew = "#";
|
||||
for (let i = 1; i < 4; i += 1) {
|
||||
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
|
||||
}
|
||||
sColor = sColorNew;
|
||||
}
|
||||
|
||||
//处理六位的颜色值
|
||||
let sColorChange : number[] = [];
|
||||
sColorChange.push(parseInt(sColor.substring(1, 3), 16));
|
||||
sColorChange.push(parseInt(sColor.substring(3, 5), 16));
|
||||
sColorChange.push(parseInt(sColor.substring(5, 7), 16));
|
||||
if (sColor.length == 9) {
|
||||
sColorChange.push(parseInt(sColor.substring(7, 9), 16) / 255);
|
||||
}
|
||||
return {
|
||||
r: sColorChange[0],
|
||||
g: sColorChange[1],
|
||||
b: sColorChange[2],
|
||||
a: sColorChange.length == 4 ? sColorChange[3] : 1
|
||||
} as RGBA
|
||||
} else if (/^(rgb|RGB|rgba|RGBA)/.test(sColor)) {
|
||||
let arr : string[] = sColor.replace(/(?:\(|\)|rgba|rgb|RGB|RGBA)*/g, "").split(",")
|
||||
let p : number[] = arr.map((val : string) : number => parseInt(val));
|
||||
|
||||
if (p.length < 3) {
|
||||
return {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 1
|
||||
} as RGBA
|
||||
}
|
||||
if (p.length == 3) {
|
||||
p.add(1)
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
r: p[0],
|
||||
g: p[1],
|
||||
b: p[2],
|
||||
a: arr.length==3?p[3]:parseFloat(arr[3])
|
||||
} as RGBA
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/* 此规范为 uni 规范,可以按照自己的需要选择是否实现 */
|
||||
import { MyApiErrorCode, MyApiFail } from "./interface.uts"
|
||||
/**
|
||||
* 错误主题
|
||||
* 注意:错误主题一般为插件名称,每个组件不同,需要使用时请更改。
|
||||
* [可选实现]
|
||||
*/
|
||||
export const UniErrorSubject = 'uts-api';
|
||||
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
* @UniError
|
||||
* [可选实现]
|
||||
*/
|
||||
export const MyAPIErrors : Map<MyApiErrorCode, string> = new Map([
|
||||
/**
|
||||
* 错误码及对应的错误信息
|
||||
*/
|
||||
[9010001, 'custom error mseeage1'],
|
||||
[9010002, 'custom error mseeage2'],
|
||||
]);
|
||||
|
||||
|
||||
/**
|
||||
* 错误对象实现
|
||||
*/
|
||||
export class MyApiFailImpl extends UniError implements MyApiFail {
|
||||
|
||||
/**
|
||||
* 错误对象构造函数
|
||||
*/
|
||||
constructor(errCode : MyApiErrorCode) {
|
||||
super();
|
||||
this.errSubject = UniErrorSubject;
|
||||
this.errCode = errCode;
|
||||
this.errMsg = MyAPIErrors.get(errCode) ?? "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
export {XRUN_START_LOGO_OPTS} from "../interface"
|
||||
import {hexToRgb} from "../libs/color"
|
||||
let xRunStartBoxDiv:null|HTMLElement = null;
|
||||
// @ts-ignore
|
||||
export function showRunLogo(opts:XRUN_START_LOGO_OPTS){
|
||||
let appwidth = '100vw';
|
||||
let appheight = '100vh';
|
||||
let _bgcolor = hexToRgb(opts.bgColor);
|
||||
let bgColor = _bgcolor?`rgba(${_bgcolor.r},${_bgcolor.g},${_bgcolor.b},${_bgcolor.a})`:'#f7f7f7'
|
||||
let _LogoBgColor = hexToRgb(opts.logoBgColor);
|
||||
let LogoBgColor = _LogoBgColor?`rgba(${_LogoBgColor.r},${_LogoBgColor.g},${_LogoBgColor.b},${_LogoBgColor.a})`:'#ffffff'
|
||||
let _fontColor = hexToRgb(opts.fontColor);
|
||||
let fontColor = _fontColor?`rgba(${_fontColor.r},${_fontColor.g},${_fontColor.b},${_fontColor.a})`:'#888888'
|
||||
|
||||
let box = document.createElement("div")
|
||||
box.style.position = 'fixed'
|
||||
box.style.left = '0px'
|
||||
box.style.top = '0px'
|
||||
box.style.zIndex = '300'
|
||||
box.style.width = appwidth
|
||||
box.style.height = appheight
|
||||
box.style.background = bgColor
|
||||
box.style.display = 'flex'
|
||||
box.style.flexDirection = 'column'
|
||||
box.style.justifyContent = 'flex-end'
|
||||
box.style.alignItems = 'center'
|
||||
|
||||
let rightText = document.createElement('span')
|
||||
rightText.style.fontSize = opts.fontSize+'px'
|
||||
rightText.style.color = fontColor
|
||||
rightText.style.marginBottom = '80px'
|
||||
rightText.style.marginTop = '12px'
|
||||
rightText.innerText = opts.rightText
|
||||
|
||||
let logoBox = document.createElement('div')
|
||||
logoBox.style.width = opts.width+'px'
|
||||
logoBox.style.height = opts.height+'px'
|
||||
logoBox.style.background = LogoBgColor
|
||||
logoBox.style.borderRadius = opts.round+'px'
|
||||
logoBox.style.padding = opts.logoPadding+'px'
|
||||
|
||||
let logo = document.createElement("img")
|
||||
logo.src = "/static/tmui4xLibs/static/"+opts.logo
|
||||
logo.style.width = opts.width+'px'
|
||||
logo.style.height = opts.height+'px'
|
||||
logo.style.borderRadius = opts.round+'px'
|
||||
|
||||
logoBox.append(logo)
|
||||
box.append(logoBox)
|
||||
box.append(rightText)
|
||||
document.body.append(box)
|
||||
|
||||
xRunStartBoxDiv = box;
|
||||
}
|
||||
|
||||
|
||||
export function hideRunLogo() {
|
||||
if(xRunStartBoxDiv){
|
||||
document.body.removeChild(xRunStartBoxDiv)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user