diff --git a/AppSample/Chat/entry/src/main/ets/MainAbility/pages/ChatDetailPage.ets b/AppSample/Chat/entry/src/main/ets/MainAbility/pages/ChatDetailPage.ets index b3d6a6580522875a5005dd177482c945d3be58cf..1e42e1f7b5486d215671f2398dcad6aa0a06d5c7 100644 --- a/AppSample/Chat/entry/src/main/ets/MainAbility/pages/ChatDetailPage.ets +++ b/AppSample/Chat/entry/src/main/ets/MainAbility/pages/ChatDetailPage.ets @@ -16,6 +16,12 @@ import { BasicDataSource } from '../common/BasicDataSource'; import { MessageBase, EMContact, MessageBody, TextMessage, ImageMessage } from './MsgBase'; import router from '@ohos.router'; +import { WantModel } from './Index' +import { ImgTextMessage, FileMessage } from './MsgBase'; +import { WantFileModel } from './Index' +import prompt from '@ohos.prompt' +import image from '@ohos.multimedia.image'; +import fileio from '@ohos.fileio'; @Entry @Component @@ -24,7 +30,7 @@ struct ChatDetailPage { @State chatName: string = '' @State msgLength: number = 0 user1 = new EMContact("1", "自己") - user2= new EMContact("2", "朋友1") + user2 = new EMContact("2", "朋友1") msg = new TextMessage("我是好友消息1") msg2 = new TextMessage("我是好友消息2") tdate = new Date() @@ -32,6 +38,12 @@ struct ChatDetailPage { keyboartStr: string private chatDetailData = new ChatDetailData() private scroller: Scroller = new Scroller() + @State wantParams: WantModel = new WantModel(); //want的自定义参数 + @State wantFileParams: WantFileModel = new WantFileModel(); //want的自定义参数 + @State visibility: Visibility = Visibility.None; + @State imgFile: image.PixelMap = undefined + @State wantId: number = 0 + @State fdImg: number = undefined build() { Column() { @@ -69,7 +81,7 @@ struct ChatDetailPage { List({ scroller: this.scroller, initialIndex: this.msgLength }) { LazyForEach(this.chatDetailData, (msg: MessageBase) => { ListItem() { - ChatItemView({ msg: msg }) + ChatItemView({ msg: msg, imgFile: $imgFile }) } }, (msg: MessageBase) => msg.msgId) } @@ -127,8 +139,66 @@ struct ChatDetailPage { .padding({ bottom: 60 }) } - private aboutToAppear(): void { + async fdTransformPixelMap(): void { + try { + let buf = new ArrayBuffer(90960); + let opt = { + offset: 0, //保证下面读取是从头开始读取的。 + position: 0, + length: 90000 + } + + let readOut = await fileio.readSync(this.wantFileParams.fdImg, buf, opt) + console.info("wjx: DetailPage----------------readOut" + readOut) + let imgSource: image.ImageSource = undefined + imgSource = await image.createImageSource(buf) + + let decodingOptions = { + editable: true, //是否可编辑。 + desiredPixelFormat: 3 //解码的像素格式。 + } + // 通过图片解码参数创建PixelMap对象。 + this.imgFile = await imgSource.createPixelMap(decodingOptions) + + } catch (errorOut) { + console.info("DetailPage---errorOut:" + errorOut); + } + + } + + private async aboutToAppear(): void { this.makeDataLocal() + //接收路由传来的分享参数 + this.wantParams = router.getParams().wantParams; + + console.log(this.wantParams.textCon) + console.log(this.wantParams.srcImg) + this.wantFileParams = router.getParams().wantFileParams + this.wantId = this.wantParams.kindId || this.wantFileParams.kindId + + this.fdImg = this.wantFileParams.fdImg + //接收AppStorage中的wantParams数据 + console.log("wjx-----wantFileParams" + JSON.stringify(this.wantFileParams)) + await this.fdTransformPixelMap() + + let user1 = new EMContact("1", "自己") + let user2 = new EMContact("2", `朋友${router.getParams().chatId.toString()}`, `/resources/images/photo${(parseInt( + router.getParams() + .chatId) % 50).toString()}.jpg`) + let content + let msg + let tdate = new Date() + + + if (this.wantId == 1) { + content = new ImgTextMessage(200, "100%", this.wantParams.srcImg, this.wantParams.textCon); //wjx: 消息内容 + msg = new MessageBase(1000, user1, user2, content, 3, tdate.getSeconds()) //消息构成 + this.chatDetailData.pushData(msg) + } else if (this.wantId == 2) { + content = new FileMessage(180, 200, this.imgFile); + msg = new MessageBase(1000, user1, user2, content, 4, tdate.getSeconds()) //消息构成 + this.chatDetailData.pushData(msg) + } } pageTransition() { @@ -172,65 +242,96 @@ struct ChatDetailPage { @Component struct ChatItemView { private msg: MessageBase + @Link imgFile: image.PixelMap build() { - if (this.msg.fo.userId != '1') { - //聊天页面对方的消息 - Row() { - Image(this.msg.fo.userImage) - .width(40) - .height(40) - .borderRadius(5) - Column() { - Text(this.msg.fo.userName) - if (this.msg.msgType === 1) { - Text((this.msg.msgBody as TextMessage).msg) - .fontSize(15) - .fontColor("#000") - .backgroundColor(Color.White) - .padding(10) - } else if (this.msg.msgType === 2) { - Image((this.msg.msgBody as ImageMessage).img) - .width((this.msg.msgBody as ImageMessage).width) - .height((this.msg.msgBody as ImageMessage).height) + Column() { + if (this.msg.fo.userId != '1') { + //聊天页面对方的消息 + Row() { + Image(this.msg.fo.userImage) + .width(40) + .height(40) + .borderRadius(5) + Column() { + Text(this.msg.fo.userName) + if (this.msg.msgType === 1) { + Text((this.msg.msgBody as TextMessage).msg) + .fontSize(15) + .fontColor("#000") + .backgroundColor(Color.White) + .padding(10) + } else if (this.msg.msgType === 2) { + Image((this.msg.msgBody as ImageMessage).img) + .width((this.msg.msgBody as ImageMessage).width) + .height((this.msg.msgBody as ImageMessage).height) + } } + .alignItems(HorizontalAlign.Start) + .margin({ left: 5 }) } - .alignItems(HorizontalAlign.Start) - .margin({ left: 5 }) - } - .width("100%") - .alignItems(VerticalAlign.Top) - .margin({ top: 15 }) - .padding({ right: 50 }) - } else { - //聊天页面本人消息 - Row() { - Image(this.msg.fo.userImage) - .width(40) - .height(40) - .borderRadius(5) - Column() { - Text(this.msg.fo.userName) - if (this.msg.msgType === 1) { - Text((this.msg.msgBody as TextMessage).msg) - .fontSize(15) - .fontColor("#000") - .backgroundColor("#7fec7d") - .borderRadius(5) - .padding(10) - } else if (this.msg.msgType === 2) { - Image((this.msg.msgBody as ImageMessage).img) - .width((this.msg.msgBody as ImageMessage).width) - .height((this.msg.msgBody as ImageMessage).height) + .width("100%") + .alignItems(VerticalAlign.Top) + .margin({ top: 15 }) + .padding({ right: 50 }) + } else { + //聊天页面本人消息 + Row() { + Image(this.msg.fo.userImage) + .width(40) + .height(40) + .borderRadius(5) + + Column() { + Text(this.msg.fo.userName) + if (this.msg.msgType === 1) { + Text((this.msg.msgBody as TextMessage).msg) + .fontSize(15) + .fontColor("#000") + .backgroundColor("#7fec7d") + .borderRadius(5) + .padding(10) + } else if (this.msg.msgType === 2) { + Image((this.msg.msgBody as ImageMessage).img) + .width((this.msg.msgBody as ImageMessage).width) + .height((this.msg.msgBody as ImageMessage).height) + } else if (this.msg.msgType === 3) { + //接收分享的页面 + + Column() { + //let msgBody = this.msg.msgBody as ImgTextMessage + Text((this.msg.msgBody as ImgTextMessage).msg) + .backgroundColor("#FFFFFF") + .width("100%") + .fontSize(15) + .fontColor("#000") + .borderRadius(5) + .padding(10) + Image((this.msg.msgBody as ImgTextMessage).img) + .width((this.msg.msgBody as ImgTextMessage).width) + .height((this.msg.msgBody as ImgTextMessage).height) + + } + .margin({ left: "40%" }) + .padding({ left: "2%", right: "2%", bottom: "2%" }) + .backgroundColor("#FFFFFF") + } else if (this.msg.msgType == 4) { + Image((this.msg.msgBody as FileMessage).img) + .width((this.msg.msgBody as FileMessage).width) + .height((this.msg.msgBody as FileMessage).height) + .objectFit(ImageFit.Contain) + } } + + .alignItems(HorizontalAlign.Start) + .margin({ left: 5 }) } - .alignItems(HorizontalAlign.Start) - .margin({ left: 5 }) + .alignItems(VerticalAlign.Top) + .width("100%") + .direction(Direction.Rtl) + .padding({ left: 50 }) + .margin({ top: 15 }) } - .width("100%") - .direction(Direction.Rtl) - .padding({ left: 50 }) - .margin({ top: 15 }) } } } diff --git a/AppSample/Chat/entry/src/main/ets/MainAbility/pages/ChatListPage.ets b/AppSample/Chat/entry/src/main/ets/MainAbility/pages/ChatListPage.ets index 22f5713649a055c2afe60c5b5a13f3c2f33b593f..9cbb41c88da65d4de4b86dfad3ecf7838238ba9b 100644 --- a/AppSample/Chat/entry/src/main/ets/MainAbility/pages/ChatListPage.ets +++ b/AppSample/Chat/entry/src/main/ets/MainAbility/pages/ChatListPage.ets @@ -16,6 +16,9 @@ import { BasicDataSource } from '../common/BasicDataSource'; import { ChatModel, EMContact } from './MsgBase'; import router from '@ohos.router'; +import { WantModel } from './Index'; +import { WantFileModel } from './Index'; + @Entry @Component @@ -37,6 +40,9 @@ struct ChatListPage { @Component export struct ChatListView { + @State wantParams: WantModel = { srcImg: "000", textCon: "000", kindId: 0 } + //@State wantParams: WantModel = new WantModel("000", "000"); + @State wantFileParams: WantFileModel = new WantFileModel(0, 0); @State chatListLength: number = 0 //滑动开始纵坐标 @State blurStart: number = 0 @@ -75,7 +81,7 @@ export struct ChatListView { LazyForEach(this.chatListData, (msg: ChatModel) => { ListItem() { - ChatView({ chatItem: msg }) + ChatView({ chatItem: msg, wantParams: this.wantParams, wantFileParams: this.wantFileParams }) } }, (msg: ChatModel) => msg.user.userId) } @@ -131,13 +137,15 @@ export struct ChatListView { @Component struct ChatView { private chatItem: ChatModel + private wantParams: WantModel + private wantFileParams: WantFileModel build() { Stack() { Column() { Row() { Row() { - Image(this.chatItem.user.userImage) + Image(this.chatItem.user.userImage) //用户头像 .width(50) .height(50) .borderRadius(5) @@ -163,9 +171,16 @@ struct ChatView { } .width("100%") .onClick(() => { + console.log(this.wantParams.textCon) router.push({ url: 'pages/ChatDetailPage', - params: { chatName: this.chatItem.user.userName, chatId: this.chatItem.user.userId } + params: { + chatName: this.chatItem.user.userName, + chatId: this.chatItem.user.userId, + //Ability来的want的分享数据 + wantParams: this.wantParams, + wantFileParams: this.wantFileParams + } }) }) } diff --git a/AppSample/Chat/entry/src/main/ets/MainAbility/pages/Index.ets b/AppSample/Chat/entry/src/main/ets/MainAbility/pages/Index.ets index a14a62b2932660a7d829584d3b41002c83c70436..1847198e78a8647db946d3c3d18393737cc27915 100644 --- a/AppSample/Chat/entry/src/main/ets/MainAbility/pages/Index.ets +++ b/AppSample/Chat/entry/src/main/ets/MainAbility/pages/Index.ets @@ -18,18 +18,112 @@ import { ChatListView } from './ChatListPage' import { DiscoverPage } from './DiscoverPage' import { SettingPage } from './SettingPage' import { FriendsPage } from './FriendsPage' +import featureAbility from '@ohos.ability.featureAbility'; import { Prompt } from '../components/Header'; +import image from '@ohos.multimedia.image'; +import fileio from '@ohos.fileio'; +export class WantModel { + srcImg: string + textCon: string + kindId: number + + constructor(srcImg: string, text: string, kindId: number) { + this.srcImg = srcImg; + this.textCon = text; + this.kindId = kindId; + } + + toString(): string { + return this.srcImg + " " + this.textCon + " " + this.kindId + } +} + +export class WantFileModel { + fdImg: number + kindId: number +} + +let readOut +let view @Entry @Component struct Index { + @State wantParams: WantModel = new WantModel("./resources/images/photo0.jpg", "111"); + @State wantFileParams: WantFileModel = new WantFileModel(); + @State flagWant: boolean = false; + @State _pixelMap: image.PixelMap = undefined + private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) + @State imgSource: image.ImageSource = undefined + + private async getWant() { + featureAbility.getWant() + .then(async (data) => { + + let want = data; + console.info("wjx----------參數取值" + JSON.stringify(want.parameters)) + if (want.parameters) { + + this.wantParams.srcImg = want.parameters.srcImg; + this.wantParams.textCon = want.parameters.text; + this.wantParams.kindId = want.parameters.kindId; + console.info("wjx: params.srcImg---" + want.parameters.srcImg) + console.info("wjx: params.textContent---" + want.parameters.text) + + this.wantFileParams.fdImg = want.parameters["keyFd"].value + + this.wantFileParams.kindId = want.parameters.kindId + console.info("wjx: params.fdImg---" + this.wantFileParams.fdImg + ",type:" + typeof (this.wantFileParams.fdImg)) + console.info("wjx: params.kindId---" + this.wantFileParams.kindId) + + let fd = want.parameters["keyFd"].value; + console.info("wjx, fd111 = " + JSON.stringify(fd)); + //测试 + let buf = new ArrayBuffer(90960); + let opt = { + offset: 0, + position: 0, + length: 90000 + } + try { + readOut = await fileio.readSync(fd, buf, opt) + console.info("wjx, fd222 = " + JSON.stringify(fd)); + console.info("wjx, readLength = " + JSON.stringify(readOut)); + console.info("wjx, buf = " + JSON.stringify(buf)); + view = new Uint32Array(buf); + console.info("wjx, view = " + JSON.stringify(view)); + } catch (e) { + console.info("wjx, e = " + JSON.stringify(e)); + } + //查看fd是否传来成功。 + try { + let stat = fileio.fstatSync(this.wantFileParams.fdImg) + console.info('wjx stat : ' + stat.uid) + } catch (error) { + console.info('wjx stat error') + } + + this.copyFileWant(); + + flagWant = true; + return flagWant; + } + return flagWant; + + }) + } + + private aboutToAppear(): void { + this.getWant(); + } + build() { Column() { Tabs({ barPosition: BarPosition.End }) { TabContent() { Column() { TopBar() - ChatListView() + ChatListView({ wantParams: this.wantParams, wantFileParams: this.wantFileParams }) } } .tabBar({ icon: $r('app.media.afr'), text: "聊天" }) diff --git a/AppSample/Chat/entry/src/main/ets/MainAbility/pages/MsgBase.ets b/AppSample/Chat/entry/src/main/ets/MainAbility/pages/MsgBase.ets index 644dc42e6e391e4398e742d536ec6dfd2bdaac20..cb159d9562ca10a45192546f2f46dc249a73d007 100644 --- a/AppSample/Chat/entry/src/main/ets/MainAbility/pages/MsgBase.ets +++ b/AppSample/Chat/entry/src/main/ets/MainAbility/pages/MsgBase.ets @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import image from '@ohos.multimedia.image'; + @Entry @Component struct MsgBase { @@ -48,6 +50,7 @@ export class ChatModel { //聊天信息 export class MessageBase { + img: image.PixelMap msgId: string fo: EMContact to: EMContact @@ -106,6 +109,41 @@ export class ImageMessage extends MessageBody { img: string } +//wjx:图片+文本消息 +export class ImgTextMessage extends MessageBody { + toString(): string { + return this.msg + ' ' + + this.height + " " + this.width + " " + this.img + } + + constructor(hei: number, wid: number, img: string | Resource, msg: string) { + super() + this.height = hei + this.width = wid + this.img = img + this.msg = msg + } + + height: number + width: number + img: string | Resource + msg: string +} +//wjx: 图片文件 +export class FileMessage extends MessageBody{ + height: number | string + width: number | string + img: image.PixelMap + constructor(hei: number | string, wid: number | string, img: image.PixelMap) { + super() + this.height = hei + this.width = wid + this.img = img + } + +} + + //user消息 export class EMContact { userId: string diff --git a/AppSample/Chat/package.json b/AppSample/Chat/package.json index 27d415e57192be5e37515e2ccd509565a607cc43..031696fba8bc438fc5cf8fe51ddf99537578fd08 100644 --- a/AppSample/Chat/package.json +++ b/AppSample/Chat/package.json @@ -15,4 +15,4 @@ "@ohos/hvigor-ohos-plugin": "1.1.3", "@ohos/hvigor": "1.1.3" } -} \ No newline at end of file +} diff --git a/Share/Share/.gitignore b/Share/Share/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..91d237bb144c7fb1777e50271857ef0f593286fc --- /dev/null +++ b/Share/Share/.gitignore @@ -0,0 +1,5 @@ +/node_modules +/local.properties +/.idea +**/build +/.hvigor \ No newline at end of file diff --git a/Share/Share/AppScope/app.json5 b/Share/Share/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..11b07fa0b529a111ff1441e4568ac22baf3766ce --- /dev/null +++ b/Share/Share/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ +{ + "app": { + "bundleName": "com.sample.share", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/Share/Share/AppScope/resources/base/element/string.json b/Share/Share/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..08938744dbe3920f3633f54a6104c60317e263ad --- /dev/null +++ b/Share/Share/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "Share" + } + ] +} diff --git a/Share/Share/AppScope/resources/base/media/app_icon.png b/Share/Share/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Share/Share/AppScope/resources/base/media/app_icon.png differ diff --git a/Share/Share/ReadMe.txt b/Share/Share/ReadMe.txt new file mode 100644 index 0000000000000000000000000000000000000000..2ec02d9b062fc8c7bf7b3ff5be7052db53a4aec8 --- /dev/null +++ b/Share/Share/ReadMe.txt @@ -0,0 +1 @@ +待提交文件 diff --git a/Share/Share/ShareComponent/.gitignore b/Share/Share/ShareComponent/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4f9a973815d0b5e49bc8547681a6b4bc7a178d12 --- /dev/null +++ b/Share/Share/ShareComponent/.gitignore @@ -0,0 +1,3 @@ +/node_modules +/.preview +/build \ No newline at end of file diff --git a/Share/Share/ShareComponent/build-profile.json5 b/Share/Share/ShareComponent/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..70158e115898274a84cc33a60dbe30307d8c8e6a --- /dev/null +++ b/Share/Share/ShareComponent/build-profile.json5 @@ -0,0 +1,27 @@ +/* + * 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. + */ +{ + "apiType": "stageMode", + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} diff --git a/Share/Share/ShareComponent/hvigorfile.js b/Share/Share/ShareComponent/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..42ed4b4a54a873e2b53441556aae93fab24b794f --- /dev/null +++ b/Share/Share/ShareComponent/hvigorfile.js @@ -0,0 +1,3 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').harTasks + diff --git a/Share/Share/ShareComponent/index.ets b/Share/Share/ShareComponent/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd47f97cc449922ccd2a339a2f1fbd2a7d68cd3c --- /dev/null +++ b/Share/Share/ShareComponent/index.ets @@ -0,0 +1,15 @@ +/* + * 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. + */ +export { ButtonDialogBuilder } from './src/main/ets/pages/Dialog' diff --git a/Share/Share/ShareComponent/package.json b/Share/Share/ShareComponent/package.json new file mode 100644 index 0000000000000000000000000000000000000000..51f96116a3ea8549862bf6455665e476ac04ecc6 --- /dev/null +++ b/Share/Share/ShareComponent/package.json @@ -0,0 +1,13 @@ +{ + "name": "@ohos/sharecomponent", + "description": "a npm package which contains arkUI2.0 page", + "ohos": { + "org": "" + }, + "version": "1.0.0", + "main": "index.ets", + "types": "", + "repository": {}, + "license": "ISC", + "dependencies": {} +} diff --git a/Share/Share/ShareComponent/src/main/ets/feature/MediaUtils.ts b/Share/Share/ShareComponent/src/main/ets/feature/MediaUtils.ts new file mode 100644 index 0000000000000000000000000000000000000000..08dc1e9d05ab834e338d2fce799d744b944b3347 --- /dev/null +++ b/Share/Share/ShareComponent/src/main/ets/feature/MediaUtils.ts @@ -0,0 +1,42 @@ +/* + * 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 Logger from '../model/logger' + +const tag: string = 'MediaUtils' + +class MediaUtils { + async getFileAssetsFromType(mediaType: number) { + let mediaList: Array = [] + let mediaLib: mediaLibrary.MediaLibrary = mediaLibrary.getMediaLibrary(globalThis.abilityContext) + Logger.info(tag, `getFileAssetsFromType,mediaType = ${mediaType}`) + let fileKeyObj = mediaLibrary.FileKey + + let fetchOption = { + selections: `${fileKeyObj.MEDIA_TYPE}=?`, + selectionArgs: [`${mediaType}`] + } + // 获取文件资源 + let fetchFileResult = await mediaLib.getFileAssets(fetchOption) + Logger.info(tag, `getFileAssetsFromType,fetchFileResult.count = ${fetchFileResult.getCount()}`) + // getCount 获取文件检索结果中的文件总数。 + if (fetchFileResult.getCount() > 0) { + mediaList = await fetchFileResult.getAllObject() // 获取文件检索结果中的所有文件资产。此方法返回FileAsset结果集。 + } + return mediaList + } +} + +export default new MediaUtils(); \ No newline at end of file diff --git a/Share/Share/ShareComponent/src/main/ets/feature/ShareUtils.ts b/Share/Share/ShareComponent/src/main/ets/feature/ShareUtils.ts new file mode 100644 index 0000000000000000000000000000000000000000..ab9f2b75b2b1a46df57fb9af5c766814a6e5699a --- /dev/null +++ b/Share/Share/ShareComponent/src/main/ets/feature/ShareUtils.ts @@ -0,0 +1,226 @@ +/* + * 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 screenshot from '@ohos.screenshot' +import image from '@ohos.multimedia.image' +import mediaLibrary from '@ohos.multimedia.mediaLibrary' +import Logger from "../model/logger" +import MediaUtils from '../feature/mediautils' + +const TAG: string = "[Sample_ShareComponent]" + +class ShareUtils { + // 分享图片、链接 + async startAbility(contextCaller, title: string, srcImg: string) { + try { + Logger.info(TAG, 'begin to start ability explicitly') + Logger.info(TAG, JSON.stringify(contextCaller)) + await contextCaller.startAbility({ + bundleName: "ohos.samples.chat", + abilityName: "com.example.entry.MainAbility", // 未设置ability名称,代表该want为隐式 + parameters: { // 分享的内容 + "kindId": 1, + "text": title, + "srcImg": srcImg + } + }) + Logger.info(TAG, 'explicit start ability succeed') + } catch (error) { + prompt.showToast({ + message: '请先安装一个chat应用!', + duration: 3000, + }); + Logger.error(TAG, `explicit start ability failed with ${error.code}`) + } + Logger.info(TAG, 'Callback when the second button is clicked') + } + // 分享图片文件 + async savePicture(data: image.PixelMap, contextCaller) { + let path + let fdTemp + try { + Logger.info(TAG, `savePicture`) + // 处理图片的格式 + let packOpts: image.PackingOption = { + format: "image/jpeg", quality: 100 + } + // 创建图片打包 + let imgPackerApi = image.createImagePacker() + let arrayBuffer = await imgPackerApi.packing(data, packOpts) + + // 创建空的文件路径 + path = contextCaller.filesDir + fdTemp = fileio.openSync(path + "/phone.png", 0o2 | 0o100, 0o666) // 新的文件 + Logger.info(TAG, "FileIoPath-----" + path + " " + "fileio----fdImg: " + fdTemp) + // 路径格式: data/storage/el2/base/haps/entry/files + + let numFromFd = await fileio.write(fdTemp, arrayBuffer) // arrayBuffer是内容 + Logger.info(TAG, "savePicture---number" + numFromFd) + } catch (error) { + Logger.info(TAG, "savePicture----error" + JSON.stringify(error)) + } + + await fileio.close(fdTemp) + fdTemp = fileio.openSync(path + "/phone.png") //新的文件 + Logger.info(TAG, "shareBefore---fdImg" + fdTemp) + return fdTemp + } + + async shareImageStartAbility(fdImg: number, contextCaller) { + Logger.info(TAG, 'begin to shareFileStartAbility') + + try { + Logger.info(TAG, JSON.stringify(contextCaller)) + + let buf = new ArrayBuffer(90960); + let opt = { + offset: 0, + position: 0, + length: 90000 + } + try { + let readOut = await fileio.readSync(fdImg, buf, opt) + // let readOut = await fileio.readSync(fd, buf, opt) + Logger.info(TAG, "y00424102, readOutBefore = " + JSON.stringify(readOut)); + Logger.info(TAG, "y00424102, buf = " + JSON.stringify(buf)); + let view = new Uint32Array(buf); + Logger.info(TAG, "wjx, view = " + JSON.stringify(view)); + } catch (e) { + Logger.info(TAG, "wjx, e = " + JSON.stringify(e)); + } + + let want = { + bundleName: "ohos.samples.chat", + abilityName: "com.example.entry.MainAbility", //未设置ability名称,代表该want为隐式, + parameters: { //分享的内容 + "kindId": 2, + "keyFd": { "type": "FD", "value": fdImg }, + } + } + + await contextCaller.startAbility(want) + Logger.info(TAG, 'shareFileStartAbility succeed') + + } catch (error) { + prompt.showToast({ + message: 'shareImageStartAbility failed!', + duration: 3000, + }); + Logger.error(TAG, `shareFileStartAbility failed with ${error.code}`) + } + } + + async getScreen(isPhone: boolean, contextCaller) { + let data: image.PixelMap + let screenShotHeight: number + let screenShotWeight: number + let QRCODE_SIZE: number = isPhone ? 300 : 300 // 生成截图的大小 + let QRCODE_PADDING: number = isPhone ? 80 : 80 // 截图保存时图片边距 + let fdImg: number + try { + //截屏图片 + Logger.info(`${TAG} getScreen,isFullScreen`) + screenShotWeight = QRCODE_SIZE + 1.1 * QRCODE_PADDING + screenShotHeight = QRCODE_SIZE + 6 * QRCODE_PADDING + + let screenshotOptions: screenshot.ScreenshotOptions = { + screenRect: { // 表示截取图像的区域,不传值默认为全屏。以下参数仅支持number + left: 160, + top: 180, // 二维码保存时图片顶部距离屏幕顶部边缘距离 + width: screenShotWeight, + height: screenShotHeight + }, + imageSize: { // 表示截取图像的大小,不传值默认为全屏。 + width: screenShotWeight, + height: screenShotHeight + }, + rotation: 0, + displayId: 0 + } + data = await screenshot.save(screenshotOptions) + + } catch (error) { + Logger.error(TAG, "getScreen----" + error) + } + // 保存图片 + fdImg = await this.savePicture(data, contextCaller) + prompt.showToast({ + "message": "截图成功! 分享加载中...", + "duration": 500 + }) + + setTimeout(() => { + this.shareImageStartAbility(fdImg, contextCaller) + }, 1500) + } + + // 分析视频文件 + async startApp(fd: number, fileAssetName: string, contextCaller) { + Logger.info(TAG, "wjx:startApp----fd" + fd) + try { + let want = { + bundleName: "com.example.revievedvideo", + abilityName: "MainAbility", // 未设置ability名称,代表该want为隐式, + parameters: { // 分享的内容 + "fileAssetName": fileAssetName, + "keyFd": { "type": "FD", "value": fd }, + } + } + + await contextCaller.startAbility(want) + } catch (error) { + Logger.info(TAG, "wjx: startAbility----error" + JSON.stringify(error)) + } + } + + async queryMedia(mediaList: Array, fileAssetName: string) { + let fdNum: number + + let currentIndex: number = -1 + for (let i = 0; i < mediaList.length; i++) { + Logger.info(TAG, `wjx: file.id=${mediaList[i].id} --- file.name=${mediaList[i].displayName}`) + try { + if (mediaList[i].displayName == fileAssetName) { + let fileAsset = mediaList[i] + // currentIndex = index + fdNum = await fileAsset.open('Rw') + Logger.info(TAG, `wjx:queryMedia---------fd ${fdNum}`) + break; + } + } catch (error) { + Logger.info(TAG, `queryMedia: ERROR----- ${error}`) + } + } + return fdNum + } + + async getFileData(contextCaller) { + let mediaList: Array = [] + let fileAssets = MediaUtils.getFileAssetsFromType(mediaLibrary.MediaType.VIDEO) + let fileAssetName: string = "video_4.mp4" + let fdVideo + + mediaList = await MediaUtils.getFileAssetsFromType(mediaLibrary.MediaType.VIDEO) + Logger.info(TAG, `wjx: getFileData------mediaList ${mediaList}`) + fdVideo = await this.queryMedia(mediaList, fileAssetName) + Logger.info(TAG, `wjx: getFileData------fd ${fdVideo}`) + + await this.startApp(fdVideo, fileAssetName, contextCaller) + } +} + + +export default new ShareUtils() \ No newline at end of file diff --git a/Share/Share/ShareComponent/src/main/ets/mock/shareData.ts b/Share/Share/ShareComponent/src/main/ets/mock/shareData.ts new file mode 100644 index 0000000000000000000000000000000000000000..4c8952cd8382f72324f5a6473514361a6ccc0077 --- /dev/null +++ b/Share/Share/ShareComponent/src/main/ets/mock/shareData.ts @@ -0,0 +1,33 @@ +/* + * 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 { DialogDataModel } from "../model/shareModel" +export const dialogData: Array = [ + { + src: $r("app.media.chat"), + text: "Chat" + }, + { + src: $r("app.media.wChat"), + text: "视频分享" + }, + { + src: $r("app.media.line"), + text: "复制链接" + }, + { + src: $r("app.media.canvas"), + text: "生成海报" + } +] \ No newline at end of file diff --git a/Share/Share/ShareComponent/src/main/ets/model/Logger.ts b/Share/Share/ShareComponent/src/main/ets/model/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..4bc3a156e0ac8d7fa626572f69680f32374d9f83 --- /dev/null +++ b/Share/Share/ShareComponent/src/main/ets/model/Logger.ts @@ -0,0 +1,48 @@ +/* + * 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' + +export 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) + } + + fatal(...args: any[]) { + hilog.fatal(this.domain, this.prefix, this.format, args) + } +} + +export default new Logger('[Location]') \ No newline at end of file diff --git a/Share/Share/ShareComponent/src/main/ets/model/httpRequest.ts b/Share/Share/ShareComponent/src/main/ets/model/httpRequest.ts new file mode 100644 index 0000000000000000000000000000000000000000..bfeb7a39cadfbd038aefce4e8de9506d404a8e01 --- /dev/null +++ b/Share/Share/ShareComponent/src/main/ets/model/httpRequest.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ +export class requestRes { + code: number + data: requestResContent + error: null +} +export class requestResContent { + id: number + uri: string + title: string + labels: string + price: string + urls: Array +} + + diff --git a/Share/Share/ShareComponent/src/main/ets/model/shareModel.ets b/Share/Share/ShareComponent/src/main/ets/model/shareModel.ets new file mode 100644 index 0000000000000000000000000000000000000000..2b3ff3e81ed1a70fb27b66ac58daf0420248f642 --- /dev/null +++ b/Share/Share/ShareComponent/src/main/ets/model/shareModel.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ +// 数据 +export class DialogDataModel { + src: Resource + text: string + constructor(src: Resource, text: string) { + this.src = src + this.text = text + } +} \ No newline at end of file diff --git a/Share/Share/ShareComponent/src/main/ets/net/httpRequest.ets b/Share/Share/ShareComponent/src/main/ets/net/httpRequest.ets new file mode 100644 index 0000000000000000000000000000000000000000..2c0d5dca20f12a4a6cad4a74b28ee0ae96ea633f --- /dev/null +++ b/Share/Share/ShareComponent/src/main/ets/net/httpRequest.ets @@ -0,0 +1,33 @@ +/* + * 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 http from '@ohos.net.http' +export function httpRequest(url, method, params, callback) { + let httpRequest = http.createHttp() + httpRequest.request(url, + { + method: http.RequestMethod.GET, + header: { + 'Content-Type': 'application/json' + }, + readTimeout: 60000, + connectTimeout: 60000 + }, (err, data) => { + if (!err) { + callback(data) + } else { + console.info('error:' + JSON.stringify(err)); + } + }); +} \ No newline at end of file diff --git a/Share/Share/ShareComponent/src/main/ets/pages/Dialog.ets b/Share/Share/ShareComponent/src/main/ets/pages/Dialog.ets new file mode 100644 index 0000000000000000000000000000000000000000..1ff670dfe8aa71c8168a487c6911555a9f323132 --- /dev/null +++ b/Share/Share/ShareComponent/src/main/ets/pages/Dialog.ets @@ -0,0 +1,341 @@ +/* +* 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 mediaQuery from '@ohos.mediaquery'; +import fileio from '@ohos.fileio' +import prompt from '@ohos.prompt' +import screenshot from '@ohos.screenshot' +import image from '@ohos.multimedia.image' +import { requestRes, requestResContent } from "../model/httprequest" +import { httpRequest } from "../net/httprequest" +import { dialogData } from "../mock/sharedata" +import { DialogDataModel } from "../model/sharemodel" +import Logger from "../model/logger" +import ShareUtils from "../feature/ShareUtils" + +interface EventHub { + emit(event: string, ...args: Object[]): void +} + +interface AbilityContext { + terminateSelf(): Promise + + eventHub: EventHub +} + +let portraitFunc = null +let isPhone: boolean = false +const TAG: string = "[Sample_ShareComponent]" + +// 弹窗,后期功能优化 +@CustomDialog +struct ShareDialogBuilder { + controller: CustomDialogController + contextCaller: any + detail0: string + detail1: string + title: string + srcImg: string + confirm: () => void + @State _pixelMap: image.PixelMap = undefined + + build() { + Column() { + Text(this.detail0) + .textAlign(TextAlign.Center) + .width("52%") + .height("4%") + .backgroundColor("#dddddd") + .borderRadius(4) + .fontSize($r("app.float.fontSize_10")) + .margin({ + bottom: $r("app.float.margin_bottom_10") + }) + + Image(this.srcImg) + .width("100%") + .height("66%") + .objectFit(ImageFit.Contain) + .margin({ + bottom: $r("app.float.margin_bottom_10") + }) + + Column() { + Row() { + Text(`¥`) + .fontSize($r("app.float.fontSize_10")) + Text(`${this.detail1}`) + .fontWeight(FontWeight.Regular) + .fontSize($r("app.float.fontSize_20")) + } + .margin({ + bottom: $r("app.float.margin_bottom_10") + }) + + Text(this.title) + .textAlign(TextAlign.Start) + .maxLines(2) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .fontWeight(FontWeight.Medium) + .fontSize($r("app.float.fontSize_18")) + .margin({ + bottom: $r("app.float.margin_bottom_10") + }) + } + .alignItems(HorizontalAlign.Start) + .width("100%") + .margin({ + bottom: $r("app.float.margin_bottom_10") + }) + + Flex({ justifyContent: FlexAlign.SpaceAround }) { + Button($r("app.string.cancel")) + .onClick(() => { + this.controller.close() + Logger.info(TAG, "ShareDialogBuilder-------- onCancel") + }) + .backgroundColor($r("app.color.color_0xffffff")) + .fontColor(Color.Black) + Button($r("app.string.shot")) + .onClick(() => { + ShareUtils.getScreen(isPhone,this.contextCaller) + Logger.info(TAG, "getScreen-------- success") + this.controller.close() + }) + .backgroundColor($r("app.color.color_0xffffff")) + .fontColor(Color.Black) + } + .margin({ + bottom: $r("app.float.margin_bottom_10") + }) + } + .borderRadius(16) + .width("60%") + .height("75%") + .padding($r("app.float.padding_24")) + .backgroundColor($r("app.color.color_FFFFFF")) + } +} + +// button的弹窗 +@CustomDialog +export struct ButtonDialogBuilder { + controller: CustomDialogController + detail0: string + detail1: string + title: string + srcImg: string + shareDialogController: CustomDialogController + private context: AbilityContext + contextCaller: any + @State dialogData: Array = dialogData + + @State _isPhone: boolean = false + listenerIsPhone = mediaQuery.matchMediaSync('(orientation:landscape)'); + + onPortrait(mediaQueryResult) { + if (mediaQueryResult.matches) { + this._isPhone = false + } else { + this._isPhone = true + } + isPhone = this._isPhone + } + + // 分享图片文件 + shareImage = () => { +// 拉起应用 +// ShareUtils.shareImageStartAbility(this.contextCaller); + Logger.info(TAG, 'Callback when the second button is clicked') + } + + onShareFriend() { + // 拉起三方应用操作 + Logger.info(TAG, `onShareChat: ${JSON.stringify(this)}`) + ShareUtils.startAbility(this.contextCaller, this.title, this.srcImg) + } + + openDialog = () => { + // 生成画布 + this.shareDialogController = new CustomDialogController({ + builder: ShareDialogBuilder({ + controller: this.shareDialogController, + contextCaller: this.contextCaller, + detail0: this.detail0, + detail1: this.detail1, + title: this.title, + srcImg: this.srcImg, + confirm: this.shareImage, + }), + cancel: undefined, + autoCancel: true, // 是否允许点击弹窗退出 + alignment: DialogAlignment.Center, + customStyle: true, + }) + this.shareDialogController.open() + + Logger.info(TAG, "openHB this.shareDialogController.open();") + Logger.info(TAG, `openHB: ${JSON.stringify(this)}`) + } + + shareVideo = () => { + ShareUtils.getFileData(this.contextCaller) + } + + async aboutToAppear() { + Logger.info(TAG, "get Component's aboutToAppear success") + this.context = getContext(this) as AbilityContext + let data = { + context: null, + launchWant: null + } + + Logger.info(TAG, 'aboutToAppear'); + this.context.eventHub.emit("getAbilityData", data) + Logger.info(TAG, 'aboutToAppear ' + JSON.stringify(data.context) + ' want:' + JSON.stringify(data.launchWant)) + this.contextCaller = data.context // 拿到全局的context,即类似globalThis.mainAbilityContext + Logger.info(TAG, JSON.stringify(this.contextCaller)) + + httpRequest("http://123.60.114.86:8090/goods/detail?id=1", "get", "", (data) => { + let requestRes: requestRes = JSON.parse(data.result) + let requestResContent: requestResContent = requestRes.data + Logger.info(TAG, "requestRes" + requestRes) + Logger.info(TAG, "requestResContent" + requestResContent) + this.title = requestResContent.title + this.detail1 = requestResContent.price + this.srcImg = requestResContent.urls[1] + Logger.info(TAG, "1111") + }) + + portraitFunc = this.onPortrait.bind(this) // bind current js instance + this.listenerIsPhone.on("change", portraitFunc) + } + + teminate() { + Logger.info(TAG, 'teminate') + this.context.terminateSelf() + } + + build() { + Column() { + Stack({ alignContent: Alignment.BottomEnd }) { + Column() { + Row() { + Text($r("app.string.toShare")) + .fontSize($r("app.float.fontSize_20")) + .fontWeight(FontWeight.Medium) + } + .margin({ + top: $r("app.float.margin_20"), + bottom: $r("app.float.margin_20") + }) + + DialogLayoutComponent({ + dialogData: $dialogData, + srcImg: this.srcImg, + controller: this.controller, + onShareFriend: this.onShareFriend.bind(this), + openDialog: this.openDialog, + shareVideo: this.shareVideo, + contextCaller: this.contextCaller + }) + + Row() { + Text($r("app.string.cancel")) + .fontSize($r("app.float.fontSize_20")) + .fontWeight(FontWeight.Normal) + } + .margin({ + top: $r("app.float.margin_20"), + bottom: $r("app.float.margin_20") + }) + .onClick(() => { + Logger.info(TAG, "onclick close") + this.controller.close() + }) + } + .borderRadius(16) + .height($r("app.float.wh_value_260")) + .backgroundColor("#F1F3F5") + } + .height("100%") + } + .width("100%") + } +} + +@Component +struct DialogLayoutComponent { + @Link dialogData: Array + onShareFriend: any + controller: CustomDialogController + openDialog: any + shareVideo: any + srcImg: string + contextCaller: any + + build() { + Column() { + Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) { + ForEach(this.dialogData.map((item1, index1) => { + return { index: index1 + 1, data: item1 } + }), (item) => { + Column() { + Image(item.data.src) + .width($r("app.float.wh_value_66")) + .height($r("app.float.wh_value_66")) + .margin({ + bottom: $r("app.float.margin_bottom_10") + }) + Text(`${item.data.text}`) + .fontSize($r("app.float.fontSize_18")) + .fontWeight(FontWeight.Normal) + } + .onClick(() => { + Logger.info(TAG, `click, index---- ${item.index}`) + if (item.index == 1) { + this.onShareFriend() + Logger.info(TAG, "onShareFriend") + this.controller.close(); + + } else if (item.index == 2) { // 图库文件分享的入口 +// Todo +// ShareUtils.getFileData(this.contextCalle + prompt.showToast({ + message: '功能开发中', + duration: 3000, + }); + this.controller.close(); + } else if (item.index == 3) { + this.controller.close() + prompt.showToast({ + message: '功能开发中', + duration: 3000, + }); + } else if (item.index == 4) { // 应用内文件分享的入口 + this.openDialog() + this.controller.close() + } + }) + + }, item => item.toString()) + } + .width("100%") + .height($r("app.float.wh_value_100")) + .margin({ + bottom: $r("app.float.margin_bottom_36") + }) + }.width("100%") + } +} \ No newline at end of file diff --git a/Share/Share/ShareComponent/src/main/module.json5 b/Share/Share/ShareComponent/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..65dd7929346a26f73107d110276930efb3108a93 --- /dev/null +++ b/Share/Share/ShareComponent/src/main/module.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ +{ + "module": { + "name": "ShareComponent", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ], + "uiSyntax": "ets" + } +} diff --git a/Share/Share/ShareComponent/src/main/resources/base/element/color.json b/Share/Share/ShareComponent/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3e3d21c0f4ad7f1ca147fd645240a87d134b6cb6 --- /dev/null +++ b/Share/Share/ShareComponent/src/main/resources/base/element/color.json @@ -0,0 +1,12 @@ +{ + "color": [ + { + "name": "color_0xffffff", + "value": "0xffffff" + }, + { + "name": "color_FFFFFF", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/Share/Share/ShareComponent/src/main/resources/base/element/float.json b/Share/Share/ShareComponent/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..4928f45d2991761f506d0502efbcb234bf139c76 --- /dev/null +++ b/Share/Share/ShareComponent/src/main/resources/base/element/float.json @@ -0,0 +1,50 @@ +{ + "float": [ + { + "name": "wh_value_260", + "value": "260vp" + }, + { + "name": "wh_value_66", + "value": "66vp" + }, + { + "name": "wh_value_100", + "value": "100vp" + }, + { + "name": "fontSize_10", + "value": "10vp" + }, + { + "name": "fontSize_18", + "value": "18vp" + }, + { + "name": "fontSize_20", + "value": "20vp" + }, + { + "name": "maxLines_2", + "value": "2vp" + }, + { + "name": "margin_bottom_10", + "value": "10vp" + }, + { + "name": "margin_bottom_36", + "value": "36vp" + }, + { + "name": "margin_20", + "value": "20vp" + }, + { + "name": "padding_24", + "value": "24vp" + } + + + ] +} \ No newline at end of file diff --git a/Share/Share/ShareComponent/src/main/resources/base/element/string.json b/Share/Share/ShareComponent/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5d462051a2a0c21da60c296ceb2d83c98c322ece --- /dev/null +++ b/Share/Share/ShareComponent/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "page_show", + "value": "page from npm package" + }, + { + "name": "cancel", + "value": "取消" + }, + { + "name": "shot", + "value": "截图并分享" + }, + { + "name": "toShare", + "value": "分享到" + }, + { + "name": "shareVideo", + "value": "(分享视频模块, 点这里)" + } + ] +} diff --git a/Share/Share/ShareComponent/src/main/resources/base/media/canvas.png b/Share/Share/ShareComponent/src/main/resources/base/media/canvas.png new file mode 100644 index 0000000000000000000000000000000000000000..008770da343b738e397345adda7724c38281ab87 Binary files /dev/null and b/Share/Share/ShareComponent/src/main/resources/base/media/canvas.png differ diff --git a/Share/Share/ShareComponent/src/main/resources/base/media/chat.png b/Share/Share/ShareComponent/src/main/resources/base/media/chat.png new file mode 100644 index 0000000000000000000000000000000000000000..b1a24b58f2c916677854206372f8257db0ce51cc Binary files /dev/null and b/Share/Share/ShareComponent/src/main/resources/base/media/chat.png differ diff --git a/Share/Share/ShareComponent/src/main/resources/base/media/icon.png b/Share/Share/ShareComponent/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Share/Share/ShareComponent/src/main/resources/base/media/icon.png differ diff --git a/Share/Share/ShareComponent/src/main/resources/base/media/line.png b/Share/Share/ShareComponent/src/main/resources/base/media/line.png new file mode 100644 index 0000000000000000000000000000000000000000..9553d8bc1fcbc61def2c0b25bb179c985d29f638 Binary files /dev/null and b/Share/Share/ShareComponent/src/main/resources/base/media/line.png differ diff --git a/Share/Share/ShareComponent/src/main/resources/base/media/phone.png b/Share/Share/ShareComponent/src/main/resources/base/media/phone.png new file mode 100644 index 0000000000000000000000000000000000000000..cb1d59b9ada2c575d07215c187010aa2c34de46a Binary files /dev/null and b/Share/Share/ShareComponent/src/main/resources/base/media/phone.png differ diff --git a/Share/Share/ShareComponent/src/main/resources/base/media/wChat.png b/Share/Share/ShareComponent/src/main/resources/base/media/wChat.png new file mode 100644 index 0000000000000000000000000000000000000000..7c160363c3f3627dd7789d7f2195bef003a15597 Binary files /dev/null and b/Share/Share/ShareComponent/src/main/resources/base/media/wChat.png differ diff --git a/Share/Share/build-profile.json5 b/Share/Share/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1ebebe145b674e71845735048c42226e29aa3b2f --- /dev/null +++ b/Share/Share/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * 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. + */ +{ + "app": { + "signingConfigs": [ + { + "name": "default", + "material": { + "certpath": "C:\\Users\\Administrator\\.ohos\\config\\openharmony\\auto_ohos_default.cer", + "storePassword": "0000001A5664050385679B07FA8781338F75969BF488CC725D91B5BC4D152E64374CACCDE99A342A3400", + "keyAlias": "debugKey", + "keyPassword": "0000001A8D0B4109B6762D059C70C3DCA5AFF1E74ADF2ED38813AC077C2D251C62E79E18C10A00E367FB", + "profile": "C:\\Users\\Administrator\\.ohos\\config\\openharmony\\auto_ohos_default_com.sample.share.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\Administrator\\.ohos\\config\\openharmony\\auto_ohos_default.p12" + } + } + ], + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "ShareComponent", + "srcPath": "./ShareComponent" + } + ] +} \ No newline at end of file diff --git a/Share/Share/entry/.gitignore b/Share/Share/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5a6ba80fa3d9498a23ae8ae7d9518f8743fa8a96 --- /dev/null +++ b/Share/Share/entry/.gitignore @@ -0,0 +1,4 @@ +/node_modules +/.preview +/build +/.cxx \ No newline at end of file diff --git a/Share/Share/entry/build-profile.json5 b/Share/Share/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..49c32ff03222ed8c90887801a65023f293a0fa38 --- /dev/null +++ b/Share/Share/entry/build-profile.json5 @@ -0,0 +1,27 @@ +/* + * 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. + */ +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/Share/Share/entry/hvigorfile.js b/Share/Share/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..d7720ee6a7aad5c617d1fd2f6fc8c87067bfa32c --- /dev/null +++ b/Share/Share/entry/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks diff --git a/Share/Share/entry/package.json b/Share/Share/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..d6ee6a55dffd192fe903c87cfbced1e439c5c845 --- /dev/null +++ b/Share/Share/entry/package.json @@ -0,0 +1,16 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/sharecomponent": "file:../ShareComponent" + } +} diff --git a/Share/Share/entry/src/main/ets/Application/MyAbilityStage.ts b/Share/Share/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..32dfe93ccff0375201857794de902cec4d239442 --- /dev/null +++ b/Share/Share/entry/src/main/ets/Application/MyAbilityStage.ts @@ -0,0 +1,7 @@ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/Share/Share/entry/src/main/ets/MainAbility/MainAbility.ts b/Share/Share/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..8b06f53ecefe223df4c6b3f6daaf21956ec3c406 --- /dev/null +++ b/Share/Share/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,77 @@ +import Ability from '@ohos.application.Ability' +import Logger from '../model/Logger' + +interface EventHub { + emit(event: string, ...args: Object[]): void +} + +interface AbilityContext { + terminateSelf(): Promise + + eventHub: EventHub +} + +export default class MainAbility extends Ability { + private TAG: string = "[Sample_ShareComponent]" + + onCreate(want, launchParam) { + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + globalThis.abilityContext = this.context + + let requestPermission = async () =>{ + let array:Array =[ + 'ohos.permission.READ_MEDIA', + 'ohos.permission.WRITE_MEDIA', + 'ohos.permission.CAPTURE_SCREEN' + ]; + try { + await this.context.requestPermissionsFromUser(array) + console.info("wjx:requestPermission-----success") + } catch(err) { + console.log("[request] is fail") + } + } + requestPermission() + + const that = this + this.context.eventHub.on("getAbilityData", (data) => { + data.context = that.context + data.launchWant = 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") + } +}; diff --git a/Share/Share/entry/src/main/ets/model/Logger.ts b/Share/Share/entry/src/main/ets/model/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..4bc3a156e0ac8d7fa626572f69680f32374d9f83 --- /dev/null +++ b/Share/Share/entry/src/main/ets/model/Logger.ts @@ -0,0 +1,48 @@ +/* + * 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' + +export 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) + } + + fatal(...args: any[]) { + hilog.fatal(this.domain, this.prefix, this.format, args) + } +} + +export default new Logger('[Location]') \ No newline at end of file diff --git a/Share/Share/entry/src/main/ets/pages/index.ets b/Share/Share/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..dd770bcb5a06a5867a8fee859075bec4fe1fcc08 --- /dev/null +++ b/Share/Share/entry/src/main/ets/pages/index.ets @@ -0,0 +1,94 @@ +/* +* 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 { ButtonDialogBuilder } from "@ohos/sharecomponent" + +@Entry +@Component +struct Index { + @State message1: Resource = $r("app.string.shareTitle1") + @State message2: Resource = $r("app.string.shareTitle2") + @State message3: Resource = $r("app.string.shareTitle3") + + //分享弹框 + controller: TabsController = new TabsController() + shareDialog: CustomDialogController + + homeBtn () { + this.shareDialog = new CustomDialogController({ + builder: ButtonDialogBuilder({ + controller: this.shareDialog, + detail0: "推荐一个好物给你请查收", + detail1: "9800", + title: "HUAWEI P50 Pocket 超光谱摄影系统 创新双屏操作体验 120Hz高刷 8GB+256GB", + srcImg: "https://res5.vmallres.com/pimages/uomcdn/CN/pms/202207/gbom/6941487270880/428_428_1142FAB7EA4DCBDD8C64BF54486A7D4Bmp.png" + }), + cancel: undefined, + autoCancel: true, + alignment: DialogAlignment.Bottom, + customStyle: true, + }) + this.shareDialog.open() + } + build() { + Row() { + Column() { + Button() { + Text(this.message1) + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + .width("60%") + .height("6%") + .margin({ + bottom: $r("app.float.fontSize_18") + }) + .onClick(() => { + this.homeBtn() + }) + Button() { + Text(this.message2) + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + .width("60%") + .height("6%") + .margin({ + bottom: $r("app.float.fontSize_18") + }) + .onClick(() => { + this.homeBtn() + }) + Button() { + Text(this.message3) + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + .width("60%") + .height("6%") + .margin({ + bottom: $r("app.float.fontSize_18") + }) + .onClick(() => { + this.homeBtn() + }) + } + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.Center) + .width('100%') + .padding($r("app.float.padding_24")) + } + .height('100%') + } +} \ No newline at end of file diff --git a/Share/Share/entry/src/main/module.json5 b/Share/Share/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..74df9a71ab329ebbad24d67f9f78621ab2e740bc --- /dev/null +++ b/Share/Share/entry/src/main/module.json5 @@ -0,0 +1,67 @@ +/* + * 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. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/MyAbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + { + "name": "ohos.permission.CAPTURE_SCREEN" + }, + { + "name": "ohos.permission.READ_MEDIA" + }, + { + "name": "ohos.permission.WRITE_MEDIA" + } + ] + } +} \ No newline at end of file diff --git a/Share/Share/entry/src/main/resources/base/element/color.json b/Share/Share/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/Share/Share/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/Share/Share/entry/src/main/resources/base/element/float.json b/Share/Share/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..d6bc844454ef7973f5413b6f083e21bd2526c3b5 --- /dev/null +++ b/Share/Share/entry/src/main/resources/base/element/float.json @@ -0,0 +1,12 @@ +{ + "float": [ + { + "name": "wh_value_1", + "value": "1vp" + }, + { + "name": "padding_24", + "value": "24vp" + } + ] +} \ No newline at end of file diff --git a/Share/Share/entry/src/main/resources/base/element/string.json b/Share/Share/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fdc8f8287a6aeafe51f0b9ecbc2e03408fb04033 --- /dev/null +++ b/Share/Share/entry/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "shareTitle1", + "value": "文本+链接分享" + }, + { + "name": "shareTitle2", + "value": "应用内文件分享" + }, + { + "name": "shareTitle3", + "value": "其它应用分享" + } + ] +} \ No newline at end of file diff --git a/Share/Share/entry/src/main/resources/base/media/icon.png b/Share/Share/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Share/Share/entry/src/main/resources/base/media/icon.png differ diff --git a/Share/Share/entry/src/main/resources/base/profile/main_pages.json b/Share/Share/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/Share/Share/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/Share/Share/entry/src/ohosTest/ets/Application/TestAbilityStage.ts b/Share/Share/entry/src/ohosTest/ets/Application/TestAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..7b072bc6c520ed7d370a4766fa62f5a7deb98b28 --- /dev/null +++ b/Share/Share/entry/src/ohosTest/ets/Application/TestAbilityStage.ts @@ -0,0 +1,21 @@ +/* + * 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class TestAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] TestAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/Share/Share/entry/src/ohosTest/ets/TestAbility/TestAbility.ts b/Share/Share/entry/src/ohosTest/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..a89e09494b0692f91b121fcdcac52dc099f6ce61 --- /dev/null +++ b/Share/Share/entry/src/ohosTest/ets/TestAbility/TestAbility.ts @@ -0,0 +1,59 @@ +/* + * 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 Ability from '@ohos.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/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)) + }); + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/Share/Share/entry/src/ohosTest/ets/TestAbility/pages/index.ets b/Share/Share/entry/src/ohosTest/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/Share/Share/entry/src/ohosTest/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * 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 router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/Share/Share/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/Share/Share/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..3fff3d67738c55060293901d04123bca0671ba69 --- /dev/null +++ b/Share/Share/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * 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 TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/Share/Share/entry/src/ohosTest/ets/test/Ability.test.ets b/Share/Share/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..05ddeb482c95dd0988f320192f72a179e8d25c73 --- /dev/null +++ b/Share/Share/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,27 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + it('assertContain',0, function () { + console.info("it begin") + let a = 'abc' + let b = 'b' + expect(a).assertContain(b) + expect(a).assertEqual(a) + }) + }) +} \ No newline at end of file diff --git a/Share/Share/entry/src/ohosTest/ets/test/List.test.ets b/Share/Share/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb35098ac281d443c7add6de76cee00a268ce092 --- /dev/null +++ b/Share/Share/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * 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 abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/Share/Share/entry/src/ohosTest/module.json5 b/Share/Share/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..60a4ec89e07f3f86707ac6c1def79a8930608788 --- /dev/null +++ b/Share/Share/entry/src/ohosTest/module.json5 @@ -0,0 +1,53 @@ +/* + * 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. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntrance": "./ets/Application/TestAbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/Share/Share/entry/src/ohosTest/resources/base/element/color.json b/Share/Share/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/Share/Share/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/Share/Share/entry/src/ohosTest/resources/base/element/string.json b/Share/Share/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..36d4230c53e9f5a07ae343ad8dc9808341975e3b --- /dev/null +++ b/Share/Share/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/Share/Share/entry/src/ohosTest/resources/base/media/icon.png b/Share/Share/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Share/Share/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/Share/Share/entry/src/ohosTest/resources/base/profile/test_pages.json b/Share/Share/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..fcef82b4dfc18e28106ff9ecd1c8b48ec74d18a4 --- /dev/null +++ b/Share/Share/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/index" + ] +} diff --git a/Share/Share/hvigorfile.js b/Share/Share/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..5f2735e3deeaf655828407544bbed9365c258278 --- /dev/null +++ b/Share/Share/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').appTasks \ No newline at end of file diff --git a/Share/Share/package.json b/Share/Share/package.json new file mode 100644 index 0000000000000000000000000000000000000000..a9a2213db52d5447a4684ca72b6bea20f1c1b99a --- /dev/null +++ b/Share/Share/package.json @@ -0,0 +1,18 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "share", + "ohos": { + "org": "huawei", + "directoryLevel": "project", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/hypium": "1.0.1", + "@ohos/hvigor-ohos-plugin": "1.1.6", + "@ohos/hvigor": "1.1.6" + } +} diff --git a/Share/Share/screenshots/04TextPhone.png b/Share/Share/screenshots/04TextPhone.png new file mode 100644 index 0000000000000000000000000000000000000000..2df21448909f63e16cedf971a9b65c6f141d5f65 Binary files /dev/null and b/Share/Share/screenshots/04TextPhone.png differ diff --git a/Share/Share/screenshots/ButtonDialog.png b/Share/Share/screenshots/ButtonDialog.png new file mode 100644 index 0000000000000000000000000000000000000000..ae7e5813d0bb47ffd4c5df4b7edc3bbe098f79e5 Binary files /dev/null and b/Share/Share/screenshots/ButtonDialog.png differ diff --git a/Share/Share/screenshots/canvasDialog.png b/Share/Share/screenshots/canvasDialog.png new file mode 100644 index 0000000000000000000000000000000000000000..a7856b06132a15a736acb3f7e6450da54be4dace Binary files /dev/null and b/Share/Share/screenshots/canvasDialog.png differ diff --git a/Share/Share/screenshots/home.png b/Share/Share/screenshots/home.png new file mode 100644 index 0000000000000000000000000000000000000000..4a1a0fe966ac4f3d66d7e36f23a413b7441fad16 Binary files /dev/null and b/Share/Share/screenshots/home.png differ diff --git a/Share/revievedVideo/.gitignore b/Share/revievedVideo/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..39187ebed671ccfd399a7e88520b1075926c058e --- /dev/null +++ b/Share/revievedVideo/.gitignore @@ -0,0 +1,4 @@ +/node_modules +/local.properties +/.idea +**/build \ No newline at end of file diff --git a/Share/revievedVideo/AppScope/app.json5 b/Share/revievedVideo/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..90a2397b9c2ed0e07165991fcb8ee88fc56086c0 --- /dev/null +++ b/Share/revievedVideo/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ +{ + "app": { + "bundleName": "com.example.revievedvideo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/Share/revievedVideo/AppScope/resources/base/element/string.json b/Share/revievedVideo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6eddd1012ed3cee652047dd6dec76fdf18d5400d --- /dev/null +++ b/Share/revievedVideo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "revievedVideo" + } + ] +} diff --git a/Share/revievedVideo/AppScope/resources/base/media/app_icon.png b/Share/revievedVideo/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Share/revievedVideo/AppScope/resources/base/media/app_icon.png differ diff --git a/Share/revievedVideo/build-profile.json5 b/Share/revievedVideo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e3ce3460ce8dd9837c84f901ae620b079d268b51 --- /dev/null +++ b/Share/revievedVideo/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * 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. + */ +{ + "app": { + "signingConfigs": [ + { + "name": "default", + "material": { + "certpath": "C:\\Users\\Administrator\\.ohos\\config\\openharmony\\auto_ohos.cer", + "storePassword": "000000187EA30211A6B681F25788788383E0C6D271E0F65970467D8BD92FDB2A1AFB396588DA6DC7", + "keyAlias": "debugKey", + "keyPassword": "00000018685A011F014EB45112BFAACF4CD204301894EC8F16BC675B6A989433647572A4AF1CB24E", + "profile": "C:\\Users\\Administrator\\.ohos\\config\\openharmony\\auto_ohos_default_com.example.revievedvideo.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\Administrator\\.ohos\\config\\openharmony\\auto_ohos.p12" + } + } + ], + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/.gitignore b/Share/revievedVideo/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4f9a973815d0b5e49bc8547681a6b4bc7a178d12 --- /dev/null +++ b/Share/revievedVideo/entry/.gitignore @@ -0,0 +1,3 @@ +/node_modules +/.preview +/build \ No newline at end of file diff --git a/Share/revievedVideo/entry/build-profile.json5 b/Share/revievedVideo/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..613cefcbe16316847a1557682d6ae9c596ac8fc6 --- /dev/null +++ b/Share/revievedVideo/entry/build-profile.json5 @@ -0,0 +1,27 @@ +/* + * 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. + */ +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/hvigorfile.js b/Share/revievedVideo/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..d7720ee6a7aad5c617d1fd2f6fc8c87067bfa32c --- /dev/null +++ b/Share/revievedVideo/entry/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks diff --git a/Share/revievedVideo/entry/package.json b/Share/revievedVideo/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..c7685ac4e7c0d79df04c96744f0d8f22cb4a9025 --- /dev/null +++ b/Share/revievedVideo/entry/package.json @@ -0,0 +1,14 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/Share/revievedVideo/entry/src/main/ets/Application/AbilityStage.ts b/Share/revievedVideo/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..6ceb0c290ae831a45143a5e2b42d4351f2fc3d7e --- /dev/null +++ b/Share/revievedVideo/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,21 @@ +/* + * 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/main/ets/MainAbility/MainAbility.ts b/Share/revievedVideo/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..ccab3f99ee26a295d12ab80ea10255ac939ce288 --- /dev/null +++ b/Share/revievedVideo/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,57 @@ +/* + * 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 Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + globalThis.abilityContext = this.context + + this.context.requestPermissionsFromUser(['ohos.permission.READ_MEDIA']) + + const that = this + this.context.eventHub.on("getAbilityData", (data) => { + data.context = that.context + data.launchWant = 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.setUIContent(this.context, "pages/index", null) + } + + 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") + } +}; diff --git a/Share/revievedVideo/entry/src/main/ets/feature/MediaUtils.ts b/Share/revievedVideo/entry/src/main/ets/feature/MediaUtils.ts new file mode 100644 index 0000000000000000000000000000000000000000..ec265f8aecc45f1e0a9169d9f734b9caef633854 --- /dev/null +++ b/Share/revievedVideo/entry/src/main/ets/feature/MediaUtils.ts @@ -0,0 +1,50 @@ +/* + * 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 Logger from '../model/logger' + +const tag: string = 'MediaUtils' + +class MediaUtils { + + + async getFileAssetsFromType(mediaType: number) { + let mediaList: Array = [] + let mediaLib: mediaLibrary.MediaLibrary = mediaLibrary.getMediaLibrary(globalThis.abilityContext) + try{ + Logger.info(tag, `getFileAssetsFromType,mediaType = ${mediaType}`) + let fileKeyObj = mediaLibrary.FileKey + + let fetchOption = { + selections: `${fileKeyObj.MEDIA_TYPE}=?`, + selectionArgs: [`${mediaType}`] + } + // 获取文件资源 + let fetchFileResult = await mediaLib.getFileAssets(fetchOption) + Logger.info(tag, `getFileAssetsFromType,fetchFileResult.count = ${fetchFileResult.getCount()}`) + // getCount 获取文件检索结果中的文件总数。 + if(fetchFileResult.getCount() > 0) { + mediaList = await fetchFileResult.getAllObject() // 获取文件检索结果中的所有文件资产。此方法返回FileAsset结果集。 + } + } catch(error) { + Logger.error(tag, `wjx:getFileAssetsFromType ---- ${error}`) + } + return mediaList + } + +} + +export default new MediaUtils(); \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/main/ets/feature/VideoPlayerUtils.ts b/Share/revievedVideo/entry/src/main/ets/feature/VideoPlayerUtils.ts new file mode 100644 index 0000000000000000000000000000000000000000..0387a45e4bd95f0e52474c636aba2b1fb953c5bb --- /dev/null +++ b/Share/revievedVideo/entry/src/main/ets/feature/VideoPlayerUtils.ts @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import media from '@ohos.multimedia.media' +import Logger from '../model/logger' + +const TAG: string = 'VideoPlayerUtils' + +export default class VideoPlayerUtils { + private videoPlayer = undefined + private playPath: string = '' + private surfaceID: string = '' + private finishCallBack: () => void = undefined + + async initVideoPlayer(playSrc, surfaceID) { + try { + await this.release() + this.playPath = playSrc + this.surfaceID = surfaceID + this.videoPlayer = await media.createVideoPlayer() //异步方式创建视频播放实例,通过Promise获取返回值。 + Logger.info(TAG, 'createVideoPlayer') + this.videoPlayer.url = this.playPath + // 开始监听视频播放完成事件。 + this.videoPlayer.on('playbackCompleted', () => { + Logger.info(TAG, 'play finish') + this.seek(0) + if (this.finishCallBack) { + this.finishCallBack() + } + }); + await this.videoPlayer.setDisplaySurface(this.surfaceID) // *注意:SetDisplaySurface需要在设置url和Prepare之间,无音频的视频流必须设置Surface否则Prepare失败。 + Logger.info(TAG, 'setDisplaySurface') + await this.videoPlayer.prepare() + await this.videoPlayer.play() + Logger.info(TAG, 'start play') + } catch (error) { + Logger.error(TAG, `initVideoPlayer ---- ${error}`) + } + } + + async play() { + Logger.info(TAG, 'play') + if (typeof (this.videoPlayer) != 'undefined') { + await this.videoPlayer.play() + } + } + // 跳转到指定播放位置。 + async seek(time) { + Logger.info(TAG, 'seek') + if (typeof (this.videoPlayer) != 'undefined') { + await this.videoPlayer.seek(time) + } + } + + getCurrentTime() { + if (typeof (this.videoPlayer) != 'undefined') { + return this.videoPlayer.currentTime + } + return 0 + } + + async pause() { + Logger.info(TAG, 'pause') + if (typeof (this.videoPlayer) != 'undefined') { + await this.videoPlayer.pause() + } + } + + async stop() { + Logger.info(TAG, 'stop') + if (typeof (this.videoPlayer) != 'undefined') { + await this.videoPlayer.stop() + } + } + + async reset(playSrc) { + if (typeof (this.videoPlayer) != 'undefined') { + this.playPath = playSrc + await this.videoPlayer.reset() + this.videoPlayer.url = this.playPath + await this.videoPlayer.prepare() + await this.videoPlayer.play() + } + } + + async release() { + if (typeof (this.videoPlayer) != 'undefined') { + await this.videoPlayer.release() + Logger.info(TAG, 'release success') + } + } + + setFinishCallBack(callback) { + this.finishCallBack = callback + } +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/main/ets/model/Logger.ts b/Share/revievedVideo/entry/src/main/ets/model/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..a3fbe1f2439499aaa41daf6d7a848e809d568b95 --- /dev/null +++ b/Share/revievedVideo/entry/src/main/ets/model/Logger.ts @@ -0,0 +1,44 @@ +/* + * 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('[VideoPlayer]') \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/main/ets/model/TimeUtils.ts b/Share/revievedVideo/entry/src/main/ets/model/TimeUtils.ts new file mode 100644 index 0000000000000000000000000000000000000000..aa0591a054df21e839b2cca634e0a390731b5f05 --- /dev/null +++ b/Share/revievedVideo/entry/src/main/ets/model/TimeUtils.ts @@ -0,0 +1,33 @@ +/* + * 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. + */ +export function fillNum(num) { + if (num < 10) { + return '0' + num + } + return num.toString() +} + +export function getTimeString(time) { + if( time == -1 || time == undefined ){ + time = 0 + } + let hour = Math.floor(time % (1000 * 60 * 60 * 24) / (1000 * 60 * 60 )) + let minute = Math.floor(time % (1000 * 60 * 60) / (1000 * 60)) + let second = Math.floor(time % (1000 * 60) / 1000) + if (hour > 0) { + return `${fillNum(hour)}:${fillNum(minute)}:${fillNum(second)}` + } + return `${fillNum(minute)}:${fillNum(second)}` +} diff --git a/Share/revievedVideo/entry/src/main/ets/pages/index.ets b/Share/revievedVideo/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e55c8f8da582af7d40b132dd4c74a4664edb468e --- /dev/null +++ b/Share/revievedVideo/entry/src/main/ets/pages/index.ets @@ -0,0 +1,168 @@ +/* + * 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 prompt from '@ohos.prompt' +import fileio from '@ohos.fileio'; +import Logger from '../model/Logger' +import MediaUtils from '../feature/mediautils' +import VideoPlayerUtils from '../feature/videoplayerutils' + +interface EventHub { + emit(event: string, ...args: Object[]): void +} + +interface AbilityContext { + terminateSelf(): Promise + eventHub: EventHub +} +const TAG: string = 'Player' + +@Entry +@Component +struct Player { + private context: AbilityContext + private globalAbilityCaller: any + @State currentIndex: number = -1 + @State fileAsset: mediaLibrary.FileAsset = undefined + @State fileId: number = 1 + @State fd: number = undefined + @State mediaList: Array = [] + private videoPlayer: VideoPlayerUtils = new VideoPlayerUtils() + private mXComponentController: XComponentController = new XComponentController() + @State surfaceId: number = 0 + @State displayName: string = "video_4.mp4" + @State ratio: number = 1.0 + + async aboutToAppear() { + Logger.info(TAG, "get Component's aboutToAppear success") + this.context = getContext(this) as AbilityContext + let data = { + context: null, + launchWant: null + } + + Logger.info(TAG, 'aboutToAppear'); + this.context.eventHub.emit("getAbilityData", data) + Logger.info(TAG, 'aboutToAppear ' + JSON.stringify(data.context) + ' want:' + JSON.stringify(data.launchWant)) + this.globalAbilityCaller = data.launchWant + Logger.info(TAG, JSON.stringify(this.globalAbilityCaller)) + try { + let that = this; + let Sharedparameters = this.globalAbilityCaller.parameters + that.fd = Sharedparameters["keyFd"].value; + that.displayName = Sharedparameters.fileAssetName + + //Test fd Content + let buf = new ArrayBuffer(90960); + let opt = { + offset: 0, + position: 0, + length: 90000 + } + try { + let readOut = await fileio.readSync(this.fd, buf, opt) + Logger.info(TAG, "wjx, readOut = " + JSON.stringify(readOut)); + Logger.info(TAG, "wjx, buf = " + JSON.stringify(buf)); + let view = new Uint32Array(buf); + Logger.info(TAG, "wjx, view = " + JSON.stringify(view)); + } catch (e) { + Logger.error(TAG, "wjx, e = " + JSON.stringify(e)); + } + + } catch (e) { + Logger.error(TAG, "b error1=========>" + e) + } + this.surfaceId = this.mXComponentController.getXComponentSurfaceId() + Logger.info(TAG, `aboutToAppear,surfaceId=${this.surfaceId}`) +// this.playVideo() + } + + async getMediaList() { + Logger.info(TAG, `aboutToAppear,id=${this.fileId}`) + this.mediaList = await MediaUtils.getFileAssetsFromType(mediaLibrary.MediaType.VIDEO) + this.mediaList.forEach((file, index) => { + Logger.info(TAG, `file.id=${file.id}`) + if (file.displayName === this.displayName) { + this.fileAsset = file + this.currentIndex = index + } + }) + } + + + async playVideo() { + Logger.info(TAG, `wjx: playVideo---- ${JSON.stringify(this.fileAsset)}`) + + try { + await this.getMediaList() + if (this.fd) { + this.ratio = this.fileAsset.width / this.fileAsset.height + this.mXComponentController.setXComponentSurfaceSize({ + surfaceWidth: this.fileAsset.width, + surfaceHeight: this.fileAsset.height + }) + this.surfaceId = this.mXComponentController.getXComponentSurfaceId() + let fdPath = 'fd://' + this.fd + Logger.info(TAG, `wjx---fd ${fdPath}`) + await this.videoPlayer.initVideoPlayer(fdPath, this.surfaceId) + + } else { + prompt.showToast({ + "message": `视频资源加載失敗,请从Share应用进入, + 并从后台清除该应用!`, + "duration": 5000 + }) + + } + } catch (error) { + prompt.showToast({ + "message": "视频资源加载失败", + "duration": 5000 + }) + Logger.error(TAG, `wjx:playVideo ---- ${error}`) + } + } + + build() { + Stack({ alignContent: Alignment.Center }) { + Row() { + XComponent({ + id: 'componentId', + type: 'surface', + controller: this.mXComponentController + }) + .onLoad(() => { + Logger.info(TAG, 'wjx:---onLoad is called') +// this.playVideo() + }) + .width('100%') + .aspectRatio(this.ratio) + } + .height('100%') + .width('100%') + .justifyContent(FlexAlign.Center) + } + .width('100%') + .height('100%') + .backgroundColor(Color.Black) + } + + onPageHide() { + this.videoPlayer.pause() + } + onPageShow(){ + this.videoPlayer.play() + } +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/main/module.json5 b/Share/revievedVideo/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..09833e9bdd646e2040443785ea198a8fe78fe06c --- /dev/null +++ b/Share/revievedVideo/entry/src/main/module.json5 @@ -0,0 +1,58 @@ +/* + * 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. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.READ_MEDIA" + } + ] + } +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/main/resources/base/element/color.json b/Share/revievedVideo/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/Share/revievedVideo/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/main/resources/base/element/string.json b/Share/revievedVideo/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c2440020ed2be4dc5274e08cfa170c721677efcc --- /dev/null +++ b/Share/revievedVideo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "revievedVideo" + } + ] +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/main/resources/base/media/icon.png b/Share/revievedVideo/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Share/revievedVideo/entry/src/main/resources/base/media/icon.png differ diff --git a/Share/revievedVideo/entry/src/main/resources/base/profile/main_pages.json b/Share/revievedVideo/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/Share/revievedVideo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/Share/revievedVideo/entry/src/ohosTest/ets/Application/AbilityStage.ts b/Share/revievedVideo/entry/src/ohosTest/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..7b072bc6c520ed7d370a4766fa62f5a7deb98b28 --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/ets/Application/AbilityStage.ts @@ -0,0 +1,21 @@ +/* + * 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class TestAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] TestAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/ohosTest/ets/TestAbility/TestAbility.ts b/Share/revievedVideo/entry/src/ohosTest/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..a89e09494b0692f91b121fcdcac52dc099f6ce61 --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/ets/TestAbility/TestAbility.ts @@ -0,0 +1,59 @@ +/* + * 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 Ability from '@ohos.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/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)) + }); + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/ohosTest/ets/TestAbility/pages/index.ets b/Share/revievedVideo/entry/src/ohosTest/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * 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 router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/Share/revievedVideo/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..3fff3d67738c55060293901d04123bca0671ba69 --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * 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 TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/ohosTest/ets/module.json5.ftl b/Share/revievedVideo/entry/src/ohosTest/ets/module.json5.ftl new file mode 100644 index 0000000000000000000000000000000000000000..0e07ced2f8bdbc55ca4a1402c0490a293e63af0e --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/ets/module.json5.ftl @@ -0,0 +1,48 @@ +/* + * 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. + */ +{ + "module": { + "name": "${moduleName}_test", + "type": "feature", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [${deviceTypes ?replace("[","")?replace("]","")}], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/Share/revievedVideo/entry/src/ohosTest/ets/test/Ability.test.ets b/Share/revievedVideo/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..05ddeb482c95dd0988f320192f72a179e8d25c73 --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,27 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + it('assertContain',0, function () { + console.info("it begin") + let a = 'abc' + let b = 'b' + expect(a).assertContain(b) + expect(a).assertEqual(a) + }) + }) +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/ohosTest/ets/test/List.test.ets b/Share/revievedVideo/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb35098ac281d443c7add6de76cee00a268ce092 --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * 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 abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/ohosTest/module.json5 b/Share/revievedVideo/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..05e4cd78901d30935748b3acd90bbc5e9247b592 --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/module.json5 @@ -0,0 +1,53 @@ +/* + * 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. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/Share/revievedVideo/entry/src/ohosTest/resources/base/element/color.json b/Share/revievedVideo/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/ohosTest/resources/base/element/string.json b/Share/revievedVideo/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..36d4230c53e9f5a07ae343ad8dc9808341975e3b --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/Share/revievedVideo/entry/src/ohosTest/resources/base/media/icon.png b/Share/revievedVideo/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Share/revievedVideo/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/Share/revievedVideo/entry/src/ohosTest/resources/base/profile/test_pages.json b/Share/revievedVideo/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..fcef82b4dfc18e28106ff9ecd1c8b48ec74d18a4 --- /dev/null +++ b/Share/revievedVideo/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/index" + ] +} diff --git a/Share/revievedVideo/hvigorfile.js b/Share/revievedVideo/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..5f2735e3deeaf655828407544bbed9365c258278 --- /dev/null +++ b/Share/revievedVideo/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').appTasks \ No newline at end of file diff --git a/Share/revievedVideo/package.json b/Share/revievedVideo/package.json new file mode 100644 index 0000000000000000000000000000000000000000..d372e7d3e161cc4b7bcd62edaddec0ae24afaa30 --- /dev/null +++ b/Share/revievedVideo/package.json @@ -0,0 +1,18 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "revievedvideo", + "ohos": { + "org": "huawei", + "directoryLevel": "project", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/hypium": "1.0.0", + "@ohos/hvigor-ohos-plugin": "1.1.3", + "@ohos/hvigor": "1.1.3" + } +} diff --git a/Share/revievedVideo/screenshots/permission.png b/Share/revievedVideo/screenshots/permission.png new file mode 100644 index 0000000000000000000000000000000000000000..4c436c93647baebfec24c548c1170f31cc4c5032 Binary files /dev/null and b/Share/revievedVideo/screenshots/permission.png differ diff --git a/Share/revievedVideo/screenshots/videoPlay.png b/Share/revievedVideo/screenshots/videoPlay.png new file mode 100644 index 0000000000000000000000000000000000000000..bbcebb634e757124e9406817aef16a98c537db5c Binary files /dev/null and b/Share/revievedVideo/screenshots/videoPlay.png differ