yuanfeiyang2_wd

desc:app启动页

export class GlobalContext {
private constructor() { }
private static instance: GlobalContext;
private _objects = new Map<string, Object>();
public static getContext(): GlobalContext {
if (!GlobalContext.instance) {
GlobalContext.instance = new GlobalContext();
}
return GlobalContext.instance;
}
getObject(value: string): Object | undefined {
return this._objects.get(value);
}
setObject(key: string, objectClass: Object): void {
this._objects.set(key, objectClass);
}
}
\ No newline at end of file
... ...
... ... @@ -16,7 +16,7 @@ export default class EntryAbility extends UIAbility {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/MainPage', (err, data) => {
windowStage.loadContent('pages/LaunchPage', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
... ...
import router from '@ohos.router'
@Entry
@Component
struct LaunchAdvertisingPage {
@State time: number = 4
timer :number = -1
enter() {
router.replaceUrl({
url:'pages/MainPage'
})
}
onPageShow(){
this.timer = setInterval(() => {
this.time--
if (this.time < 1) {
this.enter()
clearInterval(this.timer)
}
},1000)
}
build(){
Column(){
Stack({alignContent:Alignment.Bottom}){
Stack({alignContent:Alignment.Bottom}){
Column(){
Image($r('app.media.app_icon'))
.margin({
top:'128lpx',left:'48lpx',right:'48lpx',bottom:'128lpx'
})
}
.justifyContent(FlexAlign.Center)
.width('100%')
.height('100%')
.margin({
bottom: 0
})
Stack({alignContent:Alignment.TopEnd}){
Button(){
Text(this.time + 's 跳过')
.fontSize('27lpx')
.fontColor(Color.White)
.margin({left:'28lpx',right:'28lpx'})
}
.width('148lpx')
.height('56lpx')
.margin({top:'54lpx',right:'19lpx'})
.backgroundColor('#80000000')
.onClick(() => {
this.enter()
})
}
.width('100%')
.height('100%')
Button(){
Row(){
Text('点击跳转至详情或第三方应用')
.fontSize('31lpx')
.fontColor(Color.White)
.margin({
left:'55lpx'
})
Image($r('app.media.Slice'))
.width('46lpx')
.height('46lpx')
.margin({right:'55lpx'})
}.alignItems(VerticalAlign.Center)
}
.width('566lpx')
.height('111lpx')
.margin({
bottom: '51lpx'
})
.backgroundColor('#80000000')
}
}
.width('100%')
.height('84%')
.backgroundColor('#FF6C75')
.margin({top:'0'})
Image($r('app.media.LaunchPage_logo'))
.width('278lpx')
.height('154lpx')
.margin({bottom: '48lpx'})
}
.width('100%')
.height('100%')
.backgroundColor(Color.White)
}
}
\ No newline at end of file
... ...
import media from '@ohos.multimedia.media'
import App from '@system.app'
import Router from '@system.router'
import router from '@ohos.router'
import common from '@ohos.app.ability.common'
import CustomDialogComponent from '../view/CustomDialogComponent'
import preferences from '@ohos.data.preferences'
import { GlobalContext } from '../common/utils/GlobalContext'
@Entry
@Component
struct LaunchPage {
private context?: common.UIAbilityContext;
private timerId: number = 0;
private isJumpToAdvertising: boolean = false;
dialogController: CustomDialogController = new CustomDialogController({
builder: CustomDialogComponent(
{
cancel: () => {
this.onCancel();
},
confirm: () => {
this.onConfirm();
}
}),
alignment: DialogAlignment.Center,
offset: { dx: 0, dy: '-24' },
customStyle: true,
autoCancel: false
});
onCancel() {
// Exit the application.
this.context?.terminateSelf();
}
onConfirm() {
// Save privacy agreement status.
this.saveIsPrivacy();
this.jumpToAdvertisingPage();
}
jumpToAdvertisingPage() {
this.timerId = setTimeout(() => {
this.isJumpToAdvertising = true;
router.pushUrl({
url: 'pages/LaunchAdvertisingPage'
}).catch((error: Error) => {
//Logger.error(CommonConstants.LAUNCHER_PAGE_TAG, 'LauncherPage pushUrl error ' + JSON.stringify(error));
});
}, 1000);
}
onPageShow() {
this.context = getContext(this) as common.UIAbilityContext;
// Get the operation class for saving data.
this.getDataPreferences(this).then((preferences: preferences.Preferences) => {
preferences.get('isPrivacy', true).then((value: preferences.ValueType) => {
//Logger.info(CommonConstants.LAUNCHER_PAGE_TAG, 'onPageShow value: ' + value);
if (value) {
// let isJumpPrivacy: boolean = globalThis.isJumpPrivacy ?? false;
// let isJumpPrivacy: boolean = (GlobalContext.getContext().getObject('isJumpPrivacy') as boolean) ?? false;
// if (!isJumpPrivacy) {
this.dialogController.open();
// }
} else {
this.jumpToAdvertisingPage();
}
});
});
}
onPageHide() {
if (this.isJumpToAdvertising) {
router.clear();
}
// globalThis.isJumpPrivacy = true;
//GlobalContext.getContext().setObject('isJumpPrivacy', true);
clearTimeout(this.timerId);
}
getDataPreferences(common: Object) {
return preferences.getPreferences(getContext(common), 'myStore');
}
saveIsPrivacy() {
let preferences: Promise<preferences.Preferences> = this.getDataPreferences(this);
preferences.then((result: preferences.Preferences) => {
let privacyPut = result.put('isPrivacy', false);
result.flush();
privacyPut.then(() => {
//Logger.info('LauncherPage', 'Put the value of startup Successfully.');
}).catch((err: Error) => {
//Logger.error('LauncherPage', 'Put the value of startup Failed, err: ' + err);
});
}).catch((err: Error) => {
//Logger.error('LauncherPage', 'Get the preferences Failed, err: ' + err);
});
}
build(){
Stack({alignContent:Alignment.Bottom}){
Image($r('app.media.LaunchPage_logo'))
.width('278lpx')
.height('154lpx')
.margin({
bottom:'48lpx'
})
}
.width('100%')
.height('100%')
.backgroundColor(Color.White)
}
}
\ No newline at end of file
... ...
import webview from '@ohos.web.webview';
import router from '@ohos.router';
import { GlobalContext } from '../common/utils/GlobalContext'
@Entry
@Component
struct PrivacyPage {
@State message: string = 'Hello World'
webController: webview.WebviewController = new webview.WebviewController();
//@State params: object = router.getParams();
build() {
Row() {
Column() {
// Web component loading H5.
Web({ src: 'https://www.baidu.com', controller: this.webController })
.zoomAccess(false)
.width('100%')
.height('100%')
.aspectRatio(1)
// .onConfirm((event) => {
// AlertDialog.show({
// message: Const.WEB_ALERT_DIALOG_TEXT_VALUE + event?.message,
// confirm: {
// value: $r('app.string.web_alert_dialog_button_value'),
// action: () => {
// event?.result.handleConfirm();
// }
// },
// cancel: () => {
// event?.result.handleCancel();
// }
// });
// return true;
// })
// .onErrorReceive((event) => {
// if (event?.error.getErrorInfo() === 'ERR_INTERNET_DISCONNECTED') {
// prompt.showToast({
// message: $r('app.string.internet_err'),
// duration: Const.WebConstant_DURATION
// })
// }
// if (event?.error.getErrorInfo() === 'ERR_CONNECTION_TIMED_OUT') {
// prompt.showToast({
// message: $r('app.string.internet_err'),
// duration: Const.WebConstant_DURATION
// })
// }
// })
// .onProgressChange((event) => {
// if (event?.newProgress === Const.WebConstant_PROGRESS_MAX) {
// this.isLoading = false;
// clearInterval(this.intervalLoading);
// this.intervalLoading = -1;
// }
// })
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
... ...
import router from '@ohos.router';
import { GlobalContext } from '../common/utils/GlobalContext'
import { NavigatorModel } from '../viewModel/NavigatorModel';
@CustomDialog
export default struct CustomDialogComponent {
controller: CustomDialogController = new CustomDialogController({'builder': ''})
cancel: Function = () => {}
confirm: Function = () => {}
build(){
Column(){
Text($r('app.string.dialog_text_title'))
.width("90%")
.fontColor($r('app.color.dialog_text_color'))
.fontSize($r('app.float.dialog_text_privacy_size'))
.textAlign(TextAlign.Center)
.fontWeight('600')
.margin({
top: $r('app.float.dialog_text_privacy_top'),
bottom: $r('app.float.dialog_text_privacy_bottom')
})
Text($r('app.string.dialog_text_privacy_content'))
.fontSize($r('app.float.dialog_common_text_size'))
.width('90%')
Row(){
// Button(){
// Text($r('app.string.privacy_text_title_policy'))
// .fontSize('27lpx')
// .fontColor(Color.Red)
// .margin({left:'10lpx',right:'10lpx'})
// }
// .width('90%')
// .height('56lpx')
// .margin({top:'54lpx',right:'19lpx'})
// .backgroundColor('#80000000')
// .onClick(() => {
//
// })
// Button(){
// Text($r('app.string.privacy_text_title_protocol'))
// .fontSize('27lpx')
// .fontColor(Color.Red)
// .margin({left:'10lpx',right:'10lpx'})
// }
// .width('90%')
// .height('56lpx')
// .margin({top:'54lpx',right:'19lpx'})
// .backgroundColor('#80000000')
// .onClick(() => {
//
// })
// Navigator({ target: 'pages/PrivacyPage', type: NavigationType.Push }) {
// Button($r('app.string.privacy_text_title_policy'))
// .onClick(()=>{
// GlobalContext.getContext().setObject('isJumpPrivacy', true);
// })
// {
// // Text($r('app.string.privacy_text_title_policy'))
// // .fontSize($r('app.float.dialog_common_text_size'))
// // .width('50%')
// // .fontColor(Color.Red)
// // .onClick(() => {
// // GlobalContext.getContext().setObject('isJumpPrivacy', true);
// // })
// }
// .fancy(Const.MainConstant_BUTTON_MARGIN_TOP)
// }
// .params({ path: 'https://www.baidu.com', tips: '在线' } as NavigatorModel)
Text($r('app.string.privacy_text_title_policy'))
.fontSize($r('app.float.dialog_common_text_size'))
.width('40%')
.fontColor(Color.Red)
.onClick(() => {
//GlobalContext.getContext().setObject('isJumpPrivacy', false);
router.pushUrl({
url: 'pages/PrivacyPage'
}).catch((error: Error) => {
//Logger.error(CommonConstants.CUSTOM_DIALOG_TAG, 'CustomDialog pushUrl error ' + JSON.stringify(error));
});
})
Text($r('app.string.privacy_text_title_protocol'))
.fontSize($r('app.float.dialog_common_text_size'))
.width('40%')
.fontColor(Color.Red)
.onClick(() => {
//GlobalContext.getContext().setObject('isJumpPrivacy', true);
router.pushUrl({
url: 'pages/PrivacyPage'
}).catch((error: Error) => {
//Logger.error(CommonConstants.CUSTOM_DIALOG_TAG, 'CustomDialog pushUrl error ' + JSON.stringify(error));
});
})
}
Text($r('app.string.dialog_text_privacy_statement'))
.width('90%')
.fontColor($r('app.color.dialog_text_statement_color'))
.fontSize($r('app.float.dialog_common_text_size'))
Row() {
Text($r('app.string.dialog_button_disagree'))
.fancy()
.onClick(() => {
this.controller.close();
this.cancel();
})
Blank()
.backgroundColor($r('app.color.dialog_blank_background_color'))
.width($r('app.float.dialog_blank_width'))
.height($r('app.float.dialog_blank_height'))
Text($r('app.string.dialog_button_agree'))
.fancy()
.onClick(() => {
this.controller.close();
this.confirm();
})
}
.margin({ bottom: '1' })
}
.width('93%')
.borderRadius('15')
.backgroundColor(Color.White)
}
}
// Common text styles.
@Extend(Text) function fancy () {
.fontColor($r("app.color.dialog_fancy_text_color"))
.fontSize($r("app.float.dialog_fancy_text_size"))
.textAlign(TextAlign.Center)
.fontWeight(FontWeight.Medium)
.layoutWeight('1')
}
\ No newline at end of file
... ...
/**
* NewsData params info.
*/
export class NavigatorModel {
/**
* Jumping Path.
*/
path: Resource | string = '';
/**
* Prompt message.
*/
tips: Resource | string = '';
}
\ No newline at end of file
... ...
... ... @@ -7,6 +7,46 @@
{
"name": "color_F9F9F9",
"value": "#F9F9F9"
},
{
"name": "privacy_back_text",
"value": "#007DFF"
},
{
"name": "launcher_text_title_color",
"value": "#182431"
},
{
"name": "launcher_text_introduce_color",
"value": "#182431"
},
{
"name": "advertising_text_title_color",
"value": "#182431"
},
{
"name": "advertising_text_background_color",
"value": "#33000000"
},
{
"name": "home_page_text_color",
"value": "#14224D"
},
{
"name": "dialog_fancy_text_color",
"value": "#007DFF"
},
{
"name": "dialog_text_color",
"value": "#182431"
},
{
"name": "dialog_blank_background_color",
"value": "#F5F5F5"
},
{
"name": "dialog_text_statement_color",
"value": "#007DFF"
}
]
}
\ No newline at end of file
}
... ...
{
"float": [
{
"name": "float_1",
"value": "30.6"
},
{
"name": "launcher_logo_size",
"value": "119vp"
},
{
"name": "launcher_life_text_width",
"value": "105vp"
},
{
"name": "launcher_life_text_height",
"value": "35vp"
},
{
"name": "launcher_text_title_size",
"value": "26fp"
},
{
"name": "launcher_text_introduce_size",
"value": "16fp"
},
{
"name": "launcher_text_opacity",
"value": "0.6"
},
{
"name": "advertising_text_opacity",
"value": "0.4"
},
{
"name": "advertising_image_width",
"value": "54vp"
},
{
"name": "advertising_image_height",
"value": "54vp"
},
{
"name": "advertising_text_font_size",
"value": "12fp"
},
{
"name": "advertising_text_introduce_size",
"value": "16fp"
},
{
"name": "advertising_text_title_size",
"value": "26fp"
},
{
"name": "advertising_text_border_width",
"value": "1"
},
{
"name": "advertising_title_text_margin_top",
"value": "30vp"
},
{
"name": "advertising_title_text_margin_left",
"value": "260vp"
},
{
"name": "advertising_text_padding_top",
"value": "8vp"
},
{
"name": "advertising_text_padding_bottom",
"value": "8vp"
},
{
"name": "advertising_text_padding_left",
"value": "12vp"
},
{
"name": "advertising_text_padding_right",
"value": "12vp"
},
{
"name": "advertising_text_radius",
"value": "18vp"
},
{
"name": "dialog_blank_height",
"value": "32vp"
},
{
"name": "dialog_blank_width",
"value": "1vp"
},
{
"name": "dialog_common_text_size",
"value": "18fp"
},
{
"name": "dialog_text_privacy_size",
"value": "20fp"
},
{
"name": "dialog_fancy_text_size",
"value": "16fp"
},
{
"name": "dialog_text_privacy_bottom",
"value": "12vp"
},
{
"name": "dialog_text_privacy_top",
"value": "24vp"
},
{
"name": "dialog_text_declaration_bottom",
"value": "24"
},
{
"name": "dialog_text_opacity",
"value": "0.6"
},
{
"name": "privacy_text_title_size",
"value": "20fp"
},
{
"name": "privacy_back_text_size",
"value": "20fp"
},
{
"name": "privacy_text_margin_top",
"value": "10"
},
{
"name": "privacy_text_margin_bottom",
"value": "10"
},
{
"name": "privacy_bottom_text_margin",
"value": "12"
},
{
"name": "privacy_text_content_left",
"value": "24"
},
{
"name": "privacy_text_content_right",
"value": "24"
},
{
"name": "home_page_text_size",
"value": "30vp"
}
]
}
\ No newline at end of file
... ...
... ... @@ -11,6 +11,41 @@
{
"name": "EntryAbility_label",
"value": "$string:app_name"
},
{
"name": "dialog_text_title",
"value": "个人隐私保护指引"
},
{
"name": "dialog_text_subTitle",
"value": "欢迎您使用人民日报客户端!"
},
{
"name": "dialog_text_privacy_content",
"value": "为了更好地为您提供阅读新闻、发布评论等相关服务,我们会根据您使用服务的具体功能需要,收集必要的用户信息。您可通过阅读《隐私政策》和《用户协议》了解我们收集、使用、存储和共享个人信息的情况,以及对您个人隐私的保护措施。人民日报客户端深知个人信息对您的重要性,我们将以最高标准遵守法律法规要求,尽全力保护您的个人信息安全。"
},
{
"name": "dialog_text_privacy_statement",
"value": "如您同意,请点击“同意”开始接受"
},
{
"name": "dialog_button_disagree",
"value": "暂不使用"
},
{
"name": "dialog_button_agree",
"value": "同意"
},
{
"name": "privacy_text_title_policy",
"value": "《隐私政策》"
},
{
"name": "privacy_text_title_protocol",
"value": "《用户协议》"
}
]
}
\ No newline at end of file
... ...
... ... @@ -10,6 +10,9 @@
"pages/AppointmentListPage",
"pages/SettingPasswordPage",
"pages/FollowListPage",
"pages/MyHomePage"
"pages/MyHomePage",
"pages/LaunchPage",
"pages/LaunchAdvertisingPage",
"pages/PrivacyPage"
]
}
\ No newline at end of file
}
... ...
... ... @@ -11,6 +11,40 @@
{
"name": "EntryAbility_label",
"value": "$string:app_name"
},
{
"name": "dialog_text_title",
"value": "个人隐私保护指引"
},
{
"name": "dialog_text_subTitle",
"value": "欢迎您使用人民日报客户端!"
},
{
"name": "dialog_text_privacy_content",
"value": "为了更好地为您提供阅读新闻、发布评论等相关服务,我们会根据您使用服务的具体功能需要,收集必要的用户信息。您可通过阅读《隐私政策》和《用户协议》了解我们收集、使用、存储和共享个人信息的情况,以及对您个人隐私的保护措施。人民日报客户端深知个人信息对您的重要性,我们将以最高标准遵守法律法规要求,尽全力保护您的个人信息安全。"
},
{
"name": "dialog_text_privacy_statement",
"value": "如您同意,请点击“同意”开始接受"
},
{
"name": "dialog_button_disagree",
"value": "暂不使用"
},
{
"name": "dialog_button_agree",
"value": "同意"
},
{
"name": "privacy_text_title_policy",
"value": "《隐私政策》"
},
{
"name": "privacy_text_title_protocol",
"value": "《用户协议》"
}
]
}
\ No newline at end of file
... ...
... ... @@ -11,6 +11,38 @@
{
"name": "EntryAbility_label",
"value": "$string:app_name"
},
{
"name": "dialog_text_title",
"value": "个人隐私保护指引"
},
{
"name": "dialog_text_subTitle",
"value": "欢迎您使用人民日报客户端!"
},
{
"name": "dialog_text_privacy_content",
"value": "为了更好地为您提供阅读新闻、发布评论等相关服务,我们会根据您使用服务的具体功能需要,收集必要的用户信息。您可通过阅读《隐私政策》和《用户协议》了解我们收集、使用、存储和共享个人信息的情况,以及对您个人隐私的保护措施。人民日报客户端深知个人信息对您的重要性,我们将以最高标准遵守法律法规要求,尽全力保护您的个人信息安全。"
},
{
"name": "dialog_text_privacy_statement",
"value": "如您同意,请点击“同意”开始接受"
},
{
"name": "dialog_button_disagree",
"value": "暂不使用"
},
{
"name": "dialog_button_agree",
"value": "同意"
},
{
"name": "privacy_text_title_policy",
"value": "《隐私政策》"
},
{
"name": "privacy_text_title_protocol",
"value": "《用户协议》"
}
]
}
\ No newline at end of file
... ...
{
"requests" : [
]
}
\ No newline at end of file
... ...