summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/camera/Camera.java84
-rw-r--r--src/com/android/camera/VideoCamera.java95
-rw-r--r--src/com/android/camera/ui/RotateLayout.java51
-rw-r--r--src/com/android/camera/ui/SharePopup.java159
4 files changed, 202 insertions, 187 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index 9a506a6..d1315d4 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -168,16 +168,16 @@ public class Camera extends ActivityBase implements View.OnClickListener,
private GLRootView mGLRootView;
- // A button showing the last captured picture thumbnail. Clicking on it will
- // show the share popup window.
- private RotateImageView mThumbnailButton;
// A popup window that contains a bigger thumbnail and a list of apps to share.
private SharePopup mSharePopup;
// The bitmap of the last captured picture thumbnail and the URI of the
// original picture.
private Thumbnail mThumbnail;
- // A button sharing the last picture.
- private RotateImageView mShareButton;
+ // A button that contains the thumbnail and the share icon.
+ private View mShareButton;
+ // An imageview showing showing the last captured picture thumbnail.
+ private RotateImageView mThumbnailView;
+ private RotateImageView mShareIcon;
private RotateImageView mCameraSwitchIcon;
private RotateImageView mVideoSwitchIcon;
@@ -386,7 +386,6 @@ public class Camera extends ActivityBase implements View.OnClickListener,
if (!mIsImageCaptureIntent) { // no thumbnail in image capture intent
findViewById(R.id.camera_switch).setOnClickListener(this);
initThumbnailButton();
- if (mShareButton != null) mShareButton.setOnClickListener(this);
}
// Initialize shutter button.
@@ -430,7 +429,7 @@ public class Camera extends ActivityBase implements View.OnClickListener,
}
private void initThumbnailButton() {
- mThumbnailButton.setOnClickListener(this);
+ mShareButton.setOnClickListener(this);
// Load the thumbnail from the disk.
mThumbnail = Thumbnail.loadFrom(new File(getFilesDir(), LAST_THUMB_FILENAME));
updateThumbnailButton();
@@ -443,9 +442,9 @@ public class Camera extends ActivityBase implements View.OnClickListener,
mThumbnail = Thumbnail.getLastImageThumbnail(mContentResolver);
}
if (mThumbnail != null) {
- mThumbnailButton.setBitmap(mThumbnail.getBitmap());
+ mThumbnailView.setBitmap(mThumbnail.getBitmap());
} else {
- mThumbnailButton.setBitmap(null);
+ mThumbnailView.setBitmap(null);
}
}
@@ -867,7 +866,7 @@ public class Camera extends ActivityBase implements View.OnClickListener,
int inSampleSize = Util.nextPowerOf2(ratio);
mThumbnail = Thumbnail.createThumbnail(data, orientation, inSampleSize, uri);
if (mThumbnail != null) {
- mThumbnailButton.setBitmap(mThumbnail.getBitmap());
+ mThumbnailView.setBitmap(mThumbnail.getBitmap());
}
sendBroadcast(new Intent("com.android.camera.NEW_PICTURE", uri));
}
@@ -981,8 +980,9 @@ public class Camera extends ActivityBase implements View.OnClickListener,
setContentView(R.layout.camera);
}
mFocusRectangle = (FocusRectangle) findViewById(R.id.focus_rectangle);
- mThumbnailButton = (RotateImageView) findViewById(R.id.review_thumbnail);
- mShareButton = (RotateImageView) findViewById(R.id.btn_share);
+ mShareButton = findViewById(R.id.share_button);
+ mThumbnailView = (RotateImageView) findViewById(R.id.thumbnail);
+ mShareIcon = (RotateImageView) findViewById(R.id.share_icon);
mCameraSwitchIcon = (RotateImageView) findViewById(R.id.camera_switch_icon);
mVideoSwitchIcon = (RotateImageView) findViewById(R.id.video_switch_icon);
@@ -1231,8 +1231,8 @@ public class Camera extends ActivityBase implements View.OnClickListener,
private void setOrientationIndicator(int degree) {
if (mHeadUpDisplay != null) mHeadUpDisplay.setOrientation(mOrientationCompensation);
- if (mThumbnailButton != null) mThumbnailButton.setDegree(degree);
- if (mShareButton != null) mShareButton.setDegree(degree);
+ if (mThumbnailView != null) mThumbnailView.setDegree(degree);
+ if (mShareIcon != null) mShareIcon.setDegree(degree);
if (mCameraSwitchIcon != null) mCameraSwitchIcon.setDegree(degree);
if (mVideoSwitchIcon != null) mVideoSwitchIcon.setDegree(degree);
if (mSharePopup != null) mSharePopup.setOrientation(degree);
@@ -1256,31 +1256,24 @@ public class Camera extends ActivityBase implements View.OnClickListener,
updateStorageHint();
}
+ @Override
public void onClick(View v) {
switch (v.getId()) {
+ case R.id.share_button:
+ if (isCameraIdle() && mThumbnail != null) {
+ showSharePopup();
+ }
+ break;
case R.id.btn_retake:
hidePostCaptureAlert();
startPreview();
break;
- case R.id.review_thumbnail:
- if (isCameraIdle() && mThumbnail != null) {
- Util.viewUri(mThumbnail.getUri(), this);
- }
- break;
case R.id.btn_done:
doAttach();
break;
case R.id.btn_cancel:
doCancel();
break;
- case R.id.btn_gallery:
- gotoGallery();
- break;
- case R.id.btn_share:
- if (isCameraIdle() && mThumbnail != null) {
- createSharePopup();
- }
- break;
}
}
@@ -1520,7 +1513,7 @@ public class Camera extends ActivityBase implements View.OnClickListener,
hidePostCaptureAlert();
}
- dismissSharePopup();
+ if (mSharePopup != null) mSharePopup.dismiss();
if (mDidRegister) {
unregisterReceiver(mReceiver);
@@ -2448,36 +2441,13 @@ public class Camera extends ActivityBase implements View.OnClickListener,
mNotSelectableToast.show();
}
- private void createSharePopup() {
- if (mSharePopup != null) mSharePopup.dismiss();
- mSharePopup = new SharePopup(this, mThumbnail.getUri(),
- mThumbnail.getBitmap(), mOrientationCompensation, mThumbnailButton);
- mSharePopup.showAtLocation(mThumbnailButton, Gravity.NO_GRAVITY, 0, 0);
- }
-
- private void dismissSharePopup() {
- if (mSharePopup != null) {
- mSharePopup.dismiss();
- mSharePopup = null;
- }
- }
-
- private void onShareButtonClicked() {
- if (mPausing) return;
-
- // Share the last captured picture.
- if (mThumbnail != null) {
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.setType("image/jpeg");
- intent.putExtra(Intent.EXTRA_STREAM, mThumbnail.getUri());
- startActivity(Intent.createChooser(intent, getString(R.string.share_picture_via)));
- } else { // No last picture
- if (mNoShareToast == null) {
- mNoShareToast = Toast.makeText(this,
- getResources().getString(R.string.no_picture_to_share), Toast.LENGTH_SHORT);
- }
- mNoShareToast.show();
+ private void showSharePopup() {
+ Uri uri = mThumbnail.getUri();
+ if (mSharePopup == null || !uri.equals(mSharePopup.getUri())) {
+ mSharePopup = new SharePopup(this, uri, mThumbnail.getBitmap(), "image/jpeg",
+ mOrientationCompensation, mShareButton);
}
+ mSharePopup.showAtLocation(mThumbnailView, Gravity.NO_GRAVITY, 0, 0);
}
private class MyIndicatorWheelListener implements IndicatorWheel.Listener {
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index 1e0e030..d0027f2 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -150,19 +150,19 @@ public class VideoCamera extends ActivityBase
private View mReviewControl;
private Toast mNoShareToast;
- // A button showing the last captured video thumbnail. Clicking on it will
- // show the share popup window.
- private RotateImageView mThumbnailButton;
+ // An review image having same size as preview. It is displayed when
+ // recording is stopped in capture intent.
+ private ImageView mReviewImage;
// A popup window that contains a bigger thumbnail and a list of apps to share.
private SharePopup mSharePopup;
// The bitmap of the last captured video thumbnail and the URI of the
// original video.
private Thumbnail mThumbnail;
- // An review image having same size as preview. It is displayed when
- // recording is stopped in capture intent.
- private ImageView mReviewImage;
- // A button sharing the last picture.
- private RotateImageView mShareButton;
+ // A button that contains the thumbnail and the share icon.
+ private View mShareButton;
+ // An imageview showing showing the last captured picture thumbnail.
+ private RotateImageView mThumbnailView;
+ private RotateImageView mShareIcon;
private RotateImageView mCameraSwitchIcon;
private RotateImageView mVideoSwitchIcon;
private ShutterButton mShutterButton;
@@ -406,8 +406,7 @@ public class VideoCamera extends ActivityBase
setContentView(R.layout.video_camera);
initThumbnailButton();
- mShareButton = (RotateImageView) findViewById(R.id.btn_share);
- if (mShareButton != null) mShareButton.setOnClickListener(this);
+ mShareIcon = (RotateImageView) findViewById(R.id.share_icon);
mSwitcher = (SwitcherSet) findViewById(R.id.camera_switch);
mSwitcher.setVisibility(View.VISIBLE);
mSwitcher.setOnSwitchListener(this);
@@ -418,6 +417,8 @@ public class VideoCamera extends ActivityBase
mPreviewFrameLayout.setOnSizeChangedListener(this);
mReviewImage = (ImageView) findViewById(R.id.review_image);
+ mShareButton = findViewById(R.id.share_button);
+ mShareIcon = (RotateImageView) findViewById(R.id.share_icon);
mCameraSwitchIcon = (RotateImageView) findViewById(R.id.camera_switch_icon);
mVideoSwitchIcon = (RotateImageView) findViewById(R.id.video_switch_icon);
@@ -607,8 +608,8 @@ public class VideoCamera extends ActivityBase
private void setOrientationIndicator(int degree) {
if (mHeadUpDisplay != null) mHeadUpDisplay.setOrientation(mOrientationCompensation);
- if (mThumbnailButton != null) mThumbnailButton.setDegree(degree);
- if (mShareButton != null) mShareButton.setDegree(degree);
+ if (mThumbnailView != null) mThumbnailView.setDegree(degree);
+ if (mShareIcon != null) mShareIcon.setDegree(degree);
if (mCameraSwitchIcon != null) mCameraSwitchIcon.setDegree(degree);
if (mVideoSwitchIcon != null) mVideoSwitchIcon.setDegree(degree);
if (mSharePopup != null) mSharePopup.setOrientation(degree);
@@ -623,8 +624,14 @@ public class VideoCamera extends ActivityBase
}
}
+ @Override
public void onClick(View v) {
switch (v.getId()) {
+ case R.id.share_button:
+ if (!mMediaRecorderRecording && mThumbnail != null) {
+ showSharePopup();
+ }
+ break;
case R.id.btn_retake:
deleteCurrentVideo();
hideAlert();
@@ -639,19 +646,6 @@ public class VideoCamera extends ActivityBase
stopVideoRecording();
doReturnToCaller(false);
break;
- case R.id.review_thumbnail:
- if (!mMediaRecorderRecording && mThumbnail != null) {
- Util.viewUri(mThumbnail.getUri(), this);
- }
- break;
- case R.id.btn_gallery:
- gotoGallery();
- break;
- case R.id.btn_share:
- if (!mMediaRecorderRecording && mThumbnail != null) {
- createSharePopup();
- }
- break;
}
}
@@ -981,7 +975,7 @@ public class VideoCamera extends ActivityBase
finishRecorderAndCloseCamera();
- dismissSharePopup();
+ if (mSharePopup != null) mSharePopup.dismiss();
if (mReceiver != null) {
unregisterReceiver(mReceiver);
@@ -1496,7 +1490,7 @@ public class VideoCamera extends ActivityBase
mCurrentVideoFilename, Video.Thumbnails.MINI_KIND);
if (videoFrame != null) {
mThumbnail = new Thumbnail(mCurrentVideoUri, videoFrame, 0);
- mThumbnailButton.setBitmap(mThumbnail.getBitmap());
+ mThumbnailView.setBitmap(mThumbnail.getBitmap());
}
}
}
@@ -1619,8 +1613,8 @@ public class VideoCamera extends ActivityBase
}
private void initThumbnailButton() {
- mThumbnailButton = (RotateImageView) findViewById(R.id.review_thumbnail);
- mThumbnailButton.setOnClickListener(this);
+ mThumbnailView = (RotateImageView) findViewById(R.id.thumbnail);
+ findViewById(R.id.share_button).setOnClickListener(this);
// Load the thumbnail from the disk.
mThumbnail = Thumbnail.loadFrom(new File(getFilesDir(), LAST_THUMB_FILENAME));
}
@@ -1630,9 +1624,9 @@ public class VideoCamera extends ActivityBase
mThumbnail = Thumbnail.getLastVideoThumbnail(mContentResolver);
}
if (mThumbnail != null) {
- mThumbnailButton.setBitmap(mThumbnail.getBitmap());
+ mThumbnailView.setBitmap(mThumbnail.getBitmap());
} else {
- mThumbnailButton.setBitmap(null);
+ mThumbnailView.setBitmap(null);
}
}
@@ -1921,36 +1915,13 @@ public class VideoCamera extends ActivityBase
}
- private void createSharePopup() {
- if (mSharePopup != null) mSharePopup.dismiss();
- mSharePopup = new SharePopup(this, mThumbnail.getUri(),
- mThumbnail.getBitmap(), mOrientationCompensation, mThumbnailButton);
- mSharePopup.showAtLocation(mThumbnailButton, Gravity.NO_GRAVITY, 0, 0);
- }
-
- private void dismissSharePopup() {
- if (mSharePopup != null) {
- mSharePopup.dismiss();
- mSharePopup = null;
- }
- }
-
- private void onShareButtonClicked() {
- if (mPausing) return;
-
- // Share the last captured video.
- if (mThumbnail != null) {
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.setType("video/*");
- intent.putExtra(Intent.EXTRA_STREAM, mThumbnail.getUri());
- startActivity(Intent.createChooser(intent, getString(R.string.share_video_via)));
- } else { // No last picture
- if (mNoShareToast == null) {
- mNoShareToast = Toast.makeText(this,
- getResources().getString(R.string.no_video_to_share), Toast.LENGTH_SHORT);
- }
- mNoShareToast.show();
+ private void showSharePopup() {
+ Uri uri = mThumbnail.getUri();
+ if (mSharePopup == null || !uri.equals(mSharePopup.getUri())) {
+ mSharePopup = new SharePopup(this, uri, mThumbnail.getBitmap(),
+ "video/*", mOrientationCompensation, mShareButton);
}
+ mSharePopup.showAtLocation(mThumbnailView, Gravity.NO_GRAVITY, 0, 0);
}
private class MyIndicatorWheelListener implements IndicatorWheel.Listener {
@@ -1964,10 +1935,6 @@ public class VideoCamera extends ActivityBase
public void onOverriddenPreferencesClicked() {
}
-
- public void onShareButtonClicked() {
- VideoCamera.this.onShareButtonClicked();
- }
}
private class MyCameraPickerListener implements CameraPicker.Listener {
diff --git a/src/com/android/camera/ui/RotateLayout.java b/src/com/android/camera/ui/RotateLayout.java
index 6e1aa92..c900557 100644
--- a/src/com/android/camera/ui/RotateLayout.java
+++ b/src/com/android/camera/ui/RotateLayout.java
@@ -17,15 +17,14 @@
package com.android.camera.ui;
import android.content.Context;
-import android.graphics.Canvas;
import android.util.AttributeSet;
-import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
// A RotateLayout is designed to display a single item and provides the
// capabilities to rotate the item.
class RotateLayout extends ViewGroup {
+ private static final String TAG = "RotateLayout";
private int mOrientation;
private View mChild;
@@ -36,6 +35,8 @@ class RotateLayout extends ViewGroup {
@Override
protected void onFinishInflate() {
mChild = getChildAt(0);
+ mChild.setPivotX(0);
+ mChild.setPivotY(0);
}
@Override
@@ -57,54 +58,42 @@ class RotateLayout extends ViewGroup {
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
+ int w = 0, h = 0;
switch(mOrientation) {
case 0:
case 180:
measureChild(mChild, widthSpec, heightSpec);
- setMeasuredDimension(mChild.getMeasuredWidth(), mChild.getMeasuredHeight());
+ w = mChild.getMeasuredWidth();
+ h = mChild.getMeasuredHeight();
break;
case 90:
case 270:
measureChild(mChild, heightSpec, widthSpec);
- setMeasuredDimension(mChild.getMeasuredHeight(), mChild.getMeasuredWidth());
+ w = mChild.getMeasuredHeight();
+ h = mChild.getMeasuredWidth();
break;
}
- }
+ setMeasuredDimension(w, h);
- @Override
- public void dispatchDraw(Canvas canvas) {
- int w = getWidth();
- int h = getHeight();
switch (mOrientation) {
+ case 0:
+ mChild.setTranslationX(0);
+ mChild.setTranslationY(0);
+ break;
case 90:
- canvas.translate(0, h);
- canvas.rotate(-mOrientation);
+ mChild.setTranslationX(0);
+ mChild.setTranslationY(h);
break;
case 180:
- canvas.rotate(-mOrientation, w / 2, h / 2);
+ mChild.setTranslationX(w);
+ mChild.setTranslationY(h);
break;
case 270:
- canvas.translate(w, 0);
- canvas.rotate(-mOrientation);
+ mChild.setTranslationX(w);
+ mChild.setTranslationY(0);
break;
}
- super.dispatchDraw(canvas);
- }
-
- @Override
- public boolean dispatchTouchEvent(MotionEvent event) {
- float x = event.getX();
- float y = event.getY();
- float width = getWidth();
- float height = getHeight();
- switch (mOrientation) {
- case 90: event.setLocation(height - y, x); break;
- case 180: event.setLocation(width - x, height - y); break;
- case 270: event.setLocation(y, width - x); break;
- }
- boolean result = mChild.dispatchTouchEvent(event);
- event.setLocation(x, y);
- return result;
+ mChild.setRotation(-mOrientation);
}
// Rotate the view counter-clockwise
diff --git a/src/com/android/camera/ui/SharePopup.java b/src/com/android/camera/ui/SharePopup.java
index d182e2d..fc26c90 100644
--- a/src/com/android/camera/ui/SharePopup.java
+++ b/src/com/android/camera/ui/SharePopup.java
@@ -20,7 +20,11 @@ import com.android.camera.R;
import com.android.camera.Util;
import android.app.Activity;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.ColorDrawable;
@@ -29,19 +33,41 @@ import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
+import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.WindowManager;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
+import android.widget.AdapterView;
import android.widget.ImageView;
+import android.widget.ListView;
import android.widget.PopupWindow;
+import android.widget.SimpleAdapter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
// A popup window that contains a big thumbnail and a list of apps to share.
public class SharePopup extends PopupWindow implements View.OnClickListener,
- View.OnTouchListener {
+ View.OnTouchListener, AdapterView.OnItemClickListener {
+ private static final String TAG = "SharePopup";
private Context mContext;
private Uri mUri;
+ private String mMimeType;
+ private ImageView mThumbnail;
+ private int mBitmapWidth;
+ private int mBitmapHeight;
+ // A view that contains a thumbnail and a share view.
+ private ViewGroup mRootView;
+ // A view that contains the title and the list of applications to share.
+ private View mShareView;
+ // The list of the applications to share.
+ private ListView mShareList;
+ // A rotated view that contains the share view.
+ private RotateLayout mShareViewRotateLayout;
+ // A rotated view that contains the thumbnail.
+ private RotateLayout mThumbnailRotateLayout;
+ private ArrayList<ComponentName> mComponent = new ArrayList<ComponentName>();
// The maximum width of the thumbnail in landscape orientation.
private final float mImageMaxWidthLandscape;
@@ -51,26 +77,31 @@ public class SharePopup extends PopupWindow implements View.OnClickListener,
private final float mImageMaxWidthPortrait;
// The maximum height of the thumbnail in portrait orientation.
private final float mImageMaxHeightPortrait;
+ // The width of the share list in landscape mode.
+ private final float mShareListWidthLandscape;
- private ImageView mThumbnail;
- private int mBitmapWidth, mBitmapHeight;
- private RotateLayout mRotateLayout;
-
- public SharePopup(Activity activity, Uri uri, Bitmap bitmap, int orientation, View anchor) {
+ public SharePopup(Activity activity, Uri uri, Bitmap bitmap, String mimeType, int orientation,
+ View anchor) {
super(activity);
- // Initailize variables
+ // Initialize variables
mContext = activity;
mUri = uri;
+ mMimeType = mimeType;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
- View contentView = inflater.inflate(R.layout.share_popup, null, false);
+ ViewGroup sharePopup = (ViewGroup) inflater.inflate(R.layout.share_popup, null, false);
// This is required because popup window is full screen.
- contentView.setOnTouchListener(this);
- mRotateLayout = (RotateLayout) contentView.findViewById(R.id.rotate_layout);
- mThumbnail = (ImageView) contentView.findViewById(R.id.expanded_thumbnail);
+ sharePopup.setOnTouchListener(this);
+ mShareViewRotateLayout = (RotateLayout) sharePopup.findViewById(R.id.share_view_rotate_layout);
+ mThumbnailRotateLayout = (RotateLayout) sharePopup.findViewById(R.id.thumbnail_rotate_layout);
+ mShareList = (ListView) sharePopup.findViewById(R.id.share_list);
+ mShareView = sharePopup.findViewById(R.id.share_view);
+ mThumbnail = (ImageView) sharePopup.findViewById(R.id.thumbnail);
+ mRootView = (ViewGroup) sharePopup.findViewById(R.id.root);
mThumbnail.setImageBitmap(bitmap);
mThumbnail.setOnClickListener(this);
+ sharePopup.findViewById(R.id.collapse_button).setOnClickListener(this);
mBitmapWidth = bitmap.getWidth();
mBitmapHeight = bitmap.getHeight();
Resources res = mContext.getResources();
@@ -78,57 +109,77 @@ public class SharePopup extends PopupWindow implements View.OnClickListener,
mImageMaxHeightLandscape = res.getDimension(R.dimen.share_image_max_height_landscape);
mImageMaxWidthPortrait = res.getDimension(R.dimen.share_image_max_width_portrait);
mImageMaxHeightPortrait = res.getDimension(R.dimen.share_image_max_height_portrait);
+ mShareListWidthLandscape = res.getDimension(R.dimen.share_list_width_landscape);
// Initialize popup window
setWidth(WindowManager.LayoutParams.MATCH_PARENT);
setHeight(WindowManager.LayoutParams.MATCH_PARENT);
setBackgroundDrawable(new ColorDrawable());
- setContentView(contentView);
+ setContentView(sharePopup);
setOrientation(orientation);
+ setFocusable(true);
+ setAnimationStyle(R.style.AnimationPopup);
+
+ initializeLocation(activity, anchor);
- // Initialize view location
+ createShareMenu();
+ }
+
+ private void initializeLocation(Activity activity, View anchor) {
int location[] = new int[2];
anchor.getLocationOnScreen(location);
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- MarginLayoutParams params = (MarginLayoutParams) mRotateLayout.getLayoutParams();
- params.topMargin = location[1] / 2;
- params.rightMargin = (metrics.widthPixels - location[0] - anchor.getWidth()) / 2;
- mRotateLayout.setLayoutParams(params);
-
- // Start animation
- Animation fadeIn = AnimationUtils.loadAnimation(mContext, R.anim.grow_fade_in_from_right);
- mRotateLayout.startAnimation(fadeIn);
+ MarginLayoutParams params = (MarginLayoutParams) mRootView.getLayoutParams();
+ params.topMargin = location[1];
+ params.rightMargin = (metrics.widthPixels - location[0] - anchor.getWidth());
+ mRootView.setLayoutParams(params);
}
public void setOrientation(int orientation) {
// Calculate the width and the height of the thumbnail.
- float width, height;
+ float maxWidth, maxHeight;
if (orientation == 90 || orientation == 270) {
- width = mImageMaxWidthPortrait;
- height = mImageMaxHeightPortrait;
+ maxWidth = mImageMaxWidthPortrait;
+ maxHeight = mImageMaxHeightPortrait;
} else {
- width = mImageMaxWidthLandscape;
- height = mImageMaxHeightLandscape;
+ maxWidth = mImageMaxWidthLandscape;
+ maxHeight = mImageMaxHeightLandscape;
}
+ float actualAspect = maxWidth / maxHeight;
+ float desiredAspect = (float) mBitmapWidth / mBitmapHeight;
+
LayoutParams params = mThumbnail.getLayoutParams();
- if (width * mBitmapHeight > height * mBitmapWidth) {
- params.width = Math.round(mBitmapWidth * height / mBitmapHeight);
- params.height = Math.round(height);
+ if (actualAspect > desiredAspect) {
+ params.width = Math.round(maxHeight * desiredAspect);
+ params.height = Math.round(maxHeight);
} else {
- params.width = Math.round(width);
- params.height = Math.round(mBitmapHeight * params.width / mBitmapWidth);
+ params.width = Math.round(maxWidth);
+ params.height = Math.round(maxWidth / desiredAspect);
}
mThumbnail.setLayoutParams(params);
- mRotateLayout.setOrientation(orientation);
+
+ // Calculate the width of the share application list.
+ LayoutParams shareListParams = mShareView.getLayoutParams();
+ if ((orientation == 90 || orientation == 270)) {
+ shareListParams.width = params.width;
+ } else {
+ shareListParams.width = (int) mShareListWidthLandscape;
+ }
+ mShareView.setLayoutParams(shareListParams);
+ if (mShareViewRotateLayout != null) mShareViewRotateLayout.setOrientation(orientation);
+ if (mThumbnailRotateLayout != null) mThumbnailRotateLayout.setOrientation(orientation);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
- case R.id.expanded_thumbnail:
+ case R.id.thumbnail:
Util.viewUri(mUri, mContext);
break;
+ case R.id.collapse_button:
+ dismiss();
+ break;
}
}
@@ -140,4 +191,42 @@ public class SharePopup extends PopupWindow implements View.OnClickListener,
}
return false;
}
+
+ public void createShareMenu() {
+ PackageManager packageManager = mContext.getPackageManager();
+ List<ResolveInfo> infos;
+ infos = packageManager.queryIntentActivities(
+ new Intent(Intent.ACTION_SEND).setType(mMimeType), 0);
+
+ ArrayList<HashMap<String, Object>> listItem =
+ new ArrayList<HashMap<String, Object>>();
+ for(ResolveInfo info: infos) {
+ String label = info.loadLabel(packageManager).toString();
+ ComponentName component = new ComponentName(
+ info.activityInfo.packageName, info.activityInfo.name);
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put("text", label);
+ listItem.add(map);
+ mComponent.add(component);
+ }
+ SimpleAdapter listItemAdapter = new SimpleAdapter(mContext, listItem,
+ R.layout.share_item,
+ new String[] {"text"},
+ new int[] {R.id.text});
+ mShareList.setAdapter(listItemAdapter);
+ mShareList.setOnItemClickListener(this);
+ }
+
+ public Uri getUri() {
+ return mUri;
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int index, long id) {
+ Intent intent = new Intent(Intent.ACTION_SEND);
+ intent.setType(mMimeType);
+ intent.putExtra(Intent.EXTRA_STREAM, mUri);
+ intent.setComponent(mComponent.get(index));
+ mContext.startActivity(intent);
+ }
}