OSDN Git Service

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