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

Commit c0bac3aa authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Merge branch '1729-master-resolution' into 'master'

camera: change resolution for existing users aswell

See merge request !64
parents ce90653e 9870264e
Loading
Loading
Loading
Loading
Loading
+37 −16
Original line number Diff line number Diff line
@@ -1006,22 +1006,7 @@ public class MainActivity extends AppCompatActivity {
            }
        }

        String[] defaultResolutions = getResources().getStringArray(
                R.array.config_e_os_camera_default_resolution_lens);
        SharedPreferences.Editor editor = sharedPreferences.edit();

        for (String entry : defaultResolutions) {
            if (!entry.matches("\\d+:\\d+x\\d+")) continue;

            String[] mainParts = entry.split(":");
            String[] resParts = mainParts[1].split("x");
            int cameraId = Integer.parseInt(mainParts[0]);
            String resolution = resParts[0] + " " + resParts[1];

            editor.putString(PreferenceKeys.getResolutionPreferenceKey(cameraId), resolution);
        }

        editor.apply();
        updateCameraResolution();
    }

    /** Switches modes if required, if called from a relevant intent/tile.
@@ -3052,6 +3037,10 @@ public class MainActivity extends AppCompatActivity {
        if( preview.getCurrentPictureSize() != null ) {
            bundle.putInt("resolution_width", preview.getCurrentPictureSize().width);
            bundle.putInt("resolution_height", preview.getCurrentPictureSize().height);
            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
            if (pref.getBoolean("isFirstTimeResolution_" + preview.getCameraId(), true)) {
                updateCameraResolution();
            }
        }

        //List<String> video_quality = this.preview.getVideoQualityHander().getSupportedVideoQuality();
@@ -3163,6 +3152,38 @@ public class MainActivity extends AppCompatActivity {
        getFragmentManager().beginTransaction().add(android.R.id.content, fragment, "PREFERENCE_FRAGMENT").addToBackStack(null).commitAllowingStateLoss();
    }

    private void updateCameraResolution() {
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = pref.edit();
        String[] defaultResolutions = getResources().getStringArray(
                R.array.config_e_os_camera_default_resolution_lens);
        for (String entry : defaultResolutions) {
            if (!entry.matches("\\d+:\\d+x\\d+")) continue;

            String[] mainParts = entry.split(":");
            String[] resParts = mainParts[1].split("x");
            int cameraId = Integer.parseInt(mainParts[0]);
            String resolution = resParts[0] + " " + resParts[1];

            boolean existing = true;
            if (preview != null && preview.getSupportedPictureSizes(false) != null) {
                List<CameraController.Size> supportedResolutions =
                        preview.getSupportedPictureSizes(false);
                String highestResolution = supportedResolutions.get(0).width + " "
                        + supportedResolutions.get(0).height;
                String currentResolution = pref.getString(
                        PreferenceKeys.getResolutionPreferenceKey(cameraId), "");
                existing = highestResolution.equals(currentResolution) && cameraId == preview.getCameraId();
            }
            if (existing) {
                editor.putString(PreferenceKeys.getResolutionPreferenceKey(cameraId), resolution);
                editor.putBoolean("isFirstTimeResolution_" + cameraId, false);
            }
        }

        editor.apply();
    }

    public void updateForSettings(boolean update_camera) {
        updateForSettings(update_camera, null);
    }