Commit e25988c4c1c9d464c7c8ddcd491c6bd93a1d7aca

Authored by 韩亚云
1 parent deff69ec

图片加载优化测试

app/strike/src/main/AndroidManifest.xml
... ... @@ -18,6 +18,7 @@
18 18 android:theme="@style/AppTheme">
19 19 <activity android:name=".demo.activity.DemoActivity" />
20 20 <activity android:name=".MyActivity"></activity>
  21 + <activity android:name=".imgutil.ImgActivity"/>
21 22 <activity android:name=".MainActivity">
22 23 <intent-filter>
23 24 <action android:name="android.intent.action.MAIN" />
... ...
app/strike/src/main/assets/timgs.png 0 → 100644

48.7 KB

app/strike/src/main/java/com/cnlive/strike/imgutil/ImgActivity.java
... ... @@ -3,20 +3,32 @@ package com.cnlive.strike.imgutil;
3 3 import androidx.appcompat.app.AppCompatActivity;
4 4  
5 5 import android.animation.ObjectAnimator;
  6 +import android.graphics.Bitmap;
  7 +import android.graphics.Rect;
6 8 import android.os.Bundle;
  9 +import android.os.Handler;
  10 +import android.os.Message;
  11 +import android.util.Log;
7 12 import android.view.View;
8   -import android.view.ViewPropertyAnimator;
9 13 import android.widget.ImageView;
  14 +import android.widget.Toast;
10 15  
  16 +import com.bumptech.glide.load.engine.DiskCacheStrategy;
11 17 import com.bumptech.glide.request.transition.ViewPropertyTransition;
  18 +import com.cnlive.core.imageload.callback.ImageDownLoadCallBack;
  19 +import com.cnlive.core.imageload.config.PriorityMode;
  20 +import com.cnlive.core.imageload.config.ScaleMode;
12 21 import com.cnlive.core.imageload.loader.ImageLoader;
  22 +import com.cnlive.core.imageload.util.DownLoadImageService;
13 23 import com.cnlive.strike.R;
14 24  
  25 +import java.io.File;
  26 +import java.util.ArrayList;
  27 +
15 28 public class ImgActivity extends AppCompatActivity {
16 29  
17 30 private ImageView iv_test1;
18 31 private ImageView iv_test2;
19   - private ImageView iv_test02;
20 32 private ImageView iv_test3;
21 33 private ImageView iv_test4;
22 34 private ImageView iv_test5;
... ... @@ -26,12 +38,28 @@ public class ImgActivity extends AppCompatActivity {
26 38 private ImageView iv_test9;
27 39 private ImageView iv_test10;
28 40 private ImageView iv_test11;
29   - private ImageView iv_test12;
30   - private ImageView iv_test13;
31   - private ImageView iv_test14;
32   - private ImageView iv_test15;
  41 +
  42 +
  43 + Handler handler = new Handler() {
  44 + @Override
  45 + public void handleMessage(Message msg) {
  46 + super.handleMessage(msg);
  47 + if (msg.what == 1) {
  48 + iv_test11.setImageBitmap(bitmaps);
  49 + }
  50 + }
  51 + };
  52 +
33 53  
34 54 String URL1 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574403931080&di=ea10bd1adb20025f02e296d8694f7bb4&imgtype=0&src=http%3A%2F%2Fimg3.duitang.com%2Fuploads%2Fitem%2F201506%2F23%2F20150623164841_jtvR3.thumb.700_0.jpeg";
  55 + String URL2 = "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1035013881,3985887911&fm=26&gp=0.jpg";
  56 +
  57 +
  58 + String FOREWARD_SLASH = "/";
  59 + String ASSERTS_PATH ="file:///android_asset/" ;
  60 + String ANDROID_RESOURCE ="android.resource://" ;
  61 + String RAW ="/raw/" ;
  62 + Bitmap bitmaps;
35 63  
36 64 @Override
37 65 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -45,7 +73,6 @@ public class ImgActivity extends AppCompatActivity {
45 73 private void findview() {
46 74 iv_test1 = findViewById(R.id.iv_test1);
47 75 iv_test2 = findViewById(R.id.iv_test2);
48   - iv_test02 = findViewById(R.id.iv_test02);
49 76 iv_test3 = findViewById(R.id.iv_test3);
50 77 iv_test4 = findViewById(R.id.iv_test4);
51 78 iv_test5 = findViewById(R.id.iv_test5);
... ... @@ -55,10 +82,6 @@ public class ImgActivity extends AppCompatActivity {
55 82 iv_test9 = findViewById(R.id.iv_test9);
56 83 iv_test10 = findViewById(R.id.iv_test10);
57 84 iv_test11 = findViewById(R.id.iv_test11);
58   - iv_test12 = findViewById(R.id.iv_test12);
59   - iv_test13 = findViewById(R.id.iv_test13);
60   - iv_test14 = findViewById(R.id.iv_test14);
61   - iv_test15 = findViewById(R.id.iv_test15);
62 85 }
63 86  
64 87  
... ... @@ -74,21 +97,126 @@ public class ImgActivity extends AppCompatActivity {
74 97 }
75 98 };
76 99  
  100 +
  101 +// //组织数据
  102 +// ArrayList<ThumbViewInfo> mThumbViewInfoList = new ArrayList<>(); // 这个最好定义成成员变量
  103 +// ThumbViewInfo item;
  104 +// mThumbViewInfoList.clear();
  105 +// for (int i = 0;i < resultList.size(); i++) {
  106 +// Rect bounds = new Rect();
  107 +// //new ThumbViewInfo(图片地址);
  108 +// item=new ThumbViewInfo(resultList.get(i).getOriginUrl());
  109 +// item.setBounds(bounds);
  110 +// mThumbViewInfoList.add(item);
  111 +// }
  112 +//
  113 +////打开预览界面
  114 +// GPreviewBuilder.from(Context context)
  115 +// //是否使用自定义预览界面,当然8.0之后因为配置问题,必须要使用
  116 +// .to(ImageLookActivity.class)
  117 +// .setData(mThumbViewInfoList)
  118 +// .setCurrentIndex(position)
  119 +// .setSingleFling(true)
  120 +// .setType(GPreviewBuilder.IndicatorType.Number)
  121 +// // 小圆点
  122 +//// .setType(GPreviewBuilder.IndicatorType.Dot)
  123 +// .start();//启动
  124 +
77 125 ImageLoader.with(this)
78 126 .url(URL1)
79 127 .animate(animation)
  128 + .scale(ScaleMode.CENTER_CROP)
80 129 .into(iv_test1);
81 130  
82 131 ImageLoader.with(this)
83 132 .url(URL1)
84   - .scale(1)//缩放几倍
85   - .into(iv_test02);
  133 + .scale(ScaleMode.FIT_CENTER)
  134 + .into(iv_test2);
  135 +
  136 +// Glide.with(this).asGif().diskCacheStrategy(DiskCacheStrategy.RESOURCE).load(URL2).into(iv_test3);
86 137  
87 138 ImageLoader.with(this)
88   - .url(URL1)
89   - .scale(3)
90   - .into(iv_test2);
  139 + .url(URL2)
  140 + .placeHolder(R.mipmap.ic_launcher)
  141 + .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
  142 + .scale(ScaleMode.FIT_CENTER)
  143 + .into(iv_test3);
  144 +
  145 + ImageLoader.with(this)
  146 + .res(R.mipmap.timg)
  147 + .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
  148 + .into(iv_test4);
91 149  
  150 + ImageLoader.with(this)
  151 + .res(R.mipmap.timgs)
  152 + .into(iv_test5);
  153 +
  154 + ImageLoader.with(this)
  155 + .res(R.mipmap.timgs)
  156 + .vignetteFilter()//晕映
  157 + .priority(PriorityMode.PRIORITY_NORMAL)//优先级
  158 + .into(iv_test6);
  159 +
  160 + ImageLoader.with(this)
  161 + .res(R.mipmap.timgs)
  162 + .sketchFilter()
  163 + .into(iv_test7);
  164 +
  165 + ImageLoader.with(this)
  166 + .res(R.mipmap.timgs)
  167 + .sketchFilter()
  168 + .into(iv_test7);
  169 +
  170 + //加载本地图片
  171 +// ImageLoader.with(this)
  172 +// .file(new File(getFilesDir(), IMG_NAME_C))
  173 +// .placeHolder(R.mipmap.ic_launcher)
  174 +// .scale(ScaleMode.FIT_CENTER)
  175 +// .into(iv_test7);
92 176  
  177 + ImageLoader.with(this)
  178 + .asserts(ASSERTS_PATH + "timgs.png")
  179 + .into(iv_test8);
  180 +
  181 + ImageLoader.with(this)
  182 + .raw(ANDROID_RESOURCE+getPackageName()+RAW+R.raw.timgs)
  183 + .placeHolder(R.mipmap.ic_launcher)
  184 + .scale(ScaleMode.FIT_CENTER)
  185 + .asCircle()
  186 + .into(iv_test9);
  187 +
  188 + ImageLoader.with(this)
  189 + .res(R.mipmap.timgs)
  190 + .placeHolder(R.mipmap.ic_launcher)
  191 + .scale(ScaleMode.FIT_CENTER)
  192 + .rectRoundCorner(50)
  193 + .into(iv_test10);
  194 +
  195 + // .asSquare()//正方形
  196 +
  197 + findViewById(R.id.down).setOnClickListener(view -> {
  198 + ImageLoader.saveImageIntoGallery(new DownLoadImageService(ImgActivity.this, URL1, true, "lala", new ImageDownLoadCallBack() {
  199 +
  200 + @Override
  201 + public void onDownLoadSuccess(Bitmap bitmap) {
  202 + Log.e("sssssss", "onDownLoadSuccess: " );
  203 + //网络请求
  204 + bitmaps = bitmap;
  205 + Message msg = new Message();
  206 + //将获取到的String装载到msg中
  207 + msg.what = 1;
  208 + //发消息到主线程
  209 + handler.sendMessage(msg);
  210 + }
  211 +
  212 + @Override
  213 + public void onDownLoadFailed() {
  214 +// Toast.makeText(ImgActivity.this,"下载",Toast.LENGTH_SHORT).show();
  215 + }
  216 +
  217 + }));
  218 + });
93 219 }
  220 +
  221 +
94 222 }
... ...
app/strike/src/main/res/layout/activity_img.xml
... ... @@ -23,100 +23,122 @@
23 23 android:layout_height="wrap_content"
24 24 android:text="放大缩小:"
25 25 />
26   - <LinearLayout
27   - android:layout_width="wrap_content"
28   - android:layout_height="wrap_content"
29   - android:orientation="vertical">
30   - <ImageView
31   - android:id="@+id/iv_test02"
32   - android:layout_width="300dp"
33   - android:layout_height="300dp"
34   - android:padding="10dp" />
35 26 <ImageView
36 27 android:id="@+id/iv_test2"
37   - android:layout_width="300dp"
38   - android:layout_height="300dp"
  28 + android:layout_width="200dp"
  29 + android:layout_height="200dp"
39 30 android:padding="10dp" />
40   - </LinearLayout>
  31 +
  32 + <TextView
  33 + android:layout_width="wrap_content"
  34 + android:layout_height="wrap_content"
  35 + android:text="网络gif:"
  36 + />
41 37  
42 38 <ImageView
43 39 android:id="@+id/iv_test3"
44 40 android:layout_width="300dp"
45 41 android:layout_height="300dp"
46   - android:padding="30dp" />
47   -
  42 + android:padding="10dp" />
  43 + <TextView
  44 + android:layout_width="wrap_content"
  45 + android:layout_height="wrap_content"
  46 + android:text="mipmap下的gif:"
  47 + />
48 48 <ImageView
49 49 android:id="@+id/iv_test4"
50 50 android:layout_width="300dp"
51 51 android:layout_height="300dp"
52   - android:padding="30dp" />
  52 + android:padding="10dp" />
53 53  
  54 + <TextView
  55 + android:layout_width="wrap_content"
  56 + android:layout_height="wrap_content"
  57 + android:text="mipmap下的图片:"
  58 + />
54 59 <ImageView
55 60 android:id="@+id/iv_test5"
56 61 android:layout_width="300dp"
57 62 android:layout_height="300dp"
58   - android:padding="30dp" />
  63 + android:padding="10dp" />
59 64  
  65 + <TextView
  66 + android:layout_width="wrap_content"
  67 + android:layout_height="wrap_content"
  68 + android:text="滤镜优先级设置"
  69 + />
60 70 <ImageView
61 71 android:id="@+id/iv_test6"
62 72 android:layout_width="300dp"
63 73 android:layout_height="300dp"
64 74 android:padding="30dp" />
65 75  
  76 + <TextView
  77 + android:layout_width="wrap_content"
  78 + android:layout_height="wrap_content"
  79 + android:text="素描"
  80 + />
66 81 <ImageView
67 82 android:id="@+id/iv_test7"
68 83 android:layout_width="300dp"
69 84 android:layout_height="300dp"
70 85 android:padding="30dp" />
71 86  
  87 + <TextView
  88 + android:layout_width="wrap_content"
  89 + android:layout_height="wrap_content"
  90 + android:text="加载asserts下面的图片"
  91 + />
  92 +
72 93 <ImageView
73 94 android:id="@+id/iv_test8"
74 95 android:layout_width="300dp"
75 96 android:layout_height="300dp"
76 97 android:padding="30dp" />
77 98  
  99 + <TextView
  100 + android:layout_width="wrap_content"
  101 + android:layout_height="wrap_content"
  102 + android:text="加载raw下面的图片为圆"
  103 + />
78 104 <ImageView
79 105 android:id="@+id/iv_test9"
80 106 android:layout_width="300dp"
81 107 android:layout_height="300dp"
82 108 android:padding="30dp" />
83 109  
  110 + <TextView
  111 + android:layout_width="wrap_content"
  112 + android:layout_height="wrap_content"
  113 + android:text="图片设置圆角"
  114 + />
84 115 <ImageView
85 116 android:id="@+id/iv_test10"
86 117 android:layout_width="300dp"
87 118 android:layout_height="300dp"
88 119 android:padding="30dp" />
89 120  
90   - <ImageView
91   - android:id="@+id/iv_test11"
92   - android:layout_width="300dp"
93   - android:layout_height="300dp"
94   - android:padding="30dp" />
95   -
96   - <ImageView
97   - android:id="@+id/iv_test12"
98   - android:layout_width="300dp"
99   - android:layout_height="300dp"
100   - android:padding="30dp" />
101   -
102   - <ImageView
103   - android:id="@+id/iv_test13"
104   - android:layout_width="300dp"
105   - android:layout_height="300dp"
106   - android:padding="30dp" />
107   -
108   - <ImageView
109   - android:id="@+id/iv_test14"
110   - android:layout_width="300dp"
111   - android:layout_height="300dp"
112   - android:padding="30dp" />
  121 + <TextView
  122 + android:layout_width="wrap_content"
  123 + android:layout_height="wrap_content"
  124 + android:text="图片下载显示"
  125 + />
  126 + <Button
  127 + android:id="@+id/down"
  128 + android:layout_width="wrap_content"
  129 + android:layout_height="wrap_content"
  130 + android:text="下载"/>
113 131  
114 132 <ImageView
115   - android:id="@+id/iv_test15"
  133 + android:id="@+id/iv_test11"
116 134 android:layout_width="300dp"
117 135 android:layout_height="300dp"
118 136 android:padding="30dp" />
119 137  
  138 + <TextView
  139 + android:layout_width="wrap_content"
  140 + android:layout_height="wrap_content"
  141 + android:text="直接代码设置,五边形"/>
120 142  
121 143 <com.cnlive.core.imageload.util.MultiView
122 144 android:layout_width="300dp"
... ... @@ -124,8 +146,14 @@
124 146 android:layout_margin="30dp"
125 147 lb:angleCount="5"
126 148 lb:type="multi"
  149 + android:src="@mipmap/timgs"
127 150 />
128 151  
  152 + <TextView
  153 + android:layout_width="wrap_content"
  154 + android:layout_height="wrap_content"
  155 + android:text="直接代码设置,设置圆角"/>
  156 +
129 157 <com.cnlive.core.imageload.util.MultiView
130 158 android:layout_width="200dp"
131 159 android:layout_height="200dp"
... ... @@ -133,13 +161,20 @@
133 161 android:layout_gravity="center"
134 162 lb:borderRadius="10dp"
135 163 lb:type="round"
  164 + android:src="@mipmap/timgs"
136 165 />
137 166  
  167 + <TextView
  168 + android:layout_width="wrap_content"
  169 + android:layout_height="wrap_content"
  170 + android:text="直接代码设置圆"/>
  171 +
138 172 <com.cnlive.core.imageload.util.MultiView
139 173 android:layout_margin="30dp"
140 174 android:layout_width="200dp"
141 175 android:layout_height="200dp"
142 176 android:layout_gravity="center"
  177 + android:src="@mipmap/timgs"
143 178 lb:type="circle"
144 179 />
145 180  
... ...
app/strike/src/main/res/mipmap-hdpi/timg.gif 0 → 100644

264 KB

app/strike/src/main/res/mipmap-hdpi/timgs.png 0 → 100644

48.7 KB

app/strike/src/main/res/raw/timgs.png 0 → 100644

48.7 KB

core/imageload/build.gradle
... ... @@ -37,4 +37,6 @@ dependencies {
37 37 implementation 'jp.wasabeef:glide-transformations:3.0.1'
38 38 //滤镜
39 39 implementation 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
  40 + //图片预览
  41 +// implementation 'com.ycjiang:imgepreviewlibrary:1.1.3'
40 42 }
... ...
core/imageload/src/androidTest/java/com/mm999/imageload/ExampleInstrumentedTest.java deleted 100644 → 0
1   -package com.mm999.imageload;
2   -
3   -import android.content.Context;
4   -
5   -import androidx.test.platform.app.InstrumentationRegistry;
6   -import androidx.test.ext.junit.runners.AndroidJUnit4;
7   -
8   -import org.junit.Test;
9   -import org.junit.runner.RunWith;
10   -
11   -import static org.junit.Assert.*;
12   -
13   -/**
14   - * Instrumented test, which will execute on an Android device.
15   - *
16   - * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17   - */
18   -@RunWith(AndroidJUnit4.class)
19   -public class ExampleInstrumentedTest {
20   - @Test
21   - public void useAppContext() {
22   - // Context of the app under test.
23   - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24   -
25   - assertEquals("com.mm999.imageload.test", appContext.getPackageName());
26   - }
27   -}
core/imageload/src/test/java/com/mm999/imageload/ExampleUnitTest.java deleted 100644 → 0
1   -package com.mm999.imageload;
2   -
3   -import org.junit.Test;
4   -
5   -import static org.junit.Assert.*;
6   -
7   -/**
8   - * Example local unit test, which will execute on the development machine (host).
9   - *
10   - * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11   - */
12   -public class ExampleUnitTest {
13   - @Test
14   - public void addition_isCorrect() {
15   - assertEquals(4, 2 + 2);
16   - }
17   -}
18 0 \ No newline at end of file