提交 1b7ead4b 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

Merge branch 'dev' into XHY

* dev:
  添加 uts alert 示例
  nativepage 插件增加 thread示例
  修改电量插件名称为 uts--getbatteryinfo
  腾讯定位使用 gradle 引入依赖
  lifecycle 增加取消生命周期监听
  截屏监听 优化部分告警

# Conflicts:
#	uni_modules/uts-alert/utssdk/app-ios/index.uts
......@@ -38,7 +38,7 @@
</template>
<script>
import gotoDemoActivity from "@/uni_modules/uts-nativepage";
import getBatteryInfo from "@/uni_modules/uni-getbatteryinfo";
import getBatteryInfo from "@/uni_modules/uts-getbatteryinfo";
export default {
......
......@@ -4,6 +4,7 @@
<page-head :title="title"></page-head>
<button @tap="testGoOtherActivity">跳转选择界面</button>
<image :src="selectImage" v-if="selectImage"></image>
<button @tap="testUnRegLifecycle">取消注册周期函数</button>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
......@@ -20,7 +21,7 @@
</view>
</template>
<script>
import { initAppLifecycle,goOtherActivity } from '../../uni_modules/uts-advance';
import { initAppLifecycle,unRegLifecycle,goOtherActivity } from '../../uni_modules/uts-advance';
export default {
data() {
return {
......@@ -52,6 +53,10 @@
title:'请授予权限后重试'
})
}
},
testUnRegLifecycle(){
// 取消注册生命周期
unRegLifecycle();
}
}
}
......
......@@ -21,16 +21,21 @@ import Toast from 'android.widget.Toast';
import AlertDialog from 'android.app.AlertDialog';
import DialogInterface from 'android.content.DialogInterface';
import EditText from 'android.widget.EditText';
import R from 'io.dcloud.uni_modules.uts_advance.R';
import {
onAppActivityDestroy,
offAppActivityDestroy,
onAppActivityPause,
offAppActivityPause,
onAppActivityResume,
offAppActivityResume,
onAppActivityBack,
offAppActivityBack,
onAppActivityResult,
onAppTrimMemory,
offAppTrimMemory,
onAppConfigChange,
offAppConfigChange,
getUniActivity,
getAppContext
} from "io.dcloud.uts.android";
......@@ -391,3 +396,40 @@ export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
}
/**
* 取消注册生命周期函数
*/
export function unRegLifecycle() {
/**
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onapptrimmemory
*/
offAppTrimMemory();
/**
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onAppConfigChange
*/
offAppConfigChange();
/**
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitydestroy
*/
offAppActivityDestroy();
/**
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitypause
*/
offAppActivityPause();
/**
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityresume
*/
offAppActivityResume();
/**
* activity 回退物理按键事件回调
*/
offAppActivityBack();
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ export function showAlert(title: string|null, message: string|null, result: (ind
alert.addAction(okAction)
alert.addAction(cancelAction)
// 从 uniViewController 打开 alert 弹窗
// 打开 alert 弹窗
DCUTS.getCurrentViewController().present(alert, animated= true)
})
}
......@@ -57,7 +57,7 @@ export function showPrompt(title: string|null, message: string|null,placeholder:
// 将 UIAlertAction 添加到 alert 上
alert.addAction(okAction)
// 从 uniViewController 打开 alert 弹窗
// 打开 alert 弹窗
DCUTS.getCurrentViewController().present(alert, animated= true)
})
}
\ No newline at end of file
{
"id": "uni-getbatteryinfo",
"displayName": "uni-getbatteryinfo",
"id": "uts-getbatteryinfo",
"displayName": "uts-getbatteryinfo",
"version": "1.2.0",
"description": "使用uts开发,实现在多个平台获取电池电量功能",
"keywords": [
......
# uni-getbatteryinfo
# uts-getbatteryinfo
## 使用文档
```ts
// 获取电量信息
uni.getBatteryInfo({
import getBatteryInfo from "@/uni_modules/uts-getbatteryinfo";
// 获取电量信息
getBatteryInfo({
success(res) {
console.log(res);
uni.showToast({
title: "当前电量:" + res.level + '%',
icon: 'none'
});
}
})
```
......
......@@ -16,6 +16,7 @@ import Build from 'android.os.Build';
import IBinder from 'android.os.IBinder';
import Toast from 'android.widget.Toast';
import {
getUniActivity,
getAppContext
......@@ -23,6 +24,7 @@ import {
import Service from 'android.app.Service';
import System from 'java.lang.System';
import Looper from 'android.os.Looper';
......@@ -141,8 +143,30 @@ class StartBroadcastListener extends OnClickListener{
}
}
class StartThreadListener extends OnClickListener{
override onClick(v?: View):void{
new CustomThread().start()
// 提示屏幕状态监听已经注册
Toast.makeText(getAppContext(),"自定义线程已开启,注意观察控制台输出",Toast.LENGTH_LONG).show();
}
}
/**
* 自定义异步线程
*/
class CustomThread extends Thread{
constructor(){
super();
}
override run(){
Thread.sleep(1000)
console.log("CustomThread = " + Thread.currentThread().getName())
}
}
class DemoActivity extends Activity{
......@@ -160,17 +184,25 @@ class DemoActivity extends Activity{
let btn_start_screen_listen = findViewById<Button>(R.id.btn_start_screen_listen);
btn_start_screen_listen.setOnClickListener(new StartBroadcastListener());
let btn_start_thread = findViewById<Button>(R.id.btn_start_thread);
btn_start_thread.setOnClickListener(new StartThreadListener());
}
}
export default function gotoDemoActivity() {
// 跳转到一个新的界面
class IntentRunable extends Runnable{
override run(){
console.log("IntentRunable = " + Thread.currentThread().getName())
let intent = new Intent(getUniActivity(),DemoActivity().javaClass);
getUniActivity()!.startActivity(intent);
}
}
// var a = new DemoActivity();
export default function gotoDemoActivity() {
// 跳转到一个新的界面
getUniActivity()!.runOnUiThread(new IntentRunable())
return { name: "gotoDemoActivity"};
}
......
......@@ -7,4 +7,5 @@
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="demo text"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启前台服务(应用包活)" android:id="@+id/btn_start_service_front"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册屏幕状态广播监听" android:id="@+id/btn_start_screen_listen"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启异步任务" android:id="@+id/btn_start_thread"/>
</LinearLayout>
\ No newline at end of file
......@@ -45,7 +45,7 @@ class ScreenFileObserver extends FileObserver {
constructor(screenFile: string) {
super(screenFile)
super(new File(screenFile))
this.allScreen = new File(screenFile);
}
......
......@@ -3,6 +3,7 @@
"arm64-v8a"
],
"dependencies": [
"com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.4.9"
],
"minSdkVersion": 21
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册