mirror of
https://github.com/openharmony/applications_filepicker.git
synced 2026-07-01 00:17:55 -04:00
+2
-1
@@ -1,4 +1,5 @@
|
||||
/node_modules
|
||||
/local.properties
|
||||
/.idea
|
||||
**/build
|
||||
**/build
|
||||
/tsconfig.json
|
||||
@@ -1,5 +1,6 @@
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import display from '@ohos.display'
|
||||
import { Callback } from 'basic'
|
||||
import { LogInfo, LogDebug } from '../module/LogUtils'
|
||||
|
||||
let displayWidth: number = 0
|
||||
@@ -31,8 +32,39 @@ export default class MainAbility extends Ability {
|
||||
|
||||
globalThis.context = this.context
|
||||
|
||||
this.requestPermissions()
|
||||
this.requestPermissions(() => this.displayWindow(windowStage))
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
private requestPermissions(callback: Callback<void>) {
|
||||
let permissionList: Array<string> = [
|
||||
"ohos.permission.MEDIA_LOCATION",
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA"
|
||||
]
|
||||
globalThis.context.requestPermissionsFromUser(permissionList).then(function (data) {
|
||||
LogInfo(TAG, 'filePicker_MainAbility: request permission data result = ' + data.authResults)
|
||||
callback()
|
||||
}, (error) => {
|
||||
LogInfo(TAG, 'filePicker_MainAbility: fail to request permission error code = ' + error.code)
|
||||
})
|
||||
}
|
||||
|
||||
private displayWindow(windowStage) {
|
||||
display.getDefaultDisplay().then(dis => {
|
||||
displayWidth = dis.width
|
||||
displayHeight = dis.height
|
||||
@@ -40,7 +72,7 @@ export default class MainAbility extends Ability {
|
||||
globalThis.width = dis.width
|
||||
globalThis.height = dis.height
|
||||
globalThis.mainDialogWidth = dis.width
|
||||
globalThis.mainDialogHeight = (((displayHeight) - 180) * 0.7)/1.3
|
||||
globalThis.mainDialogHeight = (((displayHeight) - 180) * 0.7) / 1.3
|
||||
|
||||
LogInfo(TAG, "cjl displayWidth = " + displayWidth + " displayHeight = " + displayHeight)
|
||||
|
||||
@@ -51,7 +83,13 @@ export default class MainAbility extends Ability {
|
||||
|
||||
win.moveTo(0, 0)
|
||||
|
||||
win.setTransparent(true)
|
||||
win.setBackgroundColor("#00FFFFFF", (err, data) => {
|
||||
if (err.code) {
|
||||
LogInfo(TAG, "Fail to set the background color" + JSON.stringify(err))
|
||||
} else {
|
||||
LogInfo(TAG, "Success to set the background color" + JSON.stringify(data))
|
||||
}
|
||||
})
|
||||
|
||||
win.disableWindowDecor((err, data) => {
|
||||
if (err.code) {
|
||||
@@ -73,33 +111,4 @@ export default class MainAbility extends Ability {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
private requestPermissions() {
|
||||
let permissionList: Array<string> = [
|
||||
"ohos.permission.MEDIA_LOCATION",
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA"
|
||||
]
|
||||
globalThis.context.requestPermissionsFromUser(permissionList)
|
||||
.then(function (data) {
|
||||
LogInfo(TAG, 'filePicker_MainAbility: request permission data result = ' + data.authResults)
|
||||
}, (error) => {
|
||||
LogInfo(TAG, 'filePicker_MainAbility: fail to request permission error code = ' + error.code)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
@@ -94,7 +94,7 @@ struct Index {
|
||||
private initWork() {
|
||||
if (this.mWorker == undefined) {
|
||||
LogInfo(this.TAG, 'initWorker')
|
||||
this.mWorker = new worker.Worker('workers/DataWorker.js', { type: 'classic', name: 'filePicker' })
|
||||
this.mWorker = new worker.Worker('RK/ets/workers/DataWorker.js', { type: 'classic', name: 'filePicker' })
|
||||
this.mWorker.onerror = this.onError.bind(this)
|
||||
this.mWorker.onmessageerror = this.onMessageError.bind(this)
|
||||
this.mWorker.onexit = this.onExit.bind(this)
|
||||
|
||||
@@ -26,17 +26,7 @@
|
||||
"description": "$string:MainAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:MainAbility_label",
|
||||
"visible": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
"visible": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import display from '@ohos.display'
|
||||
import { Callback } from 'basic'
|
||||
|
||||
let displayWidth: number = 0
|
||||
let displayHeight: number = 0
|
||||
@@ -26,6 +27,39 @@ export default class MainAbility extends Ability {
|
||||
console.log("filePicker_MainAbility: onWindowStageCreate")
|
||||
|
||||
globalThis.context = this.context
|
||||
this.requestPermissions(() => this.displayWindow(windowStage))
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
private requestPermissions(callback: Callback<void>) {
|
||||
let permissionList: Array<string> = [
|
||||
"ohos.permission.MEDIA_LOCATION",
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA"
|
||||
]
|
||||
globalThis.context.requestPermissionsFromUser(permissionList).then(function (data) {
|
||||
console.log('filePicker_MainAbility: request permission data result = ' + data.authResults)
|
||||
callback()
|
||||
}, (error) => {
|
||||
console.log('filePicker_MainAbility: fail to request permission error code = ' + error.code)
|
||||
})
|
||||
}
|
||||
|
||||
private displayWindow(windowStage) {
|
||||
windowStage.setUIContent(this.context, "pages/index", null)
|
||||
|
||||
display.getDefaultDisplay().then(dis => {
|
||||
@@ -48,32 +82,5 @@ export default class MainAbility extends Ability {
|
||||
win.resetSize(vp2px(752), vp2px(446))
|
||||
})
|
||||
})
|
||||
|
||||
let permissionList: Array<string> = [
|
||||
"ohos.permission.MEDIA_LOCATION",
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA"
|
||||
]
|
||||
globalThis.context.requestPermissionsFromUser(permissionList)
|
||||
.then(function (data) {
|
||||
console.log('filePicker_MainAbility: request permission data result = ' + data.authResults)
|
||||
}, (error) => {
|
||||
console.log('filePicker_MainAbility: fail to request permission error code = ' + error.code)
|
||||
})
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
};
|
||||
|
||||
@@ -68,7 +68,7 @@ struct Index {
|
||||
private initWorker() {
|
||||
if (this.mWorker == undefined) {
|
||||
LogInfo(this.TAG, 'initWorker')
|
||||
this.mWorker = new worker.Worker('workers/DataWorker.js', { type: 'classic', name: 'filePicker' })
|
||||
this.mWorker = new worker.Worker('pad/ets/workers/DataWorker.js', { type: 'classic', name: 'filePicker' })
|
||||
this.mWorker.onerror = this.onError.bind(this)
|
||||
this.mWorker.onmessageerror = this.onMessageError.bind(this)
|
||||
this.mWorker.onexit = this.onExit.bind(this)
|
||||
|
||||
@@ -26,17 +26,7 @@
|
||||
"description": "$string:MainAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:MainAbility_label",
|
||||
"visible": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
"visible": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import display from '@ohos.display'
|
||||
import { Callback } from 'basic'
|
||||
import { LogInfo, LogDebug } from '../module/LogUtils'
|
||||
|
||||
let displayWidth: number = 0
|
||||
@@ -31,8 +32,41 @@ export default class MainAbility extends Ability {
|
||||
|
||||
globalThis.context = this.context
|
||||
|
||||
this.requestPermissions()
|
||||
this.requestPermissions(() => this.displayWindow(windowStage))
|
||||
|
||||
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
private requestPermissions(callback: Callback<void>) {
|
||||
let permissionList: Array<string> = [
|
||||
"ohos.permission.MEDIA_LOCATION",
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA"
|
||||
]
|
||||
globalThis.context.requestPermissionsFromUser(permissionList).then(function (data) {
|
||||
LogInfo(TAG, 'filePicker_MainAbility: request permission data result = ' + data.authResults)
|
||||
callback()
|
||||
}, (error) => {
|
||||
LogInfo(TAG, 'filePicker_MainAbility: fail to request permission error code = ' + error.code)
|
||||
})
|
||||
}
|
||||
|
||||
private displayWindow(windowStage) {
|
||||
display.getDefaultDisplay().then(dis => {
|
||||
displayWidth = dis.width
|
||||
displayHeight = dis.height
|
||||
@@ -51,7 +85,13 @@ export default class MainAbility extends Ability {
|
||||
|
||||
win.moveTo(0, 0)
|
||||
|
||||
win.setTransparent(true)
|
||||
win.setBackgroundColor("#00FFFFFF", (err, data) => {
|
||||
if (err.code) {
|
||||
LogInfo(TAG, "Fail to set the background color" + JSON.stringify(err))
|
||||
} else {
|
||||
LogInfo(TAG, "Success to set the background color" + JSON.stringify(data))
|
||||
}
|
||||
})
|
||||
|
||||
win.disableWindowDecor((err, data) => {
|
||||
if (err.code) {
|
||||
@@ -73,33 +113,4 @@ export default class MainAbility extends Ability {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
private requestPermissions() {
|
||||
let permissionList: Array<string> = [
|
||||
"ohos.permission.MEDIA_LOCATION",
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA"
|
||||
]
|
||||
globalThis.context.requestPermissionsFromUser(permissionList)
|
||||
.then(function (data) {
|
||||
LogInfo(TAG, 'filePicker_MainAbility: request permission data result = ' + data.authResults)
|
||||
}, (error) => {
|
||||
LogInfo(TAG, 'filePicker_MainAbility: fail to request permission error code = ' + error.code)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
@@ -94,7 +94,7 @@ struct Index {
|
||||
private initWork() {
|
||||
if (this.mWorker == undefined) {
|
||||
LogInfo(this.TAG, 'initWorker')
|
||||
this.mWorker = new worker.Worker('workers/DataWorker.js', { type: 'classic', name: 'filePicker' })
|
||||
this.mWorker = new worker.Worker('phone/ets/workers/DataWorker.js', { type: 'classic', name: 'filePicker' })
|
||||
this.mWorker.onerror = this.onError.bind(this)
|
||||
this.mWorker.onmessageerror = this.onMessageError.bind(this)
|
||||
this.mWorker.onexit = this.onExit.bind(this)
|
||||
|
||||
@@ -26,17 +26,7 @@
|
||||
"description": "$string:MainAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:MainAbility_label",
|
||||
"visible": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
"visible": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user