mirror of
https://gitee.com/openharmony/applications_photos
synced 2025-02-21 07:31:17 +00:00
some problem
Signed-off-by: z00513345 <zhuchengfeng1@huawei.com>
This commit is contained in:
parent
1ac57d4635
commit
50eefad8a6
@ -177,7 +177,6 @@ export default class MainAbility extends Ability {
|
||||
if (dataSource.getRawData(0) || times >= MainAbility.RETRY_MAX_TIMES) {
|
||||
AppStorage.SetOrCreate(Constants.APP_KEY_PHOTO_BROWSER, dataSource);
|
||||
windowStage.setUIContent(this.context, 'feature/browser/view/PhotoBrowser', null);
|
||||
ScreenManager.getInstance().initWindowMode();
|
||||
clearInterval(intervalId);
|
||||
}
|
||||
times++;
|
||||
@ -185,7 +184,6 @@ export default class MainAbility extends Ability {
|
||||
});
|
||||
} else {
|
||||
windowStage.setUIContent(this.context, pagePath, null);
|
||||
ScreenManager.getInstance().initWindowMode();
|
||||
}
|
||||
TraceControllerUtils.finishTrace('onWindowStageCreate');
|
||||
}).catch(() => {
|
||||
|
@ -12,6 +12,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import image from '@ohos.multimedia.image'
|
||||
import { MediaLibraryAccess } from '../../../access/MediaLibraryAccess';
|
||||
import { DateUtil } from '../../../utils/DateUtil';
|
||||
import { Constants } from '../../common/Constants'
|
||||
|
||||
@ -36,13 +39,14 @@ export class MediaItem {
|
||||
displayName: string;
|
||||
filePath: string;
|
||||
path: string;
|
||||
canRotate: boolean;
|
||||
private fileAsset: any
|
||||
private canRotate: number = -1;
|
||||
|
||||
constructor(data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.fileAsset = data
|
||||
this.id = data.id;
|
||||
this.mediaType = data.mediaType;
|
||||
this.uri = data.uri;
|
||||
@ -63,7 +67,6 @@ export class MediaItem {
|
||||
this.imgHeight = this.height;
|
||||
this.displayName = data.displayName;
|
||||
this.path = data.relativePath;
|
||||
this.canRotate = false;
|
||||
}
|
||||
|
||||
setThumbnail(thumbnail: string) {
|
||||
@ -74,12 +77,30 @@ export class MediaItem {
|
||||
this.isFavor = isFavorite;
|
||||
}
|
||||
|
||||
setOrientation(orientation: string) {
|
||||
async isRotatable(): Promise<boolean> {
|
||||
if (this.canRotate == -1) {
|
||||
await this.setRotatable()
|
||||
}
|
||||
return this.canRotate == 1
|
||||
}
|
||||
|
||||
private async setRotatable() {
|
||||
try {
|
||||
let fd = await MediaLibraryAccess.getInstance().openAsset('RW', this.fileAsset);
|
||||
let imageSourceApi: image.ImageSource = image.createImageSource(fd);
|
||||
let orientation = await imageSourceApi.getImageProperty("Orientation")
|
||||
this.setOrientation(orientation)
|
||||
} catch (err) {
|
||||
this.setOrientation("")
|
||||
}
|
||||
}
|
||||
|
||||
private setOrientation(orientation: string) {
|
||||
if (orientation.length == 0) {
|
||||
this.canRotate = false;
|
||||
this.canRotate = 0;
|
||||
return
|
||||
}
|
||||
this.canRotate = true;
|
||||
this.canRotate = 1;
|
||||
switch (orientation) {
|
||||
case "Left-bottom":
|
||||
this.orientation = 270
|
||||
|
@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import image from '@ohos.multimedia.image'
|
||||
import { AlbumDefine } from '../AlbumDefine'
|
||||
import { BrowserDataImpl } from '../BrowserDataImpl'
|
||||
import { Logger } from '../../../utils/Logger'
|
||||
@ -66,7 +65,6 @@ export class PhotoDataImpl extends BrowserDataImpl {
|
||||
try {
|
||||
let item = dataList[i];
|
||||
let mediaItem: MediaItem = new MediaItem(item);
|
||||
await this.checkRotate(mediaItem, item)
|
||||
if (favor[i].status = 'success') {
|
||||
mediaItem.setFavorite(favor[i].res);
|
||||
} else {
|
||||
@ -83,22 +81,6 @@ export class PhotoDataImpl extends BrowserDataImpl {
|
||||
callback.callback(mediaItemList);
|
||||
}
|
||||
|
||||
private async checkRotate(mediaItem: MediaItem, fileAsset): Promise<void> {
|
||||
this.logger.info(`checkRotate`);
|
||||
try {
|
||||
let fd = await MediaLibraryAccess.getInstance().openAsset('RW', fileAsset);
|
||||
this.logger.debug(`get fd ${fd}`);
|
||||
let imageSourceApi: image.ImageSource = image.createImageSource(fd);
|
||||
this.logger.debug(`get imageSourceApi ${mediaItem.displayName}`);
|
||||
let orientation = await imageSourceApi.getImageProperty("Orientation")
|
||||
this.logger.debug(`get imageSourceApi ${mediaItem.displayName} success ${orientation}`);
|
||||
mediaItem.setOrientation(orientation)
|
||||
} catch (err) {
|
||||
this.logger.debug(`get imageSourceApi ${mediaItem.displayName} fail`);
|
||||
mediaItem.setOrientation("")
|
||||
}
|
||||
}
|
||||
|
||||
handlePromise(promiseList) {
|
||||
return promiseList.map(promise => promise.then((res) => ({ status: 'success', res }),
|
||||
(err) => ({ status: 'failed', err })))
|
||||
|
@ -1,3 +1,4 @@
|
||||
import window from '@ohos.window';
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -78,24 +79,19 @@ export class ScreenManager {
|
||||
async initializationSize(win): Promise<void> {
|
||||
this.mainWindow = win;
|
||||
let properties = await win.getProperties();
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
if (!properties || !properties.windowRect) {
|
||||
reject();
|
||||
}
|
||||
let size = properties.windowRect;
|
||||
this.logger.info(`display screen windowRect: ${JSON.stringify(size)}`);
|
||||
this.winWidth = px2vp(size.width);
|
||||
this.winHeight = px2vp(size.height);
|
||||
this.logger.info(`display screen windowRect px2vp: ${this.winWidth} ${this.winHeight}`);
|
||||
if (this.winWidth < ScreenWidth.WIDTH_MEDIUM) {
|
||||
this.columns = ColumnSize.COLUMN_FOUR;
|
||||
} else if (this.winWidth >= ScreenWidth.WIDTH_MEDIUM && this.winWidth < ScreenWidth.WIDTH_LARGE) {
|
||||
this.columns = ColumnSize.COLUMN_EIGHT;
|
||||
} else {
|
||||
this.columns = ColumnSize.COLUMN_TWELVE;
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
let size = properties.windowRect;
|
||||
this.logger.info(`display screen windowRect: ${JSON.stringify(size)}`);
|
||||
this.winWidth = px2vp(size.width);
|
||||
this.winHeight = px2vp(size.height);
|
||||
this.logger.info(`display screen windowRect px2vp: ${this.winWidth} ${this.winHeight}`);
|
||||
if (this.winWidth < ScreenWidth.WIDTH_MEDIUM) {
|
||||
this.columns = ColumnSize.COLUMN_FOUR;
|
||||
} else if (this.winWidth >= ScreenWidth.WIDTH_MEDIUM && this.winWidth < ScreenWidth.WIDTH_LARGE) {
|
||||
this.columns = ColumnSize.COLUMN_EIGHT;
|
||||
} else {
|
||||
this.columns = ColumnSize.COLUMN_TWELVE;
|
||||
}
|
||||
await this.initWindowMode()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,9 +185,9 @@ export class ScreenManager {
|
||||
return this.naviBarHeight;
|
||||
}
|
||||
|
||||
initWindowMode() {
|
||||
private async initWindowMode() {
|
||||
this.logger.debug(`start to initialize photos application window mode: ${this.windowMode}`);
|
||||
this.checkWindowMode();
|
||||
await this.checkWindowMode();
|
||||
this.mainWindow && this.setMainWindow();
|
||||
}
|
||||
|
||||
@ -217,7 +213,7 @@ export class ScreenManager {
|
||||
}
|
||||
}
|
||||
|
||||
setMainWindow() {
|
||||
private setMainWindow() {
|
||||
this.logger.debug('setMainWindow');
|
||||
this.mainWindow.on('windowSizeChange', (data) => {
|
||||
this.logger.debug(`windowSizeChange ${JSON.stringify(data)}`);
|
||||
@ -233,14 +229,13 @@ export class ScreenManager {
|
||||
});
|
||||
}
|
||||
|
||||
setFullScreen() {
|
||||
async setFullScreen() {
|
||||
let topWindow: any = AppStorage.Get(Constants.MAIN_WINDOW);
|
||||
this.logger.debug('getTopWindow start');
|
||||
try {
|
||||
topWindow.setLayoutFullScreen(true, () => {
|
||||
this.logger.debug('setFullScreen true Succeeded');
|
||||
this.hideStatusBar();
|
||||
});
|
||||
await topWindow.setLayoutFullScreen(true)
|
||||
this.logger.debug('setFullScreen true Succeeded');
|
||||
this.hideStatusBar();
|
||||
} catch (err) {
|
||||
this.logger.error(`setFullScreen err: ${err}`);
|
||||
}
|
||||
@ -436,7 +431,7 @@ export class ScreenManager {
|
||||
topWindow.setKeepScreenOn(true, () => {
|
||||
this.logger.info('setKeepScreenOn Succeeded');
|
||||
})
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
this.logger.error(`setKeepScreenOn err: ${err}`);
|
||||
}
|
||||
}
|
||||
@ -448,7 +443,7 @@ export class ScreenManager {
|
||||
topWindow.setKeepScreenOn(false, () => {
|
||||
this.logger.info('setKeepScreenOff Succeeded');
|
||||
})
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
this.logger.error(`setKeepScreenOff err: ${err}`);
|
||||
}
|
||||
}
|
||||
|
@ -69,47 +69,6 @@ export class UiUtil {
|
||||
*/
|
||||
private static logger: Logger = new Logger('UiUtil');
|
||||
|
||||
/**
|
||||
* Set full screen immersion
|
||||
*
|
||||
* @param window window
|
||||
* @param isFullScreen isFullScreen
|
||||
*/
|
||||
static setLayoutFullScreen(paramWindow: any, isFullScreen: boolean): void {
|
||||
paramWindow.getTopWindow().then((data) => {
|
||||
this.logger.info(`WindowPlugin getTopWindow promise success data: ${data}`);
|
||||
data.setLayoutFullScreen(isFullScreen).then(() => {
|
||||
this.logger.info('finish to set full screen');
|
||||
});
|
||||
}).catch((error) => {
|
||||
this.logger.error(`WindowPlugin getTopWindow promise failed because ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set system status bar / navigation bar display / hide
|
||||
*
|
||||
* @param window window
|
||||
* @param systemBars ["status", "navigation"] ["status"] ["navigation"] []
|
||||
*/
|
||||
static setSystemUi(isShowBar: boolean): void {
|
||||
this.logger.debug('setSystemUi start');
|
||||
let topWindow: any = AppStorage.Get(Constants.MAIN_WINDOW);
|
||||
this.logger.debug('getTopWindow start');
|
||||
let names = ["status", "navigation"];
|
||||
if (!isShowBar) {
|
||||
names = [];
|
||||
}
|
||||
this.logger.debug(`getTopWindow names: ${names} end`);
|
||||
try {
|
||||
topWindow.setSystemBarEnable(names, () => {
|
||||
this.logger.debug('setFullScreen Succeeded');
|
||||
})
|
||||
} catch (err) {
|
||||
this.logger.error(`setSystemUi err: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get system status bar height
|
||||
*
|
||||
|
@ -106,8 +106,10 @@ export struct PhotoItem {
|
||||
this.logger.info(`photoCanRotateCheck not current photo`);
|
||||
return
|
||||
}
|
||||
this.logger.debug(`photoCanRotateCheck this.item.canRotate ${this.item.canRotate}`);
|
||||
this.broadCast.emit(PhotoConstants.PHOTO_CAN_ROTATE, [this.item.canRotate]);
|
||||
this.item.isRotatable().then(canRotate => {
|
||||
this.logger.debug(`photoCanRotateCheck this.item.canRotate ${canRotate}`);
|
||||
this.broadCast.emit(PhotoConstants.PHOTO_CAN_ROTATE, [canRotate]);
|
||||
})
|
||||
}
|
||||
|
||||
aboutToDisappear(): void {
|
||||
|
@ -49,7 +49,12 @@ export struct PhotoSwiper {
|
||||
}
|
||||
this.dataSource.onDataReloaded();
|
||||
} }, () => {
|
||||
this.dataSource.deleteData(this.currentIndex);
|
||||
let totalCount = this.dataSource.totalCount();
|
||||
if (this.currentIndex + 1 == totalCount) {
|
||||
this.swiperController.showPrevious()
|
||||
} else {
|
||||
this.swiperController.showNext()
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user