diff --git a/.gitattributes b/.gitattributes
index 51c63e29..6e4add21 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -13,3 +13,7 @@
*.so filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.dll filter=lfs diff=lfs merge=lfs -text
+*.dat filter=lfs diff=lfs merge=lfs -text
+*.bz2 filter=lfs diff=lfs merge=lfs -text
+*.bz filter=lfs diff=lfs merge=lfs -text
+*.gif filter=lfs diff=lfs merge=lfs -text
diff --git a/OAT.xml b/OAT.xml
new file mode 100644
index 00000000..de3b034c
--- /dev/null
+++ b/OAT.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/README.md b/README.md
index 71a9881a..b0fce4a9 100755
--- a/README.md
+++ b/README.md
@@ -39,5 +39,5 @@ The home screen launcher provides a main entry to human-machine interactions. It
System apps
-**applications\_launcher**
+**applications\_standard\_launcher**
diff --git a/README_zh.md b/README_zh.md
index a3c67ceb..8ab6c759 100755
--- a/README_zh.md
+++ b/README_zh.md
@@ -39,4 +39,4 @@
系统应用
-**applications\_launcher**
+**applications\_standard\_launcher**
diff --git a/launcher/src/main/config.json b/launcher/src/main/config.json
index fb38740b..df83fe1e 100644
--- a/launcher/src/main/config.json
+++ b/launcher/src/main/config.json
@@ -3,7 +3,7 @@
"bundleName": "com.ohos.launcher",
"vendor": "ohos",
"version": {
- "code": 1,
+ "code": 1000000,
"name": "1.0"
},
"apiVersion": {
@@ -21,7 +21,8 @@
"distro": {
"deliveryWithInstall": true,
"moduleName": "launcher",
- "moduleType": "entry"
+ "moduleType": "entry",
+ "installationFree": true
},
"abilities": [
{
@@ -57,8 +58,7 @@
"pages": [
"pages/EntryView/EntryView",
"pages/AppGridView/AppGridView",
- "pages/AppListView/AppListView",
- "pages/SettingsView/SettingsView"
+ "pages/AppListView/AppListView"
],
"name": "default",
"window": {
diff --git a/launcher/src/main/js/default/app.js b/launcher/src/main/js/default/app.js
index d2f36d8f..ac0fffc2 100644
--- a/launcher/src/main/js/default/app.js
+++ b/launcher/src/main/js/default/app.js
@@ -15,18 +15,30 @@
import AppModel from './common/model/AppModel.js'
import SettingsModel from './common/model/SettingsModel.js'
+import MMIModel from './common/model/MMIModel.js'
+import ResourceManager from './common/model/ResourceManager.js'
+import AppListInfoCacheManager from './common/cache/AppListInfoCacheManager.js'
export default {
- data: {
+ data:{
appModel: new AppModel(),
- settingsModel: new SettingsModel()
+ settingsModel: new SettingsModel(),
+ mmiModel: new MMIModel(),
+ resourceManager: new ResourceManager(),
+ appListInfoCacheManager: new AppListInfoCacheManager(),
+ screenHeight: 0,
+ screenWidth: 0
},
onCreate() {
- console.info("Application onCreate");
+ console.info("Launcher app Application onCreate");
+ this.data.appModel.registerAppListEvent();
},
onDestroy() {
- console.info("Application onDestroy");
+ console.info("Launcher app Application onDestroy");
+ this.data.resourceManager.clearCache();
+ this.data.appListInfoCacheManager.clearCache();
+ this.data.appModel.unregisterAppListEvent();
}
};
diff --git a/launcher/src/main/js/default/common/cache/AppListInfoCacheManager.js b/launcher/src/main/js/default/common/cache/AppListInfoCacheManager.js
new file mode 100644
index 00000000..7d0b899c
--- /dev/null
+++ b/launcher/src/main/js/default/common/cache/AppListInfoCacheManager.js
@@ -0,0 +1,67 @@
+/*
+ * 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 LruCache from './LruCache.js';
+import DiskLruCache from './DiskLruCache.js';
+
+/**
+ * A Manager class that provides get/set/clear cache methods for app list data.
+ */
+export default class AppListInfoCacheManager {
+ #lruCache;
+ #diskLruCache;
+
+ constructor() {
+ this.#lruCache = new LruCache();
+ this.#diskLruCache = new DiskLruCache();
+ }
+
+ /**
+ * Get cache from disk or memory.
+ *
+ * @param {string} key - key of the cache map
+ * @return {object} - cache get from the memory or disk
+ */
+ getCache(key) {
+ console.info("Launcher AppListInfoCacheManager getCache key = " + key);
+ let cache = this.#lruCache.getCache(key);
+ if (cache == undefined || cache == null || cache == '' || cache == -1) {
+ return this.#diskLruCache.getCache(key);
+ } else {
+ return cache;
+ }
+ }
+
+ /**
+ * Set cache to disk or memory.
+ *
+ * @param {string} key - key of the cache map
+ * @param {object} value - value of the cache map
+ */
+ setCache(key, value) {
+ console.info("Launcher AppListInfoCacheManager setCache key = " + key + " value = " + value);
+ this.#lruCache.putCache(key, value);
+ this.#diskLruCache.putCache(key, value);
+ }
+
+ /**
+ * Clear cache of both disk and memory.
+ */
+ clearCache() {
+ console.info("Launcher AppListInfoCacheManager clearCache");
+ this.#lruCache.clear();
+ this.#diskLruCache.clear();
+ }
+}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/cache/AppResourceCacheManager.js b/launcher/src/main/js/default/common/cache/AppResourceCacheManager.js
new file mode 100644
index 00000000..84151611
--- /dev/null
+++ b/launcher/src/main/js/default/common/cache/AppResourceCacheManager.js
@@ -0,0 +1,105 @@
+/*
+ * 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 LruCache from './LruCache.js'
+import DiskLruCache from './DiskLruCache.js'
+
+const KEY_ICON = "icon";
+const DISK_CACHE_MISS = -1;
+
+/**
+ * A Manager class that provides get/set/clear cache methods for app image data.
+ */
+export default class AppResourceCacheManager {
+ #memoryCache;
+ #diskCache;
+
+ constructor() {
+ this.#memoryCache = new LruCache();
+ this.#diskCache = new DiskLruCache();
+ }
+
+ /**
+ * Get cache from disk or memory.
+ *
+ * @param {string} key - key of the cache map
+ * @return {object} - cache get from memory or disk
+ */
+ getCache(bundleName, key) {
+ console.info("Launcher AppResourceCacheManager getCache bundleName = " + bundleName + " key = " + key);
+ let cache = this.#getCacheFromMemory(bundleName, key);
+ if (cache == undefined || cache == null || cache == '') {
+ if (key === KEY_ICON) {
+ return this.#getCacheFromDisk(bundleName);
+ }
+ return null;
+ } else {
+ return cache;
+ }
+ }
+
+ /**
+ * Set cache to disk or memory.
+ *
+ * @param {string} key - key of the cache map
+ * @param {object} value - value of the cache map
+ */
+ setCache(bundleName, key, value) {
+ console.info("Launcher AppResourceCacheManager setCache bundleName = " + bundleName + " key = " + key);
+ this.#setCacheToMemory(bundleName, key, value);
+ if (key === KEY_ICON) {
+ this.#setCacheToDisk(bundleName, key, value);
+ }
+ }
+
+ /**
+ * Clear cache of both disk and memory.
+ */
+ clearCache() {
+ console.info("Launcher AppResourceCacheManager clearCache");
+ this.#memoryCache.clear();
+ }
+
+ #getCacheFromMemory = (bundleName, key) => {
+ let cache = this.#memoryCache.getCache(bundleName);
+ if (cache == undefined || cache == null || cache == '' || cache === -1) {
+ return null;
+ } else if (cache[key] == undefined || cache[key] == null || cache[key] == '') {
+ return null;
+ } else {
+ return cache[key];
+ }
+ }
+
+ #setCacheToMemory = (bundleName, key, value) => {
+ let cache = this.#memoryCache.getCache(bundleName);
+ if (cache == undefined || cache == null || cache == '' || cache === -1) {
+ cache = {};
+ cache[key] = value;
+ } else {
+ cache[key] = value;
+ }
+ this.#memoryCache.putCache(bundleName, cache);
+ }
+
+ #getCacheFromDisk = (bundleName, key) => {
+ let data = this.#diskCache.getCache(bundleName);
+ return data !== DISK_CACHE_MISS ? data : null;
+ }
+
+ #setCacheToDisk = (bundleName, key, value) => {
+ this.#diskCache.putCache(bundleName, value);
+ }
+}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/cache/DiskLruCache.js b/launcher/src/main/js/default/common/cache/DiskLruCache.js
new file mode 100644
index 00000000..9aa62611
--- /dev/null
+++ b/launcher/src/main/js/default/common/cache/DiskLruCache.js
@@ -0,0 +1,107 @@
+/*
+ * 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 FileUtils from "../utils/FileUtils.js";
+
+/**
+ * A class provides persistent operation for memory cache.
+ */
+export default class DiskLruCache {
+ constructor(capacity = 100) {
+ this.cache = new Map();
+ this.capacity = capacity;
+ this.initMap(); //read cache from local
+ }
+
+ /**
+ * Init the cache whether the file has data.
+ */
+ initMap() {
+ console.info("Launcher DiskLruCache initMap start execution");
+ try {
+ let arr = FileUtils.readJournal().split("\n").reverse();
+ let len = arr.length >= this.capacity ? this.capacity : arr.length;
+ for (let i = 0;i < len; i++) {
+ this.cache.set(arr[i], arr[i]);
+ }
+ } catch (e) {
+ console.error("Launcher DiskLruCache initMap e " + e);
+ }
+ }
+
+ /**
+ * Get cache from disk.
+ *
+ * @param {string} key - key of the cache map
+ * @return {object} - target cache object
+ */
+ getCache(key) {
+ if (this.cache.has(key)) {
+ // exist and update
+ let temp = this.cache.get(key);
+ //delete the old cache
+ this.cache.delete(key);
+ //update the cache to recent use
+ this.cache.set(key, temp);
+ //update local cache to recent use
+ FileUtils.writeJournal(key);
+ return FileUtils.readJsonObj(key)[key];
+ }
+ return -1;
+ }
+
+ /**
+ * Put cache to disk.
+ *
+ * @param {string} key - key of the cache map
+ * @param {object} value - value of the cache map
+ */
+ putCache(key, value) {
+ if (this.cache.has(key)) {
+ // exist and update
+ this.cache.delete(key);
+ } else if (this.cache.size >= this.capacity) {
+ // if size > capacity ,remove the old
+ this.remove(this.cache.keys().next().value);
+ }
+ //update the cache to recent use
+ this.cache.set(key, value);
+ //update local cache to recent use
+ FileUtils.writeJournal(key);
+ FileUtils.writeJsonObj({
+ [key] : value
+ }, key);
+ }
+
+ /**
+ * Remove cache of corresponding key.
+ *
+ * @param {string} key - key of the cache map
+ */
+ remove(key) {
+ this.cache.delete(key);
+ FileUtils.removeFile(key);
+ }
+
+ /**
+ * Clear cache of disk.
+ */
+ clear() {
+ this.cache.forEach(function (value, key) {
+ FileUtils.removeFile(key);
+ });
+ this.cache.clear();
+ }
+}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/cache/LruCache.js b/launcher/src/main/js/default/common/cache/LruCache.js
new file mode 100644
index 00000000..c92da9b4
--- /dev/null
+++ b/launcher/src/main/js/default/common/cache/LruCache.js
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+/**
+ * A class provides memory cache operation.
+ */
+export default class LruCache {
+ constructor(capacity = 100) {
+ this.cache = new Map();
+ this.capacity = capacity; //the capacity of cache
+ }
+
+ /**
+ * Get cache from memory.
+ *
+ * @param {string} key - key of the cache map
+ * @return {object} - cache from memory
+ */
+ getCache(key) {
+ if (this.cache.has(key)) {
+ // exist and update
+ let temp = this.cache.get(key);
+ //delete the old cache
+ this.cache.delete(key);
+ //update the cache to recent use
+ this.cache.set(key, temp);
+ return temp;
+ }
+ return -1;
+ }
+
+ /**
+ * Put cache to disk.
+ *
+ * @param {string} key - key of the cache map
+ * @param {object} value - value of the cache map
+ */
+ putCache(key, value) {
+ if (this.cache.has(key)) {
+ // exist and update
+ this.cache.delete(key);
+ } else if (this.cache.size >= this.capacity) {
+ // if size > capacity ,remove the old
+ this.cache.delete(this.cache.keys().next().value);
+ }
+ //update the cache to recent use
+ this.cache.set(key, value);
+ }
+
+ /**
+ * Remove cache of corresponding key.
+ *
+ * @param {string} key - key of the cache map
+ */
+ remove(key) {
+ this.cache.delete(key);
+ }
+
+ /**
+ * Clear cache of memory.
+ */
+ clear() {
+ this.cache.clear();
+ }
+}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/colors/Colors.js b/launcher/src/main/js/default/common/colors/Colors.js
index ec86b9d8..759da5f0 100644
--- a/launcher/src/main/js/default/common/colors/Colors.js
+++ b/launcher/src/main/js/default/common/colors/Colors.js
@@ -13,7 +13,10 @@
* limitations under the License.
*/
-var Colors = {
+/**
+ * Description: Color data.
+ */
+const Colors = {
bgSelectedColor: "#FF008000",
bgUnselectedColor: "white",
fontSelectedColor: "white",
diff --git a/launcher/src/main/js/default/common/component/AppIcon/AppIcon.css b/launcher/src/main/js/default/common/component/AppIcon/AppIcon.css
index bdda70d4..42e3252e 100644
--- a/launcher/src/main/js/default/common/component/AppIcon/AppIcon.css
+++ b/launcher/src/main/js/default/common/component/AppIcon/AppIcon.css
@@ -14,9 +14,8 @@
*/
@import '../../css/CommonPageStyle.css';
+
.image-box{
- height: 110px;
- width: 110px;
display: flex;
align-items: center;
justify-content: center;
diff --git a/launcher/src/main/js/default/common/component/AppIcon/AppIcon.hml b/launcher/src/main/js/default/common/component/AppIcon/AppIcon.hml
index ee550af1..6a4c3100 100644
--- a/launcher/src/main/js/default/common/component/AppIcon/AppIcon.hml
+++ b/launcher/src/main/js/default/common/component/AppIcon/AppIcon.hml
@@ -15,6 +15,6 @@
*/
-->
-
-
+
+
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/component/AppIcon/AppIcon.js b/launcher/src/main/js/default/common/component/AppIcon/AppIcon.js
index f9db09e2..93ac5806 100644
--- a/launcher/src/main/js/default/common/component/AppIcon/AppIcon.js
+++ b/launcher/src/main/js/default/common/component/AppIcon/AppIcon.js
@@ -13,10 +13,12 @@
* limitations under the License.
*/
-import ResourceManager from '../../model/ResourceManager.js';
-
-var mResourceManager;
+let mResourceManager;
+let mDefaultAppIcon;
+/**
+ * A page element that display app icon.
+ */
export default {
props: ['itemAppId', 'itemAppIcon', 'itemBundleName'],
@@ -30,23 +32,35 @@ export default {
onInit() {
this.$watch('itemBundleName','appIconWatcher');
- mResourceManager = new ResourceManager();
- mResourceManager.getAppIcon(this.itemAppIcon, this.itemBundleName, this.iconLoadCallback);
- },
-
- onShow() {
+ mDefaultAppIcon = globalThis.$globalR('image.icon_default');
+ mResourceManager = this.$app.$def.data.resourceManager;
+ mResourceManager.getAppIcon(this.itemAppIcon, this.itemBundleName, this.iconLoadCallback, mDefaultAppIcon);
},
+ /**
+ * Watch the value of appIcon, called when the value changed.
+ *
+ * @param {object} newV - New value of appIcon
+ * @param {object} oldV - Old value of appIcon
+ */
appIconWatcher(newV, oldV) {
if (newV != null && newV != undefined) {
mResourceManager.getAppIcon(this.itemAppIcon, this.itemBundleName, this.iconLoadCallback);
}
},
+ /**
+ * Callback function when appIcon loaded from the resource manager.
+ *
+ * @param {string} image - App icon base64.
+ */
iconLoadCallback(image) {
this.appIcon = image;
},
+ /**
+ * Reload the app icon base64 from resource manager.
+ */
updateIcon() {
console.info("Launcher AppIcon updateIcon in bundleName = " + this.itemBundleName);
mResourceManager.getAppIcon(this.itemAppIcon, this.itemBundleName, this.iconLoadCallback);
diff --git a/launcher/src/main/js/default/common/component/GridName/GridName.css b/launcher/src/main/js/default/common/component/GridName/GridName.css
index 2d150204..367dda90 100644
--- a/launcher/src/main/js/default/common/component/GridName/GridName.css
+++ b/launcher/src/main/js/default/common/component/GridName/GridName.css
@@ -17,8 +17,11 @@
.app-name {
text-align: center;
- width: 110px;
- height: 60px;
+ width: 100%;
+ height: 40px;
+ line-height: 27px;
color: white;
font-size: 27px;
+ max-lines: 1;
+ text-overflow: ellipsis;
}
diff --git a/launcher/src/main/js/default/common/component/GridName/GridName.js b/launcher/src/main/js/default/common/component/GridName/GridName.js
index 6dbb4bfb..14e2572a 100644
--- a/launcher/src/main/js/default/common/component/GridName/GridName.js
+++ b/launcher/src/main/js/default/common/component/GridName/GridName.js
@@ -13,10 +13,11 @@
* limitations under the License.
*/
-import ResourceManager from '../../model/ResourceManager.js';
-
-var mResourceManager;
+let mResourceManager;
+/**
+ * A page element that display app name in GridView.
+ */
export default {
props: ['itemAppId', 'itemLabelId', 'itemBundleName', 'itemAppName'],
@@ -30,26 +31,37 @@ export default {
},
onInit() {
- this.$watch('itemBundleName','appIconWatcher');
- mResourceManager = new ResourceManager();
- mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.iconLoadCallback);
+ this.$watch('itemBundleName','appNameWatcher');
+ mResourceManager = this.$app.$def.data.resourceManager;
+ mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.appNameLoadCallback);
},
- onShow() {
- },
-
- appIconWatcher(newV, oldV) {
+ /**
+ * Watch the value of appName, called when the value changed.
+ *
+ * @param {object} newV - New value of appName.
+ * @param {object} oldV - Old value of appName.
+ */
+ appNameWatcher(newV, oldV) {
if (newV != null && newV != undefined) {
- mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.iconLoadCallback);
+ mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.appNameLoadCallback);
}
},
- iconLoadCallback(name) {
+ /**
+ * Callback function when appName loaded from the resource manager.
+ *
+ * @param {string} name - App name.
+ */
+ appNameLoadCallback(name) {
this.appName = name;
},
+ /**
+ * Reload the app name from resource manager.
+ */
updateName() {
- console.info("Launcher AppIcon updateIcon in bundleName = " + this.itemBundleName);
- mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.iconLoadCallback);
+ console.info("Launcher GridName updateName in bundleName = " + this.itemBundleName);
+ mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.appNameLoadCallback);
}
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/component/ListName/AppName.js b/launcher/src/main/js/default/common/component/ListName/AppName.js
index 6dbb4bfb..0b658b4c 100644
--- a/launcher/src/main/js/default/common/component/ListName/AppName.js
+++ b/launcher/src/main/js/default/common/component/ListName/AppName.js
@@ -13,10 +13,11 @@
* limitations under the License.
*/
-import ResourceManager from '../../model/ResourceManager.js';
-
-var mResourceManager;
+let mResourceManager;
+/**
+ * A page element that display app name in ListView.
+ */
export default {
props: ['itemAppId', 'itemLabelId', 'itemBundleName', 'itemAppName'],
@@ -30,26 +31,37 @@ export default {
},
onInit() {
- this.$watch('itemBundleName','appIconWatcher');
- mResourceManager = new ResourceManager();
- mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.iconLoadCallback);
+ this.$watch('itemBundleName','appNameWatcher');
+ mResourceManager = this.$app.$def.data.resourceManager;
+ mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.appNameLoadCallback);
},
- onShow() {
- },
-
- appIconWatcher(newV, oldV) {
+ /**
+ * Watch the value of appName, called when the value changed.
+ *
+ * @param {object} newV - New value of appName
+ * @param {object} oldV - Old value of appName
+ */
+ appNameWatcher(newV, oldV) {
if (newV != null && newV != undefined) {
- mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.iconLoadCallback);
+ mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.appNameLoadCallback);
}
},
- iconLoadCallback(name) {
+ /**
+ * Callback function when appName loaded from the resource manager.
+ *
+ * @param {string} name - App name.
+ */
+ appNameLoadCallback(name) {
this.appName = name;
},
+ /**
+ * Reload the app name from resource manager.
+ */
updateName() {
- console.info("Launcher AppIcon updateIcon in bundleName = " + this.itemBundleName);
- mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.iconLoadCallback);
+ console.info("Launcher AppName updateName in bundleName = " + this.itemBundleName);
+ mResourceManager.getAppName(this.itemLabelId, this.itemBundleName, this.itemAppName, this.appNameLoadCallback);
}
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/configs/DefaultLayoutConfig.js b/launcher/src/main/js/default/common/configs/DefaultLayoutConfig.js
index 8ea39543..3c67455d 100644
--- a/launcher/src/main/js/default/common/configs/DefaultLayoutConfig.js
+++ b/launcher/src/main/js/default/common/configs/DefaultLayoutConfig.js
@@ -13,10 +13,14 @@
* limitations under the License.
*/
-var DefaultLayoutConfig = {
+/**
+ * Default configuration of page layout and recent.
+ */
+const DefaultLayoutConfig = {
DefaultAppPageStartConfig: 'Grid',
- DefaultGridConfig: 0,
- DefaultRecentProcessLimit: 6
+ DefaultGridConfig: 1,
+ DefaultRecentProcessLimit: 20,
+ DefaultRecentProcessLimitArray: [5,10,15,20],
}
export default DefaultLayoutConfig;
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/configs/GridLayoutConfigs.js b/launcher/src/main/js/default/common/configs/GridLayoutConfigs.js
index c69d5cc2..436a6b68 100644
--- a/launcher/src/main/js/default/common/configs/GridLayoutConfigs.js
+++ b/launcher/src/main/js/default/common/configs/GridLayoutConfigs.js
@@ -13,11 +13,31 @@
* limitations under the License.
*/
-var GridLayoutConfigs = {
+/**
+ * Configuration of different layouts.
+ */
+const GridLayoutConfigs = {
GridLayoutTable: [
- {id:0, layout:'5X4', row:5, column:4},
- {id:1, layout:'4X4', row:4, column:4},
- {id:2, layout:'6X4', row:6, column:4},
+ {
+ id: 0,
+ layout: '4X4',
+ row: 4,
+ column: 4
+ },
+
+ {
+ id: 1,
+ layout: '5X4',
+ row: 5,
+ column: 4
+ },
+
+ {
+ id: 2,
+ layout: '6X4',
+ row: 6,
+ column: 4
+ },
]
}
diff --git a/launcher/src/main/js/default/common/configs/SystemApplication.js b/launcher/src/main/js/default/common/configs/SystemApplication.js
index 01435a08..d07e7e58 100644
--- a/launcher/src/main/js/default/common/configs/SystemApplication.js
+++ b/launcher/src/main/js/default/common/configs/SystemApplication.js
@@ -13,7 +13,10 @@
* limitations under the License.
*/
-var SystemApplication = {
+/**
+ * Records the system app that will not be displayed in Launcher.
+ */
+const SystemApplication = {
SystemApplicationName: 'com.ohos.launcher,com.ohos.systemui'
}
diff --git a/launcher/src/main/js/default/common/constants/EventConstants.js b/launcher/src/main/js/default/common/constants/EventConstants.js
new file mode 100644
index 00000000..73db7756
--- /dev/null
+++ b/launcher/src/main/js/default/common/constants/EventConstants.js
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/**
+ * Constants of events that will be registered to system.
+ */
+const EventConstants = {
+ EVENT_PACKAGE_ADDED : "usual.event.PACKAGE_ADDED",
+ EVENT_PACKAGE_CHANGED : "usual.event.PACKAGE_CHANGED",
+ EVENT_PACKAGE_REMOVED : "usual.event.PACKAGE_REMOVED"
+}
+
+export default EventConstants;
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/constants/LayoutConstants.js b/launcher/src/main/js/default/common/constants/LayoutConstants.js
index dcf94f39..d86c75d8 100644
--- a/launcher/src/main/js/default/common/constants/LayoutConstants.js
+++ b/launcher/src/main/js/default/common/constants/LayoutConstants.js
@@ -13,9 +13,12 @@
* limitations under the License.
*/
-var LayoutContants = {
+/**
+ * A Constant class includes layout type Strings.
+ */
+const LayoutConstants = {
Grid: "Grid",
List: "List"
}
-export default LayoutContants;
\ No newline at end of file
+export default LayoutConstants;
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/constants/PageData.js b/launcher/src/main/js/default/common/constants/PageData.js
index 8c6664a7..b94d704c 100644
--- a/launcher/src/main/js/default/common/constants/PageData.js
+++ b/launcher/src/main/js/default/common/constants/PageData.js
@@ -13,7 +13,10 @@
* limitations under the License.
*/
-var PageData = {
+/**
+ * Pages' uri that will be used as a param of RouterUtil.
+ */
+const PageData = {
GRID_APP_PAGE: 'pages/AppGridView/AppGridView',
LIST_APP_PAGE: 'pages/AppListView/AppListView'
}
diff --git a/launcher/src/main/js/default/common/css/CommonPageStyle.css b/launcher/src/main/js/default/common/css/CommonPageStyle.css
index 72045c17..0dfb8b23 100644
--- a/launcher/src/main/js/default/common/css/CommonPageStyle.css
+++ b/launcher/src/main/js/default/common/css/CommonPageStyle.css
@@ -22,17 +22,17 @@
justify-content: center;
}
-.app-icon-img{
+.app-icon-img {
border-radius: 20px;
width: 110px;
height: 110px;
}
-.app-icon-img:active{
+.app-icon-img:active {
width: 105px;
height: 105px;
}
-.app-name{
+.app-name {
color: black;
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/model/AppModel.js b/launcher/src/main/js/default/common/model/AppModel.js
index 749f6a53..b7bc5ee7 100644
--- a/launcher/src/main/js/default/common/model/AppModel.js
+++ b/launcher/src/main/js/default/common/model/AppModel.js
@@ -13,187 +13,336 @@
* limitations under the License.
*/
-import bundle_mgr from '@ohos.bundle_mgr';
-import feature_ability from '@ohos.feature_ability';
+import BundleMgr from '@ohos.bundle';
+import FeatureAbility from '@ohos.ability.featureability';
import Subscriber from '@ohos.commonevent';
import SystemApplication from '../../common/configs/SystemApplication.js';
+import EventConstants from '../../common/constants/EventConstants.js';
+import CheckEmptyUtils from '../../common/utils/CheckEmptyUtils.js';
-var mBundleInfoList = [];
-var mGridBootAppList = [];
-const DEFAULT_ICON_URL = 'common/pics/icon_default.png';
-var mAppUninstallListener = null;
-var mAppInstallListeners = [];
-var gridListCallback;
-var systemApplicationName = SystemApplication.SystemApplicationName;
-var mCommonEventSubscriber = null;
-var mCommonEventSubscribeInfo = {
- events: ["usual.event.PACKAGE_ADDED", "usual.event.PACKAGE_CHANGED", "usual.event.PACKAGE_REMOVED"]
+const UNINSTALL_SUCCESS = "UNINSTALL_SUCCESS";
+const UNINSTALL_FAILED = "UNINSTALL_FAILED";
+const IF_GET_ABILITY = 1;
+
+let mBundleInfoList = [];
+let mAppListInstallListener = [];
+let mAppListUninstallListener = [];
+let mAppListChangeListener = [];
+let installCallback;
+let systemApplicationName = SystemApplication.SystemApplicationName;
+let mCommonEventSubscriber = null;
+let mCommonEventSubscribeInfo = {
+ events: [EventConstants.EVENT_PACKAGE_ADDED,
+ EventConstants.EVENT_PACKAGE_CHANGED,
+ EventConstants.EVENT_PACKAGE_REMOVED]
};
+/**
+ * Model class, get data from system API.
+ */
export default class AppModel {
+ /**
+ * Get app information list from system by @ohos.bundle
+ *
+ * @param {object} callback - callback from presenter
+ */
getAppList(callback) {
mBundleInfoList = [];
- console.info('Launcher getAppIcon getAppList');
- bundle_mgr.getApplicationInfos().then((data) => {
- console.info('Launcher getApplicationInfos >' + JSON.stringify(data));
- for (var i = 0; i < data.length; i++) {
- if (systemApplicationName.indexOf(data[i].bundleName) > -1) {
+ console.info('Launcher AppModel getAppIcon getAppList');
+ BundleMgr.getBundleInfos(IF_GET_ABILITY).then((data) => {
+ if (CheckEmptyUtils.isEmpty(data)) {
+ console.error("Launcher AppModel getAppList getBundleInfos ERROR");
+ }
+ console.info('Launcher AppModel getBundleInfos >' + JSON.stringify(data));
+ for (let i = 0; i < data.length; i++) {
+ if (systemApplicationName.indexOf(data[i].name) > -1) {
} else {
mBundleInfoList.push(
{
- System: data[i].isSystemApp,
- AppName: data[i].label,
- AppId: data[i].name,
- AppIcon: data[i].iconId,
- bundleName: data[i].bundleName,
- labelId: data[i].labelId,
+ System:data[i].appInfo.systemApp,
+ AppName: data[i].appInfo.label,
+ AppId: data[i].appId,
+ AppIcon: data[i].appInfo.iconId,
+ bundleName:data[i].name,
+ labelId :data[i].appInfo.labelId,
+ abilityName: data[i].abilityInfos[0].name,
}
)
}
- }
+ };
let appArrayLength = mBundleInfoList.length;
- for (let i = 0; i < appArrayLength; i++) {
- var iconUrl = mBundleInfoList[i].AppIcon;
- if (iconUrl == null || iconUrl == "" || iconUrl == "undefined") {
- mBundleInfoList[i].AppIcon = DEFAULT_ICON_URL;
- }
- }
- console.info('Launcher mBundleInfoList' + JSON.stringify(mBundleInfoList));
+ console.info('Launcher AppModel mBundleInfoList' + JSON.stringify(mBundleInfoList));
callback(mBundleInfoList);
});
}
installApp() {
+
}
- uninstallApp(appId, callback) {
- console.info('Launcher uninstallApp appId' + appId);
- var result = bundle_mgr.uninstall(appId).then((data) => {
- console.info("Launcher uninstall data [" + data + "]");
- callback(true);
- }).catch(error =>
- console.info("Launcher uninstall err " + error));
- }
-
- getGridBootAppList() {
- return mGridBootAppList;
- }
-
- getGridPagesAppList(callback) {
- gridListCallback = callback;
- this.getAppList(this.getGridlist.bind(this));
- }
-
- getGridlist(list) {
- gridListCallback(this.dealList(list));
- }
-
- dealList(appList) {
- var gridPagesList = [];
- var bootListLength = mGridBootAppList.length;
- var appArrayLength = appList.length;
- for (var i = 0; i < appArrayLength; i++) {
- gridPagesList.push(appList[i]);
- for (var j = 0; j < bootListLength; j++) {
- if (appList[i].AppName === mGridBootAppList[j].AppName) {
- gridPagesList.pop();
+ /**
+ * Uninstall app by @ohos.bundle.
+ *
+ * @param {string} uninstallBundleName - bundleName of the bundle that will be uninstall
+ * @param {object} callback - callback from presenter
+ */
+ uninstallApp(uninstallBundleName, callback) {
+ console.info('Launcher AppModel uninstallApp appId' + uninstallBundleName);
+ installCallback = callback;
+ let result = BundleMgr.getBundleInstaller().then((data) => {
+ if (CheckEmptyUtils.isEmpty(data)) {
+ console.error("Launcher AppModel uninstallApp getBundleInstaller ERROR");
+ }
+ data.uninstall(uninstallBundleName, {
+ param: {
+ userId: 0,
+ isKeepData: false
}
- }
+ }, this.#OnReceiveinstallEvent);
+ }).catch(error =>
+ console.info("Launcher AppModel uninstall err " + error));
+ }
+
+ /**
+ * Callback method after uninstall.
+ *
+ * @param {object} data - uninstall result data
+ */
+ #OnReceiveinstallEvent = (data) => {
+ console.info('Launcher AppModel OnReceiveinstallEvent ' + data);
+ if (data.statusMessage == "SUCCESS") {
+ installCallback(UNINSTALL_SUCCESS);
+ } else {
+ installCallback(UNINSTALL_FAILED);
}
- return gridPagesList;
+ console.info('Launcher AppModel OnReceiveinstallEvent ');
}
- openApplication(bundleName) {
- this.getAbilityName(bundleName, this.startApplication)
- }
-
- getAbilityName(bundleName, callback) {
- console.info('Launcher getAbilityName bundleName' + bundleName);
- bundle_mgr.getBundleInfo(bundleName).then(data => {
- console.info('Launcher getBundleInfo ' + data);
- callback(data.abilityInfos[0].name, bundleName);
- });
- }
-
- startApplication(abilityname, bundleName) {
+ /**
+ * Start app by bundle name and ability name.
+ *
+ * @param {string} abilityName - ability name of target app
+ * @param {string} bundleName - bundle name of target app
+ */
+ startApplication(abilityName, bundleName) {
let paramBundleName = bundleName;
- let paramAbilityname = abilityname;
+ let paramAbilityName = abilityName;
// promise
- console.info('Launcher startApplication abilityname' + abilityname);
- var result = feature_ability.startAbility({
- bundleName: paramBundleName,
- abilityName: paramAbilityname,
- requestCode: 1,
- abilityType: "PageAbility",
+ console.info('Launcher AppModel startApplication abilityName ==> ' + abilityName + " bundleName ==> " + bundleName);
+ let result = FeatureAbility.startAbility({
want: {
- action: "action1",
- entities: ["entity1"],
- type: "PageAbility",
- flags: 2,
- elementName: {
- deviceId: "deviceId",
- bundleName: paramBundleName,
- abilityName: paramAbilityname,
- },
- },
- syncOption: 1,
+ bundleName: paramBundleName,
+ abilityName: paramAbilityName
+ }
}).then(data =>
- console.info("Launcher promise::then : " + JSON.stringify(data))
+ console.info("Launcher AppModel startApplication promise::then : " + JSON.stringify(data))
).catch(error =>
- console.info("Launcher promise::catch : " + JSON.stringify(error))
+ console.info("Launcher AppModel startApplication promise::catch : " + JSON.stringify(error))
);
- console.info("Launcher AceApplication : startAbility : " + result);
+ console.info("Launcher AppModel startApplication AceApplication : startAbility : " + result);
}
- reportAppInstallEvent() {
- console.info("Launcher AppModel reportAppInstallEvent");
- for (let i = 0; i < mAppInstallListeners.length; i++) {
- let listener = mAppInstallListeners[i];
+ /**
+ * Start app by bundle name and ability name with result.
+ *
+ * @param {string} abilityName - ability name of target app
+ * @param {string} bundleName - bundle name of target app
+ * @param {number} requestCode - result after start app
+ */
+ startApplicationForResult(abilityName, bundleName, requestCode) {
+ let paramBundleName = bundleName;
+ let paramAbilityName = abilityName;
+ // promise
+ console.info('Launcher AppModel startApplicationForResult abilityName' + abilityName);
+ let result = FeatureAbility.startAbilityForResult({
+ want: {
+ bundleName: paramBundleName,
+ abilityName: paramAbilityName
+ },
+ requestCode: requestCode,
+ },
+ (err, data) => {
+ console.log("Launcher AppModel startAbilityForResult asyncCallback StartAbilityResult: "
+ + err.code + " data: " + data)
+ }).then(data =>
+ console.info("Launcher AppModel startApplicationForResult promise::then : " + JSON.stringify(data))
+ ).catch(error =>
+ console.info("Launcher AppModel startApplicationForResult promise::catch : " + JSON.stringify(error))
+ );
+ console.info("Launcher AppModel startApplicationForResult AceApplication : startAbility : " + result);
+ }
+
+ /**
+ * Dispatch event to corresponding listeners.
+ *
+ * @param {string} event: callback event
+ * @param {object} bundleInfo: data from callback
+ */
+ #reportAppInstallEvent = (event, bundleInfo) => {
+ console.info("Launcher AppModel reportAppInstallEvent + " + event);
+ switch (event) {
+ case EventConstants.EVENT_PACKAGE_ADDED:
+ this.#notifyEventListener(mAppListInstallListener, bundleInfo);
+ break;
+ case EventConstants.EVENT_PACKAGE_CHANGED:
+ this.#notifyEventListener(mAppListChangeListener, bundleInfo);
+ break;
+ case EventConstants.EVENT_PACKAGE_REMOVED:
+ this.#notifyEventListener(mAppListUninstallListener, bundleInfo);
+ break;
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Call the callback method which comes from presenter.
+ *
+ * @param {object} eventListener - different listeners for different event
+ * @param {object} bundleInfo - callback data
+ */
+ #notifyEventListener = (eventListener, bundleInfo) => {
+ for (let i = 0; i < eventListener.length; i++) {
+ let listener = eventListener[i];
if (listener != undefined && listener != null) {
- listener();
+ console.info("Launcher AppModel notifyEventListener " + JSON.stringify(bundleInfo));
+ listener(bundleInfo);
}
}
}
- reportAppUninstallEvent(appId) {
- if (mAppUninstallListener != null) {
- mAppUninstallListener(appId);
+ /**
+ * Register install listener.
+ *
+ * @param {object} listener - install listener
+ */
+ registerAppListInstallListener(listener) {
+ if (mAppListInstallListener.indexOf(listener) == -1) {
+ mAppListInstallListener.push(listener);
}
}
- registerAppUninstallListener(listener) {
- mAppUninstallListener = listener;
+ /**
+ * Unregister install listener.
+ *
+ * @param {object} listener - install listener
+ */
+ unregisterAppListInstallListener(listener) {
+ let index = mAppListInstallListener.indexOf(listener);
+ if (index != -1) {
+ mAppListInstallListener.splice(index, 1);
+ }
}
- registerAppInstallListener(listener) {
- console.info("Launcher AppModel registerAppInstallListener");
- if (mAppInstallListeners.indexOf(listener) == -1) {
- mAppInstallListeners.push(listener);
+ /**
+ * Register uninstall listener.
+ *
+ * @param {object} listener - uninstall listener
+ */
+ registerAppListUninstallListener(listener) {
+ if (mAppListUninstallListener.indexOf(listener) == -1) {
+ mAppListUninstallListener.push(listener);
}
+ }
+
+ /**
+ * Unregister uninstall listener.
+ *
+ * @param {object} listener - uninstall listener
+ */
+ unregisterAppListUninstallListener(listener) {
+ let index = mAppListUninstallListener.indexOf(listener);
+ if (index != -1) {
+ mAppListUninstallListener.splice(index, 1);
+ }
+ }
+
+ /**
+ * Register change listener.
+ *
+ * @param {object} listener - uninstall listener
+ */
+ registerAppListChangeListener(listener) {
+ if (mAppListChangeListener.indexOf(listener) == -1) {
+ mAppListChangeListener.push(listener);
+ }
+ }
+
+ /**
+ * Unregister change listener.
+ *
+ * @param {object} listener - change listener
+ */
+ unregisterAppListChangeListener(listener) {
+ let index = mAppListChangeListener.indexOf(listener);
+ if (index != -1) {
+ mAppListChangeListener.splice(index, 1);
+ }
+ }
+
+ /**
+ * Called in app.js, create subscriber for app install/uninstall/update events.
+ */
+ registerAppListEvent() {
Subscriber.createSubscriber(
mCommonEventSubscribeInfo,
- this.createInstallationSubscriberCallBack.bind(this)
+ this.#createInstallationSubscriberCallBack.bind(this)
);
}
- unregisterAppInstallListener(listener) {
+ /**
+ * Called in app.js, unregister app install/uninstall/update events.
+ */
+ unregisterAppListEvent() {
Subscriber.unsubscribe(mCommonEventSubscriber, () => {
- console.info("Launcher AppModel unsubscribe app install listener");
- let index = mAppInstallListeners.indexOf(listener);
- if (index != -1) {
- mAppInstallListeners.splice(index, 1);
- }
+ console.info("Launcher AppModel unregisterAppListEvent");
});
}
- createInstallationSubscriberCallBack(err, data) {
+ /**
+ * Create subscriber for install/uninstall/update event
+ *
+ * @param {object} err - error message of callback
+ * @param {object} data - callback data
+ */
+ #createInstallationSubscriberCallBack = (err, data) => {
console.info("Launcher AppModel createInstallationSubscriberCallBack");
mCommonEventSubscriber = data;
- Subscriber.subscribe(mCommonEventSubscriber, this.installationSubscriberCallBack.bind(this));
+ Subscriber.subscribe(mCommonEventSubscriber, this.#installationSubscriberCallBack.bind(this));
}
- installationSubscriberCallBack(err, data) {
- console.info("Launcher AppModel installationSubscriberCallBack");
- this.reportAppInstallEvent();
+ /**
+ * callback after install/uninstall/update events, reorganize callback data.
+ *
+ * @param {object} err - error returns from the caller
+ * @param {object} data - data returns from the caller
+ */
+ #installationSubscriberCallBack = (err, data) => {
+ if (err.code == 0) {
+ if (CheckEmptyUtils.isEmpty(data)) {
+ console.error("Launcher AppModel installationSubscriberCallBack ERROR! data is empty");
+ }
+ console.info("Launcher AppModel installationSubscriberCallBack data = " + JSON.stringify(data));
+ let callbackData = data;
+ if (callbackData.event == EventConstants.EVENT_PACKAGE_REMOVED) {
+ this.#reportAppInstallEvent(callbackData.event, callbackData);
+ return;
+ }
+ BundleMgr.getBundleInfo(callbackData.bundleName, IF_GET_ABILITY).then(data => {
+ console.info('Launcher AppModel installation subscriber getBundleInfo ' + JSON.stringify(data));
+ let bundleInfo = {
+ System:data.appInfo.systemApp,
+ AppName: data.appInfo.label,
+ AppId: data.appId,
+ AppIcon: data.appInfo.iconId,
+ bundleName:data.name,
+ labelId :data.appInfo.labelId,
+ abilityName: data.abilityInfos[0].name,
+ };
+ this.#reportAppInstallEvent(callbackData.event, bundleInfo);
+ });
+ } else {
+ console.error("Launcher AppModel app list change failed --- err = " + JSON.stringify(err));
+ }
}
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/model/ILayoutConfig.js b/launcher/src/main/js/default/common/model/ILayoutConfig.js
index ccac07fb..7735593a 100644
--- a/launcher/src/main/js/default/common/model/ILayoutConfig.js
+++ b/launcher/src/main/js/default/common/model/ILayoutConfig.js
@@ -13,49 +13,144 @@
* limitations under the License.
*/
+/**
+ * An abstract class contains methods that can store layout data.
+ */
export default class ILayoutConfig {
constructor() {
}
+ /**
+ * Get the layout view type.
+ *
+ * @return {string} Layout view type, should one of 'Grid' or 'List' which is stored in LayoutConstants class.
+ */
getAppPageStartConfig() {
return this.loadAppPageStartConfig();
}
+ /**
+ * Set the layout view type.
+ *
+ * @param {string} type - Layout view type, should one of 'Grid' or 'List' which is stored in LayoutConstants class.
+ */
setAppPageStartConfig(type) {
this.saveAppPageStartConfig(type);
}
+ /**
+ * Get grid layout config id.
+ *
+ * @return {number} grid layout config id.
+ */
getGridConfig() {
return this.loadGridConfig();
}
+ /**
+ * Set grid layout config id.
+ *
+ * @param {number} id - layout config id.
+ */
setGridConfig(id) {
this.saveGridConfig(id);
}
+ /**
+ * Get recent process max limit.
+ *
+ * @return {number} recent process max limit.
+ */
getRecentProcessLimit() {
return this.loadRecentProcessLimit();
}
+ /**
+ * Set recent process max limit.
+ *
+ * @param {number} num - Recent process max limit.
+ */
setRecentProcessLimit(num) {
this.saveRecentProcessLimit(num);
}
+ /**
+ * Get layout information of grid view.
+ *
+ * @return {object} layout information.
+ */
+ getGridLayoutInfo() {
+ return this.loadGridLayoutInfo();
+ }
+
+ /**
+ * Set layout information of grid view.
+ */
+ setGridLayoutInfo(layoutInfo) {
+ this.saveGridLayoutInfo(layoutInfo);
+ }
+
+ /**
+ * Remove layout information of grid view.
+ */
+ deleteGridLayoutInfo() {
+ this.removeGridLayoutInfo();
+ }
+
+ /**
+ * Should overridden by sub-classes , load the launcher layout view type.
+ */
loadAppPageStartConfig() {
}
+ /**
+ * Should overridden by sub-classes , save the launcher layout view type.
+ */
saveAppPageStartConfig(type) {
}
+ /**
+ * Should overridden by sub-classes , load the launcher grid view layout config id.
+ */
loadGridConfig() {
}
+ /**
+ * Should overridden by sub-classes , save the launcher grid view layout config id.
+ */
saveGridConfig(id) {
}
+ /**
+ * Should overridden by sub-classes , load the recent process max limit.
+ */
loadRecentProcessLimit() {
}
+ /**
+ * Should overridden by sub-classes , save the recent process max limit.
+ */
saveRecentProcessLimit(num) {
}
+
+ /**
+ * Should overridden by sub-classes , load the layout information of grid view.
+ */
+ loadGridLayoutInfo() {
+
+ }
+
+ /**
+ * Should overridden by sub-classes , save the layout information of grid view.
+ */
+ saveGridLayoutInfo(layoutInfo) {
+
+ }
+
+ /**
+ * Should overridden by sub-classes , remove layout information of grid view.
+ */
+ removeGridLayoutInfo() {
+
+ }
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/model/LayoutConfigManager.js b/launcher/src/main/js/default/common/model/LayoutConfigManager.js
index 35b0003e..1d8623cf 100644
--- a/launcher/src/main/js/default/common/model/LayoutConfigManager.js
+++ b/launcher/src/main/js/default/common/model/LayoutConfigManager.js
@@ -15,6 +15,11 @@
import StorageLayoutConfig from './StorageLayoutConfig.js'
+/**
+ * The factory function of producing the class to operate layout config.
+ *
+ * @return {object} The class to operate layout config.
+ */
export function getLayoutConfig() {
return new StorageLayoutConfig();
}
diff --git a/launcher/src/main/js/default/common/model/MMIEventManager.js b/launcher/src/main/js/default/common/model/MMIEventManager.js
new file mode 100644
index 00000000..b27e2e10
--- /dev/null
+++ b/launcher/src/main/js/default/common/model/MMIEventManager.js
@@ -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.
+ */
+
+let mCallbacks = [];
+
+/**
+ * A manager class support Multi-Mode input events.
+ */
+export default class MMIEventManager {
+
+ /**
+ * Register the multi mode event callback function.
+ *
+ * @param {object} callback - callback function to be registered.
+ */
+ registerEventCallback(callback) {
+ mCallbacks.push(callback);
+ }
+
+ /**
+ * Unregister the multi mode event callback function.
+ *
+ * @param {object} callback - callback function to be unregistered.
+ */
+ unregisterEventCallback(callback) {
+ for (let idx = 0; idx < mCallbacks.length; idx++) {
+ if (mCallbacks[idx] == callback) {
+ mCallbacks.splice(idx, 1);
+ break;
+ }
+ }
+ }
+
+ /**
+ * Called when the multi mode event occur.
+ */
+ onMMIEvent() {
+ for (let callback of mCallbacks) {
+ if (callback != undefined) {
+ callback();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/model/MMIModel.js b/launcher/src/main/js/default/common/model/MMIModel.js
new file mode 100644
index 00000000..6fbf7425
--- /dev/null
+++ b/launcher/src/main/js/default/common/model/MMIModel.js
@@ -0,0 +1,42 @@
+/*
+ * 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 MMIEventManager from './MMIEventManager.js';
+
+let mMMIEventManager = new MMIEventManager();
+
+/**
+ * A model class provide Multi-Mode input functionality.
+ */
+export default class MMIModel {
+
+ /**
+ * Register the multi mode event callback function.
+ *
+ * @param {object} callback - callback function to be registered.
+ */
+ registerEventCallback(callback) {
+ mMMIEventManager.registerEventCallback(callback);
+ }
+
+ /**
+ * Unregister the multi mode event callback function.
+ *
+ * @param {object} callback - callback function to be unregistered.
+ */
+ unregisterEventCallback(callback) {
+ mMMIEventManager.unregisterEventCallback(callback);
+ }
+}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/model/ResourceManager.js b/launcher/src/main/js/default/common/model/ResourceManager.js
index 8e8a2548..9b4ac31d 100644
--- a/launcher/src/main/js/default/common/model/ResourceManager.js
+++ b/launcher/src/main/js/default/common/model/ResourceManager.js
@@ -13,45 +13,109 @@
* limitations under the License.
*/
-import resmgr from '@ohos.resmgr';
+import Resmgr from '@ohos.resmgr';
+import AppResourceCacheManager from '../cache/AppResourceCacheManager.js'
+import CheckEmptyUtils from '../../common/utils/CheckEmptyUtils.js';
-const DEFAULT_ICON_URL = 'common/pics/icon_default.png';
+const KEY_ICON = "icon";
+const KEY_NAME = "name";
+/**
+ * A manager class provide app icon and name from cache or system API.
+ */
export default class ResourceManager {
- ResourceManager() {
+ #appResourceCacheManager;
+ constructor() {
+ this.#appResourceCacheManager = new AppResourceCacheManager();
}
- getAppIcon(path, bundleName, callback) {
+ /**
+ * Get icon image of specific app.
+ *
+ * @param {string} path - path of target file
+ * @param {string} bundleName - bundle name of the app
+ * @param {object} callback - callback method
+ */
+ getAppIcon(path, bundleName, callback, defaultAppIcon) {
if (path == null || path == undefined || path == "" || path <= 0) {
- console.info('Launcher getAppIcon iconid > ' + DEFAULT_ICON_URL);
- callback(DEFAULT_ICON_URL);
+ console.info('Launcher ResourceManager getAppIcon iconId > ' + defaultAppIcon);
+ callback(defaultAppIcon);
} else {
- resmgr.getResourceManager(bundleName).then(item => {
- console.info('Launcher getResourceManager data>' + item);
- item.getMediaBase64(path, (error, value) => {
- console.info('Launcher getMediaBase64 value>' + value);
- if (value != null) {
- callback(value);
+ let iconBase64 = this.#appResourceCacheManager.getCache(bundleName, KEY_ICON);
+ if (iconBase64 == undefined || iconBase64 == null || iconBase64 == '') {
+ Resmgr.getResourceManager(bundleName).then(item => {
+ if (CheckEmptyUtils.isEmpty(item)) {
+ console.error("Launcher ResourceManager getAppIcon getResourceManager ERROR! item is empty");
}
+ console.info('Launcher ResourceManager getAppIcon data>' + item);
+ item.getMediaBase64(path, (error, value) => {
+ console.info('Launcher ResourceManager getAppIcon getMediaBase64 value>' + value);
+ if (value != null) {
+ this.#appResourceCacheManager.setCache(bundleName, KEY_ICON, value);
+ callback(value);
+ }
+ });
+ }).catch(e => {
+ console.error("Launcher ResourceManager getAppIcon error ")
+ callback(defaultAppIcon);
});
- });
+ } else {
+ callback(iconBase64);
+ }
}
}
+ /**
+ * Get app name of specific app.
+ *
+ * @param {string} labelId - label id of target app
+ * @param {string} bundleName - bundle name of the app
+ * @param {string} appName - app name
+ * @param {object} callback - callback method
+ */
getAppName(labelId, bundleName, appName, callback) {
if (labelId == null || labelId == undefined || labelId == "" || labelId <= 0) {
- console.info('Launcher getAppName callback ' + appName);
+ console.info('Launcher ResourceManager getAppName callback ' + appName);
callback(appName);
} else {
- resmgr.getResourceManager(bundleName).then(item => {
- console.info('Launcher getResourceManager labelId' + labelId);
- item.getString(labelId, (error, value) => {
- console.info('Launcher getString value>' + value);
- if (value != null) {
- callback(value);
- }
+ let name = this.#appResourceCacheManager.getCache(bundleName, KEY_NAME);
+ if (name == undefined || name == null || name == '') {
+ Resmgr.getResourceManager(bundleName).then(item => {
+ console.info('Launcher ResourceManager getAppName getResourceManager labelId' + labelId);
+ item.getString(labelId, (error, value) => {
+ if (CheckEmptyUtils.checkStrIsEmpty(value)) {
+ console.error("Launcher AppModel getAppName getString ERROR! value is empty");
+ }
+ console.info('Launcher ResourceManager getAppName getString value>' + value);
+ if (value != null) {
+ this.#appResourceCacheManager.setCache(bundleName, KEY_NAME, value);
+ callback(value);
+ }
+ });
+ }).catch(e => {
+ console.error("Launcher ResourceManager getAppName error ")
+ callback(appName);
});
- });
+ } else {
+ callback(name);
+ }
}
}
+
+ /**
+ * Get app resource cache.
+ *
+ * @param {string} bundleName - bundleName of target file
+ * @param {string} key - key of the cache
+ */
+ getAppResourceCache(bundleName, key) {
+ return this.#appResourceCacheManager.getCache(bundleName, key);
+ }
+
+ /**
+ * Clear resource cache
+ */
+ clearCache() {
+ this.#appResourceCacheManager.clearCache();
+ }
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/model/SettingsModel.js b/launcher/src/main/js/default/common/model/SettingsModel.js
index 264221e4..747cf790 100644
--- a/launcher/src/main/js/default/common/model/SettingsModel.js
+++ b/launcher/src/main/js/default/common/model/SettingsModel.js
@@ -15,38 +15,112 @@
import GridLayoutConfigs from '../../common/configs/GridLayoutConfigs.js';
import {getLayoutConfig} from './LayoutConfigManager.js';
+import FileUtils from "../../common/utils/FileUtils.js"
-var mLayoutConfig = getLayoutConfig();
-var mGridConfig = 0;
-var gridLayoutTable = GridLayoutConfigs.GridLayoutTable;
+const defaultLayoutInfoFilePath = "/data/accounts/account_0/applications/com.ohos.launcher/com.ohos.launcher/assets/launcher/resources/rawfile/layoutInfo.json";
+let mLayoutConfig = getLayoutConfig();
+let mGridConfig = 0;
+let mGridLayoutTable = GridLayoutConfigs.GridLayoutTable;
+
+/**
+ * A class that manage configuration data of layout and recent task.
+ */
export default class SettingsModel {
+
+ /**
+ * Get the grid view presetting collection of layout config information table.
+ *
+ * @return {object} Grid view presetting collection object.
+ */
getGridLayoutTable() {
- return gridLayoutTable;
+ return mGridLayoutTable;
}
+ /**
+ * Get default layout information of grid view.
+ *
+ * @return {object} Default layout information of grid view.
+ */
+ getDefaultLayoutInfo() {
+ return FileUtils.readJsonFile(defaultLayoutInfoFilePath);
+ }
+
+ /**
+ * Get layout config of grid view.
+ *
+ * @return {object} Layout config of grid view.
+ */
getGridConfig() {
mGridConfig = mLayoutConfig.getGridConfig();
- return gridLayoutTable[mGridConfig];
+ return mGridLayoutTable[mGridConfig];
}
+ /**
+ * Set layout config id of grid view.
+ *
+ * @param {string} id - Layout config id of grid view.
+ */
setGridConfig(id) {
mLayoutConfig.setGridConfig(id);
}
+ /**
+ * Get recent process max limit.
+ *
+ * @return {number} recent process max limit.
+ */
getRecentProcessLimit() {
return mLayoutConfig.getRecentProcessLimit();
}
+ /**
+ * Set recent process max limit.
+ *
+ * @param {number} num - Recent process max limit.
+ */
setRecentProcessLimit(num) {
mLayoutConfig.setRecentProcessLimit(num);
}
+ /**
+ * Get the layout view type.
+ *
+ * @return {string} Layout view type, should one of 'Grid' or 'List' which is stored in LayoutConstants class.
+ */
getAppPageStartConfig() {
return mLayoutConfig.getAppPageStartConfig();
}
+ /**
+ * Set the layout view type.
+ *
+ * @param {string} type - Layout view type, should one of 'Grid' or 'List' which is stored in LayoutConstants class.
+ */
setAppPageStartConfig(type) {
mLayoutConfig.setAppPageStartConfig(type);
}
+
+ /**
+ * Get layout information of grid view.
+ *
+ * @return {object} layout information.
+ */
+ getLayoutInfo() {
+ return mLayoutConfig.getGridLayoutInfo();
+ }
+
+ /**
+ * Set layout information of grid view.
+ */
+ setLayoutInfo(layoutInfo) {
+ mLayoutConfig.setGridLayoutInfo(layoutInfo);
+ }
+
+ /**
+ * Remove layout information of grid view.
+ */
+ deleteLayoutInfo() {
+ mLayoutConfig.deleteGridLayoutInfo();
+ }
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/model/StorageLayoutConfig.js b/launcher/src/main/js/default/common/model/StorageLayoutConfig.js
index 63f6dc3b..cc7b8b47 100755
--- a/launcher/src/main/js/default/common/model/StorageLayoutConfig.js
+++ b/launcher/src/main/js/default/common/model/StorageLayoutConfig.js
@@ -15,26 +15,42 @@
import ILayoutConfig from './ILayoutConfig.js';
import DefaultLayoutConfig from '../../common/configs/DefaultLayoutConfig.js';
-import storage from '@ohos.data.storage';
+import Storage from '@ohos.data.storage';
const APP_PAGE_START_CONFIG = 'AppStartPageType';
const GRID_CONFIG = "GridConfig";
const RECENT_PROCESS_LIMIT = "RecentProcessLimit";
+const GRID_LAYOUT_INFO = "GridLayoutInfo";
const PREFERENCES_PATH = '/data/accounts/account_0/appdata/com.ohos.launcher/sharedPreference/LauncherPreference';
-var mPreferences = storage.getStorageSync(PREFERENCES_PATH);
+let mPreferences = Storage.getStorageSync(PREFERENCES_PATH);
+
+/**
+ * A class that stores layout information.
+ * @extends ILayoutConfig
+ */
export default class StorageLayoutConfig extends ILayoutConfig {
constructor() {
super();
}
+ /**
+ * Load the launcher layout view type.
+ *
+ * @return {string} Layout view type , should one of 'Grid' or 'List' which is stored in LayoutConstants class.
+ */
loadAppPageStartConfig() {
console.info('Launcher mPreferences get APP_PAGE_START_CONFIG');
- var data = mPreferences.getSync(APP_PAGE_START_CONFIG, DefaultLayoutConfig.DefaultAppPageStartConfig);
+ let data = mPreferences.getSync(APP_PAGE_START_CONFIG, DefaultLayoutConfig.DefaultAppPageStartConfig);
console.info('Launcher mPreferences get' + data);
return data;
}
+ /**
+ * Save the launcher layout view type.
+ *
+ * @param {string} type - View type , should one of 'Grid' or 'List' which is stored in LayoutConstants class.
+ */
saveAppPageStartConfig(type) {
console.info('Launcher mPreferences put type' + type);
mPreferences.putSync(APP_PAGE_START_CONFIG, type);
@@ -42,13 +58,23 @@ export default class StorageLayoutConfig extends ILayoutConfig {
console.info('Launcher mPreferences put type flush');
}
+ /**
+ * Load the launcher grid view layout config id.
+ *
+ * @return {number} id - Config id.
+ */
loadGridConfig() {
console.info('Launcher mPreferences get GRID_CONFIG');
- var data = mPreferences.getSync(GRID_CONFIG, DefaultLayoutConfig.DefaultGridConfig);
+ let data = mPreferences.getSync(GRID_CONFIG, DefaultLayoutConfig.DefaultGridConfig);
console.info('Launcher mPreferences get' + data);
return data;
}
+ /**
+ * Save the launcher grid view layout config id.
+ *
+ * @param {string} id - View type , should one of 'Grid' or 'List' which is stored in LayoutConstants class.
+ */
saveGridConfig(id) {
console.info('Launcher mPreferences put id' + id);
mPreferences.putSync(GRID_CONFIG, id);
@@ -56,17 +82,64 @@ export default class StorageLayoutConfig extends ILayoutConfig {
console.info('Launcher mPreferences put id flush');
}
+ /**
+ * Load the recent process max limit.
+ *
+ * @return {number} Recent process max limit.
+ */
loadRecentProcessLimit() {
console.info('Launcher mPreferences get');
- var data = mPreferences.getSync(RECENT_PROCESS_LIMIT, DefaultLayoutConfig.DefaultRecentProcessLimit);
+ let data = mPreferences.getSync(RECENT_PROCESS_LIMIT, DefaultLayoutConfig.DefaultRecentProcessLimit);
console.info('Launcher mPreferences get' + data);
return data;
}
+ /**
+ * Save the recent process max limit.
+ *
+ * @param {number} num - Recent process max limit.
+ */
saveRecentProcessLimit(num) {
console.info('Launcher mPreferences put num' + num);
mPreferences.putSync(RECENT_PROCESS_LIMIT, num);
mPreferences.flushSync();
console.info('Launcher mPreferences put num flush');
}
+
+ /**
+ * Load the layout information of grid view.
+ *
+ * @return {object} The layout information data.
+ */
+ loadGridLayoutInfo() {
+ console.info('Launcher StorageLayoutConfig loadGridLayoutInfo start');
+ let data = mPreferences.getSync(GRID_LAYOUT_INFO, '');
+ console.info('Launcher StorageLayoutConfig loadGridLayoutInfo ' + data);
+ if(data == ''){
+ return [];
+ }else{
+ return JSON.parse(data);
+ }
+ }
+
+ /**
+ * Load the layout information of grid view.
+ *
+ * @return {object} The layout information data.
+ */
+ saveGridLayoutInfo(layoutInfo) {
+ console.info('Launcher StorageLayoutConfig saveGridLayoutInfo start');
+ mPreferences.putSync(GRID_LAYOUT_INFO, JSON.stringify(layoutInfo));
+ mPreferences.flushSync();
+ console.info('Launcher StorageLayoutConfig saveGridLayoutInfo end');
+ }
+
+ /**
+ * Remove layout information of grid view in preferences.
+ */
+ removeGridLayoutInfo() {
+ console.info('Launcher StorageLayoutConfig removeGridLayoutInfo start');
+ mPreferences.deleteSync(GRID_LAYOUT_INFO);
+ console.info('Launcher StorageLayoutConfig removeGridLayoutInfo start');
+ }
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/pics/img_return.png b/launcher/src/main/js/default/common/pics/img_return.png
new file mode 100644
index 00000000..2b4ef6f8
Binary files /dev/null and b/launcher/src/main/js/default/common/pics/img_return.png differ
diff --git a/launcher/src/main/js/default/common/pics/img_to_detail.png b/launcher/src/main/js/default/common/pics/img_to_detail.png
new file mode 100644
index 00000000..cdbb19a5
Binary files /dev/null and b/launcher/src/main/js/default/common/pics/img_to_detail.png differ
diff --git a/launcher/src/main/js/default/common/utils/CheckArray.js b/launcher/src/main/js/default/common/utils/CheckArray.js
new file mode 100644
index 00000000..b8b54d6a
--- /dev/null
+++ b/launcher/src/main/js/default/common/utils/CheckArray.js
@@ -0,0 +1,40 @@
+/*
+ * 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 default {
+
+ /**
+ * Whether the two arraies are equal.
+ *
+ * @param {array} arr1 - First array.
+ * @param {array} arr2 - Second array.
+ * @return {boolean} Verify result.
+ */
+ arrayEqual(arr1, arr2) {
+ if (arr1 === arr2) {
+ return true;
+ }
+ if (arr1.length != arr2.length) {
+ return false;
+ }
+ for (let i = 0; i < arr1.length; i++) {
+ if (arr1[i] !== arr2[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/utils/CheckEmptyUtils.js b/launcher/src/main/js/default/common/utils/CheckEmptyUtils.js
new file mode 100644
index 00000000..60e85976
--- /dev/null
+++ b/launcher/src/main/js/default/common/utils/CheckEmptyUtils.js
@@ -0,0 +1,48 @@
+/*
+ * 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 default {
+
+ /**
+ * Check obj is empty.
+ *
+ * @param {object} obj
+ * @return {boolean} true(empty)
+ */
+ isEmpty(obj) {
+ return (typeof obj === 'undefined' || obj == null || obj === '');
+ },
+
+ /**
+ * Check str is empty.
+ *
+ * @param {string} str
+ * @return {boolean} true(empty)
+ */
+ checkStrIsEmpty(str) {
+ return str.trim().length == 0;
+ },
+
+ /**
+ * Check array is empty.
+ *
+ * @param {Array}arr
+ * @return {boolean} true(empty)
+ */
+ isEmptyArr(arr) {
+ return arr.length == 0;
+ }
+}
+
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/utils/FileUtils.js b/launcher/src/main/js/default/common/utils/FileUtils.js
new file mode 100644
index 00000000..2e506988
--- /dev/null
+++ b/launcher/src/main/js/default/common/utils/FileUtils.js
@@ -0,0 +1,213 @@
+/*
+ * 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.
+ */
+
+/**
+ * An util that provides io functionality between file and JSON object.
+ */
+import Fileio from '@ohos.fileio';
+
+const writeFilePath = "/data/accounts/account_0/appdata/com.ohos.launcher/cache/";
+const journalPath = "/data/accounts/account_0/appdata/com.ohos.launcher/cache/journal.txt";
+const READ_DATA_SIZE = 4096;
+
+export default {
+
+ /**
+ * Read Json file from disk by bundleName.
+ *
+ * @param {string} bundleName - bundleName of the target file
+ * @return {object} - read object from file
+ */
+ readJsonObj(bundleName) {
+ console.info("Launcher FileUtil readJsonObj start execution");
+ let filePath = writeFilePath + bundleName + ".json";
+ return this.readJsonFile(filePath);
+ },
+
+ /**
+ * Read Json file from disk by file path.
+ *
+ * @param {string} path - path of the target file.
+ * @return {object} - read object from file
+ */
+ readJsonFile(path) {
+ console.info("Launcher FileUtil readJsonFile start execution");
+ let readStreamSync = null;
+ try {
+ readStreamSync = Fileio.Stream.createStreamSync(path, "r");
+ let content = this.getContent(readStreamSync);
+ console.info("Launcher FileUtil readJsonFile finish execution" + content);
+ return JSON.parse(content);
+ } catch (e) {
+ console.info("Launcher FileUtil readJsonFile " + e);
+ } finally {
+ readStreamSync.closeSync();
+ }
+ },
+
+ /**
+ * Write Json object to a file.
+ *
+ * @param {object} jsonObj - target JSON object will be written
+ * @param {string} bundleName - use bundleName as target file name
+ */
+ writeJsonObj(jsonObj, bundleName) {
+ console.info("Launcher FileUtil writeJsonObj start execution");
+ let filePath = writeFilePath + bundleName + ".json";
+ let content = JSON.stringify(jsonObj);
+ let writeStreamSync = null;
+ try {
+ writeStreamSync = Fileio.Stream.createStreamSync(filePath, "w+");
+ writeStreamSync.writeSync(content);
+ } catch (e) {
+ console.info("Launcher FileUtil writeJsonObj error: " + e);
+ } finally {
+ writeStreamSync.closeSync();
+ console.info("Launcher FileUtil writeJsonObj close sync");
+ }
+ },
+
+ /**
+ * Read String from disk by bundleName.
+ *
+ * @param {string} bundleName - bundleName as target file name
+ * @return {string} - read string from file
+ */
+ readStringFromFile(bundleName) {
+ console.info("Launcher FileUtil readStringFromFile start execution");
+ let filePath = writeFilePath + bundleName + ".json";
+ try {
+ var readStreamSync = fileio.Stream.createStreamSync(filePath, "r");
+ let content = this.getContent(readStreamSync);
+ console.info("Launcher FileUtil readStringFromFile finish execution" + content);
+ return content;
+ } catch (e) {
+ console.info("Launcher FileUtil readStringFromFile " + e);
+ } finally {
+ readStreamSync.closeSync();
+ }
+ },
+
+ /**
+ * Write string to a file.
+ *
+ * @param {string} string - target string will be written to file
+ * @param {string} bundleName - bundleName as target file name
+ */
+ writeStringToFile(string, bundleName) {
+ console.info("Launcher FileUtil writeStringToFile start execution");
+ let filePath = writeFilePath + bundleName + ".json";
+ try {
+ var writeStreamSync = fileio.Stream.createStreamSync(filePath, "w+");
+ writeStreamSync.writeSync(string);
+ } catch (e) {
+ console.info("Launcher FileUtil writeStringToFile error: " + e);
+ } finally {
+ writeStreamSync.closeSync();
+ console.info("Launcher FileUtil writeStringToFile close sync");
+ }
+ },
+
+ /**
+ * Record a key that maps the image as value.
+ *
+ * @param {string} content - the key maps the image file
+ */
+ writeJournal(content) {
+ let writeStreamSync = null;
+ try {
+ console.info("Launcher FileUtil writeJournal start");
+ writeStreamSync = Fileio.Stream.createStreamSync(journalPath, "a+");
+ writeStreamSync.writeSync(content + "\n");
+ } catch (e) {
+ console.info("Launcher FileUtil writeJournal error: " + e);
+ } finally {
+ writeStreamSync.closeSync();
+ console.info("Launcher FileUtil writeJournal close sync");
+ }
+ },
+
+ /**
+ * Get the keys that map the images.
+ *
+ * @return {object} object read from file
+ */
+ readJournal() {
+ console.info("Launcher FileUtil readJournal start execution");
+ let readStreamSync = null;
+ try {
+ readStreamSync = Fileio.Stream.createStreamSync(journalPath, "r");
+ return this.getContent(readStreamSync);
+ } catch (e) {
+ console.info("Launcher FileUtil readJournal error: " + e);
+ } finally {
+ readStreamSync.closeSync();
+ console.info("Launcher FileUtil readJournal closeSync");
+ }
+ },
+
+ /**
+ * Read JSON object from a file.
+ *
+ * @param {object} readStreamSync - stream of target file
+ * @return {object} - object read from file stream
+ */
+ getContent(readStreamSync) {
+ console.info("Launcher FileUtil getContent start");
+ let bufArray = [];
+ let totalLength = 0;
+ let buf = new ArrayBuffer(READ_DATA_SIZE);
+ let len = readStreamSync.readSync(buf);
+ while (len != 0) {
+ console.info("Launcher FileUtil getContent FileIO reading " + len);
+ totalLength += len;
+ if (len < READ_DATA_SIZE) {
+ buf = buf.slice(0, len);
+ bufArray.push(buf);
+ break;
+ }
+ bufArray.push(buf);
+ buf = new ArrayBuffer(READ_DATA_SIZE);
+ len = readStreamSync.readSync(buf);
+ }
+ console.info("Launcher FileUtil getContent read finished " + totalLength);
+ let contentBuf = new Uint8Array(totalLength);
+ let offset = 0;
+ for (let bufArr of bufArray) {
+ console.info("Launcher FileUtil getContent collecting " + offset);
+ let uInt8Arr = new Uint8Array(bufArr);
+ contentBuf.set(uInt8Arr, offset);
+ offset += uInt8Arr.byteLength;
+ }
+ let content = String.fromCharCode.apply(null, new Uint8Array(contentBuf));
+ return content;
+ },
+
+ /**
+ * Remove file.
+ *
+ * @param {string} bundleName - bundleName as target file name
+ */
+ removeFile(bundleName) {
+ try {
+ console.info("Launcher FileUtil removeFile")
+ //remove file,key : bundlename
+ Fileio.unlinkSync(writeFilePath + bundleName + ".json")
+ } catch (e) {
+ console.error("Launcher FileUtil removeFile delete has failed for " + e)
+ }
+ }
+}
+
\ No newline at end of file
diff --git a/launcher/src/main/js/default/common/utils/RouterUtil.js b/launcher/src/main/js/default/common/utils/RouterUtil.js
index bf620f3e..91cf7800 100644
--- a/launcher/src/main/js/default/common/utils/RouterUtil.js
+++ b/launcher/src/main/js/default/common/utils/RouterUtil.js
@@ -13,26 +13,54 @@
* limitations under the License.
*/
-import router from '@system.router';
+/**
+ * An util that encapsulates methods from @system.router.
+ */
+import Router from '@system.router';
-var Router = function () {
+let RouterUtil = function () {
return {
- push: function (uri, papams) {
- router.push({
+
+ /**
+ * Push the page into the Router stack.
+ *
+ * @param {string} uri - uri of the page
+ * @param {object} params - params while opening the page
+ */
+ push: function (uri, params) {
+ Router.push({
uri: uri,
- params: papams
+ params: params
})
- }, replace: function (uri, papams) {
- router.replace({
+ },
+
+ /**
+ * Replace original page to the current page.
+ *
+ * @param {string} uri - uri of the page
+ * @param {object} params - params while opening the page
+ */
+ replace: function (uri, params) {
+ Router.replace({
uri: uri,
- params: papams
+ params: params
})
- }, back: function () {
- router.back();
- }, clear: function () {
- router.clear();
+ },
+
+ /**
+ * Back to previous page and pop current page.
+ */
+ back: function () {
+ Router.back();
+ },
+
+ /**
+ * Clear router stack.
+ */
+ clear: function () {
+ Router.clear();
}
}
}();
-export default Router;
\ No newline at end of file
+export default RouterUtil;
\ No newline at end of file
diff --git a/launcher/src/main/js/default/i18n/en-US.json b/launcher/src/main/js/default/i18n/en-US.json
index 4a116bc5..3a3121aa 100644
--- a/launcher/src/main/js/default/i18n/en-US.json
+++ b/launcher/src/main/js/default/i18n/en-US.json
@@ -13,6 +13,12 @@
"launcher_settings": "Launcher settings",
"uninstall_app": "Uninstall App",
"layout": "Layout",
- "recent_tasks_settings": "Recent tasks settings"
+ "recent_tasks_settings": "Recent tasks settings",
+ "layout_style": "Layout style",
+ "launcher_layout": "Launcher layout",
+ "layout_grid": "grid",
+ "layout_list": "list",
+ "add_blank_page" : "Add blank page",
+ "delete_blank_page" : "delete blank page"
}
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/i18n/zh-CN.json b/launcher/src/main/js/default/i18n/zh-CN.json
index aa832cfc..273c8e68 100644
--- a/launcher/src/main/js/default/i18n/zh-CN.json
+++ b/launcher/src/main/js/default/i18n/zh-CN.json
@@ -13,6 +13,12 @@
"launcher_settings": "桌面设置",
"uninstall_app": "应用卸载",
"layout": "布局",
- "recent_tasks_settings": "最近任务设置"
+ "recent_tasks_settings": "最近任务数",
+ "layout_style": "布局样式",
+ "launcher_layout": "桌面布局",
+ "layout_grid": "网格",
+ "layout_list": "列表",
+ "add_blank_page" : "添加空白页",
+ "delete_blank_page" : "删除空白页"
}
}
\ No newline at end of file
diff --git a/launcher/src/main/js/default/pages/AppGridView/AppGridView.css b/launcher/src/main/js/default/pages/AppGridView/AppGridView.css
index 7eb25de8..bd94e12b 100644
--- a/launcher/src/main/js/default/pages/AppGridView/AppGridView.css
+++ b/launcher/src/main/js/default/pages/AppGridView/AppGridView.css
@@ -16,47 +16,30 @@
@import '../../common/css/CommonPageStyle.css';
.container {
- background-image: url("common/pics/img_wallpaper_default.jpg");
background-size: cover;
}
.body {
width: 100%;
height: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: space-around;
}
.row {
justify-content: space-around;
- height: 180px;
+ height: 170px;
width: 920px;
}
.app-box {
display: flex;
flex-direction: column;
- align-items: center;
- height: 170px;
- width: 110px;
- margin-top: 10px;
border-radius: 20px;
}
-.image-box {
- height: 110px;
- width: 110px;
- display: flex;
- align-items: center;
- justify-content: center;
-}
-
.app-name {
text-align: center;
width: 110px;
- height: 60px;
+ height: 40px;
color: white;
font-size: 27px;
}
diff --git a/launcher/src/main/js/default/pages/AppGridView/AppGridView.hml b/launcher/src/main/js/default/pages/AppGridView/AppGridView.hml
index 259d332e..5d2ea4dc 100644
--- a/launcher/src/main/js/default/pages/AppGridView/AppGridView.hml
+++ b/launcher/src/main/js/default/pages/AppGridView/AppGridView.hml
@@ -18,46 +18,70 @@
-
-
-
-
-
+
+
+
-
-
-
-
-
- {{ $item.AppName }}
-
+
+
+