├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── wsdydeni │ │ └── widget │ │ └── library │ │ ├── MainActivity.kt │ │ ├── MainViewModel.kt │ │ ├── MyApplication.kt │ │ ├── base │ │ ├── BaseViewModel.kt │ │ └── ViewModelEffect.kt │ │ ├── data │ │ └── network │ │ │ ├── ArticleList.kt │ │ │ ├── DataWrapper.kt │ │ │ ├── Requests.kt │ │ │ └── WandroidService.kt │ │ ├── dialog │ │ └── LoadingDialog.kt │ │ └── viewbind │ │ ├── ActivityViewBindings.kt │ │ ├── BindUtils.kt │ │ ├── DialogFragmentViewBindings.kt │ │ ├── FragmentViewbindings.kt │ │ ├── ViewBindingProperty.kt │ │ └── ViewGroupBindings.kt │ └── res │ ├── anim │ ├── dialog_enter.xml │ ├── dialog_exit.xml │ └── rotate_animation.xml │ ├── drawable-640dpi │ └── loading_bg.9.png │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── drawable_dialog_loading.xml │ ├── drawable_transparent.xml │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_main.xml │ ├── dialog_loading.xml │ └── layout_statusbar_placeholder.xml │ ├── mipmap-mdpi │ ├── dialog_loading_img.png │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── themes.xml ├── baselib ├── .gitignore ├── build.gradle ├── consumer-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── kotlin │ └── wsdydeni │ │ └── library │ │ └── android │ │ ├── base │ │ ├── BaseActivity.kt │ │ ├── BaseFragment.kt │ │ └── MyHandler.kt │ │ └── utils │ │ ├── another │ │ ├── LogUtil.kt │ │ └── Proxy.kt │ │ ├── density │ │ ├── AutoDensity.kt │ │ ├── AutoDensityConfig.kt │ │ ├── CancelAdapt.kt │ │ ├── CustomAdapt.kt │ │ ├── CustomAdaptManager.kt │ │ └── DesignDraft.kt │ │ ├── display │ │ └── PixelUtil.kt │ │ ├── immersion │ │ ├── ImmersionDialogExt.kt │ │ ├── ImmersionNavigationBarExt.kt │ │ └── ImmersionStatusBarExt.kt │ │ ├── keyboard │ │ ├── KeyboardExt.kt │ │ ├── KeyboardHeightListener.kt │ │ └── KeyboardHeightProvider.kt │ │ ├── lifecycle │ │ ├── LifecycleExt.kt │ │ └── RepeatOnLifecycle.kt │ │ └── view │ │ └── SpannableExtensions.kt │ └── res │ ├── layout │ └── keyboard_popup_window.xml │ └── values │ └── ids.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | ### Example user template template 17 | ### Example user template 18 | 19 | # IntelliJ project files 20 | .idea 21 | *.iml 22 | out 23 | gen 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidBaseLibrary 2 | 3 | [![](https://jitpack.io/v/wsdydeni/AndroidBaseLibrary.svg)](https://jitpack.io/#wsdydeni/AndroidBaseLibrary) 4 | [![GitHub stars](https://img.shields.io/github/stars/wsdydeni/AndroidBaseLibrary)](https://github.com/wsdydeni/AndroidBaseLibrary/stargazers) 5 | [![GitHub issues](https://img.shields.io/github/issues/wsdydeni/AndroidBaseLibrary)](https://github.com/wsdydeni/AndroidBaseLibrary/issues) 6 | 7 | `MVI` 架构的 `Android` 基础库 8 | 9 | [MVI 架构 - 用Kotlin Flow解决Android开发中的痛点问题](https://juejin.cn/post/7031726493906829319) 10 | 11 | [MVI 架构 - 不做跟风党,LiveData,StateFlow,SharedFlow 使用场景对比](https://juejin.cn/post/7007602776502960165) 12 | 13 | ## 沉浸式 14 | 15 | ### 状态栏 16 | 17 | [封装使用](https://github.com/wsdydeni/AndroidBaseLibrary/blob/master/baselib/src/main/kotlin/wsdydeni/library/android/utils/immersion/ImmersionStatusBarExt.kt) 18 | 19 | ### 导航栏 20 | 21 | [Android 系统 Bar 沉浸式完美兼容方案](https://juejin.cn/post/7075578574362640421) 22 | 23 | ## 键盘高度适配 24 | 25 | [PopupWindow 方案](https://github.com/wsdydeni/AndroidBaseLibrary/blob/master/baselib/src/main/kotlin/wsdydeni/library/android/utils/keyboard/KeyboardHeightProvider.kt) 26 | 27 | [扩展函数封装](https://github.com/wsdydeni/AndroidBaseLibrary/blob/master/baselib/src/main/kotlin/wsdydeni/library/android/utils/keyboard/KeyboardExt.kt) 28 | 29 | ## 屏幕适配 30 | 31 | [AutoDensity](https://github.com/Hbottle/AutoDensity) 32 | 33 | 今日头条Android屏幕适配方案&Smallest屏幕适配方案最佳实践 34 | 35 | ## 网络请求 36 | 37 | [AndroidBaseLibraryNetwork](https://github.com/wsdydeni/AndroidBaseLibraryNetwork/tree/master/baselib-network/src/main/java/wsdydeni/library/android_network/network) 38 | 39 | # How to Use 40 | 41 | To get a Git project into your build: 42 | 43 | ## Step 1. Add the JitPack repository to your build file 44 | 45 | Add it in your root build.gradle at the end of repositories: 46 | ```gradle 47 | allprojects { 48 | repositories { 49 | maven { url "https://jitpack.io" } 50 | } 51 | } 52 | ``` 53 | ## Step 2. Add the dependency 54 | 55 | ```gradle 56 | dependencies { 57 | implementation 'com.github.wsdydeni:AndroidBaseLibrary:1.2.0' 58 | } 59 | ``` 60 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'org.jetbrains.kotlin.android' 4 | } 5 | 6 | android { 7 | compileSdk 30 8 | 9 | defaultConfig { 10 | applicationId "wsdydeni.widget.library" 11 | minSdk 21 12 | targetSdk 30 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | kotlinOptions { 30 | jvmTarget = '1.8' 31 | } 32 | viewBinding { 33 | enabled = true 34 | } 35 | } 36 | 37 | dependencies { 38 | implementation project(':baselib') 39 | implementation 'androidx.core:core-ktx:1.3.2' 40 | implementation 'androidx.appcompat:appcompat:1.3.1' 41 | implementation 'com.google.android.material:material:1.3.0' 42 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 43 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1" 44 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" 45 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1" 46 | 47 | implementation "com.squareup.retrofit2:retrofit:2.9.0" 48 | implementation 'com.squareup.retrofit2:converter-gson:2.7.0' 49 | implementation("com.squareup.okhttp3:okhttp:4.10.0") 50 | implementation 'com.github.fengzhizi715:saf-logginginterceptor:v1.6.13' 51 | implementation 'com.google.code.gson:gson:2.8.6' 52 | implementation 'com.github.getActivity:ToastUtils:10.5' 53 | } 54 | 55 | dependencies { 56 | implementation 'com.github.wsdydeni:AndroidBaseLibraryNetwork:1.2.0' 57 | } 58 | 59 | dependencies { 60 | // debugImplementation because LeakCanary should only run in debug builds. 61 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10' 62 | } 63 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library 2 | 3 | import android.view.MotionEvent 4 | import android.view.View 5 | import android.widget.EditText 6 | import android.widget.LinearLayout 7 | import android.widget.TextView 8 | import androidx.core.content.ContextCompat 9 | import androidx.lifecycle.Lifecycle 10 | import androidx.lifecycle.lifecycleScope 11 | import com.hjq.toast.ToastUtils 12 | import kotlinx.coroutines.Job 13 | import kotlinx.coroutines.launch 14 | import wsdydeni.library.android.base.BaseActivity 15 | import wsdydeni.library.android.base.BaseActivityHandler 16 | import wsdydeni.library.android.utils.another.LogUtil 17 | import wsdydeni.library.android.utils.density.AutoDensity 18 | import wsdydeni.library.android.utils.display.PixelUtil 19 | import wsdydeni.library.android.utils.immersion.getNavBarHeight 20 | import wsdydeni.library.android.utils.immersion.getStatusBarHeight 21 | import wsdydeni.library.android.utils.immersion.showStatusBarView 22 | import wsdydeni.library.android.utils.keyboard.addKeyboardMonitor 23 | import wsdydeni.library.android.utils.lifecycle.launchAndRepeatWithViewLifecycle 24 | import wsdydeni.library.android.utils.lifecycle.repeatOnLifecycle 25 | import wsdydeni.widget.library.base.DialogDismissEffect 26 | import wsdydeni.widget.library.base.DialogShowEffect 27 | import wsdydeni.widget.library.base.ToastShowEffect 28 | import wsdydeni.widget.library.dialog.LoadingDialog 29 | 30 | class MainActivity : BaseActivity(R.layout.activity_main) { 31 | 32 | private var lastClickTime: Long = 0L 33 | 34 | override var isLightSystemBar = true 35 | 36 | override var immersiveNavigation = true 37 | 38 | override var immersionStatus = true 39 | 40 | private var loadingDialog : LoadingDialog? = null 41 | 42 | private val myHandler = BaseActivityHandlers(this) 43 | 44 | override fun initView() { 45 | addKeyboardMonitor { keyboardHeight, _, _ -> 46 | if(keyboardHeight > 1000) { 47 | return@addKeyboardMonitor 48 | } 49 | if(keyboardHeight == 0) { 50 | val inputLayout = findViewById(R.id.input_layout) 51 | inputLayout.translationY = 0f 52 | return@addKeyboardMonitor 53 | } 54 | val focusView: View? = window.decorView.findFocus() 55 | if (focusView != null && focusView is EditText) { 56 | val locations = IntArray(2) 57 | focusView.getLocationOnScreen(locations) 58 | val focusEtTop = locations[1] 59 | val focusViewHeight = focusView.measuredHeight 60 | val focusBottom = focusEtTop + focusViewHeight 61 | val generalHeight = AutoDensity.instance.getAutoDensityConfig().heightPixels 62 | if (keyboardHeight > generalHeight + getStatusBarHeight() - focusBottom) { 63 | LogUtil.d("屏幕高度: ${AutoDensity.instance.getAutoDensityConfig().heightPixels}") 64 | LogUtil.d("状态栏高度: ${getStatusBarHeight()}") 65 | LogUtil.d("导航栏高度: ${getNavBarHeight()}") 66 | LogUtil.d("输入框底部高度: $focusBottom") 67 | LogUtil.d("输入框底部到屏幕底部的距离: ${generalHeight + getStatusBarHeight() - focusBottom}") 68 | LogUtil.d("键盘高度: $keyboardHeight") 69 | val difference = (generalHeight + getStatusBarHeight()) - (focusBottom + keyboardHeight) 70 | LogUtil.d("布局纵向偏移量: $difference") 71 | LogUtil.d("偏移量dp: ${PixelUtil.px2dp(this,difference)}") 72 | val inputLayout = findViewById(R.id.input_layout) 73 | inputLayout.translationY = difference.toFloat() 74 | } 75 | } 76 | } 77 | showStatusBarView(findViewById(R.id.fillStatusBarView), ContextCompat.getColor(this, R.color.color_6d7174)) 78 | 79 | findViewById(R.id.send_btn).setOnClickListener { 80 | lifecycleScope.launch { 81 | createLoadingDialog(job = mainViewModel.getArticle()) 82 | mainViewModel.setEffect { DialogShowEffect } 83 | } 84 | } 85 | } 86 | 87 | private fun createLoadingDialog(text: String = "加载中", isCanCancelByReturn: Boolean = true, job: Job? = null) { 88 | this.loadingDialog = LoadingDialog(this,job) 89 | .setLoadingText(text) 90 | .isCanCancelByReturn(isCanCancelByReturn) 91 | } 92 | 93 | override fun initData() { 94 | observeEffect() 95 | launchAndRepeatWithViewLifecycle { 96 | mainViewModel.articleList.collect { 97 | mainViewModel.setEffect { ToastShowEffect("加载成功") } 98 | } 99 | } 100 | } 101 | 102 | /** 103 | * 防止多次点击 104 | */ 105 | override fun dispatchTouchEvent(ev: MotionEvent?): Boolean { 106 | if(ev?.action == MotionEvent.ACTION_DOWN) { 107 | if(System.currentTimeMillis() - lastClickTime < 500L) { 108 | return true 109 | } 110 | lastClickTime = System.currentTimeMillis() 111 | } 112 | return super.dispatchTouchEvent(ev) 113 | } 114 | 115 | private val mainViewModel by lazy { MainViewModel() } 116 | 117 | private fun observeEffect() { 118 | lifecycleScope.launch { 119 | repeatOnLifecycle(Lifecycle.State.STARTED) { 120 | mainViewModel.effect.collect { effect -> 121 | when(effect) { 122 | is DialogShowEffect -> { 123 | if(!isDestroyed && !isFinishing) { 124 | myHandler.post { 125 | if(!isDestroyed && !isFinishing) { 126 | loadingDialog?.let { 127 | if(!it.isShowing) it.show() 128 | } 129 | } 130 | } 131 | } 132 | } 133 | is DialogDismissEffect -> { 134 | loadingDialog?.let { dialog -> 135 | dialog.dismissCancelJob(effect.isCancel) 136 | loadingDialog = null 137 | } 138 | } 139 | is ToastShowEffect -> { 140 | ToastUtils.show(effect.text) 141 | } 142 | } 143 | } 144 | } 145 | } 146 | } 147 | 148 | companion object { 149 | class BaseActivityHandlers(activity: BaseActivity) : BaseActivityHandler(activity) 150 | } 151 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/MainViewModel.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library 2 | 3 | import androidx.lifecycle.viewModelScope 4 | import kotlinx.coroutines.* 5 | import kotlinx.coroutines.flow.* 6 | import wsdydeni.library.android.utils.another.LogUtil 7 | import wsdydeni.library.android_network.network.associatedView 8 | import wsdydeni.widget.library.base.BaseViewModel 9 | import wsdydeni.widget.library.base.DialogDismissEffect 10 | import wsdydeni.widget.library.base.DialogShowEffect 11 | import wsdydeni.widget.library.base.ToastShowEffect 12 | import wsdydeni.widget.library.data.network.ArticleList 13 | import wsdydeni.widget.library.data.network.WandroidService 14 | import wsdydeni.widget.library.data.network.getApiService 15 | 16 | class MainViewModel : BaseViewModel() { 17 | 18 | private val articleService by lazy { getApiService() } 19 | 20 | private val coroutineExceptionHandler = CoroutineExceptionHandler { _, _ -> 21 | viewModelScope.launch { setEffect { DialogDismissEffect(true) } } 22 | } 23 | 24 | private val _articleLists = MutableSharedFlow() 25 | val articleList = _articleLists.asSharedFlow() 26 | 27 | fun getArticle() : Job { 28 | return viewModelScope.launch(Dispatchers.IO + coroutineExceptionHandler, start = CoroutineStart.LAZY) { 29 | associatedView( 30 | request = suspend { articleService.getArticleList() }, 31 | onRequestSuccess = { delay(1000L) 32 | setEffect { DialogDismissEffect() } }, 33 | onRequestError = { errorMsg, _ -> 34 | setEffect { DialogDismissEffect(true) } 35 | setEffect { ToastShowEffect(errorMsg) } 36 | } 37 | ).collect { 38 | _articleLists.emit(it) 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/MyApplication.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library 2 | 3 | import android.app.Application 4 | import com.hjq.toast.ToastUtils 5 | import wsdydeni.library.android.utils.another.LogUtil 6 | import wsdydeni.library.android.utils.density.AutoDensity 7 | import wsdydeni.library.android.utils.density.DesignDraft 8 | 9 | class MyApplication : Application() { 10 | override fun onCreate() { 11 | super.onCreate() 12 | LogUtil.init(true) 13 | ToastUtils.init(this) 14 | AutoDensity.instance.init(this, DesignDraft(designSize = 360f)) 15 | } 16 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/base/BaseViewModel.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.base 2 | 3 | import androidx.lifecycle.ViewModel 4 | import kotlinx.coroutines.channels.Channel 5 | import kotlinx.coroutines.flow.receiveAsFlow 6 | 7 | open class BaseViewModel : ViewModel() { 8 | private val _effect = Channel() 9 | val effect = _effect.receiveAsFlow() 10 | 11 | suspend fun setEffect(builder: () -> ViewModelEffect) { 12 | val newEffect = builder() 13 | _effect.send(newEffect) 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/base/ViewModelEffect.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.base 2 | 3 | sealed class ViewModelEffect 4 | 5 | object DialogShowEffect : ViewModelEffect() 6 | 7 | class DialogDismissEffect(val isCancel: Boolean = false) : ViewModelEffect() 8 | 9 | class ToastShowEffect(val text: String) : ViewModelEffect() -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/data/network/ArticleList.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.data.network 2 | 3 | data class ArticleList( 4 | val curPage: Int, 5 | val datas: List
, 6 | val offset: Int, 7 | val over: Boolean, 8 | val pageCount: Int, 9 | val size: Int, 10 | val total: Int 11 | ) 12 | 13 | data class Article( 14 | val adminAdd: Boolean, 15 | val apkLink: String, 16 | val audit: Int, 17 | val author: String, 18 | val canEdit: Boolean, 19 | val chapterId: Int, 20 | val chapterName: String, 21 | val collect: Boolean, 22 | val courseId: Int, 23 | val desc: String, 24 | val descMd: String, 25 | val envelopePic: String, 26 | val fresh: Boolean, 27 | val host: String, 28 | val id: Int, 29 | val isAdminAdd: Boolean, 30 | val link: String, 31 | val niceDate: String, 32 | val niceShareDate: String, 33 | val origin: String, 34 | val prefix: String, 35 | val projectLink: String, 36 | val publishTime: Long, 37 | val realSuperChapterId: Int, 38 | val route: Boolean, 39 | val selfVisible: Int, 40 | val shareDate: Long, 41 | val shareUser: String, 42 | val superChapterId: Int, 43 | val superChapterName: String, 44 | val tags: List, 45 | val title: String, 46 | val type: Int, 47 | val userId: Int, 48 | val visible: Int, 49 | val zan: Int 50 | ) 51 | 52 | data class Tag( 53 | val name: String, 54 | val url: String 55 | ) -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/data/network/DataWrapper.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.data.network 2 | 3 | import com.google.gson.annotations.SerializedName 4 | import wsdydeni.library.android_network.network.BaseResponse 5 | import java.io.Serializable 6 | 7 | data class DataWrapper( 8 | @SerializedName("data") var data: T, 9 | @SerializedName("errorMsg") var message : String, 10 | @SerializedName("errorCode") var code : Int 11 | ) : Serializable, BaseResponse() { 12 | 13 | override fun getResponseCode(): String = code.toString() 14 | 15 | override fun getResponseData(): T = data 16 | 17 | override fun getResponseMsg(): String = message 18 | 19 | override fun isSuccess(): Boolean = code == 0 20 | 21 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/data/network/Requests.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.data.network 2 | 3 | import com.google.gson.Gson 4 | import com.safframework.http.interceptor.AndroidLoggingInterceptor 5 | import okhttp3.OkHttpClient 6 | 7 | import retrofit2.Retrofit 8 | import retrofit2.converter.gson.GsonConverterFactory 9 | import java.util.concurrent.TimeUnit 10 | 11 | inline fun getApiService() : T { 12 | val retrofit = Retrofit.Builder() 13 | .baseUrl("https://www.wanandroid.com") 14 | .client(getOkhttp()) 15 | .addConverterFactory(GsonConverterFactory.create(Gson())) 16 | .build() 17 | return retrofit.create(T::class.java) 18 | } 19 | 20 | 21 | fun getOkhttp() : OkHttpClient { 22 | return OkHttpClient.Builder() 23 | .connectTimeout(2000L,TimeUnit.MILLISECONDS) 24 | .readTimeout(2000L,TimeUnit.MILLISECONDS) 25 | .addNetworkInterceptor(AndroidLoggingInterceptor.build()) 26 | .build() 27 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/data/network/WandroidService.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.data.network 2 | 3 | import retrofit2.http.GET 4 | 5 | interface WandroidService { 6 | @GET("/article/list/0/json") 7 | suspend fun getArticleList() : DataWrapper 8 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/dialog/LoadingDialog.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.dialog 2 | 3 | import android.app.Dialog 4 | import android.content.Context 5 | import android.view.Gravity 6 | import android.view.LayoutInflater 7 | import android.view.WindowManager 8 | import kotlinx.coroutines.Job 9 | import wsdydeni.widget.library.R 10 | import wsdydeni.widget.library.databinding.DialogLoadingBinding 11 | import java.lang.ref.WeakReference 12 | 13 | class LoadingDialog(context: Context,job: Job? = null) : Dialog(context, R.style.TransparentDialog) { 14 | 15 | private val jobRef by lazy { 16 | WeakReference(job) 17 | } 18 | 19 | private fun getJob() : Job? { 20 | return jobRef.get() 21 | } 22 | 23 | private var dialogLoadingBinding: DialogLoadingBinding 24 | 25 | init { 26 | window?.let { 27 | it.setGravity(Gravity.CENTER) 28 | it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) 29 | it.setWindowAnimations(R.style.PopWindowAnimStyle) 30 | } 31 | dialogLoadingBinding = DialogLoadingBinding.inflate(LayoutInflater.from(context)) 32 | setContentView(dialogLoadingBinding.root) 33 | setOnCancelListener { 34 | getJob()?.cancel() 35 | } 36 | } 37 | 38 | fun setLoadingText(title: String?) : LoadingDialog { 39 | title?.let { dialogLoadingBinding.tipTextView.text = it } 40 | return this 41 | } 42 | 43 | /** 44 | * 弹窗显示时启动Job 45 | */ 46 | override fun show() { 47 | super.show() 48 | getJob()?.start() 49 | } 50 | 51 | /** 52 | * 是否在异常关闭时取消Job 53 | */ 54 | fun dismissCancelJob(isCancel: Boolean) { 55 | if(isCancel) getJob()?.cancel() 56 | super.dismiss() 57 | } 58 | 59 | /** 60 | * 是否可以从外部取消弹窗 61 | */ 62 | fun isCanCancelByReturn(isReturnClose: Boolean) : LoadingDialog { 63 | if(isReturnClose) setCanceledOnTouchOutside(false) else setCancelable(false) 64 | return this 65 | } 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/viewbind/ActivityViewBindings.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.viewbind 2 | 3 | import android.view.View 4 | import androidx.activity.ComponentActivity 5 | import androidx.annotation.IdRes 6 | import androidx.annotation.RestrictTo 7 | import androidx.lifecycle.LifecycleOwner 8 | import androidx.viewbinding.ViewBinding 9 | 10 | 11 | @RestrictTo(RestrictTo.Scope.LIBRARY) 12 | private class ActivityViewBindingProperty(viewBinder: (A) -> T) 13 | : LifecycleViewBindingProperty(viewBinder) 14 | { 15 | override fun getLifecycleOwner(thisRef: A): LifecycleOwner { 16 | return thisRef 17 | } 18 | } 19 | 20 | 21 | @JvmName("viewBindingActivity") 22 | public fun viewBinding(viewBinder: (A) -> T) 23 | : ViewBindingProperty = ActivityViewBindingProperty(viewBinder) 24 | 25 | 26 | /** 27 | * 通过Activity获取根视图生成对应的ViewBinding对象 28 | * 29 | * @param A 目标Activity 30 | * @param T 目标Activity的ViewBinding 31 | * @param viewBindingFactory 通过Activity根视图生成对应的ViewBinding 32 | * @param viewProvider 接收一个Activity实例获取Activity的根视图 33 | * @return ViewBinding的代理对象 34 | */ 35 | @JvmName("viewBindingActivity") 36 | public inline fun viewBinding( 37 | crossinline viewBindingFactory: (View) -> T, 38 | crossinline viewProvider: (A) -> View = ::findRootView 39 | ) : ViewBindingProperty { 40 | return viewBinding { activity -> viewBindingFactory(viewProvider(activity)) } 41 | } 42 | 43 | 44 | /** 45 | * 和上面思路一致(Activity实例换成了Activity根视图) 46 | */ 47 | @JvmName("viewBindingActivity") 48 | public inline fun viewBinding( 49 | crossinline viewBindingFactory: (View) -> T, 50 | @IdRes viewBindingRootId: Int 51 | ): ViewBindingProperty { 52 | return viewBinding { activity -> viewBindingFactory(activity.requireViewByIdCompat(viewBindingRootId)) } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/viewbind/BindUtils.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.viewbind 2 | 3 | import android.app.Activity 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import androidx.annotation.IdRes 7 | import androidx.annotation.RestrictTo 8 | import androidx.core.app.ActivityCompat 9 | import androidx.core.view.ViewCompat 10 | import androidx.fragment.app.DialogFragment 11 | 12 | 13 | @Suppress("NOTHING_TO_INLINE") 14 | @RestrictTo(RestrictTo.Scope.LIBRARY) 15 | inline fun View.requireViewByIdCompat(@IdRes id: Int): V { 16 | return ViewCompat.requireViewById(this, id) 17 | } 18 | 19 | 20 | @Suppress("NOTHING_TO_INLINE") 21 | @RestrictTo(RestrictTo.Scope.LIBRARY) 22 | inline fun Activity.requireViewByIdCompat(@IdRes id: Int): V { 23 | return ActivityCompat.requireViewById(this,id) 24 | } 25 | 26 | 27 | /** 28 | * 从目标活动获取根视图 29 | * 30 | * @param activity 目标活动 31 | * @return 根视图 32 | */ 33 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 34 | fun findRootView(activity: Activity): View { 35 | val contentView = activity.findViewById(android.R.id.content) 36 | checkNotNull(contentView) { "Activity has no content view" } 37 | return when (contentView.childCount) { 38 | 1 -> contentView.getChildAt(0) 39 | 0 -> error("Content view has no children. Provide root view explicitly") 40 | else -> error("More than one child view found in Activity content view") 41 | } 42 | } 43 | 44 | 45 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 46 | fun DialogFragment.getRootView(viewBindingRootId: Int): View { 47 | val dialog = checkNotNull(dialog) { 48 | "DialogFragment doesn't have dialog. Use viewBinding delegate after onCreateDialog" 49 | } 50 | val window = checkNotNull(dialog.window) { "Fragment's Dialog has no window" } 51 | return with(window.decorView) { if (viewBindingRootId != 0) requireViewByIdCompat(viewBindingRootId) else this } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/viewbind/DialogFragmentViewBindings.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.viewbind 2 | 3 | import androidx.annotation.RestrictTo 4 | import androidx.fragment.app.DialogFragment 5 | import androidx.fragment.app.Fragment 6 | import androidx.lifecycle.LifecycleOwner 7 | import androidx.viewbinding.ViewBinding 8 | 9 | 10 | class DialogFragmentViewBindingProperty( 11 | viewBinder: (F) -> T 12 | ) : LifecycleViewBindingProperty(viewBinder) { 13 | 14 | override fun getLifecycleOwner(thisRef: F): LifecycleOwner { 15 | if(thisRef !is DialogFragment) { 16 | error("This Fragment is must be DialogFragment") 17 | } 18 | return if (thisRef.showsDialog) { 19 | thisRef 20 | } else { 21 | try { 22 | thisRef.viewLifecycleOwner 23 | } catch (ignored: IllegalStateException) { 24 | error("Fragment doesn't have view associated with it or the view has been destroyed") 25 | } 26 | } 27 | } 28 | } 29 | 30 | 31 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 32 | fun dialogFragmentViewBinding( 33 | viewBinder: (F) -> T 34 | ): ViewBindingProperty { 35 | return DialogFragmentViewBindingProperty( 36 | viewBinder 37 | ) 38 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/viewbind/FragmentViewbindings.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.viewbind 2 | 3 | import android.view.View 4 | import androidx.annotation.IdRes 5 | import androidx.fragment.app.DialogFragment 6 | import androidx.fragment.app.Fragment 7 | import androidx.lifecycle.LifecycleOwner 8 | import androidx.viewbinding.ViewBinding 9 | 10 | 11 | private class FragmentViewBindingProperty(viewBinder: (F) -> T) 12 | : LifecycleViewBindingProperty(viewBinder) 13 | { 14 | 15 | override fun getLifecycleOwner(thisRef: F): LifecycleOwner { 16 | try { 17 | return thisRef.viewLifecycleOwner 18 | }catch (ignored: IllegalStateException) { 19 | error("Fragment doesn't have view associated with it or the view has been destroyed") 20 | } 21 | } 22 | 23 | } 24 | 25 | 26 | @JvmName("viewBindingFragment") 27 | public fun Fragment.viewBinding( 28 | viewBinder: (F: Fragment) -> T 29 | ): ViewBindingProperty 30 | { 31 | return if(this is DialogFragment) DialogFragmentViewBindingProperty(viewBinder) 32 | else FragmentViewBindingProperty(viewBinder) 33 | } 34 | 35 | 36 | @JvmName("viewBindingFragment") 37 | public inline fun Fragment.viewBinding( 38 | crossinline viewBindingFactory: (View) -> T, 39 | crossinline viewBinderProvider: (F: Fragment) -> View = Fragment::requireView 40 | ) : ViewBindingProperty 41 | { 42 | return viewBinding { fragment: Fragment -> viewBindingFactory(viewBinderProvider(fragment)) } 43 | } 44 | 45 | 46 | @JvmName("viewBindingFragment") 47 | public inline fun Fragment.viewBinding( 48 | crossinline viewBindingFactory: (View) -> T, 49 | @IdRes viewBindingRootId: Int 50 | ) : ViewBindingProperty 51 | { 52 | return if(this is DialogFragment) { 53 | dialogFragmentViewBinding { viewBindingFactory(getRootView(viewBindingRootId)) } 54 | }else { 55 | viewBinding(viewBindingFactory) { fragment -> 56 | fragment.requireView().requireViewByIdCompat(viewBindingRootId) 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/viewbind/ViewBindingProperty.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.viewbind 2 | 3 | import android.os.Handler 4 | import android.os.Looper 5 | import androidx.annotation.MainThread 6 | import androidx.annotation.RestrictTo 7 | import androidx.lifecycle.Lifecycle 8 | import androidx.lifecycle.LifecycleEventObserver 9 | import androidx.lifecycle.LifecycleOwner 10 | import androidx.viewbinding.ViewBinding 11 | import wsdydeni.library.android.utils.another.LogUtil 12 | import kotlin.properties.ReadOnlyProperty 13 | import kotlin.reflect.KProperty 14 | 15 | 16 | /** 17 | * ViewBinding只读代理对象属性 18 | * 19 | * @param R 目标对象 20 | * @param T 要代理的属性 21 | */ 22 | interface ViewBindingProperty : ReadOnlyProperty { 23 | @MainThread fun clear() 24 | } 25 | 26 | 27 | /** 28 | * 实现ViewBindingProperty 29 | */ 30 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 31 | open class LazyViewBindingProperty(protected val viewBinder: (R) -> T) : 32 | ViewBindingProperty { 33 | 34 | private var viewBinding: Any? = null 35 | 36 | @Suppress("UNCHECKED_CAST") 37 | @MainThread 38 | override fun getValue(thisRef: R, property: KProperty<*>): T { 39 | return viewBinding as? T ?: viewBinder(thisRef).also { viewBinding -> 40 | this.viewBinding = viewBinding 41 | } 42 | } 43 | 44 | @MainThread 45 | override fun clear() { 46 | viewBinding = null 47 | } 48 | } 49 | 50 | 51 | /** 52 | * 实现ViewBindingProperty同时获取调用者的Lifecycle组件实现生命周期同步 53 | */ 54 | @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 55 | abstract class LifecycleViewBindingProperty(private val viewBinder: (R) -> T) : 56 | ViewBindingProperty { 57 | 58 | private var viewBinding: T? = null 59 | 60 | protected abstract fun getLifecycleOwner(thisRef: R): LifecycleOwner 61 | 62 | @MainThread 63 | override fun getValue(thisRef: R, property: KProperty<*>): T { 64 | viewBinding?.let { return it } 65 | 66 | val lifecycle = getLifecycleOwner(thisRef).lifecycle 67 | val viewBinding = viewBinder(thisRef) 68 | if (lifecycle.currentState == Lifecycle.State.DESTROYED) { 69 | LogUtil.w("Access to viewBinding after Lifecycle is destroyed or hasn't created yet. " 70 | + "The instance of viewBinding will be not cached.") 71 | } else { 72 | lifecycle.addObserver(ClearOnDestroyLifecycleObserver()) 73 | this.viewBinding = viewBinding 74 | } 75 | return viewBinding 76 | } 77 | 78 | @MainThread 79 | override fun clear() { 80 | mainHandler.post { viewBinding = null } 81 | } 82 | 83 | private inner class ClearOnDestroyLifecycleObserver: LifecycleEventObserver { 84 | @MainThread 85 | override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { 86 | if(event == Lifecycle.Event.ON_DESTROY) { 87 | clear() 88 | } 89 | } 90 | } 91 | 92 | private companion object { 93 | private val mainHandler = Handler(Looper.getMainLooper()) 94 | } 95 | } -------------------------------------------------------------------------------- /app/src/main/java/wsdydeni/widget/library/viewbind/ViewGroupBindings.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.widget.library.viewbind 2 | 3 | import android.view.View 4 | import android.view.ViewGroup 5 | import androidx.annotation.IdRes 6 | import androidx.annotation.RestrictTo 7 | import androidx.lifecycle.LifecycleOwner 8 | import androidx.lifecycle.ViewTreeLifecycleOwner 9 | import androidx.viewbinding.ViewBinding 10 | 11 | 12 | @PublishedApi 13 | @RestrictTo(RestrictTo.Scope.LIBRARY) 14 | internal class ViewGroupViewBindingProperty( 15 | viewBinder: (V) -> T) : LifecycleViewBindingProperty(viewBinder) 16 | { 17 | override fun getLifecycleOwner(thisRef: V): LifecycleOwner { 18 | return checkNotNull(ViewTreeLifecycleOwner.get(thisRef)) { 19 | "Fragment doesn't have view associated with it or the view has been destroyed" 20 | } 21 | } 22 | } 23 | 24 | 25 | inline fun ViewGroup.viewBinding( 26 | crossinline vbFactory: (ViewGroup) -> T 27 | ) : ViewBindingProperty 28 | { 29 | return viewBinding(lifecycleAware = false, vbFactory = vbFactory) 30 | } 31 | 32 | 33 | inline fun ViewGroup.viewBinding( 34 | lifecycleAware: Boolean, crossinline vbFactory: (ViewGroup) -> T) 35 | : ViewBindingProperty 36 | { 37 | return if (lifecycleAware) { 38 | ViewGroupViewBindingProperty { viewGroup -> vbFactory(viewGroup) } 39 | } else { 40 | LazyViewBindingProperty { viewGroup -> vbFactory(viewGroup) } 41 | } 42 | } 43 | 44 | 45 | inline fun ViewGroup.viewBinding( 46 | @IdRes viewBindingRootId: Int, crossinline vbFactory: (View) -> T 47 | ) : ViewBindingProperty 48 | { 49 | return viewBinding(viewBindingRootId, lifecycleAware = false, vbFactory = vbFactory) 50 | } 51 | 52 | 53 | inline fun ViewGroup.viewBinding( 54 | @IdRes viewBindingRootId: Int, lifecycleAware: Boolean, crossinline vbFactory: (View) -> T) 55 | : ViewBindingProperty 56 | { 57 | if (lifecycleAware) return ViewGroupViewBindingProperty { viewGroup -> vbFactory(viewGroup) } 58 | return LazyViewBindingProperty { viewGroup: ViewGroup -> 59 | vbFactory(viewGroup.requireViewByIdCompat(viewBindingRootId)) 60 | } 61 | } -------------------------------------------------------------------------------- /app/src/main/res/anim/dialog_enter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/anim/dialog_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/anim/rotate_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-640dpi/loading_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wsdydeni/AndroidBaseLibrary/37ff240b101a8aced03f77293a7b4090edb83799/app/src/main/res/drawable-640dpi/loading_bg.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/drawable_dialog_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/drawable_transparent.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 17 | 18 | 26 | 27 | 34 | 35 | 39 | 40 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 21 | 22 | 30 | 31 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_statusbar_placeholder.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/dialog_loading_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wsdydeni/AndroidBaseLibrary/37ff240b101a8aced03f77293a7b4090edb83799/app/src/main/res/mipmap-mdpi/dialog_loading_img.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wsdydeni/AndroidBaseLibrary/37ff240b101a8aced03f77293a7b4090edb83799/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wsdydeni/AndroidBaseLibrary/37ff240b101a8aced03f77293a7b4090edb83799/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF000000 4 | #FFFFFFFF 5 | #80FFFFFF 6 | 7 | #A0A0A0 8 | #00599B 9 | #181819 10 | #D4D1CD 11 | #949697 12 | #FAFAFA 13 | #fefefe 14 | #ffd4d4d4 15 | #6d7174 16 | #9ca3a8 17 | #ebebeb 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0.5dp 4 | 1dp 5 | 2dp 6 | 5dp 7 | 10dp 8 | 12sp 9 | 13sp 10 | 14dp 11 | 15dp 12 | 16sp 13 | 18sp 14 | 20dp 15 | 25dp 16 | 40dp 17 | 45dp 18 | 50dp 19 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidBaseLibrary 3 | 发送 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 24 | 25 | 26 | 32 | -------------------------------------------------------------------------------- /baselib/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /baselib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.library" 2 | apply plugin: "kotlin-android" 3 | 4 | android { 5 | compileSdk 31 6 | 7 | defaultConfig { 8 | //noinspection OldTargetApi 9 | targetSdkVersion 31 10 | minSdkVersion 21 11 | version "1.2.0" 12 | } 13 | 14 | buildTypes { 15 | debug { 16 | buildConfigField("boolean","IS_DEBUG","true") 17 | consumerProguardFiles 'consumer-rules.pro' 18 | } 19 | release { 20 | buildConfigField("boolean","IS_DEBUG","false") 21 | consumerProguardFiles 'consumer-rules.pro' 22 | } 23 | } 24 | 25 | java { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | 30 | kotlinOptions { 31 | jvmTarget = JavaVersion.VERSION_1_8 32 | } 33 | 34 | } 35 | 36 | dependencies { 37 | //noinspection GradleDependency 38 | implementation("androidx.appcompat:appcompat:1.3.1") 39 | //noinspection GradleDependency 40 | implementation("androidx.lifecycle:lifecycle-common-java8:2.4.1") 41 | //noinspection GradleDependency 42 | implementation("androidx.activity:activity-ktx:1.2.2") 43 | //noinspection GradleDependency 44 | implementation("androidx.fragment:fragment-ktx:1.3.2") 45 | } -------------------------------------------------------------------------------- /baselib/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wsdydeni/AndroidBaseLibrary/37ff240b101a8aced03f77293a7b4090edb83799/baselib/consumer-rules.pro -------------------------------------------------------------------------------- /baselib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/base/BaseActivity.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.base 2 | 3 | import android.content.pm.ActivityInfo 4 | import android.os.Bundle 5 | import androidx.annotation.LayoutRes 6 | import androidx.fragment.app.FragmentActivity 7 | import wsdydeni.library.android.utils.immersion.fitNavigationBar 8 | import wsdydeni.library.android.utils.immersion.immersionStatusBar 9 | import wsdydeni.library.android.utils.immersion.immersiveNavigationBar 10 | import wsdydeni.library.android.utils.immersion.setLightNavigationBar 11 | 12 | 13 | open class BaseActivity : FragmentActivity { 14 | 15 | constructor() : super() 16 | 17 | constructor(@LayoutRes layoutId: Int) : super(layoutId) 18 | 19 | open var immersionStatus = false 20 | 21 | open var immersiveNavigation = false 22 | 23 | open var isLightSystemBar = false 24 | 25 | override fun onCreate(savedInstanceState: Bundle?) { 26 | if(immersionStatus) immersionStatusBar(false, isLightSystemBar) 27 | if(immersiveNavigation) { 28 | immersiveNavigationBar() 29 | fitNavigationBar(true) 30 | setLightNavigationBar(isLightSystemBar) 31 | } 32 | super.onCreate(savedInstanceState) 33 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT.also { requestedOrientation = it } 34 | initView() 35 | } 36 | 37 | override fun onStart() { 38 | super.onStart() 39 | initData() 40 | } 41 | 42 | open fun initView() {} 43 | open fun initData() {} 44 | 45 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/base/BaseFragment.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.base 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import androidx.annotation.LayoutRes 6 | import androidx.fragment.app.Fragment 7 | 8 | 9 | open class BaseFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { 10 | 11 | private var isInit = false 12 | 13 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 14 | super.onViewCreated(view, savedInstanceState) 15 | initView() 16 | restoreState(savedInstanceState) 17 | } 18 | 19 | override fun onResume() { 20 | super.onResume() 21 | if(!isInit&&!isHidden) { 22 | initData() 23 | isInit = true 24 | } 25 | } 26 | 27 | override fun onDestroyView() { 28 | super.onDestroyView() 29 | isInit = false 30 | } 31 | 32 | open fun restoreState(savedInstanceState: Bundle?) {} 33 | open fun initView() {} 34 | open fun initData() {} 35 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/base/MyHandler.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.base 2 | 3 | import android.os.Handler 4 | import android.os.Looper 5 | import androidx.lifecycle.DefaultLifecycleObserver 6 | import androidx.lifecycle.LifecycleOwner 7 | import wsdydeni.library.android.utils.another.noOpDelegate 8 | import java.lang.ref.WeakReference 9 | 10 | 11 | 12 | open class MyHandler(private val instance: T? = null, looper: Looper = Looper.getMainLooper()) : Handler(looper) { 13 | private val ref by lazy { 14 | WeakReference(instance) 15 | } 16 | 17 | fun getInstance() : T? { 18 | return ref.get() 19 | } 20 | 21 | val lifecycleCallbacks = object : DefaultLifecycleObserver by noOpDelegate() { 22 | override fun onDestroy(owner: LifecycleOwner) { 23 | removeCallbacksAndMessages(null) 24 | } 25 | } 26 | } 27 | 28 | open class BaseActivityHandler(activity: BaseActivity) : MyHandler(activity) { 29 | init { 30 | activity.lifecycle.addObserver(lifecycleCallbacks) 31 | } 32 | } 33 | 34 | open class BaseFragmentHandler(fragment: BaseFragment) : MyHandler() { 35 | init { 36 | fragment.viewLifecycleOwner.lifecycle.addObserver(lifecycleCallbacks) 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/another/LogUtil.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.another 2 | 3 | import android.util.Log 4 | import java.util.Formatter 5 | 6 | /** 7 | * link: https://www.jianshu.com/p/22fd7999107f 8 | */ 9 | object LogUtil { 10 | private const val MIN_STACK_OFFSET = 3 11 | 12 | private var defaultTag = "LogUtil" 13 | 14 | private const val V = Log.VERBOSE 15 | private const val D = Log.DEBUG 16 | private const val I = Log.INFO 17 | private const val W = Log.WARN 18 | private const val E = Log.ERROR 19 | 20 | private const val TOP_BORDER = "╔═══════════════════════════════════════════════════════════════════════════════════════════════════" 21 | private const val LEFT_BORDER = "║ " 22 | private const val BOTTOM_BORDER = "╚═══════════════════════════════════════════════════════════════════════════════════════════════════" 23 | private const val MAX_LEN = 1000 24 | private var open = true 25 | 26 | fun init(isLogEnable: Boolean) { 27 | open = isLogEnable 28 | if(!open) { 29 | closeLog() 30 | } 31 | } 32 | 33 | private fun processTagAndHead(): String { 34 | val elements = Thread.currentThread().stackTrace 35 | val offset = getStackOffset(elements) 36 | val targetElement = elements[offset] 37 | val head = Formatter() 38 | .format("%s [%s(%s:%d)]", 39 | "In Thread: " + Thread.currentThread().name, 40 | targetElement.methodName, 41 | targetElement.fileName, 42 | targetElement.lineNumber) 43 | 44 | return head.toString() 45 | } 46 | 47 | private fun processMsgBody(msg: String, flag: Int, tag: String = defaultTag) { 48 | printTop(flag, tag) 49 | // 首先打印调用信息 50 | printLog(flag, tag) 51 | 52 | val lineCount = msg.length / MAX_LEN 53 | if (lineCount == 0) { 54 | printLog(flag, tag, msg) 55 | } else { 56 | var index = 0 57 | var i = 0 58 | while (true) { 59 | printLog(flag, tag, msg.substring(index, index + MAX_LEN)) 60 | index += MAX_LEN 61 | if ((++i) >= lineCount) 62 | break 63 | } 64 | } 65 | printBottom(flag, tag) 66 | } 67 | 68 | private fun getStackOffset(trace: Array): Int { 69 | var i = MIN_STACK_OFFSET 70 | while (i < trace.size) { 71 | val e = trace[i] 72 | val name = e.className 73 | if (name != LogUtil::class.java.name) { 74 | return i 75 | } 76 | i++ 77 | } 78 | return 2 79 | } 80 | 81 | /* 虽然 kotlin 有默认值这种操作,但是 Log.i(tag,msg) 这种比较符合平时的操作,所以还是提供类似的重载, 82 | * 而非 LogUtil.i(msg: String,tag: String = defaultTAG) 这种带默认值参数的方法 */ 83 | 84 | fun v(msg: String) { 85 | v(defaultTag, msg) 86 | } 87 | 88 | fun i(msg: String) { 89 | i(defaultTag, msg) 90 | } 91 | 92 | fun d(msg: String) { 93 | d(defaultTag, msg) 94 | } 95 | 96 | fun w(msg: String) { 97 | w(defaultTag, msg) 98 | } 99 | 100 | fun e(msg: String) { 101 | e(defaultTag, msg) 102 | } 103 | 104 | private fun v(tag: String, msg: String) { 105 | if (!open) { 106 | return 107 | } 108 | processMsgBody(msg, V, tag) 109 | } 110 | 111 | private fun i(tag: String, msg: String) { 112 | if (!open) { 113 | return 114 | } 115 | processMsgBody(msg, I, tag) 116 | } 117 | 118 | private fun d(tag: String, msg: String) { 119 | if (!open) { 120 | return 121 | } 122 | processMsgBody(msg, D, tag) 123 | } 124 | 125 | private fun w(tag: String, msg: String) { 126 | if (!open) { 127 | return 128 | } 129 | processMsgBody(msg, W, tag) 130 | } 131 | 132 | private fun e(tag: String, msg: String) { 133 | if (!open) { 134 | return 135 | } 136 | processMsgBody(msg, E, tag) 137 | } 138 | 139 | private fun printLog(flag: Int, tag: String, msg: String = processTagAndHead()) { 140 | Log.println(flag, tag, LEFT_BORDER + msg) 141 | } 142 | 143 | private fun printBottom(flag: Int, tag: String) { 144 | Log.println(flag, tag, BOTTOM_BORDER) 145 | } 146 | 147 | private fun printTop(flag: Int, tag: String) { 148 | Log.println(flag, tag, TOP_BORDER) 149 | } 150 | 151 | private fun closeLog() { 152 | open = false 153 | } 154 | 155 | 156 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/another/Proxy.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.another 2 | 3 | import java.lang.reflect.InvocationHandler 4 | import java.lang.reflect.Proxy 5 | 6 | inline fun noOpDelegate() : T { 7 | val javaClass = T::class.java 8 | return Proxy.newProxyInstance(javaClass.classLoader, arrayOf(javaClass),noOpHandler) as T 9 | } 10 | 11 | val noOpHandler = InvocationHandler { _, _, _ -> } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/density/AutoDensity.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.density 2 | 3 | import android.app.Activity 4 | import android.app.Application 5 | import android.app.Application.ActivityLifecycleCallbacks 6 | import android.content.ComponentCallbacks 7 | import android.content.res.Configuration 8 | import android.os.Bundle 9 | import android.util.DisplayMetrics 10 | import android.util.Log 11 | 12 | /** 13 | * @Date: 2020/4/17 14 | * @Author: hugo 15 | * @Description: 今日头条的屏幕适配方案 16 | * [一种极低成本的Android屏幕适配方式](https://mp.weixin.qq.com/s/d9QCoBP6kV9VSWvVldVVwA) 17 | * [今日头条屏幕适配方案终极版正式发布](https://www.jianshu.com/p/4aa23d69d481) 18 | * [AndroidAutoSize](https://github.com/JessYanCoding/AndroidAutoSize) 19 | * 20 | * 21 | * 需要考虑以下需求: 22 | * 1.为特定Activity指定设计尺寸 : 已支持 23 | * 2.支持Activity选择不使用适配 :已支持 24 | * 3.支持第三方SDK引入的Activity适配(选择适配或者保持原来) :已支持 25 | * 4.支持选择smallest-width或者height作为设计基准 :已支持 26 | * 5.支持选择字体是否跟随适配 :已支持 27 | * 6.Fragment适配(不是很重要,但是可以参考一下是怎么做的) : 未支持 28 | * 29 | * 关于phone设计稿适配pad的问题: 30 | * 1.按照设计稿适配,这样做风险比较大,切换到竖屏的时候可能用不了(内容较长的页面需要滚动); 31 | * 2.不适配,根据sw-600dp来判断,如果大于这个值则不要初始化 AutoDensity; 32 | * 3.按照一定的策略来适配,如sw-600dp:500F, sw-800dp: 600F, 也就是按比例缩放的原理; 33 | * 34 | */ 35 | @Suppress("unused") 36 | class AutoDensity private constructor() : ActivityLifecycleCallbacks, ComponentCallbacks { 37 | 38 | companion object { 39 | val TAG: String = AutoDensity::class.java.simpleName 40 | val instance = AutoDensity() 41 | } 42 | 43 | private lateinit var application: Application 44 | private lateinit var autoDensityConfig: AutoDensityConfig 45 | private lateinit var customAdaptManager: CustomAdaptManager 46 | private var inited: Boolean = false 47 | 48 | fun getAutoDensityConfig(): AutoDensityConfig { 49 | if (!inited) { 50 | throw NullPointerException("before you call getCustomAdaptManager, call init first") 51 | } 52 | return autoDensityConfig 53 | } 54 | 55 | fun getCustomAdaptManager(): CustomAdaptManager { 56 | if (!inited) { 57 | throw NullPointerException("before you call getCustomAdaptManager, call init first") 58 | } 59 | return customAdaptManager 60 | } 61 | 62 | /** 63 | * 默认设计尺寸为: 375dp,并且以smallest-width作为设计基准 64 | * 65 | * @param application application 66 | */ 67 | fun init(application: Application) { 68 | this.init(application, DesignDraft(true, 375f, true)) 69 | } 70 | 71 | /** 72 | * 正常使用请调用这个方法 73 | * 74 | * @param application application 75 | * @param appDesignDraft design info 76 | */ 77 | fun init(application: Application, appDesignDraft: DesignDraft): AutoDensity { 78 | this.application = application 79 | this.application.registerActivityLifecycleCallbacks(this) 80 | this.application.registerComponentCallbacks(this) 81 | this.autoDensityConfig = AutoDensityConfig(application, appDesignDraft) 82 | this.customAdaptManager = CustomAdaptManager() 83 | this.inited = true 84 | return this 85 | } 86 | 87 | /** 88 | * 想象中的一种适配pad的方案(毕竟为pad单独设计一套UI和布局代价有点大),就是一种策略,通过改变设计稿的 89 | * 大小,控制在不同屏幕的缩放比例在一定的范围不要显得过大。 90 | */ 91 | fun adaptPad(): AutoDensity { 92 | val smallestWidth: Float 93 | val designDraft = autoDensityConfig.appDesignDraft 94 | smallestWidth = if (designDraft.isBaseOnSmallestWidth) { 95 | autoDensityConfig.width.coerceAtMost(autoDensityConfig.height) 96 | } else { 97 | autoDensityConfig.width.coerceAtLeast(autoDensityConfig.height) 98 | } 99 | val adaptWidth: Float = when { 100 | smallestWidth > 1000f -> { 101 | 800f 102 | } 103 | smallestWidth > 800f -> { 104 | 600f 105 | } 106 | smallestWidth > 600 -> { 107 | 500f 108 | } 109 | smallestWidth > 500 -> { 110 | 450f 111 | } 112 | else -> { 113 | designDraft.designSize 114 | } 115 | } 116 | autoDensityConfig.appDesignDraft = DesignDraft( 117 | designDraft.isBaseOnSmallestWidth, 118 | adaptWidth, designDraft.isEnableScaledFont 119 | ) 120 | return this 121 | } 122 | 123 | private fun apply(activity: Activity, designDraft: DesignDraft) { 124 | val width = autoDensityConfig.widthPixels.coerceAtMost(autoDensityConfig.heightPixels) 125 | val height = autoDensityConfig.widthPixels.coerceAtLeast(autoDensityConfig.heightPixels) 126 | if (width < 1) { 127 | Log.d(TAG, "can not read widthPixels and heightPixels") 128 | return 129 | } 130 | val targetDensity: Float = if (designDraft.isBaseOnSmallestWidth) { 131 | width / designDraft.designSize 132 | } else { 133 | height / designDraft.designSize 134 | } 135 | val targetDensityDpi = (DisplayMetrics.DENSITY_MEDIUM * targetDensity).toInt() 136 | val activityDisplayMetrics = activity.resources.displayMetrics 137 | activityDisplayMetrics.density = targetDensity 138 | activityDisplayMetrics.densityDpi = targetDensityDpi 139 | if (designDraft.isEnableScaledFont) { 140 | val targetScaledDensity = targetDensity * (autoDensityConfig.scaledDensity 141 | / autoDensityConfig.density) 142 | activityDisplayMetrics.scaledDensity = targetScaledDensity 143 | } 144 | } 145 | 146 | override fun onConfigurationChanged(newConfig: Configuration) { 147 | if (newConfig.fontScale < 0) { 148 | return 149 | } 150 | autoDensityConfig.scaledDensity = application.resources.displayMetrics.scaledDensity 151 | } 152 | 153 | override fun onLowMemory() {} 154 | 155 | override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { 156 | if (!autoDensityConfig.isEnableAutoDensity) { 157 | // 1.全局禁用AutoDensity适配,直接返回即可 158 | return 159 | } 160 | if (activity is CancelAdapt) { 161 | // 2.如果activity实现了CancelAdapt接口,那么不需要适配 162 | return 163 | } 164 | if (customAdaptManager.isCancelAdapt(activity.javaClass)) { 165 | // 3.如果是第三方SDK的activity,并且明确配置了不适配,则不适配 166 | return 167 | } 168 | val designDraft = if (activity is CustomAdapt) { 169 | // 1. 实现CustomAdapt具有最高优先级 170 | (activity as CustomAdapt).designSize() 171 | } else if (autoDensityConfig.isEnableCustomAdapt && 172 | customAdaptManager.getCustomAdaptDesignInfo(activity.javaClass) != null 173 | ) { 174 | // 2.第三方SDK的Activity,如果有独立的设计,那么使用这个设计参数 175 | customAdaptManager.getCustomAdaptDesignInfo(activity.javaClass)!! 176 | } else { 177 | // 3. 剩下的就是使用全局统一设计稿的了 178 | autoDensityConfig.appDesignDraft 179 | } 180 | try { 181 | apply(activity, designDraft) 182 | } catch (ex: Exception) { 183 | ex.printStackTrace() 184 | } 185 | } 186 | 187 | override fun onActivityStarted(activity: Activity) {} 188 | override fun onActivityResumed(activity: Activity) {} 189 | override fun onActivityPaused(activity: Activity) {} 190 | override fun onActivityStopped(activity: Activity) {} 191 | override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {} 192 | override fun onActivityDestroyed(activity: Activity) {} 193 | 194 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/density/AutoDensityConfig.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.density 2 | 3 | import android.app.Application 4 | 5 | /** 6 | * @Date: 2020/4/20 7 | * @Author: hugo 8 | * @Description: 全局的配置 9 | */ 10 | class AutoDensityConfig(application: Application, designDraft: DesignDraft) { 11 | var isEnableAutoDensity = true // 是否启用适配,如果否,则不适配,可以应急 12 | var isEnableCustomAdapt = true // 是否允许Activity自定义设计稿大小,如果否则使用全局的配置 13 | var isEnableScaledFont = true // 字体是否跟着适配 14 | var appDesignDraft: DesignDraft = designDraft // 全局的设计参数 15 | var scaledDensity: Float // 控制字体 16 | 17 | // density、widthPixels、heightPixels是设备原始值,width、height的单位是dp 18 | @JvmField 19 | val density: Float 20 | @JvmField 21 | val widthPixels: Int 22 | @JvmField 23 | val heightPixels: Int 24 | @JvmField 25 | val width: Float 26 | @JvmField 27 | val height: Float 28 | 29 | init { 30 | val displayMetrics = application.resources.displayMetrics 31 | density = displayMetrics.density 32 | scaledDensity = displayMetrics.scaledDensity 33 | widthPixels = displayMetrics.widthPixels 34 | heightPixels = displayMetrics.heightPixels 35 | width = widthPixels / density 36 | height = heightPixels / density 37 | } 38 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/density/CancelAdapt.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.density 2 | 3 | /** 4 | * @Date: 2020/4/20 5 | * @Author: hugo 6 | * @Description: 如果Activity实现这个接口,那么则不使用适配 7 | */ 8 | interface CancelAdapt -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/density/CustomAdapt.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.density 2 | 3 | /** 4 | * @Date: 2020/4/20 5 | * @Author: hugo 6 | * @Description: 如果某个Activity的设计稿尺寸和全局的不一样,可以实现这个接口 7 | */ 8 | interface CustomAdapt { 9 | /** 10 | * 设计稿 11 | * @return DesignDraft 12 | */ 13 | fun designSize(): DesignDraft 14 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/density/CustomAdaptManager.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.density 2 | 3 | import android.app.Activity 4 | 5 | /** 6 | * @Date: 2020/4/20 7 | * @Author: hugo 8 | * @Description: 第三方SDK的Activity和全局设计不一致的Activity,可以在这里添加配置单独适配 9 | * (应用内的Activity如果需要独立配置,可以实现CustomAdapt接口,而不是添加到这里,后面可以扩展一下) 10 | */ 11 | class CustomAdaptManager { 12 | private val cancelAdaptMap: MutableMap = 13 | HashMap() 14 | private val customAdaptMap: MutableMap = 15 | HashMap() 16 | 17 | fun addCancelAdapt(clazz: Class) { 18 | cancelAdaptMap[clazz.name] = clazz.name 19 | } 20 | 21 | fun addCustomAdapt( 22 | clazz: Class, 23 | designDraft: DesignDraft 24 | ) { 25 | customAdaptMap[clazz.name] = designDraft 26 | } 27 | 28 | fun isCancelAdapt(clazz: Class): Boolean { 29 | return cancelAdaptMap[clazz.name] != null 30 | } 31 | 32 | fun getCustomAdaptDesignInfo(clazz: Class): DesignDraft? { 33 | return customAdaptMap[clazz.name] 34 | } 35 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/density/DesignDraft.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.density 2 | 3 | /** 4 | * @Date: 2020/4/20 5 | * @Author: hugo 6 | * @Description: 设计稿,包含尺寸,适配方向基准(基于width或者height)和字体缩放 7 | */ 8 | class DesignDraft @JvmOverloads constructor( 9 | /** 10 | * 是否以最短边为基准 11 | */ 12 | val isBaseOnSmallestWidth: Boolean = true, 13 | /** 14 | * 设计稿的基准尺寸,如常用的:360dp、375dp 15 | */ 16 | val designSize: Float, 17 | /** 18 | * 字体是否跟着变 19 | */ 20 | val isEnableScaledFont: Boolean = true 21 | ) -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/display/PixelUtil.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.display 2 | 3 | import android.content.Context 4 | 5 | class PixelUtil { 6 | companion object { 7 | @JvmStatic 8 | fun dip2px(context: Context, dpValue: Float): Int { 9 | val scale = context.resources.displayMetrics.density 10 | return (dpValue * scale + 0.5f).toInt() 11 | } 12 | 13 | @JvmStatic 14 | fun px2dp(context: Context, pxValue: Int): Int { 15 | val scale = context.resources.displayMetrics.density 16 | return (pxValue / scale + 0.5f).toInt() 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/immersion/ImmersionDialogExt.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.immersion 2 | 3 | import android.app.Dialog 4 | import android.os.Build 5 | import android.view.Gravity 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.view.WindowManager 9 | import wsdydeni.library.android.R 10 | 11 | 12 | // https://juejin.cn/post/7075578574362640421#heading-18 13 | 14 | fun Dialog.setLightStatusBar(isLightingColor: Boolean) { 15 | val window = this.window ?: return 16 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 17 | if (isLightingColor) { 18 | window.decorView.systemUiVisibility = 19 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 20 | } else { 21 | window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE 22 | } 23 | } 24 | } 25 | 26 | fun Dialog.setLightNavigationBar(isLightingColor: Boolean) { 27 | val window = this.window ?: return 28 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isLightingColor) { 29 | window.decorView.systemUiVisibility = 30 | window.decorView.systemUiVisibility or if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR else 0 31 | } 32 | } 33 | 34 | fun Dialog.immersiveStatusBar() { 35 | val window = this.window ?: return 36 | (window.decorView as ViewGroup).setOnHierarchyChangeListener(object : ViewGroup.OnHierarchyChangeListener { 37 | override fun onChildViewAdded(parent: View?, child: View?) { 38 | if (child?.id == android.R.id.statusBarBackground) { 39 | child.scaleX = 0f 40 | } 41 | } 42 | 43 | override fun onChildViewRemoved(parent: View?, child: View?) {} 44 | }) 45 | } 46 | 47 | fun Dialog.immersiveNavigationBar() { 48 | val window = this.window ?: return 49 | (window.decorView as ViewGroup).setOnHierarchyChangeListener(object : ViewGroup.OnHierarchyChangeListener { 50 | override fun onChildViewAdded(parent: View?, child: View?) { 51 | if (child?.id == android.R.id.navigationBarBackground) { 52 | child.scaleX = 0f 53 | } else if (child?.id == android.R.id.statusBarBackground) { 54 | child.scaleX = 0f 55 | } 56 | } 57 | 58 | override fun onChildViewRemoved(parent: View?, child: View?) {} 59 | }) 60 | } 61 | 62 | fun Dialog.immersion() { 63 | window?.let { 64 | it.setGravity(Gravity.CENTER) 65 | it.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) 66 | } 67 | immersiveStatusBar() 68 | immersiveNavigationBar() 69 | setLightStatusBar(true) 70 | setLightNavigationBar(true) 71 | } 72 | -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/immersion/ImmersionNavigationBarExt.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.immersion 2 | 3 | import android.app.Activity 4 | import android.graphics.Color 5 | import android.os.Build 6 | import android.view.Gravity 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import android.widget.FrameLayout 10 | import androidx.fragment.app.FragmentActivity 11 | import androidx.lifecycle.LiveData 12 | import androidx.lifecycle.MutableLiveData 13 | import wsdydeni.library.android.R 14 | 15 | 16 | fun Activity.setLightNavigationBar(isLightingColor: Boolean) { 17 | val window = this.window 18 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isLightingColor) { 19 | window.decorView.systemUiVisibility = 20 | window.decorView.systemUiVisibility or if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR else 0 21 | } 22 | } 23 | 24 | fun Activity.getNavBarHeight(): Int { 25 | return navigationBarHeightLiveData.value ?: 0 26 | } 27 | 28 | fun Activity.setNavigationBarColor(color: Int) { 29 | val navigationBarView = window.decorView.findViewById(R.id.navigation_bar_view) 30 | if (color == 0 && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { 31 | navigationBarView?.setBackgroundColor(STATUS_BAR_MASK_COLOR) 32 | } else { 33 | navigationBarView?.setBackgroundColor(color) 34 | } 35 | } 36 | 37 | fun Activity.immersiveNavigationBar(callback: (() -> Unit)? = null) { 38 | val view = (window.decorView as ViewGroup).getChildAt(0) 39 | view.addOnLayoutChangeListener { v, _, _, _, _, _, _, _, _ -> 40 | val lp = view.layoutParams as FrameLayout.LayoutParams 41 | if (lp.bottomMargin > 0) { 42 | lp.bottomMargin = 0 43 | v.layoutParams = lp 44 | } 45 | if (view.paddingBottom > 0) { 46 | view.setPadding(0, view.paddingTop, 0, 0) 47 | val content = findViewById(android.R.id.content) 48 | content.requestLayout() 49 | } 50 | } 51 | 52 | val content = findViewById(android.R.id.content) 53 | content.setPadding(0, content.paddingTop, 0, -1) 54 | 55 | val heightLiveData = MutableLiveData() 56 | heightLiveData.value = 0 57 | window.decorView.setTag(R.id.navigation_height_live_data, heightLiveData) 58 | callback?.invoke() 59 | 60 | window.decorView.findViewById(R.id.navigation_bar_view) ?: View(window.context).apply { 61 | id = R.id.navigation_bar_view 62 | val params = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, heightLiveData.value ?: 0) 63 | params.gravity = Gravity.BOTTOM 64 | layoutParams = params 65 | (window.decorView as ViewGroup).addView(this) 66 | 67 | if (this@immersiveNavigationBar is FragmentActivity) { 68 | heightLiveData.observe(this@immersiveNavigationBar) { 69 | val lp = layoutParams 70 | lp.height = heightLiveData.value ?: 0 71 | layoutParams = lp 72 | } 73 | } 74 | 75 | (window.decorView as ViewGroup).setOnHierarchyChangeListener(object : ViewGroup.OnHierarchyChangeListener { 76 | override fun onChildViewAdded(parent: View?, child: View?) { 77 | if (child?.id == android.R.id.navigationBarBackground) { 78 | child.scaleX = 0f 79 | bringToFront() 80 | 81 | child.addOnLayoutChangeListener { _, _, top, _, bottom, _, _, _, _ -> 82 | heightLiveData.value = bottom - top 83 | } 84 | } else if (child?.id == android.R.id.statusBarBackground) { 85 | child.scaleX = 0f 86 | } 87 | } 88 | 89 | override fun onChildViewRemoved(parent: View?, child: View?) { 90 | } 91 | }) 92 | } 93 | setNavigationBarColor(Color.TRANSPARENT) 94 | } 95 | 96 | fun Activity.fitNavigationBar(fit: Boolean) { 97 | val content = findViewById(android.R.id.content) 98 | if (fit) { 99 | content.setPadding(0, content.paddingTop, 0, navigationBarHeightLiveData.value ?: 0) 100 | } else { 101 | content.setPadding(0, content.paddingTop, 0, -1) 102 | } 103 | if (this is FragmentActivity) { 104 | navigationBarHeightLiveData.observe(this) { 105 | if (content.paddingBottom != -1) { 106 | content.setPadding(0, content.paddingTop, 0, it) 107 | } 108 | } 109 | } 110 | } 111 | 112 | @Suppress("UNCHECKED_CAST") 113 | val Activity.navigationBarHeightLiveData: LiveData 114 | get() { 115 | var liveData = window.decorView.getTag(R.id.navigation_height_live_data) as? LiveData 116 | if (liveData == null) { 117 | liveData = MutableLiveData() 118 | window.decorView.setTag(R.id.navigation_height_live_data, liveData) 119 | } 120 | return liveData 121 | } 122 | 123 | private const val STATUS_BAR_MASK_COLOR = 0x7F000000 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/immersion/ImmersionStatusBarExt.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.immersion 2 | 3 | import android.app.Activity 4 | import android.content.res.Resources 5 | import android.graphics.Color 6 | import android.os.Build 7 | import android.view.View 8 | import android.widget.LinearLayout 9 | import androidx.annotation.ColorInt 10 | import androidx.core.view.ViewCompat 11 | import androidx.core.view.WindowInsetsCompat 12 | 13 | 14 | fun Activity.setSystemStatusBar(isShowSystemStatusBar: Boolean,isLightStatusBar: Boolean) { 15 | var flag = View.SYSTEM_UI_FLAG_LAYOUT_STABLE 16 | if(!isShowSystemStatusBar) { 17 | flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 18 | } 19 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isLightStatusBar) { 20 | flag = if(isLightStatusBar) flag or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 21 | else flag and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() 22 | } 23 | window.decorView.systemUiVisibility = flag 24 | if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 25 | window.setDecorFitsSystemWindows(isShowSystemStatusBar) 26 | } 27 | } 28 | 29 | fun Activity.setStatusBarColor(@ColorInt statusColor: Int) { 30 | var color = statusColor 31 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { 32 | color = Color.GRAY 33 | } 34 | window.statusBarColor = if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) color else -2 35 | } 36 | 37 | fun Activity.immersionStatusBar(isShowSystemStatusBar: Boolean,isLightStatusBar: Boolean) { 38 | setSystemStatusBar(isShowSystemStatusBar,isLightStatusBar) 39 | setStatusBarColor(Color.TRANSPARENT) 40 | } 41 | 42 | fun Activity.showStatusBarView(view: View,@ColorInt backgroundColor: Int? = null) { 43 | val lp = view.layoutParams 44 | lp.width = LinearLayout.LayoutParams.MATCH_PARENT 45 | lp.height = getStatusBarHeight() 46 | view.layoutParams = lp 47 | view.visibility = View.VISIBLE 48 | if(backgroundColor != null) { 49 | view.setBackgroundColor(backgroundColor) 50 | } 51 | } 52 | 53 | fun Activity.getStatusBarHeight() : Int { 54 | val windowInsetsCompat = ViewCompat.getRootWindowInsets(window.decorView) 55 | val insets = windowInsetsCompat?.getInsetsIgnoringVisibility(WindowInsetsCompat.Type.statusBars()) 56 | if(insets != null) { 57 | return insets.top 58 | } 59 | val resources: Resources = resources 60 | val resourceId: Int = resources.getIdentifier("status_bar_height", "dimen", "android") 61 | return resources.getDimensionPixelSize(resourceId) 62 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/keyboard/KeyboardExt.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.keyboard 2 | 3 | import androidx.fragment.app.FragmentActivity 4 | 5 | fun FragmentActivity.addKeyboardMonitor(onKeyboardHeightChanged: (keyboardHeight: Int, keyboardOpen: Boolean, isHorizontal: Boolean) -> Unit) { 6 | KeyboardHeightProvider(this,object : KeyboardHeightListener { 7 | override fun onKeyboardHeightChanged(keyboardHeight: Int,keyboardOpen: Boolean, isHorizontal: Boolean) { 8 | onKeyboardHeightChanged(keyboardHeight, keyboardOpen, isHorizontal) 9 | } 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/keyboard/KeyboardHeightListener.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.keyboard 2 | 3 | interface KeyboardHeightListener { 4 | /** 5 | * 键盘监听 6 | * 7 | * @param keyboardHeight 键盘高度 8 | * @param keyboardOpen 键盘是否打开 9 | * @param isHorizontal 是否为横屏 10 | */ 11 | fun onKeyboardHeightChanged(keyboardHeight: Int, keyboardOpen: Boolean, isHorizontal: Boolean) 12 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/keyboard/KeyboardHeightProvider.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.keyboard 2 | 3 | import android.app.Activity 4 | import android.graphics.Rect 5 | import android.graphics.drawable.ColorDrawable 6 | import android.os.Build 7 | import android.view.* 8 | import android.widget.PopupWindow 9 | import androidx.fragment.app.FragmentActivity 10 | import androidx.lifecycle.DefaultLifecycleObserver 11 | import androidx.lifecycle.LifecycleOwner 12 | import wsdydeni.library.android.R 13 | import wsdydeni.library.android.utils.another.noOpDelegate 14 | import wsdydeni.library.android.utils.display.PixelUtil 15 | 16 | 17 | /** 18 | * @see adjustNothing时监听键盘状态及高度 19 | */ 20 | class KeyboardHeightProvider(activity: FragmentActivity,listener: KeyboardHeightListener) : PopupWindow(activity) { 21 | 22 | private var recordHeight = 0 23 | 24 | init { 25 | val inflater = activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE) as LayoutInflater 26 | val popupView = inflater.inflate(R.layout.keyboard_popup_window, null, false) 27 | val onGlobalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener { 28 | val metrics = activity.resources.displayMetrics 29 | contentView.handler.sendEmptyMessageDelayed(4321,50) 30 | val rect = Rect().apply { contentView.getWindowVisibleDisplayFrame(this) } 31 | var keyboardHeight: Int = metrics.heightPixels - (rect.bottom - rect.top) 32 | if (keyboardHeight < PixelUtil.dip2px(activity,200f)) { 33 | keyboardHeight = 0 34 | } 35 | if(keyboardHeight < 1000 && keyboardHeight > PixelUtil.dip2px(activity,200f)) { 36 | recordHeight = keyboardHeight 37 | } 38 | if(keyboardHeight > 1000) { 39 | if(recordHeight != 0) { 40 | keyboardHeight = recordHeight 41 | } 42 | if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 43 | activity.window.decorView.setOnApplyWindowInsetsListener { _, insets -> 44 | insets.getInsets(WindowInsets.Type.navigationBars()).bottom.run { 45 | keyboardHeight = insets.getInsets(WindowInsets.Type.ime()).bottom.minus(this) 46 | recordHeight = keyboardHeight 47 | insets 48 | } 49 | } 50 | } 51 | } 52 | val isLandscape = metrics.widthPixels > metrics.heightPixels 53 | val keyboardOpen = keyboardHeight > 0 54 | activity.window.decorView.setOnApplyWindowInsetsListener(null) 55 | listener.onKeyboardHeightChanged(keyboardHeight, keyboardOpen, isLandscape) 56 | } 57 | contentView = popupView 58 | softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE or WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE 59 | inputMethodMode = INPUT_METHOD_NEEDED 60 | width = 0 61 | height = ViewGroup.LayoutParams.MATCH_PARENT 62 | setBackgroundDrawable(ColorDrawable(0)) 63 | val content = activity.findViewById(android.R.id.content) as ViewGroup 64 | content.post { showAtLocation(content, Gravity.NO_GRAVITY, 0, 0) } 65 | activity.lifecycle.addObserver(object : DefaultLifecycleObserver by noOpDelegate() { 66 | override fun onResume(owner: LifecycleOwner) { 67 | contentView.viewTreeObserver.addOnGlobalLayoutListener(onGlobalLayoutListener) 68 | } 69 | 70 | override fun onPause(owner: LifecycleOwner) { 71 | contentView.viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener) 72 | } 73 | 74 | override fun onDestroy(owner: LifecycleOwner) { 75 | contentView.viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener) 76 | dismiss() 77 | } 78 | }) 79 | } 80 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/lifecycle/LifecycleExt.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.lifecycle 2 | 3 | import androidx.fragment.app.Fragment 4 | import androidx.fragment.app.FragmentActivity 5 | import androidx.lifecycle.Lifecycle 6 | import androidx.lifecycle.lifecycleScope 7 | import kotlinx.coroutines.CoroutineScope 8 | import kotlinx.coroutines.Dispatchers 9 | import kotlinx.coroutines.launch 10 | import kotlin.coroutines.CoroutineContext 11 | 12 | /** 13 | * 更加简洁的语法封装 14 | * 15 | * 在 [Fragment.getViewLifecycleOwner] 达到 [minActiveState] 时,启动一个新的协程并重复 [block] 并在 [Lifecycle.Event.ON_DESTROY] 时,取消协程。 16 | * 17 | * 警告:不要在其他 CoroutineScope 中调用本函数!!! 18 | * 19 | * 如果在 CoroutineScope 中调用本函数,会隐式持有外部作用域 20 | * 21 | * 但是并不会保留外部作用域的上下文,也就是无法实现结构化并发 22 | * 23 | * @param newCoroutineContext 协程上下文 默认 [Dispatchers.Main] 24 | * @param minActiveState 需要达到的最小生命周期状态 默认 [Lifecycle.State.STARTED] 25 | * @param block 协程代码块 26 | */ 27 | inline fun Fragment.launchAndRepeatWithViewLifecycle( 28 | newCoroutineContext: CoroutineContext = Dispatchers.Main, 29 | minActiveState: Lifecycle.State = Lifecycle.State.STARTED, 30 | crossinline block: suspend CoroutineScope.() -> Unit 31 | ) { 32 | viewLifecycleOwner.lifecycleScope.launch(newCoroutineContext) { 33 | viewLifecycleOwner.lifecycle.repeatOnLifecycle(minActiveState) { 34 | block() 35 | } 36 | } 37 | } 38 | 39 | inline fun Fragment.launchAndRepeatWithViewLifecycle( 40 | minActiveState: Lifecycle.State = Lifecycle.State.STARTED, 41 | crossinline block: suspend CoroutineScope.() -> Unit 42 | ) { 43 | launchAndRepeatWithViewLifecycle(Dispatchers.Main,minActiveState,block) 44 | } 45 | 46 | /** 47 | * 更加简洁的语法封装 48 | * 49 | * 在 [FragmentActivity.getLifecycle] 达到 [minActiveState] 时,启动一个新的协程并重复 [block] 并在 [Lifecycle.Event.ON_DESTROY] 时,取消协程。 50 | * 51 | * 警告:不要在其他 CoroutineScope 中调用本函数!!! 52 | * 53 | * 如果在 CoroutineScope 中调用本函数,会隐式持有外部作用域 54 | * 55 | * 但是并不会保留外部作用域的上下文,也就是无法实现结构化并发 56 | * 57 | * @param newCoroutineContext 协程上下文 默认 [Dispatchers.Main] 58 | * @param minActiveState 需要达到的最小生命周期状态 默认 [Lifecycle.State.STARTED] 59 | * @param block 协程代码块 60 | */ 61 | inline fun FragmentActivity.launchAndRepeatWithViewLifecycle( 62 | newCoroutineContext: CoroutineContext = Dispatchers.Main, 63 | minActiveState: Lifecycle.State = Lifecycle.State.STARTED, 64 | crossinline block: suspend CoroutineScope.() -> Unit 65 | ) { 66 | lifecycleScope.launch(newCoroutineContext) { 67 | lifecycle.repeatOnLifecycle(minActiveState) { 68 | block() 69 | } 70 | } 71 | } 72 | 73 | inline fun FragmentActivity.launchAndRepeatWithViewLifecycle( 74 | minActiveState: Lifecycle.State = Lifecycle.State.STARTED, 75 | crossinline block: suspend CoroutineScope.() -> Unit 76 | ) { 77 | launchAndRepeatWithViewLifecycle(Dispatchers.Main,minActiveState,block) 78 | } -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/lifecycle/RepeatOnLifecycle.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wsdydeni.library.android.utils.lifecycle 18 | 19 | import androidx.lifecycle.Lifecycle 20 | import androidx.lifecycle.LifecycleEventObserver 21 | import androidx.lifecycle.LifecycleOwner 22 | import kotlin.coroutines.resume 23 | import kotlinx.coroutines.CoroutineScope 24 | import kotlinx.coroutines.Dispatchers 25 | import kotlinx.coroutines.Job 26 | import kotlinx.coroutines.coroutineScope 27 | import kotlinx.coroutines.launch 28 | import kotlinx.coroutines.suspendCancellableCoroutine 29 | import kotlinx.coroutines.sync.Mutex 30 | import kotlinx.coroutines.sync.withLock 31 | import kotlinx.coroutines.withContext 32 | 33 | /** 34 | * Runs the given [block] in a new coroutine when `this` [Lifecycle] is at least at [state] and 35 | * suspends the execution until `this` [Lifecycle] is [Lifecycle.State.DESTROYED]. 36 | * 37 | * The [block] will cancel and re-launch as the lifecycle moves in and out of the target state. 38 | * 39 | * ``` 40 | * class MyActivity : AppCompatActivity() { 41 | * override fun onCreate(savedInstanceState: Bundle?) { 42 | * /* ... */ 43 | * // Runs the block of code in a coroutine when the lifecycle is at least STARTED. 44 | * // The coroutine will be cancelled when the ON_STOP event happens and will 45 | * // restart executing if the lifecycle receives the ON_START event again. 46 | * lifecycleScope.launch { 47 | * lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { 48 | * uiStateFlow.collect { uiState -> 49 | * updateUi(uiState) 50 | * } 51 | * } 52 | * } 53 | * } 54 | * } 55 | * ``` 56 | * 57 | * The best practice is to call this function when the lifecycle is initialized. For 58 | * example, `onCreate` in an Activity, or `onViewCreated` in a Fragment. Otherwise, multiple 59 | * repeating coroutines doing the same could be created and be executed at the same time. 60 | * 61 | * Repeated invocations of `block` will run serially, that is they will always wait for the 62 | * previous invocation to fully finish before re-starting execution as the state moves in and out 63 | * of the required state. 64 | * 65 | * Warning: [Lifecycle.State.INITIALIZED] is not allowed in this API. Passing it as a 66 | * parameter will throw an [IllegalArgumentException]. 67 | * 68 | * @param state [Lifecycle.State] in which `block` runs in a new coroutine. That coroutine 69 | * will cancel if the lifecycle falls below that state, and will restart if it's in that state 70 | * again. 71 | * @param block The block to run when the lifecycle is at least in [state] state. 72 | */ 73 | suspend fun Lifecycle.repeatOnLifecycle( 74 | state: Lifecycle.State, 75 | block: suspend CoroutineScope.() -> Unit 76 | ) { 77 | require(state !== Lifecycle.State.INITIALIZED) { 78 | "repeatOnLifecycle cannot start work with the INITIALIZED lifecycle state." 79 | } 80 | 81 | if (currentState === Lifecycle.State.DESTROYED) { 82 | return 83 | } 84 | 85 | // This scope is required to preserve context before we move to Dispatchers.Main 86 | coroutineScope { 87 | withContext(Dispatchers.Main.immediate) { 88 | // Check the current state of the lifecycle as the previous check is not guaranteed 89 | // to be done on the main thread. 90 | if (currentState === Lifecycle.State.DESTROYED) return@withContext 91 | 92 | // Instance of the running repeating coroutine 93 | var launchedJob: Job? = null 94 | 95 | // Registered observer 96 | var observer: LifecycleEventObserver? = null 97 | try { 98 | // Suspend the coroutine until the lifecycle is destroyed or 99 | // the coroutine is cancelled 100 | suspendCancellableCoroutine { cont -> 101 | // Lifecycle observers that executes `block` when the lifecycle reaches certain state, and 102 | // cancels when it falls below that state. 103 | val startWorkEvent = Lifecycle.Event.upTo(state) 104 | val cancelWorkEvent = Lifecycle.Event.downFrom(state) 105 | val mutex = Mutex() 106 | observer = LifecycleEventObserver { _, event -> 107 | if (event == startWorkEvent) { 108 | // Launch the repeating work preserving the calling context 109 | launchedJob = this@coroutineScope.launch { 110 | // Mutex makes invocations run serially, 111 | // coroutineScope ensures all child coroutines finish 112 | mutex.withLock { 113 | coroutineScope { 114 | block() 115 | } 116 | } 117 | } 118 | return@LifecycleEventObserver 119 | } 120 | if (event == cancelWorkEvent) { 121 | launchedJob?.cancel() 122 | launchedJob = null 123 | } 124 | if (event == Lifecycle.Event.ON_DESTROY) { 125 | cont.resume(Unit) 126 | } 127 | } 128 | this@repeatOnLifecycle.addObserver(observer as LifecycleEventObserver) 129 | } 130 | } finally { 131 | launchedJob?.cancel() 132 | observer?.let { 133 | this@repeatOnLifecycle.removeObserver(it) 134 | } 135 | } 136 | } 137 | } 138 | } 139 | 140 | /** 141 | * [LifecycleOwner]'s extension function for [Lifecycle.repeatOnLifecycle] to allow an easier 142 | * call to the API from LifecycleOwners such as Activities and Fragments. 143 | * 144 | * ``` 145 | * class MyActivity : AppCompatActivity() { 146 | * override fun onCreate(savedInstanceState: Bundle?) { 147 | * /* ... */ 148 | * // Runs the block of code in a coroutine when the lifecycle is at least STARTED. 149 | * // The coroutine will be cancelled when the ON_STOP event happens and will 150 | * // restart executing if the lifecycle receives the ON_START event again. 151 | * lifecycleScope.launch { 152 | * repeatOnLifecycle(Lifecycle.State.STARTED) { 153 | * uiStateFlow.collect { uiState -> 154 | * updateUi(uiState) 155 | * } 156 | * } 157 | * } 158 | * } 159 | * } 160 | * ``` 161 | * 162 | * @see Lifecycle.repeatOnLifecycle 163 | */ 164 | suspend fun LifecycleOwner.repeatOnLifecycle( 165 | state: Lifecycle.State, 166 | block: suspend CoroutineScope.() -> Unit 167 | ): Unit = lifecycle.repeatOnLifecycle(state, block) 168 | 169 | -------------------------------------------------------------------------------- /baselib/src/main/kotlin/wsdydeni/library/android/utils/view/SpannableExtensions.kt: -------------------------------------------------------------------------------- 1 | package wsdydeni.library.android.utils.view 2 | 3 | import android.content.Context 4 | import android.graphics.Canvas 5 | import android.graphics.Color 6 | import android.graphics.Paint 7 | import android.graphics.drawable.Drawable 8 | import android.os.Build 9 | import android.text.SpannableStringBuilder 10 | import android.text.Spanned 11 | import android.text.TextPaint 12 | import android.text.method.LinkMovementMethod 13 | import android.text.style.ClickableSpan 14 | import android.text.style.DynamicDrawableSpan 15 | import android.text.style.ForegroundColorSpan 16 | import android.text.style.ImageSpan 17 | import android.view.View 18 | import android.widget.TextView 19 | import androidx.annotation.DrawableRes 20 | import wsdydeni.library.android.utils.display.PixelUtil 21 | 22 | /** 23 | * https://segmentfault.com/a/1190000040344725 24 | * 来源于上面的链接,做了一些细节改动和优化。 25 | */ 26 | 27 | class SpannableExtensions(@DrawableRes val selectDrawableId: Int, @DrawableRes val unSelectDrawableId: Int) { 28 | 29 | private var isChecked = false 30 | 31 | fun isChecked(): Boolean { 32 | return isChecked 33 | } 34 | 35 | fun setChecked(checked: Boolean) { 36 | isChecked = checked 37 | } 38 | 39 | interface OnClickListener { 40 | fun onClick(position: Int) 41 | } 42 | 43 | interface OnImageClickListener { 44 | fun onSelect(@DrawableRes selectDrawableId: Int) 45 | fun onUnSelect(@DrawableRes unSelectDrawableId: Int) 46 | } 47 | 48 | class CustomImageSpan(drawable: Drawable, verticalAlignment: Int) : ImageSpan(drawable, verticalAlignment) { 49 | override fun draw( 50 | canvas: Canvas, text: CharSequence, start: Int, end: Int, 51 | x: Float, top: Int, y: Int, bottom: Int, paint: Paint 52 | ) { 53 | val drawable = drawable 54 | canvas.save() 55 | //获取画笔的文字绘制时的具体测量数据 56 | val fm = paint.fontMetricsInt 57 | var transY = bottom - drawable.bounds.bottom 58 | if (mVerticalAlignment == ALIGN_BASELINE) { 59 | transY -= fm.descent 60 | } else if (mVerticalAlignment == ALIGN_CENTER) { //自定义居中对齐 61 | //与文字的中间线对齐(这种方式不论是否设置行间距都能保障文字的中间线和图片的中间线是对齐的) 62 | // y+ascent得到文字内容的顶部坐标,y+descent得到文字的底部坐标,(顶部坐标+底部坐标)/2=文字内容中间线坐标 63 | transY = (y + fm.descent + (y + fm.ascent)) / 2 - drawable.bounds.bottom / 2 64 | } 65 | canvas.translate(x, transY.toFloat()) 66 | drawable.draw(canvas) 67 | canvas.restore() 68 | } 69 | } 70 | 71 | // Object匿名内部类实现更改为静态内部类实现(解决ClickableSpan内存泄漏问题) 72 | class CustomClickableSpan constructor( 73 | private val update: ((textPaint: TextPaint) -> Unit), 74 | private val click: (widget: View) -> Unit 75 | ): ClickableSpan() { 76 | override fun onClick(widget: View) { 77 | click.invoke(widget) 78 | } 79 | 80 | override fun updateDrawState(ds: TextPaint) { 81 | update.invoke(ds) 82 | } 83 | } 84 | 85 | } 86 | 87 | fun SpannableStringBuilder.append(text: CharSequence,color: Int) : SpannableStringBuilder { 88 | val start: Int = length 89 | append(text) 90 | val end: Int = length 91 | setSpan(ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) 92 | return this 93 | } 94 | 95 | fun SpannableStringBuilder.replace(text: CharSequence,color: Int,vararg replaces: String) : SpannableStringBuilder { 96 | append(text) 97 | for (replace in replaces) { 98 | val start = text.toString().indexOf(replace) 99 | if (start >= 0) { 100 | val end = start + replace.length 101 | setSpan(ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) 102 | } 103 | } 104 | return this 105 | } 106 | 107 | fun SpannableStringBuilder.click(text: CharSequence,color: Int,onClickListener: SpannableExtensions.OnClickListener,vararg clickTexts: String) : SpannableStringBuilder { 108 | append(text) 109 | for (i in clickTexts.indices) { 110 | val clickText = clickTexts[i] 111 | val start = text.toString().indexOf(clickText) 112 | if (start >= 0) { 113 | val end = start + clickText.length 114 | setSpan( 115 | SpannableExtensions.CustomClickableSpan({ 116 | it.color = color 117 | it.isUnderlineText = false } 118 | ) { onClickListener.onClick(i) }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE 119 | ) 120 | } 121 | } 122 | return this 123 | } 124 | 125 | fun SpannableStringBuilder.setImageSpan(context: Context,drawable: Drawable) { 126 | drawable.setBounds(0, 0, PixelUtil.dip2px(context, 18f), PixelUtil.dip2px(context, 18f)) 127 | val verticalAlignment: Int = 128 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { 129 | DynamicDrawableSpan.ALIGN_CENTER //居中对齐 130 | } else { 131 | DynamicDrawableSpan.ALIGN_BASELINE 132 | } 133 | val imageSpan = SpannableExtensions.CustomImageSpan(drawable, verticalAlignment) 134 | setSpan(imageSpan, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) 135 | } 136 | 137 | fun SpannableStringBuilder.select( 138 | spannableExtensions: SpannableExtensions, 139 | onImageClickListener: SpannableExtensions.OnImageClickListener) : SpannableStringBuilder 140 | { 141 | setSpan(SpannableExtensions.CustomClickableSpan({ 142 | it.color = Color.WHITE 143 | it.isUnderlineText = false 144 | }){ 145 | spannableExtensions.setChecked(!spannableExtensions.isChecked()) 146 | if (spannableExtensions.isChecked()) { 147 | onImageClickListener.onSelect(spannableExtensions.selectDrawableId) 148 | } else { 149 | onImageClickListener.onUnSelect(spannableExtensions.unSelectDrawableId) 150 | } 151 | },0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) 152 | return this 153 | } 154 | 155 | fun SpannableStringBuilder.clickInto(textView: TextView) { 156 | textView.movementMethod = LinkMovementMethod.getInstance() //设置可点击状态 157 | textView.highlightColor = Color.TRANSPARENT //设置点击后的颜色为透明 158 | textView.text = this 159 | } -------------------------------------------------------------------------------- /baselib/src/main/res/layout/keyboard_popup_window.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /baselib/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | plugins { 3 | id 'com.android.application' version '7.1.2' apply false 4 | id 'com.android.library' version '7.1.2' apply false 5 | id 'org.jetbrains.kotlin.android' version '1.6.21' apply false 6 | } 7 | 8 | task clean(type: Delete) { 9 | delete rootProject.buildDir 10 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | # Enables namespacing of each library's R class so that its R class includes only the 21 | # resources declared in the library itself and none from the library's dependencies, 22 | # thereby reducing the size of the R class for that library 23 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wsdydeni/AndroidBaseLibrary/37ff240b101a8aced03f77293a7b4090edb83799/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 25 10:11:14 CST 2022 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | maven { url 'https://jitpack.io' } 7 | } 8 | } 9 | dependencyResolutionManagement { 10 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 11 | repositories { 12 | google() 13 | mavenCentral() 14 | maven { url 'https://jitpack.io' } 15 | } 16 | } 17 | rootProject.name = "AndroidBaseLibrary" 18 | include ':app' 19 | include ':baselib' 20 | --------------------------------------------------------------------------------