Merge "Fix code inspection & Format warning" into androidx-master-dev
diff --git a/ui/ui-android-text/src/main/java/androidx/text/TextLayout.kt b/ui/ui-android-text/src/main/java/androidx/text/TextLayout.kt
index f9e5c59..73709d0 100644
--- a/ui/ui-android-text/src/main/java/androidx/text/TextLayout.kt
+++ b/ui/ui-android-text/src/main/java/androidx/text/TextLayout.kt
@@ -86,9 +86,11 @@
val frameworkTextDir = getTextDirectionHeuristic(textDirectionHeuristic)
val boringMetrics = BoringLayoutCompat.isBoring(charSequence, textPaint, frameworkTextDir)
+ // TODO(haoyuchang): we didn't pass the TextDirection to Layout.getDesiredWidth(), check if
+ // there is any behavior difference from
+ // Layout.getWidthWithLimits(charSequence, start, end, paint, dir)
maxIntrinsicWidth = boringMetrics?.width?.toFloat()
- // we may need to getWidthWithLimits(maxWidth: Int, maxLines: Int)
- ?: Layout.getDesiredWidth(charSequence, start, end, textPaint)
+ ?: Layout.getDesiredWidth(charSequence, start, end, textPaint)
val finalWidth = width.toInt()
val ellipsizeWidth = finalWidth
@@ -164,6 +166,12 @@
fun getLineRight(lineIndex: Int): Float = layout.getLineRight(lineIndex)
+ fun getLineTop(line: Int): Float = layout.getLineTop(line).toFloat()
+
+ fun getLineBottom(line: Int): Float = layout.getLineBottom(line).toFloat()
+
+ fun getLineBaseline(line: Int): Float = layout.getLineBaseline(line).toFloat()
+
fun getLineHeight(lineIndex: Int): Float =
(layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex)).toFloat()
@@ -178,10 +186,6 @@
fun getLineForOffset(offset: Int): Int = layout.getLineForOffset(offset)
- fun getLineTop(line: Int): Float = layout.getLineTop(line).toFloat()
-
- fun getLineBottom(line: Int): Float = layout.getLineBottom(line).toFloat()
-
fun getSelectionPath(start: Int, end: Int, dest: Path) =
layout.getSelectionPath(start, end, dest)
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt b/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
index 4d0fd2a..00fed53 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
@@ -17,7 +17,6 @@
import android.annotation.SuppressLint
import androidx.compose.Ambient
-import androidx.compose.Children
import androidx.compose.Composable
import androidx.compose.ambient
import androidx.compose.composer
@@ -40,6 +39,7 @@
import androidx.ui.text.TextPainter
import androidx.ui.text.TextSpan
import androidx.ui.text.TextStyle
+import androidx.ui.text.style.TextAlign
import androidx.ui.text.toAnnotatedString
import androidx.ui.text.style.TextOverflow
@@ -76,7 +76,7 @@
* Whether the text should break at soft line breaks.
* If false, the glyphs in the text will be positioned as if there was unlimited horizontal
* space.
- * If [softWrap] is false, [overflow] and [textAlign] may have unexpected effects.
+ * If [softWrap] is false, [overflow] and [TextAlign] may have unexpected effects.
*/
softWrap: Boolean = DefaultSoftWrap,
/** How visual overflow should be handled. */
@@ -169,7 +169,7 @@
* Whether the text should break at soft line breaks.
* If false, the glyphs in the text will be positioned as if there was unlimited horizontal
* space.
- * If [softWrap] is false, [overflow] and [textAlign] may have unexpected effects.
+ * If [softWrap] is false, [overflow] and [TextAlign] may have unexpected effects.
*/
softWrap: Boolean = DefaultSoftWrap,
/** How visual overflow should be handled. */
@@ -227,7 +227,8 @@
Draw { canvas, _ ->
internalSelection.value?.let {
textPainter.paintBackground(
- it.start, it.end, selectionColor, canvas)
+ it.start, it.end, selectionColor, canvas
+ )
}
textPainter.paint(canvas)
}
@@ -287,7 +288,8 @@
)
if (!textSelectionProcessor.isSelected) return null
- // TODO(qqd): Determine a set of coordinates around a character that we need.
+ // TODO(qqd): Determine a set of coordinates around a character that we
+ // need.
return Selection(
startCoordinates = textSelectionProcessor.startCoordinates,
endCoordinates = textSelectionProcessor.endCoordinates,
diff --git a/ui/ui-text/integration-tests/text-demos/src/main/java/androidx/ui/text/demos/CraneText.kt b/ui/ui-text/integration-tests/text-demos/src/main/java/androidx/ui/text/demos/CraneText.kt
index a0e9bda..a4f8e25 100644
--- a/ui/ui-text/integration-tests/text-demos/src/main/java/androidx/ui/text/demos/CraneText.kt
+++ b/ui/ui-text/integration-tests/text-demos/src/main/java/androidx/ui/text/demos/CraneText.kt
@@ -280,10 +280,12 @@
// This group of text widgets show different letterSpacing.
Text {
Span(text = "$displayText ", style = TextStyle(fontSize = fontSize8))
- Span(text = displayText, style = TextStyle(
- fontSize = fontSize8,
- letterSpacing = 0.5f
- )
+ Span(
+ text = displayText,
+ style = TextStyle(
+ fontSize = fontSize8,
+ letterSpacing = 0.5f
+ )
)
}
}
@@ -292,7 +294,6 @@
fun TextDemoBaselineShift() {
Text {
Span(text = displayText, style = TextStyle(fontSize = fontSize8)) {
-
Span(
text = "superscript",
style = TextStyle(
@@ -402,7 +403,7 @@
fun TextDemoTextAlign() {
// This group of text widgets show different TextAligns: LEFT, RIGHT, CENTER, JUSTIFY, START for
// LTR and RTL, END for LTR and RTL.
- var text: String = ""
+ var text = ""
for (i in 1..10) {
text = "$text$displayText "
}
@@ -470,7 +471,7 @@
@Composable
fun TextDemoSoftWrap() {
// This group of text widgets show difference between softWrap is true and false.
- var text: String = ""
+ var text = ""
for (i in 1..10) {
text = "$text$displayText"
}
@@ -493,7 +494,7 @@
fun TexDemoTextOverflowFade() {
var text = ""
for (i in 1..15) {
- text = text + displayText
+ text += displayText
}
val textSytle =
TextStyle(fontSize = fontSize8, color = Color(0xFFFF0000.toInt()))
@@ -602,7 +603,7 @@
Color(0xFF0000FF.toInt()),
Color(0xFF00FF00.toInt()),
Color(0xFFFF0000.toInt())
- )
+ )
val selection = +state<Selection?> { null }
SelectionContainer(
@@ -651,7 +652,8 @@
SelectionContainer(
selection = selection.value,
onSelectionChange = { selection.value = it },
- mode = SelectionMode.Horizontal) {
+ mode = SelectionMode.Horizontal
+ ) {
Column {
for (i in 0..2) {
Row {
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/AnnotatedString.kt b/ui/ui-text/src/main/java/androidx/ui/text/AnnotatedString.kt
index 28140c5..7c4dff1 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/AnnotatedString.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/AnnotatedString.kt
@@ -38,6 +38,7 @@
lastStyleEnd = paragraphStyle.end
}
}
+
/**
* The information attached on the text such as a TextStyle.
*
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/Locale.kt b/ui/ui-text/src/main/java/androidx/ui/text/Locale.kt
index 826956c..2c75c98 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/Locale.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/Locale.kt
@@ -28,27 +28,21 @@
* both have the [languageCode] `he`, because `iw` is a deprecated language
* subtag that was replaced by the subtag `he`.
*
- * See also:
- *
- * * [Window.locale], which specifies the system's currently selected
- * [Locale].
- *
* The default constructor creates a new Locale object. The first argument is the
* primary language subtag, the second is the region subtag.
*
* For example:
*
- * ```dart
- * const Locale swissFrench = const Locale('fr', 'CH');
- * const Locale canadianFrench = const Locale('fr', 'CA');
- * ```
+ * val swissFrench = Locale('fr', 'CH');
+ * val canadianFrench = Locale('fr', 'CA');
+ *
*
* The primary language subtag must not be null. The region subtag is
* optional.
*
* The values are _case sensitive_, and should match the case of the relevant
- * subtags in the [IANA Language Subtag
- * Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry).
+ * subtags in the [IANA Language Subtag Registry]
+ * (https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry).
* Typically this means the primary language subtag should be lowercase and
* the region subtag should be uppercase.
*/
@@ -210,32 +204,4 @@
}
}
}
-
- // Made this a data class, so the following are probably no longer required.
- // Leaving them commented out though.
-// override fun equals(other: Any?): Boolean {
-// if (this === other) {
-// return true
-// }
-// if (other !is Locale) {
-// return false
-// }
-// return languageCode == other.languageCode && countryCode == other.countryCode
-// }
-//
-// override fun hashCode(): Int {
-// var result = 373
-// result = 37 * result + languageCode.hashCode()
-// if (_countryCode != null) {
-// result = 37 * result + countryCode!!.hashCode()
-// }
-// return result
-// }
-//
-// override fun toString(): String {
-// if (_countryCode == null) {
-// return languageCode
-// }
-// return "${languageCode}_$countryCode"
-// }
}
\ No newline at end of file
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraph.kt b/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraph.kt
index 830a776..e7923f0 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraph.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/MultiParagraph.kt
@@ -245,8 +245,7 @@
val paragraphIndex = findParagraphByIndex(paragraphInfoList, offset)
return with(paragraphInfoList[paragraphIndex]) {
- val localOffset = offset.toLocalIndex()
- paragraph.getBoundingBox(localOffset).toGlobal()
+ paragraph.getBoundingBox(offset.toLocalIndex()).toGlobal()
}
}
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/ParagraphConstraints.kt b/ui/ui-text/src/main/java/androidx/ui/text/ParagraphConstraints.kt
index fde3f64..0de2f0d 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/ParagraphConstraints.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/ParagraphConstraints.kt
@@ -38,12 +38,11 @@
* forced line break is placed after it (even if an explicit line break
* follows).
*
- * The width influences how ellipses are applied. See the discussion at [new
- * ParagraphStyle] for more details.
+ * The width influences how ellipses are applied. See the discussion at
+ * [TextPainter] for more details.
*
- * This width is also used to position glyphs according to the [TextAlign]
- * alignment described in the [ParagraphStyle] used when building the
- * [Paragraph] with a [ParagraphBuilder].
+ * This width is also used to position glyphs according to the text alignment
+ * described in the [ParagraphStyle.textAlign] to create [Paragraph].
*/
data class ParagraphConstraints(val width: Float) {
override fun toString(): String {
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/RenderComparison.kt b/ui/ui-text/src/main/java/androidx/ui/text/RenderComparison.kt
index 939a7b7..69a24fa 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/RenderComparison.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/RenderComparison.kt
@@ -21,10 +21,6 @@
* it will affect the rendering.
*
* Used by [TextSpan.compareTo] and [TextStyle.compareTo].
- *
- * The values in this enum are ordered such that they are in increasing order
- * of cost. A value with index N implies all the values with index less than N.
- * For example, [layout] (index 3) implies [paint] (2).
*/
// TODO(siyamed) remove this class if not required
internal enum class RenderComparison {
@@ -45,9 +41,6 @@
* The two objects are different but only in ways that affect paint, not layout.
*
* For example, only the color is changed.
- *
- * [RenderObject.markNeedsPaint] would be necessary to handle this kind of
- * change in a render object.
*/
PAINT,
@@ -57,9 +50,6 @@
* For example, the size is changed.
*
* This is the most drastic level of change possible.
- *
- * [RenderObject.markNeedsLayout] would be necessary to handle this kind of
- * change in a render object.
*/
LAYOUT
}
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/TextBox.kt b/ui/ui-text/src/main/java/androidx/ui/text/TextBox.kt
index 334458d..83a427b 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/TextBox.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/TextBox.kt
@@ -49,7 +49,8 @@
}
/**
- * The [left] edge of the box for left-to-right text; the [right] edge of the box for right-to-left text.
+ * The [left] edge of the box for left-to-right text; the [right] edge of the box for
+ * right-to-left text.
* See also:
* * [direction], which specifies the text direction.
*/
@@ -58,7 +59,8 @@
}
/**
- * The [right] edge of the box for left-to-right text; the [left] edge of the box for right-to-left text.
+ * The [right] edge of the box for left-to-right text; the [left] edge of the box for
+ * right-to-left text.
* See also:
* * [direction], which specifies the text direction.
*/
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/TextPainter.kt b/ui/ui-text/src/main/java/androidx/ui/text/TextPainter.kt
index 0a5d93a..c9f865d 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/TextPainter.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/TextPainter.kt
@@ -273,8 +273,8 @@
* If [maxLines] is not null, this is true if there were more lines to be drawn than the given
* [maxLines], and thus at least one line was omitted in the output; otherwise it is false.
*
- * If [maxLines] is null, this is true if [ellipsis] is true and there was a line that
- * overflowed the `maxWidth` argument passed to [layout]; otherwise it is false.
+ * If [maxLines] is null, this is true if [overflow] is [TextOverflow.Ellipsis] and there was a
+ * line that overflowed the `maxWidth` argument passed to [layout]; otherwise it is false.
*
* Valid only after [layout] has been called.
*/
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/TextSpan.kt b/ui/ui-text/src/main/java/androidx/ui/text/TextSpan.kt
index b399a56..baa9d8a 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/TextSpan.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/TextSpan.kt
@@ -66,8 +66,7 @@
*/
fun toPlainText(): String {
val buffer = StringBuilder()
- visitTextSpan {
- span: TextSpan ->
+ visitTextSpan { span: TextSpan ->
buffer.append(span.text)
true
}
@@ -84,7 +83,8 @@
}
if (other.text != text ||
children.size != other.children.size ||
- (style == null) != (other.style == null)) {
+ (style == null) != (other.style == null)
+ ) {
return RenderComparison.LAYOUT
}
var result: RenderComparison = RenderComparison.IDENTICAL
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/TextStyle.kt b/ui/ui-text/src/main/java/androidx/ui/text/TextStyle.kt
index 91bcf86..b500187 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/TextStyle.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/TextStyle.kt
@@ -45,10 +45,9 @@
* style cannot be found in the provided custom font family.
* @param fontFamily font family to be used when rendering the text.
* @param fontFeatureSettings The advanced typography settings provided by font. The format is the
- * same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop
+ * same as the CSS font-feature-settings attribute:
+ * https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop
* @param letterSpacing The amount of space (in logical pixels) to add between each letter.
- * @param wordSpacing The amount of space (in logical pixels) to add at each sequence of white-space
- * (i.e. between each word). Only works on Android Q and above.
* @param baselineShift This parameter specifies how much the baseline is shifted from the current
* position.
* @param textGeometricTransform The geometric transformation applied the text.
@@ -136,16 +135,12 @@
*
* This will not work well if the styles don't set the same fields.
*
- * The `t` argument represents position on the timeline, with 0.0 meaning that the interpolation
- * has not started, returning `a` (or something equivalent to `a`), 1.0 meaning that the
- * interpolation has finished, returning `b` (or something equivalent to `b`), and values in
- * between meaning that the interpolation is at the relevant point on the timeline between `a`
- * and `b`. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and
- * values greater than 1.0 are valid (and can easily be generated by curves such as
- * [Curves.elasticInOut]).
- *
- * Values for `t` are usually obtained from an [Animation<Float>], such as an
- * [AnimationController].
+ * The `t` argument represents position on the timeline, with 0.0 meaning that the
+ * interpolation has not started, returning `a` (or something equivalent to `a`), 1.0
+ * meaning that the interpolation has finished, returning `b` (or something equivalent to
+ * `b`), and values in between meaning that the interpolation is at the relevant point on
+ * the timeline between `a` and `b`. The interpolation can be extrapolated beyond 0.0 and
+ * 1.0, so negative values and values greater than 1.0 are valid.
*/
fun lerp(a: TextStyle? = null, b: TextStyle? = null, t: Float): TextStyle? {
val aIsNull = a == null
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraph.kt b/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraph.kt
index 054eb01..ce4624b0 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraph.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/platform/AndroidParagraph.kt
@@ -118,13 +118,13 @@
get() = 0.0f
override val maxIntrinsicWidth: Float
- get() = layout?.let { it.maxIntrinsicWidth } ?: 0.0f
+ get() = layout?.maxIntrinsicWidth ?: 0.0f
override val baseline: Float
- get() = layout?.let { it.layout.getLineBaseline(0).toFloat() } ?: 0.0f
+ get() = layout?.getLineBaseline(0) ?: 0.0f
override val didExceedMaxLines: Boolean
- get() = layout?.let { it.didExceedMaxLines } ?: false
+ get() = layout?.didExceedMaxLines ?: false
@VisibleForTesting
internal val textLocale: Locale
@@ -135,10 +135,9 @@
private val ensureLayout: TextLayout
get() {
- val tmpLayout = this.layout ?: throw java.lang.IllegalStateException(
+ return this.layout ?: throw java.lang.IllegalStateException(
"layout() should be called first"
)
- return tmpLayout
}
@VisibleForTesting
@@ -156,7 +155,7 @@
text = text,
textIndent = paragraphStyle.textIndent,
textStyles = listOf(
- AnnotatedString.Item<TextStyle>(
+ AnnotatedString.Item(
newStyle,
0,
text.length
@@ -225,7 +224,7 @@
}
override fun getPathForRange(start: Int, end: Int): Path {
- if (!(start <= end && start >= 0 && end <= text.length)) {
+ if (start !in 0..end || end > text.length) {
throw AssertionError(
"Start($start) or End($end) is out of Range(0..${text.length}), or start > end!"
)
@@ -236,7 +235,7 @@
}
override fun getCursorRect(offset: Int): Rect {
- if (!(offset in (0..text.length))) {
+ if (offset !in 0..text.length) {
throw AssertionError("offset($offset) is out of bounds (0,${text.length}")
}
// TODO(nona): Support cursor drawable.
@@ -481,7 +480,7 @@
// fontSizeScale must be applied after fontSize is applied.
fontSizeScale?.let {
- textPaint.textSize *= fontSizeScale
+ textPaint.textSize *= it
}
// TODO(siyamed): This default values are problem here. If the user just gives a single font
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/platform/TypefaceAdapter.kt b/ui/ui-text/src/main/java/androidx/ui/text/platform/TypefaceAdapter.kt
index 395f4c7..b7d89d2 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/platform/TypefaceAdapter.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/platform/TypefaceAdapter.kt
@@ -49,8 +49,8 @@
)
companion object {
- // Accept FontWeights at and above 600 to be bold. 600 comes from FontFamily.cpp#computeFakery
- // function in minikin
+ // Accept FontWeights at and above 600 to be bold. 600 comes from
+ // FontFamily.cpp#computeFakery function in minikin
private val ANDROID_BOLD = FontWeight.w600
// 16 is a random number and is not based on any strong logic
@@ -205,7 +205,8 @@
return if (Build.VERSION.SDK_INT < 28) {
val targetStyle = getTypefaceStyle(
isBold = synthesizeWeight,
- isItalic = synthesizeStyle && fontStyle == FontStyle.Italic)
+ isItalic = synthesizeStyle && fontStyle == FontStyle.Italic
+ )
Typeface.create(typeface, targetStyle)
} else {
val finalFontWeight = if (synthesizeWeight) {