public override Object InstantiateItem(ViewGroup container, int position) { var reusePosition = position % CachedPagesCount; if (_photoHolders[reusePosition] == null) { var photoCard = new CardView(_context) { LayoutParameters = _layoutParams }; if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Lollipop) { photoCard.Elevation = 0; } var photo = new ImageView(_context) { LayoutParameters = _layoutParams }; photo.SetImageDrawable(null); photo.SetScaleType(ImageView.ScaleType.CenterCrop); photo.Click += PhotoOnClick; photoCard.AddView(photo); _photoHolders[reusePosition] = photoCard; } container.AddView(_photoHolders[reusePosition]); LoadPhoto(_post.Media[position], _photoHolders[reusePosition]); return(_photoHolders[reusePosition]); }
internal static ViewGroup SetViewAppearance(ExtraView formsView, ViewGroup nativeView) { if (formsView.CornerRadius > 0 && formsView.BorderWidth > 0) { var wrapper = new CardView(Context); wrapper.Radius = Context.ToPixels(formsView.CornerRadius); wrapper.SetCardBackgroundColor(formsView.BorderColor.ToAndroid()); wrapper.CardElevation = 0; var borderW = (int)Context.ToPixels(formsView.BorderWidth); wrapper.SetContentPadding(borderW, borderW, borderW, borderW); wrapper.SetClipChildren(true); var inner = nativeView; var border = new GradientDrawable(); var innerRadius = Math.Max(formsView.CornerRadius - formsView.BorderWidth, 0); border.SetCornerRadius(Context.ToPixels(innerRadius)); if (!formsView.BackgroundColor.IsDefault) { border.SetColor(formsView.BackgroundColor.ToAndroid()); } inner.SetBackground(border); inner.ClipToOutline = true; wrapper.AddView(inner); return(wrapper); } if (formsView.CornerRadius > 0 || formsView.BorderWidth > 0) { var border = new GradientDrawable(); if (formsView.CornerRadius > 0) { border.SetCornerRadius(Context.ToPixels(formsView.CornerRadius)); } if (!formsView.BackgroundColor.IsDefault) { border.SetColor(formsView.BackgroundColor.ToAndroid()); } if (formsView.BorderWidth > 0) { var borderW = (int)Context.ToPixels(formsView.BorderWidth); border.SetStroke(borderW, formsView.BorderColor.ToAndroid()); nativeView.SetPadding(borderW, borderW, borderW, borderW); } nativeView.SetBackground(border); nativeView.ClipToOutline = true; } return(nativeView); }
void Initialize() { var padding = PixelConverter.DpToPixels(8); SetPadding(padding, padding, padding, 0); CardView card = new CardView(_context); card.LayoutParameters = new CardView.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); card.SetForegroundGravity(GravityFlags.CenterHorizontal); card.Radius = PixelConverter.DpToPixels(6); card.CardElevation = PixelConverter.DpToPixels(4); card.SetCardBackgroundColor(Resource.Color.accent); LinearLayout layoutHolder = new LinearLayout(_context); layoutHolder.Orientation = Orientation.Vertical; layoutHolder.LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); layoutHolder.SetPadding(padding, padding, padding, padding); layoutHolder.SetBackgroundResource(Resource.Color.accent); TextView titleDisplay = new TextView(_context) { Text = _ack.Title }; titleDisplay.Gravity = GravityFlags.CenterVertical; titleDisplay.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); titleDisplay.SetTextSize(ComplexUnitType.Dip, 20); titleDisplay.SetTypeface(Android.Graphics.Typeface.DefaultBold, Android.Graphics.TypefaceStyle.Bold); titleDisplay.SetTextColor(Android.Graphics.Color.AntiqueWhite); layoutHolder.AddView(titleDisplay); TextView descriptionDisplay = new TextView(_context) { Text = _ack.Description }; descriptionDisplay.Gravity = GravityFlags.CenterVertical; descriptionDisplay.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); descriptionDisplay.SetTextSize(ComplexUnitType.Dip, 14); descriptionDisplay.SetTypeface(Android.Graphics.Typeface.Default, Android.Graphics.TypefaceStyle.Normal); descriptionDisplay.SetTextColor(Android.Graphics.Color.AntiqueWhite); layoutHolder.AddView(descriptionDisplay); card.AddView(layoutHolder); AddView(card); }
protected override void OnElementChanged(ElementChangedEventArgs <CameraView> e) { base.OnElementChanged(e); if (e.NewElement != null) { if (Control == null) { var cardView = new CardView(Context); cardView.SetCardBackgroundColor(e.NewElement.BackgroundColor.ToAndroid()); cameraPreview = new TextureView(Context); cardView.AddView(cameraPreview); SetNativeControl(cardView); } cameraPreview.SurfaceTextureListener = surfaceTextureListener; } }
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { var cardView = new CardView(parent.Context) { LayoutParameters = new FrameLayout.LayoutParams(parent.Height, parent.Height), Radius = BitmapUtils.DpToPixel(5, parent.Resources) }; var image = new ImageView(parent.Context) { Id = Resource.Id.photo, LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) }; image.SetScaleType(ImageView.ScaleType.CenterCrop); cardView.AddView(image); return(new GalleryViewHolder(cardView)); }
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { var maxWidth = Style.GalleryHorizontalScreenWidth; var maxHeight = Style.GalleryHorizontalHeight; var previewSize = BitmapUtils.CalculateImagePreviewSize(_postMedia[0].Size.Width, _postMedia[0].Size.Height, maxWidth, maxHeight); var cardView = new CardView(parent.Context) { LayoutParameters = new FrameLayout.LayoutParams(previewSize.Width, previewSize.Height), Radius = BitmapUtils.DpToPixel(5, parent.Resources) }; var image = new ImageView(parent.Context) { Id = Resource.Id.photo, LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) }; image.SetScaleType(ImageView.ScaleType.FitXy); cardView.AddView(image); return(new MediaViewHolder(cardView)); }
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { var width = (int)Math.Round(((Android.App.Activity)parent.Context).WindowManager.DefaultDisplay.Width - BitmapUtils.DpToPixel(25, parent.Resources)); var height = (int)Math.Round(BitmapUtils.DpToPixel(160, parent.Resources)); var previewSize = _gallery == null? ViewUtils.CalculateImagePreviewSize(_postMedia[0].Size.Width, _postMedia[0].Size.Height, width, height) : ViewUtils.CalculateImagePreviewSize(_gallery[0].PreparedBitmap.Width, _gallery[0].PreparedBitmap.Height, width, height); var cardView = new CardView(parent.Context) { LayoutParameters = new FrameLayout.LayoutParams(previewSize.Width, previewSize.Height), Radius = BitmapUtils.DpToPixel(5, parent.Resources) }; var image = new ImageView(parent.Context) { Id = Resource.Id.photo, LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) }; image.SetScaleType(ImageView.ScaleType.FitXy); cardView.AddView(image); return(new GalleryViewHolder(cardView)); }
protected virtual void LoadView(SearchHandler searchHandler) { var query = searchHandler.Query; var placeholder = searchHandler.Placeholder; LP lp; var context = Context; _cardView = new CardView(context); using (lp = new LayoutParams(LP.MatchParent, LP.MatchParent)) _cardView.LayoutParameters = lp; var linearLayout = new LinearLayout(context); using (lp = new LP(LP.MatchParent, LP.MatchParent)) linearLayout.LayoutParameters = lp; linearLayout.Orientation = Orientation.Horizontal; _cardView.AddView(linearLayout); int padding = (int)context.ToPixels(8); _searchButton = CreateImageButton(context, searchHandler, SearchHandler.QueryIconProperty, Resource.Drawable.abc_ic_search_api_material, padding, 0); lp = new LinearLayout.LayoutParams(0, LP.MatchParent) { Gravity = GravityFlags.Fill, Weight = 1 }; _textBlock = new AppCompatAutoCompleteTextView(context) { LayoutParameters = lp, Text = query, Hint = placeholder, ImeOptions = ImeAction.Done }; lp.Dispose(); _textBlock.Enabled = searchHandler.IsSearchEnabled; _textBlock.SetBackground(null); _textBlock.SetPadding(padding, 0, padding, 0); _textBlock.SetSingleLine(true); _textBlock.Threshold = 1; _textBlock.Adapter = new ShellSearchViewAdapter(SearchHandler, _shellContext); _textBlock.ItemClick += OnTextBlockItemClicked; _textBlock.SetDropDownBackgroundDrawable(new ClipDrawableWrapper(_textBlock.DropDownBackground)); // A note on accessibility. The _textBlocks hint is what android defaults to reading in the screen // reader. Therefor we do not need to set something else. _clearButton = CreateImageButton(context, searchHandler, SearchHandler.ClearIconProperty, Resource.Drawable.abc_ic_clear_material, 0, padding); _clearPlaceholderButton = CreateImageButton(context, searchHandler, SearchHandler.ClearPlaceholderIconProperty, -1, 0, padding); linearLayout.AddView(_searchButton); linearLayout.AddView(_textBlock); linearLayout.AddView(_clearButton); linearLayout.AddView(_clearPlaceholderButton); UpdateClearButtonState(); // hook all events down here to avoid getting events while doing setup searchHandler.PropertyChanged += OnSearchHandlerPropertyChanged; _textBlock.AddTextChangedListener(this); _textBlock.SetOnEditorActionListener(this); _clearButton.Click += OnClearButtonClicked; _clearPlaceholderButton.Click += OnClearPlaceholderButtonClicked; _searchButton.Click += OnSearchButtonClicked; AddView(_cardView); linearLayout.Dispose(); }
/// <summary> /// 标注点击时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnMarkerClick(object sender, BaiduMap.MarkerClickEventArgs e) { try { if (!string.IsNullOrEmpty(e.P0.Title)) { var pin = Map.Pins.Find(e.P0); if (pin?.Terminal != null) { var color = pin?.Terminal?.RankColor ?? "#4a89dc"; //cardView var cardView = new CardView(Context) { Radius = 15 }; cardView.SetCardBackgroundColor(Color.FromHex(color).ToAndroid()); //布局 var layout = new LinearLayout(Context) { Orientation = Orientation.Vertical }; layout.SetPadding(10, 10, 10, 10); //Title var tview = new TextView(Context); tview.SetPadding(10, 10, 10, 10); tview.SetTextColor(Color.White.ToAndroid()); tview.TextSize = 12; tview.Text = e.P0.Title; //Button var param = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent) { Height = 45 }; var button = new Android.Widget.Button(Context); button.Text = "去拜访"; button.TextSize = 10; button.LayoutParameters = param; button.SetBackgroundResource(Resource.Drawable.roundShape); button.SetTextColor(Color.White.ToAndroid()); button.Click += (sender, ar) => { var pin = Map.Pins.Find(e.P0); pin?.SendClicked(pin?.Terminal); }; layout.AddView(tview); layout.AddView(button); cardView.AddView(layout); var window = new InfoWindow(cardView, e.P0.Position, -e.P0.Icon.Bitmap.Height); NativeMap.Map.ShowInfoWindow(window); } } } catch (Exception) { } }
private CardView CreateCardViewScheme1(string symbol, string description, string chgText, string timeText, string valueText, string numberOfCoinsText, string priceText, Color chgColor, int changeIcon) { CardView cardView = new CardView(Context); int cardViewWidth; //175 cardViewWidth = (GetScreenWidthInPixels() - DpToPixels(6)) / 2; //210 GridLayout.LayoutParams gridLayoutParams = new GridLayout.LayoutParams(); gridLayoutParams.Width = cardViewWidth; gridLayoutParams.Height = DpToPixels(170); gridLayoutParams.LeftMargin = DpToPixels(2); gridLayoutParams.RightMargin = DpToPixels(2); gridLayoutParams.TopMargin = DpToPixels(2); RelativeLayout rl = new RelativeLayout(cardView.Context); cardView.Tag = new Identifier(symbol); cardView.AddView(rl); GestureDetector _gestureDetector = new GestureDetector(cardView.Context, new GestureListener()); _gestureDetector.DoubleTap += (object sender, GestureDetector.DoubleTapEventArgs e) => { //apply double tap code here //var activity = (MainActivity)this.Activity; //activity.DisplayCandleChart(symbolDoubleTapped); Toast.MakeText(Context, "Double click", ToastLength.Short).Show(); }; cardView.Touch += (object sender, View.TouchEventArgs e) => { CardView cv = sender as CardView; if (cv != null) { symbolDoubleTapped = ((Identifier)cv.Tag).Name; } _gestureDetector.OnTouchEvent(e.Event); }; Button topColorStripe = new Button(cardView.Context); //topColorStripe.SetBackgroundColor(CryptoCoinColors.GetCryptoCoinColor(symbol)); RelativeLayout.LayoutParams lpbb = CreateRelativeLayoutParams(); lpbb.Width = ViewGroup.LayoutParams.MatchParent; lpbb.Height = DpToPixels(6); topColorStripe.LayoutParameters = lpbb; topColorStripe.Id = 100; rl.AddView(topColorStripe); TextView symTV = CreateTextViewEx(symbol, Color.Black, 30, TypefaceStyle.Bold, cardView.Context); //symTV.LayoutParameters = CreateRelativeLayoutParams(); RelativeLayout.LayoutParams lps = CreateRelativeLayoutParams(); lps.AddRule(LayoutRules.Below, topColorStripe.Id); symTV.LayoutParameters = lps; symTV.Id = CARDVIEW_SYMBOL_TEXT_VIEW_ID; rl.AddView(symTV); ImageView iv = new ImageView(cardView.Context); RelativeLayout.LayoutParams lpi = CreateRelativeLayoutParams(); lpi.AddRule(LayoutRules.RightOf, symTV.Id); lpi.AddRule(LayoutRules.AlignTop, symTV.Id); lpi.TopMargin = DpToPixels(5); iv.LayoutParameters = lpi; iv.SetImageResource(changeIcon); iv.Id = CARDVIEW_IMAGE_UP_DOWN_ID; rl.AddView(iv); TextView descTV = CreateTextViewEx(description, Color.Gray, 12, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpd = CreateRelativeLayoutParams(); lpd.AddRule(LayoutRules.Below, symTV.Id); lpd.LeftMargin = DpToPixels(2); lpd.TopMargin = DpToPixels(-10); descTV.LayoutParameters = lpd; descTV.Id = CARDVIEW_DESCRIPTION_TEXT_VIEW_ID; rl.AddView(descTV); TextView chgTV = CreateTextViewEx(chgText, chgColor, 12, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpc = CreateRelativeLayoutParams(); lpc.AddRule(LayoutRules.RightOf, iv.Id); lpc.AddRule(LayoutRules.AlignTop, iv.Id); lpc.TopMargin = DpToPixels(2); chgTV.LayoutParameters = lpc; chgTV.Id = CARDVIEW_CHANGE_TEXT_VIEW_ID; rl.AddView(chgTV); TextView timeTV = CreateTextViewEx(timeText, Color.Gray, 8, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpt = CreateRelativeLayoutParams(); lpt.AddRule(LayoutRules.Below, chgTV.Id); lpt.AddRule(LayoutRules.AlignLeft, chgTV.Id); timeTV.LayoutParameters = lpt; timeTV.Id = CARDVIEW_LAST_UPDATE_TEXT_VIEW_ID; rl.AddView(timeTV); TextView valueLabelTV = CreateTextViewEx("Value", Color.Gray, 10, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpvl = CreateRelativeLayoutParams(); lpvl.AddRule(LayoutRules.Below, descTV.Id); lpvl.LeftMargin = DpToPixels(2); lpvl.TopMargin = DpToPixels(17); valueLabelTV.LayoutParameters = lpvl; valueLabelTV.Id = CARDVIEW_VALUE_LABEL_TEXT_VIEW_ID; rl.AddView(valueLabelTV); TextView valueTV = CreateTextViewEx(valueText, Color.ParseColor("#EFCC00"), 22, TypefaceStyle.Bold, cardView.Context); RelativeLayout.LayoutParams lpv = CreateRelativeLayoutParams(); lpv.AddRule(LayoutRules.Below, valueLabelTV.Id); lpv.LeftMargin = DpToPixels(2); lpv.TopMargin = DpToPixels(-3); valueTV.LayoutParameters = lpv; valueTV.Id = CARDVIEW_VALUE_TEXT_VIEW_ID; rl.AddView(valueTV); TextView coinsLabelTV = CreateTextViewEx("Number of coins", Color.Gray, 10, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpnc = CreateRelativeLayoutParams(); lpnc.AddRule(LayoutRules.Below, valueTV.Id); lpnc.LeftMargin = DpToPixels(2); lpnc.TopMargin = DpToPixels(2); coinsLabelTV.LayoutParameters = lpnc; coinsLabelTV.Id = CARDVIEW_NUMBER_OF_COINS_LABEL_TEXT_VIEW_ID; rl.AddView(coinsLabelTV); TextView coinsTV = CreateTextViewEx(numberOfCoinsText, Color.Black, 12, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpcv = CreateRelativeLayoutParams(); lpcv.AddRule(LayoutRules.Below, coinsLabelTV.Id); lpcv.LeftMargin = DpToPixels(2); lpnc.TopMargin = DpToPixels(-1); coinsTV.LayoutParameters = lpcv; coinsTV.Id = CARDVIEW_NUMBER_OF_COINS_TEXT_VIEW_ID; rl.AddView(coinsTV); TextView priceTV = CreateTextViewEx(priceText, chgColor, 14, TypefaceStyle.Bold, cardView.Context); RelativeLayout.LayoutParams lpp = CreateRelativeLayoutParams(); lpp.AddRule(LayoutRules.Below, descTV.Id); lpp.LeftMargin = DpToPixels(2); lpp.TopMargin = DpToPixels(-5); priceTV.LayoutParameters = lpp; priceTV.Id = CARDVIEW_PRICE_TEXT_VIEW_ID; rl.AddView(priceTV); Android.Widget.Toolbar tb = new Android.Widget.Toolbar(cardView.Context); RelativeLayout.LayoutParams lpb = CreateRelativeLayoutParams(); lpb.AddRule(LayoutRules.Below, coinsTV.Id); lpb.TopMargin = -15; tb.Tag = new Identifier(symbol); tb.InflateMenu(Resource.Menu.CardToolbarMenu); tb.MenuItemClick += (sender, e) => { Android.Widget.Toolbar tbx = sender as Android.Widget.Toolbar; string sym = ((Identifier)tb.Tag).Name; var activity = (MainActivity)this.Activity; switch (e.Item.ItemId) { case (Resource.Id.cardmenu_qrcode): activity.ShowCryptoCurrencyAddressFragment(sym); break; case (Resource.Id.cardmenu_chart): activity.ShowCandleFragment(sym); break; case (Resource.Id.cardmenu_transactions): activity.ShowTransactionFragment(sym); break; case (Resource.Id.cardmenu_send): activity.ShowSendFragment(sym); break; case (Resource.Id.cardmenu_receive): activity.ShowReceiveFragment(sym); break; default: break; } }; tb.LayoutParameters = lpb; tb.Id = 11; rl.AddView(tb); cardView.LayoutParameters = gridLayoutParams; return(cardView); }
private CardView CreateCardViewScheme2(string symbol, string description, string numberOfCoinsText, string valueText, string priceText, Color chgColor) { CardView cardView = new CardView(Context); int cardViewWidth; cardViewWidth = (GetScreenWidthInPixels() - DpToPixels(6)) / 2; GridLayout.LayoutParams gridLayoutParams = new GridLayout.LayoutParams(); gridLayoutParams.Width = cardViewWidth; gridLayoutParams.Height = DpToPixels(170); gridLayoutParams.LeftMargin = DpToPixels(2); gridLayoutParams.RightMargin = DpToPixels(2); gridLayoutParams.TopMargin = DpToPixels(2); RelativeLayout rl = new RelativeLayout(cardView.Context); cardView.Tag = new Identifier(symbol); cardView.AddView(rl); Button topColorStripe = new Button(cardView.Context); topColorStripe.SetBackgroundColor(Color.Aqua); RelativeLayout.LayoutParams lpbb = CreateRelativeLayoutParams(); lpbb.Width = ViewGroup.LayoutParams.MatchParent; lpbb.Height = DpToPixels(6); topColorStripe.LayoutParameters = lpbb; topColorStripe.Id = 1; rl.AddView(topColorStripe); TextView symTV = CreateTextViewEx(symbol, Color.Black, 30, TypefaceStyle.Bold, cardView.Context); RelativeLayout.LayoutParams lps = CreateRelativeLayoutParams(); lps.AddRule(LayoutRules.Below, topColorStripe.Id); symTV.LayoutParameters = lps; symTV.Id = 2; rl.AddView(symTV); TextView descTV = CreateTextViewEx(description, Color.Gray, 12, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpd = CreateRelativeLayoutParams(); lpd.AddRule(LayoutRules.RightOf, symTV.Id); lpd.LeftMargin = DpToPixels(2); lpd.TopMargin = DpToPixels(20); descTV.LayoutParameters = lpd; descTV.Id = 3; rl.AddView(descTV); TextView coinsLabelTV = CreateTextViewEx("Coins", Color.Gray, 10, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpnc = CreateRelativeLayoutParams(); lpnc.AddRule(LayoutRules.Below, symTV.Id); lpnc.LeftMargin = DpToPixels(2); lpnc.TopMargin = DpToPixels(2); coinsLabelTV.LayoutParameters = lpnc; coinsLabelTV.Id = 4; rl.AddView(coinsLabelTV); TextView coinsTV = CreateTextViewEx(numberOfCoinsText, Color.Black, 12, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpcv = CreateRelativeLayoutParams(); lpcv.AddRule(LayoutRules.Below, coinsLabelTV.Id); lpcv.LeftMargin = DpToPixels(2); coinsTV.LayoutParameters = lpcv; coinsTV.Id = 5; rl.AddView(coinsTV); TextView valueLabelTV = CreateTextViewEx("Value", Color.Gray, 10, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpvl = CreateRelativeLayoutParams(); lpvl.AddRule(LayoutRules.Below, coinsTV.Id); lpvl.LeftMargin = DpToPixels(2); lpvl.TopMargin = DpToPixels(2); valueLabelTV.LayoutParameters = lpvl; valueLabelTV.Id = 6; rl.AddView(valueLabelTV); TextView valueTV = CreateTextViewEx(valueText, Color.ParseColor("#EFCC00"), 22, TypefaceStyle.Bold, cardView.Context); RelativeLayout.LayoutParams lpv = CreateRelativeLayoutParams(); lpv.AddRule(LayoutRules.Below, valueLabelTV.Id); lpv.LeftMargin = DpToPixels(2); valueTV.LayoutParameters = lpv; valueTV.Id = 7; rl.AddView(valueTV); TextView priceLabelTV = CreateTextViewEx("Price", Color.Gray, 10, TypefaceStyle.Normal, cardView.Context); RelativeLayout.LayoutParams lpvp = CreateRelativeLayoutParams(); lpvp.AddRule(LayoutRules.Below, valueTV.Id); lpvp.LeftMargin = DpToPixels(2); lpvp.TopMargin = DpToPixels(2); priceLabelTV.LayoutParameters = lpvp; priceLabelTV.Id = 8; rl.AddView(priceLabelTV); TextView priceTV = CreateTextViewEx(priceText, chgColor, 14, TypefaceStyle.Bold, cardView.Context); RelativeLayout.LayoutParams lpp = CreateRelativeLayoutParams(); lpp.AddRule(LayoutRules.Below, priceLabelTV.Id); lpp.LeftMargin = DpToPixels(2); lpp.TopMargin = DpToPixels(2); priceTV.LayoutParameters = lpp; priceTV.Id = 9; rl.AddView(priceTV); cardView.LayoutParameters = gridLayoutParams; return(cardView); }
private CardView CreateCard(Drawable image, string value, string measureType, string hour, LinearLayoutCompat.LayoutParams layoutParams) { var cardView = new CardView(this) { LayoutParameters = layoutParams }; cardView.SetCardBackgroundColor(Resources.GetColor(Resource.Color.colorPrimaryDark, Theme)); var rlContent = new RelativeLayout(this); var tvHour = new TextView(this) { Id = 4 }; var tvBloodPressure = new TextView(this) { Id = 2 }; var tvMmHg = new TextView(this) { Id = 3 }; var imIcon = new ImageView(this) { Id = 1 }; var rlParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); var tvHourParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { TopMargin = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, Resources.DisplayMetrics) }; tvHourParams.AddRule(LayoutRules.AlignParentRight); var tvBloodPressureParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { MarginStart = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, Resources.DisplayMetrics) }; tvBloodPressureParams.AddRule(LayoutRules.AlignParentTop); tvBloodPressureParams.AddRule(LayoutRules.RightOf, imIcon.Id); var tvMmHgParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { MarginStart = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 3, Resources.DisplayMetrics), TopMargin = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, Resources.DisplayMetrics) }; tvMmHgParams.AddRule(LayoutRules.RightOf, tvBloodPressure.Id); var tvIconParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { Width = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 30, Resources.DisplayMetrics), Height = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 30, Resources.DisplayMetrics), TopMargin = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 3, Resources.DisplayMetrics) }; rlContent.SetPadding((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 16, Resources.DisplayMetrics), (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 16, Resources.DisplayMetrics), (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 16, Resources.DisplayMetrics), (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 16, Resources.DisplayMetrics)); rlContent.LayoutParameters = rlParams; tvHour.LayoutParameters = tvHourParams; tvHour.Text = hour; tvHour.SetTextSize(ComplexUnitType.Sp, 16); tvHour.SetTextColor(Color.White); tvBloodPressure.LayoutParameters = tvBloodPressureParams; tvBloodPressure.Text = value; tvBloodPressure.SetTextSize(ComplexUnitType.Sp, 28); tvBloodPressure.SetTextColor(Resources.GetColor(Resource.Color.accent, Theme)); tvBloodPressure.SetTypeface(tvBloodPressure.Typeface, TypefaceStyle.Bold); tvMmHg.LayoutParameters = tvMmHgParams; tvMmHg.Text = measureType; tvMmHg.SetTextSize(ComplexUnitType.Sp, 18); tvMmHg.SetTextColor(Resources.GetColor(Resource.Color.colorSecondary, Theme)); imIcon.LayoutParameters = tvIconParams; imIcon.SetImageDrawable(image); imIcon.SetColorFilter(Color.White); rlContent.AddView(imIcon); rlContent.AddView(tvBloodPressure); rlContent.AddView(tvMmHg); rlContent.AddView(tvHour); cardView.AddView(rlContent); return(cardView); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); DrawerLayout drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close); drawer.AddDrawerListener(toggle); toggle.SyncState(); NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view); navigationView.SetNavigationItemSelectedListener(this); BottomNavigationView navigation = FindViewById <BottomNavigationView>(Resource.Id.navigation); navigation.SetOnNavigationItemSelectedListener(this); AssetManager assets = this.Assets; using (StreamReader sr = new StreamReader(assets.Open("special.json"))) { var json = sr.ReadToEnd(); var rootobject_special = JsonConvert.DeserializeObject <SpecialDefualt.Rootobject>(json); special = rootobject_special.special; } using (StreamReader sr = new StreamReader(assets.Open("perks.json"))) { var json = sr.ReadToEnd(); var rootobject_perks = JsonConvert.DeserializeObject <PerksDefualt.Rootobject>(json); perks = rootobject_perks.perks; } using (var writer = new System.IO.StringWriter()) { //count_special int c_s = 0; foreach (var c in special) { var layout_main = FindViewById <LinearLayout>(Resource.Id.add_layout_special); CardView.LayoutParams layout_card_par = new CardView.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); layout_card_par.SetMargins(30, 30, 30, 30); LinearLayout layout_card = new LinearLayout(this) { Orientation = Android.Widget.Orientation.Vertical, LayoutParameters = layout_card_par }; CardView.LayoutParams card_par = new CardView.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); card_par.SetMargins(30, 30, 30, 30); CardView card = new CardView(this) { LayoutParameters = card_par, }; card.SetCardBackgroundColor(Android.Graphics.Color.Black); var special_name = new TextView(this) { Text = special[c_s].Info[0].ToString() }; special_name.SetTextColor(Android.Graphics.Color.LimeGreen); special_name.SetTextSize(ComplexUnitType.Px, 100); var special_description = new TextView(this) { Text = special[c_s].ToString() }; special_description.SetTextColor(Android.Graphics.Color.LimeGreen); LinearLayout.LayoutParams par_layout_buttons = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { Gravity = GravityFlags.Right }; LinearLayout layout_buttons = new LinearLayout(this) { Orientation = Android.Widget.Orientation.Horizontal, LayoutParameters = par_layout_buttons }; var button1 = new ImageButton(this) { ContentDescription = c_s.ToString() }; button1.SetImageResource(Resource.Drawable.arrow_left); button1.SetBackgroundColor(Android.Graphics.Color.LimeGreen); var button2 = new ImageButton(this) { }; button2.SetImageResource(Resource.Drawable.arrow_right); button2.SetBackgroundColor(Android.Graphics.Color.LimeGreen); var editText1 = new EditText(this) { Text = special[c_s].Data[0].ToString() }; editText1.SetTextColor(Android.Graphics.Color.LimeGreen); layout_card.AddView(special_name); layout_card.AddView(special_description); layout_buttons.AddView(button1); layout_buttons.AddView(editText1); layout_buttons.AddView(button2); layout_card.AddView(layout_buttons); card.AddView(layout_card); layout_main.AddView(card); button1.Click += (o, e) => { var current = Int32.Parse(button1.ContentDescription); if (2 <= Int32.Parse(editText1.Text)) { editText1.Text = (Int32.Parse(editText1.Text) - 1).ToString(); special[current].assignedPoints -= 1; } }; button2.Click += (o, e) => { var current = Int32.Parse(button1.ContentDescription.ToString()); if (Int32.Parse(editText1.Text) <= 14) { editText1.Text = (Int32.Parse(editText1.Text) + 1).ToString(); special[current].assignedPoints += 1; } }; c_s += 1; } } using (var writer = new System.IO.StringWriter()) { //count_perks int c_p = 0; foreach (var c in perks) { var layout_main = FindViewById <LinearLayout>(Resource.Id.add_layout_special); CardView.LayoutParams layout_card_par = new CardView.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); layout_card_par.SetMargins(30, 30, 30, 30); LinearLayout layout_card = new LinearLayout(this) { Orientation = Android.Widget.Orientation.Vertical, LayoutParameters = layout_card_par }; CardView.LayoutParams card_par = new CardView.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); card_par.SetMargins(50, 0, 60, 60); CardView card = new CardView(this) { LayoutParameters = card_par }; card.SetCardBackgroundColor(Android.Graphics.Color.Black); var perk_name = new TextView(this) { Text = perks[c_p].Info[0][0].ToString() }; perk_name.SetTextColor(Android.Graphics.Color.LimeGreen); perk_name.SetTextSize(ComplexUnitType.Px, 100); var perk_description = new TextView(this) { Text = perks[c_p].Info[1][0].ToString() }; perk_description.SetTextColor(Android.Graphics.Color.LimeGreen); LinearLayout.LayoutParams par_layout_buttons = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { Gravity = GravityFlags.Right }; LinearLayout layout_buttons = new LinearLayout(this) { Orientation = Android.Widget.Orientation.Horizontal, LayoutParameters = par_layout_buttons }; var button1 = new ImageButton(this) { ContentDescription = perks[c_p].Data[1].ToString() + c_p.ToString() }; button1.SetImageResource(Resource.Drawable.arrow_left); button1.SetBackgroundColor(Android.Graphics.Color.LimeGreen); var button2 = new ImageButton(this) { ContentDescription = perks[c_p].Data[1].ToString() + c_p.ToString() }; button2.SetImageResource(Resource.Drawable.arrow_right); button2.SetBackgroundColor(Android.Graphics.Color.LimeGreen); var editText1 = new EditText(this) { Text = perks[c_p].Data[1].ToString() }; editText1.SetTextColor(Android.Graphics.Color.LimeGreen); var layoutParams = FindViewById <LinearLayout>(Resource.Id.add_layout_perks); layout_card.AddView(perk_name); layout_card.AddView(perk_description); layout_buttons.AddView(button1); layout_buttons.AddView(editText1); layout_buttons.AddView(button2); layout_card.AddView(layout_buttons); card.AddView(layout_card); layoutParams.AddView(card); var maxCardLevel = perks[c_p].Data[2]; var description = ""; foreach (int desc in perks[c_p].Info[1].ToString()) { description += desc; } button1.Click += (o, e) => { //count name and description var count = Int32.Parse(button1.ContentDescription[0].ToString()); var current = Int32.Parse(button1.ContentDescription[1].ToString()); if (1 <= Int32.Parse(editText1.Text)) { editText1.Text = (Int32.Parse(editText1.Text) - 1).ToString(); count -= 1; try { perk_name.Text = perks[current].Info[0][count].ToString(); perk_description.Text = perks[current].Info[1][count].ToString(); perks[current].assignedLevel -= 1; } catch { perk_name.Text = perks[current].Info[0][0].ToString(); perk_description.Text = perks[current].Info[1][count].ToString(); perks[current].assignedLevel -= 1; } button1.ContentDescription = count.ToString() + current.ToString(); } }; button2.Click += (o, e) => { //count name and description var count = Int32.Parse(button1.ContentDescription[0].ToString()); var current = Int32.Parse(button1.ContentDescription[1].ToString()); if (Int32.Parse(editText1.Text) <= maxCardLevel - 1) { editText1.Text = (Int32.Parse(editText1.Text) + 1).ToString(); try { perk_name.Text = perks[current].Info[0][count].ToString(); perk_description.Text = perks[current].Info[1][count].ToString(); perks[current].assignedLevel += 1; } catch { perk_name.Text = perks[current].Info[0][0].ToString(); perk_description.Text = perks[current].Info[1][count].ToString(); perks[current].assignedLevel += 1; } count += 1; button1.ContentDescription = count.ToString() + current.ToString(); } }; c_p += 1; } } videoView = FindViewById <VideoView>(Resource.Id.videoView1); var uri = Android.Net.Uri.Parse("android.resource://" + PackageName + "/" + Resource.Raw.fallout_76_video); videoView.SetVideoURI(uri); videoView.Visibility = ViewStates.Visible; MediaController media_controller = new Android.Widget.MediaController(this); //videoView.SetOnPreparedListener(new VideoLoop()); media_controller.SetMediaPlayer(videoView); videoView.SetMediaController(media_controller); videoView.RequestFocus(); var play_button = FindViewById <Button>(Resource.Id.play_button); var pause_button = FindViewById <Button>(Resource.Id.pause_button); var mute_button = FindViewById <Button>(Resource.Id.mute_button); var volume_seekBar = FindViewById <SeekBar>(Resource.Id.seek_bar); MediaPlayer player = MediaPlayer.Create(this, Resource.Raw.fallout_76_music); play_button.Click += (o, e) => { player.Start(); }; pause_button.Click += (o, e) => { player.Pause(); }; mute_button.Click += (o, e) => { player.SetVolume(0f, 0f); }; volume_seekBar.ProgressChanged += (o, e) => { float vol = (float)(Math.Log(volume_seekBar.Progress) / Math.Log(50)); player.SetVolume(vol, vol); }; var showPopupMenu = FindViewById <Button>(Resource.Id.popupButton); showPopupMenu.Click += (o, e) => { RelativeLayout layout_status = FindViewById <RelativeLayout>(Resource.Id.content_status); RelativeLayout layout_splash = FindViewById <RelativeLayout>(Resource.Id.content_splash); RelativeLayout layout_navigation = FindViewById <RelativeLayout>(Resource.Id.content_main); layout_splash.Visibility = ViewStates.Gone; layout_status.Visibility = ViewStates.Visible; layout_navigation.Visibility = ViewStates.Visible; }; /*var image_splash = FindViewById<ImageView>(Resource.Id.splash_image); * var Image = FindViewById<Image>(Resource.Raw.Fallout_76); * image_splash(Image);*/ Update_status(); }