Skip to content

Commit

Permalink
Merge pull request #244 from wordpress-mobile/issue/219-code-highligh…
Browse files Browse the repository at this point in the history
…t-color

Issue/219 code highlight color
  • Loading branch information
khaykov authored Feb 13, 2017
2 parents 51afd94 + 496fd29 commit 5fe04ff
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class AztecText : EditText, TextWatcher {
inlineFormatter = InlineFormatter(this,
InlineFormatter.CodeStyle(
array.getColor(R.styleable.AztecText_codeBackground, 0),
array.getFraction(R.styleable.AztecText_codeBackgroundAlpha, 1, 1, 0f),
array.getColor(R.styleable.AztecText_codeColor, 0)),
LineBlockFormatter.HeaderStyle(
array.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding, 0)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.*
class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, val headerStyle: LineBlockFormatter.HeaderStyle) : AztecFormatter(editor) {

data class CarryOverSpan(val span: AztecInlineSpan, val start: Int, val end: Int)
data class CodeStyle(val codeBackground: Int, val codeColor: Int)
data class CodeStyle(val codeBackground: Int, val codeBackgroundAlpha: Float, val codeColor: Int)

val carryOverSpans = ArrayList<CarryOverSpan>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.wordpress.aztec.spans

import android.graphics.Color
import android.graphics.Typeface
import android.os.Parcel
import android.text.ParcelableSpan
Expand All @@ -30,6 +31,7 @@ class AztecCodeSpan : MetricAffectingSpan, ParcelableSpan, AztecContentSpan, Azt
private val TAG: String = "code"

private var codeBackground: Int = 0
private var codeBackgroundAlpha: Float = 0.0f
private var codeColor: Int = 0

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

constructor(codeStyle: InlineFormatter.CodeStyle, attributes: String = "") : this(attributes) {
this.codeBackground = codeStyle.codeBackground
this.codeBackgroundAlpha = codeStyle.codeBackgroundAlpha
this.codeColor = codeStyle.codeColor
}

constructor(src: Parcel) {
this.codeBackground = src.readInt()
this.codeBackgroundAlpha = src.readFloat()
this.codeColor = src.readInt()
}

Expand Down Expand Up @@ -85,8 +89,9 @@ class AztecCodeSpan : MetricAffectingSpan, ParcelableSpan, AztecContentSpan, Azt
}

private fun configureTextPaint(tp: TextPaint?) {
val alpha: Int = (codeBackgroundAlpha * 255).toInt()
tp?.typeface = Typeface.MONOSPACE
tp?.bgColor = codeBackground
tp?.bgColor = Color.argb(alpha, Color.red(codeBackground), Color.green(codeBackground), Color.blue(codeBackground))
tp?.color = codeColor
}
}
14 changes: 8 additions & 6 deletions aztec/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

<declare-styleable name="AztecText">
<attr name="backgroundColor" format="reference|color" />
<attr name="blockVerticalPadding" format="reference|dimension" />
<attr name="bulletColor" format="reference|color" />
<attr name="bulletMargin" format="reference|dimension" />
<attr name="bulletPadding" format="reference|dimension" />
<attr name="bulletWidth" format="reference|dimension" />
<attr name="blockVerticalPadding" format="reference|dimension" />
<attr name="codeBackground" format="reference|color" />
<attr name="codeBackgroundAlpha" format="reference|fraction" />
<attr name="codeColor" format="reference|color" />
<attr name="historyEnable" format="reference|boolean" />
<attr name="historySize" format="reference|integer" />
<attr name="lineSpacingExtra" format="reference|dimension" />
Expand All @@ -22,14 +25,13 @@
<attr name="quoteWidth" format="reference|dimension" />
<attr name="textColor" format="reference|color" />
<attr name="textColorHint" format="reference|color" />
<attr name="codeBackground" format="reference|color" />
<attr name="codeColor" format="reference|color" />
</declare-styleable>

<declare-styleable name="SourceViewEditText">
<attr name="codeTextColor" format="reference|color" />
<attr name="attributeColor" format="reference|color" />
<attr name="codeBackgroundColor" format="reference|color" />
<attr name="codeTextColor" format="reference|color" />
<attr name="tagColor" format="reference|color" />
<attr name="attributeColor" format="reference|color" />
</declare-styleable>

</resources>
7 changes: 4 additions & 3 deletions aztec/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
<style name="AztecTextStyle">
<item name="android:textCursorDrawable">?attr/textColor</item>
<item name="backgroundColor">@android:color/transparent</item>
<item name="blockVerticalPadding">@dimen/block_vertical_padding</item>
<item name="bulletColor">@color/blue_medium</item>
<item name="bulletMargin">@dimen/bullet_margin</item>
<item name="bulletPadding">@dimen/bullet_padding</item>
<item name="bulletWidth">@dimen/bullet_width</item>
<item name="codeBackground">@color/code_background</item>
<item name="codeBackgroundAlpha">75%</item>
<item name="codeColor">@color/code</item>
<item name="lineSpacingExtra">@dimen/spacing_extra</item>
<item name="lineSpacingMultiplier">@dimen/spacing_multiplier</item>
<item name="linkColor">@color/blue_wordpress</item>
Expand All @@ -37,9 +41,6 @@
<item name="quoteMargin">@dimen/quote_margin</item>
<item name="quotePadding">@dimen/quote_padding</item>
<item name="quoteWidth">@dimen/quote_width</item>
<item name="blockVerticalPadding">@dimen/block_vertical_padding</item>
<item name="codeBackground">@color/code_background</item>
<item name="codeColor">@color/code</item>
<item name="textColor">@android:color/white</item>
<item name="textColorHint">@android:color/darker_gray</item>
</style>
Expand Down

0 comments on commit 5fe04ff

Please sign in to comment.