Exemple #1
0
        private void zapiszObrazek(Android.Net.Uri data, int requestedWidth, int requestedHeight, int id)
        {
            try{
                Stream stream = ContentResolver.OpenInputStream(data);
                BitmapFactory.Options options = new BitmapFactory.Options();

                //Options
                options.InJustDecodeBounds = true;
                options.InPurgeable        = true;
                options.InPreferredConfig  = Bitmap.Config.Rgb565;
                options.InInputShareable   = true;
                options.InDither           = false;

                //praca
                BitmapFactory.DecodeStream(stream);
                options.InSampleSize = calculateSampleSize(options, requestedWidth, requestedHeight);
                stream = ContentResolver.OpenInputStream(data);
                options.InJustDecodeBounds = false;
                Bitmap       bitmap  = BitmapFactory.DecodeStream(stream, null, options);
                MemoryStream mstream = new MemoryStream();
                bitmap.Compress(Bitmap.CompressFormat.Webp, 80, mstream);

                RunOnUiThread(() => Baza.getDataBase().zmienObrazek(id, mstream.ToArray()));                    //zapis do bazy

                //czystka
                stream = null;
                RunOnUiThread(() => Toast.MakeText(this, Resource.String.P_imageUploadComplete, ToastLength.Short).Show());
                RunOnUiThread(() => RecImage.SetImageBitmap(bitmap));
                Thread.Sleep(1000);
                mstream.SetLength(0);
                System.GC.Collect();
            }catch (Exception ex) {
                RunOnUiThread(() => Toast.MakeText(this, GetString(Resource.String.P_imageUploadError) + ex.Message, ToastLength.Short).Show());
            }
        }
Exemple #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Baza.getDataBase().setApplicationContext(this.ApplicationContext);

            SetContentView(Resource.Layout.MenuGlowne);

            Button   czysc         = FindViewById <Button> (Resource.Id.MA_Pczysc);
            Button   dodaj         = FindViewById <Button> (Resource.Id.MA_Pdodaj);
            TextView pole_szukania = FindViewById <TextView> (Resource.Id.MA_poleszukaj);
            ListView lista         = FindViewById <ListView>(Resource.Id.MA_ListaPrzepisow);

            lista.Adapter = Baza.getDataBase().getBaseAdapter();
            lista.RequestFocus();

            czysc.Visibility = Android.Views.ViewStates.Invisible;

            czysc.Click += delegate {
                pole_szukania.SetText("", TextView.BufferType.Normal);
            };

            dodaj.Click += delegate {
                FragmentTransaction trans     = FragmentManager.BeginTransaction();
                dialogAddRecipe     addRecipe = new dialogAddRecipe();
                addRecipe.Show(trans, "addRecipe");

                addRecipe.recipeEvent += delegate(object sender, onRecipeAddRequest e) {
                    Baza.getDataBase().dodajPrzepis(e.Przepis);
                };
            };

            pole_szukania.TextChanged += delegate {
                if (pole_szukania.Text != "")
                {
                    czysc.Visibility = Android.Views.ViewStates.Visible;
                }
                else
                {
                    czysc.Visibility = Android.Views.ViewStates.Invisible;
                }
                Baza.getDataBase().przeladujPrzepisy(pole_szukania.Text);
            };

            lista.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e) {
                Intent intencja = new Intent(this, typeof(PrzepisActivity));
                intencja.PutExtra("Id", e.Position);
                this.StartActivity(intencja);
                //this.OverridePendingTransition(Android.Resource.Animation.FadeIn,Android.Resource.Animation.FadeOut);
            };

            lista.ItemLongClick += delegate(object sender, AdapterView.ItemLongClickEventArgs e) {
                FragmentTransaction   trans  = FragmentManager.BeginTransaction();
                dialogShowIngredients showig = new dialogShowIngredients(Baza.getDataBase().getBaseAdapter()[e.Position].Skladniki);
                showig.Show(trans, "showIngredients");
            };
        }
Exemple #3
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View row = convertView;

            if (row == null)
            {
                row = LayoutInflater.From(kontekst).Inflate(Resource.Layout.ListRow, null, false);
            }

            TextView  Name  = row.FindViewById <TextView> (Resource.Id.ROW_Nazwa);
            TextView  Typ   = row.FindViewById <TextView> (Resource.Id.ROW_Typ);
            ImageView Image = row.FindViewById <ImageView> (Resource.Id.ROW_Obrazek);

            switch (lista[position].Typ)
            {
            case 0:
                Image.SetImageResource(Resource.Drawable.IkonaPrzepisu_danie);
                break;

            case 1:
                Image.SetImageResource(Resource.Drawable.IkonaPrzepisu_weget);
                break;

            case 2:
                Image.SetImageResource(Resource.Drawable.IkonaPrzepisu_zupa);
                break;

            case 3:
                Image.SetImageResource(Resource.Drawable.IkonaPrzepisu_deser);
                break;

            case 4:
                Image.SetImageResource(Resource.Drawable.IkonaPrzepisu_napoj);
                break;

            default:
                Image.SetImageResource(Resource.Drawable.IkonaPrzepisu_danie);
                break;
            }

            Name.Text = lista [position].Nazwa;
            Typ.Text  = Baza.getDataBase().getRecipeType(lista [position].Typ);

            return(row);
        }
Exemple #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Przepis);

            id = Intent.GetIntExtra("Id", -1);
            if (id == -1)
            {
                Finish();
            }
            else
            {
                przepis = Baza.getDataBase().getBaseAdapter() [id];
            }

            TextView Title      = FindViewById <TextView> (Resource.Id.P_title);
            TextView Igridience = FindViewById <TextView> (Resource.Id.P_skladniki);
            TextView Recipe     = FindViewById <TextView> (Resource.Id.P_przepis);

            Title.Text      = przepis.Nazwa;
            Igridience.Text = przepis.Skladniki;
            Recipe.Text     = przepis.Przepis;

            RecImage = FindViewById <ImageView> (Resource.Id.P_obrazek);

            ThreadPool.QueueUserWorkItem(o => LoadImage());

            RecImage.LongClick += delegate {
                Intent pobierzObrazek = new Intent();
                pobierzObrazek.SetType("image/*");
                pobierzObrazek.SetAction(Intent.ActionGetContent);
                this.StartActivityForResult(Intent.CreateChooser(pobierzObrazek, GetString(Resource.String.P_chooseImage)), 0);
            };

            Button DeleteBut = FindViewById <Button> (Resource.Id.P_deleteRecipe);

            DeleteBut.Click += delegate {
                FragmentTransaction trans     = FragmentManager.BeginTransaction();
                dialogDelete        addRecipe = new dialogDelete(przepis.Id);
                addRecipe.Show(trans, "deleteRecipe");
            };
        }
Exemple #5
0
        public override Android.Views.View OnCreateView(Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);
            var widok = inflater.Inflate(Resource.Layout.dialogDelete, container, false);

            Button ok     = widok.FindViewById <Button> (Resource.Id.DD_ok);
            Button cancel = widok.FindViewById <Button> (Resource.Id.DD_cancel);

            ok.Click += delegate {
                Baza.getDataBase().usunPrzepis(id);
                this.Activity.Finish();
            };

            cancel.Click += delegate {
                this.Dismiss();
            };

            return(widok);
        }
Exemple #6
0
 protected override void OnDestroy()
 {
     base.OnDestroy();
     Baza.getDataBase().wylaczBaze();
     GC.Collect();
 }