├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.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 │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── bigkoo │ │ │ │ └── kata │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── bigkoo │ │ │ └── kata │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── bigkoo │ │ └── kata │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── katafoundation ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ └── colors.xml │ │ │ └── layout │ │ │ │ ├── include_list.xml │ │ │ │ └── include_listram.xml │ │ ├── .DS_Store │ │ ├── java │ │ │ ├── .DS_Store │ │ │ └── com │ │ │ │ ├── .DS_Store │ │ │ │ └── bigkoo │ │ │ │ ├── .DS_Store │ │ │ │ ├── katafoundation │ │ │ │ ├── activity │ │ │ │ │ ├── BaseDetailActivity.java │ │ │ │ │ ├── BaseListActivity.java │ │ │ │ │ ├── BaseDataActivity.java │ │ │ │ │ ├── BaseActivity.java │ │ │ │ │ └── BaseListRAMActivity.java │ │ │ │ ├── fragment │ │ │ │ │ ├── BaseDetailFragment.java │ │ │ │ │ ├── BaseListFragment.java │ │ │ │ │ ├── BaseDataFragment.java │ │ │ │ │ ├── BaseLazyFragment.java │ │ │ │ │ ├── BaseFragment.java │ │ │ │ │ └── BaseListRAMFragment.java │ │ │ │ ├── mvpview │ │ │ │ │ └── BaseListRAMView.java │ │ │ │ ├── presenter │ │ │ │ │ └── BaseListRAMPresenter.java │ │ │ │ └── manager │ │ │ │ │ └── AppManager.java │ │ │ │ └── utils │ │ │ │ ├── OSUtils.java │ │ │ │ ├── StatusBarUtil.java │ │ │ │ └── SystemBarTintManager.java │ │ └── AndroidManifest.xml │ ├── .DS_Store │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── bigkoo │ │ │ └── katafoundation │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── bigkoo │ │ └── katafoundation │ │ └── ExampleInstrumentedTest.java ├── .DS_Store ├── build.gradle └── proguard-rules.pro ├── kataframework ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ └── strings.xml │ │ │ └── .DS_Store │ │ ├── .DS_Store │ │ ├── java │ │ │ ├── .DS_Store │ │ │ └── com │ │ │ │ ├── .DS_Store │ │ │ │ └── bigkoo │ │ │ │ ├── .DS_Store │ │ │ │ └── kataframework │ │ │ │ ├── mvpview │ │ │ │ ├── IBaseView.java │ │ │ │ ├── BaseDetailView.java │ │ │ │ ├── BaseListView.java │ │ │ │ └── BaseDataView.java │ │ │ │ ├── http │ │ │ │ ├── constants │ │ │ │ │ └── HttpStatusConstants.java │ │ │ │ └── observer │ │ │ │ │ └── HttpResultObserver.java │ │ │ │ ├── mvppresenter │ │ │ │ ├── BasePresenter.java │ │ │ │ ├── BaseAppPresenter.java │ │ │ │ ├── BaseDetailPresenter.java │ │ │ │ ├── BaseDataPresenter.java │ │ │ │ └── BaseListPresenter.java │ │ │ │ ├── bean │ │ │ │ └── HttpResult.java │ │ │ │ ├── rx │ │ │ │ ├── RxBus.java │ │ │ │ └── MainThread.java │ │ │ │ └── utils │ │ │ │ └── TUtil.java │ │ └── AndroidManifest.xml │ ├── .DS_Store │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── bigkoo │ │ │ └── kataframework │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── bigkoo │ │ └── kataframework │ │ └── ExampleInstrumentedTest.java ├── .DS_Store ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── .DS_Store ├── .gitattributes ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── vcs.xml ├── misc.xml ├── runConfigurations.xml ├── modules.xml └── codeStyles │ └── Project.xml ├── README.md ├── gradle.properties ├── .gitignore ├── gradlew.bat ├── gradlew └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /katafoundation/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /kataframework/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':kataframework', ':katafoundation' 2 | -------------------------------------------------------------------------------- /kataframework/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/.DS_Store -------------------------------------------------------------------------------- /katafoundation/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /kataframework/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/kataframework/.DS_Store -------------------------------------------------------------------------------- /katafoundation/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/katafoundation/.DS_Store -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Kata 3 | 4 | -------------------------------------------------------------------------------- /katafoundation/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/katafoundation/src/.DS_Store -------------------------------------------------------------------------------- /kataframework/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/kataframework/src/.DS_Store -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /katafoundation/src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/katafoundation/src/main/.DS_Store -------------------------------------------------------------------------------- /kataframework/src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/kataframework/src/main/.DS_Store -------------------------------------------------------------------------------- /kataframework/src/main/res/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/kataframework/src/main/res/.DS_Store -------------------------------------------------------------------------------- /katafoundation/src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/katafoundation/src/main/java/.DS_Store -------------------------------------------------------------------------------- /kataframework/src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/kataframework/src/main/java/.DS_Store -------------------------------------------------------------------------------- /kataframework/src/main/java/com/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/kataframework/src/main/java/com/.DS_Store -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/katafoundation/src/main/java/com/.DS_Store -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/kataframework/src/main/java/com/bigkoo/.DS_Store -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /katafoundation/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/katafoundation/src/main/java/com/bigkoo/.DS_Store -------------------------------------------------------------------------------- /kataframework/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saiwu-bigkoo/Android-Kata/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /katafoundation/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6EB7DC 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/mvpview/IBaseView.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.mvpview; 2 | 3 | /** 4 | * Created by Sai on 2018/3/15. 5 | */ 6 | 7 | public interface IBaseView { 8 | } 9 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/mvpview/BaseDetailView.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.mvpview; 2 | 3 | /** 4 | * Created by Sai on 2018/3/15. 5 | */ 6 | 7 | public interface BaseDetailView extends BaseDataView { 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 16 20:16:34 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-4.10.1-all.zip 7 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/mvpview/BaseListView.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.mvpview; 2 | 3 | /** 4 | * Created by sai on 2018/3/17. 5 | */ 6 | 7 | public interface BaseListView extends BaseDataView { 8 | void onLoadingMore(boolean isLoadingMore); 9 | } 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/http/constants/HttpStatusConstants.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.http.constants; 2 | 3 | /** 4 | * Created by Sai on 2018/3/15. 5 | */ 6 | 7 | public class HttpStatusConstants { 8 | public final static int CODE_SUCCESS = 0; 9 | public final static int CODE_DEFAULT = -1; 10 | } 11 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/activity/BaseDetailActivity.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.activity; 2 | 3 | import com.bigkoo.kataframework.mvppresenter.BaseDetailPresenter; 4 | 5 | /** 6 | * Created by Sai on 2018/3/16. 7 | */ 8 | 9 | public abstract class BaseDetailActivity

extends BaseDataActivity

{ 10 | 11 | @Override 12 | protected void initData() { 13 | 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/test/java/com/bigkoo/kata/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kata; 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 | } -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/fragment/BaseDetailFragment.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.fragment; 2 | 3 | import com.bigkoo.kataframework.mvppresenter.BaseDetailPresenter; 4 | 5 | /** 6 | * Created by sai on 2018/3/18. 7 | */ 8 | public abstract class BaseDetailFragment

extends BaseDataFragment

{ 9 | 10 | @Override 11 | protected void initData() { 12 | getPresenter().onLoadData(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /katafoundation/src/main/res/layout/include_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigkoo/kata/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kata; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.bigkoo.katafoundation.activity.BaseActivity; 6 | 7 | public class MainActivity extends BaseActivity { 8 | 9 | 10 | @Override 11 | protected int getLayoutResID() { 12 | return R.layout.activity_main; 13 | } 14 | 15 | @Override 16 | protected void initView() { 17 | 18 | } 19 | 20 | @Override 21 | protected void initData() { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /katafoundation/src/test/java/com/bigkoo/katafoundation/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation; 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 | } -------------------------------------------------------------------------------- /kataframework/src/test/java/com/bigkoo/kataframework/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework; 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 | } -------------------------------------------------------------------------------- /katafoundation/src/main/res/layout/include_listram.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/mvpview/BaseListRAMView.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.mvpview; 2 | 3 | import android.view.View; 4 | 5 | import com.chad.library.adapter.base.BaseQuickAdapter; 6 | import com.bigkoo.kataframework.mvpview.BaseListView; 7 | 8 | /** 9 | * Created by sai on 2018/3/18. 10 | */ 11 | 12 | public interface BaseListRAMView extends BaseListView { 13 | void onItemClick(BaseQuickAdapter adapter, View view, int position); 14 | boolean onItemChildClick(BaseQuickAdapter adapter, View view, int position); 15 | } 16 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/mvpview/BaseDataView.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.mvpview; 2 | 3 | /** 4 | * Created by Sai on 2018/3/15. 5 | */ 6 | 7 | public interface BaseDataView extends IBaseView { 8 | void onRefreshing(boolean refreshing); 9 | 10 | void onStatusEmpty(String msg); 11 | 12 | void onStatusLoading(); 13 | 14 | void onStatusError(int code, String msg); 15 | 16 | void onStatusNetworkError(String msg); 17 | 18 | void onDataSetChange(Object data, String msg); 19 | 20 | void onLoadComplete(); 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-Kata 2 | 大多数app其实都是可以通过套路快速搭建的,其中无非分为联网与不联网,而联网可以延展分为列表、详情、提交表单。我曾经写了MVVM的框架,可是DataBinding至今都没普及,比较多的都是用MVP,但实际上MVP模式写起来也略为复杂,基于MVP和MVVM我重新定义了把P作为伪M,加上一些套路,总结了这个框架,我称它为Kata。 3 | 4 | 一年前就写好了一直没开源都是自己用,经过实践一个应用即使单干,使用Kata一个月之内不加班轻轻松松也能完成,速度快的话只需一周。 5 | 6 | 用到的其他库有: 7 | BaseRecyclerViewAdapterHelper 8 | ultra-ptr 9 | rxjava 10 | rxlifecycle 11 | 12 | 感谢他们 13 | 14 | Demo如下: 15 | 16 | [KataDemo-账房先生](https://github.com/saiwu-bigkoo/KataDemo-androidlite) 17 | 18 | 实战如下,一个月一个人在不加班情况下完成80%功能,后加入团队的小伙伴三分钟上手一个月零一周完成所有功能进入测试阶段,提前完成妥妥的等着品牌发布会当天进行上线: 19 | [广汽蔚来新能源汽车app-合创](https://a.app.qq.com/o/simple.jsp?pkgname=com.gac.nioapp) -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/mvppresenter/BasePresenter.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.mvppresenter; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * T-MVP Presenter基类 7 | * Created by Sai on 2018/3/15. 8 | */ 9 | 10 | public abstract class BasePresenter { 11 | protected Context context; 12 | protected V view; 13 | 14 | public void setVM(V v, Context mContext) { 15 | this.context = mContext; 16 | this.view = v; 17 | } 18 | 19 | public void onDestroy() { 20 | context = null; 21 | view = null; 22 | } 23 | 24 | public Context getContext() { 25 | return context; 26 | } 27 | 28 | public V getView() { 29 | return view; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | android.enableJetifier=true 10 | android.useAndroidX=true 11 | org.gradle.jvmargs=-Xmx1536m 12 | # When configured, Gradle will run in incubating parallel mode. 13 | # This option should only be used with decoupled projects. More details, visit 14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 15 | # org.gradle.parallel=true 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/bigkoo/kata/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kata; 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.bigkoo.kata", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /kataframework/src/androidTest/java/com/bigkoo/kataframework/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework; 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.bigkoo.kataframework.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /katafoundation/src/androidTest/java/com/bigkoo/katafoundation/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation; 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.bigkoo.katafoundation.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /katafoundation/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 15 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | api project(':kataframework') 29 | api 'androidx.appcompat:appcompat:1.0.0-beta01' 30 | // implementation 'com.android.support:cardview-v7:28.0.0' 31 | api 'com.google.android.material:material:1.0.0-beta01' 32 | api 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.46' 33 | api 'in.srain.cube:ultra-ptr:1.0.11' 34 | } 35 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.bigkoo.kata" 7 | minSdkVersion 15 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | //网络 23 | implementation 'com.squareup.retrofit2:retrofit:2.5.0' 24 | implementation 'com.squareup.retrofit2:converter-gson:2.5.0' 25 | implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0' 26 | implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1' 27 | implementation project(':katafoundation') 28 | implementation project(':kataframework') 29 | } 30 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/activity/BaseListActivity.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.activity; 2 | 3 | import androidx.recyclerview.widget.RecyclerView; 4 | 5 | import com.chad.library.adapter.base.BaseQuickAdapter; 6 | import com.bigkoo.katafoundation.R; 7 | import com.bigkoo.kataframework.mvppresenter.BaseListPresenter; 8 | 9 | /** 10 | * Created by sai on 2018/3/18. 11 | */ 12 | 13 | public abstract class BaseListActivity

extends BaseDataActivity

{ 14 | protected RecyclerView recyclerView; 15 | protected BaseQuickAdapter adapter; 16 | 17 | @Override 18 | protected void initView() { 19 | recyclerView = findViewById(R.id.recyclerView); 20 | adapter = getAdapter(); 21 | adapter.bindToRecyclerView(recyclerView); 22 | recyclerView.setAdapter(adapter); 23 | } 24 | 25 | 26 | @Override 27 | protected void initData() { 28 | 29 | } 30 | 31 | 32 | protected abstract BaseQuickAdapter getAdapter(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/bean/HttpResult.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.bean; 2 | 3 | import com.bigkoo.kataframework.http.constants.HttpStatusConstants; 4 | 5 | /** 6 | * Created by Sai on 2018/3/15. 7 | */ 8 | 9 | public class HttpResult { 10 | /** 11 | * 默认约定返回 格式 : {"code":0,"msg":"提示消息","data":{}} 12 | * status : 0 13 | * msg : 提示消息 14 | * data : {} 15 | */ 16 | private int code = HttpStatusConstants.CODE_DEFAULT;//防止返回格式不给code 17 | private T data; 18 | private String msg; 19 | 20 | public int getCode() { 21 | return code; 22 | } 23 | 24 | public void setCode(int code) { 25 | this.code = code; 26 | } 27 | 28 | public T getData() { 29 | return data; 30 | } 31 | 32 | public void setData(T data) { 33 | this.data = data; 34 | } 35 | 36 | public String getMsg() { 37 | return msg; 38 | } 39 | 40 | public void setMsg(String msg) { 41 | this.msg = msg; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/fragment/BaseListFragment.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.fragment; 2 | 3 | import androidx.recyclerview.widget.RecyclerView; 4 | 5 | import com.chad.library.adapter.base.BaseQuickAdapter; 6 | import com.bigkoo.katafoundation.R; 7 | import com.bigkoo.kataframework.mvppresenter.BaseListPresenter; 8 | 9 | /** 10 | * Created by sai on 2018/3/18. 11 | */ 12 | 13 | public abstract class BaseListFragment

extends BaseDataFragment

{ 14 | protected RecyclerView recyclerView; 15 | protected BaseQuickAdapter adapter; 16 | 17 | @Override 18 | protected void initView() { 19 | recyclerView = findViewById(R.id.recyclerView); 20 | adapter = getAdapter(); 21 | adapter.bindToRecyclerView(recyclerView); 22 | recyclerView.setAdapter(adapter); 23 | } 24 | 25 | 26 | @Override 27 | protected void initData() { 28 | getPresenter().onLoadData(); 29 | } 30 | 31 | 32 | protected abstract BaseQuickAdapter getAdapter(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/rx/RxBus.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.rx; 2 | 3 | import io.reactivex.Observable; 4 | import io.reactivex.subjects.PublishSubject; 5 | import io.reactivex.subjects.Subject; 6 | 7 | /** 8 | * Created by Sai on 2018/3/15. 9 | */ 10 | 11 | public class RxBus { 12 | private final Subject bus; 13 | 14 | private RxBus() { 15 | bus = PublishSubject.create().toSerialized(); 16 | } 17 | 18 | private static class RxBusInstance { 19 | private static final RxBus INSTANCE = new RxBus(); 20 | } 21 | 22 | public static RxBus getInstance() { 23 | return RxBusInstance.INSTANCE; 24 | } 25 | 26 | /** 27 | * 发送事件 28 | */ 29 | public void post(Object event) { 30 | bus.onNext(event); 31 | } 32 | 33 | /** 34 | * 根据传递的 eventType 类型返回特定类型(eventType)的 被观察者 35 | */ 36 | public Observable toObservable(final Class eventType) { 37 | Observable observable = bus.ofType(eventType); 38 | return observable; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/utils/TUtil.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.utils; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | 5 | /** 6 | * 泛型实例化工具类 (MVP模式) 7 | * Created by Sai on 2018/3/15. 8 | */ 9 | 10 | public class TUtil { 11 | public static T getT(Object o, int i) { 12 | try { 13 | return ((Class) ((ParameterizedType) (o.getClass() 14 | .getGenericSuperclass())).getActualTypeArguments()[i]) 15 | .newInstance(); 16 | } catch (InstantiationException e) { 17 | e.printStackTrace(); 18 | } catch (IllegalAccessException e) { 19 | e.printStackTrace(); 20 | } catch (ClassCastException e) { 21 | e.printStackTrace(); 22 | } 23 | return null; 24 | } 25 | 26 | public static Class forName(String className) { 27 | try { 28 | return Class.forName(className); 29 | } catch (ClassNotFoundException e) { 30 | e.printStackTrace(); 31 | } 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/activity/BaseDataActivity.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.activity; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.bigkoo.kataframework.mvppresenter.BaseDataPresenter; 6 | import com.bigkoo.kataframework.utils.TUtil; 7 | 8 | /** 9 | * Created by Sai on 2018/3/20. 10 | */ 11 | public abstract class BaseDataActivity

extends BaseActivity { 12 | private P presenter; 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | initPresenter(); 16 | super.onCreate(savedInstanceState); 17 | } 18 | 19 | protected void initPresenter() { 20 | presenter = TUtil.getT(this, 0); 21 | presenter.setVM(this,this); 22 | } 23 | 24 | @Override 25 | protected void onDestroy() { 26 | super.onDestroy(); 27 | presenter.onDestroy(); 28 | } 29 | 30 | public P getPresenter() { 31 | return presenter; 32 | } 33 | 34 | // public RxManager getRxManage() { 35 | // return presenter.getRxManage(); 36 | // } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /kataframework/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 15 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | api 'io.reactivex.rxjava2:rxandroid:2.0.2' 29 | // Because RxAndroid releases are few and far between, it is recommended you also 30 | // explicitly depend on RxJava's latest version for bug fixes and new features. 31 | // (see https://github.com/ReactiveX/RxJava/releases for latest 2.x.x version) 32 | api 'io.reactivex.rxjava2:rxjava:2.x.x' 33 | implementation 'com.trello.rxlifecycle3:rxlifecycle:3.0.0' 34 | implementation 'com.trello.rxlifecycle3:rxlifecycle-components:3.0.0' 35 | 36 | } 37 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/fragment/BaseDataFragment.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.bigkoo.kataframework.mvppresenter.BaseDataPresenter; 10 | import com.bigkoo.kataframework.utils.TUtil; 11 | 12 | /** 13 | * Created by Sai on 2018/3/20. 14 | */ 15 | 16 | public abstract class BaseDataFragment

extends BaseLazyFragment{ 17 | private P presenter; 18 | 19 | @Override 20 | public void onCreate(@Nullable Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | initPresenter(); 23 | } 24 | 25 | protected void initPresenter() { 26 | presenter = TUtil.getT(this, 0); 27 | presenter.setVM(this,getActivity()); 28 | } 29 | 30 | @Override 31 | public void onDestroy() { 32 | presenter.onDestroy(); 33 | super.onDestroy(); 34 | } 35 | 36 | public P getPresenter() { 37 | return presenter; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /katafoundation/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 | -keep class com.chad.library.adapter.** { 23 | *; 24 | } 25 | -keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter 26 | -keep public class * extends com.chad.library.adapter.base.BaseViewHolder 27 | -keepclassmembers class **$** extends com.chad.library.adapter.base.BaseViewHolder { 28 | (...); 29 | } -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/fragment/BaseLazyFragment.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | 6 | /** 7 | * Created by Sai on 2018/4/16. 8 | */ 9 | 10 | public abstract class BaseLazyFragment extends BaseFragment { 11 | protected boolean isVisible = true; 12 | protected boolean isLoadData = false; 13 | private boolean isPrepared; 14 | 15 | public void setUserVisibleHint(boolean isVisibleToUser) { 16 | super.setUserVisibleHint(isVisibleToUser); 17 | if(this.getUserVisibleHint()) { 18 | this.isVisible = true; 19 | this.lazyLoad(); 20 | } else { 21 | this.isVisible = false; 22 | this.onInVisible(); 23 | } 24 | 25 | } 26 | 27 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 28 | super.onActivityCreated(savedInstanceState); 29 | this.isPrepared = true; 30 | this.lazyLoad(); 31 | } 32 | 33 | public void onInVisible() { 34 | } 35 | 36 | protected void lazyLoad() { 37 | if(this.isPrepared && this.isVisible && !this.isLoadData) { 38 | this.initData(); 39 | this.isLoadData = true; 40 | } 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | *.aab 5 | 6 | # Files for the ART/Dalvik VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | out/ 16 | 17 | # Gradle files 18 | .gradle/ 19 | build/ 20 | 21 | # Local configuration file (sdk path, etc) 22 | local.properties 23 | 24 | # Proguard folder generated by Eclipse 25 | proguard/ 26 | 27 | # Log Files 28 | *.log 29 | 30 | # Android Studio Navigation editor temp files 31 | .navigation/ 32 | 33 | # Android Studio captures folder 34 | captures/ 35 | 36 | # IntelliJ 37 | *.iml 38 | .idea/workspace.xml 39 | .idea/tasks.xml 40 | .idea/gradle.xml 41 | .idea/assetWizardSettings.xml 42 | .idea/dictionaries 43 | .idea/libraries 44 | .idea/caches 45 | 46 | # Keystore files 47 | # Uncomment the following lines if you do not want to check your keystore files in. 48 | #*.jks 49 | #*.keystore 50 | 51 | # External native build folder generated in Android Studio 2.2 and later 52 | .externalNativeBuild 53 | 54 | # Google Services (e.g. APIs or Firebase) 55 | google-services.json 56 | 57 | # Freeline 58 | freeline.py 59 | freeline/ 60 | freeline_project_description.json 61 | 62 | # fastlane 63 | fastlane/report.xml 64 | fastlane/Preview.html 65 | fastlane/screenshots 66 | fastlane/test_output 67 | fastlane/readme.md 68 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/rx/MainThread.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.rx; 2 | 3 | import io.reactivex.Observable; 4 | import io.reactivex.ObservableSource; 5 | import io.reactivex.ObservableTransformer; 6 | import io.reactivex.android.schedulers.AndroidSchedulers; 7 | import io.reactivex.schedulers.Schedulers; 8 | 9 | /** 10 | * Created by Sai on 2018/3/16. 11 | * Rx切换主线程 12 | */ 13 | 14 | public class MainThread { 15 | private static ObservableTransformer ioToMainThreadSchedulerTransformer; 16 | 17 | 18 | static { 19 | ioToMainThreadSchedulerTransformer = createIOToMainThreadScheduler(); 20 | } 21 | 22 | 23 | @SuppressWarnings("unchecked") 24 | private static ObservableTransformer createIOToMainThreadScheduler() { 25 | return new ObservableTransformer() { 26 | @Override 27 | public ObservableSource apply(Observable observable) { 28 | return observable 29 | .subscribeOn(Schedulers.io()) 30 | .observeOn(AndroidSchedulers.mainThread()); 31 | } 32 | }; 33 | } 34 | 35 | 36 | @SuppressWarnings("unchecked") 37 | public static ObservableTransformer io() { 38 | return ioToMainThreadSchedulerTransformer; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/mvppresenter/BaseAppPresenter.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.mvppresenter; 2 | 3 | import com.bigkoo.kataframework.http.observer.HttpResultObserver; 4 | import com.bigkoo.kataframework.rx.MainThread; 5 | import com.bigkoo.kataframework.rx.RxBus; 6 | import com.trello.rxlifecycle3.RxLifecycle; 7 | import com.trello.rxlifecycle3.android.ActivityEvent; 8 | 9 | import io.reactivex.Observable; 10 | import io.reactivex.functions.Consumer; 11 | import io.reactivex.subjects.BehaviorSubject; 12 | 13 | /** 14 | * Created by Sai on 2018/4/16. 15 | */ 16 | 17 | public abstract class BaseAppPresenter extends BasePresenter { 18 | private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); 19 | 20 | public void onCallHttpRequest(Observable observable, HttpResultObserver callBack){ 21 | observable 22 | .compose(MainThread.io()) 23 | .compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY)) 24 | .subscribe(callBack); 25 | } 26 | 27 | public void toObservable(final Class eventType,Consumer onNext) { 28 | RxBus.getInstance().toObservable(eventType) 29 | .compose(MainThread.io()) 30 | .compose(RxLifecycle.bindUntilEvent(this.lifecycleSubject,ActivityEvent.DESTROY)) 31 | .subscribe(onNext); 32 | } 33 | 34 | public void post(Object event){ 35 | RxBus.getInstance().post(event); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/fragment/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.fragment.app.Fragment; 6 | 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Toast; 11 | 12 | /** 13 | * Created by sai on 2018/3/18. 14 | */ 15 | 16 | public abstract class BaseFragment extends Fragment { 17 | protected View rootView; 18 | 19 | @Nullable 20 | @Override 21 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 22 | if (rootView == null) 23 | rootView = inflater.inflate(getLayoutResID(), container, false); 24 | 25 | initView(); 26 | initListener(); 27 | 28 | return rootView; 29 | } 30 | 31 | public T findViewById(int id){ 32 | return rootView.findViewById(id); 33 | } 34 | 35 | protected abstract void initData(); 36 | 37 | protected abstract void initView(); 38 | 39 | protected void initListener() { 40 | } 41 | 42 | protected abstract int getLayoutResID(); 43 | 44 | public void showToast(String msg) { 45 | Toast.makeText(getActivity().getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); 46 | } 47 | 48 | public void showToast(int msgId) { 49 | Toast.makeText(getActivity().getApplicationContext(), msgId, Toast.LENGTH_SHORT).show(); 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/mvppresenter/BaseDetailPresenter.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.mvppresenter; 2 | 3 | import com.bigkoo.kataframework.http.observer.HttpResultObserver; 4 | import com.bigkoo.kataframework.mvpview.BaseDetailView; 5 | import io.reactivex.Observable; 6 | 7 | /** 8 | * Created by Sai on 2018/3/15. 9 | */ 10 | 11 | public abstract class BaseDetailPresenter extends BaseDataPresenter{ 12 | Object data; 13 | public void setData(Object data, String msg){ 14 | this.data = data; 15 | view.onDataSetChange(data, msg); 16 | } 17 | 18 | public Object getData() { 19 | return data; 20 | } 21 | 22 | /** 23 | * 刷新/加载数据 24 | */ 25 | public void onLoadData(){ 26 | setRefreshing(true); 27 | //这里考虑到首次加载是 loading,以后加载是refresh 模式 28 | if(!isOnce()) 29 | setStatusLoading(); 30 | Observable observable = onLoadDataHttpRequest(); 31 | if(observable!=null) { 32 | onCallHttpRequest(observable,callBack); 33 | } 34 | } 35 | 36 | 37 | public HttpResultObserver callBack = new HttpResultObserver() { 38 | @Override 39 | public void onHttpSuccess(Object resultData, String msg) { 40 | if (resultData != null) { 41 | setData(resultData, msg); 42 | } 43 | else { 44 | setStatusEmpty(msg); 45 | } 46 | } 47 | 48 | @Override 49 | public void onHttpFail(int code, String msg) { 50 | setStatusError(code,msg); 51 | } 52 | 53 | @Override 54 | public void onNetWorkError(String msg) { 55 | setStatusNetworkError(msg); 56 | } 57 | 58 | @Override 59 | public void onComplete() { 60 | setOnce(true); 61 | setRefreshing(false); 62 | onLoadComplete(); 63 | } 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /kataframework/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 | -keepattributes Signature, InnerClasses, EnclosingMethod 23 | 24 | # Retrofit does reflection on method and parameter annotations. 25 | -keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations 26 | 27 | # Retain service method parameters when optimizing. 28 | -keepclassmembers,allowshrinking,allowobfuscation interface * { 29 | @retrofit2.http.* ; 30 | } 31 | 32 | # Ignore annotation used for build tooling. 33 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 34 | 35 | # Ignore JSR 305 annotations for embedding nullability information. 36 | -dontwarn javax.annotation.** 37 | 38 | # Guarded by a NoClassDefFoundError try/catch and only used when on the classpath. 39 | -dontwarn kotlin.Unit 40 | 41 | # Top-level functions that can only be used by Kotlin. 42 | -dontwarn retrofit2.KotlinExtensions 43 | 44 | # With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy 45 | # and replaces all potential values with null. Explicitly keeping the interfaces prevents this. 46 | -if interface * { @retrofit2.http.* ; } 47 | -keep,allowobfuscation interface <1> -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/activity/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.activity; 2 | 3 | import android.os.Bundle; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | import com.bigkoo.katafoundation.manager.AppManager; 9 | import com.bigkoo.utils.StatusBarUtil; 10 | 11 | /** 12 | * Created by Sai on 2018/3/15. 13 | * 基类Activity 14 | */ 15 | public abstract class BaseActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | //当FitsSystemWindows设置 true 时,会在屏幕最上方预留出状态栏高度的 padding 21 | StatusBarUtil.setRootViewFitsSystemWindows(this,false); 22 | //设置状态栏透明 23 | StatusBarUtil.setTranslucentStatus(this); 24 | //一般的手机的状态栏文字和图标都是白色的, 可如果你的应用也是纯白色的, 或导致状态栏文字看不清 25 | //所以如果你是这种情况,请使用以下代码, 设置状态使用深色文字图标风格, 否则你可以选择性注释掉这个if内容 26 | if (!StatusBarUtil.setStatusBarDarkTheme(this, true)) { 27 | //如果不支持设置深色风格 为了兼容总不能让状态栏白白的看不清, 于是设置一个状态栏颜色为半透明, 28 | //这样半透明+白=灰, 状态栏的文字能看得清 29 | StatusBarUtil.setStatusBarColor(this,0x55000000); 30 | } 31 | 32 | 33 | setContentView(getLayoutResID()); 34 | AppManager.getAppManager().addActivity(this); 35 | initView(); 36 | initData(); 37 | initListener(); 38 | } 39 | protected abstract int getLayoutResID(); 40 | 41 | protected abstract void initView(); 42 | 43 | protected abstract void initData(); 44 | 45 | protected void initListener(){} 46 | 47 | 48 | @Override 49 | protected void onDestroy() { 50 | super.onDestroy(); 51 | AppManager.getAppManager().finishActivity(this); 52 | } 53 | 54 | public void showToast(String msg) { 55 | Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_SHORT).show(); 56 | } 57 | 58 | public void showToast(int msgId) { 59 | Toast.makeText(getApplicationContext(),msgId,Toast.LENGTH_SHORT).show(); 60 | } 61 | 62 | public void onTopBarBack(View view){ 63 | finish(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/http/observer/HttpResultObserver.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.http.observer; 2 | 3 | import android.accounts.NetworkErrorException; 4 | 5 | import com.bigkoo.kataframework.bean.HttpResult; 6 | import com.bigkoo.kataframework.http.constants.HttpStatusConstants; 7 | 8 | import java.net.ConnectException; 9 | import java.net.UnknownHostException; 10 | import java.util.concurrent.TimeoutException; 11 | 12 | import io.reactivex.Observer; 13 | import io.reactivex.disposables.Disposable; 14 | 15 | /** 16 | * 网络结果预处理 17 | * Created by Sai on 2018/3/15. 18 | */ 19 | public class HttpResultObserver implements Observer> { 20 | @Override 21 | public void onSubscribe(Disposable d) { 22 | 23 | } 24 | 25 | @Override 26 | public void onNext(HttpResult result) { 27 | if (result == null) { 28 | //通常是服务器出错返回了非约定格式 29 | onHttpFail(HttpStatusConstants.CODE_DEFAULT,"网络错误,返回非正常格式,请稍后再试"); 30 | } else { 31 | if (result.getCode() == HttpStatusConstants.CODE_SUCCESS) { 32 | //正确返回约定的CODE_SUCCESS码 33 | onHttpSuccess(result.getData(),result.getMsg()); 34 | } 35 | else { 36 | //返回约定的其他类型码,可根据返回码进行相对应的操作 37 | onHttpFail(result.getCode(),result.getMsg()); 38 | } 39 | } 40 | } 41 | 42 | @Override 43 | public void onError(Throwable e) { 44 | try { 45 | if (e instanceof ConnectException 46 | || e instanceof TimeoutException 47 | || e instanceof NetworkErrorException 48 | || e instanceof UnknownHostException) { 49 | onNetWorkError("网络异常,请稍后再试"); 50 | } else { 51 | onNetWorkError(e.getMessage()); 52 | } 53 | } catch (Exception e1) { 54 | e1.printStackTrace(); 55 | } finally { 56 | onComplete(); 57 | } 58 | } 59 | 60 | @Override 61 | public void onComplete() { 62 | 63 | } 64 | 65 | /** 66 | * 正常返回结果 67 | * @param result 结果 68 | * @param msg 附带消息 69 | */ 70 | public void onHttpSuccess(T result,String msg){} 71 | 72 | /** 73 | * 正常返回但code不是CODE_SUCCESS 74 | * @param code 约定的错误码 75 | * @param msg 附带消息 76 | */ 77 | public void onHttpFail(int code, String msg){} 78 | 79 | /** 80 | * 非正常返回,通常是网络异常问题 81 | * @param msg 异常描述 82 | */ 83 | public void onNetWorkError(String msg){} 84 | // public abstract void onHttpComplete(); 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/presenter/BaseListRAMPresenter.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.presenter; 2 | 3 | import androidx.recyclerview.widget.LinearLayoutManager; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import android.view.View; 6 | 7 | import com.chad.library.adapter.base.BaseQuickAdapter; 8 | import com.bigkoo.katafoundation.mvpview.BaseListRAMView; 9 | import com.bigkoo.kataframework.mvppresenter.BaseListPresenter; 10 | 11 | import in.srain.cube.views.ptr.PtrDefaultHandler; 12 | import in.srain.cube.views.ptr.PtrFrameLayout; 13 | import in.srain.cube.views.ptr.PtrHandler; 14 | 15 | /** 16 | * Created by sai on 2018/3/18. 17 | * refresh and loadMore 基类Presenter 18 | */ 19 | 20 | public abstract class BaseListRAMPresenter extends BaseListPresenter { 21 | protected BaseQuickAdapter.RequestLoadMoreListener loadingMoreListener; 22 | protected BaseQuickAdapter.OnItemClickListener onItemClickListener; 23 | protected BaseQuickAdapter.OnItemChildClickListener onItemChildClickListener; 24 | protected PtrHandler ptrHandler; 25 | protected RecyclerView.LayoutManager layoutManager; 26 | public BaseQuickAdapter.RequestLoadMoreListener getLoadingMoreListener(){ 27 | if(loadingMoreListener == null) { 28 | loadingMoreListener = new BaseQuickAdapter.RequestLoadMoreListener() { 29 | @Override 30 | public void onLoadMoreRequested() { 31 | if(!isLoadingMore()&&!isRefreshing()) { 32 | onLoadMore(); 33 | } 34 | } 35 | }; 36 | } 37 | return loadingMoreListener; 38 | } 39 | 40 | public BaseQuickAdapter.OnItemClickListener getOnItemClickListener() { 41 | if(onItemClickListener == null) { 42 | onItemClickListener = new BaseQuickAdapter.OnItemClickListener(){ 43 | @Override 44 | public void onItemClick(BaseQuickAdapter adapter, View view, int position) { 45 | getView().onItemClick(adapter, view, position); 46 | } 47 | }; 48 | } 49 | 50 | return onItemClickListener; 51 | } 52 | 53 | public BaseQuickAdapter.OnItemChildClickListener getOnItemChildClickListener() { 54 | if(onItemChildClickListener == null) { 55 | onItemChildClickListener = new BaseQuickAdapter.OnItemChildClickListener(){ 56 | @Override 57 | public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { 58 | getView().onItemChildClick(adapter, view, position); 59 | } 60 | }; 61 | } 62 | return onItemChildClickListener; 63 | } 64 | 65 | 66 | public PtrHandler getPtrHandler() { 67 | if(ptrHandler == null){ 68 | ptrHandler = new PtrDefaultHandler() { 69 | @Override 70 | public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { 71 | return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header); 72 | } 73 | 74 | @Override 75 | public void onRefreshBegin(PtrFrameLayout frame) { 76 | if(!isLoadingMore()&&!isRefreshing()) { 77 | onLoadData(); 78 | } 79 | } 80 | }; 81 | } 82 | return ptrHandler; 83 | } 84 | 85 | public RecyclerView.LayoutManager getLayoutManager() { 86 | return new LinearLayoutManager(context); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/mvppresenter/BaseDataPresenter.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.mvppresenter; 2 | 3 | import com.bigkoo.kataframework.bean.HttpResult; 4 | import com.bigkoo.kataframework.http.observer.HttpResultObserver; 5 | import com.bigkoo.kataframework.mvpview.BaseDataView; 6 | import com.bigkoo.kataframework.rx.MainThread; 7 | import com.bigkoo.kataframework.rx.RxBus; 8 | import com.trello.rxlifecycle3.RxLifecycle; 9 | import com.trello.rxlifecycle3.android.ActivityEvent; 10 | 11 | import io.reactivex.Observable; 12 | import io.reactivex.functions.Consumer; 13 | import io.reactivex.subjects.BehaviorSubject; 14 | 15 | /** 16 | * Created by Sai on 2018/3/15. 17 | */ 18 | 19 | public abstract class BaseDataPresenter extends BasePresenter{ 20 | private final BehaviorSubject lifecycleSubject = BehaviorSubject.create(); 21 | 22 | //刷新状态 23 | private boolean refreshing = false; 24 | //空数据状态 25 | private boolean statusEmpty = false; 26 | //加载中状态 27 | private boolean statusLoading = false; 28 | //错误状态 29 | private boolean statusError = false; 30 | //网络异常状态 31 | private boolean statusNetworkError = false; 32 | //控制loading状态只有一次,对于列表的loading概念,就是首次加载数据,其余加载是刷新 33 | private boolean once = false; 34 | 35 | public boolean isOnce() { 36 | return once; 37 | } 38 | 39 | public void setOnce(boolean once) { 40 | this.once = once; 41 | } 42 | 43 | public boolean isRefreshing() { 44 | return refreshing; 45 | } 46 | 47 | public void setRefreshing(boolean refreshing) { 48 | this.refreshing = refreshing; 49 | view.onRefreshing(refreshing); 50 | } 51 | 52 | public boolean isStatusEmpty() { 53 | return statusEmpty; 54 | } 55 | 56 | public void setStatusEmpty(String msg) { 57 | this.statusEmpty = true; 58 | view.onStatusEmpty(msg); 59 | } 60 | 61 | public boolean isStatusLoading() { 62 | return statusLoading; 63 | } 64 | 65 | public void setStatusLoading() { 66 | this.statusLoading = true; 67 | view.onStatusLoading(); 68 | } 69 | 70 | public boolean isStatusError() { 71 | return statusError; 72 | } 73 | 74 | public void setStatusError(int code, String msg) { 75 | this.statusError = true; 76 | view.onStatusError(code,msg); 77 | } 78 | 79 | public boolean isStatusNetworkError() { 80 | return statusNetworkError; 81 | } 82 | 83 | public void setStatusNetworkError(String msg) { 84 | this.statusNetworkError = true; 85 | view.onStatusNetworkError(msg); 86 | } 87 | 88 | public void onLoadComplete(){ 89 | view.onLoadComplete(); 90 | } 91 | 92 | @Override 93 | public void onDestroy() { 94 | lifecycleSubject.onNext(ActivityEvent.DESTROY); 95 | super.onDestroy(); 96 | } 97 | 98 | public HttpResultObserver callBack; 99 | 100 | /** 101 | * 网络请求 102 | * @return 103 | */ 104 | public abstract Observable> onLoadDataHttpRequest(); 105 | public abstract void onLoadData(); 106 | 107 | public void onCallHttpRequest(Observable observable,HttpResultObserver callBack){ 108 | observable.compose(MainThread.io()).compose(RxLifecycle.bindUntilEvent(this.lifecycleSubject, ActivityEvent.DESTROY)).subscribe(callBack); 109 | } 110 | 111 | public void toObservable(final Class eventType,Consumer onNext) { 112 | RxBus.getInstance().toObservable(eventType).compose(MainThread.io()).compose(RxLifecycle.bindUntilEvent(this.lifecycleSubject,ActivityEvent.DESTROY)).subscribe(onNext); 113 | } 114 | 115 | public void post(Object event){ 116 | RxBus.getInstance().post(event); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/utils/OSUtils.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.utils; 2 | 3 | import android.os.Build; 4 | import android.text.TextUtils; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | 10 | /** 11 | * @Description:描述信息 12 | * @Author:Sai 13 | * @Date:2019/3/13 11:10 14 | */ 15 | public class OSUtils { 16 | public static final String ROM_MIUI = "MIUI"; 17 | public static final String ROM_EMUI = "EMUI"; 18 | public static final String ROM_FLYME = "FLYME"; 19 | public static final String ROM_OPPO = "OPPO"; 20 | public static final String ROM_SMARTISAN = "SMARTISAN"; 21 | public static final String ROM_VIVO = "VIVO"; 22 | public static final String ROM_QIKU = "QIKU"; 23 | 24 | private static final String KEY_VERSION_MIUI = "ro.miui.ui.version.name"; 25 | private static final String KEY_VERSION_EMUI = "ro.build.version.emui"; 26 | private static final String KEY_VERSION_OPPO = "ro.build.version.opporom"; 27 | private static final String KEY_VERSION_SMARTISAN = "ro.smartisan.version"; 28 | private static final String KEY_VERSION_VIVO = "ro.vivo.os.version"; 29 | 30 | private static String sName; 31 | private static String sVersion; 32 | 33 | public static boolean isEmui() { 34 | return check(ROM_EMUI); 35 | } 36 | 37 | public static boolean isMiui() { 38 | return check(ROM_MIUI); 39 | } 40 | 41 | public static boolean isVivo() { 42 | return check(ROM_VIVO); 43 | } 44 | 45 | public static boolean isOppo() { 46 | return check(ROM_OPPO); 47 | } 48 | 49 | public static boolean isFlyme() { 50 | return check(ROM_FLYME); 51 | } 52 | 53 | public static boolean is360() { 54 | return check(ROM_QIKU) || check("360"); 55 | } 56 | 57 | public static boolean isSmartisan() { 58 | return check(ROM_SMARTISAN); 59 | } 60 | 61 | public static String getName() { 62 | if (sName == null) { 63 | check(""); 64 | } 65 | return sName; 66 | } 67 | 68 | public static String getVersion() { 69 | if (sVersion == null) { 70 | check(""); 71 | } 72 | return sVersion; 73 | } 74 | 75 | public static boolean check(String rom) { 76 | if (sName != null) { 77 | return sName.equals(rom); 78 | } 79 | 80 | if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_MIUI))) { 81 | sName = ROM_MIUI; 82 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_EMUI))) { 83 | sName = ROM_EMUI; 84 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_OPPO))) { 85 | sName = ROM_OPPO; 86 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_VIVO))) { 87 | sName = ROM_VIVO; 88 | } else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_SMARTISAN))) { 89 | sName = ROM_SMARTISAN; 90 | } else { 91 | sVersion = Build.DISPLAY; 92 | if (sVersion.toUpperCase().contains(ROM_FLYME)) { 93 | sName = ROM_FLYME; 94 | } else { 95 | sVersion = Build.UNKNOWN; 96 | sName = Build.MANUFACTURER.toUpperCase(); 97 | } 98 | } 99 | return sName.equals(rom); 100 | } 101 | 102 | public static String getProp(String name) { 103 | String line = null; 104 | BufferedReader input = null; 105 | try { 106 | Process p = Runtime.getRuntime().exec("getprop " + name); 107 | input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); 108 | line = input.readLine(); 109 | input.close(); 110 | } catch (IOException ex) { 111 | return null; 112 | } finally { 113 | if (input != null) { 114 | try { 115 | input.close(); 116 | } catch (IOException e) { 117 | e.printStackTrace(); 118 | } 119 | } 120 | } 121 | return line; 122 | } 123 | } -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/fragment/BaseListRAMFragment.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.fragment; 2 | 3 | import com.bigkoo.katafoundation.R; 4 | import com.bigkoo.katafoundation.mvpview.BaseListRAMView; 5 | import com.bigkoo.katafoundation.presenter.BaseListRAMPresenter; 6 | 7 | import java.util.List; 8 | 9 | import in.srain.cube.views.ptr.PtrFrameLayout; 10 | import in.srain.cube.views.ptr.PtrHandler; 11 | import in.srain.cube.views.ptr.header.MaterialHeader; 12 | 13 | /** 14 | * Created by sai on 2018/3/18. 15 | */ 16 | 17 | public abstract class BaseListRAMFragment

extends BaseListFragment

implements BaseListRAMView { 18 | 19 | protected PtrFrameLayout ptrFrameLayout; 20 | public float PTRRESISTANCE = 1.7f; 21 | protected boolean refreshable = true; 22 | 23 | @Override 24 | protected void initView() { 25 | super.initView(); 26 | 27 | recyclerView.setLayoutManager(getPresenter().getLayoutManager()); 28 | if (refreshable) { 29 | 30 | ptrFrameLayout = findViewById(R.id.ptrFrameLayout); 31 | ptrFrameLayout.setResistance(PTRRESISTANCE); 32 | ptrFrameLayout.setKeepHeaderWhenRefresh(true); 33 | ptrFrameLayout.disableWhenHorizontalMove(true); 34 | 35 | MaterialHeader header = new MaterialHeader(getContext()); 36 | header.setColorSchemeColors(new int[]{R.color.refresh_color}); 37 | header.setPadding(0, 50, 0, 50); 38 | 39 | ptrFrameLayout.setHeaderView(header); 40 | ptrFrameLayout.addPtrUIHandler(header); 41 | PtrHandler ptrHandler = getPresenter().getPtrHandler(); 42 | if (ptrHandler != null) { 43 | ptrFrameLayout.setPtrHandler(ptrHandler); 44 | } 45 | } 46 | } 47 | 48 | @Override 49 | protected void initListener() { 50 | super.initListener(); 51 | adapter.setOnLoadMoreListener(getPresenter().getLoadingMoreListener(), recyclerView); 52 | adapter.setOnItemClickListener(getPresenter().getOnItemClickListener()); 53 | adapter.setOnItemChildClickListener(getPresenter().getOnItemChildClickListener()); 54 | } 55 | 56 | 57 | @Override 58 | public void onRefreshing(boolean refreshing) { 59 | if (refreshing) { 60 | if (!ptrFrameLayout.isRefreshing()) 61 | ptrFrameLayout.autoRefresh(true); 62 | } else { 63 | ptrFrameLayout.refreshComplete(); 64 | } 65 | } 66 | 67 | @Override 68 | public void onLoadingMore(boolean isLoadingMore) { 69 | if (!isLoadingMore) { 70 | if (adapter.isLoading()) { 71 | adapter.loadMoreComplete(); 72 | } 73 | } 74 | } 75 | 76 | @Override 77 | public void onStatusEmpty(String msg) { 78 | 79 | } 80 | 81 | @Override 82 | public void onStatusLoading() { 83 | 84 | } 85 | 86 | @Override 87 | public void onStatusError(int code, String msg) { 88 | 89 | } 90 | 91 | @Override 92 | public void onStatusNetworkError(String msg) { 93 | 94 | } 95 | 96 | @Override 97 | public void onLoadComplete() { 98 | if (adapter.isLoading()) 99 | adapter.loadMoreComplete(); 100 | if (!getPresenter().isHasMore()) { 101 | adapter.loadMoreEnd(); 102 | } 103 | } 104 | 105 | public void addData(List datas) { 106 | if (datas == null || datas.isEmpty()) { 107 | getPresenter().setHasMore(false); 108 | adapter.loadMoreEnd(); 109 | return; 110 | } 111 | if (getPresenter().isFirstPage()) { 112 | adapter.setNewData(datas); 113 | } else { 114 | adapter.addData(datas); 115 | } 116 | if (datas.size() < getPresenter().getPageSize()) { 117 | getPresenter().setHasMore(false); 118 | adapter.loadMoreEnd(); 119 | } 120 | 121 | } 122 | 123 | public void addData(Object data){ 124 | if (data == null) return; 125 | adapter.addData(data); 126 | } 127 | public void addData(int position,Object data){ 128 | if (data == null) return; 129 | adapter.addData(position,data); 130 | adapter.notifyItemRangeChanged(position + adapter.getHeaderLayoutCount(),adapter.getItemCount()-position );//通知数据与界面重新绑定 131 | } 132 | 133 | public Object getItem(int position){ 134 | return adapter.getItem(position); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/activity/BaseListRAMActivity.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.activity; 2 | 3 | import com.bigkoo.katafoundation.R; 4 | import com.bigkoo.katafoundation.mvpview.BaseListRAMView; 5 | import com.bigkoo.katafoundation.presenter.BaseListRAMPresenter; 6 | 7 | import java.util.List; 8 | 9 | import in.srain.cube.views.ptr.PtrFrameLayout; 10 | import in.srain.cube.views.ptr.PtrHandler; 11 | import in.srain.cube.views.ptr.header.MaterialHeader; 12 | 13 | /** 14 | * Created by sai on 2018/3/18. 15 | * refresh and loadMore 基类Activity 16 | */ 17 | 18 | public abstract class BaseListRAMActivity

extends BaseListActivity

implements BaseListRAMView { 19 | 20 | protected PtrFrameLayout ptrFrameLayout; 21 | public float PTRRESISTANCE = 1.7f; 22 | protected boolean refreshable = true; 23 | 24 | @Override 25 | protected void initView() { 26 | super.initView(); 27 | 28 | recyclerView.setLayoutManager(getPresenter().getLayoutManager()); 29 | if (refreshable) { 30 | 31 | ptrFrameLayout = findViewById(R.id.ptrFrameLayout); 32 | ptrFrameLayout.setResistance(PTRRESISTANCE); 33 | ptrFrameLayout.setKeepHeaderWhenRefresh(true); 34 | ptrFrameLayout.disableWhenHorizontalMove(true); 35 | 36 | MaterialHeader header = new MaterialHeader(this); 37 | header.setColorSchemeColors(new int[]{R.color.refresh_color}); 38 | header.setPadding(0, 50, 0, 50); 39 | 40 | ptrFrameLayout.setHeaderView(header); 41 | ptrFrameLayout.addPtrUIHandler(header); 42 | PtrHandler ptrHandler = getPresenter().getPtrHandler(); 43 | if (ptrHandler != null) { 44 | ptrFrameLayout.setPtrHandler(ptrHandler); 45 | } 46 | } 47 | } 48 | 49 | @Override 50 | protected void initListener() { 51 | super.initListener(); 52 | adapter.setOnLoadMoreListener(getPresenter().getLoadingMoreListener(), recyclerView); 53 | adapter.setOnItemClickListener(getPresenter().getOnItemClickListener()); 54 | adapter.setOnItemChildClickListener(getPresenter().getOnItemChildClickListener()); 55 | } 56 | 57 | 58 | @Override 59 | public void onRefreshing(boolean refreshing) { 60 | if (refreshing) { 61 | if (!ptrFrameLayout.isRefreshing()) 62 | ptrFrameLayout.autoRefresh(true); 63 | } else { 64 | ptrFrameLayout.refreshComplete(); 65 | } 66 | } 67 | 68 | @Override 69 | public void onLoadingMore(boolean isLoadingMore) { 70 | if (!isLoadingMore) { 71 | if (adapter.isLoading()) { 72 | adapter.loadMoreComplete(); 73 | } 74 | } 75 | } 76 | 77 | @Override 78 | public void onStatusEmpty(String msg) { 79 | 80 | } 81 | 82 | @Override 83 | public void onStatusLoading() { 84 | 85 | } 86 | 87 | @Override 88 | public void onStatusError(int code, String msg) { 89 | 90 | } 91 | 92 | @Override 93 | public void onStatusNetworkError( String msg) { 94 | 95 | } 96 | 97 | @Override 98 | public void onLoadComplete() { 99 | if (adapter.isLoading()) 100 | adapter.loadMoreComplete(); 101 | if (!getPresenter().isHasMore()) { 102 | adapter.loadMoreEnd(); 103 | } 104 | } 105 | 106 | public void addData(List datas) { 107 | if (datas == null || datas.isEmpty()) { 108 | getPresenter().setHasMore(false); 109 | adapter.loadMoreEnd(); 110 | return; 111 | } 112 | if (getPresenter().isFirstPage()) { 113 | adapter.setNewData(datas); 114 | } else { 115 | adapter.addData(datas); 116 | } 117 | if (datas.size() < getPresenter().getPageSize()) { 118 | getPresenter().setHasMore(false); 119 | adapter.loadMoreEnd(); 120 | } 121 | 122 | } 123 | 124 | public void addData(Object data){ 125 | if (data == null) return; 126 | adapter.addData(data); 127 | } 128 | public void addData(int position,Object data){ 129 | if (data == null) return; 130 | adapter.addData(position,data); 131 | adapter.notifyItemRangeChanged(position + adapter.getHeaderLayoutCount(),adapter.getItemCount()-position );//通知数据与界面重新绑定 132 | } 133 | 134 | public Object getItem(int position){ 135 | return adapter.getItem(position); 136 | }} 137 | -------------------------------------------------------------------------------- /kataframework/src/main/java/com/bigkoo/kataframework/mvppresenter/BaseListPresenter.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.kataframework.mvppresenter; 2 | 3 | import com.bigkoo.kataframework.http.observer.HttpResultObserver; 4 | import com.bigkoo.kataframework.mvpview.BaseListView; 5 | 6 | import java.util.ArrayList; 7 | 8 | import io.reactivex.Observable; 9 | 10 | /** 11 | * Created by Sai on 2018/3/15. 12 | */ 13 | 14 | public abstract class BaseListPresenter extends BaseDataPresenter{ 15 | protected ArrayList datas = new ArrayList<>(); 16 | protected final int firstPage = 1; 17 | //分页页码 18 | protected int page = firstPage; 19 | //分页每页Item数量 20 | public static final int PAGESIZE_DEFULT = 20; 21 | protected int pageSize = PAGESIZE_DEFULT; 22 | protected boolean isHasMore = true; 23 | protected boolean isLoadingMore = false; 24 | 25 | public int getFirstPage() { 26 | return firstPage; 27 | } 28 | 29 | public boolean isFirstPage() { 30 | return firstPage==page; 31 | } 32 | 33 | public int getPage() { 34 | return page; 35 | } 36 | 37 | public void setPage(int page) { 38 | this.page = page; 39 | } 40 | 41 | public int getPageSize() { 42 | return pageSize; 43 | } 44 | 45 | public void setPageSize(int pageSize) { 46 | this.pageSize = pageSize; 47 | } 48 | 49 | public boolean isHasMore() { 50 | return isHasMore; 51 | } 52 | 53 | public void setHasMore(boolean hasMore) { 54 | isHasMore = hasMore; 55 | } 56 | 57 | public boolean isLoadingMore() { 58 | return isLoadingMore; 59 | } 60 | 61 | public void setLoadingMore(boolean loadingMore) { 62 | isLoadingMore = loadingMore; 63 | view.onLoadingMore(loadingMore); 64 | } 65 | 66 | public void setPageAdd(){ 67 | page++; 68 | } 69 | 70 | public void addData(Object data, String msg){ 71 | this.datas.add(data); 72 | view.onDataSetChange(data, msg); 73 | } 74 | 75 | public boolean isDataEmpty() { 76 | return datas.isEmpty(); 77 | } 78 | 79 | public void clearDatas() { 80 | datas.clear(); 81 | } 82 | 83 | /** 84 | * 这里重写onLoadData,列表不能直接onLoadData,而是刷新 85 | */ 86 | @Override 87 | public void onLoadData() { 88 | onListRefresh(); 89 | } 90 | 91 | /** 92 | * 加载更多 93 | */ 94 | public void onLoadMore() { 95 | onListLoadMore(); 96 | } 97 | 98 | /** 99 | * 刷新数据 100 | */ 101 | public void onListRefresh(){ 102 | setRefreshing(true); 103 | //把分页配置还原成加载第一页状态 104 | setPage(getFirstPage()); 105 | setHasMore(true); 106 | setLoadingMore(false); 107 | if(!isOnce()) 108 | setStatusLoading(); 109 | try { 110 | onLoadHttpData(); 111 | }catch (NullPointerException e){} 112 | } 113 | 114 | /** 115 | * 加载数据 116 | */ 117 | public void onListLoadMore(){ 118 | //判断是否已经在进行加载更多 或 没有更多了,是则直接返回等待加载完成。 119 | if(isLoadingMore()||!isHasMore())return; 120 | //刷新中也直接返回不加载更多 121 | if(isRefreshing())return; 122 | setLoadingMore(true); 123 | //分页增加 124 | setPageAdd(); 125 | 126 | onLoadHttpData(); 127 | } 128 | 129 | /** 130 | * 刷新/加载数据 131 | */ 132 | public void onLoadHttpData(){ 133 | Observable observable = onLoadDataHttpRequest(); 134 | if(observable!=null) { 135 | onCallHttpRequest(observable,callBack); 136 | } 137 | } 138 | 139 | 140 | public HttpResultObserver callBack = new HttpResultObserver() { 141 | @Override 142 | public void onHttpSuccess(Object resultData, String msg) { 143 | 144 | //如果是第一页就清空旧数据再加入新数据 145 | if(isFirstPage()) { 146 | clearDatas(); 147 | } 148 | if(resultData != null) { 149 | addData(resultData, msg); 150 | } 151 | else { 152 | setHasMore(false); 153 | if(isDataEmpty()){ 154 | setStatusEmpty(msg); 155 | } 156 | } 157 | } 158 | 159 | @Override 160 | public void onHttpFail(int code, String msg) { 161 | setStatusError(code,msg); 162 | } 163 | 164 | @Override 165 | public void onNetWorkError(String msg) { 166 | setStatusNetworkError(msg); 167 | } 168 | 169 | @Override 170 | public void onComplete() { 171 | setOnce(true); 172 | 173 | setRefreshing(false); 174 | 175 | if(isFirstPage())//因为在刷新之前已经把page设为了firstPage,所以可以判断isFirstPage()来判断当前是否刷新 176 | setRefreshing(false); 177 | else 178 | setLoadingMore(false); 179 | 180 | onLoadComplete(); 181 | } 182 | }; 183 | } 184 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/katafoundation/manager/AppManager.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.katafoundation.manager; 2 | 3 | import android.app.Activity; 4 | import android.app.ActivityManager; 5 | import android.content.Context; 6 | 7 | import java.util.Stack; 8 | 9 | /** 10 | * Created by Sai on 2018/3/16. 11 | * 管理Activity栈 12 | */ 13 | public class AppManager { 14 | private static Stack activityStack; 15 | private volatile static AppManager instance; 16 | 17 | private AppManager() { 18 | 19 | } 20 | /** 21 | * 单一实例 22 | */ 23 | public static AppManager getAppManager() { 24 | if (instance == null) { 25 | synchronized (AppManager.class){ 26 | if(instance==null){ 27 | instance = new AppManager(); 28 | instance.activityStack = new Stack(); 29 | } 30 | } 31 | 32 | } 33 | return instance; 34 | } 35 | 36 | /** 37 | * 添加Activity到堆栈 38 | */ 39 | public void addActivity(Activity activity) { 40 | if (activityStack == null) { 41 | activityStack = new Stack(); 42 | } 43 | activityStack.add(activity); 44 | } 45 | 46 | /** 47 | * 获取当前Activity(堆栈中最后一个压入的) 48 | */ 49 | public Activity currentActivity() { 50 | try { 51 | Activity activity = activityStack.lastElement(); 52 | return activity; 53 | } catch (Exception e) { 54 | // e.printStackTrace(); 55 | return null; 56 | } 57 | } 58 | 59 | /** 60 | * 获取当前Activity的前一个Activity 61 | */ 62 | public Activity preActivity() { 63 | int index = activityStack.size() - 2; 64 | if (index < 0) { 65 | return null; 66 | } 67 | Activity activity = activityStack.get(index); 68 | return activity; 69 | } 70 | 71 | /** 72 | * 结束当前Activity(堆栈中最后一个压入的) 73 | */ 74 | public void finishActivity() { 75 | Activity activity = activityStack.lastElement(); 76 | finishActivity(activity); 77 | } 78 | 79 | /** 80 | * 结束指定的Activity 81 | */ 82 | public void finishActivity(Activity activity) { 83 | if (activity != null) { 84 | activityStack.remove(activity); 85 | activity.finish(); 86 | activity = null; 87 | } 88 | } 89 | 90 | /** 91 | * 移除指定的Activity 92 | */ 93 | public void removeActivity(Activity activity) { 94 | if (activity != null) { 95 | activityStack.remove(activity); 96 | activity = null; 97 | } 98 | } 99 | 100 | /** 101 | * 结束指定类名的Activity 102 | */ 103 | public void finishActivity(Class cls) { 104 | try { 105 | for (Activity activity : activityStack) { 106 | if (activity.getClass().equals(cls)) { 107 | finishActivity(activity); 108 | } 109 | } 110 | } catch (Exception e) { 111 | e.printStackTrace(); 112 | } 113 | 114 | } 115 | 116 | /** 117 | * 结束所有Activity 118 | */ 119 | public void finishAllActivity() { 120 | for (int i = 0, size = activityStack.size(); i < size; i++) { 121 | if (null != activityStack.get(i)) { 122 | activityStack.get(i).finish(); 123 | } 124 | } 125 | activityStack.clear(); 126 | } 127 | 128 | /** 129 | * 返回到指定的activity 130 | * 131 | * @param cls 132 | */ 133 | public void returnToActivity(Class cls) { 134 | while (activityStack.size() != 0) 135 | if (activityStack.peek().getClass() == cls) { 136 | break; 137 | } else { 138 | finishActivity(activityStack.peek()); 139 | } 140 | } 141 | 142 | 143 | /** 144 | * 是否已经打开指定的activity 145 | * @param cls 146 | * @return 147 | */ 148 | public boolean isOpenActivity(Class cls) { 149 | if (activityStack!=null){ 150 | for (int i = 0, size = activityStack.size(); i < size; i++) { 151 | if (cls == activityStack.peek().getClass()) { 152 | return true; 153 | } 154 | } 155 | } 156 | return false; 157 | } 158 | 159 | /** 160 | * 退出应用程序 161 | * 162 | * @param context 上下文 163 | * @param isBackground 是否开开启后台运行 164 | */ 165 | public void AppExit(Context context, Boolean isBackground) { 166 | try { 167 | finishAllActivity(); 168 | ActivityManager activityMgr = (ActivityManager) context 169 | .getSystemService(Context.ACTIVITY_SERVICE); 170 | activityMgr.restartPackage(context.getPackageName()); 171 | } catch (Exception e) { 172 | 173 | } finally { 174 | // 注意,如果您有后台程序运行,请不要支持此句子 175 | if (!isBackground) { 176 | System.exit(0); 177 | } 178 | } 179 | } 180 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/utils/StatusBarUtil.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.annotation.TargetApi; 5 | import android.app.Activity; 6 | import android.content.Context; 7 | import android.graphics.Color; 8 | import android.os.Build; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.view.Window; 12 | import android.view.WindowManager; 13 | 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.reflect.Field; 17 | import java.lang.reflect.Method; 18 | 19 | import androidx.annotation.IntDef; 20 | 21 | /** 22 | * @Description:描述信息 23 | * @Author:Sai 24 | * @Date:2019/3/12 14:37 25 | */ 26 | public class StatusBarUtil { 27 | public final static int TYPE_MIUI = 0; 28 | public final static int TYPE_FLYME = 1; 29 | public final static int TYPE_M = 3;//6.0 30 | 31 | @IntDef({TYPE_MIUI, 32 | TYPE_FLYME, 33 | TYPE_M}) 34 | @Retention(RetentionPolicy.SOURCE) 35 | @interface ViewType { 36 | } 37 | 38 | /** 39 | * 修改状态栏颜色,支持4.4以上版本 40 | * 41 | * @param colorId 颜色 42 | */ 43 | public static void setStatusBarColor(Activity activity, int colorId) { 44 | 45 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 46 | Window window = activity.getWindow(); 47 | window.setStatusBarColor(colorId); 48 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 49 | //使用SystemBarTintManager,需要先将状态栏设置为透明 50 | setTranslucentStatus(activity); 51 | SystemBarTintManager systemBarTintManager = new SystemBarTintManager(activity); 52 | systemBarTintManager.setStatusBarTintEnabled(true);//显示状态栏 53 | systemBarTintManager.setStatusBarTintColor(colorId);//设置状态栏颜色 54 | } 55 | } 56 | 57 | /** 58 | * 设置状态栏透明 59 | */ 60 | @TargetApi(19) 61 | public static void setTranslucentStatus(Activity activity) { 62 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 63 | //5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色 64 | Window window = activity.getWindow(); 65 | View decorView = window.getDecorView(); 66 | //两个 flag 要结合使用,表示让应用的主体内容占用系统状态栏的空间 67 | int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 68 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; 69 | decorView.setSystemUiVisibility(option); 70 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 71 | window.setStatusBarColor(Color.TRANSPARENT); 72 | //导航栏颜色也可以正常设置 73 | //window.setNavigationBarColor(Color.TRANSPARENT); 74 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 75 | Window window = activity.getWindow(); 76 | WindowManager.LayoutParams attributes = window.getAttributes(); 77 | int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 78 | attributes.flags |= flagTranslucentStatus; 79 | //int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; 80 | //attributes.flags |= flagTranslucentNavigation; 81 | window.setAttributes(attributes); 82 | } 83 | } 84 | 85 | 86 | /** 87 | * 代码实现android:fitsSystemWindows 88 | * 89 | * @param activity 90 | */ 91 | public static void setRootViewFitsSystemWindows(Activity activity, boolean fitSystemWindows) { 92 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 93 | ViewGroup winContent = (ViewGroup) activity.findViewById(android.R.id.content); 94 | if (winContent.getChildCount() > 0) { 95 | ViewGroup rootView = (ViewGroup) winContent.getChildAt(0); 96 | if (rootView != null) { 97 | rootView.setFitsSystemWindows(fitSystemWindows); 98 | } 99 | } 100 | } 101 | 102 | } 103 | 104 | 105 | /** 106 | * 设置状态栏深色浅色切换 107 | */ 108 | public static boolean setStatusBarDarkTheme(Activity activity, boolean dark) { 109 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 110 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 111 | setStatusBarFontIconDark(activity, TYPE_M, dark); 112 | } else if (OSUtils.isMiui()) { 113 | setStatusBarFontIconDark(activity, TYPE_MIUI, dark); 114 | } else if (OSUtils.isFlyme()) { 115 | setStatusBarFontIconDark(activity, TYPE_FLYME, dark); 116 | } else {//其他情况 117 | return false; 118 | } 119 | 120 | return true; 121 | } 122 | return false; 123 | } 124 | 125 | /** 126 | * 设置 状态栏深色浅色切换 127 | */ 128 | public static boolean setStatusBarFontIconDark(Activity activity, @ViewType int type,boolean dark) { 129 | switch (type) { 130 | case TYPE_MIUI: 131 | return setMiuiUI(activity, dark); 132 | case TYPE_FLYME: 133 | return setFlymeUI(activity, dark); 134 | case TYPE_M: 135 | default: 136 | return setCommonUI(activity,dark); 137 | } 138 | } 139 | 140 | //设置6.0 状态栏深色浅色切换 141 | public static boolean setCommonUI(Activity activity, boolean dark) { 142 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 143 | View decorView = activity.getWindow().getDecorView(); 144 | if (decorView != null) { 145 | int vis = decorView.getSystemUiVisibility(); 146 | if (dark) { 147 | vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; 148 | } else { 149 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; 150 | } 151 | if (decorView.getSystemUiVisibility() != vis) { 152 | decorView.setSystemUiVisibility(vis); 153 | } 154 | return true; 155 | } 156 | } 157 | return false; 158 | 159 | } 160 | 161 | //设置Flyme 状态栏深色浅色切换 162 | public static boolean setFlymeUI(Activity activity, boolean dark) { 163 | try { 164 | Window window = activity.getWindow(); 165 | WindowManager.LayoutParams lp = window.getAttributes(); 166 | Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); 167 | Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags"); 168 | darkFlag.setAccessible(true); 169 | meizuFlags.setAccessible(true); 170 | int bit = darkFlag.getInt(null); 171 | int value = meizuFlags.getInt(lp); 172 | if (dark) { 173 | value |= bit; 174 | } else { 175 | value &= ~bit; 176 | } 177 | meizuFlags.setInt(lp, value); 178 | window.setAttributes(lp); 179 | return true; 180 | } catch (Exception e) { 181 | e.printStackTrace(); 182 | return false; 183 | } 184 | } 185 | 186 | //设置MIUI 状态栏深色浅色切换 187 | public static boolean setMiuiUI(Activity activity, boolean dark) { 188 | try { 189 | Window window = activity.getWindow(); 190 | Class clazz = activity.getWindow().getClass(); 191 | @SuppressLint("PrivateApi") Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); 192 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); 193 | int darkModeFlag = field.getInt(layoutParams); 194 | Method extraFlagField = clazz.getDeclaredMethod("setExtraFlags", int.class, int.class); 195 | extraFlagField.setAccessible(true); 196 | if (dark) { //状态栏亮色且黑色字体 197 | extraFlagField.invoke(window, darkModeFlag, darkModeFlag); 198 | } else { 199 | extraFlagField.invoke(window, 0, darkModeFlag); 200 | } 201 | return true; 202 | } catch (Exception e) { 203 | e.printStackTrace(); 204 | return false; 205 | } 206 | } 207 | //获取状态栏高度 208 | public static int getStatusBarHeight(Context context) { 209 | int result = 0; 210 | int resourceId = context.getResources().getIdentifier( 211 | "status_bar_height", "dimen", "android"); 212 | if (resourceId > 0) { 213 | result = context.getResources().getDimensionPixelSize(resourceId); 214 | } 215 | return result; 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /katafoundation/src/main/java/com/bigkoo/utils/SystemBarTintManager.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.annotation.TargetApi; 5 | import android.app.Activity; 6 | import android.content.Context; 7 | import android.content.res.Configuration; 8 | import android.content.res.Resources; 9 | import android.content.res.TypedArray; 10 | import android.graphics.drawable.Drawable; 11 | import android.os.Build; 12 | import android.util.DisplayMetrics; 13 | import android.util.TypedValue; 14 | import android.view.Gravity; 15 | import android.view.View; 16 | import android.view.ViewConfiguration; 17 | import android.view.ViewGroup; 18 | import android.view.Window; 19 | import android.view.WindowManager; 20 | import android.widget.FrameLayout.LayoutParams; 21 | 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * Class to manage status and navigation bar tint effects when using KitKat 26 | * translucent system UI modes. 27 | */ 28 | public class SystemBarTintManager { 29 | 30 | static { 31 | // Android allows a system property to override the presence of the navigation bar. 32 | // Used by the emulator. 33 | // See https://github.com/android/platform_frameworks_base/blob/master/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java#L1076 34 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 35 | try { 36 | Class c = Class.forName("android.os.SystemProperties"); 37 | Method m = c.getDeclaredMethod("get", String.class); 38 | m.setAccessible(true); 39 | sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys"); 40 | } catch (Throwable e) { 41 | sNavBarOverride = null; 42 | } 43 | } 44 | } 45 | 46 | 47 | /** 48 | * The default system bar tint color value. 49 | */ 50 | public static final int DEFAULT_TINT_COLOR = 0x99000000; 51 | 52 | private static String sNavBarOverride; 53 | 54 | private final SystemBarConfig mConfig; 55 | private boolean mStatusBarAvailable; 56 | private boolean mNavBarAvailable; 57 | private boolean mStatusBarTintEnabled; 58 | private boolean mNavBarTintEnabled; 59 | private View mStatusBarTintView; 60 | private View mNavBarTintView; 61 | 62 | /** 63 | * Constructor. Call this in the host activity onCreate method after its 64 | * content view has been set. You should always create new instances when 65 | * the host activity is recreated. 66 | * 67 | * @param activity The host activity. 68 | */ 69 | @TargetApi(19) 70 | public SystemBarTintManager(Activity activity) { 71 | 72 | Window win = activity.getWindow(); 73 | ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); 74 | 75 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 76 | // check theme attrs 77 | int[] attrs = {android.R.attr.windowTranslucentStatus, 78 | android.R.attr.windowTranslucentNavigation}; 79 | TypedArray a = activity.obtainStyledAttributes(attrs); 80 | try { 81 | mStatusBarAvailable = a.getBoolean(0, false); 82 | mNavBarAvailable = a.getBoolean(1, false); 83 | } finally { 84 | a.recycle(); 85 | } 86 | 87 | // check window flags 88 | WindowManager.LayoutParams winParams = win.getAttributes(); 89 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 90 | if ((winParams.flags & bits) != 0) { 91 | mStatusBarAvailable = true; 92 | } 93 | bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; 94 | if ((winParams.flags & bits) != 0) { 95 | mNavBarAvailable = true; 96 | } 97 | } 98 | 99 | mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); 100 | // device might not have virtual navigation keys 101 | if (!mConfig.hasNavigtionBar()) { 102 | mNavBarAvailable = false; 103 | } 104 | 105 | if (mStatusBarAvailable) { 106 | setupStatusBarView(activity, decorViewGroup); 107 | } 108 | if (mNavBarAvailable) { 109 | setupNavBarView(activity, decorViewGroup); 110 | } 111 | 112 | } 113 | 114 | /** 115 | * Enable tinting of the system status bar. 116 | *

117 | * If the platform is running Jelly Bean or earlier, or translucent system 118 | * UI modes have not been enabled in either the theme or via window flags, 119 | * then this method does nothing. 120 | * 121 | * @param enabled True to enable tinting, false to disable it (default). 122 | */ 123 | public void setStatusBarTintEnabled(boolean enabled) { 124 | mStatusBarTintEnabled = enabled; 125 | if (mStatusBarAvailable) { 126 | mStatusBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE); 127 | } 128 | } 129 | 130 | /** 131 | * Enable tinting of the system navigation bar. 132 | *

133 | * If the platform does not have soft navigation keys, is running Jelly Bean 134 | * or earlier, or translucent system UI modes have not been enabled in either 135 | * the theme or via window flags, then this method does nothing. 136 | * 137 | * @param enabled True to enable tinting, false to disable it (default). 138 | */ 139 | public void setNavigationBarTintEnabled(boolean enabled) { 140 | mNavBarTintEnabled = enabled; 141 | if (mNavBarAvailable) { 142 | mNavBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE); 143 | } 144 | } 145 | 146 | /** 147 | * Apply the specified color tint to all system UI bars. 148 | * 149 | * @param color The color of the background tint. 150 | */ 151 | public void setTintColor(int color) { 152 | setStatusBarTintColor(color); 153 | setNavigationBarTintColor(color); 154 | } 155 | 156 | /** 157 | * Apply the specified drawable or color resource to all system UI bars. 158 | * 159 | * @param res The identifier of the resource. 160 | */ 161 | public void setTintResource(int res) { 162 | setStatusBarTintResource(res); 163 | setNavigationBarTintResource(res); 164 | } 165 | 166 | /** 167 | * Apply the specified drawable to all system UI bars. 168 | * 169 | * @param drawable The drawable to use as the background, or null to remove it. 170 | */ 171 | public void setTintDrawable(Drawable drawable) { 172 | setStatusBarTintDrawable(drawable); 173 | setNavigationBarTintDrawable(drawable); 174 | } 175 | 176 | /** 177 | * Apply the specified alpha to all system UI bars. 178 | * 179 | * @param alpha The alpha to use 180 | */ 181 | public void setTintAlpha(float alpha) { 182 | setStatusBarAlpha(alpha); 183 | setNavigationBarAlpha(alpha); 184 | } 185 | 186 | /** 187 | * Apply the specified color tint to the system status bar. 188 | * 189 | * @param color The color of the background tint. 190 | */ 191 | public void setStatusBarTintColor(int color) { 192 | if (mStatusBarAvailable) { 193 | mStatusBarTintView.setBackgroundColor(color); 194 | } 195 | } 196 | 197 | /** 198 | * Apply the specified drawable or color resource to the system status bar. 199 | * 200 | * @param res The identifier of the resource. 201 | */ 202 | public void setStatusBarTintResource(int res) { 203 | if (mStatusBarAvailable) { 204 | mStatusBarTintView.setBackgroundResource(res); 205 | } 206 | } 207 | 208 | /** 209 | * Apply the specified drawable to the system status bar. 210 | * 211 | * @param drawable The drawable to use as the background, or null to remove it. 212 | */ 213 | @SuppressWarnings("deprecation") 214 | public void setStatusBarTintDrawable(Drawable drawable) { 215 | if (mStatusBarAvailable) { 216 | mStatusBarTintView.setBackgroundDrawable(drawable); 217 | } 218 | } 219 | 220 | /** 221 | * Apply the specified alpha to the system status bar. 222 | * 223 | * @param alpha The alpha to use 224 | */ 225 | @TargetApi(11) 226 | public void setStatusBarAlpha(float alpha) { 227 | if (mStatusBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 228 | mStatusBarTintView.setAlpha(alpha); 229 | } 230 | } 231 | 232 | /** 233 | * Apply the specified color tint to the system navigation bar. 234 | * 235 | * @param color The color of the background tint. 236 | */ 237 | public void setNavigationBarTintColor(int color) { 238 | if (mNavBarAvailable) { 239 | mNavBarTintView.setBackgroundColor(color); 240 | } 241 | } 242 | 243 | /** 244 | * Apply the specified drawable or color resource to the system navigation bar. 245 | * 246 | * @param res The identifier of the resource. 247 | */ 248 | public void setNavigationBarTintResource(int res) { 249 | if (mNavBarAvailable) { 250 | mNavBarTintView.setBackgroundResource(res); 251 | } 252 | } 253 | 254 | /** 255 | * Apply the specified drawable to the system navigation bar. 256 | * 257 | * @param drawable The drawable to use as the background, or null to remove it. 258 | */ 259 | @SuppressWarnings("deprecation") 260 | public void setNavigationBarTintDrawable(Drawable drawable) { 261 | if (mNavBarAvailable) { 262 | mNavBarTintView.setBackgroundDrawable(drawable); 263 | } 264 | } 265 | 266 | /** 267 | * Apply the specified alpha to the system navigation bar. 268 | * 269 | * @param alpha The alpha to use 270 | */ 271 | @TargetApi(11) 272 | public void setNavigationBarAlpha(float alpha) { 273 | if (mNavBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 274 | mNavBarTintView.setAlpha(alpha); 275 | } 276 | } 277 | 278 | /** 279 | * Get the system bar configuration. 280 | * 281 | * @return The system bar configuration for the current device configuration. 282 | */ 283 | public SystemBarConfig getConfig() { 284 | return mConfig; 285 | } 286 | 287 | /** 288 | * Is tinting enabled for the system status bar? 289 | * 290 | * @return True if enabled, False otherwise. 291 | */ 292 | public boolean isStatusBarTintEnabled() { 293 | return mStatusBarTintEnabled; 294 | } 295 | 296 | /** 297 | * Is tinting enabled for the system navigation bar? 298 | * 299 | * @return True if enabled, False otherwise. 300 | */ 301 | public boolean isNavBarTintEnabled() { 302 | return mNavBarTintEnabled; 303 | } 304 | 305 | private void setupStatusBarView(Context context, ViewGroup decorViewGroup) { 306 | mStatusBarTintView = new View(context); 307 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight()); 308 | params.gravity = Gravity.TOP; 309 | if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) { 310 | params.rightMargin = mConfig.getNavigationBarWidth(); 311 | } 312 | mStatusBarTintView.setLayoutParams(params); 313 | mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR); 314 | mStatusBarTintView.setVisibility(View.GONE); 315 | decorViewGroup.addView(mStatusBarTintView); 316 | } 317 | 318 | private void setupNavBarView(Context context, ViewGroup decorViewGroup) { 319 | mNavBarTintView = new View(context); 320 | LayoutParams params; 321 | if (mConfig.isNavigationAtBottom()) { 322 | params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight()); 323 | params.gravity = Gravity.BOTTOM; 324 | } else { 325 | params = new LayoutParams(mConfig.getNavigationBarWidth(), LayoutParams.MATCH_PARENT); 326 | params.gravity = Gravity.RIGHT; 327 | } 328 | mNavBarTintView.setLayoutParams(params); 329 | mNavBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR); 330 | mNavBarTintView.setVisibility(View.GONE); 331 | decorViewGroup.addView(mNavBarTintView); 332 | } 333 | 334 | /** 335 | * Class which describes system bar sizing and other characteristics for the current 336 | * device configuration. 337 | */ 338 | public static class SystemBarConfig { 339 | 340 | private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height"; 341 | private static final String NAV_BAR_HEIGHT_RES_NAME = "navigation_bar_height"; 342 | private static final String NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME = "navigation_bar_height_landscape"; 343 | private static final String NAV_BAR_WIDTH_RES_NAME = "navigation_bar_width"; 344 | private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar"; 345 | 346 | private final boolean mTranslucentStatusBar; 347 | private final boolean mTranslucentNavBar; 348 | private final int mStatusBarHeight; 349 | private final int mActionBarHeight; 350 | private final boolean mHasNavigationBar; 351 | private final int mNavigationBarHeight; 352 | private final int mNavigationBarWidth; 353 | private final boolean mInPortrait; 354 | private final float mSmallestWidthDp; 355 | 356 | private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) { 357 | Resources res = activity.getResources(); 358 | mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); 359 | mSmallestWidthDp = getSmallestWidthDp(activity); 360 | mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME); 361 | mActionBarHeight = getActionBarHeight(activity); 362 | mNavigationBarHeight = getNavigationBarHeight(activity); 363 | mNavigationBarWidth = getNavigationBarWidth(activity); 364 | mHasNavigationBar = (mNavigationBarHeight > 0); 365 | mTranslucentStatusBar = translucentStatusBar; 366 | mTranslucentNavBar = traslucentNavBar; 367 | } 368 | 369 | @TargetApi(14) 370 | private int getActionBarHeight(Context context) { 371 | int result = 0; 372 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 373 | TypedValue tv = new TypedValue(); 374 | context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true); 375 | result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); 376 | } 377 | return result; 378 | } 379 | 380 | @TargetApi(14) 381 | private int getNavigationBarHeight(Context context) { 382 | Resources res = context.getResources(); 383 | int result = 0; 384 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 385 | if (hasNavBar(context)) { 386 | String key; 387 | if (mInPortrait) { 388 | key = NAV_BAR_HEIGHT_RES_NAME; 389 | } else { 390 | key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME; 391 | } 392 | return getInternalDimensionSize(res, key); 393 | } 394 | } 395 | return result; 396 | } 397 | 398 | @TargetApi(14) 399 | private int getNavigationBarWidth(Context context) { 400 | Resources res = context.getResources(); 401 | int result = 0; 402 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 403 | if (hasNavBar(context)) { 404 | return getInternalDimensionSize(res, NAV_BAR_WIDTH_RES_NAME); 405 | } 406 | } 407 | return result; 408 | } 409 | 410 | @TargetApi(14) 411 | private boolean hasNavBar(Context context) { 412 | Resources res = context.getResources(); 413 | int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android"); 414 | if (resourceId != 0) { 415 | boolean hasNav = res.getBoolean(resourceId); 416 | // check override flag (see static block) 417 | if ("1".equals(sNavBarOverride)) { 418 | hasNav = false; 419 | } else if ("0".equals(sNavBarOverride)) { 420 | hasNav = true; 421 | } 422 | return hasNav; 423 | } else { // fallback 424 | return !ViewConfiguration.get(context).hasPermanentMenuKey(); 425 | } 426 | } 427 | 428 | private int getInternalDimensionSize(Resources res, String key) { 429 | int result = 0; 430 | int resourceId = res.getIdentifier(key, "dimen", "android"); 431 | if (resourceId > 0) { 432 | result = res.getDimensionPixelSize(resourceId); 433 | } 434 | return result; 435 | } 436 | 437 | @SuppressLint("NewApi") 438 | private float getSmallestWidthDp(Activity activity) { 439 | DisplayMetrics metrics = new DisplayMetrics(); 440 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 441 | activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); 442 | } else { 443 | // TODO this is not correct, but we don't really care pre-kitkat 444 | activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); 445 | } 446 | float widthDp = metrics.widthPixels / metrics.density; 447 | float heightDp = metrics.heightPixels / metrics.density; 448 | return Math.min(widthDp, heightDp); 449 | } 450 | 451 | /** 452 | * Should a navigation bar appear at the bottom of the screen in the current 453 | * device configuration? A navigation bar may appear on the right side of 454 | * the screen in certain configurations. 455 | * 456 | * @return True if navigation should appear at the bottom of the screen, False otherwise. 457 | */ 458 | public boolean isNavigationAtBottom() { 459 | return (mSmallestWidthDp >= 600 || mInPortrait); 460 | } 461 | 462 | /** 463 | * Get the height of the system status bar. 464 | * 465 | * @return The height of the status bar (in pixels). 466 | */ 467 | public int getStatusBarHeight() { 468 | return mStatusBarHeight; 469 | } 470 | 471 | /** 472 | * Get the height of the action bar. 473 | * 474 | * @return The height of the action bar (in pixels). 475 | */ 476 | public int getActionBarHeight() { 477 | return mActionBarHeight; 478 | } 479 | 480 | /** 481 | * Does this device have a system navigation bar? 482 | * 483 | * @return True if this device uses soft key navigation, False otherwise. 484 | */ 485 | public boolean hasNavigtionBar() { 486 | return mHasNavigationBar; 487 | } 488 | 489 | /** 490 | * Get the height of the system navigation bar. 491 | * 492 | * @return The height of the navigation bar (in pixels). If the device does not have 493 | * soft navigation keys, this will always return 0. 494 | */ 495 | public int getNavigationBarHeight() { 496 | return mNavigationBarHeight; 497 | } 498 | 499 | /** 500 | * Get the width of the system navigation bar when it is placed vertically on the screen. 501 | * 502 | * @return The width of the navigation bar (in pixels). If the device does not have 503 | * soft navigation keys, this will always return 0. 504 | */ 505 | public int getNavigationBarWidth() { 506 | return mNavigationBarWidth; 507 | } 508 | 509 | /** 510 | * Get the layout inset for any system UI that appears at the top of the screen. 511 | * 512 | * @param withActionBar True to include the height of the action bar, False otherwise. 513 | * @return The layout inset (in pixels). 514 | */ 515 | public int getPixelInsetTop(boolean withActionBar) { 516 | return (mTranslucentStatusBar ? mStatusBarHeight : 0) + (withActionBar ? mActionBarHeight : 0); 517 | } 518 | 519 | /** 520 | * Get the layout inset for any system UI that appears at the bottom of the screen. 521 | * 522 | * @return The layout inset (in pixels). 523 | */ 524 | public int getPixelInsetBottom() { 525 | if (mTranslucentNavBar && isNavigationAtBottom()) { 526 | return mNavigationBarHeight; 527 | } else { 528 | return 0; 529 | } 530 | } 531 | 532 | /** 533 | * Get the layout inset for any system UI that appears at the right of the screen. 534 | * 535 | * @return The layout inset (in pixels). 536 | */ 537 | public int getPixelInsetRight() { 538 | if (mTranslucentNavBar && !isNavigationAtBottom()) { 539 | return mNavigationBarWidth; 540 | } else { 541 | return 0; 542 | } 543 | } 544 | 545 | } 546 | 547 | } 548 | 549 | --------------------------------------------------------------------------------