public override void SetImageBitmap(Bitmap bm) { RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.Create(Resources, bm); roundedDrawable.Circular = true; base.SetImageDrawable(roundedDrawable); }
private RoundedBitmapDrawable CreateRoundDrawable() { var src = BitmapFactory.DecodeResource(Resources, Resource.Drawable.image_unknown_person); var dr = RoundedBitmapDrawableFactory.Create(Resources, src); dr.Circular = true; return(dr); }
private static void SetBackgroundOnView(View view, Bitmap bitmap, AppCompatActivity activity) { Drawable d = null; if (bitmap != null) { d = RoundedBitmapDrawableFactory.Create(activity.Resources, bitmap); ((RoundedBitmapDrawable)d).CornerRadius = 10; } view.Background = d; }
public static Drawable CreateBackgroundBitmap(string image, int height, int width, float cornerRadius, int alpha = 40) { var bitmap = Application.Context.Resources.GetBitmap(image); if (bitmap != null) { width = (int)(bitmap.Width * height / bitmap.Height); bitmap = Bitmap.CreateScaledBitmap(bitmap, width, height, false); var dr = RoundedBitmapDrawableFactory.Create(Application.Context.Resources, bitmap); dr.CornerRadius = cornerRadius; dr.Mutate().SetAlpha(alpha); return(dr); } return(null); }
private void InitData() { Bitmap avatar = BitmapFactory.DecodeResource(Resources, Resource.Drawable.avacar); RoundedBitmapDrawable roundDrawable = RoundedBitmapDrawableFactory.Create(Resources, avatar); roundDrawable.Circular = true; roundDrawable.SetAntiAlias(true); userAvatar.SetImageDrawable(roundDrawable); if (userData == null) { return; } userName.Text = $"{userData["FirstName"]} {userData["MiddleName"]} {userData["LastName"]}"; genderGroup.Check(Resource.Id.userprofile_gender_male); userBirthDate.Text = ((DateTime)userData["BirthDate"]).ToShortDateString(); choosenBirthDate = (DateTime)userData["BirthDate"]; }
private Drawable GetRoundedBitmap(int imageId) { Bitmap src = BitmapFactory.DecodeResource(this.Resources, imageId); Bitmap dst; if (src.Width >= src.Height) { dst = Bitmap.CreateBitmap(src, src.Width / 2 - src.Height / 2, 0, src.Height, src.Height); } else { dst = Bitmap.CreateBitmap(src, 0, src.Height / 2 - src.Width / 2, src.Width, src.Width); } RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.Create(this.Resources, dst); roundedBitmapDrawable.CornerRadius = (dst.Width / 2); roundedBitmapDrawable.SetAntiAlias(true); return(roundedBitmapDrawable); }
public void UpdateData(BalanceModel balance, CurrencyRate currencyRate, int position) { Balance = balance; var usdBalance = 0d; var firstCardId = Resource.Drawable.wallet_card_bg1; var dr = RoundedBitmapDrawableFactory.Create(ItemView.Resources, BitmapFactory.DecodeResource(ItemView.Resources, firstCardId + position)); dr.CornerRadius = _cornerRadius; _holderImage.SetImageDrawable(dr); switch (balance.CurrencyType) { case CurrencyType.Steem: case CurrencyType.Golos: { _balanceTitle.Text = $"{balance.CurrencyType.ToString()} {AppSettings.LocalizationManager.GetText(LocalizationKeys.Balance).ToLower()}"; _tokenBalanceTitle2.Text = $"{balance.CurrencyType.ToString()} Power".ToUpper(); usdBalance = (balance.Value + balance.EffectiveSp) * (currencyRate?.UsdRate ?? 1); break; } case CurrencyType.Sbd: case CurrencyType.Gbg: { _balanceTitle.Text = $"{balance.CurrencyType.ToString().ToUpper()} {AppSettings.LocalizationManager.GetText(LocalizationKeys.Balance).ToLower()}"; _tokenBalanceTitle2.Visibility = ViewStates.Gone; _tokenBalance2.Visibility = ViewStates.Gone; usdBalance = balance.Value * (currencyRate?.UsdRate ?? 1); break; } } _username.Text = $"@{balance.UserInfo.Login}"; _balance.Text = $"$ {usdBalance.ToBalanceValueString()}".ToUpper(); _tokenBalanceTitle.Text = balance.CurrencyType.ToString().ToUpper(); _tokenBalance.Text = balance.Value.ToBalanceValueString(); _tokenBalance2.Text = balance.EffectiveSp.ToBalanceValueString(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (Intent.HasExtra(Notifications.NotificationsSenderKey)) { ViewModel.ViewConversationCommand.Execute(Intent.GetStringExtra(Notifications.NotificationsSenderKey)); } var header = this.BindingInflate(Resource.Layout.navigation_header, null); header.FindViewById(Resource.Id.status).Click += delegate { new AlertDialog.Builder(this).SetPositiveButton(Strings.SetStatus_Title, (sender, args) => { ViewModel.ChangeStatusCommand.Execute(((AlertDialog)sender).FindViewById <TextView>(Resource.Id.input).Text); }) .SetView(this.BindingInflate(Resource.Layout.dialog_change_status, null)) .SetTitle(Strings.SetStatus_Title) .Show(); }; Mvx.GetSingleton <IMvxImageCache <Bitmap> >().RequestImage(ViewModel.Character.Image).ContinueWith(task => { var drawable = RoundedBitmapDrawableFactory.Create(Resources, task.Result); drawable.Circular = true; header.FindViewById <ImageView>(Resource.Id.icon).SetImageDrawable(drawable); }); NavigationView.AddHeaderView(header); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { StudentInfoView = inflater.Inflate(Resource.Layout.StudentInfoFragmentLayout, container, false); StudentInfoView.FindViewById <Button>(Resource.Id.BoxCombinationInstructions) .Click += ShowBoxInstructions; StudentInfoView.FindViewById <Button>(Resource.Id.StudentChecksheet) .SetCommand("Click", ViewModel.ShowChecksheetCommand); StudentInfoView.FindViewById <Button>(Resource.Id.MessagingAndTelephoneInstructions) .Click += ShowTelephoneInstructions; ImageView _accountPhotoView = StudentInfoView.FindViewById <ImageView>(Resource.Id.AccountPhoto); RoundedBitmapDrawable _drawable = null; switch (userIdNumber) { case "130000": { _drawable = RoundedBitmapDrawableFactory.Create( Resources, BitmapFactory.DecodeResource( Resources, Resource.Drawable.abby)); } break; case "124801": { _drawable = RoundedBitmapDrawableFactory.Create( Resources, BitmapFactory.DecodeResource( Resources, Resource.Drawable.becki)); } break; case "118965": { _drawable = RoundedBitmapDrawableFactory.Create( Resources, BitmapFactory.DecodeResource( Resources, Resource.Drawable.account_photo)); } break; case "123456": { _drawable = RoundedBitmapDrawableFactory.Create( Resources, BitmapFactory.DecodeResource( Resources, Resource.Drawable.nick)); } break; } _drawable.CornerRadius = Math.Min(_drawable.MinimumWidth, _drawable.MinimumHeight); Activity.RunOnUiThread(() => { _accountPhotoView.SetImageDrawable(_drawable); }); //Resources _resources = Resources; //Bitmap _accountPhotoBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.account_photo); ///*SEPARATE THREAD*/ ImageView _accountPhotoView = StudentInfoView.FindViewById<ImageView>(Resource.Id.AccountPhoto); //RoundedBitmapDrawable _drawable = RoundedBitmapDrawableFactory.Create(Resources, // BitmapFactory.DecodeResource(Resources, Resource.Drawable.account_photo)); //_drawable.CornerRadius = System.Math.Min(_drawable.MinimumWidth, _drawable.MinimumHeight); #region NOTE // Use the following only if image has same width and height: // Replace _drawable.CorderRadius = ... with // _drawable.Circular = true; #endregion ParentFragment.View.FindViewById <TabLayout>( Resource.Id.MainTabLayout).TabReselected += TabReselected; SetStudentInfo(); /* Use this to return your custom view for this Fragment */ return(StudentInfoView); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e) { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null) { return; } var view = new Android.Widget.RelativeLayout(this.Context); if (Base.BackgroundImage != null) { var imageView = new ImageView(this.Context); imageView.SetScaleType(ImageView.ScaleType.FitXy); var cornerRad = Base.CornerRadius.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); var res = this.Context.Resources; var resourceId = UIHelper.GetDrawableResource(Base.BackgroundImage); Bitmap src = BitmapFactory.DecodeResource(res, resourceId); var dr = RoundedBitmapDrawableFactory.Create(res, src); dr.CornerRadius = float.Parse(cornerRad[0]); imageView.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); imageView.SetBackground(dr); imageView.SetImageBitmap(src); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { imageView.ClipToOutline = true; } view.AddView(imageView); } this.SetBackgroundColor(Xamarin.Forms.Color.Default.ToAndroid()); SetNativeControl(view); if (!string.IsNullOrWhiteSpace(Base.GradientColor)) { view.Background = GradientConverter(Base.GradientColor); } else { CreateShapeDrawable(); } Element.PropertyChanged += (s, ev) => { if (Element == null) { return; } switch (ev.PropertyName) { case "GradientColor": view.Background = GradientConverter(Base.GradientColor); break; case "HasBorder": break; } }; }
public void OnClick(View v) { var avatarView = new AvatarView(this); avatarView.AvatarSize = AvatarSize.Medium; avatarView.Name = Resources.GetString(Resource.String.persona_name_johnie_mcconnell); var thumbnailImageView = new ImageView(this); var thumbnailBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.thumbnail_example_32); var roundedCornerThumbnailDrawable = RoundedBitmapDrawableFactory.Create(Resources, thumbnailBitmap); roundedCornerThumbnailDrawable.CornerRadius = Resources.GetDimension(Resource.Dimension.uifabric_snackbar_background_corner_radius); thumbnailImageView.SetImageDrawable(roundedCornerThumbnailDrawable); switch (v.Id) { // Single line case Resource.Id.btn_snackbar_single_line: Snackbar.Make(root_view, GetString(Resource.String.snackbar_single_line), Snackbar.LengthShort, Snackbar.Style.Regular).Show(); break; case Resource.Id.btn_snackbar_single_line_custom_view: var circularProgress = (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) ? new Microsoft.OfficeUIFabric.ProgressBar(this, null, 0, Resource.Style.Widget_UIFabric_CircularProgress_Small) : LayoutInflater.Inflate(Resource.Layout.view_snackbar_circular_progress, null, false) as Microsoft.OfficeUIFabric.ProgressBar; circularProgress.IndeterminateDrawable.SetColorFilter( new Color(ContextCompat.GetColor(this, Resource.Color.snackbar_circular_progress_drawable)), PorterDuff.Mode.SrcIn); Snackbar.Make(root_view, GetString(Resource.String.snackbar_single_line), Snackbar.LengthLong, Snackbar.Style.Regular) .SetCustomView(circularProgress, Snackbar.CustomViewSize.Medium) .Show(); break; case Resource.Id.btn_snackbar_single_line_action: Snackbar.Make(root_view, GetString(Resource.String.snackbar_single_line)) .SetAction(GetString(Resource.String.snackbar_action), () => { }).Show(); break; case Resource.Id.btn_snackbar_single_line_action_custom_view: Snackbar.Make(root_view, GetString(Resource.String.snackbar_single_line)) .SetCustomView(avatarView, Snackbar.CustomViewSize.Medium) .SetAction(GetString(Resource.String.snackbar_action), () => { }) .Show(); break; // Multiline case Resource.Id.btn_snackbar_multiline: Snackbar.Make(root_view, GetString(Resource.String.snackbar_multiline), Snackbar.LengthLong).Show(); break; case Resource.Id.btn_snackbar_multiline_custom_view: var doneIconImageView = new ImageView(this); doneIconImageView.SetImageDrawable(ContextCompat.GetDrawable(this, Resource.Drawable.ic_done_white)); Snackbar.Make(root_view, GetString(Resource.String.snackbar_multiline), Snackbar.LengthLong) .SetCustomView(doneIconImageView, Snackbar.CustomViewSize.Small) .Show(); break; case Resource.Id.btn_snackbar_multiline_action: var snackbar = Snackbar.Make(root_view, GetString(Resource.String.snackbar_multiline), Snackbar.LengthIndefinite) .SetAction(GetString(Resource.String.snackbar_action), () => { }); snackbar.Show(); System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(2)) .ContinueWith(t => { snackbar.View.Post(() => snackbar.SetText(GetString(Resource.String.snackbar_description_updated))); }); break; case Resource.Id.btn_snackbar_multiline_action_custom_view: Snackbar.Make(root_view, GetString(Resource.String.snackbar_multiline)) .SetCustomView(thumbnailImageView, Snackbar.CustomViewSize.Medium) .SetAction(GetString(Resource.String.snackbar_action), () => { // handle click here }).Show(); break; case Resource.Id.btn_snackbar_multiline_long_action: Snackbar.Make(root_view, GetString(Resource.String.snackbar_multiline)) .SetAction(GetString(Resource.String.snackbar_action_long), () => { // handle click here }).Show(); break; // Announcement style case Resource.Id.btn_snackbar_announcement: var announcementIconImageView = new ImageView(this); announcementIconImageView.SetImageDrawable(ContextCompat.GetDrawable(this, Resource.Drawable.ic_birthday)); Snackbar.Make(root_view, GetString(Resource.String.snackbar_announcement), Snackbar.LengthShort, Snackbar.Style.Announcement) .SetCustomView(announcementIconImageView, Snackbar.CustomViewSize.Medium) .SetAction(GetString(Resource.String.snackbar_action), () => { // handle click here }).Show(); break; } }