Пример #1
0
        /// <summary>
        /// Creates the alarm to wake the app, to set the notification.
        /// </summary>
        /// <param name="dateTime"></param>
        /// <param name="title"></param>
        /// <param name="message"></param>
        public void Remind(DateTime notificationTime, string title, string message, long requestId)
        {
            Intent alarmIntent = new Intent(Forms.Context, typeof(ImageImprov.Droid.Notifications));  // this class is the intent as well! :)

            alarmIntent.PutExtra("message", message);
            alarmIntent.PutExtra("title", title);

            PendingIntent pendingIntent = PendingIntent.GetBroadcast(Forms.Context, (int)requestId, alarmIntent, PendingIntentFlags.OneShot);

            requestCode++;
            AlarmManager alarmManager = (AlarmManager)Forms.Context.GetSystemService(Context.AlarmService);

            long launchTime = GlobalSingletonHelpers.GetMillisecondsSinceUnixEpoch(notificationTime);

            alarmManager.Set(AlarmType.RtcWakeup, launchTime, pendingIntent);


            /*
             * // sanity check.  Turns out I'm sane.
             * long now = Java.Lang.JavaSystem.CurrentTimeMillis();
             * System.Diagnostics.Debug.WriteLine("DHB:Droid:Notifications:Remind launch time is:" + launchTime);
             * System.Diagnostics.Debug.WriteLine("DHB:Droid:Notifications:Remind droid  time is:" + now);
             */
            // don't understand the purpose of this line...
            //PendingIntent pendingIntent2 = PendingIntent.GetBroadcast(context, requestCode, alarmIntent, 0);  this crashes the system, but then requestCode is wrong...
            //PendingIntent pendingIntent2 = PendingIntent.GetBroadcast(context, (requestCode-1), alarmIntent, 0);
        }
Пример #2
0
            public void OnPictureTaken(byte[] data, Camera camera)
            {
                System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken here!");



                GlobalSingletonHelpers.readExifOrientation(data);
                //var windowManager = Android.App.Application.Context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
                //System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken device orientation:" + windowManager.DefaultDisplay.Rotation);
                System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken device orientation:" + orienter.currentOrientation);
                System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken camera orientation:" + degreesToRotateCameraToNatural);

                int rotateDegrees = degreesToRotateCameraToNatural + orienter.currentOrientation;

                // off the bottom.
                //GlobalStatusSingleton.latestImg = GlobalSingletonHelpers.rotateAndCrop(GlobalSingletonHelpers.SKBitmapFromBytes(data), rotateDegrees, offsetAmount);
                // off the top:
                //GlobalStatusSingleton.latestImg = GlobalSingletonHelpers.rotateAndCrop(GlobalSingletonHelpers.SKBitmapFromBytes(data), rotateDegrees, offsetAmount);
                // midpoint
                GlobalStatusSingleton.latestImg = GlobalSingletonHelpers.rotateAndCrop(GlobalSingletonHelpers.SKBitmapFromBytes(data), rotateDegrees);

                //GlobalStatusSingleton.mostRecentImgBytes = data;  // this is the un modified data as jpg.  bytes will give me a byte array (i think)
                //GlobalStatusSingleton.mostRecentImgBytes = GlobalStatusSingleton.latestImg.Bytes;  this is 34mb.! :)
                SKImage outImg = SKImage.FromBitmap(GlobalStatusSingleton.latestImg);

                GlobalStatusSingleton.mostRecentImgBytes = outImg.Encode(SKEncodedImageFormat.Jpeg, 100).ToArray();
                System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:MyPictureData:OnPictureTaken here!");
                timeToExit(this, null);
            }
Пример #3
0
        public void OnCameraFinished(Object sender, EventArgs e)
        {
            /*
             * var filepath = Path.Combine(Environment.GetFolderPath(
             *                 Environment.SpecialFolder.MyDocuments), "tmp.png");
             */

            InvokeOnMainThread(() => {
                Debug.WriteLine("DHB:AppDelegate:FinishedLaunching:FinishedPickingMedia_Anon");
                if (CameraServices_iOS.exitFromPhoto == true)    // probably better to acheive this by subclassing the event. but i need something quick and dirty.
                {
                    string nextFileName = GlobalStatusSingleton.IMAGE_NAME_PREFIX + GlobalStatusSingleton.imgsTakenTracker + ".jpg";
                    var filepath        = Path.Combine(Environment.GetFolderPath(
                                                           Environment.SpecialFolder.MyDocuments), nextFileName);

                    SKBitmap bitmap = GlobalSingletonHelpers.SKBitmapFromBytes(GlobalStatusSingleton.mostRecentImgBytes);
                    if (bitmap != null)
                    {
                        int degreesToRotate = CameraServices_iOS.calculateRotationDegrees();
                        Debug.WriteLine("DHB:AppDelegate:FinishedLaunching:FinishedPickingMedia_Anon time to rotate and crop; degrees:" + degreesToRotate);
                        SKBitmap finalBmp = GlobalSingletonHelpers.rotateAndCrop(bitmap, degreesToRotate);
                        //((MainPage)((Xamarin.Forms.Application.Current as App).MainPage)).img.Bitmap = finalBmp;
                        NSData finalBytes                        = NSData.FromArray(finalBmp.Bytes);
                        AppDelegate.snappedImgData               = finalBytes;
                        GlobalStatusSingleton.latestImg          = finalBmp;
                        GlobalStatusSingleton.mostRecentImgBytes = finalBmp.Bytes; // this fails... need to encode as a jpeg first.

                        SKImage img = SKImage.FromBitmap(finalBmp);
                        GlobalStatusSingleton.mostRecentImgBytes = img.Encode(SKEncodedImageFormat.Jpeg, 100).ToArray();
                        SKBitmap test = GlobalSingletonHelpers.SKBitmapFromBytes(GlobalStatusSingleton.mostRecentImgBytes);
                        //SKBitmap test = GlobalSingletonHelpers.SKBitmapFromBytes(GlobalStatusSingleton.mostRecentImgBytes);

                        Debug.WriteLine("DHB:AppDelegate:FinishedLaunching:FinishedPickingMedia_Anon finalBMP sq?");
                    }
                    else
                    {
                        Debug.WriteLine("DHB:AppDelegate:FinishedLaunching:FinishedPickingMedia_Anon bitmap was null");
                    }

                    if (snappedImgData != null)
                    {
                        snappedImgData.Save(filepath, false);
                    }

                    byte[] imgBytes = null;
                    using (var streamReader = new System.IO.StreamReader(filepath)) {
                        using (System.IO.MemoryStream memStream = new System.IO.MemoryStream()) {
                            streamReader.BaseStream.CopyTo(memStream);
                            imgBytes = memStream.ToArray();
                        }
                    }

                    ((ICamera)(((IExposeCamera)(Xamarin.Forms.Application.Current as App).MainPage).getCamera())).ShowImage(filepath, imgBytes);
                    GlobalStatusSingleton.imgsTakenTracker++;
                }
            });
            uiApplication.KeyWindow.RootViewController.DismissViewController(true, null);
        }
Пример #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            FacebookSdk.SdkInitialize(this.ApplicationContext);
            fbLogin.Init();
            global::Xamarin.Auth.Presenters.XamarinAndroid.AuthenticationConfiguration.Init(this, savedInstanceState);

            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += HandleExceptions;

            GlobalStatusSingleton.imgPath =
                Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).ToString();
            GlobalStatusSingleton.imgsTakenTracker = fs.determineNumImagesTaken() + 1;

            Forms.Init(this, savedInstanceState);
            CarouselViewRenderer.Init();
            //var cv = typeof(Xamarin.Forms.CarouselView);
            //var assembly = Assembly.Load(cv.FullName);


            // @todo find a device with no camera to test this with.
            if (Forms.Context.PackageManager.HasSystemFeature(PackageManager.FeatureCamera) == false)
            {
                GlobalStatusSingleton.hasCamera = false;
            }

            try {
                LoadApplication(new App());
            } catch (Exception e) {
                var t = Task.Run(async() => { await GlobalSingletonHelpers.SendLogData("User:"******" crash:" + e.ToString()); });
                t.Wait();

                System.Console.WriteLine("{0} Exception caught.", e);
            }

            if ((GlobalStatusSingleton.UUID == null) ||
                (!Xamarin.Forms.Application.Current.Properties.ContainsKey(App.PROPERTY_UUID)) ||
                (GlobalStatusSingleton.UUID.Equals(string.Empty)))
            {
                GlobalStatusSingleton.UUID = UUID.RandomUUID().ToString();
            }

            ns = new Notifications(this);

            //this.bundle = savedInstanceState;
            //< OnCreate
            //cameraSetup();  This doesn't work yet, so don't do it.

            // This is adding functionality to ShouldTakePicture based on the fact we are the droid app.
            // Can I pass through MainPage variable?
            ((ICamera)(((IExposeCamera)(Xamarin.Forms.Application.Current as App).MainPage).getCamera())).ShouldTakePicture += () => {
                string nextFileName = GlobalStatusSingleton.IMAGE_NAME_PREFIX + GlobalStatusSingleton.imgsTakenTracker + ".jpg";
                file = new File(Android.OS.Environment.GetExternalStoragePublicDirectory(
                                    Android.OS.Environment.DirectoryPictures), nextFileName);

                /*
                 * var intent = new Intent(MediaStore.ActionImageCapture);
                 * intent.PutExtra("android.intent.extra.quickCapture", true);
                 * intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(file));
                 * //StartActivityForResult(intent, 0);  */
                StartActivityForResult(typeof(CameraServices_Droid), CAMERA_REQUEST_CODE);
                //StartActivity(typeof(CameraServices_Droid));
            };
            //> OnCreate
            bool fakeBool = false;
        }