diff options
author | Wei Huang <weih@google.com> | 2011-11-11 07:58:40 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-11-11 07:58:40 -0800 |
commit | aaf41bcd841e8b1de39d770ebf9fa59399a7826b (patch) | |
tree | f517415c1a09c9a389e1f88c5906c76c3ea29eec | |
parent | 450396c1c56565c8b9ec1ccafbdd36de2d6ce313 (diff) | |
parent | abd82edfae4ab1a39fe7000dd22b7cab26e9fdaf (diff) | |
download | LegacyCamera-aaf41bcd841e8b1de39d770ebf9fa59399a7826b.zip LegacyCamera-aaf41bcd841e8b1de39d770ebf9fa59399a7826b.tar.gz LegacyCamera-aaf41bcd841e8b1de39d770ebf9fa59399a7826b.tar.bz2 |
Merge "Adjust share UI to full-width." into ics-mr1
-rw-r--r-- | res/layout-sw600dp/share_popup.xml | 47 | ||||
-rw-r--r-- | res/layout/share_popup.xml | 62 | ||||
-rw-r--r-- | src/com/android/camera/ui/SharePopup.java | 70 | ||||
-rw-r--r-- | src/com/android/camera/ui/StackLayout.java | 59 |
4 files changed, 153 insertions, 85 deletions
diff --git a/res/layout-sw600dp/share_popup.xml b/res/layout-sw600dp/share_popup.xml index 900d646..96b39e1 100644 --- a/res/layout-sw600dp/share_popup.xml +++ b/res/layout-sw600dp/share_popup.xml @@ -26,34 +26,39 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left|center"> - <RelativeLayout android:id="@+id/share_view" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@drawable/border_last_picture"> - <com.android.camera.ui.RotateLayout - android:id="@+id/thumbnail_rotate_layout" + <com.android.camera.ui.RotateLayout + android:id="@+id/thumbnail_rotate_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true"> + <!-- The size of the thumbnail is calculated in SharePopup.java --> + <FrameLayout android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentTop="true" - android:layout_alignParentLeft="true"> - <!-- The size of the thumbnail is calculated in SharePopup.java --> - <FrameLayout + android:layout_height="wrap_content" > + <com.android.camera.ui.StackLayout android:layout_width="wrap_content" - android:layout_height="wrap_content" > + android:layout_height="wrap_content"> <ImageView android:id="@+id/thumbnail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitCenter"/> - <ImageView android:id="@+id/play" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_gravity="center" - android:scaleType="center" - style="@style/ReviewPlayIcon"/> - </FrameLayout> - </com.android.camera.ui.RotateLayout> - </RelativeLayout> + <View + android:id="@+id/thumbnail_image_frame" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="0dp" + android:background="@drawable/border_last_picture" + android:clickable="true"/> + </com.android.camera.ui.StackLayout> + <ImageView android:id="@+id/play" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:scaleType="center" + style="@style/ReviewPlayIcon"/> + </FrameLayout> + </com.android.camera.ui.RotateLayout> <LinearLayout android:layout_width="@dimen/share_item_width" android:layout_height="match_parent" diff --git a/res/layout/share_popup.xml b/res/layout/share_popup.xml index aa70cf9..19b2152 100644 --- a/res/layout/share_popup.xml +++ b/res/layout/share_popup.xml @@ -19,42 +19,46 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:camera="http://schemas.android.com/apk/res/com.android.camera" - android:layout_height="match_parent" android:layout_width="match_parent" + android:layout_height="match_parent" android:background="@color/share_popup_background"> <FrameLayout android:id="@+id/root" - android:layout_height="wrap_content" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:layout_gravity="left|center"> - <RelativeLayout android:id="@+id/share_view" - android:layout_height="wrap_content" + <com.android.camera.ui.RotateLayout + android:id="@+id/thumbnail_rotate_layout" android:layout_width="wrap_content" - android:layout_gravity="center" - android:background="@drawable/border_last_picture"> - <com.android.camera.ui.RotateLayout - android:id="@+id/thumbnail_rotate_layout" - android:layout_height="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="bottom"> + <!-- The size of the thumbnail is calculated in SharePopup.java --> + <FrameLayout android:layout_width="wrap_content" - android:layout_alignParentBottom="true" - android:layout_alignParentRight="true"> - <!-- The size of the thumbnail is calculated in SharePopup.java --> - <FrameLayout + android:layout_height="wrap_content" > + <com.android.camera.ui.StackLayout android:layout_width="wrap_content" - android:layout_height="wrap_content" > + android:layout_height="wrap_content"> <ImageView android:id="@+id/thumbnail" - android:layout_height="wrap_content" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitCenter"/> - <ImageView android:id="@+id/play" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_gravity="center" - android:scaleType="center" - style="@style/ReviewPlayIcon"/> - </FrameLayout> - </com.android.camera.ui.RotateLayout> - </RelativeLayout> + <View + android:id="@+id/thumbnail_image_frame" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="0dp" + android:background="@drawable/border_last_picture" + android:clickable="true"/> + </com.android.camera.ui.StackLayout> + <ImageView android:id="@+id/play" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:scaleType="center" + style="@style/ReviewPlayIcon"/> + </FrameLayout> + </com.android.camera.ui.RotateLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="@dimen/share_item_height" @@ -64,14 +68,14 @@ android:layout_alignParentRight="true" android:id="@+id/goto_gallery_button_rotate" android:layout_centerVertical="true" - android:layout_height="match_parent" - android:layout_width="@dimen/share_item_height"> + android:layout_width="wrap_content" + android:layout_height="match_parent"> <ImageButton android:id="@+id/goto_gallery_button" android:background="?android:attr/selectableItemBackground" - android:layout_height="match_parent" - android:layout_width="match_parent" - android:scaleType="center" + android:layout_gravity="center" + android:layout_width="wrap_content" + android:layout_height="wrap_content" android:src="@drawable/ic_gallery" /> </com.android.camera.ui.RotateLayout> <View diff --git a/src/com/android/camera/ui/SharePopup.java b/src/com/android/camera/ui/SharePopup.java index 134b7c0..c54a38b 100644 --- a/src/com/android/camera/ui/SharePopup.java +++ b/src/com/android/camera/ui/SharePopup.java @@ -31,6 +31,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -38,10 +39,10 @@ import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import android.widget.AdapterView; -import android.widget.ImageView; +import android.widget.FrameLayout; import android.widget.GridView; +import android.widget.ImageView; import android.widget.PopupWindow; -import android.widget.RelativeLayout; import android.widget.SimpleAdapter; import java.util.ArrayList; @@ -61,17 +62,17 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, private int mBitmapWidth; private int mBitmapHeight; private int mOrientation; - // A view that contains a thumbnail and an arrow icon. - private ViewGroup mShareView; + private int mActivityOrientation; // A view that contains a list of application icons and the share view. private View mRootView; // The list of the application icons. private GridView mShareList; - // A rotated view that contains the thumbnail. + // A rotated view that contains the thumbnail and the play icon. private RotateLayout mThumbnailRotateLayout; private RotateLayout mGotoGalleryRotate; private View mPreviewFrame; private ArrayList<ComponentName> mComponent = new ArrayList<ComponentName>(); + private View mImageViewFrame; private class MySimpleAdapter extends SimpleAdapter { public MySimpleAdapter(Context context, List<? extends Map<String, ?>> data, @@ -94,7 +95,7 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, public boolean setViewValue(final View view, final Object data, final String text) { if (view instanceof ImageView) { - ((ImageView)view).setImageDrawable((Drawable) data); + ((ImageView) view).setImageDrawable((Drawable) data); return true; } return false; @@ -105,6 +106,8 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, View previewFrame) { super(activity); + mActivityOrientation = activity.getRequestedOrientation(); + // Initialize variables mContext = activity; mUri = uri; @@ -114,14 +117,18 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, ViewGroup sharePopup = (ViewGroup) inflater.inflate(R.layout.share_popup, null, false); // This is required because popup window is full screen. sharePopup.setOnTouchListener(this); - mThumbnailRotateLayout = (RotateLayout) sharePopup.findViewById(R.id.thumbnail_rotate_layout); + mThumbnailRotateLayout = + (RotateLayout) sharePopup.findViewById(R.id.thumbnail_rotate_layout); mShareList = (GridView) sharePopup.findViewById(R.id.share_list); mThumbnail = (ImageView) sharePopup.findViewById(R.id.thumbnail); mThumbnail.setImageBitmap(bitmap); - mShareView = (ViewGroup) sharePopup.findViewById(R.id.share_view); - mShareView.setOnClickListener(this); + mImageViewFrame = + (View) sharePopup.findViewById(R.id.thumbnail_image_frame); + mImageViewFrame.setOnClickListener(this); - mGotoGalleryRotate =(RotateLayout) sharePopup.findViewById(R.id.goto_gallery_button_rotate); + + mGotoGalleryRotate = + (RotateLayout) sharePopup.findViewById(R.id.goto_gallery_button_rotate); sharePopup.findViewById(R.id.goto_gallery_button).setOnClickListener(this); mBitmapWidth = bitmap.getWidth(); @@ -157,31 +164,27 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, } private void adjustThumbnailPosition() { - RelativeLayout.LayoutParams lpOld = - (RelativeLayout.LayoutParams) mThumbnailRotateLayout.getLayoutParams(); - RelativeLayout.LayoutParams lpNew = - new RelativeLayout.LayoutParams(lpOld.width, lpOld.height); + FrameLayout.LayoutParams lpOld = + (FrameLayout.LayoutParams) mThumbnailRotateLayout.getLayoutParams(); + FrameLayout.LayoutParams lpNew = + new FrameLayout.LayoutParams(lpOld.width, lpOld.height); mRootView.setBackgroundDrawable(null); if (mBitmapWidth > mBitmapHeight * 2 || mBitmapHeight > mBitmapWidth * 2) { // panorama image - lpNew.addRule(RelativeLayout.CENTER_HORIZONTAL); - lpNew.addRule(RelativeLayout.CENTER_VERTICAL); + lpNew.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL; // panorama images block the preview from showing in the background // use a special color here for that. mRootView.setBackgroundColor( mContext.getResources().getColor(R.color.share_popup_blackout)); - } else if (mBitmapWidth > mBitmapHeight) { - // landscape image - lpNew.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - lpNew.addRule(RelativeLayout.ALIGN_PARENT_TOP); - lpNew.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); } else { - // portrait image - lpNew.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - lpNew.addRule(RelativeLayout.ALIGN_PARENT_TOP); - lpNew.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + // landscape or portrait image + if (mActivityOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { + lpNew.gravity = Gravity.BOTTOM; + } else { + lpNew.gravity = Gravity.RIGHT; + } } mThumbnailRotateLayout.setLayoutParams(lpNew); @@ -192,13 +195,11 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, int hPaddingRootView = mRootView.getPaddingLeft() + mRootView.getPaddingRight(); int vPaddingRootView = mRootView.getPaddingTop() + mRootView.getPaddingBottom(); - int hPadding = mShareView.getPaddingLeft() + mShareView.getPaddingRight(); - int vPadding = mShareView.getPaddingTop() + mShareView.getPaddingBottom(); // Calculate the width and the height of the thumbnail. Reserve the // space for paddings. - float maxWidth = mPreviewFrame.getWidth() - hPadding - hPaddingRootView; - float maxHeight = mPreviewFrame.getHeight() - vPadding - vPaddingRootView; + float maxWidth = mPreviewFrame.getWidth() - hPaddingRootView; + float maxHeight = mPreviewFrame.getHeight() - vPaddingRootView; // Swap the width and height if it is portrait mode. if (orientation == 90 || orientation == 270) { float temp = maxWidth; @@ -209,10 +210,10 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, float desiredAspect = (float) mBitmapWidth / mBitmapHeight; if (mMimeType.startsWith("video/")) { - desiredAspect = 4F/3F; + desiredAspect = 4F / 3F; mThumbnail.setScaleType(ImageView.ScaleType.CENTER_CROP); } else { - mThumbnail.setScaleType(ImageView.ScaleType.CENTER_INSIDE); + mThumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER); } LayoutParams params = mThumbnail.getLayoutParams(); @@ -250,7 +251,7 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, public void onClick(View v) { switch (v.getId()) { case R.id.goto_gallery_button: - case R.id.share_view: + case R.id.thumbnail_image_frame: Util.viewUri(mUri, mContext); break; } @@ -271,7 +272,7 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, new Intent(Intent.ACTION_SEND).setType(mMimeType), 0); ArrayList<HashMap<String, Object>> items = new ArrayList<HashMap<String, Object>>(); - for (ResolveInfo info: infos) { + for (ResolveInfo info : infos) { ComponentName component = new ComponentName( info.activityInfo.packageName, info.activityInfo.name); HashMap<String, Object> map = new HashMap<String, Object>(); @@ -282,8 +283,7 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, // On phone UI, we have to know how many icons in the grid view before // the view is measured. - if (((Activity) mContext).getRequestedOrientation() - == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { + if (mActivityOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { mShareList.setNumColumns(items.size()); } diff --git a/src/com/android/camera/ui/StackLayout.java b/src/com/android/camera/ui/StackLayout.java new file mode 100644 index 0000000..ab08d2f --- /dev/null +++ b/src/com/android/camera/ui/StackLayout.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2011 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.camera.ui; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; + +// A layout designed to make the children same size as the first child. +public class StackLayout extends ViewGroup { + private static final String TAG = "StackLayout"; + + public StackLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + final int count = getChildCount(); + + // Measure only the first child. + final View child = getChildAt(0); + measureChild(child, widthMeasureSpec, heightMeasureSpec); + + // Ignore the paddings. + int width = child.getMeasuredWidth(); + int height = child.getMeasuredHeight(); + + setMeasuredDimension(resolveSize(width, widthMeasureSpec), + resolveSize(height, heightMeasureSpec)); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + final int count = super.getChildCount(); + + for (int i = 0; i < count; i++) { + final View child = getChildAt(i); + if (child.getVisibility() != View.GONE) { + child.layout(0, 0, r - l, b - t); + } + } + } +} |