Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e730889a authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

WIP

parent 4d5da2d8
Loading
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -223,9 +223,29 @@ public class MyPreferenceFragment extends PreferenceFragment implements OnShared
        final int [] heights = bundle.getIntArray("resolution_heights");
        final boolean [] supports_burst = bundle.getBooleanArray("resolution_supports_burst");

        Preference pref1 = findPreference("preference_resolution");
        PreferenceGroup pg1 = (PreferenceGroup)this.findPreference("preference_screen_photo_settings");
        pg1.removePreference(pref1);
        if( widths != null && heights != null && supports_burst != null ) {
            CharSequence [] entries = new CharSequence[widths.length];
            CharSequence [] values = new CharSequence[widths.length];
            for(int i=0;i<widths.length;i++) {
                entries[i] = widths[i] + " x " + heights[i] + " " + Preview.getAspectRatioMPString(getResources(), widths[i], heights[i], supports_burst[i]);
                values[i] = widths[i] + " " + heights[i];
            }
            ListPreference lp = (ListPreference)findPreference("preference_resolution");
            lp.setEntries(entries);
            lp.setEntryValues(values);
            String resolution_preference_key = PreferenceKeys.getResolutionPreferenceKey(cameraId);
            String resolution_value = sharedPreferences.getString(resolution_preference_key, "");
            if( MyDebug.LOG )
                Log.d(TAG, "resolution_value: " + resolution_value);
            lp.setValue(resolution_value);
            // now set the key, so we save for the correct cameraId
            lp.setKey(resolution_preference_key);
        }
        else {
            Preference pref = findPreference("preference_resolution");
            PreferenceGroup pg = (PreferenceGroup)this.findPreference("preference_screen_photo_settings");
            pg.removePreference(pref);
        }

        String fps_preference_key = PreferenceKeys.getVideoFPSPreferenceKey(cameraId);
        if( MyDebug.LOG )
+25 −1
Original line number Diff line number Diff line
@@ -2593,9 +2593,13 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
            if (current_size_index == -1) {
                // set to largest
                CameraController.Size current_size = null;

                double targetRatio = getDisplayRatio();

                for (int i = 0; i < photo_sizes.size(); i++) {
                    CameraController.Size size = photo_sizes.get(i);
                    if (current_size == null || size.width * size.height > current_size.width * current_size.height) {
                    double ratio = (double) size.width / size.height;
                    if (current_size == null || isPerfectFullScreenRatio(targetRatio, ratio)) {
                        current_size_index = i;
                        current_size = size;
                    }
@@ -2908,6 +2912,26 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
        }
    }

    private boolean isPerfectFullScreenRatio(double targetRatio, double ratio) {
        return (ratio >= targetRatio) && (ratio - targetRatio) < 0.05D;
    }

    private double getDisplayRatio() {
        Point display_size = new Point();
        Display display = ((Activity)getContext()).getWindowManager().getDefaultDisplay();
        display.getSize(display_size);
        // getSize() is adjusted based on the current rotation, so should already be landscape format, but:
        // (a) it would be good to not assume Open Camera runs in landscape mode (if we ever ran in portrait mode,
        // we'd still want display_size.x > display_size.y as preview resolutions also have width > height,
        // (b) on some devices (e.g., Nokia 8), when coming back from the Settings when device is held in Preview,
        // display size is returned in portrait format! (To reproduce, enable "Maximise preview size"; or if that's
        // already enabled, change the setting off and on.)
        if (display_size.x < display_size.y) {
            display_size.set(display_size.y, display_size.x);
        }
        return ((double) display_size.x) / (double) display_size.y;
    }

    private void setPreviewSize() {
        if (MyDebug.LOG)
            Log.d(TAG, "setPreviewSize()");