Search in sources :

Example 6 with Preview

use of net.sourceforge.opencamera.Preview.Preview in project OpenCamera by ageback.

the class PopupView method switchToWhiteBalance.

public void switchToWhiteBalance(String selected_value) {
    if (MyDebug.LOG)
        Log.d(TAG, "switchToWhiteBalance: " + selected_value);
    final MainActivity main_activity = (MainActivity) this.getContext();
    final Preview preview = main_activity.getPreview();
    boolean close_popup = false;
    int temperature = -1;
    if (selected_value.equals("manual")) {
        if (preview.getCameraController() != null) {
            String current_white_balance = preview.getCameraController().getWhiteBalance();
            if (current_white_balance == null || !current_white_balance.equals("manual")) {
                // try to choose a default manual white balance temperature as close as possible to the current auto
                if (MyDebug.LOG)
                    Log.d(TAG, "changed to manual white balance");
                close_popup = true;
                if (preview.getCameraController().captureResultHasWhiteBalanceTemperature()) {
                    temperature = preview.getCameraController().captureResultWhiteBalanceTemperature();
                    if (MyDebug.LOG)
                        Log.d(TAG, "default to manual white balance temperature: " + temperature);
                    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(main_activity);
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putInt(PreferenceKeys.WhiteBalanceTemperaturePreferenceKey, temperature);
                    editor.apply();
                }
            // otherwise default to the saved value
            }
        }
    }
    if (preview.getCameraController() != null) {
        preview.getCameraController().setWhiteBalance(selected_value);
        if (temperature > 0) {
            preview.getCameraController().setWhiteBalanceTemperature(temperature);
            // also need to update the slider!
            main_activity.setManualWBSeekbar();
        }
    }
    // keep popup open, unless switching to manual
    if (close_popup) {
        main_activity.closePopup();
    }
// main_activity.updateForSettings(getResources().getString(R.string.white_balance) + ": " + selected_value);
// main_activity.closePopup();
}
Also used : SharedPreferences(android.content.SharedPreferences) Preview(net.sourceforge.opencamera.Preview.Preview) MainActivity(net.sourceforge.opencamera.MainActivity)

Example 7 with Preview

use of net.sourceforge.opencamera.Preview.Preview in project OpenCamera by ageback.

the class MyApplicationInterface method trashLastImage.

void trashLastImage() {
    if (MyDebug.LOG)
        Log.d(TAG, "trashImage");
    Preview preview = main_activity.getPreview();
    if (preview.isPreviewPaused()) {
        for (int i = 0; i < last_images.size(); i++) {
            LastImage last_image = last_images.get(i);
            trashImage(last_images_saf, last_image.uri, last_image.name);
        }
        clearLastImages();
        preview.startCameraPreview();
    }
    // Calling updateGalleryIcon() immediately has problem that it still returns the latest image that we've just deleted!
    // But works okay if we call after a delay. 100ms works fine on Nexus 7 and Galaxy Nexus, but set to 500 just to be safe.
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            main_activity.updateGalleryIcon();
        }
    }, 500);
}
Also used : DrawPreview(net.sourceforge.opencamera.UI.DrawPreview) Preview(net.sourceforge.opencamera.Preview.Preview) Handler(android.os.Handler) Paint(android.graphics.Paint)

Example 8 with Preview

use of net.sourceforge.opencamera.Preview.Preview in project OpenCamera by ageback.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    long debug_time = 0;
    if (MyDebug.LOG) {
        Log.d(TAG, "onCreate: " + this);
        debug_time = System.currentTimeMillis();
    }
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        // don't show orientation animations
        WindowManager.LayoutParams layout = getWindow().getAttributes();
        layout.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
        getWindow().setAttributes(layout);
    }
    setContentView(R.layout.activity_main);
    // initialise any unset preferences to their default values
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting default preference values: " + (System.currentTimeMillis() - debug_time));
    if (getIntent() != null && getIntent().getExtras() != null) {
        // whether called from testing
        is_test = getIntent().getExtras().getBoolean("test_project");
        if (MyDebug.LOG)
            Log.d(TAG, "is_test: " + is_test);
    }
    if (getIntent() != null && getIntent().getExtras() != null) {
        // whether called from Take Photo widget
        if (MyDebug.LOG)
            Log.d(TAG, "take_photo?: " + getIntent().getExtras().getBoolean(TakePhoto.TAKE_PHOTO));
    }
    if (getIntent() != null && getIntent().getAction() != null) {
        // invoked via the manifest shortcut?
        if (MyDebug.LOG)
            Log.d(TAG, "shortcut: " + getIntent().getAction());
    }
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    // determine whether we should support "auto stabilise" feature
    // risk of running out of memory on lower end devices, due to manipulation of large bitmaps
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    if (MyDebug.LOG) {
        Log.d(TAG, "standard max memory = " + activityManager.getMemoryClass() + "MB");
        Log.d(TAG, "large max memory = " + activityManager.getLargeMemoryClass() + "MB");
    }
    large_heap_memory = activityManager.getLargeMemoryClass();
    if (large_heap_memory >= 128) {
        supports_auto_stabilise = true;
    }
    if (MyDebug.LOG)
        Log.d(TAG, "supports_auto_stabilise? " + supports_auto_stabilise);
    // also added the check for having 128MB standard heap, to support modded LG G2, which has 128MB standard, 256MB large - see https://sourceforge.net/p/opencamera/tickets/9/
    if (activityManager.getMemoryClass() >= 128 || activityManager.getLargeMemoryClass() >= 512) {
        supports_force_video_4k = true;
    }
    if (MyDebug.LOG)
        Log.d(TAG, "supports_force_video_4k? " + supports_force_video_4k);
    // set up components
    mainUI = new MainUI(this);
    applicationInterface = new MyApplicationInterface(this, savedInstanceState);
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating application interface: " + (System.currentTimeMillis() - debug_time));
    textFormatter = new TextFormatter(this);
    // determine whether we support Camera2 API
    initCamera2Support();
    // set up window flags for normal operation
    setWindowFlagsForCamera();
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting window flags: " + (System.currentTimeMillis() - debug_time));
    save_location_history = new SaveLocationHistory(this, "save_location_history", getStorageUtils().getSaveLocation());
    if (applicationInterface.getStorageUtils().isUsingSAF()) {
        if (MyDebug.LOG)
            Log.d(TAG, "create new SaveLocationHistory for SAF");
        save_location_history_saf = new SaveLocationHistory(this, "save_location_history_saf", getStorageUtils().getSaveLocationSAF());
    }
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after updating folder history: " + (System.currentTimeMillis() - debug_time));
    // set up sensors
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    // accelerometer sensor (for device orientation)
    if (mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
        if (MyDebug.LOG)
            Log.d(TAG, "found accelerometer");
        mSensorAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    } else {
        if (MyDebug.LOG)
            Log.d(TAG, "no support for accelerometer");
    }
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating accelerometer sensor: " + (System.currentTimeMillis() - debug_time));
    // magnetic sensor (for compass direction)
    if (mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null) {
        if (MyDebug.LOG)
            Log.d(TAG, "found magnetic sensor");
        mSensorMagnetic = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    } else {
        if (MyDebug.LOG)
            Log.d(TAG, "no support for magnetic sensor");
    }
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating magnetic sensor: " + (System.currentTimeMillis() - debug_time));
    // clear any seek bars (just in case??)
    mainUI.clearSeekBar();
    // set up the camera and its preview
    preview = new Preview(applicationInterface, ((ViewGroup) this.findViewById(R.id.preview)));
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating preview: " + (System.currentTimeMillis() - debug_time));
    // initialise on-screen button visibility
    View switchCameraButton = findViewById(R.id.switch_camera);
    switchCameraButton.setVisibility(preview.getCameraControllerManager().getNumberOfCameras() > 1 ? View.VISIBLE : View.GONE);
    View speechRecognizerButton = findViewById(R.id.audio_control);
    // disabled by default, until the speech recognizer is created
    speechRecognizerButton.setVisibility(View.GONE);
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting button visibility: " + (System.currentTimeMillis() - debug_time));
    View pauseVideoButton = findViewById(R.id.pause_video);
    pauseVideoButton.setVisibility(View.GONE);
    View takePhotoVideoButton = findViewById(R.id.take_photo_when_video_recording);
    takePhotoVideoButton.setVisibility(View.GONE);
    // We initialise optional controls to invisible/gone, so they don't show while the camera is opening - the actual visibility is
    // set in cameraSetup().
    // Note that ideally we'd set this in the xml, but doing so for R.id.zoom causes a crash on Galaxy Nexus startup beneath
    // setContentView()!
    // To be safe, we also do so for take_photo and zoom_seekbar (we already know we've had no reported crashes for focus_seekbar,
    // however).
    View takePhotoButton = findViewById(R.id.take_photo);
    takePhotoButton.setVisibility(View.INVISIBLE);
    View zoomControls = findViewById(R.id.zoom);
    zoomControls.setVisibility(View.GONE);
    View zoomSeekbar = findViewById(R.id.zoom_seekbar);
    zoomSeekbar.setVisibility(View.INVISIBLE);
    // listen for orientation event change
    orientationEventListener = new OrientationEventListener(this) {

        @Override
        public void onOrientationChanged(int orientation) {
            MainActivity.this.mainUI.onOrientationChanged(orientation);
        }
    };
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting orientation event listener: " + (System.currentTimeMillis() - debug_time));
    // set up gallery button long click
    View galleryButton = findViewById(R.id.gallery);
    galleryButton.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // preview.showToast(null, "Long click");
            longClickedGallery();
            return true;
        }
    });
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting gallery long click listener: " + (System.currentTimeMillis() - debug_time));
    // listen for gestures
    gestureDetector = new GestureDetector(this, new MyGestureDetector());
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating gesture detector: " + (System.currentTimeMillis() - debug_time));
    // set up listener to handle immersive mode options
    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
            if (!usingKitKatImmersiveMode())
                return;
            if (MyDebug.LOG)
                Log.d(TAG, "onSystemUiVisibilityChange: " + visibility);
            if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                if (MyDebug.LOG)
                    Log.d(TAG, "system bars now visible");
                // The system bars are visible. Make any desired
                // adjustments to your UI, such as showing the action bar or
                // other navigational controls.
                mainUI.setImmersiveMode(false);
                setImmersiveTimer();
            } else {
                if (MyDebug.LOG)
                    Log.d(TAG, "system bars now NOT visible");
                // The system bars are NOT visible. Make any desired
                // adjustments to your UI, such as hiding the action bar or
                // other navigational controls.
                mainUI.setImmersiveMode(true);
            }
        }
    });
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting immersive mode listener: " + (System.currentTimeMillis() - debug_time));
    // show "about" dialog for first time use; also set some per-device defaults
    boolean has_done_first_time = sharedPreferences.contains(PreferenceKeys.FirstTimePreferenceKey);
    if (MyDebug.LOG)
        Log.d(TAG, "has_done_first_time: " + has_done_first_time);
    if (!has_done_first_time) {
        setDeviceDefaults();
    }
    if (!has_done_first_time) {
        if (!is_test) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
            alertDialog.setTitle(R.string.app_name);
            alertDialog.setMessage(R.string.intro_text);
            alertDialog.setPositiveButton(android.R.string.ok, null);
            alertDialog.setNegativeButton(R.string.preference_online_help, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "online help");
                    launchOnlineHelp();
                }
            });
            alertDialog.show();
        }
        setFirstTimeFlag();
    }
    {
        // handle What's New dialog
        int version_code = -1;
        try {
            PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            version_code = pInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            if (MyDebug.LOG)
                Log.d(TAG, "NameNotFoundException exception trying to get version number");
            e.printStackTrace();
        }
        if (version_code != -1) {
            int latest_version = sharedPreferences.getInt(PreferenceKeys.LatestVersionPreferenceKey, 0);
            if (MyDebug.LOG) {
                Log.d(TAG, "version_code: " + version_code);
                Log.d(TAG, "latest_version: " + latest_version);
            }
            final boolean whats_new_enabled = false;
            if (whats_new_enabled) {
                final boolean force_whats_new = false;
                // don't show What's New if this is the first time the user has run
                if (has_done_first_time && (force_whats_new || version_code > latest_version)) {
                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
                    alertDialog.setTitle(R.string.whats_new);
                    alertDialog.setMessage(R.string.whats_new_text);
                    alertDialog.setPositiveButton(android.R.string.ok, null);
                    alertDialog.setNegativeButton(R.string.donate, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "donate");
                            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(MainActivity.getDonateLink()));
                            startActivity(browserIntent);
                        }
                    });
                    alertDialog.show();
                }
            }
            // we set the latest_version whether or not the dialog is shown - if we showed the irst time dialog, we don't
            // want to then show the What's New dialog next time we run!
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putInt(PreferenceKeys.LatestVersionPreferenceKey, version_code);
            editor.apply();
        }
    }
    setModeFromIntents(savedInstanceState);
    // load icons
    preloadIcons(R.array.flash_icons);
    preloadIcons(R.array.focus_mode_icons);
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after preloading icons: " + (System.currentTimeMillis() - debug_time));
    // initialise text to speech engine
    textToSpeechSuccess = false;
    // run in separate thread so as to not delay startup time
    new Thread(new Runnable() {

        public void run() {
            textToSpeech = new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {

                @Override
                public void onInit(int status) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "TextToSpeech initialised");
                    if (status == TextToSpeech.SUCCESS) {
                        textToSpeechSuccess = true;
                        if (MyDebug.LOG)
                            Log.d(TAG, "TextToSpeech succeeded");
                    } else {
                        if (MyDebug.LOG)
                            Log.d(TAG, "TextToSpeech failed");
                    }
                }
            });
        }
    }).start();
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: total time for Activity startup: " + (System.currentTimeMillis() - debug_time));
}
Also used : MainUI(net.sourceforge.opencamera.UI.MainUI) AlertDialog(android.app.AlertDialog) OrientationEventListener(android.view.OrientationEventListener) DialogInterface(android.content.DialogInterface) GestureDetector(android.view.GestureDetector) ActivityManager(android.app.ActivityManager) TextToSpeech(android.speech.tts.TextToSpeech) WindowManager(android.view.WindowManager) SharedPreferences(android.content.SharedPreferences) PackageInfo(android.content.pm.PackageInfo) Preview(net.sourceforge.opencamera.Preview.Preview) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Example 9 with Preview

use of net.sourceforge.opencamera.Preview.Preview in project OpenCamera by ageback.

the class DrawPreview method drawGrids.

private void drawGrids(Canvas canvas) {
    Preview preview = main_activity.getPreview();
    CameraController camera_controller = preview.getCameraController();
    if (camera_controller == null) {
        return;
    }
    switch(preference_grid_pref) {
        case "preference_grid_3x3":
            p.setColor(Color.WHITE);
            canvas.drawLine(canvas.getWidth() / 3.0f, 0.0f, canvas.getWidth() / 3.0f, canvas.getHeight() - 1.0f, p);
            canvas.drawLine(2.0f * canvas.getWidth() / 3.0f, 0.0f, 2.0f * canvas.getWidth() / 3.0f, canvas.getHeight() - 1.0f, p);
            canvas.drawLine(0.0f, canvas.getHeight() / 3.0f, canvas.getWidth() - 1.0f, canvas.getHeight() / 3.0f, p);
            canvas.drawLine(0.0f, 2.0f * canvas.getHeight() / 3.0f, canvas.getWidth() - 1.0f, 2.0f * canvas.getHeight() / 3.0f, p);
            break;
        case "preference_grid_phi_3x3":
            p.setColor(Color.WHITE);
            canvas.drawLine(canvas.getWidth() / 2.618f, 0.0f, canvas.getWidth() / 2.618f, canvas.getHeight() - 1.0f, p);
            canvas.drawLine(1.618f * canvas.getWidth() / 2.618f, 0.0f, 1.618f * canvas.getWidth() / 2.618f, canvas.getHeight() - 1.0f, p);
            canvas.drawLine(0.0f, canvas.getHeight() / 2.618f, canvas.getWidth() - 1.0f, canvas.getHeight() / 2.618f, p);
            canvas.drawLine(0.0f, 1.618f * canvas.getHeight() / 2.618f, canvas.getWidth() - 1.0f, 1.618f * canvas.getHeight() / 2.618f, p);
            break;
        case "preference_grid_4x2":
            p.setColor(Color.GRAY);
            canvas.drawLine(canvas.getWidth() / 4.0f, 0.0f, canvas.getWidth() / 4.0f, canvas.getHeight() - 1.0f, p);
            canvas.drawLine(canvas.getWidth() / 2.0f, 0.0f, canvas.getWidth() / 2.0f, canvas.getHeight() - 1.0f, p);
            canvas.drawLine(3.0f * canvas.getWidth() / 4.0f, 0.0f, 3.0f * canvas.getWidth() / 4.0f, canvas.getHeight() - 1.0f, p);
            canvas.drawLine(0.0f, canvas.getHeight() / 2.0f, canvas.getWidth() - 1.0f, canvas.getHeight() / 2.0f, p);
            p.setColor(Color.WHITE);
            // convert dps to pixels
            int crosshairs_radius = (int) (20 * scale + 0.5f);
            canvas.drawLine(canvas.getWidth() / 2.0f, canvas.getHeight() / 2.0f - crosshairs_radius, canvas.getWidth() / 2.0f, canvas.getHeight() / 2.0f + crosshairs_radius, p);
            canvas.drawLine(canvas.getWidth() / 2.0f - crosshairs_radius, canvas.getHeight() / 2.0f, canvas.getWidth() / 2.0f + crosshairs_radius, canvas.getHeight() / 2.0f, p);
            break;
        case "preference_grid_crosshair":
            p.setColor(Color.WHITE);
            canvas.drawLine(canvas.getWidth() / 2.0f, 0.0f, canvas.getWidth() / 2.0f, canvas.getHeight() - 1.0f, p);
            canvas.drawLine(0.0f, canvas.getHeight() / 2.0f, canvas.getWidth() - 1.0f, canvas.getHeight() / 2.0f, p);
            break;
        case "preference_grid_golden_spiral_right":
        case "preference_grid_golden_spiral_left":
        case "preference_grid_golden_spiral_upside_down_right":
        case "preference_grid_golden_spiral_upside_down_left":
            canvas.save();
            switch(preference_grid_pref) {
                case "preference_grid_golden_spiral_left":
                    canvas.scale(-1.0f, 1.0f, canvas.getWidth() * 0.5f, canvas.getHeight() * 0.5f);
                    break;
                case "preference_grid_golden_spiral_right":
                    // no transformation needed
                    break;
                case "preference_grid_golden_spiral_upside_down_left":
                    canvas.rotate(180.0f, canvas.getWidth() * 0.5f, canvas.getHeight() * 0.5f);
                    break;
                case "preference_grid_golden_spiral_upside_down_right":
                    canvas.scale(1.0f, -1.0f, canvas.getWidth() * 0.5f, canvas.getHeight() * 0.5f);
                    break;
            }
            p.setColor(Color.WHITE);
            p.setStyle(Paint.Style.STROKE);
            p.setStrokeWidth(stroke_width);
            int fibb = 34;
            int fibb_n = 21;
            int left = 0, top = 0;
            int full_width = canvas.getWidth();
            int full_height = canvas.getHeight();
            int width = (int) (full_width * ((double) fibb_n) / (double) (fibb));
            int height = full_height;
            for (int count = 0; count < 2; count++) {
                canvas.save();
                draw_rect.set(left, top, left + width, top + height);
                canvas.clipRect(draw_rect);
                canvas.drawRect(draw_rect, p);
                draw_rect.set(left, top, left + 2 * width, top + 2 * height);
                canvas.drawOval(draw_rect, p);
                canvas.restore();
                int old_fibb = fibb;
                fibb = fibb_n;
                fibb_n = old_fibb - fibb;
                left += width;
                full_width = full_width - width;
                width = full_width;
                height = (int) (height * ((double) fibb_n) / (double) (fibb));
                canvas.save();
                draw_rect.set(left, top, left + width, top + height);
                canvas.clipRect(draw_rect);
                canvas.drawRect(draw_rect, p);
                draw_rect.set(left - width, top, left + width, top + 2 * height);
                canvas.drawOval(draw_rect, p);
                canvas.restore();
                old_fibb = fibb;
                fibb = fibb_n;
                fibb_n = old_fibb - fibb;
                top += height;
                full_height = full_height - height;
                height = full_height;
                width = (int) (width * ((double) fibb_n) / (double) (fibb));
                left += full_width - width;
                canvas.save();
                draw_rect.set(left, top, left + width, top + height);
                canvas.clipRect(draw_rect);
                canvas.drawRect(draw_rect, p);
                draw_rect.set(left - width, top - height, left + width, top + height);
                canvas.drawOval(draw_rect, p);
                canvas.restore();
                old_fibb = fibb;
                fibb = fibb_n;
                fibb_n = old_fibb - fibb;
                full_width = full_width - width;
                width = full_width;
                left -= width;
                height = (int) (height * ((double) fibb_n) / (double) (fibb));
                top += full_height - height;
                canvas.save();
                draw_rect.set(left, top, left + width, top + height);
                canvas.clipRect(draw_rect);
                canvas.drawRect(draw_rect, p);
                draw_rect.set(left, top - height, left + 2 * width, top + height);
                canvas.drawOval(draw_rect, p);
                canvas.restore();
                old_fibb = fibb;
                fibb = fibb_n;
                fibb_n = old_fibb - fibb;
                full_height = full_height - height;
                height = full_height;
                top -= height;
                width = (int) (width * ((double) fibb_n) / (double) (fibb));
            }
            canvas.restore();
            // reset
            p.setStyle(Paint.Style.FILL);
            break;
        case "preference_grid_golden_triangle_1":
        case "preference_grid_golden_triangle_2":
            p.setColor(Color.WHITE);
            double theta = Math.atan2(canvas.getWidth(), canvas.getHeight());
            double dist = canvas.getHeight() * Math.cos(theta);
            float dist_x = (float) (dist * Math.sin(theta));
            float dist_y = (float) (dist * Math.cos(theta));
            if (preference_grid_pref.equals("preference_grid_golden_triangle_1")) {
                canvas.drawLine(0.0f, canvas.getHeight() - 1.0f, canvas.getWidth() - 1.0f, 0.0f, p);
                canvas.drawLine(0.0f, 0.0f, dist_x, canvas.getHeight() - dist_y, p);
                canvas.drawLine(canvas.getWidth() - 1.0f - dist_x, dist_y - 1.0f, canvas.getWidth() - 1.0f, canvas.getHeight() - 1.0f, p);
            } else {
                canvas.drawLine(0.0f, 0.0f, canvas.getWidth() - 1.0f, canvas.getHeight() - 1.0f, p);
                canvas.drawLine(canvas.getWidth() - 1.0f, 0.0f, canvas.getWidth() - 1.0f - dist_x, canvas.getHeight() - dist_y, p);
                canvas.drawLine(dist_x, dist_y - 1.0f, 0.0f, canvas.getHeight() - 1.0f, p);
            }
            break;
        case "preference_grid_diagonals":
            p.setColor(Color.WHITE);
            canvas.drawLine(0.0f, 0.0f, canvas.getHeight() - 1.0f, canvas.getHeight() - 1.0f, p);
            canvas.drawLine(canvas.getHeight() - 1.0f, 0.0f, 0.0f, canvas.getHeight() - 1.0f, p);
            int diff = canvas.getWidth() - canvas.getHeight();
            if (diff > 0) {
                canvas.drawLine(diff, 0.0f, diff + canvas.getHeight() - 1.0f, canvas.getHeight() - 1.0f, p);
                canvas.drawLine(diff + canvas.getHeight() - 1.0f, 0.0f, diff, canvas.getHeight() - 1.0f, p);
            }
            break;
    }
}
Also used : CameraController(net.sourceforge.opencamera.CameraController.CameraController) Preview(net.sourceforge.opencamera.Preview.Preview) Paint(android.graphics.Paint)

Example 10 with Preview

use of net.sourceforge.opencamera.Preview.Preview in project OpenCamera by ageback.

the class DrawPreview method drawCropGuides.

private void drawCropGuides(Canvas canvas) {
    Preview preview = main_activity.getPreview();
    CameraController camera_controller = preview.getCameraController();
    if (preview.isVideo() || preview_size_wysiwyg_pref) {
        String preference_crop_guide = sharedPreferences.getString(PreferenceKeys.ShowCropGuidePreferenceKey, "crop_guide_none");
        if (camera_controller != null && preview.getTargetRatio() > 0.0 && !preference_crop_guide.equals("crop_guide_none")) {
            p.setStyle(Paint.Style.STROKE);
            p.setStrokeWidth(stroke_width);
            // Yellow 500
            p.setColor(Color.rgb(255, 235, 59));
            double crop_ratio = -1.0;
            switch(preference_crop_guide) {
                case "crop_guide_1":
                    crop_ratio = 1.0;
                    break;
                case "crop_guide_1.25":
                    crop_ratio = 1.25;
                    break;
                case "crop_guide_1.33":
                    crop_ratio = 1.33333333;
                    break;
                case "crop_guide_1.4":
                    crop_ratio = 1.4;
                    break;
                case "crop_guide_1.5":
                    crop_ratio = 1.5;
                    break;
                case "crop_guide_1.78":
                    crop_ratio = 1.77777778;
                    break;
                case "crop_guide_1.85":
                    crop_ratio = 1.85;
                    break;
                case "crop_guide_2.33":
                    crop_ratio = 2.33333333;
                    break;
                case "crop_guide_2.35":
                    // actually 1920:817
                    crop_ratio = 2.35006120;
                    break;
                case "crop_guide_2.4":
                    crop_ratio = 2.4;
                    break;
            }
            if (crop_ratio > 0.0 && Math.abs(preview.getTargetRatio() - crop_ratio) > 1.0e-5) {
                /*if( MyDebug.LOG ) {
		    			Log.d(TAG, "crop_ratio: " + crop_ratio);
		    			Log.d(TAG, "preview_targetRatio: " + preview_targetRatio);
		    			Log.d(TAG, "canvas width: " + canvas.getWidth());
		    			Log.d(TAG, "canvas height: " + canvas.getHeight());
		    		}*/
                int left = 1, top = 1, right = canvas.getWidth() - 1, bottom = canvas.getHeight() - 1;
                if (crop_ratio > preview.getTargetRatio()) {
                    // crop ratio is wider, so we have to crop top/bottom
                    double new_hheight = ((double) canvas.getWidth()) / (2.0f * crop_ratio);
                    top = (canvas.getHeight() / 2 - (int) new_hheight);
                    bottom = (canvas.getHeight() / 2 + (int) new_hheight);
                } else {
                    // crop ratio is taller, so we have to crop left/right
                    double new_hwidth = (((double) canvas.getHeight()) * crop_ratio) / 2.0f;
                    left = (canvas.getWidth() / 2 - (int) new_hwidth);
                    right = (canvas.getWidth() / 2 + (int) new_hwidth);
                }
                canvas.drawRect(left, top, right, bottom, p);
            }
            // reset
            p.setStyle(Paint.Style.FILL);
        }
    }
}
Also used : CameraController(net.sourceforge.opencamera.CameraController.CameraController) Preview(net.sourceforge.opencamera.Preview.Preview) Paint(android.graphics.Paint)

Aggregations

Preview (net.sourceforge.opencamera.Preview.Preview)14 Paint (android.graphics.Paint)10 CameraController (net.sourceforge.opencamera.CameraController.CameraController)8 SharedPreferences (android.content.SharedPreferences)4 View (android.view.View)4 Intent (android.content.Intent)3 Rect (android.graphics.Rect)2 DrawPreview (net.sourceforge.opencamera.UI.DrawPreview)2 SuppressLint (android.annotation.SuppressLint)1 ActivityManager (android.app.ActivityManager)1 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 PackageInfo (android.content.pm.PackageInfo)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 RecognizerIntent (android.speech.RecognizerIntent)1 TextToSpeech (android.speech.tts.TextToSpeech)1 GestureDetector (android.view.GestureDetector)1 OrientationEventListener (android.view.OrientationEventListener)1