Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
6bb96332
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1598
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6bb96332
编写于
10月 26, 2022
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增生命周期监听 增加示例
上级
5147afd5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
103 addition
and
36 deletion
+103
-36
pages/lifecycle/lifecycle.vue
pages/lifecycle/lifecycle.vue
+20
-1
pages/resource/resource.vue
pages/resource/resource.vue
+4
-11
uni_modules/uts-advance/utssdk/app-android/index.uts
uni_modules/uts-advance/utssdk/app-android/index.uts
+74
-5
uni_modules/uts-nativepage/utssdk/app-android/index.uts
uni_modules/uts-nativepage/utssdk/app-android/index.uts
+2
-2
uni_modules/uts-toast/utssdk/app-android/config.json
uni_modules/uts-toast/utssdk/app-android/config.json
+0
-7
uni_modules/uts-toast/utssdk/app-android/index.uts
uni_modules/uts-toast/utssdk/app-android/index.uts
+3
-10
未找到文件。
pages/lifecycle/lifecycle.vue
浏览文件 @
6bb96332
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
<
template
>
<
template
>
<view>
<view>
<page-head
:title=
"title"
></page-head>
<page-head
:title=
"title"
></page-head>
<button
@
tap=
"testGoOtherActivity"
>
跳转选择界面
</button>
<image
:src=
"selectImage"
v-if=
"selectImage"
></image>
<view
class=
"uni-padding-wrap uni-common-mt"
>
<view
class=
"uni-padding-wrap uni-common-mt"
>
<view
class=
"uni-hello-text"
>
<view
class=
"uni-hello-text"
>
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
...
@@ -18,12 +20,13 @@
...
@@ -18,12 +20,13 @@
</view>
</view>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
initAppLifecycle
}
from
'
../../uni_modules/uts-advance
'
;
import
{
initAppLifecycle
,
goOtherActivity
}
from
'
../../uni_modules/uts-advance
'
;
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
title
:
'
生命周期监听
'
,
title
:
'
生命周期监听
'
,
text
:
''
,
text
:
''
,
selectImage
:
""
}
}
},
},
onLoad
:
function
(){
onLoad
:
function
(){
...
@@ -33,6 +36,22 @@
...
@@ -33,6 +36,22 @@
that
.
text
=
that
.
text
+=
eventLog
;
that
.
text
=
that
.
text
+=
eventLog
;
that
.
text
=
that
.
text
+=
'
\n
'
;
that
.
text
=
that
.
text
+=
'
\n
'
;
});
});
},
methods
:{
testGoOtherActivity
(){
var
that
=
this
;
let
ret
=
goOtherActivity
(
function
(
file
){
// 展示捕捉到的声明周期日志
console
.
log
(
file
);
that
.
selectImage
=
"
file://
"
+
file
;
});
if
(
!
ret
){
uni
.
showToast
({
title
:
'
请授予权限后重试
'
})
}
}
}
}
}
}
</
script
>
</
script
>
...
...
pages/resource/resource.vue
浏览文件 @
6bb96332
<
template
>
<
template
>
<view>
<view>
<page-head
:title=
"title"
></page-head>
<page-head
:title=
"title"
></page-head>
<image
:src=
"logo"
mode=
"aspectFit"
style=
"width: 100%;"
></image>
<image
:src=
"logo"
mode=
"aspectFit"
style=
"width: 100%;"
></image>
<view
class=
"uni-btn-v uni-common-mt"
>
<button
type=
"primary"
@
tap=
"testLogoLoad"
>
展示插件内置图片
</button>
</view>
</view>
</view>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
getLogoPath
,
playAssetAudio
}
from
'
../../uni_modules/uts-toast
'
import
{
getLogoPath
}
from
'
../../uni_modules/uts-advance
'
export
default
{
export
default
{
...
@@ -21,13 +19,8 @@
...
@@ -21,13 +19,8 @@
},
},
onLoad
:
function
(){
onLoad
:
function
(){
this
.
logo
=
getLogoPath
()
this
.
logo
=
getLogoPath
()
console
.
log
(
"
getLogoPath
"
);
},
methods
:
{
testLogoLoad
(){
this
.
logo
=
getLogoPath
()
}
}
}
}
}
</
script
>
</
script
>
...
...
uni_modules/uts-advance/utssdk/app-android/index.uts
浏览文件 @
6bb96332
...
@@ -5,15 +5,28 @@ import ViewGroup from "android.view.ViewGroup";
...
@@ -5,15 +5,28 @@ import ViewGroup from "android.view.ViewGroup";
import Gravity from "android.view.Gravity";
import Gravity from "android.view.Gravity";
import Runnable from 'java.lang.Runnable';
import Runnable from 'java.lang.Runnable';
import MediaPlayer from 'android.media.MediaPlayer';
import MediaPlayer from 'android.media.MediaPlayer';
import Log from 'android.util.Log';
import Intent from 'android.content.Intent';
import logo from "../../static/logo.png";
import logo from "../../static/logo.png";
import PackageManager from "android.content.pm.PackageManager";
import PackageManager from "android.content.pm.PackageManager";
import MediaStore from "android.provider.MediaStore";
import Bundle from "android.os.Bundle";
import ActivityCompat from "androidx.core.app.ActivityCompat";
import Manifest from "android.Manifest";
import Activity from "android.app.Activity";
import Bitmap from "android.graphics.Bitmap";
import FileOutputStream from "java.io.FileOutputStream";
import {
import {
onAppActivityDestroy,
onAppActivityDestroy,
onAppActivityPause,
onAppActivityPause,
onAppActivityResume,
onAppActivityResume,
onAppActivityBack,
onAppActivityBack,
onAppActivityStop,
onAppActivityResult,
onAppTrimMemory,
onAppConfigChange,
getUniActivity,
getUniActivity,
getAppContext
getAppContext
} from "io.dcloud.uts.android";
} from "io.dcloud.uts.android";
...
@@ -179,7 +192,44 @@ export function playAssetAudio() {
...
@@ -179,7 +192,44 @@ export function playAssetAudio() {
}
}
export function goOtherActivity(imageDone: (event:string) => void):boolean {
// 检查相关权限是否已经具备
if (ActivityCompat.checkSelfPermission(getUniActivity()!, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// 不具备权限,申请权限,并且告知用户监听失败
ActivityCompat.requestPermissions(getUniActivity()!, arrayOf(Manifest.permission.CAMERA), 1002)
return false;
}
onAppActivityResult((requestCode: Int, resultCode: Int, data?: Intent) => {
let eventName = "onAppActivityResult - requestCode:" + requestCode + " -resultCode:"+resultCode + " -data:"+JSON.stringify(data);
console.log(eventName);
if ((requestCode == 1001) && (resultCode == Activity.RESULT_OK)) {
if (data != null) {
let bundle = data.getExtras();
let mImageBitmap = bundle!.get("data") as Bitmap;
let bitmapPath = getUniActivity()!.getExternalCacheDir()!.getPath() + "/photo.png"
console.log(bitmapPath);
try{
mImageBitmap.compress(Bitmap.CompressFormat.PNG,100,new FileOutputStream(bitmapPath))
}catch(e){
}
imageDone(bitmapPath);
}
}
});
let takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//resolveActivity 返回可处理 Intent 的第一个 Activity 组件
if (takePictureIntent.resolveActivity(getUniActivity()!.getPackageManager()) != null) {
getUniActivity()!.startActivityForResult(takePictureIntent, 1001);
}
return true;
}
/**
/**
...
@@ -188,21 +238,40 @@ export function playAssetAudio() {
...
@@ -188,21 +238,40 @@ export function playAssetAudio() {
*/
*/
export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
onAppTrimMemory((level:Number) => {
let eventName = "onAppTrimMemory - " + level;
onLifecycleChange(eventName);
console.log(eventName);
});
onAppConfigChange((ret:UTSJSONObject) => {
let eventName = "onAppConfigChange - " + JSON.stringify(ret);
onLifecycleChange(eventName);
console.log(eventName);
});
/**
/**
* activity 销毁生命周期回调
* activity 销毁生命周期回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitydestroy
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitydestroy
*/
*/
onAppActivityDestroy(() => {
onAppActivityDestroy(() => {
let eventName = "onAppActivityDestroy
- " + Date.now()
;
let eventName = "onAppActivityDestroy
"
;
onLifecycleChange(eventName);
onLifecycleChange(eventName);
console.log(eventName);
console.log(eventName);
});
});
/**
/**
* activity 失去焦点生命周期回调
* activity 失去焦点生命周期回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitypause
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitypause
*/
*/
onAppActivityPause(() => {
onAppActivityPause(() => {
let eventName = "onAppActivityPause
- " + Date.now()
;
let eventName = "onAppActivityPause
"
;
onLifecycleChange(eventName);
onLifecycleChange(eventName);
console.log(eventName);
console.log(eventName);
});
});
...
@@ -211,7 +280,7 @@ export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
...
@@ -211,7 +280,7 @@ export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityresume
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityresume
*/
*/
onAppActivityResume(() => {
onAppActivityResume(() => {
let eventName = "onAppActivityResume
- " + Date.now()
;
let eventName = "onAppActivityResume
"
;
onLifecycleChange(eventName);
onLifecycleChange(eventName);
console.log(eventName);
console.log(eventName);
});
});
...
@@ -220,7 +289,7 @@ export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
...
@@ -220,7 +289,7 @@ export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityback
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityback
*/
*/
onAppActivityBack(() => {
onAppActivityBack(() => {
let eventName = "onAppActivityBack
- " + Date.now()
;
let eventName = "onAppActivityBack
"
;
onLifecycleChange(eventName);
onLifecycleChange(eventName);
console.log(eventName);
console.log(eventName);
});
});
...
...
uni_modules/uts-nativepage/utssdk/app-android/index.uts
浏览文件 @
6bb96332
...
@@ -40,7 +40,7 @@ class ForeService extends Service {
...
@@ -40,7 +40,7 @@ class ForeService extends Service {
}
}
override onBind(intent?: Intent): IBinder|null{
override onBind(
_
intent?: Intent): IBinder|null{
return null;
return null;
}
}
...
@@ -98,7 +98,7 @@ class ScreenReceiver extends BroadcastReceiver{
...
@@ -98,7 +98,7 @@ class ScreenReceiver extends BroadcastReceiver{
super();
super();
}
}
override onReceive(context: Context, intent: Intent):void {
override onReceive(
_
context: Context, intent: Intent):void {
if (Intent.ACTION_SCREEN_OFF == intent.action) {
if (Intent.ACTION_SCREEN_OFF == intent.action) {
console.log("==屏幕休眠了")
console.log("==屏幕休眠了")
}
}
...
...
uni_modules/uts-toast/utssdk/app-android/config.json
已删除
100644 → 0
浏览文件 @
5147afd5
{
"abis"
:
[
"arm64-v8a"
],
"minSdkVersion"
:
21
}
uni_modules/uts-toast/utssdk/app-android/index.uts
浏览文件 @
6bb96332
...
@@ -5,21 +5,14 @@ import {
...
@@ -5,21 +5,14 @@ import {
import XToast from "com.hjq.xtoast.XToast";
import XToast from "com.hjq.xtoast.XToast";
import R from "io.dcloud.uni_modules.uts_toast.R";
import R from "io.dcloud.uni_modules.uts_toast.R";
export function
getLogoPath
():string{
export function
showToast
():string{
// new XToast<Any>(getUniActivity())
new XToast<XToast<unknown>>(getUniActivity())
// .setDuration(1000)
// .setContentView(R.layout.window_hint)
// .setImageDrawable(android.R.id.icon, android.R.mipmap.sym_def_app_icon)
// .setText(android.R.id.message, "一秒后自动消失")
// .show();
XToast<XToast<Any>>(getUniActivity())
.setDuration(1000)
.setDuration(1000)
.setContentView(R.layout.window_hint)
.setContentView(R.layout.window_hint)
.setImageDrawable(android.R.id.icon, android.R.mipmap.sym_def_app_icon)
.setImageDrawable(android.R.id.icon, android.R.mipmap.sym_def_app_icon)
.setText(android.R.id.message, "一秒后自动消失")
.setText(android.R.id.message, "一秒后自动消失")
.show()
.show()
return "
hello toast
"
return ""
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录