- Notifications
You must be signed in to change notification settings - Fork0
A simple HMOS utils library to write any type of data into cache files and read them later.
License
Applib-HarmonyOS/CacheUtilsLibrary
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a simple Android utils library to write any type of data into cache files and then read them later, usingGson to serialize and deserialize these data.
中文版请看这里。
##Gradle
compile'com.lifeofcoding:cacheutilslibrary:1.1.0@aar'compile'com.google.code.gson:gson:2.2.2'compile'commons-io:commons-io:2.4'
If you have errors like:
duplication file during packaging of APK ...Path in archive: META-INF/LICENSE.txt...Please add such code in yourandroid entry of yourbuild.gradle file:
packagingOptions { exclude'META-INF/DEPENDENCIES' exclude'META-INF/NOTICE' exclude'META-INF/LICENSE' exclude'META-INF/LICENSE.txt' exclude'META-INF/NOTICE.txt' exclude'META-INF/ASL2.0' exclude'META-INF/MANIFEST.MF'}##ConfigurationYou need to configureCacheUtilsLibrary in yourApplication class.
publicclassMyApplicationextendsApplication {@OverridepublicvoidonCreate() {super.onCreate();// configure CacheUtilsLibraryCacheUtils.configureCache(this); }}
Don't forget to declare theMyApplication class in yourAndroidManifest.xml file.
##UsageAll sample code can be found in theMainActivity file.#####CacheString File
// writeCacheUtils.writeFile(CACHE_FILE_STRING,CACHE_FILE_CONTENT_STRING);// readStringfileContent =CacheUtils.readFile(CACHE_FILE_STRING);
#####CacheMap<String, T> File
// writeCacheUtils.writeDataMapFile(CACHE_FILE_MAP,getCacheFileContentMap());// readMap<String,Object>mapData =CacheUtils.readDataMapFile(CACHE_FILE_MAP);// get mapDataprivatestaticMap<String,Object>getCacheFileContentMap() {Map<String,Object>mapData =newHashMap<>();mapData.put("firstItem","item0");mapData.put("secondItem",1);mapData.put("thirdItem",false);returnmapData;}
#####CacheList<Map<String, T> File
// writeCacheUtils.writeDataMapsFile(CACHE_FILE_LIST_MAP,getCacheFileContentListMap());// readList<Map<String,Object>>listMapData =CacheUtils.readDataMapsFile(CACHE_FILE_LIST_MAP);// get listMapDataprivatestaticList<Map<String,Object>>getCacheFileContentListMap() {List<Map<String,Object>>listMapData =newArrayList<Map<String,Object>>();for (inti =0;i <4;i++) {Map<String,Object>item =newHashMap<>();item.put("firstItemAt" +i,"item0At" +i);item.put("secondItemAt" +i,1 +i);item.put("thirdItemAt" +i,i %2 ==0);listMapData.add(item); }returnlistMapData;}
#####CacheObject File
// writeCacheUtils.writeObjectFile(CACHE_FILE_OBJECT,MyClass.SAMPLE_MYCLASS_1);// readMyClassmyClassSample =CacheUtils.readObjectFile(CACHE_FILE_OBJECT,newTypeToken<MyClass>(){}.getType());
You can seeMyClass andMyClass.SAMPLE_MYCLASS_1here andhere.
#####CacheList<Object> File
// writeCacheUtils.writeObjectFile(CACHE_FILE_LIST_OBJECT,getCacheFileContentListObject());// readList<MyClass>myClassList =CacheUtils.readObjectFile(CACHE_FILE_LIST_OBJECT,newTypeToken<List<MyClass>>(){}.getType());// get List<MyClass> dataprivatestaticList<MyClass>getCacheFileContentListObject() {List<MyClass>listObject =newArrayList<>();listObject.add(MyClass.SAMPLE_MYCLASS_1);listObject.add(MyClass.SAMPLE_MYCLASS_2);listObject.add(MyClass.SAMPLE_MYCLASS_3);returnlistObject;}
##License
Copyright 2015-2016 Wesley LinLicensed 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 athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.About
A simple HMOS utils library to write any type of data into cache files and read them later.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Contributors3
Uh oh!
There was an error while loading.Please reload this page.