diff options
Diffstat (limited to 'src/com/android/camera/ui')
-rw-r--r-- | src/com/android/camera/ui/CameraControls.java | 17 | ||||
-rw-r--r-- | src/com/android/camera/ui/CameraRootView.java | 143 | ||||
-rw-r--r-- | src/com/android/camera/ui/ListMenu.java | 53 | ||||
-rw-r--r-- | src/com/android/camera/ui/ListMenuItem.java | 4 | ||||
-rw-r--r-- | src/com/android/camera/ui/ListSubMenu.java | 38 | ||||
-rw-r--r-- | src/com/android/camera/ui/RenderOverlay.java | 26 | ||||
-rw-r--r-- | src/com/android/camera/ui/RotateLayout.java | 27 |
7 files changed, 192 insertions, 116 deletions
diff --git a/src/com/android/camera/ui/CameraControls.java b/src/com/android/camera/ui/CameraControls.java index fa9796f0e..674cb03f7 100644 --- a/src/com/android/camera/ui/CameraControls.java +++ b/src/com/android/camera/ui/CameraControls.java @@ -27,6 +27,7 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; +import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.graphics.drawable.RippleDrawable; @@ -87,6 +88,7 @@ public class CameraControls extends RotatableLayout { private TextView mRemainingPhotosText; private int mCurrentRemaining = -1; private int mOrientation; + private final Rect mInsets = new Rect(); private int mPreviewRatio; private int mTopMargin = 0; @@ -282,20 +284,31 @@ public class CameraControls extends RotatableLayout { } @Override + protected boolean fitSystemWindows(Rect insets) { + mInsets.set(insets); + return false; + } + + @Override public void onLayout(boolean changed, int l, int t, int r, int b) { Log.d(TAG, String.format("onLayout changed=%b l=%d t=%d r=%d b=%d", changed, l, t, r, b)); super.onLayout(changed, l, t, r, b); + r -= mInsets.right; + b -= mInsets.bottom; + ViewGroup.LayoutParams lpTop = mTopBar.getLayoutParams(); lpTop.height = mTopMargin; mTopBar.setLayoutParams(lpTop); mTopBar.layout(l, t, r, mTopMargin); ViewGroup.LayoutParams lpBottom = mBottomBar.getLayoutParams(); - lpBottom.height = mBottomMargin; + lpBottom.width = r - l + mInsets.right; + lpBottom.height = mBottomMargin + mInsets.bottom; mBottomBar.setLayoutParams(lpBottom); - mBottomBar.layout(l, b - mBottomMargin, r, b); + mBottomBar.setPadding(0, 0, mInsets.right, mInsets.bottom); + mBottomBar.layout(l, b - mBottomMargin, r + mInsets.right, b + mInsets.bottom); setLocation(r - l, b - t); diff --git a/src/com/android/camera/ui/CameraRootView.java b/src/com/android/camera/ui/CameraRootView.java index 42eebaa98..92ac21e34 100644 --- a/src/com/android/camera/ui/CameraRootView.java +++ b/src/com/android/camera/ui/CameraRootView.java @@ -17,9 +17,7 @@ package com.android.camera.ui; import android.annotation.SuppressLint; -import android.app.Activity; import android.content.Context; -import android.content.res.Configuration; import android.graphics.Rect; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; @@ -28,7 +26,6 @@ import android.view.View; import android.widget.FrameLayout; import com.android.camera.util.ApiHelper; -import com.android.camera.util.CameraUtil; @SuppressLint("NewApi") public class CameraRootView extends FrameLayout { @@ -37,10 +34,10 @@ public class CameraRootView extends FrameLayout { private int mBottomMargin = 0; private int mLeftMargin = 0; private int mRightMargin = 0; - private final Rect mCurrentInsets = new Rect(0, 0, 0, 0); - private int mOffset = 0; private Object mDisplayListener; private MyDisplayListener mListener; + private Rect mLastInsets = new Rect(); + private Rect mTmpRect = new Rect(); public interface MyDisplayListener { public void onDisplayChanged(); @@ -51,26 +48,18 @@ public class CameraRootView extends FrameLayout { initDisplayListener(); } - @Override - protected boolean fitSystemWindows(Rect insets) { - // insets include status bar, navigation bar, etc - // In this case, we are only concerned with the size of nav bar - if (mCurrentInsets.equals(insets)) { - // Local copy of the insets is up to date. No need to do anything. - return false; + public void redoFitSystemWindows() { + if (mLastInsets.left != 0 || mLastInsets.right != 0 + || mLastInsets.top != 0 || mLastInsets.bottom != 0) { + Rect insets = new Rect(mLastInsets); + fitSystemWindows(insets); } + } - if (mOffset == 0) { - if (insets.bottom > 0) { - mOffset = insets.bottom; - } else if (insets.right > 0) { - mOffset = insets.right; - } - } - mCurrentInsets.set(insets); - // Make sure onMeasure will be called to adapt to the new insets. - requestLayout(); - return false; + @Override + protected boolean fitSystemWindows(Rect insets) { + mLastInsets.set(insets); + return super.fitSystemWindows(insets); } public void initDisplayListener() { @@ -101,6 +90,40 @@ public class CameraRootView extends FrameLayout { mListener = listener; } + public Rect getInsetsForOrientation(int orientation) { + switch (orientation) { + case 90: + mTmpRect.set(mLastInsets.top, mLastInsets.right, + mLastInsets.bottom, mLastInsets.left); + break; + case 180: + mTmpRect.set(mLastInsets.right, mLastInsets.bottom, + mLastInsets.left, mLastInsets.top); + break; + case 270: + mTmpRect.set(mLastInsets.bottom, mLastInsets.left, + mLastInsets.top, mLastInsets.right); + break; + default: + mTmpRect.set(mLastInsets); + break; + } + + return mTmpRect; + } + + public Rect getClientRectForOrientation(int orientation) { + Rect result = getInsetsForOrientation(orientation); + if (orientation == 90 || orientation == 270) { + result.right = getHeight() - result.right; + result.bottom = getWidth() - result.bottom; + } else { + result.right = getWidth() - result.right; + result.bottom = getHeight() - result.bottom; + } + return result; + } + @Override public void onAttachedToWindow() { super.onAttachedToWindow(); @@ -118,78 +141,4 @@ public class CameraRootView extends FrameLayout { .unregisterDisplayListener((DisplayListener) mDisplayListener); } } -/* - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int rotation = CameraUtil.getDisplayRotation((Activity) getContext()); - // all the layout code assumes camera device orientation to be portrait - // adjust rotation for landscape - int orientation = getResources().getConfiguration().orientation; - int camOrientation = (rotation % 180 == 0) ? Configuration.ORIENTATION_PORTRAIT - : Configuration.ORIENTATION_LANDSCAPE; - if (camOrientation != orientation) { - rotation = (rotation + 90) % 360; - } - // calculate margins - mLeftMargin = 0; - mRightMargin = 0; - mBottomMargin = 0; - mTopMargin = 0; - switch (rotation) { - case 0: - mBottomMargin += mOffset; - break; - case 90: - mRightMargin += mOffset; - break; - case 180: - mTopMargin += mOffset; - break; - case 270: - mLeftMargin += mOffset; - break; - } - if (mCurrentInsets != null) { - if (mCurrentInsets.right > 0) { - // navigation bar on the right - mRightMargin = mRightMargin > 0 ? mRightMargin : mCurrentInsets.right; - } else { - // navigation bar on the bottom - mBottomMargin = mBottomMargin > 0 ? mBottomMargin : mCurrentInsets.bottom; - } - } - // make sure all the children are resized - super.onMeasure(widthMeasureSpec - mLeftMargin - mRightMargin, - heightMeasureSpec - mTopMargin - mBottomMargin); - setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); - } - - @Override - public void onLayout(boolean changed, int l, int t, int r, int b) { - r -= l; - b -= t; - l = 0; - t = 0; - int orientation = getResources().getConfiguration().orientation; - // Lay out children - for (int i = 0; i < getChildCount(); i++) { - View v = getChildAt(i); - if (v instanceof CameraControls) { - // Lay out camera controls to center on the short side of the screen - // so that they stay in place during rotation - int width = v.getMeasuredWidth(); - int height = v.getMeasuredHeight(); - if (orientation == Configuration.ORIENTATION_PORTRAIT) { - int left = (l + r - width) / 2; - v.layout(left, t + mTopMargin, left + width, b - mBottomMargin); - } else { - int top = (t + b - height) / 2; - v.layout(l + mLeftMargin, top, r - mRightMargin, top + height); - } - } else { - v.layout(l + mLeftMargin, t + mTopMargin, r - mRightMargin, b - mBottomMargin); - } - } - } -*/ } diff --git a/src/com/android/camera/ui/ListMenu.java b/src/com/android/camera/ui/ListMenu.java index cb11a80f2..bf6f420da 100644 --- a/src/com/android/camera/ui/ListMenu.java +++ b/src/com/android/camera/ui/ListMenu.java @@ -20,6 +20,7 @@ package com.android.camera.ui; import android.content.Context; +import android.graphics.Rect; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; @@ -29,6 +30,7 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; +import android.widget.Space; import com.android.camera.ListPreference; import com.android.camera.PreferenceGroup; @@ -40,16 +42,17 @@ import java.util.ArrayList; import java.util.List; /* A popup window that contains several camera settings. */ -public class ListMenu extends ListView - implements ListMenuItem.Listener, - AdapterView.OnItemClickListener, - ListSubMenu.Listener { +public class ListMenu extends ListView implements + ListMenuItem.Listener, ListSubMenu.Listener, + AdapterView.OnItemClickListener, RotateLayout.Child { + @SuppressWarnings("unused") private static final String TAG = "ListMenu"; private int mHighlighted = -1; private Listener mListener; private SettingsManager mSettingsManager; private ArrayList<ListPreference> mListItem = new ArrayList<ListPreference>(); + private View mHeader, mFooter; // Keep track of which setting items are disabled // e.g. White balance will be disabled when scene mode is set to non-auto @@ -95,18 +98,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); @@ -141,6 +139,32 @@ public class ListMenu extends ListView mListener = listener; } + @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 ListMenu(Context context, AttributeSet attrs) { super(context, attrs); } @@ -258,7 +282,8 @@ public class ListMenu extends ListView @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { - if (mListener != null) { + position -= getHeaderViewsCount(); + if (mListener != null && position < mListItem.size()) { resetHighlight(); ListPreference pref = mListItem.get(position); mHighlighted = position; @@ -268,6 +293,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 b051fdd27..80b6bdd26 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 a425c7680..04da7bc49 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 { @@ -121,7 +124,7 @@ public class ListSubMenu extends ListView implements public void reloadPreference() { int index = mPreference.findIndexOfValue(mPreference.getValue()); if (index != -1) { - setItemChecked(index, true); + setItemChecked(index + getHeaderViewsCount(), true); } else { Log.e(TAG, "Invalid preference value."); mPreference.print(); @@ -135,6 +138,10 @@ public class ListSubMenu extends ListView implements @Override public void onItemClick(AdapterView<?> parent, View view, int index, long id) { + index -= getHeaderViewsCount(); + if (index < 0 || index >= getAdapter().getCount()) { + return; + } mPreference.setValueIndex(index); if (mListener != null) { mListener.onListPrefChanged(mPreference); @@ -146,6 +153,33 @@ 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); + reloadPreference(); + } + + 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/RenderOverlay.java b/src/com/android/camera/ui/RenderOverlay.java index 8e2f4457f..5f9b7aebf 100644 --- a/src/com/android/camera/ui/RenderOverlay.java +++ b/src/com/android/camera/ui/RenderOverlay.java @@ -18,6 +18,7 @@ package com.android.camera.ui; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Rect; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; @@ -48,6 +49,7 @@ public class RenderOverlay extends FrameLayout { // reverse list of touch clients private List<Renderer> mTouchClients; private int[] mPosition = new int[2]; + private final Rect mInsets = new Rect(); public RenderOverlay(Context context, AttributeSet attrs) { super(context, attrs); @@ -69,13 +71,15 @@ public class RenderOverlay extends FrameLayout { if (renderer.handlesTouch()) { mTouchClients.add(0, renderer); } - renderer.layout(getLeft(), getTop(), getRight(), getBottom()); + renderer.layout(mRenderView.getLeft(), mRenderView.getTop(), + mRenderView.getRight(), mRenderView.getBottom()); } public void addRenderer(int pos, Renderer renderer) { mClients.add(pos, renderer); renderer.setOverlay(this); - renderer.layout(getLeft(), getTop(), getRight(), getBottom()); + renderer.layout(mRenderView.getLeft(), mRenderView.getTop(), + mRenderView.getRight(), mRenderView.getBottom()); } public void remove(Renderer renderer) { @@ -88,6 +92,24 @@ public class RenderOverlay extends FrameLayout { } @Override + protected boolean fitSystemWindows(Rect insets) { + if (!mInsets.equals(insets)) { + mInsets.set(insets); + // Make sure onMeasure will be called to adapt to the new insets. + requestLayout(); + } + return false; + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + // make sure all the children are resized - insets include status bar, + // navigation bar, etc, but in this case, we are only concerned with the size of nav bar + super.onMeasure(widthMeasureSpec - mInsets.right, heightMeasureSpec - mInsets.bottom); + setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); + } + + @Override public boolean dispatchTouchEvent(MotionEvent m) { if (mGestures != null) { if (!mGestures.isEnabled()) return false; diff --git a/src/com/android/camera/ui/RotateLayout.java b/src/com/android/camera/ui/RotateLayout.java index e394aba0b..d322b69f9 100644 --- a/src/com/android/camera/ui/RotateLayout.java +++ b/src/com/android/camera/ui/RotateLayout.java @@ -18,6 +18,7 @@ package com.android.camera.ui; import android.content.Context; import android.graphics.Matrix; +import android.graphics.Rect; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; @@ -32,6 +33,11 @@ public class RotateLayout extends ViewGroup implements Rotatable { private int mOrientation; private Matrix mMatrix = new Matrix(); protected View mChild; + private CameraRootView mRootView; + + public interface Child { + void onApplyWindowInsets(Rect insets, int rootWidth, int rootHeight); + } public RotateLayout(Context context, AttributeSet attrs) { super(context, attrs); @@ -42,6 +48,10 @@ public class RotateLayout extends ViewGroup implements Rotatable { setBackgroundResource(android.R.color.transparent); } + public void setRootView(CameraRootView rootView) { + mRootView = rootView; + } + @Override protected void onFinishInflate() { setupChild(getChildAt(0)); @@ -52,14 +62,22 @@ public class RotateLayout extends ViewGroup implements Rotatable { mChild = child; child.setPivotX(0); child.setPivotY(0); + applyInsetsToChild(); } } + @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; @@ -145,6 +163,7 @@ public class RotateLayout extends ViewGroup implements Rotatable { } } mOrientation = orientation; + applyInsetsToChild(); if (mChild != null) requestLayout(); } @@ -152,4 +171,12 @@ public class RotateLayout extends ViewGroup implements Rotatable { public int getOrientation() { return mOrientation; } + + private void applyInsetsToChild() { + if (mRootView != null && mChild instanceof Child) { + Rect insets = mRootView.getInsetsForOrientation(mOrientation); + final Child child = (Child) mChild; + child.onApplyWindowInsets(insets, mRootView.getWidth(), mRootView.getHeight()); + } + } } |