1f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling/*
2f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * Copyright (C) 2013 The Android Open Source Project
3f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling *
4f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * Licensed under the Apache License, Version 2.0 (the "License");
5f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * you may not use this file except in compliance with the License.
6f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * You may obtain a copy of the License at
7f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling *
8f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling *      http://www.apache.org/licenses/LICENSE-2.0
9f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling *
10f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * Unless required by applicable law or agreed to in writing, software
11f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * distributed under the License is distributed on an "AS IS" BASIS,
12f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * See the License for the specific language governing permissions and
14f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * limitations under the License.
15f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling */
16f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling
17f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberlingpackage com.android.camera.data;
18f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling
19f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberlingimport android.content.Context;
20f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberlingimport android.net.Uri;
218a2350a3d557465b53445685db0f9ac838cf90c5Angus Kongimport android.os.Bundle;
22f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling
238e963a5a6016d246184ed65906f9d103e92b17e2Sascha Haeberlingimport com.android.camera.util.PhotoSphereHelper;
24f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling
25f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling/**
26f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling * This class breaks out the off-thread panorama support.
27f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling */
28f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberlingpublic class PanoramaMetadataLoader {
29f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling    /**
308a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong     * The key for the metadata in {@link com.android.camera.data.LocalData} to
318a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong     * indicate whether the data is a 360-degrees panorama.
32f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling     */
338a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong    private static final String KEY_PANORAMA_360 = "metadata_key_panorama_360";
347190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling
358a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong    /**
368a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong     * The key for the metadata in {@link com.android.camera.data.LocalData} to
377190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     * indicate whether the data is a panorama and the panorama viewer should be
387190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     * used to consume it.
398a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong     */
408a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong    private static final String KEY_USE_PANORAMA_VIEWER = "metadata_key_panorama_viewer";
41f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling
42f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling    /**
437190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     * The key for the metadata in {@link com.android.camera.data.LocalData} to
447190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     * indicate whether the data is a panorama with it's metadata.
457190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     */
467190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling    private static final String KEY_IS_PANORAMA = "metadata_key_is_panorama";
477190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling
487190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling    /**
498a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong     * @return whether the {@code data} is a panorama.
50f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling     */
518a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong    public static boolean isPanorama(final LocalData data) {
527190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling        return data.getMetadata().getBoolean(KEY_IS_PANORAMA);
537190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling    }
547190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling
557190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling    /**
567190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     * @return whether the {@code data} is a panorama and the panorama viewer
577190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     *         should be used to consume it.
587190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     */
597190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling    public static boolean isPanoramaAndUseViewer(final LocalData data) {
608a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong        return data.getMetadata().getBoolean(KEY_USE_PANORAMA_VIEWER);
61f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling    }
62f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling
63f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling    /**
648a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong     * @return whether the {@code data} is a 360-degrees panorama.
65f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling     */
668a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong    public static boolean isPanorama360(final LocalData data) {
678a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong        return data.getMetadata().getBoolean(KEY_PANORAMA_360);
68f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling    }
69f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling
70f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling    /**
717190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     * Extracts panorama metadata from the item with the given URI and fills the
727190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling     * {@code metadata}.
73f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling     */
748a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong    public static void loadPanoramaMetadata(final Context context, Uri contentUri,
758a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong            Bundle metadata) {
768a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong        PhotoSphereHelper.PanoramaMetadata panoramaMetadata =
778a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong                PhotoSphereHelper.getPanoramaMetadata(context, contentUri);
788a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong        if (panoramaMetadata == null) {
798a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong            return;
80f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling        }
817190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling
827190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling        // Note: The use of '!=' here is in purpose as this is a singleton that
837190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling        // is returned if this is not a panorama, so pointer comparison works.
847190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling        boolean hasMetadata = panoramaMetadata != PhotoSphereHelper.NOT_PANORAMA;
857190c6a9018e95ff0c49642442c7a069e16a6a7aSascha Haeberling        metadata.putBoolean(KEY_IS_PANORAMA, hasMetadata);
868a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong        metadata.putBoolean(KEY_PANORAMA_360, panoramaMetadata.mIsPanorama360);
878a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong        metadata.putBoolean(KEY_USE_PANORAMA_VIEWER,
888a2350a3d557465b53445685db0f9ac838cf90c5Angus Kong                panoramaMetadata.mUsePanoramaViewer);
89f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling    }
90f1f5186f7d3fd8bf35009d9e65a43914c664d82bSascha Haeberling}
91