OSDN Git Service

Merge "Import translations. DO NOT MERGE"
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / info / InfoPanel.java
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.Fragment;
24 import android.text.Html;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.ImageButton;
29 import android.widget.ImageView;
30 import android.widget.LinearLayout;
31 import android.widget.TextView;
32 import com.android.gallery3d.R;
33 import com.android.gallery3d.exif.ExifInterface;
34 import com.android.gallery3d.exif.ExifTag;
35 import com.android.gallery3d.filtershow.FilterShowActivity;
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 Fragment {
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     private ImageButton mHideButton;
50
51     private String createStringFromIfFound(ExifTag exifTag, int tag, int str) {
52         String exifString = "";
53         short tagId = exifTag.getTagId();
54         if (tagId == ExifInterface.getTrueTagKey(tag)) {
55             String label = getActivity().getString(str);
56             exifString += "<b>" + label + ": </b>";
57             exifString += exifTag.forceGetValueAsString();
58             exifString += "<br>";
59         }
60         return exifString;
61     }
62
63     @Override
64     public View onCreateView(LayoutInflater inflater, ViewGroup container,
65                              Bundle savedInstanceState) {
66
67         mMainView = (LinearLayout) inflater.inflate(
68                 R.layout.filtershow_info_panel, null, false);
69
70         mImageThumbnail = (ImageView) mMainView.findViewById(R.id.imageThumbnail);
71         Bitmap bitmap = MasterImage.getImage().getFilteredImage();
72         mImageThumbnail.setImageBitmap(bitmap);
73
74         mImageName = (TextView) mMainView.findViewById(R.id.imageName);
75         mImageSize = (TextView) mMainView.findViewById(R.id.imageSize);
76         mExifData = (TextView) mMainView.findViewById(R.id.exifData);
77         mHideButton =(ImageButton) mMainView.findViewById(R.id.cancelInfo);
78
79         HistogramView histogramView = (HistogramView) mMainView.findViewById(R.id.histogramView);
80
81         histogramView.setBitmap(bitmap);
82
83         mHideButton.setOnClickListener(new View.OnClickListener() {
84             @Override
85             public void onClick(View view) {
86                 FilterShowActivity activity = (FilterShowActivity)getActivity();
87                 activity.toggleInformationPanel();
88             }
89         });
90         Uri uri = MasterImage.getImage().getUri();
91         String path = ImageLoader.getLocalPathFromUri(getActivity(), uri);
92         Uri localUri = null;
93         if (path != null) {
94             localUri = Uri.parse(path);
95         }
96
97         if (localUri != null) {
98             mImageName.setText(localUri.getLastPathSegment());
99         }
100         Rect originalBounds = MasterImage.getImage().getOriginalBounds();
101         mImageSize.setText("" + originalBounds.width() + " x " + originalBounds.height());
102
103         List<ExifTag> exif = MasterImage.getImage().getEXIF();
104         String exifString = "";
105         if (exif != null) {
106             for (ExifTag tag : exif) {
107                 exifString += createStringFromIfFound(tag,
108                         ExifInterface.TAG_MODEL,
109                         R.string.filtershow_exif_model);
110                 exifString += createStringFromIfFound(tag,
111                         ExifInterface.TAG_APERTURE_VALUE,
112                         R.string.filtershow_exif_aperture);
113                 exifString += createStringFromIfFound(tag,
114                         ExifInterface.TAG_FOCAL_LENGTH,
115                         R.string.filtershow_exif_focal_length);
116                 exifString += createStringFromIfFound(tag,
117                         ExifInterface.TAG_ISO_SPEED_RATINGS,
118                         R.string.filtershow_exif_iso);
119                 exifString += createStringFromIfFound(tag,
120                         ExifInterface.TAG_SUBJECT_DISTANCE,
121                         R.string.filtershow_exif_subject_distance);
122                 exifString += createStringFromIfFound(tag,
123                         ExifInterface.TAG_DATE_TIME_ORIGINAL,
124                         R.string.filtershow_exif_date);
125                 exifString += createStringFromIfFound(tag,
126                         ExifInterface.TAG_F_NUMBER,
127                         R.string.filtershow_exif_f_stop);
128                 exifString += createStringFromIfFound(tag,
129                         ExifInterface.TAG_EXPOSURE_TIME,
130                         R.string.filtershow_exif_exposure_time);
131                 exifString += createStringFromIfFound(tag,
132                         ExifInterface.TAG_COPYRIGHT,
133                         R.string.filtershow_exif_copyright);
134             }
135         }
136         mExifData.setText(Html.fromHtml(exifString));
137         return mMainView;
138     }
139 }