mirror of
https://gitee.com/openharmony/applications_photos
synced 2024-11-23 07:00:09 +00:00
photoPicker UIExtension
Signed-off-by: zhouwenjun1031 <zhouwenjun6@huawei.com>
This commit is contained in:
parent
97d14962b1
commit
0bec626af1
@ -526,4 +526,8 @@ export class Constants {
|
||||
|
||||
// fileAsset path data
|
||||
static readonly KEY_FILE_DATA: string = 'data';
|
||||
|
||||
static readonly PHOTO_PICKER_SESSION_KEY: string = 'photopicker_PickerUIExtensionAbility_session';
|
||||
static readonly PHOTO_PICKER_PARAMS_KEY: string = 'photopicker_PickerUIExtensionAbility_params';
|
||||
static readonly PHOTO_PICKER_EXTENSION_WINDOW: string = 'photopicker_PickerUIExtensionAbility_extension_window';
|
||||
}
|
@ -17,7 +17,8 @@ import { Log } from '../../utils/Log';
|
||||
import { Constants } from './Constants';
|
||||
import { UiUtil } from '../../utils/UiUtil';
|
||||
import { BroadCast } from '../../utils/BroadCast';
|
||||
import type window from '@ohos.window';
|
||||
import window from '@ohos.window';
|
||||
import uiExtensionHost from '@ohos.uiExtensionHost';
|
||||
|
||||
const TAG: string = 'common_ScreenManager';
|
||||
|
||||
@ -86,20 +87,22 @@ export class ScreenManager {
|
||||
return manager;
|
||||
}
|
||||
|
||||
initializationSize(win: window.Window): Promise<void> {
|
||||
this.mainWindow = win;
|
||||
let properties: window.WindowProperties = win.getWindowProperties();
|
||||
this.isFullScreen = properties.isFullScreen;
|
||||
initializationSize(win: window.Window | undefined): Promise<void> {
|
||||
if (win) {
|
||||
this.mainWindow = win;
|
||||
let properties: window.WindowProperties = win.getWindowProperties();
|
||||
this.isFullScreen = properties.isFullScreen;
|
||||
}
|
||||
let size: window.Rect = this.getWinRect();
|
||||
|
||||
// Area data obtained through the system interface,
|
||||
// There is a possibility that the area data is incorrect.
|
||||
const statusBarHeight: number = properties && properties.windowRect ? properties.windowRect.top : this.statusBarHeight;
|
||||
const statusBarHeight: number = size ? size.top : this.statusBarHeight;
|
||||
AppStorage.SetOrCreate<number>('statusBarHeight', statusBarHeight);
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
if (!properties || !properties.windowRect) {
|
||||
if (!size) {
|
||||
reject();
|
||||
}
|
||||
let size: window.Rect = properties.windowRect;
|
||||
Log.info(TAG, `display screen windowRect: ${JSON.stringify(size)}`);
|
||||
this.winWidth = px2vp(size.width);
|
||||
this.winHeight = px2vp(size.height);
|
||||
@ -136,7 +139,7 @@ export class ScreenManager {
|
||||
this.broadcast.off(event, fn);
|
||||
}
|
||||
|
||||
setWinWidth(width: number): void{
|
||||
setWinWidth(width: number): void {
|
||||
this.winWidth = width;
|
||||
}
|
||||
|
||||
@ -177,13 +180,14 @@ export class ScreenManager {
|
||||
initWindowMode(): void {
|
||||
Log.debug(TAG, `start to initialize photos application window mode: ${this.windowMode}`);
|
||||
this.checkWindowMode();
|
||||
this.mainWindow && this.setMainWindow();
|
||||
this.getHost() && this.setMainWindow();
|
||||
}
|
||||
|
||||
destroyWindowMode(): void {
|
||||
Log.debug(TAG, `start to destory photos application window mode: ${this.windowMode}`);
|
||||
try {
|
||||
this.mainWindow.off('windowSizeChange');
|
||||
this.getHost()?.off('windowSizeChange', (data: window.Size) => {
|
||||
});
|
||||
} catch (error) {
|
||||
Log.error(TAG, `destroy window error: ${error}`);
|
||||
}
|
||||
@ -194,10 +198,13 @@ export class ScreenManager {
|
||||
}
|
||||
|
||||
async checkWindowMode(): Promise<void> {
|
||||
if (this.isUIExtensionEnv()) {
|
||||
return;
|
||||
}
|
||||
let before = this.windowMode;
|
||||
let windowStage: window.WindowStage = AppStorage.get<window.WindowStage>('photosWindowStage');
|
||||
// @ts-ignore
|
||||
let mode: WindowMode = await windowStage.getWindowMode() as WindowMode;
|
||||
let mode: WindowMode = await windowStage?.getWindowMode() as WindowMode;
|
||||
Log.info(TAG, `photos application before/current window mode: ${before}/${mode}`);
|
||||
|
||||
if (before == mode) {
|
||||
@ -213,39 +220,46 @@ export class ScreenManager {
|
||||
|
||||
setMainWindow(): void {
|
||||
Log.debug(TAG, 'setMainWindow');
|
||||
this.mainWindow.on('windowSizeChange', (data: window.Size) => {
|
||||
this.getHost()?.on('windowSizeChange', (data: window.Size) => {
|
||||
Log.debug(TAG, `windowSizeChange ${JSON.stringify(data)}`);
|
||||
try {
|
||||
let properties: window.WindowProperties = this.mainWindow.getWindowProperties();
|
||||
this.isFullScreen = properties.isFullScreen;
|
||||
} catch (exception) {
|
||||
Log.error(TAG, 'Failed to obtain the area. Cause:' + JSON.stringify(exception));
|
||||
if (!this.isUIExtensionEnv()) {
|
||||
try {
|
||||
let properties: window.WindowProperties = this.mainWindow.getWindowProperties();
|
||||
this.isFullScreen = properties.isFullScreen;
|
||||
} catch (exception) {
|
||||
Log.error(TAG, 'Failed to obtain the area. Cause:' + JSON.stringify(exception));
|
||||
}
|
||||
}
|
||||
this.onWinSizeChanged(data);
|
||||
})
|
||||
this.mainWindow.getProperties().then((prop: window.WindowProperties) => {
|
||||
Log.info(TAG, `Window prop: ${JSON.stringify(prop)}`);
|
||||
this.onWinSizeChanged(prop.windowRect);
|
||||
});
|
||||
this.onWinSizeChanged(this.getWinRect());
|
||||
}
|
||||
|
||||
destroyMainWindow(): void {
|
||||
this.mainWindow.off('windowSizeChange');
|
||||
}
|
||||
|
||||
getAvoidArea(): void {
|
||||
let topWindow: window.Window = this.getMainWindow();
|
||||
topWindow.getAvoidArea(0, (err, data: window.AvoidArea) => {
|
||||
Log.info(TAG, 'Succeeded in obtaining the area. Data:' + JSON.stringify(data));
|
||||
this.onLeftBlankChanged(data);
|
||||
this.getHost()?.off('windowSizeChange', (data: window.Size) => {
|
||||
});
|
||||
}
|
||||
|
||||
getAvoidArea(): void {
|
||||
if (this.isUIExtensionEnv()) {
|
||||
this.onLeftBlankChanged(this.getHost()?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM));
|
||||
} else {
|
||||
let topWindow: window.Window = this.getMainWindow();
|
||||
topWindow?.getAvoidArea(0, (err, data: window.AvoidArea) => {
|
||||
Log.info(TAG, 'Succeeded in obtaining the area. Data:' + JSON.stringify(data));
|
||||
this.onLeftBlankChanged(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setFullScreen(): void {
|
||||
if (this.isUIExtensionEnv()) {
|
||||
return;
|
||||
}
|
||||
let topWindow: window.Window = this.getMainWindow();
|
||||
Log.debug(TAG, 'getTopWindow start');
|
||||
try {
|
||||
topWindow.setLayoutFullScreen(true, () => {
|
||||
topWindow?.setLayoutFullScreen(true, () => {
|
||||
Log.debug(TAG, 'setFullScreen true Succeeded');
|
||||
if (AppStorage.get('deviceType') as string !== Constants.DEFAULT_DEVICE_TYPE) {
|
||||
this.hideStatusBar();
|
||||
@ -259,7 +273,10 @@ export class ScreenManager {
|
||||
}
|
||||
|
||||
setWindowBackgroundColorDefault(defaultColor: boolean): void {
|
||||
this.getMainWindow().setWindowBackgroundColor(defaultColor ? '#F1F3F5' : '#000000');
|
||||
if (this.isUIExtensionEnv()) {
|
||||
return;
|
||||
}
|
||||
this.getMainWindow()?.setWindowBackgroundColor(defaultColor ? '#F1F3F5' : '#000000');
|
||||
}
|
||||
|
||||
setSplitScreen(): void {
|
||||
@ -274,6 +291,9 @@ export class ScreenManager {
|
||||
}
|
||||
|
||||
hideStatusBar(): void {
|
||||
if (this.isUIExtensionEnv()) {
|
||||
return;
|
||||
}
|
||||
Log.debug(TAG, 'hideStatusBar start');
|
||||
let topWindow: window.Window = this.getMainWindow();
|
||||
Log.debug(TAG, 'getTopWindow start');
|
||||
@ -282,14 +302,14 @@ export class ScreenManager {
|
||||
try {
|
||||
topWindow.setSystemBarEnable(names, () => {
|
||||
Log.debug(TAG, 'hideStatusBar Succeeded');
|
||||
topWindow.getAvoidArea(0, async (err, data: window.AvoidArea) => {
|
||||
topWindow?.getAvoidArea(0, async (err, data: window.AvoidArea) => {
|
||||
Log.info(TAG, `Succeeded in obtaining the area. Data: ${JSON.stringify(data)}`);
|
||||
this.onLeftBlankChanged(data);
|
||||
let barColor: string = await UiUtil.getResourceString($r('app.color.transparent'));
|
||||
if (!barColor) {
|
||||
barColor = '#00000000';
|
||||
}
|
||||
topWindow.setSystemBarProperties({ navigationBarColor: barColor }, () => {
|
||||
topWindow?.setSystemBarProperties({ navigationBarColor: barColor }, () => {
|
||||
Log.info(TAG, 'setStatusBarColor done');
|
||||
});
|
||||
});
|
||||
@ -300,10 +320,13 @@ export class ScreenManager {
|
||||
}
|
||||
|
||||
async setDefaultStatusBarProperties(): Promise<void> {
|
||||
if (this.isUIExtensionEnv()) {
|
||||
return;
|
||||
}
|
||||
Log.debug(TAG, 'setStatusBarColor start');
|
||||
let topWindow: window.Window = this.getMainWindow();
|
||||
try {
|
||||
topWindow.setSystemBarProperties(
|
||||
topWindow?.setSystemBarProperties(
|
||||
{ statusBarColor: Constants.STATUS_BAR_BACKGROUND_COLOR,
|
||||
statusBarContentColor: Constants.STATUS_BAR_CONTENT_COLOR }, () => {
|
||||
Log.info(TAG, 'setStatusBarColor done');
|
||||
@ -314,6 +337,9 @@ export class ScreenManager {
|
||||
}
|
||||
|
||||
setSystemUi(isShowBar: boolean): void {
|
||||
if (this.isUIExtensionEnv()) {
|
||||
return;
|
||||
}
|
||||
let deviceTp: string = AppStorage.get('deviceType') as string;
|
||||
Log.debug(TAG, `setSystemUi start, isShowBar=${isShowBar}, deviceType=${deviceTp}`);
|
||||
let topWindow: window.Window = this.getMainWindow();
|
||||
@ -327,7 +353,7 @@ export class ScreenManager {
|
||||
}
|
||||
Log.debug(TAG, `getTopWindow names: ${names} end`);
|
||||
try {
|
||||
topWindow.setSystemBarEnable(names, () => {
|
||||
topWindow?.setSystemBarEnable(names, () => {
|
||||
Log.debug(TAG, `setSystemUi Succeeded: ${names}`);
|
||||
if (isShowBar) {
|
||||
topWindow.getAvoidArea(0, (err, data: window.AvoidArea) => {
|
||||
@ -379,6 +405,10 @@ export class ScreenManager {
|
||||
return AppStorage.get<window.Window>('mainWindow');
|
||||
}
|
||||
|
||||
private getProxy(): uiExtensionHost.UIExtensionHostWindowProxy {
|
||||
return AppStorage.get<uiExtensionHost.UIExtensionHostWindowProxy>(Constants.PHOTO_PICKER_EXTENSION_WINDOW) as uiExtensionHost.UIExtensionHostWindowProxy;
|
||||
}
|
||||
|
||||
private emit(event: string, argument: unknown[]): void {
|
||||
this.broadcast.emit(event, argument);
|
||||
}
|
||||
@ -442,4 +472,24 @@ export class ScreenManager {
|
||||
this.emit(ScreenManager.ON_WIN_SIZE_CHANGED, [size]);
|
||||
}
|
||||
}
|
||||
|
||||
isUIExtensionEnv(): boolean {
|
||||
let uiExtensionStage: uiExtensionHost.UIExtensionHostWindowProxy = this.getProxy();
|
||||
return uiExtensionStage ? true : false;
|
||||
}
|
||||
|
||||
private getHost(): uiExtensionHost.UIExtensionHostWindowProxy | window.Window {
|
||||
if (this.isUIExtensionEnv()) {
|
||||
return this.getProxy();
|
||||
} else {
|
||||
return this.getMainWindow();
|
||||
}
|
||||
}
|
||||
|
||||
private getWinRect(): window.Rect {
|
||||
if (this.isUIExtensionEnv()) {
|
||||
return this.getProxy()?.properties?.uiExtensionHostWindowProxyRect;
|
||||
}
|
||||
return this.getMainWindow()?.getWindowProperties()?.windowRect;
|
||||
}
|
||||
}
|
||||
|
@ -56,14 +56,15 @@ export struct ThirdSelectPhotoBrowserActionBar {
|
||||
isNeedPlaceholder: false
|
||||
})
|
||||
.padding({
|
||||
top: this.isHorizontal ? Constants.NUMBER_0 : px2vp(this.statusBarHeight)
|
||||
top: (this.isHorizontal && !ScreenManager.getInstance().isUIExtensionEnv()) ?
|
||||
$r('app.float.third_selected_actionbar_padding_top') : px2vp(this.statusBarHeight)
|
||||
})
|
||||
}
|
||||
.height(this.isHorizontal ? Constants.ActionBarHeight * Constants.PHOTO_BAR_MULTIPLES_1_5
|
||||
: Constants.ActionBarHeight * Constants.PHOTO_BAR_MULTIPLES_1_5
|
||||
+ px2vp(this.statusBarHeight))
|
||||
.markAnchor({ x: Constants.PERCENT_0, y: Constants.PERCENT_0 })
|
||||
.position({ x: Constants.PERCENT_0, y: this.leftBlank[1] })
|
||||
.position({ x: Constants.PERCENT_0, y: Constants.PERCENT_0 })
|
||||
.visibility(this.isShowBar ? Visibility.Visible : Visibility.Hidden)
|
||||
}
|
||||
|
||||
|
@ -1327,6 +1327,10 @@
|
||||
{
|
||||
"name": "ohos_id_corner_radius_default_m",
|
||||
"value": "12vp"
|
||||
},
|
||||
{
|
||||
"name": "third_selected_actionbar_padding_top",
|
||||
"value": "8vp"
|
||||
}
|
||||
]
|
||||
}
|
@ -19,6 +19,9 @@ import { SelectParams } from '../utils/ThirdSelectConstants';
|
||||
import ability from '@ohos.ability.ability';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||
import fileShare from '@ohos.fileshare';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
const TAG: string = 'thiSel_CameraGridItemComponent';
|
||||
|
||||
@ -45,6 +48,16 @@ export struct CameraGridItemComponent {
|
||||
.height('100%')
|
||||
.backgroundColor($r('sys.color.ohos_id_color_primary'))
|
||||
.opacity($r('sys.float.ohos_id_alpha_inapptip_bg'))
|
||||
.onClick((event?: ClickEvent) => {
|
||||
this.jumpCameraTakePhoto().then((result) => {
|
||||
Log.info(TAG, `resourceUri = ${JSON.stringify(result)}`);
|
||||
let want: Want | null = result.want as Want;
|
||||
if(want == null || want.parameters == null) return;
|
||||
this.resultUri = want.parameters['resourceUri'] as string;
|
||||
}).catch((err: Error) => {
|
||||
Log.error(TAG, `jumpCameraTakephoto err: ${err}`);
|
||||
});
|
||||
})
|
||||
|
||||
Column() {
|
||||
Image($r('app.media.ic_public_camera_grid_item'))
|
||||
@ -67,16 +80,7 @@ export struct CameraGridItemComponent {
|
||||
.key('PickerCamera')
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
.onClick((event?: ClickEvent) => {
|
||||
this.jumpCameraTakePhoto().then((result) => {
|
||||
Log.info(TAG, `resourceUri = ${JSON.stringify(result)}`);
|
||||
let want: Want | null = result.want as Want;
|
||||
if(want == null || want.parameters == null) return;
|
||||
this.resultUri = want.parameters['resourceUri'] as string;
|
||||
}).catch((err: Error) => {
|
||||
Log.error(TAG, `jumpCameraTakephoto err: ${err}`);
|
||||
});
|
||||
})
|
||||
.hitTestBehavior(HitTestMode.Transparent)
|
||||
}
|
||||
.width('100%')
|
||||
.aspectRatio(1)
|
||||
@ -138,9 +142,34 @@ export struct CameraGridItemComponent {
|
||||
}
|
||||
}
|
||||
};
|
||||
let context: common.UIAbilityContext = AppStorage.get<common.UIAbilityContext>('photosAbilityContext') as common.UIAbilityContext;
|
||||
context.terminateSelfWithResult(abilityResult as ability.AbilityResult).then((result: void) => {
|
||||
Log.info(TAG, `terminateSelfWithResult abilityResult: ${abilityResult} result: ${result}`);
|
||||
});
|
||||
let storage = LocalStorage.getShared();
|
||||
if (storage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
|
||||
let session = storage?.get<UIExtensionContentSession>(Constants.PHOTO_PICKER_SESSION_KEY);
|
||||
let param = storage?.get<SelectParams>(Constants.PHOTO_PICKER_PARAMS_KEY);
|
||||
try {
|
||||
if (param?.bundleName) {
|
||||
Log.debug(TAG, `grantUriPermission to ${param?.bundleName}`);
|
||||
fileShare.grantUriPermission(uri,
|
||||
param?.bundleName,
|
||||
wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION|wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION,
|
||||
(err: BusinessError):void => {
|
||||
Log.error(TAG, `failed to grantUriPermission to ${param?.bundleName}`);
|
||||
session?.terminateSelfWithResult(abilityResult).then((result: void) => {
|
||||
Log.info(TAG, `session terminateSelfWithResult abilityResult: ${abilityResult} result: ${result}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
Log.error(TAG, `err: ${JSON.stringify(err)}`);
|
||||
session?.terminateSelfWithResult(abilityResult).then((result: void) => {
|
||||
Log.info(TAG, `session terminateSelfWithResult abilityResult: ${abilityResult} result: ${result}`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let context: common.UIAbilityContext = AppStorage.get<common.UIAbilityContext>('photosAbilityContext') as common.UIAbilityContext;
|
||||
context.terminateSelfWithResult(abilityResult as ability.AbilityResult).then((result: void) => {
|
||||
Log.info(TAG, `terminateSelfWithResult abilityResult: ${abilityResult} result: ${result}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,13 +40,17 @@ import {
|
||||
ThirdSelectPhotoBrowserActionBar
|
||||
} from '@ohos/common/CommonComponents';
|
||||
|
||||
import { FormConstants, IS_HORIZONTAL } from '../utils/ThirdSelectConstants';
|
||||
import { FormConstants, IS_HORIZONTAL, LEFT_BLANK, SelectParams } from '../utils/ThirdSelectConstants';
|
||||
import { ThirdSelectedPanel } from './ThirdSelectedPanel';
|
||||
import { MouseTurnPageOperation } from '@ohos/browser/BrowserComponents';
|
||||
import { Matrix4x4 } from '@ohos/common/src/main/ets/default/utils/Matrix4x4'
|
||||
import ability from '@ohos.ability.ability';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { Results } from '@ohos/common/src/main/ets/default/view/PhotoSwiper';
|
||||
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||
import fileShare from '@ohos.fileshare';
|
||||
import wantConstant from '@ohos.ability.wantConstant';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
const TAG: string = 'thiSel_ThirdSelectPhotoBrowserBase';
|
||||
|
||||
@ -456,10 +460,42 @@ export struct ThirdSelectPhotoBrowserBase {
|
||||
}
|
||||
}
|
||||
};
|
||||
let context: common.UIAbilityContext = AppStorage.get<common.UIAbilityContext>('photosAbilityContext') as common.UIAbilityContext;
|
||||
context.terminateSelfWithResult(abilityResult).then((result: void) => {
|
||||
Log.info(TAG, `terminateSelf result: ${result}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
let localStorage = LocalStorage.getShared();
|
||||
if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
|
||||
let session = localStorage?.get<UIExtensionContentSession>(Constants.PHOTO_PICKER_SESSION_KEY);
|
||||
let param = localStorage?.get<SelectParams>(Constants.PHOTO_PICKER_PARAMS_KEY);
|
||||
if (uriArray === null || uriArray === undefined || uriArray?.length === 0) {
|
||||
session?.terminateSelfWithResult(abilityResult).then((result: void) => {
|
||||
Log.info(TAG, `session terminateSelfWithResult abilityResult: ${JSON.stringify(abilityResult)} result: ${result}`);
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
if (param?.bundleName) {
|
||||
Log.debug(TAG, `grantUriPermission to ${param?.bundleName}`);
|
||||
uriArray.forEach(uri => {
|
||||
fileShare.grantUriPermission(uri, param?.bundleName,
|
||||
wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION | wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION,
|
||||
(err: BusinessError): void => {
|
||||
Log.error(TAG, `failed to grantUriPermission to ${param?.bundleName}`);
|
||||
session?.terminateSelfWithResult(abilityResult).then((result: void) => {
|
||||
Log.info(TAG, `session terminateSelfWithResult abilityResult: ${JSON.stringify(abilityResult)} result: ${result}`);
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
Log.error(TAG, `err: ${JSON.stringify(err)}`);
|
||||
session?.terminateSelfWithResult(abilityResult).then((result: void) => {
|
||||
Log.info(TAG, `session terminateSelfWithResult abilityResult: ${JSON.stringify(abilityResult)} result: ${result}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let context: common.UIAbilityContext = AppStorage.get<common.UIAbilityContext>('photosAbilityContext') as common.UIAbilityContext;
|
||||
context.terminateSelfWithResult(abilityResult).then((result: void) => {
|
||||
Log.info(TAG, `terminateSelf result: ${result}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ import {
|
||||
BrowserController,
|
||||
GridScrollBar,
|
||||
ImageGridItemComponent,
|
||||
NoPhotoComponent,
|
||||
NoPhotoIndexComponent
|
||||
} from '@ohos/common/CommonComponents';
|
||||
import { ThirdSelectedPageActionBar } from './ThirdSelectedPageActionBar';
|
||||
@ -64,6 +65,7 @@ import SmartPickerConstants from '../common/SmartPickerConstants';
|
||||
import { SmartPickerManager } from '../common/SmartPickerManager';
|
||||
import { ThirdSelectSmartRecommendTabBar } from './ThirdSelectSmartRecommendTabBar';
|
||||
import SmartPickerDataAdapter from '../common/SmartPickerDataAdapter';
|
||||
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||
|
||||
const TAG: string = 'thiSel_ThirdSelectPhotoGridBase';
|
||||
|
||||
@ -174,7 +176,12 @@ export struct ThirdSelectPhotoGridBase {
|
||||
}
|
||||
|
||||
aboutToAppear(): void {
|
||||
let param: SelectParams = router.getParams() as SelectParams;
|
||||
let param: SelectParams;
|
||||
if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
|
||||
param = localStorage.get<SelectParams>(Constants.PHOTO_PICKER_PARAMS_KEY) as SelectParams;
|
||||
} else {
|
||||
param = router.getParams() as SelectParams;
|
||||
}
|
||||
this.initSelectParams(param);
|
||||
if (this.selectParams.isFromFa) {
|
||||
this.selectParams.filterMediaType = AlbumDefine.FILTER_MEDIA_TYPE_IMAGE;
|
||||
@ -220,7 +227,7 @@ export struct ThirdSelectPhotoGridBase {
|
||||
this.broadCast.on(BroadCastConstants.THIRD_PICKER_SWITCH_SMART_RECOMMEND_TAB, this.onSwitchSmartRecommendTabFunc);
|
||||
MediaObserver.getInstance().registerObserver(this.dataObserver);
|
||||
this.isActive = true;
|
||||
|
||||
ScreenManager.getInstance().on(ScreenManager.ON_WIN_SIZE_CHANGED, this.onWindowSizeChangeCallBack);
|
||||
Log.error(TAG, 'meow data count = ' + this.dataSource.totalCount());
|
||||
}
|
||||
|
||||
@ -274,6 +281,7 @@ export struct ThirdSelectPhotoGridBase {
|
||||
this.broadCast.off(BroadCastConstants.PICKER_INIT_DATA_FIRST_QUERY_FINISH);
|
||||
}
|
||||
this.dataSource.releaseBroadCast();
|
||||
ScreenManager.getInstance().off(ScreenManager.ON_WIN_SIZE_CHANGED, this.onWindowSizeChangeCallBack);
|
||||
Log.info(TAG, `call aboutToDisappear`)
|
||||
}
|
||||
|
||||
@ -378,6 +386,15 @@ export struct ThirdSelectPhotoGridBase {
|
||||
totalSelectedCount: $selectedCount
|
||||
})
|
||||
|
||||
if (this.isEmpty) {
|
||||
if (this.selectParams.isFromFa) {
|
||||
NoPhotoIndexComponent({ index: Constants.TIMELINE_PAGE_INDEX, hasBarSpace: false })
|
||||
} else {
|
||||
if (this.selectParams.cameraAble) {
|
||||
NoPhotoComponent({ title: $r('app.string.no_distributed_photo_head_title_album') })
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.selectParams.isFromFa && this.isEmpty) {
|
||||
NoPhotoIndexComponent({ index: Constants.TIMELINE_PAGE_INDEX, hasBarSpace: false })
|
||||
}
|
||||
@ -652,21 +669,47 @@ export struct ThirdSelectPhotoGridBase {
|
||||
let self = this;
|
||||
let uriLength = 0;
|
||||
if (uriArray == null && uriArray == undefined) {
|
||||
let context: common.UIAbilityContext = AppStorage.get<common.UIAbilityContext>('photosAbilityContext') as common.UIAbilityContext;
|
||||
context.terminateSelfWithResult(abilityResult as ability.AbilityResult).then((result: void) => {
|
||||
Log.debug(TAG, `terminateSelfWithResult result: ${result}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
} else {
|
||||
uriLength = uriArray.length;
|
||||
SelectUtil.grantPermissionForUris(uriArray, self.selectParams.bundleName).then(() => {
|
||||
Log.info(TAG, `grant permission success.`);
|
||||
if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
|
||||
let session = localStorage?.get<UIExtensionContentSession>(Constants.PHOTO_PICKER_SESSION_KEY);
|
||||
session?.terminateSelfWithResult(abilityResult as ability.AbilityResult).then((result: void) => {
|
||||
Log.debug(TAG, `session terminateSelfWithResult result: ${result}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
} else {
|
||||
let context: common.UIAbilityContext = AppStorage.get<common.UIAbilityContext>('photosAbilityContext') as common.UIAbilityContext;
|
||||
context.terminateSelfWithResult(abilityResult as ability.AbilityResult).then((result: void) => {
|
||||
Log.debug(TAG, `terminateSelfWithResult result: ${result}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
}).catch((err: Error) => {
|
||||
Log.error(TAG, `grant permission error: ${JSON.stringify(err)}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
uriLength = uriArray.length;
|
||||
if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
|
||||
let session = localStorage?.get<UIExtensionContentSession>(Constants.PHOTO_PICKER_SESSION_KEY);
|
||||
let param = localStorage?.get<SelectParams>(Constants.PHOTO_PICKER_PARAMS_KEY);
|
||||
if (param?.bundleName) {
|
||||
SelectUtil.grantPermissionForUris(uriArray, param.bundleName).then(() => {
|
||||
Log.info(TAG, `session grant permission success.`);
|
||||
let context: common.UIAbilityContext = AppStorage.get<common.UIAbilityContext>('photosAbilityContext') as common.UIAbilityContext;
|
||||
session?.terminateSelfWithResult(abilityResult as ability.AbilityResult).then((result: void) => {
|
||||
Log.debug(TAG, `session terminateSelfWithResult result: ${result}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
}).catch((err: Error) => {
|
||||
Log.error(TAG, `session grant permission error: ${JSON.stringify(err)}, self result ${JSON.stringify(abilityResult)}`);
|
||||
session?.terminateSelfWithResult(abilityResult as ability.AbilityResult).then((result: void) => {
|
||||
Log.debug(TAG, `session terminateSelfWithResult result: ${result}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
SelectUtil.grantPermissionForUris(uriArray, self.selectParams.bundleName).then(() => {
|
||||
Log.info(TAG, `grant permission success.`);
|
||||
let context: common.UIAbilityContext = AppStorage.get<common.UIAbilityContext>('photosAbilityContext') as common.UIAbilityContext;
|
||||
context.terminateSelfWithResult(abilityResult as ability.AbilityResult).then((result: void) => {
|
||||
Log.debug(TAG, `terminateSelfWithResult result: ${result}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
}).catch((err: Error) => {
|
||||
Log.error(TAG, `grant permission error: ${JSON.stringify(err)}, self result ${JSON.stringify(abilityResult)}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
interface Msg {
|
||||
isOriginalChecked: boolean;
|
||||
|
@ -62,7 +62,9 @@ export struct ThirdSelectedPageActionBar {
|
||||
})
|
||||
}
|
||||
.padding({
|
||||
top: this.isHorizontal ? Constants.NUMBER_0 : px2vp(this.statusBarHeight)
|
||||
top: (this.isHorizontal && !ScreenManager.getInstance().isUIExtensionEnv()) ?
|
||||
$r('app.float.third_selected_actionbar_padding_top') :
|
||||
(this.statusBarHeight === 0) ? $r('app.float.third_selected_actionbar_padding_top') : px2vp(this.statusBarHeight)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { BrowserConstants } from '@ohos/common';
|
||||
import { BreakpointSystem, BrowserConstants, Constants } from '@ohos/common';
|
||||
import { BrowserController } from '@ohos/common/CommonComponents';
|
||||
import { ThirdSelectPhotoBrowserBase, ThirdSelectPhotoGridBase } from '@ohos/thirdselect';
|
||||
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||
|
||||
let localStorage = LocalStorage.getShared();
|
||||
|
||||
@ -28,6 +29,19 @@ export struct ThirdSelectPhotoGridPage {
|
||||
@State @Watch('updateAnimationStatus') browserController: BrowserController = new BrowserController(true);
|
||||
@State isRunningAnimation: boolean = false;
|
||||
private onBackFunc: Function = (): void => {};
|
||||
private breakpointSystem: BreakpointSystem = new BreakpointSystem();
|
||||
|
||||
aboutToAppear() {
|
||||
if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
|
||||
this.breakpointSystem.registerOrientationChange();
|
||||
}
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
|
||||
this.breakpointSystem.unregisterOrientationChange();
|
||||
}
|
||||
}
|
||||
|
||||
onPageShow() {
|
||||
this.pageStatus = true;
|
||||
@ -44,6 +58,10 @@ export struct ThirdSelectPhotoGridPage {
|
||||
}
|
||||
if (this.onBackFunc) {
|
||||
this.onBackFunc();
|
||||
if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
|
||||
let session = localStorage?.get<UIExtensionContentSession>(Constants.PHOTO_PICKER_SESSION_KEY);
|
||||
session?.terminateSelf();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
|
||||
import { Constants, Log, UserFileManagerAccess } from '@ohos/common';
|
||||
import { ScreenManager } from '@ohos/common/src/main/ets/default/model/common/ScreenManager';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||
import { SelectParams } from '@ohos/thirdselect/src/main/ets/default/utils/ThirdSelectConstants';
|
||||
import uiExtensionHost from '@ohos.uiExtensionHost';
|
||||
|
||||
const TAG = '[PickerUIExtensionAbility]'
|
||||
|
||||
export default class PickerUIExtensionAbility extends UIExtensionAbility {
|
||||
onCreate(): void {
|
||||
Log.info(TAG, "onCreate");
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
Log.info(TAG, "onDestroy");
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
Log.info(TAG, "onForeground");
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
Log.info(TAG, "onBackground");
|
||||
}
|
||||
|
||||
onSessionCreate(want: Want, session: UIExtensionContentSession): void {
|
||||
let extensionWindow: uiExtensionHost.UIExtensionHostWindowProxy | undefined = session.getUIExtensionHostWindowProxy();
|
||||
AppStorage.setOrCreate('photosAbilityContext',this.context);
|
||||
AppStorage.setOrCreate(Constants.PHOTO_PICKER_EXTENSION_WINDOW, extensionWindow);
|
||||
let storage: LocalStorage = new LocalStorage();
|
||||
let params: SelectParams = this.parseWant(want);
|
||||
storage.setOrCreate(Constants.PHOTO_PICKER_SESSION_KEY, session);
|
||||
storage.setOrCreate(Constants.PHOTO_PICKER_PARAMS_KEY, params);
|
||||
storage.setOrCreate(Constants.PHOTO_PICKER_EXTENSION_WINDOW, extensionWindow);
|
||||
UserFileManagerAccess.getInstance().onCreate(this.context);
|
||||
ScreenManager.getInstance().initializationSize(undefined).then((): void => {
|
||||
ScreenManager.getInstance().getAvoidArea();
|
||||
ScreenManager.getInstance().setMainWindow();
|
||||
session.loadContent('pages/ThirdSelectPhotoGridPage', storage);
|
||||
Log.info(TAG, 'onSessionCreate');
|
||||
});
|
||||
}
|
||||
|
||||
onSessionDestroy(session: UIExtensionContentSession) {
|
||||
Log.info(TAG, "onSessionDestroy");
|
||||
UserFileManagerAccess.getInstance().onDestroy();
|
||||
ScreenManager.getInstance().destroyMainWindow();
|
||||
AppStorage.delete(Constants.PHOTO_PICKER_EXTENSION_WINDOW);
|
||||
}
|
||||
|
||||
private parseWant(want: Want): SelectParams {
|
||||
let wantParam: Record<string, Object> = want.parameters as Record<string, Object>;
|
||||
let params: SelectParams = SelectParams.defaultParam();
|
||||
let selectType: string = wantParam?.uri as string;
|
||||
if (selectType) {
|
||||
params.isMultiPick = selectType === Constants.WANT_PARAM_URI_SELECT_MULTIPLE;
|
||||
params.maxSelectCount = params.isMultiPick ? wantParam?.maxSelectCount as number : 1;
|
||||
params.bundleName = wantParam[Constants.KEY_WANT_PARAMETERS_CALLER_BUNDLE_NAME] as string;
|
||||
params.filterMediaType = wantParam?.filterMediaType as string;
|
||||
params.cameraAble = (wantParam?.isPhotoTakingSupported as boolean) === undefined ? true : (wantParam?.isPhotoTakingSupported as boolean);
|
||||
params.editAble = (wantParam?.isEditSupported as boolean) === undefined ? true : (wantParam?.isEditSupported as boolean);
|
||||
params.isFirstEnter = true;
|
||||
} else {
|
||||
Log.error(TAG, `invalid selectType: ${JSON.stringify(selectType)}`);
|
||||
}
|
||||
Log.info(TAG, `parseWant: ${JSON.stringify(wantParam)}, params: ${JSON.stringify(params)}`);
|
||||
return params;
|
||||
}
|
||||
}
|
@ -55,7 +55,9 @@
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home","ohos.want.action.viewData","ohos.want.action.photoPicker"
|
||||
"action.system.home",
|
||||
"ohos.want.action.viewData",
|
||||
"ohos.want.action.photoPicker"
|
||||
],
|
||||
"uris": [
|
||||
{
|
||||
@ -89,7 +91,9 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"supportWindowMode": ["fullscreen"]
|
||||
"supportWindowMode": [
|
||||
"fullscreen"
|
||||
]
|
||||
}
|
||||
],
|
||||
"extensionAbilities": [
|
||||
@ -123,7 +127,15 @@
|
||||
"type": "image/*"
|
||||
}
|
||||
],
|
||||
}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "PickerUIExtensionAbility",
|
||||
"description": "PickerUIExtensionAbility",
|
||||
"type": "sysPicker/photoPicker",
|
||||
"exported": true,
|
||||
"srcEntry": "./ets/picker/PickerUIExtensionAbility.ets"
|
||||
},
|
||||
{
|
||||
"name": "DeleteUIExtensionAbility",
|
||||
|
Loading…
Reference in New Issue
Block a user