scene mode: center grid in landscape mode

Change-Id: I90390a19ba6e58353e7939d08cd91c0998019ea4
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
diff --git a/res/layout/scene_mode_grid.xml b/res/layout/scene_mode_grid.xml
index 9984cf9..19555e6 100644
--- a/res/layout/scene_mode_grid.xml
+++ b/res/layout/scene_mode_grid.xml
@@ -38,5 +38,5 @@
         android:layout_height="wrap_content"
         android:columnWidth="@dimen/scene_mode_width"
         android:numColumns="auto_fit"
-        android:stretchMode="spacingWidthUniform"></GridView>
+        android:stretchMode="spacingWidthUniform" />
 </LinearLayout>
diff --git a/res/layout/scene_mode_grid_landscape.xml b/res/layout/scene_mode_grid_landscape.xml
new file mode 100644
index 0000000..3f75758
--- /dev/null
+++ b/res/layout/scene_mode_grid_landscape.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2016, The Linux Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+     * Redistributions of source code must retain the above copyright
+       notice, this list of conditions and the following disclaimer.
+     * Redistributions in binary form must reproduce the above
+       copyright notice, this list of conditions and the following
+       disclaimer in the documentation and/or other materials provided
+       with the distribution.
+     * Neither the name of The Linux Foundation nor the names of its
+       contributors may be used to endorse or promote products derived
+       from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:gravity="center"
+    android:orientation="horizontal">
+
+    <GridView
+        android:id="@+id/grid"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:columnWidth="@dimen/scene_mode_width"
+        android:numColumns="5"
+        android:stretchMode="spacingWidthUniform" />
+</LinearLayout>
diff --git a/res/layout/scene_mode_menu_view.xml b/res/layout/scene_mode_menu_view.xml
index bb2f38e..81ebfd8 100644
--- a/res/layout/scene_mode_menu_view.xml
+++ b/res/layout/scene_mode_menu_view.xml
@@ -27,6 +27,7 @@
      IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="center"
@@ -42,7 +43,8 @@
         android:layout_height="56dp"
         android:padding="10dp"
         android:background="@drawable/bg_custom_icon"
-        android:layout_gravity="center" />
+        android:layout_gravity="center"
+        tools:src="@drawable/ic_scene_mode_hdr" />
 
     <TextView
         android:id="@+id/label"
@@ -52,5 +54,6 @@
         android:gravity="center"
         android:layout_marginTop="8dp"
         android:textColor="@android:color/white"
-        android:textSize="16sp" />
+        android:textSize="16sp"
+        tools:text="@string/pref_camera_scenemode_entry_hdr" />
 </LinearLayout>
diff --git a/src/com/android/camera/SceneModeActivity.java b/src/com/android/camera/SceneModeActivity.java
index 280ff31..b37cce6 100644
--- a/src/com/android/camera/SceneModeActivity.java
+++ b/src/com/android/camera/SceneModeActivity.java
@@ -32,6 +32,7 @@
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.content.res.Configuration;
 import android.os.Bundle;
 import android.support.v4.view.PagerAdapter;
 import android.support.v4.view.ViewPager;
@@ -94,6 +95,16 @@
     }
 
     @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+
+        if (mPager != null) {
+            mAdapter = new MyPagerAdapter(this);
+            mPager.setAdapter(mAdapter);
+        }
+    }
+
+    @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         final boolean isSecureCamera = getIntent().getBooleanExtra(
@@ -104,7 +115,6 @@
         setContentView(R.layout.scene_mode_menu_layout);
         mSettingsManager = SettingsManager.getInstance();
 
-
         mCurrentScene = mSettingsManager.getValueIndex(SettingsManager.KEY_SCENE_MODE);
 
         mEntries = loadEntries();
@@ -226,7 +236,6 @@
 }
 
 class MyPagerAdapter extends PagerAdapter {
-
     private final SceneModeActivity mActivity;
 
     public MyPagerAdapter(SceneModeActivity activity) {
@@ -235,7 +244,10 @@
 
     @Override
     public Object instantiateItem(ViewGroup viewGroup, int position) {
-        final ViewGroup rootView = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.scene_mode_grid, viewGroup, false);
+        final int orientation = mActivity.getResources().getConfiguration().orientation;
+        final int layoutResId = (orientation == Configuration.ORIENTATION_PORTRAIT) ? R.layout.scene_mode_grid : R.layout.scene_mode_grid_landscape;
+
+        final ViewGroup rootView = (ViewGroup) mActivity.getLayoutInflater().inflate(layoutResId, viewGroup, false);
         GridView mGridView = rootView.findViewById(R.id.grid);
         mGridView.setAdapter(new GridAdapter(mActivity, position));
         viewGroup.addView(rootView);
@@ -279,68 +291,68 @@
     public boolean isViewFromObject(View view, Object object) {
         return view == object;
     }
-}
 
-class GridAdapter extends BaseAdapter {
-    private final SceneModeActivity mActivity;
-    private final LayoutInflater mInflater;
-    private final int mPage;
+    private static class GridAdapter extends BaseAdapter {
+        private final SceneModeActivity mActivity;
+        private final LayoutInflater mInflater;
+        private final int mPage;
 
-    public GridAdapter(SceneModeActivity activity, int i) {
-        mActivity = activity;
-        mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-        mPage = i;
-    }
-
-    @Override
-    public int getCount() {
-        int elem = mActivity.getElmentPerPage();
-        if (mPage == mActivity.getNumberOfPage() - 1) {
-            elem = mActivity.getNumberOfElement() - mPage * elem;
-        }
-        return elem;
-    }
-
-    @Override
-    public Object getItem(int position) {
-        return null;
-    }
-
-    @Override
-    public long getItemId(int position) {
-        return position;
-    }
-
-    @Override
-    public View getView(int position, View convertView, ViewGroup parent) {
-        View view = convertView;
-        ViewHolder viewHolder;
-
-        if (view == null) {
-            view = mInflater.inflate(R.layout.scene_mode_menu_view, parent, false);
-            viewHolder = new ViewHolder(view);
-            view.setTag(viewHolder);
-        } else {
-            viewHolder = (ViewHolder) convertView.getTag();
+        public GridAdapter(SceneModeActivity activity, int i) {
+            mActivity = activity;
+            mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+            mPage = i;
         }
 
-        final List<CharSequence> entryList = mActivity.getEntries();
-        final List<Integer> thumbnailList = mActivity.getThumbnails();
+        @Override
+        public int getCount() {
+            int elem = mActivity.getElmentPerPage();
+            if (mPage == mActivity.getNumberOfPage() - 1) {
+                elem = mActivity.getNumberOfElement() - mPage * elem;
+            }
+            return elem;
+        }
 
-        final int idx = position + mPage * mActivity.getElmentPerPage();
-        viewHolder.imageView.setImageResource(thumbnailList.get(idx));
-        viewHolder.textTitle.setText(entryList.get(position + mPage * mActivity.getElmentPerPage()));
+        @Override
+        public Object getItem(int position) {
+            return null;
+        }
 
-        return view;
-    }
+        @Override
+        public long getItemId(int position) {
+            return position;
+        }
 
-    private static class ViewHolder {
-        public final ImageView imageView;
-        public final TextView textTitle;
+        @Override
+        public View getView(int position, View convertView, ViewGroup parent) {
+            View view = convertView;
+            ViewHolder viewHolder;
 
-        ViewHolder(final View rootView) {
-            imageView = rootView.findViewById(R.id.image);
-            textTitle = rootView.findViewById(R.id.label);
+            if (view == null) {
+                view = mInflater.inflate(R.layout.scene_mode_menu_view, parent, false);
+                viewHolder = new ViewHolder(view);
+                view.setTag(viewHolder);
+            } else {
+                viewHolder = (ViewHolder) convertView.getTag();
+            }
+
+            final List<CharSequence> entryList = mActivity.getEntries();
+            final List<Integer> thumbnailList = mActivity.getThumbnails();
+
+            final int idx = position + mPage * mActivity.getElmentPerPage();
+            viewHolder.imageView.setImageResource(thumbnailList.get(idx));
+            viewHolder.textTitle.setText(entryList.get(position + mPage * mActivity.getElmentPerPage()));
+
+            return view;
+        }
+
+        private static class ViewHolder {
+            public final ImageView imageView;
+            public final TextView textTitle;
+
+            ViewHolder(final View rootView) {
+                imageView = rootView.findViewById(R.id.image);
+                textTitle = rootView.findViewById(R.id.label);
+            }
         }
     }
 }