剩余模块:生产入库,销售出库

This commit is contained in:
2025-05-20 16:07:49 +08:00
parent 933ddab8f3
commit b1d8dec263
299 changed files with 38798 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import Activity from "android.app.Activity";
import Bundle from 'android.os.Bundle';
import Build from 'android.os.Build';
import View from 'android.view.View';
import Color from 'android.graphics.Color';
import WindowManager from 'android.view.WindowManager';
import { getGlobalNotificationProgressCallBack, getGlobalNotificationProgressFinishCallBack, setGlobalNotificationProgressCallBack, setGlobalNotificationProgressFinishCallBack} from './callbacks.uts';
import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts"
export class TransparentActivity extends Activity {
constructor() {
super()
}
@Suppress("DEPRECATION")
override onCreate(savedInstanceState : Bundle | null) {
super.onCreate(savedInstanceState)
this.fullScreen(this)
const action = this.getIntent().getAction()
if (action == ACTION_DOWNLOAD_FINISH) {
setTimeout(() => {
getGlobalNotificationProgressFinishCallBack()?.()
setGlobalNotificationProgressFinishCallBack(() => { })
}, 100)
this.overridePendingTransition(0, 0)
}
if (action == ACTION_DOWNLOAD_PROGRESS) {
setTimeout(() => {
getGlobalNotificationProgressCallBack()?.()
setGlobalNotificationProgressCallBack(() => { })
}, 100)
this.overridePendingTransition(0, 0)
}
setTimeout(() => {
this.finish()
}, 20)
}
@Suppress("DEPRECATION")
private fullScreen(activity : Activity) {
if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= 21) {
const window = activity.getWindow();
const decorView = window.getDecorView();
const option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(option);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
} else {
const window = activity.getWindow();
const attributes = window.getAttributes();
const flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
attributes.flags |= flagTranslucentStatus;
window.setAttributes(attributes);
}
}
}
}

View File

@@ -0,0 +1,19 @@
let globalNotificationProgressCallBack : (() => void) | null = () => { }
let globalNotificationProgressFinishCallBack : (() => void) | null = () => { }
export function setGlobalNotificationProgressCallBack(callBack : (() => void) | null) : void {
globalNotificationProgressCallBack = callBack
}
export function getGlobalNotificationProgressCallBack() : (() => void) | null {
return globalNotificationProgressCallBack
}
export function setGlobalNotificationProgressFinishCallBack(callBack : (() => void) | null) : void {
globalNotificationProgressFinishCallBack = callBack
}
export function getGlobalNotificationProgressFinishCallBack() : (() => void) | null {
return globalNotificationProgressFinishCallBack
}

View File

@@ -0,0 +1,2 @@
export const ACTION_DOWNLOAD_FINISH = "ACTION_DOWNLOAD_FINISH"
export const ACTION_DOWNLOAD_PROGRESS = "ACTION_DOWNLOAD_PROGRESS"

View File

@@ -0,0 +1,156 @@
import Build from 'android.os.Build';
import Context from 'android.content.Context';
import NotificationManager from 'android.app.NotificationManager';
import NotificationChannel from 'android.app.NotificationChannel';
import Notification from 'android.app.Notification';
import Intent from 'android.content.Intent';
import ComponentName from 'android.content.ComponentName';
import PendingIntent from 'android.app.PendingIntent';
import { CreateNotificationProgressOptions, FinishNotificationProgressOptions } from '../interface.uts';
import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts"
import { setGlobalNotificationProgressCallBack, setGlobalNotificationProgressFinishCallBack } from './callbacks.uts';
export { TransparentActivity } from './TransparentActivity.uts';
const DOWNLOAD_PROGRESS_NOTIFICATION_ID : Int = 7890
const DC_DOWNLOAD_CHANNEL_ID = "下载文件"
const DC_DOWNLOAD_CHANNEL_NAME = "用于显示现在进度的渠道"
let notificationBuilder : Notification.Builder | null = null
let timeId = -1
let histroyProgress = 0
let isProgress = false
export function createNotificationProgress(options : CreateNotificationProgressOptions) : void {
const { content, progress, onClick } = options
if (progress == 100) {
clearTimeout(timeId)
const context = UTSAndroid.getAppContext() as Context
realCreateNotificationProgress(options.title ?? getAppName(context), content, progress, onClick)
reset()
return
}
histroyProgress = progress
if (timeId != -1) {
return
}
const context = UTSAndroid.getAppContext() as Context
if (!isProgress) {
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress, onClick)
isProgress = true
} else {
timeId = setTimeout(() => {
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress, onClick)
timeId = -1
}, 1000)
}
}
export function cancelNotificationProgress() : void {
const context = UTSAndroid.getAppContext() as Context
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(DOWNLOAD_PROGRESS_NOTIFICATION_ID)
reset()
}
function realCreateNotificationProgress(title : string, content : string, progress : number, cb : (() => void) | null) : void {
setGlobalNotificationProgressCallBack(cb)
const context = UTSAndroid.getAppContext() as Context
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
createDownloadChannel(notificationManager)
const builder = createNotificationBuilder(context)
builder.setProgress(100, progress.toInt(), false)
builder.setContentTitle(title)
builder.setContentText(content)
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_PROGRESS));
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
}
export function finishNotificationProgress(options : FinishNotificationProgressOptions) {
setGlobalNotificationProgressFinishCallBack(options.onClick)
const context = UTSAndroid.getAppContext() as Context
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
createDownloadChannel(notificationManager)
const builder = createNotificationBuilder(context)
builder.setProgress(0, 0, false)
builder.setContentTitle(options.title ?? getAppName(context))
builder.setContentText(options.content)
//小米rom setOngoing未false的时候会被通知管理器归为不重要通知
// builder.setOngoing(false)
builder.setAutoCancel(true);
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_FINISH));
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
reset()
}
function reset() {
isProgress = false
notificationBuilder = null
histroyProgress = 0
if (timeId != -1) {
clearTimeout(timeId)
timeId = -1
}
}
function createPendingIntent(context : Context, action : string) : PendingIntent {
const intent = new Intent(action);
intent.setComponent(new ComponentName(context.getPackageName(), "uts.sdk.modules.utsProgressNotification.TransparentActivity"));
let flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= 23) {
flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
}
return PendingIntent.getActivity(context, DOWNLOAD_PROGRESS_NOTIFICATION_ID, intent, flags);
}
function createDownloadChannel(notificationManager : NotificationManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
const channel = new NotificationChannel(
DC_DOWNLOAD_CHANNEL_ID,
DC_DOWNLOAD_CHANNEL_NAME,
NotificationManager.IMPORTANCE_LOW
)
notificationManager.createNotificationChannel(channel)
}
}
@Suppress("DEPRECATION")
function createNotificationBuilder(context : Context) : Notification.Builder {
if (notificationBuilder == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationBuilder = new Notification.Builder(context, DC_DOWNLOAD_CHANNEL_ID)
} else {
notificationBuilder = new Notification.Builder(context)
}
notificationBuilder!.setSmallIcon(context.getApplicationInfo().icon)
notificationBuilder!.setOngoing(true)
notificationBuilder!.setSound(null)
}
return notificationBuilder!
}
@Suppress("DEPRECATION")
function getAppName(context : Context) : string {
let appName = ""
try {
const packageManager = context.getPackageManager()
const applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0)
appName = packageManager.getApplicationLabel(applicationInfo) as string
} catch (e : Exception) {
e.printStackTrace()
}
return appName
}

View File

@@ -0,0 +1,46 @@
export type CreateNotificationProgressOptions = {
/**
* 通知标题
* @defaultValue 应用名称
*/
title ?: string | null
/**
* 通知内容
*/
content : string,
/**
* 进度
*/
progress : number,
/**
* 点击通知消息回调
* @defaultValue null
*/
onClick? : (() => void) | null
}
export type FinishNotificationProgressOptions = {
/**
* 通知标题
* @defaultValue 应用名称
*/
title ?: string | null
/**
* 通知内容
*/
content : string,
/**
* 点击通知消息回调
*/
onClick : () => void
}
export type CreateNotificationProgress = (options : CreateNotificationProgressOptions) => void;
export type CancelNotificationProgress = () => void;
export type FinishNotificationProgress = (options: FinishNotificationProgressOptions) => void

View File

@@ -0,0 +1,62 @@
import Activity from "android.app.Activity";
import Bundle from 'android.os.Bundle';
import Build from 'android.os.Build';
import View from 'android.view.View';
import Color from 'android.graphics.Color';
import WindowManager from 'android.view.WindowManager';
import { getGlobalNotificationProgressCallBack, getGlobalNotificationProgressFinishCallBack, setGlobalNotificationProgressCallBack, setGlobalNotificationProgressFinishCallBack} from './callbacks.uts';
import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts"
export class TransparentActivity extends Activity {
constructor() {
super()
}
@Suppress("DEPRECATION")
override onCreate(savedInstanceState : Bundle | null) {
super.onCreate(savedInstanceState)
this.fullScreen(this)
const action = this.getIntent().getAction()
if (action == ACTION_DOWNLOAD_FINISH) {
setTimeout(() => {
getGlobalNotificationProgressFinishCallBack()?.()
setGlobalNotificationProgressFinishCallBack(() => { })
}, 100)
this.overridePendingTransition(0, 0)
}
if (action == ACTION_DOWNLOAD_PROGRESS) {
setTimeout(() => {
getGlobalNotificationProgressCallBack()?.()
setGlobalNotificationProgressCallBack(() => { })
}, 100)
this.overridePendingTransition(0, 0)
}
setTimeout(() => {
this.finish()
}, 20)
}
@Suppress("DEPRECATION")
private fullScreen(activity : Activity) {
if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= 21) {
const window = activity.getWindow();
const decorView = window.getDecorView();
const option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(option);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
} else {
const window = activity.getWindow();
const attributes = window.getAttributes();
const flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
attributes.flags |= flagTranslucentStatus;
window.setAttributes(attributes);
}
}
}
}

View File

@@ -0,0 +1,19 @@
let globalNotificationProgressCallBack : (() => void) | null = () => { }
let globalNotificationProgressFinishCallBack : (() => void) | null = () => { }
export function setGlobalNotificationProgressCallBack(callBack : (() => void) | null) : void {
globalNotificationProgressCallBack = callBack
}
export function getGlobalNotificationProgressCallBack() : (() => void) | null {
return globalNotificationProgressCallBack
}
export function setGlobalNotificationProgressFinishCallBack(callBack : (() => void) | null) : void {
globalNotificationProgressFinishCallBack = callBack
}
export function getGlobalNotificationProgressFinishCallBack() : (() => void) | null {
return globalNotificationProgressFinishCallBack
}

View File

@@ -0,0 +1,2 @@
export const ACTION_DOWNLOAD_FINISH = "ACTION_DOWNLOAD_FINISH"
export const ACTION_DOWNLOAD_PROGRESS = "ACTION_DOWNLOAD_PROGRESS"

View File

@@ -0,0 +1,156 @@
import Build from 'android.os.Build';
import Context from 'android.content.Context';
import NotificationManager from 'android.app.NotificationManager';
import NotificationChannel from 'android.app.NotificationChannel';
import Notification from 'android.app.Notification';
import Intent from 'android.content.Intent';
import ComponentName from 'android.content.ComponentName';
import PendingIntent from 'android.app.PendingIntent';
import { CreateNotificationProgressOptions, FinishNotificationProgressOptions } from '../interface.uts';
import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts"
import { setGlobalNotificationProgressCallBack, setGlobalNotificationProgressFinishCallBack } from './callbacks.uts';
export { TransparentActivity } from './TransparentActivity.uts';
const DOWNLOAD_PROGRESS_NOTIFICATION_ID : Int = 7890
const DC_DOWNLOAD_CHANNEL_ID = "下载文件"
const DC_DOWNLOAD_CHANNEL_NAME = "用于显示现在进度的渠道"
let notificationBuilder : Notification.Builder | null = null
let timeId = -1
let histroyProgress = 0
let isProgress = false
export function createNotificationProgress(options : CreateNotificationProgressOptions) : void {
const { content, progress, onClick } = options
if (progress == 100) {
clearTimeout(timeId)
const context = UTSAndroid.getAppContext() as Context
realCreateNotificationProgress(options.title ?? getAppName(context), content, progress, onClick)
reset()
return
}
histroyProgress = progress
if (timeId != -1) {
return
}
const context = UTSAndroid.getAppContext() as Context
if (!isProgress) {
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress, onClick)
isProgress = true
} else {
timeId = setTimeout(() => {
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress, onClick)
timeId = -1
}, 1000)
}
}
export function cancelNotificationProgress() : void {
const context = UTSAndroid.getAppContext() as Context
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(DOWNLOAD_PROGRESS_NOTIFICATION_ID)
reset()
}
function realCreateNotificationProgress(title : string, content : string, progress : number, cb : (() => void) | null) : void {
setGlobalNotificationProgressCallBack(cb)
const context = UTSAndroid.getAppContext() as Context
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
createDownloadChannel(notificationManager)
const builder = createNotificationBuilder(context)
builder.setProgress(100, progress.toInt(), false)
builder.setContentTitle(title)
builder.setContentText(content)
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_PROGRESS));
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
}
export function finishNotificationProgress(options : FinishNotificationProgressOptions) {
setGlobalNotificationProgressFinishCallBack(options.onClick)
const context = UTSAndroid.getAppContext() as Context
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
createDownloadChannel(notificationManager)
const builder = createNotificationBuilder(context)
builder.setProgress(0, 0, false)
builder.setContentTitle(options.title ?? getAppName(context))
builder.setContentText(options.content)
//小米rom setOngoing未false的时候会被通知管理器归为不重要通知
// builder.setOngoing(false)
builder.setAutoCancel(true);
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_FINISH));
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
reset()
}
function reset() {
isProgress = false
notificationBuilder = null
histroyProgress = 0
if (timeId != -1) {
clearTimeout(timeId)
timeId = -1
}
}
function createPendingIntent(context : Context, action : string) : PendingIntent {
const intent = new Intent(action);
intent.setComponent(new ComponentName(context.getPackageName(), "uts.sdk.modules.utsProgressNotification.TransparentActivity"));
let flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= 23) {
flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
}
return PendingIntent.getActivity(context, DOWNLOAD_PROGRESS_NOTIFICATION_ID, intent, flags);
}
function createDownloadChannel(notificationManager : NotificationManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
const channel = new NotificationChannel(
DC_DOWNLOAD_CHANNEL_ID,
DC_DOWNLOAD_CHANNEL_NAME,
NotificationManager.IMPORTANCE_LOW
)
notificationManager.createNotificationChannel(channel)
}
}
@Suppress("DEPRECATION")
function createNotificationBuilder(context : Context) : Notification.Builder {
if (notificationBuilder == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationBuilder = new Notification.Builder(context, DC_DOWNLOAD_CHANNEL_ID)
} else {
notificationBuilder = new Notification.Builder(context)
}
notificationBuilder!.setSmallIcon(context.getApplicationInfo().icon)
notificationBuilder!.setOngoing(true)
notificationBuilder!.setSound(null)
}
return notificationBuilder!
}
@Suppress("DEPRECATION")
function getAppName(context : Context) : string {
let appName = ""
try {
const packageManager = context.getPackageManager()
const applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0)
appName = packageManager.getApplicationLabel(applicationInfo) as string
} catch (e : Exception) {
e.printStackTrace()
}
return appName
}

View File

@@ -0,0 +1,46 @@
export type CreateNotificationProgressOptions = {
/**
* 通知标题
* @defaultValue 应用名称
*/
title ?: string | null
/**
* 通知内容
*/
content : string,
/**
* 进度
*/
progress : number,
/**
* 点击通知消息回调
* @defaultValue null
*/
onClick? : (() => void) | null
}
export type FinishNotificationProgressOptions = {
/**
* 通知标题
* @defaultValue 应用名称
*/
title ?: string | null
/**
* 通知内容
*/
content : string,
/**
* 点击通知消息回调
*/
onClick : () => void
}
export type CreateNotificationProgress = (options : CreateNotificationProgressOptions) => void;
export type CancelNotificationProgress = () => void;
export type FinishNotificationProgress = (options: FinishNotificationProgressOptions) => void

View File

@@ -0,0 +1,56 @@
import Activity from "android.app.Activity";
import Bundle from 'android.os.Bundle';
import Build from 'android.os.Build';
import View from 'android.view.View';
import Color from 'android.graphics.Color';
import WindowManager from 'android.view.WindowManager';
import { getGlobalNotificationProgressCallBack, getGlobalNotificationProgressFinishCallBack, setGlobalNotificationProgressCallBack, setGlobalNotificationProgressFinishCallBack } from './callbacks.uts';
import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts";
export class TransparentActivity extends Activity {
constructor() {
super();
}
@Suppress("DEPRECATION")
override onCreate(savedInstanceState: Bundle | null) {
super.onCreate(savedInstanceState);
this.fullScreen(this);
const action = this.getIntent().getAction();
if (action == ACTION_DOWNLOAD_FINISH) {
setTimeout(() => {
getGlobalNotificationProgressFinishCallBack()?.();
setGlobalNotificationProgressFinishCallBack(() => { });
}, 100);
this.overridePendingTransition(0, 0);
}
if (action == ACTION_DOWNLOAD_PROGRESS) {
setTimeout(() => {
getGlobalNotificationProgressCallBack()?.();
setGlobalNotificationProgressCallBack(() => { });
}, 100);
this.overridePendingTransition(0, 0);
}
setTimeout(() => {
this.finish();
}, 20);
}
@Suppress("DEPRECATION")
private fullScreen(activity: Activity) {
if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= 21) {
const window = activity.getWindow();
const decorView = window.getDecorView();
const option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(option);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
}
else {
const window = activity.getWindow();
const attributes = window.getAttributes();
const flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
attributes.flags |= flagTranslucentStatus;
window.setAttributes(attributes);
}
}
}
}

View File

@@ -0,0 +1,14 @@
let globalNotificationProgressCallBack: (() => void) | null = () => { };
let globalNotificationProgressFinishCallBack: (() => void) | null = () => { };
export function setGlobalNotificationProgressCallBack(callBack: (() => void) | null): void {
globalNotificationProgressCallBack = callBack;
}
export function getGlobalNotificationProgressCallBack(): (() => void) | null {
return globalNotificationProgressCallBack;
}
export function setGlobalNotificationProgressFinishCallBack(callBack: (() => void) | null): void {
globalNotificationProgressFinishCallBack = callBack;
}
export function getGlobalNotificationProgressFinishCallBack(): (() => void) | null {
return globalNotificationProgressFinishCallBack;
}

View File

@@ -0,0 +1,2 @@
export const ACTION_DOWNLOAD_FINISH = "ACTION_DOWNLOAD_FINISH";
export const ACTION_DOWNLOAD_PROGRESS = "ACTION_DOWNLOAD_PROGRESS";

View File

@@ -0,0 +1,130 @@
import Build from 'android.os.Build';
import Context from 'android.content.Context';
import NotificationManager from 'android.app.NotificationManager';
import NotificationChannel from 'android.app.NotificationChannel';
import Notification from 'android.app.Notification';
import Intent from 'android.content.Intent';
import ComponentName from 'android.content.ComponentName';
import PendingIntent from 'android.app.PendingIntent';
import { CreateNotificationProgressOptions, FinishNotificationProgressOptions } from '../interface.uts';
import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts";
import { setGlobalNotificationProgressCallBack, setGlobalNotificationProgressFinishCallBack } from './callbacks.uts';
export { TransparentActivity } from './TransparentActivity.uts';
const DOWNLOAD_PROGRESS_NOTIFICATION_ID: Int = 7890;
const DC_DOWNLOAD_CHANNEL_ID = "下载文件";
const DC_DOWNLOAD_CHANNEL_NAME = "用于显示现在进度的渠道";
let notificationBuilder: Notification.Builder | null = null;
let timeId = -1;
let histroyProgress = 0;
let isProgress = false;
export function createNotificationProgress(options: CreateNotificationProgressOptions): void {
const { content, progress, onClick } = options;
if (progress == 100) {
clearTimeout(timeId);
const context = UTSAndroid.getAppContext() as Context;
realCreateNotificationProgress(options.title ?? getAppName(context), content, progress, onClick);
reset();
return;
}
histroyProgress = progress;
if (timeId != -1) {
return;
}
const context = UTSAndroid.getAppContext() as Context;
if (!isProgress) {
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress, onClick);
isProgress = true;
}
else {
timeId = setTimeout(() => {
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress, onClick);
timeId = -1;
}, 1000);
}
}
export function cancelNotificationProgress(): void {
const context = UTSAndroid.getAppContext() as Context;
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager;
notificationManager.cancel(DOWNLOAD_PROGRESS_NOTIFICATION_ID);
reset();
}
function realCreateNotificationProgress(title: string, content: string, progress: number, cb: (() => void) | null): void {
setGlobalNotificationProgressCallBack(cb);
const context = UTSAndroid.getAppContext() as Context;
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager;
createDownloadChannel(notificationManager);
const builder = createNotificationBuilder(context);
builder.setProgress(100, progress.toInt(), false);
builder.setContentTitle(title);
builder.setContentText(content);
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_PROGRESS));
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build());
}
export function finishNotificationProgress(options: FinishNotificationProgressOptions) {
setGlobalNotificationProgressFinishCallBack(options.onClick);
const context = UTSAndroid.getAppContext() as Context;
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager;
createDownloadChannel(notificationManager);
const builder = createNotificationBuilder(context);
builder.setProgress(0, 0, false);
builder.setContentTitle(options.title ?? getAppName(context));
builder.setContentText(options.content);
//小米rom setOngoing未false的时候会被通知管理器归为不重要通知
// builder.setOngoing(false)
builder.setAutoCancel(true);
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_FINISH));
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build());
reset();
}
function reset() {
isProgress = false;
notificationBuilder = null;
histroyProgress = 0;
if (timeId != -1) {
clearTimeout(timeId);
timeId = -1;
}
}
function createPendingIntent(context: Context, action: string): PendingIntent {
const intent = new Intent(action);
intent.setComponent(new ComponentName(context.getPackageName(), "uts.sdk.modules.utsProgressNotification.TransparentActivity"));
let flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= 23) {
flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
}
return PendingIntent.getActivity(context, DOWNLOAD_PROGRESS_NOTIFICATION_ID, intent, flags);
}
function createDownloadChannel(notificationManager: NotificationManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
const channel = new NotificationChannel(DC_DOWNLOAD_CHANNEL_ID, DC_DOWNLOAD_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
notificationManager.createNotificationChannel(channel);
}
}
@Suppress("DEPRECATION")
function createNotificationBuilder(context: Context): Notification.Builder {
if (notificationBuilder == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationBuilder = new Notification.Builder(context, DC_DOWNLOAD_CHANNEL_ID);
}
else {
notificationBuilder = new Notification.Builder(context);
}
notificationBuilder!.setSmallIcon(context.getApplicationInfo().icon);
notificationBuilder!.setOngoing(true);
notificationBuilder!.setSound(null);
}
return notificationBuilder!;
}
@Suppress("DEPRECATION")
function getAppName(context: Context): string {
let appName = "";
try {
const packageManager = context.getPackageManager();
const applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
appName = packageManager.getApplicationLabel(applicationInfo) as string;
}
catch (e: Exception) {
e.printStackTrace();
}
return appName;
}

View File

@@ -0,0 +1,38 @@
export type CreateNotificationProgressOptions = {
/**
* 通知标题
* @defaultValue 应用名称
*/
title?: string | null;
/**
* 通知内容
*/
content: string;
/**
* 进度
*/
progress: number;
/**
* 点击通知消息回调
* @defaultValue null
*/
onClick?: (() => void) | null;
};
export type FinishNotificationProgressOptions = {
/**
* 通知标题
* @defaultValue 应用名称
*/
title?: string | null;
/**
* 通知内容
*/
content: string;
/**
* 点击通知消息回调
*/
onClick: () => void;
};
export type CreateNotificationProgress = (options: CreateNotificationProgressOptions) => void;
export type CancelNotificationProgress = () => void;
export type FinishNotificationProgress = (options: FinishNotificationProgressOptions) => void;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@@ -0,0 +1 @@
body{background:transparent}.flex-center{display:flex;justify-content:center;align-items:center}.mask{position:fixed;left:0;top:0;right:0;bottom:0;background-color:rgba(0,0,0,.65)}.botton-radius{border-bottom-left-radius:.9375rem;border-bottom-right-radius:.9375rem}.content{position:relative;top:0;width:18.75rem;background-color:#fff;box-sizing:border-box;padding:0 1.5625rem;font-family:Source Han Sans CN}.text{display:block;line-height:200px;text-align:center;color:#fff}.content-top{position:absolute;top:-6.09375rem;left:0;width:18.75rem;height:8.4375rem}.content-top-text{font-size:1.40625rem;font-weight:700;color:#f8f8fa;position:absolute;top:3.75rem;left:1.5625rem;z-index:1}.content-header{height:2.1875rem}.title{font-size:1.03125rem;font-weight:700;color:#3da7ff;display:flex;align-items:center}.content-body-version{color:#fff;font-size:12px;margin-left:5px;padding:2px 6px;border-radius:4px;display:flex;background:#50aefd}.footer{height:4.6875rem;display:flex;align-items:center;justify-content:space-around}.box-des-scroll{box-sizing:border-box;height:6.25rem;text-align:left}.box-des{font-size:.8125rem;color:#000;line-height:1.5625rem}.progress-box{width:100%}.progress{width:90%;height:1.25rem}.close-img{width:2.1875rem;height:2.1875rem;z-index:1000;position:absolute;bottom:-3.75rem;left:calc(50% - 1.09375rem)}.content-button{text-align:center;flex:1;font-size:.9375rem;font-weight:400;color:#fff;border-radius:1.25rem;margin:0 .5625rem;height:2.5rem;line-height:2.5rem;background:linear-gradient(to right,#1785ff,#3da7ff)}.flex-column{display:flex;flex-direction:column;align-items:center}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="uts.sdk.modules.utsProgressNotification">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<application>
<activity android:name="uts.sdk.modules.utsProgressNotification.TransparentActivity"
android:theme="@style/DCNotificationProgressTranslucentTheme" android:hardwareAccelerated="true"
android:screenOrientation="user" android:exported="true">
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,3 @@
{
"minSdkVersion": "19"
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="DCNotificationProgressTranslucentTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>

View File

@@ -0,0 +1,255 @@
@file:Suppress("UNCHECKED_CAST", "USELESS_CAST", "INAPPLICABLE_JVM_NAME", "UNUSED_ANONYMOUS_PARAMETER", "NAME_SHADOWING")
package uts.sdk.modules.utsProgressNotification
import android.app.Activity
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import io.dcloud.uniapp.*
import io.dcloud.uniapp.extapi.*
import io.dcloud.uts.*
import io.dcloud.uts.Map
import io.dcloud.uts.Set
import io.dcloud.uts.UTSAndroid
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import uts.sdk.modules.utsProgressNotification.R
open class CreateNotificationProgressOptions (
open var title: String? = null,
@JsonNotNull
open var content: String,
@JsonNotNull
open var progress: Number,
open var onClick: (() -> Unit)? = null,
) : UTSObject()
open class FinishNotificationProgressOptions (
open var title: String? = null,
@JsonNotNull
open var content: String,
open var onClick: () -> Unit,
) : UTSObject()
val ACTION_DOWNLOAD_FINISH = "ACTION_DOWNLOAD_FINISH"
val ACTION_DOWNLOAD_PROGRESS = "ACTION_DOWNLOAD_PROGRESS"
@JvmField
var globalNotificationProgressCallBack: (() -> Unit)? = fun(){}
@JvmField
var globalNotificationProgressFinishCallBack: (() -> Unit)? = fun(){}
fun setGlobalNotificationProgressCallBack(callBack: (() -> Unit)?): Unit {
globalNotificationProgressCallBack = callBack
}
fun getGlobalNotificationProgressCallBack(): (() -> Unit)? {
return globalNotificationProgressCallBack
}
fun setGlobalNotificationProgressFinishCallBack(callBack: (() -> Unit)?): Unit {
globalNotificationProgressFinishCallBack = callBack
}
fun getGlobalNotificationProgressFinishCallBack(): (() -> Unit)? {
return globalNotificationProgressFinishCallBack
}
open class TransparentActivity : Activity {
constructor() : super() {}
@Suppress("DEPRECATION")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.fullScreen(this)
val action = this.getIntent().getAction()
if (action == ACTION_DOWNLOAD_FINISH) {
setTimeout(fun(){
getGlobalNotificationProgressFinishCallBack()?.invoke()
setGlobalNotificationProgressFinishCallBack(fun(){})
}
, 100)
this.overridePendingTransition(0, 0)
}
if (action == ACTION_DOWNLOAD_PROGRESS) {
setTimeout(fun(){
getGlobalNotificationProgressCallBack()?.invoke()
setGlobalNotificationProgressCallBack(fun(){})
}
, 100)
this.overridePendingTransition(0, 0)
}
setTimeout(fun(){
this.finish()
}
, 20)
}
@Suppress("DEPRECATION")
private fun fullScreen(activity: Activity) {
if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= 21) {
val window = activity.getWindow()
val decorView = window.getDecorView()
val option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
decorView.setSystemUiVisibility(option)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.setStatusBarColor(Color.TRANSPARENT)
} else {
val window = activity.getWindow()
val attributes = window.getAttributes()
val flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
attributes.flags = attributes.flags or flagTranslucentStatus
window.setAttributes(attributes)
}
}
}
}
val DOWNLOAD_PROGRESS_NOTIFICATION_ID: Int = 7890
val DC_DOWNLOAD_CHANNEL_ID = "下载文件"
val DC_DOWNLOAD_CHANNEL_NAME = "用于显示现在进度的渠道"
var notificationBuilder: Notification.Builder? = null
var timeId: Number = -1
var histroyProgress: Number = 0
var isProgress = false
fun createNotificationProgress(options: CreateNotificationProgressOptions): Unit {
val content = options.content
val progress = options.progress
val onClick = options.onClick
if (progress == 100) {
clearTimeout(timeId)
val context = UTSAndroid.getAppContext() as Context
realCreateNotificationProgress(options.title ?: getAppName(context), content, progress, onClick)
reset()
return
}
histroyProgress = progress
if (timeId != -1) {
return
}
val context = UTSAndroid.getAppContext() as Context
if (!isProgress) {
realCreateNotificationProgress(options.title ?: getAppName(context), content, histroyProgress, onClick)
isProgress = true
} else {
timeId = setTimeout(fun(){
realCreateNotificationProgress(options.title ?: getAppName(context), content, histroyProgress, onClick)
timeId = -1
}
, 1000)
}
}
fun cancelNotificationProgress(): Unit {
val context = UTSAndroid.getAppContext() as Context
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(DOWNLOAD_PROGRESS_NOTIFICATION_ID)
reset()
}
fun realCreateNotificationProgress(title: String, content: String, progress: Number, cb: (() -> Unit)?): Unit {
setGlobalNotificationProgressCallBack(cb)
val context = UTSAndroid.getAppContext() as Context
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
createDownloadChannel(notificationManager)
val builder = createNotificationBuilder(context)
builder.setProgress(100, progress.toInt(), false)
builder.setContentTitle(title)
builder.setContentText(content)
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_PROGRESS))
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
}
fun finishNotificationProgress(options: FinishNotificationProgressOptions) {
setGlobalNotificationProgressFinishCallBack(options.onClick)
val context = UTSAndroid.getAppContext() as Context
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
createDownloadChannel(notificationManager)
val builder = createNotificationBuilder(context)
builder.setProgress(0, 0, false)
builder.setContentTitle(options.title ?: getAppName(context))
builder.setContentText(options.content)
builder.setAutoCancel(true)
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_FINISH))
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
reset()
}
fun reset() {
isProgress = false
notificationBuilder = null
histroyProgress = 0
if (timeId != -1) {
clearTimeout(timeId)
timeId = -1
}
}
fun createPendingIntent(context: Context, action: String): PendingIntent {
val intent = Intent(action)
intent.setComponent(ComponentName(context.getPackageName(), "uts.sdk.modules.utsProgressNotification.TransparentActivity"))
var flags = PendingIntent.FLAG_UPDATE_CURRENT
if (Build.VERSION.SDK_INT >= 23) {
flags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
}
return PendingIntent.getActivity(context, DOWNLOAD_PROGRESS_NOTIFICATION_ID, intent, flags)
}
fun createDownloadChannel(notificationManager: NotificationManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(DC_DOWNLOAD_CHANNEL_ID, DC_DOWNLOAD_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW)
notificationManager.createNotificationChannel(channel)
}
}
@Suppress("DEPRECATION")
fun createNotificationBuilder(context: Context): Notification.Builder {
if (notificationBuilder == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationBuilder = Notification.Builder(context, DC_DOWNLOAD_CHANNEL_ID)
} else {
notificationBuilder = Notification.Builder(context)
}
notificationBuilder!!.setSmallIcon(context.getApplicationInfo().icon)
notificationBuilder!!.setOngoing(true)
notificationBuilder!!.setSound(null)
}
return notificationBuilder!!
}
@Suppress("DEPRECATION")
fun getAppName(context: Context): String {
var appName = ""
try {
val packageManager = context.getPackageManager()
val applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0)
appName = packageManager.getApplicationLabel(applicationInfo) as String
}
catch (e: Exception) {
e.printStackTrace()
}
return appName
}
open class CreateNotificationProgressOptionsJSONObject : UTSJSONObject() {
open var title: String? = null
open lateinit var content: String
open lateinit var progress: Number
open var onClick: UTSCallback? = null
}
open class FinishNotificationProgressOptionsJSONObject : UTSJSONObject() {
open var title: String? = null
open lateinit var content: String
open lateinit var onClick: UTSCallback
}
open class TransparentActivityByJs : TransparentActivity {
constructor() : super() {}
open fun onCreateByJs(savedInstanceState: Bundle?) {
return this.onCreate(savedInstanceState)
}
}
fun createNotificationProgressByJs(options: CreateNotificationProgressOptionsJSONObject): Unit {
return createNotificationProgress(CreateNotificationProgressOptions(title = options.title, content = options.content, progress = options.progress, onClick = fun(): Unit {
options.onClick?.invoke()
}
))
}
fun cancelNotificationProgressByJs(): Unit {
return cancelNotificationProgress()
}
fun finishNotificationProgressByJs(options: FinishNotificationProgressOptionsJSONObject) {
return finishNotificationProgress(FinishNotificationProgressOptions(title = options.title, content = options.content, onClick = fun(): Unit {
options.onClick()
}
))
}

View File

@@ -0,0 +1,38 @@
{
"version": "1",
"env": {
"compilerVersion": "4.54.2025030608-alpha"
},
"files": {
"utssdk/app-android/TransparentActivity.uts": {
"md5": "d41530560fe13e9934cc3b1fb73c9890"
},
"utssdk/app-android/callbacks.uts": {
"md5": "348b1166fafde03d77d31c708ffeca5f"
},
"utssdk/app-android/constant.uts": {
"md5": "9e03e42b19d59d8ed16f3df814dbba74"
},
"utssdk/app-android/index.uts": {
"md5": "d3752bb6c002b2da6377f0e8a215f91a"
},
"utssdk/interface.uts": {
"md5": "ff87bca6142d3990b5057f452ea3f2b4"
},
"utssdk/unierror.uts": {
"md5": "d41d8cd98f00b204e9800998ecf8427e"
},
"package.json": {
"md5": "3cdbb2337594f0c0315d1fa20a739617"
},
"utssdk/app-android/AndroidManifest.xml": {
"md5": "80263498d2ad55cb954e347c7c933e65"
},
"utssdk/app-android/config.json": {
"md5": "d903d6c89479ad424282bba97dff94ef"
},
"utssdk/app-android/res/values/notification_progress_styles.xml": {
"md5": "6fa2d7ac4d16a31ee5251cfb34bacd41"
}
}
}