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

Commit 37ce5953 authored by Julian Mancini's avatar Julian Mancini
Browse files

Format shutter speed correctly

Previously, ExifInterface would return a value, n, while the actual
format for shutter speed is 1/(2^n). This change adds a helper method
that formats shutter speed before displaying it to the user.

Bug: 64083610
Test: In place
Change-Id: I4980099c54eb342a4d5fb8fd1cb8bc371aba013c
parent ce28927a
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -132,8 +132,29 @@ public class MediaView extends TableView implements MediaDisplay {
        }

        if (tags.containsKey(ExifInterface.TAG_SHUTTER_SPEED_VALUE)) {
            String shutterSpeed = String.valueOf(tags.get(ExifInterface.TAG_SHUTTER_SPEED_VALUE));
            String shutterSpeed = String.valueOf(
                    formatShutterSpeed(tags.getDouble(ExifInterface.TAG_SHUTTER_SPEED_VALUE)));
            table.put(R.string.metadata_shutter_speed, shutterSpeed);
        }
    }

    /**
     *
     * @param speed a value n, where shutter speed equals 1/(2^n)
     * @return a String containing either a fraction that displays 1 over a positive integer, or a
     * double rounded to one decimal, depending on if 1/(2^n) is less than or greater than 1,
     * respectively.
     */
    private static String formatShutterSpeed(double speed) {
        if (speed <= 0) {
            double shutterSpeed = Math.pow(2, -1 * speed);
            String formattedSpeed = String.valueOf(Math.round(shutterSpeed * 10.0) / 10.0);
            return formattedSpeed;
        } else {
            int approximateSpeedDenom = (int) Math.pow(2, speed) + 1;
            String formattedSpeed = "1/" + String.valueOf(approximateSpeedDenom);
            return formattedSpeed;
        }
    }

}
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ public class MediaViewTest {
        mTable.assertHasRow(R.string.metadata_altitude, "1244.0");
        mTable.assertHasRow(R.string.metadata_make, "Google");
        mTable.assertHasRow(R.string.metadata_model, "Pixel");
        mTable.assertHasRow(R.string.metadata_shutter_speed, "1/100");
    }

    /**
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ final class TestMetadata {
        exif.putDouble(ExifInterface.TAG_GPS_ALTITUDE, 1244);
        exif.putString(ExifInterface.TAG_MAKE, "Google");
        exif.putString(ExifInterface.TAG_MODEL, "Pixel");
        exif.putDouble(ExifInterface.TAG_SHUTTER_SPEED_VALUE, 6.643);
        container.putBundle(DocumentsContract.METADATA_EXIF, exif);
    }
}