protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); if (e.OldElement != null || Element == null) { return; } try { if (!(Context is FormsAppCompatActivity activity)) { return; } _activity = activity; _currentView = _activity.LayoutInflater.Inflate(Resource.Layout.Coordinator, this, false); AddView(_currentView); var toolbar = _currentView.FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.myToolBar); if (toolbar == null) { return; } if (!(e.NewElement is CoordinatorPage view)) { return; } var fragment = view.NestedContent?.CreateSupportFragment(_activity); if (fragment == null) { return; } var fragmentContainer = _currentView.FindViewById <FrameLayout>(Resource.Id.fragmentContainer); _activity.SupportFragmentManager .BeginTransaction() .Replace(fragmentContainer.Id, fragment) .Commit(); /* Set Floating Button On Click */ var floatingButton = _currentView.FindViewById <Android.Support.Design.Widget.FloatingActionButton>(Resource.Id .floatingActionButton); floatingButton.Click += FloatingButtonClick; _activity.SetSupportActionBar(toolbar); UpdateCoordinatorLayout(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }
public LoadingService(FormsAppCompatActivity mainActivity) { progress = new ProgressDialog(mainActivity); progress.Indeterminate = true; progress.SetProgressStyle(ProgressDialogStyle.Spinner); progress.SetCancelable(false); }
static void VerifyLoadApplicationCalled(FormsAppCompatActivity appCompatActivity) { try { // Check for the app's main activity having already called FormsAppCompatActivity::LoadApplication(...) Type appActivityType = appCompatActivity.GetType(); while (appActivityType != null && appActivityType.Name != nameof(FormsAppCompatActivity)) { appActivityType = appActivityType.BaseType; } if (appActivityType != null) { // The private _renderersAdded boolean field will be set to true if LoadApplication has been called. var fi = appActivityType.GetField("_renderersAdded", BindingFlags.NonPublic | BindingFlags.Instance); bool renderersAdded = (bool)fi.GetValue(appCompatActivity); if (!renderersAdded) { // LoadApplication hasn't been called. Throw an exception to force the dev to rearrange the // calling order so that our Init method isn't called until after LoadApplication has been called. throw new InvalidOperationException("XFGloss.Droid.Library.Init(...) should be called AFTER " + "your main activity has called LoadApplication(...)"); } } } catch (Exception e) { Console.WriteLine("XFGloss initialization failed: " + e); // Rethrow if we intentionally threw the exception if (e is InvalidOperationException) { throw; } } }
protected override async void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); ZXing.Net.Mobile.Forms.Android.Platform.Init(); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); await CrossMedia.Current.Initialize(); Xamarin.FormsMaps.Init(this, savedInstanceState); EbNFData ebnfData = this.GetNFDataOnCreate(); application = new App(ebnfData); LoadApplication(application); if (Configuration.EbBuildConfig.NFEnabled) { IsPlayServicesAvailable(); CreateNotificationChannel(); } Instance = this; this.SetStatusBarColor(Android.Graphics.Color.ParseColor(Configuration.EbBuildConfig.StatusBarColor)); Xamarin.Forms.Application.Current.On <Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize); }
public async Task <string> GetUserName() { FormsAppCompatActivity activity = CrossCurrentActivity.Current.Activity as FormsAppCompatActivity; AccountManager manager = AccountManager.Get(activity); Account[] accounts = manager.GetAccountsByType("com.google"); List <String> emails = new List <string>(); foreach (Account account in accounts) { var name = account.Name; emails.Add(account.Name); } if (emails.Any() && emails[0] != null) { String email = emails[0]; String[] parts = email.Split('@'); if (parts.Length > 1) { return(parts[0]); } } return(""); }
protected virtual void OnCreate(Bundle bundle) { base.OnCreate(bundle); Rg.Plugins.Popup.Popup.Init((Context)this, bundle); Xamarin.Essentials.Platform.Init((Activity)this, bundle); FormsAppCompatActivity.set_ToolbarResource(2131427436); FormsAppCompatActivity.set_TabLayoutResource(2131427435); Application.set_Current(((IMvxFormsViewPresenter)Mvx.get_IoCProvider().GetSingleton <IMvxFormsViewPresenter>()).get_FormsApplication()); FormsAppCompatActivity.set_ToolbarResource(2131427436); FormsAppCompatActivity.set_TabLayoutResource(2131427435); MainActivity.instance = this; CrossCurrentActivity.get_Current().set_Activity((Activity)this); CachedImageRenderer.Init(new bool?(false)); CrossMobileAnalytics.Current.Register <GoogleMobileAnalyticsProvider>(); CrossMobileAnalytics.Current.Register <HockeyAppMobileAnalyticsProvider>(); if (((Activity)this).get_Intent().get_Data() != null) { ConfigurationRepository.SetEnvironment(((Activity)this).get_Intent().get_Data().ToString()); if (Settings.Environment != ConfigurationRepository.EnvironmentSetting.Environment) { Settings.Reset(); } } ProtectedAppsChecker.CheckProtectedAppsFeature((Context)this); }
private void AddKeyboardPlaceholder(bool shouldAdd) { if (_ultimateEntry != null && _ultimateEntry.Parent is StackLayout stackLayout) { if (shouldAdd) { // Get the Height of the screen DisplayMetrics displayMetrics = new DisplayMetrics(); FormsAppCompatActivity _activity = (FormsAppCompatActivity)Context; _activity.WindowManager.DefaultDisplay.GetMetrics(displayMetrics); double screenHeight = displayMetrics.HeightPixels / displayMetrics.Density; // Calculate the height of the area below the phantom entry field double height = screenHeight - _ultimateEntry.Y - _ultimateEntry.Height; height = height >= 0 ? height : 0; keyboardPlaceholder = new BoxView() { HeightRequest = height, HorizontalOptions = LayoutOptions.FillAndExpand }; stackLayout.Children.Add(keyboardPlaceholder); } else if (keyboardPlaceholder != null) { stackLayout.Children.Remove(keyboardPlaceholder); keyboardPlaceholder = null; } } }
/// <summary> /// initializes <see cref="Wesley.BitImageEditor"/> /// </summary> /// <param name="activity">current <see cref="Activity"/> </param> /// <param name="bundle">current <see cref="Bundle"/> </param> public static void Init(FormsAppCompatActivity activity, Bundle bundle) { CurrentActivity = activity; CurrentBundle = bundle; IsInitialized = true; LinkAssemblies(); }
public static void EnableStrictMode(this FormsAppCompatActivity activity) { #if DEBUG var builder = new StrictMode.VmPolicy.Builder(); var policy = builder.DetectActivityLeaks().PenaltyLog().Build(); StrictMode.SetVmPolicy(policy); #endif }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); Instance = this; }
public static void Run(FormsAppCompatActivity activity) { //Instance = new XamarinFormsApplication(activity); //Application.Register(new XamarinFormsApplication(activity), OperatingSystem.Linux); //var window = new Window(); //window.Bridge.AddGlobalHandler(new Handler()); //SetDevSettings(window); //Application.UriWatcher = new AndroidUriWatcher("http://localhost:8080"); //Application.ContentProvider = new EmbeddedContentProvider("quasar\\dist\\spa", typeof(SpiderEye.Sample.WeatherForecast).Assembly); //Application.Run(window, "http://local/index.html");// "file://android_asset/local.html"); }
/** * @param activity Activity that requested global theme change must apply this theme itself through recreation. * Only ThemeActivity applies themes on recreation. Other activities are not recreated * @param globalTheme */ public static void setGlobalTheme(FormsAppCompatActivity activity, string globalTheme) { currentGlobalTheme = globalTheme; // activity.finish(); // activity.startActivity(new Intent(activity, activity.getClass())); // activity.overridePendingTransition(android.R.anim.fade_in, // android.R.anim.fade_out); if (activity is ThemeActivity) { activity.Recreate(); } }
internal static void LayoutRootPage(FormsAppCompatActivity activity, Page page, int width, int height) { int statusBarHeight = Forms.IsLollipopOrNewer ? activity.GetStatusBarHeight() : 0; statusBarHeight = activity.Window.Attributes.Flags.HasFlag(WindowManagerFlags.Fullscreen) || Forms.TitleBarVisibility == AndroidTitleBarVisibility.Never ? 0 : statusBarHeight; if (page is MasterDetailPage) { page.Layout(new Rectangle(0, 0, activity.FromPixels(width), activity.FromPixels(height))); } else { page.Layout(new Rectangle(0, activity.FromPixels(statusBarHeight), activity.FromPixels(width), activity.FromPixels(height - statusBarHeight))); } }
public string GetUsername() { //ToDo:Этот вариант есть смысл использовать вместо Chrome, как сейчас! //var intent = Android.Gms.Common.AccountPicker.NewChooseAccountIntent(null, null, new String[] { "com.google" }, false, null, null, null, null); FormsAppCompatActivity activity = CrossCurrentActivity.Current.Activity as FormsAppCompatActivity; AccountManager manager = AccountManager.Get(activity); if (manager != null) { Account[] accounts = manager.GetAccountsByType("com.google"); if (accounts.Length > 0) { return(accounts.First().Name); } } return(""); }
void SetLabeledBy() { if (Element == null || Control == null) { return; } var elemValue = (VisualElement)Element.GetValue(Accessibility.LabeledByProperty); if (elemValue != null) { var id = Control.Id; if (id == -1) { id = Control.Id = FormsAppCompatActivity.GetUniqueId(); } var renderer = elemValue?.GetRenderer(); renderer?.SetLabelFor(id); } }
protected override void OnElementChanged(ElementChangedEventArgs <CarouselPage> e) { base.OnElementChanged(e); var activity = (FormsAppCompatActivity)Context; if (e.OldElement != null) { ((IPageController)e.OldElement).InternalChildren.CollectionChanged -= OnChildrenCollectionChanged; } if (e.NewElement != null) { FormsViewPager pager = _viewPager = new FormsViewPager(activity) { OverScrollMode = OverScrollMode.Never, EnableGesture = true, LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent), Adapter = new FormsFragmentPagerAdapter <ContentPage>(e.NewElement, activity.SupportFragmentManager) { CountOverride = e.NewElement.Children.Count } }; pager.Id = FormsAppCompatActivity.GetUniqueId(); pager.AddOnPageChangeListener(this); ViewGroup.AddView(pager); CarouselPage carouselPage = e.NewElement; if (carouselPage.CurrentPage != null) { ScrollToCurrentPage(); } ((IPageController)carouselPage).InternalChildren.CollectionChanged += OnChildrenCollectionChanged; } }
public AndroidServiceRegistry(FormsAppCompatActivity activity) { }
public MasterDetailContainer(MasterDetailPage parent, bool isMaster, Context context) : base(parent, isMaster, context) { Id = FormsAppCompatActivity.GetUniqueId(); _parent = parent; _isMaster = isMaster; }
public static void ChangeStatusBarColor(Color color) { FormsAppCompatActivity c = MainActivity.context as FormsAppCompatActivity; c.SetStatusBarColor(color); }
public AndroidFormsApplication(FormsAppCompatActivity mainActivity) { this.MainActivity = mainActivity; this.SynchronizationContext = SynchronizationContext.Current; }
internal AndroidApplication(FormsAppCompatActivity activity) { this.avtivity = activity; }
public static AndroidApplication CreateDefault(FormsAppCompatActivity activity) { var result = new AndroidApplication(activity); return(result); }
internal static void LayoutRootPage(FormsAppCompatActivity activity, Page page, int width, int height) { page.Layout(new Rectangle(0, 0, activity.FromPixels(width), activity.FromPixels(height))); }
public AndroidHostingPlatform(FormsAppCompatActivity app) { _app = app; _app.Lifecycle.AddObserver(this); }
public AndroidUiFactory(FormsAppCompatActivity mainActivity) { this._mainActivity = mainActivity; }
TetraPakMainActivity(FormsAppCompatActivity appActivity, Bundle savedInstanceState) { _appActivity = appActivity; _bundle = savedInstanceState; }
protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e) { base.OnElementChanged(e); var activity = (FormsAppCompatActivity)Context; if (e.OldElement != null) { ((IPageController)e.OldElement).InternalChildren.CollectionChanged -= OnChildrenCollectionChanged; } if (e.NewElement != null) { if (_tabLayout == null) { TabLayout tabs; if (FormsAppCompatActivity.TabLayoutResource > 0) { tabs = _tabLayout = activity.LayoutInflater.Inflate(FormsAppCompatActivity.TabLayoutResource, null).JavaCast <TabLayout>(); } else { tabs = _tabLayout = new TabLayout(activity) { TabMode = TabLayout.ModeFixed, TabGravity = TabLayout.GravityFill } }; FormsViewPager pager = _viewPager = new FormsViewPager(activity) { OverScrollMode = OverScrollMode.Never, EnableGesture = UseAnimations, LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent), Adapter = new FormsFragmentPagerAdapter <Page>(e.NewElement, FragmentManager) { CountOverride = e.NewElement.Children.Count } }; pager.Id = FormsAppCompatActivity.GetUniqueId(); pager.AddOnPageChangeListener(this); AddView(pager); AddView(tabs); OnChildrenCollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } TabbedPage tabbedPage = e.NewElement; if (tabbedPage.CurrentPage != null) { ScrollToCurrentPage(); } ((IPageController)tabbedPage).InternalChildren.CollectionChanged += OnChildrenCollectionChanged; UpdateBarBackgroundColor(); UpdateBarTextColor(); UpdateSwipePaging(); UpdateOffscreenPageLimit(); } }
/// <summary> /// Initializes the Android, enabling authorization. /// </summary> /// <param name="appActivity"> /// The calling (main) Activity. /// </param> /// <param name="savedInstanceState"> /// The Main Activity "context". /// </param> public static void OnCreate(FormsAppCompatActivity appActivity, Bundle savedInstanceState) { Current = new TetraPakMainActivity(appActivity, savedInstanceState); Current.OnCreate(savedInstanceState); }
public NavigationPageRenderer() { AutoPackage = false; Id = FormsAppCompatActivity.GetUniqueId(); Device.Info.PropertyChanged += DeviceInfoPropertyChanged; }
public static void Init(FormsAppCompatActivity activity) { UserDialogs.Init(activity); CachedImageRenderer.Init(true); }