-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for percentages to ShapeAppearanceModel
PiperOrigin-RevId: 272946740 (cherry picked from commit a130a0c)
- Loading branch information
Showing
11 changed files
with
131 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
lib/java/com/google/android/material/shape/RelativeCornerSize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2019 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. | ||
*/ | ||
|
||
package com.google.android.material.shape; | ||
|
||
import android.graphics.RectF; | ||
import androidx.annotation.NonNull; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* A {@link CornerSize} that takes a percent and computes the size used based on the height of the | ||
* shape. | ||
*/ | ||
public final class RelativeCornerSize implements CornerSize { | ||
|
||
private final float percent; | ||
|
||
public RelativeCornerSize(float percent) { | ||
this.percent = percent; | ||
} | ||
|
||
/** Returns the relative percent used for this {@link CornerSize} */ | ||
public float getRelativePercent() { | ||
return percent; | ||
} | ||
|
||
@Override | ||
public float getCornerSize(@NonNull RectF bounds) { | ||
return percent * bounds.height(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof RelativeCornerSize)) { | ||
return false; | ||
} | ||
RelativeCornerSize that = (RelativeCornerSize) o; | ||
return percent == that.percent; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
Object[] hashedFields = {percent}; | ||
return Arrays.hashCode(hashedFields); | ||
} | ||
} |
Oops, something went wrong.