├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── top
│ │ └── androidman
│ │ └── loading
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── top
│ │ │ └── androidman
│ │ │ └── loading
│ │ │ ├── DefaultLoadingAdapter.java
│ │ │ ├── ImageFactory.java
│ │ │ ├── LoadingApp.java
│ │ │ ├── MainActivity.java
│ │ │ └── Style.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xxhdpi
│ │ ├── icon_empty.png
│ │ ├── icon_failed.png
│ │ ├── icon_loading.png
│ │ └── icon_no_wifi.png
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── layout_default_loading_view.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── top
│ └── androidman
│ └── loading
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── loading
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── top
│ │ └── androidman
│ │ └── loading
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── top
│ │ │ └── androidman
│ │ │ └── loading
│ │ │ └── Loading.java
│ └── res
│ │ ├── drawable
│ │ └── loading.xml
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── top
│ └── androidman
│ └── loading
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 这可能是解耦程度最好的全局Loading框架
2 | ##
3 | ### 背景
4 | 几乎每一个App都会有一个Loading动画,用来让用户知道程序在运作而不是卡死从而缓解用户焦虑,提升用户体验。
5 | Loading动画结束后一般会有三种情况:
6 | - 操作成功,loading动画消失,显示正确的页面内容
7 | - 操作失败,loading动画消失,显示失败页面,让用户可以点击重试
8 | - 空页面,虽然请求成功但是没有数据返回,所以此时loading动画消失,显示空页面状态
9 |
10 | 所以总结起来,一般一个页面有以下四种状态
11 | 1. 加载状态
12 | 2. 成功状态
13 | 3. 失败状态
14 | 4. 空状态
15 |
16 | 对于一个设计良好的APP来说一般全局页面会保持一致,比如加载状态,失败状态和空状态等。但是也有可能不同的页面需要不同的各种状态,比如消息页面展示消息为空的空页面,订单页面展示订单为空的空页面;也可能是不同的页面需要不同的失败状态等
17 |
18 | ### 传统方案
19 | #### 方案一
20 | 1. 在页面的xml中写上各种状态的布局
21 | 2. 根据页面展现过程中控制各个布局的显示和隐藏
22 |
23 | 此方案耦合度极高,难以维护和修改,当App页面默认状态需要更改时代价太大,不利于维护
24 |
25 | #### 方案二
26 | 1. 自定义一个有各种状态的自定义view,
27 | 2. 这个自定义view加入到BaseFragment或BaseActivity页面的xml中
28 | 3. 在base类中提供showLoading(),showSuccess(),showFaile(),showEmpty()等方法供子类在合适的时机调用
29 |
30 | 此方案相较于第一种方案有了很大提升,用户可以对自定义的LoadingView样式进行修改,这样全局就可以得到改变,但是此方案仍然需要在xml中添加代码,存在耦合关系,不利于扩展
31 |
32 | ### 解耦方案
33 | 要解耦就先梳理一下我们需要实现的点:
34 | 1. 支持不同样式的加载、成功、失败和空状态,例如,可能有多种状态的加载样式,也可能有多种状态的空状态等
35 | 2. 整个Loading的相关东西不写到具体的页面中,利于扩展和维护
36 | 3. 支持在各种状态时添加重试逻辑,例如失败状态时点击重试,空状态时点击重新请求数据等
37 | 4. 能指定区域进行加载,例如局部刷新等
38 |
39 | 实现思路
40 | 1. 要实现第一点,兼顾不同状态可能有各种不同样式,需要根据不同的状态创建不同的view供我们在展示相应状态时使用
41 | 2. 实现第二点需要找到一个合适的时机,将我们创建的不同状态的view根据我们创建时的样式展示出来
42 | 3. 在用户需要点击重试时,用户可以加入回调,从而可以实现用户自己的逻辑
43 | 4. 要实现第四点需要找到需要加载的区域,然后在此区域上加上我们需要的布局即可
44 |
45 | ### 终极方案 Loading
46 | Loading是一个轻量级,深度解耦的加载框架,完全由用户控制,只有一个Java文件,你甚至可以直接把这个文件源码拷贝到你的工程中使用。
47 |
48 | 0. **演示**
49 |
50 | Activity|view|空状态|失败状态
51 | :---:|:---:|:---:|:---:
52 |
|
|
|
53 | 1. 引入
54 |
55 | [  ](https://bintray.com/androidman/maven/loading/1.0.0/link)
56 |
57 | ```
58 | compile 'top.androidman.loading:loading:1.0.0'
59 | ```
60 | 2.创建全局的默认Adapter,在Adapter中根据type创建不同的布局实现
61 | ```
62 | public class DefaultLoadingAdapter extends Loading.Adapter {
63 |
64 | private Context mContext;
65 |
66 | public DefaultLoadingAdapter(Context context) {
67 | this.mContext = context;
68 | }
69 |
70 | @Override
71 | public View generateView(int viewType) {
72 | View defaultLoadingView = LayoutInflater.from(mContext).inflate(R.layout.layout_default_loading_view,null);
73 | ImageView image = defaultLoadingView.findViewById(R.id.image);
74 | TextView text = defaultLoadingView.findViewById(R.id.text);
75 | int imageResource = -1;
76 | String textResource = "";
77 |
78 | defaultLoadingView.setVisibility(View.VISIBLE);
79 | switch (viewType) {
80 | case Style.LOADING:
81 | imageResource = R.drawable.loading;
82 | textResource = "正在加载。。。";
83 | break;
84 | case Style.SUCCESS:
85 | defaultLoadingView.setVisibility(View.GONE);
86 | break;
87 | case Style.EMPTY:
88 | imageResource = R.drawable.icon_empty;
89 | textResource = "没有内容哦。。。";
90 | break;
91 | case Style.FAILED:
92 | imageResource = R.drawable.icon_failed;
93 | textResource = "加载失败。。。";
94 | break;
95 | case Style.NO_WIFI:
96 | imageResource = R.drawable.icon_no_wifi;
97 | textResource = "网络出错啦,点击重试。。。";
98 | break;
99 | default:
100 | break;
101 | }
102 | image.setImageResource(imageResource);
103 | text.setText(textResource);
104 |
105 | return defaultLoadingView;
106 | }
107 | }
108 | ```
109 | 当然完全可以创建更加复杂的布局,然后返回即可,另外如果有多种样式的Loading、成功、失败、空状态也可以全部定义出来然后返回即可。
110 |
111 | 3. 在Application中进行注册
112 | ```
113 | Loading.getIns().setAdapter(new DefaultLoadingAdapter(this));
114 | ```
115 | 4. 然后你就可以在任何地方开心的进行使用了(根据创建View时type进行展示,如果是想整个activity中进行展示,在target方法中传入activity即可,如果只是想在某个view上进行展示,传入这个view就可以啦)
116 | ```
117 | Loading.getIns().target(activity).show(Style.LOADING);
118 | ```
119 | 或者
120 | ```
121 | Loading.getIns().target(view).show(Style.SUCCESS);
122 | ```
123 | ### 高级用法
124 | 每个布局都可能会加一些重试的策略在里面,这个时候只需要调用如下方案即可轻松完成
125 | ```
126 | Loading.getIns().wrap(view).show(Style.FAILED, new Loading.OnRetryListener() {
127 | @Override
128 | public void retry() {
129 | picUrl = ImageFactory.getNormalImage();
130 | loadData();
131 | }
132 | });
133 | ```
134 | 其实,不仅是失败时候,任何状态下都可以加入这个重试的回调,都可以执行
135 |
136 | ### 最后的唠叨
137 | 可能小伙伴们都注意到了**Style.LOADING**、**Style.SUCCESS**、**Style.EMPTY**、**Style.FAILED**等状态,其实这个状态是小伙伴自己定义的,就是自己定义不同状态创建不同的View,然后在展示的时候根据不同的情况show不同的type即可,所以建议把Style写到一个集中的地方,方便全局调用,例如:
138 | ```
139 | public final class Style {
140 |
141 | public static final int LOADING = 0x1;
142 | public static final int SUCCESS = 0x2;
143 | public static final int FAILED = 0x3;
144 | public static final int EMPTY = 0x4;
145 | public static final int NO_WIFI = 0x5;
146 |
147 | @IntDef({LOADING, SUCCESS, FAILED, EMPTY})
148 | @Retention(RetentionPolicy.SOURCE)
149 | public @interface Loading {
150 | }
151 |
152 | }
153 | ```
154 |
155 | 当然也可以直接写成全局常量,只要方便调用即可
156 |
157 | github传送门:[点这里](https://github.com/ansnail/Loading)
158 |
159 | ### 鸣谢
160 | 此方案思路来自于 https://github.com/luckybilly/Gloading ,对原作者表示感谢
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "top.androidman.loading"
7 | minSdkVersion 21
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | dataBinding {
20 | enabled = true
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | implementation 'com.android.support:appcompat-v7:28.0.0'
27 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
28 | testImplementation 'junit:junit:4.12'
29 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
31 | implementation 'top.androidman.loading:loading:1.0.0'
32 | api 'com.github.bumptech.glide:glide:4.8.0'
33 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/top/androidman/loading/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.chongding.loading;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.chongding.loading", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/top/androidman/loading/DefaultLoadingAdapter.java:
--------------------------------------------------------------------------------
1 | package top.androidman.loading;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.widget.ImageView;
7 | import android.widget.TextView;
8 |
9 |
10 | import top.androidman.loadinglibary.Loading;
11 |
12 | /**
13 | * @author yanjie
14 | * @version 1.0
15 | * @date 2019-04-28 16:38
16 | * @description 默认全局Adapter,
17 | */
18 | public class DefaultLoadingAdapter extends Loading.Adapter {
19 |
20 | private Context mContext;
21 |
22 | public DefaultLoadingAdapter(Context context) {
23 | this.mContext = context;
24 | }
25 |
26 | @Override
27 | public View generateView(int viewType) {
28 | View defaultLoadingView = LayoutInflater.from(mContext).inflate(R.layout.layout_default_loading_view, null);
29 | ImageView image = defaultLoadingView.findViewById(R.id.image);
30 | TextView text = defaultLoadingView.findViewById(R.id.text);
31 | int imageResource = -1;
32 | String textResource = "";
33 |
34 | defaultLoadingView.setVisibility(View.VISIBLE);
35 | switch (viewType) {
36 | case Style.LOADING:
37 | imageResource = R.drawable.loading;
38 | textResource = "正在加载。。。";
39 | break;
40 | case Style.SUCCESS:
41 | defaultLoadingView.setVisibility(View.GONE);
42 | break;
43 | case Style.EMPTY:
44 | imageResource = R.drawable.icon_empty;
45 | textResource = "没有内容哦。。。";
46 | break;
47 | case Style.FAILED:
48 | imageResource = R.drawable.icon_failed;
49 | textResource = "加载失败。。。";
50 | break;
51 | case Style.NO_WIFI:
52 | imageResource = R.drawable.icon_no_wifi;
53 | textResource = "网络出错啦,点击重试。。。";
54 | break;
55 | default:
56 | break;
57 | }
58 | image.setImageResource(imageResource);
59 | text.setText(textResource);
60 |
61 | return defaultLoadingView;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/top/androidman/loading/ImageFactory.java:
--------------------------------------------------------------------------------
1 | package top.androidman.loading;
2 |
3 | import java.util.Locale;
4 |
5 | /**
6 | * @author yanjie
7 | * @version 1.0
8 | * @date 2019-05-09 16:40
9 | */
10 | public class ImageFactory {
11 |
12 | public static String getErrorImage() {
13 | return "http://www." + System.currentTimeMillis() + ".com/abc.png";
14 | }
15 |
16 | public static String getNormalImage() {
17 | int id = (int) (Math.random() * 100000);
18 | return String.format(Locale.CHINA, "https://www.thiswaifudoesnotexist.net/example-%d.jpg", id);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/top/androidman/loading/LoadingApp.java:
--------------------------------------------------------------------------------
1 | package top.androidman.loading;
2 |
3 | import android.app.Application;
4 |
5 | import top.androidman.loadinglibary.Loading;
6 |
7 |
8 | /**
9 | * @author yanjie
10 | * @version 1.0
11 | * @date 2019-06-21 17:46
12 | * @description
13 | */
14 | public class LoadingApp extends Application {
15 |
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 | Loading.getIns().setAdapter(new DefaultLoadingAdapter(this));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/top/androidman/loading/MainActivity.java:
--------------------------------------------------------------------------------
1 | package top.androidman.loading;
2 |
3 | import android.databinding.DataBindingUtil;
4 | import android.graphics.drawable.Drawable;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.View;
10 | import android.widget.Toast;
11 |
12 | import com.bumptech.glide.Glide;
13 | import com.bumptech.glide.load.DataSource;
14 | import com.bumptech.glide.load.engine.GlideException;
15 | import com.bumptech.glide.request.RequestListener;
16 | import com.bumptech.glide.request.target.Target;
17 |
18 | import top.androidman.loading.databinding.ActivityMainBinding;
19 | import top.androidman.loadinglibary.Loading;
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | private Handler mHandler = new Handler();
24 |
25 | private ActivityMainBinding mBinding;
26 |
27 | private boolean image1Success;
28 | private boolean image2Success;
29 |
30 | private String picUrl;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | getSupportActionBar().hide();
36 | mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
37 | setContentView(mBinding.getRoot());
38 | Loading.getIns().target(this).show(Style.LOADING);
39 | Glide.with(this).load(ImageFactory.getNormalImage()).into(mBinding.ivImage1);
40 | Glide.with(this).load(ImageFactory.getNormalImage()).into(mBinding.ivImage2);
41 | mHandler.postDelayed(new Runnable() {
42 | @Override
43 | public void run() {
44 | Loading.getIns().target(MainActivity.this).show(Style.SUCCESS);
45 | }
46 | }, 3000);
47 | }
48 |
49 |
50 | public void loadImage1(View view) {
51 | Loading.getIns().target(mBinding.ivImage1).show(Style.LOADING);
52 |
53 | Glide.with(this)
54 | .load(ImageFactory.getNormalImage())
55 | .listener(new RequestListener() {
56 | @Override
57 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
58 | return false;
59 | }
60 |
61 | @Override
62 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
63 | Loading.getIns().target(mBinding.ivImage1).show(Style.SUCCESS);
64 | return false;
65 | }
66 | })
67 | .into(mBinding.ivImage1);
68 | }
69 |
70 | public void loadImage2(View view) {
71 | picUrl = ImageFactory.getErrorImage();
72 | loadData();
73 | }
74 |
75 | public void loadImageAll(View view) {
76 | image1Success = false;
77 | image2Success = false;
78 | Loading.getIns().target(mBinding.llContainer).show(Style.LOADING);
79 | Glide.with(this)
80 | .load(ImageFactory.getNormalImage())
81 | .listener(new RequestListener() {
82 | @Override
83 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
84 | return false;
85 | }
86 |
87 | @Override
88 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
89 | image1Success = true;
90 | if (image2Success) {
91 | Loading.getIns().target(mBinding.llContainer).show(Style.SUCCESS);
92 | }
93 | return false;
94 | }
95 | })
96 | .into(mBinding.ivImage1);
97 |
98 | Glide.with(this)
99 | .load(ImageFactory.getNormalImage())
100 | .listener(new RequestListener() {
101 | @Override
102 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
103 | return false;
104 | }
105 |
106 | @Override
107 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
108 | image2Success = true;
109 | if (image1Success) {
110 | Loading.getIns().target(mBinding.llContainer).show(Style.SUCCESS);
111 | }
112 | return false;
113 | }
114 | })
115 | .into(mBinding.ivImage2);
116 | }
117 |
118 | private void loadData() {
119 | Loading.getIns().target(mBinding.ivImage2).show(Style.LOADING);
120 | Glide.with(this)
121 | .load(picUrl)
122 | .listener(new RequestListener() {
123 | @Override
124 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
125 | Loading.getIns().target(mBinding.ivImage2).show(Style.FAILED, new Loading.OnRetryListener() {
126 | @Override
127 | public void retry() {
128 | picUrl = ImageFactory.getNormalImage();
129 | loadData();
130 | }
131 | });
132 | return false;
133 | }
134 |
135 | @Override
136 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
137 | Loading.getIns().target(mBinding.ivImage2).show(Style.SUCCESS);
138 | return false;
139 | }
140 | })
141 | .into(mBinding.ivImage2);
142 | }
143 |
144 | public void loadEmpty(View view) {
145 | Loading.getIns().target(mBinding.llContainer).show(Style.LOADING);
146 | mHandler.postDelayed(new Runnable() {
147 | @Override
148 | public void run() {
149 | Loading.getIns().target(mBinding.llContainer).show(Style.NO_WIFI, new Loading.OnRetryListener() {
150 | @Override
151 | public void retry() {
152 | Loading.getIns().target(mBinding.llContainer).show(Style.LOADING);
153 | mHandler.postDelayed(new Runnable() {
154 | @Override
155 | public void run() {
156 | Loading.getIns().target(mBinding.llContainer).show(Style.EMPTY, new Loading.OnRetryListener() {
157 | @Override
158 | public void retry() {
159 | Toast.makeText(MainActivity.this, "空状态", Toast.LENGTH_SHORT).show();
160 | }
161 | });
162 | }
163 | }, 3000);
164 | }
165 | });
166 | }
167 | }, 3000);
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/app/src/main/java/top/androidman/loading/Style.java:
--------------------------------------------------------------------------------
1 | package top.androidman.loading;
2 |
3 | import android.support.annotation.IntDef;
4 |
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 |
8 | /**
9 | * @author yanjie
10 | * @version 1.0
11 | * @date 2019/4/16 上午10:31
12 | * @description
13 | */
14 | public final class Style {
15 |
16 | ///////////////////////////////////////////////////////////////////////////
17 | // loading的各种状态开始
18 | ///////////////////////////////////////////////////////////////////////////
19 |
20 | public static final int LOADING = 0x1;
21 | public static final int SUCCESS = 0x2;
22 | public static final int FAILED = 0x3;
23 | public static final int EMPTY = 0x4;
24 | public static final int NO_WIFI = 0x5;
25 |
26 | @IntDef({LOADING, SUCCESS, FAILED, EMPTY})
27 | @Retention(RetentionPolicy.SOURCE)
28 | public @interface Loading {
29 | }
30 |
31 | ///////////////////////////////////////////////////////////////////////////
32 | // loading的各种状态结束
33 | ///////////////////////////////////////////////////////////////////////////
34 |
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/icon_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/drawable-xxhdpi/icon_empty.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/icon_failed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/drawable-xxhdpi/icon_failed.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/icon_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/drawable-xxhdpi/icon_loading.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/icon_no_wifi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/drawable-xxhdpi/icon_no_wifi.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
10 |
15 |
16 |
20 |
21 |
25 |
26 |
27 |
28 |
35 |
36 |
43 |
44 |
51 |
52 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_default_loading_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
22 |
23 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Loading
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/top/androidman/loading/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.chongding.loading;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/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 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.4.1'
11 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 |
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ansnail/Loading/4a43c917e26371f75e0cc48d084efdc0ebf3eb48/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue May 21 18:16:49 CST 2019
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-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
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 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/loading/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/loading/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 | defaultConfig {
8 | minSdkVersion 21
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | implementation 'com.android.support:appcompat-v7:28.0.0'
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
33 |
34 | }
35 |
36 | //==================从这里配置开始=========================
37 | apply plugin: 'com.github.dcendents.android-maven'
38 | apply plugin: 'com.jfrog.bintray'
39 |
40 | // 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version
41 | // 这个version影响后面的引用
42 | version = "1.0.0"
43 |
44 | def siteUrl = 'https://github.com/ansnail/Loading' // 项目的主页
45 | def gitUrl = 'https://github.com/ansnail/Loading.git' // Git仓库的url
46 | group = "top.androidman.loading" // Maven Group ID for the artifact,一般填你唯一的包名
47 | install {
48 | repositories.mavenInstaller {
49 | // This generates POM.xml with proper parameters
50 | pom {
51 | project {
52 | packaging 'aar'
53 | // Add your description here
54 | name '这可能是解耦程度最好的全局Loading框架' //项目的描述,可以描述下项目的基本情况
55 | url siteUrl
56 | // Set your license
57 | licenses {
58 | license {
59 | name 'The Apache Software License, Version 2.0'
60 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
61 | }
62 | }
63 | developers {//填写的开发者的基本信息
64 | developer {
65 | id 'androidman'
66 | name 'androidman'
67 | email 'androidman@yeah.net'
68 | }
69 | }
70 | scm {
71 | connection gitUrl
72 | developerConnection gitUrl
73 | url siteUrl
74 | }
75 | }
76 | }
77 | }
78 | }
79 | task sourcesJar(type: Jar) {
80 | from android.sourceSets.main.java.srcDirs
81 | classifier = 'sources'
82 | }
83 | task javadoc(type: Javadoc) {
84 | source = android.sourceSets.main.java.srcDirs
85 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
86 | }
87 | task javadocJar(type: Jar, dependsOn: javadoc) {
88 | classifier = 'javadoc'
89 | from javadoc.destinationDir
90 | }
91 | artifacts {
92 | archives javadocJar
93 | archives sourcesJar
94 | }
95 | Properties properties = new Properties()
96 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
97 | bintray {
98 | user = properties.getProperty("bintray.user")
99 | key = properties.getProperty("bintray.apikey")
100 | configurations = ['archives']
101 | pkg {
102 | repo = "maven" //发布到JCenter上的仓库名字
103 | name = "loading" //发布到JCenter上的项目名字
104 | websiteUrl = siteUrl
105 | vcsUrl = gitUrl
106 | licenses = ["Apache-2.0"]
107 | publish = true
108 | }
109 | }
110 |
111 |
--------------------------------------------------------------------------------
/loading/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/loading/src/androidTest/java/top/androidman/loading/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package top.androidman.loading;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.chongding.loadinglibary.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/loading/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/loading/src/main/java/top/androidman/loading/Loading.java:
--------------------------------------------------------------------------------
1 | package top.androidman.loading;
2 |
3 | import android.app.Activity;
4 | import android.util.SparseArray;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.FrameLayout;
8 |
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | /**
13 | * @author yanjie
14 | */
15 | public class Loading {
16 | private static final Loading OUR_INSTANCE = new Loading();
17 |
18 | /**
19 | * 存储Object和ViewHolder的Map
20 | */
21 | private Map