protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            pref    = Application.GetSharedPreferences("backgroundColor_textColor", FileCreationMode.Private);
            result  = pref.GetString("background", "White");
            result2 = pref.GetString("textColor", "Black");

            toolbar = FindViewById <V7ToolBar>(Resource.Id.toolbar);
            drawer  = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            tV1     = FindViewById <TextView>(Resource.Id.main_text);

            toolbar.SetTitle(Resource.String.title_name);
            toolbar.SetTitleTextColor(Color.White);

            SetSupportActionBar(toolbar);

            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);

            drawer.AddDrawerListener(toggle);
            toggle.SyncState();

            navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);
            navigationView.SetNavigationItemSelectedListener(this);
            //navigationView.ItemTextColor = ColorStateList.ValueOf(Color.ParseColor(result2));
            drawer.SetBackgroundColor(Color.ParseColor(result));
            toolbar.SetBackgroundColor(Color.ParseColor(result2));
            navigationView.SetBackgroundColor(Color.ParseColor(result2));
            Task.Run(async() => await Update());
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            int calcNo = Intent.GetIntExtra("CalculationType",-1);

            SetContentView (Resource.Layout.PercentDrawer);

            drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawerLayout);
            drawerLayout.SetBackgroundColor(Android.Graphics.Color.AntiqueWhite);
            ColorDrawable colorDrawable = new ColorDrawable (Color.Black);
            this.ActionBar.SetBackgroundDrawable (colorDrawable);

            drawerToggle = new ActionBarDrawerToggle (this, drawerLayout, Resource.String.DrawerOpenDescription, Resource.String.DrawerCloseDescription);

            drawerLayout.SetDrawerListener (drawerToggle);

            drawerListView = FindViewById<ListView> (Resource.Id.drawerListView);
            drawerListView.Adapter = new ArrayAdapter<string> (this, Android.Resource.Layout.SimpleListItem1, calculationTitles);
            drawerListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => OnMenuItemClick(e.Position);
            drawerListView.SetItemChecked (calcNo, true);
            OnMenuItemClick (calcNo);

            ActionBar.SetDisplayHomeAsUpEnabled (true);
        }
        private async Task Update()
        {
            while (!stop)
            {
                await Task.Delay(400);

                result  = pref.GetString("background", "White");
                result2 = pref.GetString("textColor", "Black");
                RunOnUiThread(() =>
                {
                    tV1.SetTextColor(Color.ParseColor(result2));
                    drawer.SetBackgroundColor(Color.ParseColor(result));
                    toolbar.SetBackgroundColor(Color.Black);
                    navigationView.SetBackgroundColor(Color.ParseColor(result));
                    navigationView.ItemTextColor = ColorStateList.ValueOf(Color.ParseColor(result2));
                });
            }
        }
Beispiel #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            if (DataManager.Get <ISettingsManager>().Settings.InAppPurchase)
            {
                BillingHandler = new SaneInAppBillingHandler(this, DataManager.Get <ISettingsManager>().Settings.PublicKey);

                try
                {
                    Task.Run(
                        async() => {
                        await BillingHandler.Connect();

                        if (DownloadManager.IsLogged())
                        {
                            //abbonamenti
                            var purch   = await BillingHandler.GetPurchases(ItemType.Subscription);
                            var subList = new List <Dictionary <string, string> >();

                            foreach (var p in purch)
                            {
                                //BillingHandler.ConsumePurchase(p);
                                Dictionary <string, string> data = new Dictionary <string, string>();

                                string orderID = p.OrderId;
                                if (orderID == null || orderID == "")
                                {
                                    orderID = p.PurchaseToken;
                                }

                                data.Add("packageName", this.PackageName);
                                data.Add("orderId", orderID);
                                data.Add("productId", p.ProductId);
                                data.Add("developerPayload", p.DeveloperPayload);
                                data.Add("purchaseTime", p.PurchaseTime.ToString());
                                data.Add("purchaseToken", p.PurchaseToken);
                                data.Add("purchaseState", p.PurchaseState.ToString());

                                subList.Add(data);
                            }

                            var encodeData = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(subList)));

                            Notification.CheckSubscriptions(encodeData);
                        }
                    }

                        );
                    //await _billingHandler.Connect();
                }
                catch (InAppBillingException ex)
                {
                    // Thrown if the commection fails for whatever reason (device doesn't support In-App billing, etc.)
                    // All methods (except for Disconnect()) may throw this exception,
                    // handling it is omitted for brevity in the rest of the samples
                    Log.Error("HomeScreen", ex.Message);
                }
            }

            //permessi cartella condivisa
            if (!this.CanAccessExternal())
            {
                var permissions = new string[] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage };
                this.RequestPermissions(permissions, 1);
            }

            //this.SetTheme(Resource.Style.MB);

            SetContentView(Resource.Layout.HomeScreen);


            MenuLabels = new Dictionary <string, string>()
            {
                { "edicola", GetString(Resource.String.menu_Edicola) },
                { "download", GetString(Resource.String.menu_Download) },
                { "impostazioni", GetString(Resource.String.menu_Settings) },
                { "crediti", GetString(Resource.String.menu_Credits) },
                { "ciccio", "ddddddd" }
            };

            _Title = _DrawerTitle = Title = this.AppName();

            _Drawer        = this.FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            _DrawerList    = this.FindViewById <ListView>(Resource.Id.left_drawer);
            _DrawerContent = this.FindViewById <LinearLayout>(Resource.Id.drawer_content);

            _Drawer.SetBackgroundColor(Color.Transparent.FromHex("eeeeee"));

            //voci menu
            List <string> Sections = new List <string>();

            if (DataManager.Get <ISettingsManager>().Settings.EdicolaEnabled)
            {
                MenuItems.Add("edicola");
                Sections.Add(MenuLabels["edicola"]);
            }

            if (DataManager.Get <ISettingsManager>().Settings.DownloadEnabled)
            {
                MenuItems.Add("download");
                Sections.Add(MenuLabels["download"]);
            }

            if (DataManager.Get <ISettingsManager>().Settings.SettingsEnabled)
            {
                MenuItems.Add("impostazioni");
                Sections.Add(MenuLabels["impostazioni"]);
            }

            MenuItems.Add("crediti");
            Sections.Add(MenuLabels["crediti"]);

            //_DrawerList.Adapter = new ArrayAdapter<string>(this, Resource.Layout.DrawerListItem, Sections);
            _DrawerList.Adapter = new DrawerAdapter <string>(this, Resource.Layout.DrawerListItem, Sections);

            _DrawerList.ItemClick += (sender, args) => ListItemClicked(args.Position);

            _Drawer.SetDrawerShadow(Resource.Drawable.drawer_shadow_light, (int)Android.Views.GravityFlags.Start);

            _DrawerContent.SetBackgroundColor(Color.Transparent.FromHex(DataManager.Get <ISettingsManager>().Settings.MenuFondoColor));
            _DrawerList.SetBackgroundColor(Color.Transparent.FromHex(DataManager.Get <ISettingsManager>().Settings.MenuFondoColor));

            _DrawerList.Divider       = new ColorDrawable(Color.Transparent);
            _DrawerList.DividerHeight = 8;

            _DrawerToggle = new MyActionBarDrawerToggle(this, _Drawer,
                                                        Resource.Drawable.ic_drawer,
                                                        Resource.String.DrawerOpen,
                                                        Resource.String.DrawerClose);


            //Display the current fragments title and update the options menu
            _DrawerToggle.DrawerClosed += (o, args) =>
            {
                this.ActionBar.Title = _Title;
                ActionBar.SetDisplayShowCustomEnabled(true);
                this.InvalidateOptionsMenu();
            };

            //Display the drawer title and update the options menu
            _DrawerToggle.DrawerOpened += (o, args) =>
            {
                this.ActionBar.Title = _DrawerTitle;
                ActionBar.SetDisplayShowCustomEnabled(false);
                this.InvalidateOptionsMenu();
            };

            //Set the drawer lister to be the toggle.
            _Drawer.SetDrawerListener(this._DrawerToggle);


            //if first time you will want to go ahead and click first item.
            if (bundle == null)
            {
                ListItemClicked(0);
            }

            /*string color = "#" + DataManager.Get<ISettingsManager>().Settings.NavigationBarColor;
             * ActionBar.SetBackgroundDrawable(new ColorDrawable(Color.ParseColor(color)));
             *
             * int amId = this.Resources.GetIdentifier("action_context_bar", "id", "android");
             * View view= FindViewById(amId);
             * view.SetBackgroundColor(Color.ParseColor(color));
             */

            ActionBar.SetCustomView(Resource.Layout.CustomActionBar);
            ActionBar.SetDisplayShowCustomEnabled(true);

            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetHomeButtonEnabled(true);
            //ActionBar.SetDisplayShowHomeEnabled (false);
            ActionBar.SetIcon(Android.Resource.Color.Transparent);

            ActionBar.SetBackgroundDrawable(new ColorDrawable(Color.Transparent.FromHex(DataManager.Get <ISettingsManager>().Settings.NavigationBarColor)));

            //ActionBar.CustomView.Background.Colorize(DataManager.Get<ISettingsManager>().Settings.NavigationBarColor);

            var btnBack = ActionBar.CustomView.FindViewById <Button>(Resource.Id.btnBack);

            btnBack.SetTextColor(Color.Transparent.FromHex(DataManager.Get <ISettingsManager>().Settings.TintColor));

            btnBack.Click += (sender, e) =>
            {
                if (_CurrentItem == "crediti" || _CurrentItem == "impostazioni")
                {
                    _Drawer.OpenDrawer(_DrawerContent);
                }
            };

            //colore titolo
            var titleId = Resources.GetIdentifier("action_bar_title", "id", "android");
            var abTitle = FindViewById <TextView>(titleId);

            abTitle.SetTextColor(Color.Transparent.FromHex(DataManager.Get <ISettingsManager>().Settings.TintColor));

            //se è un'applicazione edicola e non ci sono documenti lo mando direttamente ai downloads
            if (DataManager.Get <ISettingsManager>().Settings.EdicolaEnabled&& DataManager.Get <ISettingsManager>().Settings.DownloadEnabled)
            {
                if (FileSystemManager.ElemetsInBaseDir == 0)
                {
                    //if(/*this.CanAccessExternal() &&*/ FileSystemManager.DocumentsToImport == 0)
                    GoTo(1);
                }
            }

            //coloro l'icona di navigazione
            ColorizeDrawer();
        }