Skip to content

Commit 6f2cedc

Browse files
committed
Create sp & dp annotations & remove unused dependencies
1 parent c475b77 commit 6f2cedc

File tree

13 files changed

+180
-73
lines changed

13 files changed

+180
-73
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
github: skydoves
2-
ko_fi: skydoves
3-
custom: https://www.buymeacoffee.com/skydoves
2+
custom: ["https://www.paypal.me/skydoves", "https://www.buymeacoffee.com/skydoves"]

androidribbon/src/main/java/com/skydoves/androidribbon/RibbonLayout.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class RibbonLayout : FrameLayout, RibbonInterface {
5858
getAttrs(attrs)
5959
}
6060

61-
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
61+
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs,
62+
defStyleAttr) {
6263
getAttrs(attrs, defStyleAttr)
6364
}
6465

@@ -72,7 +73,8 @@ class RibbonLayout : FrameLayout, RibbonInterface {
7273
}
7374

7475
private fun getAttrs(attributeSet: AttributeSet, defStyleAttr: Int) {
75-
val typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.RibbonLayout, defStyleAttr, 0)
76+
val typedArray =
77+
context.obtainStyledAttributes(attributeSet, R.styleable.RibbonLayout, defStyleAttr, 0)
7678
try {
7779
setTypeArray(typedArray)
7880
} finally {
@@ -81,8 +83,10 @@ class RibbonLayout : FrameLayout, RibbonInterface {
8183
}
8284

8385
private fun setTypeArray(typeArray: TypedArray) {
84-
this.ribbonHeaderAlign = typeArray.getInteger(R.styleable.RibbonLayout_ribbonLayout_header_align, ribbonHeaderAlign)
85-
this.ribbonBottomAlign = typeArray.getInteger(R.styleable.RibbonLayout_ribbonLayout_bottom_align, ribbonBottomAlign)
86+
this.ribbonHeaderAlign =
87+
typeArray.getInteger(R.styleable.RibbonLayout_ribbonLayout_header_align, ribbonHeaderAlign)
88+
this.ribbonBottomAlign =
89+
typeArray.getInteger(R.styleable.RibbonLayout_ribbonLayout_bottom_align, ribbonBottomAlign)
8690
}
8791

8892
/** update [RibbonLayout] after finishing inflate. */

androidribbon/src/main/java/com/skydoves/androidribbon/RibbonRecyclerView.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class RibbonRecyclerView : RecyclerView, IRibbonList {
4040
onCreate()
4141
}
4242

43-
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
43+
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs,
44+
defStyleAttr) {
4445
getAttrs(attrs, defStyleAttr)
4546
onCreate()
4647
}
@@ -55,7 +56,8 @@ class RibbonRecyclerView : RecyclerView, IRibbonList {
5556
}
5657

5758
private fun getAttrs(attributeSet: AttributeSet, defStyleAttr: Int) {
58-
val typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.RibbonRecyclerView, defStyleAttr, 0)
59+
val typedArray =
60+
context.obtainStyledAttributes(attributeSet, R.styleable.RibbonRecyclerView, defStyleAttr, 0)
5961
try {
6062
setTypeArray(typedArray)
6163
} finally {
@@ -65,7 +67,8 @@ class RibbonRecyclerView : RecyclerView, IRibbonList {
6567

6668
private fun setTypeArray(typeArray: TypedArray) {
6769
space = typeArray.getDimension(R.styleable.RibbonRecyclerView_ribbon_recycler_space, space)
68-
orientation = typeArray.getInt(R.styleable.RibbonRecyclerView_ribbon_recycler_orientation, orientation)
70+
orientation =
71+
typeArray.getInt(R.styleable.RibbonRecyclerView_ribbon_recycler_orientation, orientation)
6972
}
7073

7174
private fun onCreate() {

androidribbon/src/main/java/com/skydoves/androidribbon/RibbonTagItemDecoration.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ import android.view.View
2121
import androidx.recyclerview.widget.RecyclerView
2222

2323
/** RibbonTagItemDecoration creates the space of [RecyclerView] by orientation align. */
24-
class RibbonTagItemDecoration(private val space: Int, private val orientation: Int) : RecyclerView.ItemDecoration() {
25-
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
24+
class RibbonTagItemDecoration(
25+
private val space: Int,
26+
private val orientation: Int
27+
) : RecyclerView.ItemDecoration() {
28+
override fun getItemOffsets(
29+
outRect: Rect,
30+
view: View,
31+
parent: RecyclerView,
32+
state: RecyclerView.State
33+
) {
2634
super.getItemOffsets(outRect, view, parent, state)
2735
when (orientation) {
2836
0 -> outRect.bottom = space

androidribbon/src/main/java/com/skydoves/androidribbon/RibbonView.kt

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ import android.graphics.drawable.GradientDrawable
2525
import android.util.AttributeSet
2626
import android.view.Gravity
2727
import androidx.annotation.ColorInt
28+
import androidx.annotation.ColorRes
2829
import androidx.appcompat.widget.AppCompatTextView
2930
import androidx.core.content.ContextCompat
31+
import com.skydoves.androidribbon.annotations.Dp
32+
import com.skydoves.androidribbon.annotations.Sp
3033

3134
@DslMarker
3235
annotation class RibbonDsl
@@ -60,26 +63,31 @@ class RibbonView : AppCompatTextView, RibbonInterface {
6063
field = value
6164
rotation(value)
6265
}
66+
@Dp
6367
var ribbonRadius = 10f
6468
set(value) {
6569
field = value
6670
updateRibbon()
6771
}
72+
@Dp
6873
var paddingLeft = 8f
6974
set(value) {
7075
field = value
7176
updateRibbon()
7277
}
78+
@Dp
7379
var paddingTop = 4f
7480
set(value) {
7581
field = value
7682
updateRibbon()
7783
}
84+
@Dp
7885
var paddingRight = 8f
7986
set(value) {
8087
field = value
8188
updateRibbon()
8289
}
90+
@Dp
8391
var paddingBottom = 4f
8492
set(value) {
8593
field = value
@@ -95,7 +103,8 @@ class RibbonView : AppCompatTextView, RibbonInterface {
95103
getAttrs(attrs)
96104
}
97105

98-
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
106+
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs,
107+
defStyleAttr) {
99108
onCreate()
100109
getAttrs(attrs, defStyleAttr)
101110
}
@@ -118,7 +127,8 @@ class RibbonView : AppCompatTextView, RibbonInterface {
118127
}
119128

120129
private fun getAttrs(attributeSet: AttributeSet, defStyleAttr: Int) {
121-
val typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.RibbonView, defStyleAttr, 0)
130+
val typedArray =
131+
context.obtainStyledAttributes(attributeSet, R.styleable.RibbonView, defStyleAttr, 0)
122132
try {
123133
setTypeArray(typedArray)
124134
} finally {
@@ -130,12 +140,16 @@ class RibbonView : AppCompatTextView, RibbonInterface {
130140
this.ribbonDrawable = typeArray.getDrawable(R.styleable.RibbonView_ribbon_drawable)
131141
this.ribbonBackgroundColor =
132142
typeArray.getColor(R.styleable.RibbonView_ribbon_background_color, ribbonBackgroundColor)
133-
this.ribbonRadius = typeArray.getDimension(R.styleable.RibbonView_ribbon_ribbonRadius, ribbonRadius)
143+
this.ribbonRadius =
144+
typeArray.getDimension(R.styleable.RibbonView_ribbon_ribbonRadius, ribbonRadius)
134145
this.ribbonRotation = typeArray.getInt(R.styleable.RibbonView_ribbon_rotation, ribbonRotation)
135-
this.paddingLeft = typeArray.getDimension(R.styleable.RibbonView_ribbon_padding_left, paddingLeft)
146+
this.paddingLeft =
147+
typeArray.getDimension(R.styleable.RibbonView_ribbon_padding_left, paddingLeft)
136148
this.paddingTop = typeArray.getDimension(R.styleable.RibbonView_ribbon_padding_top, paddingTop)
137-
this.paddingRight = typeArray.getDimension(R.styleable.RibbonView_ribbon_padding_right, paddingRight)
138-
this.paddingBottom = typeArray.getDimension(R.styleable.RibbonView_ribbon_padding_bottom, paddingBottom)
149+
this.paddingRight =
150+
typeArray.getDimension(R.styleable.RibbonView_ribbon_padding_right, paddingRight)
151+
this.paddingBottom =
152+
typeArray.getDimension(R.styleable.RibbonView_ribbon_padding_bottom, paddingBottom)
139153
}
140154

141155
/** initialize attributes by [RibbonView.Builder] */
@@ -192,46 +206,51 @@ class RibbonView : AppCompatTextView, RibbonInterface {
192206
class Builder(val context: Context) {
193207
@JvmField
194208
var ribbonDrawable: Drawable? = null
195-
@ColorInt
196-
@JvmField
209+
@JvmField @ColorInt
197210
var ribbonBackgroundColor = ContextCompat.getColor(context, R.color.colorPrimary)
198211
@JvmField
199212
var ribbonRotation = 0
200-
@JvmField
213+
@JvmField @Dp
201214
var ribbonRadius = 10f
202-
@JvmField
215+
@JvmField @Dp
203216
var paddingLeft = 8f
204-
@JvmField
217+
@JvmField @Dp
205218
var paddingTop = 4f
206-
@JvmField
219+
@JvmField @Dp
207220
var paddingRight = 8f
208-
@JvmField
221+
@JvmField @Dp
209222
var paddingBottom = 4f
210223
@JvmField
211224
var text = ""
212-
@JvmField
225+
@JvmField @ColorInt
213226
var textColor = Color.WHITE
214-
@JvmField
227+
@JvmField @Sp
215228
var textSize = 12f
216229
@JvmField
217230
var textStyle = Typeface.NORMAL
218231

219-
fun setRibbonDrawable(RibbonDrawable: Drawable?): Builder = apply { this.ribbonDrawable = RibbonDrawable }
220-
fun setRibbonBackgroundColor(@ColorInt color: Int): Builder = apply { this.ribbonBackgroundColor = color }
232+
fun setRibbonDrawable(RibbonDrawable: Drawable?): Builder = apply {
233+
this.ribbonDrawable = RibbonDrawable
234+
}
235+
236+
fun setRibbonBackgroundColor(@ColorInt color: Int): Builder = apply {
237+
this.ribbonBackgroundColor = color
238+
}
239+
240+
fun setRibbonBackgroundColorResource(@ColorRes color: Int): Builder = apply {
241+
this.ribbonBackgroundColor = ContextCompat.getColor(this.context, color)
242+
}
243+
221244
fun setRibbonRotation(value: Int): Builder = apply { this.ribbonRotation = value }
222-
fun setRibbonRadius(value: Float): Builder = apply { this.ribbonRadius = value }
223-
fun setPaddingLeft(value: Float): Builder = apply { this.paddingLeft = value }
224-
fun setPaddingTop(value: Float): Builder = apply { this.paddingTop = value }
225-
fun setPaddingRight(value: Float): Builder = apply { this.paddingRight = value }
226-
fun setPaddingBottom(value: Float): Builder = apply { this.paddingBottom = value }
245+
fun setRibbonRadius(@Dp value: Float): Builder = apply { this.ribbonRadius = value }
246+
fun setPaddingLeft(@Dp value: Float): Builder = apply { this.paddingLeft = value }
247+
fun setPaddingTop(@Dp value: Float): Builder = apply { this.paddingTop = value }
248+
fun setPaddingRight(@Dp value: Float): Builder = apply { this.paddingRight = value }
249+
fun setPaddingBottom(@Dp value: Float): Builder = apply { this.paddingBottom = value }
227250
fun setText(value: String): Builder = apply { this.text = value }
228-
fun setTextColor(value: Int): Builder = apply { this.textColor = value }
229-
fun setTextSize(value: Float): Builder = apply { this.textSize = value }
251+
fun setTextColor(@ColorInt value: Int): Builder = apply { this.textColor = value }
252+
fun setTextSize(@Sp value: Float): Builder = apply { this.textSize = value }
230253
fun setTextStyle(value: Int): Builder = apply { this.textStyle = value }
231-
fun build(): RibbonView {
232-
val ribbon = RibbonView(context)
233-
ribbon.onCreateByBuilder(this)
234-
return ribbon
235-
}
254+
fun build(): RibbonView = RibbonView(context).apply { onCreateByBuilder(this@Builder) }
236255
}
237256
}

androidribbon/src/main/java/com/skydoves/androidribbon/ShimmerRibbonView.kt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ fun colorShimmer(block: Shimmer.ColorHighlightBuilder.() -> Unit): Shimmer =
3636

3737
/** create a [shimmerRibbonView] by [ShimmerRibbonView.Builder] using dsl. */
3838
@Suppress("unused")
39-
fun shimmerRibbonView(context: Context, block: ShimmerRibbonView.Builder.() -> Unit): ShimmerRibbonView =
39+
fun shimmerRibbonView(
40+
context: Context,
41+
block: ShimmerRibbonView.Builder.() -> Unit
42+
): ShimmerRibbonView =
4043
ShimmerRibbonView.Builder(context).apply(block).build()
4144

4245
/** ShimmerRibbonView implements [RibbonView] on [ShimmerFrameLayout] for shimmering effect. */
@@ -67,7 +70,8 @@ class ShimmerRibbonView : ShimmerFrameLayout, RibbonInterface {
6770
getAttrs(attrs)
6871
}
6972

70-
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
73+
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs,
74+
defStyleAttr) {
7175
getAttrs(attrs, defStyleAttr)
7276
}
7377

@@ -81,7 +85,8 @@ class ShimmerRibbonView : ShimmerFrameLayout, RibbonInterface {
8185
}
8286

8387
private fun getAttrs(attributeSet: AttributeSet, defStyleAttr: Int) {
84-
val typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.ShimmerRibbonView, defStyleAttr, 0)
88+
val typedArray =
89+
context.obtainStyledAttributes(attributeSet, R.styleable.ShimmerRibbonView, defStyleAttr, 0)
8590
try {
8691
setTypeArray(typedArray)
8792
} finally {
@@ -97,25 +102,34 @@ class ShimmerRibbonView : ShimmerFrameLayout, RibbonInterface {
97102
ribbonBackgroundColor
98103
)
99104
ribbonRadius =
100-
typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_ribbonRadius, ribbonRadius)
101-
paddingLeft = typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_padding_left, paddingLeft)
102-
paddingTop = typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_padding_top, paddingTop)
105+
typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_ribbonRadius,
106+
ribbonRadius)
107+
paddingLeft =
108+
typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_padding_left,
109+
paddingLeft)
110+
paddingTop =
111+
typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_padding_top, paddingTop)
103112
paddingRight =
104-
typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_padding_right, paddingRight)
113+
typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_padding_right,
114+
paddingRight)
105115
paddingBottom =
106-
typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_padding_bottom, paddingBottom)
116+
typeArray.getDimension(R.styleable.ShimmerRibbonView_shimmer_ribbon_padding_bottom,
117+
paddingBottom)
107118
}.apply {
108119
text = typeArray.getString(R.styleable.ShimmerRibbonView_shimmer_ribbon_text)
109-
setTextColor(typeArray.getColor(R.styleable.ShimmerRibbonView_shimmer_ribbon_textColor, Color.WHITE))
120+
setTextColor(
121+
typeArray.getColor(R.styleable.ShimmerRibbonView_shimmer_ribbon_textColor, Color.WHITE))
110122
textSize =
111-
typeArray.getDimensionPixelSize(R.styleable.ShimmerRibbonView_shimmer_ribbon_textSize, 12).toFloat()
123+
typeArray.getDimensionPixelSize(R.styleable.ShimmerRibbonView_shimmer_ribbon_textSize, 12)
124+
.toFloat()
112125

113126
when (typeArray.getInteger(R.styleable.ShimmerRibbonView_shimmer_ribbon_textStyle, 0)) {
114127
0 -> typeface = Typeface.DEFAULT_BOLD
115128
1 -> setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC)
116129
}
117130
}
118-
frameRotation = typeArray.getInt(R.styleable.ShimmerRibbonView_shimmer_ribbon_rotation, frameRotation)
131+
frameRotation =
132+
typeArray.getInt(R.styleable.ShimmerRibbonView_shimmer_ribbon_rotation, frameRotation)
119133
}
120134

121135
private fun onCreateByBuilder(builder: Builder) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2019 skydoves
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 com.skydoves.androidribbon.annotations
18+
19+
import androidx.annotation.Dimension
20+
21+
/**
22+
* Denotes that an integer parameter, field or method return value is expected
23+
* to represent a device independent pixel dimension.
24+
*/
25+
@MustBeDocumented
26+
@kotlin.annotation.Retention(AnnotationRetention.BINARY)
27+
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER,
28+
AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD,
29+
AnnotationTarget.LOCAL_VARIABLE)
30+
@Dimension(unit = Dimension.DP)
31+
annotation class Dp
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2019 skydoves
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 com.skydoves.androidribbon.annotations
18+
19+
import androidx.annotation.Dimension
20+
21+
/**
22+
* Denotes that an integer parameter, field or method return value is expected
23+
* to represent a scale independent pixel dimension.
24+
*/
25+
@MustBeDocumented
26+
@kotlin.annotation.Retention(AnnotationRetention.BINARY)
27+
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER,
28+
AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD,
29+
AnnotationTarget.LOCAL_VARIABLE)
30+
@Dimension(unit = Dimension.SP)
31+
annotation class Sp

app/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ android {
1515
}
1616

1717
dependencies {
18-
implementation "androidx.appcompat:appcompat:$versions.androidxAppcompat"
1918
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"
20-
implementation "androidx.recyclerview:recyclerview:$versions.recyclerView"
21-
implementation "androidx.cardview:cardview:$versions.cardView"
19+
implementation "com.google.android.material:material:$versions.googleMaterial"
2220
implementation project(":androidribbon")
2321
}
2422

0 commit comments

Comments
 (0)