Fix info panel

bug:10705772
Change-Id: I9481aec8baf1a7b1782be5cf47acbf3269768cee
diff --git a/res/layout/filtershow_info_panel.xml b/res/layout/filtershow_info_panel.xml
index 39446df..43878b6 100644
--- a/res/layout/filtershow_info_panel.xml
+++ b/res/layout/filtershow_info_panel.xml
@@ -16,51 +16,11 @@
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="match_parent"
+              android:minWidth="340dp"
               android:layout_height="match_parent"
               android:orientation="vertical"
-              android:background="#3a4e56">
-
-    <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal"
-            android:background="#222">
-
-        <ImageButton
-                android:id="@+id/cancelInfo"
-                android:layout_width="wrap_content"
-                android:layout_height="fill_parent"
-                android:layout_gravity="left|center_vertical"
-                android:background="@android:color/transparent"
-                android:layout_weight=".1"
-                android:gravity="left"
-                android:src="@drawable/ic_menu_cancel_holo_light"
-                android:textSize="18dip"/>
-
-        <ImageView
-                android:layout_width="2dp"
-                android:layout_height="fill_parent"
-                android:src="@drawable/filtershow_vertical_bar"/>
-
-        <TextView
-                style="?android:textAppearanceLarge"
-                android:textStyle="bold"
-                android:textColor="#fff"
-                android:layout_weight="1"
-                android:layout_gravity="left|center_vertical"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:padding="8dip"
-                android:text="@string/filtershow_show_info_panel"/>
-
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                  android:layout_width="match_parent"
-                  android:layout_height="match_parent"
-                  android:orientation="vertical"
-                  android:background="#3a4e56"
-                  android:padding="16dp">
+              android:background="@color/background_main_toolbar"
+              android:padding="16dp">
 
     <ScrollView
             android:layout_width="match_parent"
@@ -74,87 +34,78 @@
             <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:orientation="horizontal">
+                    android:orientation="horizontal"
+                    >
 
-                <LinearLayout
+                <TextView
+                        android:id="@+id/imageName"
+                        style="?android:textAppearanceSmall"
+                        android:textStyle="bold"
+                        android:textColor="#80ffffff"
+                        android:layout_gravity="start"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_weight="1"
+                        android:gravity="start"/>
+
+                <TextView
+                        android:id="@+id/imageSize"
+                        style="?android:textAppearanceSmall"
+                        android:textAllCaps="true"
+                        android:textColor="#80ffffff"
+                        android:textStyle="bold"
+                        android:layout_gravity="end"
                         android:layout_width="0dp"
                         android:layout_height="wrap_content"
                         android:layout_weight="1"
-                        android:orientation="vertical">
+                        android:gravity="end"/>
 
-                    <TextView
-                            style="?android:textAppearanceLarge"
-                            android:textStyle="bold"
-                            android:textColor="#fff"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:text="@string/filtershow_show_info_panel_name"/>
+            </LinearLayout>
 
-                    <TextView
-                            android:id="@+id/imageName"
-                            style="?android:textAppearanceSmall"
-                            android:textStyle="bold"
-                            android:textColor="#80ffffff"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"/>
-
-                    <TextView
-                            style="?android:textAppearanceLarge"
-                            android:textStyle="bold"
-                            android:textColor="#fff"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:text="@string/filtershow_show_info_panel_size"/>
-
-                    <TextView
-                            android:id="@+id/imageSize"
-                            style="?android:textAppearanceSmall"
-                            android:textAllCaps="true"
-                            android:textColor="#80ffffff"
-                            android:textStyle="bold"
-                            android:lineSpacingMultiplier="1.2"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"/>
-
-                </LinearLayout>
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="16dp"
+                    >
 
                 <ImageView
                         android:id="@+id/imageThumbnail"
-                        android:layout_width="200dp"
-                        android:layout_height="200dp"
-                        android:scaleType="centerInside"
+                        android:layout_weight="0.3"
+                        android:layout_width="0dp"
+                        android:layout_height="196dp"
+                        android:scaleType="centerCrop"
+                        android:layout_marginRight="16dp"
                         android:background="@null"
-                        android:layout_weight="1"
+
                         />
+
+                <com.android.gallery3d.filtershow.info.HistogramView
+                        android:id="@+id/histogramView"
+                        android:layout_weight="0.7"
+                        android:layout_width="0dp"
+                        android:layout_height="196dp"
+                        android:layout_margin="0dp"/>
             </LinearLayout>
 
             <TextView
                     style="?android:textAppearanceLarge"
+                    android:id="@+id/exifLabel"
                     android:textStyle="bold"
                     android:textColor="#fff"
-                    android:layout_width="match_parent"
+                    android:layout_marginTop="16dp"
+                    android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:text="@string/filtershow_show_info_panel_histogram"/>
-
-            <com.android.gallery3d.filtershow.info.HistogramView
-                    android:id="@+id/histogramView"
-                    android:layout_width="match_parent"
-                    android:layout_height="250dp"
-                    android:layout_margin="16dp"/>
-
-            <TextView
-                    style="?android:textAppearanceLarge"
-                    android:textStyle="bold"
-                    android:textColor="#fff"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
+                    android:layout_gravity="start"
                     android:text="@string/filtershow_show_info_panel_exif"/>
 
             <TextView
                     android:id="@+id/exifData"
                     android:layout_width="match_parent"
-                    android:layout_height="wrap_content"/>
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="16dp"
+                    android:layout_gravity="start"
+                    />
         </LinearLayout>
     </ScrollView>
-    </LinearLayout>
+
 </LinearLayout>
\ No newline at end of file
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index 56ae93e..089fc8a 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -147,7 +147,6 @@
     private boolean mShowingTinyPlanet = false;
     private boolean mShowingImageStatePanel = false;
     private boolean mShowingVersionsPanel = false;
-    private boolean mShowingInformationPanel = false;
 
     private final Vector<ImageShow> mImageViews = new Vector<ImageShow>();
 
@@ -331,35 +330,12 @@
         }
     }
 
-    public void hideInformationPanel() {
-        FrameLayout infoLayout = (FrameLayout) findViewById(R.id.central_panel_container);
-        infoLayout.setVisibility(View.GONE);
-        Fragment fragment = getSupportFragmentManager().findFragmentByTag(InfoPanel.FRAGMENT_TAG);
-        if (fragment != null) {
-            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-            transaction.remove(fragment);
-            transaction.commit();
-        }
-        mShowingInformationPanel = false;
-    }
-
     public void toggleInformationPanel() {
-        mShowingInformationPanel = !mShowingInformationPanel;
-        if (!mShowingInformationPanel) {
-            hideInformationPanel();
-            showDefaultImageView();
-            return;
-        }
         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
         transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
-        FrameLayout infoLayout = (FrameLayout) findViewById(R.id.central_panel_container);
-        infoLayout.setVisibility(View.VISIBLE);
-        mEditorPlaceHolder.hide();
-        mImageShow.setVisibility(View.GONE);
 
         InfoPanel panel = new InfoPanel();
-        transaction.replace(R.id.central_panel_container, panel, InfoPanel.FRAGMENT_TAG);
-        transaction.commit();
+        panel.show(transaction, InfoPanel.FRAGMENT_TAG);
     }
 
     private void loadXML() {
@@ -681,7 +657,6 @@
         }
         mCurrentEditor = mEditorPlaceHolder.showEditor(representation.getEditorId());
         loadEditorPanel(representation, mCurrentEditor);
-        hideInformationPanel();
     }
 
     public Editor getEditor(int editorID) {
@@ -1206,8 +1181,6 @@
         fillCategories();
         loadMainPanel();
 
-        mShowingInformationPanel = false;
-
         // mLoadBitmapTask==null implies you have looked at the intent
         if (!mShowingTinyPlanet && (mLoadBitmapTask == null)) {
             mCategoryFiltersAdapter.removeTinyPlanet();
@@ -1244,7 +1217,6 @@
     }
 
     public void showDefaultImageView() {
-        hideInformationPanel();
         mEditorPlaceHolder.hide();
         mImageShow.setVisibility(View.VISIBLE);
         MasterImage.getImage().setCurrentFilter(null);
diff --git a/src/com/android/gallery3d/filtershow/info/HistogramView.java b/src/com/android/gallery3d/filtershow/info/HistogramView.java
index ad56fe4..99cf235 100644
--- a/src/com/android/gallery3d/filtershow/info/HistogramView.java
+++ b/src/com/android/gallery3d/filtershow/info/HistogramView.java
@@ -27,15 +27,15 @@
 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();
+    private Paint mPaint = new Paint();
+    private int[] redHistogram = new int[256];
+    private int[] greenHistogram = new int[256];
+    private int[] blueHistogram = new int[256];
+    private Path mHistoPath = new Path();
 
     class ComputeHistogramTask extends AsyncTask<Bitmap, Void, int[]> {
         @Override
@@ -85,28 +85,29 @@
                 max = histogram[i];
             }
         }
-        float w = getWidth() - Spline.curveHandleSize();
-        float h = getHeight() - Spline.curveHandleSize() / 2.0f;
-        float dx = Spline.curveHandleSize() / 2.0f;
+        float w = getWidth(); // - Spline.curveHandleSize();
+        float h = getHeight(); // - Spline.curveHandleSize() / 2.0f;
+        float dx = 0; // Spline.curveHandleSize() / 2.0f;
         float wl = w / histogram.length;
         float wh = h / max;
-        Paint paint = new Paint();
-        paint.setARGB(100, 255, 255, 255);
-        paint.setStrokeWidth((int) Math.ceil(wl));
+
+        mPaint.reset();
+        mPaint.setAntiAlias(true);
+        mPaint.setARGB(100, 255, 255, 255);
+        mPaint.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);
+        mPaint.setStyle(Paint.Style.STROKE);
+        canvas.drawRect(dx, 0, dx + w, h, mPaint);
+        canvas.drawLine(dx + w / 3, 0, dx + w / 3, h, mPaint);
+        canvas.drawLine(dx + 2 * w / 3, 0, dx + 2 * w / 3, h, mPaint);
 
-        Paint paint2 = new Paint();
-        paint2.setColor(color);
-        paint2.setStrokeWidth(6);
-        paint2.setXfermode(new PorterDuffXfermode(mode));
-        gHistoPath.reset();
-        gHistoPath.moveTo(dx, h);
+        mPaint.setStyle(Paint.Style.FILL);
+        mPaint.setColor(color);
+        mPaint.setStrokeWidth(6);
+        mPaint.setXfermode(new PorterDuffXfermode(mode));
+        mHistoPath.reset();
+        mHistoPath.moveTo(dx, h);
         boolean firstPointEncountered = false;
         float prev = 0;
         float last = 0;
@@ -116,22 +117,22 @@
             if (l != 0) {
                 float v = h - (l + prev) / 2.0f;
                 if (!firstPointEncountered) {
-                    gHistoPath.lineTo(x, h);
+                    mHistoPath.lineTo(x, h);
                     firstPointEncountered = true;
                 }
-                gHistoPath.lineTo(x, v);
+                mHistoPath.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);
+        mHistoPath.lineTo(last, h);
+        mHistoPath.lineTo(w, h);
+        mHistoPath.close();
+        canvas.drawPath(mHistoPath, mPaint);
+        mPaint.setStrokeWidth(2);
+        mPaint.setStyle(Paint.Style.STROKE);
+        mPaint.setARGB(255, 200, 200, 200);
+        canvas.drawPath(mHistoPath, mPaint);
     }
 
     public void onDraw(Canvas canvas) {
diff --git a/src/com/android/gallery3d/filtershow/info/InfoPanel.java b/src/com/android/gallery3d/filtershow/info/InfoPanel.java
index 39102f1..3a66578 100644
--- a/src/com/android/gallery3d/filtershow/info/InfoPanel.java
+++ b/src/com/android/gallery3d/filtershow/info/InfoPanel.java
@@ -20,11 +20,12 @@
 import android.graphics.Rect;
 import android.net.Uri;
 import android.os.Bundle;
-import android.support.v4.app.Fragment;
+import android.support.v4.app.DialogFragment;
 import android.text.Html;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.Window;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
@@ -32,13 +33,12 @@
 import com.android.gallery3d.R;
 import com.android.gallery3d.exif.ExifInterface;
 import com.android.gallery3d.exif.ExifTag;
-import com.android.gallery3d.filtershow.FilterShowActivity;
 import com.android.gallery3d.filtershow.cache.ImageLoader;
 import com.android.gallery3d.filtershow.imageshow.MasterImage;
 
 import java.util.List;
 
-public class InfoPanel extends Fragment {
+public class InfoPanel extends DialogFragment {
     public static final String FRAGMENT_TAG = "InfoPanel";
     private static final String LOGTAG = FRAGMENT_TAG;
     private LinearLayout mMainView;
@@ -46,7 +46,6 @@
     private TextView mImageName;
     private TextView mImageSize;
     private TextView mExifData;
-    private ImageButton mHideButton;
 
     private String createStringFromIfFound(ExifTag exifTag, int tag, int str) {
         String exifString = "";
@@ -63,6 +62,9 @@
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
+        if (getDialog() != null) {
+            getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+        }
 
         mMainView = (LinearLayout) inflater.inflate(
                 R.layout.filtershow_info_panel, null, false);
@@ -74,19 +76,11 @@
         mImageName = (TextView) mMainView.findViewById(R.id.imageName);
         mImageSize = (TextView) mMainView.findViewById(R.id.imageSize);
         mExifData = (TextView) mMainView.findViewById(R.id.exifData);
-        mHideButton =(ImageButton) mMainView.findViewById(R.id.cancelInfo);
+        TextView exifLabel = (TextView) mMainView.findViewById(R.id.exifLabel);
 
         HistogramView histogramView = (HistogramView) mMainView.findViewById(R.id.histogramView);
-
         histogramView.setBitmap(bitmap);
 
-        mHideButton.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                FilterShowActivity activity = (FilterShowActivity)getActivity();
-                activity.toggleInformationPanel();
-            }
-        });
         Uri uri = MasterImage.getImage().getUri();
         String path = ImageLoader.getLocalPathFromUri(getActivity(), uri);
         Uri localUri = null;
@@ -102,6 +96,7 @@
 
         List<ExifTag> exif = MasterImage.getImage().getEXIF();
         String exifString = "";
+        boolean hasExifData = false;
         if (exif != null) {
             for (ExifTag tag : exif) {
                 exifString += createStringFromIfFound(tag,
@@ -131,9 +126,15 @@
                 exifString += createStringFromIfFound(tag,
                         ExifInterface.TAG_COPYRIGHT,
                         R.string.filtershow_exif_copyright);
+                hasExifData = true;
             }
         }
-        mExifData.setText(Html.fromHtml(exifString));
+        if (hasExifData) {
+            exifLabel.setVisibility(View.VISIBLE);
+            mExifData.setText(Html.fromHtml(exifString));
+        } else {
+            exifLabel.setVisibility(View.GONE);
+        }
         return mMainView;
     }
 }