void InitPopupMenu() { int layoutWidth = (Resources.DisplayMetrics.WidthPixels * 31) / 100; int layoutHeight = 4 * ((int)Resources.GetDimension(Resource.Dimension.main_menu_icon_size) + 2); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(layoutWidth, layoutHeight); lp.AddRule(LayoutRules.Below, myActionBar.Id); lp.TopMargin = (int)Resources.GetDimension(Resource.Dimension.action_bar_height); RelativeLayout popupMenu = this.FindViewById <RelativeLayout>(Resource.Id.popup_mainmenu_inner); Log.Debug("MainMenu InitPopupMenu", "popupMenu=" + (popupMenu != null)); popupMenu.LayoutParameters = lp; popupMenu.SetBackgroundResource(Resource.Drawable.actionbar_background); MainMenuFragment mainmenupopup_fragment = (MainMenuFragment)SupportFragmentManager.FindFragmentById(Resource.Id.mainmenupopup_fragment); mainmenupopup_fragment.IsPopupMenu = true; Button btnSettings = this.FindViewById <Button>(Resource.Id.btnSettingsMain); btnSettings.Touch += (object sender, View.TouchEventArgs e) => { switch (e.Event.Action & MotionEventActions.Mask) { case MotionEventActions.Up: popupMenu.Visibility = ViewStates.Gone; SettingsClicked(); break; } }; }
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())); }