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.gallery3d.filtershow.info;
18 
19 import android.graphics.Bitmap;
20 import android.graphics.Rect;
21 import android.net.Uri;
22 import android.os.Bundle;
23 import android.support.v4.app.DialogFragment;
24 import android.text.Html;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.view.Window;
29 import android.widget.ImageButton;
30 import android.widget.ImageView;
31 import android.widget.LinearLayout;
32 import android.widget.TextView;
33 import com.android.gallery3d.R;
34 import com.android.gallery3d.exif.ExifInterface;
35 import com.android.gallery3d.exif.ExifTag;
36 import com.android.gallery3d.filtershow.cache.ImageLoader;
37 import com.android.gallery3d.filtershow.imageshow.MasterImage;
38 
39 import java.util.List;
40 
41 public class InfoPanel extends DialogFragment {
42     public static final String FRAGMENT_TAG = "InfoPanel";
43     private static final String LOGTAG = FRAGMENT_TAG;
44     private LinearLayout mMainView;
45     private ImageView mImageThumbnail;
46     private TextView mImageName;
47     private TextView mImageSize;
48     private TextView mExifData;
49 
createStringFromIfFound(ExifTag exifTag, int tag, int str)50     private String createStringFromIfFound(ExifTag exifTag, int tag, int str) {
51         String exifString = "";
52         short tagId = exifTag.getTagId();
53         if (tagId == ExifInterface.getTrueTagKey(tag)) {
54             String label = getActivity().getString(str);
55             exifString += "<b>" + label + ": </b>";
56             exifString += exifTag.forceGetValueAsString();
57             exifString += "<br>";
58         }
59         return exifString;
60     }
61 
62     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)63     public View onCreateView(LayoutInflater inflater, ViewGroup container,
64                              Bundle savedInstanceState) {
65         if (getDialog() != null) {
66             getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
67         }
68 
69         mMainView = (LinearLayout) inflater.inflate(
70                 R.layout.filtershow_info_panel, null, false);
71 
72         mImageThumbnail = (ImageView) mMainView.findViewById(R.id.imageThumbnail);
73         Bitmap bitmap = MasterImage.getImage().getFilteredImage();
74         mImageThumbnail.setImageBitmap(bitmap);
75 
76         mImageName = (TextView) mMainView.findViewById(R.id.imageName);
77         mImageSize = (TextView) mMainView.findViewById(R.id.imageSize);
78         mExifData = (TextView) mMainView.findViewById(R.id.exifData);
79         TextView exifLabel = (TextView) mMainView.findViewById(R.id.exifLabel);
80 
81         HistogramView histogramView = (HistogramView) mMainView.findViewById(R.id.histogramView);
82         histogramView.setBitmap(bitmap);
83 
84         Uri uri = MasterImage.getImage().getUri();
85         String path = ImageLoader.getLocalPathFromUri(getActivity(), uri);
86         Uri localUri = null;
87         if (path != null) {
88             localUri = Uri.parse(path);
89         }
90 
91         if (localUri != null) {
92             mImageName.setText(localUri.getLastPathSegment());
93         }
94         Rect originalBounds = MasterImage.getImage().getOriginalBounds();
95         mImageSize.setText("" + originalBounds.width() + " x " + originalBounds.height());
96 
97         List<ExifTag> exif = MasterImage.getImage().getEXIF();
98         String exifString = "";
99         boolean hasExifData = false;
100         if (exif != null) {
101             for (ExifTag tag : exif) {
102                 exifString += createStringFromIfFound(tag,
103                         ExifInterface.TAG_MODEL,
104                         R.string.filtershow_exif_model);
105                 exifString += createStringFromIfFound(tag,
106                         ExifInterface.TAG_APERTURE_VALUE,
107                         R.string.filtershow_exif_aperture);
108                 exifString += createStringFromIfFound(tag,
109                         ExifInterface.TAG_FOCAL_LENGTH,
110                         R.string.filtershow_exif_focal_length);
111                 exifString += createStringFromIfFound(tag,
112                         ExifInterface.TAG_ISO_SPEED_RATINGS,
113                         R.string.filtershow_exif_iso);
114                 exifString += createStringFromIfFound(tag,
115                         ExifInterface.TAG_SUBJECT_DISTANCE,
116                         R.string.filtershow_exif_subject_distance);
117                 exifString += createStringFromIfFound(tag,
118                         ExifInterface.TAG_DATE_TIME_ORIGINAL,
119                         R.string.filtershow_exif_date);
120                 exifString += createStringFromIfFound(tag,
121                         ExifInterface.TAG_F_NUMBER,
122                         R.string.filtershow_exif_f_stop);
123                 exifString += createStringFromIfFound(tag,
124                         ExifInterface.TAG_EXPOSURE_TIME,
125                         R.string.filtershow_exif_exposure_time);
126                 exifString += createStringFromIfFound(tag,
127                         ExifInterface.TAG_COPYRIGHT,
128                         R.string.filtershow_exif_copyright);
129                 hasExifData = true;
130             }
131         }
132         if (hasExifData) {
133             exifLabel.setVisibility(View.VISIBLE);
134             mExifData.setText(Html.fromHtml(exifString));
135         } else {
136             exifLabel.setVisibility(View.GONE);
137         }
138         return mMainView;
139     }
140 }
141