public static int GetColor(Context context, int color) { var tv = new Android.Util.TypedValue(); context.Theme.ResolveAttribute(color, tv, true); return(tv.Data); }
InputStreamInvoker GetResourceStream(int resId, Android.Util.TypedValue outValue) { Application.Context.Resources.GetValue(resId, outValue, true); IntPtr sp = OpenNonAsset(Application.Context.Resources.Assets, outValue.AssetCookie, outValue.String.ToString(), 2 /* AssetManager.ACCESS_STREAMING */); Java.IO.InputStream s = Java.Lang.Object.GetObject <Java.IO.InputStream> (sp, JniHandleOwnership.TransferLocalRef); return(new InputStreamInvoker(s)); }
public void DrawableFromResStream_ShouldBeTypeNinePatchDrawable(int resId, string name) { var value = new Android.Util.TypedValue(); InputStreamInvoker si = GetResourceStream(resId, value); var d = Drawable.CreateFromResourceStream(Application.Context.Resources, value, si, value.String.ToString(), null); Assert.IsNotNull(d, $"An image should have been retrieved from resource `{name}`."); Assert.IsNotNull(d as NinePatchDrawable, $"The drawable created from resource `{name}` should be a NinePatchDrawable."); }
public void BitmapFromDecodeResStream_ShouldContainNinePatchChunk(int resId, string name) { var value = new Android.Util.TypedValue(); InputStreamInvoker si = GetResourceStream(resId, value); Bitmap bm = BitmapFactory.DecodeResourceStream(Application.Context.Resources, value, si, null, null); byte[] chunk = bm.GetNinePatchChunk(); Assert.IsTrue(NinePatch.IsNinePatchChunk(chunk), $"Bitmap decoded from resource stream with id `{name}` did not contain a valid NinePatch chunk."); }
public static int GetSelectableItemBackground(Context context) { if (selectableItemBackground == 0) { var outValue = new Android.Util.TypedValue(); context.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, outValue, true); selectableItemBackground = outValue.ResourceId; } return(selectableItemBackground); }
public static bool TryResolveAttribute(this Resources.Theme?theme, int id, out float?value) { using (var tv = new Android.Util.TypedValue()) { if (theme != null && theme.ResolveAttribute(id, tv, resolveRefs: true)) { value = tv.Data; return(true); } } value = null; return(false); }
//TODO RM: Ensure this works with pre 5.0 like 4.4 public static Android.Util.TypedValue GetTypedValueFromActv(ContextThemeWrapper activity) { Android.Util.TypedValue typedValue = new Android.Util.TypedValue(); try { return(activity.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, typedValue, true) ? typedValue : null); } catch (Exception e) { _logger.Error($"An Error occurred while retrieving the SelectableItemBackground used for transparent buttons. {e.Message}"); return(null); } }
/// <summary> /// フリッカスタイルをセットします。 /// </summary> /// <param name="onOff"></param> private void SetFlickerStyle(bool onOff) { var rootLayout = FindViewById <LinearLayout>(Resource.Id.rootLayout); if (flickOn) { rootLayout.SetBackgroundColor(Constants.FLICKER_COLOR); } else { var attrValue = new Android.Util.TypedValue(); Theme.ResolveAttribute(Android.Resource.Attribute.ColorBackground, attrValue, true); rootLayout.SetBackgroundColor(Resources.GetColor(attrValue.ResourceId)); } }
private FrameworkElement GetNativeSplashScreen(SplashScreen splashScreen) { try { var activity = ContextHelper.Current as Activity; // Get the theme's windowBackground (which we use as splash screen) var attribute = new Android.Util.TypedValue(); activity?.Theme.ResolveAttribute(Android.Resource.Attribute.WindowBackground, attribute, true); var windowBackgroundResourceId = attribute.ResourceId; // Get the splash screen size var splashScreenSize = GetSplashScreenSize(activity); // Create the splash screen surface var splashView = new Android.Views.View(activity); splashView.SetBackgroundResource(attribute.ResourceId); // We use a Canvas to ensure it's clipped but not resized (important when device has soft-keys) var element = new Canvas { // We set a background to prevent touches from going through Background = SolidColorBrushHelper.Transparent, // We use a Border to ensure proper layout Children = { new Border() { Width = splashScreenSize.Width, Height = splashScreenSize.Height, Child = VisualTreeHelper.AdaptNative(splashView), } }, }; return(element); } catch (Exception e) { typeof(ExtendedSplashScreen).Log().LogError(0, e, "Error while getting native splash screen."); return(null); } }
public static void SetLegislatorContactMthdVisibility(View imageButton, ContactMethod contactMethod, Android.Util.TypedValue selectableItemBackground) { imageButton.Visibility = contactMethod.IsEmpty ? ViewStates.Gone : ViewStates.Visible; if (selectableItemBackground != null) { imageButton.SetBackgroundResource(selectableItemBackground.ResourceId); } }