コード例 #1
0
        //MyPagerAdapter pageadapter;

        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            SetTheme(Resource.Style.Theme_Normal);

            SetContentView(Resource.Layout.Roles_Activity);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            // Sets the Toolbar to act as the ActionBar for this Activity window.
            // Make sure the toolbar exists in the activity and is not null
            SetSupportActionBar(toolbar);

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            Window.ClearFlags(WindowManagerFlags.TranslucentStatus);

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
                Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);

                // finally change the color
                Window.SetStatusBarColor(Resources.GetColor(Android.Resource.Color.Transparent));
            }

            //create fragment:

            string id = Intent.Extras?.GetString("id");

            if (id != "")
            {
                //Analytics.TrackEvent("ChooseRole");

                //load event info:
                cancel = new CancellationTokenSource();
                AndHUD.Shared.Show(this, Resources.GetString(Resource.String.connecting), -1, MaskType.Black, null, null, true, () =>
                {
                    cancel.Cancel();
                    Finish();
                });

                try
                {
                    CurrentEvent = await Bootlegger.BootleggerClient.GetEventInfo(id, cancel.Token);
                }
                catch (Exception)
                {
                    SetResult(Result.FirstUser);
                    Finish();
                    return;
                }
                finally
                {
                    AndHUD.Shared.Dismiss();
                }
            }
            else
            {
                CurrentEvent = Bootlegger.BootleggerClient.CurrentEvent;
            }

            Bootleg.API.Bootlegger.BootleggerClient.LogUserAction("ChooseRole",
                                                                  new KeyValuePair <string, string>("eventid", CurrentEvent.id));

            CollapsingToolbarLayout collapsingToolbar = FindViewById <CollapsingToolbarLayout>(Resource.Id.collapsing_toolbar);

            collapsingToolbar.SetTitle(CurrentEvent.name);
            //collapsingToolbar.SetCollapsedTitleTextColor(Color.Transparent);
            collapsingToolbar.SetExpandedTitleTextAppearance(Resource.Style.ExpandedAppBar);
            Typeface font = ResourcesCompat.GetFont(this, Resource.Font.montserratregular);

            FindViewById <CollapsingToolbarLayout>(Resource.Id.collapsing_toolbar).CollapsedTitleTypeface = font;
            FindViewById <CollapsingToolbarLayout>(Resource.Id.collapsing_toolbar).ExpandedTitleTypeface  = font;

            if (!string.IsNullOrEmpty(CurrentEvent.roleimg))
            {
                FindViewById <AppBarLayout>(Resource.Id.appbar).SetExpanded(false, false);
            }

            if (!string.IsNullOrEmpty(CurrentEvent.iconbackground) && !WhiteLabelConfig.REDUCE_BANDWIDTH)
            {
                Picasso.With(this).Load(CurrentEvent.iconbackground).CenterCrop().Fit().MemoryPolicy(MemoryPolicy.NoCache, MemoryPolicy.NoStore).Into(FindViewById <ImageView>(Resource.Id.defaultback), new Action(() => {
                    var bitmap      = ((BitmapDrawable)FindViewById <ImageView>(Resource.Id.defaultback).Drawable).Bitmap;
                    Palette palette = Palette.From(bitmap).Generate();
                    int vibrant     = palette.GetLightVibrantColor(0);
                    if (vibrant == 0)
                    {
                        vibrant = palette.GetMutedColor(0);
                    }
                    int dark = palette.GetVibrantColor(0);
                    if (dark == 0)
                    {
                        dark = palette.GetLightMutedColor(0);
                    }
                    //FindViewById<CollapsingToolbarLayout>(Resource.Id.collapsing_toolbar).SetContentScrimColor(vibrant);
                    //FindViewById<CollapsingToolbarLayout>(Resource.Id.collapsing_toolbar).SetStatusBarScrimColor(dark);
                }), null);
            }
            else
            {
                Picasso.With(this).Load(Resource.Drawable.user_back).CenterCrop().Fit().Into(FindViewById <ImageView>(Resource.Id.defaultback));
            }

            AndHUD.Shared.Dismiss();



            SelectRoleFrag myrole;

            if (bundle == null)
            {
                myrole = new SelectRoleFrag(CurrentEvent, false);
                myrole.OnRoleChanged += Myrole_OnRoleChanged;
                Android.Support.V4.App.FragmentTransaction ft = SupportFragmentManager.BeginTransaction();
                try
                {
                    ft.Add(Resource.Id.roles_frag_holder, myrole, "rolefragment").Commit();
                }
                catch
                {
                    //failed dont know why!
                }
            }
            else
            {
                myrole = SupportFragmentManager.FindFragmentByTag("rolefragment") as SelectRoleFrag;
                myrole.OnRoleChanged += Myrole_OnRoleChanged;
            }
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_food_detail);
            food_name               = FindViewById <TextView>(Resource.Id.food_name);
            food_price              = FindViewById <TextView>(Resource.Id.food_price);
            food_description        = FindViewById <TextView>(Resource.Id.food_description);
            food_image              = FindViewById <ImageView>(Resource.Id.img_food);
            collapsingToolbarLayout = FindViewById <CollapsingToolbarLayout>(Resource.Id.collapsing);
            btnCart      = FindViewById <FloatingActionButton>(Resource.Id.btnCart);
            numberButton = FindViewById <Button>(Resource.Id.number_button);
            Food_name    = Intent.GetStringExtra("foodName").Trim();
            collapsingToolbarLayout.SetExpandedTitleTextAppearance(Resource.Style.ExpandedAppbar);
            collapsingToolbarLayout.SetExpandedTitleTextAppearance(Resource.Style.CollapsedAppbar);


            int  foodid;
            bool res   = int.TryParse(Food_name, out foodid);
            var  data  = db.selectallFood();                                 //Call Table
            var  data1 = data.Where(x => x.mFid == foodid).FirstOrDefault(); //Linq Query

            food_name.Text        = data1.mCaption;
            food_price.Text       = data1.mPrice.ToString();
            food_description.Text = data1.mDescription;
            food_image.SetImageResource(data1.mPhotoID);

            //Cart button
            btnCart.Click += delegate
            {
                ISharedPreferences pref     = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
                string             userName = pref.GetString("Usermail", String.Empty);
                try
                {
                    var    query      = db.selectallUser();
                    var    query1     = query.Where(x => x.Email == userName).FirstOrDefault();
                    Intent cartIntent = new Intent(this, typeof(Cart));
                    cartIntent.PutExtra("usrID", query1.Uid.ToString());
                    this.StartActivity(cartIntent);
                }

                catch (Exception ex)
                {
                    Toast.MakeText(Application.Context, ex.ToString(), ToastLength.Short).Show();
                }
            };

            // Add item button
            numberButton.Click += delegate
            {
                ISharedPreferences pref     = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
                string             userName = pref.GetString("Usermail", String.Empty);
                try
                {
                    var query  = db.selectallUser();
                    var query1 = query.Where(x => x.Email == userName).FirstOrDefault();

                    UserCart cart = new UserCart()
                    {
                        fdID  = foodid,
                        usrID = query1.Uid
                    };
                    db.insertUserCart(cart);
                    Toast.MakeText(Application.Context, data1.mCaption + " added to cart!", ToastLength.Short).Show();
                }
                catch (Exception ex)
                {
                    Toast.MakeText(Application.Context, ex.ToString(), ToastLength.Short).Show();
                }
            };
        }