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
-[](http://android-arsenal.com/details/1/3740)
-[](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/'
+ }
+ }
+ }
+```
-[](https://github.com/amitshekhariitbhu/GlideBitmapPool) [](https://github.com/amitshekhariitbhu/GlideBitmapPool/fork) [](https://github.com/amitshekhariitbhu)
-[](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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
deleted file mode 100644
index cde69bcccec65160d92116f20ffce4fce0b5245c..0000000000000000000000000000000000000000
Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
deleted file mode 100644
index c133a0cbd379f5af6dbf1a899a0293ca5eccfad0..0000000000000000000000000000000000000000
Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
deleted file mode 100644
index bfa42f0e7b91d006d22352c9ff2f134e504e3c1d..0000000000000000000000000000000000000000
Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
deleted file mode 100644
index 324e72cdd7480cb983fa1bcc7ce686e51ef87fe7..0000000000000000000000000000000000000000
Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
deleted file mode 100644
index aee44e138434630332d88b1680f33c4b24c70ab3..0000000000000000000000000000000000000000
Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ
diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml
deleted file mode 100644
index f27c022457b138b41deb13dac47c9d3db5105e97..0000000000000000000000000000000000000000
--- a/app/src/main/res/values-w820dp/dimens.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
- 64dp
-
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
deleted file mode 100644
index df69d36a97587112be9f99e54936604483e3a12f..0000000000000000000000000000000000000000
--- a/app/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
- #3F51B5
- #303F9F
- #FF4081
-
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
deleted file mode 100644
index a5c4f5b639fa6d45a7ab3cfcafd2a6241ad598c2..0000000000000000000000000000000000000000
--- a/app/src/main/res/values/dimens.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
- 16dp
- 16dp
-
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
deleted file mode 100644
index 46f6f4bf9c53857fa72ddf74b32446a6d00f659f..0000000000000000000000000000000000000000
--- a/app/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
- GlideBitmapPool
-
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
deleted file mode 100644
index c1b962ce967991d482f08a3fea9866b5c6018c87..0000000000000000000000000000000000000000
--- a/app/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/app/src/test/java/com/glidebitmappool/ExampleUnitTest.java b/app/src/test/java/com/glidebitmappool/ExampleUnitTest.java
deleted file mode 100644
index 0489d698c23672c7702034b6e267bff3c606ed19..0000000000000000000000000000000000000000
--- a/app/src/test/java/com/glidebitmappool/ExampleUnitTest.java
+++ /dev/null
@@ -1,32 +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 org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * To work on unit tests, switch the Test Artifact in the Build Variants view.
- */
-public class ExampleUnitTest {
- @Test
- public void addition_isCorrect() throws Exception {
- assertEquals(4, 2 + 2);
- }
-}
\ No newline at end of file
diff --git a/assets/gcsamplelog.png b/assets/gcsamplelog.png
deleted file mode 100644
index 65b097755e67476401cdcd5aea44feecb366d36e..0000000000000000000000000000000000000000
Binary files a/assets/gcsamplelog.png and /dev/null differ
diff --git a/assets/glidebitmappool.png b/assets/glidebitmappool.png
deleted file mode 100644
index 8c674c0a0c8f06e41a67f9f81b73f1bc4d50d354..0000000000000000000000000000000000000000
Binary files a/assets/glidebitmappool.png and /dev/null differ
diff --git a/build.gradle b/build.gradle
index cf197e5f74b7c219b02607c7b3f24584a8f3fa88..65297cc8d10945f0d0ce2519f0492ca27b006e3d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,41 +1,40 @@
-/*
- * 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.
- */
-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
+apply plugin: 'com.huawei.ohos.app'
+
+ohos {
+ compileSdkVersion 5
+ defaultConfig {
+ compatibleSdkVersion 4
+ }
+}
buildscript {
repositories {
+ maven {
+ url 'https://mirrors.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.0'
- classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
- classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
+ classpath 'com.huawei.ohos:hap:2.4.2.7'
+ classpath 'com.huawei.ohos:decctest:1.0.0.6'
}
}
allprojects {
repositories {
+ maven {
+ url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
+ }
+ maven {
+ url 'https://mirrors.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
jcenter()
}
}
-
-task clean(type: Delete) {
- delete rootProject.buildDir
-}
diff --git a/changeLog.md b/changeLog.md
new file mode 100644
index 0000000000000000000000000000000000000000..71738d8598ab9bd353ed1fb2980c50c290192a3a
--- /dev/null
+++ b/changeLog.md
@@ -0,0 +1,11 @@
+# 基本功能:
+ 用于重用位图内存的内存管理库
+
+
+# 修改点:
+1. 暂无
+
+
+# 遗留问题(暂不支持的功能):
+1. openharmony与原项目内存展示有差异
+2. decodeResourceStream方法暂不支持
\ No newline at end of file
diff --git a/app/.gitignore b/entry/.gitignore
similarity index 100%
rename from app/.gitignore
rename to entry/.gitignore
diff --git a/entry/build.gradle b/entry/build.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..45d90ee70bba79bcfe5e28204118d4244b00f8e3
--- /dev/null
+++ b/entry/build.gradle
@@ -0,0 +1,13 @@
+apply plugin: 'com.huawei.ohos.hap'
+ohos {
+ compileSdkVersion 5
+ defaultConfig {
+ compatibleSdkVersion 4
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
+ testCompile 'junit:junit:4.12'
+ compile project(path: ':glide_bitmap_pool')
+}
diff --git a/entry/src/main/config.json b/entry/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..e9636f9fd7e878fee174dd156f187a321aa0bb6e
--- /dev/null
+++ b/entry/src/main/config.json
@@ -0,0 +1,71 @@
+{
+ "app": {
+ "bundleName": "com.glidebitmappoolsample",
+ "vendor": "work",
+ "version": {
+ "code": 1,
+ "name": "1.0"
+ },
+ "apiVersion": {
+ "compatible": 5,
+ "target": 5,
+ "releaseType": "Release"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "reqPermissions": [
+ {
+ "name": "ohos.permission.WRITE_MEDIA",
+ "reason": "允许应用读写用户外部存储中的媒体文件信息",
+ "usedScene": {
+ "ability": [
+ "com.glidebitmappoolsample.MainAbilty"
+ ],
+ "when": "always"
+ }
+ },
+ {
+ "name": "ohos.permission.READ_MEDIA",
+ "reason": "允许应用读取用户外部存储中的媒体文件信息",
+ "usedScene": {
+ "ability": [
+ "com.glidebitmappoolsample.MainAbilty"
+ ],
+ "when": "always"
+ }
+ }
+ ],
+ "package": "com.glidebitmappoolsample",
+ "name": ".MyApplication",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "entry",
+ "moduleType": "entry"
+ },
+ "abilities": [
+ {
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home"
+ ]
+ }
+ ],
+ "orientation": "unspecified",
+ "name": "com.glidebitmappoolsample.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "HM_GlideBitmapPool_master",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/entry/src/main/java/com/glidebitmappoolsample/Constants.java b/entry/src/main/java/com/glidebitmappoolsample/Constants.java
new file mode 100644
index 0000000000000000000000000000000000000000..1fc23140671b60be68b8612317ffd6b57a90d5f5
--- /dev/null
+++ b/entry/src/main/java/com/glidebitmappoolsample/Constants.java
@@ -0,0 +1,65 @@
+/*
+ * 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 an 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;
+
+/**
+ * 静态常量
+ *
+ * @author renpengfei
+ * @since 2021-05-14
+ */
+public final class Constants {
+ /**
+ * 10
+ */
+ public static final int TEN = 10;
+ /**
+ * 20
+ */
+ public static final int TWENTY = 20;
+
+ /**
+ * 100
+ */
+ public static final int ONE_HUNDRED = 100;
+ /**
+ * 1024
+ */
+ public static final int ONE_THOUSAND_AND_TWENTY_FOUR = 1024;
+ /**
+ * -1
+ */
+ public static final int NEGATIVE_ONE = -1;
+ /**
+ * test
+ */
+ public static final String TEST = "test";
+ /**
+ * 格式
+ */
+ public static final String FORMAT = ".png";
+
+ /**
+ * 打印
+ */
+ public static final String TAG = "TAG";
+
+ /**
+ * 构造
+ */
+ private Constants() {
+ }
+}
diff --git a/entry/src/main/java/com/glidebitmappoolsample/MainAbility.java b/entry/src/main/java/com/glidebitmappoolsample/MainAbility.java
new file mode 100644
index 0000000000000000000000000000000000000000..13a4c0fa2d3d1c396c1760a4682cb74464fad438
--- /dev/null
+++ b/entry/src/main/java/com/glidebitmappoolsample/MainAbility.java
@@ -0,0 +1,114 @@
+/*
+ * 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 an 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 com.glidebitmappool.GlideBitmapPool;
+
+import com.glidebitmappoolsample.slice.MainAbilitySlice;
+import com.glidebitmappoolsample.util.FileUtils;
+import ohos.aafwk.ability.Ability;
+import ohos.aafwk.content.Intent;
+import ohos.agp.window.dialog.ToastDialog;
+import ohos.bundle.IBundleManager;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+
+/**
+ * 主页
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ */
+public class MainAbility extends Ability {
+ private static final int PERMISSION_REQUEST_CODE = 0;
+ private static final String WRITE_USER_STORAGE = "ohos.permission.WRITE_USER_STORAGE";
+ private static final String READ_USER_STORAGE = "ohos.permission.READ_USER_STORAGE";
+ private static final int MAX_SIZE = 2 * 1024 * 1024;
+ private String mRequiredError1 = null;
+ private String mRequiredError2 = null;
+ private String mRequiredSuccess = null;
+
+ private HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x001, "TAG");
+
+ /**
+ * 主页初始化
+ *
+ * @param intent
+ */
+ @Override
+ public void onStart(Intent intent) {
+ super.onStart(intent);
+ super.setMainRoute(MainAbilitySlice.class.getName());
+
+ FileUtils.copy2Memory(getContext(), "icon.png");
+ for (int i1 = 1; i1 <= Constants.TWENTY; i1++) {
+ String path = "test" + i1 + ".png";
+ FileUtils.copy2Memory(getContext(), path);
+ }
+
+ GlideBitmapPool.initialize(MAX_SIZE);
+
+ mRequiredError1 = getString(ResourceTable.String_image_access_required);
+ mRequiredError2 = getString(ResourceTable.String_storage_permission_denied);
+ mRequiredSuccess = getString(ResourceTable.String_image_access_success);
+
+ requestPermission();
+ }
+
+ private void requestPermission() {
+ if (verifyCallingPermission(WRITE_USER_STORAGE) != IBundleManager.PERMISSION_GRANTED
+ || verifyCallingPermission(READ_USER_STORAGE) != IBundleManager.PERMISSION_GRANTED) {
+ if (canRequestPermission(WRITE_USER_STORAGE)
+ || canRequestPermission(READ_USER_STORAGE)) {
+ requestPermissionsFromUser(
+ new String[]{WRITE_USER_STORAGE, READ_USER_STORAGE}, PERMISSION_REQUEST_CODE);
+ } else {
+ HiLog.error(logLabel, mRequiredError1);
+ new ToastDialog(getContext()).setContentText(mRequiredError1).show();
+ }
+ } else {
+ HiLog.error(logLabel, mRequiredError2);
+ new ToastDialog(getContext()).setContentText(mRequiredError2).show();
+ }
+ }
+
+ /**
+ * 请求权限回调
+ *
+ * @param requestCode
+ * @param permissions
+ * @param grantResults
+ */
+ @Override
+ public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) {
+ super.onRequestPermissionsFromUserResult(requestCode, permissions, grantResults);
+ switch (requestCode) {
+ case PERMISSION_REQUEST_CODE:
+ if (grantResults.length > 0 && (grantResults[0] == IBundleManager.PERMISSION_GRANTED
+ && grantResults[1] == IBundleManager.PERMISSION_GRANTED)) {
+ HiLog.error(logLabel, mRequiredSuccess);
+ new ToastDialog(getContext()).setContentText(mRequiredSuccess).show();
+ } else {
+ HiLog.error(logLabel, mRequiredError2);
+ new ToastDialog(getContext()).setContentText(mRequiredError2).show();
+ }
+ return;
+ default:
+ break;
+ }
+ }
+}
diff --git a/entry/src/main/java/com/glidebitmappoolsample/MyApplication.java b/entry/src/main/java/com/glidebitmappoolsample/MyApplication.java
new file mode 100644
index 0000000000000000000000000000000000000000..3d0e651949d629f477ac331b1b6ac1f76ccdc9d3
--- /dev/null
+++ b/entry/src/main/java/com/glidebitmappoolsample/MyApplication.java
@@ -0,0 +1,35 @@
+/*
+ * 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 an 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 ohos.aafwk.ability.AbilityPackage;
+
+/**
+ * 主程序
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ */
+public class MyApplication extends AbilityPackage {
+ /**
+ * 初始化
+ */
+ @Override
+ public void onInitialize() {
+ super.onInitialize();
+ }
+}
diff --git a/entry/src/main/java/com/glidebitmappoolsample/slice/MainAbilitySlice.java b/entry/src/main/java/com/glidebitmappoolsample/slice/MainAbilitySlice.java
new file mode 100644
index 0000000000000000000000000000000000000000..2ccadfa7ed479aad8e8eac1b56f67bca63acb8d6
--- /dev/null
+++ b/entry/src/main/java/com/glidebitmappoolsample/slice/MainAbilitySlice.java
@@ -0,0 +1,258 @@
+/*
+ * 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 an 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.slice;
+
+import com.glidebitmappool.GlideBitmapFactory;
+import com.glidebitmappool.GlideBitmapPool;
+
+import com.glidebitmappoolsample.Constants;
+import com.glidebitmappoolsample.ResourceTable;
+import ohos.aafwk.ability.AbilitySlice;
+import ohos.aafwk.content.Intent;
+import ohos.agp.components.Button;
+import ohos.agp.components.Component;
+import ohos.agp.utils.LayoutAlignment;
+import ohos.agp.window.dialog.ToastDialog;
+import ohos.app.Environment;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+import ohos.media.image.ImageSource;
+import ohos.media.image.PixelMap;
+
+import java.io.File;
+
+/**
+ * 主页
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ */
+public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
+ private HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x001, "TAG");
+
+ /**
+ * 主页启动
+ *
+ * @param intent
+ */
+ @Override
+ public void onStart(Intent intent) {
+ super.onStart(intent);
+ super.setUIContent(ResourceTable.Layout_ability_main);
+
+ initComponent();
+ }
+
+ private void initComponent() {
+ Button normalResource = (Button) findComponentById(ResourceTable.Id_normalResource);
+ Button normalFile = (Button) findComponentById(ResourceTable.Id_normalFile);
+ Button resourceOptimized = (Button) findComponentById(ResourceTable.Id_resourceOptimized);
+ normalResource.setClickedListener(this);
+ normalFile.setClickedListener(this);
+ resourceOptimized.setClickedListener(this);
+
+ Button fileOptimized = (Button) findComponentById(ResourceTable.Id_fileOptimized);
+ Button downSample = (Button) findComponentById(ResourceTable.Id_downSample);
+ Button clearMemory = (Button) findComponentById(ResourceTable.Id_clearMemory);
+ fileOptimized.setClickedListener(this);
+ downSample.setClickedListener(this);
+ clearMemory.setClickedListener(this);
+ }
+
+ /**
+ * 正常资源回收机制
+ */
+ private void runNormalResource() {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ releaseBitmapMethod();
+ }
+ }).start();
+ }
+
+ private void releaseBitmapMethod() {
+ HiLog.error(logLabel, "runNormalResource---start");
+ ImageSource imageSource = ImageSource.createIncrementalSource(new ImageSource.SourceOptions());
+ PixelMap pixelMap1 = imageSource.createPixelmap(
+ ResourceTable.Media_test1, GlideBitmapFactory.getDecodingOptions());
+ pixelMap1.release();
+ PixelMap pixelMap2 = imageSource.createPixelmap(
+ ResourceTable.Media_test2,GlideBitmapFactory.getDecodingOptions());
+ pixelMap2.release();
+ PixelMap pixelMap3 = imageSource.createPixelmap(
+ ResourceTable.Media_test3,GlideBitmapFactory.getDecodingOptions());
+ pixelMap3.release();
+ PixelMap pixelMap4 = imageSource.createPixelmap(
+ ResourceTable.Media_test4,GlideBitmapFactory.getDecodingOptions());
+ pixelMap4.release();
+ PixelMap pixelMap5 = imageSource.createPixelmap(
+ ResourceTable.Media_test5,GlideBitmapFactory.getDecodingOptions());
+ pixelMap5.release();
+ PixelMap pixelMap6 = imageSource.createPixelmap(
+ ResourceTable.Media_test6,GlideBitmapFactory.getDecodingOptions());
+ pixelMap6.release();
+ PixelMap pixelMap7 = imageSource.createPixelmap(
+ ResourceTable.Media_test7,GlideBitmapFactory.getDecodingOptions());
+ pixelMap7.release();
+ PixelMap pixelMap8 = imageSource.createPixelmap(
+ ResourceTable.Media_test8,GlideBitmapFactory.getDecodingOptions());
+ pixelMap8.release();
+ PixelMap pixelMap9 = imageSource.createPixelmap(
+ ResourceTable.Media_test9,GlideBitmapFactory.getDecodingOptions());
+ pixelMap9.release();
+ PixelMap pixelMap10 = imageSource.createPixelmap(
+ ResourceTable.Media_test10,GlideBitmapFactory.getDecodingOptions());
+ pixelMap10.release();
+ HiLog.error(logLabel, "runNormalResource---end");
+ }
+
+ /**
+ * 普通文件回收机制
+ */
+ private void runNormalFile() {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ HiLog.error(logLabel, "runNormalFile---start");
+ String path = getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath()
+ + File.separator + Constants.TEST;
+ HiLog.error(logLabel, "runNormalFile--path--" + path);
+ for (int i1 = 1; i1 <= Constants.TEN; i1++) {
+ ImageSource imageSource = ImageSource.create(
+ path + i1 + Constants.FORMAT,new ImageSource.SourceOptions());
+ PixelMap pixelMap = imageSource.createPixelmap(GlideBitmapFactory.getDecodingOptions());
+ pixelMap.release();
+ }
+ HiLog.error(logLabel, "runNormalFile---end");
+ }
+ }).start();
+ }
+
+ private void runResourceOptimized() {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ putBitmapMethod();
+ }
+ }).start();
+ }
+
+ private void putBitmapMethod() {
+ HiLog.error(logLabel,"runResourceOptimized---start");
+ PixelMap pixelMap1 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test1);
+ GlideBitmapPool.putBitmap(pixelMap1);
+ PixelMap pixelMap2 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test2);
+ GlideBitmapPool.putBitmap(pixelMap2);
+ PixelMap pixelMap3 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test3);
+ GlideBitmapPool.putBitmap(pixelMap3);
+ PixelMap pixelMap4 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test4);
+ GlideBitmapPool.putBitmap(pixelMap4);
+ PixelMap pixelMap5 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test5);
+ GlideBitmapPool.putBitmap(pixelMap5);
+ PixelMap pixelMap6 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test6);
+ GlideBitmapPool.putBitmap(pixelMap6);
+ PixelMap pixelMap7 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test7);
+ GlideBitmapPool.putBitmap(pixelMap7);
+ PixelMap pixelMap8 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test8);
+ GlideBitmapPool.putBitmap(pixelMap8);
+ PixelMap pixelMap9 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test9);
+ GlideBitmapPool.putBitmap(pixelMap9);
+ PixelMap pixelMap10 = GlideBitmapFactory.decodeResource(getContext(), ResourceTable.Media_test10);
+ GlideBitmapPool.putBitmap(pixelMap10);
+ }
+
+ private void runFileOptimized() {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ HiLog.error(logLabel, "runFileOptimized---start");
+ String path = getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath()
+ + File.separator + Constants.TEST;
+ HiLog.error(logLabel, "runFileOptimized--path--" + path);
+ for (int i1 = 1; i1 <= Constants.TEN; i1++) {
+ PixelMap pixelMap = GlideBitmapFactory.decodeFile(path + i1 + Constants.FORMAT);
+ GlideBitmapPool.putBitmap(pixelMap);
+ }
+ HiLog.error(logLabel, "runFileOptimized---end");
+ } catch (IllegalArgumentException e) {
+ HiLog.error(logLabel, e.getMessage());
+ }
+ }
+ }).start();
+ }
+
+ private void runDownSample() {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ HiLog.error(logLabel, "runDownSample---start");
+ String absolutePath = getContext().getExternalCacheDir().getAbsolutePath();
+ String path = getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath()
+ + File.separator + Constants.TEST;
+ for (int i1 = 1; i1 <= Constants.TEN; i1++) {
+ PixelMap pixelMap = GlideBitmapFactory.decodeFile(
+ path + i1 + Constants.FORMAT, Constants.ONE_HUNDRED, Constants.ONE_HUNDRED);
+ GlideBitmapPool.putBitmap(pixelMap);
+ }
+ HiLog.error(logLabel, "runDownSample---end");
+ } catch (IllegalArgumentException e) {
+ HiLog.error(logLabel, e.getMessage());
+ }
+ }
+ }).start();
+ }
+
+ private void clearMemory() {
+ GlideBitmapPool.clearMemory();
+ HiLog.error(logLabel, "clearMemory");
+ new ToastDialog(getContext()).setText("clearMemory").setAlignment(LayoutAlignment.CENTER).show();
+ }
+
+ /**
+ * button 事件监听
+ *
+ * @param component
+ */
+ @Override
+ public void onClick(Component component) {
+ switch (component.getId()) {
+ case ResourceTable.Id_normalFile:
+ runNormalFile();
+ break;
+ case ResourceTable.Id_normalResource:
+ runNormalResource();
+ break;
+ case ResourceTable.Id_resourceOptimized:
+ runResourceOptimized();
+ break;
+ case ResourceTable.Id_fileOptimized:
+ runFileOptimized();
+ break;
+ case ResourceTable.Id_downSample:
+ runDownSample();
+ break;
+ case ResourceTable.Id_clearMemory:
+ clearMemory();
+ break;
+ default:
+ break;
+ }
+ }
+}
\ No newline at end of file
diff --git a/entry/src/main/java/com/glidebitmappoolsample/util/FileUtils.java b/entry/src/main/java/com/glidebitmappoolsample/util/FileUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..801999469e20755a0e9fe435249afadd0d41159a
--- /dev/null
+++ b/entry/src/main/java/com/glidebitmappoolsample/util/FileUtils.java
@@ -0,0 +1,142 @@
+/*
+ * 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 an 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.util;
+
+import com.glidebitmappoolsample.Constants;
+import ohos.app.Context;
+import ohos.app.Environment;
+import ohos.global.resource.RawFileEntry;
+import ohos.global.resource.ResourceManager;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+import java.nio.charset.StandardCharsets;
+import java.util.Locale;
+
+/**
+ * 文件工具类
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ */
+public final class FileUtils {
+ private static HiLogLabel hiLogLabel = new HiLogLabel(HiLog.LOG_APP, 0x001, Constants.TAG);
+ private static boolean delete;
+
+ private FileUtils() {
+ }
+
+ /**
+ * 复制文件到当前目录
+ *
+ * @param context
+ * @param fileName
+ * @return boolean
+ */
+ public static boolean copy2Memory(Context context, String fileName) {
+ File cacheDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
+ try {
+ if (!cacheDir.exists()) {
+ boolean mkdirs = cacheDir.mkdirs();
+ }
+ File outFile = new File(cacheDir, fileName);
+ if (!outFile.exists()) {
+ boolean isRes = outFile.createNewFile();
+ if (!isRes) {
+ return false;
+ }
+ } else if (outFile.length() > (long) Constants.TEN) {
+ return true;
+ }
+ InputStream inputStream = getInputStream(context, fileName);
+
+ FileOutputStream fos = new FileOutputStream(outFile);
+ byte[] buffer = new byte[Constants.ONE_THOUSAND_AND_TWENTY_FOUR];
+ int byteCount;
+ while ((byteCount = inputStream.read(buffer)) != Constants.NEGATIVE_ONE) {
+ fos.write(buffer, 0, byteCount);
+ }
+ fos.flush();
+ inputStream.close();
+ fos.close();
+ return true;
+ } catch (IllegalArgumentException | IOException e) {
+ HiLog.error(hiLogLabel, e.getMessage());
+ return false;
+ }
+ }
+
+ private static InputStream getInputStream(Context context, String fileName) {
+ ResourceManager resourceManager = context.getResourceManager();
+ RawFileEntry rawFileEntry = resourceManager.getRawFileEntry(
+ String.format("resources/rawfile/%s".toLowerCase(Locale.ENGLISH), fileName));
+ InputStream inputStream = null;
+ try {
+ inputStream = rawFileEntry.openRawFile();
+ } catch (IOException e) {
+ e.getMessage();
+ }
+ return inputStream;
+ }
+
+ /**
+ * 获取文件名称
+ *
+ * @param filePath
+ * @return String
+ */
+ public static String getFileName(String filePath) {
+ return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
+ }
+
+ /**
+ * 创建写入内容文件
+ * 请注意一定要申请文件读写权限
+ *
+ * @param context
+ * @param filePaths
+ * @return String
+ */
+ public static String createInputFile(Context context, String... filePaths) {
+ File file = new File(context.getExternalCacheDir(), "input.txt");
+ StringBuilder content = new StringBuilder();
+ for (String filePath : filePaths) {
+ content.append("file ").append(FileUtils.getFileName(filePath)).append(System.lineSeparator());
+ }
+ if (!file.exists()) {
+ String string = null;
+ try {
+ boolean newFile = file.createNewFile();
+ RandomAccessFile raf = new RandomAccessFile(file, "rwd");
+ raf.seek(file.length());
+ raf.write(content.toString().getBytes(StandardCharsets.UTF_8));
+ raf.close();
+ return file.getCanonicalPath();
+ } catch (IOException e) {
+ e.getMessage();
+ return string;
+ }
+ } else {
+ delete = file.delete();
+ return createInputFile(context, filePaths);
+ }
+ }
+}
diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..8237584d9751965878ab45873e761389c11018e7
--- /dev/null
+++ b/entry/src/main/resources/base/element/string.json
@@ -0,0 +1,28 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "HM_GlideBitmapPool_master"
+ },
+ {
+ "name": "mainability_description",
+ "value": "Java_Phone_Empty Feature Ability"
+ },
+ {
+ "name": "HelloWorld",
+ "value": "Hello World"
+ },
+ {
+ "name": "image_access_required",
+ "value": "需要存取图片权限"
+ },
+ {
+ "name": "storage_permission_denied",
+ "value": "存储权限被拒绝"
+ },
+ {
+ "name": "image_access_success",
+ "value": "成功获取存储权限"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/entry/src/main/resources/base/graphic/background_ability_main.xml b/entry/src/main/resources/base/graphic/background_ability_main.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0
--- /dev/null
+++ b/entry/src/main/resources/base/graphic/background_ability_main.xml
@@ -0,0 +1,6 @@
+
+
+
+
\ No newline at end of file
diff --git a/entry/src/main/resources/base/graphic/background_button.xml b/entry/src/main/resources/base/graphic/background_button.xml
new file mode 100644
index 0000000000000000000000000000000000000000..38a25a1902633d1711ac7c89376a64332d9046c2
--- /dev/null
+++ b/entry/src/main/resources/base/graphic/background_button.xml
@@ -0,0 +1,6 @@
+
+
+
+
\ No newline at end of file
diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml
new file mode 100644
index 0000000000000000000000000000000000000000..08c0f3877b62f29468a50e9cc281e168a8ad6496
--- /dev/null
+++ b/entry/src/main/resources/base/layout/ability_main.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ
diff --git a/app/src/main/res/drawable/test1.png b/entry/src/main/resources/base/media/test1.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test1.png
rename to entry/src/main/resources/base/media/test1.png
diff --git a/app/src/main/res/drawable/test10.png b/entry/src/main/resources/base/media/test10.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test10.png
rename to entry/src/main/resources/base/media/test10.png
diff --git a/app/src/main/res/drawable/test11.png b/entry/src/main/resources/base/media/test11.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test11.png
rename to entry/src/main/resources/base/media/test11.png
diff --git a/app/src/main/res/drawable/test12.png b/entry/src/main/resources/base/media/test12.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test12.png
rename to entry/src/main/resources/base/media/test12.png
diff --git a/app/src/main/res/drawable/test13.png b/entry/src/main/resources/base/media/test13.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test13.png
rename to entry/src/main/resources/base/media/test13.png
diff --git a/app/src/main/res/drawable/test14.png b/entry/src/main/resources/base/media/test14.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test14.png
rename to entry/src/main/resources/base/media/test14.png
diff --git a/app/src/main/res/drawable/test15.png b/entry/src/main/resources/base/media/test15.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test15.png
rename to entry/src/main/resources/base/media/test15.png
diff --git a/app/src/main/res/drawable/test16.png b/entry/src/main/resources/base/media/test16.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test16.png
rename to entry/src/main/resources/base/media/test16.png
diff --git a/app/src/main/res/drawable/test17.png b/entry/src/main/resources/base/media/test17.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test17.png
rename to entry/src/main/resources/base/media/test17.png
diff --git a/app/src/main/res/drawable/test18.png b/entry/src/main/resources/base/media/test18.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test18.png
rename to entry/src/main/resources/base/media/test18.png
diff --git a/app/src/main/res/drawable/test19.png b/entry/src/main/resources/base/media/test19.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test19.png
rename to entry/src/main/resources/base/media/test19.png
diff --git a/app/src/main/res/drawable/test2.png b/entry/src/main/resources/base/media/test2.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test2.png
rename to entry/src/main/resources/base/media/test2.png
diff --git a/app/src/main/res/drawable/test20.png b/entry/src/main/resources/base/media/test20.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test20.png
rename to entry/src/main/resources/base/media/test20.png
diff --git a/app/src/main/res/drawable/test3.png b/entry/src/main/resources/base/media/test3.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test3.png
rename to entry/src/main/resources/base/media/test3.png
diff --git a/app/src/main/res/drawable/test4.png b/entry/src/main/resources/base/media/test4.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test4.png
rename to entry/src/main/resources/base/media/test4.png
diff --git a/app/src/main/res/drawable/test5.png b/entry/src/main/resources/base/media/test5.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test5.png
rename to entry/src/main/resources/base/media/test5.png
diff --git a/app/src/main/res/drawable/test6.png b/entry/src/main/resources/base/media/test6.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test6.png
rename to entry/src/main/resources/base/media/test6.png
diff --git a/app/src/main/res/drawable/test7.png b/entry/src/main/resources/base/media/test7.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test7.png
rename to entry/src/main/resources/base/media/test7.png
diff --git a/app/src/main/res/drawable/test8.png b/entry/src/main/resources/base/media/test8.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test8.png
rename to entry/src/main/resources/base/media/test8.png
diff --git a/app/src/main/res/drawable/test9.png b/entry/src/main/resources/base/media/test9.png
old mode 100755
new mode 100644
similarity index 100%
rename from app/src/main/res/drawable/test9.png
rename to entry/src/main/resources/base/media/test9.png
diff --git a/entry/src/main/resources/rawfile/icon.png b/entry/src/main/resources/rawfile/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/entry/src/main/resources/rawfile/icon.png differ
diff --git a/entry/src/main/resources/rawfile/test1.png b/entry/src/main/resources/rawfile/test1.png
new file mode 100644
index 0000000000000000000000000000000000000000..aaee7b2c8676fe59a66de5aa868ab052171a66a7
Binary files /dev/null and b/entry/src/main/resources/rawfile/test1.png differ
diff --git a/entry/src/main/resources/rawfile/test10.png b/entry/src/main/resources/rawfile/test10.png
new file mode 100644
index 0000000000000000000000000000000000000000..44161ae159eff288dc2795efbff5e472dab8c27f
Binary files /dev/null and b/entry/src/main/resources/rawfile/test10.png differ
diff --git a/entry/src/main/resources/rawfile/test11.png b/entry/src/main/resources/rawfile/test11.png
new file mode 100644
index 0000000000000000000000000000000000000000..8cfe780435d408cc74773c4c0604c9613f86c9e0
Binary files /dev/null and b/entry/src/main/resources/rawfile/test11.png differ
diff --git a/entry/src/main/resources/rawfile/test12.png b/entry/src/main/resources/rawfile/test12.png
new file mode 100644
index 0000000000000000000000000000000000000000..5870fe46c1a9b906fd8796f9cc3a1aa3cd479f6c
Binary files /dev/null and b/entry/src/main/resources/rawfile/test12.png differ
diff --git a/entry/src/main/resources/rawfile/test13.png b/entry/src/main/resources/rawfile/test13.png
new file mode 100644
index 0000000000000000000000000000000000000000..b5a8b6f77d100467664a2142e80016c71145b07a
Binary files /dev/null and b/entry/src/main/resources/rawfile/test13.png differ
diff --git a/entry/src/main/resources/rawfile/test14.png b/entry/src/main/resources/rawfile/test14.png
new file mode 100644
index 0000000000000000000000000000000000000000..3c6dd3a2772d6ea41a20d3d8133da031c01a4ca3
Binary files /dev/null and b/entry/src/main/resources/rawfile/test14.png differ
diff --git a/entry/src/main/resources/rawfile/test15.png b/entry/src/main/resources/rawfile/test15.png
new file mode 100644
index 0000000000000000000000000000000000000000..dfbe16704fd182ff65b99ffdac82fcd8ee57b66c
Binary files /dev/null and b/entry/src/main/resources/rawfile/test15.png differ
diff --git a/entry/src/main/resources/rawfile/test16.png b/entry/src/main/resources/rawfile/test16.png
new file mode 100644
index 0000000000000000000000000000000000000000..9fac2d82120b60909b6fa0fc18e2f70ea84546c7
Binary files /dev/null and b/entry/src/main/resources/rawfile/test16.png differ
diff --git a/entry/src/main/resources/rawfile/test17.png b/entry/src/main/resources/rawfile/test17.png
new file mode 100644
index 0000000000000000000000000000000000000000..5a18bddf794cd38bf1cb9e11009879efbce61a76
Binary files /dev/null and b/entry/src/main/resources/rawfile/test17.png differ
diff --git a/entry/src/main/resources/rawfile/test18.png b/entry/src/main/resources/rawfile/test18.png
new file mode 100644
index 0000000000000000000000000000000000000000..cc118a8c088b28178c1b4bef7f858a07e383e8df
Binary files /dev/null and b/entry/src/main/resources/rawfile/test18.png differ
diff --git a/entry/src/main/resources/rawfile/test19.png b/entry/src/main/resources/rawfile/test19.png
new file mode 100644
index 0000000000000000000000000000000000000000..1085bca78bcf8c61664ffd6fbb702a26bddb1065
Binary files /dev/null and b/entry/src/main/resources/rawfile/test19.png differ
diff --git a/entry/src/main/resources/rawfile/test2.png b/entry/src/main/resources/rawfile/test2.png
new file mode 100644
index 0000000000000000000000000000000000000000..6ac766b107ff5cd568df465c09aab8914a650c96
Binary files /dev/null and b/entry/src/main/resources/rawfile/test2.png differ
diff --git a/entry/src/main/resources/rawfile/test20.png b/entry/src/main/resources/rawfile/test20.png
new file mode 100644
index 0000000000000000000000000000000000000000..ba1810a2ab400261e6e825f034e2450333aac3b3
Binary files /dev/null and b/entry/src/main/resources/rawfile/test20.png differ
diff --git a/entry/src/main/resources/rawfile/test3.png b/entry/src/main/resources/rawfile/test3.png
new file mode 100644
index 0000000000000000000000000000000000000000..a8cd923a1ac02d51a54c86ecc47d14ea556213f6
Binary files /dev/null and b/entry/src/main/resources/rawfile/test3.png differ
diff --git a/entry/src/main/resources/rawfile/test4.png b/entry/src/main/resources/rawfile/test4.png
new file mode 100644
index 0000000000000000000000000000000000000000..275443d6e172ba7c26cb1d5c4dfe0d5ea035a654
Binary files /dev/null and b/entry/src/main/resources/rawfile/test4.png differ
diff --git a/entry/src/main/resources/rawfile/test5.png b/entry/src/main/resources/rawfile/test5.png
new file mode 100644
index 0000000000000000000000000000000000000000..cfe52af2bd3d647c32b9edad1589e7c6f6005d0a
Binary files /dev/null and b/entry/src/main/resources/rawfile/test5.png differ
diff --git a/entry/src/main/resources/rawfile/test6.png b/entry/src/main/resources/rawfile/test6.png
new file mode 100644
index 0000000000000000000000000000000000000000..7a3395a91a8703d93915e79949bd38c318788451
Binary files /dev/null and b/entry/src/main/resources/rawfile/test6.png differ
diff --git a/entry/src/main/resources/rawfile/test7.png b/entry/src/main/resources/rawfile/test7.png
new file mode 100644
index 0000000000000000000000000000000000000000..47e3bd935caf958aae864a7c74ac04eede65d078
Binary files /dev/null and b/entry/src/main/resources/rawfile/test7.png differ
diff --git a/entry/src/main/resources/rawfile/test8.png b/entry/src/main/resources/rawfile/test8.png
new file mode 100644
index 0000000000000000000000000000000000000000..5b49d820b912702e29209c4928982845f168903d
Binary files /dev/null and b/entry/src/main/resources/rawfile/test8.png differ
diff --git a/entry/src/main/resources/rawfile/test9.png b/entry/src/main/resources/rawfile/test9.png
new file mode 100644
index 0000000000000000000000000000000000000000..fb445e77c23e43ce34e86e3dc480660d17435c80
Binary files /dev/null and b/entry/src/main/resources/rawfile/test9.png differ
diff --git a/entry/src/test/java/com/glidebitmappoolsample/ExampleTest.java b/entry/src/test/java/com/glidebitmappoolsample/ExampleTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e9d819420c02e32316e4f8b5ad24abfd4b992d20
--- /dev/null
+++ b/entry/src/test/java/com/glidebitmappoolsample/ExampleTest.java
@@ -0,0 +1,9 @@
+package com.glidebitmappoolsample;
+
+import org.junit.Test;
+
+public class ExampleTest {
+ @Test
+ public void onStart() {
+ }
+}
diff --git a/glide-bitmap-pool/build.gradle b/glide-bitmap-pool/build.gradle
deleted file mode 100644
index 99ba66de1e8a3abc7a2068406253306342efcfca..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/build.gradle
+++ /dev/null
@@ -1,42 +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.library'
-
-android {
- compileSdkVersion 23
- buildToolsVersion "23.0.3"
-
- defaultConfig {
- minSdkVersion 9
- 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'
-}
-apply from: 'upload.gradle'
diff --git a/glide-bitmap-pool/proguard-rules.pro b/glide-bitmap-pool/proguard-rules.pro
deleted file mode 100644
index 6b7a2bf25ec2e485c512e8a370e46db237828a65..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/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/glide-bitmap-pool/src/main/AndroidManifest.xml b/glide-bitmap-pool/src/main/AndroidManifest.xml
deleted file mode 100644
index 92d104d35338ddd18aa1a44776876e312c662293..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/GlideBitmapFactory.java b/glide-bitmap-pool/src/main/java/com/glidebitmappool/GlideBitmapFactory.java
deleted file mode 100644
index 52024843b27ae0aa870c1166b1a61f0e2d7b0593..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/GlideBitmapFactory.java
+++ /dev/null
@@ -1,406 +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.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Rect;
-import android.os.Build;
-import android.util.TypedValue;
-
-import com.glidebitmappool.internal.Util;
-
-import java.io.FileDescriptor;
-import java.io.InputStream;
-
-/**
- * Created by amitshekhar on 18/06/16.
- */
-public class GlideBitmapFactory {
-
- public static Bitmap decodeFile(String pathName) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeFile(pathName, options);
- options.inSampleSize = 1;
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeFile(pathName, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeFile(pathName, options);
- }
- }
-
- public static Bitmap decodeFile(String pathName, int reqWidth, int reqHeight) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeFile(pathName, options);
- options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeFile(pathName, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeFile(pathName, options);
- }
- }
-
- public static Bitmap decodeResource(Resources res, int id) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeResource(res, id, options);
- options.inSampleSize = 1;
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeResource(res, id, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeResource(res, id, options);
- }
- }
-
- public static Bitmap decodeResource(Resources res, int id, int reqWidth, int reqHeight) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeResource(res, id, options);
- options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeResource(res, id, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeResource(res, id, options);
- }
- }
-
- public static Bitmap decodeByteArray(byte[] data, int offset, int length) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeByteArray(data, offset, length, options);
- options.inSampleSize = 1;
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeByteArray(data, offset, length, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeByteArray(data, offset, length, options);
- }
- }
-
- public static Bitmap decodeByteArray(byte[] data, int offset, int length, int reqWidth, int reqHeight) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeByteArray(data, offset, length, options);
- options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeByteArray(data, offset, length, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeByteArray(data, offset, length, options);
- }
- }
-
- public static Bitmap decodeResourceStream(Resources res, TypedValue value, InputStream is, Rect pad) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeResourceStream(res, value, is, pad, options);
- options.inSampleSize = 1;
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeResourceStream(res, value, is, pad, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeResourceStream(res, value, is, pad, options);
- }
- }
-
- public static Bitmap decodeResourceStream(Resources res, TypedValue value, InputStream is, Rect pad, int reqWidth, int reqHeight) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeResourceStream(res, value, is, pad, options);
- options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeResourceStream(res, value, is, pad, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeResourceStream(res, value, is, pad, options);
- }
- }
-
- public static Bitmap decodeStream(InputStream is) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeStream(is, null, options);
- options.inSampleSize = 1;
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeStream(is, null, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeStream(is, null, options);
- }
- }
-
- public static Bitmap decodeStream(InputStream is, int reqWidth, int reqHeight) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeStream(is, null, options);
- options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeStream(is, null, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeStream(is, null, options);
- }
- }
-
- public static Bitmap decodeStream(InputStream is, Rect outPadding) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeStream(is, outPadding, options);
- options.inSampleSize = 1;
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeStream(is, outPadding, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeStream(is, outPadding, options);
- }
- }
-
- public static Bitmap decodeStream(InputStream is, Rect outPadding, int reqWidth, int reqHeight) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeStream(is, outPadding, options);
- options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeStream(is, outPadding, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeStream(is, outPadding, options);
- }
- }
-
- public static Bitmap decodeFileDescriptor(FileDescriptor fd) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeFileDescriptor(fd, null, options);
- options.inSampleSize = 1;
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeFileDescriptor(fd, null, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeFileDescriptor(fd, null, options);
- }
- }
-
- public static Bitmap decodeFileDescriptor(FileDescriptor fd, int reqWidth, int reqHeight) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeFileDescriptor(fd, null, options);
- options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeFileDescriptor(fd, null, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeFileDescriptor(fd, null, options);
- }
- }
-
- public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeFileDescriptor(fd, outPadding, options);
- options.inSampleSize = 1;
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeFileDescriptor(fd, outPadding, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeFileDescriptor(fd, outPadding, options);
- }
- }
-
- public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, int reqWidth, int reqHeight) {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeFileDescriptor(fd, outPadding, options);
- options.inSampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inMutable = true;
- Bitmap inBitmap = GlideBitmapPool.getBitmap(options.outWidth, options.outHeight, options.inPreferredConfig);
- if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
- options.inBitmap = inBitmap;
- }
- }
- options.inJustDecodeBounds = false;
- try {
- return BitmapFactory.decodeFileDescriptor(fd, outPadding, options);
- } catch (Exception e) {
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
- options.inBitmap = null;
- }
- return BitmapFactory.decodeFileDescriptor(fd, outPadding, options);
- }
- }
-
-
-}
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/BitmapPool.java b/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/BitmapPool.java
deleted file mode 100644
index 97735d4425b9831085ad753f7e25aca573015793..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/BitmapPool.java
+++ /dev/null
@@ -1,41 +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.internal;
-
-import android.graphics.Bitmap;
-
-/**
- * Created by amitshekhar on 17/06/16.
- */
-public interface BitmapPool {
-
- int getMaxSize();
-
- void setSizeMultiplier(float sizeMultiplier);
-
- void put(Bitmap bitmap);
-
- Bitmap get(int width, int height, Bitmap.Config config);
-
- Bitmap getDirty(int width, int height, Bitmap.Config config);
-
- void clearMemory();
-
- void trimMemory(int level);
-}
-
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/LruPoolStrategy.java b/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/LruPoolStrategy.java
deleted file mode 100644
index b26e407967b714dcffaa835aa119f792f8684fec..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/LruPoolStrategy.java
+++ /dev/null
@@ -1,37 +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.internal;
-
-import android.graphics.Bitmap;
-
-/**
- * Created by amitshekhar on 17/06/16.
- */
-interface LruPoolStrategy {
- void put(Bitmap bitmap);
-
- Bitmap get(int width, int height, Bitmap.Config config);
-
- Bitmap removeLast();
-
- String logBitmap(Bitmap bitmap);
-
- String logBitmap(int width, int height, Bitmap.Config config);
-
- int getSize(Bitmap bitmap);
-}
\ No newline at end of file
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/Poolable.java b/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/Poolable.java
deleted file mode 100644
index b51ceee73b8517469e2da005eaddf38059251e35..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/Poolable.java
+++ /dev/null
@@ -1,26 +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.internal;
-
-/**
- * Created by amitshekhar on 17/06/16.
- */
-interface Poolable {
- void offer();
-}
-
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/Util.java b/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/Util.java
deleted file mode 100644
index 26cf604d8d60d850c665f276ec73887f274c058b..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/Util.java
+++ /dev/null
@@ -1,138 +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.internal;
-
-import android.annotation.TargetApi;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.Build;
-
-import java.util.ArrayDeque;
-import java.util.Queue;
-
-/**
- * Created by amitshekhar on 17/06/16.
- */
-public class Util {
-
- private Util() {
- // Utility class.
- }
-
- @TargetApi(Build.VERSION_CODES.KITKAT)
- public static int getBitmapByteSize(Bitmap bitmap) {
- // The return value of getAllocationByteCount silently changes for recycled bitmaps from the
- // internal buffer size to row bytes * height. To avoid random inconsistencies in caches, we
- // instead assert here.
- if (bitmap.isRecycled()) {
- throw new IllegalStateException("Cannot obtain size for recycled Bitmap: " + bitmap
- + "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + bitmap.getConfig());
- }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- // Workaround for KitKat initial release NPE in Bitmap, fixed in MR1. See issue #148.
- try {
- return bitmap.getAllocationByteCount();
- } catch (NullPointerException e) {
- // Do nothing.
- }
- }
- return bitmap.getHeight() * bitmap.getRowBytes();
- }
-
- public static int getBitmapByteSize(int width, int height, Bitmap.Config config) {
- return width * height * getBytesPerPixel(config);
- }
-
- private static int getBytesPerPixel(Bitmap.Config config) {
- // A bitmap by decoding a gif has null "config" in certain environments.
- if (config == null) {
- config = Bitmap.Config.ARGB_8888;
- }
-
- int bytesPerPixel;
- switch (config) {
- case ALPHA_8:
- bytesPerPixel = 1;
- break;
- case RGB_565:
- case ARGB_4444:
- bytesPerPixel = 2;
- break;
- case ARGB_8888:
- default:
- bytesPerPixel = 4;
- break;
- }
- return bytesPerPixel;
- }
-
- public static Queue createQueue(int size) {
- return new ArrayDeque<>(size);
- }
-
- public static boolean bothNullOrEqual(Object a, Object b) {
- return a == null ? b == null : a.equals(b);
- }
-
- public static boolean canUseForInBitmap(
- Bitmap candidate, BitmapFactory.Options targetOptions) {
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- // From Android 4.4 (KitKat) onward we can re-use if the byte size of
- // the new bitmap is smaller than the reusable bitmap candidate
- // allocation byte count.
- int width = targetOptions.outWidth / targetOptions.inSampleSize;
- int height = targetOptions.outHeight / targetOptions.inSampleSize;
- int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
-
- try {
- return byteCount <= candidate.getAllocationByteCount();
- } catch (NullPointerException e) {
- return byteCount <= candidate.getHeight() * candidate.getRowBytes();
- }
- }
- // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1
- return candidate.getWidth() == targetOptions.outWidth
- && candidate.getHeight() == targetOptions.outHeight
- && targetOptions.inSampleSize == 1;
- }
-
-
- public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
- // Raw height and width of image
- final int height = options.outHeight;
- final int width = options.outWidth;
- int inSampleSize = 1;
-
- if (height > reqHeight || width > reqWidth) {
-
- final int halfHeight = height / 2;
- final int halfWidth = width / 2;
-
- // Calculate the largest inSampleSize value that is a power of 2 and keeps both
- // height and width larger than the requested height and width.
- while ((halfHeight / inSampleSize) > reqHeight
- && (halfWidth / inSampleSize) > reqWidth) {
- inSampleSize *= 2;
- }
- }
-
- return inSampleSize;
- }
-
-}
diff --git a/glide-bitmap-pool/src/main/res/values/strings.xml b/glide-bitmap-pool/src/main/res/values/strings.xml
deleted file mode 100644
index 46f6f4bf9c53857fa72ddf74b32446a6d00f659f..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
- GlideBitmapPool
-
diff --git a/glide-bitmap-pool/src/test/java/com/glidebitmappool/ExampleUnitTest.java b/glide-bitmap-pool/src/test/java/com/glidebitmappool/ExampleUnitTest.java
deleted file mode 100644
index 0489d698c23672c7702034b6e267bff3c606ed19..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/src/test/java/com/glidebitmappool/ExampleUnitTest.java
+++ /dev/null
@@ -1,32 +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 org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * To work on unit tests, switch the Test Artifact in the Build Variants view.
- */
-public class ExampleUnitTest {
- @Test
- public void addition_isCorrect() throws Exception {
- assertEquals(4, 2 + 2);
- }
-}
\ No newline at end of file
diff --git a/glide-bitmap-pool/upload.gradle b/glide-bitmap-pool/upload.gradle
deleted file mode 100755
index 88256ddd2222a5fd64e0f5b2a7bbc2beb025944c..0000000000000000000000000000000000000000
--- a/glide-bitmap-pool/upload.gradle
+++ /dev/null
@@ -1,101 +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.github.dcendents.android-maven'
-apply plugin: "com.jfrog.bintray"
-
-def siteUrl = 'https://github.com/amitshekhariitbhu/GlideBitmapPool'
-def gitUrl = 'https://github.com/amitshekhariitbhu/GlideBitmapPool.git'
-
-group = "com.amitshekhar.android"
-version = '0.0.1'
-
-install {
- repositories.mavenInstaller {
- pom.project {
- packaging 'aar'
-
- name 'Glide Bitmap Pool'
- description 'Glide Bitmap Pool is a memory management library for reusing the bitmap memory'
-
- url siteUrl
-
- licenses {
- license {
- name 'The Apache Software License, Version 2.0'
- url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- }
- }
-
- developers {
- developer {
- id 'amitshekhariitbhu'
- name 'Amit Shekhar'
- email 'amit.shekhar.iitbhu@gmail.com'
- }
- }
-
- scm {
- connection gitUrl
- developerConnection gitUrl
- url siteUrl
- }
- }
- }
-}
-
-task sourcesJar(type: Jar) {
- from android.sourceSets.main.java.srcDirs
- classifier = 'sources'
-}
-
-task javadoc(type: Javadoc) {
- source = android.sourceSets.main.java.srcDirs
- classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
- classpath += configurations.compile
-}
-
-task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
-}
-artifacts {
- archives javadocJar
- archives sourcesJar
-}
-
-if (project.rootProject.file("local.properties").exists()) {
- Properties properties = new Properties()
- properties.load(project.rootProject.file('local.properties').newDataInputStream())
-
- bintray {
- user = properties.getProperty("bintray.user")
- key = properties.getProperty("bintray.apikey")
-
- configurations = ['archives']
- dryRun = false
-
- pkg {
- repo = "maven"
- name = "glide-bitmap-pool"
- websiteUrl = siteUrl
- vcsUrl = gitUrl
- licenses = ["Apache-2.0"]
- publish = true
- }
- }
-}
diff --git a/glide-bitmap-pool/.gitignore b/glide_bitmap_pool/.gitignore
similarity index 100%
rename from glide-bitmap-pool/.gitignore
rename to glide_bitmap_pool/.gitignore
diff --git a/glide_bitmap_pool/build.gradle b/glide_bitmap_pool/build.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..ab88c3009d8c2ddd387481757f1eb81ba8c834fe
--- /dev/null
+++ b/glide_bitmap_pool/build.gradle
@@ -0,0 +1,13 @@
+apply plugin: 'com.huawei.ohos.library'
+ohos {
+ compileSdkVersion 5
+ defaultConfig {
+ compatibleSdkVersion 4
+ }
+
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ testCompile 'junit:junit:4.12'
+}
diff --git a/glide_bitmap_pool/src/main/config.json b/glide_bitmap_pool/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..58e6d864c10d2024e5562f36e7b77c28ab1ea1b4
--- /dev/null
+++ b/glide_bitmap_pool/src/main/config.json
@@ -0,0 +1,27 @@
+{
+ "app": {
+ "bundleName": "com.glidebitmappoolsample",
+ "vendor": "glidebitmappool",
+ "version": {
+ "code": 1,
+ "name": "1.0"
+ },
+ "apiVersion": {
+ "compatible": 4,
+ "target": 5,
+ "releaseType": "Beta1"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "com.glidebitmappool",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "glide_bitmap_pool",
+ "moduleType": "har"
+ }
+ }
+}
\ No newline at end of file
diff --git a/glide_bitmap_pool/src/main/java/com/glidebitmappool/GlideBitmapFactory.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/GlideBitmapFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..1eab913ff2b9ad64d242706cfd75367683fb3bda
--- /dev/null
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/GlideBitmapFactory.java
@@ -0,0 +1,671 @@
+package com.glidebitmappool;
+
+import com.glidebitmappool.internal.Util;
+
+import ohos.app.Context;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+import ohos.media.image.ImageSource;
+import ohos.media.image.PixelMap;
+import ohos.media.image.common.AllocatorType;
+import ohos.media.image.common.PixelFormat;
+import ohos.media.image.common.Rect;
+import ohos.media.image.common.Size;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * 位图池使用类
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ */
+public class GlideBitmapFactory {
+ private static final String FORMAT = "image/png";
+ private static HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x001, "TAG");
+ private static boolean isScale;
+
+ private GlideBitmapFactory() {
+ }
+
+ /**
+ * 根据路径获取解码图片
+ *
+ * @param pathName
+ * @return PixelMap
+ * @noinspection checkstyle:WhitespaceAround
+ */
+ public static PixelMap decodeFile(String pathName) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+
+ isScale = true;
+
+ PixelMap pixelMapFromPath = getPixelMapFromPath(pathName, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromPath.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromPath.getImageInfo().size.height : 0);
+
+ options.sampleSize = 1;
+ /**
+ * android API 大于11
+ */
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = true;
+
+ try {
+ return getPixelMapFromPath(pathName, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromPath(pathName, options);
+ }
+ }
+
+ /**
+ * 根据路径获取解码图片
+ *
+ * @param pathName
+ * @param reqWidth
+ * @param reqHeight
+ * @return PixelMap
+ */
+ public static PixelMap decodeFile(String pathName, int reqWidth, int reqHeight) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ isScale = true;
+ PixelMap pixelMapFromPath = getPixelMapFromPath(pathName, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromPath.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromPath.getImageInfo().size.height : 0);
+
+ options.sampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromPath(pathName, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromPath(pathName, options);
+ }
+ }
+
+ /**
+ * 根据资源id解码图片
+ *
+ * @param context
+ * @param id
+ * @return PixelMap
+ */
+ public static PixelMap decodeResource(Context context, int id) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ isScale = true;
+ PixelMap pixelMapFromResource = getPixelMapFromResource(context, id, options);
+// HiLog.error(logLabel,"TAG-width---"+pixelMapFromResource.getImageInfo().size.width);
+// HiLog.error(logLabel,"TAG-height---"+pixelMapFromResource.getImageInfo().size.height);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromResource.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromResource.getImageInfo().size.height : 0);
+ options.sampleSize = 1;
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = true;
+ try {
+ return getPixelMapFromResource(context, id, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromResource(context, id, options);
+ }
+ }
+
+ /**
+ * 根据资源id解码图片
+ *
+ * @param context
+ * @param id
+ * @param reqWidth
+ * @param reqHeight
+ * @return PixelMap
+ */
+ public static PixelMap decodeResource(Context context, int id, int reqWidth, int reqHeight) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ isScale = true;
+ PixelMap pixelMapFromResource = getPixelMapFromResource(context, id, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromResource.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromResource.getImageInfo().size.height : 0);
+
+ options.sampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromResource(context, id, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromResource(context, id, options);
+ }
+ }
+
+ /**
+ * 根据字节数组解码图片
+ *
+ * @param data
+ * @param offset
+ * @param length
+ * @return PixelMap
+ */
+ public static PixelMap decodeByteArray(byte[] data, int offset, int length) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ isScale = true;
+ PixelMap pixelMapFromArray = getPixelMapFromArray(data, offset, length, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromArray.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromArray.getImageInfo().size.height : 0);
+
+ options.sampleSize = 1;
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromArray(data, offset, length, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromArray(data, offset, length, options);
+ }
+ }
+
+ /**
+ * 根据字节数据解码图片
+ *
+ * @param data
+ * @param offset
+ * @param length
+ * @param reqWidth
+ * @param reqHeight
+ * @return PixelMap
+ */
+ public static PixelMap decodeByteArray(byte[] data, int offset, int length, int reqWidth, int reqHeight) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ isScale = true;
+ PixelMap pixelMapFromArray = getPixelMapFromArray(data, offset, length, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromArray.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromArray.getImageInfo().size.height : 0);
+
+ options.sampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromArray(data, offset, length, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromArray(data, offset, length, options);
+ }
+ }
+
+ // decodeResourceStream 鸿蒙没有对应
+ /* public static PixelMap decodeResourceStream(Resources res, TypedValue value, InputStream is, Rect pad) {
+ final ImageSource.DecodingOptions options = new ImageSource.DecodingOptions();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeResourceStream(res, value, is, pad, options);
+ options.sampleSize = 1;
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+ options.inBitmap = inBitmap;
+ }
+ options.inJustDecodeBounds = false;
+ try {
+ return BitmapFactory.decodeResourceStream(res, value, is, pad, options);
+ } catch (IllegalArgumentException e) {
+ options.inBitmap = null;
+ return BitmapFactory.decodeResourceStream(res, value, is, pad, options);
+ }
+ }*/
+
+ // decodeResourceStream 鸿蒙没有对应
+ /* public static PixelMap decodeResourceStream(
+ Resources res, TypedValue value, InputStream is, Rect pad, int reqWidth, int reqHeight) {
+ final ImageSource.DecodingOptions options = new ImageSource.DecodingOptions();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeResourceStream(res, value, is, pad, options);
+ options.sampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+ options.inBitmap = inBitmap;
+ }
+ options.inJustDecodeBounds = false;
+ try {
+ return BitmapFactory.decodeResourceStream(res, value, is, pad, options);
+ } catch (IllegalArgumentException e) {
+ options.inBitmap = null;
+ return BitmapFactory.decodeResourceStream(res, value, is, pad, options);
+ }
+ }*/
+
+ /**
+ * 根据流数据解码图片
+ *
+ * @param is
+ * @return PixelMap
+ */
+ public static PixelMap decodeStream(InputStream is) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+
+ isScale = true;
+ PixelMap pixelMapFromInputStream = getPixelMapFromInputStream(is, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromInputStream.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromInputStream.getImageInfo().size.height : 0);
+
+ options.sampleSize = 1;
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromInputStream(is, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromInputStream(is, options);
+ }
+ }
+
+ /**
+ * 根据流数据解码图片
+ *
+ * @param is
+ * @param reqWidth
+ * @param reqHeight
+ * @return PixelMap
+ */
+ public static PixelMap decodeStream(InputStream is, int reqWidth, int reqHeight) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ isScale = true;
+ PixelMap pixelMapFromInputStream = getPixelMapFromInputStream(is, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromInputStream.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromInputStream.getImageInfo().size.height : 0);
+
+ options.sampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromInputStream(is, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromInputStream(is, options);
+ }
+ }
+
+ /**
+ * 根据流数据解码图片
+ *
+ * @param is
+ * @param outPadding
+ * @return PixelMap
+ */
+ public static PixelMap decodeStream(InputStream is, Rect outPadding) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ isScale = true;
+ options.desiredRegion = outPadding;
+ PixelMap pixelMapFromInputStream = getPixelMapFromInputStream(is, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromInputStream.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromInputStream.getImageInfo().size.height : 0);
+
+ options.sampleSize = 1;
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromInputStream(is, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromInputStream(is, options);
+ }
+ }
+
+ /**
+ * 根据流数据解码图片
+ *
+ * @param is
+ * @param outPadding
+ * @param reqWidth
+ * @param reqHeight
+ * @return PixelMap
+ */
+ public static PixelMap decodeStream(InputStream is, Rect outPadding, int reqWidth, int reqHeight) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ options.desiredRegion = outPadding;
+ isScale = true;
+ PixelMap pixelMapFromInputStream = getPixelMapFromInputStream(is, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromInputStream.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromInputStream.getImageInfo().size.height : 0);
+
+ options.sampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromInputStream(is, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromInputStream(is, options);
+ }
+ }
+
+ /**
+ * 根据文件描述类解码图片
+ *
+ * @param fd
+ * @return PixelMap
+ */
+ public static PixelMap decodeFileDescriptor(FileDescriptor fd) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ isScale = true;
+ PixelMap pixelMapFromFileDescriptor = getPixelMapFromFileDescriptor(fd, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromFileDescriptor.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromFileDescriptor.getImageInfo().size.height : 0);
+
+ options.sampleSize = 1;
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromFileDescriptor(fd, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromFileDescriptor(fd, options);
+ }
+ }
+
+ /**
+ * 根据文件描述类解码图片
+ *
+ * @param fd
+ * @param reqWidth
+ * @param reqHeight
+ * @return PixelMap
+ */
+ public static PixelMap decodeFileDescriptor(FileDescriptor fd, int reqWidth, int reqHeight) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ isScale = true;
+ PixelMap pixelMapFromFileDescriptor = getPixelMapFromFileDescriptor(fd, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromFileDescriptor.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromFileDescriptor.getImageInfo().size.height : 0);
+
+ options.sampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromFileDescriptor(fd, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromFileDescriptor(fd, options);
+ }
+ }
+
+ /**
+ * 根据文件描述类解码图片
+ *
+ * @param fd
+ * @param outPadding
+ * @return PixelMap
+ */
+ public static PixelMap decodeFileDescriptor(FileDescriptor fd, Rect outPadding) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ options.desiredRegion = outPadding;
+ isScale = true;
+ PixelMap pixelMapFromFileDescriptor = getPixelMapFromFileDescriptor(fd, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromFileDescriptor.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromFileDescriptor.getImageInfo().size.height : 0);
+
+ options.sampleSize = 1;
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromFileDescriptor(fd, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromFileDescriptor(fd, options);
+ }
+ }
+
+ /**
+ * 根据文件描述类解码图片
+ *
+ * @param fd
+ * @param outPadding
+ * @param reqWidth
+ * @param reqHeight
+ * @return PixelMap
+ */
+ public static PixelMap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, int reqWidth, int reqHeight) {
+ final ImageSource.DecodingOptions options = getDecodingOptions();
+ options.desiredRegion = outPadding;
+ isScale = true;
+ PixelMap pixelMapFromFileDescriptor = getPixelMapFromFileDescriptor(fd, options);
+ options.desiredSize = new Size(isScale
+ ? pixelMapFromFileDescriptor.getImageInfo().size.width : 0,
+ isScale ? pixelMapFromFileDescriptor.getImageInfo().size.height : 0);
+
+ options.sampleSize = Util.calculateInSampleSize(options, reqWidth, reqHeight);
+ options.editable = true;
+ PixelMap inBitmap = GlideBitmapPool.getBitmap(options.desiredSize.width,
+ options.desiredSize.height, options.desiredPixelFormat);
+ if (inBitmap != null && Util.canUseForInBitmap(inBitmap, options)) {
+// options.inBitmap = inBitmap;
+ }
+ isScale = false;
+ try {
+ return getPixelMapFromFileDescriptor(fd, options);
+ } catch (IllegalArgumentException e) {
+// options.inBitmap = null;
+ return getPixelMapFromFileDescriptor(fd, options);
+ }
+ }
+
+ /**
+ * 获取解码属性
+ *
+ * @return 解码属性
+ */
+ public static ImageSource.DecodingOptions getDecodingOptions() {
+ ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions();
+ decodingOptions.allocator = AllocatorType.DEFAULT;
+ decodingOptions.desiredRegion = new Rect(0, 0, 0, 0);
+ decodingOptions.desiredPixelFormat = PixelFormat.ARGB_8888;
+
+ return decodingOptions;
+ }
+
+ /**
+ * 根据存储路径获取位图
+ *
+ * @param path
+ * @param decodingOptions
+ * @return PixelMap
+ */
+ private static PixelMap getPixelMapFromPath(String path, ImageSource.DecodingOptions decodingOptions) {
+ System.out.println("getPixelMapFromPath---" + path);
+ PixelMap pixelmap = null;
+ try {
+ ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions();
+ sourceOptions.formatHint = FORMAT;
+ ImageSource imageSource = ImageSource.create(path, sourceOptions);
+ pixelmap = imageSource.createPixelmap(decodingOptions);
+ return pixelmap;
+ } catch (IllegalArgumentException e) {
+ HiLog.error(logLabel, e.getMessage());
+ }
+
+ return pixelmap;
+ }
+
+ /**
+ * 根据资源文件获取位图
+ *
+ * @param context
+ * @param resId
+ * @param decodingOptions
+ * @return PixelMap
+ */
+ private static PixelMap getPixelMapFromResource(
+ Context context, int resId, ImageSource.DecodingOptions decodingOptions) {
+ InputStream drawableInputStream = null;
+ PixelMap pixelmap = null;
+ try {
+ drawableInputStream = context.getResourceManager().getResource(resId);
+ ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions();
+ sourceOptions.formatHint = FORMAT;
+ ImageSource imageSource = ImageSource.create(drawableInputStream, sourceOptions);
+ pixelmap = imageSource.createPixelmap(decodingOptions);
+ return pixelmap;
+ } catch (Exception e) {
+ HiLog.error(logLabel, e.getMessage());
+ } finally {
+ try {
+ if (drawableInputStream != null) {
+ drawableInputStream.close();
+ }
+ } catch (IOException e) {
+ HiLog.error(logLabel, e.getMessage());
+ }
+ }
+ return pixelmap;
+ }
+
+ /**
+ * 从指定字节数组解码位图
+ *
+ * @param data
+ * @param offset
+ * @param length
+ * @param decodingOptions
+ * @return PixelMap
+ */
+ private static PixelMap getPixelMapFromArray(
+ byte[] data, int offset, int length, ImageSource.DecodingOptions decodingOptions) {
+ PixelMap pixelmap = null;
+ try {
+ ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions();
+ sourceOptions.formatHint = FORMAT;
+ ImageSource imageSource = ImageSource.create(data, offset, length, sourceOptions);
+ pixelmap = imageSource.createPixelmap(decodingOptions);
+ return pixelmap;
+ } catch (IllegalArgumentException e) {
+ HiLog.error(logLabel, e.getMessage());
+ }
+
+ return pixelmap;
+ }
+
+ /**
+ * 通过流数据解码位图
+ *
+ * @param inputStream
+ * @param decodingOptions
+ * @return PixelMap
+ */
+ private static PixelMap getPixelMapFromInputStream(
+ InputStream inputStream, ImageSource.DecodingOptions decodingOptions) {
+ PixelMap pixelmap = null;
+ try {
+ ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions();
+ sourceOptions.formatHint = FORMAT;
+ ImageSource imageSource = ImageSource.create(inputStream, sourceOptions);
+ pixelmap = imageSource.createPixelmap(decodingOptions);
+ return pixelmap;
+ } catch (IllegalArgumentException e) {
+ HiLog.error(logLabel, e.getMessage());
+ }
+ return pixelmap;
+ }
+
+ /**
+ * 通过文件描述解码位图
+ *
+ * @param fileDescriptor
+ * @param decodingOptions
+ * @return PixelMap
+ */
+ private static PixelMap getPixelMapFromFileDescriptor(
+ FileDescriptor fileDescriptor, ImageSource.DecodingOptions decodingOptions) {
+ PixelMap pixelmap = null;
+ try {
+ ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions();
+ sourceOptions.formatHint = FORMAT;
+ ImageSource imageSource = ImageSource.create(fileDescriptor, sourceOptions);
+ pixelmap = imageSource.createPixelmap(decodingOptions);
+ return pixelmap;
+ } catch (IllegalArgumentException e) {
+ HiLog.error(logLabel, e.getMessage());
+ }
+ return pixelmap;
+ }
+}
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/GlideBitmapPool.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/GlideBitmapPool.java
similarity index 45%
rename from glide-bitmap-pool/src/main/java/com/glidebitmappool/GlideBitmapPool.java
rename to glide_bitmap_pool/src/main/java/com/glidebitmappool/GlideBitmapPool.java
index 72fbdece89cf977c6b0c4c0ef8b2a65560fc0574..9f05600f34b0743e134a294c6c0ce77eb744d948 100644
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/GlideBitmapPool.java
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/GlideBitmapPool.java
@@ -1,56 +1,51 @@
-/*
- * 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.graphics.Bitmap;
-import android.os.Build;
-
import com.glidebitmappool.internal.BitmapPool;
-import com.glidebitmappool.internal.BitmapPoolAdapter;
import com.glidebitmappool.internal.LruBitmapPool;
+import ohos.media.image.PixelMap;
+import ohos.media.image.common.PixelFormat;
+
import java.util.Set;
/**
- * Created by amitshekhar on 17/06/16.
+ * 位图池初基类
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ * Description: 位图池初基类
*/
public class GlideBitmapPool {
-
private static final int DEFAULT_MAX_SIZE = 6 * 1024 * 1024;
- private BitmapPool bitmapPool;
private static GlideBitmapPool sInstance;
+ private BitmapPool bitmapPool;
+ /**
+ * 构造
+ *
+ * @param maxSize
+ */
private GlideBitmapPool(int maxSize) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- bitmapPool = new LruBitmapPool(maxSize);
- } else {
- bitmapPool = new BitmapPoolAdapter();
- }
+ // Android api大于等于11使用
+ bitmapPool = new LruBitmapPool(maxSize);
}
- private GlideBitmapPool(int maxSize, Set allowedConfigs) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- bitmapPool = new LruBitmapPool(maxSize, allowedConfigs);
- } else {
- bitmapPool = new BitmapPoolAdapter();
- }
+ /**
+ * 构造
+ *
+ * @param maxSize
+ * @param allowedConfigs
+ */
+ private GlideBitmapPool(int maxSize, Set allowedConfigs) {
+ // Android api大于等于11使用
+ bitmapPool = new LruBitmapPool(maxSize, allowedConfigs);
}
+ /**
+ * 初始化
+ *
+ * @return GlideBitmapPool
+ */
private static GlideBitmapPool getInstance() {
if (sInstance == null) {
sInstance = new GlideBitmapPool(DEFAULT_MAX_SIZE);
@@ -58,39 +53,81 @@ public class GlideBitmapPool {
return sInstance;
}
+ /**
+ * 初始化
+ *
+ * @param maxSize
+ */
public static void initialize(int maxSize) {
sInstance = new GlideBitmapPool(maxSize);
}
- public static void initialize(int maxSize, Set allowedConfigs) {
+ /**
+ * 初始化
+ *
+ * @param maxSize
+ * @param allowedConfigs
+ */
+ public static void initialize(int maxSize, Set allowedConfigs) {
sInstance = new GlideBitmapPool(maxSize, allowedConfigs);
}
- public static void putBitmap(Bitmap bitmap) {
+ /**
+ * 添加位图
+ *
+ * @param bitmap
+ */
+ public static void putBitmap(PixelMap bitmap) {
getInstance().bitmapPool.put(bitmap);
}
- public static Bitmap getBitmap(int width, int height, Bitmap.Config config) {
+ /**
+ * 获取位图
+ *
+ * @param width
+ * @param height
+ * @param config
+ * @return PixelMap
+ */
+ public static PixelMap getBitmap(int width, int height, PixelFormat config) {
return getInstance().bitmapPool.get(width, height, config);
}
- public static Bitmap getDirtyBitmap(int width, int height, Bitmap.Config config) {
+ /**
+ * 获取位图
+ *
+ * @param width
+ * @param height
+ * @param config
+ * @return PixelMap
+ */
+ public static PixelMap getDirtyBitmap(int width, int height, PixelFormat config) {
return getInstance().bitmapPool.getDirty(width, height, config);
}
+ /**
+ * 清除缓存
+ */
public static void clearMemory() {
getInstance().bitmapPool.clearMemory();
}
+ /**
+ * 清除部分缓存
+ *
+ * @param level
+ */
public static void trimMemory(int level) {
getInstance().bitmapPool.trimMemory(level);
}
+ /**
+ * 关闭位图池
+ */
public static void shutDown() {
if (sInstance != null) {
sInstance.bitmapPool.clearMemory();
sInstance = null;
}
}
-
}
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/AttributeStrategy.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/AttributeStrategy.java
similarity index 42%
rename from glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/AttributeStrategy.java
rename to glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/AttributeStrategy.java
index d20a282cb8d96c7651235894c7e7b7f110199ea0..9b537ec8b7a2b4fe6d723b00e7564de6f3e464f0 100644
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/AttributeStrategy.java
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/AttributeStrategy.java
@@ -1,80 +1,129 @@
-/*
- * 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.internal;
-import android.graphics.Bitmap;
+import ohos.media.image.PixelMap;
+import ohos.media.image.common.ImageInfo;
+import ohos.media.image.common.PixelFormat;
+import ohos.media.image.common.Size;
/**
- * Created by amitshekhar on 17/06/16.
+ * 位图池属性类
+ *
+ * @author renpengfei
+ * @since 2021-03-12
*/
public class AttributeStrategy implements LruPoolStrategy {
private final KeyPool keyPool = new KeyPool();
- private final GroupedLinkedMap groupedMap = new GroupedLinkedMap<>();
+ private final GroupedLinkedMap groupedMap = new GroupedLinkedMap<>();
- public void put(Bitmap bitmap) {
- final Key key = keyPool.get(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
+ /**
+ * put
+ *
+ * @param bitmap 图片
+ */
+ @Override
+ public void put(PixelMap bitmap) {
+ // 获取位图宽、高、以及其他配置信息
+ ImageInfo imageInfo = bitmap.getImageInfo();
+ Size size = imageInfo.size;
+ final Key key = keyPool.get(size.width, size.height, imageInfo.pixelFormat);
groupedMap.put(key, bitmap);
}
+ /**
+ * get
+ *
+ * @param width 宽
+ * @param height 高
+ * @param config 格式
+ * @return PixelMap
+ */
@Override
- public Bitmap get(int width, int height, Bitmap.Config config) {
+ public PixelMap get(int width, int height, PixelFormat config) {
final Key key = keyPool.get(width, height, config);
return groupedMap.get(key);
}
+ /**
+ * removeLast
+ *
+ * @return PixelMap
+ */
@Override
- public Bitmap removeLast() {
+ public PixelMap removeLast() {
return groupedMap.removeLast();
}
+ /**
+ * logBitmap
+ *
+ * @param bitmap
+ * @return String
+ */
@Override
- public String logBitmap(Bitmap bitmap) {
+ public String logBitmap(PixelMap bitmap) {
return getBitmapString(bitmap);
}
+ /**
+ * logBitmap
+ *
+ * @param width 宽
+ * @param height 高
+ * @param config 格式
+ * @return String
+ */
@Override
- public String logBitmap(int width, int height, Bitmap.Config config) {
+ public String logBitmap(int width, int height, PixelFormat config) {
return getBitmapString(width, height, config);
}
+ /**
+ * 获取图片大小
+ *
+ * @param bitmap
+ * @return int
+ */
@Override
- public int getSize(Bitmap bitmap) {
+ public int getSize(PixelMap bitmap) {
return Util.getBitmapByteSize(bitmap);
}
+ /**
+ * toString
+ *
+ * @return String
+ */
@Override
public String toString() {
- return "AttributeStrategy:\n " + groupedMap;
+ return "AttributeStrategy:" + System.lineSeparator() + groupedMap;
}
- private static String getBitmapString(Bitmap bitmap) {
- return getBitmapString(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
+ /**
+ * getBitmapString
+ *
+ * @param bitmap
+ * @return String
+ */
+ private static String getBitmapString(PixelMap bitmap) {
+ // 获取位图宽、高、以及其他配置信息
+ ImageInfo imageInfo = bitmap.getImageInfo();
+ Size size = imageInfo.size;
+ return getBitmapString(size.width, size.height, imageInfo.pixelFormat);
}
- private static String getBitmapString(int width, int height, Bitmap.Config config) {
+ private static String getBitmapString(int width, int height, PixelFormat config) {
return "[" + width + "x" + height + "], " + config;
}
- // Visible for testing.
+ /**
+ * 测试使用
+ *
+ * @since 2021-03-12
+ */
static class KeyPool extends BaseKeyPool {
- public Key get(int width, int height, Bitmap.Config config) {
+ public Key get(int width, int height, PixelFormat config) {
Key result = get();
result.init(width, height, config);
return result;
@@ -86,28 +135,33 @@ public class AttributeStrategy implements LruPoolStrategy {
}
}
- // Visible for testing.
+ /**
+ * 测试使用
+ *
+ * @since 2021-03-12
+ */
static class Key implements Poolable {
private final KeyPool pool;
private int width;
private int height;
- // Config can be null :(
- private Bitmap.Config config;
- public Key(KeyPool pool) {
+ // Config can be null
+ private PixelFormat config;
+
+ Key(KeyPool pool) {
this.pool = pool;
}
- public void init(int width, int height, Bitmap.Config config) {
- this.width = width;
- this.height = height;
- this.config = config;
+ public void init(int width1, int height1, PixelFormat pixelFormat) {
+ this.width = width1;
+ this.height = height1;
+ this.config = pixelFormat;
}
@Override
- public boolean equals(Object o) {
- if (o instanceof Key) {
- Key other = (Key) o;
+ public boolean equals(Object object) {
+ if (object instanceof Key) {
+ Key other = (Key) object;
return width == other.width && height == other.height && config == other.config;
}
return false;
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/BaseKeyPool.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/BaseKeyPool.java
similarity index 43%
rename from glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/BaseKeyPool.java
rename to glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/BaseKeyPool.java
index 1d1c2c71c1d234cc6e2555f48524f520c666a38a..68f9ee04d0e058597e5bff975bb0fb54a30011e4 100644
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/BaseKeyPool.java
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/BaseKeyPool.java
@@ -1,31 +1,26 @@
-/*
- * 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.internal;
import java.util.Queue;
/**
- * Created by amitshekhar on 17/06/16.
+ * 位图密钥池基类
+ *
+ * @author renpengfei
+ * @param
+ * @since 2021-03-12
*/
abstract class BaseKeyPool {
+ /**
+ * 默认最大容量
+ */
private static final int MAX_SIZE = 20;
private final Queue keyPool = Util.createQueue(MAX_SIZE);
+ /**
+ * 通过轮询从位图密钥池获取
+ *
+ * @return T
+ */
protected T get() {
T result = keyPool.poll();
if (result == null) {
@@ -34,12 +29,22 @@ abstract class BaseKeyPool {
return result;
}
+ /**
+ * 将指定元素插入密钥池
+ *
+ * @param key
+ */
public void offer(T key) {
if (keyPool.size() < MAX_SIZE) {
keyPool.offer(key);
}
}
+ /**
+ * 初始化
+ *
+ * @return T
+ */
protected abstract T create();
}
diff --git a/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/BitmapPool.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/BitmapPool.java
new file mode 100644
index 0000000000000000000000000000000000000000..64a237516c09b43df459ac25da219f3d9576fda5
--- /dev/null
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/BitmapPool.java
@@ -0,0 +1,66 @@
+package com.glidebitmappool.internal;
+
+import ohos.media.image.PixelMap;
+import ohos.media.image.common.PixelFormat;
+
+/**
+ * 位图池功能
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ */
+public interface BitmapPool {
+ /**
+ * 获取bitmap最大容量
+ *
+ * @return 容量
+ */
+ int getMaxSize();
+
+ /**
+ * 动态调整位图池容量大小
+ *
+ * @param sizeMultiplier
+ */
+ void setSizeMultiplier(float sizeMultiplier);
+
+ /**
+ * 添加指定的图片到位图池
+ *
+ * @param bitmap
+ */
+ void put(PixelMap bitmap);
+
+ /**
+ * 返回一个匹配给定宽 高 配置的像素图
+ *
+ * @param width
+ * @param height
+ * @param config
+ * @return 位图
+ */
+ PixelMap get(int width, int height, PixelFormat config);
+
+ /**
+ * 与get方法一样,只是返回的任何非空位图对象都可能包含未擦除的像素数据或随机数据
+ *
+ * @param width
+ * @param height
+ * @param config
+ * @return 位图
+ */
+ PixelMap getDirty(int width, int height, PixelFormat config);
+
+ /**
+ * 移除位图池中所有位图
+ */
+ void clearMemory();
+
+ /**
+ * 根据给定的level移除部分位图
+ *
+ * @param level
+ */
+ void trimMemory(int level);
+}
+
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/BitmapPoolAdapter.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/BitmapPoolAdapter.java
similarity index 35%
rename from glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/BitmapPoolAdapter.java
rename to glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/BitmapPoolAdapter.java
index 2f6fa3ef474444ab9e7ad20567b2ade24bb75b5e..730182b6fd7d31cf1efa819152e28fc9db5173d1 100644
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/BitmapPoolAdapter.java
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/BitmapPoolAdapter.java
@@ -1,26 +1,14 @@
-/*
- * 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.internal;
-import android.graphics.Bitmap;
+import ohos.media.image.PixelMap;
+import ohos.media.image.common.PixelFormat;
+import ohos.media.image.common.Size;
/**
- * Created by amitshekhar on 17/06/16.
+ * 位图池实现类,android API 11 之前使用
+ *
+ * @author renpengfei
+ * @since 2021-03-12
*/
public class BitmapPoolAdapter implements BitmapPool {
@Override
@@ -34,17 +22,20 @@ public class BitmapPoolAdapter implements BitmapPool {
}
@Override
- public void put(Bitmap bitmap) {
- bitmap.recycle();
+ public void put(PixelMap bitmap) {
+ bitmap.release();
}
@Override
- public Bitmap get(int width, int height, Bitmap.Config config) {
- return Bitmap.createBitmap(width, height, config);
+ public PixelMap get(int width, int height, PixelFormat config) {
+ PixelMap.InitializationOptions initializationOptions = new PixelMap.InitializationOptions();
+ initializationOptions.size = new Size(width,height);
+ initializationOptions.pixelFormat = config;
+ return PixelMap.create(initializationOptions);
}
@Override
- public Bitmap getDirty(int width, int height, Bitmap.Config config) {
+ public PixelMap getDirty(int width, int height, PixelFormat config) {
return get(width, height, config);
}
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/GroupedLinkedMap.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/GroupedLinkedMap.java
similarity index 66%
rename from glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/GroupedLinkedMap.java
rename to glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/GroupedLinkedMap.java
index fe7811065199088f38c74b7e77b02bc1b661e06f..0f945811881b37a82ad892850b263ebf05c267cd 100644
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/GroupedLinkedMap.java
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/GroupedLinkedMap.java
@@ -1,34 +1,35 @@
-/*
- * 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.internal;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
- * Created by amitshekhar on 17/06/16.
+ * 位图池链式组
+ *
+ * @author renpengfei
+ * @param
+ * @param
+ * @since 2021-03-12
*/
public class GroupedLinkedMap {
+ private static final int TWO = 2;
+
+ private HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x001, "GroupedLinkedMap--");
+
private final LinkedEntry head = new LinkedEntry<>();
private final Map> keyToEntry = new HashMap<>();
+ /**
+ * 往位图池添加数据
+ *
+ * @param key
+ * @param value
+ */
public void put(K key, V value) {
LinkedEntry entry = keyToEntry.get(key);
@@ -43,6 +44,12 @@ public class GroupedLinkedMap {
entry.add(value);
}
+ /**
+ * 根据key获取数据
+ *
+ * @param key
+ * @return value
+ */
public V get(K key) {
LinkedEntry entry = keyToEntry.get(key);
if (entry == null) {
@@ -52,16 +59,24 @@ public class GroupedLinkedMap {
key.offer();
}
+ HiLog.error(logLabel, "key---" + entry.key + "---values--"
+ + entry.values + "--prev--" + entry.prev + "---next--" + entry.next);
makeHead(entry);
return entry.removeLast();
}
+ /**
+ * 删除最后一条数据
+ *
+ * @return value
+ */
public V removeLast() {
+ V removed = null;
LinkedEntry last = head.prev;
while (!last.equals(head)) {
- V removed = last.removeLast();
+ removed = last.removeLast();
if (removed != null) {
return removed;
} else {
@@ -80,26 +95,30 @@ public class GroupedLinkedMap {
last = last.prev;
}
- return null;
+ return removed;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("GroupedLinkedMap( ");
LinkedEntry current = head.next;
- boolean hadAtLeastOneItem = false;
+ boolean isHadAtLeastOneItem = false;
while (!current.equals(head)) {
- hadAtLeastOneItem = true;
+ isHadAtLeastOneItem = true;
sb.append('{').append(current.key).append(':').append(current.size()).append("}, ");
current = current.next;
}
- if (hadAtLeastOneItem) {
- sb.delete(sb.length() - 2, sb.length());
+ if (isHadAtLeastOneItem) {
+ sb.delete(sb.length() - TWO, sb.length());
}
return sb.append(" )").toString();
}
- // Make the entry the most recently used item.
+ /**
+ * Make the entry the most recently used item.
+ *
+ * @param entry
+ */
private void makeHead(LinkedEntry entry) {
removeEntry(entry);
entry.prev = head;
@@ -107,7 +126,11 @@ public class GroupedLinkedMap {
updateEntry(entry);
}
- // Make the entry the least recently used item.
+ /**
+ * Make the entry the least recently used item.
+ *
+ * @param entry
+ */
private void makeTail(LinkedEntry entry) {
removeEntry(entry);
entry.prev = head.prev;
@@ -125,33 +148,43 @@ public class GroupedLinkedMap {
entry.next.prev = entry.prev;
}
+ /**
+ * 链式
+ *
+ * @param
+ * @param
+ * @since2021-03-12
+ */
private static class LinkedEntry {
+ private LinkedEntry next;
+ private LinkedEntry prev;
private final K key;
private List values;
- LinkedEntry next;
- LinkedEntry prev;
- // Used only for the first item in the list which we will treat specially and which will not
- // contain a value.
- public LinkedEntry() {
+ /**
+ * Used only for the first item in the list which we will treat specially and which will not contain value.
+ */
+ LinkedEntry() {
this(null);
}
- public LinkedEntry(K key) {
- next = prev = this;
+ LinkedEntry(K key) {
+ next = prev;
+ prev = this;
+ next = this;
this.key = key;
}
- public V removeLast() {
+ V removeLast() {
final int valueSize = size();
return valueSize > 0 ? values.remove(valueSize - 1) : null;
}
- public int size() {
+ int size() {
return values != null ? values.size() : 0;
}
- public void add(V value) {
+ void add(V value) {
if (values == null) {
values = new ArrayList<>();
}
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/LruBitmapPool.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/LruBitmapPool.java
similarity index 41%
rename from glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/LruBitmapPool.java
rename to glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/LruBitmapPool.java
index be478b043bd84fc37e88b3fe41737ffbb026a798..bc4fbbb1937f2c43f36810af7efa2bf15b4780f9 100644
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/LruBitmapPool.java
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/LruBitmapPool.java
@@ -1,28 +1,13 @@
-/*
- * 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.internal;
-import android.annotation.SuppressLint;
-import android.annotation.TargetApi;
-import android.graphics.Bitmap;
-import android.graphics.Color;
-import android.os.Build;
-import android.util.Log;
+import ohos.agp.utils.Color;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+import ohos.media.image.PixelMap;
+import ohos.media.image.common.AlphaType;
+import ohos.media.image.common.ImageInfo;
+import ohos.media.image.common.PixelFormat;
+import ohos.media.image.common.Size;
import java.util.Arrays;
import java.util.Collections;
@@ -30,14 +15,20 @@ import java.util.HashSet;
import java.util.Set;
/**
- * Created by amitshekhar on 17/06/16.
+ * 缓存位图池
+ *
+ * @author renpengfei
+ * @since 2021-03-12
*/
public class LruBitmapPool implements BitmapPool {
private static final String TAG = LruBitmapPool.class.getSimpleName();
- private static final Bitmap.Config DEFAULT_CONFIG = Bitmap.Config.ARGB_8888;
+ private static final PixelFormat DEFAULT_CONFIG = PixelFormat.ARGB_8888;
+ private static final int TRIM_MEMORY_BACKGROUND = 40;
+ private static final int TRIM_MEMORY_UI_HIDDEN = 20;
+ private final int two = 2;
private final LruPoolStrategy strategy;
- private final Set allowedConfigs;
+ private final Set allowedConfigs;
private final int initialMaxSize;
private final BitmapTracker tracker;
@@ -48,7 +39,10 @@ public class LruBitmapPool implements BitmapPool {
private int puts;
private int evictions;
- private LruBitmapPool(int maxSize, LruPoolStrategy strategy, Set allowedConfigs) {
+ private int domain = 0x001;
+ private HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, domain, TAG);
+
+ private LruBitmapPool(int maxSize, LruPoolStrategy strategy, Set allowedConfigs) {
this.initialMaxSize = maxSize;
this.maxSize = maxSize;
this.strategy = strategy;
@@ -56,11 +50,22 @@ public class LruBitmapPool implements BitmapPool {
this.tracker = new NullBitmapTracker();
}
+ /**
+ * 构建一定数量的缓存池
+ *
+ * @param maxSize
+ */
public LruBitmapPool(int maxSize) {
this(maxSize, getDefaultStrategy(), getDefaultAllowedConfigs());
}
- public LruBitmapPool(int maxSize, Set allowedConfigs) {
+ /**
+ * 构建一定数量的缓存池并添加配置
+ *
+ * @param maxSize
+ * @param allowedConfigs
+ */
+ public LruBitmapPool(int maxSize, Set allowedConfigs) {
this(maxSize, getDefaultStrategy(), allowedConfigs);
}
@@ -76,23 +81,23 @@ public class LruBitmapPool implements BitmapPool {
}
@Override
- public synchronized void put(Bitmap bitmap) {
+ public synchronized void put(PixelMap bitmap) {
if (bitmap == null) {
throw new NullPointerException("Bitmap must not be null");
}
- if (bitmap.isRecycled()) {
+ if (bitmap.isReleased()) {
throw new IllegalStateException("Cannot pool recycled bitmap");
}
- if (!bitmap.isMutable() || strategy.getSize(bitmap) > maxSize
- || !allowedConfigs.contains(bitmap.getConfig())) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "Reject bitmap from pool"
+ if (!bitmap.isEditable() || strategy.getSize(bitmap) > maxSize
+ || !allowedConfigs.contains(bitmap.getImageInfo().pixelFormat)) {
+ if (HiLog.isLoggable(domain, TAG, HiLog.LOG_APP)) {
+ HiLog.info(logLabel, "Reject bitmap from pool"
+ ", bitmap: " + strategy.logBitmap(bitmap)
- + ", is mutable: " + bitmap.isMutable()
- + ", is allowed config: " + allowedConfigs.contains(bitmap.getConfig()));
+ + ", is mutable: " + bitmap.isEditable()
+ + ", is allowed config: " + allowedConfigs.contains(bitmap.getImageInfo().pixelFormat));
}
- bitmap.recycle();
+ bitmap.release();
return;
}
@@ -103,8 +108,8 @@ public class LruBitmapPool implements BitmapPool {
puts++;
currentSize += size;
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "Put bitmap in pool=" + strategy.logBitmap(bitmap));
+ if (HiLog.isLoggable(domain, TAG, HiLog.LOG_APP)) {
+ HiLog.info(logLabel, "Put bitmap in pool=" + strategy.logBitmap(bitmap));
}
dump();
@@ -116,32 +121,38 @@ public class LruBitmapPool implements BitmapPool {
}
@Override
- public Bitmap get(int width, int height, Bitmap.Config config) {
- Bitmap result = getDirtyOrNull(width, height, config);
+ public PixelMap get(int width, int height, PixelFormat config) {
+ PixelMap result = getDirtyOrNull(width, height, config);
if (result != null) {
- result.eraseColor(Color.TRANSPARENT);
+ result.writePixels(Color.TRANSPARENT.getValue());
} else {
- result = Bitmap.createBitmap(width, height, config);
+ PixelMap.InitializationOptions initializationOptions = new PixelMap.InitializationOptions();
+ initializationOptions.size = new Size(width,height);
+ initializationOptions.pixelFormat = config;
+ result = PixelMap.create(initializationOptions);
}
return result;
}
@Override
- public Bitmap getDirty(int width, int height, Bitmap.Config config) {
- Bitmap result = getDirtyOrNull(width, height, config);
+ public PixelMap getDirty(int width, int height, PixelFormat config) {
+ PixelMap result = getDirtyOrNull(width, height, config);
if (result == null) {
- result = Bitmap.createBitmap(width, height, config);
+ PixelMap.InitializationOptions initializationOptions = new PixelMap.InitializationOptions();
+ initializationOptions.size = new Size(width,height);
+ initializationOptions.pixelFormat = config;
+ result = PixelMap.create(initializationOptions);
}
return result;
}
- private synchronized Bitmap getDirtyOrNull(int width, int height, Bitmap.Config config) {
+ private synchronized PixelMap getDirtyOrNull(int width, int height, PixelFormat config) {
// Config will be null for non public config types, which can lead to transformations naively
// passing in null as the requested config here. See issue #194.
- final Bitmap result = strategy.get(width, height, config != null ? config : DEFAULT_CONFIG);
+ final PixelMap result = strategy.get(width, height, config != null ? config : DEFAULT_CONFIG);
if (result == null) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Missing bitmap=" + strategy.logBitmap(width, height, config));
+ if (HiLog.isLoggable(domain, TAG, HiLog.DEBUG)) {
+ HiLog.debug(logLabel, "Missing bitmap=" + strategy.logBitmap(width, height, config));
}
misses++;
} else {
@@ -150,62 +161,76 @@ public class LruBitmapPool implements BitmapPool {
tracker.remove(result);
normalize(result);
}
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "Get bitmap=" + strategy.logBitmap(width, height, config));
+ if (HiLog.isLoggable(domain, TAG, HiLog.LOG_APP)) {
+ HiLog.info(logLabel, "Get bitmap=" + strategy.logBitmap(width, height, config));
}
dump();
return result;
}
- // Setting these two values provides Bitmaps that are essentially equivalent to those returned
- // from Bitmap.createBitmap.
- private static void normalize(Bitmap bitmap) {
+ /**
+ * Setting these two values provides Bitmaps that are essentially equivalent to those returned
+ * from Bitmap.createBitmap.
+ *
+ * @param bitmap
+ */
+ private static void normalize(PixelMap bitmap) {
maybeSetAlpha(bitmap);
maybeSetPreMultiplied(bitmap);
}
- @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
- private static void maybeSetAlpha(Bitmap bitmap) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
- bitmap.setHasAlpha(true);
- }
+ private static void maybeSetAlpha(PixelMap bitmap) {
+ bitmap.setAlphaType(AlphaType.UNPREMUL);
}
- @TargetApi(Build.VERSION_CODES.KITKAT)
- private static void maybeSetPreMultiplied(Bitmap bitmap) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- bitmap.setPremultiplied(true);
- }
+ private static void maybeSetPreMultiplied(PixelMap bitmap) {
+ bitmap.setAlphaType(AlphaType.PREMUL);
}
@Override
public void clearMemory() {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "clearMemory");
+ if (HiLog.isLoggable(domain, TAG, HiLog.DEBUG)) {
+ HiLog.debug(logLabel, "clearMemory");
}
trimToSize(0);
}
- @SuppressLint("InlinedApi")
@Override
public void trimMemory(int level) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "trimMemory, level=" + level);
+ if (HiLog.isLoggable(domain, TAG, HiLog.DEBUG)) {
+ HiLog.debug(logLabel, "trimMemory, level=" + level);
}
- if (level >= android.content.ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
+
+ /**
+ * 20:例如,由于用户触摸了设备上的Home键,因此应用程序UI被隐藏。您的应用程序应释放分配给UI显示的资源,以释放内存。
+ */
+
+ /**
+ * 40:设备的内存不足,并且您的应用程序位于LRU列表的顶部。该系统不太可能杀死您的应用程序。
+ * 为了将您的应用程序进程在缓存中保留更长的时间,您的应用程序应通过释放一些易于恢复的资源来增加可用的系统内存。
+ * 这样,您的应用程序可以平稳地返回到前台,而不必重新启动。
+ */
+
+ /**
+ * android中对应具体数值 int TRIM_MEMORY_BACKGROUND = 40
+ */
+ if (level >= TRIM_MEMORY_BACKGROUND) {
clearMemory();
- } else if (level >= android.content.ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
- trimToSize(maxSize / 2);
+ /**
+ * android中对应具体数值 int TRIM_MEMORY_UI_HIDDEN = 20
+ */
+ } else if (level >= TRIM_MEMORY_UI_HIDDEN) {
+ trimToSize(maxSize / two);
}
}
private synchronized void trimToSize(int size) {
while (currentSize > size) {
- final Bitmap removed = strategy.removeLast();
+ final PixelMap removed = strategy.removeLast();
if (removed == null) {
- if (Log.isLoggable(TAG, Log.WARN)) {
- Log.w(TAG, "Size mismatch, resetting");
+ if (HiLog.isLoggable(domain, TAG, HiLog.WARN)) {
+ HiLog.warn(logLabel, "Size mismatch, resetting");
dumpUnchecked();
}
currentSize = 0;
@@ -214,67 +239,82 @@ public class LruBitmapPool implements BitmapPool {
tracker.remove(removed);
currentSize -= strategy.getSize(removed);
evictions++;
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Evicting bitmap=" + strategy.logBitmap(removed));
+ if (HiLog.isLoggable(domain, TAG, HiLog.DEBUG)) {
+ HiLog.debug(logLabel, "Evicting bitmap=" + strategy.logBitmap(removed));
}
dump();
- removed.recycle();
+ removed.release();
}
}
private void dump() {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ if (HiLog.isLoggable(domain, TAG, HiLog.LOG_APP)) {
dumpUnchecked();
}
}
private void dumpUnchecked() {
- Log.v(TAG, "Hits=" + hits + ", misses=" + misses + ", puts=" + puts + ", evictions=" + evictions
- + ", currentSize=" + currentSize + ", maxSize=" + maxSize + "\nStrategy=" + strategy);
+ HiLog.info(logLabel, "Hits=" + hits + ", misses=" + misses + ", puts=" + puts + ", evictions=" + evictions
+ + ", currentSize=" + currentSize + ", maxSize=" + maxSize
+ + System.lineSeparator() + "Strategy=" + strategy);
}
private static LruPoolStrategy getDefaultStrategy() {
final LruPoolStrategy strategy;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- strategy = new SizeConfigStrategy();
- } else {
- strategy = new AttributeStrategy();
- }
+
+ /**
+ * Android api 19以上
+ */
+ strategy = new SizeConfigStrategy();
+
return strategy;
}
- private static Set getDefaultAllowedConfigs() {
- Set configs = new HashSet<>();
- configs.addAll(Arrays.asList(Bitmap.Config.values()));
- if (Build.VERSION.SDK_INT >= 19) {
- configs.add(null);
- }
+ private static Set getDefaultAllowedConfigs() {
+ Set configs = new HashSet<>();
+ configs.addAll(Arrays.asList(PixelFormat.values()));
+
+ /**
+ * Android api 19以上
+ */
+ configs.add(null);
return Collections.unmodifiableSet(configs);
}
+ /**
+ * 位图接口类
+ *
+ * @since 2021-03-12
+ */
private interface BitmapTracker {
- void add(Bitmap bitmap);
+ void add(PixelMap bitmap);
- void remove(Bitmap bitmap);
+ void remove(PixelMap bitmap);
}
+ /**
+ * 位图调试类
+ *
+ * @since 2021-03-12
+ */
@SuppressWarnings("unused")
// Only used for debugging
private static class ThrowingBitmapTracker implements BitmapTracker {
- private final Set bitmaps = Collections.synchronizedSet(new HashSet());
+ private final Set bitmaps = Collections.synchronizedSet(new HashSet());
@Override
- public void add(Bitmap bitmap) {
+ public void add(PixelMap bitmap) {
+ ImageInfo imageInfo = bitmap.getImageInfo();
+ Size size = imageInfo.size;
if (bitmaps.contains(bitmap)) {
throw new IllegalStateException(
- "Can't add already added bitmap: " + bitmap + " [" + bitmap.getWidth() + "x" + bitmap
- .getHeight() + "]");
+ "Can't add already added bitmap: " + bitmap + " [" + size.width + "x" + size.height + "]");
}
bitmaps.add(bitmap);
}
@Override
- public void remove(Bitmap bitmap) {
+ public void remove(PixelMap bitmap) {
if (!bitmaps.contains(bitmap)) {
throw new IllegalStateException("Cannot remove bitmap not in tracker");
}
@@ -282,14 +322,19 @@ public class LruBitmapPool implements BitmapPool {
}
}
+ /**
+ * 空位图
+ *
+ * @since 2021-03-12
+ */
private static class NullBitmapTracker implements BitmapTracker {
@Override
- public void add(Bitmap bitmap) {
+ public void add(PixelMap bitmap) {
// Do nothing.
}
@Override
- public void remove(Bitmap bitmap) {
+ public void remove(PixelMap bitmap) {
// Do nothing.
}
}
diff --git a/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/LruPoolStrategy.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/LruPoolStrategy.java
new file mode 100644
index 0000000000000000000000000000000000000000..2226b407d6c4f664a5438f3e815c2c3fffd590a5
--- /dev/null
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/LruPoolStrategy.java
@@ -0,0 +1,62 @@
+package com.glidebitmappool.internal;
+
+import ohos.media.image.PixelMap;
+import ohos.media.image.common.PixelFormat;
+
+/**
+ * 缓存池接口
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ */
+interface LruPoolStrategy {
+ /**
+ * 添加缓存图
+ *
+ * @param bitmap 图片
+ */
+ void put(PixelMap bitmap);
+
+ /**
+ * 获取缓存图
+ *
+ * @param width 宽
+ * @param height 高
+ * @param config 格式
+ * @return PixelMap
+ */
+ PixelMap get(int width, int height, PixelFormat config);
+
+ /**
+ * 删除最后一条
+ *
+ * @return PixelMap
+ */
+ PixelMap removeLast();
+
+ /**
+ * 打印图片日志
+ *
+ * @param bitmap
+ * @return String
+ */
+ String logBitmap(PixelMap bitmap);
+
+ /**
+ * 打印图片日志
+ *
+ * @param width 宽
+ * @param height 高
+ * @param config 格式
+ * @return String
+ */
+ String logBitmap(int width, int height, PixelFormat config);
+
+ /**
+ * 获取图片大小
+ *
+ * @param bitmap
+ * @return int
+ */
+ int getSize(PixelMap bitmap);
+}
\ No newline at end of file
diff --git a/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/Poolable.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/Poolable.java
new file mode 100644
index 0000000000000000000000000000000000000000..f8fde64c5093c6b48dcbcc2b98e70640819a6e54
--- /dev/null
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/Poolable.java
@@ -0,0 +1,15 @@
+package com.glidebitmappool.internal;
+
+/**
+ * 缓存Bean
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ */
+interface Poolable {
+ /**
+ * 插入元素
+ */
+ void offer();
+}
+
diff --git a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/SizeConfigStrategy.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/SizeConfigStrategy.java
similarity index 51%
rename from glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/SizeConfigStrategy.java
rename to glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/SizeConfigStrategy.java
index f8149ddb246f672589c7b3143f3d1d3b11f3f616..8cbb3ccecbf6c6dcacdcb18af70488a9dd8def09 100644
--- a/glide-bitmap-pool/src/main/java/com/glidebitmappool/internal/SizeConfigStrategy.java
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/SizeConfigStrategy.java
@@ -1,88 +1,94 @@
-/*
- * 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.internal;
-import android.annotation.TargetApi;
-import android.graphics.Bitmap;
-import android.os.Build;
+import ohos.media.image.PixelMap;
+import ohos.media.image.common.PixelFormat;
+import ohos.media.image.common.Size;
import java.util.HashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
-
/**
- * Created by amitshekhar on 17/06/16.
+ * 位图尺寸配置类
+ *
+ * @author renpengfei
+ * @since 2021-03-12
*/
-@TargetApi(Build.VERSION_CODES.KITKAT)
public class SizeConfigStrategy implements LruPoolStrategy {
private static final int MAX_SIZE_MULTIPLE = 8;
+ private static final int TWO = 2;
+
+ // The value returned by Bitmaps with the hidden Bitmap config.
+ private static final PixelFormat[] ARGB_8888_IN_CONFIGS =
+ new PixelFormat[]{PixelFormat.ARGB_8888, null,};
- private static final Bitmap.Config[] ARGB_8888_IN_CONFIGS =
- new Bitmap.Config[]{
- Bitmap.Config.ARGB_8888,
- // The value returned by Bitmaps with the hidden Bitmap config.
- null,
- };
// We probably could allow ARGB_4444 and RGB_565 to decode into each other, but ARGB_4444 is
// deprecated and we'd rather be safe.
- private static final Bitmap.Config[] RGB_565_IN_CONFIGS =
- new Bitmap.Config[]{Bitmap.Config.RGB_565};
- private static final Bitmap.Config[] ARGB_4444_IN_CONFIGS =
- new Bitmap.Config[]{Bitmap.Config.ARGB_4444};
- private static final Bitmap.Config[] ALPHA_8_IN_CONFIGS =
- new Bitmap.Config[]{Bitmap.Config.ALPHA_8};
+ private static final PixelFormat[] RGB_565_IN_CONFIGS =
+ new PixelFormat[]{PixelFormat.RGB_565};
+// private static final PixelFormat[] ARGB_4444_IN_CONFIGS =
+// new PixelFormat[]{PixelFormat.ARGB_4444};
+// private static final PixelFormat[] ALPHA_8_IN_CONFIGS =
+// new PixelFormat[]{PixelFormat.ALPHA_8};
private final KeyPool keyPool = new KeyPool();
- private final GroupedLinkedMap groupedMap = new GroupedLinkedMap<>();
- private final Map> sortedSizes = new HashMap<>();
-
+ private final GroupedLinkedMap groupedMap = new GroupedLinkedMap<>();
+ private final Map> sortedSizes = new HashMap<>();
+
+ /**
+ * 添加图片
+ *
+ * @param bitmap 图片
+ */
@Override
- public void put(Bitmap bitmap) {
+ public void put(PixelMap bitmap) {
int size = Util.getBitmapByteSize(bitmap);
- Key key = keyPool.get(size, bitmap.getConfig());
+ Key key = keyPool.get(size, bitmap.getImageInfo().pixelFormat);
groupedMap.put(key, bitmap);
- NavigableMap sizes = getSizesForConfig(bitmap.getConfig());
+ NavigableMap sizes = getSizesForConfig(bitmap.getImageInfo().pixelFormat);
Integer current = sizes.get(key.size);
sizes.put(key.size, current == null ? 1 : current + 1);
}
+ /**
+ * 获取图片
+ *
+ * @param width 宽
+ * @param height 高
+ * @param config 格式
+ * @return PixelMap
+ */
@Override
- public Bitmap get(int width, int height, Bitmap.Config config) {
+ public PixelMap get(int width, int height, PixelFormat config) {
int size = Util.getBitmapByteSize(width, height, config);
Key bestKey = findBestKey(size, config);
- Bitmap result = groupedMap.get(bestKey);
+ PixelMap result = groupedMap.get(bestKey);
if (result != null) {
// Decrement must be called before reconfigure.
decrementBitmapOfSize(bestKey.size, result);
- result.reconfigure(width, height,
- result.getConfig() != null ? result.getConfig() : Bitmap.Config.ARGB_8888);
+ Size infoSize = result.getImageInfo().size;
+ infoSize.width = width;
+ infoSize.height = height;
+ result.resetConfig(infoSize, result.getImageInfo().pixelFormat != null
+ ? result.getImageInfo().pixelFormat : PixelFormat.ARGB_8888);
}
return result;
}
- private Key findBestKey(int size, Bitmap.Config config) {
+ /**
+ * 设置key
+ *
+ * @param size
+ * @param config
+ * @return Key
+ */
+ private Key findBestKey(int size, PixelFormat config) {
Key result = keyPool.get(size, config);
- for (Bitmap.Config possibleConfig : getInConfigs(config)) {
+ for (PixelFormat possibleConfig : getInConfigs(config)) {
NavigableMap sizesForPossibleConfig = getSizesForConfig(possibleConfig);
Integer possibleSize = sizesForPossibleConfig.ceilingKey(size);
if (possibleSize != null && possibleSize <= size * MAX_SIZE_MULTIPLE) {
@@ -98,8 +104,8 @@ public class SizeConfigStrategy implements LruPoolStrategy {
}
@Override
- public Bitmap removeLast() {
- Bitmap removed = groupedMap.removeLast();
+ public PixelMap removeLast() {
+ PixelMap removed = groupedMap.removeLast();
if (removed != null) {
int removedSize = Util.getBitmapByteSize(removed);
decrementBitmapOfSize(removedSize, removed);
@@ -107,8 +113,15 @@ public class SizeConfigStrategy implements LruPoolStrategy {
return removed;
}
- private void decrementBitmapOfSize(Integer size, Bitmap removed) {
- Bitmap.Config config = removed.getConfig();
+ /**
+ * 减少位图大小
+ *
+ * @param size
+ * @param removed
+ * @throws NullPointerException
+ */
+ private void decrementBitmapOfSize(Integer size, PixelMap removed) {
+ PixelFormat config = removed.getImageInfo().pixelFormat;
NavigableMap sizes = getSizesForConfig(config);
Integer current = sizes.get(size);
if (current == null) {
@@ -125,7 +138,13 @@ public class SizeConfigStrategy implements LruPoolStrategy {
}
}
- private NavigableMap getSizesForConfig(Bitmap.Config config) {
+ /**
+ * 获取配置大小
+ *
+ * @param config
+ * @return NavigableMap
+ */
+ private NavigableMap getSizesForConfig(PixelFormat config) {
NavigableMap sizes = sortedSizes.get(config);
if (sizes == null) {
sizes = new TreeMap<>();
@@ -134,20 +153,40 @@ public class SizeConfigStrategy implements LruPoolStrategy {
return sizes;
}
+ /**
+ * 日志信息
+ *
+ * @param bitmap
+ * @return String
+ */
@Override
- public String logBitmap(Bitmap bitmap) {
+ public String logBitmap(PixelMap bitmap) {
int size = Util.getBitmapByteSize(bitmap);
- return getBitmapString(size, bitmap.getConfig());
+ return getBitmapString(size, bitmap.getImageInfo().pixelFormat);
}
+ /**
+ * 日志信息
+ *
+ * @param width 宽
+ * @param height 高
+ * @param config 格式
+ * @return String
+ */
@Override
- public String logBitmap(int width, int height, Bitmap.Config config) {
+ public String logBitmap(int width, int height, PixelFormat config) {
int size = Util.getBitmapByteSize(width, height, config);
return getBitmapString(size, config);
}
+ /**
+ * 获取大小
+ *
+ * @param bitmap
+ * @return int
+ */
@Override
- public int getSize(Bitmap bitmap) {
+ public int getSize(PixelMap bitmap) {
return Util.getBitmapByteSize(bitmap);
}
@@ -158,50 +197,66 @@ public class SizeConfigStrategy implements LruPoolStrategy {
.append("SizeConfigStrategy{groupedMap=")
.append(groupedMap)
.append(", sortedSizes=(");
- for (Map.Entry> entry : sortedSizes.entrySet()) {
+ for (Map.Entry> entry : sortedSizes.entrySet()) {
sb.append(entry.getKey()).append('[').append(entry.getValue()).append("], ");
}
if (!sortedSizes.isEmpty()) {
- sb.replace(sb.length() - 2, sb.length(), "");
+ sb.replace(sb.length() - TWO, sb.length(), "");
}
return sb.append(")}").toString();
}
- // Visible for testing.
+ /**
+ *
+ */
static class KeyPool extends BaseKeyPool {
-
- public Key get(int size, Bitmap.Config config) {
+ public Key get(int size, PixelFormat config) {
Key result = get();
result.init(size, config);
return result;
}
+ /**
+ * 初始化
+ *
+ * @return Key
+ */
@Override
protected Key create() {
return new Key(this);
}
}
- // Visible for testing.
+ /**
+ * 测试使用
+ *
+ * @since 2021-03-12
+ */
static final class Key implements Poolable {
private final KeyPool pool;
private int size;
- private Bitmap.Config config;
+ private PixelFormat config;
- public Key(KeyPool pool) {
+ Key(KeyPool pool) {
this.pool = pool;
}
- // Visible for testing.
- Key(KeyPool pool, int size, Bitmap.Config config) {
+ /**
+ * Visible for testing.
+ *
+ * @param pool
+ * @param size
+ * @param config
+ */
+ Key(KeyPool pool, int size, PixelFormat config) {
this(pool);
init(size, config);
}
- public void init(int size, Bitmap.Config config) {
- this.size = size;
- this.config = config;
+ void init(int size1, PixelFormat pixelFormat) {
+ this.size = size1;
+ this.config = pixelFormat;
}
@Override
@@ -215,9 +270,9 @@ public class SizeConfigStrategy implements LruPoolStrategy {
}
@Override
- public boolean equals(Object o) {
- if (o instanceof Key) {
- Key other = (Key) o;
+ public boolean equals(Object object) {
+ if (object instanceof Key) {
+ Key other = (Key) object;
return size == other.size
&& Util.bothNullOrEqual(config, other.config);
}
@@ -232,22 +287,35 @@ public class SizeConfigStrategy implements LruPoolStrategy {
}
}
- private static String getBitmapString(int size, Bitmap.Config config) {
+ /**
+ * getBitmapString
+ *
+ * @param size
+ * @param config
+ * @return String
+ */
+ private static String getBitmapString(int size, PixelFormat config) {
return "[" + size + "](" + config + ")";
}
- private static Bitmap.Config[] getInConfigs(Bitmap.Config requested) {
+ /**
+ * 获取配置
+ *
+ * @param requested
+ * @return PixelFormat
+ */
+ private static PixelFormat[] getInConfigs(PixelFormat requested) {
switch (requested) {
case ARGB_8888:
return ARGB_8888_IN_CONFIGS;
case RGB_565:
return RGB_565_IN_CONFIGS;
- case ARGB_4444:
- return ARGB_4444_IN_CONFIGS;
- case ALPHA_8:
- return ALPHA_8_IN_CONFIGS;
+// case ARGB_4444:
+// return ARGB_4444_IN_CONFIGS;
+// case ALPHA_8:
+// return ALPHA_8_IN_CONFIGS;
default:
- return new Bitmap.Config[]{requested};
+ return new PixelFormat[]{requested};
}
}
}
diff --git a/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/Util.java b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/Util.java
new file mode 100644
index 0000000000000000000000000000000000000000..57a05481531803f6770c65b8a152a128df41a539
--- /dev/null
+++ b/glide_bitmap_pool/src/main/java/com/glidebitmappool/internal/Util.java
@@ -0,0 +1,179 @@
+package com.glidebitmappool.internal;
+
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+import ohos.media.image.ImageSource;
+import ohos.media.image.PixelMap;
+import ohos.media.image.common.ImageInfo;
+import ohos.media.image.common.PixelFormat;
+import ohos.media.image.common.Size;
+
+import java.util.ArrayDeque;
+import java.util.Objects;
+import java.util.Queue;
+
+/**
+ * 位图工具类
+ *
+ * @author renpengfei
+ * @since 2021-03-12
+ */
+public class Util {
+ private static final int ONE = 1;
+ private static final int TWO = 2;
+ private static final int FOUR = 4;
+
+ private static HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x001, "Util");
+
+ private Util() {
+ // Utility class.
+ }
+
+ /**
+ * 获取位图字节数
+ *
+ * @param bitmap
+ * @return int
+ * @throws IllegalStateException
+ */
+ public static int getBitmapByteSize(PixelMap bitmap) {
+ ImageInfo imageInfo = bitmap.getImageInfo();
+ Size size = imageInfo.size;
+
+ /**
+ * 对于回收的位图,
+ * getAllocationByteCount的返回值无提示地从内部缓冲区大小更改为行字节*高度。
+ * 为了避免缓存中的随机不一致,我们在这里断言。
+ */
+ if (bitmap.isReleased()) {
+ throw new IllegalStateException("Cannot obtain size for recycled Bitmap: " + bitmap
+ + "[" + size.width + "x" + size.height + "] " + imageInfo.pixelFormat);
+ }
+
+ // Workaround for KitKat initial release NPE in Bitmap, fixed in MR1. See issue #148.
+ try {
+ return (int) bitmap.getPixelBytesNumber();
+ } catch (IllegalArgumentException e) {
+ HiLog.error(logLabel, e.getMessage());
+ }
+
+ return bitmap.getImageInfo().size.height * bitmap.getBytesNumberPerRow();
+ }
+
+ /**
+ * 获取位图字节数
+ *
+ * @param width
+ * @param height
+ * @param config
+ * @return int
+ */
+ public static int getBitmapByteSize(int width, int height, PixelFormat config) {
+ return width * height * getBytesPerPixel(config);
+ }
+
+ /**
+ * 获取字节像素
+ *
+ * @param config
+ * @return int
+ */
+ private static int getBytesPerPixel(PixelFormat config) {
+ // 通过解码gif的位图在某些环境中具有空的“ config”。
+ if (config == null) {
+ config = PixelFormat.ARGB_8888;
+ }
+
+ int bytesPerPixel;
+ switch (config) {
+ case ARGB_8888:
+ bytesPerPixel = ONE;
+ break;
+// case ARGB_4444:
+ case RGB_565:
+ bytesPerPixel = TWO;
+ break;
+ default:
+ bytesPerPixel = FOUR;
+ break;
+ }
+ return bytesPerPixel;
+ }
+
+ /**
+ * 创建队列
+ *
+ * @param size
+ * @param
+ * @return 返回数组队列
+ */
+ public static Queue createQueue(int size) {
+ return new ArrayDeque<>(size);
+ }
+
+ /**
+ * 判空
+ *
+ * @param object
+ * @param object1
+ * @return boolean
+ */
+ public static boolean bothNullOrEqual(Object object, Object object1) {
+ return Objects.equals(object, object1);
+ }
+
+ /**
+ * 是否可用位图
+ *
+ * @param candidate 位图
+ * @param targetOptions 属性
+ * @return boolean
+ */
+ public static boolean canUseForInBitmap(
+ PixelMap candidate, ImageSource.DecodingOptions targetOptions) {
+ /**
+ * 从Android 4.4(KitKat)开始,如果新位图的字节大小小于可重复使用的位图候选分配字节数,我们可以重新使用
+ */
+ ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions();
+ decodingOptions.desiredSize = new Size(1, 1);
+ int width = decodingOptions.desiredSize.width / targetOptions.sampleSize;
+ int height = decodingOptions.desiredSize.width / targetOptions.sampleSize;
+ int byteCount = width * height * getBytesPerPixel(candidate.getImageInfo().pixelFormat);
+
+ try {
+ return byteCount <= candidate.getPixelBytesCapacity();
+ } catch (IllegalArgumentException e) {
+ return byteCount <= candidate.getImageInfo().size.height * candidate.getBytesNumberPerRow();
+ }
+ }
+
+ /**
+ * 计算样本大小
+ *
+ * @param options
+ * @param reqWidth
+ * @param reqHeight
+ * @return int
+ */
+ public static int calculateInSampleSize(ImageSource.DecodingOptions options, int reqWidth, int reqHeight) {
+ // Raw height and width of image
+ final int height = options.desiredSize.height;
+ final int width = options.desiredSize.width;
+ int inSampleSize = 1;
+
+ if (height > reqHeight || width > reqWidth) {
+ final int halfHeight = height / TWO;
+ final int halfWidth = width / TWO;
+
+ /**
+ * 计算最大的inSampleSize值,该值为2的幂,并且高度和宽度都大于请求的高度和宽度。
+ */
+ while ((halfHeight / inSampleSize) > reqHeight
+ && (halfWidth / inSampleSize) > reqWidth) {
+ inSampleSize *= TWO;
+ }
+ }
+
+ return inSampleSize;
+ }
+}
diff --git a/glide_bitmap_pool/src/main/resources/base/element/string.json b/glide_bitmap_pool/src/main/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..e58c7d7ee9cd58a91e5cac9aae2ad3657ed551f8
--- /dev/null
+++ b/glide_bitmap_pool/src/main/resources/base/element/string.json
@@ -0,0 +1,8 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "glide_bitmap_pool"
+ }
+ ]
+}
diff --git a/gradle.properties b/gradle.properties
index e110e1d4c657e75560e858194f84e6907068ed4b..0daf1830fbdef07e50a44d74210c8c82f1b66278 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,35 +1,10 @@
-#
-# 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.
-#
-
# Project-wide Gradle settings.
-
-# IDE (e.g. Android Studio) users:
+# IDE (e.g. DevEco Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
-
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
-
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
-# Default value: -Xmx10248m -XX:MaxPermSize=256m
-# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
-
-# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
\ No newline at end of file
+# If the Chinese output is garbled, please configure the following parameter.
+# org.gradle.jvmargs=-Dfile.encoding=GBK
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 13372aef5e24af05341d49695ee84e5f9b594659..490fda8577df6c95960ba7077c43220e5bb2c0d9 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index b94f1f5fbf1bfc924c58dcca637c19884a046439..f59159e865d4b59feb1b8c44b001f62fc5d58df4 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,23 +1,5 @@
-#
-# 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.
-#
-
-#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
diff --git a/gradlew b/gradlew
index 9d82f78915133e1c35a6ea51252590fb38efac2f..2fe81a7d95e4f9ad2c9b2a046707d36ceb3980b3 100755
--- a/gradlew
+++ b/gradlew
@@ -1,4 +1,20 @@
-#!/usr/bin/env bash
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# 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
+#
+# https://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.
+#
##############################################################################
##
@@ -6,20 +22,38 @@
##
##############################################################################
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
-warn ( ) {
+warn () {
echo "$*"
}
-die ( ) {
+die () {
echo
echo "$*"
echo
@@ -30,6 +64,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
+nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
@@ -40,26 +75,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
+ NONSTOP* )
+ nonstop=true
+ ;;
esac
-# Attempt to set APP_HOME
-# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
-done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -85,7 +105,7 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -105,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
@@ -134,27 +154,30 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
- i=$((i+1))
+ i=`expr $i + 1`
done
case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
-# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
-function splitJvmOpts() {
- JVM_OPTS=("$@")
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
}
-eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
-JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+APP_ARGS=`save "$@"`
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
-exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
index 8a0b282aa6885fb573c106b3551f7275c5f17e8e..62bd9b9ccefea2b65ae41e5d9a545e2021b90a1d 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -1,3 +1,19 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@@ -8,14 +24,17 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -46,10 +65,9 @@ echo location of your Java installation.
goto fail
:init
-@rem Get command-line arguments, handling Windowz variants
+@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
-if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
@@ -60,11 +78,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
-goto execute
-
-:4NT_args
-@rem Get arguments from the 4NT Shell from JP Software
-set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
diff --git a/settings.gradle b/settings.gradle
index ac8adff515cff78dde3aeea364a2980d85101264..9fb9f8e021a5673300f1772de9a9d6c5090b26ae 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,18 +1 @@
-/*
- * 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.
- */
-
-include ':app', ':glide-bitmap-pool'
+include ':entry', ':glide_bitmap_pool'