protected override void OnElementChanged(ElementChangedEventArgs <Slider> e) { base.OnElementChanged(e); if (e.OldElement == null) { var seekBar = CreateNativeControl(); SetNativeControl(seekBar); seekBar.Max = 1000; seekBar.SetOnSeekBarChangeListener(this); defaultthumbcolorfilter = seekBar.Thumb.GetColorFilter(); defaultprogresstintmode = seekBar.ProgressTintMode; defaultprogressbackgroundtintmode = seekBar.ProgressBackgroundTintMode; defaultprogresstintlist = seekBar.ProgressTintList; defaultprogressbackgroundtintlist = seekBar.ProgressBackgroundTintList; defaultthumb = seekBar.Thumb; } Slider slider = e.NewElement; _min = slider.Minimum; _max = slider.Maximum; Value = slider.Value; UpdateSliderColors(); }
public static void TintMenuActionIcons(Toolbar toolbar, Color color, PorterDuff.Mode tintMode = null) { for (int i = 0; i < toolbar.Menu.Size(); i++) { var item = toolbar.Menu.GetItem(i); var drw = item.Icon; if (drw != null) { if (tintMode != null) { DrawableCompat.SetTintMode(drw, tintMode); } item.SetIcon(drw.GetTintedDrawable(color, true, false, true)); } if (item.ActionView is global::Android.Support.V7.Widget.SearchView sv) { ImageView iv = sv.FindViewById <ImageView>(Resource.Id.search_button); if (iv != null) { if (tintMode != null) { DrawableCompat.SetTintMode(iv.Drawable, tintMode); } iv.Drawable.SetDrawableTint(color); } } } }
public static void SetTint(ProgressBar progressBar, Color color, bool skipIndeterminate) { ColorStateList sl = ColorStateList.ValueOf(color); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { progressBar.ProgressTintList = sl; progressBar.SecondaryProgressTintList = sl; if (!skipIndeterminate) { progressBar.IndeterminateTintList = sl; } } else { PorterDuff.Mode mode = PorterDuff.Mode.SrcIn; if (Build.VERSION.SdkInt <= BuildVersionCodes.GingerbreadMr1) { mode = PorterDuff.Mode.Multiply; } if (!skipIndeterminate && progressBar.IndeterminateDrawable != null) { progressBar.IndeterminateDrawable.SetColorFilter(color, mode); } if (progressBar.ProgressDrawable != null) { progressBar.ProgressDrawable.SetColorFilter(color, mode); } } }
public override void SetColorFilter(Color color, PorterDuff.Mode mode) { if (_placeholder != null) { _placeholder.SetColorFilter(color, mode); } base.SetColorFilter(color, mode); }
public override void SetColorFilter(Color color, PorterDuff.Mode mode) { if (IsBitmapDrawableValid(placeholder)) { placeholder.SetColorFilter(color, mode); } base.SetColorFilter(color, mode); }
public virtual void SetImageTintMode(PorterDuff.Mode tintMode) { try { MOnImageChangedListener?.OnBitmapLoaded(GetBitmap()); } catch (Exception e) { Console.WriteLine(e); } }
private static void TintOverflowIcon(Toolbar toolbar, Color color, PorterDuff.Mode tintMode = null) { if (color != null && toolbar.OverflowIcon != null) { if (tintMode != null) { DrawableCompat.SetTintMode(toolbar.OverflowIcon, tintMode); } toolbar.OverflowIcon.SetDrawableTint(color); } }
public virtual void SetImageTintMode(PorterDuff.Mode tintMode) { try { MOnImageChangedListener?.OnBitmapLoaded(GetBitmap()); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var v = inflater.Inflate(Resource.Layout.tinting_fragment, null); // Set a drawable as the image to display image = (ImageView)v.FindViewById(Resource.Id.image); image.SetImageResource(Resource.Drawable.btn_default_normal_holo); // Get text labels and seekbars for the four color components alphaBar = (SeekBar)v.FindViewById(Resource.Id.alphaSeek); alphaText = (TextView)v.FindViewById(Resource.Id.alphaText); greenBar = (SeekBar)v.FindViewById(Resource.Id.greenSeek); greenText = (TextView)v.FindViewById(Resource.Id.greenText); redBar = (SeekBar)v.FindViewById(Resource.Id.redSeek); redText = (TextView)v.FindViewById(Resource.Id.redText); blueBar = (SeekBar)v.FindViewById(Resource.Id.blueSeek); blueText = (TextView)v.FindViewById(Resource.Id.blueText); // Set a listener to update tinted image when selections have changed alphaBar.SetOnSeekBarChangeListener(new MySeekBarChangeListener(this)); greenBar.SetOnSeekBarChangeListener(new MySeekBarChangeListener(this)); redBar.SetOnSeekBarChangeListener(new MySeekBarChangeListener(this)); blueBar.SetOnSeekBarChangeListener(new MySeekBarChangeListener(this)); // Set up the spinner for blend mode selection from a string array resource blendSpinner = (Spinner)v.FindViewById(Resource.Id.blendSpinner); ISpinnerAdapter sa = ArrayAdapter.CreateFromResource(Activity, Resource.Array.blend_modes, Android.Resource.Layout.SimpleSpinnerDropDownItem); blendSpinner.Adapter = sa; // Set a listener to update the tinted image when a blend mode is selected blendSpinner.OnItemSelectedListener = new MyBlendListener(this); // Select the first item blendSpinner.SetSelection(0); mode = MODES [0]; if (savedInstanceState != null) { // Resore the previous state if this fragment has been restored blendSpinner.SetSelection(savedInstanceState.GetInt(STATE_BLEND)); alphaBar.Progress = savedInstanceState.GetInt(STATE_ALPHA); redBar.Progress = savedInstanceState.GetInt(STATE_RED); greenBar.Progress = savedInstanceState.GetInt(STATE_GREEN); blueBar.Progress = savedInstanceState.GetInt(STATE_BLUE); } // Apply the default blend mode and color UpdateTint(GetColor(), GetTintMode()); return(v); }
public override void SetColorFilter(Color color, PorterDuff.Mode mode) { try { if (placeholder.IsValidAndHasValidBitmap()) { placeholder.SetColorFilter(color, mode); } base.SetColorFilter(color, mode); } catch (Exception) { } }
public SafeSliderRenderer(Context context) : base(context) { _defaultThumbDrawable = Thumb; _defaultThumbColorFilter = Thumb.GetColorFilter(); _defaultProgressTintList = ProgressTintList; _defaultProgressTintMode = ProgressTintMode; _defaultProgressBackgroundTintList = ProgressBackgroundTintList; _defaultProgressBackgroundTintMode = ProgressBackgroundTintMode; Max = SeekBarDelta; DuplicateParentStateEnabled = false; SetOnSeekBarChangeListener(this); }
public override void SetColorFilter(Color color, PorterDuff.Mode mode) { try { if (IsBitmapDrawableValid(_placeholder)) { _placeholder.SetColorFilter(color, mode); } } catch (Exception ex) { ImageService.Instance.Config.Logger?.Error("Placeholder SetColorFilter", ex); } base.SetColorFilter(color, mode); }
//http://stackoverflow.com/questions/31953503/how-to-set-icon-color-of-menuitem public Drawable ChangeColorFilter(Drawable drawable, Color newcolor, PorterDuff.Mode mode) { if (drawable == null) { return(null); } var wrapped = DrawableCompat.Wrap(drawable); // This should avoid tinting all the arrows wrapped = wrapped.Mutate(); //PorterDuff.Mode.SrcAtop //PorterDuff.Mode.SrcIn wrapped.SetColorFilter(newcolor, mode); return(wrapped); }
protected override void OnDraw(Canvas canvas) { Drawable localDrawable = Drawable; if (localDrawable == null) { return; } if (localDrawable is NinePatchDrawable) { return; } if (this.paint == null) { PorterDuff.Mode localMode = PorterDuff.Mode.DstIn; Paint localPaint = new Paint(); localPaint.FilterBitmap = false; localPaint.AntiAlias = true; localPaint.SetXfermode(new PorterDuffXfermode(localMode)); this.paint = localPaint; } int width = Width; int height = Height; /** 保存layer */ int layer = canvas.SaveLayer(0.0F, 0.0F, width, height, null, SaveFlags.All); /** 设置drawable的大小 */ localDrawable.SetBounds(0, 0, width, height); /** 将drawable绑定到bitmap(this.mask)上面(drawable只能通过bitmap显示出来) */ localDrawable.Draw(canvas); if ((this.mask == null) || (this.mask.IsRecycled)) { this.mask = CreateOvalBitmap(width, height); } /** 将bitmap画到canvas上面 */ canvas.DrawBitmap(this.mask, 0.0F, 0.0F, this.paint); /** 将画布复制到layer上 */ canvas.RestoreToCount(layer); DrawBorder(canvas, width, height); }
// Update the tint of the image based on ARGB sliders and the selected mode option public void UpdateTint(int color, PorterDuff.Mode mode) { // Set the color hint of the image hintColor = color; // Set the color tint mode based on the selection of the Spinner this.mode = mode; // Log selection Log.Debug(TAG, string.Format("Updating tint with color [ARGB: {0},{1},{2},{3} and mode [{4}]", Color.GetAlphaComponent(color), Color.GetRedComponent(color), Color.GetGreenComponent(color), Color.GetBlueComponent(color), mode.ToString())); // Apply the color tint for the selected tint mode image.SetColorFilter(new Color(hintColor), this.mode); // Update the text for each label with the value for each channel alphaText.SetText("Alpha: " + alphaBar.Progress.ToString(), TextView.BufferType.Normal); redText.SetText("Red: " + redBar.Progress.ToString(), TextView.BufferType.Normal); greenText.SetText("Green: " + greenBar.Progress.ToString(), TextView.BufferType.Normal); blueText.SetText("Blue: " + blueBar.Progress.ToString(), TextView.BufferType.Normal); }
public static void SetTint(SeekBar seekBar, Color color) { ColorStateList s1 = ColorStateList.ValueOf(color); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { seekBar.ThumbTintList = s1; seekBar.ProgressTintList = s1; } else if (Build.VERSION.SdkInt > BuildVersionCodes.GingerbreadMr1) { Drawable progressDrawable = DrawableCompat.Wrap(seekBar.ProgressDrawable); seekBar.ProgressDrawable = progressDrawable; DrawableCompat.SetTintList(progressDrawable, s1); if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean) { Drawable thumbDrawable = DrawableCompat.Wrap(seekBar.Thumb); DrawableCompat.SetTintList(thumbDrawable, s1); seekBar.SetThumb(thumbDrawable); } } else { PorterDuff.Mode mode = PorterDuff.Mode.SrcIn; if (Build.VERSION.SdkInt <= BuildVersionCodes.GingerbreadMr1) { mode = PorterDuff.Mode.Multiply; } if (seekBar.IndeterminateDrawable != null) { seekBar.IndeterminateDrawable.SetColorFilter(color, mode); } if (seekBar.ProgressDrawable != null) { seekBar.ProgressDrawable.SetColorFilter(color, mode); } } }
internal static void ApplyProgressBarColors(this AProgressBar progressBar, PlatformColor progressColor, PlatformColor backgroundColor, PorterDuff.Mode mode) { if ((int)Forms.SdkInt == 21 && progressBar.ProgressDrawable is ALayerDrawable progressDrawable) { progressBar.ProgressTintList = ColorStateList.ValueOf(progressColor); progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(backgroundColor); progressBar.ProgressBackgroundTintMode = mode; if (progressDrawable.GetDrawable(0) is AGradientDrawable layer0) { layer0.SetColor(backgroundColor); } if (progressDrawable.GetDrawable(1) is AScaleDrawable layer1) { layer1.SetColorFilter(progressColor, FilterMode.SrcIn); } if (progressDrawable.GetDrawable(2) is AScaleDrawable layer2) { layer2.SetColorFilter(progressColor, FilterMode.SrcIn); } } else if (Forms.IsLollipopOrNewer) { progressBar.ProgressTintList = ColorStateList.ValueOf(progressColor); progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(backgroundColor); progressBar.ProgressBackgroundTintMode = mode; } else { (progressBar.Indeterminate ? progressBar.IndeterminateDrawable : progressBar.ProgressDrawable).SetColorFilter(progressColor, FilterMode.SrcIn); } }
public static void SetColorFilter(this ADrawable drawable, Color color, AColorFilter defaultColorFilter, PorterDuff.Mode mode) { if (drawable == null) { return; } if (color == Color.Default) { SetColorFilter(drawable, defaultColorFilter); return; } drawable.SetColorFilter(color.ToAndroid(), mode); }
public PorterDuffXfermode(PorterDuff.Mode mode) { Mode = mode; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (LastNonConfigurationInstance != null) { //bug in Mono for Android or whatever: after config change the extra fields are wrong // -> reload: Reload(); return; } _appTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent); SetContentView(Resource.Layout.entry_edit); _closeForReload = false; // Likely the app has been killed exit the activity if (!App.Kp2a.DatabaseIsUnlocked) { Finish(); return; } if (Intent.GetBooleanExtra(IntentContinueWithEditing, false)) { //property "State" will return the state } else { Database db = App.Kp2a.GetDb(); App.Kp2a.EntryEditActivityState = new EntryEditActivityState(); ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this); State.ShowPassword = !prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default)); Intent i = Intent; String uuidBytes = i.GetStringExtra(KeyEntry); PwUuid entryId = PwUuid.Zero; if (uuidBytes != null) { entryId = new PwUuid(MemUtil.HexStringToByteArray(uuidBytes)); } State.ParentGroup = null; if (entryId.Equals(PwUuid.Zero)) { //creating new entry String groupId = i.GetStringExtra(KeyParent); State.ParentGroup = db.KpDatabase.RootGroup.FindGroup(new PwUuid(MemUtil.HexStringToByteArray(groupId)), true); PwUuid templateId = new PwUuid(MemUtil.HexStringToByteArray(i.GetStringExtra(KeyTemplateUuid))); PwEntry templateEntry = null; if (!PwUuid.Zero.Equals(templateId)) { templateEntry = db.Entries[templateId]; } if (KpEntryTemplatedEdit.IsTemplate(templateEntry)) { CreateNewFromKpEntryTemplate(db, templateEntry); } else if (templateEntry != null) { CreateNewFromStandardTemplate(templateEntry); } else { CreateNewWithoutTemplate(db); } _appTask.PrepareNewEntry(State.EntryInDatabase); State.IsNew = true; State.EntryModified = true; } else { Debug.Assert(entryId != null); State.EntryInDatabase = db.Entries [entryId]; State.IsNew = false; } State.Entry = State.EntryInDatabase.CloneDeep(); if (KpEntryTemplatedEdit.IsTemplated(db, State.Entry)) { State.EditMode = new KpEntryTemplatedEdit(db, State.Entry); } else { State.EditMode = new DefaultEdit(); } } if (!State.EntryModified) { SetResult(KeePass.ExitNormal); } else { SetResult(KeePass.ExitRefreshTitle); } FillData(); View scrollView = FindViewById(Resource.Id.entry_scroll); scrollView.ScrollBarStyle = ScrollbarStyles.InsideInset; ImageButton iconButton = (ImageButton)FindViewById(Resource.Id.icon_button); if (State.SelectedIcon) { App.Kp2a.GetDb().DrawableFactory.AssignDrawableTo(iconButton, this, App.Kp2a.GetDb().KpDatabase, (PwIcon)State.SelectedIconId, State.SelectedCustomIconId, false); } iconButton.Click += (sender, evt) => { UpdateEntryFromUi(State.Entry); IconPickerActivity.Launch(this); }; // Generate password button FindViewById(Resource.Id.generate_button).Click += (sender, e) => { UpdateEntryFromUi(State.Entry); GeneratePasswordActivity.Launch(this); }; // Save button //SupportActionBar.SetCustomView(Resource.Layout.SaveButton); if (State.IsNew) { SupportActionBar.Title = GetString(Resource.String.add_entry); } else { SupportActionBar.Title = GetString(Resource.String.edit_entry); } SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); // Respect mask password setting MakePasswordVisibleOrHidden(); ImageButton btnTogglePassword = (ImageButton)FindViewById(Resource.Id.toggle_password); btnTogglePassword.Click += (sender, e) => { State.ShowPassword = !State.ShowPassword; MakePasswordVisibleOrHidden(); }; PorterDuff.Mode mMode = PorterDuff.Mode.SrcAtop; Color color = new Color(189, 189, 189); btnTogglePassword.SetColorFilter(color, mMode); Button addButton = (Button)FindViewById(Resource.Id.add_advanced); addButton.Visibility = ViewStates.Visible; addButton.Click += (sender, e) => { LinearLayout container = (LinearLayout)FindViewById(Resource.Id.advanced_container); KeyValuePair <string, ProtectedString> pair = new KeyValuePair <string, ProtectedString>("", new ProtectedString(true, "")); View ees = CreateExtraStringView(pair); container.AddView(ees); State.EntryModified = true; /*TextView keyView = (TextView) ees.FindViewById(Resource.Id.title); * keyView.RequestFocus();*/ EditAdvancedString(ees.FindViewById(Resource.Id.edit_extra)); }; SetAddExtraStringEnabled(); ((CheckBox)FindViewById(Resource.Id.entry_expires_checkbox)).CheckedChange += (sender, e) => { State.Entry.Expires = e.IsChecked; if (e.IsChecked) { if (State.Entry.ExpiryTime < DateTime.Now) { State.Entry.ExpiryTime = DateTime.Now; } } UpdateExpires(); State.EntryModified = true; }; }
public Drawable ChangeColorFilter(Drawable drawable, int newColor, PorterDuff.Mode mode) { return(ChangeColorFilter(drawable, new Color(newColor), mode)); }
internal static void ApplyProgressBarColors(this AProgressBar progressBar, PlatformColor progressColor, PlatformColor backgroundColor, PorterDuff.Mode mode) { if (Forms.IsLollipopOrNewer) { progressBar.ProgressTintList = ColorStateList.ValueOf(progressColor); progressBar.ProgressBackgroundTintList = ColorStateList.ValueOf(backgroundColor); progressBar.ProgressBackgroundTintMode = mode; } else { (progressBar.Indeterminate ? progressBar.IndeterminateDrawable : progressBar.ProgressDrawable).SetColorFilter(progressColor, PorterDuff.Mode.SrcIn); } }
protected PorterDuffColorFilter(Color color, PorterDuff.Mode mode) { _color = color; _mode = mode; }