public static void Activated(object sender, EventArgs eventArgs) { var menu = sender as IMenu; if (menu == null) { var popover = PaneManager.Instance.FromNavContext(Pane.Popover)?.CurrentView; menu = (popover as IListView)?.Menu ?? (popover as IGridView)?.Menu ?? (popover as IBrowserView)?.Menu ?? (popover as BaseFragment)?.Menu; } if (menu == null || menu.ButtonCount <= 0) { return; } var items = new string[menu.ButtonCount]; for (var i = 0; i < menu.ButtonCount; i++) { items[i] = menu.GetButton(i).Title; } var builder = new AlertDialog.Builder(DroidFactory.MainActivity) .SetItems(items, DroidFactory.GetNativeObject <Menu>(menu, nameof(menu))); builder.Create().Show(); }
public override Android.Views.View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var parent = ((Android.Views.View)_canvas).Parent; if (parent != null) { ((ViewGroup)parent).RemoveView(_canvas); } _container = new LinearLayout(Activity) { Orientation = Orientation.Vertical, }; _container.AddView(_canvas, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 0) { Weight = 1, }); var bar = DroidFactory.GetNativeObject <Android.Views.View>(_toolbar, "Toolbar"); if (bar != null) { if (bar.Parent != _container && bar.Parent != null) { ((ViewGroup)bar.Parent).RemoveView(bar); } _container.AddView(bar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent)); ((Toolbar)bar).UpdateItems(); } Render(); return(_container); }
public void AddChild(IElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } var concreteControl = DroidFactory.GetNativeObject <View>(element, nameof(element)); if (concreteControl == null) { throw new ArgumentException("Element must provide a native Pair.", nameof(element)); } if (concreteControl.Parent == this) { return; } var oldElement = string.IsNullOrEmpty(element.ID) ? null : Children.FirstOrDefault(c => c.ID == element.ID); if (oldElement != null) { RemoveChild(oldElement); } (concreteControl.Parent as ViewGroup)?.RemoveView(concreteControl); AddView(concreteControl); }
public static void RequestResize(this IElement element, bool condition = true) { var gridBase = DroidFactory.GetNativeObject <GridBase>(element.Parent, nameof(element.Parent)); if (gridBase != null && condition) { gridBase.ResizeRequested = true; } }
public void OnTabSelected(ActionBar.Tab actionTab, FragmentTransaction ft) { if (_inFlight) { return; } var itemPosition = actionTab.Position; var masterStack = (FragmentHistoryStack)PaneManager.Instance.FromNavContext(Pane.Master, itemPosition); var tab = TabItems.ElementAt(itemPosition); var nativeTab = DroidFactory.GetNativeObject <TabItem>(tab, "tab"); if (itemPosition != SelectedIndex && !PaneManager.Instance.ShouldNavigate(tab.NavigationLink, Pane.Tabs, NavigationType.Tab)) { DroidFactory.MainActivity.ActionBar.GetTabAt(_selectedIndex).Select(); return; } var navTabs = _model as NavigationTabs; if (masterStack.CurrentView != null && (navTabs == null || !navTabs.TabItems[itemPosition].RefreshOnFocus)) { if (itemPosition != SelectedIndex) { _selectedIndex = itemPosition; this.OnPropertyChanged("SelectedIndex"); nativeTab.OnSelected(); } iApp.SetNavigationContext(new iLayer.NavigationContext { OutputOnPane = Pane.Tabs, NavigatedActiveTab = itemPosition, }); masterStack.Align(NavigationType.Tab); return; } iLayer.NavigationContext context; if (masterStack.CurrentLayer != null && (context = masterStack.CurrentLayer.NavContext) != null) { //Fix layer context if it was modified in a different tab context.ClearPaneHistoryOnOutput = false; context.NavigatedActivePane = Pane.Tabs; context.NavigatedActiveTab = itemPosition; context.OutputOnPane = Pane.Master; } if (itemPosition != iApp.CurrentNavContext.ActiveTab) { var masterView = (PaneManager.Instance.FromNavContext(Pane.Master, iApp.CurrentNavContext.ActiveTab) as FragmentHistoryStack)?.CurrentView as IView; iApp.SetNavigationContext(new iLayer.NavigationContext { OutputOnPane = Pane.Tabs, NavigatedActiveTab = itemPosition, }); masterView?.RaiseEvent("Deactivated", EventArgs.Empty); } _selectedIndex = itemPosition; this.OnPropertyChanged("SelectedIndex"); nativeTab.Activate(this); }
public void OnTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { if (_inFlight) { return; } var actionTab = DroidFactory.GetNativeObject <TabItem>(TabItems.ElementAt(tab.Position), "actionTab"); actionTab.Activate(this); }
public void Deselect() { SetBackgroundColor(BackgroundColor.ToColor()); var labels = Children.OfType <ILabel>().Select(f => DroidFactory.GetNativeObject <Label>(f, "label")); foreach (var label in labels) { label.SetTextColor(label.ForegroundColor.ToColor()); } }
public static Size MeasureView(this IElement view, Size constraints) { var nativeView = DroidFactory.GetNativeObject <View>(view, nameof(view)); if (nativeView == null) { return(new Size()); } nativeView.Measure(View.MeasureSpec.MakeMeasureSpec(GetMeasureSpec(constraints.Width), view.HorizontalAlignment == HorizontalAlignment.Stretch ? MeasureSpecMode.Exactly : MeasureSpecMode.AtMost), View.MeasureSpec.MakeMeasureSpec(GetMeasureSpec(constraints.Height), MeasureSpecMode.Unspecified)); return(new Size(nativeView.MeasuredWidth, nativeView.MeasuredHeight)); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var layout = new LinearLayout(Activity) { Orientation = Orientation.Vertical, }; var search = DroidFactory.GetNativeObject <SearchBox>(SearchBox, nameof(SearchBox)); AttachSearchView(search, layout); List = MXContainer.Resolve <ListView>(Activity) ?? new ListView(Activity); List.OnItemSelectedListener = this; List.OnItemClickListener = this; List.OnItemLongClickListener = this; List.DescendantFocusability = DescendantFocusability.BeforeDescendants; List.ScrollingCacheEnabled = false; List.Adapter = new CellAdapter(this); List.ScrollStateChanged += (o, e) => { if (e.ScrollState == ScrollState.Idle) { var cell = List.GetChildAt(0); _index = List.FirstVisiblePosition; _top = cell?.Top ?? 0; } List.DescendantFocusability = DescendantFocusability.BeforeDescendants; if (_touchScroll) { DroidFactory.HideKeyboard(true); } if (e.ScrollState == ScrollState.Idle) { _touchScroll = true; } RequestFocusHomeUp = false; }; List.SetRecyclerListener(this); SeparatorColor = _separatorColor; layout.AddView(List, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent)); if (search == null || search.FocusRequested) { layout.RequestFocus(); } else { List.RequestFocus(); } return(layout); }
public void Highlight() { if (SelectionColor.IsDefaultColor) { Deselect(); return; } SetBackgroundColor(SelectionColor.ToColor()); var labels = Children.OfType <ILabel>().Select(f => DroidFactory.GetNativeObject <Label>(f, "label")); foreach (var label in labels) { label.SetTextColor(label.HighlightColor.ToColor()); } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (_browser == null) { _browser = new RichText { Parent = this, }; _browser.Load(); } var viewParent = ((View)_browser).Parent as ViewGroup; if (viewParent != null) { _browser.Browser.LoadFinished -= ClientLoadFinished; viewParent.RemoveView(_browser); } _browser.Browser.AttachToView(this); _browser.Browser.LoadFinished += ClientLoadFinished; UserAgent = _agent; if (_url != null) { Load(_url); _url = null; } else if (_doc != null) { LoadFromString(_doc); _doc = null; } var control = DroidFactory.GetNativeObject <View>(_toolbar, "value"); if (control != null) { ((ViewGroup)control.Parent)?.RemoveView(control); _browser.AddView(control, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent)); } return(_browser); }
internal void UpdateItems() { _bar.RemoveAllViews(); if (SecondaryItems != null) { foreach (var control in SecondaryItems.Select(item => DroidFactory.GetNativeObject <Android.Views.View>(item, "item")).Where(item => item != null)) { _bar.AddView(control); } } if (PrimaryItems == null || !PrimaryItems.Any()) { return; } { _bar.AddView(new Android.Views.View(Context), new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MatchParent, 1)); foreach (var control in PrimaryItems.Select(item => DroidFactory.GetNativeObject <Android.Views.View>(item, "item")).Where(item => item != null)) { _bar.AddView(control); } } }
public override View GetView(int position, View convertView, ViewGroup parent) { int sectionIndex, cellIndex; GetSectionAndIndex(Parent.Sections, position, out sectionIndex, out cellIndex); var layer = Parent.GetModel() as iLayer; var sectionIndexProperty = typeof(iLayerItem).GetProperty("SectionIndex", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); var outOfSync = layer != null && (layer.Items.Count == 0 || layer.Items.Count > 1 && layer.Items.All(i => (int)sectionIndexProperty.GetValue(i) == 0)); var count = _itemCount; if (!_headerIndices.Any()) { count--; } if (!_footerIndices.Any()) { count--; } if (!Parent.Sections.Any() || outOfSync || position >= count) { return(new View(DroidFactory.MainActivity)); } object cell = GetCell(sectionIndex, cellIndex, convertView as ICell) ?? (convertView == null ? null : GetCell(sectionIndex, cellIndex, new CustomItemContainer(convertView))); if (cell == null) { if (sectionIndex > -1) { var section = Parent.Sections[sectionIndex]; if (_headerIndices.Contains(position) && section.Header != null) { return(DroidFactory.GetNativeObject <View>(section.Header, "Header")); } if (_footerIndices.Contains(position) && section.Footer != null) { return(DroidFactory.GetNativeObject <View>(section.Footer, "Footer")); } } if (convertView == null) { iApp.Log.Error("View not found for item in section {0}, cell {1}", sectionIndex, cellIndex); return(new View(DroidFactory.MainActivity)); } } var custom = cell as CustomItemContainer; if (custom != null) { cell = custom.CustomItem; } var pairable = cell as IPairable; if (cell is IGridBase || pairable?.Pair is IGridBase) { var grid = DroidFactory.GetNativeObject <GridBase>(cell, "IGridBase"); grid.Parent = Parent; } if (cell is IGridCell || pairable?.Pair is IGridCell) { var grid = DroidFactory.GetNativeObject <GridCell>(cell, "IGridCell"); grid.Metadata["Index"] = position; if (position == Parent.SelectedIndex) { grid.Highlight(); } else { grid.Deselect(); } return(grid); } if (cell is IRichContentCell || pairable?.Pair is IRichContentCell) { var richText = DroidFactory.GetNativeObject <RichText>(cell, "IRichContentCell"); richText.Parent = Parent; richText.Load(); return(richText); } if (cell is View || pairable?.Pair is View) { var nativeView = DroidFactory.GetNativeObject <View>(cell, "cell"); if (nativeView != null) { return(nativeView); } } iApp.Log.Warn("Native view not found for custom item in section {0}, cell {1}", sectionIndex, cellIndex); return(new View(DroidFactory.MainActivity)); }
public bool OnNavigationItemSelected(int itemPosition, long itemId) { if (DroidFactory.Tabs != this) { return(false); } var masterStack = (FragmentHistoryStack)PaneManager.Instance.FromNavContext(Pane.Master, itemPosition); var tab = TabItems.ElementAt(itemPosition); var nativeTab = DroidFactory.GetNativeObject <TabItem>(TabItems.ElementAt(itemPosition), "tab"); if (itemPosition != SelectedIndex && !PaneManager.Instance.ShouldNavigate(tab.NavigationLink, Pane.Tabs, NavigationType.Tab)) { return(false); } if (masterStack.CurrentView == null) { SelectedIndex = itemPosition; this.OnPropertyChanged("SelectedIndex"); nativeTab.Activate(this); } else { if (itemPosition == SelectedIndex) { masterStack.Align(NavigationType.Tab); return(true); } SelectedIndex = itemPosition; var navTabs = _model as NavigationTabs; if (navTabs != null && navTabs.TabItems[itemPosition].RefreshOnFocus) { this.OnPropertyChanged("SelectedIndex"); nativeTab.Activate(this); return(true); } iLayer.NavigationContext context; if (masterStack.CurrentLayer != null && (context = masterStack.CurrentLayer.NavContext) != null) { //Fix layer context if it was modified in a different tab context.ClearPaneHistoryOnOutput = false; context.NavigatedActivePane = Pane.Tabs; context.NavigatedActiveTab = itemPosition; context.OutputOnPane = Pane.Master; } if (itemPosition != iApp.CurrentNavContext.ActiveTab) { var masterView = (PaneManager.Instance.FromNavContext(Pane.Master, iApp.CurrentNavContext.ActiveTab) as FragmentHistoryStack)?.CurrentView as IView; iApp.SetNavigationContext(new iLayer.NavigationContext { OutputOnPane = Pane.Tabs, NavigatedActiveTab = itemPosition, }); masterView?.RaiseEvent("Deactivated", EventArgs.Empty); } nativeTab.OnSelected(); this.OnPropertyChanged("SelectedIndex"); masterStack.Align(NavigationType.Tab); (PaneManager.Instance.FromNavContext(Pane.Detail, 0) as FragmentHistoryStack)?.PopToRoot(); } return(true); }
public void RemoveChild(IElement control) { var concreteControl = DroidFactory.GetNativeObject <View>(control, nameof(control)); RemoveView(concreteControl); }
/// <summary> /// Synchronize the rendered stack with the <see cref="Views"/> collection /// </summary> public void Align(NavigationType navType) { var view = _views.LastOrDefault(); if (view == null) { return; } _views.RemoveAll(v => Device.Reflector.IsAssignableFrom(typeof(LoginLayer), v.ModelType) && !Equals(v, view)); var monoView = view as IView; if (monoView?.Pair is Fragment) { view = DroidFactory.GetNativeObject <Fragment>(monoView, "view") as IMXView; } var fragment = view as Fragment; if (fragment == null) { _views.Remove(view); } else { #region Popover initialization FragmentManager popoverManager = null; if (Context.ActivePane == Pane.Popover) { #region Popover teardown if (view is VanityFragment) { DroidFactory.HideKeyboard(false); PopoverActivity.Close(true); PopoverFragment.Close(); return; } #endregion if (PopoverFragment.Instance != null) { popoverManager = PopoverFragment.ChildFragmentManager; } else if (PopoverActivity.Instance == null) { IHistoryEntry frag; if (Build.VERSION.SdkInt > BuildVersionCodes.JellyBean && iApp.Factory.LargeFormFactor && ((frag = view as IHistoryEntry ?? (view as IPairable)?.Pair as IHistoryEntry) == null || frag.PopoverPresentationStyle != PopoverPresentationStyle.FullScreen)) { var name = Java.Lang.Class.FromType(typeof(PopoverFragment)).Name; var dialog = (DialogFragment)Fragment.Instantiate(DroidFactory.MainActivity, name); dialog.Show(DroidFactory.MainActivity.FragmentManager, null); } else { DroidFactory.MainActivity.StartActivity(MXContainer.Resolve <Type>("Popover")); } return; } } #endregion iApp.CurrentNavContext.ActivePane = Context.ActivePane; iApp.CurrentNavContext.ActiveLayer = view.GetModel() as iLayer; (popoverManager ?? DroidFactory.MainActivity.FragmentManager) .BeginTransaction() .Replace(FragmentId, fragment) .CommitAllowingStateLoss(); } #region Update screen titles if (Context.ActivePane == Pane.Popover) { PopoverFragment.UpdateTitle(); var titleUpdater = PopoverActivity.Instance?.GetType().GetMethod("UpdateTitle", BindingFlags.Static | BindingFlags.NonPublic); titleUpdater?.Invoke(null, null); } else if (DroidFactory.Tabs == null || !DroidFactory.Tabs.TabItems.Any()) { DroidFactory.RefreshTitles(); } else { DroidFactory.Tabs.Title = monoView?.Title ?? iApp.Instance.Title; } #endregion }