From ffd44061e93cfd63040b909024407a8c5953422e Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Fri, 7 Oct 2016 14:06:28 +0200 Subject: Furtherly improve list menu handling. Improve layout of top-level menu items, and avoid second level menu items being obscured by the navigation bar. RM-290 Change-Id: Ic3ee983e33613f7337839d11cae9520b86636b7d --- res/layout/list_menu_item.xml | 50 ++++++++++++++++------------- src/com/android/camera/PhotoUI.java | 4 ++- src/com/android/camera/VideoUI.java | 4 ++- src/com/android/camera/ui/ListMenu.java | 21 ++++++------ src/com/android/camera/ui/ListMenuItem.java | 4 +-- src/com/android/camera/ui/ListSubMenu.java | 31 +++++++++++++++++- src/com/android/camera/ui/RotateLayout.java | 12 +++++-- 7 files changed, 87 insertions(+), 39 deletions(-) diff --git a/res/layout/list_menu_item.xml b/res/layout/list_menu_item.xml index 025bb607d..36e41d2a5 100644 --- a/res/layout/list_menu_item.xml +++ b/res/layout/list_menu_item.xml @@ -28,37 +28,41 @@ --> + android:orientation="horizontal" + android:gravity="center_vertical" + android:paddingLeft="8dip" + android:paddingRight="8dip" > + android:layout_marginRight="16dp" /> - + android:orientation="vertical"> - + + + + + diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java index bacffe6fe..f00b63eb2 100644 --- a/src/com/android/camera/PhotoUI.java +++ b/src/com/android/camera/PhotoUI.java @@ -776,12 +776,14 @@ public class PhotoUI implements PieListener, Gravity.START | Gravity.TOP)); mRootView.addView(mMenuLayout); } - mMenuLayout.addView(popup); + mMenuLayout.addView(popup, new RotateLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mMenuLayout.setOrientation(mOrientation, true); } if (level == 2) { if (mSubMenuLayout == null) { mSubMenuLayout = new RotateLayout(mActivity, null); + mSubMenuLayout.setRootView(mRootView); mRootView.addView(mSubMenuLayout); } diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java index b983cd1fb..a5ec680dd 100644 --- a/src/com/android/camera/VideoUI.java +++ b/src/com/android/camera/VideoUI.java @@ -760,12 +760,14 @@ public class VideoUI implements PieRenderer.PieListener, Gravity.START | Gravity.TOP)); mRootView.addView(mMenuLayout); } - mMenuLayout.addView(popup); + mMenuLayout.addView(popup, new RotateLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mMenuLayout.setOrientation(mOrientation, true); } if (level == 2) { if (mSubMenuLayout == null) { mSubMenuLayout = new RotateLayout(mActivity, null); + mSubMenuLayout.setRootView(mRootView); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( CameraActivity.SETTING_LIST_WIDTH_2, LayoutParams.WRAP_CONTENT); mSubMenuLayout.setLayoutParams(params); diff --git a/src/com/android/camera/ui/ListMenu.java b/src/com/android/camera/ui/ListMenu.java index bb21f7e0a..f56200a55 100644 --- a/src/com/android/camera/ui/ListMenu.java +++ b/src/com/android/camera/ui/ListMenu.java @@ -75,18 +75,13 @@ public class ListMenu extends ListView mOffString = context.getString(R.string.setting_off); } - private int getSettingLayoutId(ListPreference pref) { - return R.layout.list_menu_item; - } - @Override public View getView(int position, View convertView, ViewGroup parent) { ListPreference pref = mListItem.get(position); - int viewLayoutId = getSettingLayoutId(pref); ListMenuItem view = (ListMenuItem) convertView; view = (ListMenuItem) - mInflater.inflate(viewLayoutId, parent, false); + mInflater.inflate(R.layout.list_menu_item, parent, false); view.initialize(pref); // no init for restore one view.setSettingChangedListener(ListMenu.this); @@ -112,7 +107,7 @@ public class ListMenu extends ListView } @Override - public void onApplyWindowInsets(Rect insets) { + public void onApplyWindowInsets(Rect insets, int rootWidth, int rootHeight) { if (mHeader == null) { mHeader = new Space(getContext()); addHeaderView(mHeader); @@ -122,8 +117,10 @@ public class ListMenu extends ListView setFooterDividersEnabled(false); } - adjustViewHeight(mHeader, insets.top); - adjustViewHeight(mFooter, insets.bottom); + boolean largerThanRoot = + getPreCalculatedHeight() - insets.top - insets.bottom > rootHeight; + adjustViewHeight(mHeader, largerThanRoot ? insets.top : 0); + adjustViewHeight(mFooter, largerThanRoot ? insets.bottom : 0); } private void adjustViewHeight(View view, int height) { @@ -241,6 +238,12 @@ public class ListMenu extends ListView } + private int getPreCalculatedHeight() { + int count = getAdapter().getCount(); + return count * (int) getContext().getResources().getDimension(R.dimen.setting_row_height) + + (count - 1) * getDividerHeight(); + } + public void reloadPreference() { int count = getChildCount(); for (int i = 0; i < count; i++) { diff --git a/src/com/android/camera/ui/ListMenuItem.java b/src/com/android/camera/ui/ListMenuItem.java index f3c7f017e..4774b8319 100644 --- a/src/com/android/camera/ui/ListMenuItem.java +++ b/src/com/android/camera/ui/ListMenuItem.java @@ -22,7 +22,7 @@ import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.accessibility.AccessibilityEvent; -import android.widget.RelativeLayout; +import android.widget.LinearLayout; import android.widget.TextView; import android.widget.ImageView; @@ -40,7 +40,7 @@ import org.codeaurora.snapcam.R; * Other setting popup window includes several InLineSettingItem items with * different types if possible. */ -public class ListMenuItem extends RelativeLayout { +public class ListMenuItem extends LinearLayout { private static final String TAG = "ListMenuItem"; private Listener mListener; protected ListPreference mPreference; diff --git a/src/com/android/camera/ui/ListSubMenu.java b/src/com/android/camera/ui/ListSubMenu.java index 3501af3bc..87c99c0fe 100644 --- a/src/com/android/camera/ui/ListSubMenu.java +++ b/src/com/android/camera/ui/ListSubMenu.java @@ -29,11 +29,13 @@ import android.graphics.Rect; import android.util.AttributeSet; import android.util.Log; import android.view.View; +import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.SimpleAdapter; +import android.widget.Space; import com.android.camera.IconListPreference; import com.android.camera.ListPreference; @@ -45,10 +47,11 @@ import org.codeaurora.snapcam.R; // the entries will contain both text and icons. Otherwise, entries will be // shown in text. public class ListSubMenu extends ListView implements - AdapterView.OnItemClickListener { + RotateLayout.Child, AdapterView.OnItemClickListener { private static final String TAG = "ListPrefSettingPopup"; private ListPreference mPreference; private Listener mListener; + private View mHeader, mFooter; private int mY; static public interface Listener { @@ -145,6 +148,32 @@ public class ListSubMenu extends ListView implements super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); } + @Override + public void onApplyWindowInsets(Rect insets, int rootWidth, int rootHeight) { + if (mHeader == null) { + mHeader = new Space(getContext()); + addHeaderView(mHeader); + setHeaderDividersEnabled(false); + mFooter = new Space(getContext()); + addFooterView(mFooter); + setFooterDividersEnabled(false); + } + + boolean largerThanRoot = + getPreCalculatedHeight() - insets.top - insets.bottom > rootHeight; + adjustViewHeight(mHeader, largerThanRoot ? insets.top : 0); + adjustViewHeight(mFooter, largerThanRoot ? insets.bottom : 0); + } + + private void adjustViewHeight(View view, int height) { + ViewGroup.LayoutParams lp = view.getLayoutParams(); + if (lp == null) { + lp = generateDefaultLayoutParams(); + } + lp.height = height; + view.setLayoutParams(lp); + } + public int getPreCalculatedHeight() { int count = getAdapter().getCount(); return count * (int) getContext().getResources().getDimension(R.dimen.setting_row_height) diff --git a/src/com/android/camera/ui/RotateLayout.java b/src/com/android/camera/ui/RotateLayout.java index 61bcf2282..1ebdf719d 100644 --- a/src/com/android/camera/ui/RotateLayout.java +++ b/src/com/android/camera/ui/RotateLayout.java @@ -36,7 +36,7 @@ public class RotateLayout extends ViewGroup implements Rotatable { private CameraRootView mRootView; public interface Child { - void onApplyWindowInsets(Rect insets); + void onApplyWindowInsets(Rect insets, int rootWidth, int rootHeight); } public RotateLayout(Context context, AttributeSet attrs) { @@ -66,11 +66,18 @@ public class RotateLayout extends ViewGroup implements Rotatable { } } + @Override public void addView(View child) { super.addView(child); setupChild(child); } + @Override + public void addView(View child, LayoutParams params) { + super.addView(child, params); + setupChild(child); + } + public void removeView(View v) { super.removeView(v); mOrientation = 0; @@ -165,7 +172,8 @@ public class RotateLayout extends ViewGroup implements Rotatable { private void applyInsetsToChild() { if (mRootView != null && mChild instanceof Child) { Rect insets = mRootView.getInsetsForOrientation(mOrientation); - ((Child) mChild).onApplyWindowInsets(insets); + final Child child = (Child) mChild; + child.onApplyWindowInsets(insets, mRootView.getWidth(), mRootView.getHeight()); } } -- cgit v1.2.3