├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── hankkin
│ │ └── pagelayoutdemo_java
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── hankkin
│ │ │ └── pagelayoutdemo_java
│ │ │ ├── DefaultActivity.java
│ │ │ ├── DemoActivity.java
│ │ │ ├── FragmentActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── TestFragment.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_launcher_background.xml
│ │ └── pic.png
│ │ ├── layout
│ │ ├── activity_default.xml
│ │ ├── activity_demo.xml
│ │ ├── activity_fragment.xml
│ │ ├── activity_main.xml
│ │ ├── fragment_test.xml
│ │ ├── layout_custom.xml
│ │ ├── layout_empty_demo.xml
│ │ ├── layout_error_demo.xml
│ │ └── layout_loading_demo.xml
│ │ ├── menu
│ │ └── menus.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
│ │ └── icon_smile.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
│ └── com
│ └── hankkin
│ └── pagelayoutdemo_java
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── pagelayout-java
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── hankkin
│ │ └── pagelayout_java
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── hankkin
│ │ │ └── pagelayout_java
│ │ │ ├── BlinkLayout.java
│ │ │ └── PageLayout.java
│ └── res
│ │ ├── drawable
│ │ ├── pic_empty.png
│ │ └── pic_error.png
│ │ ├── layout
│ │ ├── layout_empty.xml
│ │ ├── layout_error.xml
│ │ └── layout_loading.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── hankkin
│ └── pagelayout_java
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.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 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PageLayoutDemojava
2 | 一款简单的page切换 空布局、错误布局、加载布局,支持一键配置、定义,不需要xml编写
3 |
4 | > **该功能是支持单独为某个布局设置状态改变的,比如很多同学提到的我一个listview的数据没有获取到,fun initPage(targetView: Any),这个targetView你只需要设置成你的listview或者包裹你listview的parent布局就OK了,具体原理可以看下面的代码解析啊,遍历获取索引,然后记录索引值....**
5 |
6 | **如果您想看Kotlin版本,点击[https://github.com/Hankkin/PageLayoutDemo](https://github.com/Hankkin/PageLayoutDemo)**
7 |
8 | > 项目中我们经常会用到的加载数据,加载完数据后显示内容,如果没有数据显示一个空白页,这是如果网络错误了显示一个网络错误页,自定义一个PageLayout。
9 |
10 | ## 绪论
11 | Android中经常使用一个空白页和网络错误页用来提高用户体验,给用户一个较好的感官,如果获取到的数据为空,那么会显示一个空白数据页,如果在获取数据的过程中网络错误了,会显示一个网络异常页,像最近比较火的某东这样,见下图。网上也有一些开源的组件,大部分都是自定义继承某个布局在xml中让其作为跟布局,然后将自己的内容布局添加进去,效果也都不错,但是个人总觉得稍微有些麻烦,不是那么灵活,n多个xml布局都去定义,写的心烦,所以有了今天的主角。
12 |
13 |
14 |
15 |
16 | ## 思考
17 | 实现的思路实际上是和上面说的一样,只不过换了一种方式,我们手动获取到contentView,将它从DecorView中移除,然后交给PageLayout取管理。当时考虑的时候就是不想在每个xml中去写页面切换的布局,那么我们可不可以用Java代码去控制?带着下面几个问题一起来看一下。
18 |
19 | - 1.自定义一个布局让其作为跟布局
20 | - 2.提供切换**加载loading**、**空白页empty**、**错误页errror**、**内容页content**功能
21 | - 3.怎么让其取管理上边的四个页面?
22 | - 4.contentView怎么添加?
23 | - 5.如果我想切换的跟布局不是个Activity或者Fragment怎么办?
24 | - 6.因为切换页面状态的功能一般都是一个APP统一的,那么可不可以一键配置呢?
25 |
26 | ## 实现
27 |
28 | ### 1.代码设计
29 |
30 | 首先我们定义PageLayout继承FrameLayout或者LinearLayou或者其他的布局都可以,然后我们需要提供切换四个布局的功能,当然如果支持自定义就更好了,还有状态布局里面的一些属性,还方便一键配置,所以最后采用了Builder模式来创建,使用方式就和Android里面的**AlertDialog**一样,通过Builder去构建一个PageLayout。最后的样子是长这样的:
31 |
32 | | 方法 | 注释 |
33 | | :------------------------- | ----------------------------- |
34 | | showLoading() | 显示loading |
35 | | showError() | 显示错误布局 |
36 | | showEmpty() | 显示空布局 |
37 | | hide() | 显示内容布局 |
38 | | **Builder** | |
39 | | setLoading() | setLoadingText() |
40 | | setError() | setDefaultLoadingBlinkText() |
41 | | setEmpty() | setLoadingTextColor() |
42 | | setDefaultEmptyText() | setDefaultLoadingBlinkColor() |
43 | | setDefaultEmptyTextColor() | setDefaultErrorText() |
44 | | setDefaultErrorTextColor() | setEmptyDrawable() |
45 | | setErrorDrawable() | |
46 |
47 |
48 |
49 | **默认样式**
50 | ```
51 | PageLayout.Builder(this)
52 | .initPage(ll_default)
53 | .setOnRetryListener(object : PageLayout.OnRetryClickListener{
54 | override fun onRetry() {
55 | loadData()
56 | }
57 |
58 | })
59 | .create()
60 | ```
61 |
62 | **自定义样式**
63 |
64 | ```
65 | PageLayout.Builder(this)
66 | .initPage(ll_demo)
67 | .setLoading(R.layout.layout_loading_demo)
68 | .setEmpty(R.layout.layout_empty_demo,R.id.tv_page_empty_demo)
69 | .setError(R.layout.layout_error_demo,R.id.tv_page_error_demo,object : PageLayout.OnRetryClickListener{
70 | override fun onRetry() {
71 | loadData()
72 | }
73 | })
74 | .setEmptyDrawable(R.drawable.pic_empty)
75 | .setErrorDrawable(R.drawable.pic_error)
76 | .create()
77 | ```
78 |
79 | ### 2.设置PageLayout
80 |
81 | > 考虑好了代码设计方式之后,我们来具体实现功能,首先需要考虑上面的5,6点:
82 |
83 | **contentView怎么添加?**
84 |
85 | **如果我想切换的跟布局不是个Activity或者Fragment怎么办?**
86 |
87 | #### 1.Activity
88 | 如果我们要切换的跟布局是个Activity时,首先我们需要了解一下Android中的setContentView()方法,很熟悉,是我们新建完Activity后默认会在生命周期方法onCreate()中默认存在的,那么setContentView()做了些什么呢?我们先看一张图:
89 |
90 | 
91 |
92 | > 一个Activity是通过ActivityThread创建出来的,创建完毕后,会将DecorView添加到Window中,同时会创建ViewRootImpl对象,并将ViewRootImpl对象和DecorView建立关联,setContentView()是通过getWindow()调用的,这里的window实际初始化的时候初始化为PhoneWindow,也就是说Activity会调用PhoneWindow的setContentView()将layout布局添加到DecorView上,而此时的DecorView就是那个最底层的View。然后通过LayoutInflater.infalte()方法加载布局生成View对象并通过addView()方法添加到Window上,(一层一层的叠加到Window上)所以,Activity其实不是显示视图,Window才是真正的显示视图。
93 |
94 | 再来看上面的那张图,可以说DecorView是一个界面的真正跟布局,TitleView我们可以通过设置theme样式显示隐藏的,状态布局切换时我们不考虑TitleView,我们只需要考虑ContentView,而ContentView也就是**android.R.id.content**,知道了这些我们来看看怎么获取将contenView交给PageLayout管理。
95 |
96 | #### 2.Fragment、View
97 |
98 | 如果我们要切换的跟布局是个Fragment、View时,我们只需要获取到它的parent
99 |
100 | ### 3.PageLayout设置跟布局
101 | 获取到了contentView跟布局后,我们要移除自己的显示内容的布局,并把这个布局交给PageLayout,下面看一下代码,注释的很详细了
102 |
103 | ```
104 | /**
105 | * set target view for root
106 | */
107 | fun initPage(targetView: Any): Builder {
108 | var content: ViewGroup? = null
109 | when (targetView) {
110 | is Activity -> { //如果是Activity,获取到android.R.content
111 | mContext = targetView
112 | content = (mContext as Activity).findViewById(android.R.id.content)
113 | }
114 | is Fragment -> { //如果是Fragment获取到parent
115 | mContext = targetView.activity!!
116 | content = (targetView.view)?.parent as ViewGroup
117 | }
118 | is View -> { //如果是View,也取到parent
119 | mContext = targetView.context
120 | try {
121 | content = (targetView.parent) as ViewGroup
122 | } catch (e: TypeCastException) {
123 | }
124 | }
125 | }
126 | val childCount = content?.childCount
127 | var index = 0
128 | val oldContent: View
129 | if (targetView is View) { //如果是某个线性布局或者相对布局时,遍历它的孩子,找到对应的索引,记录下来
130 | oldContent = targetView
131 | childCount?.let {
132 | for (i in 0 until childCount) {
133 | if (content!!.getChildAt(i) === oldContent) {
134 | index = i
135 | break
136 | }
137 | }
138 | }
139 |
140 | } else { //如果是Activity或者Fragment时,取到索引为第一个的View
141 | oldContent = content!!.getChildAt(0)
142 | }
143 | mPageLayout.mContent = oldContent //给PageLayout设置contentView
144 | mPageLayout.removeAllViews()
145 | content?.removeView(oldContent) //将本身content移除,并且把PageLayout添加到DecorView中去
146 | val lp = oldContent.layoutParams
147 | content?.addView(mPageLayout, index, lp)
148 | mPageLayout.addView(oldContent)
149 | initDefault() //设置默认状态布局
150 | return this
151 | }
152 | ```
153 |
154 | 这样我们就解决了上面的5,6的问题。
155 |
156 | ### 4.其他
157 |
158 | - **因为错误布局中一般都包括一个点击重试的功能,如果你需要自定义布局,你可以在配置PageLayout之前,设置好错误布局和点击事件,然后setError进去,同时也提供了一个默认方式的方法**
159 |
160 | ```
161 | fun setError(errorView: Int, errorClickId: Int, onRetryClickListener: OnRetryClickListener)
162 | ```
163 | - **考虑到此功能的APP统一性,所以并没有提供过多的自定义功能,如果你需要的话,你都可以提前设置好View,然后进行set**
164 | - **之前和同事讨论,xml形式和代码形式哪个更方便更灵活,这些都属于个人喜好吧,如果你更喜欢在xml里写的话,你可以进行改造,也挺简单,目前没提供xml方式,PageLayout的初衷就是模仿AlertDialog方式,随时随地使用状态布局切换**
165 | - **你也可以在BaseActivity和BaseFragment中进行PageLayout的初始化,Demo中未使用,自行解决**
166 |
167 | ## 效果图
168 |
169 | 
170 |
171 |
172 | 代码已经上传到Github[https://github.com/Hankkin/PageLayoutDemojava](https://github.com/Hankkin/PageLayoutDemojava)
173 |
174 |
175 | **Reading:一款不错的Material Desgin风格的Kotlin版本的开源APP**
176 | [https://github.com/Hankkin/Reading](https://github.com/Hankkin/Reading)
177 |
178 | 欢迎大家Follow、star、fork,谢谢
179 | 如果有不合适的地方,请提issues讨论指正
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.hankkin.pagelayoutdemo_java"
7 | minSdkVersion 15
8 | targetSdkVersion 27
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.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 | dependencies {
21 | implementation fileTree(include: ['*.jar'], dir: 'libs')
22 | implementation 'com.android.support:appcompat-v7:27.1.1'
23 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
24 | testImplementation 'junit:junit:4.12'
25 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
26 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
27 | implementation project(':pagelayout-java')
28 | }
29 |
--------------------------------------------------------------------------------
/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/com/hankkin/pagelayoutdemo_java/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayoutdemo_java;
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.hankkin.pagelayoutdemo_java", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hankkin/pagelayoutdemo_java/DefaultActivity.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayoutdemo_java;
2 |
3 | import android.os.Handler;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.Menu;
8 | import android.view.MenuInflater;
9 | import android.view.MenuItem;
10 |
11 | import com.hankkin.pagelayout_java.PageLayout;
12 |
13 | public class DefaultActivity extends AppCompatActivity {
14 |
15 | private PageLayout mPageLayout;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_default);
21 |
22 | mPageLayout = new PageLayout.Builder(this)
23 | .initPage(findViewById(R.id.ll_default))
24 | .setCustomView(LayoutInflater.from(this).inflate(R.layout.layout_custom,null))
25 | .setOnRetryListener(new PageLayout.OnRetryClickListener() {
26 | @Override
27 | public void onRetry() {
28 | loadData();
29 | }
30 | })
31 | .create();
32 |
33 | loadData();
34 | }
35 |
36 | private void loadData(){
37 | mPageLayout.showLoading();
38 | new Handler().post(new Runnable() {
39 | @Override
40 | public void run() {
41 | mPageLayout.hide();
42 | }
43 | });
44 | }
45 |
46 | @Override
47 | public boolean onCreateOptionsMenu(Menu menu) {
48 | new MenuInflater(this).inflate(R.menu.menus,menu);
49 | return super.onCreateOptionsMenu(menu);
50 | }
51 |
52 | @Override
53 | public boolean onOptionsItemSelected(MenuItem item) {
54 | switch (item.getItemId()){
55 | case R.id.menu_content:
56 | mPageLayout.hide();
57 | break;
58 | case R.id.menu_customer:
59 | mPageLayout.showCustom();
60 | break;
61 | case R.id.menu_empty:
62 | mPageLayout.showEmpty();
63 | break;
64 | case R.id.menu_error:
65 | mPageLayout.showError();
66 | break;
67 | case R.id.menu_loading:
68 | mPageLayout.showLoading();
69 | break;
70 | }
71 | return super.onOptionsItemSelected(item);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hankkin/pagelayoutdemo_java/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayoutdemo_java;
2 |
3 | import android.os.Handler;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.Menu;
8 | import android.view.MenuInflater;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 |
14 | import com.hankkin.pagelayout_java.PageLayout;
15 |
16 | public class DemoActivity extends AppCompatActivity {
17 |
18 | private PageLayout mPageLayout;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_demo);
24 |
25 | View custom = LayoutInflater.from(this)
26 | .inflate(R.layout.layout_custom, null);
27 | ((ImageView) (custom.findViewById(R.id.iv_custom))).setImageResource(R.mipmap.icon_smile);
28 | ((TextView) custom.findViewById(R.id.tv_custom_content)).setText("This is PageLayout");
29 | mPageLayout = new PageLayout.Builder(this)
30 | .initPage(findViewById(R.id.ll_demo))
31 | .setLoading(R.layout.layout_loading_demo, R.id.tv_page_loading_demo)
32 | .setEmpty(R.layout.layout_empty_demo, R.id.tv_page_empty_demo)
33 | .setCustomView(custom)
34 | .setError(R.layout.layout_error_demo, R.id.tv_page_error_demo, new PageLayout.OnRetryClickListener() {
35 | @Override
36 | public void onRetry() {
37 | loadData();
38 | }
39 | })
40 | .setEmptyDrawable(R.drawable.pic_empty)
41 | .setErrorDrawable(R.drawable.pic_error)
42 | .setLoadingText("Loading")
43 | .create();
44 |
45 | loadData();
46 | }
47 |
48 |
49 | private void loadData() {
50 | mPageLayout.showLoading();
51 | new Handler().post(new Runnable() {
52 | @Override
53 | public void run() {
54 | mPageLayout.hide();
55 | }
56 | });
57 | }
58 |
59 | @Override
60 | public boolean onCreateOptionsMenu(Menu menu) {
61 | new MenuInflater(this).inflate(R.menu.menus, menu);
62 | return super.onCreateOptionsMenu(menu);
63 | }
64 |
65 | @Override
66 | public boolean onOptionsItemSelected(MenuItem item) {
67 | switch (item.getItemId()) {
68 | case R.id.menu_content:
69 | mPageLayout.hide();
70 | break;
71 | case R.id.menu_customer:
72 | mPageLayout.showCustom();
73 | break;
74 | case R.id.menu_empty:
75 | mPageLayout.showEmpty();
76 | break;
77 | case R.id.menu_error:
78 | mPageLayout.showError();
79 | break;
80 | case R.id.menu_loading:
81 | mPageLayout.showLoading();
82 | break;
83 | }
84 | return super.onOptionsItemSelected(item);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hankkin/pagelayoutdemo_java/FragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayoutdemo_java;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentTransaction;
6 |
7 | public class FragmentActivity extends android.support.v4.app.FragmentActivity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_fragment);
13 |
14 | TestFragment fragment = new TestFragment();
15 | FragmentManager fragmentManager = getSupportFragmentManager();
16 | FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
17 | fragmentTransaction.replace(R.id.container, fragment);
18 | fragmentTransaction.commit();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hankkin/pagelayoutdemo_java/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayoutdemo_java;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 |
15 | findViewById(R.id.btn_default).setOnClickListener(new View.OnClickListener() {
16 | @Override
17 | public void onClick(View v) {
18 | startActivity(new Intent(MainActivity.this,DefaultActivity.class));
19 | }
20 | });
21 |
22 | findViewById(R.id.btn_demo).setOnClickListener(new View.OnClickListener() {
23 | @Override
24 | public void onClick(View v) {
25 | startActivity(new Intent(MainActivity.this,DemoActivity.class));
26 | }
27 | });
28 |
29 | findViewById(R.id.btn_fg).setOnClickListener(new View.OnClickListener() {
30 | @Override
31 | public void onClick(View v) {
32 | startActivity(new Intent(MainActivity.this,FragmentActivity.class));
33 | }
34 | });
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hankkin/pagelayoutdemo_java/TestFragment.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayoutdemo_java;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
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.hankkin.pagelayout_java.PageLayout;
13 |
14 |
15 | /**
16 | * A simple {@link Fragment} subclass.
17 | * Activities that contain this fragment must implement the
18 | * {@link TestFragment.OnFragmentInteractionListener} interface
19 | * to handle interaction events.
20 | * Use the {@link TestFragment#newInstance} factory method to
21 | * create an instance of this fragment.
22 | */
23 | public class TestFragment extends Fragment {
24 | // TODO: Rename parameter arguments, choose names that match
25 | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
26 | private static final String ARG_PARAM1 = "param1";
27 | private static final String ARG_PARAM2 = "param2";
28 |
29 | // TODO: Rename and change types of parameters
30 | private String mParam1;
31 | private String mParam2;
32 |
33 | private PageLayout mPageLayout;
34 |
35 |
36 |
37 | public TestFragment() {
38 | // Required empty public constructor
39 | }
40 |
41 | /**
42 | * Use this factory method to create a new instance of
43 | * this fragment using the provided parameters.
44 | *
45 | * @param param1 Parameter 1.
46 | * @param param2 Parameter 2.
47 | * @return A new instance of fragment TestFragment.
48 | */
49 | // TODO: Rename and change types and number of parameters
50 | public static TestFragment newInstance(String param1, String param2) {
51 | TestFragment fragment = new TestFragment();
52 | Bundle args = new Bundle();
53 | args.putString(ARG_PARAM1, param1);
54 | args.putString(ARG_PARAM2, param2);
55 | fragment.setArguments(args);
56 | return fragment;
57 | }
58 |
59 | @Override
60 | public void onCreate(Bundle savedInstanceState) {
61 | super.onCreate(savedInstanceState);
62 | if (getArguments() != null) {
63 | mParam1 = getArguments().getString(ARG_PARAM1);
64 | mParam2 = getArguments().getString(ARG_PARAM2);
65 | }
66 | }
67 |
68 | @Override
69 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
70 | Bundle savedInstanceState) {
71 | // Inflate the layout for this fragment
72 | return inflater.inflate(R.layout.fragment_test, container, false);
73 | }
74 |
75 |
76 |
77 | @Override
78 | public void onAttach(Context context) {
79 | super.onAttach(context);
80 |
81 | }
82 |
83 | @Override
84 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
85 | super.onActivityCreated(savedInstanceState);
86 | PageLayout pageLayout = new PageLayout.Builder(getActivity())
87 | // .initPage(getActivity().findViewById(R.id.fl_test))
88 | .initPage(this)
89 | .create();
90 | pageLayout.showLoading();
91 | }
92 |
93 | @Override
94 | public void onDetach() {
95 | super.onDetach();
96 | }
97 |
98 | /**
99 | * This interface must be implemented by activities that contain this
100 | * fragment to allow an interaction in this fragment to be communicated
101 | * to the activity and potentially other fragments contained in that
102 | * activity.
103 | *
104 | * See the Android Training lesson Communicating with Other Fragments for more information.
107 | */
108 | public interface OnFragmentInteractionListener {
109 | // TODO: Update argument type and name
110 | void onFragmentInteraction(Uri uri);
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/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/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/drawable/pic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/drawable/pic.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_default.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
22 |
27 |
32 |
33 |
38 |
39 |
44 |
45 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
18 |
23 |
28 |
33 |
34 |
39 |
40 |
45 |
46 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
20 |
21 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_custom.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
16 |
17 |
22 |
23 |
28 |
29 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_empty_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_error_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_loading_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
14 |
15 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menus.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/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/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_smile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-xhdpi/icon_smile.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PageLayoutDemo-java
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/hankkin/pagelayoutdemo_java/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayoutdemo_java;
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 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Oct 13 10:45:17 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-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 |
--------------------------------------------------------------------------------
/pagelayout-java/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/pagelayout-java/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 |
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 26
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.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | implementation 'com.android.support:appcompat-v7:26.1.0'
30 | 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 |
--------------------------------------------------------------------------------
/pagelayout-java/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 |
--------------------------------------------------------------------------------
/pagelayout-java/src/androidTest/java/com/hankkin/pagelayout_java/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayout_java;
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() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.hankkin.pagelayout_java.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pagelayout-java/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/pagelayout-java/src/main/java/com/hankkin/pagelayout_java/BlinkLayout.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayout_java;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.Bitmap;
9 | import android.graphics.Canvas;
10 | import android.graphics.Color;
11 | import android.graphics.LinearGradient;
12 | import android.graphics.Paint;
13 | import android.graphics.PorterDuff;
14 | import android.graphics.PorterDuffXfermode;
15 | import android.graphics.Shader;
16 | import android.os.Build;
17 | import android.support.annotation.ColorInt;
18 | import android.support.annotation.RequiresApi;
19 | import android.support.v4.content.ContextCompat;
20 | import android.util.AttributeSet;
21 | import android.view.ViewTreeObserver;
22 | import android.widget.LinearLayout;
23 |
24 | public class BlinkLayout extends LinearLayout {
25 |
26 | private Paint maskPaint;
27 |
28 | private ValueAnimator maskAnimator;
29 |
30 | private Bitmap localAvailableBitmap;
31 | private Bitmap localMaskBitmap;
32 |
33 | private Bitmap destinationBitmap;
34 | private Bitmap sourceMaskBitmap;
35 | private Canvas canvasForRendering;
36 |
37 | private int maskOffsetX;
38 |
39 | private boolean isAnimationStarted;
40 |
41 | private int shimmerAnimationDuration;
42 |
43 | @ColorInt
44 | private int shimmerColor;
45 |
46 | public BlinkLayout(Context context) {
47 | this(context, null);
48 | }
49 |
50 | public BlinkLayout(Context context, AttributeSet attrs) {
51 | this(context, attrs, 0);
52 | }
53 |
54 | public BlinkLayout(Context context, AttributeSet attrs, int defStyle) {
55 | super(context, attrs, defStyle);
56 |
57 | setWillNotDraw(false);
58 |
59 | maskPaint = new Paint();
60 | maskPaint.setAntiAlias(true);
61 | maskPaint.setDither(true);
62 | maskPaint.setFilterBitmap(true);
63 | maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
64 |
65 | TypedArray a = context.getTheme().obtainStyledAttributes(
66 | attrs,
67 | R.styleable.BlinkLayout,
68 | 0, 0);
69 |
70 | try {
71 | shimmerAnimationDuration = a.getInteger(R.styleable.BlinkLayout_blink_animation_duration, 1500);
72 | shimmerColor = a.getColor(R.styleable.BlinkLayout_blink_color, ContextCompat.getColor(context, R.color.shimmer_color));
73 | } finally {
74 | a.recycle();
75 | }
76 | }
77 |
78 | @Override
79 | protected void onDetachedFromWindow() {
80 | resetShimmering();
81 | super.onDetachedFromWindow();
82 | }
83 |
84 | @Override
85 | protected void dispatchDraw(Canvas canvas) {
86 | if (!isAnimationStarted || getWidth() <= 0 || getHeight() <= 0) {
87 | super.dispatchDraw(canvas);
88 | } else {
89 | dispatchDrawUsingBitmap(canvas);
90 | }
91 | }
92 |
93 | public void startShimmerAnimation() {
94 | if (isAnimationStarted) {
95 | return;
96 | }
97 |
98 | if (getWidth() == 0) {
99 | getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
100 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
101 | @Override
102 | public void onGlobalLayout() {
103 | BlinkLayout.this.getViewTreeObserver().removeOnGlobalLayoutListener(this);
104 | startShimmerAnimation();
105 | }
106 | });
107 |
108 | return;
109 | }
110 |
111 | Animator animator = getShimmerAnimation();
112 | animator.start();
113 | isAnimationStarted = true;
114 | }
115 |
116 | public void stopShimmerAnimation() {
117 | resetShimmering();
118 | }
119 |
120 | public void setShimmerColor(int shimmerColor) {
121 | this.shimmerColor = shimmerColor;
122 |
123 | if (isAnimationStarted) {
124 | resetShimmering();
125 | startShimmerAnimation();
126 | }
127 | }
128 |
129 | private void dispatchDrawUsingBitmap(Canvas canvas) {
130 | super.dispatchDraw(canvas);
131 |
132 | localAvailableBitmap = getDestinationBitmap();
133 | if (localAvailableBitmap == null) {
134 | return;
135 | }
136 |
137 | if (canvasForRendering == null) {
138 | canvasForRendering = new Canvas(localAvailableBitmap);
139 | }
140 |
141 | drawMask(canvasForRendering);
142 | canvas.save();
143 | canvas.clipRect(maskOffsetX, 0, maskOffsetX + getWidth() / 2, getHeight());
144 | canvas.drawBitmap(localAvailableBitmap, 0, 0, null);
145 | canvas.restore();
146 |
147 | localAvailableBitmap = null;
148 | }
149 |
150 | private void drawMask(Canvas renderCanvas) {
151 | localMaskBitmap = getSourceMaskBitmap();
152 | if (localMaskBitmap == null) {
153 | return;
154 | }
155 |
156 | renderCanvas.save();
157 | renderCanvas.clipRect(maskOffsetX, 0,
158 | maskOffsetX + localMaskBitmap.getWidth(),
159 | getHeight());
160 |
161 | super.dispatchDraw(renderCanvas);
162 | renderCanvas.drawBitmap(localMaskBitmap, maskOffsetX, 0, maskPaint);
163 |
164 | renderCanvas.restore();
165 |
166 | localMaskBitmap = null;
167 | }
168 |
169 | private void resetShimmering() {
170 | if (maskAnimator != null) {
171 | maskAnimator.end();
172 | maskAnimator.removeAllUpdateListeners();
173 | }
174 |
175 | maskAnimator = null;
176 | isAnimationStarted = false;
177 |
178 | releaseBitMaps();
179 | }
180 |
181 | private void releaseBitMaps() {
182 | if (sourceMaskBitmap != null) {
183 | sourceMaskBitmap.recycle();
184 | sourceMaskBitmap = null;
185 | }
186 |
187 | if (destinationBitmap != null) {
188 | destinationBitmap.recycle();
189 | destinationBitmap = null;
190 | }
191 |
192 | canvasForRendering = null;
193 | }
194 |
195 | private Bitmap getDestinationBitmap() {
196 | if (destinationBitmap == null) {
197 | destinationBitmap = createBitmap(getWidth(), getHeight());
198 | }
199 |
200 | return destinationBitmap;
201 | }
202 |
203 | private Bitmap getSourceMaskBitmap() {
204 | if (sourceMaskBitmap != null) {
205 | return sourceMaskBitmap;
206 | }
207 |
208 | int width = getWidth() / 2;
209 | int height = getHeight();
210 |
211 | sourceMaskBitmap = createBitmap(width, height);
212 | Canvas canvas = new Canvas(sourceMaskBitmap);
213 |
214 | LinearGradient gradient = new LinearGradient(
215 | 0, 0,
216 | width, 0,
217 | new int[]{Color.TRANSPARENT, shimmerColor, shimmerColor, Color.TRANSPARENT},
218 | new float[]{0.25F, 0.5F, 0.5F, 0.75F},
219 | Shader.TileMode.CLAMP);
220 |
221 | canvas.rotate(20, width / 2, height / 2);
222 |
223 | Paint paint = new Paint();
224 | paint.setShader(gradient);
225 | int padding = (int) (Math.sqrt(2) * Math.max(width, height)) / 2;
226 | canvas.drawRect(0, -padding, width, height + padding, paint);
227 |
228 | return sourceMaskBitmap;
229 | }
230 |
231 | private Animator getShimmerAnimation() {
232 | if (maskAnimator != null) {
233 | return maskAnimator;
234 | }
235 |
236 | final int animationToX = getWidth();
237 | final int animationFromX = -animationToX;
238 | final int shimmerBitmapWidth = getWidth() / 2;
239 | final int shimmerAnimationFullLength = animationToX - animationFromX;
240 |
241 | maskAnimator = ValueAnimator.ofFloat(0.0F, 1.0F);
242 | maskAnimator.setDuration(shimmerAnimationDuration);
243 | maskAnimator.setRepeatCount(ObjectAnimator.INFINITE);
244 |
245 | final float[] value = new float[1];
246 | maskAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
247 | @Override
248 | public void onAnimationUpdate(ValueAnimator animation) {
249 | value[0] = (Float) animation.getAnimatedValue();
250 | maskOffsetX = ((int) (animationFromX + shimmerAnimationFullLength * value[0]));
251 |
252 | if (maskOffsetX + shimmerBitmapWidth >= 0) {
253 | invalidate();
254 | }
255 | }
256 | });
257 |
258 | return maskAnimator;
259 | }
260 |
261 | private Bitmap createBitmap(int width, int height) {
262 | try {
263 | return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
264 | } catch (OutOfMemoryError e) {
265 | System.gc();
266 | return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
267 | }
268 | }
269 | }
--------------------------------------------------------------------------------
/pagelayout-java/src/main/java/com/hankkin/pagelayout_java/PageLayout.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayout_java;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.content.Context;
6 | import android.graphics.drawable.Drawable;
7 | import android.os.Looper;
8 | import android.support.annotation.NonNull;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.FrameLayout;
15 | import android.widget.TextView;
16 |
17 |
18 | /**
19 | * Created by ${Hankkin} on 2018/10/12.
20 | */
21 |
22 | public class PageLayout extends FrameLayout {
23 |
24 | enum State {
25 | EMPTY_TYPE,
26 | LOADING_TYPE,
27 | ERROR_TYPE,
28 | CONTENT_TYPE,
29 | CUSTOM_TYPE
30 | }
31 |
32 | private View mLoading;
33 | private View mEmpty;
34 | private View mError;
35 | private View mContent;
36 | private View mCustom;
37 | private Context mContext;
38 | private BlinkLayout mBlinkLayout;
39 | private State mCurrentState;
40 |
41 | public PageLayout(@NonNull Context context) {
42 | super(context);
43 | }
44 |
45 | public PageLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
46 | super(context, attrs);
47 | }
48 |
49 | public PageLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
50 | super(context, attrs, defStyleAttr);
51 | }
52 |
53 | private void showView(final State state) {
54 | if (Looper.myLooper() == Looper.getMainLooper()) {
55 | changeView(state);
56 | } else {
57 | post(new Runnable() {
58 | @Override
59 | public void run() {
60 | changeView(state);
61 | }
62 | });
63 | }
64 | }
65 |
66 | private void changeView(State state) {
67 | mCurrentState = state;
68 | setViewGone();
69 | switch (state) {
70 | case LOADING_TYPE:
71 | mLoading.setVisibility(VISIBLE);
72 | break;
73 | case EMPTY_TYPE:
74 | mEmpty.setVisibility(VISIBLE);
75 | break;
76 | case ERROR_TYPE:
77 | mError.setVisibility(VISIBLE);
78 | break;
79 | case CUSTOM_TYPE:
80 | if (mCustom != null)
81 | mCustom.setVisibility(VISIBLE);
82 | break;
83 | case CONTENT_TYPE:
84 | mContent.setVisibility(VISIBLE);
85 | break;
86 | }
87 | }
88 |
89 | private void setViewGone() {
90 | mLoading.setVisibility(GONE);
91 | mEmpty.setVisibility(GONE);
92 | mError.setVisibility(GONE);
93 | mContent.setVisibility(GONE);
94 | if (mCustom != null) {
95 | mCustom.setVisibility(GONE);
96 | }
97 | }
98 |
99 | public void showLoading() {
100 | showView(State.LOADING_TYPE);
101 | if (mBlinkLayout != null) {
102 | mBlinkLayout.startShimmerAnimation();
103 | }
104 | }
105 |
106 | public void showError() {
107 | showView(State.ERROR_TYPE);
108 | }
109 |
110 | public void showEmpty() {
111 | showView(State.EMPTY_TYPE);
112 | }
113 |
114 | public void hide() {
115 | showView(State.CONTENT_TYPE);
116 | if (mBlinkLayout != null) {
117 | mBlinkLayout.stopShimmerAnimation();
118 | }
119 | }
120 |
121 | public void showCustom() {
122 | showView(State.CUSTOM_TYPE);
123 | }
124 |
125 | public static class Builder {
126 | private PageLayout mPageLayout;
127 | private LayoutInflater mInflater;
128 | private Context mContext;
129 | private TextView mTvEmpty;
130 | private TextView mTvError;
131 | private TextView mTvErrorRetry;
132 | private TextView mTvLoading;
133 | private TextView mTvLoadingBlink;
134 | private BlinkLayout mBlinkLayout;
135 | private OnRetryClickListener mOnRetryClickListener;
136 |
137 | public Builder(Context context) {
138 | mContext = context;
139 | this.mPageLayout = new PageLayout(mContext);
140 | this.mInflater = LayoutInflater.from(mContext);
141 | }
142 |
143 | private void initDefault() {
144 | if (mPageLayout.mEmpty == null) {
145 | setDefaultEmpty();
146 | }
147 | if (mPageLayout.mError == null) {
148 | setDefaultError();
149 | }
150 | if (mPageLayout.mLoading == null) {
151 | setDefaultLoading();
152 | }
153 |
154 | }
155 |
156 | private void setDefaultEmpty() {
157 | mPageLayout.mEmpty = mInflater.inflate(R.layout.layout_empty, mPageLayout, false);
158 | mTvEmpty = mPageLayout.mEmpty.findViewById(R.id.tv_page_empty);
159 | mPageLayout.mEmpty.setVisibility(GONE);
160 | mPageLayout.addView(mPageLayout.mEmpty);
161 | }
162 |
163 | private void setDefaultError() {
164 | mPageLayout.mError = mInflater.inflate(R.layout.layout_error, mPageLayout, false);
165 | mTvError = mPageLayout.mError.findViewById(R.id.tv_page_error);
166 | mTvErrorRetry = mPageLayout.mError.findViewById(R.id.tv_page_error_retry);
167 | mTvErrorRetry.setOnClickListener(new OnClickListener() {
168 | @Override
169 | public void onClick(View view) {
170 | if (mOnRetryClickListener != null) {
171 | mOnRetryClickListener.onRetry();
172 | }
173 | }
174 | });
175 | mPageLayout.mError.setVisibility(GONE);
176 | mPageLayout.addView(mPageLayout.mError);
177 | }
178 |
179 |
180 | private void setDefaultLoading() {
181 | mPageLayout.mLoading = mInflater.inflate(R.layout.layout_loading, mPageLayout, false);
182 | mBlinkLayout = mPageLayout.mLoading.findViewById(R.id.java_blinklayout);
183 | mPageLayout.mBlinkLayout = mBlinkLayout;
184 | mTvLoadingBlink = mPageLayout.mLoading.findViewById(R.id.tv_page_loading_blink);
185 | mPageLayout.mLoading.setVisibility(GONE);
186 | mPageLayout.addView(mPageLayout.mLoading);
187 | }
188 |
189 | /**
190 | * 设置loading布局
191 | */
192 | public Builder setLoading(int loadingId, int loadingTvId) {
193 | View loading = mInflater.inflate(loadingId, mPageLayout, false);
194 | mTvLoading = loading.findViewById(loadingTvId);
195 | mPageLayout.mLoading = loading;
196 | mPageLayout.addView(loading);
197 | return this;
198 | }
199 |
200 | /**
201 | * 自定义错误布局
202 | * 默认样式,传入错误文案ID,及点击回调
203 | */
204 | public Builder setError(int errorId, int errorClickId, final OnRetryClickListener onRetryClickListener) {
205 | View error = mInflater.inflate(errorId, mPageLayout, false);
206 | mPageLayout.mError = error;
207 | mPageLayout.addView(error);
208 | mTvError = error.findViewById(errorClickId);
209 | mTvError.setOnClickListener(new OnClickListener() {
210 | @Override
211 | public void onClick(View view) {
212 | onRetryClickListener.onRetry();
213 | }
214 | });
215 | return this;
216 | }
217 |
218 | /**
219 | * 自定义错误布局
220 | * 设置前需手动初始化好View中各个事件
221 | */
222 | public Builder setError(View error) {
223 | mPageLayout.mError = error;
224 | mPageLayout.addView(error);
225 | return this;
226 | }
227 |
228 | /**
229 | * 自定义空布局
230 | */
231 | public Builder setEmpty(int empty, int emptyTvId) {
232 | View view = mInflater.inflate(empty, mPageLayout, false);
233 | mTvEmpty = view.findViewById(emptyTvId);
234 | mPageLayout.mEmpty = view;
235 | mPageLayout.addView(view);
236 | return this;
237 | }
238 |
239 | /**
240 | * 自定义布局
241 | */
242 | public Builder setCustomView(View view) {
243 | mPageLayout.mCustom = view;
244 | mPageLayout.addView(view);
245 | return this;
246 | }
247 |
248 | /**
249 | * 设置加载文案
250 | */
251 | public Builder setLoadingText(String text) {
252 | mTvLoading.setText(text);
253 | return this;
254 | }
255 |
256 | /**
257 | * 设置默认闪烁加载文案
258 | */
259 | public Builder setDefaultLoadingBlinkText(String text) {
260 | mTvLoadingBlink.setText(text);
261 | return this;
262 | }
263 |
264 |
265 | /**
266 | * 设置加载文字颜色
267 | */
268 | public Builder setLoadingTextColor(int color) {
269 | mTvLoading.setTextColor(mContext.getResources().getColor(color));
270 | return this;
271 | }
272 |
273 | /**
274 | * 设置默认加载闪烁颜色
275 | */
276 | public Builder setDefaultLoadingBlinkColor(int color) {
277 | mBlinkLayout.setShimmerColor(mContext.getResources().getColor(color));
278 | return this;
279 | }
280 |
281 | /**
282 | * 设置默认空布局文案
283 | */
284 | public Builder setDefaultEmptyText(String text) {
285 | mTvEmpty.setText(text);
286 | return this;
287 | }
288 |
289 | /**
290 | * 设置默认空布局文案颜色
291 | */
292 | public Builder setDefaultEmptyTextColor(int color) {
293 | mTvEmpty.setTextColor(mContext.getResources().getColor(color));
294 | return this;
295 | }
296 |
297 | /**
298 | * 设置默认错误布局文案
299 | */
300 | public Builder setDefaultErrorText(String text) {
301 | mTvError.setText(text);
302 | return this;
303 | }
304 |
305 |
306 | /**
307 | * 设置默认错误布局文案颜色
308 | */
309 | public Builder setDefaultErrorTextColor(int color) {
310 | mTvError.setTextColor(mContext.getResources().getColor(color));
311 | return this;
312 | }
313 |
314 | /**
315 | * 设置默认错误布局重试文案
316 | */
317 | public Builder setDefaultErrorRetryText(String text) {
318 | mTvErrorRetry.setText(text);
319 | return this;
320 | }
321 |
322 | /**
323 | * 设置默认错误布局重试文案颜色
324 | */
325 | public Builder setDefaultErrorRetryTextColor(int color) {
326 | mTvErrorRetry.setTextColor(mContext.getResources().getColor(color));
327 | return this;
328 | }
329 |
330 | /**
331 | * 设置空布局提醒图片
332 | */
333 | public Builder setEmptyDrawable(int resId) {
334 | setTopDrawables(mTvEmpty, resId);
335 | return this;
336 | }
337 |
338 | /**
339 | * 设置错误布局提醒图片
340 | */
341 | public Builder setErrorDrawable(int resId) {
342 | setTopDrawables(mTvError, resId);
343 | return this;
344 | }
345 |
346 |
347 | /**
348 | * 设置布局top drawable
349 | */
350 | private Builder setTopDrawables(TextView textView, int resId) {
351 | if (resId == 0) {
352 | textView.setCompoundDrawables(null, null, null, null);
353 | }
354 | Drawable drawable = mContext.getResources().getDrawable(resId);
355 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//必须设置图片大小,否则不显示
356 | textView.setCompoundDrawables(null, drawable, null, null);
357 | textView.setCompoundDrawablePadding(20);
358 | return this;
359 | }
360 |
361 | public Builder initPage(Object targetView) {
362 | ViewGroup content = null;
363 | if (targetView instanceof Activity) {
364 | mContext = (Context) targetView;
365 | content = ((Activity) targetView).findViewById(android.R.id.content);
366 | } else if (targetView instanceof Fragment) {
367 | mContext = ((Fragment) targetView).getActivity();
368 | content = (ViewGroup) ((Fragment) targetView).getView().getParent();
369 | } else if (targetView instanceof android.support.v4.app.Fragment) {//新增V4Fragment
370 | mContext = ((android.support.v4.app.Fragment) targetView).getActivity();
371 | content = (ViewGroup) ((android.support.v4.app.Fragment) targetView).getView().getParent();
372 | }else if (targetView instanceof View) {
373 | mContext = ((View) targetView).getContext();
374 | content = (ViewGroup) ((View) targetView).getParent();
375 | }
376 | if (content != null) {
377 | int childCount = content.getChildCount();
378 | int index = 0;
379 | View oldContent = null;
380 | if (targetView instanceof View) {
381 | oldContent = (View) targetView;
382 | for (int i = 0; i < childCount; i++) {
383 | if (content.getChildAt(i) == oldContent) {
384 | index = i;
385 | break;
386 | }
387 | }
388 | } else {
389 | oldContent = content.getChildAt(0);
390 | }
391 | mPageLayout.mContent = oldContent;
392 | mPageLayout.removeAllViews();
393 | content.removeView(oldContent);
394 | ViewGroup.LayoutParams params = oldContent.getLayoutParams();
395 | content.addView(mPageLayout, index, params);
396 | mPageLayout.addView(oldContent);
397 | initDefault();
398 | }
399 | return this;
400 | }
401 |
402 | public Builder setOnRetryListener(OnRetryClickListener onRetryListener) {
403 | this.mOnRetryClickListener = onRetryListener;
404 | return this;
405 | }
406 |
407 | public PageLayout create() {
408 | return mPageLayout;
409 | }
410 |
411 | }
412 |
413 | public interface OnRetryClickListener {
414 | void onRetry();
415 | }
416 | }
417 |
--------------------------------------------------------------------------------
/pagelayout-java/src/main/res/drawable/pic_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/pagelayout-java/src/main/res/drawable/pic_empty.png
--------------------------------------------------------------------------------
/pagelayout-java/src/main/res/drawable/pic_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/PageLayoutDemojava/e6a7c91479dffb2a597c9759098952bf9a605874/pagelayout-java/src/main/res/drawable/pic_error.png
--------------------------------------------------------------------------------
/pagelayout-java/src/main/res/layout/layout_empty.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/pagelayout-java/src/main/res/layout/layout_error.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
28 |
29 |
--------------------------------------------------------------------------------
/pagelayout-java/src/main/res/layout/layout_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/pagelayout-java/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ff662c
4 | #ff662c
5 | #ff662c
6 | #b1b1b1
7 | #a2878787
8 |
9 |
10 |
--------------------------------------------------------------------------------
/pagelayout-java/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | EmptyPage
3 | 网络开小差了
4 | 点击重试
5 | 暂无新数据
6 |
7 |
--------------------------------------------------------------------------------
/pagelayout-java/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/pagelayout-java/src/test/java/com/hankkin/pagelayout_java/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.pagelayout_java;
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() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app' ,':pagelayout-java'
2 |
--------------------------------------------------------------------------------