-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e6fe41
commit ef47474
Showing
33 changed files
with
1,242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/build | ||
/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
id 'kotlin-kapt' | ||
} | ||
|
||
android { | ||
namespace 'com.xayah.design' | ||
compileSdk 32 | ||
|
||
viewBinding { | ||
enabled = true | ||
} | ||
|
||
dataBinding { | ||
enabled = true | ||
} | ||
|
||
defaultConfig { | ||
minSdk 26 | ||
targetSdk 32 | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation 'androidx.appcompat:appcompat:1.3.1' | ||
implementation 'com.google.android.material:material:1.5.0' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
|
||
def lifecycle_version = "2.4.1" | ||
// ViewModel | ||
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version") | ||
// ViewModel utilities for Compose | ||
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version") | ||
// LiveData | ||
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version") | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
design/src/androidTest/java/com/xayah/design/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.xayah.design | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.xayah.design.test", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.xayah.design | ||
|
||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.widget.FrameLayout | ||
import androidx.annotation.AttrRes | ||
import androidx.annotation.StyleRes | ||
import com.xayah.design.databinding.ComponentActionLabelBinding | ||
|
||
class ActionLabel @JvmOverloads constructor( | ||
context: Context, | ||
attributeSet: AttributeSet? = null, | ||
@AttrRes defStyleAttr: Int = 0, | ||
@StyleRes defStyleRes: Int = 0 | ||
) : FrameLayout(context, attributeSet, defStyleAttr, defStyleRes) { | ||
private val binding = ComponentActionLabelBinding | ||
.inflate(LayoutInflater.from(context), this, true) | ||
|
||
var icon: Drawable? | ||
get() = binding.iconView.background | ||
set(value) { | ||
binding.iconView.background = value | ||
} | ||
|
||
var text: CharSequence? | ||
get() = binding.textView.text | ||
set(value) { | ||
binding.textView.text = value | ||
} | ||
|
||
var subtext: CharSequence? | ||
get() = binding.subtextView.text | ||
set(value) { | ||
binding.subtextView.text = value | ||
binding.subtextView.visibility = if (value == null) View.GONE else View.VISIBLE | ||
} | ||
|
||
override fun setOnClickListener(l: OnClickListener?) { | ||
binding.root.setOnClickListener(l) | ||
} | ||
|
||
init { | ||
context.theme.obtainStyledAttributes( | ||
attributeSet, | ||
R.styleable.ActionLabel, | ||
defStyleAttr, | ||
defStyleRes | ||
).apply { | ||
try { | ||
icon = getDrawable(R.styleable.ActionLabel_icon) | ||
text = getString(R.styleable.ActionLabel_text) | ||
subtext = getString(R.styleable.ActionLabel_subtext) | ||
} finally { | ||
recycle() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.xayah.design | ||
|
||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import androidx.annotation.AttrRes | ||
import androidx.annotation.DimenRes | ||
import com.google.android.material.card.MaterialCardView | ||
import com.xayah.design.databinding.ComponentLargeActionLabelBinding | ||
import com.xayah.design.util.resolveClickableAttrs | ||
import com.xayah.design.util.selectableItemBackground | ||
|
||
class LargeActionCard @JvmOverloads constructor( | ||
context: Context, | ||
attributeSet: AttributeSet? = null, | ||
@AttrRes defStyleAttr: Int = 0 | ||
) : MaterialCardView(context, attributeSet, defStyleAttr) { | ||
private val binding = ComponentLargeActionLabelBinding | ||
.inflate(LayoutInflater.from(context), this, true) | ||
|
||
var text: CharSequence? | ||
get() = binding.textView.text | ||
set(value) { | ||
binding.textView.text = value | ||
} | ||
|
||
var subtext: CharSequence? | ||
get() = binding.subtextView.text | ||
set(value) { | ||
binding.subtextView.text = value | ||
} | ||
|
||
var icon: Drawable? | ||
get() = binding.iconView.background | ||
set(value) { | ||
binding.iconView.background = value | ||
} | ||
|
||
init { | ||
context.resolveClickableAttrs(attributeSet, defStyleAttr) { | ||
isFocusable = focusable(true) | ||
isClickable = clickable(true) | ||
foreground = foreground() ?: context.selectableItemBackground | ||
} | ||
|
||
context.theme.obtainStyledAttributes( | ||
attributeSet, | ||
R.styleable.LargeActionCard, | ||
defStyleAttr, | ||
0 | ||
).apply { | ||
try { | ||
icon = getDrawable(R.styleable.LargeActionCard_icon) | ||
text = getString(R.styleable.LargeActionCard_text) | ||
subtext = getString(R.styleable.LargeActionCard_subtext) | ||
} finally { | ||
recycle() | ||
} | ||
} | ||
|
||
minimumHeight = getPixels(R.dimen.large_action_card_min_height) | ||
radius = getPixels(R.dimen.large_action_card_radius).toFloat() | ||
// elevation = getPixels(R.dimen.large_action_card_elevation).toFloat() | ||
} | ||
|
||
private fun getPixels(@DimenRes resId: Int): Int { | ||
return resources.getDimensionPixelSize(resId) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.xayah.design | ||
|
||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.widget.FrameLayout | ||
import androidx.annotation.AttrRes | ||
import androidx.annotation.StyleRes | ||
import com.xayah.design.databinding.ComponentLargeActionLabelBinding | ||
import com.xayah.design.util.resolveClickableAttrs | ||
import com.xayah.design.util.selectableItemBackground | ||
|
||
class LargeActionLabel @JvmOverloads constructor( | ||
context: Context, | ||
attributeSet: AttributeSet? = null, | ||
@AttrRes defStyleAttr: Int = 0, | ||
@StyleRes defStyleRes: Int = 0 | ||
) : FrameLayout(context, attributeSet, defStyleAttr, defStyleRes) { | ||
private val binding = ComponentLargeActionLabelBinding | ||
.inflate(LayoutInflater.from(context), this, true) | ||
|
||
var icon: Drawable? | ||
get() = binding.iconView.background | ||
set(value) { | ||
binding.iconView.background = value | ||
} | ||
|
||
var text: CharSequence? | ||
get() = binding.textView.text | ||
set(value) { | ||
binding.textView.text = value | ||
} | ||
|
||
var subtext: CharSequence? | ||
get() = binding.subtextView.text | ||
set(value) { | ||
binding.subtextView.text = value | ||
|
||
if (value == null) { | ||
binding.subtextView.visibility = View.GONE | ||
} else { | ||
binding.subtextView.visibility = View.VISIBLE | ||
} | ||
} | ||
|
||
init { | ||
context.resolveClickableAttrs( | ||
attributeSet, | ||
defStyleAttr, | ||
defStyleRes | ||
) { | ||
isFocusable = focusable(true) | ||
isClickable = clickable(true) | ||
background = background() ?: context.selectableItemBackground | ||
} | ||
|
||
context.theme.obtainStyledAttributes( | ||
attributeSet, | ||
R.styleable.LargeActionLabel, | ||
defStyleAttr, | ||
defStyleRes | ||
).apply { | ||
try { | ||
icon = getDrawable(R.styleable.LargeActionLabel_icon) | ||
text = getString(R.styleable.LargeActionLabel_text) | ||
subtext = getString(R.styleable.LargeActionLabel_subtext) | ||
} finally { | ||
recycle() | ||
} | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
design/src/main/java/com/xayah/design/adapter/ViewAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.xayah.design.adapter | ||
|
||
import android.widget.CompoundButton | ||
import androidx.databinding.BindingAdapter | ||
import com.xayah.design.preference.Clickable | ||
import com.xayah.design.preference.EditableText | ||
import com.xayah.design.preference.SelectableList | ||
import com.xayah.design.preference.Switch | ||
|
||
class ViewAdapter { | ||
companion object { | ||
@BindingAdapter("items") | ||
@JvmStatic | ||
fun setItems(v: SelectableList, array: Array<String>?) { | ||
if (array != null) { | ||
v.setItems(array) | ||
} | ||
} | ||
|
||
@BindingAdapter("onConfirm") | ||
@JvmStatic | ||
fun setSelectableListOnConfirmListener( | ||
v: SelectableList, | ||
listener: ((v: SelectableList, choice: Int) -> Unit) | ||
) { | ||
v.setOnConfirmListener(listener) | ||
} | ||
|
||
@BindingAdapter("onConfirm") | ||
@JvmStatic | ||
fun setEditableTextOnConfirmListener( | ||
v: EditableText, | ||
listener: ((v: EditableText, content: CharSequence?) -> Unit) | ||
) { | ||
v.setOnConfirmListener(listener) | ||
} | ||
|
||
@BindingAdapter("onCheckedChange") | ||
@JvmStatic | ||
fun setOnCheckedChangeListener( | ||
v: Switch, | ||
listener: ((buttonView: CompoundButton, isChecked: Boolean) -> Unit) | ||
) { | ||
v.setOnCheckedChangeListener(listener) | ||
} | ||
|
||
@BindingAdapter("isRound") | ||
@JvmStatic | ||
fun setRound(view: Clickable, isRound: Boolean) { | ||
view.setRound(isRound) | ||
} | ||
} | ||
} |
Oops, something went wrong.