Skip to content

Commit

Permalink
[ShapeableImageView] Support contentPadding
Browse files Browse the repository at this point in the history
Resolves #1871

GIT_ORIGIN_REV_ID=42b91686512ed77d38f5a70a26cc52157ff4184b
Co-authored-by: ymarian <38727469+ymarian@users.noreply.github.com>
PiperOrigin-RevId: 342906676
  • Loading branch information
drewhamilton authored and wcshi committed Nov 17, 2020
1 parent a99966a commit c4f7de1
Show file tree
Hide file tree
Showing 6 changed files with 490 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public View onCreateDemoView(
layoutInflater.inflate(R.layout.catalog_imageview, viewGroup, false /* attachToRoot */);
MaterialButtonToggleGroup toggleGroup = view.findViewById(R.id.togglegroup);
ShapeableImageView imageView = view.findViewById(R.id.image_view);
ShapeableImageView iconView = view.findViewById(R.id.icon_view);

SparseArray<ShapeAppearanceModel> shapes = new SparseArray<>();
shapes.put(
Expand All @@ -66,10 +67,14 @@ public View onCreateDemoView(
return;
}

ShapeAppearanceModel shape = shapes.get(checkedId);

// Randomly makes dog wink.
imageView.setImageResource(
random.nextBoolean() ? R.drawable.dog_image : R.drawable.dog_image_wink);
imageView.setShapeAppearanceModel(shapes.get(checkedId));
imageView.setShapeAppearanceModel(shape);

iconView.setShapeAppearanceModel(shape);
});

return view;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2020 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal"
tools:ignore="newApi">
<path
android:fillColor="@android:color/white"
android:pathData="M4.5,9.5m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"/>
<path
android:fillColor="@android:color/white"
android:pathData="M9,5.5m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"/>
<path
android:fillColor="@android:color/white"
android:pathData="M15,5.5m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"/>
<path
android:fillColor="@android:color/white"
android:pathData="M19.5,9.5m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"/>
<path
android:fillColor="@android:color/white"
android:pathData="M17.34,14.86c-0.87,-1.02 -1.6,-1.89 -2.48,-2.91 -0.46,-0.54 -1.05,-1.08 -1.75,-1.32 -0.11,-0.04 -0.22,-0.07 -0.33,-0.09 -0.25,-0.04 -0.52,-0.04 -0.78,-0.04s-0.53,0 -0.79,0.05c-0.11,0.02 -0.22,0.05 -0.33,0.09 -0.7,0.24 -1.28,0.78 -1.75,1.32 -0.87,1.02 -1.6,1.89 -2.48,2.91 -1.31,1.31 -2.92,2.76 -2.62,4.79 0.29,1.02 1.02,2.03 2.33,2.32 0.73,0.15 3.06,-0.44 5.54,-0.44h0.18c2.48,0 4.81,0.58 5.54,0.44 1.31,-0.29 2.04,-1.31 2.33,-2.32 0.31,-2.04 -1.3,-3.49 -2.61,-4.8z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -15,96 +15,116 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_viewGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/cat_imageview_padding"
android:orientation="vertical">
android:layout_height="match_parent">

<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/togglegroup"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/main_viewGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:checkedButton="@id/button_square"
app:selectionRequired="true"
app:singleSelection="true">
<Button
android:id="@+id/button_square"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_imageview_square" />
android:padding="@dimen/cat_imageview_padding"
android:orientation="vertical">

<Button
android:id="@+id/button_diamond"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_imageview_diamond" />
<Button
android:id="@+id/button_circle"
style="?attr/materialButtonOutlinedStyle"
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/togglegroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_imageview_circle" />
android:layout_gravity="center"
app:checkedButton="@id/button_square"
app:selectionRequired="true"
app:singleSelection="true">
<Button
android:id="@+id/button_square"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_imageview_square" />

</com.google.android.material.button.MaterialButtonToggleGroup>

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image_view"
android:layout_margin="10dp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
app:strokeColor="?attr/colorSecondary"
app:shapeAppearance="?attr/shapeAppearanceMediumComponent"
app:strokeWidth="1dp"
android:elevation="5dp"
android:padding="8dp"
app:srcCompat="@drawable/dog_image" />
<Button
android:id="@+id/button_diamond"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_imageview_diamond" />
<Button
android:id="@+id/button_circle"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_imageview_circle" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layoutDirection="ltr"
android:orientation="horizontal"
tools:ignore="UnusedAttribute">
</com.google.android.material.button.MaterialButtonToggleGroup>

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image_view_jpeg"
android:layout_width="wrap_content"
android:id="@+id/image_view"
android:layout_margin="10dp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:elevation="5dp"
app:shapeAppearance="@style/ShapeAppearanceImageLeft"
app:srcCompat="@drawable/cat_image"
android:adjustViewBounds="true"
app:strokeColor="?attr/colorSecondary"
app:strokeWidth="1dp" />
app:shapeAppearance="?attr/shapeAppearanceMediumComponent"
app:strokeWidth="1dp"
android:elevation="5dp"
android:padding="8dp"
app:srcCompat="@drawable/dog_image" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layoutDirection="ltr"
android:orientation="horizontal"
tools:ignore="UnusedAttribute">

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image_view_jpeg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:elevation="5dp"
app:shapeAppearance="@style/ShapeAppearanceImageLeft"
app:srcCompat="@drawable/cat_image"
app:strokeColor="?attr/colorSecondary"
app:strokeWidth="1dp" />

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image_view_gif"
tools:ignore="InefficientWeight"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:elevation="5dp"
app:shapeAppearance="@style/ShapeAppearanceImageRight"
app:srcCompat="@drawable/cateyes_image"
app:strokeColor="?attr/colorSecondary"
app:strokeWidth="1dp" />

</LinearLayout>

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image_view_gif"
tools:ignore="InefficientWeight"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:elevation="5dp"
app:shapeAppearance="@style/ShapeAppearanceImageRight"
app:srcCompat="@drawable/cateyes_image"
app:strokeColor="?attr/colorSecondary"
app:strokeWidth="1dp" />
android:id="@+id/icon_view"
android:layout_margin="10dp"
android:layout_gravity="center"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="?colorSecondary"
android:elevation="2dp"
app:contentPadding="8dp"
app:shapeAppearance="?shapeAppearanceSmallComponent"
app:srcCompat="@drawable/ic_pets_24dp"
app:tint="?colorOnSecondary"
tools:ignore="UnusedAttribute" />

</LinearLayout>

</LinearLayout>
</ScrollView>
Loading

0 comments on commit c4f7de1

Please sign in to comment.