protected override void OnElementChanged(ElementChangedEventArgs <Flip> e) { base.OnElementChanged(e); this.Count = this.Element.Children.Count(); var root = new AW.RelativeLayout(this.Context); root.SetBackgroundColor(Color.Green.ToAndroid()); this.VP = new ViewPager(this.Context); this.VP.PageSelected += VP_PageSelected; //如果传入的 items 是 IEnumerable 类型的 (未ToList) , 会一直去计算那个 IEnumerable , 可断点到 GetChildrenViews 里, 会一直在那里执行, 从而导致子视图不显示 this.VP.Adapter = new FlipViewAdapter(this.Context, this.GetChildrenViews().ToList()); root.AddView(this.VP, LayoutParams.MatchParent, LayoutParams.MatchParent); this.PointsContainer = new LinearLayout(this.Context); this.PointsContainer.Orientation = Orientation.Horizontal; var lp = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.WrapContent, 20); lp.AddRule(LayoutRules.AlignParentBottom); lp.AddRule(LayoutRules.CenterHorizontal); root.AddView(this.PointsContainer, lp); this.SetNativeControl(root); this.SetPoints(); root.Invalidate(); root.RequestLayout(); }
private void CreateCustomKeyboard() { var activity = (Activity)this.context; var rootView = activity.Window.DecorView.FindViewById(Android.Resource.Id.Content); var activityRootView = (ViewGroup)((ViewGroup)rootView).GetChildAt(0); this.mKeyboardView = activityRootView.FindViewById <Android.InputMethodServices.KeyboardView>(Resource.Id.customKeyboard); // If the previous line fails, it means the keyboard needs to be created and added if (this.mKeyboardView == null) { this.mKeyboardView = (Android.InputMethodServices.KeyboardView)activity.LayoutInflater.Inflate(Resource.Layout.CustomKeyboard, null); this.mKeyboardView.Id = Resource.Id.customKeyboard; this.mKeyboardView.Focusable = true; this.mKeyboardView.FocusableInTouchMode = true; this.mKeyboardView.Release += (sender, e) => { }; var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); layoutParams.AddRule(LayoutRules.AlignParentBottom); activityRootView.AddView(this.mKeyboardView, layoutParams); } this.HideKeyboardView(); this.mKeyboard = new Android.InputMethodServices.Keyboard(this.context, Resource.Xml.special_keyboard); this.SetCurrentKeyboard(); }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (e.PropertyName == "CurrentPage") { UpgradeTabbedItemsAppereance(); } if (!(GetChildAt(0) is ViewGroup layout)) { return; } if (!(layout.GetChildAt(1) is BottomNavigationView bottomNavigationView)) { return; } var topShadow = LayoutInflater.From(Context).Inflate(Resource.Layout.view_shadow, null); var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, 15); layoutParams.AddRule(LayoutRules.Above, bottomNavigationView.Id); layout.AddView(topShadow, 2, layoutParams); }
protected override void OnElementChanged(ElementChangedEventArgs <Flip> e) { base.OnElementChanged(e); var root = new Android.Widget.RelativeLayout(this.Context); root.SetBackgroundColor(Color.Yellow.ToAndroid()); this.Scroller = new HorizontalScrollView(this.Context); root.AddView(this.Scroller, new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)); this.Scroller.SetBackgroundColor(Color.Green.ToAndroid()); this.Scroller.HorizontalScrollBarEnabled = false; this.Container = new Android.Widget.LinearLayout(this.Context); this.Container.Orientation = Orientation.Horizontal; this.Scroller.AddView(this.Container); this.Scroller.Touch += scroller_Touch; this.PointsContainer = new LinearLayout(this.Context); this.PointsContainer.Orientation = Orientation.Horizontal; //this.PointsContainer. = Android.Views.TextAlignment.Center; var lp = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.WrapContent, 20); lp.AddRule(LayoutRules.AlignParentBottom); lp.AddRule(LayoutRules.CenterHorizontal); root.AddView(this.PointsContainer, lp); this.SetNativeControl(root); root.Invalidate(); root.RequestLayout(); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.TabbedPage> e) { base.OnElementChanged(e); if (!(GetChildAt(0) is ViewGroup layout)) { return; } if (!(layout.GetChildAt(1) is BottomNavigationView bottomNavView)) { return; } if (e.NewElement != null) { tabbedPage = e.NewElement as CustomTabbedPage; bottomNavigationView = (GetChildAt(0) as Android.Widget.RelativeLayout).GetChildAt(1) as BottomNavigationView; bottomNavigationView.NavigationItemSelected += BottomNavigationView_NavigationItemSelected; //Call to remove animation SetShiftMode(bottomNavigationView, false, false); fontFamily = ((CustomTabbedPage)e.NewElement).FontFamily + ".ttf"; //Call to change the font try { ChangeFont(); } catch (Exception) { } //Set shadow var topShadow = LayoutInflater.From(Context).Inflate(Resource.Layout.view_shadow, null); var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, 15); layoutParams.AddRule(LayoutRules.Above, bottomNavView.Id); layout.AddView(topShadow, 2, layoutParams); } if (e.OldElement != null) { bottomNavigationView.NavigationItemSelected -= BottomNavigationView_NavigationItemSelected; } for (int i = 0; i < Element.Children.Count; i++) { var item = bottomNavigationView.Menu.GetItem(i); var icon = item.Icon; if (icon != null) { icon = Android.Support.V4.Graphics.Drawable.DrawableCompat.Wrap(icon); if (i == 0) { icon.SetColorFilter(tabbedPage.SelectedTabColor.ToAndroid(), PorterDuff.Mode.SrcIn); } else { icon.SetColorFilter(tabbedPage.UnselectedTabColor.ToAndroid(), PorterDuff.Mode.SrcIn); } } } }
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); } } } }
// apply a layout rule static void ApplyRule(Android.Widget.RelativeLayout.LayoutParams lp, LayoutRule rule) { if (rule.Subject.HasValue) { lp.AddRule(rule, rule.Subject.Value); } else { lp.AddRule(rule); } }
protected override void OnElementChanged(ElementChangedEventArgs <Flip> e) { base.OnElementChanged(e); if (e.OldElement != null) { e.OldElement.Children.CollectionChanged -= this.Children_CollectionChanged; e.OldElement.NextRequired -= this.Element_NextRequired; e.OldElement.IndexRequired -= this.Element_IndexRequired; } if (this.Element == null) { return; } var Root = new AW.RelativeLayout(this.Context); this.VP = new ViewPager(this.Context); this.VP.PageSelected += VP_PageSelected; //如果传入的 items 是 IEnumerable 类型的 (未ToList) , 会一直去计算那个 IEnumerable , 可断点到 GetChildrenViews 里, 会一直在那里执行, 从而导致子视图不显示 this.Adapter = new FlipViewAdapter(this.VP); Adapter.SetItems(this.GetChildrenViews().ToList()); Adapter.PosChanged += Adapter_PosChanged; this.VP.Adapter = Adapter; this.VP.AddOnPageChangeListener(Adapter); Root.AddView(this.VP, LayoutParams.MatchParent, LayoutParams.MatchParent); this.PointsContainer = new LinearLayout(this.Context); this.PointsContainer.Orientation = Orientation.Horizontal; var lp = new AW.RelativeLayout.LayoutParams(LayoutParams.WrapContent, 20); lp.AddRule(LayoutRules.AlignParentBottom); lp.AddRule(LayoutRules.CenterHorizontal); Root.AddView(this.PointsContainer, lp); this.SetNativeControl(Root); if (this.Element.ShowIndicator) { this.SetPoints(); } Root.Invalidate(); Root.RequestLayout(); this.Element.NextRequired += Element_NextRequired; this.Element.IndexRequired += Element_IndexRequired; this.Element.Children.CollectionChanged += Children_CollectionChanged; }
protected override TextInputLayout CreateNativeControl() { var textInputLayout = new TextInputLayout(Context); var editText = new EditText(Context); #region Add the Keyboard in your Page var activity = Forms.Context as Activity; var rootView = activity.Window.DecorView.FindViewById(Android.Resource.Id.Content); //activity.Window.SetSoftInputMode(SoftInput.StateAlwaysHidden); // (SoftInput.StateAlwaysHidden); activityRootView = ((ViewGroup)rootView).GetChildAt(0) as ViewGroup; mKeyboardView = new CustomKeyboardView(Forms.Context, null); Android.Widget.RelativeLayout.LayoutParams layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); // or wrap_content layoutParams.AddRule(LayoutRules.AlignParentBottom); activityRootView.AddView(mKeyboardView, layoutParams); #endregion //First open the current page, hide the Keyboard mKeyboardView.Visibility = ViewStates.Gone; //Use the custom Keyboard mKeyboard = new Android.InputMethodServices.Keyboard(Context, Resource.Xml.keyboard); mKeyboardView.Keyboard = mKeyboard; mKeyboardView.Key += async(sender, e) => { if (e.PrimaryCode == Keycode.NavigateNext) { this.mKeyboardView.Visibility = ViewStates.Gone; // or this (not working yet) // https://forums.xamarin.com/discussion/58763/key-detection-on-form-plus-making-the-keyboard-disappear-on-a-device-with-physical-keys //var inputMethodManager = (InputMethodManager)this.Context.GetSystemService(Activity.InputMethodService); //this.mKeyboard.Dispose(); ////this.mKeyboardView.WindowToken //inputMethodManager.HideSoftInputFromWindow(this.mKeyboardView.WindowToken, 0); return; } long eventTime = JavaSystem.CurrentTimeMillis(); KeyEvent ev = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, e.PrimaryCode, 0, 0, 0, 0, KeyEventFlags.SoftKeyboard | KeyEventFlags.EditorAction); DispatchKeyEvent(ev); await Task.Delay(1); }; textInputLayout.AddView(editText); return(textInputLayout); }
/// <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); }
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 <TabbedPage> e) { base.OnElementChanged(e); var activity = (FormsAppCompatActivity)Context; if (e.NewElement != null) { var relativeLayout = this.GetChildAt(0) as Android.Widget.RelativeLayout; if (relativeLayout != null) { bottomNarView = relativeLayout.GetChildAt(1).JavaCast <BottomNavigationView>(); BottomNavigationViewUtils.SetShiftMode(bottomNarView, false, false); floating = activity.LayoutInflater.Inflate(Resource.Layout.FloatingActionButton, null).JavaCast <FloatingActionButton>(); floating.Click += async delegate(object sender, EventArgs ev) { if (UserTokenSettings.Current.HasExpiresIn()) { MessagingService.Current.SendMessage(MessageKeys.NavigateLogin); } else { if (this.Element.CurrentPage is StatusesTopTabbedPage) { await NavigationService.PushAsync(this.Element.Navigation, new StatusesEditPage(new Statuses())); } else if (this.Element.CurrentPage is QuestionsTopTabbedPage) { await NavigationService.PushAsync(this.Element.Navigation, new QuestionsEditPage(new Questions())); } } }; var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(Android.Widget.RelativeLayout.LayoutParams.WrapContent, Android.Widget.RelativeLayout.LayoutParams.WrapContent); layoutParams.AddRule(LayoutRules.AlignParentRight); layoutParams.AddRule(LayoutRules.AlignParentBottom); layoutParams.AddRule(LayoutRules.Above, bottomNarView.Id); floating.LayoutParameters = layoutParams; relativeLayout.AddView(floating); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.TabbedPage> e) { base.OnElementChanged(e); if (!(GetChildAt(0) is ViewGroup layout)) { return; } if (!(layout.GetChildAt(1) is BottomNavigationView bottomNavigationView)) { return; } var topShadow = LayoutInflater.From(Context).Inflate(Resource.Layout.view_shadow, null); var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, 15); layoutParams.AddRule(LayoutRules.Above, bottomNavigationView.Id); layout.AddView(topShadow, 2, layoutParams); var childViews = GetAllChildViews(ViewGroup); var scale = Resources.DisplayMetrics.Density; var paddingDp = 9; var dpAsPixels = (int)(paddingDp * scale + 0.5f); foreach (var childView in childViews) { if (childView is BottomNavigationItemView tab) { tab.SetPadding(tab.PaddingLeft, dpAsPixels, tab.PaddingRight, tab.PaddingBottom); } else if (childView is TextView textView) { textView.SetTextColor(Android.Graphics.Color.Transparent); } } }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnElementChanged(ElementChangedEventArgs <AtomVideoPlayer> e) { base.OnElementChanged(e); if (Element == null) { return; } videoView = new VideoView(this.Context); var vlp = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); vlp.AddRule(LayoutRules.CenterInParent); //vlp.AddRule(LayoutRules.AlignParentLeft); //vlp.AddRule(LayoutRules.AlignParentRight); //vlp.AddRule(LayoutRules.AlignParentBottom); videoView.LayoutParameters = vlp; //vlp.AddRule(LayoutRules.fill); var mc = new MediaController(this.Context); videoView.SetMediaController(mc); var ctrl = new Android.Widget.RelativeLayout(this.Context); ctrl.AddView(videoView); SetNativeControl(ctrl); ResetVideo(); if (Element.IsPlaying) { videoView.Start(); } else { videoView.StopPlayback(); } mc.Show(0); }
protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e) { try { base.OnElementChanged(e); } catch (Exception ex) { Console.WriteLine(ex); } if (Element == null) { return; } if (ViewGroup == null) { return; } var vg = (ViewGroup)GetChildAt(0); for (int i = 0; i < vg.ChildCount; i++) { var v = vg.GetChildAt(i); if (v is BottomNavigationView) { BottomNavigationView _tabbar = v as BottomNavigationView; var topShadow = LayoutInflater.From(Context).Inflate(Resource.Layout.view_shadow, null); var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, 15); layoutParams.AddRule(LayoutRules.Above, v.Id); vg.AddView(topShadow, 2, layoutParams); DisableShiftMode(_tabbar); } } }
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; } }
protected override void OnAttached() { var effect = Element.Effects.FirstOrDefault(x => x is SignKeys.Effects.CustomTabViewEffect); if (effect == null || Container == null) { return; } var containerRef = new WeakReference <ViewGroup>(Container); var meRef = new WeakReference <CustomTabViewEffectImpl>(this); Device.InvokeOnMainThreadAsync(() => { if (containerRef.TryGetTarget(out ViewGroup container) && meRef.TryGetTarget(out CustomTabViewEffectImpl me) && container.GetChildView <BottomNavigationView>() is BottomNavigationView bottomNavView && TabEffect.GetTabView(me.Element) is VisualElement xfView) { bottomNavView.DisableView(); var renderer = (VisualElementRenderer <Xamarin.Forms.View>)Xamarin.Forms.Platform.Android.Platform.CreateRendererWithContext(xfView, container.Context); Xamarin.Forms.Platform.Android.Platform.SetRenderer(xfView, renderer); renderer.Elevation = bottomNavView.Elevation + 1; renderer.Tracker.UpdateLayout(); me.renderer = renderer; var viewHeight = me.CaculateTabHeight(bottomNavView); me.layoutChangeListener = new RendererLayoutChangeListener(); renderer.AddOnLayoutChangeListener(me.layoutChangeListener); var layoutParams = new Android.Widget.RelativeLayout.LayoutParams( Android.Widget.RelativeLayout.LayoutParams.MatchParent, viewHeight); //layoutParams.AddRule(Android.Widget.LayoutRules.AlignTop, bottomNavView.Id); layoutParams.AddRule(Android.Widget.LayoutRules.AlignBottom, bottomNavView.Id); var parentView = (Android.Widget.RelativeLayout)bottomNavView.Parent; parentView.AddView(renderer, layoutParams); } }); }
protected override TextInputLayout CreateNativeControl() { var textInputLayout = new TextInputLayout(Context); var editText = new EditText(Context); #region Add the Keyboard in your Page var activity = Forms.Context as Activity; var rootView = activity.Window.DecorView.FindViewById(Android.Resource.Id.Content); activity.Window.SetSoftInputMode(SoftInput.StateAlwaysHidden); activityRootView = ((ViewGroup)rootView).GetChildAt(0) as ViewGroup; mKeyboardView = new CustomKeyboardView(Forms.Context, null); Android.Widget.RelativeLayout.LayoutParams layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); // or wrap_content layoutParams.AddRule(LayoutRules.AlignParentBottom); activityRootView.AddView(mKeyboardView, layoutParams); #endregion //First open the current page, hide the Keyboard mKeyboardView.Visibility = ViewStates.Gone; //Use the custom Keyboard mKeyboard = new Android.InputMethodServices.Keyboard(Context, Resource.Xml.keyboard); mKeyboardView.Keyboard = mKeyboard; mKeyboardView.Key += async(sender, e) => { long eventTime = JavaSystem.CurrentTimeMillis(); KeyEvent ev = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, e.PrimaryCode, 0, 0, 0, 0, KeyEventFlags.SoftKeyboard | KeyEventFlags.KeepTouchMode); DispatchKeyEvent(ev); await Task.Delay(1); }; textInputLayout.AddView(editText); return(textInputLayout); }
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); }
protected override void OnSizeChanged(int w, int h, int oldw, int oldh) { base.OnSizeChanged(w, h, oldw, oldh); // Update the video size from the new orientation Android.Widget.RelativeLayout.LayoutParams videoLayoutParams; if (w < h) { // Portrait videoLayoutParams = new Android.Widget.RelativeLayout.LayoutParams((int)_videoSizePortrait.Width, (int)_videoSizePortrait.Height); } else { // Landscape videoLayoutParams = new Android.Widget.RelativeLayout.LayoutParams((int)_videoSizeLandscape.Width, (int)_videoSizeLandscape.Height); } videoLayoutParams.AddRule(LayoutRules.CenterInParent); _videoview.LayoutParameters = videoLayoutParams; }
// ---------------------------------------------- #region Overrides protected override void OnElementChanged(ElementChangedEventArgs <ManneVideoView> e) { base.OnElementChanged(e); if (e.NewElement == null) { return; } // Get the Forms control _view = e.NewElement; // Init Sizes SetVideoDimensions(new Size(710, 400)); // Create the container var layout = new Android.Widget.RelativeLayout(Forms.Context); var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); layout.LayoutParameters = layoutParams; // Create the VideoView _videoview = new Android.Widget.VideoView(Forms.Context); var videoLayoutParams = new Android.Widget.RelativeLayout.LayoutParams(0, 0); videoLayoutParams.AddRule(LayoutRules.CenterInParent); _videoview.LayoutParameters = videoLayoutParams; // Set the View View as the native control for this renderer layout.AddView(_videoview); SetNativeControl(layout); // Try to play LoadAndPlay(); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.TabbedPage> e) { base.OnElementChanged(e); if (!(GetChildAt(0) is ViewGroup layout)) { return; } if (!(layout.GetChildAt(1) is BottomNavigationView bottomNavigationView)) { return; } var topShadow = LayoutInflater.From(Context).Inflate(Resource.Layout.view_shadow, null); var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, 15); layoutParams.AddRule(LayoutRules.Above, bottomNavigationView.Id); layout.AddView(topShadow, 2, layoutParams); }
void SetupUserInterface() { var metrics = Resources.DisplayMetrics; view = CurrentContext.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false); videoView = view.FindViewById <VideoView>(Resource.Id.textureView); timer = view.FindViewById <Chronometer>(Resource.Id.timerId); mainLayout = new Android.Widget.RelativeLayout(Context); Android.Widget.RelativeLayout.LayoutParams liveViewParams = new Android.Widget.RelativeLayout.LayoutParams( Android.Widget.RelativeLayout.LayoutParams.FillParent, Android.Widget.RelativeLayout.LayoutParams.FillParent); liveViewParams.Width = metrics.WidthPixels; // 80% liveViewParams.Height = (metrics.HeightPixels / 5) * 4; captureButton = view.FindViewById <Android.Widget.Button>(Resource.Id.takePhotoButton); buttonHolder = new Android.Widget.RelativeLayout(Context); captureButtonParams = new Android.Widget.RelativeLayout.LayoutParams( Android.Widget.RelativeLayout.LayoutParams.FillParent, Android.Widget.RelativeLayout.LayoutParams.FillParent); captureButtonParams.Width = metrics.WidthPixels; captureButtonParams.Height = (metrics.HeightPixels / 5) * 1; captureButtonParams.AddRule(LayoutRules.AlignParentBottom); buttonHolder.LayoutParameters = captureButtonParams; timer.Visibility = ViewStates.Invisible; Holder = videoView.Holder; Holder.AddCallback(this); Holder.SetType(SurfaceType.PushBuffers); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.TabbedPage> e) { tab = e.NewElement as TabbedPage; base.OnElementChanged(e); if (!(GetChildAt(0) is ViewGroup layout)) { return; } if (!(layout.GetChildAt(1) is BottomNavigationView bottomNavigationView)) { return; } var topShadow = LayoutInflater.From(Context).Inflate(Resource.Layout.view_shadow, null); var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, 15); layoutParams.AddRule(LayoutRules.Above, bottomNavigationView.Id); layout.AddView(topShadow, 2, layoutParams); bottomNavigationView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityLabeled; bottomNavi = bottomNavigationView; if (e.NewElement != null) { bottomNavigationView.NavigationItemSelected += BottomNavigationItemSelected; } if (e.OldElement != null) { bottomNavigationView.NavigationItemSelected -= BottomNavigationItemSelected; } }
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(); } }
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); }
// remove a layout rule static void RemoveRule(Android.Widget.RelativeLayout.LayoutParams lp, LayoutRule rule) { lp.RemoveRule(rule.Verb); }