sync SystemUI code

Signed-off-by: r00498791 <renjie32@huawei.com>
This commit is contained in:
r00498791
2022-01-11 20:00:31 +08:00
parent 14e3ec9b6c
commit da1c8aa393
70 changed files with 1419 additions and 527 deletions
+59 -44
View File
@@ -1,44 +1,59 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.huawei.ohos.app'
apply from: "./infra/config_exts.gradle"
ohos {
compileSdkVersion rootProject.ext.version.compileSdk
defaultConfig {
compatibleSdkVersion rootProject.ext.version.compatibleSdk
}
supportSystem "standard"
}
buildscript {
repositories {
maven {
url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
}
maven {
url 'https://mirrors.huaweicloud.com/repository/maven/'
}
maven {
url 'https://developer.huawei.com/repo/'
}
jcenter()
}
dependencies {
classpath 'com.huawei.ohos:hap:3.0.3.2'
}
}
allprojects {
repositories {
maven {
url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
}
maven {
url 'https://mirrors.huaweicloud.com/repository/maven/'
}
maven {
url 'https://developer.huawei.com/repo/'
}
jcenter()
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.huawei.ohos.app'
apply from: "./infra/config_exts.gradle"
ohos {
signingConfigs {
release {
storeFile file('D:\\xu\\OpenHarmony.p12')
storePassword '00000016F2017A40C8B50DAD39A176E1D19A0BE947D48AC71C90F0DEB0CD251285923218A84F'
keyAlias = 'OpenHarmony Application Release'
keyPassword '00000016E8775BE9B2A7B5239556EDAE1A9000261023E5C8202C19A43936B6989FA617A094F7'
signAlg = 'SHA256withECDSA'
profile file('D:\\xu\\systemui.p7b')
certpath file('D:\\xu\\OpenHarmonyApplication.cer')
}
}
compileSdkVersion rootProject.ext.version.compileSdk
defaultConfig {
compatibleSdkVersion rootProject.ext.version.compatibleSdk
}
supportSystem "standard"
}
buildscript {
repositories {
maven {
url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
allowInsecureProtocol = true
}
maven {
url 'https://mirrors.huaweicloud.com/repository/maven/'
allowInsecureProtocol = true
}
maven {
url 'https://developer.huawei.com/repo/'
allowInsecureProtocol = true
}
}
dependencies {
classpath 'com.huawei.ohos:hap:3.0.5.2'
}
}
allprojects {
repositories {
maven {
url 'http://repo.ark.tools.huawei.com/artifactory/maven-public/'
allowInsecureProtocol = true
}
maven {
url 'https://mirrors.huaweicloud.com/repository/maven/'
allowInsecureProtocol = true
}
maven {
url 'https://developer.huawei.com/repo/'
allowInsecureProtocol = true
}
}
}
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2021 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 ResMgr from '@ohos.resourceManager';
/**
* Resource util
*/
export class ResourceUtil {
private resMgr;
/**
* Initialize ResourceManager
*/
async initResourceManager(): Promise<void> {
if (!this.resMgr) {
this.resMgr = await ResMgr.getResourceManager('com.ohos.systemui');
}
return this.resMgr;
}
/**
* Get string value from NormalResource instance
*
* @param resource - NormalResource instance
*/
async getString(resource): Promise<string> {
await this.initResourceManager();
return await this.resMgr.getString(resource.id);
}
/**
* Get direction value from NormalResource instance
*
* @param resource - NormalResource instance
*/
async getConfiguration(): Promise<string> {
await this.initResourceManager();
return await this.resMgr.getConfiguration();
}
}
let resourceUtil = new ResourceUtil();
export default resourceUtil as ResourceUtil;
+37 -24
View File
@@ -16,34 +16,30 @@
import Window from '@ohos.window';
import display from '@ohos.display'
import Log from './Log.ets';
import ResourceUtil from './ResourceUtil.ets';
const TAG = 'WindowManager';
const STATUS_BAR_H = 0.07;
var maxWidth;
var maxHeight;
var minHeight;
var quicklySettingH;
var notificationH;
/**
* Manage window size changes.
*/
export default class WindowManager {
initWindowManager() {
Log.showInfo(TAG, 'initWindowManager ');
async initWindowManager() {
Log.showInfo(TAG, 'initWindowManager');
maxWidth = AppStorage.SetAndLink("maxWidth", 0);
maxHeight = AppStorage.SetAndLink("maxHeight", 0);
minHeight = AppStorage.SetAndLink("minHeight", 0);
display.getDefaultDisplay()
await display.getDefaultDisplay()
.then(dis => {
maxWidth.set(dis.width);
maxHeight.set(dis.height);
minHeight.set(this.getStatusBarDefaultHeight(dis.height));
Log.showInfo(TAG, `initWindowManager maxWidth ${maxWidth.get()} maxHeight ${maxHeight.get()} minHeight ${minHeight.get()}`);
})
maxWidth.set(dis.width);
maxHeight.set(dis.height);
Log.showInfo(TAG, `initWindowManager maxWidth ${maxWidth.get()} maxHeight ${maxHeight.get()} minHeight ${minHeight.get()}`);
})
}
/**
@@ -55,12 +51,18 @@ export default class WindowManager {
Log.showInfo(TAG, 'enter setWindowMax =================');
Window.getTopWindow()
.then((windowData) => {
windowData.resetSize(maxWidth.get(), maxHeight.get())
.then((result) => {
Log.showInfo(TAG, result);
callback(result);
Log.showInfo(TAG, 'enter setWindowMin maxWidth =================' + maxWidth.get() + " minHeight " + minHeight.get());
windowData.resetSize(parseInt(maxWidth.get()), parseInt(maxHeight.get()))
.then((result) => {
Log.showInfo(TAG, result);
callback(result);
});
windowData.moveTo(0, 0)
.then((result) => {
Log.showInfo(TAG, result);
});
});
});
}
/**
@@ -72,15 +74,26 @@ export default class WindowManager {
Log.showInfo(TAG, 'enter setWindowMin =================');
Window.getTopWindow()
.then((windowData) => {
windowData.resetSize(maxWidth.get(), minHeight.get())
.then((result) => {
Log.showInfo(TAG, result);
callback(result);
Log.showInfo(TAG, 'enter setWindowMin maxWidth =================' + maxWidth.get() + " minHeight " + minHeight.get());
windowData.resetSize(parseInt(maxWidth.get()), parseInt(minHeight.get()))
.then((result) => {
Log.showInfo(TAG, result);
callback(result);
});
});
});
}
getStatusBarDefaultHeight(maxheight) {
return parseInt((maxheight * STATUS_BAR_H).toString())
/**
* Set the window to the minimum size.
*
* @param {Object} callback - Callback function.
*/
async initWindowMin(width, height, x, y) {
AppStorage.Set("showStatusBar", true);
Log.showInfo(TAG, 'enter initWindowMin =================');
Log.showInfo(TAG, 'width:' + width + ' height:' + height + ' x:' + x + ' y:' + y);
let abilityWindow = await Window.getTopWindow();
await abilityWindow.moveTo(parseInt(x), parseInt(y));
await abilityWindow.resetSize(parseInt(width), parseInt(height));
}
}
@@ -25,7 +25,7 @@ export default class HeightConfigUtils {
return STATUS_BAR_MIN_HEIGHT;
}
getNavMinH(){
getminHeight(){
return NAV_BAR_MIN_HEIGHT;
}
+2 -2
View File
@@ -17,8 +17,8 @@
```
### 环境搭建
打开DevEco Studio链接下载安装,安装步骤及安装说明详见下载地址开发者网站
打开DevEco Studio链接下载安装,安装步骤及安装说明详见下载地址[下载地址](https://developer.harmonyos.com/cn/develop/deveco-studio#download)
## 基础开发说明
### 系统接口调用
#### NAPI接口集成
+1 -1
View File
@@ -1 +1 @@
/build
/build
+12 -12
View File
@@ -1,12 +1,12 @@
apply plugin: 'com.huawei.ohos.hap'
ohos {
compileSdkVersion rootProject.ext.version.compileSdk
defaultConfig {
compatibleSdkVersion rootProject.ext.version.compatibleSdk
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.huawei.ohos.hap'
ohos {
compileSdkVersion rootProject.ext.version.compileSdk
defaultConfig {
compatibleSdkVersion rootProject.ext.version.compatibleSdk
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
testCompile 'junit:junit:4.12'
}
+1 -1
View File
@@ -1 +1 @@
{}
{}
+2 -1
View File
@@ -54,6 +54,7 @@
},
"pages": ["pages/index"]
}
]
],
"srcPath": "default"
}
}
@@ -1,12 +1,12 @@
{
"string": [
{
"name": "app_name",
"value": "SystemUI"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
]
{
"string": [
{
"name": "app_name",
"value": "SystemUI"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
}
]
}
@@ -18,6 +18,7 @@
"deliveryWithInstall": true,
"moduleName": "airplanecomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -1,5 +0,0 @@
{
"color": [
]
}
@@ -1,4 +0,0 @@
{
"float": [
]
}
@@ -17,6 +17,7 @@
"deliveryWithInstall": true,
"moduleName": "batterycomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -18,6 +18,7 @@
"deliveryWithInstall": true,
"moduleName": "brightnesscomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -15,12 +15,12 @@
import Log from '../../../../../../common/src/main/ets/default/Log.ets';
import commonEvent from '@ohos.commonEvent';
import settings from '@ohos.settingsnapi';
import settings from '@ohos.settings';
import featureAbility from '@ohos.ability.featureAbility';
const SYSTEMUI_BRIGHTNESS = 'brightness';
const SYSTEMUI_BRIGHTNESS = 'settings.screen.brightness';
const TAG = 'Control-brightnessManager';
var mBrightnessValue = AppStorage.SetAndLink('BrightnessValue', 255);
var mBrightnessValue = AppStorage.SetAndLink('BrightnessValue', 150);
export class brightnessManager {
helper: any
@@ -36,7 +36,7 @@ export class brightnessManager {
registerBrightness() {
this.helper.on("dataChange", this.uri, (err) => {
let data = settings.getValue(this.helper, SYSTEMUI_BRIGHTNESS, '100')
let data = settings.getValue(this.helper, SYSTEMUI_BRIGHTNESS, '150')
Log.showInfo(TAG, `after brightness datachange settings getValue ${parseInt(data)}`);
mBrightnessValue.set(parseInt(data));
})
@@ -50,7 +50,7 @@ export class brightnessManager {
getValue() {
Log.showInfo(TAG, 'getValue');
let data = settings.getValue(this.helper, SYSTEMUI_BRIGHTNESS, '100');
let data = settings.getValue(this.helper, SYSTEMUI_BRIGHTNESS, '150');
Log.showInfo(TAG, `settings getValue ${parseInt(data)}`);
mBrightnessValue.set(parseInt(data));
}
@@ -61,7 +61,7 @@ export struct MyBrightness {
min: this.brightnessItem.min,
max: this.brightnessItem.max,
step: 1,
style: SliderStyle.INSET
style: SliderStyle.InSet
})
.width('100%')
@@ -27,6 +27,7 @@
"deliveryWithInstall": true,
"moduleName": "capsulecomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -1,4 +0,0 @@
{
"string": [
]
}
+2 -1
View File
@@ -17,6 +17,7 @@
"deliveryWithInstall": true,
"moduleName": "clockcomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -15,50 +15,16 @@
import timeModel from '../timeModel.ets'
import Log from '../../../../../../../common/src/main/ets/default/Log.ets'
import featureAbility from '@ohos.ability.featureAbility'
import settings from '@ohos.settingsnapi';
const TAG = 'ClockComponent-clockIcon';
const LOOP_TIME = 20000;
@Component
export default struct ClockIcon {
@StorageLink('time') mTime: string = '16:01'
isUsing24hFormat: boolean
aboutToAppear() {
Log.showInfo(TAG, 'aboutToAppear');
timeModel.initTimeModel(this.isUsing24hFormat);
var isOnChange: boolean = false;
var timeInterval = setInterval(() => {
if (isOnChange) {
return;
}
Log.showInfo(TAG, 'setInterval')
let urivar = settings.getUri('settings.time.format')
Log.showInfo(TAG, 'urivar = ' + urivar)
let helper = featureAbility.acquireDataAbilityHelper(urivar);
Log.showInfo(TAG, ' helper = ' + helper)
helper.on("dataChange", urivar, (err) => {
if (err.code !== 0) {
Log.showError(TAG, `failed to getAbilityWant because ${err.message}`);
return;
} else {
let getRetValue = settings.getValue(helper, 'settings.time.format', '24')
Log.showInfo(TAG, 'observer reveive notifychange on success format = ' + getRetValue)
if (getRetValue === '12') {
isOnChange = true;
this.isUsing24hFormat = false;
} else if (getRetValue === '24') {
isOnChange = true;
this.isUsing24hFormat = true;
}
timeModel.initTimeModel(this.isUsing24hFormat);
}
Log.showInfo(TAG, 'observer reveive notifychange on success data : ' + JSON.stringify(err))
})
}, LOOP_TIME);
timeModel.initTimeModel();
}
aboutToDisappear() {
@@ -14,7 +14,7 @@
*/
import Log from '../../../../../../common/src/main/ets/default/Log.ets'
import featureAbility from '@ohos.ability.featureAbility'
import settings from '@ohos.settingsnapi';
import settings from '@ohos.settings';
const SHORT_LENGTH = 1;
const LOOP_TIME = 3000;
@@ -26,24 +26,15 @@ var mTimeLink;
var mDayLink;
var mWeekDayLink;
var mMonthLink;
var misUsing24hFormat: boolean;
var misUsing24hFormat: boolean = true;
export class TimeModel {
/**
* Init Time Model
*
*/
initTimeModel(isUsing24hFormat: boolean) {
Log.showInfo(TAG, 'initTimeModel' + isUsing24hFormat);
var reFresh: boolean = (misUsing24hFormat === isUsing24hFormat);
misUsing24hFormat = isUsing24hFormat;
Log.showInfo(TAG, `timeInterval : ${timeInterval} type: ${typeof timeInterval}`);
if (!reFresh) {
let date = new Date();
Log.showInfo(TAG, `getCurrentDate ${date.toTimeString()}`);
this.updateTime(date);
}
initTimeModel() {
Log.showInfo(TAG, 'initTimeModel');
if (timeInterval === null || timeInterval === undefined) {
Log.showInfo(TAG, 'first initTimeModel');
mTimeLink = AppStorage.SetAndLink('time', '');
@@ -52,6 +43,36 @@ export class TimeModel {
mMonthLink = AppStorage.SetAndLink('month', '');
this.getCurrentDate();
}
this.listenTimeFormat();
}
listenTimeFormat() {
Log.showInfo(TAG, 'listenTimeFormat')
let urivar = null;
let helper = null;
try {
urivar = settings.getUri('settings.time.format')
helper = featureAbility.acquireDataAbilityHelper(urivar);
} catch (e) {
Log.showInfo(TAG, `settings getValue error: ${e.toString()}`);
}
helper.on("dataChange", urivar, (err) => {
if (err.code !== 0) {
Log.showError(TAG, `failed to getAbilityWant because ${err.message}`);
return;
} else {
let getRetValue = settings.getValue(helper, 'settings.time.format', '24')
Log.showInfo(TAG, 'observer reveive notifychange on success format = ' + getRetValue)
if (getRetValue === '12') {
misUsing24hFormat = false;
} else if (getRetValue === '24') {
misUsing24hFormat = true;
}
this.updateTime(new Date());
}
Log.showInfo(TAG, 'observer reveive notifychange on success data : ' + JSON.stringify(err))
})
}
unInitTimeModel() {
@@ -97,6 +118,7 @@ export class TimeModel {
}
let minutes = dateTime.getMinutes();
mTimeLink.set(`${this.fill(hours)}:${this.fill(minutes)}`);
Log.showInfo(TAG, 'updateTime set' + `${this.fill(hours)}:${this.fill(minutes)}`);
}
fill(value) {
@@ -19,5 +19,6 @@
"moduleName": "controlcentercomponent",
"moduleType": "har"
},
"srcPath": "default"
}
}
@@ -18,6 +18,7 @@
"deliveryWithInstall": true,
"moduleName": "managementcomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -18,7 +18,6 @@ import commonevent from '@ohos.commonevent';
import Constants from './common/constants.ets';
import FeatureAbilityManager from '../../../../../../../../common/src/main/ets/default/abilitymanager/featureAbilityManager.ets';
import Input from '@ohos.multimodalInput.inputEventClient';
import settings from '@ohos.settingsnapi';
import featureAbility from '@ohos.ability.featureAbility';
const TAG = 'KeyCodeEvent'
@@ -72,7 +71,7 @@ export class KeyCodeEvent {
// After consulting the multi-mode subsystem, this parameter proved meaningless and remained unchanged
keyDownDuration: 1,
// This parameter changes with the version, and is currently 10008
maxKeyCode: 10008
isIntercepted: false
}
res = Input.injectEvent({
KeyEvent: keyEvent
@@ -89,7 +88,7 @@ export class KeyCodeEvent {
// After consulting the multi-mode subsystem, this parameter proved meaningless and remained unchanged
keyDownDuration: 1,
// This parameter changes with the version, and is currently 10008
maxKeyCode: 10008
isIntercepted: false
}
res = Input.injectEvent({
KeyEvent: keyEvent
+2 -1
View File
@@ -18,6 +18,7 @@
"deliveryWithInstall": true,
"moduleName": "noticeitem",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -49,6 +49,14 @@ export class InputActionButtonData {
content: string = '';
}
interface RuleData {
isAllowBanner?: boolean;
isAllowSound?: boolean;
isAllowVibrationValues?: boolean;
isAllowStatusBarShow?: boolean;
isAllowNotificationListShow?: boolean;
}
export interface NotificationItemData {
id: string;
hashcode: string;
@@ -73,6 +81,13 @@ export interface NotificationItemData {
slotLevel?: any;
source?: number;
versionName?: string;
sound?: string;
vibrationValues?: Array<number>;
ruleData?:RuleData;
template?: any;
isOngoing?: boolean;
isUnremovable?: boolean;
isRemoveAllowed?: boolean;
}
export interface NotificationServiceListener {
@@ -15,15 +15,19 @@
//import { NotificationSubscriber } from './notification/notificationSubscriber';
import Notification from '@ohos.notification';
import PluginComponentManager from '@ohos.plugincomponent'
import Log from '../../../../../../../../../common/src/main/ets/default/Log.ets';
const TAG = 'NotificationManager';
// Temporary path
const EXTERNAL_JSON_PATH = '/system/etc/NotificationTemplate/external.json'
export default class NotificationManager {
static TYPE_BASIC: number = Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT;
static TYPE_LONG: number = Notification.ContentType.NOTIFICATION_CONTENT_LONG_TEXT;
static TYPE_MULTI: number = Notification.ContentType.NOTIFICATION_CONTENT_MULTILINE;
static TYPE_PICTURE: number = Notification.ContentType.NOTIFICATION_CONTENT_PICTURE;
static NotificationTemplateMap = null;
static subscribeNotification(tag, subscriber, asyncCallback) {
Log.showInfo(TAG, `subscribeNotification from: ${tag}`);
@@ -49,4 +53,73 @@ export default class NotificationManager {
Log.showInfo(TAG, `getAllActiveNotifications from: ${tag}`);
Notification.getAllActiveNotifications(callback);
}
static initNotificationTemplateMap(tag) {
Log.showInfo(TAG, `initNotificationTemplateMap from: ${tag}`);
if (NotificationManager.NotificationTemplateMap === null) {
NotificationManager.NotificationTemplateMap = new Map()
NotificationManager.requestTemplate(tag, '', EXTERNAL_JSON_PATH);
}
}
static request(tag, param, asyncCallback) {
Log.showInfo(TAG, `request from: ${tag}`);
PluginComponentManager.request(param, (err, data) => {
asyncCallback(err, data);
});
}
static push(tag, param, asyncCallback) {
Log.showInfo(TAG, `push from: ${tag}`);
PluginComponentManager.push(param, () => {
asyncCallback();
});
}
static requestListener(tag, asyncCallback) {
Log.showInfo(TAG, `requestListener from: ${tag}`);
PluginComponentManager.on('request', (source, name, data) => {
asyncCallback(source, name, data);
})
}
static pushListener(tag, asyncCallback) {
Log.showInfo(TAG, `pushListener from: ${tag}`);
PluginComponentManager.on('push', (source, template, data, extraData) => {
asyncCallback(source, template, data, extraData);
});
}
static requestTemplate(tag, templateName, templatePath) {
Log.showInfo(TAG, `requestTemplate from: ${tag}`);
let reqWant = {
bundleName: '',
abilityName: ''
};
let reqData = {}
let requestParam = {
want: reqWant,
name: templateName,
data: reqData,
jsonPath: templatePath
};
NotificationManager.request(tag, requestParam, (err, data) => {
Log.showInfo(TAG, `request finished err: ${JSON.stringify(err)} data: ${JSON.stringify(data)}`)
Log.showInfo(TAG, `request finished templateData: ${templateName} data: ${JSON.stringify(data.componentTemplate)}`)
if (data !== null && data !== undefined) {
Log.showInfo(TAG, `request finished data.componentTemplate.source:${JSON.stringify(data.componentTemplate.source)}`)
let templates = JSON.parse(data.componentTemplate.source);
Log.showInfo(TAG, `request templates: ${JSON.stringify(templates)}`)
for (let key in templates) {
NotificationManager.NotificationTemplateMap.set(key, {
"source": templates[key], "ability": ""
});
}
}
Log.showInfo(TAG, `request finished notificationTemplateMap: ${JSON.stringify(NotificationManager.NotificationTemplateMap)}`)
});
}
}
@@ -18,6 +18,7 @@ import NotificationSubscriber from '@ohos.notificationSubscriber';
import Log from '../../../../../../../../../common/src/main/ets/default/Log.ets';
import NotificationManager from './NotificationManager.ets';
import ParseDataUtil from './ParseDataUtil.ets';
import RuleController from './rule/RuleController.ets';
const TAG = 'NotificationService';
@@ -36,6 +37,7 @@ export class NotificationService {
init() {
this.loadAllNotifications();
this.subscribeNotification(this.getSubscriber());
this.loadNotificationTemplate()
}
public register(listener) {
@@ -54,17 +56,15 @@ export class NotificationService {
Log.showInfo(TAG, "unRegister listener success");
}
public removeAll(){
public removeAll() {
Log.showInfo(TAG, 'removeAll start');
NotificationManager.removeAll(TAG, (data) => {
Log.showInfo(TAG, `removeAll => data: ${JSON.stringify(data)}`);
});
}
public remove(code: string) {
NotificationManager.remove(TAG, code,(data) => {
NotificationManager.remove(TAG, code, (data) => {
Log.showInfo(TAG, `removeNotificationItem ==> data: ${JSON.stringify(data)}`);
})
}
@@ -74,7 +74,7 @@ export class NotificationService {
Log.showInfo(TAG, `getAllActiveNotifications err: ${JSON.stringify(err)}`);
Log.showInfo(TAG, `getAllActiveNotifications requestsArr: ${JSON.stringify(requestsArr)}`);
if (Array.isArray(requestsArr)) {
for(let i = 0,len = requestsArr.length; i< len; i++) {
for (let i = 0, len = requestsArr.length; i < len; i++) {
this.handleNotificationLoad(requestsArr[i]);
}
}
@@ -93,22 +93,25 @@ export class NotificationService {
handleNotificationAdd(data) {
Log.showInfo(TAG, 'handleNotificationAdd started');
Log.showInfo(TAG, 'sortingMap' + JSON.stringify(data.sortingMap||{}));
Log.showInfo(TAG, 'sortingMap' + JSON.stringify(data.sortingMap || {}));
Log.showInfo(TAG, JSON.stringify(data));
ParseDataUtil.parseData(data, (err, record) => {
Log.showInfo(TAG, `parseData after = ${JSON.stringify(record)}`);
Log.showInfo(TAG, `listeners.length = ${JSON.stringify(data)}`);
for(let i = 0,len = listeners.length; i< len; i++) {
Log.showInfo(TAG, `notify listener ` + i);
listeners[i].onNotificationConsume(record);
}
ParseDataUtil.parseData(data, (err, intermediateData) => {
Log.showInfo(TAG, `parseData after = ${JSON.stringify(intermediateData)}`);
RuleController.getNotificationData(intermediateData, (finalItemData) => {
Log.showInfo(TAG, `RuleController.getNotificationData after = ${JSON.stringify(finalItemData)}`);
Log.showInfo(TAG, `listeners.length = ${JSON.stringify(data)}`);
for (let i = 0, len = listeners.length; i < len; i++) {
Log.showInfo(TAG, `notify listener ` + i);
listeners[i].onNotificationConsume(finalItemData);
}
});
});
}
handleNotificationCancel(data) {
console.info("===>handleNotificationCancel data : ==> " + `data:${JSON.stringify(data)}`);
ParseDataUtil.parseData(data, (err, record) => {
for(let i = 0,len = listeners.length; i< len; i++) {
for (let i = 0, len = listeners.length; i < len; i++) {
listeners[i].onNotificationCancel(record);
}
});
@@ -117,19 +120,35 @@ export class NotificationService {
handleNotificationLoad(data) {
console.info("===>handleNotificationLoad data : ==> " + `data:${JSON.stringify(data)}`);
ParseDataUtil.parseData(data, (err, record) => {
for(let i = 0,len = listeners.length; i< len; i++) {
for (let i = 0, len = listeners.length; i < len; i++) {
listeners[i].onNotificationLoad(record);
}
});
}
subscribeNotification(subscriber) {
let callback = (err,data) => {
let callback = (err, data) => {
Log.showInfo(TAG, `subscribeCallback finished err: ${JSON.stringify(err)} data: ${JSON.stringify(data)}`)
};
NotificationManager.subscribeNotification(TAG, subscriber, callback);
}
loadNotificationTemplate() {
Log.showInfo(TAG, 'loadNotificationTemplate start');
NotificationManager.initNotificationTemplateMap(TAG);
}
getPluginTempLate(templateName) {
Log.showInfo(TAG, `getPluginTempLate param:${templateName}`);
let pluginTempLate = null;
if (NotificationManager.NotificationTemplateMap !== null) {
pluginTempLate = NotificationManager.NotificationTemplateMap.get(templateName);
}
Log.showInfo(TAG, `getPluginTempLate pluginTempLate:${JSON.stringify(pluginTempLate)}`);
return pluginTempLate;
}
}
let notificationService = new NotificationService();
export default notificationService as NotificationService;
@@ -46,6 +46,18 @@ export default class ParseDataUtil {
} catch (e) {
Log.showInfo(TAG, `slot level get error: ${e.toString()}`);
}
let sound = '';
try {
sound = data?.sortingMap?.sortings[request.hashCode]?.slot.sound;
} catch (e) {
Log.showInfo(TAG, `sound get error: ${e.toString()}`);
}
let vibrationValues = [];
try {
vibrationValues = data?.sortingMap?.sortings[request.hashCode]?.slot.vibrationValues;
} catch (e) {
Log.showInfo(TAG, `vibrationValues get error: ${e.toString()}`);
}
Log.showInfo(TAG, `want = ${JSON.stringify(request.wantAgent)}`);
Log.showInfo(TAG, `actionButtons = ${JSON.stringify(request.actionButtons)}`);
Log.showInfo(TAG, `largeIcon = ${request.largeIcon}`);
@@ -63,7 +75,13 @@ export default class ParseDataUtil {
smallIcon: NotificationConfig.USE_NOTIFICATION_ICON ? (request?.smallIcon ?? appMessage.icon) : appMessage.icon,
largeIcon: request.largeIcon,
slotLevel: slotLevel,
source: request.source
source: request.source,
sound: sound? sound : '',
vibrationValues: vibrationValues? vibrationValues : [],
template: request?.template,
isOngoing: request.isOngoing,
isUnremovable: request.isUnremovable,
isRemoveAllowed: request.isRemoveAllowed
};
Log.showInfo(TAG, `notificationItem construct over ====================`);
switch (request?.content?.contentType) {
@@ -1,21 +0,0 @@
/*
* Copyright (c) 2021 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.
*/
export interface RuleData {
isAllowBanner:boolean;
sound:string;
vibration:string;
isAllowLockScreen:boolean;
}
@@ -13,49 +13,37 @@
* limitations under the License.
*/
import {NotificationItemData} from '../../common/constants.ets'
import Log from '../../../../../../../../../common/src/main/ets/default/Log.ets';
const TAG = 'RuleController';
export default class RuleController {
import {NotificationItemData} from '../../common/constants.ets';
import Log from '../../../../../../../../../../common/src/main/ets/default/Log.ets';
import {SlotLevel} from '@ohos.notification';
import Notification from '@ohos.notification';
import CheckEmptyUtils from '../../../../../../../../../../common/src/main/ets/default/CheckEmptyUtils.ets';
import Bundle from '@ohos.bundle';
const TAG = 'NotificationRuleController';
export class RuleController {
/**
* Check if this notification is allow show or not
*
* @param {notificationItemData} Data of the notification
* @param {callback} Data of the type to show the notification
*/
static getNotificationData(notificationItemData, callback) {
if (typeof notificationItemData !== NotificationItemData) {
Log.showInfo(TAG, "type is not NotificationItemData")
callback(undefined)
return
}
getNotificationData(notificationItemData: NotificationItemData, callback) {
Log.showInfo(TAG, "getNotificationData start")
Log.showInfo(TAG, `notificationItemData = ${JSON.stringify(notificationItemData)}`);
this.this.isAllowSendNotification(notificationItemData.name, 0, "", (isSuccess) => {
this.isAllowSendNotification(notificationItemData, (isSuccess) => {
if (!isSuccess) {
Log.showInfo(TAG, "user is not allow this to send notification")
callback(undefined)
return
Log.showInfo(TAG, "user is not allow this to send notification");
callback(undefined);
return;
}
this.isTooMuchNotification((isSuccess) => {
if (!isSuccess) {
Log.showInfo(TAG, "There are too much notification")
callback(undefined)
return
}
this.isAppTooMuchNotification(notificationItemData.name, 0, (isSuccess) => {
if (!isSuccess) {
Log.showInfo(TAG, "There are too much notification")
callback(undefined)
}
this.getNotificationDataByApp(notificationItemData.name, 0, "", (originData) => {
this.updateNotificationDataBySense(originData, (finialData) => {
callback(finalData)
});
});
this.getNotificationDataByApp(notificationItemData, (originalData) => {
Log.showInfo(TAG, `originalData = ${JSON.stringify(originalData)}`);
this.updateNotificationDataBySense(originalData, (finalData) => {
Log.showInfo(TAG, `finalData = ${JSON.stringify(finalData)}`);
callback(finalData);
});
});
});
@@ -64,56 +52,106 @@ export default class RuleController {
/**
* Check if user allow the app send notification or not
*
* @param {name} Package name of the app
* @param {uid} Uid of the app to distinguish twin app
* @param {channelId} The channel id of the app which is used to send notification
* @param {notificationItemData} The origin notification data
* @param {callback} The user allow the app send notification or not
*/
private static isAllowSendNotification(name, uid, channelId, callback) {
// TODO 权限管理
isAllowSendNotification(notificationItemData, callback) {
Log.showInfo(TAG, "isAllowSendNotification start");
Bundle.getBundleInfo(notificationItemData.bundleName, 0)
.then((data) => {
Log.showInfo(TAG, `getBundleInfo : ${JSON.stringify(data)}`)
Notification.isNotificationEnabled({ bundle: notificationItemData.bundleName, uid: data.uid })
.then((flag) => {
Log.showInfo(TAG, `Notification.isNotificationEnabled:` + flag)
callback(flag);
});
});
}
/**
* Check there have been too much notification that there is no need to show another
* Check whether sound or vibration is allowed
*
*
* @param {callback} Send too much notification or not
* @param {notificationItemData} The origin notification data
* @param {callback} whether sound or vibration is allowed
*/
private static isTooMuchNotification(callback) {
// TODO 通知总条数显示限制
SoundOrVibrate(notificationItemData, callback) {
Log.showInfo(TAG, "SoundOrVibrate start")
let sound = false;
let vibrationValues = false;
if (!CheckEmptyUtils.checkStrIsEmpty(notificationItemData.sound)) {
sound = true;
Log.showInfo(TAG, `notificationItemData.sound is allowed = ${sound}`);
}
if (!CheckEmptyUtils.isEmptyArr(notificationItemData.vibrationValues)) {
vibrationValues = true;
Log.showInfo(TAG, `notificationItemData.vibrationValues is allowed = ${vibrationValues}`);
}
callback(sound, vibrationValues);
}
/**
* Check if the app send too much notification to can not show another from this app
*
*
* @param {name} Package name of the app
* @param {uid} Uid of the app to distinguish twin app
* @param {callback} Send too much notification or not
*/
private static isAppTooMuchNotification(name, uid, callback) {
// TODO 单应用通知显示限制
}
/**
* Get notification data of the notification channel
* Get notification data of the notification
*
* @param {name} Package name of the app which send notification
* @param {uid} Uid of the app which send notification to distinguish twin app
* @param {channelId} The channel id of the app which is used to send notification
* @param {notificationItemData} The origin notification data
* @param {callback} The type to show notification
*/
private static getNotificationDataByApp(name, uid, channelId, callback) {
// TODO 提醒方式
getNotificationDataByApp(notificationItemData, callback) {
Log.showInfo(TAG, "getNotificationDataByApp start")
let mNotificationItemData : NotificationItemData = notificationItemData;
mNotificationItemData.ruleData = {
isAllowBanner: false,
isAllowSound: false,
isAllowVibrationValues: false,
isAllowStatusBarShow : false,
isAllowNotificationListShow : false
};
Log.showInfo(TAG, `notificationItemData.slotLevel = ${notificationItemData.slotLevel}`);
if (notificationItemData.slotLevel === SlotLevel.LEVEL_HIGH) {
mNotificationItemData.ruleData.isAllowBanner = true;
this.SoundOrVibrate(notificationItemData, (sound, vibrationValues) => {
mNotificationItemData.ruleData.isAllowSound = sound;
mNotificationItemData.ruleData.isAllowVibrationValues = vibrationValues;
});
mNotificationItemData.ruleData.isAllowStatusBarShow = true;
mNotificationItemData.ruleData.isAllowNotificationListShow = true;
} else if (notificationItemData.slotLevel === SlotLevel.LEVEL_DEFAULT) {
this.SoundOrVibrate(notificationItemData, (sound, vibrationValues) => {
mNotificationItemData.ruleData.isAllowSound = sound;
mNotificationItemData.ruleData.isAllowVibrationValues = vibrationValues;
});
mNotificationItemData.ruleData.isAllowStatusBarShow = true;
mNotificationItemData.ruleData.isAllowNotificationListShow = true;
} else if (notificationItemData.slotLevel === SlotLevel.LEVEL_LOW ||
notificationItemData.slotLevel === SlotLevel.LEVEL_MIN) {
mNotificationItemData.ruleData.isAllowNotificationListShow = true;
} else {
mNotificationItemData.ruleData.isAllowNotificationListShow = false;
}
Log.showInfo(TAG, `mNotificationItemData.ruleData = ${JSON.stringify(mNotificationItemData.ruleData)}`);
callback(mNotificationItemData);
}
/**
* Check the sense of the phone to update the show type
*
* @param {notificationData} The origin notification data
* @param {callback} The finial notification data
* @param {notificationItemData} The origin notification data
* @param {callback} The final notification data
*/
private static updateNotificationDataBySense(notificationData, callback) {
// TODO 场景管理
updateNotificationDataBySense(notificationItemData, callback) {
Log.showInfo(TAG, "updateNotificationDataBySense start")
let mNotificationItemData = notificationItemData;
// TODO Scenario Management
callback(mNotificationItemData);
}
}
}
let ruleController = new RuleController();
export default ruleController as RuleController;
@@ -27,7 +27,6 @@ export default struct NotificationListComponent {
@StorageProp('minHeight') minHeight: number = 0
@State notificationH: number = 0
aboutToAppear() {
Log.showInfo(TAG, `notificationList, aboutToAppear`)
this.notificationH = this.maxHeight - (this.minHeight * 2) - Constants.QUICKLY_SETTING_H;
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2021 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 Log from '../../../../../../../../../../common/src/main/ets/default/Log.ets';
import ViewModel from '../../viewmodel/ViewModel.ets';
const TAG = 'NoticeItem-CustomItem';
@Component
export default struct CustomItem {
private customItemData: any = {};
private template: any = {};
private templateData: any = {};
@State isDebugMode: boolean = false;
aboutToAppear() {
Log.showInfo(TAG, `aboutToAppear Start`)
this.template = ViewModel.getPluginTempLate(this.customItemData.template.name);
this.templateData = this.customItemData.template.data;
Log.showInfo(TAG, `template = ${JSON.stringify(this.template)}`)
Log.showInfo(TAG, `templateData = ${JSON.stringify(this.templateData)}`)
}
build() {
Stack({ alignContent: Alignment.TopStart }) {
Column() {
PluginComponent({
template: this.template,
data: this.templateData
}).onComplete(() => {
Log.showInfo(TAG, `Complete`)
}).onError(({errcode, msg}) => {
Log.showInfo(TAG, `Error code:${errcode} message:${msg}`)
})
.size({ width: 400, height: 130 })
}
.backgroundColor($r('app.color.notificationitem_background'))
.opacity($r('app.float.item_opicaty'))
.borderRadius($r('app.float.item_borderradius'))
.margin({
left: $r('app.float.item_marginleft'),
right: $r('app.float.item_marginright'),
top: $r('app.float.item_margintop')
})
.padding({
left: $r('app.float.item_paddingleft'),
right: $r('app.float.item_paddingright'),
bottom: $r('app.float.item_paddingbottom')
})
if (this.isDebugMode) {
Column() {
Text("-- DEBUG --")
.fontSize('32')
.fontWeight(FontWeight.Bold)
.fontColor(0xCCCCCC)
.opacity(0.5)
}.margin(10)
}
}
}
}
@@ -0,0 +1,133 @@
/*
* Copyright (c) 2021 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 Constants from '../../common/constants.ets';
import basicItem from './basicItem.ets';
import longItem from './longItem.ets';
import multiItem from './multiItem.ets';
import pictureItem from './pictureItem.ets';
import titleItem from './titleItem.ets';
import Log from '../../../../../../../../../../common/src/main/ets/default/Log.ets';
import CheckEmptyUtils from '../../../../../../../../../../common/src/main/ets/default/CheckEmptyUtils.ets';
import ViewModel from '../../viewmodel/ViewModel.ets';
import ActionComponent from './actionComponent.ets';
const TAG = 'NoticeItem-GeneralItem';
@Component
export default struct GeneralItem {
private generalItemData: any = {}
@State hasPicture: boolean = false
@State isExpand: boolean = false
@State needExpand: boolean = true
aboutToAppear() {
Log.showInfo(TAG, `aboutToAppear Start`)
if (CheckEmptyUtils.isEmpty(this.generalItemData.largeIcon)) {
this.hasPicture = false;
} else {
this.hasPicture = true;
}
this.needExpand = this.checkItemNeedExpand()
}
checkItemNeedExpand() {
if (this.generalItemData.contentType === Constants.NOTIFICATION_TYPE_BASIC
&& (!(this.generalItemData.actionButtons?.length > 0))) {
return false;
} else {
return true;
}
}
aboutToDisappear() {
Log.showInfo(TAG, `aboutToDisappear`);
}
build() {
Column() {
titleItem({
notificationSmallIcon: this.generalItemData.smallIcon,
notificationName: this.generalItemData.appName,
notificationTime: this.generalItemData.time,
isExpand: $isExpand,
needExpand: this.needExpand
})
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start }) {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start }) {
if (this.generalItemData.contentType === Constants.NOTIFICATION_TYPE_BASIC) {
basicItem({
itemData: this.generalItemData
});
}
if (this.generalItemData.contentType === Constants.NOTIFICATION_TYPE_LONG) {
longItem({
itemData: this.generalItemData,
isExpand: this.isExpand
});
}
if (this.generalItemData.contentType === Constants.NOTIFICATION_TYPE_MULTILINE) {
multiItem({
itemData: this.generalItemData,
isExpand: this.isExpand
});
}
if (this.generalItemData.contentType === Constants.NOTIFICATION_TYPE_PICTURE) {
pictureItem({
itemData: this.generalItemData,
isExpand: this.isExpand
});
}
}
.width(this.hasPicture ? '85%' : '100%')
.margin({ top: $r('app.float.body_margin_top') })
if (this.hasPicture) {
Column() {
Image(this.generalItemData.largeIcon)
.objectFit(ImageFit.Contain)
.width(50)
.height(50)
}
.alignItems(HorizontalAlign.End)
.margin({ top: $r('app.float.body_margin_top') })
.width('15%')
}
}
.onClick(() => {
ViewModel.clickItem(this.generalItemData);
})
if (this.isExpand) {
ActionComponent({ itemData: this.generalItemData })
}
}
.backgroundColor($r('app.color.notificationitem_background'))
.opacity($r('app.float.item_opicaty'))
.borderRadius($r('app.float.item_borderradius'))
.margin({
left: $r('app.float.item_marginleft'),
right: $r('app.float.item_marginright'),
top: $r('app.float.item_margintop')
})
.padding({
left: $r('app.float.item_paddingleft'),
right: $r('app.float.item_paddingright'),
bottom: $r('app.float.item_paddingbottom')
})
}
}
@@ -13,34 +13,26 @@
* limitations under the License.
*/
import Constants, {NotificationItemData} from '../../common/constants.ets';
import basicItem from './basicItem.ets';
import longItem from './longItem.ets';
import multiItem from './multiItem.ets';
import pictureItem from './pictureItem.ets';
import titleItem from './titleItem.ets';
import Constants from '../../common/constants.ets';
import GeneralItem from './generalItem.ets';
import CustomItem from './customItem.ets';
import Log from '../../../../../../../../../../common/src/main/ets/default/Log.ets';
import CheckEmptyUtils from '../../../../../../../../../../common/src/main/ets/default/CheckEmptyUtils.ets';
import ViewModel from '../../viewmodel/ViewModel.ets';
import SettingDialog from './settingDialog.ets';
import ConfirmDialog from './confirmDialog.ets';
import ActionComponent from './actionComponent.ets';
import ConfirmDialog from './confirmDialog.ets'
const TAG = 'NoticeItem-NotificationItem';
@Component
export default struct NotificationItem {
private itemData: any = {}
@State hasPicture: boolean = false
@State isExpand: boolean = false
@State needExpand: boolean = true
@State deleteIconDisplay: boolean = false;
@State itemWidth: string = '100%'
startX: number = 0
startY: number = 0
@State moveX: number = 0
@State moveY: number = 0
settingDialogController: CustomDialogController = new CustomDialogController({
builder: SettingDialog({
itemData: this.itemData,
@@ -49,12 +41,11 @@ export default struct NotificationItem {
autoCancel: false,
offset: { dx: 0, dy: 200 }
});
confirmDialogController: CustomDialogController = new CustomDialogController({
builder: ConfirmDialog({
title: $r('app.string.closeNovice'),
bundleName: this.itemData.name,
action: ViewModel.removeNotificationItem.bind(ViewModel,this.itemData,true)
action: ViewModel.removeNotificationItem.bind(ViewModel, this.itemData, true)
}),
autoCancel: false,
offset: { dx: 0, dy: 250 }
@@ -62,20 +53,6 @@ export default struct NotificationItem {
aboutToAppear() {
Log.showInfo(TAG, `aboutToAppear Start`)
if (CheckEmptyUtils.isEmpty(this.itemData.largeIcon)) {
this.hasPicture = false;
} else {
this.hasPicture = true;
}
this.needExpand = this.checkItemNeedExpand()
}
checkItemNeedExpand() {
if (this.itemData.contentType === Constants.NOTIFICATION_TYPE_BASIC && (!(this.itemData.actionButtons?.length > 0))) {
return false;
} else {
return true;
}
}
aboutToDisappear() {
@@ -86,76 +63,12 @@ export default struct NotificationItem {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
Row() {
Column() {
titleItem({
notificationSmallIcon: this.itemData.smallIcon,
notificationName: this.itemData.appName,
notificationTime: this.itemData.time,
isExpand: $isExpand,
needExpand: this.needExpand
})
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start }) {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start }) {
if (this.itemData.contentType === Constants.NOTIFICATION_TYPE_BASIC) {
basicItem({
itemData: this.itemData
});
}
if (this.itemData.contentType === Constants.NOTIFICATION_TYPE_LONG) {
longItem({
itemData: this.itemData,
isExpand: this.isExpand
});
}
if (this.itemData.contentType === Constants.NOTIFICATION_TYPE_MULTILINE) {
multiItem({
itemData: this.itemData,
isExpand: this.isExpand
});
}
if (this.itemData.contentType === Constants.NOTIFICATION_TYPE_PICTURE) {
pictureItem({
itemData: this.itemData,
isExpand: this.isExpand
});
}
}
.width(this.hasPicture ? '85%' : '100%')
.margin({ top: $r('app.float.body_margin_top') })
if (this.hasPicture) {
Column() {
Image(this.itemData.largeIcon)
.objectFit(ImageFit.Contain)
.width(50)
.height(50)
}
.alignItems(HorizontalAlign.End)
.margin({ top: $r('app.float.body_margin_top') })
.width('15%')
}
}
.onClick(() => {
ViewModel.clickItem(this.itemData);
})
if (this.isExpand) {
ActionComponent({ itemData: this.itemData })
if (CheckEmptyUtils.isEmpty(this.itemData.template)) {
GeneralItem({ generalItemData: this.itemData })
} else {
CustomItem({ customItemData: this.itemData })
}
}
.backgroundColor($r('app.color.notificationitem_background'))
.opacity($r('app.float.item_opicaty'))
.borderRadius($r('app.float.item_borderradius'))
.margin({
left: $r('app.float.item_marginleft'),
right: $r('app.float.item_marginright'),
top: $r('app.float.item_margintop')
})
.padding({
left: $r('app.float.item_paddingleft'),
right: $r('app.float.item_paddingright'),
bottom: this.isExpand ? 0 : $r('app.float.item_paddingbottom')
})
.onTouch(this.touchNotificationItem.bind(this))
.width(this.itemWidth)
@@ -167,13 +80,15 @@ export default struct NotificationItem {
.width($r('app.float.item_delete_image_width'))
.height($r('app.float.item_delete_image_height'))
.onClick(this.showSettingDialog.bind(this))
Image($r('app.media.delete')) //delete
.objectFit(ImageFit.Contain)
.width($r('app.float.item_delete_image_width'))
.height($r('app.float.item_delete_image_height'))
.onClick(() => {
ViewModel.removeNotificationItem(this.itemData, true);
})
if (this.itemData.isRemoveAllowed) {
Image($r('app.media.delete')) //delete
.objectFit(ImageFit.Contain)
.width($r('app.float.item_delete_image_width'))
.height($r('app.float.item_delete_image_height'))
.onClick(() => {
ViewModel.removeNotificationItem(this.itemData, true);
})
}
}
}
.width('30%')
@@ -15,6 +15,7 @@
import Log from '../../../../../../../../../common/src/main/ets/default/Log.ets';
import media from '@ohos.multimedia.media';
import vibrator from '@ohos.vibrator';
import wantAgent from '@ohos.wantAgent';
import SourceType from '@ohos.notification'
import NotificationService from '../model/NotificationService.ets'
@@ -30,20 +31,20 @@ const GROUP_THRESHOLD = 10;
* Notification ViewModel class.
*/
export class ViewModel {
audioPlayer: any
audioPlayer: any;
mNotificationList: any[];
mAppNotificationCount: any;
mCallback: any;
mNotificationCtrl: any = {}
mNotificationCtrl: any = {};
constructor() {
let tempLink = AppStorage.SetAndLink('notificationList', []);
this.mNotificationList = tempLink.get();
this.mAppNotificationCount = new Map();
this.audioPlayer = media.createAudioPlayer();
this.audioPlayer.src = 'file://system/etc/Light.ogg';
this.audioPlayer.src = 'file://system/etc/capture.ogg';
this.registerCallback();
this.loadFlowControlInfos()
this.loadFlowControlInfos();
}
registerCallback() {
@@ -59,13 +60,17 @@ export class ViewModel {
NotificationService.unRegister(this.mCallback);
}
/**
* notification CancelCallback
*
* @param {Object} data - return notificationItemData.
*/
onNotificationConsume(notificationItemData) {
if (notificationItemData === undefined) {
Log.showInfo(TAG, `onNotificationConsume notificationItemData is undefined`);
return;
}
this.onNotificationCancel(notificationItemData)
Log.showInfo(TAG, `onNotificationConsume ${JSON.stringify(notificationItemData)}`);
//Verify the notifications can be displayed
if (!this.isCanShow(notificationItemData.bundleName)) {
@@ -79,12 +84,18 @@ export class ViewModel {
if (this.mAppNotificationCount[notificationItemData.appName] >= GROUP_THRESHOLD) {
this.groupNotification(notificationItemData, this.mAppNotificationCount[notificationItemData.appName]);
} else {
// Todo Sort Insert
this.mNotificationList.unshift(notificationItemData);
this.updateFlowControlInfos(notificationItemData.bundleName, true)
if (notificationItemData.ruleData.isAllowStatusBarShow) {
//TODO statusbar show
}
if (notificationItemData.ruleData.isAllowNotificationListShow) {
this.mNotificationList.unshift(notificationItemData);
Log.showInfo(TAG, `reminder start `);
this.reminderWay(notificationItemData);
Log.showInfo(TAG, `reminder end `);
this.updateFlowControlInfos(notificationItemData.bundleName, true)
}
this.updateNotification();
}
// Todo doAction(notificationItemData);
}
/**
@@ -130,12 +141,12 @@ export class ViewModel {
}
updateNotification() {
Log.showInfo(TAG, `updateNotification list: ${JSON.stringify(this.mNotificationList)}`);
Log.showInfo(TAG, `updateNotification len: ${this.mNotificationList.length}`);
Log.showInfo(TAG, `updateNotification list: ${JSON.stringify(this.mNotificationList)}`);
Log.showInfo(TAG, `updateNotification length: ${this.mNotificationList.length}`);
this.sortNotification()
let listLink = AppStorage.Link('notificationList');
listLink.set(this.mNotificationList);
Log.showInfo(TAG, `updateNotification list: ${JSON.stringify(listLink.get())}`);
Log.showInfo(TAG, `updateNotification list: ${JSON.stringify(listLink.get())}`);
}
/**
@@ -170,12 +181,12 @@ export class ViewModel {
if (this.mNotificationList == undefined || this.mNotificationList == null || this.mNotificationList.length < 1) {
this.mNotificationList = []
} else {
let index = this.mNotificationList.length
while (index--) {
Log.showInfo(TAG, `mNotificationList[${index}].source: ${this.mNotificationList[index].source}`);
//Except the Long term notifications
if (this.mNotificationList[index].source != SourceType.TYPE_CONTINUOUS) {
if (this.mNotificationList[index].isRemoveAllowed &&
!this.mNotificationList[index].isOngoing && !this.mNotificationList[index].isUnremovable) {
Log.showInfo(TAG, `mNotificationList[${index}].hashcode: ${this.mNotificationList[index].hashcode}`);
let hashCode = this.mNotificationList[index].hashcode
this.removeSysNotificationItem(hashCode)
@@ -302,6 +313,39 @@ export class ViewModel {
Log.showInfo(TAG, `updateFlowControlInfos:${JSON.stringify(this.mNotificationCtrl)}`);
}
reminderWay(itemData) {
if (itemData.ruleData.isAllowBanner) {
//TODO banner notification
}
if (itemData.ruleData.isAllowSound) {
try {
this.audioPlayer.src = itemData.sound;
Log.showInfo(TAG, `sound start `);
this.audioPlayer.play();
Log.showInfo(TAG, `sound end `);
} catch (e) {
Log.showInfo(TAG, `sound notificationItem id${itemData.id} alert error: ${e.toString()}`);
}
}
if (itemData.ruleData.isAllowVibrationValues) {
Log.showInfo(TAG, `vibrate start`);
for (let i = 0, len = itemData.vibrationValues.length; i < len; i++) {
vibrator.vibrate(itemData.vibrationValues[i], function(error){
Log.showInfo(TAG, `vibrate id${i}`);
if (error) {
Log.showInfo(TAG, "error.code" + error.code + "error.message" + error.message);
} else {
Log.showInfo(TAG, "Callback returned to indicate a successful vibration.");
}
})
}
}
}
getPluginTempLate(templateName) {
Log.showInfo(TAG, 'getPluginTempLate: ' + templateName);
return NotificationService.getPluginTempLate(templateName)
}
}
let viewModel = new ViewModel();
@@ -17,6 +17,7 @@
"deliveryWithInstall": true,
"moduleName": "signalcomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -18,6 +18,7 @@
"deliveryWithInstall": true,
"moduleName": "statusbarcomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -0,0 +1,124 @@
/*
* Copyright (c) 2021 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 display from '@ohos.display'
import Log from '../../../../../../../../common/src/main/ets/default/Log.ets'
import ResourceUtil from '../../../../../../../../common/src/main/ets/default/ResourceUtil.ets'
const TAG = 'StatusBarConfiguration';
var statusbarPosition;
var directionStatus;
var shortSideLength = '0';
var maxWidth;
var maxHeight;
var minHeight;
var realWidth;
var realHeight;
var xCoordinate = 0;
var yCoordinate = 0;
enum Position {
NOT_CONFIGURED,
LEFT_POSITION,
TOP_POSITION,
RIGHT_POSITION,
BOTTOM_POSITION
}
/**
* Get window size.
*/
class StatusBarConfiguration {
async initStatusBarConfiguration() {
Log.showInfo(TAG, 'initWindowManager');
minHeight = AppStorage.SetAndLink("minHeight", 0);
await display.getDefaultDisplay()
.then(dis => {
maxWidth = dis.width;
maxHeight = dis.height;
Log.showInfo(TAG, `initWindowManager maxWidth ${maxWidth} maxHeight ${maxHeight} minHeight ${minHeight.get()}`);
})
}
async getDirectionAndPosition() {
Log.showInfo(TAG, 'getDirectionAndPosition' + 1);
directionStatus = await ResourceUtil.getConfiguration();
Log.showInfo(TAG, 'getDirectionAndPosition' + 2);
if (directionStatus.direction == -1) {
Log.showInfo(TAG, 'getDirectionAndPosition' + 3);
statusbarPosition = await ResourceUtil.getString($r("app.string.status_bar_position_landscape"))
shortSideLength = await ResourceUtil.getString($r("app.string.status_bar_size_landscape"));
} else if (directionStatus.direction == 1) {
statusbarPosition = await ResourceUtil.getString($r("app.string.status_bar_position_landscape"))
shortSideLength = await ResourceUtil.getString($r("app.string.status_bar_size_landscape"));
} else {
statusbarPosition = await ResourceUtil.getString($r("app.string.status_bar_position_portrait"))
shortSideLength = await ResourceUtil.getString($r("app.string.status_bar_size_portrait"));
}
Log.showInfo(TAG, 'getDirectionAndPosition' + 4);
shortSideLength = vp2px(parseInt(shortSideLength)) + '';
Log.showInfo(TAG, 'directionStatus = ' + directionStatus.direction);
Log.showInfo(TAG, 'statusbarPosition = ' + statusbarPosition);
Log.showInfo(TAG, 'lpx2px(parseInt(shortSideLength)) = ' + shortSideLength);
}
/**
* Get status bar configuration
*/
public async getConfiguration() {
await this.initStatusBarConfiguration();
await this.getDirectionAndPosition();
if (statusbarPosition == Position.TOP_POSITION || statusbarPosition == Position.BOTTOM_POSITION) {
AppStorage.Set("showHorizontal", true);
minHeight.set(parseInt(shortSideLength));
realWidth = maxWidth;
realHeight = parseInt(shortSideLength);
if (statusbarPosition == Position.BOTTOM_POSITION) {
yCoordinate = parseInt(maxHeight) - parseInt(shortSideLength);
} else {
AppStorage.Set("ableToMaximize", true);
}
} else if (statusbarPosition == Position.LEFT_POSITION || statusbarPosition == Position.RIGHT_POSITION) {
AppStorage.Set("showHorizontal", false);
AppStorage.Set("ableToMaximize", false);
minHeight.set(parseInt(shortSideLength));
realWidth = parseInt(shortSideLength);
realHeight = maxHeight;
if (statusbarPosition == Position.RIGHT_POSITION) {
xCoordinate = parseInt(maxWidth) - parseInt(shortSideLength);
}
} else {
realWidth = 0;
realHeight = 0;
}
Log.showInfo(TAG, `initWindowManager xCoordinate ${xCoordinate} yCoordinate ${yCoordinate}`);
Log.showInfo(TAG, `initWindowManager realWidth ${realWidth} realHeight ${realHeight}`);
var configuration = {
realWidth: realWidth,
realHeight: realHeight,
xCoordinate: xCoordinate,
yCoordinate: yCoordinate
}
return configuration;
}
}
let statusBarConfiguration = new StatusBarConfiguration();
export default statusBarConfiguration;
@@ -37,6 +37,7 @@ export default struct StatusBarComponent {
@StorageLink('maxHeight') @Watch('onSizeUpdated') maxHeight: number = 0
@StorageLink('minHeight') @Watch('onSizeUpdated') minHeight: number = 0
@StorageLink('StatusBarComponentIsStart') mIsStart: boolean = false
@StorageLink("showHorizontal") showHorizontal: boolean = AppStorage.SetAndLink("showHorizontal", true).get();
aboutToAppear() {
Log.showInfo(TAG, `aboutToAppear Start, mStatusBarComponentConfig: ${JSON.stringify(this.mStatusBarComponentConfig)}`)
@@ -72,28 +73,53 @@ export default struct StatusBarComponent {
}
build() {
Row() {
StatusBarGroup({
mColor: this.mStatusBarColor,
mComponents: this.mStatusBarLayout[0],
mLayoutWeight: 1,
mAlignItems: HorizontalAlign.Start
})
StatusBarGroup({
mColor: this.mStatusBarColor,
mComponents: this.mStatusBarLayout[1],
mLayoutWeight: 0,
mAlignItems: HorizontalAlign.Center
})
StatusBarGroup({
mColor: this.mStatusBarColor,
mComponents: this.mStatusBarLayout[2],
mLayoutWeight: 1,
mAlignItems: HorizontalAlign.End
})
if (this.showHorizontal) {
Row() {
StatusBarGroup({
mColor: this.mStatusBarColor,
mComponents: this.mStatusBarLayout[0],
mLayoutWeight: 1,
mAlignItems: HorizontalAlign.Start
})
StatusBarGroup({
mColor: this.mStatusBarColor,
mComponents: this.mStatusBarLayout[1],
mLayoutWeight: 0,
mAlignItems: HorizontalAlign.Center
})
StatusBarGroup({
mColor: this.mStatusBarColor,
mComponents: this.mStatusBarLayout[2],
mLayoutWeight: 1,
mAlignItems: HorizontalAlign.End
})
}
.width('100%')
.height('100%')
} else {
Column() {
StatusBarGroup({
mColor: this.mStatusBarColor,
mComponents: this.mStatusBarLayout[0],
mLayoutWeight: 1,
mAlignItems: VerticalAlign.Center
})
StatusBarGroup({
mColor: this.mStatusBarColor,
mComponents: this.mStatusBarLayout[1],
mLayoutWeight: 0,
mAlignItems: VerticalAlign.Center
})
StatusBarGroup({
mColor: this.mStatusBarColor,
mComponents: this.mStatusBarLayout[2],
mLayoutWeight: 1,
mAlignItems: VerticalAlign.Center
})
}
.width('100%')
.height('100%')
}
.width('100%')
.height('100%')
}
}
@@ -104,6 +130,7 @@ struct StatusBarGroup {
@State mLayoutWeight: number = 1
@State mAlignItems: HorizontalAlign = HorizontalAlign.Center;
@StorageLink('StatusBarEmptyWidth') mStatusBarEmptyWidth: any = 0
@StorageLink("showHorizontal") showHorizontal: boolean = AppStorage.SetAndLink("showHorizontal", true).get();
aboutToAppear() {
Log.showInfo(TAG_StatusBarGroup, `aboutToAppear Start`)
@@ -115,37 +142,75 @@ struct StatusBarGroup {
}
build() {
Column() {
Row() {
ForEach(this.mComponents, (componentName: string) => {
Row() {
if (componentName == Constants.EMPTY) {
StatusBarEmptyIcon()
} else if (componentName == Constants.WIFI) {
WifiIcon()
} else if (componentName == Constants.SIGNAL) {
SignalIcon()
} else if (componentName == Constants.CLOCK) {
ClockIcon()
} else if (componentName == Constants.BATTERY) {
BatteryIcon()
} else if (componentName == Constants.CAPSULE) {
CapsuleIcon()
} else if (componentName == Constants.NOTIFICATION) {
StatusBarNotificationIcon()
} else {
IconItemComponent({
keyId: componentName,
color: this.mColor
})
if (this.showHorizontal) {
Column() {
Row() {
ForEach(this.mComponents, (componentName: string) => {
Row() {
if (componentName == Constants.EMPTY) {
StatusBarEmptyIcon()
} else if (componentName == Constants.WIFI) {
WifiIcon()
} else if (componentName == Constants.SIGNAL) {
SignalIcon()
} else if (componentName == Constants.CLOCK) {
ClockIcon()
} else if (componentName == Constants.BATTERY) {
BatteryIcon()
} else if (componentName == Constants.CAPSULE) {
CapsuleIcon()
} else if (componentName == Constants.NOTIFICATION) {
StatusBarNotificationIcon()
} else {
IconItemComponent({
keyId: componentName,
color: this.mColor
})
}
}
}
.height('100%')
}, (componentName: string) => componentName)
.height('100%')
}, (componentName: string) => componentName)
}
}
.alignItems(this.mAlignItems)
.layoutWeight(this.mLayoutWeight)
} else {
Row() {
Column() {
ForEach(this.mComponents, (componentName: string) => {
Row() {
if (componentName == Constants.EMPTY) {
StatusBarEmptyIcon()
} else if (componentName == Constants.WIFI) {
WifiIcon()
} else if (componentName == Constants.SIGNAL) {
SignalIcon()
} else if (componentName == Constants.CLOCK) {
ClockIcon()
} else if (componentName == Constants.BATTERY) {
BatteryIcon()
} else if (componentName == Constants.CAPSULE) {
CapsuleIcon()
} else if (componentName == Constants.NOTIFICATION) {
StatusBarNotificationIcon()
} else {
IconItemComponent({
keyId: componentName,
color: this.mColor
})
}
}
.width('100%')
.margin({
top: $r("app.float.status_bar_vertical_margin"),
bottom: $r("app.float.status_bar_vertical_margin")
})
}, (componentName: string) => componentName)
}
}
.alignItems(this.mAlignItems)
.layoutWeight(this.mLayoutWeight)
}
.alignItems(this.mAlignItems)
.layoutWeight(this.mLayoutWeight)
}
}
@@ -3,6 +3,10 @@
{
"name": "icon_item_fontsize",
"value": "18"
},
{
"name": "status_bar_vertical_margin",
"value": "24"
}
]
}
@@ -1,4 +0,0 @@
{
"string": [
]
}
@@ -1,4 +0,0 @@
{
"string": [
]
}
@@ -1,4 +0,0 @@
{
"string": [
]
}
@@ -18,6 +18,7 @@
"deliveryWithInstall": true,
"moduleName": "volumecomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -15,12 +15,12 @@
import audio from '@ohos.multimedia.audio';
import Log from '../../../../../../common/src/main/ets/default/Log.ets';
import settings from '@ohos.settingsnapi';
import settings from '@ohos.settings';
import featureAbility from '@ohos.ability.featureAbility';
const SYSTEMUI_AUDIOVOLUMETYPE_MEDIA = 'Audio.AudioVolumeType.MEDIA'
const SYSTEMUI_AUDIOVOLUMETYPE_MEDIA = 'settings.audio.media'
let TAG = 'Control-VolumeModel';
var mVolumeValue = AppStorage.SetAndLink('VolumeValue', 10);
var mVolumeValue = AppStorage.SetAndLink('VolumeValue', 5);
export class VolumeModel {
helper: any
@@ -72,7 +72,7 @@ export struct MyVol {
min: this.volume.minValue,
max: this.volume.maxValue,
step: 1,
style: SliderStyle.INSET
style: SliderStyle.InSet
})
.width('100%')
.blockColor(Color.Blue)
+2 -1
View File
@@ -17,6 +17,7 @@
"deliveryWithInstall": true,
"moduleName": "wificomponent",
"moduleType": "har"
}
},
"srcPath": "default"
}
}
@@ -1,4 +0,0 @@
{
"color": [
]
}
+10 -10
View File
@@ -1,10 +1,10 @@
# Project-wide Gradle settings.
# IDE (e.g. DevEco Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# If the Chinese output is garbled, please configure the following parameter.
# org.gradle.jvmargs=-Dfile.encoding=GBK
# Project-wide Gradle settings.
# IDE (e.g. DevEco Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# If the Chinese output is garbled, please configure the following parameter.
# org.gradle.jvmargs=-Dfile.encoding=GBK
+1 -1
View File
@@ -1,6 +1,6 @@
ext {
version = [
compileSdk: 7,
compileSdk: 8,
compatibleSdk: 4
]
}
+2 -1
View File
@@ -46,6 +46,7 @@
"autoDesignWidth": false
}
}
]
],
"srcPath": "default"
}
}
@@ -14,15 +14,21 @@
*/
import configManager from '../../../../../../features/navigationservice/src/main/ets/com/ohos/navigationservice/ConfigManager.ets'
import WindowManager from '../../../../../../common/src/main/ets/default/WindowManager.ets'
import NavBarConfiguration from './common/NavBarConfiguration.ets'
let mConfigMangager = configManager;
export default {
onCreate() {
async onCreate() {
console.info('Application onCreate')
let val = await NavBarConfiguration.getConfiguration();
let mWindowManager = new WindowManager();
await mWindowManager.initWindowManager();
await mWindowManager.initWindowMin(val.realWidth, val.realHeight, val.xCoordinate, val.yCoordinate)
mConfigMangager.initConfig();
},
onDestroy() {
console.info('Application onDestroy')
},
}
}
@@ -0,0 +1,154 @@
/*
* Copyright (c) 2021 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 display from '@ohos.display';
import Log from '../../../../../../../common/src/main/ets/default/Log.ets';
import ResourceUtil from '../../../../../../../common/src/main/ets/default/ResourceUtil.ets';
const TAG = 'NavBarConfiguration';
var directionNav;
var navbarPosition;
var statusbarPosition;
var navShortSideLength = '0';
var statusShortSideLength = '0';
var maxWidth;
var maxHeight;
var minHeight;
var realWidth;
var realHeight;
var xCoordinate = 0;
var yCoordinate = 0;
enum Position {
NOT_CONFIGURED,
LEFT_POSITION,
TOP_POSITION,
RIGHT_POSITION,
BOTTOM_POSITION
}
/**
* Get window size.
*/
class NavBarConfiguration {
async initNavBarConfiguration() {
Log.showInfo(TAG, 'initNavBarConfiguration');
minHeight = AppStorage.SetAndLink("minNavHeight", 0);
await display.getDefaultDisplay()
.then(dis => {
maxWidth = dis.width;
maxHeight = dis.height;
Log.showInfo(TAG, `initNavBarConfiguration maxWidth ${maxWidth} maxHeight ${maxHeight} minHeight ${minHeight.get()}`);
})
}
async getDirectionAndPosition() {
directionNav = await ResourceUtil.getConfiguration();
if (directionNav.direction == -1) {
statusbarPosition = await ResourceUtil.getString($r("app.string.status_bar_position_landscape"))
navbarPosition = await ResourceUtil.getString($r("app.string.nav_bar_position_landscape"))
statusShortSideLength = await ResourceUtil.getString($r("app.string.status_bar_size_landscape"));
navShortSideLength = await ResourceUtil.getString($r("app.string.nav_bar_size_landscape"));
} else if (directionNav.direction == 1) {
statusbarPosition = await ResourceUtil.getString($r("app.string.status_bar_position_landscape"))
navbarPosition = await ResourceUtil.getString($r("app.string.nav_bar_position_landscape"))
statusShortSideLength = await ResourceUtil.getString($r("app.string.status_bar_size_landscape"));
navShortSideLength = await ResourceUtil.getString($r("app.string.nav_bar_size_landscape"));
} else {
statusbarPosition = await ResourceUtil.getString($r("app.string.status_bar_position_portrait"))
navbarPosition = await ResourceUtil.getString($r("app.string.nav_bar_position_portrait"))
statusShortSideLength = await ResourceUtil.getString($r("app.string.status_bar_size_portrait"));
navShortSideLength = await ResourceUtil.getString($r("app.string.nav_bar_size_portrait"));
}
statusShortSideLength = vp2px(parseInt(statusShortSideLength)) + '';
navShortSideLength = vp2px(parseInt(navShortSideLength)) + '';
Log.showInfo(TAG, 'statusShortSideLength = ' + statusShortSideLength);
Log.showInfo(TAG, 'navShortSideLength = ' + navShortSideLength);
Log.showInfo(TAG, 'directionnav = ' + directionNav.direction);
Log.showInfo(TAG, 'statusbarPosition = ' + statusbarPosition);
Log.showInfo(TAG, 'NavbarPosition = ' + navbarPosition);
}
/**
* Get nav bar configuration
*/
public async getConfiguration() {
await this.initNavBarConfiguration();
await this.getDirectionAndPosition();
if (navbarPosition == Position.TOP_POSITION || navbarPosition == Position.BOTTOM_POSITION) {
AppStorage.Set("showNavHorizontal", true);
minHeight.set(parseInt(navShortSideLength));
Log.showInfo(TAG, 'TOP_POSITION = ' + 2);
if (statusbarPosition == Position.LEFT_POSITION || statusbarPosition == Position.RIGHT_POSITION) {
realWidth = parseInt(maxWidth) - parseInt(statusShortSideLength);
} else {
realWidth = maxWidth;
}
Log.showInfo(TAG, 'TOP_POSITION = ' + 3);
realHeight = parseInt(navShortSideLength);
Log.showInfo(TAG, 'TOP_POSITION = ' + 4);
if (statusbarPosition == Position.LEFT_POSITION) {
xCoordinate = parseInt(statusShortSideLength);
} else {
xCoordinate = 0;
}
Log.showInfo(TAG, 'TOP_POSITION = ' + 5);
if (navbarPosition == Position.BOTTOM_POSITION) {
yCoordinate = parseInt(maxHeight) - parseInt(navShortSideLength);
Log.showInfo(TAG, 'BOTTOM_POSITION = ' + yCoordinate);
}
} else if (navbarPosition == Position.LEFT_POSITION || navbarPosition == Position.RIGHT_POSITION) {
AppStorage.Set("showNavHorizontal", false);
minHeight.set(parseInt(navShortSideLength));
if (statusbarPosition == Position.TOP_POSITION || statusbarPosition == Position.BOTTOM_POSITION) {
realHeight = parseInt(maxHeight) - parseInt(statusShortSideLength);
} else {
realHeight = maxHeight;
}
realWidth = parseInt(navShortSideLength);
if (statusbarPosition == Position.TOP_POSITION) {
yCoordinate = parseInt(statusShortSideLength);
} else {
yCoordinate = 0;
}
if (navbarPosition == Position.RIGHT_POSITION) {
xCoordinate = parseInt(maxWidth) - parseInt(navShortSideLength);
}
} else {
realWidth = 0;
realHeight = 0;
}
Log.showInfo(TAG, `initWindowManager xCoordinate ${xCoordinate} yCoordinate ${yCoordinate}`);
Log.showInfo(TAG, `initWindowManager realWidth ${realWidth} realHeight ${realHeight}`);
var configuration = {
realWidth: realWidth,
realHeight: realHeight,
xCoordinate: xCoordinate,
yCoordinate: yCoordinate
}
return configuration;
}
}
let navBarConfiguration = new NavBarConfiguration();
export default navBarConfiguration;
@@ -16,32 +16,31 @@
import Three from './threeLayout.ets'
import Log from '../../../../../../../common/src/main/ets/default/Log.ets';
import HeightConfigUtils from '../../../../../../../common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ets';
import Constants from '../common/constants.ets'
const STORAGE_NAVIGATION_TYPE = 'navigationType'
let mConfigReader;
let mHeightConfigUtils;
const TAG = 'NavigationBar-Index';
@Entry
@Component
struct Index {
@StorageLink('navigationLayoutConfig') mConfig: any = {}
@StorageLink('NavMinH') NavMinH:number = 32
@StorageLink('minNavHeight') minNavHeight: number = 32
@StorageLink("showNavHorizontal") showNavHorizontal: boolean = true
onBackPress(): boolean {
return true;
}
aboutToAppear() {
Log.showInfo(TAG, `aboutToAppear Start`)
mHeightConfigUtils = new HeightConfigUtils();
let NavMinH = AppStorage.SetAndLink("NavMinH", 32);
let NavCoefficient = AppStorage.SetAndLink("NavCoefficient", 1.0);
NavMinH.set(mHeightConfigUtils.getNavMinH());
NavCoefficient.set(mHeightConfigUtils.getNavHCoefficient());
}
aboutToDisappear(){
aboutToDisappear() {
Log.showInfo(TAG, `aboutToDisAppear`)
}
@@ -51,8 +50,8 @@ struct Index {
}
.width('100%')
.height('100%')
.constraintSize({ minHeight: this.NavMinH })
.constraintSize({ minHeight: this.minNavHeight })
.backgroundColor($r('app.color.index_background'))
.padding({ left: '18%', right: '18%' })
.padding(this.showNavHorizontal ? { left: '18%', right: '18%' } : { top: '18%', bottom: '18%' })
}
}
@@ -27,6 +27,7 @@ export default struct keyButton {
@Prop keyCode: number;
@State backGroundColor: any = $r('app.color.button_default_background');
@StorageLink('NavCoefficient') NavCoefficient:number = 1.0
@StorageLink("showNavHorizontal") showNavHorizontal: boolean = AppStorage.SetAndLink("showNavHorizontal", true).get();
aboutToAppear() {
Log.showInfo(TAG, `aboutToAppear Start`)
@@ -48,8 +49,8 @@ export default struct keyButton {
.size({ width: Constants.IMAGE_WIDTH*this.NavCoefficient, height:Constants.IMAGE_HEIGHT*this.NavCoefficient })
}
.onTouch(this.onKeyTouch.bind(this))
.width(Constants.BUTTON_WIDTH*this.NavCoefficient)
.height('100%')
.width(this.showNavHorizontal ? Constants.BUTTON_WIDTH*this.NavCoefficient : '100%')
.height(this.showNavHorizontal ? '100%' : Constants.BUTTON_WIDTH*this.NavCoefficient )
}
private onKeyTouch(event:TouchEvent) {
@@ -26,7 +26,7 @@ let KeyCodeArr: any[] = [
@Component
export default struct oneLayout {
@StorageLink('NavMinH') NavMinH:number = 32
@StorageLink('minNavHeight') minNavHeight:number = 32
aboutToAppear() {
Log.showInfo(TAG, `aboutToAppear Start`)
@@ -46,7 +46,7 @@ export default struct oneLayout {
})
}
.height('100%')
.constraintSize({ minHeight: this.NavMinH })
.constraintSize({ minHeight: this.minNavHeight })
.align(Alignment.Center)
})
}
@@ -35,8 +35,8 @@ let KeyCodeArr: any[] = [
@Component
export default
struct threeLayout {
@StorageLink('NavMinH') NavMinH:number = 32
@StorageLink('minNavHeight') minNavHeight:number = 32
@StorageLink("showNavHorizontal") showNavHorizontal: boolean = AppStorage.SetAndLink("showNavHorizontal", false).get();
aboutToAppear() {
Log.showInfo(TAG, `aboutToAppear Start`)
}
@@ -46,18 +46,34 @@ struct threeLayout {
}
build() {
Grid() {
ForEach(KeyCodeArr, (item: any) => {
GridItem() {
keyButton({ uri: item.uri, keyCode: item.keyCode })
}
.height('100%')
.constraintSize({ minHeight: this.NavMinH })
.align(Alignment.Center)
})
if (this.showNavHorizontal) {
Grid() {
ForEach(KeyCodeArr, (item: any) => {
GridItem() {
keyButton({ uri: item.uri, keyCode: item.keyCode })
}
.height('100%')
.constraintSize({ minHeight: this.minNavHeight })
.align(Alignment.Center)
})
}
.columnsTemplate(Constants.THREE_TEMPLATE)
.height('100%')
.align(Alignment.Center);
} else {
Grid() {
ForEach(KeyCodeArr, (item: any) => {
GridItem() {
keyButton({ uri: item.uri, keyCode: item.keyCode })
}
.width('100%')
.constraintSize({ minHeight: this.minNavHeight })
.align(Alignment.Center)
})
}
.rowsTemplate(Constants.THREE_TEMPLATE)
.width('100%')
.align(Alignment.Center);
}
.columnsTemplate(Constants.THREE_TEMPLATE)
.height('100%')
.align(Alignment.Center);
}
}
@@ -1,9 +1,41 @@
{
"string": [
{
"name": "nav_bar_size_portrait",
"value": "52"
},
{
"name": "nav_bar_size_landscape",
"value": "52"
},
{
"name": "nav_bar_position_portrait",
"value": "4"
},
{
"name": "nav_bar_position_landscape",
"value": "4"
},
{
"name": "app_name",
"value": "NavigationBar"
},
{
"name": "status_bar_size_portrait",
"value": "52"
},
{
"name": "status_bar_size_landscape",
"value": "52"
},
{
"name": "status_bar_position_portrait",
"value": "1"
},
{
"name": "status_bar_position_landscape",
"value": "2"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
@@ -1,9 +1,41 @@
{
"string": [
{
"name": "nav_bar_size_portrait",
"value": "52"
},
{
"name": "nav_bar_size_landscape",
"value": "52"
},
{
"name": "nav_bar_position_portrait",
"value": "1"
},
{
"name": "nav_bar_position_landscape",
"value": "4"
},
{
"name": "app_name",
"value": "NavigationBar"
},
{
"name": "status_bar_size_portrait",
"value": "52"
},
{
"name": "status_bar_size_landscape",
"value": "52"
},
{
"name": "status_bar_position_portrait",
"value": "1"
},
{
"name": "status_bar_position_landscape",
"value": "2"
},
{
"name": "mainability_description",
"value": "JS_Phone_Empty Feature Ability"
@@ -1,8 +1,40 @@
{
"string": [
{
"name": "nav_bar_size_portrait",
"value": "52"
},
{
"name": "nav_bar_size_landscape",
"value": "52"
},
{
"name": "nav_bar_position_portrait",
"value": "1"
},
{
"name": "nav_bar_position_landscape",
"value": "4"
},
{
"name": "app_name",
"value": "navigationBar"
"value": "NavigationBar"
},
{
"name": "status_bar_size_portrait",
"value": "52"
},
{
"name": "status_bar_size_landscape",
"value": "52"
},
{
"name": "status_bar_position_portrait",
"value": "1"
},
{
"name": "status_bar_position_landscape",
"value": "2"
},
{
"name": "mainability_description",
@@ -50,6 +50,7 @@
"pages/setEnable"
]
}
]
],
"srcPath": "default"
}
}
+2 -1
View File
@@ -44,6 +44,7 @@
},
"pages": ["pages/index"]
}
]
],
"srcPath": "default"
}
}
+13 -6
View File
@@ -12,12 +12,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import WindowManager from '../../../../../../common/src/main/ets/default/WindowManager.ets'
import StatusBarConfiguration from '../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/common/StatusBarConfiguration.ets';
export default {
onCreate() {
console.info('SystemUI statusBar Application onCreate')
},
onDestroy() {
console.info('SystemUI statusBar Application onDestroy')
},
async onCreate() {
console.info('SystemUI statusBar Application onCreate')
let val = await StatusBarConfiguration.getConfiguration();
let mWindowManager = new WindowManager();
await mWindowManager.initWindowManager();
await mWindowManager.initWindowMin(val.realWidth, val.realHeight, val.xCoordinate, val.yCoordinate)
},
onDestroy() {
console.info('SystemUI statusBar Application onDestroy')
},
}
@@ -16,13 +16,14 @@
import Log from '../../../../../../../common/src/main/ets/default/Log.ets'
import ReadConfigUtil from '../../../../../../../common/src/main/ets/default/ReadConfigUtil.ets'
import Notification from './notification.ets'
import WindowManager from '../../../../../../../common/src/main/ets/default/WindowManager.ets'
import ControlCenterComponent from './control.ets'
import Constants from './common/constants.ets'
import NavigationEvent from './common/navigationEvent.ets'
import mBrightnessManager from '../../../../../../../features/brightnesscomponent/src/main/ets/default/brightnessManager.ets';
import HeightConfigUtils from '../../../../../../../common/src/main/ets/default/heightcofigUtils/HeightConfigUtils.ets';
import StatusBarComponent from '../../../../../../../features/statusbarcomponent/src/main/ets/com/ohos/pages/StatusBarComponent.ets';
import WindowManager from '../../../../../../../common/src/main/ets/default/WindowManager.ets';
import Window from '@ohos.window';
const STATUS_BAR_COMPONENT_CONFIG_FILE_PATH = "/data/accounts/account_0/applications/com.ohos.systemui/" +
"com.ohos.systemui.statusbar/assets/statusbar/resources/rawfile/statusbarcomponentConfig.json";
@@ -43,6 +44,8 @@ struct Index {
@State moveX: number = 0
@State moveY: number = 0
@StorageLink("showStatusBar") showStatusBar: boolean = true
@StorageLink("showHorizontal") showHorizontal: boolean = true
@StorageLink("ableToMaximize") ableToMaximize: boolean = true
@StorageLink('minHeight') minHeight: number = 0
@StorageLink('maxWidth') maxWidth: number = 0
@StorageLink('StatusMinH') StatusMinH: number = 24
@@ -56,8 +59,7 @@ struct Index {
}
aboutToAppear() {
Log.showInfo(TAG, `aboutToAppear, showStatusBar: ${this.showStatusBar}`);
Log.showInfo(TAG, `aboutToAppear, start showStatusBar: ${this.showStatusBar}`);
mHeightConfigUtils = new HeightConfigUtils();
let StatusMinH;
let StatusCoefficient;
@@ -85,17 +87,19 @@ struct Index {
mWindowManager = new WindowManager();
mWindowManager.initWindowManager();
this.mCallback = {
"onStateChange": this.onStateChange.bind(this)
}
NavigationEvent.registerCallback(this.mCallback);
Log.showInfo(TAG, `aboutToAppear, end showStatusBar: ${this.showStatusBar}`);
}
onStateChange(data) {
this.showStatusBar = true;
mWindowManager.setWindowMin((result) => {
})
if (this.ableToMaximize) {
this.showStatusBar = true;
mWindowManager.setWindowMin((result) => {
})
}
}
aboutToDisappear() {
@@ -115,7 +119,7 @@ struct Index {
.height('100%')
.backgroundColor($r("app.color.statusbar_background"))
.onTouch(this.touchEvent.bind(this))
} else {
} else if (this.showHorizontal && this.ableToMaximize) {
if (vp2px(this.startX) <= parseInt((this.maxWidth / 2).toString())) {
Notification({ showStatusBar: $showStatusBar, minHeight: this.minHeight })
} else {
@@ -134,7 +138,9 @@ struct Index {
touchEvent(event: TouchEvent) {
Log.showInfo(TAG, 'touchEvent================' + event.touches)
Log.showInfo(TAG, 'touchEvent================ stringfy' + JSON.stringify(event.touches))
if (!this.showHorizontal && !this.ableToMaximize) {
return;
}
if (event.type == Constants.TOUCHTYPE_DOWN) { //down
this.startX = event.touches[0].screenX
this.startY = event.touches[0].screenY
@@ -1,4 +1,4 @@
{
{
"float": [
{
"name": "statusbar_height",
@@ -1,5 +1,21 @@
{
"string": [
{
"name": "status_bar_size_portrait",
"value": "52"
},
{
"name": "status_bar_size_landscape",
"value": "52"
},
{
"name": "status_bar_position_portrait",
"value": "1"
},
{
"name": "status_bar_position_landscape",
"value": "2"
},
{
"name": "app_name",
"value": "SystemUI"
@@ -1,5 +1,21 @@
{
"string": [
{
"name": "status_bar_size_portrait",
"value": "52"
},
{
"name": "status_bar_size_landscape",
"value": "52"
},
{
"name": "status_bar_position_portrait",
"value": "1"
},
{
"name": "status_bar_position_landscape",
"value": "2"
},
{
"name": "app_name",
"value": "SystemUI"
@@ -1,5 +1,21 @@
{
"string": [
{
"name": "status_bar_size_portrait",
"value": "52"
},
{
"name": "status_bar_size_landscape",
"value": "52"
},
{
"name": "status_bar_position_portrait",
"value": "1"
},
{
"name": "status_bar_position_landscape",
"value": "2"
},
{
"name": "app_name",
"value": "SystemUI"