Search in sources :

Example 1 with CameraException

use of de.vier_bier.habpanelviewer.reporting.motion.CameraException in project habpanelviewer by vbier.

the class InternalCommandHandler method handleCommand.

@Override
public boolean handleCommand(Command cmd) {
    final String cmdStr = cmd.getCommand();
    String parameter;
    if ("RESTART".equals(cmdStr)) {
        cmd.start();
        mActivity.destroy();
        ProcessPhoenix.triggerRebirth(mActivity);
    } else if ("UPDATE_ITEMS".equals(cmdStr)) {
        cmd.start();
        mConnection.sendCurrentValues();
    } else if ("ENABLE_MOTION_DETECTION".equals(cmdStr)) {
        cmd.start();
        setMotionDetectionEnabled(true);
    } else if ("DISABLE_MOTION_DETECTION".equals(cmdStr)) {
        cmd.start();
        setMotionDetectionEnabled(false);
    } else if ((parameter = matchesRegexp(CAPTURE_SCREEN_PATTERN, cmdStr)) != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ScreenCapturer c = mActivity.getCapturer();
            if (c == null) {
                cmd.failed("could not create capture class. Has the permission been granted?");
            } else {
                cmd.start();
                Bitmap bmp = c.captureScreen();
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                bmp.compress(Bitmap.CompressFormat.JPEG, 90, os);
                byte[] bytes = os.toByteArray();
                mConnection.updateJpeg(parameter, bytes);
            }
        } else {
            cmd.failed("Lollipop or newer needed to capture the screen");
        }
    } else if ((parameter = matchesRegexp(CAPTURE_CAMERA_PATTERN, cmdStr)) != null) {
        cmd.start();
        try {
            final String p = parameter;
            mMotionDetector.getCamera().takePicture(new ICamera.IPictureListener() {

                @Override
                public void picture(byte[] data) {
                    mConnection.updateJpeg(p, data);
                    cmd.finished();
                }

                @Override
                public void error(String message) {
                    cmd.failed(message);
                }

                @Override
                public void progress(String message) {
                    cmd.progress(message);
                }
            }, takePictureDelay);
        } catch (CameraException e) {
            cmd.failed(e.getLocalizedMessage());
        }
        return true;
    } else if ((parameter = matchesRegexp(START_PATTERN, cmdStr)) != null) {
        Intent launchIntent = mActivity.getPackageManager().getLaunchIntentForPackage(parameter);
        if (launchIntent != null) {
            cmd.start();
            mActivity.startActivity(launchIntent);
        } else {
            cmd.failed("could not find app for package " + parameter);
        }
    } else {
        return false;
    }
    cmd.finished();
    return true;
}
Also used : Bitmap(android.graphics.Bitmap) ScreenCapturer(de.vier_bier.habpanelviewer.ScreenCapturer) CameraException(de.vier_bier.habpanelviewer.reporting.motion.CameraException) Intent(android.content.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with CameraException

use of de.vier_bier.habpanelviewer.reporting.motion.CameraException in project habpanelviewer by vbier.

the class MainActivity method updateMotionPreferences.

public void updateMotionPreferences() {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
    if (mCam != null) {
        try {
            mCam.updateFromPreferences(prefs);
        } catch (CameraException e) {
            Toast.makeText(this, "failed to update camera state from preferences", Toast.LENGTH_LONG).show();
        }
    }
    if (mMotionDetector != null) {
        mMotionDetector.updateFromPreferences(prefs);
    }
    SurfaceView motionView = findViewById(R.id.motionView);
    boolean showPreview = prefs.getBoolean("pref_motion_detection_preview", false);
    if (showPreview) {
        motionView.setVisibility(View.VISIBLE);
    } else {
        motionView.setVisibility(View.INVISIBLE);
    }
    motionView.setLayoutParams(motionView.getLayoutParams());
}
Also used : SharedPreferences(android.content.SharedPreferences) CameraException(de.vier_bier.habpanelviewer.reporting.motion.CameraException) SurfaceView(android.view.SurfaceView)

Aggregations

CameraException (de.vier_bier.habpanelviewer.reporting.motion.CameraException)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 SurfaceView (android.view.SurfaceView)1 ScreenCapturer (de.vier_bier.habpanelviewer.ScreenCapturer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1