提交 628a4a4a 编写于 作者: 杜庆泉's avatar 杜庆泉

修改uts插件 可能出现编译告警的源码

上级 531e8c82
......@@ -7,7 +7,7 @@
<button type="primary" @tap="testScreenShotPremission">准备截屏监听权限</button>
<button type="primary" @tap="testScreenShotListen">监听截屏事件</button>
<button type="primary" @tap="testScreenShotOff">关闭截屏监听</button>
<image :src="screenImage" class="screenImage" mode="aspectFit"></image>
<image :src="screenImage" class="screenImage" mode="aspectFit" ></image>
</view>
</view>
</template>
......@@ -24,7 +24,7 @@
data() {
return {
title: '系统API示例',
screenImage:"../../static/logo.png"
screenImage:""
}
},
onUnload: function() {},
......
......@@ -2,68 +2,57 @@
<view>
<page-head :title="title"></page-head>
<uni-section title="任务" type="line">
<uni-collapse>
<uni-collapse-item title="延迟任务">
<button type="primary" @tap="testTimer">延迟任务</button>
</uni-collapse-item>
<uni-collapse>
<uni-collapse-item title="延迟任务">
<button @tap="testTimer" class="itemButton">开启延迟任务</button>
</uni-collapse-item>
<uni-collapse-item title="定时任务">
<button type="primary" @tap="testInterval">定时任务</button>
<button type="primary" @tap="testClearInterval">关闭定时任务</button>
</uni-collapse-item>
<uni-collapse-item title="定时任务">
<button @tap="testInterval" class="itemButton">开启定时任务</button>
<button @tap="testClearInterval" class="itemButton">关闭定时任务</button>
</uni-collapse-item>
</uni-collapse>
</uni-collapse>
</uni-section>
<uni-collapse>
<uni-collapse-item title="进阶语法示例">
<button type="primary" class="itemButton" @tap="testSyntax">进阶语法示例</button>
</uni-collapse-item>
</uni-collapse>
<uni-section title="语法" type="line">
<uni-collapse>
<uni-collapse-item title="进阶语法示例">
<button type="primary" @tap="testSyntax">进阶语法示例</button>
</uni-collapse-item>
</uni-collapse>
</uni-section>
<uni-section title="资源" type="line">
<uni-collapse>
<uni-collapse-item title="资源加载">
<button type="primary" @tap="gotoResourceDemo">资源加载示例</button>
</uni-collapse-item>
</uni-collapse>
</uni-section>
<uni-collapse>
<uni-collapse-item title="图片加载示例">
<button type="primary" @tap="gotoResourceDemo" class="itemButton">资源加载示例</button>
</uni-collapse-item>
<uni-collapse-item title="asset操作示例">
<button type="primary" class="itemButton">播放asset音频(需自定义基座)</button>
</uni-collapse-item>
<uni-section title="内置函数" type="line">
<uni-collapse>
<uni-collapse-item title="生命周期">
<button type="primary" @tap="testLifecyle">activity生命周期监听</button>
</uni-collapse-item>
</uni-collapse>
</uni-section>
<uni-section title="原生UI" type="line">
<uni-collapse>
<uni-collapse-item title="DecorView操作示例">
<button type="primary" @tap="testAddToDecorView">添加TextView至视图顶层</button>
<button type="primary" @tap="testRemoveToDecorView">移除视图顶层的TextView</button>
</uni-collapse-item>
</uni-collapse>
</uni-section>
</uni-collapse>
<uni-collapse>
<uni-collapse-item title="生命周期">
<button type="primary" @tap="testLifecyle" class="itemButton">activity生命周期监听</button>
</uni-collapse-item>
</uni-collapse>
<uni-collapse>
<uni-collapse-item title="DecorView操作示例">
<button type="primary" @tap="testAddToDecorView" class="itemButton">添加TextView至视图顶层</button>
<button type="primary" @tap="testRemoveToDecorView" class="itemButton">移除视图顶层的TextView</button>
</uni-collapse-item>
</uni-collapse>
</view>
......@@ -270,6 +259,10 @@
</script>
<style>
.itemButton {
margin-top: 5px;
margin-bottom: 5px;
margin-left: 10px;
margin-right: 10px;
}
</style>
import Rect from "android.graphics.Rect";
import Color from "android.graphics.Color";
import TextView from "android.widget.TextView";
import FrameLayout from "android.widget.FrameLayout";
import ViewGroup from "android.view.ViewGroup";
import Gravity from "android.view.Gravity";
import Runnable from 'java.lang.Runnable';
import Exception from 'java.lang.Exception';
import MediaPlayer from 'android.media.MediaPlayer';
import logo from "../../static/logo.png";
......
......@@ -46,14 +46,14 @@ class ForeService extends Service {
override onStartCommand(intent:Intent ,flags:Int ,startId:Int ):Int {
let mBuilder = new NotificationCompat.Builder(this);
let mBuilder = new NotificationCompat.Builder(this,"uts-test");
mBuilder.setAutoCancel(true) // 点击后让通知将消失
mBuilder.setContentText("测试")
mBuilder.setContentTitle("测试")
mBuilder.setWhen(System.currentTimeMillis()) //通知产生的时间,会在通知信息里显示
mBuilder.setPriority(Notification.PRIORITY_DEFAULT) //设置该通知优先级
mBuilder.setPriority(NotificationManager.IMPORTANCE_DEFAULT) //设置该通知优先级
mBuilder.setOngoing(false) //ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接)
mBuilder.setDefaults(Notification.DEFAULT_ALL) //向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
......
import {
onAppActivityDestroy,
onAppActivityPause,
onAppActivityResume,
onAppActivityBack,
getUniActivity,
getAppContext
getUniActivity
} from "io.dcloud.uts.android";
......@@ -23,7 +18,6 @@ import Cursor from "android.database.Cursor";
import ContentObserver from "android.database.ContentObserver";
import Uri from "android.net.Uri";
import BitmapFactory from "android.graphics.BitmapFactory";
import Display from "android.view.Display";
import Locale from "java.util.Locale";
import WindowManager from "android.view.WindowManager";
import FileObserver from "android.os.FileObserver";
......@@ -35,7 +29,7 @@ import Environment from "android.os.Environment";
* 读取媒体数据库时需要读取的列,其中 width、height 字段在 API 16 之后才有
*/
const MEDIA_PROJECTIONS_API_16 = arrayOf(
MediaStore.Images.ImageColumns.DATA,
"_data",
MediaStore.Images.ImageColumns.DATE_TAKEN,
MediaStore.Images.ImageColumns.WIDTH,
MediaStore.Images.ImageColumns.HEIGHT
......@@ -63,19 +57,24 @@ class ScreenFileObserver extends FileObserver {
constructor(screenFile: File) {
super(screenFile)
this.allScreen = screenFile;
console.log(allScreen);
}
override onEvent(event: Int, path?: String): void {
if (event == FileObserver.CREATE) {
var newPath: string = new File(allScreen, path).path;
let newPath: string = new File(allScreen, path!).path;
let currentTime = System.currentTimeMillis();
if ((currentTime - lastFileObserverTime) < 1000) {
// 本地截屏行为比上一次超过1000ms,才认为是一个有效的时间
return;
}
console.log(path);
lastFileObserverTime = System.currentTimeMillis()
listenOption!.onImageCatchChange(newPath)
listenOption.onImageCatchChange(newPath)
}
}
}
......@@ -120,8 +119,7 @@ function handleMediaContentChange(contentUri: Uri) {
MEDIA_PROJECTIONS_API_16,
null, null,
MediaStore.Images.ImageColumns.DATE_ADDED + " desc limit 1"
)!
)
if (cursor == null) {
return
......@@ -132,7 +130,7 @@ function handleMediaContentChange(contentUri: Uri) {
}
// 获取各列的索引
let dataIndex = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA)
let dataIndex = cursor.getColumnIndex("_data")
let dateTakenIndex = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATE_TAKEN)
let widthIndex = cursor.getColumnIndex(MediaStore.Images.ImageColumns.WIDTH)
let heightIndex = cursor.getColumnIndex(MediaStore.Images.ImageColumns.HEIGHT)
......@@ -140,8 +138,8 @@ function handleMediaContentChange(contentUri: Uri) {
// 获取行数据
let data = cursor.getString(dataIndex)
let dateTaken = cursor.getLong(dateTakenIndex)
let width = 0;
let height = 0;
let width:number;
let height:number;
if (widthIndex >= 0 && heightIndex >= 0) {
width = cursor.getInt(widthIndex)
height = cursor.getInt(heightIndex)
......@@ -165,7 +163,7 @@ function handleMediaContentChange(contentUri: Uri) {
/**
* 获取媒体库内置图像的大小
*/
function getImageSize(imagePath: string): Point {
function getImageSize(imagePath: string): Point{
let options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeFile(imagePath, options)
......@@ -179,7 +177,7 @@ function handleMediaRowData(data: String, dateTaken: Long, width: Int, height: I
if (checkScreenShot(data, dateTaken, width, height)) {
if (!checkCallback(data)) {
listenOption!.onImageCatchChange(data)
listenOption.onImageCatchChange(data)
}
} else {
// 如果在观察区间媒体数据库有数据改变,又不符合截屏规则
......@@ -247,8 +245,13 @@ function getRealScreenSize(): Point | null {
let screenSize: Point = Point();
try {
let windowManager = getUniActivity()!.getSystemService(Context.WINDOW_SERVICE) as WindowManager
let defaultDisplay = windowManager.defaultDisplay
defaultDisplay.getRealSize(screenSize)
screenSize.x = windowManager.currentWindowMetrics.bounds.width();
screenSize.y = windowManager.currentWindowMetrics.bounds.height();
// let defaultDisplay = windowManager.defaultDisplay
// let defaultDisplay = getUniActivity()!.display
// defaultDisplay!.getRealSize(screenSize)
console.log(screenSize);
} catch (e) {
e.printStackTrace()
}
......@@ -302,13 +305,25 @@ export function requestPremission() {
*/
export function onUserCaptureScreen(success: (res: string) => void) {
listenOption.onImageCatchChange = success;
console.log(Build.VERSION.SDK_INT);
console.log(Build.VERSION_CODES.Q);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// android 10 以上版本,使用监听文件的方式,更加可靠
var directory_screenshot: File;
let directory_screenshot: File;
var directory_pictures = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES);
var directory_dcim = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM);
// let directory_pictures = getUniActivity()!.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
// let directory_dcim = getUniActivity()!.getExternalFilesDir(Environment.DIRECTORY_DCIM)
let directory_pictures = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES);
let directory_dcim = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM);
console.log(directory_pictures);
console.log(directory_dcim);
// console.log(directory_pictures2);
// console.log(directory_dcim2);
if (Build.MANUFACTURER.equals("Xiaomi", true)) {
directory_screenshot = File(directory_dcim, "Screenshots");
......@@ -349,6 +364,7 @@ export function onUserCaptureScreen(success: (res: string) => void) {
* 关闭截屏监听
*/
export function offUserCaptureScreen(success: (res: string) => void) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// android 10以上,关闭监听通过移除文件监听器实现
if (screenOB != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册