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

Commit ca78cbf0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Format shutter speed correctly"

parents 5e0e7c7a 37ce5953
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -133,8 +133,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);
    }
}