1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.camera.data;
18 
19 import android.content.Context;
20 import android.net.Uri;
21 import android.os.Bundle;
22 
23 import com.android.camera.util.PhotoSphereHelper;
24 
25 /**
26  * This class breaks out the off-thread panorama support.
27  */
28 public class PanoramaMetadataLoader {
29     /**
30      * The key for the metadata in {@link com.android.camera.data.LocalData} to
31      * indicate whether the data is a 360-degrees panorama.
32      */
33     private static final String KEY_PANORAMA_360 = "metadata_key_panorama_360";
34 
35     /**
36      * The key for the metadata in {@link com.android.camera.data.LocalData} to
37      * indicate whether the data is a panorama and the panorama viewer should be
38      * used to consume it.
39      */
40     private static final String KEY_USE_PANORAMA_VIEWER = "metadata_key_panorama_viewer";
41 
42     /**
43      * The key for the metadata in {@link com.android.camera.data.LocalData} to
44      * indicate whether the data is a panorama with it's metadata.
45      */
46     private static final String KEY_IS_PANORAMA = "metadata_key_is_panorama";
47 
48     /**
49      * @return whether the {@code data} is a panorama.
50      */
isPanorama(final LocalData data)51     public static boolean isPanorama(final LocalData data) {
52         return data.getMetadata().getBoolean(KEY_IS_PANORAMA);
53     }
54 
55     /**
56      * @return whether the {@code data} is a panorama and the panorama viewer
57      *         should be used to consume it.
58      */
isPanoramaAndUseViewer(final LocalData data)59     public static boolean isPanoramaAndUseViewer(final LocalData data) {
60         return data.getMetadata().getBoolean(KEY_USE_PANORAMA_VIEWER);
61     }
62 
63     /**
64      * @return whether the {@code data} is a 360-degrees panorama.
65      */
isPanorama360(final LocalData data)66     public static boolean isPanorama360(final LocalData data) {
67         return data.getMetadata().getBoolean(KEY_PANORAMA_360);
68     }
69 
70     /**
71      * Extracts panorama metadata from the item with the given URI and fills the
72      * {@code metadata}.
73      */
loadPanoramaMetadata(final Context context, Uri contentUri, Bundle metadata)74     public static void loadPanoramaMetadata(final Context context, Uri contentUri,
75             Bundle metadata) {
76         PhotoSphereHelper.PanoramaMetadata panoramaMetadata =
77                 PhotoSphereHelper.getPanoramaMetadata(context, contentUri);
78         if (panoramaMetadata == null) {
79             return;
80         }
81 
82         // Note: The use of '!=' here is in purpose as this is a singleton that
83         // is returned if this is not a panorama, so pointer comparison works.
84         boolean hasMetadata = panoramaMetadata != PhotoSphereHelper.NOT_PANORAMA;
85         metadata.putBoolean(KEY_IS_PANORAMA, hasMetadata);
86         metadata.putBoolean(KEY_PANORAMA_360, panoramaMetadata.mIsPanorama360);
87         metadata.putBoolean(KEY_USE_PANORAMA_VIEWER,
88                 panoramaMetadata.mUsePanoramaViewer);
89     }
90 }
91