void AddStatusBarUnderlay() { _statusBarUnderlay = new global::Android.Views.View(this); var layoutParameters = new ARelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, GetStatusBarHeight()) { AlignWithParent = true }; layoutParameters.AddRule(LayoutRules.AlignTop); _statusBarUnderlay.LayoutParameters = layoutParameters; _layout.AddView(_statusBarUnderlay); if (Forms.IsLollipopOrNewer) { Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); Window.SetStatusBarColor(AColor.Transparent); int primaryColorDark = GetColorPrimaryDark(); if (primaryColorDark != 0) { int r = AColor.GetRedComponent(primaryColorDark); int g = AColor.GetGreenComponent(primaryColorDark); int b = AColor.GetBlueComponent(primaryColorDark); int a = AColor.GetAlphaComponent(primaryColorDark); SetStatusBarColor(AColor.Argb(a, r, g, b)); } } }
protected override async void OnElementChanged(ElementChangedEventArgs <BottomBarPage> e) { base.OnElementChanged(e); if (e.NewElement != null) { _element = e.NewElement; if (_bottomNavigationView == null) { _rootLayout = new Android.Widget.RelativeLayout(Context) { LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent) }; AddView(_rootLayout); _frameLayout = new FrameLayout(Context) { LayoutParameters = new ActionBar.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent, GravityFlags.Fill) }; _rootLayout.AddView(_frameLayout); _bottomNavigationView = new BottomNavigationViewEx(Context) { LayoutParameters = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent) }; (_bottomNavigationView.LayoutParameters as Android.Widget.RelativeLayout.LayoutParams)?.AddRule(LayoutRules.AlignParentBottom); _bottomNavigationView.SetOnNavigationItemSelectedListener(this); if (_element.BarTextColor != default(Color)) { _bottomNavigationView.ItemTextColor = ColorStateList.ValueOf(_element.BarTextColor.ToAndroid()); _bottomNavigationView.ItemIconTintList = ColorStateList.ValueOf(_element.BarTextColor.ToAndroid()); } if (_element.BarBackgroundColor != default(Color)) { _bottomNavigationView.SetBackgroundColor(_element.BarBackgroundColor.ToAndroid()); } foreach (var page in Element.Children) { await AddPage(page); } _rootLayout.AddView(_bottomNavigationView, 1); _bottomNavigationView.EnableShiftingMode(false); _bottomNavigationView.EnableItemShiftingMode(false); ChangeCurrentPage(Element.Children[0]); _element.ChildAdded += Element_ChildAdded; _element.ChildRemoved += Element_ChildRemoved; } } }
protected virtual void InitializeShadow() { try { if (bottomNavigationView != null && supportTabbedPage.IsShadow) { if (relativeLayout != null) { var background = new LinearLayout(SupportWidgetXFSetup.Activity); background.SetBackgroundResource(Resource.Drawable.shadowclonenavigation_top); background.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent) { Height = 7 }; relativeLayout.AddView(background); var param = background.LayoutParameters as Android.Widget.RelativeLayout.LayoutParams; param.AddRule(LayoutRules.Above, bottomNavigationView.Id); } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
public void setMuPDFView(int page) { if (_core == null) { return; } // Now create the UI. // First create the document view mDocView = new MuPDFReaderView(this); mAdapter = new MuPDFPageAdapter(this, _core); mDocView.SetAdapter(mAdapter); mDocView.DisplayedViewIndex = page; // Stick the document view and the buttons overlay into a parent view if (mPDFView != null) { try { mPDFView.AddView(mDocView); } catch (Exception e) { Console.WriteLine(e + " <==========="); } } }
void InternalSetPage(Page page) { if (!Forms.IsInitialized) { throw new InvalidOperationException("Call Forms.Init (Activity, Bundle) before this"); } if (_platform != null) { _platform.SetPage(page); return; } _busyCount = 0; MessagingCenter.Subscribe <Page, bool>(this, Page.BusySetSignalName, OnPageBusy); MessagingCenter.Subscribe <Page, AlertArguments>(this, Page.AlertSignalName, OnAlertRequested); MessagingCenter.Subscribe <Page, ActionSheetArguments>(this, Page.ActionSheetSignalName, OnActionSheetRequested); _platform = new AppCompat.Platform(this); if (_application != null) { _application.Platform = _platform; } _platform.SetPage(page); _layout.AddView(_platform); _layout.BringToFront(); }
protected virtual void InitializeModify() { try { if (bottomNavigationView != null && supportTabbedPage.IsShadow) { if (supportTabbedPage.IsShadow) { if (relativeLayout != null) { var background = new LinearLayout(SupportWidgetXFSetup.Activity); background.SetBackgroundResource(Resource.Drawable.shadowclonenavigation_top); background.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent) { Height = 7 }; relativeLayout.AddView(background); var param = background.LayoutParameters as Android.Widget.RelativeLayout.LayoutParams; param.AddRule(LayoutRules.Above, bottomNavigationView.Id); } } if (supportTabbedPage.TitleAndIconLayout == TabbedIconTitleArrange.OnlyIcon) { var scale = Resources.DisplayMetrics.Density; var paddingDp = 9; var dpAsPixels = (int)(paddingDp * scale + 0.5f); bottomNavigationView.SetPadding(bottomNavigationView.PaddingLeft, dpAsPixels, bottomNavigationView.PaddingRight, bottomNavigationView.PaddingBottom); } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var relLayout = new Android.Widget.RelativeLayout(this); tvX = new TextView(this); tvY = new TextView(this); tvX.Text = "textview xx"; tvY.Text = "textview yy"; mChart = new BarChart(this); mChart.SetDrawBarShadow(false); mChart.SetDrawValueAboveBar(true); mChart.Description.Enabled = true; mChart.SetMaxVisibleValueCount(60); mChart.SetPinchZoom(true); mChart.SetBackgroundColor(Android.Graphics.Color.White); setData(12, 50); relLayout.AddView(mChart, 650, 1000); SetContentView(relLayout); }
protected override void OnElementChanged(ElementChangedEventArgs <DropDownMenuView> e) { base.OnElementChanged(e); if (e.NewElement != null) { _dropDownView = (DropDownMenuView)e.NewElement; if (Control == null) { Android.Widget.RelativeLayout wraper = new Android.Widget.RelativeLayout(Android.App.Application.Context); ContextThemeWrapper theme = new ContextThemeWrapper(Android.App.Application.Context, Mobile.Droid.Resource.Style.Base_Widget_AppCompat_TextView_SpinnerItem); _nativeView = new Spinner(theme); _nativeView.OnItemSelectedListener = this; if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.M) { _nativeView.SetBackgroundResource(Mobile.Droid.Resource.Drawable.abc_btn_borderless_material); } else { wraper.SetBackgroundResource(Mobile.Droid.Resource.Drawable.abc_btn_borderless_material); } _nativeView.LayoutParameters = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); _dropDownView.SetItemSelection = (i) => { _nativeView.SetSelection(i); }; ImageView downIcon = new ImageView(Android.App.Application.Context); var param = new Android.Widget.RelativeLayout.LayoutParams(20, 20); param.AddRule(LayoutRules.AlignParentRight); param.AddRule(LayoutRules.CenterInParent); param.SetMargins(0, 0, 14, 0); downIcon.LayoutParameters = param; downIcon.SetImageResource(Mobile.Droid.Resource.Drawable.abc_ic_arrow_drop_right_black_24dp); wraper.AddView(_nativeView); wraper.AddView(downIcon); SetNativeControl(wraper); } if (_dropDownView.ItemsSource != null) { SetApdater(); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.TabbedPage> e) { base.OnElementChanged(e); if (e.NewElement != null) { if (ViewGroup.GetChildAt(0) is AWidget.RelativeLayout relativeLayout) { _relativeLayout = relativeLayout; if (relativeLayout.GetChildAt(1) is BottomNavigationView bottomNavigationView) { //var txt = new TextView(Context); //txt.Text = "HalloHallo"; //txt.SetBackgroundColor(Android.Graphics.Color.Red); //txt.LayoutParameters = parms1; var count = _relativeLayout.ChildCount; ExtendedTabbedPage page = e.NewElement as ExtendedTabbedPage; var contentView = page.TabHeaderContent; var renderer = Platform.CreateRendererWithContext(contentView, this.Context); if (Platform.GetRenderer(contentView) == null) { Platform.SetRenderer(contentView, renderer); } AWidget.RelativeLayout.LayoutParams layoutParms = new AWidget.RelativeLayout.LayoutParams( LayoutParams.MatchParent, (int)contentView.HeightRequest); layoutParms.AddRule(AWidget.LayoutRules.Above, bottomNavigationView.Id); //Platform.SetRenderer(renderer) renderer.Tracker.UpdateLayout(); var nativeView = renderer.View; //view.SetBackground(Android.Widget.FrameLayout); nativeView.LayoutParameters = layoutParms; //SetNativeControl //view.Layout(0, 0, (int)tb.TabHeaderContent.WidthRequest, (int)tb.TabHeaderContent.HeightRequest); //view.tr _relativeLayout.AddView(nativeView); //_relativeLayout.UpdateViewLayout(view, parms1); //var view = ConvertFormsToNative(tb.TabHeaderContent, new Rectangle(0, 0, 100, 100)); //_relativeLayout.AddView(view, count); //_relativeLayout.AddView(view); //_relativeLayout.AddView(txt, count); } } } }
protected override void OnElementChanged(ElementChangedEventArgs <MyAwesomeView> e) { base.OnElementChanged(e); if (Control == null) { takePhotoButton = new Android.Widget.Button(this.Context); var layoutparams = new Android.Widget.RelativeLayout.LayoutParams(150, 150); layoutparams.AddRule(LayoutRules.AlignParentBottom); layoutparams.AddRule(LayoutRules.CenterHorizontal); layoutparams.BottomMargin = 50; takePhotoButton.LayoutParameters = layoutparams; takePhotoButton.Click += TakePhotoButton_Click; SwitchButtonColor(); liveCameraStream = new TextureView(this.Context); liveCameraStream.SurfaceTextureListener = this; var mainView = new Android.Widget.RelativeLayout(this.Context); mainView.AddView(liveCameraStream); mainView.AddView(takePhotoButton); SetNativeControl(mainView); } if (Control == null || Element == null) { return; } if (e.OldElement != null) { Element.RequestCameraPermissionTask = null; Element.StartSessionAction = null; } if (e.NewElement != null) { Element.RequestCameraPermissionTask = AuthorizeCameraUse(); Element.StartSessionAction = SetupLiveCameraRear; } }
private void SetupUserInterface() { mainLayout = new Android.Widget.RelativeLayout(Context); liveView = new TextureView(Context); Android.Widget.RelativeLayout.LayoutParams liveViewParams = new Android.Widget.RelativeLayout.LayoutParams( LayoutParams.MatchParent, LayoutParams.MatchParent); liveView.LayoutParameters = liveViewParams; mainLayout.AddView(liveView); capturePhotoButtonSatart = new Button(Context); capturePhotoButtonSatart.SetBackgroundDrawable(ContextCompat.GetDrawable(Context, Resource.Drawable.startVideo)); Android.Widget.RelativeLayout.LayoutParams captureButtonParamsStart = new Android.Widget.RelativeLayout.LayoutParams( LayoutParams.WrapContent, LayoutParams.WrapContent); captureButtonParamsStart.Height = 120; captureButtonParamsStart.Width = 120; capturePhotoButtonSatart.LayoutParameters = captureButtonParamsStart; mainLayout.AddView(capturePhotoButtonSatart); capturePhotoButtonStop = new Button(Context); capturePhotoButtonStop.SetBackgroundDrawable(ContextCompat.GetDrawable(Context, Resource.Drawable.stopVideo)); Android.Widget.RelativeLayout.LayoutParams captureButtonParamsStop = new Android.Widget.RelativeLayout.LayoutParams( LayoutParams.WrapContent, LayoutParams.WrapContent); captureButtonParamsStop.Height = 120; captureButtonParamsStop.Width = 120; capturePhotoButtonStop.LayoutParameters = captureButtonParamsStop; capturePhotoButtonStop.Visibility = ViewStates.Invisible; animatorSet = new AnimatorSet(); animatorSet.PlaySequentially( ObjectAnimator.OfFloat(capturePhotoButtonStop, "alpha", 1, 0)); animatorSet.SetDuration(0); //animationcapturePhotoInspectionButtonSet.AnimationEnd += EndAnimation; animatorSet.Start(); mainLayout.AddView(capturePhotoButtonStop); AddView(mainLayout); }
private void SetUpFab() { Fab = FindViewById <Android.Widget.RelativeLayout>(Resource.Id.fab); var cross = ViewUtil.GetUpwardFAB(this); //cross.SetBackgroundColor(new Android.Graphics.Color(ContextCompat.GetColor(this, Android.Resource.Color.White))); Fab.AddView(cross); Fab.Click += (sender, e) => { IntentUtil.GoToCreatePost(this); //add layout and tint to layout }; }
/// <summary> /// /// </summary> private void PrepareHint() { _hintLabel = new TextView(this.Context); _hintLabel.Text = "Hint label"; Android.Widget.RelativeLayout.LayoutParams relativeLayoutParameters = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); relativeLayoutParameters.AddRule(LayoutRules.AlignParentBottom); relativeLayoutParameters.AddRule(LayoutRules.CenterHorizontal); _hintLabel.LayoutParameters = relativeLayoutParameters; _hintLayout = new Android.Widget.RelativeLayout(this.Context); _hintLayout.LayoutParameters = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, 0); _hintLayout.SetPadding(0, 0, 0, 7); _hintLayout.AddView(_hintLabel); }
void InternalSetPage(Page page) { if (!Forms.IsInitialized) throw new InvalidOperationException("Call Forms.Init (Activity, Bundle) before this"); if (Platform != null) { Platform.SetPage(page); return; } PopupManager.ResetBusyCount(this); Platform = new AppCompat.Platform(this); Platform.SetPage(page); _layout.AddView(Platform); _layout.BringToFront(); }
public static RelativeLayout CreateRoot(this ExtendedTabbedPageRenderer renderer, int barId, int pageContainerId, out FrameLayout pageContainer) { var rootLayout = new RelativeLayout(renderer.Context) { LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent), }; var pageParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); pageParams.AddRule(LayoutRules.Above, barId); pageContainer = new FrameLayout(renderer.Context) { LayoutParameters = pageParams, Id = pageContainerId }; rootLayout.AddView(pageContainer, 0, pageParams); return(rootLayout); }
public static BottomNavigationViewEx SetupBottomBar(this BottomTabbedRenderer renderer, Android.Widget.RelativeLayout rootLayout, BottomNavigationViewEx bottomNav, int barId) { if (bottomNav != null) { rootLayout.RemoveView(bottomNav); bottomNav.SetOnNavigationItemSelectedListener(null); } var barParams = new Android.Widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MatchParent, BottomTabbedRenderer.BottomBarHeight.HasValue ? (int)rootLayout.Context.ToPixels(BottomTabbedRenderer.BottomBarHeight.Value) : ViewGroup.LayoutParams.WrapContent); //Add alignment rules to close to the lower edge of the parent contro barParams.AddRule(LayoutRules.AlignParentBottom); bottomNav = new BottomNavigationViewEx(rootLayout.Context) { LayoutParameters = barParams, Id = barId }; if (BottomTabbedRenderer.BackgroundColor.HasValue) { bottomNav.SetBackgroundColor(BottomTabbedRenderer.BackgroundColor.Value); } if (BottomTabbedRenderer.ItemIconTintList != null) { bottomNav.ItemIconTintList = BottomTabbedRenderer.ItemIconTintList; } if (BottomTabbedRenderer.ItemTextColor != null) { bottomNav.ItemTextColor = BottomTabbedRenderer.ItemTextColor; } if (BottomTabbedRenderer.ItemBackgroundResource.HasValue) { bottomNav.ItemBackgroundResource = BottomTabbedRenderer.ItemBackgroundResource.Value; } //The listening callback method "setOnNavigationItemSelectedListener()", which defaults to the first entry being the first item selected, can be set by //"navigation.getMenu().getItem(index).setChecked(true);" bottomNav.SetOnNavigationItemSelectedListener(renderer); rootLayout.AddView(bottomNav, 1, barParams); return(bottomNav); }
public void ElementSizeChanged(double w, double h) { if (oglView != null) { // // 現在のOGLViewを削除 baseView.RemoveView(oglView); oglView.Dispose(); oglView = null; } oglView = new OGLView(this.Context) { Sphere = ((EquirectanglarView)Element).Sphere, VertexShader = ((EquirectanglarView)Element).VertexShader, FragmentShader = ((EquirectanglarView)Element).FragmentShader, TextureImage = ((EquirectanglarView)Element).TextureImage }; baseView.AddView(oglView, LayoutParams.MatchParent); }
public static BottomNavigationViewEx SetupBottomBar(this BottomTabbedRenderer renderer, Android.Widget.RelativeLayout rootLayout, BottomNavigationViewEx bottomNav, int barId) { if (bottomNav != null) { rootLayout.RemoveView(bottomNav); bottomNav.SetOnNavigationItemSelectedListener(null); } var barParams = new Android.Widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MatchParent, BottomTabbedRenderer.BottomBarHeight.HasValue ? (int)rootLayout.Context.ToPixels(BottomTabbedRenderer.BottomBarHeight.Value) : ViewGroup.LayoutParams.WrapContent); barParams.AddRule(LayoutRules.AlignParentBottom); bottomNav = new BottomNavigationViewEx(rootLayout.Context) { LayoutParameters = barParams, Id = barId }; if (BottomTabbedRenderer.BackgroundColor.HasValue) { bottomNav.SetBackgroundColor(BottomTabbedRenderer.BackgroundColor.Value); } if (BottomTabbedRenderer.ItemIconTintList != null) { bottomNav.ItemIconTintList = BottomTabbedRenderer.ItemIconTintList; } if (BottomTabbedRenderer.ItemTextColor != null) { bottomNav.ItemTextColor = BottomTabbedRenderer.ItemTextColor; } if (BottomTabbedRenderer.ItemBackgroundResource.HasValue) { bottomNav.ItemBackgroundResource = BottomTabbedRenderer.ItemBackgroundResource.Value; } bottomNav.SetOnNavigationItemSelectedListener(renderer); rootLayout.AddView(bottomNav, 1, barParams); return(bottomNav); }
public void addSlideUpSheet(CustomPin pin, CustomMap map) { Android.App.Activity mainActivity = CrossCurrentActivity.Current.Activity; Android.Views.View view = mainActivity.CurrentFocus; Android.Views.View root = view.RootView; Android.Views.View altRoot = mainActivity.Window.DecorView.FindViewById(Android.Resource.Id.Content); Android.Widget.RelativeLayout parent = view.Parent as Android.Widget.RelativeLayout; parent.RemoveView(view); Console.WriteLine("Retrieved current focus..."); //LinearLayout BottomSheetPage = new LinearLayout(mainActivity); Console.WriteLine("Created a new layout..."); if (Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService) is Android.Views.LayoutInflater inflater) { Android.Views.View bottomSheetView = inflater.Inflate(Resource.Layout.BottomSheet, null); Android.Views.View test = inflater.Inflate(Resource.Layout.XamarinMapInfoWindow, null); Console.WriteLine("Created a bsheet..."); Cheesebaron.SlidingUpPanel.SlidingUpPanelLayout main = bottomSheetView as Cheesebaron.SlidingUpPanel.SlidingUpPanelLayout; Android.Widget.RelativeLayout bottom = main.FindViewById <Android.Widget.RelativeLayout>(Resource.Id.mainWindow); bottom.AddView(view); mainActivity.SetContentView(main); //parent.AddView(bottomSheetView); //inflate to bsheet //add the two views //BottomSheetPage.AddView(view.RootView); //Console.WriteLine("Added the currentfocus..."); //BottomSheetPage.AddView(bottomSheetView); //Console.WriteLine("Added the bsheet..."); //// $$$$$$ PROFIT $$$$$$$ //mainActivity.SetContentView(BottomSheetPage); //Console.WriteLine("Set content view!!!!"); } }
protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e) { base.OnElementChanged(e); var activity = (FormsAppCompatActivity)Context; if (e.OldElement != null) { ((IPageController)e.OldElement).InternalChildren.CollectionChanged -= OnChildrenCollectionChanged; } if (e.NewElement != null) { if (IsBottomTabPlacement) { if (_relativeLayout == null) { _relativeLayout = new AWidget.RelativeLayout(Context) { LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent), }; if (_bottomNavigationView != null) { _relativeLayout.RemoveView(_bottomNavigationView); _bottomNavigationView.SetOnNavigationItemSelectedListener(null); } var bottomNavigationViewLayoutParams = new AWidget.RelativeLayout.LayoutParams( LayoutParams.MatchParent, LayoutParams.WrapContent); bottomNavigationViewLayoutParams.AddRule(AWidget.LayoutRules.AlignParentBottom); _bottomNavigationView = new BottomNavigationView(Context) { LayoutParameters = bottomNavigationViewLayoutParams, Id = Platform.GenerateViewId() }; var viewPagerParams = new AWidget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); viewPagerParams.AddRule(AWidget.LayoutRules.Above, _bottomNavigationView.Id); FormsViewPager pager = _viewPager = CreateFormsViewPager(activity, e.NewElement); pager.Id = Platform.GenerateViewId(); pager.AddOnPageChangeListener(this); _relativeLayout.AddView(pager, viewPagerParams); _relativeLayout.AddView(_bottomNavigationView, bottomNavigationViewLayoutParams); AddView(_relativeLayout); } } else { if (_tabLayout == null) { TabLayout tabs; if (FormsAppCompatActivity.TabLayoutResource > 0) { tabs = _tabLayout = activity.LayoutInflater.Inflate(FormsAppCompatActivity.TabLayoutResource, null).JavaCast <TabLayout>(); } else { tabs = _tabLayout = new TabLayout(activity) { TabMode = TabLayout.ModeFixed, TabGravity = TabLayout.GravityFill } }; FormsViewPager pager = _viewPager = CreateFormsViewPager(activity, e.NewElement); pager.Id = Platform.GenerateViewId(); pager.AddOnPageChangeListener(this); AddView(pager); AddView(tabs); } } OnChildrenCollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); TabbedPage tabbedPage = e.NewElement; if (tabbedPage.CurrentPage != null) { ScrollToCurrentPage(); } _previousPage = tabbedPage.CurrentPage; ((IPageController)tabbedPage).InternalChildren.CollectionChanged += OnChildrenCollectionChanged; UpdateBarBackgroundColor(); UpdateBarTextColor(); UpdateItemIconColor(); UpdateSwipePaging(); UpdateOffscreenPageLimit(); } }
protected override async void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); var metrics = Resources.DisplayMetrics; var activity = this.Context as Activity; relativeLayout = new RelLayout(activity); var relativeLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); // Create topTextView - "Scan QR code to swap contact info" topTextView = new TextView(activity); topTextView.Text = "Scan QR code to swap contact info"; topTextView.Gravity = GravityFlags.Center; topTextView.SetTextColor(AColor.Rgb(38, 173, 230)); topTextView.TextSize = 14f; topTextView.Typeface = Typeface.CreateFromAsset(Forms.Context.Assets, "OpenSans-Bold.ttf"); RelLayout.LayoutParams topTVLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); relativeLayout.AddView(topTextView, topTVLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Create the Barcode Picker View */ barcodePicker = new ScanditSDKBarcodePicker(activity, "EeQ6GjLtEeSWsF/zcFfsWC8RqIt/+skbdZJ/MWpLIR8"); barcodePicker.OverlayView.AddListener(this); // disable all codes except QR for scanning barcodePicker.Set1DScanningEnabled(false); barcodePicker.Set2DScanningEnabled(false); barcodePicker.SetCode128Enabled(false); barcodePicker.SetCode39Enabled(false); barcodePicker.SetCode93Enabled(false); barcodePicker.SetDataMatrixEnabled(false); barcodePicker.SetEan13AndUpc12Enabled(false); barcodePicker.SetEan8Enabled(false); barcodePicker.SetItfEnabled(false); barcodePicker.SetMicroDataMatrixEnabled(false); barcodePicker.SetUpceEnabled(false); /* - * - * - * - * - * - * - */ barcodePicker.SetQrEnabled(true); /* - * - * - * - * - * - * - */ RelLayout.LayoutParams bpLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); bpLayoutParams.AddRule(LayoutRules.CenterHorizontal); relativeLayout.AddView(barcodePicker, bpLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Create the overlay view -- this is to cover the bottom part of the barcode scanner view */ overlay = new AView(activity); overlay.SetBackgroundColor(AColor.White); RelLayout.LayoutParams oLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); oLayoutParams.AddRule(LayoutRules.AlignParentBottom); relativeLayout.AddView(overlay, oLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ // Create bottomTextView - "Share your contact info" bottomTextView = new TextView(activity); bottomTextView.Text = "Share your contact info"; bottomTextView.Gravity = GravityFlags.Center; bottomTextView.SetTextColor(AColor.Rgb(38, 173, 230)); bottomTextView.TextSize = 14f; bottomTextView.Typeface = Typeface.CreateFromAsset(Forms.Context.Assets, "OpenSans-Bold.ttf"); RelLayout.LayoutParams bottomTVLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); relativeLayout.AddView(bottomTextView, bottomTVLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * * Generating QR code * * */ IBarcodeWriter barcodeWriter = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new ZXing.Common.EncodingOptions { Width = 175, Height = 175 } }; // TODO: temp code - move to view model var service = TinyIoC.TinyIoCContainer.Current.Resolve <CouchbaseConnect2014.Services.ICouchbaseService> (); var contactId = service.GetUserId(); var repo = TinyIoC.TinyIoCContainer.Current.Resolve <CouchbaseConnect2014.Services.IRepository> (); var localUser = await repo.GetProfile(); // end of temp code var qrContent = string.Format("{0},{1},{2}", contactId, localUser.First, localUser.Last); var result = barcodeWriter.Write(qrContent); qrImageView = new ImageView(activity); qrImageView.SetImageBitmap(result); RelLayout.LayoutParams qrLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); qrLayoutParams.AddRule(LayoutRules.CenterHorizontal); relativeLayout.AddView(qrImageView, qrLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ AddView(relativeLayout, relativeLayoutParams); barcodePicker.SetScanningHotSpot(0.5f, 0.2f); barcodePicker.OverlayView.SetViewfinderDimension(0.4f, 0.28f); barcodePicker.OverlayView.SetTorchEnabled(false); barcodePicker.StartScanning(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AToolbar bar; if (ToolbarResource != 0) { bar = LayoutInflater.Inflate(ToolbarResource, null).JavaCast <AToolbar>(); if (bar == null) { throw new InvalidOperationException("ToolbarResource must be set to a Android.Support.V7.Widget.Toolbar"); } } else { bar = new AToolbar(this); } SetSupportActionBar(bar); Window.SetSoftInputMode(SoftInput.AdjustPan); _layout = new ARelativeLayout(BaseContext); SetContentView(_layout); Xamarin.Forms.Application.ClearCurrent(); _previousState = _currentState; _currentState = AndroidApplicationLifecycleState.OnCreate; OnStateChanged(); _statusBarUnderlay = new global::Android.Views.View(this); var layoutParameters = new ARelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, GetStatusBarHeight()) { AlignWithParent = true }; layoutParameters.AddRule(LayoutRules.AlignTop); _statusBarUnderlay.LayoutParameters = layoutParameters; _layout.AddView(_statusBarUnderlay); if (Forms.IsLollipopOrNewer) { Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(SystemUiFlags.LayoutFullscreen | SystemUiFlags.LayoutStable); Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); Window.SetStatusBarColor(AColor.Transparent); int primaryColorDark = GetColorPrimaryDark(); if (primaryColorDark != 0) { int r = AColor.GetRedComponent(primaryColorDark); int g = AColor.GetGreenComponent(primaryColorDark); int b = AColor.GetBlueComponent(primaryColorDark); int a = AColor.GetAlphaComponent(primaryColorDark); SetStatusBarColor(AColor.Argb(a, r, g, b)); } } }
protected override async void OnElementChanged (ElementChangedEventArgs<Page> e) { base.OnElementChanged (e); var metrics = Resources.DisplayMetrics; var activity = this.Context as Activity; relativeLayout = new RelLayout (activity); var relativeLayoutParams = new RelLayout.LayoutParams ( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); // Create topTextView - "Scan QR code to swap contact info" topTextView = new TextView (activity); topTextView.Text = "Scan QR code to swap contact info"; topTextView.Gravity = GravityFlags.Center; topTextView.SetTextColor (AColor.Rgb (38, 173, 230)); topTextView.TextSize = 14f; topTextView.Typeface = Typeface.CreateFromAsset (Forms.Context.Assets, "OpenSans-Bold.ttf"); RelLayout.LayoutParams topTVLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); relativeLayout.AddView (topTextView, topTVLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Create the Barcode Picker View */ barcodePicker = new ScanditSDKBarcodePicker (activity, "EeQ6GjLtEeSWsF/zcFfsWC8RqIt/+skbdZJ/MWpLIR8"); barcodePicker.OverlayView.AddListener (this); // disable all codes except QR for scanning barcodePicker.Set1DScanningEnabled (false); barcodePicker.Set2DScanningEnabled (false); barcodePicker.SetCode128Enabled (false); barcodePicker.SetCode39Enabled (false); barcodePicker.SetCode93Enabled (false); barcodePicker.SetDataMatrixEnabled (false); barcodePicker.SetEan13AndUpc12Enabled (false); barcodePicker.SetEan8Enabled (false); barcodePicker.SetItfEnabled (false); barcodePicker.SetMicroDataMatrixEnabled (false); barcodePicker.SetUpceEnabled (false); /* - * - * - * - * - * - * - */ barcodePicker.SetQrEnabled (true); /* - * - * - * - * - * - * - */ RelLayout.LayoutParams bpLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); bpLayoutParams.AddRule(LayoutRules.CenterHorizontal); relativeLayout.AddView (barcodePicker, bpLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Create the overlay view -- this is to cover the bottom part of the barcode scanner view */ overlay = new AView(activity); overlay.SetBackgroundColor (AColor.White); RelLayout.LayoutParams oLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); oLayoutParams.AddRule(LayoutRules.AlignParentBottom); relativeLayout.AddView (overlay, oLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ // Create bottomTextView - "Share your contact info" bottomTextView = new TextView (activity); bottomTextView.Text = "Share your contact info"; bottomTextView.Gravity = GravityFlags.Center; bottomTextView.SetTextColor (AColor.Rgb (38, 173, 230)); bottomTextView.TextSize = 14f; bottomTextView.Typeface = Typeface.CreateFromAsset (Forms.Context.Assets, "OpenSans-Bold.ttf"); RelLayout.LayoutParams bottomTVLayoutParams = new RelLayout.LayoutParams( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); relativeLayout.AddView (bottomTextView, bottomTVLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * * Generating QR code * * */ IBarcodeWriter barcodeWriter = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new ZXing.Common.EncodingOptions { Width = 175, Height = 175 } }; // TODO: temp code - move to view model var service = TinyIoC.TinyIoCContainer.Current.Resolve<CouchbaseConnect2014.Services.ICouchbaseService> (); var contactId = service.GetUserId (); var repo = TinyIoC.TinyIoCContainer.Current.Resolve<CouchbaseConnect2014.Services.IRepository> (); var localUser = await repo.GetProfile (); // end of temp code var qrContent = string.Format ("{0},{1},{2}", contactId, localUser.First, localUser.Last); var result = barcodeWriter.Write (qrContent); qrImageView = new ImageView (activity); qrImageView.SetImageBitmap (result); RelLayout.LayoutParams qrLayoutParams = new RelLayout.LayoutParams ( RelLayout.LayoutParams.MatchParent, RelLayout.LayoutParams.MatchParent ); qrLayoutParams.AddRule (LayoutRules.CenterHorizontal); relativeLayout.AddView (qrImageView, qrLayoutParams); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ AddView (relativeLayout, relativeLayoutParams); barcodePicker.SetScanningHotSpot (0.5f, 0.2f); barcodePicker.OverlayView.SetViewfinderDimension (0.4f, 0.28f); barcodePicker.OverlayView.SetTorchEnabled (false); barcodePicker.StartScanning(); }
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; } }; }
private Android.Views.View CreateLayout(Context context) { Android.Widget.RelativeLayout layout = new Android.Widget.RelativeLayout(context); var layoutParam = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); layout.SetPadding(30, 15, 30, 15); layout.LayoutParameters = layoutParam; //main layout Android.Widget.LinearLayout mainView = new Android.Widget.LinearLayout(context); var paramLayout = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); mainView.Orientation = Orientation.Vertical; paramLayout.AddRule(NativeCell.IsIncoming ? LayoutRules.AlignParentLeft : LayoutRules.AlignParentRight); paramLayout.SetMargins(NativeCell.IsIncoming ? 0 : 50, 0, NativeCell.IsIncoming ? 50 : 0, 0); mainView.SetPadding(30, 30, 30, 30); mainView.LayoutParameters = paramLayout; //set drawable GradientDrawable shape = new GradientDrawable(); shape.SetCornerRadius(NativeCell.CornerRadius * 2); shape.SetColor(NativeCell.IsIncoming ? NativeCell.IncomingColor.ToAndroid() : NativeCell.OutgoingColor.ToAndroid()); mainView.Background = shape; // name text NameText = new TextView(context); NameText.SetTextColor(NativeCell.NameFontColor.ToAndroid()); NameText.TextSize = NativeCell.NameFontSize; NameText.Text = NativeCell.Name; NameText.Id = Name_Text_Id; var paramNameText = new Android.Widget.LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); NameText.LayoutParameters = paramNameText; //message text MessageText = new TextView(context); MessageText.SetTextColor(NativeCell.TextFontColor.ToAndroid()); MessageText.Text = NativeCell.MessageBody; MessageText.TextSize = NativeCell.TextFontSize; MessageText.Id = Message_Text_Id; var paramMessageText = new Android.Widget.LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); MessageText.LayoutParameters = paramMessageText; // status layout LinearLayout linearLayout = new LinearLayout(context); linearLayout.Orientation = Orientation.Horizontal; var paramlinearLayout = new Android.Widget.LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); paramlinearLayout.Gravity = Android.Views.GravityFlags.Right; linearLayout.SetGravity(Android.Views.GravityFlags.Right); linearLayout.LayoutParameters = paramlinearLayout; // status text StatusText = new TextView(context); StatusText.SetTextColor(NativeCell.InfoFontColor.ToAndroid()); StatusText.Text = StatusHelper.GetStatusString(NativeCell.Status); StatusText.Id = Status_Text_Id; StatusText.TextSize = NativeCell.InfoFontSize; StatusText.SetPadding(0, 0, 10, 0); StatusText.Gravity = Android.Views.GravityFlags.Left; var paramStatusText = new Android.Widget.LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); paramStatusText.Gravity = Android.Views.GravityFlags.Left; StatusText.LayoutParameters = paramStatusText; if (!NativeCell.IsIncoming) { linearLayout.AddView(StatusText); } // date text DateText = new TextView(context); DateText.SetTextColor(NativeCell.InfoFontColor.ToAndroid()); DateText.Text = NativeCell.Date; DateText.SetLines(1); DateText.TextSize = NativeCell.InfoFontSize; DateText.SetMinWidth(LayoutParams.WrapContent); DateText.Id = Date_Text_Id; var paramDateText = new Android.Widget.LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); DateText.LayoutParameters = paramDateText; linearLayout.AddView(DateText); if (!string.IsNullOrWhiteSpace(NameText.Text) && NativeCell.IsIncoming) { mainView.AddView(NameText); } mainView.AddView(MessageText); mainView.AddView(linearLayout); layout.AddView(mainView); return(layout); }