├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── themes.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── color │ │ │ │ ├── color_md_text_btn_background.xml │ │ │ │ ├── color_md_outlined_btn_background.xml │ │ │ │ ├── color_md_contained_btn_text.xml │ │ │ │ ├── color_md_text_btn_text.xml │ │ │ │ ├── color_md_contained_btn_stroke.xml │ │ │ │ ├── color_md_dashed_btn_text.xml │ │ │ │ ├── color_md_outlined_btn_text.xml │ │ │ │ ├── color_md_contained_btn_background.xml │ │ │ │ └── color_md_outlined_btn_stroke.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ └── activity_live_data_test.xml │ │ │ └── drawable │ │ │ │ └── bg_button_dash_selector.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── ldlywt │ │ │ │ └── commoncode │ │ │ │ ├── App.kt │ │ │ │ ├── location │ │ │ │ ├── LocationHelperV2.kt │ │ │ │ ├── LocationPermissionUtils.kt │ │ │ │ ├── FusedLocationHelper.kt │ │ │ │ ├── NetWorkLocationHelper.kt │ │ │ │ └── LocationHelper.kt │ │ │ │ ├── livedata │ │ │ │ ├── TakePhotoLiveData.kt │ │ │ │ ├── RequestPermissionLiveData.kt │ │ │ │ ├── TimerGlobalLiveData.kt │ │ │ │ └── NetworkWatchLiveData.kt │ │ │ │ ├── view │ │ │ │ └── LifecycleView.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── permission │ │ │ │ └── PermissionKtx.kt │ │ │ │ └── activity │ │ │ │ └── LiveDataTestActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ldlywt │ │ │ └── commoncode │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── ldlywt │ │ └── commoncode │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── ktx ├── .gitignore ├── consumer-rules.pro ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── ldlywt │ │ │ └── ktx │ │ │ ├── EditText.kt │ │ │ ├── dp.kt │ │ │ ├── ActivityKtx.kt │ │ │ ├── snackbar.kt │ │ │ ├── clipboard.kt │ │ │ ├── ViewKtx.kt │ │ │ ├── toast.kt │ │ │ ├── FlowKtx.kt │ │ │ ├── Version.kt │ │ │ ├── Network.kt │ │ │ ├── hidekeyboard.kt │ │ │ ├── Cursor.kt │ │ │ ├── File.kt │ │ │ └── StringKtx.kt │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ldlywt │ │ │ └── ktx │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── ldlywt │ │ └── ktx │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── .idea ├── .gitignore ├── compiler.xml ├── kotlinc.xml ├── vcs.xml ├── gradle.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── settings.gradle ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /ktx/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /ktx/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidCommonCode 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldlywt/AndroidCommonCode/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ktx/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ktx/src/main/java/com/ldlywt/ktx/EditText.kt: -------------------------------------------------------------------------------- 1 | package com.ldlywt.ktx 2 | 3 | 4 | import android.widget.EditText 5 | 6 | val EditText.value 7 | get() = text?.toString() ?: "" -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Oct 28 14:19:26 CST 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_md_text_btn_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_md_outlined_btn_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Common Generic Code Organizer 2 | 3 | ## Outline 4 | 5 | [![o5MSdP.md.png](https://s1.ax1x.com/2021/12/10/o5MSdP.md.png)](https://imgtu.com/i/o5MSdP) 6 | 7 | ## MaterialDesign Button Styles 8 | 9 | [![o5Qe6H.md.png](https://s1.ax1x.com/2021/12/10/o5Qe6H.md.png)](https://imgtu.com/i/o5Qe6H) 10 | -------------------------------------------------------------------------------- /ktx/src/main/java/com/ldlywt/ktx/dp.kt: -------------------------------------------------------------------------------- 1 | package com.ldlywt.ktx 2 | 3 | import android.content.res.Resources 4 | 5 | // Convert px to dp 6 | val Int.dp: Int 7 | get() = (this / Resources.getSystem().displayMetrics.density).toInt() 8 | 9 | //Convert dp to px 10 | val Int.px: Int 11 | get() = (this * Resources.getSystem().displayMetrics.density).toInt() -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | dependencyResolutionManagement { 2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 3 | repositories { 4 | google() 5 | mavenCentral() 6 | jcenter() // Warning: this repository is going to shut down soon 7 | } 8 | } 9 | rootProject.name = "AndroidCommonCode" 10 | include ':app' 11 | include ':ktx' 12 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_md_contained_btn_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_md_text_btn_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_md_contained_btn_stroke.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_md_dashed_btn_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_md_outlined_btn_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_md_contained_btn_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/color/color_md_outlined_btn_stroke.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/ldlywt/commoncode/App.kt: -------------------------------------------------------------------------------- 1 | package com.ldlywt.commoncode 2 | 3 | import android.app.Application 4 | 5 | val applicationContext = App.instance 6 | 7 | class App : Application() { 8 | 9 | override fun onCreate() { 10 | super.onCreate() 11 | instance = this 12 | } 13 | 14 | companion object { 15 | lateinit var instance: App 16 | private set 17 | } 18 | } -------------------------------------------------------------------------------- /ktx/src/main/java/com/ldlywt/ktx/ActivityKtx.kt: -------------------------------------------------------------------------------- 1 | package com.ldlywt.ktx 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import android.os.Bundle 6 | 7 | inline fun Activity.startActivity(bundle: Bundle? = null) { 8 | val intent = Intent(this, T::class.java) 9 | if (bundle != null) { 10 | intent.putExtras(bundle) 11 | } 12 | startActivity(intent) 13 | } 14 | -------------------------------------------------------------------------------- /ktx/src/test/java/com/ldlywt/ktx/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.ldlywt.ktx 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/test/java/com/ldlywt/commoncode/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.ldlywt.commoncode 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /ktx/src/main/java/com/ldlywt/ktx/snackbar.kt: -------------------------------------------------------------------------------- 1 | package com.ldlywt.ktx 2 | 3 | import android.view.View 4 | import androidx.annotation.StringRes 5 | import com.google.android.material.snackbar.Snackbar 6 | 7 | fun View.snackbar(message: String, duration: Int = Snackbar.LENGTH_LONG) { 8 | Snackbar.make(this, message, duration).show() 9 | } 10 | 11 | fun View.snackbar(@StringRes message: Int, duration: Int = Snackbar.LENGTH_LONG) { 12 | Snackbar.make(this, message, duration).show() 13 | } -------------------------------------------------------------------------------- /ktx/src/main/java/com/ldlywt/ktx/clipboard.kt: -------------------------------------------------------------------------------- 1 | package com.ldlywt.ktx 2 | 3 | import android.content.ClipData 4 | import android.content.ClipboardManager 5 | import android.content.Context 6 | import androidx.core.content.ContextCompat 7 | 8 | fun String.copyToClipboard(context: Context) { 9 | val clipboardManager = ContextCompat.getSystemService(context, ClipboardManager::class.java) 10 | val clip = ClipData.newPlainText("clipboard", this) 11 | clipboardManager?.setPrimaryClip(clip) 12 | } -------------------------------------------------------------------------------- /ktx/src/main/java/com/ldlywt/ktx/ViewKtx.kt: -------------------------------------------------------------------------------- 1 | package com.ldlywt.ktx 2 | 3 | import android.view.View 4 | 5 | fun View.clickWithLimit(intervalMill: Int = 500, block: ((v: View?) -> Unit)) { 6 | setOnClickListener(object : View.OnClickListener { 7 | var last = 0L 8 | override fun onClick(v: View?) { 9 | if (System.currentTimeMillis() - last > intervalMill) { 10 | block(v) 11 | last = System.currentTimeMillis() 12 | } 13 | } 14 | }) 15 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |