Esempio n. 1
0
        private async Task RenderImageAsync(LocationPicture pic)
        {
            CanvasDevice       device       = CanvasDevice.GetSharedDevice();
            CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, (int)Inker.ActualWidth, (int)Inker.ActualHeight, 96);

            var image = await CanvasBitmap.LoadAsync(device, new Uri(pic.RawImageUri));

            using (var ds = renderTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.White);
                ds.DrawImage(image, image.Bounds);
                ds.DrawInk(Inker.InkPresenter.StrokeContainer.GetStrokes());
            }

            var filename    = pic.ID + "_final.jpg";
            var localFolder = ApplicationData.Current.LocalFolder;

            // TODO
            // datatemplate has a handle on the file and it won't let me replace it.
            // too lazy to fix, so just create a new file
            var file = await localFolder.CreateFileAsync(filename, CreationCollisionOption.GenerateUniqueName);

            using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                await renderTarget.SaveAsync(fileStream, CanvasBitmapFileFormat.Jpeg, 1f);
            pic.ImageUri = "ms-appdata:///local/" + file.Name;
        }
Esempio n. 2
0
        private async void PasteImageButton_Click(object sender, RoutedEventArgs e)
        {
            Button bt = sender as Button;

            bt.IsEnabled = false;
            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.Bitmap))
            {
                IRandomAccessStreamReference imageReceived = null;

                try

                {
                    imageReceived = await dataPackageView.GetBitmapAsync();

                    var id = Guid.NewGuid().ToString();
                    using (var stream = await imageReceived.OpenReadAsync())
                    {
                        var decoder = await BitmapDecoder.CreateAsync(stream);

                        var localFolder = ApplicationData.Current.LocalFolder;
                        var file        = await localFolder.CreateFileAsync(id + ".jpg", CreationCollisionOption.ReplaceExisting);

                        using (var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                        {
                            var encoder = await BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder);

                            await encoder.FlushAsync();
                        }
                    }

                    LocationPicture pic = new LocationPicture();
                    pic.ID          = id;
                    pic.RawImageUri = pic.ImageUri = "ms-appdata:///local/" + id + ".jpg";

                    LocationEnumaration loc;
                    string currentLoc = (MainPivot.SelectedItem as PivotItem).Header as string;
                    Enum.TryParse <LocationEnumaration>(currentLoc, out loc);
                    pic.Location = loc;

                    Data.Pictures.Add(pic);
                    Pictures[currentLoc].Add(pic);


                    // Don't save until navigating from page for demo purposes
                    //await DataSource.GetInstance().UpdateAppointmentsAsync();
                }
                catch (Exception ex)

                {
                }
            }

            bt.IsEnabled = true;
        }
Esempio n. 3
0
        public async Task <int> EditAsync(string name, string description, string adress, string phoneNumber, string email, string website, string facebookPage, string instagramPage, string userId, string mapLink, string perks, string type, List <string> imageUrls, string latinName, int id)
        {
            var location = await this.locationsRepository
                           .All()
                           .FirstOrDefaultAsync(l => l.Id == id);

            if (imageUrls.Count > 0)
            {
                location.ImageUrl = imageUrls.First().Insert(54, "c_fill,h_800,w_600/");
                var locationPictures = await this.locationPicturesRepository
                                       .All()
                                       .Where(m => m.LocationId == id)
                                       .ToListAsync();

                foreach (var locPic in locationPictures)
                {
                    locPic.IsDeleted = true;
                    locPic.DeletedOn = DateTime.UtcNow;
                    this.locationPicturesRepository.Update(locPic);
                }

                foreach (var url in imageUrls)
                {
                    var locationPicture = new LocationPicture
                    {
                        PictureUrl = url.Insert(54, "c_fill,h_960,w_1920/"),
                        LocationId = location.Id,
                    };

                    await this.locationPicturesRepository.AddAsync(locationPicture);

                    await this.locationPicturesRepository.SaveChangesAsync();
                }
            }

            location.Name          = name;
            location.Description   = description;
            location.Adress        = adress;
            location.PhoneNumber   = phoneNumber;
            location.Email         = email;
            location.Website       = website;
            location.FacebookPage  = facebookPage;
            location.InstagramPage = instagramPage;
            location.UserId        = userId;
            location.MapLink       = mapLink;
            location.Perks         = perks;
            location.Type          = type;
            location.LatinName     = latinName;

            await this.locationsRepository.SaveChangesAsync();

            return(location.Id);
        }
Esempio n. 4
0
        private async Task LoadInk(LocationPicture pic)
        {
            Inker.InkPresenter.StrokeContainer.Clear();
            StorageFile file = await TryGetFileAsync(pic.InkUri);

            if (file != null)
            {
                using (var stream = await file.OpenReadAsync())
                {
                    await Inker.InkPresenter.StrokeContainer.LoadAsync(stream);
                }
            }
        }
Esempio n. 5
0
        private async Task SaveInk(LocationPicture pic)
        {
            var localFolder = ApplicationData.Current.LocalFolder;
            var file        = await localFolder.CreateFileAsync(pic.ID + ".gif", CreationCollisionOption.ReplaceExisting);

            if (file != null && Inker.InkPresenter.StrokeContainer.GetStrokes().Count > 0)
            {
                using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await Inker.InkPresenter.StrokeContainer.SaveAsync(stream);
                }
            }
            pic.InkUri = "ms-appdata:///local/" + pic.ID + ".gif";
        }
Esempio n. 6
0
        public async Task <int> CreateAsync(string name, string description, string adress, string phoneNumber, string email, string website, string facebookPage, string instagramPage, string userId, string mapLink, string perks, string type, List <string> imageUrls, string latinName)
        {
            var location = new Location
            {
                Name          = name,
                Description   = description,
                Adress        = adress,
                PhoneNumber   = phoneNumber,
                Email         = email,
                Website       = website,
                FacebookPage  = facebookPage,
                InstagramPage = instagramPage,
                UserId        = userId,
                MapLink       = mapLink,
                Perks         = perks,
                Type          = type,
                ImageUrl      = imageUrls.First().Insert(54, "c_fill,h_800,w_600/"),
                LatinName     = latinName,
            };

            await this.locationsRepository.AddAsync(location);

            await this.locationsRepository.SaveChangesAsync();

            foreach (var url in imageUrls)
            {
                var locationPicture = new LocationPicture
                {
                    PictureUrl = url.Insert(54, "c_fill,h_960,w_1920/"),
                    LocationId = location.Id,
                };

                await this.locationPicturesRepository.AddAsync(locationPicture);

                await this.locationPicturesRepository.SaveChangesAsync();
            }

            return(location.Id);
        }
Esempio n. 7
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.NewBigDays);

            Geneticist.Splice(this);

            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetActionBar(toolbar);
            ActionBar.Title = "Edit Big Days";

            _cameraHelpers = new CameraHelpers(this);
            MainActivity._BDDB.CheckRepeats();
            _Edit = Intent.GetBooleanExtra("Edit", false);

            _ImageArea = FindViewById <ImageView>(Resource.Id.imageArea);
            _ImageArea.SetScaleType(ImageView.ScaleType.CenterCrop);


            _UiTimeEdit        = FindViewById <EditText>(Resource.Id.timeEdit);
            _UiTimeEdit.Click += (o, e) => ShowDialog(TIME_DIALOG_ID);

            _UiDateEdit        = FindViewById <EditText>(Resource.Id.dateEdit);
            _UiDateEdit.Click += (o, e) => { ShowDialog(DATE_DIALOG_ID); };

            _UiEditRepeat        = FindViewById <EditText>(Resource.Id.editRepeat);
            _UiEditRepeat.Click += (sender, e) =>
            {
                var IntentRepeatSelect = new Intent(this, typeof(RepeatSelect));
                IntentRepeatSelect.PutExtra("Num", _RepeatNum);
                StartActivityForResult(IntentRepeatSelect, (int)RequestCode.Repeat);
            };

            _ImgPath         = "img17.jpg";
            _ImageStorageNum = LocationPicture.ResourcesImage;

            // Get the current time
            DateTime now = DateTime.Now;

            now     = now.AddHours(1);
            hour    = now.Hour;
            minute  = DateTime.Now.Minute;
            seconds = DateTime.Now.Second;

            // get the current date
            date = DateTime.Today;

            _UiName = FindViewById <EditText>(Resource.Id.BigDayName);

            if (_Edit)
            {
                _ID = Intent.GetIntExtra("ID", 0);
                if (_ID != 0)
                {
                    _Item = MainActivity._BDDB.SelectItem(_ID);

                    _UiName.Text = _Item._Name;

                    // Get the current time
                    hour   = _Item._EndDate.Hour;
                    minute = _Item._EndDate.Minute;

                    // get the current date
                    date = _Item._EndDate;

                    _RepeatNum         = _Item._Repeat;
                    _Notification      = _Item._Notification;
                    _UiEditRepeat.Text = _RepeatStrs[_RepeatNum].ToString();

                    _AlertStr = _AlertStrOld = _Item._Alerts;

                    _ImageStorageNum = (LocationPicture)_Item._ImageStorage;
                    _ImgPath         = _Item._Image;
                    _ImageBase64     = _Item.ImageBase64;

                    foreach (var i in MainActivity._BDitems)
                    {
                        if (i._ID == _ID)
                        {
                            _ImageArea.SetImageBitmap(i._BigImg);
                        }
                    }
                }
            }
            else
            {
                Resources res     = Resources;
                int       imageID = res.GetIdentifier(_ImgPath.Replace(".jpg", ""), "drawable", PackageName);
                Drawable  def     = new BitmapDrawable(BitmapHelpers.DecodeSampledBitmapFromResource(res, imageID, (int)MainActivity._DisplayWidth, (int)MainActivity._DisplayWidth, this));
                _ImageArea.SetImageDrawable(def);
            }

            _NM = (NotificationManager)GetSystemService(NotificationService);

            _UiAlerts        = FindViewById <Button>(Resource.Id.Alerts);
            _UiAlerts.Click += (sender, e) =>
            {
                string[] alerts = _AlertStr.Split('#');
                int      i      = 0;
                foreach (var a in alerts)
                {
                    string[] alertStr = a.Split(';');
                    garbage[i] = 0;
                    if (alertStr[1] == "1")
                    {
                        garbage[i] = Convert.ToInt32(alertStr[2]);
                    }
                    i++;
                }
                var IntentAlerts = new Intent(this, typeof(Alerts));
                IntentAlerts.PutExtra("Alert", _AlertStr);
                StartActivityForResult(IntentAlerts, (int)RequestCode.Alerts);
            };

            // Display the current date
            UpdateDisplayTime();

            // display the current date (this method is below)
            UpdateDisplayDate();

            _UiSeveOrEdit        = FindViewById <ImageButton>(Resource.Id.SeveOrEdit);
            _UiSeveOrEdit.Click += (sender, e) =>
            {
                if (_Edit)
                {
                    _Item._ID   = _ID;
                    _Item._Name = _UiName.Text.ToString();
                    DateTime d = Convert.ToDateTime(_UiDateEdit.Text.ToString());
                    DateTime t = Convert.ToDateTime(_UiTimeEdit.Text.ToString());
                    _Item._EndDate      = new DateTime(d.Year, d.Month, d.Day, t.Hour, t.Minute, t.Second);
                    _Item._Image        = _ImgPath;
                    _Item._ImageStorage = (int)_ImageStorageNum;
                    _Item._Repeat       = _RepeatNum;
                    _Item.ImageBase64   = _ImageBase64;
                    int garbageMain = _Notification;

                    _Item._Notification = new System.Random().Next(0, 999999);

                    AlarmHelpers.UpdateAlarm(this, _Item, garbageMain);

                    _Item._Alerts = _AlertStr;
                    string[]            alertOld = _AlertStrOld.Split('#');
                    NotificationManager NM       = (NotificationManager)GetSystemService(Context.NotificationService);
                    foreach (var ao in alertOld)
                    {
                        string[] ao2 = ao.Split(';');
                        if (ao2[1] == "1")
                        {
                            int ID = Convert.ToInt32(ao2[2]);
                            NM.Cancel(ID);
                        }
                    }
                    string[] alerts = _AlertStr.Split('#');
                    int      i      = 0;
                    foreach (var a in alerts)
                    {
                        string[] alertStr = a.Split(';');
                        if (alertStr[1] == "1")
                        {
                            int ID = Convert.ToInt32(alertStr[2]);
                            AlarmHelpers.UpdateAlertsAlarm(this, _Item, ID, alertStr, garbage[i]);
                        }

                        i++;
                    }
                    MainActivity._BDDB.Update(_Item);
                    Intent ParentIntent = new Intent(this, typeof(MainActivity));
                    SetResult(Result.Ok, ParentIntent);
                    Finish();
                }
                else
                {
                    _Item       = new BigDaysItemModel();
                    _Item._Name = _UiName.Text.ToString();
                    DateTime d = Convert.ToDateTime(_UiDateEdit.Text.ToString());
                    DateTime t = Convert.ToDateTime(_UiTimeEdit.Text.ToString());
                    _Item._EndDate      = new DateTime(d.Year, d.Month, d.Day, t.Hour, t.Minute, t.Second);
                    _Item._Image        = _ImgPath;
                    _Item._ImageStorage = (int)_ImageStorageNum;
                    _Item._Repeat       = _RepeatNum;
                    _Item.ImageBase64   = _ImageBase64;


                    _Item._Notification = new System.Random().Next(0, 999999);
                    _Item._ID           = MainActivity._BDDB.GetLastID() + 1;

                    AlarmHelpers.SetAlarm(this, _Item);

                    _Item._Alerts = _AlertStr;
                    string[] alerts = _AlertStr.Split('#');
                    foreach (var a in alerts)
                    {
                        string[] alertStr = a.Split(';');
                        if (alertStr[1] == "1")
                        {
                            int ID = Convert.ToInt32(alertStr[2]);
                            _Item._ID = MainActivity._BDDB.GetLastID() + 1;

                            AlarmHelpers.SetAlertsAlarm(this, _Item, ID, alertStr);
                        }
                    }

                    MainActivity._BDDB.Insert(_Item);

                    List <BigDaysItemModel> items = MainActivity._BDDB.SelectBDItems();
                    if (items.Count == 1)
                    {
                        MainActivity._BDDB.SetActive(items[0]._ID);
                    }

                    Intent ParentIntent = new Intent(this, typeof(ListActivity));
                    SetResult(Result.Ok, ParentIntent);
                    Finish();
                }
            };
            _UiCancelOrDelete = FindViewById <ImageButton>(Resource.Id.CancelOrDelete);
            if (_Edit)
            {
                _UiCancelOrDelete.SetImageResource(Resource.Drawable.ic_action_discard);
            }

            _UiCancelOrDelete.Click += (sender, e) =>
            {
                if (_Edit)
                {
                    AlarmHelpers.RemoveAlarm(this, _Notification);

                    foreach (var g in garbage)
                    {
                        if (g != 0)
                        {
                            Intent        IntentNot          = new Intent(this, typeof(NotificationView));
                            PendingIntent mAlarmSenderCansel = PendingIntent.GetBroadcast(this, g, IntentNot, PendingIntentFlags.UpdateCurrent);
                            AlarmManager  am = (AlarmManager)GetSystemService(Context.AlarmService);
                            am.Cancel(mAlarmSenderCansel);
                        }
                    }

                    if (_ID != 0)
                    {
                        MainActivity._BDDB.Delete(_ID);
                    }

                    for (int i = 0; i < MainActivity._BDitems.Count; i++)
                    {
                        if (MainActivity._BDitems[i]._ID == _ID)
                        {
                            MainActivity._BDitems.RemoveAt(i);
                        }
                    }


                    List <BigDaysItemModel> items = MainActivity._BDDB.SelectBDItems();
                    if (items.Count > 0)
                    {
                        MainActivity._BDDB.SetActive(items[0]._ID);
                    }

                    Intent ParentIntent = new Intent(this, typeof(ListActivity));
                    SetResult(Result.Ok, ParentIntent);
                    Finish();
                }
                else
                {
                    Intent ParentIntent = new Intent(this, typeof(ListActivity));
                    SetResult(Result.Canceled, ParentIntent);
                    Finish();
                }
            };
        }
Esempio n. 8
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (resultCode == Result.Ok)
            {
                switch (requestCode)
                {
                case 0:
                    if (data == null)
                    {
                        break;
                    }
#if _TRIAL_
                    int imgPos = data.GetIntExtra("pos", 0);
                    if (imgPos > 1)
                    {
                        AlertDialog.Builder builder;
                        builder = new AlertDialog.Builder(this);
                        builder.SetTitle("Free Version");
                        builder.SetMessage("You can select only 2 first images in free version. Please purchase full version (no ad banner) to select any images.\n\nBy clicking \"Buy Now\" you will redirect to Full version (no ad banner) purchase page.");
                        builder.SetCancelable(false);
                        builder.SetPositiveButton("Buy Now", delegate {
                            Intent browserIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(Constants.VersionLink));
                            StartActivity(browserIntent);
                        });
                        builder.SetNegativeButton("Continue", delegate {  });
                        builder.Show();
                    }
                    else
                    {
                        _ImgPath = data.GetStringExtra("image");
                        try{
                            Resources res     = Resources;
                            int       imageID = res.GetIdentifier(_ImgPath.Replace(".jpg", ""), "drawable", PackageName);
                            _ImageArea.SetImageDrawable(res.GetDrawable(imageID));
                        } catch (OutOfMemoryError em) {
                            AlertDialog.Builder builder;
                            builder = new AlertDialog.Builder(this);
                            builder.SetTitle("Error");
                            builder.SetMessage("Out Of Memory Error №98");
                            builder.SetCancelable(false);
                            builder.SetPositiveButton("OK", delegate { Finish(); });
                            builder.Show();
                        }
                        _ImageStorageNum = LocationPicture.ResourcesImage;
                    }
#else
                    _ImgPath = data.GetStringExtra("image");
                    try
                    {
                        Resources res     = Resources;
                        int       imageID = res.GetIdentifier(_ImgPath.Replace(".jpg", ""), "drawable", PackageName);
                        _ImageArea.SetImageDrawable(res.GetDrawable(imageID));
                    }
                    catch (OutOfMemoryError)
                    {
                        AlertDialog.Builder builder;
                        builder = new AlertDialog.Builder(this);
                        builder.SetTitle("Error CodeBlock №99");
                        builder.SetMessage("Out Of Memory Error");
                        builder.SetCancelable(false);
                        builder.SetPositiveButton("OK", delegate { Finish(); });
                        builder.Show();
                    }
                    _ImageStorageNum = LocationPicture.ResourcesImage;
                                                #endif
                    break;

                case (int)RequestCode.PickImage:
                    try
                    {
                        if (data == null)
                        {
                            break;
                        }
                        var imagesURl = data.GetStringExtra("image");

                        Constants.ImageBtmUri = string.IsNullOrEmpty(imagesURl) ? data.DataString : imagesURl;

                        var IntentShareActivity = new Intent(this, typeof(ImagePreview));
                        StartActivityForResult(IntentShareActivity, (int)RequestCode.ReturnPickImagePath);
                    }
                    catch (OutOfMemoryError)
                    {
                        AlertDialog.Builder builder;
                        builder = new AlertDialog.Builder(this);
                        builder.SetTitle("Error CodeBlock №100");
                        builder.SetMessage("Out Of Memory Error");
                        builder.SetCancelable(false);
                        builder.SetPositiveButton("OK", delegate { Finish(); });
                        builder.Show();
                    }
                    break;

                case (int)RequestCode.ReturnPickImagePath:

                    if (data != null)
                    {
                        string result = data.GetStringExtra("result");
                        _ImageArea.SetImageBitmap(Constants.ImageBtm);
                        _ImageStorageNum = LocationPicture.Base64Image;

                        _ImageBase64 = BitmapToBase64Converter.BitmapToBase64(Constants.ImageBtm);
                    }
                    else
                    {
                        AlertDialog.Builder builder;
                        builder = new AlertDialog.Builder(this);
                        builder.SetTitle("Error CodeBlock №66");
                        builder.SetMessage("ReturnPickImagePath is null");
                        builder.SetCancelable(false);
                        builder.SetPositiveButton("OK", delegate { Finish(); });
                        builder.Show();
                    }
                    break;

                case (int)RequestCode.CameraImage:
                    try
                    {
                        Intent          mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                        Android.Net.Uri contentUri      = Android.Net.Uri.FromFile(App._file);
                        mediaScanIntent.SetData(contentUri);
                        SendBroadcast(mediaScanIntent);

                        Constants.ImageBtmUri = contentUri.ToString();

                        var IntentShareActivity2 = new Intent(this, typeof(ImagePreview));
                        StartActivityForResult(IntentShareActivity2, (int)RequestCode.ReturnPickImagePath);
                    }
                    catch (OutOfMemoryError)
                    {
                        AlertDialog.Builder builder;
                        builder = new AlertDialog.Builder(this);
                        builder.SetTitle("Error CodeBlock №101");
                        builder.SetMessage("Out Of Memory Error");
                        builder.SetCancelable(false);
                        builder.SetPositiveButton("OK", delegate { Finish(); });
                        builder.Show();
                    }
                    break;

                case (int)RequestCode.Repeat:
                    _RepeatNum         = data.GetIntExtra("Num", 0);
                    _UiEditRepeat.Text = _RepeatStrs[_RepeatNum];
                    break;

                case (int)RequestCode.Alerts:
                    _AlertStr = data.GetStringExtra("Alert");
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 9
0
 private Task LoadPicture(LocationPicture pic)
 {
     Imager.Source = new BitmapImage(new Uri(pic.RawImageUri));
     return(LoadInk(pic));
 }