public void AddFragmentOver(BaseFragment fragment) { if (fragment == null) { return; } //dotn replace an the existing fragment with one of the same type. var existingFragment = GetOverFragment(); if (existingFragment.GetType() == fragment.GetType()) { return; } var tag = fragment.GetType().Name; var transaction = SupportFragmentManager.BeginTransaction(); transaction.Replace(Resource.Id.over_fragment, fragment); transaction.AddToBackStack(tag); transaction.Commit(); SupportFragmentManager.ExecutePendingTransactions(); UpdateToolbar(); }
protected override void OnStart() { base.OnStart(); // Create a fragment for every setting that will be shown in this page var settingHighestPriorityFragment = new SettingsFragment(LocalizationResource.SettingHighestPriorityName, LocalizationResource.SettingHighestPriorityDescription, SettingType.Toggleable); var settingRecalculateTasksFragment = new SettingsFragment(LocalizationResource.SettingRecalculateTasksName, LocalizationResource.SettingRecalculateTasksDescription, SettingType.Toggleable); var settingChangeLanguageFragment = new SettingsFragment(LocalizationResource.SettingChangeLanguageName, LocalizationResource.SettingChangeLanguageDescription, SettingType.MultipleValues); // Show them in the view SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.settingHighestPriority, settingHighestPriorityFragment) .Replace(Resource.Id.settingRecalculateTasks, settingRecalculateTasksFragment) .Replace(Resource.Id.settingChangeLanguage, settingChangeLanguageFragment) .AddToBackStack(null) .Commit(); SupportFragmentManager.ExecutePendingTransactions(); // Setup bindings for every fragment SetupBindingForSettingEntry(settingHighestPriorityFragment, "Checked HighestPrioritySetAsFirst"); SetupBindingForSettingEntry(settingRecalculateTasksFragment, "Checked RecalculateTasksAfterBreak"); SetupBindingForSettingEntry(settingChangeLanguageFragment, "ItemsSource LanguageItems; SelectedItem LanguageValue"); // For dropdown, make manual binding for selected item because automatic one doesn't work var initialValuePosition = (BindingContext.DataContext as SettingsPageViewModel).LanguageItems.IndexOf((BindingContext.DataContext as SettingsPageViewModel).LanguageValue); (settingChangeLanguageFragment.SettableView as MvxSpinner).ItemSelected += MvxSpinner_ItemSelected; (settingChangeLanguageFragment.SettableView as MvxSpinner).SetSelection(initialValuePosition); }
public virtual void OnTabChanged(string tag) { var newTab = _lookup[tag]; if (_currentTab != newTab) { var ft = SupportFragmentManager.BeginTransaction(); OnTabFragmentChanging(tag, ft); if (_currentTab?.CachedFragment != null) { ft.Detach(_currentTab.CachedFragment); } if (newTab != null) { if (newTab.CachedFragment == null) { newTab.CachedFragment = Fragment.Instantiate(this, FragmentJavaName(newTab.FragmentType), newTab.Bundle); FixupDataContext(newTab); ft.Add(_tabContentId, newTab.CachedFragment, newTab.Tag); } else { FixupDataContext(newTab); ft.Attach(newTab.CachedFragment); } } _currentTab = newTab; ft.Commit(); SupportFragmentManager.ExecutePendingTransactions(); } }
private void openPinInputFrag() { SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.rlforfrag, pinInputFragment, "PINFRAGMENT") .AddToBackStack(null) .Commit(); SupportFragmentManager.ExecutePendingTransactions(); }
protected void ReplaceFragment(Fragment fragment, int fragmentTargetResId, bool addToBackstack = true, string tag = null) { if (addToBackstack) { SupportFragmentManager.BeginTransaction().Replace(fragmentTargetResId, fragment, tag).AddToBackStack(tag).Commit(); } else { SupportFragmentManager.BeginTransaction().Replace(fragmentTargetResId, fragment, tag).Commit(); } SupportFragmentManager.ExecutePendingTransactions(); }
/// <summary> /// Show Fragment with a specific tag at a specific placeholder /// </summary> /// <param name="tag">The tag for the fragment to lookup</param> /// <param name="contentId">Where you want to show the Fragment</param> /// <param name="bundle">Bundle which usually contains a Serialized MvxViewModelRequest</param> /// <param name="forceAddToBackStack">If you want to force add the fragment to the backstack so on backbutton it will go back to it. Note: This will override IMvxCachedFragmentInfo.AddToBackStack configuration.</param> /// <param name="forceReplaceFragment">Force replace a fragment with the same tag at the same contentid</param> protected void ShowFragment(string tag, int contentId, Bundle bundle = null, bool forceAddToBackStack = false, bool forceReplaceFragment = false) { IMvxCachedFragmentInfo fragInfo; FragmentCacheConfiguration.TryGetValue(tag, out fragInfo); if (fragInfo == null) { throw new MvxException("Could not find tag: {0} in cache, you need to register it first.", tag); } // We shouldn't replace the current fragment unless we really need to. var shouldReplaceCurrentFragment = forceReplaceFragment || ShouldReplaceCurrentFragment(contentId, tag); if (!shouldReplaceCurrentFragment) { return; } var ft = SupportFragmentManager.BeginTransaction(); OnBeforeFragmentChanging(fragInfo, ft); fragInfo.ContentId = contentId; //If we already have a previously created fragment, we only need to send the new parameters if (fragInfo.CachedFragment != null) { fragInfo.CachedFragment.Arguments.Clear(); fragInfo.CachedFragment.Arguments.PutAll(bundle); } else { //Otherwise, create one and cache it fragInfo.CachedFragment = Fragment.Instantiate(this, FragmentJavaName(fragInfo.FragmentType), bundle); OnFragmentCreated(fragInfo, ft); } ft.Replace(fragInfo.ContentId, fragInfo.CachedFragment, fragInfo.Tag); if (fragInfo.AddToBackStack || forceAddToBackStack) { ft.AddToBackStack(fragInfo.Tag); } OnFragmentChanging(fragInfo, ft); ft.Commit(); //TODO: manager crashes sometimes SupportFragmentManager.ExecutePendingTransactions(); OnFragmentChanged(fragInfo); }
/// <summary> /// Show Fragment with a specific tag at a specific placeholder /// </summary> /// <param name="tag">The tag for the fragment to lookup</param> /// <param name="contentId">Where you want to show the Fragment</param> /// <param name="bundle">Bundle which usually contains a Serialized MvxViewModelRequest</param> protected void ShowFragment(string tag, int contentId, Bundle bundle = null) { FragmentInfo fragInfo; _lookup.TryGetValue(tag, out fragInfo); if (fragInfo == null) { throw new MvxException("Could not find tag: {0} in cache, you need to register it first.", tag); } string currentFragment; _currentFragments.TryGetValue(contentId, out currentFragment); // Only do something if we are not currently showing the tag at the contentId if (IsContentIdCurrentyShowingFragmentWithTag(contentId, tag)) { return; } var ft = SupportFragmentManager.BeginTransaction(); OnBeforeFragmentChanging(tag, ft); // if there is a Fragment showing on the contentId we want to present at // remove it first. RemoveFragmentIfShowing(ft, contentId); fragInfo.ContentId = contentId; // if we haven't already created a Fragment, do it now if (fragInfo.CachedFragment == null) { fragInfo.CachedFragment = Fragment.Instantiate(this, FragmentJavaName(fragInfo.FragmentType), bundle); ft.Add(fragInfo.ContentId, fragInfo.CachedFragment, fragInfo.Tag); } else { ft.Attach(fragInfo.CachedFragment); } _currentFragments[contentId] = fragInfo.Tag; OnFragmentChanging(tag, ft); ft.Commit(); SupportFragmentManager.ExecutePendingTransactions(); }
/// <summary> /// Called when [save instance state]. /// </summary> /// <param name="outState">State of the out.</param> protected override void OnSaveInstanceState(Bundle outState) { this.Log().Debug("OnSaveInstanceState => {0}", Convert.ToString(outState)); // Utility.ReleaseSubscriptions(_subscriptions); // Detach current fragment if (!String.IsNullOrEmpty(_currentFragmentTag)) { var ft = SupportFragmentManager.BeginTransaction(); RemoveCurrentFragment(ft); ft.Commit(); } SupportFragmentManager.ExecutePendingTransactions(); base.OnSaveInstanceState(outState); this.Log().Debug("OnSaveInstanceState => currentFragmentTag '{0}'", _currentFragmentTag); }
public override void OnBackPressed() { var fragment = SupportFragmentManager.FindFragmentByTag("PINKEYBOARDFRAGMENT"); if (fragment == null) { base.OnBackPressed(); } else { RunOnUiThread(() => { var transaction = SupportFragmentManager.BeginTransaction(); transaction.Remove(pinKeyBoardFragment); transaction.Commit(); SupportFragmentManager.ExecutePendingTransactions(); }); pinKeyFragmentVisible = false; } }
protected override async void OnResume() { base.OnResume(); //// if bluetooth is enabled fire off enable ble request (caught by the bluetooth reciever which will //// then turn on the bluetooth device if (_androidBluetoothManager.Adapter.IsEnabled) { DisableBluetooth(); } else { EnableBluetooth(); } // refresh browser //_webView.LoadUrl("javascript:window.location.reload(true)"); var needsPermissionRequest = ZXing.Net.Mobile.Android.PermissionsHandler.NeedsPermissionRequest(this); if (needsPermissionRequest) { await ZXing.Net.Mobile.Android.PermissionsHandler.RequestPermissionsAsync(this); } if (_scanFragment == null) { _scanFragment = new ZXingScannerFragment(); SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.mainBarcodeScannerFrameLayout, _scanFragment) .Commit(); SupportFragmentManager.ExecutePendingTransactions(); } if (!needsPermissionRequest) { StartScanningForQRCode(); } }
private void EnterSearchUi() { inSearchUI = true; // Unset scroll flag var toolbarParams = collapsingToolbar.LayoutParameters as AppBarLayout.LayoutParams; toolbarParams.ScrollFlags &= ~AppBarLayout.LayoutParams.ScrollFlagScroll; if (mSearchFragment == null) { AddSearchFragment(); return; } mSearchFragment.UserVisibleHint = true; var transaction = SupportFragmentManager .BeginTransaction(); transaction.Show(mSearchFragment); transaction.CommitAllowingStateLoss(); SupportFragmentManager.ExecutePendingTransactions(); SetupSearchUi(); }
public void OnFocusChange(View v, bool hasFocus) { if (hasFocus && v.GetType() == typeof(Android.Support.V7.Widget.AppCompatEditText)) { pinKeyFragmentVisible = true; SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.rlforfrag, pinKeyBoardFragment, "PINKEYBOARDFRAGMENT") .Commit(); SupportFragmentManager.ExecutePendingTransactions(); } else { RunOnUiThread(() => { var transaction = SupportFragmentManager.BeginTransaction(); transaction.Remove(pinKeyBoardFragment); transaction.Commit(); SupportFragmentManager.ExecutePendingTransactions(); }); pinKeyFragmentVisible = false; } }
public virtual void OnTabChanged(string tag) { var newTab = _lookup[tag]; if (_currentTab != newTab) { var ft = SupportFragmentManager.BeginTransaction(); OnTabFragmentChanging(tag, ft); if (_currentTab?.CachedFragment != null) { ft.Detach(_currentTab.CachedFragment); } if (newTab != null) { if (newTab.CachedFragment == null) { var fragmentClass = Class.FromType(newTab.FragmentType); newTab.CachedFragment = SupportFragmentManager.FragmentFactory.Instantiate( fragmentClass.ClassLoader, fragmentClass.Name ); FixupDataContext(newTab); ft.Add(_tabContentId, newTab.CachedFragment, newTab.Tag); } else { FixupDataContext(newTab); ft.Attach(newTab.CachedFragment); } } _currentTab = newTab; ft.Commit(); SupportFragmentManager.ExecutePendingTransactions(); } }
/// <summary> /// Show Fragment with a specific tag at a specific placeholder /// </summary> /// <param name="tag">The tag for the fragment to lookup</param> /// <param name="contentId">Where you want to show the Fragment</param> /// <param name="bundle">Bundle which usually contains a Serialized MvxViewModelRequest</param> /// <param name="forceAddToBackStack">If you want to force add the fragment to the backstack so on backbutton it will go back to it. Note: This will override IMvxCachedFragmentInfo.AddToBackStack configuration.</param> /// <param name="forceReplaceFragment">If you want the fragment to be re-created</param> protected virtual void ShowFragment(string tag, int contentId, Bundle bundle, bool forceAddToBackStack = false, bool forceReplaceFragment = false) { IMvxCachedFragmentInfo fragInfo; FragmentCacheConfiguration.TryGetValue(tag, out fragInfo); IMvxCachedFragmentInfo currentFragInfo = null; var currentFragment = SupportFragmentManager.FindFragmentById(contentId); if (currentFragment != null) { FragmentCacheConfiguration.TryGetValue(currentFragment.Tag, out currentFragInfo); } if (fragInfo == null) { throw new MvxException("Could not find tag: {0} in cache, you need to register it first.", tag); } // We shouldn't replace the current fragment unless we really need to. FragmentReplaceMode fragmentReplaceMode = FragmentReplaceMode.ReplaceFragmentAndViewModel; if (!forceReplaceFragment) { fragmentReplaceMode = ShouldReplaceCurrentFragment(fragInfo, currentFragInfo, bundle); } if (fragmentReplaceMode == FragmentReplaceMode.NoReplace) { return; } var ft = SupportFragmentManager.BeginTransaction(); OnBeforeFragmentChanging(fragInfo, ft); fragInfo.ContentId = contentId; //If we already have a previously created fragment, we only need to send the new parameters if (fragInfo.CachedFragment != null && fragmentReplaceMode == FragmentReplaceMode.ReplaceFragment) { fragInfo.CachedFragment.Arguments.Clear(); fragInfo.CachedFragment.Arguments.PutAll(bundle); } else { //Otherwise, create one and cache it fragInfo.CachedFragment = Fragment.Instantiate(this, FragmentJavaName(fragInfo.FragmentType), bundle); OnFragmentCreated(fragInfo, ft); } ft.Replace(fragInfo.ContentId, fragInfo.CachedFragment, fragInfo.Tag); //if replacing ViewModel then clear the cache after the fragment //has been added to the transaction so that the Tag property is not null //and the UniqueImmutableCacheTag property (if not overridden) has the correct value if (fragmentReplaceMode == FragmentReplaceMode.ReplaceFragmentAndViewModel) { var cache = Mvx.GetSingleton <IMvxMultipleViewModelCache>(); cache.GetAndClear(fragInfo.ViewModelType, GetTagFromFragment(fragInfo.CachedFragment)); } if (fragInfo.AddToBackStack || forceAddToBackStack) { ft.AddToBackStack(fragInfo.Tag); } OnFragmentChanging(fragInfo, ft); ft.Commit(); SupportFragmentManager.ExecutePendingTransactions(); OnFragmentChanged(fragInfo); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); AndroidEnvironment.UnhandledExceptionRaiser += (sender, e) => { RetailMobile.Error.LogError(this, e.Exception.Message, e.Exception.StackTrace); }; PreferencesUtil.LoadSettings(this); Sync.GenerateDatabase(this); SetContentView(Resource.Layout.main); pbLoadingLayout = FindViewById <RelativeLayout>(Resource.Id.pbLoadingLayout); RelativeLayout layoutFragment1 = FindViewById <RelativeLayout>(Resource.Id.fragment1); RelativeLayout layoutFragment2 = FindViewById <RelativeLayout>(Resource.Id.fragment2); RelativeLayout layoutFragment3 = FindViewById <RelativeLayout>(Resource.Id.fragment3); LinearLayout layout2 = FindViewById <LinearLayout>(Resource.Id.layout2); mainActionBar = (RetailMobile.Fragments.ItemActionBar)SupportFragmentManager.FindFragmentById(Resource.Id.ActionBar1); bool isLoggedIn = false; if (layoutFragment1 != null) { if (!string.IsNullOrEmpty(PreferencesUtil.Username) && !string.IsNullOrEmpty(PreferencesUtil.Password) && LoginFragment.Login(this, PreferencesUtil.Username, PreferencesUtil.Password)) { isLoggedIn = true; if (layoutFragment2 == null && layoutFragment3 == null) { fragmentInvoice = new InvoiceInfoFragment(); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment1, fragmentInvoice); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.AddToBackStack("Invoice"); ft.Commit(); } else { fragmentMainMenu = new MainMenuFragment(); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment1, fragmentMainMenu); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.AddToBackStack("MainMenu"); ft.Commit(); } } else { isLoggedIn = false; LoginFragment fragmentLogin = new LoginFragment(); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment1, fragmentLogin); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.AddToBackStack("Login"); ft.Commit(); } } if (layoutFragment2 != null && layoutFragment3 != null) { if (isLoggedIn) { layout2.Visibility = ViewStates.Visible; fragmentDetails = DetailsFragment.NewInstance((int)MainMenu.MenuItems.Invoices); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment2, fragmentDetails); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); fragmentInvoice = InvoiceInfoFragment.NewInstance(0); ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment3, fragmentInvoice); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); } else { layoutFragment3.Visibility = ViewStates.Gone; layoutFragment2.Visibility = ViewStates.Gone; } } if (layoutFragment2 == null && layoutFragment3 == null) { menu = new Com.Jeremyfeinstein.Slidingmenu.Lib.SlidingMenu(this); menu.Mode = 0; menu.TouchModeAbove = SlidingMenu.TouchmodeNone; menu.SetShadowWidthRes(Resource.Dimension.shadow_width); menu.SetShadowDrawable(Resource.Drawable.shadow); menu.SetBehindOffsetRes(Resource.Dimension.slidingmenu_offset); menu.SetFadeDegree(0.35f); menu.AttachToActivity(this, Com.Jeremyfeinstein.Slidingmenu.Lib.SlidingMenu.SlidingContent); menu.SetMenu(Resource.Layout.FragmentMainMenu); } SupportFragmentManager.ExecutePendingTransactions(); System.Threading.Tasks.Task.Factory.StartNew(() => Sync.SyncUsers(this)).ContinueWith(task => this.RunOnUiThread(() => HideProgressBar())); }