Home | History | Annotate | Download | only in data
      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 
     21 /**
     22  * A helper class to load the metadata of
     23  * {@link com.android.camera.data.LocalData}.
     24  */
     25 public class MetadataLoader {
     26 
     27     private static final String KEY_METADATA_CACHED = "metadata_cached";
     28 
     29     /**
     30      * Adds information to the data's metadata bundle if any is available and returns
     31      * true if metadata was added and false otherwise. In either case, sets
     32      * a flag indicating that we've cached any available metadata and don't need to
     33      * load metadata again for this particular item.
     34      *
     35      * @param context A context.
     36      * @param data The data to update metadata for.
     37      * @return true if any metadata was added to the data, false otherwise.
     38      */
     39     public static boolean loadMetadata(final Context context, final LocalData data) {
     40         boolean metadataAdded = false;
     41         if (data.getLocalDataType() == LocalData.LOCAL_IMAGE) {
     42             PanoramaMetadataLoader.loadPanoramaMetadata(context, data.getUri(),
     43                     data.getMetadata());
     44             RgbzMetadataLoader.loadRgbzMetadata(context, data.getUri(), data.getMetadata());
     45             metadataAdded = true;
     46         } else if (data.getLocalDataType() == LocalData.LOCAL_VIDEO) {
     47             VideoRotationMetadataLoader.loadRotationMetdata(data);
     48             metadataAdded = true;
     49         }
     50         data.getMetadata().putBoolean(MetadataLoader.KEY_METADATA_CACHED, true);
     51         return metadataAdded;
     52     }
     53 
     54     static boolean isMetadataCached(final LocalData data) {
     55         return data.getMetadata().getBoolean(MetadataLoader.KEY_METADATA_CACHED);
     56     }
     57 }
     58