protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); /*AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((o,e)=> * { * Android.Util.Log.Debug("e : ",e.ToString() ); * Android.Util.Log.Debug("e.ExceptionObject: ",e.ExceptionObject.ToString() ); * Crashlytics.Android.Crashlytics1.Log(e.ToString()); * Crashlytics.Android.Crashlytics1.Log(e.ExceptionObject.ToString()); * });*/ AndroidEnvironment.UnhandledExceptionRaiser += (sender, e) => { RetailMobile.Error.LogError(this, e.Exception.Message, e.Exception.StackTrace); }; PreferencesUtil.LoadSettings(this); Sync.GenerateDatabase(this); Crashlytics.Android.Crashlytics1.Start(this); SetContentView(Resource.Layout.MainMenu); bool isTablet = Common.isTabletDevice(this); if (isTablet) { myActionBar = (RetailMobile.Fragments.ActionBar)SupportFragmentManager.FindFragmentById(Resource.Id.ActionBarMain); myActionBar.SyncClicked += new Fragments.ActionBar.SyncCLickedDelegate(MyActionBar_SyncClicked); myActionBar.MenuClicked += new RetailMobile.Fragments.ActionBar.MenuClickedDelegate(MenuClicked); myActionBar.SettingsClicked += new RetailMobile.Fragments.ActionBar.SettingsCLickedDelegate(SettingsClicked); ShowProgressBar(); if (Common.isPortrait(this)) { // MainMenuPopup.InitPopupMenu(this, myActionBar.Id); InitPopupMenu(); } } System.Threading.Tasks.Task.Factory.StartNew(() => Sync.SyncUsers(this)).ContinueWith(task => this.RunOnUiThread(() => HideProgressBar())); if (!string.IsNullOrEmpty(PreferencesUtil.Username) && !string.IsNullOrEmpty(PreferencesUtil.Password) && LoginFragment.Login(this, PreferencesUtil.Username, PreferencesUtil.Password)) { if (isTablet) { this.FindViewById <LinearLayout>(Resource.Id.layoutList).Visibility = ViewStates.Visible; this.FindViewById <FrameLayout>(Resource.Id.details_fragment).Visibility = ViewStates.Visible; this.FindViewById <LinearLayout>(Resource.Id.layoutDetails).Visibility = ViewStates.Visible; var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.details_fragment, DetailsFragment.NewInstance((int)MainMenu.MenuItems.Invoices)); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.detailInfo_fragment, InvoiceInfoFragment.NewInstance(0)); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); if (this.Resources.Configuration.Orientation == Android.Content.Res.Orientation.Landscape) { this.FindViewById <LinearLayout>(Resource.Id.LayoutMenu).Visibility = ViewStates.Visible; } else { myActionBar.ButtonMenuVisibility = ViewStates.Visible; myActionBar.ButtonSettingsVisibility = ViewStates.Gone; } } else { // var intent = new Android.Content.Intent(); // intent.SetClass(this, typeof(TransactionFragmentActivity)); // StartActivity(intent); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.actionbar_phone_fragment, new RetailMobile.Fragments.ItemActionBar(), "ItemActionBar"); ft.Replace(Resource.Id.content_phone_fragment, InvoiceInfoFragment.NewInstance(0)); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); } } else { if (isTablet) { myActionBar.ButtonMenuVisibility = ViewStates.Gone; var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.detailInfo_fragment, new LoginFragment()); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); } else { myActionBar = new RetailMobile.Fragments.ActionBar(); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.actionbar_phone_fragment, myActionBar);//new RetailMobile.Fragments.ActionBar() ft.Replace(Resource.Id.content_phone_fragment, new LoginFragment()); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); myActionBar.SyncClicked += new Fragments.ActionBar.SyncCLickedDelegate(MyActionBar_SyncClicked); myActionBar.MenuClicked += new RetailMobile.Fragments.ActionBar.MenuClickedDelegate(MenuClicked); myActionBar.SettingsClicked += new RetailMobile.Fragments.ActionBar.SettingsCLickedDelegate(SettingsClicked); ShowProgressBar(); } } }
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())); }
void btnLogin_Click(object sender, EventArgs e) { string username = this.tbUsername.Text; string password = this.tbPassword.Text; if (LoginFragment.Login(this.Activity, username, password)) { RelativeLayout f1 = this.Activity.FindViewById <RelativeLayout>(Resource.Id.fragment1); RelativeLayout f2 = this.Activity.FindViewById <RelativeLayout>(Resource.Id.fragment2); RelativeLayout f3 = this.Activity.FindViewById <RelativeLayout>(Resource.Id.fragment3); LinearLayout l2 = this.Activity.FindViewById <LinearLayout>(Resource.Id.layout2); LinearLayout l3 = this.Activity.FindViewById <LinearLayout>(Resource.Id.layout3); if (f2 != null && f3 != null) { f2.Visibility = ViewStates.Visible; f3.Visibility = ViewStates.Visible; l2.Visibility = ViewStates.Visible; l3.Visibility = ViewStates.Visible; var ft = FragmentManager.BeginTransaction(); ft = FragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment1, new MainMenuFragment()); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); DetailsFragment details = DetailsFragment.NewInstance((int)MainMenu.MenuItems.Invoices); ft = FragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment2, details); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); ft = FragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment3, InvoiceInfoFragment.NewInstance(0)); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); } else { var ft = FragmentManager.BeginTransaction(); ft = FragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment1, InvoiceInfoFragment.NewInstance(0)); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); } InputMethodManager imm = (InputMethodManager)Activity.GetSystemService( Android.Content.Context.InputMethodService); imm.HideSoftInputFromWindow(tbPassword.WindowToken, 0); imm.HideSoftInputFromWindow(tbUsername.WindowToken, 0); /*if (isTablet) * { * this.Activity.FindViewById<LinearLayout>(Resource.Id.layoutList).Visibility = ViewStates.Visible; * this.Activity.FindViewById<FrameLayout>(Resource.Id.details_fragment).Visibility = ViewStates.Visible; * this.Activity.FindViewById<LinearLayout>(Resource.Id.layoutDetails).Visibility = ViewStates.Visible; * * DetailsFragment details = DetailsFragment.NewInstance((int)MainMenu.MenuItems.Invoices); * var ft = FragmentManager.BeginTransaction(); * ft.Replace(Resource.Id.details_fragment, details); * ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); * ft.Commit(); * * ft = FragmentManager.BeginTransaction(); * ft.Replace(Resource.Id.detailInfo_fragment, InvoiceInfoFragment.NewInstance(0)); * ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); * ft.Commit(); * * if (this.Resources.Configuration.Orientation == Android.Content.Res.Orientation.Landscape) * { * View layoutMenu = this.Activity.FindViewById<LinearLayout>(Resource.Id.LayoutMenu); * if(layoutMenu != null) * layoutMenu.Visibility = ViewStates.Visible; * } * else * { * RetailMobile.Fragments.ActionBar myActionBar = (RetailMobile.Fragments.ActionBar)Activity.SupportFragmentManager.FindFragmentById(Resource.Id.ActionBarMain); * * myActionBar.ButtonMenuVisibility = ViewStates.Visible; * myActionBar.ButtonSettingsVisibility = ViewStates.Gone; * } * } * else * { * // var intent = new Android.Content.Intent(); * // intent.SetClass(this.Activity, typeof(TransactionFragmentActivity)); * // StartActivity(intent); * * var ft = this.Activity.SupportFragmentManager.BeginTransaction(); * ft.Replace(Resource.Id.actionbar_phone_fragment, new RetailMobile.Fragments.ItemActionBar(), "ItemActionBar"); * ft.Replace(Resource.Id.content_phone_fragment, InvoiceInfoFragment.NewInstance(0)); * ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); * ft.Commit(); * }*/ } else { Toast.MakeText(Activity.ApplicationContext, Activity.GetString(Resource.String.InvalidUserOrPass), ToastLength.Short).Show(); } }