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

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

Merge "Include megapixel rating along w/ dimension."

parents 31b3b356 8f6c7bf8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:paddingEnd="5dp"
        android:textColor="@android:color/black"
        android:textSize="14sp"
        android:textAlignment="viewStart">
+4 −0
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@

    <!--The height and width of a photo. Note that this is probably camera EXIF data.-->
    <string name="metadata_dimensions">Dimensions</string>
    <!--The message that displays the width and height of a photo followed by a the
     "megapixel rating" this corresponds to. Cameras are frequently rated by "megapixels".
     In U.S. English this is denoted by a number followed by "MP". E.g. 12.2MP or 8MP. -->
    <string name="metadata_dimensions_display"><xliff:g id="width" example="1280">%1$d</xliff:g> x <xliff:g id="height" example="1024">%2$d</xliff:g> - <xliff:g id="megapixels" example="12.2">%3$,.1f</xliff:g>MP</string>
    <!--The location of where a photo was taken. (i.e. latitude, longitude) Note that this is probably camera EXIF data.-->
    <string name="metadata_location">Location</string>
    <!--The elevation the photo was taken. Note that this is probably camera EXIF data.-->
+8 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.documentsui.inspector;

import android.content.Context;
import android.content.res.Resources;
import android.media.ExifInterface;
import android.media.MediaMetadata;
import android.os.Bundle;
@@ -40,6 +41,7 @@ public class MediaView extends TableView implements MediaDisplay {

    private static final String METADATA_KEY_AUDIO = "android.media.metadata.audio";
    private static final String METADATA_KEY_VIDEO = "android.media.metadata.video";
    private Resources mResources;

    public MediaView(Context context) {
        this(context, null);
@@ -51,6 +53,7 @@ public class MediaView extends TableView implements MediaDisplay {

    public MediaView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mResources = context.getResources();
    }

    @Override
@@ -59,7 +62,7 @@ public class MediaView extends TableView implements MediaDisplay {

        Bundle exif = metadata.getBundle(DocumentsContract.METADATA_EXIF);
        if (exif != null) {
            showExifData(this, doc, exif, geoClickListener);
            showExifData(this, mResources, doc, exif, geoClickListener);
        }

        Bundle video = metadata.getBundle(METADATA_KEY_VIDEO);
@@ -80,6 +83,7 @@ public class MediaView extends TableView implements MediaDisplay {
    @VisibleForTesting
    public static void showExifData(
            TableDisplay table,
            Resources resources,
            DocumentInfo doc,
            Bundle tags,
            @Nullable Runnable geoClickListener) {
@@ -88,8 +92,10 @@ public class MediaView extends TableView implements MediaDisplay {
            && tags.containsKey(ExifInterface.TAG_IMAGE_LENGTH)) {
            int width = tags.getInt(ExifInterface.TAG_IMAGE_WIDTH);
            int height = tags.getInt(ExifInterface.TAG_IMAGE_LENGTH);
            float megaPixels = height * width / 1000000f;
            table.put(R.string.metadata_dimensions,
                    String.valueOf(width) + " x " + String.valueOf(height));
                    resources.getString(
                            R.string.metadata_dimensions_display, width, height, megaPixels));
        }

        if (tags.containsKey(ExifInterface.TAG_DATETIME)) {
+4 −1
Original line number Diff line number Diff line
@@ -85,10 +85,12 @@ public abstract class TestResources extends Resources {
        return strings.get(id);
    }

    @Override
    @NonNull
    public final String getString(
            @StringRes int id, Object... formatArgs) throws NotFoundException {
        return getString(id);
        final String raw = getString(id);
        return String.format(raw, formatArgs);
    }

    @Override
@@ -106,6 +108,7 @@ public abstract class TestResources extends Resources {
        return null;
    }

    @Override
    public final CharSequence getText(@StringRes int resId) {
        return getString(resId);
    }
+7 −4
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@ import android.test.suitebuilder.annotation.SmallTest;

import com.android.documentsui.R;
import com.android.documentsui.testing.TestEnv;
import com.android.documentsui.testing.TestResources;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,11 +33,14 @@ import org.junit.runner.RunWith;
@SmallTest
public class MediaViewTest {

    private TestResources mResources;
    private TestTable mTable;
    private Bundle mMetadata;

    @Before
    public void setUp() {
        mResources = TestResources.create();
        mResources.strings.put(R.string.metadata_dimensions_display, "%d x %d, %.1fMP");
        mTable = new TestTable();
        mMetadata = new Bundle();
        TestMetadata.populateExifData(mMetadata);
@@ -50,9 +53,9 @@ public class MediaViewTest {
    @Test
    public void testPrintMetadata_BundleTags() throws Exception {
        Bundle exif = mMetadata.getBundle(DocumentsContract.METADATA_EXIF);
        MediaView.showExifData(mTable, TestEnv.FILE_JPG, exif, null);
        MediaView.showExifData(mTable, mResources, TestEnv.FILE_JPG, exif, null);

        mTable.assertHasRow(R.string.metadata_dimensions, "3840 x 2160");
        mTable.assertHasRow(R.string.metadata_dimensions, "3840 x 2160, 8.3MP");
        mTable.assertHasRow(R.string.metadata_date_time, "Jan 01, 1970, 12:16 AM");
        mTable.assertHasRow(R.string.metadata_location, "33.995918,  -118.475342");
        mTable.assertHasRow(R.string.metadata_altitude, "1244.0");
@@ -73,7 +76,7 @@ public class MediaViewTest {
        exif.putDouble(ExifInterface.TAG_GPS_LATITUDE, 37.7749);

        mMetadata.putBundle(DocumentsContract.METADATA_EXIF, exif);
        MediaView.showExifData(mTable, TestEnv.FILE_JPG, mMetadata, null);
        MediaView.showExifData(mTable, mResources, TestEnv.FILE_JPG, mMetadata, null);
        mTable.assertEmpty();
    }
}
Loading