Пример #1
0
 protected override void OnResume()
 {
     base.OnResume();
     cameraCurrentlyLocked = defaultCameraId;
     mCamera = Android.Hardware.Camera.Open(defaultCameraId);
     if (mPreview == null)
     {
         mPreview = new Preview(this);
         mPreview.PreviewCamera = mCamera;
         SetContentView(mPreview);
     }
     if (mSensorManager == null)
     {
         mSensorManager = (SensorManager)GetSystemService(SensorService);
         accSensor      = mSensorManager.GetDefaultSensor(SensorType.Accelerometer);
         mSensorManager.RegisterListener(this, accSensor, SensorDelay.Normal);
     }
 }
Пример #2
0
        //    protected override void OnDestroy()
        //    {
        //        base.OnDestroy();
        //        matrix = null;
        //        mPreview = null;
        //        start = null;
        //        mid = null;
        //        bitmaptrophy = null;
        //        mCamera = null;
        //        previewing = false;
        //        fmanager = null;
        //        trophyFragment = null;
        //     mSensorManager = null;
        //     accSensor = null;
        //     magnetSensor = null;
        //}

        protected override void OnPause()
        {
            base.OnPause();
            // Because the Camera object is a shared resource, it's very
            // important to release it when the activity is paused.
            if (mCamera != null)
            {
                mPreview.PreviewCamera = null;
                mCamera.Release();
                mCamera = null;
            }
            if (mPreview != null)
            {
                mPreview.Dispose();
                mPreview = null;
            }
            previewing = false;
            mSensorManager.UnregisterListener(this, accSensor);
            //mSensorManager.UnregisterListener(this, magnetSensor);
        }
Пример #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Window.SetFormat(Format.Translucent);
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
            fmanager = FragmentManager;
            Window.SetBackgroundDrawable(new ColorDrawable(Color.Black));
            Bundle extras = Intent.Extras;

            if (extras != null)
            {
                TrophyName = extras.GetString("TrophyName");
            }

            trophyFragment = TrophyFragment.newInstance(TrophyName, this);
            //trophyFragment.SetStyle(DialogFragmentStyle.Normal, Resource.Style.AppThemepp);
            trophyFragment.Show(fmanager, "fragment_edit_name");
            trophyFragment.Cancelable      = false;
            trophyFragment.OnCAptureClick += (Bitmap obj, LinearLayout linearButton) => {
                if (obj != null)
                {
                    try
                    {
                        bitmaptrophy = obj;
                        mCamera.TakePicture(null, null, mPreview);
                    }
                    catch (System.Exception ex)
                    {
                        trophyFragment.progressBarLL.Visibility = ViewStates.Gone;
                        System.Console.WriteLine("Take Picture Exception:" + ex.ToString());
                    }
                }
            };

            trophyFragment.ResetAcitivity += (bool obj) => {
                System.GC.Collect();
            };

            trophyFragment.BackPressEvent += (bool obj) => {
                trophyFragment.Dismiss();
                Finish();
            };

            trophyFragment.ChangeCameraFace += (bool obj) => {
                if (previewing)
                {
                    mCamera.StopPreview();
                }
                //NB: if you don't release the current camera before switching, you app will crash
                mCamera.Release();

                //swap the id of the camera to be used
                if (currentCameraId == Android.Hardware.Camera.CameraInfo.CameraFacingBack)
                {
                    currentCameraId = Android.Hardware.Camera.CameraInfo.CameraFacingFront;
                    IsFrontCamera   = true;
                }
                else
                {
                    currentCameraId = Android.Hardware.Camera.CameraInfo.CameraFacingBack;
                    IsFrontCamera   = false;
                }

                mCamera = Android.Hardware.Camera.Open((int)currentCameraId);

                SetCameraDisplayOrientation(this, (int)currentCameraId, mCamera);
                try
                {
                    mCamera.SetPreviewDisplay(mPreview.mHolder);
                }
                catch (System.Exception exx)
                {
                    System.Console.WriteLine("Exception Changeing Camera:" + exx.ToString());
                }
                //Android.Hardware.Camera.Parameters parameters = mCamera.GetParameters();
                //parameters.SetPreviewSize(mPreview.mPreviewSize.Width, mPreview.mPreviewSize.Height);
                //System.Console.WriteLine("Param mPreviewSize.Width:" + mPreview.mPreviewSize.Width + " mPreviewSize.height:" + mPreview.mPreviewSize.Height);
                //parameters.SetPictureSize(mPreview.mPreviewSize.Width, mPreview.mPreviewSize.Height);
                //parameters.JpegQuality = (100);
                //parameters.PictureFormat = (ImageFormat.Jpeg);
                //parameters.FocusMode = Android.Hardware.Camera.Parameters.FocusModeAuto;
                //if (parameters.IsZoomSupported)
                //    parameters.Zoom = (0);
                //mCamera.SetParameters(parameters);
                //mCamera.StartPreview();
                previewing = false;
                mPreview.Dispose();
                mPreview = new Preview(this);
                SetContentView(mPreview);
                mPreview.PreviewCamera = mCamera;
            };

            //numberOfCameras = Android.Hardware.Camera.NumberOfCameras;

            //// Find the ID of the default camera
            //Android.Hardware.Camera.CameraInfo cameraInfo = new Android.Hardware.Camera.CameraInfo();
            //for (int i = 0; i < numberOfCameras; i++)
            //{
            //    Android.Hardware.Camera.GetCameraInfo(i, cameraInfo);
            //    if (cameraInfo.Facing == CameraFacing.Back)
            //    {
            //        defaultCameraId = i;
            //    }
            //}
        }