Skip to content

Commit 5fe04ff

Browse files
authored
Merge pull request #244 from wordpress-mobile/issue/219-code-highlight-color
Issue/219 code highlight color
2 parents 51afd94 + 496fd29 commit 5fe04ff

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
<declare-styleable name="AztecText">
66
<attr name="backgroundColor" format="reference|color" />
7+
<attr name="blockVerticalPadding" format="reference|dimension" />
78
<attr name="bulletColor" format="reference|color" />
89
<attr name="bulletMargin" format="reference|dimension" />
910
<attr name="bulletPadding" format="reference|dimension" />
1011
<attr name="bulletWidth" format="reference|dimension" />
11-
<attr name="blockVerticalPadding" format="reference|dimension" />
12+
<attr name="codeBackground" format="reference|color" />
13+
<attr name="codeBackgroundAlpha" format="reference|fraction" />
14+
<attr name="codeColor" format="reference|color" />
1215
<attr name="historyEnable" format="reference|boolean" />
1316
<attr name="historySize" format="reference|integer" />
1417
<attr name="lineSpacingExtra" format="reference|dimension" />
@@ -22,14 +25,13 @@
2225
<attr name="quoteWidth" format="reference|dimension" />
2326
<attr name="textColor" format="reference|color" />
2427
<attr name="textColorHint" format="reference|color" />
25-
<attr name="codeBackground" format="reference|color" />
26-
<attr name="codeColor" format="reference|color" />
2728
</declare-styleable>
28-
29+
2930
<declare-styleable name="SourceViewEditText">
30-
<attr name="codeTextColor" format="reference|color" />
31+
<attr name="attributeColor" format="reference|color" />
3132
<attr name="codeBackgroundColor" format="reference|color" />
33+
<attr name="codeTextColor" format="reference|color" />
3234
<attr name="tagColor" format="reference|color" />
33-
<attr name="attributeColor" format="reference|color" />
3435
</declare-styleable>
36+
3537
</resources>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
<style name="AztecTextStyle">
2525
<item name="android:textCursorDrawable">?attr/textColor</item>
2626
<item name="backgroundColor">@android:color/transparent</item>
27+
<item name="blockVerticalPadding">@dimen/block_vertical_padding</item>
2728
<item name="bulletColor">@color/blue_medium</item>
2829
<item name="bulletMargin">@dimen/bullet_margin</item>
2930
<item name="bulletPadding">@dimen/bullet_padding</item>
3031
<item name="bulletWidth">@dimen/bullet_width</item>
32+
<item name="codeBackground">@color/code_background</item>
33+
<item name="codeBackgroundAlpha">75%</item>
34+
<item name="codeColor">@color/code</item>
3135
<item name="lineSpacingExtra">@dimen/spacing_extra</item>
3236
<item name="lineSpacingMultiplier">@dimen/spacing_multiplier</item>
3337
<item name="linkColor">@color/blue_wordpress</item>
@@ -37,9 +41,6 @@
3741
<item name="quoteMargin">@dimen/quote_margin</item>
3842
<item name="quotePadding">@dimen/quote_padding</item>
3943
<item name="quoteWidth">@dimen/quote_width</item>
40-
<item name="blockVerticalPadding">@dimen/block_vertical_padding</item>
41-
<item name="codeBackground">@color/code_background</item>
42-
<item name="codeColor">@color/code</item>
4344
<item name="textColor">@android:color/white</item>
4445
<item name="textColorHint">@android:color/darker_gray</item>
4546
</style>

0 commit comments

Comments
 (0)