-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix insets, insets-extensions, and insets-helper after targeting SDK 29
- Loading branch information
1 parent
111a2c6
commit 3ba7db3
Showing
7 changed files
with
109 additions
and
74 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
50 changes: 50 additions & 0 deletions
50
insets-helper/src/main/java/net/xpece/androidx/optical/OpticalInsetsHelper.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,50 @@ | ||
package net.xpece.androidx.optical; | ||
|
||
import android.annotation.TargetApi; | ||
import android.graphics.Insets; | ||
import android.graphics.drawable.Drawable; | ||
import android.view.View; | ||
|
||
import androidx.annotation.RequiresApi; | ||
|
||
/** | ||
* Helper class for making views aware of optical insets | ||
* on {@link android.graphics.drawable.InsetDrawable InsetDrawable} below API 21, | ||
* and {@link android.graphics.drawable.LayerDrawable LayerDrawable} (including children | ||
* such as {@link android.graphics.drawable.RippleDrawable RippleDrawable}) on all API levels. | ||
*/ | ||
@RequiresApi(16) | ||
public final class OpticalInsetsHelper { | ||
|
||
private final View view; | ||
|
||
private Insets opticalInsets = null; | ||
|
||
public OpticalInsetsHelper(final View view) { | ||
this.view = view; | ||
} | ||
|
||
/** | ||
* Return this from {@code View#getOpticalInsets()}. | ||
*/ | ||
@TargetApi(29) | ||
public Insets onGetOpticalInsets() { | ||
if (opticalInsets == null) { | ||
// Same as platform, we don't support changing insets once resolved. | ||
final Drawable background = view.getBackground(); | ||
opticalInsets = background != null ? background.getOpticalInsets() : InsetsCompat.NONE; | ||
// If background.getOpticalInsets() returns null this will blow up. | ||
} | ||
return opticalInsets; | ||
} | ||
|
||
/** | ||
* Call this from {@code View#setOpticalInsets(Insets)}. | ||
*/ | ||
public void onSetOpticalInsets(final Insets insets) { | ||
if (opticalInsets != insets) { | ||
opticalInsets = insets; | ||
view.requestLayout(); | ||
} | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
insets-helper/src/main/java/net/xpece/androidx/optical/OpticalInsetsHelper.kt
This file was deleted.
Oops, something went wrong.
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