Skip to content

Commit 2fd39ed

Browse files
committed
Add alpha attribute to code span
1 parent cd306bb commit 2fd39ed

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class AztecText : EditText, TextWatcher {
131131
inlineFormatter = InlineFormatter(this,
132132
InlineFormatter.CodeStyle(
133133
array.getColor(R.styleable.AztecText_codeBackground, 0),
134+
array.getFraction(R.styleable.AztecText_codeBackgroundAlpha, 1, 1, 0f),
134135
array.getColor(R.styleable.AztecText_codeColor, 0)),
135136
LineBlockFormatter.HeaderStyle(
136137
array.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)))

aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java.util.*
1414
class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, val headerStyle: LineBlockFormatter.HeaderStyle) : AztecFormatter(editor) {
1515

1616
data class CarryOverSpan(val span: AztecInlineSpan, val start: Int, val end: Int)
17-
data class CodeStyle(val codeBackground: Int, val codeColor: Int)
17+
data class CodeStyle(val codeBackground: Int, val codeBackgroundAlpha: Float, val codeColor: Int)
1818

1919
val carryOverSpans = ArrayList<CarryOverSpan>()
2020

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecCodeSpan.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.wordpress.aztec.spans
1919

20+
import android.graphics.Color
2021
import android.graphics.Typeface
2122
import android.os.Parcel
2223
import android.text.ParcelableSpan
@@ -30,6 +31,7 @@ class AztecCodeSpan : MetricAffectingSpan, ParcelableSpan, AztecContentSpan, Azt
3031
private val TAG: String = "code"
3132

3233
private var codeBackground: Int = 0
34+
private var codeBackgroundAlpha: Float = 0.0f
3335
private var codeColor: Int = 0
3436

3537
override var attributes: String = ""
@@ -40,11 +42,13 @@ class AztecCodeSpan : MetricAffectingSpan, ParcelableSpan, AztecContentSpan, Azt
4042

4143
constructor(codeStyle: InlineFormatter.CodeStyle, attributes: String = "") : this(attributes) {
4244
this.codeBackground = codeStyle.codeBackground
45+
this.codeBackgroundAlpha = codeStyle.codeBackgroundAlpha
4346
this.codeColor = codeStyle.codeColor
4447
}
4548

4649
constructor(src: Parcel) {
4750
this.codeBackground = src.readInt()
51+
this.codeBackgroundAlpha = src.readFloat()
4852
this.codeColor = src.readInt()
4953
}
5054

@@ -85,8 +89,9 @@ class AztecCodeSpan : MetricAffectingSpan, ParcelableSpan, AztecContentSpan, Azt
8589
}
8690

8791
private fun configureTextPaint(tp: TextPaint?) {
92+
val alpha: Int = (codeBackgroundAlpha * 255).toInt()
8893
tp?.typeface = Typeface.MONOSPACE
89-
tp?.bgColor = codeBackground
94+
tp?.bgColor = Color.argb(alpha, Color.red(codeBackground), Color.green(codeBackground), Color.blue(codeBackground))
9095
tp?.color = codeColor
9196
}
9297
}

aztec/src/main/res/values/attrs.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
<attr name="textColor" format="reference|color" />
2424
<attr name="textColorHint" format="reference|color" />
2525
<attr name="codeBackground" format="reference|color" />
26+
<attr name="codeBackgroundAlpha" format="reference|fraction" />
2627
<attr name="codeColor" format="reference|color" />
2728
</declare-styleable>
28-
29+
2930
<declare-styleable name="SourceViewEditText">
3031
<attr name="codeTextColor" format="reference|color" />
3132
<attr name="codeBackgroundColor" format="reference|color" />

aztec/src/main/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<item name="quoteWidth">@dimen/quote_width</item>
4040
<item name="blockVerticalPadding">@dimen/block_vertical_padding</item>
4141
<item name="codeBackground">@color/code_background</item>
42+
<item name="codeBackgroundAlpha">75%</item>
4243
<item name="codeColor">@color/code</item>
4344
<item name="textColor">@android:color/white</item>
4445
<item name="textColorHint">@android:color/darker_gray</item>

0 commit comments

Comments
 (0)