提交 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 @@ ...@@ -38,7 +38,7 @@
</template> </template>
<script> <script>
import gotoDemoActivity from "@/uni_modules/uts-nativepage"; import gotoDemoActivity from "@/uni_modules/uts-nativepage";
import getBatteryInfo from "@/uni_modules/uni-getbatteryinfo"; import getBatteryInfo from "@/uni_modules/uts-getbatteryinfo";
export default { export default {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<button @tap="testGoOtherActivity">跳转选择界面</button> <button @tap="testGoOtherActivity">跳转选择界面</button>
<image :src="selectImage" v-if="selectImage"></image> <image :src="selectImage" v-if="selectImage"></image>
<button @tap="testUnRegLifecycle">取消注册周期函数</button>
<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函数注册了生命周期监听。
...@@ -20,7 +21,7 @@ ...@@ -20,7 +21,7 @@
</view> </view>
</template> </template>
<script> <script>
import { initAppLifecycle,goOtherActivity } from '../../uni_modules/uts-advance'; import { initAppLifecycle,unRegLifecycle,goOtherActivity } from '../../uni_modules/uts-advance';
export default { export default {
data() { data() {
return { return {
...@@ -52,6 +53,10 @@ ...@@ -52,6 +53,10 @@
title:'请授予权限后重试' title:'请授予权限后重试'
}) })
} }
},
testUnRegLifecycle(){
// 取消注册生命周期
unRegLifecycle();
} }
} }
} }
......
...@@ -21,16 +21,21 @@ import Toast from 'android.widget.Toast'; ...@@ -21,16 +21,21 @@ import Toast from 'android.widget.Toast';
import AlertDialog from 'android.app.AlertDialog'; import AlertDialog from 'android.app.AlertDialog';
import DialogInterface from 'android.content.DialogInterface'; import DialogInterface from 'android.content.DialogInterface';
import EditText from 'android.widget.EditText'; import EditText from 'android.widget.EditText';
import R from 'io.dcloud.uni_modules.uts_advance.R';
import { import {
onAppActivityDestroy, onAppActivityDestroy,
offAppActivityDestroy,
onAppActivityPause, onAppActivityPause,
offAppActivityPause,
onAppActivityResume, onAppActivityResume,
offAppActivityResume,
onAppActivityBack, onAppActivityBack,
offAppActivityBack,
onAppActivityResult, onAppActivityResult,
onAppTrimMemory, onAppTrimMemory,
offAppTrimMemory,
onAppConfigChange, onAppConfigChange,
offAppConfigChange,
getUniActivity, getUniActivity,
getAppContext getAppContext
} from "io.dcloud.uts.android"; } from "io.dcloud.uts.android";
...@@ -391,3 +396,40 @@ export function initAppLifecycle(onLifecycleChange: (event:string) => void) { ...@@ -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 ...@@ -25,7 +25,7 @@ export function showAlert(title: string|null, message: string|null, result: (ind
alert.addAction(okAction) alert.addAction(okAction)
alert.addAction(cancelAction) alert.addAction(cancelAction)
// 从 uniViewController 打开 alert 弹窗 // 打开 alert 弹窗
DCUTS.getCurrentViewController().present(alert, animated= true) DCUTS.getCurrentViewController().present(alert, animated= true)
}) })
} }
...@@ -57,7 +57,7 @@ export function showPrompt(title: string|null, message: string|null,placeholder: ...@@ -57,7 +57,7 @@ export function showPrompt(title: string|null, message: string|null,placeholder:
// 将 UIAlertAction 添加到 alert 上 // 将 UIAlertAction 添加到 alert 上
alert.addAction(okAction) alert.addAction(okAction)
// 从 uniViewController 打开 alert 弹窗 // 打开 alert 弹窗
DCUTS.getCurrentViewController().present(alert, animated= true) DCUTS.getCurrentViewController().present(alert, animated= true)
}) })
} }
\ No newline at end of file
{ {
"id": "uni-getbatteryinfo", "id": "uts-getbatteryinfo",
"displayName": "uni-getbatteryinfo", "displayName": "uts-getbatteryinfo",
"version": "1.2.0", "version": "1.2.0",
"description": "使用uts开发,实现在多个平台获取电池电量功能", "description": "使用uts开发,实现在多个平台获取电池电量功能",
"keywords": [ "keywords": [
......
# uni-getbatteryinfo # uts-getbatteryinfo
## 使用文档 ## 使用文档
```ts ```ts
// 获取电量信息
uni.getBatteryInfo({ import getBatteryInfo from "@/uni_modules/uts-getbatteryinfo";
success(res) { // 获取电量信息
console.log(res); getBatteryInfo({
uni.showToast({ success(res) {
title: "当前电量:" + res.level + '%', uni.showToast({
icon: 'none' title: "当前电量:" + res.level + '%',
}); icon: 'none'
} });
}
}) })
``` ```
......
...@@ -32,4 +32,4 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) { ...@@ -32,4 +32,4 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
options.fail?.(res) options.fail?.(res)
options.complete?.(res) options.complete?.(res)
} }
} }
...@@ -16,6 +16,7 @@ import Build from 'android.os.Build'; ...@@ -16,6 +16,7 @@ import Build from 'android.os.Build';
import IBinder from 'android.os.IBinder'; import IBinder from 'android.os.IBinder';
import Toast from 'android.widget.Toast'; import Toast from 'android.widget.Toast';
import { import {
getUniActivity, getUniActivity,
getAppContext getAppContext
...@@ -23,6 +24,7 @@ import { ...@@ -23,6 +24,7 @@ import {
import Service from 'android.app.Service'; import Service from 'android.app.Service';
import System from 'java.lang.System'; import System from 'java.lang.System';
import Looper from 'android.os.Looper';
...@@ -141,8 +143,30 @@ class StartBroadcastListener extends OnClickListener{ ...@@ -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{ class DemoActivity extends Activity{
...@@ -160,17 +184,25 @@ 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); let btn_start_screen_listen = findViewById<Button>(R.id.btn_start_screen_listen);
btn_start_screen_listen.setOnClickListener(new StartBroadcastListener()); btn_start_screen_listen.setOnClickListener(new StartBroadcastListener());
let btn_start_thread = findViewById<Button>(R.id.btn_start_thread);
btn_start_thread.setOnClickListener(new StartThreadListener());
} }
} }
class IntentRunable extends Runnable{
override run(){
console.log("IntentRunable = " + Thread.currentThread().getName())
let intent = new Intent(getUniActivity(),DemoActivity().javaClass);
getUniActivity()!.startActivity(intent);
}
}
export default function gotoDemoActivity() { export default function gotoDemoActivity() {
// 跳转到一个新的界面 // 跳转到一个新的界面
let intent = new Intent(getUniActivity(),DemoActivity().javaClass); getUniActivity()!.runOnUiThread(new IntentRunable())
getUniActivity()!.startActivity(intent);
// var a = new DemoActivity();
return { name: "gotoDemoActivity"}; return { name: "gotoDemoActivity"};
} }
......
...@@ -7,4 +7,5 @@ ...@@ -7,4 +7,5 @@
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="demo text"/> <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_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_screen_listen"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启异步任务" android:id="@+id/btn_start_thread"/>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -45,7 +45,7 @@ class ScreenFileObserver extends FileObserver { ...@@ -45,7 +45,7 @@ class ScreenFileObserver extends FileObserver {
constructor(screenFile: string) { constructor(screenFile: string) {
super(screenFile) super(new File(screenFile))
this.allScreen = new File(screenFile); this.allScreen = new File(screenFile);
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"arm64-v8a" "arm64-v8a"
], ],
"dependencies": [ "dependencies": [
"com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.4.9"
], ],
"minSdkVersion": 21 "minSdkVersion": 21
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册