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

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

Merge branch '5334-Revert_force_resolution_set_on_camera_mode' into 'master'

5334-Revert_force_resolution_set_on_camera_mode

See merge request !37
parents 4d5da2d8 78ab8a8f
Loading
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ public class MainActivity extends Activity {
    //private boolean ui_placement_right = true;

    private boolean want_no_limits; // whether we want to run with FLAG_LAYOUT_NO_LIMITS
    private boolean can_draw_nav_bar = true;
    private boolean set_window_insets_listener; // whether we've enabled a setOnApplyWindowInsetsListener()
    private int navigation_gap;
    public static volatile boolean test_preview_want_no_limits; // test flag, if set to true then instead use test_preview_want_no_limits_value; needs to be static, as it needs to be set before activity is created to take effect
@@ -652,8 +653,10 @@ public class MainActivity extends Activity {
        }
    }

    public void handleDecorFitsSystemWindows() {
        setDecorFitsSystemWindows(!isInFullScreenMode());
    public void handleDecorFitsSystemWindows(double previewRatio, double screenRatio) {
        boolean decorFitsSystemWindows = screenRatio >= previewRatio;
        setDecorFitsSystemWindows(decorFitsSystemWindows);
        can_draw_nav_bar = !decorFitsSystemWindows;
    }

    /**
@@ -666,10 +669,10 @@ public class MainActivity extends Activity {
    }

    /**
     * if sdk>=R & not in full screen, means the DecorFitsSystemWindows=true, then we can ignore navigationGap.
     * if sdk>=R & can't draw navigation bar, means the DecorFitsSystemWindows=true, then we can ignore navigationGap.
     */
    public int getNavigationGap() {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !isInFullScreenMode()) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !can_draw_nav_bar) {
            return 0;
        }
        return want_no_limits ? navigation_gap : 0;
+23 −4
Original line number Diff line number Diff line
@@ -222,10 +222,29 @@ public class MyPreferenceFragment extends PreferenceFragment implements OnShared
        final int [] widths = bundle.getIntArray("resolution_widths");
        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 )
+8 −26
Original line number Diff line number Diff line
@@ -3470,21 +3470,6 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
        return optimalSize;
    }

    private static CameraController.Size getClosestSizeForFullScreen(List<CameraController.Size> sizes, double targetRatio) {
        if (MyDebug.LOG)
            Log.d(TAG, "getClosestSize()");
        CameraController.Size optimalSize = null;
        double minDiff = Double.MIN_VALUE;
        for (CameraController.Size size : sizes) {
            double ratio = (double) size.width / size.height;
            if ((ratio - targetRatio) > minDiff) {
                optimalSize = size;
                minDiff = ratio - targetRatio;
            }
        }
        return (optimalSize != null) ? optimalSize : getClosestSize(sizes, targetRatio, null);
    }

    public CameraController.Size getOptimalPreviewSize(List<CameraController.Size> sizes) {
        if (MyDebug.LOG)
            Log.d(TAG, "getOptimalPreviewSize()");
@@ -3518,7 +3503,6 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
            if (MyDebug.LOG)
                Log.d(TAG, "display_size: " + display_size.x + " x " + display_size.y);
        }
        ((MainActivity)getContext()).handleDecorFitsSystemWindows();
        double targetRatio = calculateTargetRatioForPreview(display_size);
        int targetHeight = Math.min(display_size.y, display_size.x);
        if (targetHeight <= 0) {
@@ -3540,17 +3524,9 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
            // can't find match for aspect ratio, so find closest one
            if (MyDebug.LOG)
                Log.d(TAG, "no preview size matches the aspect ratio");
            if (((MainActivity)getContext()).isInFullScreenMode()) {
                optimalSize = getClosestSizeForFullScreen(sizes, targetRatio);
            } else {
            optimalSize = getClosestSize(sizes, targetRatio, null);
        }
        }

        if (((MainActivity)getContext()).isInFullScreenMode()) {
           camera_controller.setPictureSize(optimalSize.width, optimalSize.height);
        }

        handleDecorFitsSystemWindows(optimalSize, display_size);
        if (MyDebug.LOG) {
            Log.d(TAG, "chose optimalSize: " + optimalSize.width + " x " + optimalSize.height);
            Log.d(TAG, "optimalSize ratio: " + ((double) optimalSize.width / optimalSize.height));
@@ -3558,6 +3534,12 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
        return optimalSize;
    }

    private void handleDecorFitsSystemWindows(CameraController.Size optimalSize, Point display_size) {
        double previewRatio = (double) optimalSize.width / optimalSize.height;
        double screenRatio = (double) display_size.x / display_size.y;
        ((MainActivity)getContext()).handleDecorFitsSystemWindows(previewRatio, screenRatio);
    }

    public CameraController.Size getOptimalVideoPictureSize(List<CameraController.Size> sizes, double targetRatio) {
        if (MyDebug.LOG)
            Log.d(TAG, "getOptimalVideoPictureSize()");
+1 −1
Original line number Diff line number Diff line
@@ -349,7 +349,7 @@ public class PopupView extends LinearLayout {
            if( MyDebug.LOG )
                Log.d(TAG, "PopupView time 8: " + (System.nanoTime() - debug_time));

            if( !preview.isVideo() && photo_mode != MyApplicationInterface.PhotoMode.Panorama && !main_activity.isInFullScreenMode()) {
            if( !preview.isVideo() && photo_mode != MyApplicationInterface.PhotoMode.Panorama ) {
                // Only show photo resolutions in photo mode - even if photo snapshots whilst recording video is supported, the
                // resolutions for that won't match what the user has requested for photo mode resolutions.
                // And Panorama mode chooses its own resolution.