void DisposeSwipeItems() { if (_actionView != null) { _actionView.RemoveFromParent(); _actionView.Dispose(); _actionView = null; } }
protected override void Dispose(bool disposing) { if (_isDisposed) { return; } if (disposing) { if (Element != null) { Element.CloseRequested -= OnCloseRequested; } if (_detector != null) { _detector.Dispose(); _detector = null; } if (_scrollParent != null) { if (_scrollParent is ScrollView scrollView) { scrollView.Scrolled -= OnParentScrolled; } if (_scrollParent is ListView listView) { listView.Scrolled -= OnParentScrolled; } if (_scrollParent is Xamarin.Forms.CollectionView collectionView) { collectionView.Scrolled -= OnParentScrolled; } } if (_contentView != null) { _contentView.RemoveFromParent(); _contentView.Dispose(); _contentView = null; } if (_actionView != null) { _actionView.RemoveFromParent(); _actionView.Dispose(); _actionView = null; } } _isDisposed = true; base.Dispose(disposing); }
void DisposeSwipeItems() { if (_actionView != null) { RemoveView(_actionView); _actionView.Dispose(); _actionView = null; } }
void UpdateSwipeItems() { if (_contentView == null || _actionView != null) { return; } SwipeItems items = GetSwipeItemsByDirection(); if (items == null || items.Count == 0) { return; } _actionView = new LinearLayoutCompat(_context); using (var layoutParams = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)) _actionView.LayoutParameters = layoutParams; _actionView.Orientation = LinearLayoutCompat.Horizontal; var swipeItems = new List <AView>(); foreach (var item in items) { AView swipeItem = null; if (item is SwipeItem formsSwipeItem) { formsSwipeItem.PropertyChanged += OnSwipeItemPropertyChanged; swipeItem = CreateSwipeItem(formsSwipeItem); _actionView.AddView(swipeItem); _swipeItems.Add(formsSwipeItem, swipeItem); } if (item is SwipeItemView formsSwipeItemView) { formsSwipeItemView.PropertyChanged += OnSwipeItemPropertyChanged; swipeItem = CreateSwipeItemView(formsSwipeItemView); _actionView.AddView(swipeItem); UpdateSwipeItemViewLayout(formsSwipeItemView); _swipeItems.Add(formsSwipeItemView, swipeItem); } swipeItems.Add(swipeItem); } AddView(_actionView); _contentView?.BringToFront(); _actionView.Layout(0, 0, _contentView.Width, _contentView.Height); LayoutSwipeItems(swipeItems); swipeItems.Clear(); }
protected override void Dispose(bool disposing) { if (_isDisposed) { return; } if (disposing) { if (Element != null) { Element.CloseRequested -= OnCloseRequested; } if (_detector != null) { _detector.Dispose(); _detector = null; } if (_scrollParent != null) { if (_scrollParent is AbsListView listView) { listView.ScrollStateChanged += OnParentScrollStateChanged; } else { _scrollParent.ScrollChange -= OnParentScrollChange; } _scrollParent = null; } if (_contentView != null) { _contentView.RemoveFromParent(); _contentView.Dispose(); _contentView = null; } if (_actionView != null) { _actionView.RemoveFromParent(); _actionView.Dispose(); _actionView = null; } } _isDisposed = true; base.Dispose(disposing); }
void DisposeSwipeItems() { _isOpen = false; _swipeThreshold = 0; if (_actionView != null) { _actionView.RemoveFromParent(); _actionView.Dispose(); _actionView = null; } }
Task RunWindowTest <THandler>(IWindow window, Func <THandler, Task> action) where THandler : class, IElementHandler { return(InvokeOnMainThreadAsync(async() => { AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup; var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context); var fragmentManager = MauiContext.GetFragmentManager(); var viewFragment = new WindowTestFragment(MauiContext, window); try { linearLayoutCompat.Id = AView.GenerateViewId(); fragmentManager .BeginTransaction() .Add(linearLayoutCompat.Id, viewFragment) .Commit(); rootView.AddView(linearLayoutCompat); await viewFragment.FinishedLoading; if (typeof(THandler).IsAssignableFrom(window.Handler.GetType())) { await action((THandler)window.Handler); } else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType())) { await action((THandler)window.Content.Handler); } } finally { if (window.Handler != null) { window.Handler.DisconnectHandler(); } rootView.RemoveView(linearLayoutCompat); fragmentManager .BeginTransaction() .Remove(viewFragment) .Commit(); await linearLayoutCompat.OnUnloadedAsync(); if (viewFragment.View != null) { await viewFragment.View.OnUnloadedAsync(); } } })); }
void DisposeSwipeItems() { _isOpen = false; UnsubscribeSwipeItemEvents(); _swipeItems.Clear(); if (_actionView != null) { _actionView.RemoveFromParent(); _actionView.Dispose(); _actionView = null; } }
protected override void OnCreate(Bundle savedInstanceState) { Log.Debug(TAG, "OnCreate"); base.OnCreate(savedInstanceState); ScriptId = Intent.Extras.GetInt(nameof(ScriptModel.Id), 0); CardTitle = FindViewById <AppCompatTextView>(Resource.Id.command_card_title); CardSubtitle = FindViewById <AppCompatTextView>(Resource.Id.command_card_subtitle); HiddenCommandCheckBox = FindViewById <AppCompatCheckBox>(Resource.Id.checkBoxHiddenCommand); PauseSecondsBeforeStarting = FindViewById <AppCompatEditText>(Resource.Id.editTextPauseSecBeforeExecuting); FooterLayout = FindViewById <LinearLayoutCompat>(Resource.Id.command_footer_layout); RequiredCondition = FindViewById <SwitchCompat>(Resource.Id.switchCondition); HardwareCondition = FindViewById <AppCompatSpinner>(Resource.Id.spinnerCommandHardwareCondition); PortCondition = FindViewById <AppCompatSpinner>(Resource.Id.spinnerCommandPortCondition); StateCondition = FindViewById <AppCompatSpinner>(Resource.Id.spinnerCommandStateCondition); RequiredCondition.Checked = false; // HardwareCondition.Enabled = false; PortCondition.Enabled = false; StateCondition.Enabled = false; TypesCommand = FindViewById <AppCompatSpinner>(Resource.Id.spinnerTypeCommand); about_selected_command = FindViewById <AppCompatTextView>(Resource.Id.about_selected_command); CommandConfigForm = FindViewById <LinearLayoutCompat>(Resource.Id.command_config_form); ButtonOk = FindViewById <AppCompatButton>(Resource.Id.command_button_ok); HardwaresListSpinnerLoad(ref HardwareCondition); ArrayAdapter adapterPortStatusesCondition = ArrayAdapter <string> .CreateFromResource(this, Resource.Array.required_condition_port_states_array, Android.Resource.Layout.SimpleSpinnerItem); adapterPortStatusesCondition.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); StateCondition.Adapter = adapterPortStatusesCondition; ArrayAdapter adapterTypesCommands = ArrayAdapter <string> .CreateFromResource(this, Resource.Array.commands_types_array, Android.Resource.Layout.SimpleSpinnerItem); adapterTypesCommands.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); TypesCommand.Adapter = adapterTypesCommands; }
protected override void OnPause() { base.OnPause(); SettingsLogView.Click -= SettingsLogButton_Click; RefreshLogView.Click -= RefreshLogButton_Click; if (SettingsLogViewForm != null) { SettingsLogViewForm = LayoutInflater.Inflate(Resource.Layout.FormSettingsLogView, SettingsLogViewArea, false) as LinearLayoutCompat; // checkBoxTracView.CheckedChange -= CheckBoxTracView_CheckedChange; checkBoxInfoView.CheckedChange -= CheckBoxTracView_CheckedChange; checkBoxWarnView.CheckedChange -= CheckBoxTracView_CheckedChange; checkBoxErrView.CheckedChange -= CheckBoxTracView_CheckedChange; // SettingsLogViewArea.AddView(SettingsLogViewForm); } }
private void SettingsLogButton_Click(object sender, EventArgs e) { bool LOG_SETTINGS_FORM_VISIBLE = SettingsLogViewForm == null; Preferences.Set(Constants.LOG_SETTINGS_FORM_VISIBLE, LOG_SETTINGS_FORM_VISIBLE); // if (LOG_SETTINGS_FORM_VISIBLE) { SettingsLogViewForm = LayoutInflater.Inflate(Resource.Layout.FormSettingsLogView, SettingsLogViewArea, false) as LinearLayoutCompat; // checkBoxTracView = SettingsLogViewForm.FindViewById <AppCompatCheckBox>(Resource.Id.checkBoxTracView); checkBoxTracView.Checked = Preferences.Get(Resources.GetResourceEntryName(checkBoxTracView.Id), true); checkBoxTracView.CheckedChange += CheckBoxTracView_CheckedChange; checkBoxInfoView = SettingsLogViewForm.FindViewById <AppCompatCheckBox>(Resource.Id.checkBoxInfoView); checkBoxInfoView.Checked = Preferences.Get(Resources.GetResourceEntryName(checkBoxInfoView.Id), true); checkBoxInfoView.CheckedChange += CheckBoxTracView_CheckedChange; checkBoxWarnView = SettingsLogViewForm.FindViewById <AppCompatCheckBox>(Resource.Id.checkBoxWarnView); checkBoxWarnView.Checked = Preferences.Get(Resources.GetResourceEntryName(checkBoxWarnView.Id), true); checkBoxWarnView.CheckedChange += CheckBoxTracView_CheckedChange; checkBoxErrView = SettingsLogViewForm.FindViewById <AppCompatCheckBox>(Resource.Id.checkBoxErrView); checkBoxErrView.Checked = Preferences.Get(Resources.GetResourceEntryName(checkBoxErrView.Id), true); checkBoxErrView.CheckedChange += CheckBoxTracView_CheckedChange; // SettingsLogViewArea.AddView(SettingsLogViewForm); } else { checkBoxTracView.CheckedChange -= CheckBoxTracView_CheckedChange; checkBoxInfoView.CheckedChange -= CheckBoxTracView_CheckedChange; checkBoxWarnView.CheckedChange -= CheckBoxTracView_CheckedChange; checkBoxErrView.CheckedChange -= CheckBoxTracView_CheckedChange; // checkBoxTracView = null; checkBoxInfoView = null; checkBoxWarnView = null; checkBoxErrView = null; // SettingsLogViewArea.RemoveAllViews(); SettingsLogViewForm = null; } }
Task CreateNavigationViewHandlerAsync(IStackNavigationView navigationView, Func <NavigationViewHandler, Task> action) { return(InvokeOnMainThreadAsync(async() => { var context = MauiProgram.DefaultContext; var rootView = (context as AppCompatActivity).Window.DecorView as ViewGroup; var linearLayoutCompat = new LinearLayoutCompat(context); var fragmentManager = MauiContext.GetFragmentManager(); var viewFragment = new NavViewFragment(MauiContext); try { linearLayoutCompat.Id = View.GenerateViewId(); fragmentManager .BeginTransaction() .Add(linearLayoutCompat.Id, viewFragment) .Commit(); rootView.AddView(linearLayoutCompat); await viewFragment.FinishedLoading; var handler = CreateHandler(navigationView, viewFragment.ScopedMauiContext); if (navigationView is NavigationViewStub nvs && nvs.NavigationStack?.Count > 0) { navigationView.RequestNavigation(new NavigationRequest(nvs.NavigationStack, false)); await nvs.OnNavigationFinished; } await action(handler); } finally { rootView.RemoveView(linearLayoutCompat); fragmentManager .BeginTransaction() .Remove(viewFragment) .Commit(); } })); }
Task SetupWindowForTests <THandler>(IWindow window, Func <Task> runTests, IMauiContext mauiContext = null) where THandler : class, IElementHandler { mauiContext ??= MauiContext; return(InvokeOnMainThreadAsync(async() => { AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup; _decorDrawable ??= rootView.Background; var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context); var fragmentManager = MauiContext.GetFragmentManager(); var viewFragment = new WindowTestFragment(MauiContext, window); try { linearLayoutCompat.Id = AView.GenerateViewId(); rootView.AddView(linearLayoutCompat); fragmentManager .BeginTransaction() .Add(linearLayoutCompat.Id, viewFragment) .Commit(); await viewFragment.FinishedLoading; await runTests.Invoke(); } finally { if (window.Handler != null) { window.Handler.DisconnectHandler(); } fragmentManager .BeginTransaction() .Remove(viewFragment) .Commit(); rootView.RemoveView(linearLayoutCompat); await linearLayoutCompat.OnUnloadedAsync(); if (viewFragment.View != null) { await viewFragment.View.OnUnloadedAsync(); } await viewFragment.FinishedDestroying; // This is mainly to remove changes to the decor view that shell imposes if (_decorDrawable != rootView.Background) { rootView.Background = _decorDrawable; } // Unset the Support Action bar if the calling code has set the support action bar if (MauiContext.Context.GetActivity() is AppCompatActivity aca) { aca.SetSupportActionBar(null); } } })); }
Task RunWindowTest <THandler>(IWindow window, Func <THandler, Task> action) where THandler : class, IElementHandler { return(InvokeOnMainThreadAsync(async() => { AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup; _decorDrawable ??= rootView.Background; var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context); var fragmentManager = MauiContext.GetFragmentManager(); var viewFragment = new WindowTestFragment(MauiContext, window); try { linearLayoutCompat.Id = AView.GenerateViewId(); rootView.AddView(linearLayoutCompat); fragmentManager .BeginTransaction() .Add(linearLayoutCompat.Id, viewFragment) .Commit(); await viewFragment.FinishedLoading; if (window.Content is Shell shell) { await OnLoadedAsync(shell.CurrentPage); } if (typeof(THandler).IsAssignableFrom(window.Handler.GetType())) { await action((THandler)window.Handler); } else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType())) { await action((THandler)window.Content.Handler); } else if (window.Content is ContentPage cp && typeof(THandler).IsAssignableFrom(cp.Content.Handler.GetType())) { await action((THandler)cp.Content.Handler); } else { throw new Exception($"I can't work with {typeof(THandler)}"); } } finally { if (window.Handler != null) { window.Handler.DisconnectHandler(); } fragmentManager .BeginTransaction() .Remove(viewFragment) .Commit(); rootView.RemoveView(linearLayoutCompat); await linearLayoutCompat.OnUnloadedAsync(); if (viewFragment.View != null) { await viewFragment.View.OnUnloadedAsync(); } await viewFragment.FinishedDestroying; // This is mainly to remove changes to the decor view that shell imposes if (_decorDrawable != rootView.Background) { rootView.Background = _decorDrawable; } // Unset the Support Action bar if the calling code has set the support action bar if (MauiContext.Context.GetActivity() is AppCompatActivity aca) { aca.SetSupportActionBar(null); } // Ideally this wouldn't be needed but I haven't found the right platform // component I can key into for knowing when the world can move on await Task.Delay(1000); fragmentManager.ExecutePendingTransactions(); } }));
Task RunWindowTest <THandler>(IWindow window, Func <THandler, Task> action) where THandler : class, IElementHandler { return(InvokeOnMainThreadAsync(async() => { AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup; var decorBackground = rootView.Background; var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context); var fragmentManager = MauiContext.GetFragmentManager(); var viewFragment = new WindowTestFragment(MauiContext, window); try { linearLayoutCompat.Id = AView.GenerateViewId(); rootView.AddView(linearLayoutCompat); fragmentManager .BeginTransaction() .Add(linearLayoutCompat.Id, viewFragment) .Commit(); await viewFragment.FinishedLoading; if (typeof(THandler).IsAssignableFrom(window.Handler.GetType())) { await action((THandler)window.Handler); } else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType())) { await action((THandler)window.Content.Handler); } else if (window.Content is ContentPage cp && typeof(THandler).IsAssignableFrom(cp.Content.Handler.GetType())) { await action((THandler)cp.Content.Handler); } else { throw new Exception($"I can't work with {typeof(THandler)}"); } } finally { if (window.Handler != null) { window.Handler.DisconnectHandler(); } rootView.RemoveView(linearLayoutCompat); fragmentManager .BeginTransaction() .Remove(viewFragment) .Commit(); await linearLayoutCompat.OnUnloadedAsync(); if (viewFragment.View != null) { await viewFragment.View.OnUnloadedAsync(); } // This is mainly to remove changes to the decor view that shell imposes if (decorBackground != rootView.Background) { rootView.Background = decorBackground; } // Unset the Support Action bar if the calling code has set the support action bar if (MauiContext.Context.GetActivity() is AppCompatActivity aca) { aca.SetSupportActionBar(null); } } }));
protected override void OnCreate(Bundle savedInstanceState) { Log.Debug(TAG, "OnCreate"); base.OnCreate(savedInstanceState); lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { scriptHardware = db.Scripts.Include(x => x.Commands).Include(x => x.TriggerPort).FirstOrDefault(x => x.Id == Intent.Extras.GetInt(nameof(ScriptModel.Id), 0)); } } TopLayout = FindViewById <LinearLayoutCompat>(Resource.Id.script_top_layout); FooterLayout = FindViewById <LinearLayoutCompat>(Resource.Id.script_footer_layout); CardTitle.Text = GetText(Resource.String.script_edit_title); CardSubtitle.Text = GetText(Resource.String.script_edit_subtitle); DeleteScript = new AppCompatButton(this) { Text = GetText(Resource.String.delete_title) }; DeleteScript.SetTextColor(Color.DarkRed); DeleteScript.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); FooterLayout.AddView(DeleteScript); ButtonOk.Tag = scriptHardware.Id; CommandsScript = new AppCompatButton(this) { Text = $"{GetString(Resource.String.commands_title)} ({scriptHardware.Commands.Count})" }; CommandsScript.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); TopLayout.AddView(CommandsScript); StartScript = new AppCompatButton(this) { Text = GetText(Resource.String.run_the_script_title), Enabled = scriptHardware.Commands.Count > 0 }; StartScript.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); TopLayout.AddView(StartScript); ScriptName.Text = scriptHardware.Name; if (scriptHardware.TriggerPort != null) { AutorunTrigger.Checked = true; PortTrigger.Enabled = true; HardwareTrigger.Enabled = true; StateTrigger.Enabled = true; int indexPosition = Hardwares.Keys.ToList().IndexOf(scriptHardware.TriggerPort.HardwareId); HardwareTrigger.SetSelection(indexPosition); PortsList_UpdateSpinner(scriptHardware.TriggerPort.HardwareId, ref PortTrigger, scriptHardware.TriggerPort.Id);//, ref Ports string[] statuses = Resources.GetStringArray(Resource.Array.script_trigger_port_states_array); if (scriptHardware.TriggerPortState == true) { indexPosition = Array.IndexOf(statuses, GetString(Resource.String.abc_capital_on)); } else if (scriptHardware.TriggerPortState == false) { indexPosition = Array.IndexOf(statuses, GetString(Resource.String.abc_capital_off)); } else { indexPosition = Array.IndexOf(statuses, GetString(Resource.String.abc_capital_switch)); } StateTrigger.SetSelection(indexPosition); } }
protected void TypesCommand_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e) { //command_executer_id = -1; //command_executer_parameter = null; int Position = TypesCommand.SelectedItemPosition; selected_type_command_name = Resources.GetStringArray(Resource.Array.commands_types_array)[Position]; string command_type_array_item_port = GetString(Resource.String.command_type_array_item_port); string command_type_array_item_controller = GetString(Resource.String.command_type_array_item_controller); string command_type_array_item_transfer = GetString(Resource.String.command_type_array_item_transit); //if (AbstractSettingsManage.Command != null) //{ // switch (AbstractSettingsManage.Command.TypeCommand) // { // case TypesCommands.Port: // command_type_array_item_port = GetString(Resource.String.command_type_array_item_port); // if (selected_type_command_name != command_type_array_item_port) // { // return; // } // break; // case TypesCommands.Controller: // if (selected_type_command_name != command_type_array_item_controller) // { // return; // } // break; // case TypesCommands.Exit: // if (selected_type_command_name != command_type_array_item_transfer) // { // return; // } // break; // } //} Log.Debug(TAG, $"TypesCommand_ItemSelected({selected_type_command_name}) - Position:{Position}"); CommandConfigForm.RemoveAllViews(); if (selected_type_command_name == command_type_array_item_port) { SelectedTypeCommand = TypesCommands.Port; about_selected_command.Text = GetString(Resource.String.about_selected_command_port_title); CommandConfigFormBody = LayoutInflater.Inflate(Resource.Layout.FormPortCommand, CommandConfigForm, false) as LinearLayoutCompat; AppCompatSpinner Controllers = CommandConfigFormBody.FindViewById <AppCompatSpinner>(Resource.Id.spinnerControllerPortCommand); AppCompatSpinner Ports = CommandConfigFormBody.FindViewById <AppCompatSpinner>(Resource.Id.spinnerPortCommand); AppCompatSpinner States = CommandConfigFormBody.FindViewById <AppCompatSpinner>(Resource.Id.spinnerStateCommand); SettingsManageKit = new SettingsManagePort(this, Controllers, Ports, States); } else if (selected_type_command_name == command_type_array_item_controller) { SelectedTypeCommand = TypesCommands.Controller; about_selected_command.Text = GetString(Resource.String.about_selected_command_controller_title); CommandConfigFormBody = LayoutInflater.Inflate(Resource.Layout.FormControllerCommand, CommandConfigForm, false) as LinearLayoutCompat; AppCompatSpinner Controllers = CommandConfigFormBody.FindViewById <AppCompatSpinner>(Resource.Id.spinnerControllerCommand); EditText CommandText = CommandConfigFormBody.FindViewById <EditText>(Resource.Id.editTextParametrControllerCommand); SettingsManageKit = new SettingsManageController(this, Controllers, CommandText); } else if (selected_type_command_name == command_type_array_item_transfer) { SelectedTypeCommand = TypesCommands.Exit; about_selected_command.Text = GetString(Resource.String.about_selected_command_transit_title); CommandConfigFormBody = LayoutInflater.Inflate(Resource.Layout.FormTransferCommand, CommandConfigForm, false) as LinearLayoutCompat; AppCompatSpinner Scriptes = CommandConfigFormBody.FindViewById <AppCompatSpinner>(Resource.Id.spinnerCommandScript); AppCompatSpinner Steps = CommandConfigFormBody.FindViewById <AppCompatSpinner>(Resource.Id.spinnerCommandStepScript); SettingsManageKit = new SettingsManageTransfer(this, Scriptes, Steps); } else { } CommandConfigForm.AddView(CommandConfigFormBody); }