82 lines
2.1 KiB
Plaintext
82 lines
2.1 KiB
Plaintext
import FrameLayout from "android.widget.FrameLayout";
|
|
import { xCamreaUOpts } from '../../utssdk/interface';
|
|
import { xCamrea } from "./libs/camrea.uts"
|
|
import LinearLayout from 'android.widget.LinearLayout';
|
|
import Color from 'android.graphics.Color';
|
|
import View from "android.view.View";
|
|
import ViewGroup from 'android.view.ViewGroup';
|
|
import TextView from 'android.widget.TextView'
|
|
|
|
/**
|
|
* 检查相机权限
|
|
*/
|
|
export function checkPermissions() : Promise<boolean> {
|
|
let permissionCheck = ["android.permission.CAMERA"]
|
|
return new Promise((res, rej) => {
|
|
if (UTSAndroid.checkSystemPermissionGranted(UTSAndroid.getUniActivity()!, permissionCheck)) {
|
|
res(true)
|
|
} else {
|
|
console.log("当前不具备指定权限")
|
|
// 请求拍照权限
|
|
UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permissionCheck, function (a : boolean, _ : string[]) {
|
|
res(true)
|
|
}, function (a : boolean, _ : string[]) {
|
|
//用户拒绝了部分权限
|
|
rej(false)
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
export class xCamreaU {
|
|
viewBox_width = 0;
|
|
viewBox_height = 0;
|
|
$element : UniNativeViewElement;
|
|
targetView : FrameLayout | null = null;
|
|
config : xCamreaUOpts;
|
|
camera : xCamrea | null = null;
|
|
constructor(element : UniNativeViewElement, opts : xCamreaUOpts) {
|
|
this.config = opts;
|
|
this.$element = element;
|
|
this.bindView();
|
|
this.camera = new xCamrea(this.targetView!)
|
|
}
|
|
bindView() {
|
|
let layview = new FrameLayout(this.$element.getAndroidActivity()!);
|
|
this.targetView = layview
|
|
this.$element.bindAndroidView(this.targetView!);
|
|
}
|
|
getIsOpeningCameraing() : boolean {
|
|
return this.camera!.getIsOpeningCameraing()
|
|
}
|
|
setCameraDir(dir : string) {
|
|
this.camera!.setCameraDir(dir)
|
|
}
|
|
setFlash(flash : boolean) {
|
|
this.camera!.setFlash(flash)
|
|
}
|
|
openCamrea() {
|
|
this.camera!.openCamrea()
|
|
}
|
|
|
|
takePhoto(call : (path : string) => void) {
|
|
this.camera!.takePhoto(call)
|
|
}
|
|
start(call : (path : string) => void) {
|
|
this.camera!.startRecoderVideo(call)
|
|
}
|
|
pause() {
|
|
this.camera!.pauseRecoderVideo()
|
|
}
|
|
|
|
stop() {
|
|
this.camera!.stopRecoderVideo()
|
|
}
|
|
|
|
/** 关闭相机 */
|
|
close() {
|
|
this.camera!.closeCamrea()
|
|
}
|
|
|
|
} |