Skip to content

Commit 66a322c

Browse files
committed
Investigation
1 parent d6e5e21 commit 66a322c

File tree

15 files changed

+15546
-0
lines changed

15 files changed

+15546
-0
lines changed

sample-tests/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'org.jetbrains.kotlin.android'
3+
apply plugin: 'app.cash.paparazzi'
4+
5+
android {
6+
namespace 'app.cash.paparazzi.sample.tests'
7+
8+
compileSdk libs.versions.compileSdk.get() as int
9+
defaultConfig {
10+
minSdk libs.versions.minSdk.get() as int
11+
}
12+
compileOptions {
13+
sourceCompatibility = libs.versions.javaTarget.get()
14+
targetCompatibility = libs.versions.javaTarget.get()
15+
}
16+
}
17+
18+
dependencies {
19+
// Remove if https://github.com/airbnb/lottie-android/pull/2507 lands
20+
implementation libs.androidx.appcompat
21+
}
22+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package app.cash.paparazzi.sample.tests
2+
3+
import android.content.Context
4+
import android.graphics.Color
5+
import android.icu.text.MessageFormat
6+
import android.text.Html
7+
import android.util.TypedValue
8+
import android.view.Gravity
9+
import android.view.View
10+
import android.view.ViewGroup
11+
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
12+
import android.widget.ImageView
13+
import android.widget.LinearLayout
14+
import android.widget.TextView
15+
import androidx.annotation.ColorInt
16+
import androidx.annotation.DrawableRes
17+
18+
class ResourcesDemoView(context: Context) : LinearLayout(context) {
19+
init {
20+
setBackgroundColor(Color.WHITE)
21+
orientation = LinearLayout.VERTICAL
22+
layoutParams = ViewGroup.LayoutParams(
23+
ViewGroup.LayoutParams.MATCH_PARENT,
24+
ViewGroup.LayoutParams.MATCH_PARENT
25+
)
26+
addImageView(R.drawable.camera)
27+
addImageView(R.drawable.ic_android_black_24dp)
28+
addTextView(resources.getBoolean(R.bool.adjust_view_bounds).toString())
29+
addTextView(
30+
text = "Color",
31+
backgroundColor = resources.getColor(R.color.keypadGreen, null)
32+
)
33+
addTextView(resources.getString(R.string.string_escaped_chars))
34+
addTextView("Height: ${resources.getDimension(R.dimen.textview_height)}")
35+
addTextView("Max speed: ${context.resources.getInteger(R.integer.max_speed)}")
36+
addTextView("Plurals:")
37+
plurals.forEach { (label, quantity) ->
38+
addView(
39+
LinearLayout(context).apply {
40+
orientation = LinearLayout.HORIZONTAL
41+
addTextView("$label:", width = WRAP_CONTENT, leftMargin = dip(4f))
42+
addTextView(
43+
context.resources.getQuantityString(R.plurals.plural_name, quantity),
44+
width = WRAP_CONTENT,
45+
weight = 1f,
46+
leftMargin = dip(4f),
47+
rightMargin = dip(4f)
48+
)
49+
}
50+
)
51+
}
52+
addTextView(resources.getString(R.string.string_name))
53+
addTextView(MessageFormat.format(context.resources.getString(R.string.string_name_xliff), 5))
54+
addTextView(
55+
Html.fromHtml(
56+
resources.getString(R.string.string_name_html_escaped),
57+
Html.FROM_HTML_MODE_LEGACY
58+
)
59+
)
60+
addTextView(resources.getText(R.string.string_name_html_unescaped))
61+
addTextView(resources.getStringArray(R.array.string_array_name).joinToString())
62+
}
63+
64+
private fun LinearLayout.addImageView(@DrawableRes drawableRes: Int) {
65+
addView(
66+
ImageView(context).apply {
67+
layoutParams = LinearLayout.LayoutParams(
68+
ViewGroup.LayoutParams.WRAP_CONTENT,
69+
ViewGroup.LayoutParams.WRAP_CONTENT
70+
)
71+
.apply {
72+
gravity = Gravity.CENTER
73+
height = dip(IMAGE_SIZE)
74+
width = dip(IMAGE_SIZE)
75+
}
76+
setImageResource(drawableRes)
77+
}
78+
)
79+
}
80+
81+
private fun LinearLayout.addTextView(
82+
text: CharSequence,
83+
@ColorInt backgroundColor: Int = 0,
84+
width: Int = ViewGroup.LayoutParams.MATCH_PARENT,
85+
height: Int = ViewGroup.LayoutParams.WRAP_CONTENT,
86+
weight: Float = 0f,
87+
leftMargin: Int = 0,
88+
rightMargin: Int = 0
89+
) {
90+
addView(
91+
TextView(context).apply {
92+
layoutParams = LinearLayout.LayoutParams(width, height, weight).apply {
93+
setMargins(leftMargin, 0, rightMargin, 0)
94+
}
95+
this.text = text
96+
setTextColor(Color.BLACK)
97+
setBackgroundColor(backgroundColor)
98+
}
99+
)
100+
}
101+
102+
private fun View.dip(value: Float): Int =
103+
TypedValue.applyDimension(
104+
TypedValue.COMPLEX_UNIT_DIP,
105+
value,
106+
resources.displayMetrics
107+
).toInt()
108+
109+
companion object {
110+
val plurals =
111+
mapOf("Zero" to 0, "One" to 1, "Two" to 2, "Few" to 3, "Many" to 11, "Other" to 100)
112+
const val IMAGE_SIZE = 120f
113+
}
114+
}
15 KB
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#000000"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="#FF000000" android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z"/>
5+
</vector>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical"
7+
android:background="@color/keypadGreen"
8+
android:padding="30dp"
9+
>
10+
11+
<TextView
12+
android:id="@+id/amount"
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
android:text="$5.00"
16+
android:textSize="70dp"
17+
android:gravity="center"
18+
android:textColor="@android:color/white"
19+
android:textFontWeight="100"
20+
android:layout_weight="2"
21+
/>
22+
23+
<TextView
24+
android:id="@+id/amount123"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:text="1 2 3"
28+
android:textSize="45dp"
29+
android:gravity="center"
30+
android:textFontWeight="200"
31+
android:textColor="@android:color/white"
32+
android:layout_weight="1"
33+
/>
34+
<TextView
35+
android:id="@+id/amount456"
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content"
38+
android:text="4 5 6"
39+
android:textFontWeight="400"
40+
41+
android:textSize="45dp"
42+
android:gravity="center"
43+
android:textColor="@android:color/white"
44+
android:layout_weight="1"
45+
/>
46+
<TextView
47+
android:id="@+id/amount789"
48+
android:layout_width="match_parent"
49+
android:layout_height="wrap_content"
50+
android:text="7 8 9"
51+
android:textFontWeight="600"
52+
53+
android:textSize="45dp"
54+
android:gravity="center"
55+
android:textColor="@android:color/white"
56+
android:layout_weight="1"
57+
/>
58+
<TextView
59+
android:id="@+id/amount0"
60+
android:layout_width="match_parent"
61+
android:layout_height="wrap_content"
62+
android:text="# 0     . "
63+
android:textSize="45dp"
64+
android:textFontWeight="800"
65+
66+
android:gravity="center"
67+
android:textColor="@android:color/white"
68+
android:layout_weight="1"
69+
/>
70+
71+
</LinearLayout>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:gravity="center"
5+
android:background="@color/launchBackground"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
>
9+
10+
<ImageView
11+
android:layout_width="200dp"
12+
android:layout_height="200dp"
13+
android:src="@drawable/camera"
14+
/>
15+
16+
<TextView
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:gravity="center"
20+
android:textColor="@color/cameraBody"
21+
android:text="paparazzi"
22+
android:textSize="70dp"
23+
android:textFontWeight="100"
24+
/>
25+
26+
</LinearLayout>

0 commit comments

Comments
 (0)