├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── MySimpleFresco.iml
├── README.md
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── bzh
│ │ └── mysimplefresco
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ ├── aa.jpg
│ ├── bb.jpg
│ ├── bbb_splash.png
│ └── fontawesome-webfont.ttf
│ ├── java
│ └── com
│ │ └── bzh
│ │ └── mysimplefresco
│ │ ├── FontManager.java
│ │ ├── MyApplication.java
│ │ ├── MyPhotoView.java
│ │ ├── activity
│ │ ├── BaseActivity.java
│ │ ├── MainActivity.java
│ │ └── MyPhotoViewActivity.java
│ │ ├── fragment
│ │ ├── BaseFragment.java
│ │ ├── OneFragment.java
│ │ └── TwoFragment.java
│ │ └── lib
│ │ ├── ImagePipelineConfigUtils.java
│ │ ├── LoadingProgressDrawable.java
│ │ ├── MyBasePostProcessor.java
│ │ ├── MyNinePatchDrawable.java
│ │ ├── MySimpleDraweeView.java
│ │ ├── NinePatchChunk.java
│ │ └── Utils.java
│ └── res
│ ├── layout
│ ├── activity_main.xml
│ ├── bzh_ui_one_fragment.xml
│ ├── bzh_ui_two_fragment.xml
│ ├── menu_header.xml
│ ├── photoview_activity.xml
│ └── zoomabledraweeeview_activity.xml
│ ├── menu
│ ├── drawer_menu.xml
│ └── menu_main.xml
│ ├── mipmap-hdpi
│ ├── ic_arrow_back_white_24dp.png
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ ├── ic_arrow_back_white_24dp.png
│ ├── ic_global_menu_direct.png
│ ├── ic_global_menu_feed.png
│ ├── ic_global_menu_likes.png
│ ├── ic_global_menu_nearby.png
│ ├── ic_global_menu_news.png
│ ├── ic_global_menu_popular.png
│ ├── ic_global_menu_search.png
│ ├── ic_launcher.png
│ ├── identify_gif.9.png
│ ├── identify_long.9.png
│ ├── identify_number.9.png
│ ├── load_progress_0.png
│ ├── load_progress_1.png
│ ├── load_progress_10.png
│ ├── load_progress_11.png
│ ├── load_progress_12.png
│ ├── load_progress_2.png
│ ├── load_progress_3.png
│ ├── load_progress_4.png
│ ├── load_progress_5.png
│ ├── load_progress_6.png
│ ├── load_progress_7.png
│ ├── load_progress_8.png
│ ├── load_progress_9.png
│ └── round_default_icon.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-v21
│ └── styles.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── color.xml
│ ├── dimens.xml
│ ├── icons.xml
│ ├── ids.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── resource
├── 1.gif
├── 2.gif
└── 3.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | MySimpleDraweeView
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
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 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/MySimpleFresco.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # deprecated
2 |
3 | # 请注意
4 |
5 | 这个向东西是我在项目初期,随意写的。并没有持续完善。
6 |
7 | # 小技巧
8 |
9 | 1. SimpleDraweeView的简易封装,显示图片只需要一句话。
10 |
11 | 2. 根据宽高比例来确定图片控件大小
12 |
13 | 2. 9Path图+Overly实现标识符效果。
14 |
15 | 3. Fresco默认没有对GIF图进行处理。如何解决,大量GIF会导致OOM的问题。
16 |
17 | 4. 结合列表使用时,重复设置图片加载导致闪烁的问题(通过设置TAG解决)。
18 |
19 | 5. 使用后处理器对下载完成后的图片进行处理-截取/缩放。
20 |
21 | 6. Fresco结合PhotoView使用,并可以使用SimpleDraweeView加载进度属性。
22 |
23 | **PhotoView结合**
24 |
25 | 
26 |
27 | **加载进度**
28 |
29 | 
30 |
31 |
32 | **延迟加载**
33 | 
34 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
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 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.bzh.mysimplefresco"
9 | minSdkVersion 19
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:design:23.1.1'
25 | compile 'com.android.support:appcompat-v7:23.1.1'
26 | compile 'com.android.support:cardview-v7:23.1.1'
27 | compile 'com.android.support:recyclerview-v7:23.1.1'
28 | compile 'com.android.support:support-v4:23.1.1'
29 |
30 | compile 'com.commit451:PhotoView:1.2.4'
31 | compile 'com.facebook.fresco:fresco:0.8.1'
32 | compile 'com.jakewharton:butterknife:7.0.1'
33 | }
34 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/biezhihua/android-sdk-linux/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/bzh/mysimplefresco/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/assets/aa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/assets/aa.jpg
--------------------------------------------------------------------------------
/app/src/main/assets/bb.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/assets/bb.jpg
--------------------------------------------------------------------------------
/app/src/main/assets/bbb_splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/assets/bbb_splash.png
--------------------------------------------------------------------------------
/app/src/main/assets/fontawesome-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/assets/fontawesome-webfont.ttf
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/FontManager.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco;
2 |
3 | import android.content.Context;
4 | import android.graphics.Typeface;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | /**
10 | * ==========================================================
11 | * 版权: 别志华 版权所有(c) 2015
12 | * 作者: 别志华 biezhihua@163.com
13 | * 创建日期: 15-9-26
14 | * 描述:
15 | * 版本: V1.0
16 | * 修订历史:
17 | * ==========================================================
18 | */
19 | public class FontManager {
20 |
21 | public static final String ROOT = "fonts/";
22 | public static final String FONTAWESOME = ROOT + "fontawesome-webfont.ttf";
23 |
24 | public static Typeface getTypeface(Context context, String font) {
25 | return Typeface.createFromAsset(context.getAssets(), font);
26 | }
27 |
28 | public static void markAsIconContainer(View v, Typeface typeface) {
29 | if (v instanceof ViewGroup) {
30 | ViewGroup vg = (ViewGroup) v;
31 | for (int i = 0; i < vg.getChildCount(); i++) {
32 | View child = vg.getChildAt(i);
33 | markAsIconContainer(child, typeface);
34 | }
35 | } else if (v instanceof TextView) {
36 | ((TextView) v).setTypeface(typeface);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco;
2 |
3 | import android.app.Application;
4 |
5 | import com.bzh.mysimplefresco.lib.ImagePipelineConfigUtils;
6 | import com.facebook.drawee.backends.pipeline.Fresco;
7 |
8 | /**
9 | * ==========================================================
10 | * 版权: 别志华 版权所有(c) 2015
11 | * 作者: 别志华 biezhihua@163.com
12 | * 创建日期: 15-9-26
13 | * 描述:
14 | * 版本: V1.0
15 | * 修订历史:
16 | * ==========================================================
17 | */
18 | public class MyApplication extends Application {
19 |
20 | @Override
21 | public void onCreate() {
22 | super.onCreate();
23 | Fresco.initialize(this, ImagePipelineConfigUtils.getDefaultImagePipelineConfig(this));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/MyPhotoView.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.drawable.Animatable;
6 | import android.graphics.drawable.Drawable;
7 | import android.net.Uri;
8 | import android.util.AttributeSet;
9 | import android.view.MotionEvent;
10 |
11 | import com.bzh.mysimplefresco.lib.LoadingProgressDrawable;
12 | import com.facebook.common.references.CloseableReference;
13 | import com.facebook.datasource.DataSource;
14 | import com.facebook.drawee.backends.pipeline.Fresco;
15 | import com.facebook.drawee.controller.AbstractDraweeController;
16 | import com.facebook.drawee.controller.BaseControllerListener;
17 | import com.facebook.drawee.generic.GenericDraweeHierarchy;
18 | import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
19 | import com.facebook.drawee.view.DraweeHolder;
20 | import com.facebook.imagepipeline.common.ResizeOptions;
21 | import com.facebook.imagepipeline.core.ImagePipeline;
22 | import com.facebook.imagepipeline.image.CloseableImage;
23 | import com.facebook.imagepipeline.image.CloseableStaticBitmap;
24 | import com.facebook.imagepipeline.image.ImageInfo;
25 | import com.facebook.imagepipeline.request.ImageRequest;
26 | import com.facebook.imagepipeline.request.ImageRequestBuilder;
27 |
28 | import uk.co.senab.photoview.PhotoView;
29 |
30 | /**
31 | * ==========================================================
32 | * 版权: 别志华 版权所有(c) 2015
33 | * 作者: 别志华 biezhihua@163.com
34 | * 创建日期: 2015/11/16 17:19
35 | * 描述:
36 | * 版本: V1.0
37 | * 修订历史:
38 | * 自定义的View,我们就要处理好下面这几个函数,
39 | * 这样才能保证引用计数的正确性,否则可能就会引起内存泄露。
40 | * 其实就是要在View移除屏幕或进入屏幕去维护好引用计数了。
41 | * onAttachedToWindow()
42 | * onDetacherFromWindow()
43 | * onStartTemporaryDetach()
44 | * onFinishTemporaryDetach()
45 | * onTouchEvent()
46 | * ==========================================================
47 | */
48 | public class MyPhotoView extends PhotoView {
49 |
50 | private DraweeHolder mDraweeHolder;
51 |
52 | public MyPhotoView(Context context) {
53 | this(context, null);
54 | }
55 |
56 | public MyPhotoView(Context context, AttributeSet attr) {
57 | this(context, attr, 0);
58 | }
59 |
60 | public MyPhotoView(Context context, AttributeSet attr, int defStyle) {
61 | super(context, attr, defStyle);
62 | selfInit();
63 | }
64 |
65 | private void selfInit() {
66 | if (mDraweeHolder == null) {
67 | final GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources())
68 | .setProgressBarImage(new LoadingProgressDrawable(getContext())).build();
69 |
70 | mDraweeHolder = DraweeHolder.create(hierarchy, getContext());
71 | }
72 | }
73 |
74 | @Override
75 | protected void onDetachedFromWindow() {
76 | super.onDetachedFromWindow();
77 | mDraweeHolder.onDetach();
78 | }
79 |
80 | @Override
81 | protected void onAttachedToWindow() {
82 | super.onAttachedToWindow();
83 | mDraweeHolder.onAttach();
84 | }
85 |
86 | @Override
87 | protected boolean verifyDrawable(Drawable dr) {
88 | super.verifyDrawable(dr);
89 | return dr == mDraweeHolder.getHierarchy().getTopLevelDrawable();
90 | }
91 |
92 | @Override
93 | public void onStartTemporaryDetach() {
94 | super.onStartTemporaryDetach();
95 | mDraweeHolder.onDetach();
96 | }
97 |
98 | @Override
99 | public void onFinishTemporaryDetach() {
100 | super.onFinishTemporaryDetach();
101 | mDraweeHolder.onAttach();
102 | }
103 |
104 | @Override
105 | public boolean onTouchEvent(MotionEvent event) {
106 | return mDraweeHolder.onTouchEvent(event) || super.onTouchEvent(event);
107 | }
108 |
109 | public void setImageUri(String uri, ResizeOptions options) {
110 |
111 | final ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri))
112 | .setResizeOptions(options)
113 | .setAutoRotateEnabled(true)
114 | .build();
115 | final ImagePipeline imagePipeline = Fresco.getImagePipeline();
116 | final DataSource> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
117 | final AbstractDraweeController controller = Fresco.newDraweeControllerBuilder()
118 | .setOldController(mDraweeHolder.getController())
119 | .setImageRequest(imageRequest)
120 | .setControllerListener(new BaseControllerListener() {
121 | @Override
122 | public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
123 | super.onFinalImageSet(id, imageInfo, animatable);
124 |
125 | CloseableReference imageCloseableReference = null;
126 | try {
127 | imageCloseableReference = dataSource.getResult();
128 | if (imageCloseableReference != null) {
129 | final CloseableImage image = imageCloseableReference.get();
130 | if (image != null && image instanceof CloseableStaticBitmap) {
131 | CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image;
132 | final Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap();
133 | if (bitmap != null) {
134 | setImageBitmap(bitmap);
135 | setScaleType(ScaleType.CENTER_CROP);
136 | }
137 | }
138 | }
139 | } finally {
140 | dataSource.close();
141 | CloseableReference.closeSafely(imageCloseableReference);
142 | }
143 | }
144 | })
145 | .build();
146 | mDraweeHolder.setController(controller);
147 | setImageDrawable(mDraweeHolder.getTopLevelDrawable());
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | import com.bzh.mysimplefresco.fragment.BaseFragment;
7 |
8 | import java.lang.ref.WeakReference;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | /**
13 | * ==========================================================
14 | * 版权: 别志华 版权所有(c) 2015
15 | * 作者: 别志华 biezhihua@163.com
16 | * 创建日期: 15-9-26
17 | * 描述:
18 | * 版本: V1.0
19 | * 修订历史:
20 | * ==========================================================
21 | */
22 | public class BaseActivity extends AppCompatActivity {
23 | private Map> fragmentRefs;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 |
29 | fragmentRefs = new HashMap>();
30 | }
31 |
32 |
33 | public void addFragment(String tag, BaseFragment fragment) {
34 | fragmentRefs.put(tag, new WeakReference(fragment));
35 | }
36 |
37 | public void removeFragment(String tag) {
38 | fragmentRefs.remove(tag);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.activity;
2 |
3 | import android.os.Build;
4 | import android.os.Bundle;
5 | import android.support.design.widget.NavigationView;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.widget.DrawerLayout;
8 | import android.view.Gravity;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 | import android.widget.LinearLayout;
12 |
13 | import com.bzh.mysimplefresco.R;
14 | import com.bzh.mysimplefresco.fragment.OneFragment;
15 | import com.bzh.mysimplefresco.fragment.TwoFragment;
16 | import com.bzh.mysimplefresco.lib.MySimpleDraweeView;
17 |
18 | import butterknife.Bind;
19 | import butterknife.ButterKnife;
20 |
21 | public class MainActivity extends BaseActivity {
22 |
23 |
24 | @Bind(R.id.navigationView)
25 | NavigationView navigationView;
26 | @Bind(R.id.drawer)
27 | DrawerLayout drawer;
28 |
29 | MySimpleDraweeView ivMenuUserProfilePhoto;
30 | LinearLayout vGlobalMenuHeader;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_main);
36 | ButterKnife.bind(this);
37 | final View headerView = navigationView.getHeaderView(0);
38 | ivMenuUserProfilePhoto = (MySimpleDraweeView) headerView.findViewById(R.id.ivMenuUserProfilePhoto);
39 | vGlobalMenuHeader = (LinearLayout) headerView.findViewById(R.id.vGlobalMenuHeader);
40 |
41 | if (savedInstanceState == null) {
42 | getSupportFragmentManager()
43 | .beginTransaction()
44 | .add(R.id.layContentRoot, OneFragment.newInstance(), OneFragment.class.getSimpleName())
45 | .commit();
46 | }
47 |
48 | initMenuHeader();
49 |
50 | initNavigationView();
51 | }
52 |
53 | private void initNavigationView() {
54 | navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
55 | @Override
56 | public boolean onNavigationItemSelected(MenuItem menuItem) {
57 |
58 | switch (menuItem.getItemId()) {
59 | case R.id.menu_1:
60 | Fragment oneFragment = getSupportFragmentManager().findFragmentByTag(OneFragment.class.getSimpleName());
61 | if (oneFragment == null) {
62 | oneFragment = OneFragment.newInstance();
63 | }
64 | getSupportFragmentManager()
65 | .beginTransaction()
66 | .replace(R.id.layContentRoot, oneFragment, OneFragment.class.getSimpleName())
67 | .commit();
68 | break;
69 | case R.id.menu_2:
70 | Fragment twoFragment = getSupportFragmentManager().findFragmentByTag(TwoFragment.class.getSimpleName());
71 | if (twoFragment == null) {
72 | twoFragment = TwoFragment.newInstance();
73 | }
74 | getSupportFragmentManager()
75 | .beginTransaction()
76 | .replace(R.id.layContentRoot, twoFragment, TwoFragment.class.getSimpleName())
77 | .commit();
78 | break;
79 | }
80 | drawer.closeDrawer(Gravity.LEFT);
81 | return false;
82 | }
83 | });
84 | }
85 |
86 | private void initMenuHeader() {
87 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
88 | vGlobalMenuHeader.setPadding(vGlobalMenuHeader.getPaddingLeft(),
89 | vGlobalMenuHeader.getPaddingTop() + this.getResources().getDimensionPixelSize(R.dimen.status_bar_height),
90 | vGlobalMenuHeader.getPaddingRight(),
91 | vGlobalMenuHeader.getPaddingBottom());
92 | }
93 | ivMenuUserProfilePhoto.setRoundDraweeViewUrl("http://git.oschina.net/biezhihua/MyResource/raw/master/biezhihua.png");
94 | }
95 |
96 |
97 | @Override
98 | protected void onDestroy() {
99 | super.onDestroy();
100 | ButterKnife.unbind(this);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/activity/MyPhotoViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.activity;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import com.bzh.mysimplefresco.MyPhotoView;
9 | import com.bzh.mysimplefresco.R;
10 | import com.facebook.imagepipeline.common.ResizeOptions;
11 |
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 |
15 | import butterknife.Bind;
16 | import butterknife.ButterKnife;
17 |
18 | /**
19 | * ==========================================================
20 | * 版权: 音悦台 版权所有(c) 2015
21 | * 作者: 别志华 biezhihua@163.com
22 | * 创建日期: 2015/11/16 17:39
23 | * 描述:
24 | * 版本: V1.0
25 | * 修订历史:
26 | * ==========================================================
27 | */
28 | public class MyPhotoViewActivity extends BaseActivity {
29 |
30 | @Bind(R.id.myPhotoView)
31 | MyPhotoView myPhotoView;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.photoview_activity);
37 | ButterKnife.bind(this);
38 |
39 | final int widthPixels = getResources().getDisplayMetrics().widthPixels;
40 | final int heightPixels = getResources().getDisplayMetrics().heightPixels;
41 |
42 | try {
43 | InputStream open = getAssets().open("aa.jpg");
44 | Bitmap bitmap = BitmapFactory.decodeStream(open);
45 | // myPhotoView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
46 | myPhotoView.setImageBitmap(bitmap);
47 | myPhotoView.setImageUri("http://img5.duitang.com/uploads/item/201511/04/20151104214718_FfnST.jpeg"
48 | , null);
49 | } catch (IOException e) {
50 | e.printStackTrace();
51 | }
52 |
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/fragment/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.fragment;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import com.bzh.mysimplefresco.activity.BaseActivity;
13 |
14 | import java.nio.charset.IllegalCharsetNameException;
15 |
16 | /**
17 | * ==========================================================
18 | * 版权: 别志华 版权所有(c) 2015
19 | * 作者: 别志华 biezhihua@163.com
20 | * 创建日期: 15-9-26
21 | * 描述:
22 | * 版本: V1.0
23 | * 修订历史:
24 | * ==========================================================
25 | */
26 | public abstract class BaseFragment extends Fragment {
27 |
28 | private ViewGroup rootView;
29 |
30 | @Override
31 | public void onAttach(Context context) {
32 | super.onAttach(context);
33 |
34 | if (context instanceof Activity && context instanceof BaseActivity) {
35 | ((BaseActivity) context).addFragment(toString(), this);
36 | }
37 |
38 | }
39 |
40 | @Override
41 | public void onDetach() {
42 | super.onDetach();
43 | if (getActivity() != null && getActivity() instanceof BaseActivity) {
44 | ((BaseActivity) getActivity()).removeFragment(this.toString());
45 | }
46 | }
47 |
48 | @Nullable
49 | @Override
50 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
51 |
52 | if (inflateContentView() > 0) {
53 | rootView = (ViewGroup) inflater.inflate(inflateContentView(), null);
54 | rootView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
55 |
56 | _layoutInit(inflater, savedInstanceState);
57 |
58 | layoutInit(inflater, savedInstanceState);
59 |
60 | return rootView;
61 | }
62 | return super.onCreateView(inflater, container, savedInstanceState);
63 | }
64 |
65 |
66 | protected void _layoutInit(LayoutInflater inflater, Bundle savedInstanceState) {
67 | }
68 |
69 | protected void layoutInit(LayoutInflater inflater, Bundle savedInstanceState) {
70 | }
71 |
72 | @Override
73 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
74 | super.onActivityCreated(savedInstanceState);
75 | if (savedInstanceState == null) {
76 | requestData();
77 | }
78 | }
79 |
80 | public void requestData() {
81 |
82 | }
83 |
84 | public abstract int inflateContentView();
85 |
86 | public ViewGroup getRootView() {
87 | return rootView;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/fragment/OneFragment.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.design.widget.CollapsingToolbarLayout;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import com.bzh.mysimplefresco.R;
13 | import com.bzh.mysimplefresco.activity.BaseActivity;
14 | import com.bzh.mysimplefresco.lib.MySimpleDraweeView;
15 | import com.bzh.mysimplefresco.lib.Utils;
16 |
17 | import butterknife.Bind;
18 | import butterknife.ButterKnife;
19 |
20 | /**
21 | * ==========================================================
22 | * 版权: 别志华 版权所有(c) 2015
23 | * 作者: 别志华 biezhihua@163.com
24 | * 创建日期: 15-9-26
25 | * 描述:
26 | * 版本: V1.0
27 | * 修订历史:
28 | * ==========================================================
29 | */
30 | public class OneFragment extends BaseFragment {
31 |
32 | @Bind(R.id.toolbar)
33 | Toolbar toolbar;
34 |
35 | @Bind(R.id.collapsing_toolbar_layout)
36 | CollapsingToolbarLayout collapsingToolbarLayout;
37 |
38 | @Bind(R.id.theme_photo)
39 | MySimpleDraweeView themePhoto;
40 |
41 | @Bind(R.id.photo_1)
42 | MySimpleDraweeView photo_1;
43 |
44 | @Bind(R.id.photo_2)
45 | MySimpleDraweeView photo_2;
46 |
47 | @Bind(R.id.photo_3)
48 | MySimpleDraweeView photo_3;
49 |
50 | public static OneFragment newInstance() {
51 | OneFragment fragment = new OneFragment();
52 | Bundle bundle = new Bundle();
53 | fragment.setArguments(bundle);
54 | return fragment;
55 | }
56 |
57 | @Override
58 | public int inflateContentView() {
59 | return R.layout.bzh_ui_one_fragment;
60 | }
61 |
62 | @Override
63 | public void layoutInit(LayoutInflater inflater, Bundle savedInstanceState) {
64 | super.layoutInit(inflater, savedInstanceState);
65 | ButterKnife.bind(this, getRootView());
66 |
67 | initToolbar();
68 |
69 | photo_1.setWidthAndHeight(1024, 768);
70 | photo_1.setAutoPlayAnimations(true);
71 | photo_1.setGifChartIdentify(true);
72 | photo_1.setDraweeViewUrl("http://git.oschina.net/biezhihua/MyResource/raw/master/25-173250_974.gif");
73 |
74 | photo_2.setWidthAndHeight(1024, 768);
75 | photo_2.setLongChartIdentify(true);
76 | photo_2.setDraweeViewUrl("http://git.oschina.net/biezhihua/MyResource/raw/master/3_1024x768.jpg");
77 |
78 | photo_3.setWidthAndHeight(1024, 768);
79 | photo_3.setNumberChartIdentify(99);
80 | photo_3.setDraweeViewUrl("http://git.oschina.net/biezhihua/MyResource/raw/master/3_1024x768.jpg");
81 | }
82 |
83 | private void initToolbar() {
84 | if (getActivity() != null) {
85 | themePhoto.setWidthAndHeight(Utils.getScreenWidth(getActivity()), getActivity().getResources().getDimensionPixelSize(R.dimen.theme_photo_height));
86 | }
87 | themePhoto.setDraweeViewUrl("http://git.oschina.net/biezhihua/MyResource/raw/master/3_1024x768.jpg");
88 |
89 | if (toolbar != null && getActivity() != null && getActivity() instanceof BaseActivity) {
90 | final BaseActivity activity = (BaseActivity) getActivity();
91 | activity.setSupportActionBar(toolbar);
92 | activity.getSupportActionBar().setDisplayShowHomeEnabled(false);
93 | activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
94 | toolbar.setNavigationIcon(R.mipmap.ic_arrow_back_white_24dp);
95 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
96 | @Override
97 | public void onClick(View v) {
98 | activity.finish();
99 | }
100 | });
101 | collapsingToolbarLayout.setTitle("一句话搞定图片显示");
102 | collapsingToolbarLayout.setExpandedTitleColor(Color.WHITE);//设置还没收缩时状态下字体颜色
103 | collapsingToolbarLayout.setCollapsedTitleTextColor(Color.WHITE);//设置收缩后Toolbar上字体的颜色
104 | }
105 | }
106 |
107 | @Override
108 | public void onDestroyView() {
109 | super.onDestroyView();
110 | ButterKnife.unbind(getRootView());
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/fragment/TwoFragment.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.fragment;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.design.widget.FloatingActionButton;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 |
11 | import com.bzh.mysimplefresco.R;
12 | import com.bzh.mysimplefresco.activity.BaseActivity;
13 | import com.bzh.mysimplefresco.activity.MyPhotoViewActivity;
14 | import com.facebook.drawee.view.SimpleDraweeView;
15 |
16 | import butterknife.Bind;
17 | import butterknife.ButterKnife;
18 | import butterknife.OnClick;
19 |
20 | /**
21 | * ==========================================================
22 | * 版权: 别志华 版权所有(c) 2015
23 | * 作者: 别志华 biezhihua@163.com
24 | * 创建日期: 15-9-26
25 | * 描述:
26 | * 版本: V1.0
27 | * 修订历史:
28 | * ==========================================================
29 | */
30 | public class TwoFragment extends BaseFragment {
31 |
32 | @Bind(R.id.toolbar)
33 | Toolbar toolbar;
34 | @Bind(R.id.fab)
35 | FloatingActionButton fab;
36 | @Bind(R.id.draweeView)
37 | SimpleDraweeView draweeView;
38 |
39 | public static TwoFragment newInstance() {
40 | TwoFragment fragment = new TwoFragment();
41 | Bundle bundle = new Bundle();
42 | fragment.setArguments(bundle);
43 | return fragment;
44 | }
45 |
46 | @Override
47 | public int inflateContentView() {
48 | return R.layout.bzh_ui_two_fragment;
49 | }
50 |
51 | @Override
52 | public void layoutInit(LayoutInflater inflater, Bundle savedInstanceState) {
53 | super.layoutInit(inflater, savedInstanceState);
54 | ButterKnife.bind(this, getRootView());
55 | initToolbar();
56 |
57 | if (savedInstanceState == null) {
58 | draweeView.setAspectRatio(1F);
59 | draweeView.setImageURI(Uri.parse("http://img5.duitang.com/uploads/item/201511/04/20151104214718_FfnST.jpeg"));
60 | }
61 | }
62 |
63 | @OnClick(R.id.draweeView)
64 | public void onClickDraweeView(View view) {
65 | startActivity(new Intent(getContext(), MyPhotoViewActivity.class));
66 | }
67 |
68 | private void initToolbar() {
69 | if (toolbar != null && getActivity() != null && getActivity() instanceof BaseActivity) {
70 | final BaseActivity activity = (BaseActivity) getActivity();
71 | activity.setSupportActionBar(toolbar);
72 | activity.getSupportActionBar().setDisplayShowHomeEnabled(false);
73 | activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
74 | toolbar.setTitle("测试Fresco的aspect");
75 | toolbar.setNavigationIcon(R.mipmap.ic_arrow_back_white_24dp);
76 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View v) {
79 | activity.finish();
80 | }
81 | });
82 | }
83 | }
84 |
85 | @Override
86 | public void onDestroyView() {
87 | super.onDestroyView();
88 | ButterKnife.unbind(getRootView());
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/lib/ImagePipelineConfigUtils.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.lib;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.os.Environment;
6 |
7 | import com.facebook.cache.disk.DiskCacheConfig;
8 | import com.facebook.common.disk.NoOpDiskTrimmableRegistry;
9 | import com.facebook.common.internal.Supplier;
10 | import com.facebook.common.memory.MemoryTrimType;
11 | import com.facebook.common.memory.MemoryTrimmable;
12 | import com.facebook.common.memory.NoOpMemoryTrimmableRegistry;
13 | import com.facebook.common.util.ByteConstants;
14 | import com.facebook.imagepipeline.cache.MemoryCacheParams;
15 | import com.facebook.imagepipeline.core.ImagePipelineConfig;
16 | import com.facebook.imagepipeline.core.ImagePipelineFactory;
17 |
18 | /**
19 | * ==========================================================
20 | * 版权: 别志华 版权所有(c) 2015
21 | * 作者: 别志华 biezhihua@163.com
22 | * 创建日期: 15-9-23
23 | * 描述:
24 | * 版本: V1.0
25 | * 修订历史:
26 | * ==========================================================
27 | */
28 | public class ImagePipelineConfigUtils {
29 |
30 | //分配的可用内存
31 | private static final int MAX_HEAP_SIZE = (int) Runtime.getRuntime().maxMemory();
32 |
33 | //使用的缓存数量
34 | private static final int MAX_MEMORY_CACHE_SIZE = MAX_HEAP_SIZE / 4;
35 |
36 | //小图极低磁盘空间缓存的最大值(特性:可将大量的小图放到额外放在另一个磁盘空间防止大图占用磁盘空间而删除了大量的小图)
37 | private static final int MAX_SMALL_DISK_VERYLOW_CACHE_SIZE = 20 * ByteConstants.MB;
38 |
39 | //小图低磁盘空间缓存的最大值(特性:可将大量的小图放到额外放在另一个磁盘空间防止大图占用磁盘空间而删除了大量的小图)
40 | private static final int MAX_SMALL_DISK_LOW_CACHE_SIZE = 60 * ByteConstants.MB;
41 |
42 | //默认图极低磁盘空间缓存的最大值
43 | private static final int MAX_DISK_CACHE_VERYLOW_SIZE = 20 * ByteConstants.MB;
44 |
45 | //默认图低磁盘空间缓存的最大值
46 | private static final int MAX_DISK_CACHE_LOW_SIZE = 60 * ByteConstants.MB;
47 |
48 | //默认图磁盘缓存的最大值
49 | private static final int MAX_DISK_CACHE_SIZE = 100 * ByteConstants.MB;
50 |
51 | //小图所放路径的文件夹名
52 | private static final String IMAGE_PIPELINE_SMALL_CACHE_DIR = "ImagePipelineCacheSmall";
53 |
54 | //默认图所放路径的文件夹名
55 | private static final String IMAGE_PIPELINE_CACHE_DIR = "ImagePipelineCacheDefault";
56 |
57 | public static ImagePipelineConfig getDefaultImagePipelineConfig(Context context) {
58 |
59 | //内存配置
60 | final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
61 | MAX_MEMORY_CACHE_SIZE,// 内存缓存中总图片的最大大小,以字节为单位。
62 | Integer.MAX_VALUE,// 内存缓存中图片的最大数量。
63 | MAX_MEMORY_CACHE_SIZE,// 内存缓存中准备清除但尚未被删除的总图片的最大大小,以字节为单位。
64 | Integer.MAX_VALUE,// 内存缓存中准备清除的总图片的最大数量。
65 | Integer.MAX_VALUE);// 内存缓存中单个图片的最大大小。
66 |
67 | //修改内存图片缓存数量,空间策略(这个方式有点恶心)
68 | Supplier mSupplierMemoryCacheParams = new Supplier() {
69 | @Override
70 | public MemoryCacheParams get() {
71 | return bitmapCacheParams;
72 | }
73 | };
74 |
75 | //小图片的磁盘配置
76 | DiskCacheConfig diskSmallCacheConfig = DiskCacheConfig.newBuilder().setBaseDirectoryPath(context.getApplicationContext().getCacheDir())//缓存图片基路径
77 | .setBaseDirectoryName(IMAGE_PIPELINE_SMALL_CACHE_DIR)//文件夹名
78 | .setMaxCacheSize(MAX_DISK_CACHE_SIZE)//默认缓存的最大大小。
79 | .setMaxCacheSizeOnLowDiskSpace(MAX_SMALL_DISK_LOW_CACHE_SIZE)//缓存的最大大小,使用设备时低磁盘空间。
80 | .setMaxCacheSizeOnVeryLowDiskSpace(MAX_SMALL_DISK_VERYLOW_CACHE_SIZE)//缓存的最大大小,当设备极低磁盘空间
81 | .setDiskTrimmableRegistry(NoOpDiskTrimmableRegistry.getInstance())
82 | .build();
83 |
84 | //默认图片的磁盘配置
85 | DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder().setBaseDirectoryPath(Environment.getExternalStorageDirectory().getAbsoluteFile())//缓存图片基路径
86 | .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)//文件夹名
87 | .setMaxCacheSize(MAX_DISK_CACHE_SIZE)//默认缓存的最大大小。
88 | .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)//缓存的最大大小,使用设备时低磁盘空间。
89 | .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)//缓存的最大大小,当设备极低磁盘空间
90 | .setDiskTrimmableRegistry(NoOpDiskTrimmableRegistry.getInstance())
91 | .build();
92 |
93 | //缓存图片配置
94 | ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context)
95 | .setBitmapsConfig(Bitmap.Config.RGB_565)
96 | .setBitmapMemoryCacheParamsSupplier(mSupplierMemoryCacheParams)
97 | .setSmallImageDiskCacheConfig(diskSmallCacheConfig)
98 | .setMainDiskCacheConfig(diskCacheConfig)
99 | .setMemoryTrimmableRegistry(NoOpMemoryTrimmableRegistry.getInstance())
100 | .setResizeAndRotateEnabledForNetwork(true);
101 |
102 | NoOpMemoryTrimmableRegistry.getInstance().registerMemoryTrimmable(new MemoryTrimmable() {
103 | @Override
104 | public void trim(MemoryTrimType trimType) {
105 | final double suggestedTrimRatio = trimType.getSuggestedTrimRatio();
106 |
107 | if (MemoryTrimType.OnCloseToDalvikHeapLimit.getSuggestedTrimRatio() == suggestedTrimRatio
108 | || MemoryTrimType.OnSystemLowMemoryWhileAppInBackground.getSuggestedTrimRatio() == suggestedTrimRatio
109 | || MemoryTrimType.OnSystemLowMemoryWhileAppInForeground.getSuggestedTrimRatio() == suggestedTrimRatio
110 | ) {
111 | ImagePipelineFactory.getInstance().getImagePipeline().clearMemoryCaches();
112 | }
113 | }
114 | });
115 |
116 | return configBuilder.build();
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/lib/LoadingProgressDrawable.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.lib;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.ColorFilter;
9 | import android.graphics.Paint;
10 | import android.graphics.drawable.Drawable;
11 | import android.util.Log;
12 |
13 | import com.bzh.mysimplefresco.R;
14 |
15 |
16 | /**
17 | * ==========================================================
18 | * 版权: 别志华 版权所有(c) 2015
19 | * 作者: 别志华 biezhihua@163.com
20 | * 创建日期: 15-9-17
21 | * 描述: 加载进度
22 | * 版本: V1.0
23 | * 修订历史:
24 | * ==========================================================
25 | */
26 | public class LoadingProgressDrawable extends Drawable {
27 |
28 | private static final String TAG = "LoadingProgressDrawable";
29 | private static int[] Loadings = {
30 | R.mipmap.load_progress_1,
31 | R.mipmap.load_progress_3,
32 | R.mipmap.load_progress_4,
33 | R.mipmap.load_progress_6,
34 | R.mipmap.load_progress_7,
35 | R.mipmap.load_progress_8,
36 | R.mipmap.load_progress_9,
37 | R.mipmap.load_progress_10,
38 | R.mipmap.load_progress_11,
39 | R.mipmap.load_progress_12
40 | };
41 | private Paint mPaint;
42 | private int mLevel;
43 | private Context context;
44 |
45 | public LoadingProgressDrawable(Context context) {
46 | this.context = context;
47 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
48 | }
49 |
50 | BitmapFactory.Options options = new BitmapFactory.Options();
51 |
52 | @Override
53 | public void draw(Canvas canvas) {
54 | Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), Loadings[getIndex()], options);
55 |
56 | int left = getBounds().right / 2 - options.outWidth / 2;
57 | int top = getBounds().bottom / 2 - options.outHeight / 2;
58 |
59 | canvas.drawBitmap(bitmap, left, top, mPaint);
60 | }
61 |
62 | private int getIndex() {
63 | int index = mLevel / 1000;
64 | if (index < 0) {
65 | index = 0;
66 | } else if (index >= Loadings.length) {
67 | index = Loadings.length - 1;
68 | }
69 | return index;
70 | }
71 |
72 | @Override
73 | public void setAlpha(int alpha) {
74 | mPaint.setAlpha(alpha);
75 | }
76 |
77 | @Override
78 | public void setColorFilter(ColorFilter cf) {
79 | mPaint.setColorFilter(cf);
80 | }
81 |
82 | @Override
83 | public int getOpacity() {
84 | return Color.TRANSPARENT;
85 | }
86 |
87 | @Override
88 | protected boolean onLevelChange(int level) {
89 | this.mLevel = level;
90 | this.invalidateSelf();
91 | return true;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/lib/MyBasePostProcessor.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.lib;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapRegionDecoder;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.PorterDuff;
8 | import android.graphics.Rect;
9 |
10 | import com.facebook.common.references.CloseableReference;
11 | import com.facebook.imageformat.ImageFormat;
12 | import com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory;
13 | import com.facebook.imagepipeline.request.BasePostprocessor;
14 |
15 | import java.io.ByteArrayOutputStream;
16 | import java.io.IOException;
17 |
18 | /**
19 | * ==========================================================
20 | * 版权: 别志华 版权所有(c) 2015
21 | * 作者: 别志华 biezhihua@163.com
22 | * 创建日期: 15-9-23
23 | * 描述: 用于处理图片的类,在图片尚未传给process之前处理
24 | * 版本: V1.0
25 | * 修订历史:
26 | * ==========================================================
27 | */
28 | public class MyBasePostProcessor extends BasePostprocessor {
29 |
30 | Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
31 |
32 | MySimpleDraweeView draweeView;
33 |
34 | public MyBasePostProcessor(MySimpleDraweeView draweeView) {
35 | this.draweeView = draweeView;
36 | }
37 |
38 | @Override
39 | public CloseableReference process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
40 |
41 | // 默认宽高比例显示 W:H = 1:2
42 | // 按照宽高比例截取图片区域
43 | if (sourceBitmap.getHeight() > (int) (sourceBitmap.getWidth() * MySimpleDraweeView.DEF_RATIO)) {
44 | Bitmap bitmap = decodeRegion(sourceBitmap, sourceBitmap.getWidth(), (int) (sourceBitmap.getWidth() * MySimpleDraweeView.DEF_RATIO));
45 | return super.process(bitmap, bitmapFactory);
46 | }
47 |
48 | // 将PNG图片转换成JPG,并将背景色设置为指定颜色
49 | else if (ImageFormat.PNG.equals(draweeView.getImageFormat()) && draweeView.isReplacePNGBackground() != -1) {
50 | replaceTransparent2TargetColor(sourceBitmap, draweeView.isReplacePNGBackground());
51 | }
52 |
53 | // PNG图片,并且设置了图片最大宽高,如果加载的PNG图片宽高超过指定宽高,并截取指定大小
54 | else if (ImageFormat.PNG.equals(draweeView.getImageFormat())
55 | && draweeView.getTargetImageSize() != -1
56 | && (sourceBitmap.getWidth() > draweeView.getTargetImageSize() || sourceBitmap.getHeight() > draweeView.getTargetImageSize())) {
57 |
58 | // 压缩图片
59 | Bitmap bitmap = Utils.decodeSampledBitmapFromByteArray(
60 | bitmap2Bytes(sourceBitmap, 100),
61 | draweeView.getTargetImageSize(),
62 | draweeView.getTargetImageSize());
63 |
64 | // 截取图片
65 | Bitmap region = decodeRegion(bitmap, draweeView.getTargetImageSize(), draweeView.getTargetImageSize());
66 | bitmap.recycle();
67 |
68 | return super.process(region, bitmapFactory);
69 | }
70 | return super.process(sourceBitmap, bitmapFactory);
71 | }
72 |
73 | private void replaceTransparent2TargetColor(Bitmap sourceBitmap, int color) {
74 | Canvas canvas = new Canvas(sourceBitmap);
75 | canvas.drawColor(color, PorterDuff.Mode.DST_OVER);
76 | canvas.drawBitmap(sourceBitmap, 0, 0, mPaint);
77 | }
78 |
79 | /**
80 | * 将bitmap转化为数组
81 | */
82 | public static byte[] bitmap2Bytes(Bitmap bitmap, int quality) {
83 | if (bitmap == null) {
84 | throw new IllegalArgumentException("bitmap is not null");
85 | }
86 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
87 | bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos);
88 | return baos.toByteArray();
89 | }
90 |
91 | /**
92 | * 截取bitmap指定的宽高
93 | */
94 | public static Bitmap decodeRegion(Bitmap bitmap, int width, int height) {
95 | return decodeRegion(bitmap2Bytes(bitmap, 100), width, height);
96 | }
97 |
98 | public static Bitmap decodeRegion(byte[] bytes, int width, int height) {
99 | BitmapRegionDecoder bitmapRegionDecoder = null;
100 | try {
101 | bitmapRegionDecoder = BitmapRegionDecoder.newInstance(bytes, 0, bytes.length, true);
102 | } catch (IOException e) {
103 | e.printStackTrace();
104 | }
105 | Rect rect = new Rect(0, 0, width, height);
106 | assert bitmapRegionDecoder != null;
107 | return bitmapRegionDecoder.decodeRegion(rect, null);
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/lib/MyNinePatchDrawable.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.lib;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 | import android.graphics.drawable.NinePatchDrawable;
10 | import android.text.TextUtils;
11 |
12 | import com.bzh.mysimplefresco.R;
13 |
14 |
15 | /**
16 | * ==========================================================
17 | * 版权: 别志华 版权所有(c) 2015
18 | * 作者: 别志华 biezhihua@163.com
19 | * 创建日期: 15-9-18
20 | * 描述:
21 | * 版本: V1.0
22 | * 修订历史:
23 | * ==========================================================
24 | */
25 | public class MyNinePatchDrawable extends NinePatchDrawable {
26 | private String mStr;
27 | private Paint mPaint;
28 |
29 | public MyNinePatchDrawable(Resources res, Bitmap bitmap, byte[] chunk, Rect padding, String srcName, String str) {
30 | super(res, bitmap, chunk, padding, srcName);
31 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
32 | mPaint.setColor(Color.WHITE);
33 | mPaint.setStyle(Paint.Style.FILL);
34 | mPaint.setTextSize(res.getDimensionPixelSize(R.dimen.text_size_16));
35 | mStr = str;
36 | }
37 |
38 |
39 | @Override
40 | public void draw(Canvas canvas) {
41 | super.draw(canvas);
42 | if (TextUtils.isEmpty(mStr)) {
43 | return;
44 | }
45 | float textHeight = mPaint.descent() - mPaint.ascent();
46 | float textWidth = mPaint.measureText(mStr);
47 |
48 | float offsetX = textWidth / 2;
49 | float offsetY = textHeight / 2;
50 |
51 | float disY = getIntrinsicHeight() / 2 - offsetY;
52 | float disX = getIntrinsicWidth() / 2 - offsetX;
53 |
54 | canvas.drawText(mStr, this.getBounds().right - getIntrinsicWidth() + disX, this.getBounds().bottom - getIntrinsicHeight() + textHeight, mPaint);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/lib/MySimpleDraweeView.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.lib;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Color;
7 | import android.graphics.NinePatch;
8 | import android.graphics.drawable.Animatable;
9 | import android.graphics.drawable.ColorDrawable;
10 | import android.graphics.drawable.Drawable;
11 | import android.net.Uri;
12 | import android.os.Build;
13 | import android.text.TextUtils;
14 | import android.util.AttributeSet;
15 | import android.view.ViewGroup;
16 |
17 | import com.bzh.mysimplefresco.R;
18 | import com.facebook.drawee.backends.pipeline.Fresco;
19 | import com.facebook.drawee.controller.AbstractDraweeController;
20 | import com.facebook.drawee.controller.BaseControllerListener;
21 | import com.facebook.drawee.controller.ControllerListener;
22 | import com.facebook.drawee.drawable.ScalingUtils;
23 | import com.facebook.drawee.generic.GenericDraweeHierarchy;
24 | import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
25 | import com.facebook.drawee.generic.RoundingParams;
26 | import com.facebook.drawee.view.SimpleDraweeView;
27 | import com.facebook.imageformat.ImageFormat;
28 | import com.facebook.imagepipeline.common.ResizeOptions;
29 | import com.facebook.imagepipeline.image.ImageInfo;
30 | import com.facebook.imagepipeline.request.ImageRequest;
31 | import com.facebook.imagepipeline.request.ImageRequestBuilder;
32 | import com.facebook.imagepipeline.request.Postprocessor;
33 |
34 | import java.io.File;
35 |
36 |
37 | /**
38 | * ==========================================================
39 | * 版权: 别志华 版权所有(c) 2015
40 | * 作者: 别志华 biezhihua@163.com
41 | * 创建日期: 2015/7/12 16:20
42 | * 版本: V5.0
43 | * 修订历史:
44 | * ==========================================================
45 | */
46 | public class MySimpleDraweeView extends SimpleDraweeView {
47 |
48 | // 默认的宽高比例
49 | public static final float DEF_RATIO = 2.0f;
50 | private Context mContext;
51 | private Postprocessor mPostProcessor; // 后处理器(在图片下载完成后对图片进行处理-截取/缩放等)
52 | private ControllerListener mControllerListener; // 下载监听器
53 | private ResizeOptions mResizeOptions; // 图片缩放,优先级非常高;缩放的尺寸并不是按照指定的尺寸,而是根据内部来计算出一个合适的值;
54 | private ScalingUtils.ScaleType mDraweeViewScaleType;// 图片缩放类型,默认为CENTER_CROP
55 | private Drawable mProgressBar; // 加载进度
56 | private Drawable mPlaceholderDrawable; // 加载背景
57 | private Drawable mGifChartOverlay; // GIF的覆盖物图
58 | private Drawable mLongChartOverlay; // 长图的覆盖物图
59 | private Drawable mNumberChartOverlay; // 数字的覆盖物图
60 | private boolean mAutoPlayAnimations = false; // 是否自动播放GIF图-不自动播放
61 | private boolean isCutGif; // 是否裁剪GIF
62 | private double mHeightRatio; // 宽高比例
63 | private int mTargetImageSize = -1; // 指定的图片尺寸
64 | private int mIsReplacePngBg2TargetColor = -1; // 是否处理PNG图片的透明背景为指定颜色
65 | private ImageRequest.ImageType mImageType; // 图片类型-默认
66 | private ImageFormat mImageFormat = ImageFormat.JPEG;// 图片类型-默认JPEG
67 | private ImageRequest.RequestLevel mLowestPermittedRequestLevel;// 图片加载的请求类型-默认FULL_FETCH
68 | private String uriPathTag; // 加载图片的TAG,用于不重复加载图片
69 |
70 | public MySimpleDraweeView(Context context, GenericDraweeHierarchy hierarchy) {
71 | super(context, hierarchy);
72 | init(context);
73 | }
74 |
75 | public MySimpleDraweeView(Context context) {
76 | super(context);
77 | init(context);
78 | }
79 |
80 | public MySimpleDraweeView(Context context, AttributeSet attrs) {
81 | this(context, attrs, 0);
82 | init(context);
83 | }
84 |
85 | public MySimpleDraweeView(Context context, AttributeSet attrs, int defStyle) {
86 | super(context, attrs);
87 | init(context);
88 | }
89 |
90 | public void init(Context context) {
91 | if (!isInEditMode()) {
92 | this.mContext = context;
93 | mPlaceholderDrawable = new ColorDrawable(Color.GRAY);
94 | }
95 | mPostProcessor = new MyBasePostProcessor(this);
96 | mImageType = ImageRequest.ImageType.DEFAULT;
97 | mControllerListener = new DefaultBaseControllerListener();
98 | mDraweeViewScaleType = ScalingUtils.ScaleType.CENTER_CROP;
99 | mLowestPermittedRequestLevel = ImageRequest.RequestLevel.FULL_FETCH;
100 | }
101 |
102 | /**
103 | * 是否设置GIF标识
104 | */
105 | public MySimpleDraweeView setGifChartIdentify(final boolean isShowGifIdentify) {
106 | if (isShowGifIdentify) {
107 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
108 | mGifChartOverlay = mContext.getDrawable(R.mipmap.identify_gif);
109 | } else {
110 | mGifChartOverlay = mContext.getResources().getDrawable(R.mipmap.identify_gif);
111 | }
112 | } else {
113 | mGifChartOverlay = null;
114 | }
115 | return this;
116 | }
117 |
118 | /**
119 | * 设置长图标识
120 | */
121 | public MySimpleDraweeView setLongChartIdentify(final int imageWidth, final int imageHeight) {
122 | return setLongChartIdentify(imageHeight > imageWidth * DEF_RATIO);
123 | }
124 |
125 | /**
126 | * 设置数字标识,内部会判断是否大于1
127 | */
128 | public MySimpleDraweeView setNumberChartIdentify(int number) {
129 | if (number > 1) {
130 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.identify_number);
131 | byte[] chunk = bitmap.getNinePatchChunk();
132 | if (NinePatch.isNinePatchChunk(chunk)) {
133 | mNumberChartOverlay = new MyNinePatchDrawable(getResources(), bitmap, chunk, NinePatchChunk.deserialize(chunk).mPaddings, null, number + "");
134 | } else {
135 | mNumberChartOverlay = null;
136 | }
137 | } else {
138 | mNumberChartOverlay = null;
139 | }
140 | return this;
141 | }
142 |
143 | /**
144 | * 加载url图片
145 | */
146 | public MySimpleDraweeView setDraweeViewUrl(final String url) {
147 | return setDraweeViewUri(Uri.parse(url));
148 | }
149 |
150 | /**
151 | * 加载本地资源图片
152 | */
153 | public MySimpleDraweeView setDraweeViewResId(final int resId) {
154 | return setDraweeViewUri(getUriByResId(resId));
155 | }
156 |
157 | /**
158 | * 加载uri图片
159 | */
160 | public MySimpleDraweeView setDraweeViewUri(final Uri uri) {
161 | return setControllerByType(uri, "NORMAL");
162 | }
163 |
164 | /**
165 | * 加载url圆形图片
166 | */
167 | public MySimpleDraweeView setRoundDraweeViewUrl(final String url) {
168 | return setRoundDraweeViewUri(Uri.parse(url));
169 | }
170 |
171 | /**
172 | * 加载本地资源圆形图片
173 | */
174 | public MySimpleDraweeView setRoundDraweeViewResId(final int resId) {
175 | return setRoundDraweeViewUri(getUriByResId(resId));
176 | }
177 |
178 | /**
179 | * 加载uri圆形图片
180 | */
181 | public MySimpleDraweeView setRoundDraweeViewUri(final Uri uri) {
182 | return setControllerByType(uri, "ROUND");
183 | }
184 |
185 | /**
186 | * 根据图片宽高设置控件尺寸
187 | */
188 | public MySimpleDraweeView setWidthAndHeight(final float width, final float height) {
189 | float picRatio = height / width;
190 | if (picRatio >= DEF_RATIO) {
191 | picRatio = DEF_RATIO;
192 | }
193 | this.setHeightRatio(picRatio);
194 | return this;
195 | }
196 |
197 | public MySimpleDraweeView setMaxWidthLayoutParams(final int maxWidth, final int width, final int height) {
198 | float widthRatio = (float) width / (float) maxWidth;
199 | float tmpheight = ((float) height / widthRatio);
200 |
201 | float ratio = tmpheight / maxWidth;
202 | if (ratio > DEF_RATIO) {
203 | ratio = DEF_RATIO;
204 | }
205 | tmpheight = maxWidth * ratio;
206 |
207 | // 设置单张图片的布局
208 | ViewGroup.LayoutParams layoutparams = getLayoutParams();
209 | layoutparams.height = (int) tmpheight;
210 | layoutparams.width = maxWidth;
211 | setLayoutParams(layoutparams);
212 | return this;
213 | }
214 |
215 | /**
216 | * 指定的PNG图片的透明背景颜色为白色
217 | */
218 | public MySimpleDraweeView replacePNGBackground2White() {
219 | return replacePNGBackground(Color.WHITE);
220 | }
221 |
222 | /**
223 | * 如果不为-1说明需要替换PNG的透明背景色
224 | */
225 | public int isReplacePNGBackground() {
226 | return mIsReplacePngBg2TargetColor;
227 | }
228 |
229 | /**
230 | * 是否需要替换PNG图片的透明背景为指定的颜色,需要则设置指定的颜色值
231 | */
232 | public MySimpleDraweeView replacePNGBackground(int targetColor) {
233 | if (targetColor == -1) {
234 | throw new RuntimeException("颜色值不能指定为-1");
235 | }
236 | this.mIsReplacePngBg2TargetColor = targetColor;
237 | return this;
238 | }
239 |
240 |
241 | /**
242 | * 截取图片的大小
243 | * TODO:待重构
244 | */
245 | public int getTargetImageSize() {
246 | return mTargetImageSize;
247 | }
248 |
249 | /**
250 | * TODO: 待重构
251 | */
252 | public void setTargetImageSize(int targetImageSize) {
253 | this.mTargetImageSize = targetImageSize;
254 | }
255 |
256 | public ImageFormat getImageFormat() {
257 | return mImageFormat;
258 | }
259 |
260 | /**
261 | * 是否剪切GIF的第一帧
262 | */
263 | public void setIsCutGif(boolean isCutGif) {
264 | this.isCutGif = isCutGif;
265 | }
266 |
267 | /**
268 | * 是否自动播放GIF,默认False
269 | */
270 | public MySimpleDraweeView setAutoPlayAnimations(boolean mAutoPlayAnimations) {
271 | this.mAutoPlayAnimations = mAutoPlayAnimations;
272 | return this;
273 | }
274 |
275 | public MySimpleDraweeView setControllerListener(ControllerListener mControllerListener) {
276 | this.mControllerListener = mControllerListener;
277 | return this;
278 | }
279 |
280 | public MySimpleDraweeView setResizeOptions(ResizeOptions resizeOptions) {
281 | this.mResizeOptions = resizeOptions;
282 | return this;
283 | }
284 |
285 | public MySimpleDraweeView setProgressBar(Drawable mProgressBar) {
286 | this.mProgressBar = mProgressBar;
287 | return this;
288 | }
289 |
290 | public MySimpleDraweeView setDraweeViewScaleType(ScalingUtils.ScaleType mDraweeViewScaleType) {
291 | this.mDraweeViewScaleType = mDraweeViewScaleType;
292 | return this;
293 | }
294 |
295 | public MySimpleDraweeView setPlaceholderDrawable(Drawable placeholderDrawable) {
296 | this.mPlaceholderDrawable = placeholderDrawable;
297 | return this;
298 | }
299 |
300 | public MySimpleDraweeView setLowestPermittedRequestLevel(ImageRequest.RequestLevel mLowestPermittedRequestLevel) {
301 | this.mLowestPermittedRequestLevel = mLowestPermittedRequestLevel;
302 | return this;
303 | }
304 |
305 | ////////////////////////////////////////////////////////////////////////////////////////////////
306 | //////////////////////////////////////私有方法///////////////////////////////////////////////////
307 | ////////////////////////////////////////////////////////////////////////////////////////////////
308 |
309 | /**
310 | * 图片加载完成时,为控件设置Tag
311 | */
312 | private class DefaultBaseControllerListener extends BaseControllerListener {
313 | @Override
314 | public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
315 | super.onFinalImageSet(id, imageInfo, animatable);
316 | MySimpleDraweeView.this.setTag(R.id.uriPath, uriPathTag);
317 | }
318 | }
319 |
320 | // 正常
321 | private void setHierarchy() {
322 | if (mContext == null) {
323 | throw new IllegalArgumentException("Context is not null");
324 | }
325 |
326 | final GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(mContext.getResources())
327 | .setFadeDuration(this.getFadeDuration())
328 | .setOverlay(this.getMyOverlay())
329 | .setActualImageScaleType(this.getDraweeViewScaleType())
330 | .setProgressBarImage(this.getProgressBar(), ScalingUtils.ScaleType.CENTER_INSIDE)
331 | .setPlaceholderImage(this.getPlaceholderDrawable(), ScalingUtils.ScaleType.CENTER_CROP)
332 | .build();
333 | super.setHierarchy(hierarchy);
334 | }
335 |
336 | // 圆形
337 | private void setRoundHierarchy() {
338 | if (mContext == null) {
339 | throw new IllegalArgumentException("Context is not null");
340 | }
341 |
342 | Drawable defaultIcon;
343 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
344 | defaultIcon = mContext.getDrawable(R.mipmap.round_default_icon);
345 | } else {
346 | defaultIcon = mContext.getResources().getDrawable(R.mipmap.round_default_icon);
347 | }
348 |
349 | final GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(mContext.getResources())
350 | .setPlaceholderImage(defaultIcon)
351 | .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
352 | .setRoundingParams(RoundingParams.asCircle())
353 | .build();
354 | super.setHierarchy(hierarchy);
355 | }
356 |
357 | private ImageRequest getImageRequest(MySimpleDraweeView view, Uri uri) {
358 | switch (mImageFormat) {
359 | case JPEG:
360 | case PNG:
361 | return ImageRequestBuilder
362 | .newBuilderWithSource(uri)
363 | .setImageType(view.getImageType())
364 | .setLowestPermittedRequestLevel(view.getLowestPermittedRequestLevel())
365 | .setPostprocessor(view.getPostProcessor())//修改图片
366 | .setResizeOptions(view.getResizeOptions())
367 | .setAutoRotateEnabled(true)
368 | .setLocalThumbnailPreviewsEnabled(true)
369 | .setProgressiveRenderingEnabled(false)
370 | .build();
371 | case GIF:
372 | if (uri.getScheme().toLowerCase().contains("file") && isCutGif()) {
373 | // 针对本地Gif预览时做特殊处理,裁剪出第一帧并显示
374 | File file = new File(uri.getPath());
375 | File cutFile = Utils.getCopyFile(file);
376 | Uri newUri = new Uri.Builder().scheme("file").path(cutFile.getAbsolutePath()).build();
377 | return ImageRequestBuilder
378 | .newBuilderWithSource(newUri)
379 | .setLowestPermittedRequestLevel(view.getLowestPermittedRequestLevel())
380 | .setPostprocessor(view.getPostProcessor())
381 | .setResizeOptions(view.getResizeOptions())
382 | .setAutoRotateEnabled(true).build();
383 | } else {
384 | return ImageRequestBuilder
385 | .newBuilderWithSource(uri)
386 | .setLowestPermittedRequestLevel(view.getLowestPermittedRequestLevel())
387 | .setAutoRotateEnabled(true)
388 | .build();
389 | }
390 | }
391 | throw new RuntimeException("must have a ImageRequest");
392 | }
393 |
394 | private MySimpleDraweeView setControllerByType(final Uri uri, final String type) {
395 | uriPathTag = uri.toString();
396 | this.setImageFormat(uriPathTag);
397 | if (noRepeatLoadImage(uriPathTag)) {
398 |
399 | if ("NORMAL".equals(type)) {
400 | setHierarchy();
401 | } else if ("ROUND".equals(type)) {
402 | setRoundHierarchy();
403 | }
404 |
405 | final AbstractDraweeController controller = Fresco.newDraweeControllerBuilder()
406 | .setAutoPlayAnimations(this.getAutoPlayAnimations())//自动播放图片动画
407 | .setControllerListener(this.getControllerListener())
408 | .setImageRequest(getImageRequest(this, uri))
409 | .setOldController(this.getController())
410 | .build();
411 | super.setController(controller);
412 | }
413 | return this;
414 | }
415 |
416 | /**
417 | * 获取遮盖物
418 | * 数字 > GIF > 长图
419 | */
420 | private Drawable getMyOverlay() {
421 | if (null != mNumberChartOverlay) {
422 | return mNumberChartOverlay;
423 | } else if (null != mGifChartOverlay) {
424 | return mGifChartOverlay;
425 | } else if (null != mLongChartOverlay) {
426 | return mLongChartOverlay;
427 | }
428 | return new ColorDrawable(Color.TRANSPARENT);
429 | }
430 |
431 | private ControllerListener getControllerListener() {
432 | return mControllerListener;
433 | }
434 |
435 | private ScalingUtils.ScaleType getDraweeViewScaleType() {
436 | return mDraweeViewScaleType;
437 | }
438 |
439 | private int getFadeDuration() {
440 | return 0;
441 | }
442 |
443 | private Drawable getPlaceholderDrawable() {
444 | return mPlaceholderDrawable;
445 | }
446 |
447 | private ImageRequest.RequestLevel getLowestPermittedRequestLevel() {
448 | return mLowestPermittedRequestLevel;
449 | }
450 |
451 | private ImageRequest.ImageType getImageType() {
452 | return mImageType;
453 | }
454 |
455 | private Postprocessor getPostProcessor() {
456 | return mPostProcessor;
457 | }
458 |
459 | private ResizeOptions getResizeOptions() {
460 | return mResizeOptions;
461 | }
462 |
463 | @Override
464 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
465 | if (mHeightRatio > 0.0) {
466 | int width = MeasureSpec.getSize(widthMeasureSpec);
467 | int height = (int) (width * mHeightRatio);
468 | super.setMeasuredDimension(width, height);
469 | } else {
470 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
471 | }
472 | }
473 |
474 | private boolean getAutoPlayAnimations() {
475 | return mAutoPlayAnimations;
476 | }
477 |
478 | private Drawable getProgressBar() {
479 | return mProgressBar;
480 | }
481 |
482 | /**
483 | * 判定Tag和Url是否相等,相等代表图片已经加载过,不需要从新加载
484 | */
485 | private boolean noRepeatLoadImage(String imgUrl) {
486 | return !(TextUtils.isEmpty(imgUrl) || TextUtils.isEmpty(this.getTag(R.id.uriPath) + "")) && !(this.getTag(R.id.uriPath) + "").equals(imgUrl);
487 | }
488 |
489 | /**
490 | * 是否设置长图标识
491 | */
492 | public MySimpleDraweeView setLongChartIdentify(final boolean isLongChartIdentify) {
493 | if (isLongChartIdentify) {
494 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
495 | mLongChartOverlay = mContext.getDrawable(R.mipmap.identify_long);
496 | } else {
497 | mLongChartOverlay = mContext.getResources().getDrawable(R.mipmap.identify_long);
498 | }
499 | } else {
500 | mLongChartOverlay = null;
501 | }
502 | return this;
503 | }
504 |
505 | private Uri getUriByResId(int resId) {
506 |
507 | // 增加对资源id类型的图片类型判断
508 | BitmapFactory.Options opts = new BitmapFactory.Options();
509 | opts.inJustDecodeBounds = true;
510 | BitmapFactory.decodeResource(getResources(), resId, opts);
511 | if (opts.outMimeType.equals("image/png")) {
512 | mImageFormat = ImageFormat.PNG;
513 | }
514 |
515 | return new Uri.Builder().scheme("res").path(String.valueOf(resId)).build();
516 | }
517 |
518 | private boolean isCutGif() {
519 | return isCutGif;
520 | }
521 |
522 | private void setHeightRatio(double ratio) {
523 | if (ratio != mHeightRatio) {
524 | mHeightRatio = ratio;
525 | requestLayout();
526 | }
527 | }
528 |
529 | private void setImageFormat(final String url) {
530 | if (url.toLowerCase().endsWith("gif")) {
531 | mImageFormat = ImageFormat.GIF;
532 | } else if (url.toLowerCase().endsWith("jpeg") || url.toLowerCase().endsWith("jpg")) {
533 | mImageFormat = ImageFormat.JPEG;
534 | } else if (url.toLowerCase().endsWith("png")) {
535 | mImageFormat = ImageFormat.PNG;
536 | }
537 | }
538 |
539 | }
540 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/lib/NinePatchChunk.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.lib;
2 |
3 | import android.graphics.Rect;
4 |
5 | import java.nio.ByteBuffer;
6 | import java.nio.ByteOrder;
7 |
8 | /**
9 | * ==========================================================
10 | * 版权: 别志华 版权所有(c) 2015
11 | * 作者: 别志华 biezhihua@163.com
12 | * 创建日期: 15-9-23
13 | * 描述:
14 | * 版本: V1.0
15 | * 修订历史:
16 | * ==========================================================
17 | */
18 | public class NinePatchChunk {
19 |
20 | public static final int NO_COLOR = 0x00000001;
21 | public static final int TRANSPARENT_COLOR = 0x00000000;
22 |
23 | public final Rect mPaddings = new Rect();
24 |
25 | public int mDivX[];
26 | public int mDivY[];
27 | public int mColor[];
28 |
29 | private static void readIntArray(final int[] data, final ByteBuffer buffer) {
30 | for (int i = 0, n = data.length; i < n; ++i)
31 | data[i] = buffer.getInt();
32 | }
33 |
34 | private static void checkDivCount(final int length) {
35 | if (length == 0 || (length & 0x01) != 0)
36 | throw new RuntimeException("invalid nine-patch: " + length);
37 | }
38 |
39 | public static NinePatchChunk deserialize(final byte[] data) {
40 | final ByteBuffer byteBuffer =
41 | ByteBuffer.wrap(data).order(ByteOrder.nativeOrder());
42 |
43 | if (byteBuffer.get() == 0) return null; // is not serialized
44 |
45 | final NinePatchChunk chunk = new NinePatchChunk();
46 | chunk.mDivX = new int[byteBuffer.get()];
47 | chunk.mDivY = new int[byteBuffer.get()];
48 | chunk.mColor = new int[byteBuffer.get()];
49 |
50 | checkDivCount(chunk.mDivX.length);
51 | checkDivCount(chunk.mDivY.length);
52 |
53 | // skip 8 bytes
54 | byteBuffer.getInt();
55 | byteBuffer.getInt();
56 |
57 | chunk.mPaddings.left = byteBuffer.getInt();
58 | chunk.mPaddings.right = byteBuffer.getInt();
59 | chunk.mPaddings.top = byteBuffer.getInt();
60 | chunk.mPaddings.bottom = byteBuffer.getInt();
61 |
62 | // skip 4 bytes
63 | byteBuffer.getInt();
64 |
65 | readIntArray(chunk.mDivX, byteBuffer);
66 | readIntArray(chunk.mDivY, byteBuffer);
67 | readIntArray(chunk.mColor, byteBuffer);
68 |
69 | return chunk;
70 | }
71 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bzh/mysimplefresco/lib/Utils.java:
--------------------------------------------------------------------------------
1 | package com.bzh.mysimplefresco.lib;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.os.Environment;
7 | import android.util.DisplayMetrics;
8 | import android.util.Log;
9 |
10 | import java.io.File;
11 | import java.io.FileInputStream;
12 | import java.io.FileNotFoundException;
13 | import java.io.FileOutputStream;
14 | import java.io.IOException;
15 | import java.security.MessageDigest;
16 | import java.security.NoSuchAlgorithmException;
17 |
18 | /**
19 | * ==========================================================
20 | * 版权: 别志华 版权所有(c) 2015
21 | * 作者: 别志华 biezhihua@163.com
22 | * 创建日期: 15-9-26
23 | * 描述:
24 | * 版本: V1.0
25 | * 修订历史:
26 | * ==========================================================
27 | */
28 | public class Utils {
29 | public static File getCopyFile(File file) {
30 | File copyFile = new File(Environment.getExternalStorageDirectory() + File.separator + getMD5(file.getName()));
31 | if (!copyFile.exists()) {
32 | BitmapFactory.Options options = new BitmapFactory.Options();
33 | Bitmap bitmap = null;
34 | try {
35 | bitmap = BitmapFactory.decodeStream(new FileInputStream(file), null, options);
36 | } catch (FileNotFoundException e) {
37 | e.printStackTrace();
38 | }
39 | Bitmap region = MyBasePostProcessor.decodeRegion(bitmap, options.outWidth, options.outHeight);
40 | byte[] bytes = MyBasePostProcessor.bitmap2Bytes(region, 80);
41 | FileOutputStream fo;
42 | try {
43 | fo = new FileOutputStream(copyFile);
44 | fo.write(bytes);
45 | fo.flush();
46 | fo.close();
47 | } catch (FileNotFoundException e) {
48 | e.printStackTrace();
49 | } catch (IOException e) {
50 | e.printStackTrace();
51 | }
52 | }
53 | return copyFile;
54 | }
55 |
56 | private static final String STR_EMPTY = "";
57 | private static final String STR_MD5 = "MD5";
58 |
59 | public static String getMD5(String content) {
60 | if (content != null && !"".equals(content)) {
61 | try {
62 | MessageDigest digest = MessageDigest.getInstance(STR_MD5);
63 | digest.update(content.getBytes());
64 | return getHashString(digest);
65 |
66 | } catch (NoSuchAlgorithmException e) {
67 | Log.e("yyt", e.getMessage());
68 | }
69 | return STR_EMPTY;
70 | }
71 | return "";
72 | }
73 |
74 | private static String getHashString(MessageDigest digest) {
75 | StringBuilder builder = new StringBuilder(STR_EMPTY);
76 | for (byte b : digest.digest()) {
77 | builder.append(Integer.toHexString((b >> 4) & 0xf));
78 | builder.append(Integer.toHexString(b & 0xf));
79 | }
80 | return builder.toString();
81 | }
82 |
83 | public static Bitmap decodeSampledBitmapFromByteArray(byte[] datas, int reqWidth, int reqHeight) {
84 | long startTime = System.currentTimeMillis();
85 | final BitmapFactory.Options options = new BitmapFactory.Options();
86 | // 当inJustDecodeBounds设为true时,不会加载图片仅获取图片尺寸信息
87 | options.inJustDecodeBounds = true;
88 | // 此时仅会将图片信息会保存至options对象内,decode方法不会返回bitmap对象
89 | BitmapFactory.decodeByteArray(datas, 0, datas.length, options);
90 |
91 | // 计算压缩比例,如inSampleSize=4时,图片会压缩成原图的1/4
92 | options.inSampleSize = calculateInSampleSizeGetSmall(options, reqWidth, reqHeight);
93 |
94 | // 当inJustDecodeBounds设为false时,BitmapFactory.decode...就会返回图片对象了
95 | options.inJustDecodeBounds = false;
96 | // 利用计算的比例值获取压缩后的图片对象
97 | options.inPreferredConfig = Bitmap.Config.ARGB_8888;
98 | options.inPurgeable = true;
99 | options.inInputShareable = true;
100 | Bitmap bitmap = BitmapFactory.decodeByteArray(datas, 0, datas.length, options);
101 | return bitmap;
102 | }
103 |
104 |
105 | public static int calculateInSampleSizeGetSmall(BitmapFactory.Options options, int reqWidth, int reqHeight) {
106 | // 源图片的高度和宽度
107 | final int height = options.outHeight;
108 | final int width = options.outWidth;
109 | int inSampleSize = 1;
110 | if (height > reqHeight || width > reqWidth) {
111 | // 计算出实际宽高和目标宽高的比率
112 | final int heightRatio = Math.round((float) height / (float) reqHeight);
113 | final int widthRatio = Math.round((float) width / (float) reqWidth);
114 | // 选择宽和高中最小的比率作为inSampleSize的值,这样可以保证最终图片的宽和高
115 | // 一定都会大于等于目标的宽和高。
116 | inSampleSize = heightRatio < widthRatio ? widthRatio : heightRatio;
117 | }
118 | return inSampleSize;
119 | }
120 |
121 | public static int getScreenWidth(Context context) {
122 | if (null != context) {
123 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
124 | return metrics.widthPixels;
125 | }
126 | return 0;
127 | }
128 |
129 | public static int getScreenHeight(Context context) {
130 | if (null != context) {
131 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
132 | return metrics.heightPixels;
133 | }
134 | return 0;
135 | }
136 |
137 |
138 | public static int dip2px(Context context, int dipValue) {
139 | float reSize = context.getResources().getDisplayMetrics().density;
140 | return (int) ((dipValue * reSize) + 0.5);
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
18 |
19 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bzh_ui_one_fragment.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
13 |
14 |
23 |
24 |
25 |
33 |
34 |
40 |
41 |
42 |
43 |
44 |
48 |
49 |
54 |
55 |
59 |
60 |
64 |
65 |
70 |
71 |
75 |
76 |
77 |
78 |
79 |
80 |
86 |
87 |
91 |
92 |
97 |
98 |
102 |
103 |
104 |
105 |
106 |
107 |
113 |
114 |
118 |
119 |
124 |
125 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
146 |
147 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bzh_ui_two_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
20 |
21 |
22 |
23 |
29 |
30 |
35 |
36 |
37 |
38 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/menu_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
29 |
30 |
31 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/photoview_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/zoomabledraweeeview_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/drawer_menu.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-hdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_global_menu_direct.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/ic_global_menu_direct.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_global_menu_feed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/ic_global_menu_feed.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_global_menu_likes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/ic_global_menu_likes.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_global_menu_nearby.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/ic_global_menu_nearby.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_global_menu_news.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/ic_global_menu_news.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_global_menu_popular.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/ic_global_menu_popular.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_global_menu_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/ic_global_menu_search.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/identify_gif.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/identify_gif.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/identify_long.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/identify_long.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/identify_number.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/identify_number.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_0.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_1.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_10.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_11.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_12.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_2.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_3.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_4.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_5.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_6.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_7.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_8.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/load_progress_9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/load_progress_9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/round_default_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xhdpi/round_default_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #2d5d82
4 | #21425d
5 | #01bcd5
6 | #007787
7 | #44000000
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 10sp
4 | 25dp
5 | 256dp
6 | 16dp
7 | 16dp
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/icons.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MySimpleFresco
3 |
4 | Hello world!
5 | Settings
6 | 曾经有一份真诚的爱情放在我面前
7 | ,我没有珍惜,等我失去的时候我才后悔莫及,人世间最痛苦的事莫过于此。如果上天能够给我一个再来一次的机会,我会对那个女孩子说三个字:我爱你。如果非要在这份爱上加上一个期限,我希望是……一万年!
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
12 |
19 |
20 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.1'
9 | // NOTE: Do not place your application dependencies here; they belong
10 | // in the individual module build.gradle files
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | jcenter()
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 26 14:59:36 CST 2015
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-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/resource/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/resource/1.gif
--------------------------------------------------------------------------------
/resource/2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/resource/2.gif
--------------------------------------------------------------------------------
/resource/3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/biezhihua/MySimpleDraweeView/f94f8fe41ad499b938def19c4bacb8032b9f9054/resource/3.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------