protected override View GetCellCore (Cell item, View convertView, ViewGroup parent, Context context) { var cell = (LinearLayout)base.GetCellCore(item, convertView, parent, context); cell.SetPadding(20, 30, 0, 30); cell.DividerPadding = 50; var div = new ShapeDrawable(); div.SetIntrinsicHeight(1); div.Paint.Set(new Paint { Color = Color.FromHex("00FFFFFF").ToAndroid() }); if (parent is ListView) { ((ListView)parent).Divider = div; ((ListView)parent).DividerHeight = 1; } var image = (ImageView)cell.GetChildAt(0); image.SetScaleType(ImageView.ScaleType.FitCenter); image.LayoutParameters.Width = 60; image.LayoutParameters.Height = 60; var linear = (LinearLayout)cell.GetChildAt(1); linear.SetGravity(GravityFlags.CenterVertical); var label = (TextView)linear.GetChildAt(0); label.SetTextColor(Color.White.ToAndroid()); label.TextSize = Font.SystemFontOfSize(NamedSize.Medium).ToScaledPixel() * 1.25f; label.Gravity = (GravityFlags.CenterVertical); label.SetTextColor(Color.FromHex("FFFFFF").ToAndroid()); var secondaryLabel = (TextView)linear.GetChildAt(1); secondaryLabel.Visibility = ViewStates.Gone; return cell; }
protected override View GetCellCore (Cell item, View convertView, ViewGroup parent, Context context) { var cell = (LinearLayout)base.GetCellCore (item, convertView, parent, context); cell.SetPadding(20, 10, 0, 10); cell.DividerPadding = 50; var div = new ShapeDrawable(); div.SetIntrinsicHeight(1); div.Paint.Set(new Paint { Color = MobileCRM.Shared.Helpers.AppColors.SEPARATOR.ToAndroid() }); if (parent is ListView) { ((ListView)parent).Divider = div; ((ListView)parent).DividerHeight = 1; } var label = (TextView)((LinearLayout)cell.GetChildAt(1)).GetChildAt(0); label.SetTextColor(MobileCRM.Shared.Helpers.AppColors.LABELWHITE.ToAndroid()); label.TextSize = Font.SystemFontOfSize(NamedSize.Large).ToScaledPixel(); var secondaryLabel = (TextView)((LinearLayout)cell.GetChildAt(1)).GetChildAt(1); secondaryLabel.SetTextColor(MobileCRM.Shared.Helpers.AppColors.LABELBLUE.ToAndroid()); secondaryLabel.TextSize = Font.SystemFontOfSize(NamedSize.Medium).ToScaledPixel(); return cell; }
protected override View GetCellCore (Cell item, View convertView, ViewGroup parent, Context context) { var cell = (LinearLayout)base.GetCellCore (item, convertView, parent, context); cell.SetPadding(20, 10, 0, 10); cell.DividerPadding = 50; var div = new ShapeDrawable(); div.SetIntrinsicHeight(1); //div.Paint.Set(new Paint { Color = Color.FromHex("00FFFFFF").ToAndroid() }); if (parent is ListView) { ((ListView)parent).Divider = div; ((ListView)parent).DividerHeight = 1; } var label = (TextView)((LinearLayout)cell.GetChildAt(1)).GetChildAt(0); label.SetTextColor(Color.FromHex("000000").ToAndroid()); label.TextSize = Font.SystemFontOfSize(NamedSize.Large).ToScaledPixel(); var secondaryLabel = (TextView)((LinearLayout)cell.GetChildAt(1)).GetChildAt(1); secondaryLabel.SetTextColor(Color.FromHex("738182").ToAndroid()); secondaryLabel.TextSize = Font.SystemFontOfSize(NamedSize.Medium).ToScaledPixel(); return cell; }
Drawable?GetShape(AColor color) { if (_indicatorView == null || Context == null) { return(null); } AShapeDrawable shape; if (_indicatorView.IsCircleShape()) { shape = new AShapeDrawable(new AShapes.OvalShape()); } else { shape = new AShapeDrawable(new AShapes.RectShape()); } var indicatorSize = _indicatorView.IndicatorSize; shape.SetIntrinsicHeight((int)Context.ToPixels(indicatorSize)); shape.SetIntrinsicWidth((int)Context.ToPixels(indicatorSize)); if (shape.Paint != null) { shape.Paint.Color = color; } return(shape); }
private void updateBackground() { var shape = new RoundRectShape(Enumerable.Repeat(5f, 8).ToArray(), null, null); var background = new ShapeDrawable(shape); background.Paint.Color = global::Android.Graphics.Color.White; this.Control.Background = background; }
Drawable?GetShape(AColor color) { if (_indicatorView == null || Context == null) { return(null); } AShapeDrawable shape; if (_indicatorView.IsCircleShape()) { shape = new AShapeDrawable(new AShapes.OvalShape()); } else { shape = new AShapeDrawable(new AShapes.RectShape()); } var indicatorSize = _indicatorView.IndicatorSize; shape.SetIntrinsicHeight((int)Context.ToPixels(indicatorSize)); shape.SetIntrinsicWidth((int)Context.ToPixels(indicatorSize)); if (shape.Paint != null) #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962 { shape.Paint.Color = color; } #pragma warning restore CA1416 return(shape); }
private ShapeDrawable GetBackground() { var shapeDrawable = new ShapeDrawable(); shapeDrawable.Paint.SetStyle(Paint.Style.Stroke); shapeDrawable.Paint.Color = Color.Gray; shapeDrawable.Paint.StrokeWidth = 6; return shapeDrawable; }
private ShapeDrawable CreateRectangle(Color color) { ShapeDrawable rect = new ShapeDrawable(new RectShape()); var paint = new Paint(); paint.SetARGB(255,color.R,color.G,color.B); paint.SetStyle(Paint.Style.Fill); paint.StrokeWidth = 4; rect.Paint.Set(paint); return rect; }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it btnLight = FindViewById<ImageButton>(Resource.Id.imageButton); btnLight.SetImageResource(Resource.Drawable.iTorchOff); Android.Content.PM.PackageManager pm = PackageManager; hasFlash = pm.HasSystemFeature(Android.Content.PM.PackageManager.FeatureCameraFlash); if (!hasFlash) { //set alert for executing the task AlertDialog.Builder alert = new AlertDialog.Builder (this); alert.SetTitle ("Error"); alert.SetMessage ("Sorry, your device doesn't support flash light"); alert.SetPositiveButton ("OK", (senderAlert, args) => { Finish (); } ); //run the alert in UI thread to display in the screen RunOnUiThread (() => { alert.Show(); } ); } btnLight.Click += delegate { if (isFlashOn) { // turn off flash TurnOffFlash(); int h = btnLight.Height; btnLight.SetImageResource(Resource.Drawable.iTorchOff); //ShapeDrawable mDrawable = new ShapeDrawable(new OvalShape()); ///mDrawable.Paint.SetShader(new LinearGradient(0, 0, 0, h, Color.Red, Color.Red, Shader.TileMode.Repeat)); //btnLight.SetBackgroundDrawable (mDrawable); //btnLight.Text="Tap to off the flash"; } else { // turn on flash TurnOnFlash(); btnLight.SetImageResource(Resource.Drawable.iTourchOn); int h = btnLight.Height; ShapeDrawable mDrawable = new ShapeDrawable(new OvalShape()); mDrawable.Paint.SetShader(new LinearGradient(0, 0, 0, h, Color.Green, Color.Red, Shader.TileMode.Repeat)); //btnLight.SetBackgroundDrawable (mDrawable); //btnLight.Text="Tap to on the flash"; } //btnLight.Text = string.Format ("{0} clicks!", count++); }; }
public ShapeView(Context context) : base(context) { _drawable = new AShapeDrawable(null); _drawable.Paint.AntiAlias = true; _density = Resources.DisplayMetrics.Density; _pathFillBounds = new global::Android.Graphics.RectF(); _pathStrokeBounds = new global::Android.Graphics.RectF(); _aspect = Stretch.None; }
public CircleView(Context context, int width, int height, int offset): base(context) { var paint = new Paint(); paint.Color = Color.Red; paint.SetStyle(Paint.Style.Stroke); paint.StrokeWidth = 3; _shape = new ShapeDrawable(new OvalShape()); _shape.Paint.Set(paint); _shape.SetBounds(offset, offset, width-offset, height-offset); }
public MyOvalShape(Context context) : base(context) { var paint = new Paint(); paint.SetARGB(255, 200, 255, 0); paint.SetStyle(Paint.Style.Stroke); paint.StrokeWidth = 4; _shape = new ShapeDrawable(new OvalShape()); _shape.Paint.Set(paint); _shape.SetBounds(20, 20, 300, 200); }
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { var shape = new ShapeDrawable(new RectShape()); shape.Paint.Color = Android.Graphics.Color.Transparent; shape.Paint.StrokeWidth = 2; shape.Paint.SetStyle(Paint.Style.Stroke); Typeface font = Typeface.CreateFromAsset(Forms.Context.Assets, "BTrafcBd.ttf"); Control.Typeface = font; Control.TextSize = 14; Control.SetBackgroundDrawable(shape); } }
public OverallView(Context context) : base(context) { SetOnTouchListener(this); SetBackgroundColor(Color.White); var paint = new Paint(); paint.SetARGB(255, 200, 255, 0); paint.SetStyle(Paint.Style.Stroke); paint.StrokeWidth = 4; _shape = new ShapeDrawable(new OvalShape()); _shape.Paint.Set(paint); //_shape.SetBounds(20, 20, 300, 200); }
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) { base.OnElementChanged(e); if (this.Control != null) { var entry = (ExtendedEntry)this.Element; var control = this.Control; var shape = new ShapeDrawable(new RectShape()); shape.Paint.SetStyle(Paint.Style.Stroke); control.Background = shape; SetBorderColor(entry, control); SetBorderWidth(entry, control); } }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); //LayoutInflater inflater; var topLeft = FindViewById(Resource.Id.floating_shape1); var topRight = FindViewById(Resource.Id.floating_shape2); var bottomLeft = FindViewById(Resource.Id.floating_shape3); var bottomRight= FindViewById(Resource.Id.floating_shape4); topLeft.Touch += delegate { int h = topLeft.Height; ShapeDrawable mDrawable = new ShapeDrawable(new OvalShape()); mDrawable.Paint.SetShader(new LinearGradient(0, 0, 0, h, Color.Red, Color.Red, Shader.TileMode.Repeat)); topLeft.SetBackgroundDrawable (mDrawable); }; topRight.Touch += delegate { int h = topRight.Height; ShapeDrawable mDrawable = new ShapeDrawable(new OvalShape()); mDrawable.Paint.SetShader(new LinearGradient(0, 0, 0, h, Color.Yellow, Color.Yellow, Shader.TileMode.Repeat)); topRight.SetBackgroundDrawable (mDrawable); }; bottomLeft.Touch += delegate { int h = bottomLeft.Height; ShapeDrawable mDrawable = new ShapeDrawable(new OvalShape()); mDrawable.Paint.SetShader(new LinearGradient(0, 0, 0, h, Color.Green, Color.Green, Shader.TileMode.Repeat)); bottomLeft.SetBackgroundDrawable (mDrawable); }; bottomRight.Touch += delegate { int h = bottomRight.Height; ShapeDrawable mDrawable = new ShapeDrawable(new OvalShape()); mDrawable.Paint.SetShader(new LinearGradient(0, 0, 0, h, Color.ParseColor("#330000FF"), Color.ParseColor ("#110000FF"), Shader.TileMode.Repeat)); bottomRight.SetBackgroundDrawable (mDrawable); Toast.MakeText (this,"you have clicked on "+Resource.Id.floating_shape1,ToastLength.Long).Show(); }; }
Drawable GetShape(AColor color) { var indicatorSize = IndicatorView.IndicatorSize; AShapeDrawable shape; if (_shapeType == AShapeType.Oval) { shape = new AShapeDrawable(new AShapes.OvalShape()); } else { shape = new AShapeDrawable(new AShapes.RectShape()); } shape.SetIntrinsicHeight((int)Context.ToPixels(indicatorSize)); shape.SetIntrinsicWidth((int)Context.ToPixels(indicatorSize)); shape.Paint.Color = color; return(shape); }
private void updateSearchBackground() { var shape = new RectShape(); var searchBackground = new ShapeDrawable(shape); searchBackground.Paint.Color = global::Android.Graphics.Color.White; int searchPlateId = this.Control.Context.Resources.GetIdentifier("android:id/search_plate", null, null); var searchPlateView = this.Control.FindViewById(searchPlateId); if (searchPlateView != null) { searchPlateView.Background = searchBackground; } int textId = this.Control.Context.Resources.GetIdentifier("android:id/search_src_text", null, null); var textView = (Android.Widget.TextView) this.Control.FindViewById(textId); if (textView != null) { textView.TextSize = 14; textView.LayoutParameters.Height = LayoutParams.MatchParent; } }
void InitDrawShape() { _shape = null; var paint = new Paint (); paint.SetARGB ( _shapeViewModel.Shape.FilledColor.A, _shapeViewModel.Shape.FilledColor.R, _shapeViewModel.Shape.FilledColor.G, _shapeViewModel.Shape.FilledColor.B); paint.SetStyle (Paint.Style.FillAndStroke); paint.StrokeWidth = 4; _shape = new ShapeDrawable (new OvalShape ()); _shape.Paint.Set (paint); _shape.SetBounds ( 0, 0, _shapeViewModel.Shape.Radius * 2, _shapeViewModel.Shape.Radius * 2); }
Drawable GetShape(AColor color) { var indicatorSize = IndicatorView.IndicatorSize; AShapeDrawable shape; if (_shapeType == AShapeType.Oval) { shape = new AShapeDrawable(new AShapes.OvalShape()); } else { shape = new AShapeDrawable(new AShapes.RectShape()); } shape.SetIntrinsicHeight((int)Context.ToPixels(indicatorSize)); shape.SetIntrinsicWidth((int)Context.ToPixels(indicatorSize)); #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962 shape.Paint.Color = color; #pragma warning restore CA1416 return(shape); }
private void updateBackground() { var tabButton = this.Element as TabButton; if (tabButton.IsSelected) { if (_selectedBackground == null) { var shape = new RoundRectShape(new float[]{ 10, 10, 10, 10, 0, 0, 0, 0 }, null, null); _selectedBackground = new ShapeDrawable(shape); _selectedBackground.Paint.Color = Colors.Secondary.ToAndroid(); } this.Control.Background = _selectedBackground; } else { if (_deselectedBackground == null) { var shape = new RoundRectShape(new float[]{ 10, 10, 10, 10, 0, 0, 0, 0 }, null, null); _deselectedBackground = new ShapeDrawable(shape); _deselectedBackground.Paint.Color = Colors.Main.ToAndroid(); } this.Control.Background = _deselectedBackground; } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { // Currently in a layout without a container, so no reason to create our view. return null; } Point displaySize = new Point( ); Activity.WindowManager.DefaultDisplay.GetSize( displaySize ); ScreenSize = new System.Drawing.SizeF( displaySize.X, displaySize.Y ); // scale the image to match the view's width ScreenToImageScalar = (float) SourceImage.Width / (float) ScreenSize.Width; // get the scaled dimensions, maintaining aspect ratio float scaledWidth = (float)SourceImage.Width * (1.0f / ScreenToImageScalar); float scaledHeight = (float)SourceImage.Height * (1.0f / ScreenToImageScalar); // now, if the scaled height is too large, re-calc with Height is the dominant, // so we guarantee a fit within the view. if( scaledHeight > ScreenSize.Height ) { ScreenToImageScalar = (float) SourceImage.Height / (float) ScreenSize.Height; scaledWidth = (float)SourceImage.Width * (1.0f / ScreenToImageScalar); scaledHeight = (float)SourceImage.Height * (1.0f / ScreenToImageScalar); } ScaledSourceImage = Bitmap.CreateScaledBitmap( SourceImage, (int)scaledWidth, (int)scaledHeight, false ); // setup our layout for touch input RelativeLayout view = inflater.Inflate( Resource.Layout.ImageCrop, container, false ) as RelativeLayout; view.SetOnTouchListener( this ); // create the view that will display the image to crop ImageView = new AspectScaledImageView( Rock.Mobile.PlatformSpecific.Android.Core.Context ); ImageView.LayoutParameters = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent ); ImageView.LayoutParameters.Width = ScaledSourceImage.Width; ImageView.LayoutParameters.Height = ScaledSourceImage.Height; // center the image ImageView.SetX( (ScreenSize.Width - ImageView.LayoutParameters.Width ) / 2 ); ImageView.SetY( (ScreenSize.Height - ImageView.LayoutParameters.Height ) / 2 ); view.AddView( ImageView ); // create the draggable crop view that will let the user pic which part of the image to use. CropView = new View( Rock.Mobile.PlatformSpecific.Android.Core.Context ); CropView.LayoutParameters = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent ); // the crop view's dimensions should be based on what the user wanted to crop to. We'll do width, and then height as a scale of width. CropView.LayoutParameters.Width = (int) (scaledWidth < scaledHeight ? scaledWidth : scaledHeight); CropView.LayoutParameters.Height = (int) ((float) CropView.LayoutParameters.Width * CropAspectRatio); // the crop view should be a nice outlined rounded rect float _Radius = 3.0f; RoundRectShape rectShape = new RoundRectShape( new float[] { _Radius, _Radius, _Radius, _Radius, _Radius, _Radius, _Radius, _Radius }, null, null ); // configure its paint ShapeDrawable border = new ShapeDrawable( rectShape ); border.Paint.SetStyle( Paint.Style.Stroke ); border.Paint.StrokeWidth = 8; border.Paint.Color = Color.WhiteSmoke; CropView.Background = border; // set our clamp values CropViewMinPos = new PointF( (ScreenSize.Width - scaledWidth) / 2, (ScreenSize.Height - scaledHeight) / 2 ); CropViewMaxPos = new PointF( CropViewMinPos.X + (scaledWidth - CropView.LayoutParameters.Width), CropViewMinPos.Y + (scaledHeight - CropView.LayoutParameters.Height) ); view.AddView( CropView ); // create a mask layer that will block out the parts of the image that will be cropped MaskLayer = new Rock.Mobile.PlatformSpecific.Android.Graphics.MaskLayer( (int)ScreenSize.Width, (int)ScreenSize.Height, CropView.LayoutParameters.Width, CropView.LayoutParameters.Height, Rock.Mobile.PlatformSpecific.Android.Core.Context ); MaskLayer.LayoutParameters = new RelativeLayout.LayoutParams( (int)ScreenSize.Width, (int)ScreenSize.Height ); MaskLayer.Opacity = 0.00f; view.AddView( MaskLayer ); // Now setup our bottom area with cancel, crop, and text to explain RelativeLayout bottomBarLayout = new RelativeLayout( Rock.Mobile.PlatformSpecific.Android.Core.Context ); bottomBarLayout.LayoutParameters = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent ); ((RelativeLayout.LayoutParams)bottomBarLayout.LayoutParameters).AddRule( LayoutRules.AlignParentBottom ); // set the nav subBar color (including opacity) Color navColor = Rock.Mobile.UI.Util.GetUIColor( PrivateSubNavToolbarConfig.BackgroundColor ); navColor.A = (Byte) ( (float) navColor.A * PrivateSubNavToolbarConfig.Opacity ); bottomBarLayout.SetBackgroundColor( navColor ); bottomBarLayout.LayoutParameters.Height = 150; view.AddView( bottomBarLayout ); // setup the cancel button (which will undo cropping or take you back to the picture taker) CancelButton = new Button( Rock.Mobile.PlatformSpecific.Android.Core.Context ); CancelButton.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent ); CancelButton.Gravity = GravityFlags.Left; ((RelativeLayout.LayoutParams)CancelButton.LayoutParameters).AddRule( LayoutRules.AlignParentLeft ); // set the crop button's font Android.Graphics.Typeface fontFace = Rock.Mobile.PlatformSpecific.Android.Graphics.FontManager.Instance.GetFont( PrivateControlStylingConfig.Icon_Font_Secondary ); CancelButton.SetTypeface( fontFace, Android.Graphics.TypefaceStyle.Normal ); CancelButton.SetTextSize( Android.Util.ComplexUnitType.Dip, PrivateImageCropConfig.CropCancelButton_Size ); CancelButton.Text = PrivateImageCropConfig.CropCancelButton_Text; CancelButton.Click += (object sender, EventArgs e) => { // don't allow button presses while animations are going on if( Animating == false ) { // if they hit cancel while previewing, go back to editing if( Mode == CropMode.Previewing ) { SetMode( CropMode.Editing ); } else { // they pressed it while they're in editing mode, so go back to camera mode Activity.OnBackPressed( ); } } }; bottomBarLayout.AddView( CancelButton ); // setup the Confirm button, which will use a font to display its graphic ConfirmButton = new Button( Rock.Mobile.PlatformSpecific.Android.Core.Context ); ConfirmButton.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent ); ConfirmButton.Gravity = GravityFlags.Right; ((RelativeLayout.LayoutParams)ConfirmButton.LayoutParameters).AddRule( LayoutRules.AlignParentRight ); // set the crop button's font fontFace = Rock.Mobile.PlatformSpecific.Android.Graphics.FontManager.Instance.GetFont( PrivateControlStylingConfig.Icon_Font_Secondary ); ConfirmButton.SetTypeface( fontFace, Android.Graphics.TypefaceStyle.Normal ); ConfirmButton.SetTextSize( Android.Util.ComplexUnitType.Dip, PrivateImageCropConfig.CropOkButton_Size ); ConfirmButton.Text = PrivateImageCropConfig.CropOkButton_Text; // when clicked, we should crop the image. ConfirmButton.Click += (object sender, EventArgs e) => { // don't allow button presses while animations are going on if( Animating == false ) { // if they pressed confirm while editing, go to preview if( Mode == CropMode.Editing ) { SetMode( CropMode.Previewing ); } else { // notify the caller SpringboardParent.ModalFragmentDone( CroppedImage ); } } }; bottomBarLayout.AddView( ConfirmButton ); // start in editing mode (obviously) SetMode( CropMode.Editing ); // start the cropper centered MoveCropView( new PointF( (ScreenSize.Width - CropView.LayoutParameters.Width) / 2, (ScreenSize.Height - CropView.LayoutParameters.Height) / 2 ) ); MaskLayer.Position = new PointF( CropView.GetX( ), CropView.GetY( ) ); return view; }
private Drawable CreateDrawable (int color) { var ovalShape = new OvalShape (); var shapeDrawable = new ShapeDrawable (ovalShape); shapeDrawable.Paint.Color = new Color (color); if (hasShadow && !HasLollipopApi) { var shadowDrawable = Resources.GetDrawable (size == FabSize.Normal ? Resource.Drawable.fab_shadow : Resource.Drawable.fab_shadow_mini); var layerDrawable = new LayerDrawable (new Drawable[]{ shadowDrawable, shapeDrawable }); layerDrawable.SetLayerInset (1, shadowSize, shadowSize, shadowSize, shadowSize); return layerDrawable; } else { return shapeDrawable; } }
private void Show (bool animate, Animation anim) { if (this.Background == null) { if (badgeBackground == null) { badgeBackground = this.DefaultBackground; } this.SetBackgroundDrawable (badgeBackground); } ApplyLayoutParams (); if (animate) { this.StartAnimation (anim); } Visibility = ViewStates.Visible; isShown = true; }
async Task InitDrawShape () { if (_shapeViewModel.Image == null) { var paint = new Paint (); paint.SetARGB ( _shapeViewModel.Shape.FilledColor.A, _shapeViewModel.Shape.FilledColor.R, _shapeViewModel.Shape.FilledColor.G, _shapeViewModel.Shape.FilledColor.B); paint.SetStyle (Paint.Style.FillAndStroke); paint.StrokeWidth = 4; _shape = new ShapeDrawable (new RectShape ()); _shape.Paint.Set (paint); _shape.SetBounds ( 0, 0, _shapeViewModel.Shape.Radius * 2, _shapeViewModel.Shape.Radius * 2); } await _shapeViewModel.LoadImageIfNeed (); }
private void CreateBallView() { this.FV = new FrameLayout(this); var shape = new OvalShape(); var dr = new ShapeDrawable(shape); dr.Paint.Color = Color.WhiteSmoke; dr.Paint.Alpha = 100; this.FV.Background = dr; //������βü�� //this.FV.SetClipChildren(true); //this.FV.SetClipToPadding(true); this.FV.SetOnTouchListener(this); this.FV.SetOnClickListener(this); var img = new ImageView(this); img.SetImageResource(Resource.Drawable.Icon); this.Img = img;//������ FreameLayout �������� this.FV.AddView(img); var param = new WindowManagerLayoutParams(); param.Width = WindowManagerLayoutParams.WrapContent; param.Height = WindowManagerLayoutParams.WrapContent; //������������Ӧ���� ԭ�㣬 ������ó�����ֵ�� �϶���ʱ��λ�û��д�� param.Gravity = GravityFlags.Top | GravityFlags.Left; param.Flags = WindowManagerFlags.NotFocusable; //�������ã� ��Ȼ���� WindowManager.AddView ��ʱ��� param.Type = WindowManagerTypes.Phone; param.Format = Android.Graphics.Format.Transparent; this.WindowManager.AddView(this.FV, param); }
private void AddBall(float x, float y) { var rnd = new Random(); var circle = new OvalShape(); circle.Resize(BallSize * density, BallSize * density); var drawable = new ShapeDrawable(circle); var shapeHolder = new ShapeHolder(drawable); shapeHolder.X = x; shapeHolder.Y = y - (BallSize / 2f); var red = 100 + rnd.Next(155); var green = 100 + rnd.Next(155); var blue = 100 + rnd.Next(155); var color = new Color(red, green, blue); var darkColor = new Color(red / 4, green / 4, blue); var paint = drawable.Paint; var gradient = new RadialGradient(37.5f, 12.5f, 50f, color, darkColor, Shader.TileMode.Clamp); paint.SetShader(gradient); shapeHolder.Paint = paint; balls.Add(shapeHolder); }
private Drawable CreateSelector(Color color) { ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape()); darkerCircle.Paint.Color = TranslucentColor(ShiftColorUp(color)); StateListDrawable stateListDrawable = new StateListDrawable(); stateListDrawable.AddState(new int[] { Android.Resource.Attribute.StatePressed }, darkerCircle); return stateListDrawable; }
/// <summary> /// Initializes the joystick and displacement shapes /// </summary> private void InitShapes() { // Paint for joystick ovals var paintStick = new Paint(); paintStick.SetARGB(255, 78, 78, 78); paintStick.SetStyle(Paint.Style.Fill); // Shape for left joystick m_ShapeStickLeft = new ShapeDrawable(new OvalShape()); m_ShapeStickLeft.Paint.Set(paintStick); // Shape for right joystick m_ShapeStickRight = new ShapeDrawable(new OvalShape()); m_ShapeStickRight.Paint.Set(paintStick); // Paint for displacement ovals var paintRadius = new Paint(); paintRadius.SetARGB(255, 230, 230, 230); paintRadius.SetStyle(Paint.Style.Fill); // Shape for left displacement m_ShapeRadiusLeft = new ShapeDrawable(new OvalShape()); m_ShapeRadiusLeft.Paint.Set(paintRadius); // Shape for right displacement m_ShapeRadiusRight = new ShapeDrawable(new OvalShape()); m_ShapeRadiusRight.Paint.Set(paintRadius); }
protected override void OnLayout(bool changed, int left, int top, int right, int bottom) { base.OnLayout(changed, left, top, right, bottom); float density = Context.Resources.DisplayMetrics.Density; mDiameter = Math.Min(MeasuredWidth, MeasuredHeight); if (mDiameter <= 0) { mDiameter = (int)density * DEFAULT_CIRCLE_DIAMETER; } if (Background == null && mCircleBackgroundEnabled) { int shadowYOffset = (int)(density * Y_OFFSET); int shadowXOffset = (int)(density * X_OFFSET); mShadowRadius = (int)(density * SHADOW_RADIUS); if (ElevationSupported()) { mBgCircle = new ShapeDrawable(new OvalShape()); ViewCompat.SetElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(mShadowRadius, mDiameter, this); mBgCircle = new ShapeDrawable(oval); ViewCompat.SetLayerType(this, ViewCompat.LayerTypeSoftware, mBgCircle.Paint); mBgCircle.Paint.SetShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); int padding = (int)mShadowRadius; SetPadding(padding, padding, padding, padding); } mBgCircle.Paint.Color = mBackGroundColor; SetBackgroundDrawable(mBgCircle); } mProgressDrawable.SetBackgrounColor(mBackGroundColor); mProgressDrawable.SetColorSchemeColors(mColors); mProgressDrawable.SetSizeParameters(mDiameter, mDiameter, mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius, mProgressStokeWidth, mArrowWidth < 0 ? mProgressStokeWidth * 5 : mArrowWidth, mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight); if (IsShowArrow()) { mProgressDrawable.SetArrowScale(1f); mProgressDrawable.ShowArrow(true); } base.SetImageDrawable(null); base.SetImageDrawable(mProgressDrawable); mProgressDrawable.SetAlpha(255); mProgressDrawable.Start(); }
Bitmap CreateRect(Color color, float displayDensity) { var dp3 = (int) (3 * displayDensity); var dp24 = (int) (24 * displayDensity); var bitmap = Bitmap.CreateBitmap(dp24, dp24, Bitmap.Config.Argb8888); var canvas = new Canvas(bitmap); var rectShape = new ShapeDrawable(); rectShape.Paint.Color = color; rectShape.Paint.SetPathEffect(new CornerPathEffect(dp3)); rectShape.SetBounds(dp3, dp3, canvas.Width - dp3, canvas.Height - dp3); rectShape.Draw(canvas); return bitmap; }
public static void SetTheme (ToggleButton toggleButton, FlatTheme theme, int padding, int size) { toggleButton.SetWidth(size * 5); toggleButton.SetHeight(size); //setTextOff(""); //setTextOn(""); int radius = size - 4; float[] outerR = new float[]{radius, radius, radius, radius, radius, radius, radius, radius}; // creating unchecked-enabled state drawable var uncheckedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null)); uncheckedEnabledFrontCore.Paint.Color = theme.LightAccentColor; var uncheckedEnabledFront = new InsetDrawable(uncheckedEnabledFrontCore, 5); var uncheckedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null)); uncheckedEnabledBack.Paint.Color = Color.ParseColor("#f2f2f2"); uncheckedEnabledBack.SetPadding(0, 0, size / 2 * 5, 0); Drawable[] d1 = {uncheckedEnabledBack, uncheckedEnabledFront}; var uncheckedEnabled = new LayerDrawable(d1); // creating checked-enabled state drawable var checkedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null)); checkedEnabledFrontCore.Paint.Color = theme.LightAccentColor; var checkedEnabledFront = new InsetDrawable(checkedEnabledFrontCore, 5); ShapeDrawable checkedEnabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null)); checkedEnabledBack.Paint.Color = theme.VeryLightAccentColor; checkedEnabledBack.SetPadding(size / 2 * 5, 0, 0, 0); Drawable[] d2 = {checkedEnabledBack, checkedEnabledFront}; LayerDrawable checkedEnabled = new LayerDrawable(d2); // creating unchecked-disabled state drawable ShapeDrawable uncheckedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null)); uncheckedDisabledFrontCore.Paint.Color = Color.ParseColor("#d2d2d2"); InsetDrawable uncheckedDisabledFront = new InsetDrawable(uncheckedDisabledFrontCore, 5); ShapeDrawable uncheckedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null)); uncheckedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2"); uncheckedDisabledBack.SetPadding(0, 0, size / 2 * 5, 0); Drawable[] d3 = {uncheckedDisabledBack, uncheckedDisabledFront}; LayerDrawable uncheckedDisabled = new LayerDrawable(d3); // creating checked-disabled state drawable ShapeDrawable checkedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(outerR, null, null)); checkedDisabledFrontCore.Paint.Color = theme.VeryLightAccentColor; InsetDrawable checkedDisabledFront = new InsetDrawable(checkedDisabledFrontCore, 5); ShapeDrawable checkedDisabledBack = new ShapeDrawable(new RoundRectShape(outerR, null, null)); checkedDisabledBack.Paint.Color = Color.ParseColor("#f2f2f2"); checkedDisabledBack.SetPadding(size / 2 * 5, 0, 0, 0); Drawable[] d4 = {checkedDisabledBack, checkedDisabledFront}; LayerDrawable checkedDisabled = new LayerDrawable(d4); toggleButton.SetPadding(0, padding, 0, padding); PaintDrawable paintDrawable = new PaintDrawable(theme.BackgroundColor); paintDrawable.SetIntrinsicHeight(size); paintDrawable.SetIntrinsicWidth(size); paintDrawable.SetPadding(size, 0, 0, 0); StateListDrawable states = new StateListDrawable(); states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled}, new InsetDrawable(uncheckedEnabled, padding * 2)); states.AddState(new int[]{Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled}, new InsetDrawable(checkedEnabled, padding * 2)); states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled}, new InsetDrawable(uncheckedDisabled, padding * 2)); states.AddState(new int[]{Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled}, new InsetDrawable(checkedDisabled, padding * 2)); toggleButton.SetBackgroundDrawable(states); toggleButton.SetTextSize(ComplexUnitType.Sp, 0); }
public EllipseDrawableView(Context context) : base(context) { drawable = new ShapeDrawable(new OvalShape()); }
public static void SetTheme(EditText editText, FlatTheme theme, FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, FlatUI.FlatTextAppearance textAppearance, int style, int radius, int padding, int border) { float[] outerR = new float[]{radius, radius, radius, radius, radius, radius, radius, radius}; // creating normal state drawable var normalFront = new ShapeDrawable(new RoundRectShape(outerR, null, null)); normalFront.SetPadding(padding, padding, padding, padding); var normalBack = new ShapeDrawable(new RoundRectShape(outerR, null, null)); normalBack.SetPadding(border, border, border, border); if (style == 0) { // flat normalFront.Paint.Color = Color.Transparent; normalBack.Paint.Color = theme.LightAccentColor; editText.SetTextColor(theme.VeryLightAccentColor); } else if (style == 1) { // box normalFront.Paint.Color = Color.White; normalBack.Paint.Color = theme.LightAccentColor; editText.SetTextColor(theme.BackgroundColor); } else if (style == 2) { // transparent normalFront.Paint.Color = Color.Transparent; normalBack.Paint.Color = Color.Transparent; editText.SetTextColor(theme.BackgroundColor); } Drawable[] d = {normalBack, normalFront}; LayerDrawable normal = new LayerDrawable(d); editText.SetBackgroundDrawable(normal); editText.SetHintTextColor(theme.VeryLightAccentColor); if (textAppearance == FlatUI.FlatTextAppearance.Dark) editText.SetTextColor(theme.DarkAccentColor); else if (textAppearance == FlatUI.FlatTextAppearance.Light) editText.SetTextColor(theme.VeryLightAccentColor); var typeface = FlatUI.GetFont(editText.Context, fontFamily, fontWeight); if (typeface != null) editText.SetTypeface(typeface, TypefaceStyle.Normal); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // Gain Access to all views and controls in our layout leftTray = FindViewById<UIActionTray> (Resource.Id.trayLeft); rightTray = FindViewById<UIActionTray> (Resource.Id.trayRight); toolsTray = FindViewById<UIActionTray> (Resource.Id.trayTools); propertyTray = FindViewById<UIActionTray> (Resource.Id.trayProperty); paletteTray = FindViewById<UIActionTray> (Resource.Id.trayPalette); documentTray = FindViewById<UIActionTray> (Resource.Id.trayDocuments); // Create a TrayManager to handle a collection of "palette" // trays. It will automatically close any open tray when // another tray in this collection is opened. trayManager = new UIActionTrayManager (); // Automatically close the left and right trays when any tray // in the manager's collection is opened trayManager.TrayOpened += (tray) => { // Animate the trays being closed leftTray.CloseTray (true); rightTray.CloseTray (true); }; // Setup the left side tray leftTray.trayType = UIActionTrayType.Draggable; leftTray.orientation = UIActionTrayOrientation.Left; leftTray.tabLocation = UIActionTrayTabLocation.BottomOrRight; leftTray.frameType = UIActionTrayFrameType.EdgeOnly; leftTray.tabType = UIActionTrayTabType.IconAndTitle; leftTray.bringToFrontOnTouch=true; // Style tray leftTray.appearance.background = Color.Gray; leftTray.appearance.border = Color.Red; leftTray.icon = Resource.Drawable.icon_calendar; leftTray.title = "Events"; leftTray.appearance.tabAlpha=100; leftTray.CloseTray (false); // Respond to the left tray being touched leftTray.Touched+= (tray) => { //Yes, close this tray and aminate the closing rightTray.CloseTray (true); // Tell any open palette trays to close trayManager.CloseAllTrays (); // Close document tray documentTray.CloseTray (true); }; // Setup the right side tray rightTray.trayType = UIActionTrayType.Popup; rightTray.orientation = UIActionTrayOrientation.Right; rightTray.bringToFrontOnTouch = true; rightTray.CloseTray (false); // Respond to the tray being opened rightTray.Opened+= (tray) => { //Close this tray and aminate the closing leftTray.CloseTray (true); // Tell any open palette trays to close trayManager.CloseAllTrays (); // Close document tray documentTray.CloseTray (true); }; // Set tray type documentTray.trayType = UIActionTrayType.AutoClosingPopup; documentTray.orientation = UIActionTrayOrientation.Bottom; documentTray.tabType = UIActionTrayTabType.GripAndTitle; documentTray.bringToFrontOnTouch=true; // Style tray documentTray.tabWidth = 125; documentTray.appearance.background = Color.Gray; documentTray.title = "Documents"; documentTray.CloseTray (false); // Respond to the tray being opened documentTray.Opened += (tray) => { // Close left and right trays leftTray.CloseTray(true); rightTray.CloseTray(true); }; //-------------------------------------------------------------------------------------- // Create three action tray's and use them as a collection via an ActionTrayManager //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- // Palette 1 // Set tray type paletteTray.trayType = UIActionTrayType.AutoClosingPopup; paletteTray.orientation = UIActionTrayOrientation.Top; paletteTray.tabLocation = UIActionTrayTabLocation.TopOrLeft; paletteTray.tabType = UIActionTrayTabType.IconAndTitle; paletteTray.CloseTray (false); // Style tray paletteTray.tabWidth = 125; paletteTray.appearance.background = Color.Gray; paletteTray.icon = Resource.Drawable.icon_palette; paletteTray.title="Palette"; // Add this tray to the manager's collection trayManager.AddTray (paletteTray); //-------------------------------------------------------------------------------------- // Palette 2 // Setup property tray type propertyTray.trayType = UIActionTrayType.Popup; propertyTray.orientation = UIActionTrayOrientation.Top; propertyTray.tabLocation = UIActionTrayTabLocation.TopOrLeft; propertyTray.tabType = UIActionTrayTabType.IconAndTitle; propertyTray.CloseTray (false); // Style tray propertyTray.tabWidth = 125; propertyTray.appearance.background = Color.Rgb (38,38,38); propertyTray.icon=Resource.Drawable.icon_measures; propertyTray.title="Properties"; // Add this tray to the manager's collection trayManager.AddTray (propertyTray); //-------------------------------------------------------------------------------------- // Palette 3 // Setup tools tray type toolsTray.trayType = UIActionTrayType.AutoClosingPopup; toolsTray.orientation = UIActionTrayOrientation.Top; toolsTray.tabType = UIActionTrayTabType.IconOnly; toolsTray.CloseTray (false); // Style tools tray toolsTray.tabWidth = 50; toolsTray.tabLocation = UIActionTrayTabLocation.BottomOrRight; toolsTray.appearance.background = Color.Rgb (38,38,38); toolsTray.tabType = UIActionTrayTabType.CustomDrawn; toolsTray.icon = Resource.Drawable.icon_pencil; // Custom draw this tab toolsTray.CustomDrawDragTab += (tray, canvas, rect) => { //Draw background var body= new ShapeDrawable(new RectShape()); body.Paint.Color=tray.appearance.background; body.SetBounds (rect.Left, rect.Top, rect.Right, rect.Bottom); body.Draw (canvas); //Define icon paint var iPaint=new Paint(); iPaint.Alpha=tray.appearance.tabAlpha; //Load bitmap var bitmap=BitmapFactory.DecodeResource(Resources,tray.icon); //Draw image canvas.DrawBitmap (bitmap, rect.Left+1, rect.Top+5, iPaint); }; // Add this tray to the manager's collection trayManager.AddTray (toolsTray); }