未验证 提交 c931f334 编写于 作者: O openharmony_ci 提交者: Gitee

!7773 validator新增camera模块,预置audio模块模板合入1018分支

Merge pull request !7773 from 田文哲/monthly_20221018
...@@ -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'},
...@@ -58,30 +61,93 @@ struct IndexPage { ...@@ -58,30 +61,93 @@ struct IndexPage {
{title:'CanvasShadowColor',uri:'pages/ArkUI/CanvasShadowColor'}, {title:'CanvasShadowColor',uri:'pages/ArkUI/CanvasShadowColor'},
{title:'CanvasShadowOffsetX',uri:'pages/ArkUI/CanvasShadowOffsetX'}, {title:'CanvasShadowOffsetX',uri:'pages/ArkUI/CanvasShadowOffsetX'},
{title:'CanvasShadowOffsetY',uri:'pages/ArkUI/CanvasShadowOffsetY'}, {title:'CanvasShadowOffsetY',uri:'pages/ArkUI/CanvasShadowOffsetY'},
{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 +230,7 @@ struct IndexPage { ...@@ -164,8 +230,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 +247,11 @@ struct IndexPage { ...@@ -182,6 +247,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 +322,6 @@ struct IndexPage { ...@@ -252,7 +322,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 +337,7 @@ struct IndexPage { ...@@ -268,8 +337,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 +351,13 @@ function filewrite(name1,results,titles){ ...@@ -283,13 +351,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(){
......
/*
* 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/CanvasCustomContainer2';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
private img:ImageBitmap = new ImageBitmap("src/main/resources/base/media/flower.jpg");
@State FillColor: string = '#FF000000';
@State X: number = 0;
@State name: string = 'CanvasImageSmoothingEnabled';
@State StepTips: string = '操作步骤:点击不同的控件'+'\n'+'预期结果:切换平滑过渡效果';
@State Vue: boolean = false;
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('True').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(10, 100, 400, 300);
this.context.imageSmoothingEnabled = true;
this.context.drawImage( this.img,0,0,400,200);
this.Vue = true;
})
Text('False').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(10, 100, 400, 300);
this.context.imageSmoothingEnabled = false;
this.context.drawImage( this.img,0,0,400,200);
this.Vue = true;
})
}.width('70%').height('30%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
.width('100%')
.height('100%')
.backgroundColor('#ffffffff')
.onReady(() =>{
this.context.imageSmoothingEnabled = false;
this.context.drawImage( this.img,0,0,200,200);
})
}.width('100%').height('60%')
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url: 'pages/ArkUI/ArkUI_index',
StepTips: this.StepTips,
content: this.specificNoParam,
FillColor: $FillColor,
X: $X,
name: $name,
Vue: $Vue,
})
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
\ No newline at end of file
...@@ -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-2023 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. * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer'; import {CustomContainer} from '../common/CustomContainer';
import FirstDialog from '../model/FirstDialog'; import FirstDialog from '../model/FirstDialog';
@Entry @Entry
@Component @Component
struct SetCircle { struct CustomContainerUser {
@State FillColor: string = '#FF000000'; private listArr: number[] = Array.from(new Array(50).keys());
@State name: string = 'startImagePreviewPromise1'; @State name: string = 'ScrollingList';
@State StepTips: string = '测试步骤:点击“点击预览”按钮' + '\n' + '预期结果:可以成功预览到一张图片'; @State StepTips: string = '操作步骤:滑动列表观察是否能正常滑动'+'\n'+'预期结果:列表滑动正常';
async aboutToAppear(){ @State Vue: boolean = false;
await FirstDialog.ChooseDialog(this.StepTips,this.name); async aboutToAppear(){
} await FirstDialog.ChooseDialog(this.StepTips,this.name);
@Builder specificNoParam() { this.Vue = true;
Column() { }
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { @Builder specificNoParam() {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' }) Column() {
.onClick(() => { List() {
let TAG = 'startImagePreviewPromise1'; ForEach(this.listArr,(item:any,index:number) => {
let images = [ ListItem() {
"datashare:///media/image/3", Text('Item #' + (index + 1)).width('100%').height(50).fontSize(16).fontColor(Color.White).margin({left:'10vp'})
]; }
let index = 1; },index => index)
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, index).then(() => { }.height('100%').width('100%').divider({strokeWidth:1,color:Color.Grey})
console.log(TAG + "Succeeded in previewing the images."); }.height('83%').width('100%')
}).catch((err) => { }
console.log(TAG + "An error occurred when previewing the images." + JSON.stringify(err)); build() {
}); Column() {
}) CustomContainer({
} title: this.name,
}.width('100%').height('80%').backgroundColor(Color.White) Url: 'pages/Audio/Audio_index',
} StepTips: this.StepTips,
build() { content: this.specificNoParam.bind(this),
Column() { name: $name,
CustomContainer({ Vue: $Vue,
title: this.name, })
Url: 'pages/MediaLibrary/MediaLibrary_index', }.width('100%').height('100%').backgroundColor(Color.Black)
StepTips: this.StepTips, }
content: this.specificNoParam, }
FillColor: $FillColor,
name:$name
})
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
/*
* Copyright (c) 2022-2023 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/Camera/Camera_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-2023 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/Camera/Camera_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-2023 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/Camera/Camera_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-2023 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/Camera/Camera_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-2023 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/Camera/Camera_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. * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import camera from '@ohos.multimedia.camera'
import {CustomContainer} from '../common/MediaCustomContainer'; import Logger from '../model/Logger'
import FirstDialog from '../model/FirstDialog'; import CameraService from '../model/CameraService'
@Entry import {CustomContainer} from '../common/CameraOrientation';
@Component import FirstDialog from '../model/FirstDialog';
struct SetCircle { const CameraMode = {
@State FillColor: string = '#FF000000'; MODE_PHOTO: 0, // 拍照模式
@State name: string = 'startImagePreviewCallback4'; MODE_VIDEO: 1 // 录像模式
@State StepTips: string = '测试步骤:点击“点击预览”按钮'+'\n'+'预期结果:预览图片失败'; }
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name); @Entry
} @Component
@Builder specificNoParam() { struct SetCircle {
Column() { @State FillColor: string = '#FF000000';
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { @State name: string = 'CameraVideo';
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' }) @State StepTips: string = '测试目的:用于测试相机不同分辨率下的录像能力\n-上边显示录像的预览窗口\n-按下测试按钮后触发3s录像,回放的录像文件将在录像结束后显示在下边窗口\n-使用下拉框可以选择相机设备和分辨率'+'\n'+'预期结果:回放的录像视频与预览窗口的画面一致';
.onClick(() => { private tag: string = 'qlw'
let TAG = 'startImagePreviewCallback4'; private mXComponentController: XComponentController = new XComponentController()
let images = [ @State surfaceId: number = 0;
"datashare:///media/image/9999", private x: number = 0;
"datashare:///media/image/9998", @State curModel: number = CameraMode.MODE_PHOTO
"datashare:///media/image/9997", @State cameraDeviceIndex: number = 0
"datashare:///media/image/9996", @State imageRotationValue: number = camera.ImageRotation.ROTATION_90
]; @State qualityLevelValue: number = camera.QualityLevel.QUALITY_LEVEL_LOW
let index = 2; @State assetUri: string = undefined
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, index, (err) => { @State Vue: boolean = false
if (err) { async aboutToAppear(){
console.log(TAG + "An error occurred when previewing the images." + JSON.stringify(err)); await FirstDialog.ChooseDialog(this.StepTips,this.name);
return; }
} handleTakePicture = (assetUri: string) => {
console.log(TAG + "Succeeded in previewing the images."); this.assetUri = assetUri
}); Logger.info(this.tag, `Video recorder end, assetUri: ${this.assetUri}`)
}) }
} @Builder specificNoParam() {
}.width('100%').height('80%').backgroundColor(Color.White) Column() {
} }
build() { }
Column() { build() {
CustomContainer({ Column() {
title: this.name, CustomContainer({
Url:'pages/MediaLibrary/MediaLibrary_index', title: this.name,
StepTips:this.StepTips, Url:'pages/Camera/Camera_index',
content: this.specificNoParam, StepTips:this.StepTips,
FillColor:$FillColor, content: this.specificNoParam,
name:$name FillColor:$FillColor,
}) name: $name,
}.width('100%').height('100%').backgroundColor(Color.Black) 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-2023 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/Camera/CameraOrientation0'},
{title:'CameraOrientation90',uri:'pages/Camera/CameraOrientation90'},
{title:'CameraOrientation180',uri:'pages/Camera/CameraOrientation180'},
{title:'CameraOrientation270',uri:'pages/Camera/CameraOrientation270'},
{title:'CameraFormat',uri:'pages/Camera/CameraFormat'},
{title:'CameraVideo',uri:'pages/Camera/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')
.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
/* /*
* Copyright (c) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import {CustomContainer} from '../common/CustomContainer';
import {CustomContainer} from '../common/MediaCustomContainer'; import FirstDialog from '../model/FirstDialog';
import FirstDialog from '../model/FirstDialog'; @Entry
@Entry @Component
@Component struct CustomContainerUser {
struct SetCircle { private listArr: number[] = Array.from(new Array(50).keys());
@State FillColor: string = '#FF000000'; @State name: string = 'ScrollingList';
@State name: string = 'startImagePreviewPromise2'; @State StepTips: string = '操作步骤:滑动列表观察是否能正常滑动'+'\n'+'预期结果:列表滑动正常';
@State StepTips: string = '测试步骤:点击“点击预览”按钮' + '\n' + '预期结果:起始图片为第一张图片,一共可以预览到两张图片'; @State Vue: boolean = false;
async aboutToAppear(){ async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name); await FirstDialog.ChooseDialog(this.StepTips,this.name);
} this.Vue = true;
@Builder specificNoParam() { }
Column() { @Builder specificNoParam() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { Column() {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' }) List() {
.onClick(() => { ForEach(this.listArr,(item:any,index:number) => {
let TAG = 'startImagePreviewPromise2'; ListItem() {
let images = [ Text('Item #' + (index + 1)).width('100%').height(50).fontSize(16).fontColor(Color.White).margin({left:'10vp'})
"datashare:///media/image/3", }
"datashare:///media/image/4", },index => index)
]; }.height('100%').width('100%').divider({strokeWidth:1,color:Color.Grey})
let index = 1; }.height('83%').width('100%')
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, index).then(() => { }
console.log(TAG + "Succeeded in previewing the images."); build() {
}).catch((err) => { Column() {
console.log(TAG + "An error occurred when previewing the images." + JSON.stringify(err)); CustomContainer({
}); title: this.name,
}) Url: 'pages/Experience/Experience_index',
} StepTips: this.StepTips,
}.width('100%').height('80%').backgroundColor(Color.White) content: this.specificNoParam.bind(this),
} name: $name,
Vue: $Vue,
build() { })
Column() { }.width('100%').height('100%').backgroundColor(Color.Black)
CustomContainer({ }
title: this.name, }
Url: 'pages/MediaLibrary/MediaLibrary_index',
StepTips: this.StepTips,
content: this.specificNoParam,
FillColor: $FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startImagePreviewCallback1';
@State StepTips: string = '测试步骤:点击“点击预览”按钮'+'\n'+'预期结果:可以预览到一张图片';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startImagePreviewCallback1';
let images = [
"datashare:///media/image/3",
];
let index = 1;
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, index, (err) => {
if (err) {
console.log(TAG + "An error occurred when previewing the images." + JSON.stringify(err));
return;
}
console.log(TAG + "Succeeded in previewing the images.");
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startImagePreviewCallback2';
@State StepTips: string = '测试步骤:点击“点击预览”按钮'+'\n'+'预期结果:起始图片为第一张图片,一共可以预览到两张图片';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startImagePreviewCallback2';
let images = [
"datashare:///media/image/3",
"datashare:///media/image/4",
];
let index = 1;
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, index, (err) => {
if (err) {
console.log(TAG + "An error occurred when previewing the images." + JSON.stringify(err));
return;
}
console.log(TAG + "Succeeded in previewing the images.");
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startImagePreviewCallback3';
@State StepTips: string = '测试步骤:点击“点击预览”按钮'+'\n'+'预期结果:起始图片为第三张图片,一共可以预览到四张图片';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startImagePreviewCallback3';
let images = [
"datashare:///media/image/3",
"datashare:///media/image/4",
"datashare:///media/image/5",
"datashare:///media/image/6",
];
let index = 2;
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, index, (err) => {
if (err) {
console.log(TAG + "An error occurred when previewing the images." + JSON.stringify(err));
return;
}
console.log(TAG + "Succeeded in previewing the images.");
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startImagePreviewCallback5';
@State StepTips: string = '测试步骤:点击“点击预览”按钮'+'\n'+'预期结果:成功预览一张图片';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startImagePreviewCallback5';
let images = [
"datashare:///media/image/3",
];
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, (err) => {
if (err) {
console.log(TAG + "startImagePreview_One An error occurred when previewing the images." + JSON.stringify(err));
return;
}
console.log(TAG + "startImagePreview_One Succeeded in previewing the images.");
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startImagePreviewCallback6';
@State StepTips: string = '测试步骤:点击“点击预览”按钮'+'\n'+'预期结果:成功预览五张图片';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startImagePreviewCallback6';
let images = [
"datashare:///media/image/3",
"datashare:///media/image/4",
"datashare:///media/image/5",
"datashare:///media/image/6",
"datashare:///media/image/2",
];
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, (err) => {
if (err) {
console.log(TAG + "startImagePreview_MultiPle An error occurred when previewing the images." + JSON.stringify(err));
return;
}
console.log(TAG + "startImagePreview_MultiPle Succeeded in previewing the images.");
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startImagePreviewCallback7';
@State StepTips: string = '测试步骤:点击“点击预览”按钮'+'\n'+'预期结果:预览图片失败';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startImagePreviewCallback7';
let images = [
"datashare:///media/image/9999",
];
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, (err) => {
if (err) {
console.log(TAG + "startImagePreview_One An error occurred when previewing the images." + JSON.stringify(err));
return;
}
console.log(TAG + "startImagePreview_One Succeeded in previewing the images.");
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startImagePreviewPromise3';
@State StepTips: string = '测试步骤:点击“点击预览”按钮' + '\n' + '预期结果:起始图片为第二张图片,一共可以预览到三张图片';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startImagePreviewPromise3';
let images = [
"datashare:///media/image/3",
"datashare:///media/image/4",
"datashare:///media/image/5",
];
let index = 1;
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, index).then(() => {
console.log(TAG + "Succeeded in previewing the images.");
}).catch((err) => {
console.log(TAG + "An error occurred when previewing the images." + JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url: 'pages/MediaLibrary/MediaLibrary_index',
StepTips: this.StepTips,
content: this.specificNoParam,
FillColor: $FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startMediaSelectCallback1';
@State StepTips: string = '测试步骤:点击“点击选择”按钮'+'\n'+'预期结果:可以选择一张图片(单选)';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击选择').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startMediaSelectCallback1';
let option : mediaLibrary.MediaSelectOption = {
type : "image",
count : 1
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startMediaSelect(option, (err, value) => {
if (err) {
console.log(TAG + "An error occurred when selecting image resources." + JSON.stringify(err));
return;
}
console.log(TAG + "image resources selected." + JSON.stringify(value));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor, name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startMediaSelectCallback2';
@State StepTips: string = '测试步骤:点击“点击选择”按钮'+'\n'+'预期结果:可以选择多张图片(多选)';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击选择').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startMediaSelectCallback2';
let option : mediaLibrary.MediaSelectOption = {
type : "image",
count : 2
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startMediaSelect(option, (err, value) => {
if (err) {
console.log(TAG + "An error occurred when selecting image resources." + JSON.stringify(err));
return;
}
console.log(TAG + "image resources selected." + JSON.stringify(value));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startMediaSelectCallback3';
@State StepTips: string = '测试步骤:点击“点击选择”按钮'+'\n'+'预期结果:可以选择多个图片、视频文件';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击选择').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startMediaSelectCallback3';
let option : mediaLibrary.MediaSelectOption = {
type : "media",
count : 2
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startMediaSelect(option, (err, value) => {
if (err) {
console.log(TAG + "An error occurred when selecting image resources." + JSON.stringify(err));
return;
}
console.log(TAG + "image resources selected." + JSON.stringify(value));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startMediaSelectCallback4';
@State StepTips: string = '测试步骤:点击“点击选择”按钮'+'\n'+'预期结果:可以选择多个视频资源';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击选择').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startMediaSelectCallback4';
let option : mediaLibrary.MediaSelectOption = {
type : "video",
count : 2
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startMediaSelect(option, (err, value) => {
if (err) {
console.log(TAG + "An error occurred when selecting image resources." + JSON.stringify(err));
return;
}
console.log(TAG + "image resources selected." + JSON.stringify(value));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startMediaSelectPromise1';
@State StepTips: string = '测试步骤:点击“点击选择”按钮'+'\n'+'预期结果:可以选择单张图片';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击选择').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startMediaSelectPromise1';
let option : mediaLibrary.MediaSelectOption = {
type : "image",
count : 1
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startMediaSelect(option).then((value) => {
console.log(TAG + "Media resources selected." + JSON.stringify(value));
}).catch((err) => {
console.log(TAG + "An error occurred when selecting media resources." + JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startMediaSelectPromise2';
@State StepTips: string = '测试步骤:点击“点击选择”按钮'+'\n'+'预期结果:可以选择多张图片';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击选择').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startMediaSelectPromise2';
let option : mediaLibrary.MediaSelectOption = {
type : "image",
count : 2
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startMediaSelect(option).then((value) => {
console.log(TAG + "Media resources selected." + JSON.stringify(value));
}).catch((err) => {
console.log(TAG + "An error occurred when selecting media resources." + JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startMediaSelectPromise3';
@State StepTips: string = '测试步骤:点击“点击选择”按钮'+'\n'+'预期结果:可以选择多个图片、视频资源';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击选择').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startMediaSelect5_media2';
let option : mediaLibrary.MediaSelectOption = {
type : "media",
count : 2
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startMediaSelect(option).then((value) => {
console.log(TAG + "Media resources selected." + JSON.stringify(value));
}).catch((err) => {
console.log(TAG + "An error occurred when selecting media resources." + JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'startMediaSelectPromise4';
@State StepTips: string = '测试步骤:点击“点击选择”按钮'+'\n'+'预期结果:可以选择单个视频';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击选择').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' })
.onClick(() => {
let TAG = 'startMediaSelect5_video2';
let option : mediaLibrary.MediaSelectOption = {
type : "video",
count : -1
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startMediaSelect(option).then((value) => {
console.log(TAG + "Media resources selected." + JSON.stringify(value));
}).catch((err) => {
console.log(TAG + "An error occurred when selecting media resources." + JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'storeMediaAssetCallback1';
@State StepTips: string = '操作步骤:点击“点击保存”按钮'+'\n'+'预期结果:成功保存一张图片,资源内容为“hello world”';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam(){
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击保存').margin('2%').backgroundColor('#FFDDDDF8').fontSize(20).border({ width: 1 }).size({ width: '70%', height: '20%' })
.onClick(async () => {
let TAG = 'storeMediaAssetCallback1';
let data = await globalThis.abilityContext.getFilesDir();
let time = new Date().getTime();
console.log("data is"+ JSON.stringify(data));
data = 'data/storage/el2/base/haps/entry';
let JpgPath = data + "/files/"+time + ".jpg";
let srcFd =await fileio.open(JpgPath,0o102,0o0600);
await fileio.write(srcFd,"hello world");
await fileio.close(srcFd);
let option = {
src : JpgPath,
mimeType : "image/*",
relativePath : "Pictures/"
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).storeMediaAsset(option, (err, value) => {
if (err) {
console.log(TAG +"An error occurred when storing image resources." + JSON.stringify(err));
return;
}
AlertDialog.show(
{
title: '保存成功',
message: '查询到Pictures路径下新增一个.jpg格式的图片资源,资源内容为“hello world”',
confirm: {
value: 'OK',
action: () => {
console.info(TAG + 'Button-clicking callback')
}
},
cancel: () => {
console.info(TAG + 'Closed callbacks')
}
}
)
console.log(TAG + "image resources stored. "+ JSON.stringify(value));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'storeMediaAssetCallback2';
@State StepTips: string = '操作步骤:点击“点击保存”按钮'+'\n'+'预期结果:成功保存音频,资源内容为“hello world”';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam(){
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击保存').margin('2%').backgroundColor('#FFDDDDF8').fontSize(20).border({ width: 1 }).size({ width: '70%', height: '20%' })
.onClick(async () => {
let TAG = 'storeMediaAssetCallback2';
let data = await globalThis.abilityContext.getFilesDir();
let time = new Date().getTime();
console.log("data is"+ JSON.stringify(data));
data = 'data/storage/el2/base/haps/entry';
let PathMp3 = data + "/files/"+time + ".mp3";
let srcFd =await fileio.open(PathMp3,0o102,0o0600);
await fileio.write(srcFd,"hello world");
await fileio.close(srcFd);
let option = {
src : PathMp3,
mimeType : "audio/mp3",
relativePath : "Audios/"
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).storeMediaAsset(option, (err, value) => {
if (err) {
console.log(TAG + "An error occurred when storing audios resources."+ JSON.stringify(err));
return;
}
AlertDialog.show(
{
title: '保存成功',
message: '查询到Audios路径下新增一个.mp3格式的音频资源,资源内容为“hello world”',
confirm: {
value: 'OK',
action: () => {
console.info(TAG + 'Button-clicking callback')
}
},
cancel: () => {
console.info(TAG + 'Closed callbacks')
}
}
)
console.log(TAG + "audios resources stored. "+ JSON.stringify(value));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'storeMediaAssetCallback3';
@State StepTips: string = '操作步骤:点击“点击保存”按钮'+'\n'+'预期结果:成功保存视频,资源内容为“hello world”';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam(){
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击保存').margin('2%').backgroundColor('#FFDDDDF8').fontSize(20).border({ width: 1 }).size({ width: '70%', height: '20%' })
.onClick(async () => {
let TAG = 'storeMediaAssetCallback3';
let data = await globalThis.abilityContext.getFilesDir();
let time = new Date().getTime();
console.log("data is"+ JSON.stringify(data));
data = 'data/storage/el2/base/haps/entry';
let PathMp4 = data + "/files/"+time + ".mp4";
let srcFd =await fileio.open(PathMp4,0o102,0o0600);
await fileio.write(srcFd,"hello world");
await fileio.close(srcFd);
let option = {
src : PathMp4,
mimeType : "video/mp4",
relativePath : "Videos/"
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).storeMediaAsset(option, (err, value) => {
if (err) {
console.log(TAG + "An error occurred when storing videos resources."+ JSON.stringify(err));
return;
}
AlertDialog.show(
{
title: '保存成功',
message: '查询到Videos路径下新增一个.mp4格式的视频资源,资源内容为“hello world”',
confirm: {
value: 'OK',
action: () => {
console.info(TAG + 'Button-clicking callback')
}
},
cancel: () => {
console.info(TAG + 'Closed callbacks')
}
}
)
console.log(TAG + "videos resources stored. "+ JSON.stringify(value));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'storeMediaAssetCallback4';
@State StepTips: string = '操作步骤:点击“点击保存”按钮'+'\n'+'预期结果:成功保存文件,资源内容为“hello world”';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam(){
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击保存').margin('2%').backgroundColor('#FFDDDDF8').fontSize(20).border({ width: 1 }).size({ width: '70%', height: '20%' })
.onClick(async () => {
let TAG = 'storeMediaAssetCallback4';
let data = await globalThis.abilityContext.getFilesDir();
let time = new Date().getTime();
console.log("data is"+ JSON.stringify(data));
data = 'data/storage/el2/base/haps/entry';
let PathPdf = data + "/files/"+time + ".Pdf";
let srcFd =await fileio.open(PathPdf,0o102,0o0600);
await fileio.write(srcFd,"hello world");
await fileio.close(srcFd);
let option = {
src : PathPdf,
mimeType : "file/pdf",
relativePath : "Documents/"
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).storeMediaAsset(option, (err, value) => {
if (err) {
console.log(TAG + "An error occurred when storing files resources."+ JSON.stringify(err));
return;
}
AlertDialog.show(
{
title: '保存成功',
message: '查询到Documents路径下新增一个.Pdf格式的文件资源,资源内容为“hello world”',
confirm: {
value: 'OK',
action: () => {
console.info(TAG + 'Button-clicking1 callback')
}
},
cancel: () => {
console.info(TAG + 'Closed1 callbacks')
}
}
)
console.log(TAG + "files resources stored. "+ JSON.stringify(value));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'storeMediaAssetPromise1';
@State StepTips: string = '操作步骤:点击“点击保存”按钮'+'\n'+'预期结果:成功保存图片,资源内容为“hello world”';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击保存').margin('2%').backgroundColor('#FFDDDDF8').fontSize(20).border({ width: 1 }).size({ width: '70%', height: '20%' })
.onClick(async () => {
let TAG = 'storeMediaAssetPromise1';
let context0 = featureAbility.getContext();
let data = await context0.getFilesDir();
let time = new Date().getTime();
console.log("data is"+ JSON.stringify(data));
data = 'data/storage/el2/base/haps/entry';
let JpgPath = data + "/files/"+time + ".jpg";
let srcFd =await fileio.open(JpgPath,0o102,0o0600);
await fileio.write(srcFd,"hello world");
await fileio.close(srcFd);
let option = {
src : JpgPath,
mimeType : "image/*",
relativePath : "Pictures/"
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).storeMediaAsset(option).then((value) => {
AlertDialog.show(
{
title: '保存成功',
message: '查询到Pictures路径下新增一个.jpg格式的图片资源,资源内容为“hello world”',
confirm: {
value: 'OK',
action: () => {
console.info(TAG + 'Button-clicking callback')
}
},
cancel: () => {
console.info(TAG + 'Closed callbacks')
}
}
)
console.log(TAG + "image resources stored. "+ JSON.stringify(value));
}).catch((err) => {
console.log(TAG + "An error occurred when storing image resources."+ JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'storeMediaAssetPromise2';
@State StepTips: string = '操作步骤:点击“点击保存”按钮'+'\n'+'预期结果:成功保存音频,资源内容为“hello world”';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击保存').margin('2%').backgroundColor('#FFDDDDF8').fontSize(20).border({ width: 1 }).size({ width: '70%', height: '20%' })
.onClick(async () => {
let TAG = 'storeMediaAssetPromise2';
let data = await globalThis.abilityContext.getFilesDir();
let time = new Date().getTime();
console.log("data is"+ JSON.stringify(data));
data = 'data/storage/el2/base/haps/entry';
let PathMp3 = data + "/files/"+time + ".mp3";
let srcFd =await fileio.open(PathMp3,0o102,0o0600);
await fileio.write(srcFd,"hello world");
await fileio.close(srcFd);
let option = {
src : PathMp3,
mimeType : "audio/mp3",
relativePath : "Audios/"
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).storeMediaAsset(option).then((value) => {
AlertDialog.show(
{
title: '保存成功',
message: '查询到Audios路径下新增一个.mp3格式的音频资源,资源内容为“hello world”',
confirm: {
value: 'OK',
action: () => {
console.info(TAG + 'Button-clicking callback')
}
},
cancel: () => {
console.info(TAG + 'Closed callbacks')
}
}
)
console.log(TAG + "audios resources stored. "+ JSON.stringify(value));
}).catch((err) => {
console.log(TAG + "An error occurred when storing audios resources."+ JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'storeMediaAssetPromise3';
@State StepTips: string = '操作步骤:点击“点击保存”按钮'+'\n'+'预期结果:成功保存视频,资源内容为“hello world”';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击保存').margin('2%').backgroundColor('#FFDDDDF8').fontSize(20).border({ width: 1 }).size({ width: '70%', height: '20%' })
.onClick(async () => {
let TAG = 'storeMediaAssetPromise3';
let data = await globalThis.abilityContext.getFilesDir();
let time = new Date().getTime();
console.log("data is"+ JSON.stringify(data));
data = 'data/storage/el2/base/haps/entry';
let PathMp4 = data + "/files/"+time + ".mp4";
let srcFd =await fileio.open(PathMp4,0o102,0o0600);
await fileio.write(srcFd,"hello world");
await fileio.close(srcFd);
let option = {
src : PathMp4,
mimeType : "video/mp4",
relativePath : "Videos/"
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).storeMediaAsset(option).then((value) => {
AlertDialog.show(
{
title: '保存成功',
message: '查询到Videos路径下新增一个.mp4格式的视频资源,资源内容为“hello world”',
confirm: {
value: 'OK',
action: () => {
console.info(TAG + ' Button-clicking callback')
}
},
cancel: () => {
console.info(TAG + ' Closed callbacks')
}
}
)
console.log(TAG + " videos resources stored. "+ JSON.stringify(value));
}).catch((err) => {
console.log(TAG + " An error occurred when storing videos resources."+ JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'storeMediaAssetPromise4';
@State StepTips: string = '操作步骤:点击“点击保存”按钮'+'\n'+'预期结果:成功保存文件,资源内容为“hello world”';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击保存').margin('2%').backgroundColor('#FFDDDDF8').fontSize(20).border({ width: 1 }).size({ width: '70%', height: '20%' })
.onClick(async () => {
let TAG = 'storeMediaAssetPromise4';
let data = await globalThis.abilityContext.getFilesDir();
let time = new Date().getTime();
console.log("data is"+ JSON.stringify(data));
data = 'data/storage/el2/base/haps/entry';
let PathPdf = data + "/files/"+time + ".Pdf";
let srcFd =await fileio.open(PathPdf,0o102,0o0600);
await fileio.write(srcFd,"hello world");
await fileio.close(srcFd);
let option = {
src : PathPdf,
mimeType : "file/pdf",
relativePath : "Documents/"
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).storeMediaAsset(option).then((value) => {
AlertDialog.show(
{
title: '保存成功',
message: '查询到Documents路径下新增一个.Pdf格式的文件资源,资源内容为“hello world”',
confirm: {
value: 'OK',
action: () => {
console.info(TAG + 'Button-clicking callback')
}
},
cancel: () => {
console.info(TAG + 'Closed callbacks')
}
}
)
console.log(TAG + "files resources stored. "+ JSON.stringify(value));
}).catch((err) => {
console.log(TAG + "An error occurred when storing files resources."+ JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility';
import {CustomContainer} from '../common/MediaCustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
@State FillColor: string = '#FF000000';
@State name: string = 'storeMediaAssetPromise5';
@State StepTips: string = '操作步骤:点击“点击保存”按钮'+'\n'+'预期结果:保存图片失败';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('点击保存').margin('2%').backgroundColor('#FFDDDDF8').fontSize(20).border({ width: 1 }).size({ width: '70%', height: '20%' })
.onClick(async () => {
let TAG = 'storeMediaAssetPromise5';
let data = await globalThis.abilityContext.getFilesDir();
let time = new Date().getTime();
console.log("data is"+ JSON.stringify(data));
data = 'data/storage/el2/base/haps/entry';
let JpgPath = data + "/files/"+time + ".jpg";
let srcFd =await fileio.open(JpgPath,0o102,0o0600);
await fileio.write(srcFd,"hello world");
await fileio.close(srcFd);
let option = {
src : JpgPath,
mimeType : "123",
relativePath : "Pictures/"
};
mediaLibrary.getMediaLibrary(globalThis.abilityContext).storeMediaAsset(option).then((value) => {
console.log(TAG + "image resources stored. "+ JSON.stringify(value));
}).catch((err) => {
AlertDialog.show(
{
title: '保存失败',
message: '媒体MIME类型错误',
confirm: {
value: 'OK',
action: () => {
console.info(TAG + 'Button-clicking callback')
}
},
cancel: () => {
console.info(TAG + 'Closed callbacks')
}
}
)
console.log(TAG + "An error occurred when storing image resources."+ JSON.stringify(err));
});
})
}
}.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/MediaLibrary/MediaLibrary_index',
StepTips:this.StepTips,
content: this.specificNoParam,
FillColor:$FillColor,
name:$name
})
}.width('100%').height('100%').backgroundColor(Color.Black)
}
}
\ No newline at end of file
/*
* Copyright (c) 2022-2023 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 + '/Player';
let VarColor = [];
let ColorBackPath = path + '/PlayerColorBack.txt';
let txtPath = path1 + 'PlayerReport.txt';
let xmlPath =path1 + 'PlayerTest.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/Player/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('Player', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'Player'. 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('Player', 1);
promise.then(() => {
console.info("Succeeded in putting value of 'Player'.");
});
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('Player 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/Player/PlayerTest.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 + '/PlayerReport.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","ActsPlayerTest");
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", "ActsPlayerTest");
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. * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import {CustomContainer} from '../common/CustomContainer';
import {CustomContainer} from '../common/MediaCustomContainer'; import FirstDialog from '../model/FirstDialog';
import FirstDialog from '../model/FirstDialog'; @Entry
@Entry @Component
@Component struct CustomContainerUser {
struct SetCircle { private listArr: number[] = Array.from(new Array(50).keys());
@State FillColor: string = '#FF000000'; @State name: string = 'ScrollingList';
@State name: string = 'startImagePreviewPromise4'; @State StepTips: string = '操作步骤:滑动列表观察是否能正常滑动'+'\n'+'预期结果:列表滑动正常';
@State StepTips: string = '测试步骤:点击“点击预览”按钮' + '\n' + '预期结果:预览图片失败'; @State Vue: boolean = false;
async aboutToAppear(){ async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name); await FirstDialog.ChooseDialog(this.StepTips,this.name);
} this.Vue = true;
@Builder specificNoParam() { }
Column() { @Builder specificNoParam() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { Column() {
Text('点击预览').margin('5%').fontSize(20).border({ width: 1 }).size({ width: '75%', height: '30%' }) List() {
.onClick(() => { ForEach(this.listArr,(item:any,index:number) => {
let TAG = 'startImagePreviewPromise4'; ListItem() {
let images = [ Text('Item #' + (index + 1)).width('100%').height(50).fontSize(16).fontColor(Color.White).margin({left:'10vp'})
"datashare:///media/image/9999", }
"datashare:///media/image/9998", },index => index)
"datashare:///media/image/9997", }.height('100%').width('100%').divider({strokeWidth:1,color:Color.Grey})
]; }.height('83%').width('100%')
let index = 1; }
mediaLibrary.getMediaLibrary(globalThis.abilityContext).startImagePreview(images, index).then(() => { build() {
console.log(TAG + "Succeeded in previewing the images."); Column() {
}).catch((err) => { CustomContainer({
console.log(TAG + "An error occurred when previewing the images." + JSON.stringify(err)); title: this.name,
}); Url: 'pages/Player/Player_index',
}) StepTips: this.StepTips,
} content: this.specificNoParam.bind(this),
}.width('100%').height('80%').backgroundColor(Color.White) name: $name,
} Vue: $Vue,
})
build() { }.width('100%').height('100%').backgroundColor(Color.Black)
Column() { }
CustomContainer({ }
title: this.name,
Url: 'pages/MediaLibrary/MediaLibrary_index',
StepTips: this.StepTips,
content: this.specificNoParam,
FillColor: $FillColor,
name:$name
})
}.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 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}`);
}
}
}
...@@ -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-2023 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 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('Audio', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'Audio'. Data: " + data);
});
promise = preferences.put('Audio', 0);
promise.then(() => {
console.info("Succeeded in putting value of 'Audio'.");
});
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 ResetPlayer = 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('Player', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'Player'. Data: " + data);
});
promise = preferences.put('Player', 0);
promise.then(() => {
console.info("Succeeded in putting value of 'Player'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
}
static ResetExperience = 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('Experience', 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'Experience'. Data: " + data);
});
promise = preferences.put('Experience', 0);
promise.then(() => {
console.info("Succeeded in putting value of 'Experience'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册