mirror of
https://gitee.com/openharmony/applications_app_samples
synced 2024-11-26 18:20:47 +00:00
!4768 【Sample】修复FlipClock应用添加闹钟,点击“是”无反应问题
Merge pull request !4768 from 颜欢/master
This commit is contained in:
commit
9ce3200c6d
@ -15,12 +15,13 @@
|
||||
|
||||
{
|
||||
"app": {
|
||||
"compileSdkVersion": 9,
|
||||
"compatibleSdkVersion": 9,
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default"
|
||||
"signingConfig": "default",
|
||||
"compileSdkVersion": 12,
|
||||
"compatibleSdkVersion": 12,
|
||||
"runtimeOS": "OpenHarmony"
|
||||
}
|
||||
],
|
||||
"signingConfigs": []
|
||||
|
@ -13,49 +13,76 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import StorageModel from '../model/StorageModel'
|
||||
import { CustomDatePicker } from '../common/CustomDataPicker'
|
||||
import { MyDataSource } from '../common/DataSource'
|
||||
import reminderAgentManager from '@ohos.reminderAgentManager'
|
||||
import log from '../model/Logger'
|
||||
import StorageModel from '../model/StorageModel';
|
||||
import { CustomDatePicker } from '../common/CustomDataPicker';
|
||||
import { MyDataSource, ContactSource, Contact } from '../common/DataSource';
|
||||
import reminderAgentManager from '@ohos.reminderAgentManager';
|
||||
import Logger from '../model/Logger';
|
||||
import { calendarManager } from '@kit.CalendarKit';
|
||||
import { calendarMgr } from '../entryability/EntryAbility';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import deviceInfo from '@ohos.deviceInfo';
|
||||
|
||||
const TAG: string = 'AlarmClock'
|
||||
const TAG: string = 'AlarmClock';
|
||||
|
||||
@Component
|
||||
export struct AlarmClock {
|
||||
@State total: number = 0
|
||||
@State listItems: MyDataSource = new MyDataSource([])
|
||||
private datePicker: CustomDialogController = null
|
||||
private storage: StorageModel = StorageModel.getInstance()
|
||||
@State total: number = 0;
|
||||
@State listItems: ContactSource = new ContactSource([]);
|
||||
private datePicker: CustomDialogController | null = null;
|
||||
private storage: StorageModel = StorageModel.getInstance();
|
||||
private calendar : calendarManager.Calendar | undefined = undefined;
|
||||
@State isDefault: boolean = false;
|
||||
|
||||
async getTest(): Promise<void> {
|
||||
this.listItems.replaceData([])
|
||||
let amount = await this.storage.getStorageValue('amount')
|
||||
this.listItems.replaceData([]);
|
||||
let amount = await this.storage.getStorageValue('amount');
|
||||
if (amount !== 'null') {
|
||||
this.total = parseInt(amount)
|
||||
this.total = parseInt(amount.toString());
|
||||
}
|
||||
for (let i = 0; i <= this.total; i++) {
|
||||
let alarmClock = await this.storage.getStorageValue(`alarmClock${i}`)
|
||||
let alarmClock = await this.storage.getStorageValue(`alarmClock${i}`);
|
||||
Logger.info(`alarmClock` + JSON.stringify(alarmClock));
|
||||
if (alarmClock !== 'null') {
|
||||
let dataTime = JSON.parse(alarmClock).hour + ':' + JSON.parse(alarmClock).minute
|
||||
this.listItems.pushData({
|
||||
key: `alarmClock${i}`,
|
||||
value: dataTime,
|
||||
reminderId: JSON.parse(alarmClock).reminderId
|
||||
})
|
||||
let dataTime = JSON.parse(alarmClock.toString()).hour + ':' + JSON.parse(alarmClock.toString()).minute;
|
||||
Logger.info(`dataTime` + JSON.stringify(dataTime));
|
||||
this.listItems.pushData(
|
||||
new Contact(
|
||||
`alarmClock${i}`,
|
||||
dataTime,
|
||||
JSON.parse(alarmClock.toString()).reminderId
|
||||
)
|
||||
);
|
||||
Logger.info(`this.listItems` + JSON.stringify(this.listItems));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取设备类型
|
||||
async getDeviceType(){
|
||||
try {
|
||||
let deviceType = deviceInfo.deviceType;
|
||||
Logger.info(`deviceType` + JSON.stringify(deviceType));
|
||||
if (deviceType === 'default') {
|
||||
this.isDefault = true;
|
||||
} else {
|
||||
this.isDefault = false;
|
||||
}
|
||||
} catch (e) {
|
||||
Logger.info(`getSync unexpected error: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
this.getDeviceType();
|
||||
this.storage.getFromStorage().then(() => {
|
||||
this.getTest()
|
||||
this.getTest();
|
||||
})
|
||||
}
|
||||
|
||||
countChange(result): void {
|
||||
this.total = result
|
||||
this.getTest()
|
||||
countChange(result: number): void {
|
||||
this.total = result;
|
||||
this.getTest();
|
||||
}
|
||||
|
||||
build() {
|
||||
@ -73,11 +100,15 @@ export struct AlarmClock {
|
||||
.onClick(() => {
|
||||
if (this.datePicker === null) {
|
||||
this.datePicker = new CustomDialogController({
|
||||
builder: CustomDatePicker({ total: this.total, countChange: this.countChange.bind(this) }),
|
||||
builder: CustomDatePicker({
|
||||
total: this.total,
|
||||
countChange: this.countChange.bind(this),
|
||||
isDefault: this.isDefault
|
||||
}),
|
||||
autoCancel: true
|
||||
})
|
||||
}
|
||||
this.datePicker.open()
|
||||
this.datePicker.open();
|
||||
})
|
||||
}
|
||||
.height(62)
|
||||
@ -86,7 +117,7 @@ export struct AlarmClock {
|
||||
|
||||
Scroll() {
|
||||
List() {
|
||||
LazyForEach(this.listItems, (item, index) => {
|
||||
LazyForEach(this.listItems, (item: Contact, index) => {
|
||||
ListItem() {
|
||||
Row() {
|
||||
Text(item.value)
|
||||
@ -96,19 +127,34 @@ export struct AlarmClock {
|
||||
.id('deleteAlarmClock')
|
||||
.margin({ left: '20%' })
|
||||
.onClick(async () => {
|
||||
await this.storage.deleteSync(item.key)
|
||||
this.listItems['dataArray'].splice(index, 1)
|
||||
this.listItems.notifyDataReload()
|
||||
await this.storage.deleteSync(item.key);
|
||||
this.listItems.dataArray.splice(index, 1);
|
||||
this.listItems.notifyDataReload();
|
||||
Logger.info(`item.reminderId` + JSON.stringify(item.reminderId));
|
||||
try {
|
||||
reminderAgentManager.cancelReminder(item.reminderId, (err, data) => {
|
||||
if (err) {
|
||||
log.info(TAG, `callback err code: ${err.code} message: ${err.message}`)
|
||||
} else {
|
||||
log.info(TAG, `cancelReminder callback`)
|
||||
}
|
||||
})
|
||||
if (this.isDefault === true) {
|
||||
reminderAgentManager.cancelReminder(item.reminderId, (err, data) => {
|
||||
if (err) {
|
||||
Logger.info(TAG, `callback err code: ${err.code} message: ${err.message}`);
|
||||
} else {
|
||||
Logger.info(TAG, `cancelReminder callback`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
|
||||
if (err) {
|
||||
Logger.error(`Failed to get calendar. Code: {err.code}, message: {err.message}`);
|
||||
} else {
|
||||
Logger.info(`Succeeded in getting calendar, data -> {JSON.stringify(data)}`);
|
||||
this.calendar = data;
|
||||
await this.calendar.deleteEvent(item.reminderId).then(() => {
|
||||
Logger.info(`Succeeded in deleting event`);
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
log.info(TAG, `cancelReminder code: ${error.code} message: ${error.message}`)
|
||||
Logger.info(TAG, `cancelReminder code: ${error.code} message: ${error.message}`);
|
||||
}
|
||||
})
|
||||
.width('20%')
|
||||
@ -122,7 +168,7 @@ export struct AlarmClock {
|
||||
.borderRadius(24)
|
||||
.margin({ bottom: 5 })
|
||||
.backgroundColor($r('app.color.divider_bg'))
|
||||
}, (item, index) => {
|
||||
}, (item: Contact, index) => {
|
||||
return JSON.stringify(item) + index
|
||||
})
|
||||
}
|
||||
|
@ -13,132 +13,133 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import display from '@ohos.display'
|
||||
import mediaquery from '@ohos.mediaquery'
|
||||
import display from '@ohos.display';
|
||||
import mediaQuery from '@ohos.mediaquery';
|
||||
|
||||
let passSec: number = 0
|
||||
let pickerH: number = 0
|
||||
let pickerM: number = 0
|
||||
let pickerS: number = 0
|
||||
let countInSec: number = 0
|
||||
let passSec: number = 0;
|
||||
let pickerH: number = 0;
|
||||
let pickerM: number = 0;
|
||||
let pickerS: number = 0;
|
||||
let countInSec: number = 0;
|
||||
|
||||
@Component
|
||||
export struct CountDown {
|
||||
@State displayWidth: number = 0
|
||||
@State timer: number = 0
|
||||
@State displayHeight: number = 0
|
||||
@State centerY: number = 0
|
||||
@State rotates: number = 0
|
||||
@State hoursTime: number = 0
|
||||
@State clockWidth: number = 0
|
||||
@State densityDPI: number = 0
|
||||
@State minuteTime: number = 0
|
||||
@State secondTime: number = 0
|
||||
@State clockHeight: number = 0
|
||||
@State progressVal: number = 0
|
||||
@State densityPixels: number = 0
|
||||
@State scaledDensity: number = 0
|
||||
@State clockDialWidth: number = 0
|
||||
@State clockDialHeight: number = 0
|
||||
@State isRunning: boolean = false
|
||||
@State isPausing: boolean = false
|
||||
@State startImg: Resource = $r('app.media.start')
|
||||
@State resetImg: Resource = $r('app.media.resetccc')
|
||||
private settings: RenderingContextSettings = new RenderingContextSettings(true)
|
||||
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
|
||||
@State lineLength: number = undefined
|
||||
@State pickerHeight: number = undefined
|
||||
@State pointerHeight: number = undefined
|
||||
scroller: Scroller = new Scroller()
|
||||
listener = mediaquery.matchMediaSync('(orientation:landscape)')
|
||||
@State displayWidth: number = 0;
|
||||
@State timer: number = 0;
|
||||
@State displayHeight: number = 0;
|
||||
@State centerY: number = 0;
|
||||
@State rotates: number = 0;
|
||||
@State hoursTime: number = 0;
|
||||
@State clockWidth: number = 0;
|
||||
@State densityDPI: number = 0;
|
||||
@State minuteTime: number = 0;
|
||||
@State secondTime: number = 0;
|
||||
@State clockHeight: number = 0;
|
||||
@State progressVal: number = 0;
|
||||
@State densityPixels: number = 0;
|
||||
@State scaledDensity: number = 0;
|
||||
@State clockDialWidth: number = 0;
|
||||
@State clockDialHeight: number = 0;
|
||||
@State isRunning: boolean = false;
|
||||
@State isPausing: boolean = false;
|
||||
@State startImg: Resource = $r('app.media.start');
|
||||
@State resetImg: Resource = $r('app.media.resetccc');
|
||||
private settings: RenderingContextSettings = new RenderingContextSettings(true);
|
||||
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
|
||||
@State lineLength: number | undefined = undefined;
|
||||
@State pickerHeight: number | undefined = undefined;
|
||||
@State pointerHeight: number | undefined = undefined;
|
||||
scroller: Scroller = new Scroller();
|
||||
listener = mediaQuery.matchMediaSync('(orientation:landscape)');
|
||||
private portraitFunc: () => void = () => {};
|
||||
|
||||
onPortrait(mediaQueryResult) {
|
||||
onPortrait(mediaQueryResult: mediaQuery.MediaQueryResult) {
|
||||
if (mediaQueryResult.matches) {
|
||||
this.pointerHeight = 310
|
||||
this.lineLength = 345
|
||||
this.clockDialHeight = 212
|
||||
this.clockDialWidth = 212
|
||||
this.clockHeight = 188
|
||||
this.clockWidth = 188
|
||||
this.centerY = 99
|
||||
this.pointerHeight = 310;
|
||||
this.lineLength = 345;
|
||||
this.clockDialHeight = 212;
|
||||
this.clockDialWidth = 212;
|
||||
this.clockHeight = 188;
|
||||
this.clockWidth = 188;
|
||||
this.centerY = 99;
|
||||
} else {
|
||||
this.clockDialHeight = 280
|
||||
this.clockDialWidth = 280
|
||||
this.clockHeight = 250
|
||||
this.clockWidth = 250
|
||||
this.pickerHeight = 128
|
||||
this.pointerHeight = 375
|
||||
this.lineLength = 410
|
||||
this.centerY = 125
|
||||
this.clockDialHeight = 280;
|
||||
this.clockDialWidth = 280;
|
||||
this.clockHeight = 250;
|
||||
this.clockWidth = 250;
|
||||
this.pickerHeight = 128;
|
||||
this.pointerHeight = 375;
|
||||
this.lineLength = 410;
|
||||
this.centerY = 125;
|
||||
}
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
let portraitFunc = this.onPortrait.bind(this)
|
||||
this.listener.on('change', portraitFunc)
|
||||
let displayObj = display.getDefaultDisplaySync()
|
||||
this.displayWidth = displayObj.width
|
||||
this.displayHeight = displayObj.height
|
||||
this.densityDPI = undefined
|
||||
this.densityPixels = displayObj.densityPixels
|
||||
this.scaledDensity = displayObj.scaledDensity
|
||||
this.portraitFunc = this.onPortrait.bind(this);
|
||||
this.listener.on('change', this.portraitFunc);
|
||||
let displayObj = display.getDefaultDisplaySync();
|
||||
this.displayWidth = displayObj.width;
|
||||
this.displayHeight = displayObj.height;
|
||||
this.densityDPI = 0;
|
||||
this.densityPixels = displayObj.densityPixels;
|
||||
this.scaledDensity = displayObj.scaledDensity;
|
||||
}
|
||||
|
||||
timerCountDown() {
|
||||
this.secondTime--
|
||||
this.secondTime--;
|
||||
if (this.secondTime < 0) {
|
||||
this.minuteTime--
|
||||
this.secondTime = 59
|
||||
this.minuteTime--;
|
||||
this.secondTime = 59;
|
||||
}
|
||||
if (this.minuteTime < 0) {
|
||||
this.minuteTime = 59
|
||||
this.hoursTime--
|
||||
this.minuteTime = 59;
|
||||
this.hoursTime--;
|
||||
}
|
||||
if (this.hoursTime < 0) {
|
||||
this.reset()
|
||||
return
|
||||
this.reset();
|
||||
return;
|
||||
}
|
||||
passSec++
|
||||
this.progressVal = 100 - passSec * 100 / countInSec
|
||||
this.rotates = passSec * 360 / countInSec
|
||||
this.progressVal = 100 - passSec * 100 / countInSec;
|
||||
this.rotates = passSec * 360 / countInSec;
|
||||
}
|
||||
|
||||
start() {
|
||||
if (!this.isPausing) {
|
||||
this.hoursTime = pickerH
|
||||
this.minuteTime = pickerM
|
||||
this.secondTime = pickerS
|
||||
this.hoursTime = pickerH;
|
||||
this.minuteTime = pickerM;
|
||||
this.secondTime = pickerS;
|
||||
}
|
||||
countInSec = pickerH * 3600 + pickerM * 60 + pickerS
|
||||
this.isRunning = true
|
||||
this.isPausing = false
|
||||
this.startImg = $r('app.media.pause')
|
||||
this.resetImg = $r('app.media.reset')
|
||||
this.timer = setInterval(this.timerCountDown.bind(this), 1000)
|
||||
countInSec = pickerH * 3600 + pickerM * 60 + pickerS;
|
||||
this.isRunning = true;
|
||||
this.isPausing = false;
|
||||
this.startImg = $r('app.media.pause');
|
||||
this.resetImg = $r('app.media.reset');
|
||||
this.timer = setInterval(this.timerCountDown.bind(this), 1000);
|
||||
}
|
||||
|
||||
pause() {
|
||||
clearInterval(this.timer)
|
||||
this.isRunning = true
|
||||
this.isPausing = true
|
||||
this.startImg = $r('app.media.start')
|
||||
clearInterval(this.timer);
|
||||
this.isRunning = true;
|
||||
this.isPausing = true;
|
||||
this.startImg = $r('app.media.start');
|
||||
}
|
||||
|
||||
reset() {
|
||||
clearInterval(this.timer)
|
||||
this.isRunning = false
|
||||
this.isPausing = false
|
||||
this.progressVal = 0
|
||||
this.rotates = 0
|
||||
passSec = 0
|
||||
this.hoursTime = 0
|
||||
this.minuteTime = 0
|
||||
this.secondTime = 0
|
||||
pickerH = 0
|
||||
pickerM = 0
|
||||
pickerS = 0
|
||||
this.startImg = $r('app.media.start')
|
||||
this.resetImg = $r('app.media.resetccc')
|
||||
clearInterval(this.timer);
|
||||
this.isRunning = false;
|
||||
this.isPausing = false;
|
||||
this.progressVal = 0;
|
||||
this.rotates = 0;
|
||||
passSec = 0;
|
||||
this.hoursTime = 0;
|
||||
this.minuteTime = 0;
|
||||
this.secondTime = 0;
|
||||
pickerH = 0;
|
||||
pickerM = 0;
|
||||
pickerS = 0;
|
||||
this.startImg = $r('app.media.start');
|
||||
this.resetImg = $r('app.media.resetccc');
|
||||
}
|
||||
|
||||
build() {
|
||||
@ -155,14 +156,14 @@ export struct CountDown {
|
||||
|
||||
Canvas(this.context)
|
||||
.onReady(() => {
|
||||
this.context.lineWidth = 8
|
||||
this.context.strokeStyle = '#f2400a'
|
||||
this.context.beginPath()
|
||||
this.context.moveTo(15, 0)
|
||||
this.context.arc(15, this.pointerHeight, 10, 3.14 * 1.5, 3.14 * 0.5)
|
||||
this.context.lineTo(15, this.lineLength)
|
||||
this.context.arc(15, this.pointerHeight, 10, 3.14 * 0.5, 3.14 * 1.5)
|
||||
this.context.stroke()
|
||||
this.context.lineWidth = 8;
|
||||
this.context.strokeStyle = '#f2400a';
|
||||
this.context.beginPath();
|
||||
this.context.moveTo(15, 0);
|
||||
this.context.arc(15, this.pointerHeight, 10, 3.14 * 1.5, 3.14 * 0.5);
|
||||
this.context.lineTo(15, this.lineLength);
|
||||
this.context.arc(15, this.pointerHeight, 10, 3.14 * 0.5, 3.14 * 1.5);
|
||||
this.context.stroke();
|
||||
})
|
||||
.id('countdownCanvas')
|
||||
.width(10)
|
||||
@ -221,12 +222,12 @@ export struct CountDown {
|
||||
.height(48)
|
||||
.onClick(() => {
|
||||
if (pickerH + pickerM + pickerS === 0) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
if (!this.isRunning || this.isPausing) {
|
||||
this.start()
|
||||
this.start();
|
||||
} else {
|
||||
this.pause()
|
||||
this.pause();
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -239,8 +240,8 @@ export struct CountDown {
|
||||
|
||||
@Component
|
||||
struct Time {
|
||||
pickerArrayGen(num) {
|
||||
return Array.from({ length: num }, (_, i) => (i < 10) ? ('0' + i) : ('' + i))
|
||||
pickerArrayGen(num: number) {
|
||||
return Array.from({ length: num }, (_: string, i) => (i < 10) ? ('0' + i) : ('' + i));
|
||||
}
|
||||
|
||||
build() {
|
||||
@ -249,8 +250,8 @@ struct Time {
|
||||
TextPicker({ range: this.pickerArrayGen(24) })
|
||||
.width(60)
|
||||
.height('100%')
|
||||
.onChange((value: string, index: number) => {
|
||||
pickerH = index
|
||||
.onChange((value: string | string[], index: number | number[]) => {
|
||||
pickerH = index as number;
|
||||
})
|
||||
|
||||
Text(':')
|
||||
@ -263,8 +264,8 @@ struct Time {
|
||||
.id('minute')
|
||||
.width(60)
|
||||
.height('100%')
|
||||
.onChange((value: string, index: number) => {
|
||||
pickerM = index
|
||||
.onChange((value: string | string[], index: number | number[]) => {
|
||||
pickerM = index as number;
|
||||
})
|
||||
|
||||
Text(':')
|
||||
@ -276,8 +277,8 @@ struct Time {
|
||||
TextPicker({ range: this.pickerArrayGen(60) })
|
||||
.width(60)
|
||||
.height('100%')
|
||||
.onChange((value: string, index: number) => {
|
||||
pickerS = index
|
||||
.onChange((value: string | string[], index: number | number[]) => {
|
||||
pickerS = index as number;
|
||||
})
|
||||
}
|
||||
.height(128)
|
||||
@ -307,9 +308,9 @@ struct Time {
|
||||
}
|
||||
}
|
||||
|
||||
function FormatTime(num) {
|
||||
function FormatTime(num: number) {
|
||||
if (num > 99 || num < 0) {
|
||||
return '**'
|
||||
return '**';
|
||||
}
|
||||
return (num < 10) ? ('0' + num).toString() : num.toString()
|
||||
return (num < 10) ? ('0' + num).toString() : num.toString();
|
||||
}
|
@ -13,26 +13,71 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import StorageModel from '../model/StorageModel'
|
||||
import reminderAgentManager from '@ohos.reminderAgentManager'
|
||||
import StorageModel from '../model/StorageModel';
|
||||
import reminderAgentManager from '@ohos.reminderAgentManager';
|
||||
import Logger from '../model/Logger';
|
||||
import { calendarManager } from '@kit.CalendarKit';
|
||||
import { calendarMgr } from '../entryability/EntryAbility';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
|
||||
interface DateTime {
|
||||
hour: string,
|
||||
minute: string,
|
||||
reminderId: number,
|
||||
}
|
||||
|
||||
@CustomDialog
|
||||
export struct CustomDatePicker {
|
||||
@State hour: number = 0
|
||||
@State minute: number = 0
|
||||
@State reminderId: number = 0
|
||||
@State hourTest: string = ''
|
||||
@State minuteTest: string = ''
|
||||
private total: number
|
||||
private selectedTime: Date = new Date()
|
||||
private controller: CustomDialogController
|
||||
private countChange: (result: number) => void
|
||||
@State year: number = 0;
|
||||
@State month: number = 0;
|
||||
@State day: number = 0;
|
||||
@State hour: number = 0;
|
||||
@State minute: number = 0;
|
||||
@State seconds: number = 0;
|
||||
@State reminderId: number = 0;
|
||||
@State hourTest: string = '';
|
||||
@State minuteTest: string = '';
|
||||
@State secondTest: string = '';
|
||||
private total: number = 0;
|
||||
private selectedTime: Date = new Date();
|
||||
private controller: CustomDialogController;
|
||||
private countChange: (result: number) => void = () => {};
|
||||
private calendar : calendarManager.Calendar | undefined = undefined;
|
||||
@Link isDefault: boolean;
|
||||
|
||||
aboutToAppear() {
|
||||
this.hour = this.selectedTime.getHours()
|
||||
this.minute = this.selectedTime.getMinutes()
|
||||
this.hourTest = (this.hour > 9 ? '' : '0') + this.hour
|
||||
this.minuteTest = (this.minute > 9 ? '' : '0') + this.minute
|
||||
this.year = this.selectedTime.getFullYear();
|
||||
this.month = this.selectedTime.getMonth() + 1;
|
||||
this.day = this.selectedTime.getDate();
|
||||
this.hour = this.selectedTime.getHours();
|
||||
this.minute = this.selectedTime.getMinutes();
|
||||
this.seconds = this.selectedTime.getSeconds();
|
||||
this.hourTest = (this.hour > 9 ? '' : '0') + this.hour;
|
||||
this.minuteTest = (this.minute > 9 ? '' : '0') + this.minute;
|
||||
this.secondTest = (this.seconds > 9 ? '' : '0') + this.seconds;
|
||||
if (this.isDefault === false) {
|
||||
this.setCalendarReminder();
|
||||
}
|
||||
}
|
||||
|
||||
setCalendarReminder(){
|
||||
let config: calendarManager.CalendarConfig = {
|
||||
enableReminder: true,
|
||||
color: '#aabbcc',
|
||||
};
|
||||
calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
|
||||
if (err) {
|
||||
Logger.error(`Failed to get calendar. Code: {err.code}, message: {err.message}`);
|
||||
} else {
|
||||
Logger.info(`Succeeded in getting calendar, data ->` + JSON.stringify(data));
|
||||
this.calendar = data;
|
||||
await this.calendar.setConfig(config).then(() => {
|
||||
Logger.info(`Succeeded in setting config, config -> ` + JSON.stringify(config));
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.error(`Failed to set config. Code: {err.code}, message: {err.message}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
build() {
|
||||
@ -56,10 +101,10 @@ export struct CustomDatePicker {
|
||||
.id('timePicker')
|
||||
.useMilitaryTime(true)
|
||||
.onChange((date) => {
|
||||
this.hour = date.hour
|
||||
this.minute = date.minute
|
||||
this.hourTest = (date.hour > 9 ? '' : '0') + date.hour
|
||||
this.minuteTest = (date.minute > 9 ? '' : '0') + date.minute
|
||||
this.hour = date.hour;
|
||||
this.minute = date.minute;
|
||||
this.hourTest = (date.hour > 9 ? '' : '0') + date.hour;
|
||||
this.minuteTest = (date.minute > 9 ? '' : '0') + date.minute;
|
||||
})
|
||||
}
|
||||
.height('30%')
|
||||
@ -72,24 +117,50 @@ export struct CustomDatePicker {
|
||||
.layoutWeight(1)
|
||||
.backgroundColor(Color.White)
|
||||
.onClick(async () => {
|
||||
let reminderRequest: reminderAgentManager.ReminderRequestAlarm = {
|
||||
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_ALARM,
|
||||
hour: this.hour,
|
||||
minute: this.minute,
|
||||
title: getContext(this).resourceManager.getStringSync($r('app.string.alarmClock')),
|
||||
maxScreenWantAgent: {
|
||||
pkgName: 'ohos.samples.flipclock',
|
||||
abilityName: 'ohos.samples.flipclock.EntryAbility'
|
||||
},
|
||||
ringDuration: 5
|
||||
if (this.isDefault === true) {
|
||||
let reminderRequest: reminderAgentManager.ReminderRequestAlarm = {
|
||||
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_ALARM,
|
||||
hour: this.hour,
|
||||
minute: this.minute,
|
||||
title: getContext(this).resourceManager.getStringSync($r('app.string.alarmClock')),
|
||||
maxScreenWantAgent: {
|
||||
pkgName: 'ohos.samples.flipclock',
|
||||
abilityName: 'ohos.samples.flipclock.EntryAbility'
|
||||
},
|
||||
ringDuration: 5
|
||||
}
|
||||
this.reminderId = await reminderAgentManager.publishReminder(reminderRequest);
|
||||
} else {
|
||||
let date = this.year + '-' + this.month + '-' + this.day;
|
||||
let time = this.hourTest + ':' + this.minuteTest + ':' + this.secondTest;
|
||||
let selectDate = date + ' ' + time;
|
||||
Logger.info(`selectDate: ${selectDate}`);
|
||||
let event: calendarManager.Event = {
|
||||
type: calendarManager.EventType.NORMAL,
|
||||
startTime: Date.parse(selectDate),
|
||||
endTime: Date.parse(selectDate) + 60 * 60 * 1000,
|
||||
reminderTime: [0],
|
||||
title: getContext(this).resourceManager.getStringSync($r('app.string.alarmClock'))
|
||||
};
|
||||
await this.calendar!.addEvent(event).then((data: number) => {
|
||||
Logger.info(`Succeeded in adding event, id -> {data}`);
|
||||
this.reminderId = data;
|
||||
Logger.info(`this.reminderId is` + JSON.stringify(this.reminderId));
|
||||
}).catch((err: BusinessError) => {
|
||||
Logger.error(`Failed to add event` + JSON.stringify(err));
|
||||
});
|
||||
}
|
||||
this.reminderId = await reminderAgentManager.publishReminder(reminderRequest)
|
||||
let dateTime = { hour: this.hourTest, minute: this.minuteTest, reminderId: this.reminderId }
|
||||
StorageModel.getInstance().putStorageValue(`alarmClock${this.total}`, dateTime)
|
||||
this.total += 1
|
||||
StorageModel.getInstance().putStorageValue('amount', this.total)
|
||||
this.controller.close()
|
||||
this.countChange(this.total)
|
||||
let dateTime: DateTime = {
|
||||
hour: this.hourTest,
|
||||
minute: this.minuteTest,
|
||||
reminderId: this.reminderId
|
||||
};
|
||||
Logger.info(`dateTime: ` + dateTime);
|
||||
StorageModel.getInstance().putStorageValue(`alarmClock${this.total}`, dateTime);
|
||||
this.total += 1;
|
||||
StorageModel.getInstance().putTotalStorageValue('amount', this.total);
|
||||
this.controller.close();
|
||||
this.countChange(this.total);
|
||||
})
|
||||
|
||||
Button($r('app.string.no'))
|
||||
@ -98,7 +169,7 @@ export struct CustomDatePicker {
|
||||
.backgroundColor(Color.White)
|
||||
.layoutWeight(1)
|
||||
.onClick(() => {
|
||||
this.controller.close()
|
||||
this.controller.close();
|
||||
})
|
||||
}
|
||||
.margin({ top: 10, bottom: 20 })
|
||||
|
@ -14,56 +14,56 @@
|
||||
*/
|
||||
|
||||
class BasicDataSource implements IDataSource {
|
||||
private listeners: DataChangeListener[] = []
|
||||
private listeners: DataChangeListener[] = [];
|
||||
|
||||
public totalCount(): number {
|
||||
return 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
public getData(index: number): any {
|
||||
return undefined
|
||||
public getData(index: number): void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
registerDataChangeListener(listener: DataChangeListener): void {
|
||||
if (this.listeners.indexOf(listener) < 0) {
|
||||
this.listeners.push(listener)
|
||||
this.listeners.push(listener);
|
||||
}
|
||||
}
|
||||
|
||||
unregisterDataChangeListener(listener: DataChangeListener): void {
|
||||
const pos = this.listeners.indexOf(listener)
|
||||
const pos = this.listeners.indexOf(listener);
|
||||
if (pos >= 0) {
|
||||
this.listeners.splice(pos, 1)
|
||||
this.listeners.splice(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
notifyDataReload(): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataReloaded()
|
||||
listener.onDataReloaded();
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataAdd(index: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataAdd(index)
|
||||
listener.onDataAdd(index);
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataChange(index: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataChange(index)
|
||||
listener.onDataChange(index);
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataDelete(index: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataDelete(index)
|
||||
listener.onDataDelete(index);
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataMove(from: number, to: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataMove(from, to)
|
||||
listener.onDataMove(from, to);
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -72,37 +72,88 @@ export class TabType {
|
||||
icon: Resource;
|
||||
icon_after: Resource;
|
||||
text: Resource;
|
||||
num: number
|
||||
num: number;
|
||||
|
||||
constructor(icon: Resource, icon_after: Resource, text: Resource, num: number) {
|
||||
this.icon = icon;
|
||||
this.icon_after = icon_after;
|
||||
this.text = text;
|
||||
this.num = num;
|
||||
}
|
||||
}
|
||||
|
||||
export class MyDataSource extends BasicDataSource {
|
||||
private dataArray: TabType[] = []
|
||||
private dataArray: TabType[] = [];
|
||||
|
||||
constructor(data: TabType[]) {
|
||||
super()
|
||||
this.dataArray = data
|
||||
this.dataArray = data;
|
||||
}
|
||||
|
||||
public totalCount(): number {
|
||||
return this.dataArray.length
|
||||
return this.dataArray.length;
|
||||
}
|
||||
|
||||
public getData(index: number): any {
|
||||
return this.dataArray[index]
|
||||
public getData(index: number): TabType {
|
||||
return this.dataArray[index];
|
||||
}
|
||||
|
||||
public deleteData(index: number): void {
|
||||
this.dataArray.splice(index, 1)
|
||||
this.notifyDataAdd(index)
|
||||
this.dataArray.splice(index, 1);
|
||||
this.notifyDataAdd(index);
|
||||
}
|
||||
|
||||
public pushData(index: any): void {
|
||||
this.dataArray.push(index)
|
||||
this.notifyDataAdd(this.dataArray.length - 1)
|
||||
public pushData(data: TabType): void {
|
||||
this.dataArray.push(data);
|
||||
this.notifyDataAdd(this.dataArray.length - 1);
|
||||
}
|
||||
|
||||
public replaceData(result: TabType[]): void {
|
||||
this.dataArray = result
|
||||
this.notifyDataReload()
|
||||
this.dataArray = result;
|
||||
this.notifyDataReload();
|
||||
}
|
||||
}
|
||||
|
||||
export class Contact {
|
||||
key: string;
|
||||
value: string;
|
||||
reminderId: number;
|
||||
|
||||
constructor(key: string, value: string, reminderId: number) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.reminderId = reminderId;
|
||||
}
|
||||
}
|
||||
|
||||
export class ContactSource extends BasicDataSource {
|
||||
public dataArray: Contact[] = [];
|
||||
|
||||
constructor(data: Array<Contact>) {
|
||||
super()
|
||||
this.dataArray = data;
|
||||
}
|
||||
|
||||
public totalCount(): number {
|
||||
return this.dataArray.length;
|
||||
}
|
||||
|
||||
public getData(index: number): Contact {
|
||||
return this.dataArray[index];
|
||||
}
|
||||
|
||||
public deleteData(index: number): void {
|
||||
this.dataArray.splice(index, 1);
|
||||
this.notifyDataAdd(index);
|
||||
}
|
||||
|
||||
public pushData(data: Contact): void {
|
||||
this.dataArray.push(data);
|
||||
this.notifyDataAdd(this.dataArray.length - 1);
|
||||
}
|
||||
|
||||
public replaceData(result: Contact[]): void {
|
||||
this.dataArray = result;
|
||||
this.notifyDataReload();
|
||||
}
|
||||
}
|
||||
|
@ -15,35 +15,35 @@
|
||||
|
||||
@Component
|
||||
export struct FlipClock {
|
||||
@State timeOne: Array<number> = []
|
||||
@State timeTwo: Array<number> = []
|
||||
@State timeThree: Array<number> = []
|
||||
@State timeFour: Array<number> = []
|
||||
@State angleOne: Array<number> = [0, 0, 0, 0, 0, 0]
|
||||
@State angleTwo: Array<number> = [-90, -90, -90, -90, -90, -90]
|
||||
@State timeOne: Array<number> = [];
|
||||
@State timeTwo: Array<number> = [];
|
||||
@State timeThree: Array<number> = [];
|
||||
@State timeFour: Array<number> = [];
|
||||
@State angleOne: Array<number> = [0, 0, 0, 0, 0, 0];
|
||||
@State angleTwo: Array<number> = [-90, -90, -90, -90, -90, -90];
|
||||
|
||||
aboutToAppear() {
|
||||
const arr = this.changeTime()
|
||||
this.timeOne = [...arr]
|
||||
this.timeTwo = [...arr]
|
||||
this.timeThree = [...arr]
|
||||
this.timeFour = [...arr]
|
||||
const arr = this.changeTime();
|
||||
this.timeOne = [...arr];
|
||||
this.timeTwo = [...arr];
|
||||
this.timeThree = [...arr];
|
||||
this.timeFour = [...arr];
|
||||
setInterval(() => {
|
||||
const time = new Date()
|
||||
const time = new Date();
|
||||
if (this.timeOne[5] != time.getSeconds() % 10) {
|
||||
const arr = this.changeTime()
|
||||
const arr = this.changeTime();
|
||||
for (let i = 0;i < 6; i++) {
|
||||
if (arr[i] != this.timeFour[i]) {
|
||||
this.timeFour[i] = arr[i]
|
||||
this.animationOne(i)
|
||||
this.timeFour[i] = arr[i];
|
||||
this.animationOne(i);
|
||||
setTimeout(() => {
|
||||
this.timeTwo[i] = arr[i]
|
||||
this.timeTwo[i] = arr[i];
|
||||
}, 100)
|
||||
setTimeout(() => {
|
||||
this.timeThree[i] = arr[i]
|
||||
this.timeThree[i] = arr[i];
|
||||
}, 150)
|
||||
setTimeout(() => {
|
||||
this.timeOne[i] = arr[i]
|
||||
this.timeOne[i] = arr[i];
|
||||
}, 240)
|
||||
}
|
||||
}
|
||||
@ -53,41 +53,41 @@ export struct FlipClock {
|
||||
|
||||
//修改时间
|
||||
changeTime(): Array<number> {
|
||||
const time = new Date()
|
||||
const hour = time.getHours()
|
||||
const hourOne = Math.floor(hour / 10)
|
||||
const hourTwo = hour % 10
|
||||
const minutesOne = Math.floor(time.getMinutes() / 10)
|
||||
const minutesTwo = time.getMinutes() % 10
|
||||
const secondsOne = Math.floor(time.getSeconds() / 10)
|
||||
const secondsTwo = time.getSeconds() % 10
|
||||
return [hourOne, hourTwo, minutesOne, minutesTwo, secondsOne, secondsTwo]
|
||||
const time = new Date();
|
||||
const hour = time.getHours();
|
||||
const hourOne = Math.floor(hour / 10);
|
||||
const hourTwo = hour % 10;
|
||||
const minutesOne = Math.floor(time.getMinutes() / 10);
|
||||
const minutesTwo = time.getMinutes() % 10;
|
||||
const secondsOne = Math.floor(time.getSeconds() / 10);
|
||||
const secondsTwo = time.getSeconds() % 10;
|
||||
return [hourOne, hourTwo, minutesOne, minutesTwo, secondsOne, secondsTwo];
|
||||
}
|
||||
|
||||
animationOne(i): void {
|
||||
animationOne(i: number): void {
|
||||
animateTo({
|
||||
duration: 250,
|
||||
delay: 0,
|
||||
iterations: 1,
|
||||
onFinish: () => {
|
||||
this.animationTwo(i)
|
||||
this.angleOne[i] = 0
|
||||
this.animationTwo(i);
|
||||
this.angleOne[i] = 0;
|
||||
}
|
||||
}, () => this.angleOne[i] = 90)
|
||||
}
|
||||
|
||||
animationTwo(i): void {
|
||||
animationTwo(i: number): void {
|
||||
animateTo({
|
||||
duration: 250,
|
||||
delay: 0,
|
||||
iterations: 1,
|
||||
onFinish: () => {
|
||||
this.angleTwo[i] = -90
|
||||
this.angleTwo[i] = -90;
|
||||
}
|
||||
}, () => this.angleTwo[i] = 0)
|
||||
}
|
||||
|
||||
@Builder box(num) {
|
||||
@Builder box(num: number) {
|
||||
Column() {
|
||||
Divider()
|
||||
.zIndex(5)
|
||||
|
@ -18,7 +18,7 @@ import window from '@ohos.window';
|
||||
|
||||
@Component
|
||||
export struct LockSwitch {
|
||||
private isLock: boolean = false
|
||||
private isLock: boolean = false;
|
||||
@Link isComTime: boolean;
|
||||
private isKeepScreenOn: boolean = false;
|
||||
|
||||
@ -29,7 +29,7 @@ export struct LockSwitch {
|
||||
Toggle({ type: ToggleType.Switch, isOn: this.isLock })
|
||||
.id('screenLight')
|
||||
.onChange(() => {
|
||||
this.isLock = !(this.isLock)
|
||||
this.isLock = !(this.isLock);
|
||||
let windowClass: window.Window | undefined = AppStorage.Get('windowClass');
|
||||
if (this.isLock === true) {
|
||||
// 打开常亮
|
||||
|
@ -13,18 +13,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import window from '@ohos.window'
|
||||
import brightness from '@ohos.brightness'
|
||||
import { LockSwitch } from '../common/LockSwitch'
|
||||
import Logger from '../model/Logger'
|
||||
import window from '@ohos.window';
|
||||
import brightness from '@ohos.brightness';
|
||||
import { LockSwitch } from '../common/LockSwitch';
|
||||
import Logger from '../model/Logger';
|
||||
|
||||
@Component
|
||||
export struct Setting {
|
||||
@State isFullScreen: boolean = false
|
||||
@State inSetValue: number = 40
|
||||
@State isFullScreen: boolean = false;
|
||||
@State inSetValue: number = 40;
|
||||
|
||||
setBrightness(): void {
|
||||
brightness.setValue(this.inSetValue)
|
||||
brightness.setValue(this.inSetValue);
|
||||
}
|
||||
|
||||
build() {
|
||||
@ -41,13 +41,13 @@ export struct Setting {
|
||||
Toggle({ type: ToggleType.Switch, isOn: this.isFullScreen })
|
||||
.switchPointColor(0xe5ffffff)
|
||||
.onChange(async () => {
|
||||
this.isFullScreen = !this.isFullScreen
|
||||
this.isFullScreen = !this.isFullScreen;
|
||||
try {
|
||||
const win = await window.getLastWindow(getContext(this))
|
||||
let names = this.isFullScreen ? [] : ['status', 'navigation']
|
||||
await win.setWindowSystemBarEnable(names as Array<'status' | 'navigation'>)
|
||||
const win = await window.getLastWindow(getContext(this));
|
||||
let names = this.isFullScreen ? [] : ['status', 'navigation'];
|
||||
await win.setWindowSystemBarEnable(names as Array<'status' | 'navigation'>);
|
||||
} catch (err) {
|
||||
Logger.info(`setFullScreen fail, code = ${err.code}`)
|
||||
Logger.info(`setFullScreen fail, code = ${err.code}`);
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -95,8 +95,8 @@ export struct Setting {
|
||||
.trackColor(Color.Black)
|
||||
.selectedColor(0xCCCCCC)
|
||||
.onChange((value: number, mode: SliderChangeMode) => {
|
||||
this.inSetValue = value
|
||||
this.setBrightness()
|
||||
this.inSetValue = value;
|
||||
this.setBrightness();
|
||||
})
|
||||
}
|
||||
.width('98%')
|
||||
@ -116,7 +116,7 @@ export struct Setting {
|
||||
|
||||
@Component
|
||||
struct Lock {
|
||||
@State isComTime: boolean = true
|
||||
@State isComTime: boolean = true;
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
|
@ -13,10 +13,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import Logger from '../model/Logger'
|
||||
import Notification from '@ohos.notificationManager'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import Window from '@ohos.window';
|
||||
import Logger from '../model/Logger';
|
||||
import Notification from '@ohos.notificationManager';
|
||||
import { abilityAccessCtrl, common, PermissionRequestResult, Permissions } from '@kit.AbilityKit';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { calendarManager } from '@kit.CalendarKit';
|
||||
|
||||
export let calendarMgr: calendarManager.CalendarManager | null = null;
|
||||
export let mContext: common.UIAbilityContext | null = null;
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onWindowStageCreate(windowStage: Window.WindowStage) {
|
||||
@ -27,11 +33,22 @@ export default class EntryAbility extends UIAbility {
|
||||
});
|
||||
windowStage.loadContent('pages/Index', (err, data) => {
|
||||
if (err.code) {
|
||||
Logger.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`)
|
||||
return
|
||||
Logger.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`);
|
||||
return;
|
||||
}
|
||||
Logger.info(`loadContent success`)
|
||||
Logger.info(`loadContent success`);
|
||||
});
|
||||
|
||||
mContext = this.context;
|
||||
const permissions: Permissions[] = ['ohos.permission.READ_CALENDAR', 'ohos.permission.WRITE_CALENDAR'];
|
||||
let atManager = abilityAccessCtrl.createAtManager();
|
||||
atManager.requestPermissionsFromUser(mContext, permissions).then((result: PermissionRequestResult) => {
|
||||
console.log(`get Permission success, result: {JSON.stringify(result)}`);
|
||||
calendarMgr = calendarManager.getCalendarManager(mContext);
|
||||
}).catch((error: BusinessError) => {
|
||||
console.error(`get Permission error. Code: {error.code}, message: {error.message}`);
|
||||
})
|
||||
|
||||
let windowClass: Window.Window | undefined = undefined;
|
||||
try {
|
||||
Window.getLastWindow(this.context, (err, data) => {
|
||||
|
@ -13,31 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TabType } from '../common/DataSource'
|
||||
import { TabType } from '../common/DataSource';
|
||||
|
||||
export const tabArray: Array<TabType> = [
|
||||
{
|
||||
icon: $r('app.media.worldclock'),
|
||||
icon_after: $r('app.media.worldclock_blue'),
|
||||
text: $r('app.string.tab0'),
|
||||
num: 0
|
||||
},
|
||||
{
|
||||
icon: $r('app.media.clock'),
|
||||
icon_after: $r('app.media.clock_blue'),
|
||||
text: $r('app.string.tab1'),
|
||||
num: 1
|
||||
},
|
||||
{
|
||||
icon: $r('app.media.timer'),
|
||||
icon_after: $r('app.media.timer_blue'),
|
||||
text: $r('app.string.tab2'),
|
||||
num: 2
|
||||
},
|
||||
{
|
||||
icon: $r('app.media.settings'),
|
||||
icon_after: $r('app.media.settings_blue'),
|
||||
text: $r('app.string.tab3'),
|
||||
num: 3
|
||||
}
|
||||
new TabType($r('app.media.worldclock'), $r('app.media.worldclock_blue'), $r('app.string.tab0'), 0),
|
||||
new TabType($r('app.media.clock'), $r('app.media.clock_blue'), $r('app.string.tab1'), 1),
|
||||
new TabType($r('app.media.timer'), $r('app.media.timer_blue'), $r('app.string.tab2'), 2),
|
||||
new TabType($r('app.media.settings'), $r('app.media.settings_blue'), $r('app.string.tab3'), 3)
|
||||
]
|
@ -13,33 +13,33 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import hilog from '@ohos.hilog'
|
||||
import hilog from '@ohos.hilog';
|
||||
|
||||
class Logger {
|
||||
private domain: number
|
||||
private prefix: string
|
||||
private format: string = '%{public}s, %{public}s'
|
||||
private domain: number;
|
||||
private prefix: string;
|
||||
private format: string = '%{public}s, %{public}s';
|
||||
|
||||
constructor(prefix: string) {
|
||||
this.prefix = prefix
|
||||
this.domain = 0xFF00
|
||||
this.prefix = prefix;
|
||||
this.domain = 0xFF00;
|
||||
}
|
||||
|
||||
debug(...args: string[]) {
|
||||
hilog.debug(this.domain, this.prefix, this.format, args)
|
||||
hilog.debug(this.domain, this.prefix, this.format, args);
|
||||
}
|
||||
|
||||
info(...args: string[]) {
|
||||
hilog.info(this.domain, this.prefix, this.format, args)
|
||||
hilog.info(this.domain, this.prefix, this.format, args);
|
||||
}
|
||||
|
||||
warn(...args: string[]) {
|
||||
hilog.warn(this.domain, this.prefix, this.format, args)
|
||||
hilog.warn(this.domain, this.prefix, this.format, args);
|
||||
}
|
||||
|
||||
error(...args: string[]) {
|
||||
hilog.error(this.domain, this.prefix, this.format, args)
|
||||
hilog.error(this.domain, this.prefix, this.format, args);
|
||||
}
|
||||
}
|
||||
|
||||
export default new Logger('[Sample_FlipClock]')
|
||||
export default new Logger('[Sample_FlipClock]');
|
@ -13,52 +13,60 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import data_preferences from '@ohos.data.preferences'
|
||||
import data_preferences from '@ohos.data.preferences';
|
||||
|
||||
export default class StorageModel {
|
||||
static instance: StorageModel = null
|
||||
private storage = null
|
||||
static instance: StorageModel | null = null;
|
||||
private storage: data_preferences.Preferences | null = null;
|
||||
|
||||
public static getInstance() {
|
||||
if (this.instance === null) {
|
||||
this.instance = new StorageModel()
|
||||
if (StorageModel.instance === null) {
|
||||
StorageModel.instance = new StorageModel();
|
||||
}
|
||||
return this.instance
|
||||
return StorageModel.instance;
|
||||
}
|
||||
|
||||
async getFromStorage() {
|
||||
this.storage = await data_preferences.getPreferences(getContext(this), `storage`)
|
||||
return
|
||||
this.storage = await data_preferences.getPreferences(getContext(this), `storage`);
|
||||
return;
|
||||
}
|
||||
|
||||
async getStorage() {
|
||||
if (this.storage !== null) {
|
||||
return this.storage
|
||||
return this.storage;
|
||||
} else {
|
||||
await this.getFromStorage()
|
||||
return this.storage
|
||||
await this.getFromStorage();
|
||||
return this.storage;
|
||||
}
|
||||
}
|
||||
|
||||
async putStorageValue(putKey: string, alarmClock) {
|
||||
let value = JSON.stringify(alarmClock)
|
||||
this.storage = await this.getStorage()
|
||||
await this.storage.put(putKey, value)
|
||||
async putStorageValue(putKey: string, alarmClock: object) {
|
||||
let value = JSON.stringify(alarmClock);
|
||||
this.storage = await this.getStorage();
|
||||
await this.storage!.put(putKey, value);
|
||||
|
||||
await this.storage.flush()
|
||||
await this.storage!.flush();
|
||||
}
|
||||
|
||||
async putTotalStorageValue(putKey: string, alarmClock: number){
|
||||
let value = JSON.stringify(alarmClock);
|
||||
this.storage = await this.getStorage();
|
||||
await this.storage!.put(putKey, value);
|
||||
|
||||
await this.storage!.flush();
|
||||
}
|
||||
|
||||
async getStorageValue(getKey: string) {
|
||||
this.storage = await this.getStorage()
|
||||
let getValue = this.storage.get(getKey, 'null')
|
||||
this.storage = await this.getStorage();
|
||||
let getValue = this.storage!.get(getKey, 'null');
|
||||
|
||||
return getValue
|
||||
return getValue;
|
||||
}
|
||||
|
||||
async deleteSync(key: string) {
|
||||
await this.storage.delete(key)
|
||||
await this.storage.flush()
|
||||
let result = await this.storage.get(key, 'null')
|
||||
return result
|
||||
await this.storage!.delete(key);
|
||||
await this.storage!.flush();
|
||||
let result = await this.storage!.get(key, 'null');
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -58,17 +58,17 @@ struct Index {
|
||||
ForEach(tabArray, (item: TabType) => {
|
||||
TabContent() {
|
||||
if (item.num === 0) {
|
||||
FlipClock()
|
||||
FlipClock();
|
||||
} else if (item.num === 1) {
|
||||
AlarmClock()
|
||||
AlarmClock();
|
||||
} else if (item.num === 2) {
|
||||
CountDown()
|
||||
CountDown();
|
||||
} else if (item.num === 3) {
|
||||
SetBrightness()
|
||||
SetBrightness();
|
||||
}
|
||||
}
|
||||
.tabBar(this.tabBuilder(item))
|
||||
}, item => JSON.stringify(item))
|
||||
}, (item: TabType) => JSON.stringify(item))
|
||||
}
|
||||
.zIndex(-1)
|
||||
.width('100%')
|
||||
|
@ -35,12 +35,18 @@
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.NOTIFICATION_CONTROLLER"
|
||||
},
|
||||
{
|
||||
"name" : "ohos.permission.READ_CALENDAR"
|
||||
},
|
||||
{
|
||||
"name" : "ohos.permission.WRITE_CALENDAR"
|
||||
}
|
||||
],
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntrance": "./ets/entryability/EntryAbility.ets",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:EntryAbility_label",
|
||||
|
Loading…
Reference in New Issue
Block a user