protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.NewElement != null) { var view = (CustomEntry)Element; if (view.IsCurvedCornersEnabled) { // creating gradient drawable for the curved background var _gradientBackground = new Android.Graphics.Drawables.GradientDrawable(); _gradientBackground.SetShape(ShapeType.Rectangle); _gradientBackground.SetColor(view.BackgroundColor.ToAndroid()); // Thickness of the stroke line _gradientBackground.SetStroke(view.BorderWidth, view.BorderColor.ToAndroid()); // Radius for the curves _gradientBackground.SetCornerRadius( DpToPixels(this.Context, Convert.ToSingle(view.CornerRadius))); // set the background of the Control.SetBackground(_gradientBackground); } // Set padding for the internal text from border Control.SetPadding( (int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingTop, (int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingBottom); } }
internal static GradientDrawable getBadgeDrawable(BadgeItem badgeItem, Context context) { GradientDrawable shape = new GradientDrawable(); shape.SetShape(ShapeType.Rectangle); shape.SetCornerRadius(context.Resources.GetDimensionPixelSize(Resource.Dimension.badge_corner_radius)); shape.SetColor(new Color(badgeItem.GetBackgroundColor(context))); shape.SetStroke(badgeItem.BorderWidth, new Color(badgeItem.GetBorderColor(context))); return(shape); }
public void Start(string message, string exceptionMessage = null) { Activity.FlipScreen(Resource.Layout.Logon); using (var userName = Activity.FindViewById<EditText>(Resource.Id.userName)) using (var password = Activity.FindViewById<EditText>(Resource.Id.password)) using (var loginButton = Activity.FindViewById<TextView>(Resource.Id.login)) using (var demoButton = Activity.FindViewById<TextView>(Resource.Id.demo)) using (var caption = Activity.FindViewById<TextView>(Resource.Id.caption)) using (var caption1 = Activity.FindViewById<TextView>(Resource.Id.caption1)) using (var caption2 = Activity.FindViewById<TextView>(Resource.Id.caption2)) using (var bottomText1 = Activity.FindViewById<TextView>(Resource.Id.bottomText1)) using (var bottomText2 = Activity.FindViewById<TextView>(Resource.Id.bottomText2)) using (var messageText = Activity.FindViewById<TextView>(Resource.Id.loginMessage)) using (var topImg = Activity.FindViewById<ImageView>(Resource.Id.imageViewTop)) using (var bottomImg = Activity.FindViewById<ImageView>(Resource.Id.imageViewBottom)) using (var lockImg = Activity.FindViewById<ImageView>(Resource.Id.lockImage)) using (var logoImg = Activity.FindViewById<ImageView>(Resource.Id.logoImage)) using (var topBitmap = (BitmapDrawable)topImg.Drawable) using (var botBitmap = (BitmapDrawable)bottomImg.Drawable) { userName.Hint = D.USER_NAME; password.Hint = D.PASSWORD; loginButton.Text = D.LOGON; demoButton.Text = D.DEMO; caption.Text = D.BIT_MOBILE; int width = Activity.Resources.DisplayMetrics.WidthPixels; int topHeight = topBitmap.Bitmap.Height * width / topBitmap.Bitmap.Width; topImg.LayoutParameters.Width = width; topImg.LayoutParameters.Height = topHeight; int botHeight = botBitmap.Bitmap.Height * width / botBitmap.Bitmap.Width; bottomImg.LayoutParameters.Width = width; bottomImg.LayoutParameters.Height = botHeight; const int radius = 10; Color baseColor = GetBaseColor(); using (var shape = new GradientDrawable()) { shape.SetShape(ShapeType.Rectangle); shape.SetColor(Color.Transparent); shape.SetCornerRadius(radius); shape.SetStroke(2, baseColor); userName.SetBackgroundDrawable(shape); password.SetBackgroundDrawable(shape); } using (var shape = new GradientDrawable()) { shape.SetShape(ShapeType.Rectangle); shape.SetCornerRadius(radius); shape.SetStroke(0, Color.Transparent); Color buttonColor = GetLoginButtonColor(); shape.SetColor(buttonColor); loginButton.SetBackgroundDrawable(shape); } using (var shape = new GradientDrawable()) { shape.SetShape(ShapeType.Rectangle); shape.SetCornerRadius(radius); shape.SetStroke(0, Color.Transparent); Color buttonColor = GetDemoButtonColor(); shape.SetColor(buttonColor); demoButton.SetBackgroundDrawable(shape); } messageText.Text = message; if (exceptionMessage != null) messageText.SetTextColor(new Color(247, 71, 71)); userName.Text = Settings.UserName; password.Text = Settings.DevelopModeEnabled || exceptionMessage != null ? Settings.Password : ""; loginButton.Click += LoginButtonClick; demoButton.Click += DemoButtonOnClick; demoButton.Visibility = Settings.DemoEnabled ? ViewStates.Visible : ViewStates.Gone; if (Settings.CurrentSolutionType != SolutionType.BitMobile) { caption.Text = ""; using (Drawable d = userName.GetCompoundDrawables()[0]) d.SetColorFilter(baseColor, PorterDuff.Mode.SrcIn); using (Drawable d = password.GetCompoundDrawables()[0]) d.SetColorFilter(baseColor, PorterDuff.Mode.SrcIn); lockImg.Drawable.SetColorFilter(baseColor, PorterDuff.Mode.SrcIn); caption.Visibility = ViewStates.Invisible; bottomText1.Text = D.EFFECTIVE_SOLUTIONS_BASED_ON_1C_FOR_BUSINESS; bottomText2.Text = D.FIRST_BIT_COPYRIGHT; SetBackground(topImg, bottomImg, caption1, caption2, logoImg); } } if (exceptionMessage != null && Settings.DevelopModeEnabled) using (var builder = new AlertDialog.Builder(Activity)) { builder.SetTitle(message); builder.SetMessage(exceptionMessage); builder.SetPositiveButton(D.OK, (sender, e) => { }); builder.Show(); } if (Settings.WaitDebuggerEnabled) Toast.MakeText(Activity, "Waiting for debugger to attach", ToastLength.Long).Show(); }
/* Snippet 2 Ende */ /// <summary> /// Aufgenommenes Foto durch Project Oxford analysieren lassen und das Ergebnis visualisieren /// </summary> /// <param name="requestCode"></param> /// <param name="resultCode"></param> /// <param name="data"></param> protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); var progressBar = FindViewById<ProgressBar>(Resource.Id.progressBar1); try { // User canceled if (resultCode == Result.Canceled) return; MediaFile file = await data.GetMediaFileExtraAsync(this); //Alte Face-Rectangles entfernen var rellayout = FindViewById<RelativeLayout>(Resource.Id.relativeLayout1); for (int i = 2; i < rellayout.ChildCount; i++) { rellayout.RemoveViewAt(i); } progressBar.Visibility = ViewStates.Visible; //Foto in ImageView anzeigen var bmp = BitmapFactory.DecodeFile(file.Path); ImageView _imgView = FindViewById<ImageView>(Resource.Id.imageView1); _imgView.SetImageBitmap(bmp); //Bild Analyse durch Project Oxford await _vm.Load(file.GetStream()); //Brechnen der Face Rectangle Positionen float scale; if (_imgView.Width / bmp.Width >= _imgView.Height / bmp.Height) { scale = (float)bmp.Height / _imgView.Height; } else { scale = (float)bmp.Width / _imgView.Width; } var relX = (_imgView.Width - bmp.Width / scale) / 2; var relY = (_imgView.Height - bmp.Height / scale) / 2; foreach (Emotion.Contract.Emotion emo in _vm.Emotions) { //Zeichnen der Face Rectangles var butt = new Button(this); GradientDrawable drawable = new GradientDrawable(); drawable.SetShape(ShapeType.Rectangle); drawable.SetStroke(5, Color.Rgb(34, 135, 202)); drawable.SetColor(Color.Transparent); butt.Background = drawable; var layoutparams = new RelativeLayout.LayoutParams((int)Math.Ceiling(emo.FaceRectangle.Width / scale), (int)Math.Ceiling(emo.FaceRectangle.Height / scale)); layoutparams.SetMargins((int)Math.Ceiling(emo.FaceRectangle.Left / scale + relX), (int)Math.Ceiling(emo.FaceRectangle.Top / scale + relY), 0, 0); butt.LayoutParameters = layoutparams; butt.SetPadding(0, 0, 0, 0); butt.Click += (e, s) => { //Bei Klick auf Face Rectangle Emotionswerte anzeigen (FindViewById<ProgressBar>(Resource.Id.angerProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Anger * 100); (FindViewById<ProgressBar>(Resource.Id.contemptProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Contempt * 100); (FindViewById<ProgressBar>(Resource.Id.disgustProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Disgust * 100); (FindViewById<ProgressBar>(Resource.Id.fearProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Fear * 100); (FindViewById<ProgressBar>(Resource.Id.happinessProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Happiness * 100); (FindViewById<ProgressBar>(Resource.Id.neutralProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Neutral * 100); (FindViewById<ProgressBar>(Resource.Id.sadnessProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Sadness * 100); (FindViewById<ProgressBar>(Resource.Id.surpriseProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Surprise * 100); }; rellayout.AddView(butt); } } finally{ progressBar.Visibility = ViewStates.Invisible; } }
public static bool BackgroundChanged(this IStyleHelper helper , IStyleSheet styleSheet, IBound bound, out Drawable background, bool whithoutImage = false) { if (!whithoutImage) { IBackgroundImage image; if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path)) { background = styleSheet.GetCache<ImageCache>().GetImage(image.Path, bound.Width, bound.Height); return true; } // if control has background image, we have to ignore background color if (!string.IsNullOrWhiteSpace(image.Path)) { background = null; return false; } } IBackgroundColor backgroundColor; IBorderStyle borderStyle; IBorderWidth borderWidth; IBorderColor borderColor; IBorderRadius borderRadius; if (helper.TryGet(out backgroundColor) | helper.TryGet(out borderStyle) | helper.TryGet(out borderWidth) | helper.TryGet(out borderColor) | helper.TryGet(out borderRadius)) { if (borderStyle.Style == BorderStyleValues.Solid) { var shape = new GradientDrawable(); var width = (int)Math.Round(borderWidth.Value); Color color = borderColor.ToColorOrTransparent(); shape.SetShape(ShapeType.Rectangle); shape.SetColor(backgroundColor.ToColorOrTransparent()); shape.SetCornerRadius(borderRadius.Radius); shape.SetStroke(width, color); background = shape; } else background = new ColorDrawable(backgroundColor.ToColorOrTransparent()); return true; } background = null; return false; }
public static Drawable ColorWithBorders(this IStyleSheet styleSheet, IStyledObject control, Color color) { IStyleSheetHelper helper = styleSheet.Helper; Drawable drawable; if (styleSheet.Helper.HasBorder(control)) { var shape = new GradientDrawable(); var borderWidth = (int)Math.Round(helper.BorderWidth(control)); Color borderColor = ToColorOrTransparent(helper.BorderColor(control)); shape.SetShape(ShapeType.Rectangle); shape.SetColor(color); shape.SetCornerRadius(helper.BorderRadius(control)); shape.SetStroke(borderWidth, borderColor); drawable = shape; } else drawable = new ColorDrawable(color); return drawable; }