diff --git a/.gitignore b/.gitignore index d702c5c7e883e8b63dc42ad863b93973e14fc470..603b14077394cd2294ac6922fe619669630ef3ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,14 @@ *.iml .gradle /local.properties -/.idea/workspace.xml +/.idea/caches /.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml .DS_Store /build /captures -/.idea - +.externalNativeBuild +.cxx diff --git a/README.md b/README.md index 75c2fea987d712e8e1df8ebbf02a29fadc458cdb..7dc7ad0eeb71095af8da120dc5d76fbc29ed06ad 100755 --- a/README.md +++ b/README.md @@ -1,78 +1,66 @@ -# Glide Bitmap Pool +# Glide Bitmap Pool -[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Glide%20Bitmap%20Pool-blue.svg?style=flat)](http://android-arsenal.com/details/1/3740) -[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/amitshekhariitbhu/GlideBitmapPool/blob/master/LICENSE) +**本项目是基于开源项目Glide Bitmap Pool进行openharmony的移植和开发的,可以通过项目标签以及github地址 ( https://github.com/Sunzxyong/GlideBitmapPool ) 追踪到原项目版本** - +## 项目介绍 -### About Glide Bitmap Pool +- 项目名称:GlideBitmapPool工具类 +- 所属系列:openharmony的第三方组件适配移植 +- 功能:用于重用位图内存的内存管理库 +- 项目移植状态:已完成 +- 调用差异:openharmony与原库内存展示有差异 +- 开发版本:sdk5,DevEco Studio2.1 beta4 +- 原项目Doc地址: -Glide Bitmap Pool is a memory management library for reusing the bitmap memory. As it reuses bitmap memory , so -no more GC calling again and again , hence smooth running application. It uses inBitmap while decoding the bitmap -on the supported android versions. All the version use-cases has been handled to optimize it better. +## 项目介绍 -* [Glide](https://github.com/bumptech/glide) , [Fresco](https://github.com/facebook/fresco) and [Fast Android Networking](https://github.com/amitshekhariitbhu/Fast-Android-Networking) uses Bitmap Pool Concept to -load images efficiently. +- 编程语言:Java -### Why use this library ? +## 安装教程 -An Image heavy Application decodes many images , so there will be continuous allocation and deallocation -of memory in application , and that results in very frequent calling of GC(Garbage Collector). And -finally because of very frequent calling of GC , the application UI freezes. -Use Bitmap pool to avoid continuous allocation and deallocation of memory in application -and reduce GC overhead that will result in smooth running application. -Suppose we have to load few bitmap in Android Application. -When we load bitmapOne , it will allocate the memory for bitmapOne. -Then if we don’t need bitmapOne , do not recycle bitmap (as if you recycle, it will make GC to be called) , -so use this bitmapOne as an inBitmap for bitmapTwo so that , the same memory can be reused for bitmapTwo. -In this way , we can avoid continuous allocation and deallocation of memory in application and reduce GC overhead. -But the problem is that there are few restrictions as android version less than Honeycomb does not supports it , -few android version less than Kitkat only when we use inSampleSize = 1 , above that it supports -completely and few other issues. -So , all these types of cases are handled in this library - -* [Detail Explanation can be found here](https://medium.com/@amitshekhar/how-to-use-bitmap-pool-in-android-56c71a55533c#.m41wqfk8h) - -#### GET RID OF : GC_FOR_ALLOC freed 1568K, 23% free 37664K/48844K, paused 141ms, total 143ms - (whenever you see this log , your application is lagging) - - - -### Show some :heart: -* Be sure to click the "Star" button in the upper right of this page. :smile: +1.在项目根目录下的build.gradle文件中, +``` + allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } + } +``` -[![GitHub stars](https://img.shields.io/github/stars/amitshekhariitbhu/GlideBitmapPool.svg?style=social&label=Star)](https://github.com/amitshekhariitbhu/GlideBitmapPool) [![GitHub forks](https://img.shields.io/github/forks/amitshekhariitbhu/GlideBitmapPool.svg?style=social&label=Fork)](https://github.com/amitshekhariitbhu/GlideBitmapPool/fork) [![GitHub followers](https://img.shields.io/github/followers/amitshekhariitbhu.svg?style=social&label=Follow)](https://github.com/amitshekhariitbhu) -[![Twitter Follow](https://img.shields.io/twitter/follow/amitiitbhu.svg?style=social)](https://twitter.com/amitiitbhu) +2.在项目根目录下的build.gradle文件中, +``` + dependencies { + implementation('com.gitee.chinasoft_ohos:GlideBitmapPool:0.0.1-SNAPSHOT') + ...... + } +``` -## Requirements -Glide Bitmap Pool can be included in any Android or Java application. +如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, -Glide Bitmap Pool supports Android 2.3 (Gingerbread) and later. +并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 -## Using Glide Bitmap Pool in your application +## 使用说明 -Add this in your build.gradle -```groovy -compile 'com.amitshekhar.android:glide-bitmap-pool:0.0.1' -``` -Then initialize it in onCreate() Method of application class, : ```java GlideBitmapPool.initialize(10 * 1024 * 1024); // 10mb max memory size ``` ### Decoding the bitmap from file path ```java -Bitmap bitmap = GlideBitmapFactory.decodeFile(filePath); +PixelMap pixelMap = GlideBitmapFactory.decodeFile(filePath); ``` ### Decoding the bitmap from resources ```java -Bitmap bitmap = GlideBitmapFactory.decodeResource(getResources(), R.drawable.testImage); +PixelMap pixelMap = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test1); ``` ### Decoding the down sample bitmap ```java -Bitmap bitmap = GlideBitmapFactory.decodeFile(filePath,100,100); +PixelMap pixelMap = GlideBitmapFactory.decodeFile(filePath,100,100); ``` ### Making the bitmap available for recycle or reuse @@ -82,7 +70,7 @@ GlideBitmapPool.putBitmap(bitmap); ### Getting the empty bitmap from the pool ```java -Bitmap bitmap = GlideBitmapPool.getBitmap(width, height, config); +PixelMap pixelMap = GlideBitmapPool.getBitmap(width, height, config); ``` ### Clearing or Trimming Memory @@ -94,14 +82,10 @@ GlideBitmapPool.trimMemory(level); ### Migrating to Glide Bitmap Pool ```java // ------ decoding ------- +// new code +PixelMap pixelMap = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test1); -// old code -Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test1); - -// new code -Bitmap bitmap = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test1); - -// ------ recycling ------- +// ------ recycling ------- // old code bitmap.recycle(); @@ -110,12 +94,8 @@ bitmap.recycle(); GlideBitmapPool.putBitmap(bitmap); // ------ creating a bitmap ------- - -// old code -Bitmap bitmap = Bitmap.create(width, height, config); - // new code -Bitmap bitmap = GlideBitmapPool.getBitmap(width, height, config); +PixelMap pixelMap = GlideBitmapPool.getBitmap(width, height, config); ``` ### Important @@ -127,24 +107,20 @@ Bitmap bitmap = GlideBitmapPool.getBitmap(width, height, config); // use GlideBitmapPool.getBitmap(width, height, config); as it returns bitmap from the pool that can be reused. ``` -### Credits and references -* [Glide](https://github.com/bumptech/glide) - As it uses the same bitmap pool that is used by [Glide](https://github.com/bumptech/glide) -* [Managing Bitmap Memory](https://developer.android.com/training/displaying-bitmaps/manage-memory.html) -* [Loading Large Bitmaps Efficiently](https://developer.android.com/training/displaying-bitmaps/load-bitmap.html) -### TODO -* More Optimization with further updates. +## 测试信息 +CodeCheck代码测试无异常 -### Contact - Let's become friend -- [Twitter](https://twitter.com/amitiitbhu) -- [Github](https://github.com/amitshekhariitbhu) -- [Medium](https://medium.com/@amitshekhar) -- [Facebook](https://www.facebook.com/amit.shekhar.iitbhu) +CloudTest代码测试无异常 -### Have an issue or need a feature in Glide Bitmap Pool -- Best way to do so is - [Create an issue](https://github.com/amitshekhariitbhu/GlideBitmapPool/issues/new) +火绒安全病毒安全检测通过 -### License +当前版本demo功能与原组件基本无差异 + +## 版本迭代 +- 0.0.1-SNAPSHOT + +## 版权和许可信息 ``` Copyright (C) 2016 Amit Shekhar Copyright (C) 2011 Android Open Source Project @@ -160,7 +136,4 @@ Bitmap bitmap = GlideBitmapPool.getBitmap(width, height, config); 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. -``` - -### Contributing to Glide Bitmap Pool -Just make pull request. You are in! \ No newline at end of file +``` \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index ad67144199f66bac096542b0f4af91ee99c20a1b..0000000000000000000000000000000000000000 --- a/app/build.gradle +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2016 Amit Shekhar - * Copyright (C) 2011 Android Open Source Project - * - * 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. - */ - -apply plugin: 'com.android.application' - -android { - compileSdkVersion 23 - buildToolsVersion "23.0.3" - - defaultConfig { - applicationId "com.glidebitmappool" - minSdkVersion 15 - targetSdkVersion 23 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.4.0' - compile project(':glide-bitmap-pool') -} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro deleted file mode 100644 index 6b7a2bf25ec2e485c512e8a370e46db237828a65..0000000000000000000000000000000000000000 --- a/app/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/amitshekhar/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/app/src/androidTest/java/com/glidebitmappool/ApplicationTest.java b/app/src/androidTest/java/com/glidebitmappool/ApplicationTest.java deleted file mode 100644 index b4c28d844afdb7ac2388520a54760c76fbfb3fd7..0000000000000000000000000000000000000000 --- a/app/src/androidTest/java/com/glidebitmappool/ApplicationTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2016 Amit Shekhar - * Copyright (C) 2011 Android Open Source Project - * - * 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. - */ - -package com.glidebitmappool; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/androidTest/java/com/glidebitmappoolsample/ApplicationTest.java b/app/src/androidTest/java/com/glidebitmappoolsample/ApplicationTest.java deleted file mode 100644 index e5b8bc2e1f94f59813e3b26ad4d7cc3212ad93c5..0000000000000000000000000000000000000000 --- a/app/src/androidTest/java/com/glidebitmappoolsample/ApplicationTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2016 Amit Shekhar - * Copyright (C) 2011 Android Open Source Project - * - * 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. - */ - -package com.glidebitmappoolsample; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml deleted file mode 100644 index c20d66abfdd85314ff3d1629bde89ad4840cdda8..0000000000000000000000000000000000000000 --- a/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/glidebitmappoolsample/MainActivity.java b/app/src/main/java/com/glidebitmappoolsample/MainActivity.java deleted file mode 100644 index a0e724f312a9f6b68efea2beb6a774259f9347b3..0000000000000000000000000000000000000000 --- a/app/src/main/java/com/glidebitmappoolsample/MainActivity.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2016 Amit Shekhar - * Copyright (C) 2011 Android Open Source Project - * - * 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. - */ - -package com.glidebitmappoolsample; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.Bundle; -import android.os.Environment; -import android.support.v7.app.AppCompatActivity; -import android.view.View; - -import com.glidebitmappool.GlideBitmapFactory; -import com.glidebitmappool.GlideBitmapPool; - -import java.io.File; - -public class MainActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - GlideBitmapPool.initialize(10 * 1024 * 1024); - } - - public void normalResource(View view) { - new Thread(new Runnable() { - @Override - public void run() { - Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.test1); - bitmap1.recycle(); - Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.test2); - bitmap2.recycle(); - Bitmap bitmap3 = BitmapFactory.decodeResource(getResources(), R.drawable.test3); - bitmap3.recycle(); - Bitmap bitmap4 = BitmapFactory.decodeResource(getResources(), R.drawable.test4); - bitmap4.recycle(); - Bitmap bitmap5 = BitmapFactory.decodeResource(getResources(), R.drawable.test5); - bitmap5.recycle(); - Bitmap bitmap6 = BitmapFactory.decodeResource(getResources(), R.drawable.test6); - bitmap6.recycle(); - Bitmap bitmap7 = BitmapFactory.decodeResource(getResources(), R.drawable.test7); - bitmap7.recycle(); - Bitmap bitmap8 = BitmapFactory.decodeResource(getResources(), R.drawable.test8); - bitmap8.recycle(); - Bitmap bitmap9 = BitmapFactory.decodeResource(getResources(), R.drawable.test9); - bitmap9.recycle(); - Bitmap bitmap10 = BitmapFactory.decodeResource(getResources(), R.drawable.test10); - bitmap10.recycle(); - } - }).start(); - } - - public void normalFile(View view) { - new Thread(new Runnable() { - @Override - public void run() { - String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Download" + File.separator + "test"; - for (int i = 1; i <= 10; i++) { - Bitmap bitmap = BitmapFactory.decodeFile(path + i + ".png"); - bitmap.recycle(); - } - } - }).start(); - } - - public void resourceOptimized(View view) { - - new Thread(new Runnable() { - @Override - public void run() { - Bitmap bitmap1 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test1); - GlideBitmapPool.putBitmap(bitmap1); - - Bitmap bitmap2 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test2); - GlideBitmapPool.putBitmap(bitmap2); - - Bitmap bitmap3 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test3); - GlideBitmapPool.putBitmap(bitmap3); - - Bitmap bitmap4 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test4); - GlideBitmapPool.putBitmap(bitmap4); - - Bitmap bitmap5 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test5); - GlideBitmapPool.putBitmap(bitmap5); - - Bitmap bitmap6 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test6); - GlideBitmapPool.putBitmap(bitmap6); - - Bitmap bitmap7 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test7); - GlideBitmapPool.putBitmap(bitmap7); - - Bitmap bitmap8 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test8); - GlideBitmapPool.putBitmap(bitmap8); - - Bitmap bitmap9 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test9); - GlideBitmapPool.putBitmap(bitmap9); - - Bitmap bitmap10 = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test10); - GlideBitmapPool.putBitmap(bitmap10); - } - }).start(); - } - - public void fileOptimized(View view) { - new Thread(new Runnable() { - @Override - public void run() { - try { - String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Download" + File.separator + "test"; - for (int i = 1; i <= 10; i++) { - Bitmap bitmap = GlideBitmapFactory.decodeFile(path + i + ".png"); - GlideBitmapPool.putBitmap(bitmap); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - }).start(); - } - - public void downSample(View view) { - new Thread(new Runnable() { - @Override - public void run() { - try { - String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Download" + File.separator + "test"; - for (int i = 1; i <= 10; i++) { - Bitmap bitmap = GlideBitmapFactory.decodeFile(path + i + ".png", 100, 100); - GlideBitmapPool.putBitmap(bitmap); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - }).start(); - } - - public void clearMemory(View view) { - GlideBitmapPool.clearMemory(); - } -} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index da7d39c72155316c2cb6ae7b30c694f858b2033e..0000000000000000000000000000000000000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - -