This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
291 additions
and
43 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
120 changes: 120 additions & 0 deletions
120
Xamarin.Forms.ControlGallery.Android/DrawableExtensions.cs
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,120 @@ | ||
using System; | ||
using ADrawable = Android.Graphics.Drawables.Drawable; | ||
using AColorFilter = Android.Graphics.ColorFilter; | ||
using AColor = Android.Graphics.Color; | ||
using ADrawableCompat = Android.Support.V4.Graphics.Drawable.DrawableCompat; | ||
using Android.Graphics; | ||
|
||
namespace Xamarin.Forms.Platform.Android | ||
{ | ||
enum FilterMode | ||
{ | ||
SrcIn, | ||
Multiply, | ||
SrcAtop | ||
} | ||
|
||
internal static class DrawableExtensions | ||
{ | ||
|
||
#if __ANDROID_29__ | ||
public static BlendMode GetFilterMode(FilterMode mode) | ||
{ | ||
switch (mode) | ||
{ | ||
case FilterMode.SrcIn: | ||
return BlendMode.SrcIn; | ||
case FilterMode.Multiply: | ||
return BlendMode.Multiply; | ||
case FilterMode.SrcAtop: | ||
return BlendMode.SrcAtop; | ||
} | ||
|
||
throw new Exception("Invalid Mode"); | ||
} | ||
|
||
#else | ||
[Obsolete] | ||
static PorterDuff.Mode GetFilterMode(FilterMode mode) | ||
{ | ||
return GetFilterModePre29(mode); | ||
} | ||
#endif | ||
|
||
[Obsolete] | ||
static PorterDuff.Mode GetFilterModePre29(FilterMode mode) | ||
{ | ||
switch (mode) | ||
{ | ||
case FilterMode.SrcIn: | ||
return PorterDuff.Mode.SrcIn; | ||
case FilterMode.Multiply: | ||
return PorterDuff.Mode.Multiply; | ||
case FilterMode.SrcAtop: | ||
return PorterDuff.Mode.SrcAtop; | ||
} | ||
|
||
throw new Exception("Invalid Mode"); | ||
} | ||
|
||
public static AColorFilter GetColorFilter(this ADrawable drawable) | ||
{ | ||
if (drawable == null) | ||
return null; | ||
|
||
return ADrawableCompat.GetColorFilter(drawable); | ||
} | ||
|
||
public static void SetColorFilter(this ADrawable drawable, AColorFilter colorFilter) | ||
{ | ||
if (drawable == null) | ||
return; | ||
|
||
if (colorFilter == null) | ||
ADrawableCompat.ClearColorFilter(drawable); | ||
|
||
drawable.SetColorFilter(colorFilter); | ||
} | ||
|
||
|
||
public static void SetColorFilter(this ADrawable drawable, Color color, AColorFilter defaultColorFilter, FilterMode mode) | ||
{ | ||
if (drawable == null) | ||
return; | ||
|
||
if (color == Color.Default) | ||
{ | ||
SetColorFilter(drawable, defaultColorFilter); | ||
return; | ||
} | ||
|
||
drawable.SetColorFilter(color.ToAndroid(), mode); | ||
} | ||
|
||
public static void SetColorFilter(this ADrawable drawable, Color color, FilterMode mode) | ||
{ | ||
drawable.SetColorFilter(color.ToAndroid(), mode); | ||
} | ||
|
||
public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode) | ||
{ | ||
#if __ANDROID_29__ | ||
if((int)global::Android.OS.Build.VERSION.SdkInt >= 29) | ||
drawable.SetColorFilter(new BlendModeColorFilter(color, GetFilterMode(mode))); | ||
else | ||
#pragma warning disable CS0612 // Type or member is obsolete | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
drawable.SetColorFilter(color, GetFilterModePre29(mode)); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
#pragma warning restore CS0612 // Type or member is obsolete | ||
#else | ||
#pragma warning disable CS0612 // Type or member is obsolete | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
drawable.SetColorFilter(color, GetFilterMode(mode)); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
#pragma warning restore CS0612 // Type or member is obsolete | ||
#endif | ||
} | ||
|
||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
Xamarin.Forms.ControlGallery.Android/Properties/AndroidManifest.xml
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
23 changes: 23 additions & 0 deletions
23
Xamarin.Forms.ControlGallery.Android/Properties/AndroidManifest28.xml
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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="AndroidControlGallery.AndroidControlGallery" android:installLocation="auto"> | ||
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="28" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> | ||
<!-- The following two permissions are not required to use | ||
Google Maps Android API v2, but are recommended. --> | ||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.BATTERY_STATS" /> | ||
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||
<uses-permission android:name="android.permission.READ_LOGS" /> | ||
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" /> | ||
<uses-feature android:glEsVersion="0x00020000" android:required="true" /> | ||
<application android:label="AndroidControlGallery" android:supportsRtl="true"> | ||
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> | ||
<uses-library android:name="org.apache.http.legacy" android:required="false" /> | ||
</application> | ||
</manifest> |
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
Oops, something went wrong.