1 /* 2 * Copyright (C) 2010 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 package com.android.gallery3d.ui; 17 18 import android.content.Context; 19 import android.view.View.MeasureSpec; 20 21 import com.android.gallery3d.R; 22 import com.android.gallery3d.app.AbstractGalleryActivity; 23 import com.android.gallery3d.data.MediaDetails; 24 import com.android.gallery3d.ui.DetailsAddressResolver.AddressResolvingListener; 25 26 public class DetailsHelper { 27 private static DetailsAddressResolver sAddressResolver; 28 private DetailsViewContainer mContainer; 29 30 public interface DetailsSource { size()31 public int size(); setIndex()32 public int setIndex(); getDetails()33 public MediaDetails getDetails(); 34 } 35 36 public interface CloseListener { onClose()37 public void onClose(); 38 } 39 40 public interface DetailsViewContainer { reloadDetails()41 public void reloadDetails(); setCloseListener(CloseListener listener)42 public void setCloseListener(CloseListener listener); show()43 public void show(); hide()44 public void hide(); 45 } 46 DetailsHelper(AbstractGalleryActivity activity, GLView rootPane, DetailsSource source)47 public DetailsHelper(AbstractGalleryActivity activity, GLView rootPane, DetailsSource source) { 48 mContainer = new DialogDetailsView(activity, source); 49 } 50 layout(int left, int top, int right, int bottom)51 public void layout(int left, int top, int right, int bottom) { 52 if (mContainer instanceof GLView) { 53 GLView view = (GLView) mContainer; 54 view.measure(MeasureSpec.UNSPECIFIED, 55 MeasureSpec.makeMeasureSpec(bottom - top, MeasureSpec.AT_MOST)); 56 view.layout(0, top, view.getMeasuredWidth(), top + view.getMeasuredHeight()); 57 } 58 } 59 reloadDetails()60 public void reloadDetails() { 61 mContainer.reloadDetails(); 62 } 63 setCloseListener(CloseListener listener)64 public void setCloseListener(CloseListener listener) { 65 mContainer.setCloseListener(listener); 66 } 67 resolveAddress(AbstractGalleryActivity activity, double[] latlng, AddressResolvingListener listener)68 public static String resolveAddress(AbstractGalleryActivity activity, double[] latlng, 69 AddressResolvingListener listener) { 70 if (sAddressResolver == null) { 71 sAddressResolver = new DetailsAddressResolver(activity); 72 } else { 73 sAddressResolver.cancel(); 74 } 75 return sAddressResolver.resolveAddress(latlng, listener); 76 } 77 pause()78 public static void pause() { 79 if (sAddressResolver != null) sAddressResolver.cancel(); 80 } 81 show()82 public void show() { 83 mContainer.show(); 84 } 85 hide()86 public void hide() { 87 mContainer.hide(); 88 } 89 getDetailsName(Context context, int key)90 public static String getDetailsName(Context context, int key) { 91 switch (key) { 92 case MediaDetails.INDEX_TITLE: 93 return context.getString(R.string.title); 94 case MediaDetails.INDEX_DESCRIPTION: 95 return context.getString(R.string.description); 96 case MediaDetails.INDEX_DATETIME: 97 return context.getString(R.string.time); 98 case MediaDetails.INDEX_LOCATION: 99 return context.getString(R.string.location); 100 case MediaDetails.INDEX_PATH: 101 return context.getString(R.string.path); 102 case MediaDetails.INDEX_WIDTH: 103 return context.getString(R.string.width); 104 case MediaDetails.INDEX_HEIGHT: 105 return context.getString(R.string.height); 106 case MediaDetails.INDEX_ORIENTATION: 107 return context.getString(R.string.orientation); 108 case MediaDetails.INDEX_DURATION: 109 return context.getString(R.string.duration); 110 case MediaDetails.INDEX_MIMETYPE: 111 return context.getString(R.string.mimetype); 112 case MediaDetails.INDEX_SIZE: 113 return context.getString(R.string.file_size); 114 case MediaDetails.INDEX_MAKE: 115 return context.getString(R.string.maker); 116 case MediaDetails.INDEX_MODEL: 117 return context.getString(R.string.model); 118 case MediaDetails.INDEX_FLASH: 119 return context.getString(R.string.flash); 120 case MediaDetails.INDEX_APERTURE: 121 return context.getString(R.string.aperture); 122 case MediaDetails.INDEX_FOCAL_LENGTH: 123 return context.getString(R.string.focal_length); 124 case MediaDetails.INDEX_WHITE_BALANCE: 125 return context.getString(R.string.white_balance); 126 case MediaDetails.INDEX_EXPOSURE_TIME: 127 return context.getString(R.string.exposure_time); 128 case MediaDetails.INDEX_ISO: 129 return context.getString(R.string.iso); 130 default: 131 return "Unknown key" + key; 132 } 133 } 134 } 135 136 137