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

Commit c143db29 authored by Steve McKay's avatar Steve McKay
Browse files

Correctly format video duration.

Change-Id: I4e138550a15b5afcbe2bf495f045bb9b192573a7
Test: Added new video duration coverage.
Bug: 64298693
parent e76007b8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -59,6 +59,10 @@ public final class Shared {
    public static final String ACTION_PICK_COPY_DESTINATION =
            "com.android.documentsui.PICK_COPY_DESTINATION";

    // These values track values declared in MediaDocumentsProvider.
    public static final String METADATA_KEY_AUDIO = "android.media.metadata.audio";
    public static final String METADATA_KEY_VIDEO = "android.media.metadata.video";

    /**
     * Extra boolean flag for {@link #ACTION_PICK_COPY_DESTINATION}, which
     * specifies if the destination directory needs to create new directory or not.
+7 −10
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.util.AttributeSet;

import com.android.documentsui.R;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.Shared;
import com.android.documentsui.inspector.InspectorController.MediaDisplay;
import com.android.documentsui.inspector.InspectorController.TableDisplay;

@@ -39,9 +40,7 @@ import javax.annotation.Nullable;
 */
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;
    private final Resources mResources;

    public MediaView(Context context) {
        this(context, null);
@@ -65,7 +64,7 @@ public class MediaView extends TableView implements MediaDisplay {
            showExifData(this, mResources, doc, exif, geoClickListener);
        }

        Bundle video = metadata.getBundle(METADATA_KEY_VIDEO);
        Bundle video = metadata.getBundle(Shared.METADATA_KEY_VIDEO);
        if (video != null) {
            showVideoData(this, mResources, doc, video);
        }
@@ -73,17 +72,15 @@ public class MediaView extends TableView implements MediaDisplay {
        setVisible(!isEmpty());
    }

    private static void showVideoData(
            TableDisplay table,
            Resources resources,
            DocumentInfo doc,
            Bundle tags) {
    @VisibleForTesting
    public static void showVideoData(
            TableDisplay table, Resources resources, DocumentInfo doc, Bundle tags) {

        addDimensionsRow(table, resources, tags);

        if (tags.containsKey(MediaMetadata.METADATA_KEY_DURATION)) {
            int millis = tags.getInt(MediaMetadata.METADATA_KEY_DURATION);
            table.put(R.string.metadata_duration, DateUtils.formatElapsedTime(millis));
            table.put(R.string.metadata_duration, DateUtils.formatElapsedTime(millis / 1000));
        }
    }

+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public class TestEnv {
    public static DocumentInfo FILE_JPG;
    public static DocumentInfo FILE_GIF;
    public static DocumentInfo FILE_PDF;
    public static DocumentInfo FILE_MP4;
    public static DocumentInfo FILE_APK;
    public static DocumentInfo FILE_PARTIAL;
    public static DocumentInfo FILE_ARCHIVE;
@@ -152,6 +153,7 @@ public class TestEnv {
        FILE_JPG = model.createFile("jiffy.jpg");
        FILE_GIF = model.createFile("glibby.gif");
        FILE_PDF = model.createFile("busy.pdf");
        FILE_MP4 = model.createFile("cameravideo.mp4");
        FILE_APK = model.createFile("becareful.apk");
        FILE_PARTIAL = model.createFile(
                "UbuntuFlappyBird.iso",
+49 −6
Original line number Diff line number Diff line
@@ -16,12 +16,14 @@
package com.android.documentsui.inspector;

import android.media.ExifInterface;
import android.media.MediaMetadata;
import android.os.Bundle;
import android.provider.DocumentsContract;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

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

@@ -44,6 +46,7 @@ public class MediaViewTest {
        mTable = new TestTable();
        mMetadata = new Bundle();
        TestMetadata.populateExifData(mMetadata);
        TestMetadata.populateVideoData(mMetadata);
    }

    /**
@@ -51,7 +54,7 @@ public class MediaViewTest {
     * bundle.
     */
    @Test
    public void testPrintMetadata_BundleTags() throws Exception {
    public void testShowExifData() throws Exception {
        mResources.strings.put(R.string.metadata_aperture_format, "f/%.1f");
        Bundle exif = mMetadata.getBundle(DocumentsContract.METADATA_EXIF);
        MediaView.showExifData(mTable, mResources, TestEnv.FILE_JPG, exif, null);
@@ -72,13 +75,53 @@ public class MediaViewTest {
     * @throws Exception
     */
    @Test
    public void testPrintMetadata_BundlePartialTags() throws Exception {
        Bundle exif = new Bundle();
        exif.putInt(ExifInterface.TAG_IMAGE_WIDTH, 3840);
        exif.putDouble(ExifInterface.TAG_GPS_LATITUDE, 37.7749);
    public void testShowExifData_PartialGpsTags() throws Exception {
        Bundle data = new Bundle();
        data.putDouble(ExifInterface.TAG_GPS_LATITUDE, 37.7749);

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

    /**
     * Bundle only supplies half of the values for the pairs that print in printMetaData. No put
     * method should be called as the correct conditions have not been met.
     * @throws Exception
     */
    @Test
    public void testShowExifData_PartialDimensionTags() throws Exception {
        Bundle data = new Bundle();
        data.putInt(ExifInterface.TAG_IMAGE_WIDTH, 3840);

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

    /**
     * Test that the updateMetadata method is printing metadata for selected items found in the
     * bundle.
     */
    @Test
    public void testShowVideoData() throws Exception {
        Bundle data = mMetadata.getBundle(Shared.METADATA_KEY_VIDEO);
        MediaView.showVideoData(mTable, mResources, TestEnv.FILE_MP4, data);

        mTable.assertHasRow(R.string.metadata_duration, "01:12");
        mTable.assertHasRow(R.string.metadata_dimensions, "1920 x 1080, 2.1MP");
    }

    /**
     * Test that the updateMetadata method is printing metadata for selected items found in the
     * bundle.
     */
    @Test
    public void testShowVideoData_HourPlusDuration() throws Exception {
        Bundle data = mMetadata.getBundle(Shared.METADATA_KEY_VIDEO);
        data.putInt(MediaMetadata.METADATA_KEY_DURATION, 21660000);
        MediaView.showVideoData(mTable, mResources, TestEnv.FILE_MP4, data);

        mTable.assertHasRow(R.string.metadata_duration, "6:01:00");
    }
}
+28 −14
Original line number Diff line number Diff line
@@ -16,26 +16,40 @@
package com.android.documentsui.inspector;

import android.media.ExifInterface;
import android.media.MediaMetadata;
import android.os.Bundle;
import android.provider.DocumentsContract;

import com.android.documentsui.base.Shared;

final class TestMetadata {
    private TestMetadata() {}

    static void populateExifData(Bundle container) {
        Bundle exif = new Bundle();
        exif.putInt(ExifInterface.TAG_IMAGE_WIDTH, 3840);
        exif.putInt(ExifInterface.TAG_IMAGE_LENGTH, 2160);
        exif.putString(ExifInterface.TAG_DATETIME, "Jan 01, 1970, 12:16 AM");
        exif.putString(ExifInterface.TAG_GPS_LATITUDE, "33/1,59/1,4530/100");
        exif.putString(ExifInterface.TAG_GPS_LONGITUDE, "118/1,28/1,3124/100");
        exif.putString(ExifInterface.TAG_GPS_LATITUDE_REF, "N");
        exif.putString(ExifInterface.TAG_GPS_LONGITUDE_REF, "W");
        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);
        exif.putDouble(ExifInterface.TAG_APERTURE, 2.0);
        container.putBundle(DocumentsContract.METADATA_EXIF, exif);
        Bundle data = new Bundle();
        container.putBundle(DocumentsContract.METADATA_EXIF, data);

        data.putInt(ExifInterface.TAG_IMAGE_WIDTH, 3840);
        data.putInt(ExifInterface.TAG_IMAGE_LENGTH, 2160);
        data.putString(ExifInterface.TAG_DATETIME, "Jan 01, 1970, 12:16 AM");
        data.putString(ExifInterface.TAG_GPS_LATITUDE, "33/1,59/1,4530/100");
        data.putString(ExifInterface.TAG_GPS_LONGITUDE, "118/1,28/1,3124/100");
        data.putString(ExifInterface.TAG_GPS_LATITUDE_REF, "N");
        data.putString(ExifInterface.TAG_GPS_LONGITUDE_REF, "W");
        data.putDouble(ExifInterface.TAG_GPS_ALTITUDE, 1244);
        data.putString(ExifInterface.TAG_MAKE, "Google");
        data.putString(ExifInterface.TAG_MODEL, "Pixel");
        data.putDouble(ExifInterface.TAG_SHUTTER_SPEED_VALUE, 6.643);
        data.putDouble(ExifInterface.TAG_APERTURE, 2.0);
    }

    static void populateVideoData(Bundle container) {
        Bundle data = new Bundle();
        container.putBundle(Shared.METADATA_KEY_VIDEO, data);

        // By convention we reuse exif tags for dimensions.
        data.putInt(ExifInterface.TAG_IMAGE_WIDTH, 1920);
        data.putInt(ExifInterface.TAG_IMAGE_LENGTH, 1080);
        data.putInt(MediaMetadata.METADATA_KEY_DURATION, 72000);
    }
}
Loading