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

!7056 添加手动测试用例actsvalidator到acts仓

Merge pull request !7056 from 田文哲/master
......@@ -48,6 +48,7 @@ _all_test_packages = [
"${ACTS_ROOT}/barrierfree:barrierfree",
"${ACTS_ROOT}/applications:applications",
"${ACTS_ROOT}/wukong:wukong",
"${ACTS_ROOT}/validator:validator",
]
_all_test_packages_ivi = [
......
# 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("//build/ohos_var.gni")
import("//test/xts/tools/build/suite.gni")
group("validator") {
testonly = true
if (is_standard_system) {
deps = [ "acts_validator:acts_validator_test" ]
}
}
{
"app": {
"bundleName": "com.example.actsvalidator",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"keepAlive": true,
"singleUser": true,
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
{
"string": [
{
"name": "app_name",
"value": "ActsValidator"
}
]
}
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("acts_validator_test") {
hap_profile = "./src/main/module.json"
js_build_mode = "debug"
deps = [
":acts_validator_assets",
":acts_validator_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsValidatorTest"
}
ohos_app_scope("acts_validator_app_profile") {
app_profile = "./AppScope/app.json"
sources = [ "./AppScope/resources" ]
}
ohos_js_assets("acts_validator_assets") {
source_dir = "./src/main/ets"
}
ohos_resources("acts_validator_resources") {
sources = [ "./src/main/resources" ]
deps = [ ":acts_validator_app_profile" ]
hap_profile = "./src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "300000",
"testcase-timeout": "300000",
"shell-timeout": "300000",
"bundle-name": "com.example.actsvalidator",
"package-name": "com.example.actsvalidator"
},
"kits": [
{
"test-file-name": [
"ActsValidatorTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"run-command": [
"hilog -Q pidoff"
]
}
]
}
\ No newline at end of file
import AbilityStage from "@ohos.app.ability.AbilityStage"
import Logger from '../pages/model/Logger'
export default class MyAbilityStage extends AbilityStage {
onCreate() {
Logger.info('[MyAbilityStage]', 'MyAbilityStage onCreate')
}
}
\ No newline at end of file
import Ability from '@ohos.app.ability.UIAbility'
const PERMISSIONS: Array<string> = [
'ohos.permission.READ_MEDIA',
'ohos.permission.WRITE_MEDIA',
'ohos.permission.CAPTURE_SCREEN']
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
this.context.requestPermissionsFromUser(PERMISSIONS)
globalThis.dir=this.context.filesDir;
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
windowStage.loadContent("pages/index", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import prompt from '@ohos.prompt';
import router from '@ohos.router';
import fileio from '@ohos.fileio';
import xml from '@ohos.xml';
import fileIO from '@ohos.fileio';
import util from '@ohos.util';
const TAG = 'ParseXML';
let path = globalThis.dir;
let path1;
path1 = path + '/report1';
@Entry
@Component
struct IndexPage {
@State BackColor: string = '#ff808080';
@State ClearAll : boolean = false;
private current : number = undefined;
@State count : number = 0;
@State result : string = '';
private TestCaseList = [
{title:'Scroll List',uri:'pages/ArkUI/ScrollListTest'},
{title:'TouchMove',uri:'pages/ArkUI/TouchMoveTest'},
{title:'PinchGesture',uri:'pages/ArkUI/PinchGestureTest'},
{title:'RotationGesture',uri:'pages/ArkUI/RotationGestureTest'},
{title:'SwipeGesture',uri:'pages/ArkUI/SwipeGestureTest'},
{title:'LongPressGesture',uri:'pages/ArkUI/LongPressGesture'},
{title:'TapGesture',uri:'pages/ArkUI/TapGesture'},
{title:'PanGesture',uri:'pages/ArkUI/PanGesture'},
{title:'CanvasFillStyle',uri:'pages/ArkUI/CanvasFillStyle'},
{title:'CanvasLineWidth',uri:'pages/ArkUI/CanvasLineWidth'},
{title:'CanvasStrokeStyle',uri:'pages/ArkUI/CanvasStrokeStyle'},
{title:'CanvasLineCap',uri:'pages/ArkUI/CanvasLineCap'},
{title:'CanvasLineJoin',uri:'pages/ArkUI/CanvasLineJoin'},
{title:'CanvasMiterLimit',uri:'pages/ArkUI/CanvasMiterLimit'},
{title:'CanvasFont',uri:'pages/ArkUI/CanvasFont'},
{title:'CanvasTextAlign',uri:'pages/ArkUI/CanvasTextAlign'},
{title:'CanvasGlobalAlpha',uri:'pages/ArkUI/CanvasGlobalAlpha'},
{title:'CanvasLineDashOffset',uri:'pages/ArkUI/CanvasLineDashOffset'},
{title:'CanvasGlobalCompositeOperation',uri:'pages/ArkUI/CanvasGlobalCompositeOperation'},
{title:'CanvasShadowBlur',uri:'pages/ArkUI/CanvasShadowBlur'},
{title:'CanvasShadowColor',uri:'pages/ArkUI/CanvasShadowColor'},
{title:'CanvasShadowOffsetX',uri:'pages/ArkUI/CanvasShadowOffsetX'},
{title:'CanvasShadowOffsetY',uri:'pages/ArkUI/CanvasShadowOffsetY'},
{title:'CanvasImageSmoothingEnabled',uri:'pages/ArkUI/CanvasImageSmoothingEnabled'},
]
@State ColorObject : string[] = ['#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080',
'#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080',
'#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080']
onPageShow(){
if (this.count === 1){
this.result = router.getParams()['result'];
let titles = router.getParams()['title'];
let name1 = '刚刚点进了哪个用例:'+ titles;
let results = this.result;
if (this.result === 'Pass'){
this.ColorObject[this.current] = '#ff008000';
filewrite(name1,results,titles)
}
else if (this.result === 'Fail'){
this.ColorObject[this.current] = '#ffff0000';
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('ArkUI 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(() => {
this.ClearAll = true;
this.ColorObject.forEach((value, index) => {
this.ColorObject[index] = '#ff808080';
});
this.ClearText();
prompt.showToast({
message: '结果已删除', duration: 1000
});
})
Button(){
Image($r('app.media.ic_public_save'))
.width('30vp')
.height('30vp')
.margin({ left: 30 })
}.backgroundColor(Color.Black)
.onClick(() => {
this.ReadTextParseXml();
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)
Text(this.BackColor.toString()).visibility(Visibility.None)
}.width('100%').height(50).alignItems(VerticalAlign.Center).backgroundColor(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);
}
ReadTextParseXml(){
let ReportPath = path1 + '/report1.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 arrayBuffer = new ArrayBuffer(40960);
let bufView = new DataView(arrayBuffer);
let serializer = new xml.XmlSerializer(bufView);
serializer.setDeclaration();
serializer.startElement("testsuite");
serializer.setAttributes("name","ActsArkUITest");
for(let i=0; i<title.length; i++){
serializer.startElement("testcase");
serializer.setAttributes("name",String(title[i]));
serializer.setAttributes("result",String(result[i]));
serializer.endElement();
}
serializer.endElement();
let that = new util.TextDecoder('utf-8');
let array = new Uint8Array(arrayBuffer);
let serializerStr = that.decode(array);
let xmlPath = path1 + "/ArkUITest.xml";
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 txtpath = path1 + '/report1.txt';
let fd = fileio.openSync(txtpath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(4096);
let RD = fileio.readSync(fd,buf);
console.info("RRRRRRRRRRd"+RD);
let report = String.fromCharCode.apply(null,new Uint8Array(buf));
let WriteTitle = (titles).toString();
let number = WriteTitle.length + 6;
let Index = report.indexOf(WriteTitle);
let Log = (titles+";"+results+";").toString();
if (Index == -1){
fileio.writeSync(fd,Log);
}
else if (Index != -1){
let key = report.substring(Index,Index+number);
let FD = fileio.openSync(txtpath, 0o102, 0o666);
report = report.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = report.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(txtpath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {CustomContainer} from '../common/CanvasCustomContainer1';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
@State FillColor: string = '#FF000000';
@State name: string = 'CanvasFillStyle';
@State StepTips: string = '操作步骤:点击不同的颜色控件'+'\n'+'预期结果:原本默认黑色的填色区域会随点击变化';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('Red').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(100, 160, 150, 100);
this.FillColor = '#FFFF0000';
this.context.fillStyle = this.FillColor;
this.context.fillRect(100, 160, 150, 100);
})
Text('Yellow').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(100, 160, 150, 100);
this.FillColor = '#fffffc3c';
this.context.fillStyle = this.FillColor;
this.context.fillRect(100, 160, 150, 100);
})
Text('Green').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(100, 160, 150, 100);
this.FillColor = '#ff19fa00';
this.context.fillStyle = this.FillColor;
this.context.fillRect(100, 160, 150, 100);
})
}.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.fillStyle = this.FillColor;
this.context.fillRect(100, 160, 150, 100);
})
}.width('100%').height('70%')
}.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,
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 {CustomContainer} from '../common/CanvasCustomContainer1';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
@State FillColor: string = '#FF000000';
@State name: string = 'CanvasFillStyle';
@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 }){
Row(){
Text('').fontSize(0).border({width:0}).size({width:'0%',height:'1%'})
}
Row({space:10}){
Text('font-style').fontSize(13).border({width:0}).size({width:'24%',height:'18%'})
Text('normal').fontSize(13).border({width:2}).size({width:'24%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal normal 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('italic').fontSize(13).border({width:2}).size({width:'24%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'italic normal 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
}
Row({space:8}) {
Text('font-weight').fontSize(13).border({ width: 0 }).size({ width: '24%', height: '18%' })
Text('normal').fontSize(13).border({ width: 2 }).size({ width: '16%', height: '18%' })
.onClick(() => {
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal normal 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('bold').fontSize(13).border({width:2}).size({width:'16%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal bold 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('bolder').fontSize(13).border({width:2}).size({width:'16%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal bolder 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('lighter').fontSize(13).border({width:2}).size({width:'16%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal lighter 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
}
Row({space:5}) {
Text('100').fontSize(13).border({ width: 2 }).size({ width: '10%', height: '18%' })
.onClick(() => {
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal 100 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('200').fontSize(13).border({width:2}).size({width:'10%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal 200 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('300').fontSize(13).border({width:2}).size({width:'10%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal 300 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('400').fontSize(13).border({width:2}).size({width:'10%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal 400 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('500').fontSize(13).border({width:2}).size({width:'10%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal 500 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('600').fontSize(13).border({width:2}).size({width:'10%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal 600 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('700').fontSize(13).border({width:2}).size({width:'10%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal 700 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('800').fontSize(13).border({width:2}).size({width:'10%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal 800 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('900').fontSize(13).border({width:2}).size({width:'10%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal 900 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
}
Row({space:10}){
Text('font-family').fontSize(13).border({width:0}).size({width:'24%',height:'18%'})
Text('sans-serif').fontSize(13).border({width:2}).size({width:'24%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal normal 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('serif').fontSize(13).border({width:2}).size({width:'24%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal normal 120px serif';
this.context.fillText("Hello World", 80, 120);
})
Text('monospace').fontSize(13).border({width:2}).size({width:'24%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal normal 120px monospace';
this.context.fillText("Hello World", 80, 120);
})
}
Row({space:10}) {
Text('font-size').fontSize(13).border({ width: 0 }).size({ width: '18%', height: '18%' })
Text('small').fontSize(13).border({ width: 2 }).size({ width: '18%', height: '18%' })
.onClick(() => {
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal normal 10px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('medium').fontSize(13).border({width:2}).size({width:'18%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal normal 50px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('large').fontSize(13).border({width:2}).size({width:'18%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal normal 80px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
Text('extra').fontSize(13).border({width:2}).size({width:'18%',height:'18%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.font = 'normal normal 120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
}
}.width('90%').height('30%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
.width('100%')
.height('100%')
.backgroundColor('#ffffffff')
.onReady(() =>{
this.context.font = '120px sans-serif';
this.context.fillText("Hello World", 80, 120);
})
}.width('100%').height('70%')
}.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,
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 {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);
@State FillColor: string = '#FF000000';
@State X: number = 20;
@State name: string = 'CanvasGlobalAlpha';
@State StepTips: string = '操作步骤:拖动滑块向右移动'+'\n'+'预期结果:透明度随着拖拽距离而改变,并显示透明度';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('→').fontSize(16).border({width:2}).size({width:'20%',height:'20%'})
.translate({ x: this.X, y: 20, z: 5 })
.gesture(
PanGesture({})
.onActionStart((event: GestureEvent) => {
this.context.clearRect(100, 100, 250, 200);
console.info('Pan start');
})
.onActionUpdate((event: GestureEvent) => {
this.X = event.offsetX;
})
.onActionEnd(() => {
console.info('Pan end');
})
)
Text('透明度: ' + (this.X)*0.005 )
}.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.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalAlpha = (this.X)*0.005;
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(200, 200, 50, 50);
})
}.width('100%').height('70%')
}.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
})
}.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 {CustomContainer} from '../common/CanvasCustomContainer1';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
@State FillColor: string = '#FF000000';
@State name: string = 'CanvasGlobalCompositeOperation';
@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 }){
Row(){
Text('').fontSize(0).border({width:0}).size({width:'0%',height:'2%'})
}
Row({space:10}){
Text('s-over').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'source-over';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
Text('s-atop').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'source-atop';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
Text('s-in').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'source-in';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
Text('s-out').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'source-out';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
}
Row({space:10}){
Text('d-over').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=> {
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'destination-over';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
Text('d-atop').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=> {
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'destination-atop';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
Text('d-in').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=> {
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'destination-in';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
Text('d-out').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=> {
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'destination-out';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
}
Row({space:10}){
Text('lighter').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=> {
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'lighter';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
Text('copy').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=> {
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'copy';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
Text('xor').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=> {
this.context.clearRect(0, 10, 350, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'xor';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
Text('').fontSize(0).border({width:0}).size({width:'18%',height:'20%'})
}
}.width('90%').height('30%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
.width('100%')
.height('100%')
.backgroundColor('#ffffffff')
.onReady(() =>{
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 50, 50);
this.context.globalCompositeOperation = 'source-over';
this.context.fillStyle = 'rgb(0,0,255)';
this.context.fillRect(180, 180, 50, 50);
})
}.width('100%').height('70%')
}.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,
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 {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'+'预期结果:切换平滑过渡效果';
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);
})
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);
})
}.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
})
}.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 {CustomContainer} from '../common/CanvasCustomContainer1';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
@State FillColor: string = '#FF000000';
@State name: string = 'CanvasLineCap';
@State StepTips: string = '操作步骤:点击不同的端点样式控件'+'\n'+'预期结果:原本默认端点样式会随点击变化';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('butt').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(90, 90, 170, 120);
this.context.lineWidth = 8;
this.context.beginPath();
this.context.lineCap = 'butt';
this.context.moveTo(100, 100);
this.context.lineTo(250, 100);
this.context.stroke();
})
Text('round').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(90, 90, 170, 120);
this.context.lineWidth = 8;
this.context.beginPath();
this.context.lineCap = 'round';
this.context.moveTo(100, 100);
this.context.lineTo(250, 100);
this.context.stroke();
})
Text('square').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(90, 90, 170, 120);
this.context.lineWidth = 8;
this.context.beginPath();
this.context.lineCap = 'square';
this.context.moveTo(100, 100);
this.context.lineTo(250, 100);
this.context.stroke();
})
}.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.lineWidth = 8;
this.context.beginPath();
this.context.lineCap = 'round';
this.context.moveTo(100, 100);
this.context.lineTo(250, 100);
this.context.stroke();
})
}.width('100%').height('70%')
}.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,
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 {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);
@State FillColor: string = '#FF000000';
@State X: number = 0;
@State name: string = 'CanvasLineDashOffset';
@State StepTips: string = '操作步骤:拖动滑块向右移动'+'\n'+'预期结果:虚线偏移量随着拖拽距离而改变,并显示偏移量';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('→').fontSize(16).border({width:2}).size({width:'20%',height:'20%'})
.translate({ x: this.X, y: 20, z: 5 })
.gesture(
PanGesture({})
.onActionStart((event: GestureEvent) => {
this.context.clearRect(100, 100, 250, 200);
console.info('Pan start');
})
.onActionUpdate((event: GestureEvent) => {
this.X = event.offsetX;
})
.onActionEnd(() => {
console.info('Pan end');
})
)
Text('虚线偏移量: ' + (this.X)*0.1 )
}.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.arc(180, 150, 50, 0, 6.28);
this.context.setLineDash([20,30]);
this.context.lineDashOffset = (this.X)*0.1;
this.context.stroke();
})
}.width('100%').height('70%')
}.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
})
}.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 {CustomContainer} from '../common/CanvasCustomContainer1';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
@State FillColor: string = '#FF000000';
@State name: string = 'CanvasLineJoin';
@State StepTips: string = '操作步骤:点击不同的交点样式控件'+'\n'+'预期结果:原本默认交点样式会随点击变化';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('round').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(90, 90, 170, 120);
this.context.beginPath();
this.context.lineWidth = 8;
this.context.lineJoin = 'round';
this.context.moveTo(120, 100);
this.context.lineTo(210, 130);
this.context.lineTo(120, 180);
this.context.stroke();
})
Text('bevel').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(90, 90, 170, 120);
this.context.beginPath();
this.context.lineWidth = 8;
this.context.lineJoin = 'bevel';
this.context.moveTo(120, 100);
this.context.lineTo(210, 130);
this.context.lineTo(120, 180);
this.context.stroke();
})
Text('miter').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(90, 90, 170, 120);
this.context.beginPath();
this.context.lineWidth = 8;
this.context.lineJoin = 'miter';
this.context.moveTo(120, 100);
this.context.lineTo(210, 130);
this.context.lineTo(120, 180);
this.context.stroke();
})
}.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.beginPath();
this.context.lineWidth = 8;
this.context.lineJoin = 'miter';
this.context.moveTo(120, 100);
this.context.lineTo(210, 130);
this.context.lineTo(120, 180);
this.context.stroke();
})
}.width('100%').height('70%')
}.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,
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 {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);
@State FillColor: string = '#FF000000';
@State name: string = 'CanvasLineWidth';
@State StepTips: string = '操作步骤:拖动滑块向右移动'+'\n'+'预期结果:边框会随着移动距离而变粗,并显示边框粗细';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@State X: number = 20;
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('→').fontSize(16).border({width:2}).size({width:'20%',height:'20%'})
.translate({ x: this.X, y: 20, z: 5 })
.gesture(
PanGesture({})
.onActionStart((event: GestureEvent) => {
this.context.clearRect(100, 100, 250, 200);
console.info('Pan start');
})
.onActionUpdate((event: GestureEvent) => {
this.X = event.offsetX;
})
.onActionEnd(() => {
console.info('Pan end');
})
)
Text('边框粗细: ' + (this.X)*0.05 )
}.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.lineWidth = (this.X)*0.05;
this.context.strokeRect(120, 120, 120, 120);
})
}.width('100%').height('70%')
}.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
})
}.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 {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);
@State FillColor: string = '#FF000000';
@State X: number = 0;
@State name: string = 'CanvasMiterLimit';
@State StepTips: string = '操作步骤:向右拖动MiterLimit按键'+'\n'+'预期结果:斜接面限制值会随拖动距离变化,并显示限制值大小';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('MiterLimit').fontSize(18).border({width:2}).size({width:'40%',height:'30%'})
.translate({ x: this.X, y: 20, z: 5 })
.gesture(
PanGesture({})
.onActionStart((event: GestureEvent) => {
this.context.clearRect(100, 100, 250, 200);
console.info('Pan start');
})
.onActionUpdate((event: GestureEvent) => {
this.X = event.offsetX;
})
.onActionEnd(() => {
console.info('Pan end');
})
)
Text('边框粗细: ' + (this.X)*0.05 )
}.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.lineWidth = 8;
this.context.lineJoin = 'miter';
this.context.miterLimit = (this.X)*0.05;
this.context.moveTo(160, 100);
this.context.lineTo(190, 105);
this.context.lineTo(160, 107);
this.context.stroke();
})
}.width('100%').height('70%')
}.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
})
}.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 {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);
@State FillColor: string = '#FF000000';
@State X: number = 0;
@State name: string = 'CanvasShadowBlur';
@State StepTips: string = '操作步骤:拖动滑块向右移动'+'\n'+'预期结果:阴影会随着拖动距离增大而变模糊,并显示模糊数值';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('→').fontSize(16).border({width:2}).size({width:'20%',height:'20%'})
.translate({ x: this.X, y: 20, z: 5 })
.gesture(
PanGesture({})
.onActionStart((event: GestureEvent) => {
this.context.clearRect(10, 50, 400, 300);
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
console.info('Pan start');
})
.onActionUpdate((event: GestureEvent) => {
this.X = event.offsetX;
})
.onActionEnd(() => {
console.info('Pan end');
})
)
Text('阴影模糊: ' + this.X )
}.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.shadowBlur = this.X;
this.context.shadowColor = 'rgb(0,0,0)';
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
})
}.width('100%').height('70%')
}.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
})
}.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 {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);
@State FillColor: string = '#FF000000';
@State X: number = 0;
@State name: string = 'CanvasShadowColor';
@State StepTips: string = '操作步骤:点击不同的颜色控件'+'\n'+'预期结果:原本默认蓝色的阴影会随点击变化';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('Blue').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(10, 100, 400, 300);
this.context.shadowBlur = 30;
this.context.shadowColor = 'rgb(0,0,255)';
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
})
Text('Yellow').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(10, 100, 400, 300);
this.context.shadowBlur = 30;
this.context.shadowColor = '#fffffc3c';
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
})
Text('Green').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(10, 100, 400, 300);
this.context.shadowBlur = 30;
this.context.shadowColor = '#ff19fa00';
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
})
}.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.shadowBlur = 30;
this.context.shadowColor = 'rgb(0,0,255)';
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
})
}.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
})
}.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 {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);
@State FillColor: string = '#FF000000';
@State X: number = 0;
@State name: string = 'CanvasShadowOffsetX';
@State StepTips: string = '操作步骤:拖动滑块向右移动'+'\n'+'预期结果:阴影会随着拖动距离增大而向下偏移,并显示偏移数值';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('→').fontSize(16).border({width:2}).size({width:'20%',height:'20%'})
.translate({ x: this.X, y: 20, z: 5 })
.gesture(
PanGesture({})
.onActionStart((event: GestureEvent) => {
this.context.clearRect(10, 50, 400, 300);
this.context.shadowColor = 'rgb(0,0,0)';
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
console.info('Pan start');
})
.onActionUpdate((event: GestureEvent) => {
this.X = event.offsetX;
})
.onActionEnd(() => {
console.info('Pan end');
})
)
Text('阴影偏移: ' + (this.X)*0.05 )
}.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.shadowBlur = 10;
this.context.shadowOffsetX = (this.X)*0.05;
this.context.shadowColor = 'rgb(0,0,0)';
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
})
}.width('100%').height('70%')
}.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
})
}.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 {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);
@State FillColor: string = '#FF000000';
@State X: number = 0;
@State name: string = 'CanvasShadowOffsetY';
@State StepTips: string = '操作步骤:拖动滑块向右移动'+'\n'+'预期结果:阴影会随着拖动距离增大而向下偏移,并显示偏移数值';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('→').fontSize(16).border({width:2}).size({width:'20%',height:'20%'})
.translate({ x: this.X, y: 20, z: 5 })
.gesture(
PanGesture({})
.onActionStart((event: GestureEvent) => {
this.context.clearRect(10, 50, 400, 300);
this.context.shadowColor = 'rgb(0,0,0)';
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
console.info('Pan start');
})
.onActionUpdate((event: GestureEvent) => {
this.X = event.offsetX;
})
.onActionEnd(() => {
console.info('Pan end');
})
)
Text('阴影偏移: ' + (this.X)*0.05 )
}.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.shadowBlur = 10;
this.context.shadowOffsetY = (this.X)*0.05;
this.context.shadowColor = 'rgb(0,0,0)';
this.context.fillStyle = 'rgb(255,0,0)';
this.context.fillRect(150, 150, 100, 100);
})
}.width('100%').height('70%')
}.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
})
}.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 {CustomContainer} from '../common/CanvasCustomContainer1';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
@State FillColor: string = '#FF000000';
@State name: string = 'CanvasStrokeStyle';
@State StepTips: string = '操作步骤:点击不同的颜色控件'+'\n'+'预期结果:原本默认黑色的边框会随点击变化';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('Red').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(90, 150, 170, 120);
this.FillColor = '#FFFF0000';
this.context.lineWidth = 10;
this.context.strokeStyle = '#FFFF0000';
this.context.strokeRect(100, 160, 150, 100);
})
Text('Yellow').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(90, 150, 170, 120);
this.FillColor = '#fffffc3c';
this.context.lineWidth = 10;
this.context.strokeStyle = '#fffffc3c';
this.context.strokeRect(100, 160, 150, 100);
})
Text('Green').fontSize(16).border({width:2}).size({width:'25%',height:'20%'})
.onClick(()=>{
this.context.clearRect(90, 150, 170, 120);
this.FillColor = '#ff19fa00';
this.context.lineWidth = 10;
this.context.strokeStyle = '#ff19fa00';
this.context.strokeRect(100, 160, 150, 100);
})
}.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.lineWidth = 10;
this.context.strokeStyle = this.FillColor;
this.context.strokeRect(100, 160, 150, 100);
})
}.width('100%').height('70%')
}.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,
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 {CustomContainer} from '../common/CanvasCustomContainer1';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
@State FillColor: string = '#FF000000';
@State name: string = 'CanvasTextAlign';
@State StepTips: string = '操作步骤:点击不同的文本对齐方式控件'+'\n'+'预期结果:原本默认的对齐方式会随点击变化';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('start').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.lineWidth = 2;
this.context.moveTo(180, 10);
this.context.lineTo(180, 310);
this.context.stroke();
this.context.textAlign = 'start';
this.context.fillText('textAlign=start', 180, 160);
})
Text('end').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.lineWidth = 2;
this.context.moveTo(180, 10);
this.context.lineTo(180, 310);
this.context.stroke();
this.context.textAlign = 'end';
this.context.fillText('textAlign=end', 180, 160);
})
Text('left').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.lineWidth = 2;
this.context.moveTo(180, 10);
this.context.lineTo(180, 310);
this.context.stroke();
this.context.textAlign = 'left';
this.context.fillText('textAlign=left', 180, 160);
})
Text('center').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.lineWidth = 2;
this.context.moveTo(180, 10);
this.context.lineTo(180, 310);
this.context.stroke();
this.context.textAlign = 'center';
this.context.fillText('textAlign=center', 180, 160);
})
Text('right').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=> {
this.context.clearRect(0, 10, 350, 300);
this.context.lineWidth = 2;
this.context.moveTo(180, 10);
this.context.lineTo(180, 310);
this.context.stroke();
this.context.textAlign = 'right';
this.context.fillText('textAlign=right', 180, 160);
})
}.width('90%').height('30%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
.width('100%')
.height('100%')
.backgroundColor('#ffffffff')
.onReady(() =>{
this.context.lineWidth = 2;
this.context.moveTo(180, 10);
this.context.lineTo(180, 310);
this.context.stroke();
this.context.font = '60px sans-serif';
this.context.textAlign = 'start';
this.context.fillText('textAlign=start', 180, 160);
})
}.width('100%').height('70%')
}.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,
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 {CustomContainer} from '../common/CanvasCustomContainer1';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SetCircle {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
@State FillColor: string = '#FF000000';
@State name: string = 'CanvasTextBaseline';
@State StepTips: string = '操作步骤:点击不同的水平对齐方式'+'\n'+'预期结果:原本默认水平对齐方式会随点击变化';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text('Top').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.strokeStyle = '#0000ff';
this.context.lineWidth = 2;
this.context.moveTo(0, 120);
this.context.lineTo(400, 120);
this.context.stroke();
this.context.textBaseline = 'top';
this.context.fillText('Top', 160, 120);
})
Text('Bottom').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.strokeStyle = '#0000ff';
this.context.lineWidth = 2;
this.context.moveTo(0, 120);
this.context.lineTo(400, 120);
this.context.stroke();
this.context.textBaseline = 'bottom';
this.context.fillText('Bottom', 160, 120);
})
Text('Middle').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.strokeStyle = '#0000ff';
this.context.lineWidth = 2;
this.context.moveTo(0, 120);
this.context.lineTo(400, 120);
this.context.stroke();
this.context.textBaseline = 'middle';
this.context.fillText('Middle', 160, 120);
})
Text('Alphabetic').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=>{
this.context.clearRect(0, 10, 350, 300);
this.context.strokeStyle = '#0000ff';
this.context.lineWidth = 2;
this.context.moveTo(0, 120);
this.context.lineTo(400, 120);
this.context.stroke();
this.context.textBaseline = 'alphabetic';
this.context.fillText('Alphabetic', 160, 120);
})
Text('Hanging').fontSize(13).border({width:2}).size({width:'18%',height:'20%'})
.onClick(()=> {
this.context.clearRect(0, 10, 350, 300);
this.context.strokeStyle = '#0000ff';
this.context.lineWidth = 2;
this.context.moveTo(0, 120);
this.context.lineTo(400, 120);
this.context.stroke();
this.context.textBaseline = 'hanging';
this.context.fillText('Hanging', 160, 120);
})
}.width('90%').height('30%')
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
.width('100%')
.height('100%')
.backgroundColor('#ffffffff')
.onReady(() =>{
this.context.strokeStyle = '#0000ff';
this.context.lineWidth = 2;
this.context.moveTo(0, 120);
this.context.lineTo(400, 120);
this.context.stroke();
this.context.font = '60px sans-serif';
this.context.textBaseline = 'top';
this.context.fillText('Top', 160, 120);
})
}.width('100%').height('70%')
}.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,
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 {CustomContainer} from '../common/CustomContainer2';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct LongPressGestureExample {
@State X: number = 0;
@State name: string = 'LongPressGesture';
@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 }) {
Image($r("app.media.flower")).height('60%').width('70%')
}
.height('250vp').width('350vp').padding(20)
.gesture(
LongPressGesture({ repeat: true })
.onAction((event: GestureEvent) => {
if (event.repeat) {
this.X++;
}
})
.onActionEnd(() => {
this.X = 0;
})
)
Text('长按动作连续触发:' + this.X).fontColor(Color.Black)
}.width('100%').height('80%').backgroundColor(Color.White)
.justifyContent(FlexAlign.SpaceEvenly)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/ArkUI/ArkUI_index',
content: this.specificNoParam,
StepTips:this.StepTips,
X:$X,
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 {CustomContainer} from '../common/CustomContainer3';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct PanGestureExample {
@State X: number = 0;
@State Y: number = 0;
@State name: string = 'PanGesture';
@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 }) {
Image($r("app.media.flower")).height('60%').width('70%')
}
.height('250vp').width('350vp').padding(20)
.margin(80).translate({ x: this.X, y: this.Y, z: 5 })
.gesture(
PanGesture({})
.onActionStart((event: GestureEvent) => {
console.info('Pan start');
})
.onActionUpdate((event: GestureEvent) => {
this.X = event.offsetX;
this.Y = event.offsetY;
})
.onActionEnd(() => {
console.info('Pan end');
})
)
Text('偏移坐标x: ' + this.X + '\n' + '偏移坐标y: ' + this.Y)
}.width('100%').height('80%').backgroundColor(Color.White)
.justifyContent(FlexAlign.SpaceEvenly)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/ArkUI/ArkUI_index',
StepTips:this.StepTips,
content: this.specificNoParam,
X:$X, Y:$Y,
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 {CustomContainer} from '../common/CustomContainer2';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct PinchGuestureTest {
@State X: number = 1;
@State name: string = 'PinchGuesture';
@State StepTips: string = '操作步骤:用手指触摸捏合图片(至少2根手指,最大为5指)'+'\n'+'预期结果:图片能够被正常捏合放缩';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column(){
Flex({direction:FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Image($r("app.media.flower")).height('60%').width('70%')
}
.height('250vp').width('350vp').padding(20)
.scale({ x: this.X, y: this.X, z: this.X })
.gesture(
PinchGesture()
.onActionUpdate((event: GestureEvent) => {
this.X = event.scale;
})
)
Text('捏合放缩比例:'+this.X).fontColor(Color.Black)
} .width('100%').height('80%').backgroundColor(Color.White)
.justifyContent(FlexAlign.SpaceEvenly)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/ArkUI/ArkUI_index',
StepTips:this.StepTips,
content: this.specificNoParam,
X:$X,
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 {CustomContainer} from '../common/CustomContainer2';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct RotationGuestureTest {
@State X: number = 0;
@State name: string = 'RotationGuesture';
@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 }) {
Image($r("app.media.flower")).height('60%').width('70%')
}
.height('250vp').width('350vp').padding(20)
.rotate({ x:1, y:1, z:1, angle: this.X })
.margin(80)
.gesture(
RotationGesture()
.onActionUpdate((event: GestureEvent) => {
this.X = event.angle;
})
)
Text('旋转角度:' + this.X)
}.height('80%').width('100%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/ArkUI/ArkUI_index',
StepTips:this.StepTips,
content: this.specificNoParam,
X:$X,
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 {CustomContainer} from '../common/CustomContainer';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct CustomContainerUser {
private listArr: number[] = Array.from(new Array(50).keys());
@State name: string = 'ScrollingList';
@State StepTips: string = '操作步骤:滑动列表观察是否能正常滑动'+'\n'+'预期结果:列表滑动正常';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam() {
Column() {
List() {
ForEach(this.listArr,(item:any,index:number) => {
ListItem() {
Text('Item #' + (index + 1)).width('100%').height(50).fontSize(16).fontColor(Color.White).margin({left:'10vp'})
}
},index => index)
}.height('100%').width('100%').divider({strokeWidth:1,color:Color.Grey})
}.height('83%').width('100%')
}
build() {
Column() {
CustomContainer({
title:this.name,
Url:'pages/ArkUI/ArkUI_index',
StepTips:this.StepTips,
content: this.specificNoParam.bind(this),
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 {CustomContainer} from '../common/CustomContainer3';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct SwipeGestureTest {
@State X : number = 0;
@State Y : number = 0;
@State name: string = 'SwipeGesture';
@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 }) {
Image($r("app.media.flower")).height('60%').width('70%')
}
.height('250vp').width('350vp').padding(20)
.rotate({x: 0, y: 0, z: 1, angle: this.X})
.gesture(
SwipeGesture({fingers: 1, direction: SwipeDirection.Vertical})
.onAction((event: GestureEvent) => {
this.Y = event.speed;
this.X = event.angle;
})
)
Flex({direction:FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }){
Text("滑动手势速度 : " + this.Y)
Text("滑动手势角度 : " + this.X)
}.height('15%').width('100%').padding(20)
}
.width('100%').height('80%').backgroundColor(Color.White)
.justifyContent(FlexAlign.SpaceEvenly)
}
build() {
Column() {
CustomContainer({
title: this.name,
Url:'pages/ArkUI/ArkUI_index',
StepTips:this.StepTips,
content: this.specificNoParam,
X :$X, Y :$Y,
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 {CustomContainer} from '../common/CustomContainer4';
import FirstDialog from '../model/FirstDialog';
@Entry
@Component
struct TapGestureExample {
@State value: string = '';
@State name: string = 'TapGesture';
@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 }) {
Image($r("app.media.flower")).height('60%').width('70%')
}
.height('250vp').width('350vp').padding(20)
.gesture(
TapGesture({ count: 2 })
.onAction(() => {
this.value = 'TapGesture onAction';
})
)
Text(this.value)
}.width('100%').height('80%').backgroundColor(Color.White)
.justifyContent(FlexAlign.SpaceEvenly)
}
build() {
Column() {
CustomContainer({
title: this.name,
StepTips:this.StepTips,
Url:'pages/ArkUI/ArkUI_index',
content: this.specificNoParam,
value:$value,
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 prompt from '@ohos.prompt';
import fileio from '@ohos.fileio';
import router from '@ohos.router';
import screenshot from '@ohos.screenshot';
import image from '@ohos.multimedia.image';
import Logger from '../model/Logger'
import FirstDialog from '../model/FirstDialog';
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
const TAG = '[Screenshot]';
let path = globalThis.dir;
@Component
struct CustomContainer1 {
@Link x: number;
@Link y: number;
@Link isshow: Visibility;
@Link name:string;
title : string = '';
StepTips: string = '';
Url : string = '';
@BuilderParam content: () => void;
@Builder
PassBtn(text: Resource, isFullScreen: boolean) {
Button() {
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);
})
}
@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);
})
}
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', title:this.name,}
})
})
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`);
prompt.showToast({
message: '图片保存成功', duration: 1000
});
}
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}`);
}
}
}
@Entry
@Component
struct SetCircle {
@State x: number = 0;
@State y: number = 0;
@State isshow: Visibility = Visibility.None;
@State name: string = 'TouchMove';
@State StepTips: string = '操作步骤:手指触摸屏幕并滑动' + '\n' + '预期结果:在手指触摸处出现红色圆圈,并跟随手指滑动';
async aboutToAppear(){
await FirstDialog.ChooseDialog(this.StepTips,this.name);
}
@Builder specificNoParam1() {
Column() {
Circle()
.width('20vp').height('20vp').position({ x: this.x, y: this.y }).visibility(this.isshow)
.fill(Color.Red)
}.onTouch((event: TouchEvent) => {
let x = event.touches[0].x;
let y = event.touches[0].y;
if (event.type === TouchType.Down) {
this.x = x;
this.y = y;
this.isshow = Visibility.Visible;
}
else if (event.type === TouchType.Move) {
this.x = x;
this.y = y;
this.isshow = Visibility.Visible;
}
else if (event.type === TouchType.Up) {
this.isshow = Visibility.None;
}
})
.width('100%').height('80%').backgroundColor(Color.White)
}
build() {
Column() {
CustomContainer1({
title: this.name,
Url: 'pages/ArkUI/ArkUI_index',
StepTips: this.StepTips,
content: this.specificNoParam1,
x: $x,
y: $y,
isshow: $isshow,
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 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';
const TAG = 'ParseXML';
let path = globalThis.dir;
let path1;
path1 = path + '/report2';
@Entry
@Component
struct IndexPage {
@State BackColor: string = '#ff808080';
@State ClearAll : boolean = false;
private current : number = undefined;
@State count : number = 0;
@State result : string = '';
private TestCaseList = [
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_PR_0100',uri:'pages/MediaLibrary/startImagePreviewPromise1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_PR_0200',uri:'pages/MediaLibrary/startImagePreviewPromise2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_PR_0300',uri:'pages/MediaLibrary/startImagePreviewPromise3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_PR_ERR_0400',uri:'pages/MediaLibrary/startImagePreviewPromise4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_INDEX_CB_0100',uri:'pages/MediaLibrary/startImagePreviewCallback1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_INDEX_CB_0200',uri:'pages/MediaLibrary/startImagePreviewCallback2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_INDEX_CB_0300',uri:'pages/MediaLibrary/startImagePreviewCallback3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_INDEX_CB_ERR_0400',uri:'pages/MediaLibrary/startImagePreviewCallback4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_CB_0100',uri:'pages/MediaLibrary/startImagePreviewCallback5'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_CB_0200',uri:'pages/MediaLibrary/startImagePreviewCallback6'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGEPREVIEW_CB_ERR_0300',uri:'pages/MediaLibrary/startImagePreviewCallback7'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_CB_0100',uri:'pages/MediaLibrary/startMediaSelectCallback1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_CB_0200',uri:'pages/MediaLibrary/startMediaSelectCallback2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_CB_0300',uri:'pages/MediaLibrary/startMediaSelectCallback3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_CB_0400',uri:'pages/MediaLibrary/startMediaSelectCallback4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_PR_0100',uri:'pages/MediaLibrary/startMediaSelectPromise1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_PR_0200',uri:'pages/MediaLibrary/startMediaSelectPromise2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_PR_0300',uri:'pages/MediaLibrary/startMediaSelectPromise3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STARTIMAGESELECT_PR_0400',uri:'pages/MediaLibrary/startMediaSelectPromise4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_0100',uri:'pages/MediaLibrary/storeMediaAssetPromise1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_0200',uri:'pages/MediaLibrary/storeMediaAssetPromise2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_0300',uri:'pages/MediaLibrary/storeMediaAssetPromise3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_0400',uri:'pages/MediaLibrary/storeMediaAssetPromise4'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_PR_ERR_0500',uri:'pages/MediaLibrary/storeMediaAssetPromise5'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_CB_0100',uri:'pages/MediaLibrary/storeMediaAssetCallback1'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_CB_0200',uri:'pages/MediaLibrary/storeMediaAssetCallback2'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_CB_0300',uri:'pages/MediaLibrary/storeMediaAssetCallback3'},
{title:'SUB_MULTIMEDIA_MEDIALIBRARY_STOREMEDIAASSET_CB_0400',uri:'pages/MediaLibrary/storeMediaAssetCallback4'},
]
@State ColorObject : string[] = ['#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080',
'#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080',
'#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080','#ff808080']
onPageShow(){
if (this.count === 1){
this.result = router.getParams()['result'];
let titles = router.getParams()['title'];
let name1 = '刚刚点进了哪个用例:'+ titles;
let results = this.result;
if (this.result === 'Pass'){
this.ColorObject[this.current] = '#ff008000';
filewrite(name1,results,titles);
}
else if (this.result === 'Fail'){
this.ColorObject[this.current] = '#ffff0000';
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('MediaLibrary')
.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(() => {
this.ClearAll = true;
this.TestCaseList.forEach((value, index) => {
this.ColorObject[index] = '#ff808080';
})
this.ClearText();
prompt.showToast({
message: '结果已删除', duration: 1000
});
})
Button(){
Image($r('app.media.ic_public_save'))
.width('30vp')
.height('30vp')
.margin({ left: 30 })
}.backgroundColor(Color.Black)
.onClick(() => {
this.ReadTextParseXml();
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)
Text(this.BackColor.toString()).visibility(Visibility.None)
}.width('100%').height(50).alignItems(VerticalAlign.Center).backgroundColor(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);
}
ReadTextParseXml() {
let ReportPath = path1 + '/report2.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 arrayBuffer = new ArrayBuffer(40960);
let bufView = new DataView(arrayBuffer);
let serializer = new xml.XmlSerializer(bufView);
serializer.setDeclaration();
serializer.startElement("testsuite");
serializer.setAttributes("name", "ActsMediaTest");
for (let i = 0; i < title.length; i++) {
serializer.startElement("testcase");
serializer.setAttributes("name", String(title[i]));
serializer.setAttributes("result", String(result[i]));
serializer.endElement();
}
serializer.endElement();
let that = new util.TextDecoder('utf-8');
let array = new Uint8Array(arrayBuffer);
let serializerStr = that.decode(array);
let xmlPath = path1 + "/MediaTest.xml";
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 txtpath = path1 + '/report2.txt';
let fd = fileio.openSync(txtpath, 0o100 | 0o2002, 0o664);
let buf = new ArrayBuffer(4096);
let RD = fileio.readSync(fd,buf);
console.info("RRRRRRRRRRd"+RD);
let report = String.fromCharCode.apply(null,new Uint8Array(buf));
let WriteTitle = (titles).toString();
let number = WriteTitle.length + 6;
let Index = report.indexOf(WriteTitle);
let Log = (titles+";"+results+";").toString();
if (Index == -1){
fileio.writeSync(fd,Log);
}
else if (Index != -1){
let key = report.substring(Index,Index+number);
let FD = fileio.openSync(txtpath, 0o102, 0o666);
report = report.replace(key,Log);
let buffer = new ArrayBuffer(4096);
let rd = fileio.readSync(FD,buffer);
let Report = report.substring(0,rd);
fileio.closeSync(FD);
let Fd = fileio.openSync(txtpath, 0o102, 0o666);
fileio.writeSync(Fd,Report);
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 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 = 0;
mediaLibrary.getMediaLibrary().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 = 0;
mediaLibrary.getMediaLibrary().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().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 = 'startImagePreviewCallback4';
@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 = 'startImagePreviewCallback4';
let images = [
"datashare:///media/image/9999",
"datashare:///media/image/9998",
"datashare:///media/image/9997",
"datashare:///media/image/9996",
];
let index = 2;
mediaLibrary.getMediaLibrary().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().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().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().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 = 'startImagePreviewPromise1';
@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 = 'startImagePreviewPromise1';
let images = [
"datashare:///media/image/3",
];
let index = 0;
mediaLibrary.getMediaLibrary().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 = 'startImagePreviewPromise2';
@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 = 'startImagePreviewPromise2';
let images = [
"datashare:///media/image/3",
"datashare:///media/image/4",
];
let index = 0;
mediaLibrary.getMediaLibrary().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 = '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().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 = 'startImagePreviewPromise4';
@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 = 'startImagePreviewPromise4';
let images = [
"datashare:///media/image/9999",
"datashare:///media/image/9998",
"datashare:///media/image/9997",
];
let index = 1;
mediaLibrary.getMediaLibrary().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().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().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().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().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().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().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().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().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 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().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 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 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().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 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 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().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 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 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().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().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 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 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().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 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 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().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 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 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().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 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 : "123",
relativePath : "Pictures/"
};
mediaLibrary.getMediaLibrary().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 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 FirstDialog{
static ChooseDialog = async (StepTips:string,name: string)=>{
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(name, 0);
await promise.then((data) => {
Test = data;
console.info("Succeeded in getting value of 'startup'. Data: " + data);
});
if(Test != 1) {
AlertDialog.show(
{
title: '操作提示',
message: StepTips,
primaryButton: {
value: '不再提醒',fontColor:Color.Grey,
action: () => {
let promise = preferences.put(name, 1);
promise.then(() => {
console.info("Succeeded in putting value of 'test'.");
});
promise = preferences.flush();
promise.then(() => {
console.info("Succeeded in flushing.");
});
}
},
secondaryButton: {
value: '我已知晓',
action: () => {
}
},
cancel: () => {
}
}
)
}
return;
}
}
\ 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 hilog from '@ohos.hilog';
class Logger {
private domain: number;
private prefix: string;
private format: string = "%{public}s, %{public}s";
constructor(prefix: string) {
this.prefix = prefix;
this.domain = 0xFF00;
}
debug(...args: any[]) {
hilog.debug(this.domain, this.prefix, this.format, args);
}
info(...args: any[]) {
hilog.info(this.domain, this.prefix, this.format, args);
}
warn(...args: any[]) {
hilog.warn(this.domain, this.prefix, this.format, args);
}
error(...args: any[]) {
hilog.error(this.domain, this.prefix, this.format, args);
}
}
export default new Logger('[Screenshot]');
\ No newline at end of file
此差异已折叠。
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?><svg width="36" height="36" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8 11L40 11" stroke="#c0c0c9" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/><path d="M18 5L30 5" stroke="#c0c0c9" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/><path d="M12 17H36V40C36 41.6569 34.6569 43 33 43H15C13.3431 43 12 41.6569 12 40V17Z" fill="#c0c0c9" stroke="#c0c0c9" stroke-width="3" stroke-linejoin="round"/><path d="M20 25L28 33" stroke="#FFF" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/><path d="M28 25L20 33" stroke="#FFF" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?><svg width="36" height="36" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M24 44C29.5228 44 34.5228 41.7614 38.1421 38.1421C41.7614 34.5228 44 29.5228 44 24C44 18.4772 41.7614 13.4772 38.1421 9.85786C34.5228 6.23858 29.5228 4 24 4C18.4772 4 13.4772 6.23858 9.85786 9.85786C6.23858 13.4772 4 18.4772 4 24C4 29.5228 6.23858 34.5228 9.85786 38.1421C13.4772 41.7614 18.4772 44 24 44Z" fill="#565bf1" stroke="#565bf1" stroke-width="3" stroke-linejoin="round"/><path d="M24 28.6248V24.6248C27.3137 24.6248 30 21.9385 30 18.6248C30 15.3111 27.3137 12.6248 24 12.6248C20.6863 12.6248 18 15.3111 18 18.6248" stroke="#FFF" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/><path fill-rule="evenodd" clip-rule="evenodd" d="M24 37.6248C25.3807 37.6248 26.5 36.5055 26.5 35.1248C26.5 33.7441 25.3807 32.6248 24 32.6248C22.6193 32.6248 21.5 33.7441 21.5 35.1248C21.5 36.5055 22.6193 37.6248 24 37.6248Z" fill="#FFF"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?><svg width="36" height="36" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6 9C6 7.34315 7.34315 6 9 6H34.2814L42 13.2065V39C42 40.6569 40.6569 42 39 42H9C7.34315 42 6 40.6569 6 39V9Z" fill="#c0c0c9" stroke="#c0c0c9" stroke-width="3" stroke-linejoin="round"/><path fill-rule="evenodd" clip-rule="evenodd" d="M24.0083 6L24 13.3846C24 13.7245 23.5523 14 23 14H15C14.4477 14 14 13.7245 14 13.3846L14 6" fill="#FFF"/><path d="M24.0083 6L24 13.3846C24 13.7245 23.5523 14 23 14H15C14.4477 14 14 13.7245 14 13.3846L14 6H24.0083Z" stroke="#FFF" stroke-width="3" stroke-linejoin="round"/><path d="M9 6H34.2814" stroke="#c0c0c9" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/><path d="M14 26H34" stroke="#FFF" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/><path d="M14 34H24.0083" stroke="#FFF" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></svg>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册