public override void AddView(AView child, int index, LayoutParams @params) { if (index == -1 && AddFlag && child.GetType().ToString() == sPageContainer) { index = ChildCount - 1; } base.AddView(child, index, @params); if (child is AToolbar) { Toolbar = child as AToolbar; } else if (child.GetType().ToString() == sPageContainer) { PageContainer = child as ViewGroup; var layoutParam = new LayoutParams(LayoutParams.MatchParent, 8); if (!AddFlag) { AddView(ProgressBar, layoutParam); } } else if (child is AProgressBar) { AddFlag = true; } }
public override void AddView(Android.Views.View child) { child.GetType().GetRuntimeProperty("TopPadding").SetValue(child, 0); var padding = child.GetType().GetRuntimeProperty("TopPadding").GetValue(child); base.AddView(child); }
public bool OnDrag(AViews.View v, DragEvent e) { switch (e.Action) { case DragAction.Started: break; case DragAction.Entered: System.Diagnostics.Debug.WriteLine($"DragAction.Entered from {v.GetType()}"); break; case DragAction.Location: break; case DragAction.Exited: System.Diagnostics.Debug.WriteLine($"DragAction.Entered from {v.GetType()}"); if (!(v is AWidget.ListView)) { var positionEntered = GetListPositionForView(v); System.Diagnostics.Debug.WriteLine($"DragAction.Exited index {positionEntered}"); } break; case DragAction.Drop: System.Diagnostics.Debug.WriteLine($"DragAction.Drop from {v.GetType()}"); var mobileItem = (DragItem)e.LocalState; if (!(v is AWidget.ListView) && v != mobileItem.View) { mobileItem.Index = GetListPositionForView(v); mobileItem.View.Visibility = ViewStates.Visible; if (_element.ItemsSource is IOrderable orderable) { orderable.ChangeOrdinal(mobileItem.OriginalIndex, mobileItem.Index); } } break; case DragAction.Ended: System.Diagnostics.Debug.WriteLine($"DragAction.Drop from {v.GetType()}"); break; } return(true); }
public override void OnViewAdded(View child) { base.OnViewAdded(child); if (child.GetType() == typeof(Toolbar)) { Toolbar = (Toolbar)child; LayoutParent = new LinearLayout(Toolbar.Context) { LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent), Orientation = Orientation.Vertical }; LayoutParent.SetGravity(GravityFlags.Center); TextViewTitle = new TextView(LayoutParent.Context) { LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent) }; TextViewTitle.SetTextAppearance(Resource.Style.TextAppearance_AppCompat_Widget_ActionBar_Title); LayoutParent.AddView(TextViewTitle); Toolbar.AddView(LayoutParent); } CurrentPage = Element?.Navigation?.NavigationStack?.Last(); if (CurrentPage != null) { CurrentPage.PropertyChanged += PagePropertyChanged; Setup(CurrentPage); } }
void ClearChildren(ViewGroup group) { if (group == null) { return; } int count = group.ChildCount; for (var i = 0; i < count; i++) { AView child = group.GetChildAt(i); var g = child as ViewGroup; if (g != null) { ClearChildren(g); } Type childType = child.GetType(); Stack <AView> stack; if (!_freeViews.TryGetValue(childType, out stack)) { _freeViews[childType] = stack = new Stack <AView>(); } stack.Push(child); } group.RemoveAllViews(); }
protected Delegate CreateEventHandler(object target, View view, MethodMapping methodMapping, out EventInfo evnt) { Delegate del = null; evnt = null; if (view != null) { evnt = view.GetType().GetEvent(methodMapping.Attribute.EventName); if (evnt != null) { try { del = CreateDelegate(target, methodMapping, evnt); } catch (Exception ex) { Geneticist.HandleError( ex, "Error creating delegate from '{0}' for event '{1}'.", methodMapping.Method.Name, methodMapping.Attribute.EventName); } } else { Geneticist.HandleError( "Unable to find event '{0}' for method '{1}'.", methodMapping.Attribute.EventName, methodMapping.Method.Name); } } return del; }
public override void OnViewAdded(Android.Views.View child) { if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) { _toolbar = (Android.Support.V7.Widget.Toolbar)child; _toolbar.ChildViewAdded += Toolbar_ChildViewAdded; } }
// hide keyboard when clicking anywhere but EditText protected void setupParent(View view) { //Set up touch listener for non-text box and not checkbox views to hide keyboard. if (!(view.OnCheckIsTextEditor()) && view.GetType() != typeof (CheckBox) && view.Id != Resource.Id.colorsCheckBoxesLayout) { view.Touch += (sender, args) => { hideSoftKeyboard(); }; } //If a layout container, iterate over children if (view.GetType().BaseType == typeof(ViewGroup)) { for (int i = 0; i < ((ViewGroup) view).ChildCount; i++) { View innerView = ((ViewGroup) view).GetChildAt(i); setupParent(innerView); } } }
public override void OnViewAdded(Android.Views.View child) { base.OnViewAdded(child); if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) { _toolbar = (Android.Support.V7.Widget.Toolbar)child; _toolbar.SetBackgroundColor(global::Android.Graphics.Color.White); } }
public override void OnViewAdded(Android.Views.View child) { base.OnViewAdded(child); if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) { _toolbar = (Android.Support.V7.Widget.Toolbar)child; } }
public override void OnViewAdded(Android.Views.View child) { base.OnViewAdded(child); if (child.GetType() == typeof(Support.Toolbar)) { var lastPage = Element?.Navigation?.NavigationStack?.Last(); /*if (_toolbar !=null) * { * _toolbar.ChildViewAdded -= OnToolbarChildViewAdded; * var lPage = Element?.Navigation?.NavigationStack?.Last(); * lPage.PropertyChanged -= LastPage_PropertyChanged; * }*/ _toolbar = (Android.Support.V7.Widget.Toolbar)child; _originalToolbarBackground = _toolbar.Background; var originalContent = (Context as Activity)?.Window?.DecorView?.FindViewById <FrameLayout>(Window.IdAndroidContent); if (originalContent != null) { _originalWindowContent = originalContent.Foreground; } _parentLayout = new Android.Widget.FrameLayout(_toolbar.Context) { LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent) }; //Create custom title view layout _titleViewLayout = new Android.Widget.LinearLayout(_parentLayout.Context) { Orientation = Android.Widget.Orientation.Vertical, LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent) }; _titleTextView = new AppCompatTextView(_parentLayout.Context) { LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent) }; //Add title/subtitle to title view layout _titleViewLayout.AddView(_titleTextView); //Add title view layout to main layout _parentLayout.AddView(_titleViewLayout); //Add main layout to toolbar _toolbar.AddView(_parentLayout); _toolbar.ChildViewAdded += OnToolbarChildViewAdded; lastPage.PropertyChanged += LastPage_PropertyChanged; } }
public override void OnViewAdded(Android.Views.View child) { base.OnViewAdded(child); if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) { toolbar = (Android.Support.V7.Widget.Toolbar)child; toolbar.SetForegroundGravity(GravityFlags.Center); toolbar.ChildViewAdded += Toolbar_ChildViewAdded; } }
public override void OnViewRemoved(Android.Views.View child) { base.OnViewRemoved(child); if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) { if (_toolbar != null) { var lastPage = Element?.Navigation?.NavigationStack?.Last(); _toolbar.ChildViewAdded -= OnToolbarChildViewAdded; } } }
public override void OnViewAdded(Android.Views.View child) { try { base.OnViewAdded(child); if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) { toolbar = (Android.Support.V7.Widget.Toolbar)child; toolbar.ChildViewAdded += Toolbar_ChildViewAdded; } } catch { } }
public override void RemoveView(AView view) { base.RemoveView(view); if (view.GetType().ToString() == sPageContainer) { PageContainer = null; } else if (view is AProgressBar) { AddFlag = false; } }
/// <summary> /// When adding a view, tweak the top padding if necessary. /// According to: /// https://github.com/xamarin/Xamarin.Forms/blob/589adbd3ef145ec85f9fe64eda008251c1cdb745/Xamarin.Forms.Platform.Android/AppCompat/MasterDetailPageRenderer.cs /// The TopPadding is always set for the detail. This works fine when the master detail is shown normally, but /// if it is inside a navigation page (such as the inspection view) then you get extra unwanted padding. /// The 'fix' is to set the top padding to 0 for the detail, only of course the types and fields are hidden from us... /// </summary> /// <param name="child">Child.</param> public override void AddView(Android.Views.View child) { try { var isMasterField = child.GetType().GetField("_isMaster", BindingFlags.NonPublic | BindingFlags.Instance); if (isMasterField == null) { return; } var isMaster = isMasterField.GetValue(child); if ((bool)isMaster) { return; } var parentField = child.GetType().GetField("_parent", BindingFlags.NonPublic | BindingFlags.Instance); if (parentField == null) { return; } var parent = parentField.GetValue(child) as MasterDetailPage; if (parent == null || !(parent.Parent is NavigationPage)) { return; } var topPaddingProperty = child.GetType().GetProperty("TopPadding", BindingFlags.Public | BindingFlags.Instance); if (topPaddingProperty != null) { topPaddingProperty.SetValue(child, 0); } } finally { base.AddView(child); } }
void Disp(Android.Views.View vi, string spc = "") { System.Diagnostics.Debug.WriteLine("{0}{1}", spc, vi.GetType().Name); var vg = vi as ViewGroup; if (vg != null) { for (int i = 0; i < vg.ChildCount; i++) { var v = vg.GetChildAt(i); Disp(v, spc + " "); } } }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { var navigationPage = Element as NavigationPage; if (navigationPage.BarBackgroundColor != Color.Transparent) { if (navigationPage.CurrentPage.GetType() != typeof(PetProfilePage)) { base.OnLayout(changed, l, t + ActionBarHeight(), r, b + ActionBarHeight()); } } else { base.OnLayout(changed, l, t, r, b + ActionBarHeight()); } AToolbar bar = _toolbar; bar.BringToFront(); for (var i = 0; i < ChildCount; i++) { AView child = GetChildAt(i); var pageContainer = child.GetType().GetProperty("Child")?.GetValue(child) as IVisualElementRenderer; Page childPage = pageContainer?.Element as Page; if (childPage == null) { return; } bool childHasNavBar = NavigationPage.GetHasNavigationBar(childPage); if (childHasNavBar) { if (navigationPage.BarBackgroundColor != Color.Transparent) { if (navigationPage.CurrentPage.GetType() != typeof(PetProfilePage)) { child.Layout(0, ActionBarHeight(), r, b + ActionBarHeight()); } } else { child.Layout(0, 0, r, b + ActionBarHeight()); } } } }
public override void OnViewAdded(Android.Views.View child) { base.OnViewAdded(child); if (child.GetType() == typeof(Toolbar)) { _toolbar = (Toolbar)child; if (MainActivity.ToolBar == null) { MainActivity.ToolBar = _toolbar; MainActivity.ToolBar.SetBackgroundColor(Element.BarBackgroundColor.ToAndroid()); } } }
public Binding(View target, string targetProperty, object source, string sourceProperty, Func<object, object> convert, Func<object, object> convertBack) { Target = target; Source = source; TargetProperty = Target.GetType().GetProperty(targetProperty); SourceProperty = Source.GetType().GetProperty(sourceProperty); Convert = convert; ConvertBack = convertBack; Target.FocusChange += Target_FocusChange; var inpc = Source as INotifyPropertyChanged; if (inpc != null) inpc.PropertyChanged += Source_PropertyChanged; UpdateTarget(); }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); AToolbar bar = _toolbar; bar.BringToFront(); //int barHeight = ActionBarHeight(); //bar.Measure(MeasureSpecFactory.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(barHeight, MeasureSpecMode.Exactly)); //var barOffset = ToolbarVisible ? barHeight : 0; //int containerHeight = b - t - ContainerPadding; //PageController.ContainerArea = new Rectangle(0, 0, Context.FromPixels(r - l), Context.FromPixels(containerHeight)); for (var i = 0; i < ChildCount; i++) { AView child = GetChildAt(i); var pageContainer = child.GetType().GetProperty("Child")?.GetValue(child) as IVisualElementRenderer; Page childPage = pageContainer?.Element as Page; if (childPage == null) { return; } // We need to base the layout of both the child and the bar on the presence of the NavBar on the child Page itself. // If we layout the bar based on ToolbarVisible, we get a white bar flashing at the top of the screen. // If we layout the child based on ToolbarVisible, we get a white bar flashing at the bottom of the screen. bool childHasNavBar = NavigationPage.GetHasNavigationBar(childPage); if (childHasNavBar) { //bar.Layout(0, 0, r - l, barHeight); child.Layout(0, 0, r, b); } } }
public override void OnViewRemoved(Android.Views.View child) { base.OnViewRemoved(child); if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) { if (_toolbar != null) { try { var lastPage = Element?.Navigation?.NavigationStack?.Last(); _toolbar.ChildViewAdded -= OnToolbarChildViewAdded; lastPage.PropertyChanged -= LastPage_PropertyChanged; } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } } }
public override void OnViewAdded(Android.Views.View child) { base.OnViewAdded(child); if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) { _toolbar = (Android.Support.V7.Widget.Toolbar)child; _originalToolbarBackground = _toolbar.Background; var originalContent = (Context as Activity)?.Window?.DecorView?.FindViewById <FrameLayout>(Window.IdAndroidContent); if (originalContent != null) { _originalWindowContent = originalContent.Foreground; } _leftMenuLayout = new Android.Widget.LinearLayout(_toolbar.Context) { Orientation = Android.Widget.Orientation.Horizontal, LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent), }; _rightMenuLayout = new Android.Widget.LinearLayout(_toolbar.Context) { Orientation = Android.Widget.Orientation.Horizontal, LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent), }; //foreach (var item in Element.CurrentPage.ToolbarItems) //{ // if (item.Priority == 0) // { // _leftMenuLayout.AddView(GetButton(item)); // } // else // { // _rightMenuLayout.AddView(GetButton(item)); // } //} //Create custom title view layout _titleViewLayout = new Android.Widget.LinearLayout(_toolbar.Context) { Orientation = Android.Widget.Orientation.Vertical, LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent), }; //Create custom title text view _titleTextView = new TextView(_titleViewLayout.Context) { Gravity = GravityFlags.CenterHorizontal, LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent), }; //Create custom subtitle text view _subTitleTextView = new TextView(_titleViewLayout.Context) { LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent) }; _titleViewLayout.AddView(_titleTextView); _titleViewLayout.AddView(_subTitleTextView); _toolbar.AddView(_titleViewLayout); _toolbar.AddView(_leftMenuLayout); _toolbar.AddView(_rightMenuLayout); _toolbar.ChildViewAdded += OnToolbarChildViewAdded; } }
public static void UpdateView(View view, object value) { if (view != null) { string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed case "Android.Widget.ProgressBar": { var progressBar = (ProgressBar)view; int progressValue = (int)(value ?? 0); if (progressBar.Progress != progressValue) progressBar.Progress = progressValue; } break; case "Android.Webkit.WebView": { var webView = (Android.Webkit.WebView)view; if (value is Uri) { string newUrl = value.ToString(); if (webView.Url != newUrl) webView.LoadUrl(newUrl); } else { webView.LoadData(value == null ? "" : value.ToString(), "text/html", null); } } break; case "Macaw.UIComponents.MultiImageView": { if (value is Uri) value = ((Uri)value).AbsoluteUri; var multiImageView = (Macaw.UIComponents.MultiImageView)view; multiImageView.LoadImageList(value == null ? null : new[] { (string)value }); multiImageView.LoadImage(); // TODO: Update to MultiImageView 1.2 when it is published, to fix hang on no connection and to get rid of this LoadImage call. } break; default: if (view is TextView) { var textView = (TextView)view; string text = value == null ? "" : value.ToString(); if (textView.Text != text) textView.Text = text; } else if (view is AdapterView) { var adapterView = (AdapterView)view; var adapter = adapterView.GetAdapter() as IDataBindableListAdapter; if (adapter != null) { int position = adapter.GetItemPosition(value); if (adapterView is AbsListView) { var absListView = (AbsListView)adapterView; if (!absListView.IsItemChecked(position)) { absListView.SetItemChecked(position, true); } } else { if (adapterView.SelectedItemPosition != position) adapterView.SetSelection(position); } } } else throw new NotImplementedException("View type not implemented: " + viewTypeName); break; } } }
private static bool ViewDrawerIsOpenedGetDefaultValue(View view, IBindingMemberInfo bindingMemberInfo) { DrawerLayout drawer = FindDrawer(view); if (drawer == null) { IBindingMemberInfo rootMember = BindingServiceProvider.VisualTreeManager.GetRootMember(view.GetType()); if (rootMember != null) rootMember.TryObserve(view, DrawerInitializer.Instance); return false; } DrawerListenerImpl.GetOrAdd(drawer); return drawer.IsDrawerOpen(view); }
/// <summary> /// Traverses the view hierarchy and updates the bindings. /// </summary> protected void BindViewTree(object dataSource, View view, IList<WeakReference> reusableBindings = null) { var tag = view.GetBindingTag (); if (tag != null) { if (!tag.BindingEnabled) return; if (tag.OverrideDataSource) dataSource = tag.DataSource; if (tag.BindingDescriptions != null) { if (dataSource == null) { MvxBindingTrace.Trace( MvxTraceLevel.Warning, "Binding view {0} with an empty data source.", view.GetType().Name); } if (tag.Bindings.Count > 0 || dataSource != null) { // Try to reuse weak reference for the tag: WeakReference weakTag = null; if (reusableBindings != null) { for (var i = 0; i < reusableBindings.Count; i++) { if (reusableBindings[i] == null) continue; if (reusableBindings[i].Target == tag) { weakTag = reusableBindings[i]; reusableBindings[i] = null; } } } if (weakTag == null) weakTag = new WeakReference(tag); _viewTags.Add(weakTag); if (tag.Bindings.Count > 0) { // Update old bindings only: foreach (var binding in tag.Bindings) { binding.DataContext = dataSource; } } else { // Create bindings: var bindings = this.GetService<IMvxBinder>() .Bind(dataSource, view, tag.BindingDescriptions); if (bindings != null) { foreach (var binding in bindings) { tag.Bindings.Add(binding); } } } } } } var viewGroup = view as ViewGroup; if (viewGroup != null) { var count = viewGroup.ChildCount; for (var i = 0; i < count; i++) { BindViewTree(dataSource, viewGroup.GetChildAt(i), reusableBindings); } } }
public bool OnDrag(AViews.View view, AViews.DragEvent e) { switch (e.Action) { case AViews.DragAction.Started: break; case AViews.DragAction.Entered: System.Diagnostics.Debug.WriteLine($"DragAction.Entered from {view.GetType()}"); if (!(view is AWidget.ListView)) { var dragItem = (DragItem)e.LocalState; var targetPosition = InsertOntoView(view, dragItem); dragItem.Index = targetPosition; // Keep a list of items that has translation so we can reset // them once the drag'n'drop is finished. translatedItems.Add(view); listView.Invalidate(); } break; case AViews.DragAction.Location: break; case AViews.DragAction.Exited: System.Diagnostics.Debug.WriteLine($"DragAction.Entered from {view.GetType()}"); if (!(view is AWidget.ListView)) { var positionEntered = GetListPositionForView(view); System.Diagnostics.Debug.WriteLine($"DragAction.Exited index {positionEntered}"); } break; case AViews.DragAction.Drop: System.Diagnostics.Debug.WriteLine($"DragAction.Drop from {view.GetType()}"); break; case AViews.DragAction.Ended: System.Diagnostics.Debug.WriteLine($"DragAction.Ended from {view.GetType()}"); if (!(view is AWidget.ListView)) { return(false); } var mobileItem = (DragItem)e.LocalState; mobileItem.View.Visibility = AViews.ViewStates.Visible; foreach (var v in translatedItems) { v.TranslationY = 0; } translatedItems.Clear(); if (element.ItemsSource is IOrderableCollection orderable) { orderable.ChangeOrder(mobileItem.OriginalIndex, mobileItem.Index); } break; } return(true); }
protected virtual IDataContext GetDataContext(View view, Context context, IAttributeSet attrs) { var dataContext = new DataContext(); var strings = ReadStringAttributeValue(context, attrs, Resource.Styleable.Binding, BindingAttrIndex); if (strings != null && strings.Count != 0) dataContext.Add(ViewFactoryConstants.Bindings, strings); SetAttributeValue(view, context, attrs, Resource.Styleable.ItemsControl, Resource.Styleable.ItemsControl_ItemTemplate, AttachedMemberConstants.ItemTemplate, dataContext, ViewFactoryConstants.ItemTemplateId); SetAttributeValue(view, context, attrs, Resource.Styleable.ItemsControl, Resource.Styleable.ItemsControl_DropDownItemTemplate, AttachedMembers.AdapterView.DropDownItemTemplate, dataContext, ViewFactoryConstants.DropDownItemTemplateId); SetAttributeValue(view, context, attrs, Resource.Styleable.Control, Resource.Styleable.Control_ContentTemplate, AttachedMemberConstants.ContentTemplate, dataContext, ViewFactoryConstants.ContentTemplateId); SetAttributeValue(view, context, attrs, Resource.Styleable.Menu, Resource.Styleable.Menu_MenuTemplate, AttachedMembers.Toolbar.MenuTemplate, dataContext, ViewFactoryConstants.MenuTemplateId); SetAttributeValue(view, context, attrs, Resource.Styleable.Menu, Resource.Styleable.Menu_PopupMenuTemplate, AttachedMembers.View.PopupMenuTemplate, dataContext, ViewFactoryConstants.PopupMenuTemplateId); strings = ReadStringAttributeValue(context, attrs, Resource.Styleable.Menu, new[] { Resource.Styleable.Menu_PopupMenuEvent }); if (strings != null && strings.Count > 0) { string eventName = strings[0]; dataContext.Add(ViewFactoryConstants.PopupMenuEvent, eventName); IBindingMemberInfo member = BindingServiceProvider .MemberProvider .GetBindingMember(view.GetType(), AttachedMembers.View.PopupMenuEvent, false, false); if (member != null) member.SetSingleValue(view, eventName); } strings = ReadStringAttributeValue(context, attrs, Resource.Styleable.Menu, new[] { Resource.Styleable.Menu_PlacementTargetPath }); if (strings != null && strings.Count > 0) { string path = strings[0]; dataContext.Add(ViewFactoryConstants.PlacementTargetPath, path); IBindingMemberInfo member = BindingServiceProvider .MemberProvider .GetBindingMember(view.GetType(), AttachedMembers.View.PopupMenuPlacementTargetPath, false, false); if (member != null) member.SetSingleValue(view, path); } return dataContext; }
private static void SetAttributeValue(View view, Context context, IAttributeSet attrs, int[] groupId, int requiredAttributeId, string attachedMemberName, IDataContext dataContext, DataConstant<int> constant) { int? value = ReadAttributeValueId(context, attrs, groupId, requiredAttributeId); if (!value.HasValue) return; dataContext.Add(constant, value.Value); IBindingMemberInfo member = BindingServiceProvider .MemberProvider .GetBindingMember(view.GetType(), attachedMemberName, false, false); if (member != null) member.SetSingleValue(view, value); }
public bool OnDrag(AViews.View v, DragEvent e) { switch (e.Action) { case DragAction.Started: break; case DragAction.Entered: System.Diagnostics.Debug.WriteLine($"DragAction.Entered from {v.GetType()}"); if (!(v is AWidget.ListView)) { var dragItem = (DragItem)e.LocalState; var targetPosition = InsertOntoView(v, dragItem); dragItem.Index = targetPosition; // Keep a list of items that has translation so we can reset // them once the drag'n'drop is finished. _translatedItems.Add(v); _listView.Invalidate(); } break; case DragAction.Location: //_currentPosition = (int)e.GetY(); //System.Diagnostics.Debug.WriteLine($"DragAction.Location from {v.GetType()} => {_currentPosition}"); break; case DragAction.Exited: System.Diagnostics.Debug.WriteLine($"DragAction.Entered from {v.GetType()}"); if (!(v is AWidget.ListView)) { var positionEntered = GetListPositionForView(v); var item1 = _listAdapter.GetItem(positionEntered); System.Diagnostics.Debug.WriteLine($"DragAction.Exited index {positionEntered}"); } break; case DragAction.Drop: System.Diagnostics.Debug.WriteLine($"DragAction.Drop from {v.GetType()}"); //} break; case DragAction.Ended: if (!(v is AWidget.ListView)) { return(false); } System.Diagnostics.Debug.WriteLine($"DragAction.Ended from {v.GetType()}"); var mobileItem = (DragItem)e.LocalState; mobileItem.View.Visibility = ViewStates.Visible; foreach (var view in _translatedItems) { view.TranslationY = 0; } _translatedItems.Clear(); if (_element.ItemsSource is IOrderable orderable) { orderable.ChangeOrdinal(mobileItem.OriginalIndex, mobileItem.Index); } break; } return(true); }
public override void AddView (View child) { try { base.AddView (child); } catch { Console.WriteLine ("!!!! Caught exception: Failed to add View: " + child.GetType ()); } }
public static void UpdateView(View view, object value) { if (view != null) { string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed case "Android.Widget.ProgressBar": { var progressBar = (ProgressBar)view; int progressValue = (int)(value ?? 0); if (progressBar.Progress != progressValue) progressBar.Progress = progressValue; } break; case "Android.Webkit.WebView": { var webView = (Android.Webkit.WebView)view; if (value is Uri) { string newUrl = value.ToString(); if (webView.Url != newUrl) webView.LoadUrl(newUrl); } else { webView.LoadData(value == null ? "" : value.ToString(), "text/html", null); } } break; default: if (view is TextView) { var textView = (TextView)view; string text = value == null ? "" : value.ToString(); if (textView.Text != text) textView.Text = text; } else if (view is AdapterView) { var adapterView = (AdapterView)view; var adapter = adapterView.GetAdapter() as IDataBindableListAdapter; if (adapter != null) { int position = adapter.GetItemPosition(value); if (adapterView is AbsListView) { var absListView = (AbsListView)adapterView; if (!absListView.IsItemChecked(position)) { absListView.SetItemChecked(position, true); } } else { if (adapterView.SelectedItemPosition != position) adapterView.SetSelection(position); } } } else throw new NotImplementedException("View type not implemented: " + viewTypeName); break; } } }
/** * Called when a view loaded and call a mapping function * * @param view the calling view * @param mappedObject If available, the object to map with the view. Else add the view to mappingWaitings */ public void CallMappingOnView(CarpaccioAction action, View view, Object mappedObject) { if (action.IsCallMapping) { CarpaccioLogger.d(TAG, "callMappingOnView mapping=" + mappedObject + " action=" + action.CompleteCall + " view=" + view.GetType().Name); string arg = action.Args[0]; //only map the first argument string objectName; string call; if (arg.Contains(".")) { //"$user.getName()" call = arg.Substring(1, arg.Length - 1); // "user.getName()" objectName = call.Substring(0, arg.IndexOf('.') - 1); // "user" } else { objectName = arg.Substring(1, arg.Length - 1); // "user" call = objectName; // "user" } //if you already have the object if (mappedObject != null) { string value = Evaluate(mappedObject, call); CarpaccioLogger.d(TAG, "callMappingOnView evaluate(" + call + ")" + " on " + mappedObject.GetType().Name + " returned " + value); action.Values = new[]{value}; //TODO MappingManagerCallback.CallActionOnView(action, view); } else { //add to waiting List<MappingWaiting> waitings = MappingWaitings.GetOrDefault(objectName) ?? new List<MappingWaiting>(); //["user"] = List<MappingWaiting> waitings.Add(new MappingWaiting(view, action, call, objectName)); CarpaccioLogger.d(TAG, "added to waiting " + call + " for " + view.GetType().Name); MappingWaitings.AddOrUpdate(objectName, waitings); } } }