Skip to content

Commit 8ffec48

Browse files
author
Nick Rout
committed
Add ShapeableImageView to component list
1 parent 01c455b commit 8ffec48

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

MaterialThemeBuilder/app/src/main/java/io/material/materialthemebuilder/ui/component/Component.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ enum class Component {
3838
TABS,
3939
SNACKBAR,
4040
DIALOG,
41-
BOTTOM_SHEET
41+
BOTTOM_SHEET,
42+
IMAGE
4243
}

MaterialThemeBuilder/app/src/main/java/io/material/materialthemebuilder/ui/component/ComponentViewHolder.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import io.material.materialthemebuilder.ui.component.Component.TABS
4848
import io.material.materialthemebuilder.ui.component.Component.SNACKBAR
4949
import io.material.materialthemebuilder.ui.component.Component.DIALOG
5050
import io.material.materialthemebuilder.ui.component.Component.BOTTOM_SHEET
51+
import io.material.materialthemebuilder.ui.component.Component.IMAGE
5152

5253
/**
5354
* Sealed class to define all [RecyclerView.ViewHolder]s used to display [Component]s.
@@ -179,6 +180,10 @@ sealed class ComponentViewHolder(val view: View) : RecyclerView.ViewHolder(view)
179180
}
180181
}
181182

183+
class ImageComponentViewHolder(
184+
parent: ViewGroup
185+
) : ComponentViewHolder(inflate(parent, R.layout.component_image))
186+
182187
companion object {
183188
fun create(
184189
parent: ViewGroup,
@@ -202,6 +207,7 @@ sealed class ComponentViewHolder(val view: View) : RecyclerView.ViewHolder(view)
202207
SNACKBAR -> SnackbarComponentViewHolder(parent)
203208
DIALOG -> DialogComponentViewHolder(parent)
204209
BOTTOM_SHEET -> BottomSheetComponentViewHolder(parent, listener)
210+
IMAGE -> ImageComponentViewHolder(parent)
205211
}
206212
}
207213

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2019 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
xmlns:tools="http://schemas.android.com/tools"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
android:clipToPadding="false"
24+
android:paddingTop="@dimen/keyline_5"
25+
android:paddingBottom="@dimen/keyline_5"
26+
android:paddingStart="@dimen/keyline_4"
27+
android:paddingEnd="@dimen/keyline_4">
28+
29+
<io.material.materialthemebuilder.widget.LabelLinkView
30+
android:id="@+id/label"
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content"
33+
android:text="@string/image_label_title"
34+
app:linkUrl="https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/imageview/ShapeableImageView.java"
35+
app:layout_constraintStart_toStartOf="parent"
36+
app:layout_constraintTop_toTopOf="parent" />
37+
38+
<com.google.android.material.imageview.ShapeableImageView
39+
android:layout_width="match_parent"
40+
android:layout_height="192dp"
41+
android:scaleType="centerCrop"
42+
app:srcCompat="@drawable/sample_image"
43+
app:shapeAppearance="?attr/shapeAppearanceMediumComponent"
44+
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.MyTheme.Image"
45+
app:strokeColor="?attr/colorPrimary"
46+
app:strokeWidth="2dp"
47+
android:layout_marginTop="@dimen/component_label_horizontal_margin"
48+
app:layout_constraintStart_toStartOf="parent"
49+
app:layout_constraintTop_toBottomOf="@+id/label"
50+
tools:ignore="ContentDescription" />
51+
52+
</androidx.constraintlayout.widget.ConstraintLayout>

MaterialThemeBuilder/app/src/main/res/values/shape.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,10 @@
4848
<!--Your custom shape here-->
4949
</style>
5050

51+
<!--Shape Appearance overlay for ShapeableImageView -->
52+
<style name="ShapeAppearanceOverlay.MyTheme.Image" parent="">
53+
<item name="cornerSize">0dp</item>
54+
<item name="cornerSizeTopLeft">50%</item>
55+
</style>
56+
5157
</resources>

MaterialThemeBuilder/app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<resources>
1818
<string name="app_name">Build a Material Theme</string>
19-
<string name="theme_name_hint">Theme name...</string>
19+
<string name="theme_name_hint">Theme name</string>
2020

2121
<string name="lorem_ipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</string>
2222

@@ -88,6 +88,7 @@
8888
<string name="bottom_sheet_label_title">Bottom sheet</string>
8989
<string name="bottom_sheet_button_label">Show bottom sheet</string>
9090

91+
<string name="image_label_title">Image</string>
9192

9293
<!--Theme Summary-->
9394
<string name="label_color_scheme_title">Color scheme</string>

0 commit comments

Comments
 (0)