提交 1c2973bd 编写于 作者: T tianwenzhe

add camera

Signed-off-by: Ntian-wenzhe411 <tianwenzhe2@huawei.com>
上级 59a2d656
...@@ -18,7 +18,7 @@ export default class MainAbility extends Ability { ...@@ -18,7 +18,7 @@ export default class MainAbility extends Ability {
console.log("[Demo] MainAbility onWindowStageCreate") console.log("[Demo] MainAbility onWindowStageCreate")
let AtManager = abilityAccessCtrl.createAtManager(); let AtManager = abilityAccessCtrl.createAtManager();
AtManager.requestPermissionsFromUser(this.context,["ohos.permission.READ_MEDIA","ohos.permission.WRITE_MEDIA", AtManager.requestPermissionsFromUser(this.context,["ohos.permission.READ_MEDIA","ohos.permission.WRITE_MEDIA",
"ohos.permission.CAPTURE_SCREEN","ohos.permission.INTERNET"]).then(() => {}) "ohos.permission.CAPTURE_SCREEN","ohos.permission.INTERNET","ohos.permission.CAMERA"]).then(() => {})
windowStage.loadContent("pages/index", (err, data) => { windowStage.loadContent("pages/index", (err, data) => {
if (err.code) { if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err)); console.error('Failed to load the content. Cause:' + JSON.stringify(err));
......
...@@ -18,24 +18,27 @@ import fileio from '@ohos.fileio'; ...@@ -18,24 +18,27 @@ import fileio from '@ohos.fileio';
import xml from '@ohos.xml'; import xml from '@ohos.xml';
import fileIO from '@ohos.fileio'; import fileIO from '@ohos.fileio';
import util from '@ohos.util'; import util from '@ohos.util';
import data_preferences from '@ohos.data.preferences';
const TAG = 'ParseXML'; const TAG = 'ParseXML';
let path = globalThis.dir; let path = globalThis.dir;
let path1; let path1 = path + '/ArkUI';
path1 = path + '/ArkUI';
let VarColor = [];
let ColorBackPath = path + '/ArkUIColorBack.txt';
let txtPath = path1 + 'ArkUIReport.txt';
let xmlPath =path1 + 'ArkUITest.xml';
@Entry @Entry
@Component @Component
struct IndexPage { struct IndexPage {
@State BackColor: string = '#ff808080';
@State ClearAll : boolean = false; @State ClearAll : boolean = false;
private current : number = undefined; private current : number = undefined;
@State count : number = 0; @State count : number = 0;
@State result : string = ''; @State result : string = '';
@State TEST : number = 0;
private TestCaseList = [ private TestCaseList = [
{title:'Scroll List',uri:'pages/ArkUI/ScrollListTest'}, {title:'ScrollingList',uri:'pages/ArkUI/ScrollListTest'},
{title:'TouchMove',uri:'pages/ArkUI/TouchMoveTest'}, {title:'TouchMove',uri:'pages/ArkUI/TouchMoveTest'},
{title:'PinchGesture',uri:'pages/ArkUI/PinchGestureTest'}, {title:'PinchGesture',uri:'pages/ArkUI/PinchGestureTest'},
{title:'RotationGesture',uri:'pages/ArkUI/RotationGestureTest'}, {title:'RotationGesture',uri:'pages/ArkUI/RotationGestureTest'},
...@@ -60,28 +63,92 @@ struct IndexPage { ...@@ -60,28 +63,92 @@ struct IndexPage {
{title:'CanvasShadowOffsetY',uri:'pages/ArkUI/CanvasShadowOffsetY'}, {title:'CanvasShadowOffsetY',uri:'pages/ArkUI/CanvasShadowOffsetY'},
{title:'CanvasImageSmoothingEnabled',uri:'pages/ArkUI/CanvasImageSmoothingEnabled'}, {title:'CanvasImageSmoothingEnabled',uri:'pages/ArkUI/CanvasImageSmoothingEnabled'},
] ]
@State ColorObject : string[] = ['#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080', @State ColorObject : string[] = VarColor;
'#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080', async onPageShow(){
'#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080'] let Test = null;
onPageShow(){ let context =null;
context = globalThis.getContext();
let preferences;
let promise = data_preferences.getPreferences(context,'mystore');
await promise.then((object) => {
preferences = object;
});
promise = preferences.get('ArkUI', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'ArkUI'. Data: " + data);
});
if(Test != 1) {
let fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
for(let i = 0; i < this.TestCaseList.length; i++) {
let log = (this.TestCaseList[i].title+';'+'#ff808080'+';').toString();
fileio.writeSync(fd,log);
}
fileio.closeSync(fd);
}
promise = preferences.put('ArkUI', 1);
promise.then(() => {
console.info("Succeeded in putting value of 'ArkUI'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
this.TEST = Test;
let opt = fileio.openSync(ColorBackPath, 0o100 | 0o2002, 0o664);
let buff = new ArrayBuffer(40960);
fileio.readSync(opt,buff);
let ColorBack = String.fromCharCode.apply(null, new Uint8Array(buff));
let TestList = ColorBack.split(';');
for (let i = 0; i < Math.floor(TestList.length / 2); i++) {
VarColor[i] = TestList[i*2+1];
}
fileio.closeSync(opt);
if (this.count === 1){ if (this.count === 1){
this.result = router.getParams()['result']; this.result = router.getParams()['result'];
let titles = router.getParams()['title']; let titles = router.getParams()['title'];
let name1 = '刚刚点进了哪个用例:'+ titles; let name1 = '刚刚点进了哪个用例:'+ titles;
let results = this.result; let results = this.result;
let WriteTitle = (titles).toString();
let number = WriteTitle.length + 11;
let Index = ColorBack.indexOf(WriteTitle);
if (this.result === 'Pass'){ if (this.result === 'Pass'){
this.ColorObject[this.current] = '#ff008000'; this.ColorObject[this.current] = '#ff008000';
let Log = (titles+';'+'#ff008000'+';');
let key = ColorBack.substring(Index,Index+number);
let FD = fileio.openSync(ColorBackPath, 0o102, 0o666);
ColorBack = ColorBack.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = ColorBack.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
filewrite(name1,results,titles) filewrite(name1,results,titles)
} }
else if (this.result === 'Fail'){ else if (this.result === 'Fail'){
this.ColorObject[this.current] = '#ffff0000'; this.ColorObject[this.current] = '#ffff0000';
let Log = (titles+';'+'#ffff0000'+';');
let key = ColorBack.substring(Index,Index+number);
let FD = fileio.openSync(ColorBackPath, 0o102, 0o666);
ColorBack = ColorBack.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = ColorBack.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
filewrite(name1,results,titles); filewrite(name1,results,titles);
} }
else if (this.result === 'None'){ else if (this.result === 'None'){
this.ColorObject[this.current] = this.ColorObject[this.current]; this.ColorObject[this.current] = this.ColorObject[this.current];
} }
} }
} }
build(){ build(){
Column(){ Column(){
...@@ -164,8 +231,7 @@ struct IndexPage { ...@@ -164,8 +231,7 @@ struct IndexPage {
ListItem(){ ListItem(){
Row(){ Row(){
Text(item.title).fontSize(16).fontColor(Color.Black) Text(item.title).fontSize(16).fontColor(Color.Black)
Text(this.BackColor.toString()).visibility(Visibility.None) }.width('100%').height(50).alignItems(VerticalAlign.Center).backgroundColor(this.count===0&&this.TEST===0?'#ff808080':this.ColorObject[index])
}.width('100%').height(50).alignItems(VerticalAlign.Center).backgroundColor(this.ColorObject[index])
.onClick(( )=>{ .onClick(( )=>{
this.count = 1; this.count = 1;
this.ClearAll=false; this.ClearAll=false;
...@@ -182,6 +248,11 @@ struct IndexPage { ...@@ -182,6 +248,11 @@ struct IndexPage {
ClearText(){ ClearText(){
fileio.rmdirSync(path1); fileio.rmdirSync(path1);
fileio.mkdirSync(path1); fileio.mkdirSync(path1);
let fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
for(let i = 0; i < this.TestCaseList.length; i++) {
let log = (this.TestCaseList[i].title+';'+'#ff808080'+';').toString();
fileio.writeSync(fd,log);
}
} }
ReadTextParseXml(){ ReadTextParseXml(){
let ReportPath = path1 + '/ArkUIReport.txt'; let ReportPath = path1 + '/ArkUIReport.txt';
...@@ -252,7 +323,6 @@ struct IndexPage { ...@@ -252,7 +323,6 @@ struct IndexPage {
let that = new util.TextDecoder('utf-8'); let that = new util.TextDecoder('utf-8');
let array = new Uint8Array(arrayBuffer); let array = new Uint8Array(arrayBuffer);
let serializerStr = that.decode(array); let serializerStr = that.decode(array);
let xmlPath = path1 + "/ArkUITest.xml";
console.info(xmlPath); console.info(xmlPath);
try{ try{
console.error(TAG,"write xmlPath =" +xmlPath); console.error(TAG,"write xmlPath =" +xmlPath);
...@@ -268,8 +338,7 @@ struct IndexPage { ...@@ -268,8 +338,7 @@ struct IndexPage {
} }
} }
function filewrite(name1,results,titles){ function filewrite(name1,results,titles){
let txtpath = path1 + '/ArkUIReport.txt'; let fd = fileio.openSync(txtPath, 0o100 | 0o2002, 0o664);
let fd = fileio.openSync(txtpath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
let RD = fileio.readSync(fd,buf); let RD = fileio.readSync(fd,buf);
console.info("RRRRRRRRRRd"+RD); console.info("RRRRRRRRRRd"+RD);
...@@ -283,13 +352,13 @@ function filewrite(name1,results,titles){ ...@@ -283,13 +352,13 @@ function filewrite(name1,results,titles){
} }
else if (Index != -1){ else if (Index != -1){
let key = report.substring(Index,Index+number); let key = report.substring(Index,Index+number);
let FD = fileio.openSync(txtpath, 0o102, 0o666); let FD = fileio.openSync(txtPath, 0o102, 0o666);
report = report.replace(key,Log); report = report.replace(key,Log);
let buffer = new ArrayBuffer(4096); let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer); let rd = fileio.readSync(FD,buffer);
let Report = report.substring(0,rd); let Report = report.substring(0,rd);
fileio.closeSync(FD); fileio.closeSync(FD);
let Fd = fileio.openSync(txtpath, 0o102, 0o666); let Fd = fileio.openSync(txtPath, 0o102, 0o666);
fileio.writeSync(Fd,Report); fileio.writeSync(Fd,Report);
} }
} }
\ No newline at end of file
...@@ -20,7 +20,7 @@ struct SetCircle { ...@@ -20,7 +20,7 @@ struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true); private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
@State FillColor: string = '#FF000000'; @State FillColor: string = '#FF000000';
@State name: string = 'CanvasFillStyle'; @State name: string = 'CanvasFont';
@State StepTips: string = '操作步骤:点击不同的字体控件'+'\n'+'预期结果:原本默认字体会改变'; @State StepTips: string = '操作步骤:点击不同的字体控件'+'\n'+'预期结果:原本默认字体会改变';
@State Vue: boolean = false; @State Vue: boolean = false;
async aboutToAppear(){ async aboutToAppear(){
......
...@@ -18,7 +18,7 @@ import FirstDialog from '../model/FirstDialog'; ...@@ -18,7 +18,7 @@ import FirstDialog from '../model/FirstDialog';
@Component @Component
struct PinchGuestureTest { struct PinchGuestureTest {
@State X: number = 1; @State X: number = 1;
@State name: string = 'PinchGuesture'; @State name: string = 'PinchGesture';
@State StepTips: string = '操作步骤:用手指触摸捏合图片(至少2根手指,最大为5指)'+'\n'+'预期结果:图片能够被正常捏合放缩'; @State StepTips: string = '操作步骤:用手指触摸捏合图片(至少2根手指,最大为5指)'+'\n'+'预期结果:图片能够被正常捏合放缩';
@State Vue: boolean = false; @State Vue: boolean = false;
async aboutToAppear(){ async aboutToAppear(){
......
...@@ -18,7 +18,7 @@ import FirstDialog from '../model/FirstDialog'; ...@@ -18,7 +18,7 @@ import FirstDialog from '../model/FirstDialog';
@Component @Component
struct RotationGuestureTest { struct RotationGuestureTest {
@State X: number = 0; @State X: number = 0;
@State name: string = 'RotationGuesture'; @State name: string = 'RotationGesture';
@State StepTips: string = '操作步骤:用至少两根手指旋转图像(最多五根手指)'+'\n'+'预期结果:图片能够正常旋转'; @State StepTips: string = '操作步骤:用至少两根手指旋转图像(最多五根手指)'+'\n'+'预期结果:图片能够正常旋转';
@State Vue: boolean = false; @State Vue: boolean = false;
async aboutToAppear(){ async aboutToAppear(){
......
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import prompt from '@ohos.prompt';
import router from '@ohos.router';
import fileio from '@ohos.fileio';
import xml from '@ohos.xml';
import fileIO from '@ohos.fileio';
import util from '@ohos.util';
import data_preferences from '@ohos.data.preferences';
const TAG = 'ParseXML';
let path = globalThis.dir;
let path1 = path + '/Audio';
let VarColor = [];
let ColorBackPath = path + '/AudioColorBack.txt';
let txtPath = path1 + 'AudioReport.txt';
let xmlPath =path1 + 'AudioTest.xml';
@Entry
@Component
struct IndexPage {
@State ClearAll : boolean = false;
private current : number = undefined;
@State count : number = 0;
@State result : string = '';
@State TEST : number = 0;
private TestCaseList = [
{title:'ScrollingList',uri:'pages/Audio/ScrollListTest'},
]
@State ColorObject : string[] = VarColor;
async onPageShow(){
let Test = null;
let context =null;
context = globalThis.getContext();
let preferences;
let promise = data_preferences.getPreferences(context,'mystore');
await promise.then((object) => {
preferences = object;
});
promise = preferences.get('Audio', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'Audio'. Data: " + data);
});
if(Test != 1) {
let fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
for(let i = 0; i < this.TestCaseList.length; i++) {
let log = (this.TestCaseList[i].title+';'+'#ff808080'+';').toString();
fileio.writeSync(fd,log);
}
fileio.closeSync(fd);
}
promise = preferences.put('Audio', 1);
promise.then(() => {
console.info("Succeeded in putting value of 'Audio'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
this.TEST = Test;
let opt = fileio.openSync(ColorBackPath, 0o100 | 0o2002, 0o664);
let buff = new ArrayBuffer(40960);
fileio.readSync(opt,buff);
let ColorBack = String.fromCharCode.apply(null, new Uint8Array(buff));
let TestList = ColorBack.split(';');
for (let i = 0; i < Math.floor(TestList.length / 2); i++) {
VarColor[i] = TestList[i*2+1];
}
fileio.closeSync(opt);
if (this.count === 1){
this.result = router.getParams()['result'];
let titles = router.getParams()['title'];
let name1 = '刚刚点进了哪个用例:'+ titles;
let results = this.result;
let WriteTitle = (titles).toString();
let number = WriteTitle.length + 11;
let Index = ColorBack.indexOf(WriteTitle);
if (this.result === 'Pass'){
this.ColorObject[this.current] = '#ff008000';
let Log = (titles+';'+'#ff008000'+';');
let key = ColorBack.substring(Index,Index+number);
let FD = fileio.openSync(ColorBackPath, 0o102, 0o666);
ColorBack = ColorBack.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = ColorBack.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
filewrite(name1,results,titles)
}
else if (this.result === 'Fail'){
this.ColorObject[this.current] = '#ffff0000';
let Log = (titles+';'+'#ffff0000'+';');
let key = ColorBack.substring(Index,Index+number);
let FD = fileio.openSync(ColorBackPath, 0o102, 0o666);
ColorBack = ColorBack.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = ColorBack.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
filewrite(name1,results,titles);
}
else if (this.result === 'None'){
this.ColorObject[this.current] = this.ColorObject[this.current];
}
}
}
build(){
Column(){
Row() {
Button() {
Image($r('app.media.ic_public_back')).width('20vp').height('18vp')
}.backgroundColor(Color.Black)
.onClick(() => {
router.back();
})
Row(){
Text('Audio SubSystem')
.fontColor(Color.White)
.fontSize('22fp')
}.justifyContent(FlexAlign.SpaceAround).backgroundColor(Color.Black)
Row() {
Button(){
Image($r('app.media.ic_public_delete'))
.width('30vp')
.height('30vp')
}.backgroundColor(Color.Black)
.onClick(() => {
AlertDialog.show(
{
message: "是否删除所有记录",
primaryButton: {
value: 'Yes',
action: () => {
this.ClearAll = true;
this.ColorObject.forEach((value, index) => {
this.ColorObject[index] = '#ff808080';
});
this.ClearText();
prompt.showToast({
message: '结果已删除', duration: 1000
});
}
},
secondaryButton: {
value: 'No',
action: () => {
}
},
cancel: () => {
}
}
)
})
Button(){
Image($r('app.media.ic_public_save'))
.width('30vp')
.height('30vp')
.margin({ left: 30 })
}.backgroundColor(Color.Black)
.onClick(() => {
this.ReadTextParseXml();
AlertDialog.show({
message: "报告已生成,如需查看通过命令行输入'hdc_std file recv /data/app/el2/100/base/com.example.actsvalidator/haps/entry/files/Audio/AudioTest.xml -本地路径'",
confirm:{
value:'OK',
action:()=>{
prompt.showToast({
message: '报告已生成', duration: 1000
})
}
},
cancel: () => {
prompt.showToast({
message: '报告已生成', duration: 1000
});
}
})
})
}
}.width('100%').justifyContent(FlexAlign.SpaceAround).margin({top:'15vp'}).height('6%').backgroundColor(Color.Black)
List({space:5}){
ForEach(this.TestCaseList,(item,index) => {
ListItem(){
Row(){
Text(item.title).fontSize(16).fontColor(Color.Black)
}.width('100%').height(50).alignItems(VerticalAlign.Center).backgroundColor(this.count===0&&this.TEST===0?'#ff808080':this.ColorObject[index])
.onClick(( )=>{
this.count = 1;
this.ClearAll=false;
this.current = index;
router.push({
url: item.uri,
})
})
}
},item => item.title)
}.width('100%').height('92%')
}.width('100%').height('100%').backgroundColor(Color.Black)
}
ClearText(){
fileio.rmdirSync(path1);
fileio.mkdirSync(path1);
let fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
for(let i = 0; i < this.TestCaseList.length; i++) {
let log = (this.TestCaseList[i].title+';'+'#ff808080'+';').toString();
fileio.writeSync(fd,log);
}
}
ReadTextParseXml(){
let ReportPath = path1 + '/AudioReport.txt';
let dir = fileio.opendirSync(path1);
console.info("ssssss"+dir);
while (dir) {
let OP = fileio.openSync(ReportPath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(40960);
let RD = fileio.readSync(OP,buf);
console.info("ddddd"+RD);
let report;
function ab2str(buf) {
return report = String.fromCharCode.apply(null,new Uint8Array(buf));
}
ab2str(buf);
let str1 = report.split(";");
let title = [];
let result = [];
for(let i=0; i<Math.floor(str1.length/2); i++){
title[i] = str1[i*2];
result[i] = str1[i*2+1];
}
let FailIndex = report.indexOf('Fail');
let FailNum = 0;
while (FailIndex != -1) {
console.log(FailIndex);
FailNum++;
FailIndex = report.indexOf('Fail',FailIndex + 1);
}
let failNum = (FailNum).toString();
let PassIndex = report.indexOf('Pass');
let PassNum = 0;
while (PassIndex != -1) {
console.log(PassIndex);
PassNum++;
PassIndex = report.indexOf('Pass',PassIndex + 1);
}
let TestNum = FailNum + PassNum;
let testNum = (TestNum).toString();
let ignoreNum = (24-TestNum).toString();
let arrayBuffer = new ArrayBuffer(40960);
let bufView = new DataView(arrayBuffer);
let serializer = new xml.XmlSerializer(bufView);
serializer.setDeclaration();
serializer.startElement("testsuite");
serializer.setAttributes("name","ActsAudioTest");
serializer.setAttributes("time", " ");
serializer.setAttributes("errors", "0");
serializer.setAttributes("disabled", "0");
serializer.setAttributes("failures", failNum);
serializer.setAttributes("ignored", ignoreNum);
serializer.setAttributes("tests", testNum);
serializer.setAttributes("message", " ");
serializer.setAttributes("modulename", "ActsAudioTest");
for (let i = 0; i < title.length; i++) {
serializer.startElement("testcase");
serializer.setAttributes("name", String(title[i]));
serializer.setAttributes("status", " ");
serializer.setAttributes("time", " ");
serializer.setAttributes("classname", " ");
serializer.setAttributes("result", String(result[i]));
serializer.setAttributes("level", " ");
serializer.setAttributes("message", " ");
serializer.endElement();
}
serializer.endElement();
let that = new util.TextDecoder('utf-8');
let array = new Uint8Array(arrayBuffer);
let serializerStr = that.decode(array);
console.info(xmlPath);
try{
console.error(TAG,"write xmlPath =" +xmlPath);
var xmlfd = fileIO.openSync(xmlPath, 0o102, 0o666);
fileIO.writeSync(xmlfd,serializerStr);
}catch(err){
console.error(TAG,"read xmlPath =" + xmlPath + "error:" + err);
}finally{
fileIO.closeSync(xmlfd);
}
return;
}
}
}
function filewrite(name1,results,titles){
let fd = fileio.openSync(txtPath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(4096);
let RD = fileio.readSync(fd,buf);
console.info("RRRRRRRRRRd"+RD);
let report = String.fromCharCode.apply(null,new Uint8Array(buf));
let WriteTitle = (titles).toString();
let number = WriteTitle.length + 6;
let Index = report.indexOf(WriteTitle);
let Log = (titles+";"+results+";").toString();
if (Index == -1){
fileio.writeSync(fd,Log);
}
else if (Index != -1){
let key = report.substring(Index,Index+number);
let FD = fileio.openSync(txtPath, 0o102, 0o666);
report = report.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = report.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(txtPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {CustomContainer} from '../common/CustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct CustomContainerUser {
private listArr: number[] = Array.from(new Array(50).keys());
@State name: string = 'ScrollingList';
@State StepTips: string = '操作步骤:滑动列表观察是否能正常滑动'+'\n'+'预期结果:列表滑动正常';
@State Vue: boolean = false;
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
this.Vue = true;
}
@Builder specificNoParam() {
Column() {
List() {
ForEach(this.listArr,(item:any,index:number) => {
ListItem() {
Text('Item #' + (index + 1)).width('100%').height(50).fontSize(16).fontColor(Color.White).margin({left:'10vp'})
}
},index => index)
}.height('100%').width('100%').divider({strokeWidth:1,color:Color.Grey})
}.height('83%').width('100%')
}
build() {
Column() {
CustomContainer({
title: this.name,
Url: 'pages/Audio/Audio_index',
StepTips: this.StepTips,
content: this.specificNoParam.bind(this),
name: $name,
Vue: $Vue,
})
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import camera from '@ohos.multimedia.camera'
import Logger from '../model/Logger'
import CameraService from '../model/CameraService'
import {CustomContainer} from '../common/CameraOrientation';
import FirstDialog from '../model/FirstDialog';
const CameraMode = {
MODE_PHOTO: 0, // 拍照模式
MODE_VIDEO: 1 // 录像模式
}
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'CameraFormat';
@State StepTips: string = '测试目的:用于测试相机预览和拍照旋转能力\n-左侧显示给定旋转角度后的预览窗口\n-右侧显示拍照后的图片\n-对于前置摄像头会有镜像效果'+'\n'+'预期结果:拍照图片与预览窗口的画面一致';
private tag: string = 'qlw'
private mXComponentController: XComponentController = new XComponentController()
@State surfaceId: number = 0;
private x: number = 0;
@State curModel: number = CameraMode.MODE_PHOTO
@State cameraDeviceIndex: number = 0
@State imageRotationValue: number = camera.ImageRotation.ROTATION_90
@State qualityLevelValue: number = camera.QualityLevel.QUALITY_LEVEL_LOW
@State photoUri: string = undefined
@State Vue: boolean = false
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
handleTakePicture = (photoUri: string) => {
this.photoUri = photoUri
Logger.info(this.tag, `takePicture end, photoUri: ${this.photoUri}`)
}
@Builder specificNoParam() {
Column() {
}
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/CameraOrientation/Camera_Orientation_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name: $name,
Vue: $Vue
}).height('30%').width('100%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
XComponent({
id: 'componentId',
type: 'surface',
controller: this.mXComponentController
})
.onLoad(async () => {
Logger.info(this.tag, 'onLoad is called')
// @ts-ignore
this.mXComponentController.setXComponentSurfaceSize({ surfaceWidth: 10, surfaceHeight: 10 })
// @ts-ignore
this.surfaceId = this.mXComponentController.getXComponentSurfaceId()
Logger.info(this.tag, `onLoad surfaceId: ${this.surfaceId}`)
this.curModel = CameraMode.MODE_PHOTO
CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex)
})
.height('40%')
.width('40%')
Text('Camera Preview').fontSize('20fp')
Text('Camera').fontSize(20)
// Select(qualityLevel)
// .selected(2)
// .value('请选择')
// .font({ size: 20, weight: 20, family: 'serif', style: FontStyle.Normal })
// .selectedOptionFont({ size: 20, weight: 20, family: 'serif', style: FontStyle.Normal })
// .optionFont({ size: 20, weight: 40, family: 'serif', style: FontStyle.Normal })
// .onSelect((index: number, value: string) => {
// console.info("Select:" + index)
// console.info("Select qualityLevelValue:" + value)
// this.qualityLevelValue = Number(value)
// })
Button('NEXT', {
type: ButtonType.Normal,
stateEffect: true
}).borderRadius(8).backgroundColor(0x317aff).width('20%').onClick(() => {
CameraService.takePicture(this.imageRotationValue, this.qualityLevelValue)
CameraService.setTakePictureCallback(this.handleTakePicture.bind(this))
this.Vue = true
})
}.width('100%').height('70%').backgroundColor(Color.White)
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
//@CustomDialog
//struct CustomDialogExample {
// @Link textValue: string
// @Link inputValue: string
// @Link qualityLevelValue: number
// @Link imageRotationValue: number
// @Link imageResolutionValue: string
// controller: CustomDialogController
// cancel: () => void
// confirm: () => void
//}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import camera from '@ohos.multimedia.camera'
import Logger from '../model/Logger'
import CameraService from '../model/CameraService'
import {CustomContainer} from '../common/CameraOrientation';
import FirstDialog from '../model/FirstDialog';
const CameraMode = {
MODE_PHOTO: 0, // 拍照模式
MODE_VIDEO: 1 // 录像模式
}
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'CameraOrientation0';
@State StepTips: string = '测试目的:用于测试相机预览和拍照旋转能力\n-左侧显示给定旋转角度后的预览窗口\n-右侧显示拍照后的图片\n-对于前置摄像头会有镜像效果'+'\n'+'预期结果:拍照图片与预览窗口的画面一致';
private tag: string = 'qlw'
private mXComponentController: XComponentController = new XComponentController()
@State surfaceId: number = 0;
@State curModel: number = CameraMode.MODE_PHOTO
@State cameraDeviceIndex: number = 0
@State imageRotationValue: number = camera.ImageRotation.ROTATION_90
@State qualityLevelValue: number = camera.QualityLevel.QUALITY_LEVEL_LOW
@State assetUri: string = undefined
@State Vue: boolean = false
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
handleTakePicture = (assetUri: string) => {
this.assetUri = assetUri
Logger.info(this.tag, `takePicture end, assetUri: ${this.assetUri}`)
}
@Builder specificNoParam() {
Column() {
}
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/CameraOrientation/Camera_Orientation_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name: $name,
Vue: $Vue
}).height('30%').width('100%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
XComponent({
id: 'componentId',
type: 'surface',
controller: this.mXComponentController
})
.onLoad(async () => {
Logger.info(this.tag, 'onLoad is called')
// @ts-ignore
this.mXComponentController.setXComponentSurfaceSize({ surfaceWidth: 10, surfaceHeight: 10 })
// @ts-ignore
this.surfaceId = this.mXComponentController.getXComponentSurfaceId()
Logger.info(this.tag, `onLoad surfaceId: ${this.surfaceId}`)
this.curModel = CameraMode.MODE_PHOTO
CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex)
})
.height('40%')
.width('40%')
Text('Camera Preview').fontSize('20fp')
Image(this.assetUri || $r('app.media.img'))
.width('40%').height('40%').border({ width: 1 }).objectFit(ImageFit.Contain)
Text('Oriented Photo').fontSize('20fp')
Button('拍照', {
type: ButtonType.Normal,
stateEffect: true
}).borderRadius(8).backgroundColor(0x317aff).width('20%').onClick(() => {
CameraService.takePicture(this.imageRotationValue, this.qualityLevelValue)
CameraService.setTakePictureCallback(this.handleTakePicture.bind(this))
this.Vue = true
})
}.width('100%').height('70%').backgroundColor(Color.White)
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import camera from '@ohos.multimedia.camera'
import Logger from '../model/Logger'
import CameraService from '../model/CameraService'
import {CustomContainer} from '../common/CameraOrientation';
import FirstDialog from '../model/FirstDialog';
const CameraMode = {
MODE_PHOTO: 0, // 拍照模式
MODE_VIDEO: 1 // 录像模式
}
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'CameraOrientation180';
@State StepTips: string = '测试目的:用于测试相机预览和拍照旋转能力\n-左侧显示给定旋转角度后的预览窗口\n-右侧显示拍照后的图片\n-对于前置摄像头会有镜像效果'+'\n'+'预期结果:拍照图片与预览窗口的画面一致';
private tag: string = 'qlw'
private mXComponentController: XComponentController = new XComponentController()
@State surfaceId: number = 0;
@State curModel: number = CameraMode.MODE_PHOTO
@State cameraDeviceIndex: number = 0
@State imageRotationValue: number = camera.ImageRotation.ROTATION_180
@State qualityLevelValue: number = camera.QualityLevel.QUALITY_LEVEL_LOW
@State assetUri: string = undefined
@State Vue: boolean = false
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
handleTakePicture = (assetUri: string) => {
this.assetUri = assetUri
Logger.info(this.tag, `takePicture end, assetUri: ${this.assetUri}`)
}
@Builder specificNoParam() {
Column() {
}
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/CameraOrientation/Camera_Orientation_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name,
Vue: $Vue,
}).height('30%').width('100%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
XComponent({
id: 'componentId',
type: 'surface',
controller: this.mXComponentController
})
.onLoad(async () => {
Logger.info(this.tag, 'onLoad is called')
// @ts-ignore
this.mXComponentController.setXComponentSurfaceSize({ surfaceWidth: 10, surfaceHeight: 10 })
// @ts-ignore
this.surfaceId = this.mXComponentController.getXComponentSurfaceId()
Logger.info(this.tag, `onLoad surfaceId: ${this.surfaceId}`)
this.curModel = CameraMode.MODE_PHOTO
CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex)
})
.height('40%')
.width('40%')
Text('Camera Preview').fontSize('20fp')
Image(this.assetUri || $r('app.media.img'))
.width('40%').height('40%').border({ width: 1 }).objectFit(ImageFit.Contain)
Text('Oriented Photo').fontSize('20fp')
Button('拍照', {
type: ButtonType.Normal,
stateEffect: true
}).borderRadius(8).backgroundColor(0x317aff).width('20%').onClick(() => {
CameraService.takePicture(this.imageRotationValue, this.qualityLevelValue)
CameraService.setTakePictureCallback(this.handleTakePicture.bind(this))
this.Vue = true
})
}.width('100%').height('70%').backgroundColor(Color.White)
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import camera from '@ohos.multimedia.camera'
import Logger from '../model/Logger'
import CameraService from '../model/CameraService'
import {CustomContainer} from '../common/CameraOrientation';
import FirstDialog from '../model/FirstDialog';
const CameraMode = {
MODE_PHOTO: 0, // 拍照模式
MODE_VIDEO: 1 // 录像模式
}
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'CameraOrientation270';
@State StepTips: string = '测试目的:用于测试相机预览和拍照旋转能力\n-左侧显示给定旋转角度后的预览窗口\n-右侧显示拍照后的图片\n-对于前置摄像头会有镜像效果'+'\n'+'预期结果:拍照图片与预览窗口的画面一致';
private tag: string = 'qlw'
private mXComponentController: XComponentController = new XComponentController()
@State surfaceId: number = 0;
@State curModel: number = CameraMode.MODE_PHOTO
@State cameraDeviceIndex: number = 0
@State imageRotationValue: number = camera.ImageRotation.ROTATION_270
@State qualityLevelValue: number = camera.QualityLevel.QUALITY_LEVEL_LOW
@State assetUri: string = undefined
@State Vue: boolean = false
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
handleTakePicture = (assetUri: string) => {
this.assetUri = assetUri
Logger.info(this.tag, `takePicture end, assetUri: ${this.assetUri}`)
}
@Builder specificNoParam() {
Column() {
}
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/CameraOrientation/Camera_Orientation_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name,
Vue: $Vue
}).height('30%').width('100%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
XComponent({
id: 'componentId',
type: 'surface',
controller: this.mXComponentController
})
.onLoad(async () => {
Logger.info(this.tag, 'onLoad is called')
// @ts-ignore
this.mXComponentController.setXComponentSurfaceSize({ surfaceWidth: 10, surfaceHeight: 10 })
// @ts-ignore
this.surfaceId = this.mXComponentController.getXComponentSurfaceId()
Logger.info(this.tag, `onLoad surfaceId: ${this.surfaceId}`)
this.curModel = CameraMode.MODE_PHOTO
CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex)
})
.height('40%')
.width('40%')
Text('Camera Preview').fontSize('20fp')
Image(this.assetUri || $r('app.media.img'))
.width('40%').height('40%').border({ width: 1 }).objectFit(ImageFit.Contain)
Text('Oriented Photo').fontSize('20fp')
Button('拍照', {
type: ButtonType.Normal,
stateEffect: true
}).borderRadius(8).backgroundColor(0x317aff).width('20%').onClick(() => {
CameraService.takePicture(this.imageRotationValue, this.qualityLevelValue)
CameraService.setTakePictureCallback(this.handleTakePicture.bind(this))
this.Vue = true
})
}.width('100%').height('70%').backgroundColor(Color.White)
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import camera from '@ohos.multimedia.camera'
import Logger from '../model/Logger'
import CameraService from '../model/CameraService'
import {CustomContainer} from '../common/CameraOrientation';
import FirstDialog from '../model/FirstDialog';
const CameraMode = {
MODE_PHOTO: 0, // 拍照模式
MODE_VIDEO: 1 // 录像模式
}
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'CameraOrientation90';
@State StepTips: string = '测试目的:用于测试相机预览和拍照旋转能力\n-左侧显示给定旋转角度后的预览窗口\n-右侧显示拍照后的图片\n-对于前置摄像头会有镜像效果'+'\n'+'预期结果:拍照图片与预览窗口的画面一致';
private tag: string = 'qlw'
private mXComponentController: XComponentController = new XComponentController()
@State surfaceId: number = 0;
@State curModel: number = CameraMode.MODE_PHOTO
@State cameraDeviceIndex: number = 0
@State imageRotationValue: number = camera.ImageRotation.ROTATION_0
@State qualityLevelValue: number = camera.QualityLevel.QUALITY_LEVEL_LOW
@State assetUri: string = undefined
@State Vue: boolean = false
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
handleTakePicture = (assetUri: string) => {
this.assetUri = assetUri
Logger.info(this.tag, `takePicture end, assetUri: ${this.assetUri}`)
}
@Builder specificNoParam() {
Column() {
}
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/CameraOrientation/Camera_Orientation_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name,
Vue: $Vue
}).height('30%').width('100%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
XComponent({
id: 'componentId',
type: 'surface',
controller: this.mXComponentController
})
.onLoad(async () => {
Logger.info(this.tag, 'onLoad is called')
// @ts-ignore
this.mXComponentController.setXComponentSurfaceSize({ surfaceWidth: 10, surfaceHeight: 10 })
// @ts-ignore
this.surfaceId = this.mXComponentController.getXComponentSurfaceId()
Logger.info(this.tag, `onLoad surfaceId: ${this.surfaceId}`)
this.curModel = CameraMode.MODE_PHOTO
CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex)
})
.height('40%')
.width('40%')
Text('Camera Preview').fontSize('20fp')
Image(this.assetUri || $r('app.media.img'))
.width('40%').height('40%').border({ width: 1 }).objectFit(ImageFit.Contain)
Text('Oriented Photo').fontSize('20fp')
Button('拍照', {
type: ButtonType.Normal,
stateEffect: true
}).borderRadius(8).backgroundColor(0x317aff).width('20%').onClick(() => {
CameraService.takePicture(this.imageRotationValue, this.qualityLevelValue)
CameraService.setTakePictureCallback(this.handleTakePicture.bind(this))
this.Vue = true
})
}.width('100%').height('70%').backgroundColor(Color.White)
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import camera from '@ohos.multimedia.camera'
import Logger from '../model/Logger'
import CameraService from '../model/CameraService'
import {CustomContainer} from '../common/CameraOrientation';
import FirstDialog from '../model/FirstDialog';
const CameraMode = {
MODE_PHOTO: 0, // 拍照模式
MODE_VIDEO: 1 // 录像模式
}
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'CameraVideo';
@State StepTips: string = '测试目的:用于测试相机不同分辨率下的录像能力\n-上边显示录像的预览窗口\n-按下测试按钮后触发3s录像,回放的录像文件将在录像结束后显示在下边窗口\n-使用下拉框可以选择相机设备和分辨率'+'\n'+'预期结果:回放的录像视频与预览窗口的画面一致';
private tag: string = 'qlw'
private mXComponentController: XComponentController = new XComponentController()
@State surfaceId: number = 0;
private x: number = 0;
@State curModel: number = CameraMode.MODE_PHOTO
@State cameraDeviceIndex: number = 0
@State imageRotationValue: number = camera.ImageRotation.ROTATION_90
@State qualityLevelValue: number = camera.QualityLevel.QUALITY_LEVEL_LOW
@State assetUri: string = undefined
@State Vue: boolean = false
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
handleTakePicture = (assetUri: string) => {
this.assetUri = assetUri
Logger.info(this.tag, `Video recorder end, assetUri: ${this.assetUri}`)
}
@Builder specificNoParam() {
Column() {
}
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/CameraOrientation/Camera_Orientation_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name: $name,
Vue: $Vue
}).height('30%').width('100%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
XComponent({
id: 'componentId',
type: 'surface',
controller: this.mXComponentController
})
.onLoad(async () => {
Logger.info(this.tag, 'onLoad is called')
// @ts-ignore
this.mXComponentController.setXComponentSurfaceSize({ surfaceWidth: 10, surfaceHeight: 10 })
// @ts-ignore
this.surfaceId = this.mXComponentController.getXComponentSurfaceId()
Logger.info(this.tag, `onLoad surfaceId: ${this.surfaceId}`)
this.curModel = CameraMode.MODE_PHOTO
CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex)
})
.height('40%')
.width('40%')
Text('Camera Preview').fontSize('20fp')
// Video()
Text('Video playback').fontSize('20fp')
Button('Test', {
type: ButtonType.Normal,
stateEffect: true
}).borderRadius(8).backgroundColor(0x317aff).width('20%').onClick(() => {
CameraService.startVideo()
CameraService.setTakePictureCallback(this.handleTakePicture.bind(this))
this.Vue = true
})
}.width('100%').height('70%').backgroundColor(Color.White)
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import prompt from '@ohos.prompt';
import router from '@ohos.router';
import fileio from '@ohos.fileio';
import xml from '@ohos.xml';
import fileIO from '@ohos.fileio';
import util from '@ohos.util';
import data_preferences from '@ohos.data.preferences';
const TAG = 'ParseXML';
let path = globalThis.dir;
let path1 = path + '/Camera';
let VarColor = [];
let ColorBackPath = path + '/CameraColorBack.txt';
let txtPath = path1 + 'CameraReport.txt';
let xmlPath = path1 + 'CameraTest.xml';
@Entry
@Component
struct IndexPage {
@State ClearAll : boolean = false;
private current : number = undefined;
@State count : number = 0;
@State result : string = '';
@State TEST : number = 0;
private TestCaseList = [
{title:'CameraOrientation0',uri:'pages/CameraOrientation/CameraOrientation0'},
{title:'CameraOrientation90',uri:'pages/CameraOrientation/CameraOrientation90'},
{title:'CameraOrientation180',uri:'pages/CameraOrientation/CameraOrientation180'},
{title:'CameraOrientation270',uri:'pages/CameraOrientation/CameraOrientation270'},
{title:'CameraFormat',uri:'pages/CameraOrientation/CameraFormat'},
{title:'CameraVideo',uri:'pages/CameraOrientation/CameraVideo'},
]
@State ColorObject : string[] = VarColor;
async onPageShow(){
let Test = null;
let context =null;
context = globalThis.getContext();
let preferences;
let promise = data_preferences.getPreferences(context,'mystore');
await promise.then((object) => {
preferences = object;
});
promise = preferences.get('Camera', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'Camera'. Data: " + data);
});
if(Test != 1) {
let fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
for(let i = 0; i < this.TestCaseList.length; i++) {
let log = (this.TestCaseList[i].title+';'+'#ff808080'+';').toString();
fileio.writeSync(fd,log);
}
fileio.closeSync(fd);
}
promise = preferences.put('Camera', 1);
promise.then(() => {
console.info("Succeeded in putting value of 'Camera'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
this.TEST = Test;
let opt = fileio.openSync(ColorBackPath, 0o100 | 0o2002, 0o664);
let buff = new ArrayBuffer(40960);
fileio.readSync(opt,buff);
let ColorBack = String.fromCharCode.apply(null, new Uint8Array(buff));
let TestList = ColorBack.split(';');
for (let i = 0; i < Math.floor(TestList.length / 2); i++) {
VarColor[i] = TestList[i*2+1];
}
fileio.closeSync(opt);
if (this.count === 1){
this.result = router.getParams()['result'];
let titles = router.getParams()['title'];
let name1 = '刚刚点进了哪个用例:'+ titles;
let results = this.result;
let WriteTitle = (titles).toString();
let number = WriteTitle.length + 11;
let Index = ColorBack.indexOf(WriteTitle);
if (this.result === 'Pass'){
this.ColorObject[this.current] = '#ff008000';
let Log = (titles+';'+'#ff008000'+';');
let key = ColorBack.substring(Index,Index+number);
let FD = fileio.openSync(ColorBackPath, 0o102, 0o666);
ColorBack = ColorBack.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = ColorBack.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
filewrite(name1,results,titles)
}
else if (this.result === 'Fail'){
this.ColorObject[this.current] = '#ffff0000';
let Log = (titles+';'+'#ffff0000'+';');
let key = ColorBack.substring(Index,Index+number);
let FD = fileio.openSync(ColorBackPath, 0o102, 0o666);
ColorBack = ColorBack.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = ColorBack.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
filewrite(name1,results,titles);
}
else if (this.result === 'None'){
this.ColorObject[this.current] = this.ColorObject[this.current];
}
}
}
build(){
Column(){
Row() {
Button() {
Image($r('app.media.ic_public_back')).width('20vp').height('18vp')
}.backgroundColor(Color.Black)
.onClick(() => {
router.back();
})
Row(){
Text('Camera Oritentation')
.fontColor(Color.White)
.fontSize('20fp')
}.justifyContent(FlexAlign.SpaceAround).backgroundColor(Color.Black)
Row() {
Button(){
Image($r('app.media.ic_public_delete'))
.width('30vp')
.height('30vp')
}.backgroundColor(Color.Black)
.onClick(() => {
AlertDialog.show(
{
message: "是否删除所有记录",
primaryButton: {
value: 'Yes',
action: () => {
this.ClearAll = true;
this.ColorObject.forEach((value, index) => {
this.ColorObject[index] = '#ff808080';
});
this.ClearText();
prompt.showToast({
message: '结果已删除', duration: 1000
});
}
},
secondaryButton: {
value: 'No',
action: () => {
}
},
cancel: () => {
}
}
)
})
Button(){
Image($r('app.media.ic_public_save'))
.width('30vp')
.height('30vp')
.margin({ left: 30 })
}.backgroundColor(Color.Black)
.onClick(() => {
this.ReadTextParseXml();
AlertDialog.show({
message: "报告已生成,如需查看通过命令行输入'hdc_std file recv /data/app/el2/100/base/com.example.actsvalidator/haps/entry/files/report1/CameraTest.xml -本地路径'",
confirm:{
value:'OK',
action:()=>{
prompt.showToast({
message: '报告已生成', duration: 1000
})
}
},
cancel: () => {
prompt.showToast({
message: '报告已生成', duration: 1000
})
}
})
})
}
}.width('100%').justifyContent(FlexAlign.SpaceAround).margin({top:'15vp'}).height('6%').backgroundColor(Color.Black)
List({space:5}){
ForEach(this.TestCaseList,(item,index) => {
ListItem(){
Row(){
Text(item.title).fontSize(16).fontColor(Color.Black)
}.width('100%').height(50).alignItems(VerticalAlign.Center).backgroundColor(this.count===0&&this.TEST===0?'#ff808080':this.ColorObject[index])
.onClick(( )=>{
this.count = 1;
this.ClearAll=false;
this.current = index;
router.push({
url: item.uri,
})
})
}
},item => item.title)
}.width('100%').height('92%')
}.width('100%').height('100%').backgroundColor(Color.Black)
}
ClearText(){
fileio.rmdirSync(path1);
fileio.mkdirSync(path1);
let fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
for(let i = 0; i < this.TestCaseList.length; i++) {
let log = (this.TestCaseList[i].title+';'+'#ff808080'+';').toString();
fileio.writeSync(fd,log);
}
}
ReadTextParseXml(){
let ReportPath = path1 + '/CameraReport.txt';
let dir = fileio.opendirSync(path1);
console.info("ssssss"+dir);
while (dir) {
let OP = fileio.openSync(ReportPath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(40960);
let RD = fileio.readSync(OP,buf);
console.info("ddddd"+RD);
let report;
function ab2str(buf) {
return report = String.fromCharCode.apply(null,new Uint8Array(buf));
}
ab2str(buf);
let str1 = report.split(";");
let title = [];
let result = [];
for(let i=0; i<Math.floor(str1.length/2); i++){
title[i] = str1[i*2];
result[i] = str1[i*2+1];
}
let FailIndex = report.indexOf('Fail');
let FailNum = 0;
while (FailIndex != -1) {
console.log(FailIndex);
FailNum++;
FailIndex = report.indexOf('Fail',FailIndex + 1);
}
let failNum = (FailNum).toString();
let PassIndex = report.indexOf('Pass');
let PassNum = 0;
while (PassIndex != -1) {
console.log(PassIndex);
PassNum++;
PassIndex = report.indexOf('Pass',PassIndex + 1);
}
let TestNum = FailNum + PassNum;
let testNum = (TestNum).toString();
let ignoreNum = (4-TestNum).toString();
let arrayBuffer = new ArrayBuffer(40960);
let bufView = new DataView(arrayBuffer);
let serializer = new xml.XmlSerializer(bufView);
serializer.setDeclaration();
serializer.startElement("testsuite");
serializer.setAttributes("name", "ActsCameraTest");
serializer.setAttributes("time", " ");
serializer.setAttributes("errors", "0");
serializer.setAttributes("disabled", "0");
serializer.setAttributes("failures", failNum);
serializer.setAttributes("ignored", ignoreNum);
serializer.setAttributes("tests", testNum);
serializer.setAttributes("message", " ");
serializer.setAttributes("modulename", "ActsCameraTest");
for (let i = 0; i < title.length; i++) {
serializer.startElement("testcase");
serializer.setAttributes("name", String(title[i]));
serializer.setAttributes("status", " ");
serializer.setAttributes("time", " ");
serializer.setAttributes("classname", " ");
serializer.setAttributes("result", String(result[i]));
serializer.setAttributes("level", " ");
serializer.setAttributes("message", " ");
serializer.endElement();
}
serializer.endElement();
let that = new util.TextDecoder('utf-8');
let array = new Uint8Array(arrayBuffer);
let serializerStr = that.decode(array);
console.info(xmlPath);
try{
console.error(TAG,"write xmlPath =" +xmlPath);
var xmlfd = fileIO.openSync(xmlPath, 0o102, 0o666);
fileIO.writeSync(xmlfd,serializerStr);
}catch(err){
console.error(TAG,"read xmlPath =" + xmlPath + "error:" + err);
}finally{
fileIO.closeSync(xmlfd);
}
return;
}
}
}
function filewrite(name1,results,titles){
let fd = fileio.openSync(txtPath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(4096);
let RD = fileio.readSync(fd,buf);
console.info("RRRRRRRRRRd"+RD);
let report = String.fromCharCode.apply(null,new Uint8Array(buf));
let WriteTitle = (titles).toString();
let number = WriteTitle.length + 6;
let Index = report.indexOf(WriteTitle);
let Log = (titles+";"+results+";").toString();
if (Index == -1){
fileio.writeSync(fd,Log);
}
else if (Index != -1){
let key = report.substring(Index,Index+number);
let FD = fileio.openSync(txtPath, 0o102, 0o666);
report = report.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = report.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(txtPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
}
}
\ No newline at end of file
...@@ -18,72 +18,141 @@ import fileio from '@ohos.fileio'; ...@@ -18,72 +18,141 @@ import fileio from '@ohos.fileio';
import xml from '@ohos.xml'; import xml from '@ohos.xml';
import fileIO from '@ohos.fileio'; import fileIO from '@ohos.fileio';
import util from '@ohos.util'; import util from '@ohos.util';
import data_preferences from '@ohos.data.preferences';
const TAG = 'ParseXML'; const TAG = 'ParseXML';
let path = globalThis.dir; let path = globalThis.dir;
let path1; let path1 = path + '/MediaLibrary';
path1 = path + '/MediaLibrary';
let VarColor = [];
let ColorBackPath = path + '/MediaColorBack.txt';
let txtPath = path1 + '/MediaLibraryReport.txt';
let xmlPath = path1 + "/MediaLibraryTest.xml";
@Entry @Entry
@Component @Component
struct IndexPage { struct IndexPage {
@State BackColor: string = '#ff808080';
@State ClearAll : boolean = false; @State ClearAll : boolean = false;
private current : number = undefined; private current : number = undefined;
@State count : number = 0; @State count : number = 0;
@State result : string = ''; @State result : string = '';
@State TEST : number = 0;
private TestCaseList = [ private TestCaseList = [
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_PR_0100',uri:'pages/MediaLibrary/startImagePreviewPromise1'}, {title:'startImagePreviewPromise1',uri:'pages/MediaLibrary/startImagePreviewPromise1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_PR_0200',uri:'pages/MediaLibrary/startImagePreviewPromise2'}, {title:'startImagePreviewPromise2',uri:'pages/MediaLibrary/startImagePreviewPromise2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_PR_0300',uri:'pages/MediaLibrary/startImagePreviewPromise3'}, {title:'startImagePreviewPromise3',uri:'pages/MediaLibrary/startImagePreviewPromise3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_PR_ERR_0400',uri:'pages/MediaLibrary/startImagePreviewPromise4'}, {title:'startImagePreviewPromise4',uri:'pages/MediaLibrary/startImagePreviewPromise4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_INDEX_CB_0100',uri:'pages/MediaLibrary/startImagePreviewCallback1'}, {title:'startImagePreviewCallback1',uri:'pages/MediaLibrary/startImagePreviewCallback1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_INDEX_CB_0200',uri:'pages/MediaLibrary/startImagePreviewCallback2'}, {title:'startImagePreviewCallback2',uri:'pages/MediaLibrary/startImagePreviewCallback2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_INDEX_CB_0300',uri:'pages/MediaLibrary/startImagePreviewCallback3'}, {title:'startImagePreviewCallback3',uri:'pages/MediaLibrary/startImagePreviewCallback3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_INDEX_CB_ERR_0400',uri:'pages/MediaLibrary/startImagePreviewCallback4'}, {title:'startImagePreviewCallback4',uri:'pages/MediaLibrary/startImagePreviewCallback4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_CB_0100',uri:'pages/MediaLibrary/startImagePreviewCallback5'}, {title:'startImagePreviewCallback5',uri:'pages/MediaLibrary/startImagePreviewCallback5'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_CB_0200',uri:'pages/MediaLibrary/startImagePreviewCallback6'}, {title:'startImagePreviewCallback6',uri:'pages/MediaLibrary/startImagePreviewCallback6'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_CB_ERR_0300',uri:'pages/MediaLibrary/startImagePreviewCallback7'}, {title:'startImagePreviewCallback7',uri:'pages/MediaLibrary/startImagePreviewCallback7'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_CB_0100',uri:'pages/MediaLibrary/startMediaSelectCallback1'}, {title:'startMediaSelectCallback1',uri:'pages/MediaLibrary/startMediaSelectCallback1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_CB_0200',uri:'pages/MediaLibrary/startMediaSelectCallback2'}, {title:'startMediaSelectCallback2',uri:'pages/MediaLibrary/startMediaSelectCallback2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_CB_0300',uri:'pages/MediaLibrary/startMediaSelectCallback3'}, {title:'startMediaSelectCallback3',uri:'pages/MediaLibrary/startMediaSelectCallback3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_CB_0400',uri:'pages/MediaLibrary/startMediaSelectCallback4'}, {title:'startMediaSelectCallback4',uri:'pages/MediaLibrary/startMediaSelectCallback4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_PR_0100',uri:'pages/MediaLibrary/startMediaSelectPromise1'}, {title:'startMediaSelectPromise1',uri:'pages/MediaLibrary/startMediaSelectPromise1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_PR_0200',uri:'pages/MediaLibrary/startMediaSelectPromise2'}, {title:'startMediaSelectPromise2',uri:'pages/MediaLibrary/startMediaSelectPromise2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_PR_0300',uri:'pages/MediaLibrary/startMediaSelectPromise3'}, {title:'startMediaSelectPromise3',uri:'pages/MediaLibrary/startMediaSelectPromise3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_PR_0400',uri:'pages/MediaLibrary/startMediaSelectPromise4'}, {title:'startMediaSelectPromise4',uri:'pages/MediaLibrary/startMediaSelectPromise4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_0100',uri:'pages/MediaLibrary/storeMediaAssetPromise1'}, {title:'storeMediaAssetPromise1',uri:'pages/MediaLibrary/storeMediaAssetPromise1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_0200',uri:'pages/MediaLibrary/storeMediaAssetPromise2'}, {title:'storeMediaAssetPromise2',uri:'pages/MediaLibrary/storeMediaAssetPromise2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_0300',uri:'pages/MediaLibrary/storeMediaAssetPromise3'}, {title:'storeMediaAssetPromise3',uri:'pages/MediaLibrary/storeMediaAssetPromise3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_0400',uri:'pages/MediaLibrary/storeMediaAssetPromise4'}, {title:'storeMediaAssetPromise4',uri:'pages/MediaLibrary/storeMediaAssetPromise4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_ERR_0500',uri:'pages/MediaLibrary/storeMediaAssetPromise5'}, {title:'storeMediaAssetPromise5',uri:'pages/MediaLibrary/storeMediaAssetPromise5'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_CB_0100',uri:'pages/MediaLibrary/storeMediaAssetCallback1'}, {title:'storeMediaAssetCallback1',uri:'pages/MediaLibrary/storeMediaAssetCallback1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_CB_0200',uri:'pages/MediaLibrary/storeMediaAssetCallback2'}, {title:'storeMediaAssetCallback2',uri:'pages/MediaLibrary/storeMediaAssetCallback2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_CB_0300',uri:'pages/MediaLibrary/storeMediaAssetCallback3'}, {title:'storeMediaAssetCallback3',uri:'pages/MediaLibrary/storeMediaAssetCallback3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_CB_0400',uri:'pages/MediaLibrary/storeMediaAssetCallback4'}, {title:'storeMediaAssetCallback4',uri:'pages/MediaLibrary/storeMediaAssetCallback4'},
] ]
@State ColorObject : string[] = ['#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080', @State ColorObject : string[] = VarColor;
'#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080', async onPageShow(){
'#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080'] let Test = null;
onPageShow(){ let context =null;
context = globalThis.getContext();
let preferences;
let promise = data_preferences.getPreferences(context,'mystore');
await promise.then((object) => {
preferences = object;
});
promise = preferences.get('Media', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'Media'. Data: " + data);
});
if(Test != 1) {
let fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
for(let i = 0; i < this.TestCaseList.length; i++) {
let log = (this.TestCaseList[i].title+';'+'#ff808080'+';').toString();
fileio.writeSync(fd,log);
}
fileio.closeSync(fd);
}
promise = preferences.put('Media', 1);
promise.then(() => {
console.info("Succeeded in putting value of 'Media'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
this.TEST = Test;
let opt = fileio.openSync(ColorBackPath, 0o100 | 0o2002, 0o664);
let buff = new ArrayBuffer(40960);
fileio.readSync(opt,buff);
let ColorBack = String.fromCharCode.apply(null, new Uint8Array(buff));
let TestList = ColorBack.split(';');
for (let i = 0; i < Math.floor(TestList.length / 2); i++) {
VarColor[i] = TestList[i*2+1];
}
fileio.closeSync(opt);
if (this.count === 1){ if (this.count === 1){
this.result = router.getParams()['result']; this.result = router.getParams()['result'];
let titles = router.getParams()['title']; let titles = router.getParams()['title'];
let name1 = '刚刚点进了哪个用例:'+ titles; let name1 = '刚刚点进了哪个用例:'+ titles;
let results = this.result; let results = this.result;
let WriteTitle = (titles).toString();
let number = WriteTitle.length + 11;
let Index = ColorBack.indexOf(WriteTitle);
if (this.result === 'Pass'){ if (this.result === 'Pass'){
this.ColorObject[this.current] = '#ff008000'; this.ColorObject[this.current] = '#ff008000';
filewrite(name1,results,titles); let Log = (titles+';'+'#ff008000'+';');
let key = ColorBack.substring(Index,Index+number);
let FD = fileio.openSync(ColorBackPath, 0o102, 0o666);
ColorBack = ColorBack.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = ColorBack.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
filewrite(name1,results,titles)
} }
else if (this.result === 'Fail'){ else if (this.result === 'Fail'){
this.ColorObject[this.current] = '#ffff0000'; this.ColorObject[this.current] = '#ffff0000';
let Log = (titles+';'+'#ffff0000'+';');
let key = ColorBack.substring(Index,Index+number);
let FD = fileio.openSync(ColorBackPath, 0o102, 0o666);
ColorBack = ColorBack.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = ColorBack.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
filewrite(name1,results,titles); filewrite(name1,results,titles);
} }
else if (this.result === 'None'){ else if (this.result === 'None'){
this.ColorObject[this.current] = this.ColorObject[this.current]; this.ColorObject[this.current] = this.ColorObject[this.current];
} }
} }
} }
build(){ build(){
Column(){ Column(){
...@@ -166,8 +235,7 @@ struct IndexPage { ...@@ -166,8 +235,7 @@ struct IndexPage {
ListItem(){ ListItem(){
Row(){ Row(){
Text(item.title).fontSize(16).fontColor(Color.Black) Text(item.title).fontSize(16).fontColor(Color.Black)
Text(this.BackColor.toString()).visibility(Visibility.None) }.width('100%').height(50).alignItems(VerticalAlign.Center).backgroundColor(this.count===0&&this.TEST===0?'#ff808080':this.ColorObject[index])
}.width('100%').height(50).alignItems(VerticalAlign.Center).backgroundColor(this.ColorObject[index])
.onClick(( )=>{ .onClick(( )=>{
this.count = 1; this.count = 1;
this.ClearAll=false; this.ClearAll=false;
...@@ -184,6 +252,11 @@ struct IndexPage { ...@@ -184,6 +252,11 @@ struct IndexPage {
ClearText(){ ClearText(){
fileio.rmdirSync(path1); fileio.rmdirSync(path1);
fileio.mkdirSync(path1); fileio.mkdirSync(path1);
let fd = fileio.openSync(ColorBackPath, 0o102, 0o666);
for(let i = 0; i < this.TestCaseList.length; i++) {
let log = (this.TestCaseList[i].title+';'+'#ff808080'+';').toString();
fileio.writeSync(fd,log);
}
} }
ReadTextParseXml() { ReadTextParseXml() {
let ReportPath = path1 + '/MediaLibraryReport.txt'; let ReportPath = path1 + '/MediaLibraryReport.txt';
...@@ -254,7 +327,6 @@ struct IndexPage { ...@@ -254,7 +327,6 @@ struct IndexPage {
let that = new util.TextDecoder('utf-8'); let that = new util.TextDecoder('utf-8');
let array = new Uint8Array(arrayBuffer); let array = new Uint8Array(arrayBuffer);
let serializerStr = that.decode(array); let serializerStr = that.decode(array);
let xmlPath = path1 + "/MediaLibraryTest.xml";
console.info(xmlPath); console.info(xmlPath);
try { try {
console.error(TAG, "write xmlPath =" + xmlPath); console.error(TAG, "write xmlPath =" + xmlPath);
...@@ -270,8 +342,7 @@ struct IndexPage { ...@@ -270,8 +342,7 @@ struct IndexPage {
} }
} }
function filewrite(name1,results,titles){ function filewrite(name1,results,titles){
let txtpath = path1 + '/MediaLibraryReport.txt'; let fd = fileio.openSync(txtPath, 0o100 | 0o2002, 0o664);
let fd = fileio.openSync(txtpath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
let RD = fileio.readSync(fd,buf); let RD = fileio.readSync(fd,buf);
console.info("RRRRRRRRRRd"+RD); console.info("RRRRRRRRRRd"+RD);
...@@ -285,13 +356,13 @@ function filewrite(name1,results,titles){ ...@@ -285,13 +356,13 @@ function filewrite(name1,results,titles){
} }
else if (Index != -1){ else if (Index != -1){
let key = report.substring(Index,Index+number); let key = report.substring(Index,Index+number);
let FD = fileio.openSync(txtpath, 0o102, 0o666); let FD = fileio.openSync(txtPath, 0o102, 0o666);
report = report.replace(key,Log); report = report.replace(key,Log);
let buffer = new ArrayBuffer(4096); let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer); let rd = fileio.readSync(FD,buffer);
let Report = report.substring(0,rd); let Report = report.substring(0,rd);
fileio.closeSync(FD); fileio.closeSync(FD);
let Fd = fileio.openSync(txtpath, 0o102, 0o666); let Fd = fileio.openSync(txtPath, 0o102, 0o666);
fileio.writeSync(Fd,Report); fileio.writeSync(Fd,Report);
} }
} }
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@ohos.fileio';
import prompt from '@ohos.prompt';
import router from '@ohos.router';
import screenshot from '@ohos.screenshot';
import image from '@ohos.multimedia.image';
import Logger from '../model/Logger';
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
let path = globalThis.dir;
const TAG = '[Screenshot]';
@Component
export struct CustomContainer {
@Link FillColor: string;
@Link name: string;
@Link Vue : boolean;
Url : string = '';
title : string = '';
StepTips: string = '';
@BuilderParam content: () => void;
@Builder
PassBtn(text: Resource, isFullScreen: boolean) {
if(this.Vue == false){
Button({stateEffect:this.Vue}) {
Image($r('app.media.ic_public_pass')).width('20vp').height('20vp')
}.width('30%').height('30vp').backgroundColor(Color.Grey).opacity(0.4)
.onClick(()=>{
})
}
else{
Button({stateEffect:this.Vue}) {
Image($r('app.media.ic_public_pass')).width('20vp').height('20vp')
}.width('30%').height('30vp').backgroundColor(Color.Grey)
.onClick(()=>{
router.back({
url:this.Url,
params: {result : 'Pass', title : this.name,
}
})
this.getScreen(isFullScreen);
prompt.showToast({
message: '通过', duration: 1000
});
})
}
}
@Builder
FailBtn(text: Resource, isFullScreen: boolean) {
Button(){
Image($r('app.media.ic_public_fail')).width('20vp').height('20vp')
}.width('30%').height('30vp').backgroundColor(Color.Grey)
.onClick(()=>{
router.back({
url:this.Url,
params: {result : 'Fail',title : this.name,
}
})
this.getScreen(isFullScreen);
prompt.showToast({
message: '失败', duration: 1000
});
})
}
build() {
Column() {
Row() {
Button(){
Image($r('app.media.ic_public_back')).width('20vp').height('18vp').margin({left:'20vp'})
}.backgroundColor(Color.Black)
.onClick(()=>{
router.back({
url:this.Url,
params: {result : 'None',}
})
})
Text(this.title).fontColor(Color.White).fontSize('18fp').margin({left:'-20vp'})
Text('hello').fontColor(Color.White).visibility(Visibility.Hidden)
}.backgroundColor(Color.Black).height('10%').width('100%').justifyContent(FlexAlign.SpaceBetween)
this.content();
Blank()
Row() {
this.PassBtn($r('app.string.btn_fullscreen'), true);
Button(){
Image($r('app.media.ic_public_help')).width('20vp').height('20vp')
}.width('30%').height('30vp').backgroundColor(Color.Grey)
.onClick(() =>{
AlertDialog.show(
{
title:'操作提示',
message: this.StepTips,
confirm:{
value:'OK',
action:()=>{
}
}
}
)
})
this.FailBtn($r('app.string.btn_fullscreen'), true);
}.width('100%').justifyContent(FlexAlign.SpaceEvenly).backgroundColor(Color.Black)
}.height('98%').width('100%')
}
async savePicture(data: image.PixelMap, context: any) {
Logger.info(TAG, `savePicture`);
let packOpts: image.PackingOption = {
format: "image/jpeg", quality: 100
};
let info = {
prefix: 'IMG_', suffix: '.jpg', directory: mediaLibrary.DirectoryType.DIR_IMAGE
};
let name = this.name;
let displayName = `${info.prefix}${name}${info.suffix}`;
let dirPath = path + '/' + displayName;
let imagePackerApi = image.createImagePacker();
let arrayBuffer = await imagePackerApi.packing(data, packOpts);
let fd = fileio.openSync(dirPath,0o102,0o666);
imagePackerApi.release();
try {
await fileio.write(fd, arrayBuffer);
} catch (err) {
Logger.error(`write failed, code is ${err.code}, message is ${err.message}`);
}
await fileio.close(fd);
Logger.info(TAG, `write done`);
}
getScreen = (isFullScreen: boolean) => {
let screenshotOptions: screenshot.ScreenshotOptions = {
screenRect: { left: 0, top: 0, width: 400, height: 400 },
imageSize: { width: 400, height: 400 },
rotation: 0,
displayId: 0
};
if (isFullScreen) {
screenshotOptions = {
rotation: 0
}
}
try {
screenshot.save(screenshotOptions, (err, data: image.PixelMap) => {
if (err) {
Logger.info(TAG, `Failed to save the screenshot. Error:${JSON.stringify(err)}`);
}
Logger.info(TAG, 'save callback');
this.savePicture(data, getContext(this) as any);
})
} catch (err) {
Logger.error(`save failed, code is ${err.code}, message is ${err.message}`);
}
}
}
...@@ -18,21 +18,32 @@ import fileio from '@ohos.fileio'; ...@@ -18,21 +18,32 @@ import fileio from '@ohos.fileio';
import xml from '@ohos.xml'; import xml from '@ohos.xml';
import fileIO from '@ohos.fileio'; import fileIO from '@ohos.fileio';
import util from '@ohos.util'; import util from '@ohos.util';
import DateTimeUtil from './model/DateTimeUtil' import DateTimeUtil from './model/DateTimeUtil';
import data_preferences from '@ohos.data.preferences';
import FlushData from '../pages/model/FlushData'
const TAG = 'ParseXML'; const TAG = 'ParseXML';
let path=globalThis.dir; let path=globalThis.dir;
let path1; let path1 = path + '/ArkUI';
let path2; let path2 = path + '/MediaLibrary';
console.info("ssssssssss"+path); let path3 = path + '/Camera';
path1 = path + '/ArkUI'; let path4 = path + '/Audio';
console.info("ssssssssss"+path1); let ArkUIColorBackPath = path + '/ArkUIColorBack.txt';
path2 = path + '/MediaLibrary'; let MediaColorBackPath = path + '/MediaColorBack.txt';
console.info("ssssssssss"+path2); let CameraColorBackPath = path + '/CameraColorBack.txt';
fileio.rmdirSync(path); let AudioColorBackPath = path + '/AudioColorBack.txt';
fileio.mkdirSync(path); fileio.openSync(ArkUIColorBackPath, 0o100 | 0o2002, 0o664);
fileio.mkdirSync(path1); fileio.openSync(MediaColorBackPath, 0o100 | 0o2002, 0o664);
fileio.mkdirSync(path2); fileio.openSync(CameraColorBackPath, 0o100 | 0o2002, 0o664);
fileio.openSync(AudioColorBackPath, 0o100 | 0o2002, 0o664);
let TimePath = path + '/Time.txt';
fileio.openSync(TimePath, 0o100 | 0o2002, 0o664);
let xmlPath = path + '/Test.xml';
fileio.openSync(xmlPath, 0o100 | 0o2002, 0o664);
let path11 = path1 + '/ArkUIReport.txt';
let path22 = path2 + '/MediaReport.txt';
let path33 = path3 + '/CameraReport.txt';
let path44 = path4 + '/AudioReport.txt';
@Entry @Entry
@Component @Component
...@@ -40,9 +51,45 @@ struct IndexPage { ...@@ -40,9 +51,45 @@ struct IndexPage {
private TestCaseList = [ private TestCaseList = [
{title:'ArkUI',uri:'pages/ArkUI/ArkUI_index'}, {title:'ArkUI',uri:'pages/ArkUI/ArkUI_index'},
{title:'MediaLibrary',uri:'pages/MediaLibrary/MediaLibrary_index'}, {title:'MediaLibrary',uri:'pages/MediaLibrary/MediaLibrary_index'},
{title:'Camera',uri:'pages/Camera/Camera_index'}, {title:'Camera',uri:'pages/CameraOrientation/Camera_Orientation_index'},
{title:'Audio',uri:'pages/Audio/Audio_index'},
] ]
@State ColorObject : string[] = ['#ff808080','#ff808080','#ff808080'] @State ColorObject : string[] = ['#ff808080','#ff808080','#ff808080','#ff808080','#ff808080']
async onPageShow(){
let Test = null;
let context =null;
context = globalThis.getContext();
let preferences;
let promise = data_preferences.getPreferences(context,'mystore');
await promise.then((object) => {
preferences = object;
});
promise = preferences.get('index', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'index'. Data: " + data);
});
if(Test != 1) {
fileio.mkdirSync(path1);
fileio.mkdirSync(path2);
fileio.mkdirSync(path3);
fileio.mkdirSync(path4);
let promise = preferences.put('index', 1);
promise.then(() => {
console.info("Succeeded in putting value of 'index'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
}
fileio.openSync(path11, 0o100 | 0o2002, 0o664);
fileio.openSync(path22, 0o100 | 0o2002, 0o664);
fileio.openSync(path33, 0o100 | 0o2002, 0o664);
fileio.openSync(path44, 0o100 | 0o2002, 0o664);
}
build(){ build(){
Column(){ Column(){
Row() { Row() {
...@@ -118,7 +165,7 @@ struct IndexPage { ...@@ -118,7 +165,7 @@ struct IndexPage {
url: item.uri, url: item.uri,
}) })
let dateTimeUtil = new DateTimeUtil(); let dateTimeUtil = new DateTimeUtil();
let time = `${dateTimeUtil.getFullYear()}-${dateTimeUtil.getMonth()}-${dateTimeUtil.getDate()} ${dateTimeUtil.getHour()}:${dateTimeUtil.getMinute()}:${dateTimeUtil.getSecond()}`; let time = `${dateTimeUtil.getFullYear()}-${dateTimeUtil.getMonth()}-${dateTimeUtil.getDay()} ${dateTimeUtil.getHour()}:${dateTimeUtil.getMinute()}:${dateTimeUtil.getSecond()}`;
let TimePath = path + "/Time.txt"; let TimePath = path + "/Time.txt";
let OP = fileio.openSync(TimePath, 0o100 | 0o2002, 0o664); let OP = fileio.openSync(TimePath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
...@@ -132,15 +179,33 @@ struct IndexPage { ...@@ -132,15 +179,33 @@ struct IndexPage {
}.width('100%').height('100%').backgroundColor(Color.Black) }.width('100%').height('100%').backgroundColor(Color.Black)
} }
ClearText(){ ClearText(){
fileio.rmdirSync(path); fileio.unlinkSync(TimePath);
fileio.mkdirSync(path); fileio.unlinkSync(xmlPath);
fileio.mkdirSync(path1); fileio.unlinkSync(path11);
fileio.mkdirSync(path2); fileio.unlinkSync(path22);
fileio.unlinkSync(path33);
fileio.unlinkSync(path44);
fileio.unlinkSync(ArkUIColorBackPath);
fileio.unlinkSync(MediaColorBackPath);
fileio.unlinkSync(CameraColorBackPath);
fileio.openSync(TimePath, 0o100 | 0o2002, 0o664);
fileio.openSync(xmlPath, 0o100 | 0o2002, 0o664);
fileio.openSync(path11, 0o100 | 0o2002, 0o664);
fileio.openSync(path22, 0o100 | 0o2002, 0o664);
fileio.openSync(path33, 0o100 | 0o2002, 0o664);
fileio.openSync(path44, 0o100 | 0o2002, 0o664);
fileio.openSync(ArkUIColorBackPath, 0o100 | 0o2002, 0o664);
fileio.openSync(MediaColorBackPath, 0o100 | 0o2002, 0o664);
fileio.openSync(CameraColorBackPath, 0o100 | 0o2002, 0o664);
fileio.openSync(AudioColorBackPath, 0o100 | 0o2002, 0o664);
FlushData.ResetArkUI();
FlushData.ResetMedia();
FlushData.ResetCamera();
FlushData.ResetAudio();
} }
SaveXml() { SaveXml() {
let dateTimeUtil = new DateTimeUtil(); let dateTimeUtil = new DateTimeUtil();
let endtime = `${dateTimeUtil.getFullYear()}-${dateTimeUtil.getMonth()}-${dateTimeUtil.getDate()} ${dateTimeUtil.getHour()}:${dateTimeUtil.getMinute()}:${dateTimeUtil.getSecond()}`; let endtime = `${dateTimeUtil.getFullYear()}-${dateTimeUtil.getMonth()}-${dateTimeUtil.getDay()} ${dateTimeUtil.getHour()}:${dateTimeUtil.getMinute()}:${dateTimeUtil.getSecond()}`;
let TimePath = path + "/Time.txt";
let fd = fileio.openSync(TimePath, 0o100 | 0o2002, 0o664); let fd = fileio.openSync(TimePath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(40960); let buf = new ArrayBuffer(40960);
fileio.readSync(fd,buf); fileio.readSync(fd,buf);
...@@ -148,8 +213,6 @@ struct IndexPage { ...@@ -148,8 +213,6 @@ struct IndexPage {
let Index = StartTime.indexOf(';'); let Index = StartTime.indexOf(';');
let starttime = StartTime.substring(0,Index); let starttime = StartTime.substring(0,Index);
let path11 = path1 + '/ArkUI.txt';
let path22 = path2 + '/MediaLibrary.txt';
let OP1 = fileio.openSync(path11, 0o100 | 0o2002, 0o664); let OP1 = fileio.openSync(path11, 0o100 | 0o2002, 0o664);
let buf1 = new ArrayBuffer(40960); let buf1 = new ArrayBuffer(40960);
fileio.readSync(OP1,buf1); fileio.readSync(OP1,buf1);
...@@ -308,7 +371,6 @@ struct IndexPage { ...@@ -308,7 +371,6 @@ struct IndexPage {
let that = new util.TextDecoder('utf-8'); let that = new util.TextDecoder('utf-8');
let array = new Uint8Array(arrayBuffer); let array = new Uint8Array(arrayBuffer);
let serializerStr = that.decode(array); let serializerStr = that.decode(array);
let xmlPath = path + "/Test.xml";
console.info(xmlPath); console.info(xmlPath);
try { try {
console.error(TAG, "write xmlPath =" + xmlPath); console.error(TAG, "write xmlPath =" + xmlPath);
......
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import camera from '@ohos.multimedia.camera'
import deviceInfo from '@ohos.deviceInfo'
import fileio from '@ohos.fileio'
import image from '@ohos.multimedia.image'
import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import Logger from '../model/Logger'
import MediaUtils from '../model/MediaUtils'
const CameraMode = {
MODE_PHOTO: 0, // 拍照模式
MODE_VIDEO: 1 // 录像模式
}
//const CameraSize = {
// WIDTH: 1280,
// HEIGHT: 960
//}
const CameraSize = {
WIDTH: 4096,
HEIGHT: 3072
}
class CameraService {
private tag: string = 'qlw CameraService'
private static instance: CameraService = new CameraService()
private mediaUtil = MediaUtils.getInstance()
private cameraManager: camera.CameraManager = undefined
private cameras: Array<camera.CameraDevice> = undefined
private cameraOutputCapability: camera.CameraOutputCapability = undefined
private cameraId: string = ''
private cameraInput: camera.CameraInput = undefined
private previewOutput: camera.PreviewOutput = undefined
private photoOutPut: camera.PhotoOutput = undefined
private captureSession: camera.CaptureSession = undefined
private mReceiver: image.ImageReceiver = undefined
private photoUri: string = ''
private fileAsset: mediaLibrary.FileAsset = undefined
private fd: number = -1
private curMode = CameraMode.MODE_PHOTO
private videoRecorder: media.VideoRecorder = undefined
private videoOutput: camera.VideoOutput = undefined
private handleTakePicture: (photoUri: string) => void = undefined
private mirrorValue: boolean = false
private videoConfig: any = {
audioSourceType: 1,
videoSourceType: 0,
profile: {
audioBitrate: 48000,
audioChannels: 2,
audioCodec: 'audio/mp4v-es',
audioSampleRate: 48000,
durationTime: 1000,
fileFormat: 'mp4',
videoBitrate: 48000,
videoCodec: 'video/mp4v-es',
// videoFrameWidth: globalThis.videoSize.width,
// videoFrameHeight: globalThis.videoSize.height,
videoFrameWidth: 176,
videoFrameHeight: 144,
videoFrameRate: 30
},
url: '',
orientationHint: 0,
location: { latitude: 30, longitude: 130 },
maxSize: 10000,
maxDuration: 10000
}
constructor() {
this.mReceiver = image.createImageReceiver(CameraSize.WIDTH, CameraSize.HEIGHT, image.ImageFormat.JPEG, 8)
Logger.info(this.tag, 'createImageReceiver')
this.mReceiver.on('imageArrival', () => {
Logger.info(this.tag, 'imageArrival')
this.mReceiver.readNextImage((err, image) => {
Logger.info(this.tag, 'readNextImage')
if (err || image === undefined) {
Logger.error(this.tag, 'failed to get valid image')
return
}
image.getComponent(4, (errMsg, img) => {
Logger.info(this.tag, 'getComponent')
if (errMsg || img === undefined) {
Logger.info(this.tag, 'failed to get valid buffer')
return
}
let buffer
if (img.byteBuffer) {
buffer = img.byteBuffer
} else {
Logger.error(this.tag, 'img.byteBuffer is undefined')
}
this.savePicture(buffer, image)
})
})
})
}
async savePicture(buffer: ArrayBuffer, img: image.Image) {
Logger.info(this.tag, 'savePicture')
this.fileAsset = await this.mediaUtil.createAndGetUri(mediaLibrary.MediaType.IMAGE)
this.photoUri = this.fileAsset.uri
Logger.info(this.tag, `this.photoUri = ${this.photoUri}`)
this.fd = await this.mediaUtil.getFdPath(this.fileAsset)
Logger.info(this.tag, `this.fd = ${this.fd}`)
await fileio.write(this.fd, buffer)
await this.fileAsset.close(this.fd)
await img.release()
Logger.info(this.tag, 'save image done')
if (this.handleTakePicture) {
this.handleTakePicture(this.photoUri)
}
}
async initCamera(surfaceId: number, cameraDeviceIndex: number) {
try{
Logger.info(this.tag, 'initCamera')
if (this.curMode === CameraMode.MODE_VIDEO) {
await this.releaseCamera()
}
if (this.curMode === CameraMode.MODE_PHOTO) {
await this.releasePhotoCamera()
}
Logger.info(this.tag, `deviceInfo.deviceType = ${deviceInfo.deviceType}`)
if (deviceInfo.deviceType === 'default') {
this.videoConfig.videoSourceType = 1
} else {
this.videoConfig.videoSourceType = 0
}
this.cameraManager = await camera.getCameraManager(globalThis.abilityContext)
Logger.info(this.tag, 'getCameraManager')
this.cameras = await this.cameraManager.getSupportedCameras()
Logger.info(this.tag, `get cameras ${this.cameras.length}`)
if (this.cameras.length === 0) {
Logger.info(this.tag, 'cannot get cameras')
return
}
this.cameraInput = await this.cameraManager.createCameraInput(this.cameras[cameraDeviceIndex])
await this.cameraInput.open((err) => {
if(err){
Logger.info(this.tag, `cameraInput open Failed : ${err}`)
return
}
Logger.info(this.tag, `cameraInput open success`)
})
Logger.info(this.tag, 'createCameraInput')
this.cameraOutputCapability = await this.cameraManager.getSupportedOutputCapability(this.cameras[cameraDeviceIndex])
Logger.info(this.tag, 'cameraOutputCapability: ' + JSON.stringify(this.cameraOutputCapability))
Logger.info(this.tag, 'cameraOutputCapability previewProfiles: ' + JSON.stringify(this.cameraOutputCapability.previewProfiles))
Logger.info(this.tag, 'cameraOutputCapability photoProfiles: ' + JSON.stringify(this.cameraOutputCapability.photoProfiles))
Logger.info(this.tag, 'cameraOutputCapability videoProfiles: ' + JSON.stringify(this.cameraOutputCapability.videoProfiles))
this.previewOutput = await this.cameraManager.createPreviewOutput(this.cameraOutputCapability.previewProfiles[0], surfaceId.toString())
Logger.info(this.tag, 'createPreviewOutput')
let mSurfaceId = await this.mReceiver.getReceivingSurfaceId()
this.photoOutPut = await this.cameraManager.createPhotoOutput(this.cameraOutputCapability.photoProfiles[0], (mSurfaceId))
Logger.info(this.tag, 'createPhotoOutput')
this.captureSession = await this.cameraManager.createCaptureSession()
Logger.info(this.tag, 'createCaptureSession')
await this.captureSession.beginConfig()
Logger.info(this.tag, 'beginConfig')
await this.captureSession.addInput(this.cameraInput)
await this.captureSession.addOutput(this.previewOutput)
await this.captureSession.addOutput(this.photoOutPut)
await this.captureSession.commitConfig()
await this.captureSession.start()
Logger.info(this.tag, 'captureSession start')
}catch(err){
Logger.info(this.tag, 'initCamera err: ' + err)
}
}
setTakePictureCallback(callback) {
this.handleTakePicture = callback
}
async takePicture(rotationValue, qualityLevel) {
Logger.info(this.tag, 'takePicture')
if (this.curMode === CameraMode.MODE_VIDEO) {
this.curMode = CameraMode.MODE_PHOTO
}
// if(this.photoOutPut.isMirrorSupported()){
// this.mirrorValue = true
// }
let photoSettings = {
rotation: rotationValue,
quality: qualityLevel,
location: { // 位置信息,经纬度
latitude: 0,
longitude: 0,
altitude: 1000
},
mirror: this.mirrorValue
}
Logger.info(this.tag, JSON.stringify(photoSettings))
try{
await this.photoOutPut.capture(photoSettings)
}catch(err){
Logger.info(this.tag, `takePicture err ${err.message}`)
}
Logger.info(this.tag, 'takePicture done')
}
async startVideo() {
try{
Logger.info(this.tag, 'startVideo begin')
await this.captureSession.stop()
await this.captureSession.beginConfig()
Logger.info(this.tag, 'beginConfig')
if (this.curMode === CameraMode.MODE_PHOTO) {
this.curMode = CameraMode.MODE_VIDEO
if (this.photoOutPut) {
await this.captureSession.removeOutput(this.photoOutPut)
}
} else {
if (this.videoOutput) {
await this.captureSession.removeOutput(this.videoOutput)
}
}
}catch(err){
Logger.info(this.tag, 'startVideo err1: ' + err)
}
this.fileAsset = await this.mediaUtil.createAndGetUri(mediaLibrary.MediaType.VIDEO)
this.fd = await this.mediaUtil.getFdPath(this.fileAsset)
this.videoRecorder = await media.createVideoRecorder()
this.videoConfig.url = `fd://${this.fd}`
await this.videoRecorder.prepare(this.videoConfig)
let videoId = await this.videoRecorder.getInputSurface()
Logger.info(this.tag, `cameraOutputCapability.videoProfiles ${this.cameraOutputCapability.videoProfiles.length}`)
// let index = 0
// this.videoOutput = await this.cameraManager.createVideoOutput(this.cameraOutputCapability.videoProfiles[index], videoId)
// @ts-ignore
let videoProfilesObj: camera.VideoProfile = {
"format": 1003,
"size":{
"width": 176,
"height": 144
},
"frameRateRange":{
"min": -1,
"max": 0
}
}
try{
this.videoOutput = await this.cameraManager.createVideoOutput(videoProfilesObj, videoId)
await this.captureSession.addOutput(this.videoOutput)
await this.captureSession.commitConfig()
Logger.info(this.tag, 'captureSession commitConfig')
await this.captureSession.start()
Logger.info(this.tag, 'captureSession start')
await this.videoOutput.start()
Logger.info(this.tag, 'videoOutput start')
await this.videoRecorder.start()
Logger.info(this.tag, 'videoRecorder start')
}catch(err){
Logger.info(this.tag, 'startVideo err2: ' + err)
}
}
async stopVideo() {
Logger.info(this.tag, 'stopVideo called')
await this.videoRecorder.stop()
await this.videoRecorder.release()
await this.videoOutput.stop()
await this.fileAsset.close(this.fd)
}
async releaseCamera() {
Logger.info(this.tag, 'releaseCamera')
if (this.cameraInput) {
// @ts-ignore
await this.cameraInput.release()
}
if (this.previewOutput) {
await this.previewOutput.release()
}
if (this.photoOutPut) {
await this.photoOutPut.release()
}
if (this.videoOutput) {
await this.videoOutput.release()
}
if (this.captureSession) {
await this.captureSession.release()
}
}
async releasePhotoCamera() {
Logger.info(this.tag, 'releaseCamera')
if (this.cameraInput) {
// @ts-ignore
await this.cameraInput.release()
}
if (this.previewOutput) {
await this.previewOutput.release()
}
if (this.photoOutPut) {
await this.photoOutPut.release()
}
if (this.captureSession) {
await this.captureSession.release()
}
}
}
export default new CameraService()
\ No newline at end of file
...@@ -21,6 +21,10 @@ export default class DateTimeUtil { ...@@ -21,6 +21,10 @@ export default class DateTimeUtil {
/** /**
* 时分秒 * 时分秒
*/ */
getTime() {
const DATETIME = new Date()
return this.concatTime(DATETIME.getHours(), DATETIME.getMinutes(), DATETIME.getSeconds())
}
getHour() { getHour() {
const DATETIME = new Date() const DATETIME = new Date()
return DATETIME.getHours() return DATETIME.getHours()
...@@ -37,6 +41,10 @@ export default class DateTimeUtil { ...@@ -37,6 +41,10 @@ export default class DateTimeUtil {
/** /**
* 年月日 * 年月日
*/ */
getDate() {
const DATETIME = new Date()
return this.concatDate(DATETIME.getFullYear(), DATETIME.getMonth() + 1, DATETIME.getDate())
}
getFullYear() { getFullYear() {
const DATETIME = new Date() const DATETIME = new Date()
return DATETIME.getFullYear() return DATETIME.getFullYear()
...@@ -45,7 +53,7 @@ export default class DateTimeUtil { ...@@ -45,7 +53,7 @@ export default class DateTimeUtil {
const DATETIME = new Date() const DATETIME = new Date()
return DATETIME.getMonth() + 1 return DATETIME.getMonth() + 1
} }
getDate() { getDay() {
const DATETIME = new Date() const DATETIME = new Date()
return DATETIME.getDate() return DATETIME.getDate()
} }
......
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import data_preferences from '@ohos.data.preferences';
export default class FlushData{
static ResetArkUI = async ()=>{
let Test = null;
let context =null;
context = globalThis.getContext();
let preferences;
let promise = data_preferences.getPreferences(context,'mystore');
await promise.then((object) => {
preferences = object;
});
promise = preferences.get('ArkUI', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'startup'. Data: " + data);
});
promise = preferences.put('ArkUI', 0);
promise.then(() => {
console.info("Succeeded in putting value of 'test'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
}
static ResetMedia = async ()=>{
let Test = null;
let context =null;
context = globalThis.getContext();
let preferences;
let promise = data_preferences.getPreferences(context,'mystore');
await promise.then((object) => {
preferences = object;
});
promise = preferences.get('Media', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'startup'. Data: " + data);
});
promise = preferences.put('Media', 0);
promise.then(() => {
console.info("Succeeded in putting value of 'test'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
}
static ResetCamera = async ()=>{
let Test = null;
let context =null;
context = globalThis.getContext();
let preferences;
let promise = data_preferences.getPreferences(context,'mystore');
await promise.then((object) => {
preferences = object;
});
promise = preferences.get('Camera', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'startup'. Data: " + data);
});
promise = preferences.put('Camera', 0);
promise.then(() => {
console.info("Succeeded in putting value of 'test'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
}
static ResetAudio = async ()=>{
let Test = null;
let context =null;
context = globalThis.getContext();
let preferences;
let promise = data_preferences.getPreferences(context,'mystore');
await promise.then((object) => {
preferences = object;
});
promise = preferences.get('Camera', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'startup'. Data: " + data);
});
promise = preferences.put('Camera', 0);
promise.then(() => {
console.info("Succeeded in putting value of 'test'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import DateTimeUtil from '../model/DateTimeUtil'
import Logger from './Logger'
export default class MediaUtils {
private tag: string = 'qlw MediaUtils'
private mediaTest: mediaLibrary.MediaLibrary = mediaLibrary.getMediaLibrary(globalThis.abilityContext)
private static instance: MediaUtils = new MediaUtils()
public static getInstance() {
if (this.instance === undefined) {
this.instance = new MediaUtils()
}
return this.instance
}
async createAndGetUri(mediaType: number) {
let info = this.getInfoFromType(mediaType)
let dateTimeUtil = new DateTimeUtil()
let name = `${dateTimeUtil.getDate()}_${dateTimeUtil.getTime()}`
let displayName = `${info.prefix}${name}${info.suffix}`
Logger.info(this.tag, `displayName = ${displayName},mediaType = ${mediaType}`)
let publicPath = await this.mediaTest.getPublicDirectory(info.directory)
Logger.info(this.tag, `publicPath = ${publicPath}`)
return await this.mediaTest.createAsset(mediaType, displayName, publicPath)
}
async queryFile(dataUri: any) {
let fileKeyObj = mediaLibrary.FileKey
if (dataUri !== undefined) {
let args = dataUri.id.toString()
let fetchOp = {
selections: `${fileKeyObj.ID}=?`,
selectionArgs: [args],
}
const fetchFileResult = await this.mediaTest.getFileAssets(fetchOp)
Logger.info(this.tag, `fetchFileResult.getCount() = ${fetchFileResult.getCount()}`)
const fileAsset = await fetchFileResult.getAllObject()
return fileAsset[0]
}
}
async getFdPath(fileAsset: any) {
let fd = await fileAsset.open('Rw')
Logger.info(this.tag, `fd = ${fd}`)
return fd
}
async createFile(mediaType: number) {
let dataUri = await this.createAndGetUri(mediaType)
if (dataUri) {
let fileAsset = await this.queryFile(dataUri)
if (fileAsset) {
let fd = await this.getFdPath(fileAsset)
return fd
}
}
}
async getFileAssetsFromType(mediaType: number) {
Logger.info(this.tag, `getFileAssetsFromType,mediaType = ${mediaType}`)
let fileKeyObj = mediaLibrary.FileKey
let fetchOp = {
selections: `${fileKeyObj.MEDIA_TYPE}=?`,
selectionArgs: [`${mediaType}`],
}
const fetchFileResult = await this.mediaTest.getFileAssets(fetchOp)
Logger.info(this.tag, `getFileAssetsFromType,fetchFileResult.count = ${fetchFileResult.getCount()}`)
let fileAssets = []
if (fetchFileResult.getCount() > 0) {
fileAssets = await fetchFileResult.getAllObject()
}
return fileAssets
}
async getAlbums() {
Logger.info(this.tag, 'getAlbums begin')
let albums = []
const [ files, images, videos, audios ] = await Promise.all([
this.getFileAssetsFromType(mediaLibrary.MediaType.FILE),
this.getFileAssetsFromType(mediaLibrary.MediaType.IMAGE),
this.getFileAssetsFromType(mediaLibrary.MediaType.VIDEO),
this.getFileAssetsFromType(mediaLibrary.MediaType.AUDIO)
])
albums.push({
albumName: 'Documents', count: files.length, mediaType: mediaLibrary.MediaType.FILE
})
albums.push({
albumName: 'Pictures', count: images.length, mediaType: mediaLibrary.MediaType.IMAGE
})
albums.push({
albumName: 'Videos', count: videos.length, mediaType: mediaLibrary.MediaType.VIDEO
})
albums.push({
albumName: 'Audios', count: audios.length, mediaType: mediaLibrary.MediaType.AUDIO
})
return albums
}
deleteFile(media: any) {
let uri = media.uri
Logger.info(this.tag, `deleteFile,uri = ${uri}`)
return this.mediaTest.deleteAsset(uri)
}
onDateChange(callback: () => void) {
this.mediaTest.on('albumChange', () => {
Logger.info(this.tag, 'albumChange called')
callback()
})
this.mediaTest.on('imageChange', () => {
Logger.info(this.tag, 'imageChange called')
callback()
})
this.mediaTest.on('audioChange', () => {
Logger.info(this.tag, 'audioChange called')
callback()
})
this.mediaTest.on('videoChange', () => {
Logger.info(this.tag, 'videoChange called')
callback()
})
this.mediaTest.on('fileChange', () => {
Logger.info(this.tag, 'fileChange called')
callback()
})
}
offDateChange() {
this.mediaTest.off('albumChange')
this.mediaTest.off('imageChange')
this.mediaTest.off('audioChange')
this.mediaTest.off('videoChange')
this.mediaTest.off('fileChange')
}
getInfoFromType(mediaType: number) {
let result = {
prefix: '', suffix: '', directory: 0
}
switch (mediaType) {
case mediaLibrary.MediaType.FILE:
result.prefix = 'FILE_'
result.suffix = '.txt'
result.directory = mediaLibrary.DirectoryType.DIR_DOCUMENTS
break
case mediaLibrary.MediaType.IMAGE:
result.prefix = 'IMG_'
result.suffix = '.jpg'
result.directory = mediaLibrary.DirectoryType.DIR_IMAGE
break
case mediaLibrary.MediaType.VIDEO:
result.prefix = 'VID_'
result.suffix = '.mp4'
result.directory = mediaLibrary.DirectoryType.DIR_VIDEO
break
case mediaLibrary.MediaType.AUDIO:
result.prefix = 'AUD_'
result.suffix = '.wav'
result.directory = mediaLibrary.DirectoryType.DIR_AUDIO
break
}
return result
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import media from '@ohos.multimedia.media'
import Logger from '../model/Logger'
let audioConfig = {
audioSourceType: 1,
audioEncoder: 3,
audioEncodeBitRate: 22050,
audioSampleRate: 22050,
numberOfChannels: 2,
format: 6,
uri: ''
}
export default class RecordModel {
private tag: string = 'qlw RecordModel'
private audioRecorder: media.AudioRecorder = undefined
initAudioRecorder(handleStateChange: () => void) {
this.release();
this.audioRecorder = media.createAudioRecorder()
Logger.info(this.tag, 'create audioRecorder success')
this.audioRecorder.on('prepare', () => {
Logger.info(this.tag, 'setCallback prepare case callback is called')
this.audioRecorder.start()
})
this.audioRecorder.on('start', () => {
Logger.info(this.tag, 'setCallback start case callback is called')
handleStateChange()
})
this.audioRecorder.on('stop', () => {
Logger.info(this.tag, 'audioRecorder stop called')
this.audioRecorder.release()
})
this.audioRecorder.on('pause', () => {
Logger.info(this.tag, 'audioRecorder pause finish')
handleStateChange()
})
this.audioRecorder.on('resume', () => {
Logger.info(this.tag, 'audioRecorder resume finish')
handleStateChange()
})
}
release() {
if (typeof (this.audioRecorder) !== `undefined`) {
Logger.info(this.tag, 'audioRecorder release')
this.audioRecorder.release()
this.audioRecorder = undefined
}
}
startRecorder(pathName: string) {
Logger.info(this.tag, `startRecorder, pathName = ${pathName}`)
if (typeof (this.audioRecorder) !== 'undefined') {
Logger.info(this.tag, 'start prepare')
audioConfig.uri = pathName
this.audioRecorder.prepare(audioConfig)
} else {
Logger.error(this.tag, 'case failed, audioRecorder is null')
}
}
pause() {
Logger.info(this.tag, 'audioRecorder pause called')
if (typeof (this.audioRecorder) !== `undefined`) {
this.audioRecorder.pause()
}
}
resume() {
Logger.info(this.tag, 'audioRecorder resume called')
if (typeof (this.audioRecorder) !== `undefined`) {
this.audioRecorder.resume()
}
}
finish() {
if (typeof (this.audioRecorder) !== `undefined`) {
this.audioRecorder.stop()
}
}
}
\ No newline at end of file
...@@ -47,6 +47,12 @@ ...@@ -47,6 +47,12 @@
}, },
{ {
"name": "ohos.permission.INTERNET" "name": "ohos.permission.INTERNET"
},
{
"name": "ohos.permission.MEDIA_LOCATION"
},
{
"name": "ohos.permission.CAMERA"
} }
] ]
} }
......
...@@ -55,6 +55,15 @@ ...@@ -55,6 +55,15 @@
"pages/MediaLibrary/storeMediaAssetPromise2", "pages/MediaLibrary/storeMediaAssetPromise2",
"pages/MediaLibrary/storeMediaAssetPromise3", "pages/MediaLibrary/storeMediaAssetPromise3",
"pages/MediaLibrary/storeMediaAssetPromise4", "pages/MediaLibrary/storeMediaAssetPromise4",
"pages/MediaLibrary/storeMediaAssetPromise5" "pages/MediaLibrary/storeMediaAssetPromise5",
"pages/CameraOrientation/Camera_Orientation_index",
"pages/CameraOrientation/CameraOrientation0",
"pages/CameraOrientation/CameraOrientation90",
"pages/CameraOrientation/CameraOrientation180",
"pages/CameraOrientation/CameraOrientation270",
"pages/CameraOrientation/CameraFormat",
"pages/CameraOrientation/CameraVideo",
"pages/Audio/Audio_index",
"pages/Audio/ScrollListTest"
] ]
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册