void RemovePage(Page page) { if (!_isAttachedToWindow) { PushCurrentPages(); } Fragment fragment = GetPageFragment(page); if (fragment == null) { return; } #if DEBUG // Enables logging of moveToState operations to logcat #pragma warning disable CS0618 // Type or member is obsolete FragmentManager.EnableDebugLogging(true); #pragma warning restore CS0618 // Type or member is obsolete #endif // Go ahead and take care of the fragment bookkeeping for the page being removed FragmentTransaction transaction = FragmentManager.BeginTransactionEx(); transaction.RemoveEx(fragment); transaction.CommitAllowingStateLossEx(); // And remove the fragment from our own stack _fragmentStack.Remove(fragment); Device.StartTimer(TimeSpan.FromMilliseconds(10), () => { UpdateToolbar(); return(false); }); }
private void ReplaceTopFragment(SupportFragment fragmentView) { try { if (fragmentView.IsVisible) { return; } var trans = SupportFragmentManager.BeginTransaction(); trans.Replace(TopFragment.Id, fragmentView); if (SupportFragmentManager.BackStackEntryCount == 0) { trans.AddToBackStack(null); } trans.Commit(); TopFragment.TranslationY = 1200; TopFragment.Animate().SetInterpolator(new FastOutSlowInInterpolator()).TranslationYBy(-1200) .SetDuration(500); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
protected virtual void OnBeforeFragmentChanging(FragmentTransaction ft, Fragment fragment, MvxFragmentPresentationAttribute attribute, MvxViewModelRequest request) { if (CurrentActivity is IMvxAndroidSharedElements sharedElementsActivity) { var elements = new List<string>(); foreach (KeyValuePair<string, View> item in sharedElementsActivity.FetchSharedElementsToAnimate(attribute, request)) { var transitionName = item.Value.GetTransitionNameSupport(); if (!string.IsNullOrEmpty(transitionName)) { ft.AddSharedElement(item.Value, transitionName); elements.Add($"{item.Key}:{transitionName}"); } else { MvxLog.Instance.Warn("A XML transitionName is required in order to transition a control when navigating."); } } if (elements.Count > 0) fragment.Arguments.PutString(SharedElementsBundleKey, string.Join("|", elements)); } if (!attribute.EnterAnimation.Equals(int.MinValue) && !attribute.ExitAnimation.Equals(int.MinValue)) { if (!attribute.PopEnterAnimation.Equals(int.MinValue) && !attribute.PopExitAnimation.Equals(int.MinValue)) ft.SetCustomAnimations(attribute.EnterAnimation, attribute.ExitAnimation, attribute.PopEnterAnimation, attribute.PopExitAnimation); else ft.SetCustomAnimations(attribute.EnterAnimation, attribute.ExitAnimation); } if (attribute.TransitionStyle != int.MinValue) ft.SetTransitionStyle(attribute.TransitionStyle); }
private AndroidX.Fragment.App.Fragment CreateFragment(string tag) { AndroidX.Fragment.App.Fragment result = null; switch (tag) { case "clock_fragment": if (clockFragment == null) { clockFragment = new ClockFragment(); } result = clockFragment; break; case "notification_fragment": if (notificationFragment == null) { notificationFragment = new NotificationFragment(); } result = notificationFragment; break; case "music_fragment": if (musicFragment == null) { musicFragment = new MusicFragment(); } result = musicFragment; break; } Log.Debug("LiveDisplay", "create: " + result.ToString()); return(result); }
public bool OnNavigationItemSelected(IMenuItem item) { while (SupportFragmentManager.BackStackEntryCount != 0) { SupportFragmentManager.PopBackStackImmediate(); } switch (item.ItemId) { case Resource.Id.navigation_home: currentF = new MainFlowFragment(); loadFragment(currentF); return(true); case Resource.Id.navigation_plus: currentF = new NewPostFragment(); loadFragment(currentF); return(true); case Resource.Id.navigation_profile: currentF = new ProfileFragment(); loadFragment(currentF); return(true); } return(false); }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); if (ETC.useLightTheme) { SetTheme(Resource.Style.GFS_Toolbar_Light); } // Create your application here SetContentView(Resource.Layout.MainLayout); // Find View & Connect Event toolbar = FindViewById <AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.MainMainToolbar); fContainer = FindViewById <FrameLayout>(Resource.Id.MainFragmentContainer); bottomNavigation = FindViewById <BottomNavigationView>(Resource.Id.MainBottomNavigation); SetSupportActionBar(toolbar); SupportActionBar.SetTitle(Resource.String.MainActivity_Title); bottomNavigation.ItemSelected += (sender, e) => { ChangeFragment(e.Item.ItemId); }; // Set Fragment mainHomeF = new HomeFragment(); mainDBF = new DBFragment(); mainGFDv1F = new GFDv1Fragment(); mainGFUtilF = new GFUtilFragment(); mainOtherF = new OtherFragment(); // Set Program Exit Timer exitTimer.Interval = 2000; exitTimer.Elapsed += delegate { exitTimer.Stop(); }; // Load Init Process int startIndex = int.Parse(Preferences.Get("StartMainFragment", "0")); bottomNavigation.SelectedItemId = startIndex switch { 1 => Resource.Id.MainNavigation_DB, 2 => Resource.Id.MainNavigation_GFDv1, 3 => Resource.Id.MainNavigation_GFUtil, 4 => Resource.Id.MainNavigation_Other, _ => Resource.Id.MainNavigation_Home, }; _ = InitializeProcess(); } catch (Exception ex) { ETC.LogError(ex, this); Toast.MakeText(this, Resource.String.Activity_OnCreateError, ToastLength.Short).Show(); } }
protected override void Dispose(bool disposing) { if (_disposed) { return; } _disposed = true; if (disposing) { if (_currentFragment != null && !FragmentManager.IsDestroyed) { FragmentTransaction transaction = FragmentManager.BeginTransactionEx(); transaction.RemoveEx(_currentFragment); transaction.SetTransitionEx((int)FragmentTransit.None); transaction.CommitAllowingStateLossEx(); FragmentManager.ExecutePendingTransactionsEx(); _currentFragment = null; } _parent = null; _pageContainer = null; _fragmentManager = null; RemoveAllViews(); DisposeChildRenderers(); } base.Dispose(disposing); }
/// <summary> /// Wires a control to a property. /// This should be called in the Fragment's OnCreateView, with the newly inflated layout. /// </summary> /// <param name="fragment">The fragment.</param> /// <param name="inflatedView">The inflated view.</param> /// <param name="resolveMembers">The resolve members.</param> public static void WireUpControls(this Fragment fragment, View inflatedView, ResolveStrategy resolveMembers = ResolveStrategy.Implicit) { if (fragment is null) { throw new ArgumentNullException(nameof(fragment)); } var members = fragment.GetWireUpMembers(resolveMembers); foreach (var member in members) { try { // Find the android control with the same name from the view var view = inflatedView.GetControl(fragment.GetType().Assembly, member.GetResourceName()); // Set the activity field's value to the view with that identifier member.SetValue(fragment, view); } catch (Exception ex) { throw new MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex); } } }
void AddTransitionTimer(TaskCompletionSource <bool> tcs, Fragment fragment, FragmentManager fragmentManager, IReadOnlyCollection <Fragment> fragmentsToRemove, int duration, bool shouldUpdateToolbar) { Device.StartTimer(TimeSpan.FromMilliseconds(duration), () => { tcs.TrySetResult(true); Current?.SendAppearing(); if (shouldUpdateToolbar) { UpdateToolbar(); } if (fragmentsToRemove.Count > 0) { FragmentTransaction fragmentTransaction = fragmentManager.BeginTransactionEx(); foreach (Fragment frag in fragmentsToRemove) { fragmentTransaction.RemoveEx(frag); } fragmentTransaction.CommitAllowingStateLossEx(); } return(false); }); }
private void PopFragment(FragmentManager fragmentManager, MvxFragmentPresentationAttribute fragmentAttribute, Fragment fragmentToPop) { var ft = fragmentManager.BeginTransaction(); if (!fragmentAttribute.EnterAnimation.Equals(int.MinValue) && !fragmentAttribute.ExitAnimation.Equals(int.MinValue)) { if (!fragmentAttribute.PopEnterAnimation.Equals(int.MinValue) && !fragmentAttribute.PopExitAnimation.Equals(int.MinValue)) { ft.SetCustomAnimations( fragmentAttribute.EnterAnimation, fragmentAttribute.ExitAnimation, fragmentAttribute.PopEnterAnimation, fragmentAttribute.PopExitAnimation); } else { ft.SetCustomAnimations( fragmentAttribute.EnterAnimation, fragmentAttribute.ExitAnimation); } } if (fragmentAttribute.TransitionStyle != int.MinValue) { ft.SetTransitionStyle(fragmentAttribute.TransitionStyle); } ft.Remove(fragmentToPop); ft.CommitAllowingStateLoss(); OnFragmentPopped(ft, fragmentToPop, fragmentAttribute); }
protected virtual void OnBeforeFragmentChanging( FragmentTransaction fragmentTransaction, Fragment fragment, MvxFragmentPresentationAttribute attribute, MvxViewModelRequest request) { if (fragmentTransaction == null) { throw new ArgumentNullException(nameof(fragmentTransaction)); } if (fragment == null) { throw new ArgumentNullException(nameof(fragment)); } ValidateArguments(attribute, request); if (CurrentActivity.IsActivityAlive() && CurrentActivity is IMvxAndroidSharedElements sharedElementsActivity) { var elements = new List <string>(); foreach (var(key, value) in sharedElementsActivity.FetchSharedElementsToAnimate(attribute, request)) { var transitionName = value.GetTransitionNameSupport(); if (!string.IsNullOrEmpty(transitionName)) { fragmentTransaction.AddSharedElement(value, transitionName); elements.Add($"{key}:{transitionName}"); } else { _logger.Value?.Log(LogLevel.Warning, "A XML transitionName is required in order to transition a control when navigating."); } } if (elements.Count > 0) { fragment.Arguments.PutString(SharedElementsBundleKey, string.Join("|", elements)); } } if (!attribute.EnterAnimation.Equals(int.MinValue) && !attribute.ExitAnimation.Equals(int.MinValue)) { if (!attribute.PopEnterAnimation.Equals(int.MinValue) && !attribute.PopExitAnimation.Equals(int.MinValue)) { fragmentTransaction.SetCustomAnimations(attribute.EnterAnimation, attribute.ExitAnimation, attribute.PopEnterAnimation, attribute.PopExitAnimation); } else { fragmentTransaction.SetCustomAnimations(attribute.EnterAnimation, attribute.ExitAnimation); } } if (attribute.TransitionStyle != int.MinValue) { fragmentTransaction.SetTransitionStyle(attribute.TransitionStyle); } }
public void LoadFragment(Fragment fragment) { var transaction = SupportFragmentManager.BeginTransaction(); transaction.Replace(Resource.Id.main_fragment, fragment); transaction.AddToBackStack(null); transaction.Commit(); }
public static void Replace(Activity activity, Fragment fragment) { if (activity is AppCompatActivity compatActivity) { compatActivity.SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.content_frame, fragment) .Commit(); } }
private static bool TryHandleBackPress(Fragment fragment) { if (fragment is IHandleBack backHandler) { return(backHandler.OnBackPressed()); } return(false); }
internal static void OnClick(Fragment fragment, View view, Func <View, bool> onClick) { var stopCall = onClick(view); if (!stopCall && fragment.Activity is View.IOnClickListener listener) { listener.OnClick(view); } }
public HomeAdapter(Fragment context, HomeViewModel home) : base() { this.context = context; posts = home.Flow; avtrs = home.UsersAvatars; nicks = home.UsersNames; listener = OnClick; }
public static void StartActivity(this Fragment fragment, Type activityType) { var activity = fragment.Activity; if (activity == null) { return; } activity.StartActivity(activityType); }
protected override void OnDonePressed(AndroidX.Fragment.App.Fragment currentFragment) { AppSettings.AppTutorialInit = true; base.OnDonePressed(currentFragment); var intent = new Intent(this, typeof(MainActivity)); StartActivity(intent); Finish(); }
public override void OnFragmentViewDestroyed( AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f) { if (f is NavigationViewFragment pf) { _stackNavigationManager.OnNavigationViewFragmentDestroyed(fm, pf); } base.OnFragmentViewDestroyed(fm, f); }
private bool loadFragment(Fragment fragment) { if (fragment != null) { AndroidX.Fragment.App.FragmentTransaction ft = fm.BeginTransaction(); ft.SetCustomAnimations(Resource.Animation.fragment_open_enter, Resource.Animation.fragment_open_exit, Resource.Animation.abc_popup_enter, Resource.Animation.abc_popup_exit); ft.Replace(Resource.Id.fragmContainer, fragment).Commit(); return(true); } return(false); }
private static TFragment SafeCast <TFragment>(Fragment fragment) where TFragment : Fragment { if (!(fragment is TFragment)) { MvxLog.Instance.Warn("Fragment type mismatch got {0} but expected {1}", fragment.GetType().FullName, typeof(TFragment).FullName); return(default(TFragment)); } return((TFragment)fragment); }
public static void Push(Activity activity, Fragment fragment) { if (activity is AppCompatActivity compatActivity) { compatActivity.SupportFragmentManager.BeginTransaction() .AddToBackStack(null) //.SetCustomAnimations(Resource.Animation.fragment_slide_in_from_bottom, Resource.Animation.fragment_fade_out, Resource.Animation.fragment_fade_in, Resource.Animation.fragment_slide_out_to_bottom) .SetCustomAnimations(Resource.Animation.fragment_fade_in, Resource.Animation.fragment_fade_out, Resource.Animation.fragment_fade_in, Resource.Animation.fragment_fade_out) .Replace(Resource.Id.content_frame, fragment) .Commit(); } }
private static TFragment SafeCast <TFragment>(Fragment fragment) where TFragment : Fragment { if (!(fragment is TFragment)) { MvxLogHost.Default?.Log(LogLevel.Warning, "Fragment type mismatch got {fragmentType} but expected {expectedType}", fragment.GetType().FullName, typeof(TFragment).FullName); return(default(TFragment)); } return((TFragment)fragment); }
private void PerformFragmentNavigation(SupportFragment fragment, string fragmentTag) { var menuTransaction = SupportFragmentManager.BeginTransaction(); menuTransaction.SetCustomAnimations(Resource.Animation.abc_slide_in_top, Resource.Animation.abc_fade_out); menuTransaction.Replace(Resource.Id.fragment_container, fragment, fragmentTag); menuTransaction.AddToBackStack(null); menuTransaction.Commit(); }
public override void OnAttachFragment(AndroidX.Fragment.App.Fragment fragment) { base.OnAttachFragment(fragment); if (fragment is PostsFragment postsFragment) { postsFragment.Delegate = this; } else if (fragment is CommentsFragment postsDetailFragment) { postsDetailFragment.Delegate = this; } }
public static NavController?GetNavController(this Fragment fragment, View?view = null) { NavController?navController = null; if (fragment.Activity is IHostNavController host) { navController = host.NavController; } if (navController == null && view != null) { navController = Navigation.FindNavController(view); } return(navController); }
private void ReplaceFragment(AndroidX.Fragment.App.Fragment newFragment) { string tag = newFragment.Id.ToString(); var transaction = SupportFragmentManager.BeginTransaction(); transaction.DisallowAddToBackStack(); transaction.SetTransition((int)FragmentTransit.FragmentOpen); int fadeInAnimId = Resource.Animation.abc_fade_in; int fadeOutAnimId = Resource.Animation.abc_fade_out; transaction.SetCustomAnimations(fadeInAnimId, fadeOutAnimId, fadeInAnimId, fadeOutAnimId); transaction.Replace(Resource.Id.navigation_fragment_frame, newFragment, tag); transaction.Commit(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (ETC.useLightTheme) { SetTheme(Resource.Style.GFS_NoActionBar_Light); } // Create your application here SetContentView(Resource.Layout.CalcMainLayout); ETC.LoadDBSync(ETC.skillTrainingList, "SkillTraining.gfs", true); ETC.LoadDBSync(ETC.freeOPList, "FreeOP.gfs", true); // Set Main Drawer mainDrawerLayout = FindViewById <DrawerLayout>(Resource.Id.Calc_MainDrawerLayout); mainDrawerLayout.DrawerOpened += delegate { SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.MenuOpen); }; mainDrawerLayout.DrawerClosed += delegate { SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.Menu); }; mainNavigationView = FindViewById <NavigationView>(Resource.Id.Calc_NavigationView); mainNavigationView.NavigationItemSelected += MainNavigationView_NavigationItemSelected; // Set ActionBar SetSupportActionBar(FindViewById <AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.Calc_Toolbar)); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetDisplayShowTitleEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); SupportActionBar.Title = Resources.GetString(Resource.String.TitleName_ExpItemCalc); SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.Menu); // Set Fragment ft = SupportFragmentManager.BeginTransaction(); expItemCalcF = new ExpItemCalc(); coreCalcF = new DummyCore(); coalitionGradeF = new CoalitionGrade(); skillTrainingCalcF = new SkillTraining(); fstGradeUpF = new FSTGradeUp(); areaExpCalcF = new AreaExpCalc(); ft.Add(Resource.Id.CalcFragmentContainer, expItemCalcF, "ExpItemCalc"); ft.Commit(); }
public void OnTabSelected(AndroidX.AppCompat.App.ActionBar.Tab tab, AndroidX.Fragment.App.FragmentTransaction ft) { var className = Java.Lang.Class.FromType(fragmentType).Name; if (fragment == null) { fragment = AndroidX.Fragment.App.Fragment.Instantiate(parent, className, args); ft.Add(Android.Resource.Id.Content, fragment, tag); } else { ft.Attach(fragment); } // TODO: Add AutoTracking here once the autoTracking fixes make it into the SDK. }
public TabListener(AppCompatActivity activity, string tag, Bundle args = null) { this.parent = activity; this.tag = tag; this.fragmentType = typeof(TFragment); this.args = args; this.fragment = parent.SupportFragmentManager.FindFragmentByTag(tag); if (fragment != null && !fragment.IsDetached) { activity.SupportFragmentManager.BeginTransaction() .Detach(fragment) .Commit(); } }