private LayerDrawable createNormalDrawable(TypedArray attr) { LayerDrawable drawableNormal = (LayerDrawable)getDrawable(Resource.Drawable.rect_normal).Mutate(); GradientDrawable drawableTop = (GradientDrawable)drawableNormal.GetDrawable(0).Mutate(); drawableTop.SetCornerRadius(getCornerRadius()); int blueDark = getColor(Resource.Color.blue_pressed); int colorPressed = attr.GetColor(Resource.Styleable.FlatButton_pb_colorPressed, blueDark); drawableTop.SetColor(colorPressed); GradientDrawable drawableBottom = (GradientDrawable)drawableNormal.GetDrawable(1).Mutate(); drawableBottom.SetCornerRadius(getCornerRadius()); int blueNormal = getColor(Resource.Color.blue_normal); int colorNormal = attr.GetColor(Resource.Styleable.FlatButton_pb_colorNormal, blueNormal); drawableBottom.SetColor(colorNormal); return(drawableNormal); }
// Max of 2 characters public static void SetBadgeText(Context context, IMenuItem item, string text, Color backgroundColor, Color textColor) { //var iconized = Iconize.FindIconForKey("fa-envelope"); //if (iconized != null) //{ // var drawable = new IconDrawable(context, iconized).Color(Android.Graphics.Color.ParseColor("#7fadf7")).SizeDp(30); // item.SetIcon(drawable); //} if (item.Icon == null) { return; } BadgeDrawable badge = null; Drawable icon = item.Icon; if (item.Icon is LayerDrawable) { LayerDrawable lDrawable = item.Icon as LayerDrawable; if (string.IsNullOrEmpty(text) || text == "0") { icon = lDrawable.GetDrawable(0); lDrawable.Dispose(); } else { for (var i = 0; i < lDrawable.NumberOfLayers; i++) { if (lDrawable.GetDrawable(i) is BadgeDrawable) { badge = lDrawable.GetDrawable(i) as BadgeDrawable; break; } } if (badge == null) { badge = new BadgeDrawable(context, backgroundColor, textColor); icon = new LayerDrawable(new Drawable[] { item.Icon, badge }); } } } else { badge = new BadgeDrawable(context, backgroundColor, textColor); icon = new LayerDrawable(new Drawable[] { item.Icon, badge }); } badge?.SetBadgeText(text); item.SetIcon(icon); icon.Dispose(); }
public void OnQueryComplete(int token, Java.Lang.Object cookie, ICursor cursor) { if (Activity == null) { return; } Day day = (Day)cookie; // Clear out any existing sessions before inserting again day.BlocksView.RemoveAllBlocks(); try { while (cursor.MoveToNext()) { string type = cursor.GetString(BlocksQuery.BLOCK_TYPE); // TODO: place random blocks at bottom of entire layout int column; try { column = TypeColumnMap[type]; } catch { continue; } string blockId = cursor.GetString(BlocksQuery.BLOCK_ID); string title = cursor.GetString(BlocksQuery.BLOCK_TITLE); long start = cursor.GetLong(BlocksQuery.BLOCK_START); long end = cursor.GetLong(BlocksQuery.BLOCK_END); bool containsStarred = cursor.GetInt(BlocksQuery.CONTAINS_STARRED) != 0; BlockView blockView = new BlockView(Activity, blockId, title, start, end, containsStarred, column); int sessionsCount = cursor.GetInt(BlocksQuery.SESSIONS_COUNT); if (sessionsCount > 0) { blockView.Click += HandleClick; } else { blockView.Focusable = false; blockView.Enabled = false; LayerDrawable buttonDrawable = (LayerDrawable)blockView.Background; buttonDrawable.GetDrawable(0).SetAlpha(DISABLED_BLOCK_ALPHA); buttonDrawable.GetDrawable(2).SetAlpha(DISABLED_BLOCK_ALPHA); } day.BlocksView.AddView(blockView); } } finally { cursor.Close(); } }
// Max of 2 characters public static void SetBadgeText(Context context, IMenuItem item, string text, Color backgroundColor, Color textColor) { if (item.Icon == null) { return; } BadgeDrawable badge = null; Drawable icon = item.Icon; if (item.Icon is LayerDrawable) { LayerDrawable lDrawable = item.Icon as LayerDrawable; if (string.IsNullOrEmpty(text) || text == "0") { icon = lDrawable.GetDrawable(0); lDrawable.Dispose(); } else { for (var i = 0; i < lDrawable.NumberOfLayers; i++) { if (lDrawable.GetDrawable(i) is BadgeDrawable) { badge = lDrawable.GetDrawable(i) as BadgeDrawable; break; } } if (badge == null) { badge = new BadgeDrawable(context, backgroundColor, textColor); icon = new LayerDrawable(new Drawable[] { item.Icon, badge }); } } } else { badge = new BadgeDrawable(context, backgroundColor, textColor); icon = new LayerDrawable(new Drawable[] { item.Icon, badge }); } badge?.SetBadgeText(text); item.SetIcon(icon); icon.Dispose(); }
public static IEnumerable <Drawable> Drawables(this LayerDrawable layer) { for (var i = 0; i < layer.NumberOfLayers; i++) { yield return(layer.GetDrawable(i)); } }
public static Drawable FromDrawable(Drawable drawable, Resources r) { if (drawable != null) { if (drawable.GetType() == typeof(RoundedCornerDrawable)) { return(drawable); } else if (drawable.GetType() == typeof(LayerDrawable)) { LayerDrawable ld = drawable as LayerDrawable; int num = ld.NumberOfLayers; for (int i = 0; i < num; i++) { Drawable d = ld.GetDrawable(i); ld.SetDrawableByLayerId(ld.GetId(i), FromDrawable(d, r)); } return(ld); } Bitmap bm = DrawableToBitmap(drawable); if (bm != null) { return(new RoundedCornerDrawable(bm, r)); } } return(drawable); }
private void SetColor(ProgressBar bar, Color color) { LayerDrawable progressDrawable = (LayerDrawable)bar.ProgressDrawable; Drawable primaryColor = progressDrawable.GetDrawable(2); primaryColor.SetColorFilter(new LightingColorFilter(0, color)); progressDrawable.SetDrawableByLayerId(progressDrawable.GetId(2), new ClipDrawable(primaryColor, GravityFlags.Left, ClipDrawableOrientation.Horizontal)); }
/// <summary> /// Helper method used to assign a color state list to the specified layer if it exists. /// </summary> /// <param name="drawable">Drawable.</param> /// <param name="index">Index.</param> /// <param name="colorList">Color list.</param> public static void SetLayerTintList(LayerDrawable drawable, int index, ColorStateList colorList) { if (drawable?.NumberOfLayers > index) { var layer = drawable.GetDrawable(index); var wrapper = DrawableCompat.Wrap(layer); DrawableCompat.SetTintList(wrapper, colorList); } }
private void SetFillColor(LayerDrawable drawable) { if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Android.Support.V4.Graphics.Drawable.DrawableCompat.SetTint(drawable, element.GetFillColor().ToAndroid()); } else { drawable.GetDrawable(2).SetColorFilter(element.GetFillColor().ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcAtop); } }
public BlockView(Context context, string blockId, string title, long startTime, long endTime, bool containsStarred, int column) : base(context) { mBlockId = blockId; mTitle = title; mStartTime = startTime; mEndTime = endTime; mContainsStarred = containsStarred; mColumn = column; Text = mTitle; // TODO: turn into color state list with layers? Color textColor = Android.Graphics.Color.White; Color accentColor = new Color(-1); switch (mColumn) { case 0: accentColor = Resources.GetColor(Resource.Color.block_column_1); break; case 1: accentColor = Resources.GetColor(Resource.Color.block_column_2); break; case 2: accentColor = Resources.GetColor(Resource.Color.block_column_3); break; } LayerDrawable buttonDrawable = (LayerDrawable) context.Resources.GetDrawable(Resource.Drawable.btn_block); buttonDrawable.GetDrawable(0).SetColorFilter(accentColor, PorterDuff.Mode.SrcAtop); buttonDrawable.GetDrawable(1).SetAlpha(mContainsStarred ? 255 : 0); SetTextColor(textColor); SetBackgroundDrawable(buttonDrawable); }
public AlterColorSlider(SeekBar seekbar, Element element) { _seekbar = seekbar; _element = element; _orgProgress = _seekbar.ProgressDrawable.Current as LayerDrawable; if (_orgProgress == null) { notSupported = true; return; } _progress = (LayerDrawable)(_seekbar.ProgressDrawable.Current.GetConstantState().NewDrawable()); _minDrawable = _progress.GetDrawable(2); _maxDrawable = _progress.GetDrawable(0); _orgThumb = _seekbar.Thumb; _thumb = _seekbar.Thumb.GetConstantState().NewDrawable(); _seekbar.ProgressDrawable = _progress; _seekbar.SetThumb(_thumb); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.ProviderProfile); RatingBar ratingBar = FindViewById <RatingBar>(Resource.Id.ratingBar); ImageButton btnback = FindViewById <ImageButton>(Resource.Id.btnback); LayerDrawable stars = (LayerDrawable)ratingBar.ProgressDrawable; stars.GetDrawable(2).SetColorFilter(Color.Yellow, PorterDuff.Mode.SrcAtop); productlayot = FindViewById <LinearLayout>(Resource.Id.productlayout); reviewconsumerlayout = FindViewById <LinearLayout>(Resource.Id.reviewconsumerlayout); productlayot.Click += Productlayot_Click; reviewconsumerlayout.Click += Reviewconsumerlayout_Click; btnback.Click += Btnback_Click; // Create your application here }
private void SetDefaultColor(LayerDrawable drawable) { drawable.GetDrawable(0).SetColorFilter(Android.Graphics.Color.Gray, Android.Graphics.PorterDuff.Mode.SrcAtop); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); bool configurationChange = false; SetContentView(Resource.Layout.MusicPlayListTracksLayout); Log.Info(TAG, "OnCreate: - checking for ReadExternalStorage permission"); CheckReadExternalStoragePermission(); try { if (savedInstanceState != null) { _selectedListItemIndex = savedInstanceState.GetInt("selectedItemIndex"); Log.Info(TAG, "OnCreate: - savedInstanceState value - selectedItemIndex - " + _selectedListItemIndex.ToString()); _playListID = savedInstanceState.GetInt("playListID"); Log.Info(TAG, "OnCreate: - savedInstanceState value - playListID - " + _playListID.ToString()); _isPaused = savedInstanceState.GetBoolean("isPaused"); Log.Info(TAG, "OnCreate: - savedInstanceState value - isPaused - " + (_isPaused?"True":"False")); _isPlaying = savedInstanceState.GetBoolean("isPlaying"); Log.Info(TAG, "OnCreate: - savedInstanceState value - isPlaying - " + (_isPlaying?"True":"False")); if (_isPlaying || _isPaused) { _currentTrackPosition = savedInstanceState.GetInt("trackPosition"); Log.Info(TAG, "OnCreate: isPlaying, currentTrackPosition - " + _currentTrackPosition.ToString()); } configurationChange = true; } if ((Intent != null && Intent.HasExtra("selectedIndex"))) { _selectedListItemIndex = Intent.GetIntExtra("selectedIndex", -1); } Log.Info(TAG, "OnCreate: _selectedListItemIndex is " + _selectedListItemIndex.ToString()); GetFieldComponents(); _imageLoader = ImageLoader.Instance; _imageLoader.LoadImage ( "drawable://" + Resource.Drawable.cds, new ImageLoadingListener ( loadingComplete: (imageUri, view, loadedImage) => { var args = new LoadingCompleteEventArgs(imageUri, view, loadedImage); ImageLoader_LoadingComplete(null, args); } ) ); SetupCallbacks(); if (Intent != null && Intent.HasExtra("playListID")) { _playListID = Intent.GetIntExtra("playListID", -1); Log.Info(TAG, "OnCreate: playListID - " + _playListID.ToString()); } PlayList playList = GlobalData.PlayListItems.Find(play => play.PlayListID == _playListID); if (playList != null) { _playListName.Text = playList.PlayListName.Trim(); } _toolbar = ToolbarHelper.SetupToolbar(this, Resource.Id.musicTrackListToolbar, Resource.String.MusicPlayListTracksToolbarTitle, Color.White); if (_trackProgress != null) { //change the colour of the progressbar (primary progress is on layer 2, layer 0 is background, layer 1 is secondary progress) LayerDrawable layers = (LayerDrawable)_trackProgress.ProgressDrawable; layers.GetDrawable(0).SetColorFilter(Color.LightBlue, PorterDuff.Mode.SrcIn); layers.GetDrawable(2).SetColorFilter(Color.DarkBlue, PorterDuff.Mode.SrcIn); } UpdateAdapter(); SetupMediaPlayer(); //do we have permission to play at this time? if (PermissionsHelper.HasPermission(this, ConstantsAndTypes.AppPermission.ReadExternalStorage)) { Log.Info(TAG, "OnCreate: Permission to read external storage is true"); if (_selectedListItemIndex != -1) { Log.Info(TAG, "OnCreate: isPlaying, calling Play_Click, selectedListItemIndex - " + _selectedListItemIndex.ToString()); Play_Click(null, null); } else { Log.Info(TAG, "OnCreate: No selected index (-1), configurationChange is " + (configurationChange ? "True" : "False") + ", _isPlaying is " + (_isPlaying ? "True" : "False") + ", _isPaused is " + (_isPaused ? "True" : "False")); if (configurationChange && (_isPlaying || _isPaused)) { Play_Click(null, null); } } } else { Log.Info(TAG, "OnCreate: Permission to read external storage is FALSE"); } } catch (System.Exception e) { Log.Error(TAG, "OnCreate: Exception - " + e.Message); if (GlobalData.ShowErrorDialog) { ErrorDisplay.ShowErrorAlert(this, e, GetString(Resource.String.ErrorMusicPlayListTracksActivityCreate), "MusicPlayListTracksActivity.OnCreate"); } } }