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