Skip to content

Commit

Permalink
init dsl item
Browse files Browse the repository at this point in the history
  • Loading branch information
angcyo committed Apr 28, 2023
1 parent 931291d commit 0ab6493
Show file tree
Hide file tree
Showing 81 changed files with 7,155 additions and 202 deletions.
8 changes: 4 additions & 4 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'

android {
compileSdk 33
compileSdk Integer.parseInt(C_SDK)

defaultConfig {
applicationId "com.angcyo.dslitem.demo"
minSdkVersion 16
targetSdkVersion 33
minSdk Integer.parseInt(M_SDK)
targetSdk Integer.parseInt(T_SDK)
versionCode 1
versionName "1.0"

Expand All @@ -27,7 +27,6 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Expand All @@ -36,4 +35,5 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation project(":dslitem")
implementation project(":dslitem2")
}
17 changes: 13 additions & 4 deletions demo/src/main/java/com/angcyo/dslitem/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.angcyo.dsladapter.initDslAdapter
import com.angcyo.item.*
import com.angcyo.item.DslBaseEditItem
import com.angcyo.item.DslBaseInfoItem
import com.angcyo.item.DslBaseLabelItem
import com.angcyo.item.DslButtonItem
import com.angcyo.item.DslGridItem
import com.angcyo.item.DslLabelEditItem
import com.angcyo.item.DslLabelTextItem
import com.angcyo.item.DslSwitchInfoItem
import com.angcyo.item.DslTextInfoItem
import com.angcyo.item.DslTextItem
import com.angcyo.item.style.itemEditText

class MainActivity : AppCompatActivity() {

Expand All @@ -16,8 +26,7 @@ class MainActivity : AppCompatActivity() {
render {
DslBaseEditItem()() {
itemEditText = this::class.java.simpleName
_lastEditSelectionStart = itemEditText?.length ?: -1

editItemConfig._lastEditSelectionStart = itemEditText?.length ?: -1
configEditTextStyle {
hint = "请输入..."
}
Expand Down Expand Up @@ -62,7 +71,7 @@ class MainActivity : AppCompatActivity() {
DslLabelEditItem()() {
itemLabelText = "Label"
itemEditText = this::class.java.simpleName
_lastEditSelectionStart = itemEditText?.length ?: -1
editItemConfig._lastEditSelectionStart = itemEditText?.length ?: -1

configEditTextStyle {
hint = "请输入..."
Expand Down
12 changes: 5 additions & 7 deletions dslitem/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdk 33
compileSdk Integer.parseInt(C_SDK)

defaultConfig {
vectorDrawables.useSupportLibrary = true

minSdkVersion 16
targetSdkVersion 33
minSdk Integer.parseInt(M_SDK)
targetSdk Integer.parseInt(T_SDK)

consumerProguardFiles 'consumer-rules.pro'
}
namespace 'com.angcyo.item'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

//https://mvnrepository.com/artifact/androidx.appcompat/appcompat
implementation 'androidx.appcompat:appcompat:1.6.1'

Expand All @@ -28,11 +26,11 @@ dependencies {
api 'androidx.recyclerview:recyclerview:1.3.0'

//https://github.com/angcyo/DslAdapter
api 'com.github.angcyo:DslAdapter:5.2.0'
api 'com.github.angcyo:DslAdapter:6.0.1'

//https://github.com/angcyo/DslSpan
api 'com.github.angcyo:DslSpan:1.1.0'

//https://github.com/angcyo/DslButton
api 'com.github.angcyo:DslButton:1.2.0'
api 'com.github.angcyo:DslButton:1.3.0'
}
113 changes: 113 additions & 0 deletions dslitem/src/main/java/com/angcyo/drawable/DslAttrBadgeDrawable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.angcyo.drawable

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.util.AttributeSet
import android.view.Gravity
import com.angcyo.dpi
import com.angcyo.item.R

/**
* 角标
* Email:[email protected]
* @author angcyo
* @date 2019/12/13
* Copyright (c) 2019 ShenZhen O&M Cloud Co., Ltd. All rights reserved.
*/
open class DslAttrBadgeDrawable : DslBadgeDrawable() {

/**是否要绘制角标*/
var drawBadge: Boolean = true

override fun initAttribute(context: Context, attributeSet: AttributeSet?) {
val typedArray =
context.obtainStyledAttributes(attributeSet, R.styleable.DslAttrBadgeDrawable)
drawBadge = typedArray.getBoolean(R.styleable.DslAttrBadgeDrawable_r_draw_badge, drawBadge)
gradientSolidColor =
typedArray.getColor(
R.styleable.DslAttrBadgeDrawable_r_badge_solid_color,
Color.RED
)
badgeTextColor =
typedArray.getColor(
R.styleable.DslAttrBadgeDrawable_r_badge_text_color,
Color.WHITE
)
badgeGravity = typedArray.getInt(
R.styleable.DslAttrBadgeDrawable_r_badge_gravity,
Gravity.TOP or Gravity.RIGHT
)
badgeOffsetX = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_offset_x,
badgeOffsetX
)
badgeCircleRadius = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_circle_radius,
4 * dpi
)
val badgeRadius = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_radius,
10 * dpi
)
cornerRadius(badgeRadius.toFloat())
badgeOffsetY = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_offset_y,
badgeOffsetY
)
badgePaddingLeft = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_padding_left,
4 * dpi
)
badgePaddingRight = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_padding_right,
4 * dpi
)
badgePaddingTop = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_padding_top,
0
)
badgePaddingBottom = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_padding_bottom,
0
)
//脚本文本内容
badgeText = typedArray.getString(R.styleable.DslAttrBadgeDrawable_r_badge_text)
badgeTextSize = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_text_size,
12 * dpi
).toFloat()

//自定义的背景
originDrawable =
typedArray.getDrawable(R.styleable.DslAttrBadgeDrawable_r_badge_bg_drawable)

badgeTextOffsetX = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_text_offset_x,
badgeTextOffsetX
)

badgeTextOffsetY = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_text_offset_y,
badgeTextOffsetY
)

badgeCircleOffsetX = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_circle_offset_x,
badgeTextOffsetX
)

badgeCircleOffsetY = typedArray.getDimensionPixelOffset(
R.styleable.DslAttrBadgeDrawable_r_badge_circle_offset_y,
badgeTextOffsetY
)
typedArray.recycle()
super.initAttribute(context, attributeSet)
}

override fun draw(canvas: Canvas) {
if (drawBadge) {
super.draw(canvas)
}
}
}
Loading

0 comments on commit 0ab6493

Please sign in to comment.