├── BitmapCanary
├── settings.gradle
├── app
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable-hdpi
│ │ │ │ └── printlogo.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_demo2.xml
│ │ │ │ └── activity_demo.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── java
│ │ │ └── smallnew
│ │ │ │ └── bitmapcanary
│ │ │ │ ├── DemoActivity2.java
│ │ │ │ ├── DemoApplication.java
│ │ │ │ └── DemoActivity.java
│ │ │ └── AndroidManifest.xml
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── app.iml
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── androidbitmapcanary
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ │ ├── AndroidManifest.xml
│ │ │ └── java
│ │ │ └── hexin
│ │ │ └── androidbitmapcanary
│ │ │ ├── DetectorFactory.java
│ │ │ ├── ImagesrcDetector.java
│ │ │ ├── BackgroundDetecotor.java
│ │ │ ├── Detector.java
│ │ │ ├── ActivityDrawableWatcher.java
│ │ │ └── DrawableDetectUtil.java
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── androidbitmapcanary.iml
├── local.properties
├── build.gradle
├── gradle.properties
├── BitmapCanary.iml
├── gradlew.bat
└── gradlew
├── detect_demo.png
└── README.md
/BitmapCanary/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':androidbitmapcanary'
2 |
--------------------------------------------------------------------------------
/detect_demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/detect_demo.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BitmapCanary
3 |
4 |
--------------------------------------------------------------------------------
/BitmapCanary/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidBitmapCanary
3 |
4 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/drawable-hdpi/printlogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/drawable-hdpi/printlogo.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smallnew/BitmapCanary/HEAD/BitmapCanary/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/BitmapCanary/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 02 17:31:08 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/java/smallnew/bitmapcanary/DemoActivity2.java:
--------------------------------------------------------------------------------
1 | package smallnew.bitmapcanary;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | public class DemoActivity2 extends Activity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_demo2);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/java/smallnew/bitmapcanary/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package smallnew.bitmapcanary;
2 |
3 | import android.app.Application;
4 |
5 | import hexin.androidbitmapcanary.ActivityDrawableWatcher;
6 |
7 | /**
8 | * Created by smallnew on 2018/5/3.
9 | */
10 |
11 | public class DemoApplication extends Application {
12 | @Override
13 | public void onCreate() {
14 | super.onCreate();
15 | ActivityDrawableWatcher.watchDrawable(this);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/BitmapCanary/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | #Sat May 05 20:35:15 CST 2018
11 | sdk.dir=D\:\\Android\\sdk
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BitmapCanary
2 | Detect Android bitmap size when app runing,检查安卓运行时使用的bitmap大小,检查出过大的位图并展示
3 |
4 | 介绍:
5 | Android工程中会使用大量的图片,但是如果图片放置的drawable目录位置不正确,可能会导致图片占用的内存过大,可能导致cpu使用更多时间分配更多内存,可能导致内存溢出
6 | 现在可以使用BitmapCanary来方便开发者检查工程中过大的图片,可视化展示,一句代码即可接入该功能
7 |
8 |
9 | 使用方法:
10 |
11 | 下载并依赖androidbitmapcanary
12 |
13 | ActivityDrawableWatcher.watchDrawable(this);//这样就ok啦
14 |
15 | app界面会有蒙层来表示该图片的位图已经超过了视图的1.5倍(长宽)大小,并有白色数字标明倍数
16 |
17 |
18 | 
19 |
--------------------------------------------------------------------------------
/BitmapCanary/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.0'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 16
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 |
14 |
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | implementation 'com.android.support:appcompat-v7:26.1.0'
30 | }
31 |
--------------------------------------------------------------------------------
/BitmapCanary/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "smallnew.bitmapcanary"
7 | minSdkVersion 16
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation fileTree(include: ['*.jar'], dir: 'libs')
22 | implementation 'com.android.support.constraint:constraint-layout:1.1.0'
23 | implementation project(':androidbitmapcanary')
24 | }
25 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/java/smallnew/bitmapcanary/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package smallnew.bitmapcanary;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | public class DemoActivity extends Activity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_demo);
14 | findViewById(R.id.iv_go2).setOnClickListener(new View.OnClickListener() {
15 | @Override
16 | public void onClick(View view) {
17 | startActivity(new Intent(DemoActivity.this,DemoActivity2.class));
18 | }
19 | });
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/BitmapCanary/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1024m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/BitmapCanary/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/BitmapCanary/BitmapCanary.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/layout/activity_demo2.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
16 |
17 |
22 |
23 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/layout/activity_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
21 |
22 |
26 |
27 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/src/main/java/hexin/androidbitmapcanary/DetectorFactory.java:
--------------------------------------------------------------------------------
1 | package hexin.androidbitmapcanary;
2 |
3 | import java.util.HashMap;
4 |
5 | /**
6 | * 图片检测工厂
7 | * Created by smallnew on 2018\5\5 0005.
8 | */
9 |
10 | public class DetectorFactory {
11 |
12 | public static final int DETECT_TYPE_BACKGROUND = 1;
13 | public static final int DETECT_TYPE_IMAGESRC = 2;
14 | private static HashMap detectorCache = new HashMap<>();
15 |
16 | public static Detector getDetector(int detectType){
17 | if(detectorCache.containsKey(detectType)){
18 | return detectorCache.get(detectType);
19 | }else {
20 | return produceDetector(detectType);
21 | }
22 | }
23 |
24 | private static Detector produceDetector(int detectType){
25 | if(DETECT_TYPE_BACKGROUND == detectType){
26 | return new BackgroundDetecotor();
27 | }else if(DETECT_TYPE_IMAGESRC == detectType){
28 | return new ImagesrcDetector();
29 | }else {//todo checkbox detector、progress detecor ... adding furtue
30 | throw new IllegalArgumentException("detectType not support "+detectType);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/src/main/java/hexin/androidbitmapcanary/ImagesrcDetector.java:
--------------------------------------------------------------------------------
1 | package hexin.androidbitmapcanary;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.BitmapDrawable;
5 | import android.graphics.drawable.Drawable;
6 | import android.graphics.drawable.StateListDrawable;
7 | import android.widget.ImageView;
8 |
9 | import static hexin.androidbitmapcanary.DrawableDetectUtil.MAX_SCALE;
10 |
11 | /**
12 | * 图片检测
13 | * Created by smallnew on 2018\5\5 0005.
14 | */
15 |
16 | public class ImagesrcDetector extends Detector{
17 | public ImagesrcDetector() {
18 | }
19 |
20 | @Override
21 | public void detect(ImageView imageView) {
22 | Drawable srcDrawable = imageView.getDrawable();
23 | if(srcDrawable instanceof StateListDrawable){
24 | srcDrawable = srcDrawable.getCurrent();
25 | }
26 | if(srcDrawable instanceof BitmapDrawable){
27 | Bitmap bitmap = ((BitmapDrawable) srcDrawable).getBitmap();
28 | if(bitmap.getHeight()>imageView.getHeight()*MAX_SCALE
29 | ||bitmap.getWidth()>imageView.getWidth()*MAX_SCALE){
30 | markScaleView(bitmap,imageView);
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/src/main/java/hexin/androidbitmapcanary/BackgroundDetecotor.java:
--------------------------------------------------------------------------------
1 | package hexin.androidbitmapcanary;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.BitmapDrawable;
5 | import android.graphics.drawable.Drawable;
6 | import android.graphics.drawable.StateListDrawable;
7 | import android.view.View;
8 |
9 | import static hexin.androidbitmapcanary.DrawableDetectUtil.MAX_SCALE;
10 |
11 | /**
12 | * 背景图片检测
13 | * Created by smallnew on 2018\5\5 0005.
14 | */
15 |
16 | public class BackgroundDetecotor extends Detector {
17 | public BackgroundDetecotor() {
18 | super();
19 | }
20 |
21 | @Override
22 | public void detect(View view) {
23 | Drawable backGroupDrawable = view.getBackground();
24 | if(backGroupDrawable instanceof StateListDrawable){
25 | backGroupDrawable = backGroupDrawable.getCurrent();
26 | }
27 | if(backGroupDrawable!=null&&backGroupDrawable instanceof BitmapDrawable){
28 | Bitmap bitmap = ((BitmapDrawable) backGroupDrawable).getBitmap();
29 | if(bitmap.getHeight()>view.getHeight()*MAX_SCALE
30 | ||bitmap.getWidth()>view.getWidth()*MAX_SCALE){
31 | markScaleView(bitmap,view);
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/src/main/java/hexin/androidbitmapcanary/Detector.java:
--------------------------------------------------------------------------------
1 | package hexin.androidbitmapcanary;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Color;
5 | import android.os.Build;
6 | import android.view.View;
7 | import android.view.ViewOverlay;
8 |
9 | import static hexin.androidbitmapcanary.DrawableDetectUtil.getTipColorByScale;
10 |
11 | /**
12 | * Created by smallnew on 2018\5\5 0005.
13 | */
14 |
15 | public abstract class Detector {
16 |
17 | public Detector(){
18 |
19 | }
20 |
21 | abstract public void detect(T view);
22 |
23 | protected void markScaleView(Bitmap bitmap, T view){
24 | float scale = Math.max(bitmap.getHeight()*1.0f/view.getHeight(),bitmap.getWidth()*1.0f/view.getWidth());
25 | if(Build.VERSION.SDK_INT>=18){
26 | ViewOverlay overlay = view.getOverlay();
27 | overlay.clear();
28 | DrawableDetectUtil.TextDetectDrawable detectDrawable = new DrawableDetectUtil.TextDetectDrawable();
29 | detectDrawable.setText(String.format("%.1f",scale));
30 | detectDrawable.setBgColor(getTipColorByScale(scale));
31 | detectDrawable.setBounds(0,0,view.getWidth(),view.getHeight());
32 | overlay.add(detectDrawable);
33 | }else {
34 | view.setBackgroundColor(getTipColorByScale(scale));
35 | }
36 | }
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/BitmapCanary/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/src/main/java/hexin/androidbitmapcanary/ActivityDrawableWatcher.java:
--------------------------------------------------------------------------------
1 | package hexin.androidbitmapcanary;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.view.ViewTreeObserver;
9 |
10 | import java.lang.ref.WeakReference;
11 | import java.util.HashMap;
12 |
13 | /**
14 | * Created by smallnew on 2018/5/2.
15 | */
16 |
17 | public class ActivityDrawableWatcher {
18 | private static HashMap drawableListenerRecord;
19 | public static void watchDrawable(Application application){
20 | new ActivityDrawableWatcher(application).startWatch();
21 | }
22 | private static class DrawableDetectListener implements ViewTreeObserver.OnGlobalLayoutListener{
23 | private WeakReference rootView;
24 | public DrawableDetectListener(View rootView){
25 | this.rootView = new WeakReference(rootView);
26 | }
27 | @Override
28 | public void onGlobalLayout() {
29 | if(rootView!=null&&rootView.get()!=null&&rootView.get() instanceof ViewGroup){
30 | DrawableDetectUtil.detectDrawableSize((ViewGroup)rootView.get());
31 | }
32 | }
33 | }
34 | private final Application.ActivityLifecycleCallbacks lifecycleCallbacks =
35 | new Application.ActivityLifecycleCallbacks() {
36 | @Override
37 | public void onActivityCreated(Activity activity, Bundle bundle) {
38 | View decorView = activity.getWindow().getDecorView();
39 | ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
40 | DrawableDetectListener drawableDetectListener = new DrawableDetectListener(decorView);
41 | viewTreeObserver.addOnGlobalLayoutListener(drawableDetectListener);
42 | drawableListenerRecord.put(decorView.hashCode(),drawableDetectListener);
43 | }
44 |
45 | @Override
46 | public void onActivityStarted(Activity activity) {
47 |
48 | }
49 |
50 | @Override
51 | public void onActivityResumed(Activity activity) {
52 |
53 | }
54 |
55 | @Override
56 | public void onActivityPaused(Activity activity) {
57 |
58 | }
59 |
60 | @Override
61 | public void onActivityStopped(Activity activity) {
62 |
63 | }
64 |
65 | @Override
66 | public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
67 |
68 | }
69 |
70 | @Override
71 | public void onActivityDestroyed(Activity activity) {
72 | View decorView = activity.getWindow().getDecorView();
73 | ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
74 | DrawableDetectListener detectListener = drawableListenerRecord.get(decorView.hashCode());
75 | if(detectListener!=null) {
76 | viewTreeObserver.removeOnGlobalLayoutListener(detectListener);
77 | }
78 | }
79 | };
80 | private final Application application;
81 |
82 | public ActivityDrawableWatcher(Application application){
83 | this.application = application;
84 | drawableListenerRecord = new HashMap<>();
85 | }
86 |
87 | public void startWatch(){
88 | stopWatch();
89 | application.registerActivityLifecycleCallbacks(lifecycleCallbacks);
90 | }
91 |
92 | public void stopWatch(){
93 | application.unregisterActivityLifecycleCallbacks(lifecycleCallbacks);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/src/main/java/hexin/androidbitmapcanary/DrawableDetectUtil.java:
--------------------------------------------------------------------------------
1 | package hexin.androidbitmapcanary;
2 |
3 |
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.ColorFilter;
8 | import android.graphics.Paint;
9 | import android.graphics.PixelFormat;
10 | import android.graphics.Rect;
11 | import android.graphics.drawable.BitmapDrawable;
12 | import android.graphics.drawable.Drawable;
13 | import android.os.Build;
14 | import android.support.annotation.NonNull;
15 | import android.support.annotation.Nullable;
16 | import android.text.TextPaint;
17 | import android.view.View;
18 | import android.view.ViewGroup;
19 | import android.view.ViewOverlay;
20 | import android.widget.ImageView;
21 |
22 | public class DrawableDetectUtil{
23 |
24 | public static float MAX_SCALE = 1.5f;
25 | public static float MAX_SCALE_2 = 2f;
26 | public static float MAX_SCALE_3 = 3f;
27 |
28 | public static void detectDrawableSize(ViewGroup rootView){
29 | if(rootView==null||rootView.getChildCount()==0){
30 | return;
31 | }
32 | detectDrawable(rootView);
33 | }
34 |
35 | public static void detectDrawable(View view){
36 | if(view==null||view.getVisibility()==View.GONE||view.getHeight()==0||view.getWidth()==0){
37 | return;
38 | }
39 | Detector detectorBackground = DetectorFactory.getDetector(DetectorFactory.DETECT_TYPE_BACKGROUND);
40 | detectorBackground.detect(view);
41 |
42 | if(view instanceof ImageView){
43 | ImageView imageView = (ImageView)view;
44 | Detector detectorImageSrc = DetectorFactory.getDetector(DetectorFactory.DETECT_TYPE_IMAGESRC);
45 | detectorImageSrc.detect(imageView);
46 | }
47 | if(view instanceof ViewGroup&&((ViewGroup) view).getChildCount()>0){
48 | ViewGroup viewGroup = (ViewGroup)view;
49 | for(int i=0;iMAX_SCALE&&scale=MAX_SCALE_2&&scale=MAX_SCALE_3){
63 | return Color.argb(140,234,34,50);
64 | }
65 | return Color.TRANSPARENT;
66 | }
67 |
68 | static public class TextDetectDrawable extends Drawable{
69 |
70 | private Paint textPaint;
71 | private String mText="";
72 | private int mBgColor = Color.TRANSPARENT;
73 |
74 | public TextDetectDrawable() {
75 | this.textPaint = new TextPaint();
76 | this.textPaint.setColor(Color.WHITE);
77 | this.textPaint.setStyle(Paint.Style.FILL);
78 | this.textPaint.setTextAlign(Paint.Align.CENTER);
79 | }
80 |
81 | public void setText(String text) {
82 | this.mText = text;
83 | }
84 |
85 | public void setBgColor(int bgColor) {
86 | this.mBgColor = bgColor;
87 | }
88 |
89 | @Override
90 | public void draw(@NonNull Canvas canvas) {
91 | Rect bounds = getBounds();
92 | int count = canvas.save();
93 | canvas.translate(bounds.left,bounds.top);
94 | int fontSize = Math.min(bounds.height(),bounds.width())/2;
95 | textPaint.setTextSize(fontSize);
96 | canvas.drawColor(mBgColor);
97 | canvas.drawText(mText,bounds.centerX(),bounds.height()/2-(textPaint.descent()+textPaint.ascent())/2,textPaint);
98 | canvas.restoreToCount(count);
99 | }
100 |
101 | @Override
102 | public void setAlpha(int i) {
103 | textPaint.setAlpha(i);
104 | }
105 |
106 | @Override
107 | public void setColorFilter(@Nullable ColorFilter colorFilter) {
108 | textPaint.setColorFilter(colorFilter);
109 | }
110 |
111 | @Override
112 | protected void onBoundsChange(Rect bounds) {
113 | super.onBoundsChange(bounds);
114 | invalidateSelf();
115 | }
116 |
117 | @Override
118 | public int getOpacity() {
119 | return PixelFormat.OPAQUE;
120 | }
121 | }
122 | }
--------------------------------------------------------------------------------
/BitmapCanary/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/BitmapCanary/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/BitmapCanary/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/BitmapCanary/androidbitmapcanary/androidbitmapcanary.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------