summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/info
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-08-08 20:47:28 -0700
committernicolasroard <nicolasroard@google.com>2013-08-08 21:22:31 -0700
commit860af325f2030a03c526e8551a85230d17df7b15 (patch)
treed8dca2a774d52055ea3d65a0b71fcc74dd9422c3 /src/com/android/gallery3d/filtershow/info
parent430e46b06f8e7ee1ca3e7ecdcef3e0a978637c03 (diff)
downloadandroid_packages_apps_Gallery2-860af325f2030a03c526e8551a85230d17df7b15.tar.gz
android_packages_apps_Gallery2-860af325f2030a03c526e8551a85230d17df7b15.tar.bz2
android_packages_apps_Gallery2-860af325f2030a03c526e8551a85230d17df7b15.zip
Add version category
Fix bugs when loading Add info panel Change-Id: I28966f2419b902405bc60e9cc927b109777a6a2d
Diffstat (limited to 'src/com/android/gallery3d/filtershow/info')
-rw-r--r--src/com/android/gallery3d/filtershow/info/HistogramView.java143
-rw-r--r--src/com/android/gallery3d/filtershow/info/InfoPanel.java128
2 files changed, 271 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/filtershow/info/HistogramView.java b/src/com/android/gallery3d/filtershow/info/HistogramView.java
new file mode 100644
index 000000000..6d820ec39
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/info/HistogramView.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.gallery3d.filtershow.info;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
+import android.os.AsyncTask;
+import android.util.AttributeSet;
+import android.view.View;
+import com.android.gallery3d.filtershow.imageshow.Spline;
+
+public class HistogramView extends View {
+
+ private Bitmap mBitmap;
+ int[] redHistogram = new int[256];
+ int[] greenHistogram = new int[256];
+ int[] blueHistogram = new int[256];
+ Path gHistoPath = new Path();
+
+ class ComputeHistogramTask extends AsyncTask<Bitmap, Void, int[]> {
+ @Override
+ protected int[] doInBackground(Bitmap... params) {
+ int[] histo = new int[256 * 3];
+ Bitmap bitmap = params[0];
+ int w = bitmap.getWidth();
+ int h = bitmap.getHeight();
+ int[] pixels = new int[w * h];
+ bitmap.getPixels(pixels, 0, w, 0, 0, w, h);
+ for (int i = 0; i < w; i++) {
+ for (int j = 0; j < h; j++) {
+ int index = j * w + i;
+ int r = Color.red(pixels[index]);
+ int g = Color.green(pixels[index]);
+ int b = Color.blue(pixels[index]);
+ histo[r]++;
+ histo[256 + g]++;
+ histo[512 + b]++;
+ }
+ }
+ return histo;
+ }
+
+ @Override
+ protected void onPostExecute(int[] result) {
+ System.arraycopy(result, 0, redHistogram, 0, 256);
+ System.arraycopy(result, 256, greenHistogram, 0, 256);
+ System.arraycopy(result, 512, blueHistogram, 0, 256);
+ invalidate();
+ }
+ }
+
+ public HistogramView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void setBitmap(Bitmap bitmap) {
+ mBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
+ new ComputeHistogramTask().execute(mBitmap);
+ }
+
+ private void drawHistogram(Canvas canvas, int[] histogram, int color, PorterDuff.Mode mode) {
+ int max = 0;
+ for (int i = 0; i < histogram.length; i++) {
+ if (histogram[i] > max) {
+ max = histogram[i];
+ }
+ }
+ float w = getWidth() - Spline.curveHandleSize();
+ float h = getHeight() - Spline.curveHandleSize() / 2.0f;
+ float dx = Spline.curveHandleSize() / 2.0f;
+ float wl = w / histogram.length;
+ float wh = (0.3f * h) / max;
+ Paint paint = new Paint();
+ paint.setARGB(100, 255, 255, 255);
+ paint.setStrokeWidth((int) Math.ceil(wl));
+
+ // Draw grid
+ paint.setStyle(Paint.Style.STROKE);
+ canvas.drawRect(dx, 0, dx + w, h, paint);
+ canvas.drawLine(dx + w / 3, 0, dx + w / 3, h, paint);
+ canvas.drawLine(dx + 2 * w / 3, 0, dx + 2 * w / 3, h, paint);
+ paint.setStyle(Paint.Style.FILL_AND_STROKE);
+
+ Paint paint2 = new Paint();
+ paint2.setColor(color);
+ paint2.setStrokeWidth(6);
+ paint2.setXfermode(new PorterDuffXfermode(mode));
+ gHistoPath.reset();
+ gHistoPath.moveTo(dx, h);
+ boolean firstPointEncountered = false;
+ float prev = 0;
+ float last = 0;
+ for (int i = 0; i < histogram.length; i++) {
+ float x = i * wl + dx;
+ float l = histogram[i] * wh;
+ if (l != 0) {
+ float v = h - (l + prev) / 2.0f;
+ if (!firstPointEncountered) {
+ gHistoPath.lineTo(x, h);
+ firstPointEncountered = true;
+ }
+ gHistoPath.lineTo(x, v);
+ prev = l;
+ last = x;
+ }
+ }
+ gHistoPath.lineTo(last, h);
+ gHistoPath.lineTo(w, h);
+ gHistoPath.close();
+ canvas.drawPath(gHistoPath, paint2);
+ paint2.setStrokeWidth(2);
+ paint2.setStyle(Paint.Style.STROKE);
+ paint2.setARGB(255, 200, 200, 200);
+ canvas.drawPath(gHistoPath, paint2);
+ }
+
+ public void onDraw(Canvas canvas) {
+ canvas.drawARGB(0, 0, 0, 0);
+ drawHistogram(canvas, redHistogram, Color.RED, PorterDuff.Mode.SCREEN);
+ drawHistogram(canvas, greenHistogram, Color.GREEN, PorterDuff.Mode.SCREEN);
+ drawHistogram(canvas, blueHistogram, Color.BLUE, PorterDuff.Mode.SCREEN);
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/info/InfoPanel.java b/src/com/android/gallery3d/filtershow/info/InfoPanel.java
new file mode 100644
index 000000000..a06527f3a
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/info/InfoPanel.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.gallery3d.filtershow.info;
+
+import android.graphics.Bitmap;
+import android.graphics.Rect;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Html;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import com.android.gallery3d.R;
+import com.android.gallery3d.exif.ExifInterface;
+import com.android.gallery3d.exif.ExifTag;
+import com.android.gallery3d.filtershow.cache.ImageLoader;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
+
+import java.util.List;
+
+public class InfoPanel extends Fragment {
+ public static final String FRAGMENT_TAG = "InfoPanel";
+ private static final String LOGTAG = FRAGMENT_TAG;
+ private LinearLayout mMainView;
+ private ImageView mImageThumbnail;
+ private TextView mImageName;
+ private TextView mImageSize;
+ private TextView mExifData;
+
+ private String createStringFromIfFound(ExifTag exifTag, int tag, int str) {
+ String exifString = "";
+ short tagId = exifTag.getTagId();
+ if (tagId == ExifInterface.getTrueTagKey(tag)) {
+ String label = getActivity().getString(str);
+ exifString += "<b>" + label + ": </b>";
+ exifString += exifTag.forceGetValueAsString();
+ exifString += "<br>";
+ }
+ return exifString;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ mMainView = (LinearLayout) inflater.inflate(
+ R.layout.filtershow_info_panel, null, false);
+
+ mImageThumbnail = (ImageView) mMainView.findViewById(R.id.imageThumbnail);
+ Bitmap bitmap = MasterImage.getImage().getFilteredImage();
+ mImageThumbnail.setImageBitmap(bitmap);
+
+ mImageName = (TextView) mMainView.findViewById(R.id.imageName);
+ mImageSize = (TextView) mMainView.findViewById(R.id.imageSize);
+ mExifData = (TextView) mMainView.findViewById(R.id.exifData);
+ HistogramView histogramView = (HistogramView) mMainView.findViewById(R.id.histogramView);
+
+ histogramView.setBitmap(bitmap);
+
+ Uri uri = MasterImage.getImage().getUri();
+ String path = ImageLoader.getLocalPathFromUri(getActivity(), uri);
+ Uri localUri = null;
+ if (path != null) {
+ localUri = Uri.parse(path);
+ }
+
+ if (localUri != null) {
+ mImageName.setText(localUri.getLastPathSegment());
+ }
+ Rect originalBounds = MasterImage.getImage().getOriginalBounds();
+ mImageSize.setText("" + originalBounds.width() + " x " + originalBounds.height());
+
+ List<ExifTag> exif = MasterImage.getImage().getEXIF();
+ String exifString = "";
+ if (exif != null) {
+ for (ExifTag tag : exif) {
+ exifString += createStringFromIfFound(tag,
+ ExifInterface.TAG_MODEL,
+ R.string.filtershow_exif_model);
+ exifString += createStringFromIfFound(tag,
+ ExifInterface.TAG_APERTURE_VALUE,
+ R.string.filtershow_exif_aperture);
+ exifString += createStringFromIfFound(tag,
+ ExifInterface.TAG_FOCAL_LENGTH,
+ R.string.filtershow_exif_focal_length);
+ exifString += createStringFromIfFound(tag,
+ ExifInterface.TAG_ISO_SPEED_RATINGS,
+ R.string.filtershow_exif_iso);
+ exifString += createStringFromIfFound(tag,
+ ExifInterface.TAG_SUBJECT_DISTANCE,
+ R.string.filtershow_exif_subject_distance);
+ exifString += createStringFromIfFound(tag,
+ ExifInterface.TAG_DATE_TIME_ORIGINAL,
+ R.string.filtershow_exif_date);
+ exifString += createStringFromIfFound(tag,
+ ExifInterface.TAG_F_NUMBER,
+ R.string.filtershow_exif_f_stop);
+ exifString += createStringFromIfFound(tag,
+ ExifInterface.TAG_EXPOSURE_TIME,
+ R.string.filtershow_exif_exposure_time);
+ exifString += createStringFromIfFound(tag,
+ ExifInterface.TAG_COPYRIGHT,
+ R.string.filtershow_exif_copyright);
+ }
+ }
+ mExifData.setText(Html.fromHtml(exifString));
+ return mMainView;
+ }
+}