From 09e4cd95bebcaa68cb40dca08af0d48fdab2fce8 Mon Sep 17 00:00:00 2001 From: nukc <353932158@qq.com> Date: Thu, 22 Sep 2016 14:07:46 +0800 Subject: [PATCH] update inject(activity) ..., deprecated inject(activity, hasActionBar) --- README-en.md | 121 ------------- README-zh.md | 170 ++++++++++++++++++ README.md | 127 ++++--------- app/build.gradle | 14 +- .../github/nukc/sample/CustomActivity.java | 2 +- .../github/nukc/sample/InjectActivity.java | 2 +- app/src/main/res/layout/view_empty.xml | 4 +- app/src/main/res/layout/view_retry.xml | 4 +- bintray.gradle | 2 +- library/build.gradle | 8 +- .../com/github/nukc/stateview/StateView.java | 22 ++- library/src/main/res/layout/base_empty.xml | 4 +- library/src/main/res/layout/base_retry.xml | 6 +- 13 files changed, 255 insertions(+), 231 deletions(-) delete mode 100644 README-en.md create mode 100644 README-zh.md diff --git a/README-en.md b/README-en.md deleted file mode 100644 index 5819316..0000000 --- a/README-en.md +++ /dev/null @@ -1,121 +0,0 @@ -# StateView - -[ ![Download](https://api.bintray.com/packages/nukc/maven/StateView/images/download.svg) ](https://bintray.com/nukc/maven/StateView/_latestVersion) -[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-StateView-green.svg?style=true)](https://android-arsenal.com/details/1/4255) - -StateView is a lightweight view that absorb characteristics of ViewStub. It can occupy less memory that the initia state is not visible and does not occupy the position of the layout. When the operation show empty / retry / loading view, -it will be added to the layout. - - - -## Installation - -add the dependency to your build.gradle: - -```groovy - compile 'com.github.nukc.stateview:library:0.3.4' -``` - -##Usage - -Include the StateView widget in your layout. - -```xml - - - -``` - -To switch the state view: - -- ```mStateView.showEmpty();``` -- ```mStateView.showLoading();``` -- ```mStateView.showRetry();``` -- ``` mStateView.showContent();``` - -To listen the retry click: - -```java - mStateView.setOnRetryClickListener(new StateView.OnRetryClickListener() { - @Override - public void onRetryClick() { - //do something, no need to call showLoading() - } - }); -``` - -To customize view: - -- Global settings way: create a new layout (layout's name must be ```base_empty```/```base_retry```/```base_loading```). - -- Single page setting: create a new layout whit different name, and set resource in java. - -```java -setEmptyResource(@LayoutRes int emptyResource) - -setRetryResource(@LayoutRes int retryResource) - -setLoadingResource(@LayoutRes int loadingResource) -``` - - -Can be directly used in java. - -```java - mStateView = StateView.inject(Activity activity); - //if has actionbar/toolbar - mStateView = StateView.inject(activity, true); -``` - -```java - mStateView = StateView.inject(ViewGroup parent); - - mStateView = StateView.inject(ViewGroup parent, boolean hasActionBar); -``` - -```java - //can be use in onCreateView of Fragment - mStateView = StateView.inject(View view); - - mStateView = StateView.inject(View view, boolean hasActionBar); -``` - -## Custom Attribute - -```xml - - - - - - - -``` - - -## License - - The MIT License (MIT) - - Copyright (c) 2016 Nukc - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. \ No newline at end of file diff --git a/README-zh.md b/README-zh.md new file mode 100644 index 0000000..b5e6cd7 --- /dev/null +++ b/README-zh.md @@ -0,0 +1,170 @@ +# StateView + +[ ![Download](https://api.bintray.com/packages/nukc/maven/StateView/images/download.svg) ](https://bintray.com/nukc/maven/StateView/_latestVersion) +[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-StateView-green.svg?style=true)](https://android-arsenal.com/details/1/4255) + +StateView一个轻量级的控件, 继承自`View`, 吸收了`ViewStub`的一些特性, 初始状态下是不可见的, 不占布局位置, 占用内存少。 +当进行操作显示空/重试/加载视图后, 该视图才会被添加到布局中。所以当用不到显示视图的时候, 占用内存是很少的。 +由于目前只有3个视图, 所以至多只会添加3次, 相对于其他具有同样功能的一些控件, StateView更具有优势。 + + + + +```groovy + compile 'com.github.nukc.stateview:library:0.3.5' +``` + +## 使用方法 + +直接在代码中使用: + +- 注入到Activity +```java + mStateView = StateView.inject(Activity activity); +``` + +- 注入到ViewGroup +```java + mStateView = StateView.inject(ViewGroup parent); + + mStateView = StateView.inject(ViewGroup parent, boolean hasActionBar); +``` + +```java + //可用于在Fragment的onCreateView中 + mStateView = StateView.inject(View view); + + mStateView = StateView.inject(View view, boolean hasActionBar); +``` + +或添加到布局: + +```xml + + + +``` + +- 显示空视图: ```mStateView.showEmpty();``` +- 显示加载视图: ```mStateView.showLoading();``` +- 显示重试视图: ```mStateView.showRetry();``` +- 显示内容: ``` mStateView.showContent();``` + +设置重试点击事件: + +```java + mStateView.setOnRetryClickListener(new StateView.OnRetryClickListener() { + @Override + public void onRetryClick() { + //do something, no need to call showLoading() + //不需要调用showLoading()方法, StateView自会调用 + } + }); +``` + +设置自定义视图: + +- 全局设置办法:在自己项目的layout下新建, 名字跟StateView默认layout一样即可(也不用代码设置). +默认layout的名字:```base_empty```/```base_retry```/```base_loading```. + +- 单页面设置:layout名字不一样, 然后再代码设置. + +```java +setEmptyResource(@LayoutRes int emptyResource) + +setRetryResource(@LayoutRes int retryResource) + +setLoadingResource(@LayoutRes int loadingResource) +``` + + +## Custom Attribute + +```xml + + + + + + + +``` + +## ChangeLog + +#### Version 0.3.5 +更改inject(activity)方法, 不直接添加到DecorView中, 而加到Content中. +Deprecated几个方法. + +#### Version 0.3.3 +增加自定义视图的Sample; +修改library的默认layout名字 + +#### Version 0.3.2 +进一步测试, 增加Sample; +删除没必要的方法, 考虑到注入不应该遮挡工具栏, 为此增加inject方法 + +#### Version 0.3.1 +增加静态方法: +inject(View view),该参数view必须是viewGroup,可用于在Fragment中 + +#### Version 0.3.0 +增加静态方法: +inject(Activity activity),用于把StateView添加到DecorView中; + +inject(ViewGroup parent),用于添加到ViewGroup中 + +#### Version: 0.2.4 +修复显示LoadingView后还能触摸下层的View + +#### Version: 0.2.3 +修复 [issues #2](https://github.com/nukc/StateView/issues/2) + +#### Version: 0.2.1 +更新gradle和library版本, 增加一个私有方法showView。 + +#### Version: 0.2.0 +修复v0.1.0版本中当使用layout_below的时候addView可能无法正常显示的问题。 + +#### Version: 0.1.0 +测试Sample得知: +```xml + +``` + 使用 android:layout_below="@+id/ll" 的话 , addView有时会无法正常显示,有时却正常。在寻找问题。。 + + 3个按钮错乱多按几次,有几率会出现不显示的情况。 + + + +## License + + The MIT License (MIT) + + Copyright (c) 2016 Nukc + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 85e9246..64f5660 100644 --- a/README.md +++ b/README.md @@ -3,23 +3,44 @@ [ ![Download](https://api.bintray.com/packages/nukc/maven/StateView/images/download.svg) ](https://bintray.com/nukc/maven/StateView/_latestVersion) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-StateView-green.svg?style=true)](https://android-arsenal.com/details/1/4255) -[English](https://github.com/nukc/StateView/blob/master/README-en.md) +[中文](https://github.com/nukc/StateView/blob/master/README-zh.md) -StateView一个轻量级的控件, 继承自`View`, 吸收了`ViewStub`的一些特性, 初始状态下是不可见的, 不占布局位置, 占用内存少。 -当进行操作显示空/重试/加载视图后, 该视图才会被添加到布局中。所以当用不到显示视图的时候, 占用内存是很少的。 -由于目前只有3个视图, 所以至多只会添加3次, 相对于其他具有同样功能的一些控件, StateView更具有优势。 +StateView is a lightweight view that absorb characteristics of ViewStub. It can occupy less memory that the initia state is not visible and does not occupy the position of the layout. When the operation show empty / retry / loading view, +it will be added to the layout. -## 安装 +## Installation + +add the dependency to your build.gradle: ```groovy - compile 'com.github.nukc.stateview:library:0.3.4' + compile 'com.github.nukc.stateview:library:0.3.5' +``` + +##Usage + +Can be directly used in java. + +```java + mStateView = StateView.inject(Activity activity); +``` + +```java + mStateView = StateView.inject(ViewGroup parent); + + mStateView = StateView.inject(ViewGroup parent, boolean hasActionBar); ``` -## 使用方法 +```java + //can be use in onCreateView of Fragment + mStateView = StateView.inject(View view); -添加到布局: + mStateView = StateView.inject(View view, boolean hasActionBar); +``` + + +Or include the StateView widget in your layout. ```xml @@ -30,29 +51,29 @@ StateView一个轻量级的控件, 继承自`View`, 吸收了`ViewStub`的一些 ``` -- 显示空视图: ```mStateView.showEmpty();``` -- 显示加载视图: ```mStateView.showLoading();``` -- 显示重试视图: ```mStateView.showRetry();``` -- 显示内容: ``` mStateView.showContent();``` +To switch the state view: + +- ```mStateView.showEmpty();``` +- ```mStateView.showLoading();``` +- ```mStateView.showRetry();``` +- ``` mStateView.showContent();``` -设置重试点击事件: +To listen the retry click: ```java mStateView.setOnRetryClickListener(new StateView.OnRetryClickListener() { @Override public void onRetryClick() { //do something, no need to call showLoading() - //不需要调用showLoading()方法, StateView自会调用 } }); ``` -设置自定义视图: +To customize view: -- 全局设置办法:在自己项目的layout下新建, 名字跟StateView默认layout一样即可(也不用代码设置). -默认layout的名字:```base_empty```/```base_retry```/```base_loading```. +- Global settings way: create a new layout (layout's name must be ```base_empty```/```base_retry```/```base_loading```). -- 单页面设置:layout名字不一样, 然后再代码设置. +- Single page setting: create a new layout whit different name, and set resource in java. ```java setEmptyResource(@LayoutRes int emptyResource) @@ -63,29 +84,6 @@ setLoadingResource(@LayoutRes int loadingResource) ``` -或直接在代码中使用: - -- 注入到Activity -```java - mStateView = StateView.inject(Activity activity); - //如果有actionbar/toolbar - mStateView = StateView.inject(activity, true); -``` - -- 注入到ViewGroup -```java - mStateView = StateView.inject(ViewGroup parent); - - mStateView = StateView.inject(ViewGroup parent, boolean hasActionBar); -``` - -```java - //可用于在Fragment的onCreateView中 - mStateView = StateView.inject(View view); - - mStateView = StateView.inject(View view, boolean hasActionBar); -``` - ## Custom Attribute ```xml @@ -98,53 +96,6 @@ setLoadingResource(@LayoutRes int loadingResource) ``` -## ChangeLog - -#### Version 0.3.3 -增加自定义视图的Sample; -修改library的默认layout名字 - -#### Version 0.3.2 -进一步测试, 增加Sample; -删除没必要的方法, 考虑到注入不应该遮挡工具栏, 为此增加inject方法 - -#### Version 0.3.1 -增加静态方法: -inject(View view),该参数view必须是viewGroup,可用于在Fragment中 - -#### Version 0.3.0 -增加静态方法: -inject(Activity activity),用于把StateView添加到DecorView中; - -inject(ViewGroup parent),用于添加到ViewGroup中 - -#### Version: 0.2.4 -修复显示LoadingView后还能触摸下层的View - -#### Version: 0.2.3 -修复 [issues #2](https://github.com/nukc/StateView/issues/2) - -#### Version: 0.2.1 -更新gradle和library版本, 增加一个私有方法showView。 - -#### Version: 0.2.0 -修复v0.1.0版本中当使用layout_below的时候addView可能无法正常显示的问题。 - -#### Version: 0.1.0 -测试Sample得知: -```xml - -``` - 使用 android:layout_below="@+id/ll" 的话 , addView有时会无法正常显示,有时却正常。在寻找问题。。 - - 3个按钮错乱多按几次,有几率会出现不显示的情况。 - - ## License diff --git a/app/build.gradle b/app/build.gradle index 1d069f9..907748e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion "23.0.2" + compileSdkVersion 24 + buildToolsVersion "23.0.3" defaultConfig { applicationId "com.github.nukc.sample" - minSdkVersion 8 - targetSdkVersion 23 + minSdkVersion 9 + targetSdkVersion 24 versionCode 1 versionName "1.0" } @@ -23,7 +23,7 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile project(':library') - compile 'com.android.support:appcompat-v7:23.4.0' - compile 'com.android.support:design:23.4.0' - compile 'com.android.support:support-v4:23.4.0' + compile 'com.android.support:appcompat-v7:24.2.0' + compile 'com.android.support:design:24.2.0' + compile 'com.android.support:support-v4:24.2.0' } diff --git a/app/src/main/java/com/github/nukc/sample/CustomActivity.java b/app/src/main/java/com/github/nukc/sample/CustomActivity.java index 7d58a6e..e69f53e 100644 --- a/app/src/main/java/com/github/nukc/sample/CustomActivity.java +++ b/app/src/main/java/com/github/nukc/sample/CustomActivity.java @@ -17,7 +17,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom); - mStateView = StateView.inject(this, true); + mStateView = StateView.inject(this); mStateView.setEmptyResource(R.layout.view_empty); mStateView.setRetryResource(R.layout.view_retry); diff --git a/app/src/main/java/com/github/nukc/sample/InjectActivity.java b/app/src/main/java/com/github/nukc/sample/InjectActivity.java index 7996837..6511dd5 100644 --- a/app/src/main/java/com/github/nukc/sample/InjectActivity.java +++ b/app/src/main/java/com/github/nukc/sample/InjectActivity.java @@ -19,7 +19,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_inject); - mStateView = StateView.inject(this, true); + mStateView = StateView.inject(this); mStateView.setOnRetryClickListener(new StateView.OnRetryClickListener() { @Override diff --git a/app/src/main/res/layout/view_empty.xml b/app/src/main/res/layout/view_empty.xml index d97b0a9..7849c08 100644 --- a/app/src/main/res/layout/view_empty.xml +++ b/app/src/main/res/layout/view_empty.xml @@ -1,10 +1,12 @@ + android:orientation="vertical" + app:theme="@style/Theme.AppCompat.Light"> + android:orientation="vertical" + app:theme="@style/Theme.AppCompat.Light"> + android:background="@android:color/white" + app:theme="@style/Theme.AppCompat.Light"> + xmlns:app="http://schemas.android.com/apk/res-auto" + android:background="@android:color/white" + app:theme="@style/Theme.AppCompat.Light"> + android:text="@string/text_retry" /> \ No newline at end of file