diff options
author | Martijn Coenen <maco@google.com> | 2011-10-11 16:37:29 -0700 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2011-10-11 16:37:29 -0700 |
commit | 90e1b000b385d7fa11481ddca4d61d6b425d7579 (patch) | |
tree | daef84dc62d15df0ab2a8d30b303f3f8dde71360 /src | |
parent | e59ab8f4cfcbfb2d17fe264dbaec65e6bd708e05 (diff) | |
download | packages_apps_nfc-90e1b000b385d7fa11481ddca4d61d6b425d7579.zip packages_apps_nfc-90e1b000b385d7fa11481ddca4d61d6b425d7579.tar.gz packages_apps_nfc-90e1b000b385d7fa11481ddca4d61d6b425d7579.tar.bz2 |
NFC: Remove statusbar/navbar from animated screenshot.
This just crops the status bar and the navbar from the screenshot we take.
This makes the animation look right in all cases, except for when we are full screen:
in that scenario we're cropping away too much.
Also removed the clone view (was no longer used) and cleaned FireflyRenderer
a bit.
Bug: 5318512
Change-Id: I37189a576f19937c2cae4ec368f26ac0725a1b62
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/nfc/FireflyRenderThread.java | 6 | ||||
-rw-r--r-- | src/com/android/nfc/SendUi.java | 56 |
2 files changed, 39 insertions, 23 deletions
diff --git a/src/com/android/nfc/FireflyRenderThread.java b/src/com/android/nfc/FireflyRenderThread.java index 6fec5e5..5019ffb 100644 --- a/src/com/android/nfc/FireflyRenderThread.java +++ b/src/com/android/nfc/FireflyRenderThread.java @@ -338,8 +338,6 @@ public class FireflyRenderThread extends Thread { float mX; // between -mDisplayHeight and mDisplayHeight float mY; // between -mDisplayWidth and mDisplayWidth float mZ; // between 0.0 (near) and 1.0 (far) - float mX0; - float mY0; float mZ0; float mT; float mScale; @@ -350,8 +348,8 @@ public class FireflyRenderThread extends Thread { } void reset() { - mX0 = mX = (float) (Math.random() * mDisplayWidth) * 4 - 2 * mDisplayWidth; - mY0 = mY = (float) (Math.random() * mDisplayHeight) * 4 - 2 * mDisplayHeight; + mX = (float) (Math.random() * mDisplayWidth) * 4 - 2 * mDisplayWidth; + mY = (float) (Math.random() * mDisplayHeight) * 4 - 2 * mDisplayHeight; mZ0 = mZ = (float) (Math.random()) * 2 - 1; mT = 0f; mScale = 1.5f; diff --git a/src/com/android/nfc/SendUi.java b/src/com/android/nfc/SendUi.java index 5b5c34c..e65e184 100644 --- a/src/com/android/nfc/SendUi.java +++ b/src/com/android/nfc/SendUi.java @@ -94,7 +94,6 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, final StatusBarManager mStatusBarManager; final View mScreenshotLayout; final ImageView mScreenshotView; - final ImageView mCloneView; final ImageView mBackgroundImage; final TextureView mTextureView; final TextView mTextHint; @@ -136,8 +135,6 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.screenshot); mScreenshotLayout.setFocusable(true); - mCloneView = (ImageView) mScreenshotLayout.findViewById(R.id.clone); - mTextHint = (TextView) mScreenshotLayout.findViewById(R.id.calltoaction); mTextureView = (TextureView) mScreenshotLayout.findViewById(R.id.fireflies); @@ -179,7 +176,7 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, mSlowSendAnimator.setInterpolator(new DecelerateInterpolator()); mSlowSendAnimator.setDuration(SLOW_SEND_DURATION_MS); - mFastCloneAnimator = ObjectAnimator.ofPropertyValuesHolder(mCloneView, postX, postY); + mFastCloneAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, postX, postY); mFastCloneAnimator.setInterpolator(new DecelerateInterpolator()); mFastCloneAnimator.setDuration(FAST_CLONE_DURATION_MS); @@ -221,6 +218,12 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, /** Show pre-send animation */ public void showPreSend() { + // Update display metrics + mDisplay.getRealMetrics(mDisplayMetrics); + + final int statusBarHeight = mContext.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.status_bar_height); + if (mScreenshotBitmap == null || mAttached) { return; } @@ -228,12 +231,9 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, mScreenshotView.setImageBitmap(mScreenshotBitmap); mScreenshotView.setTranslationX(0f); mScreenshotView.setAlpha(1.0f); - mScreenshotLayout.requestFocus(); + mScreenshotView.setPadding(0, statusBarHeight, 0, 0); - mCloneView.setImageBitmap(mScreenshotBitmap); - mCloneView.setVisibility(View.GONE); - mCloneView.setScaleX(INTERMEDIATE_SCALE); - mCloneView.setScaleY(INTERMEDIATE_SCALE); + mScreenshotLayout.requestFocus(); mTextHint.setAlpha(0.0f); mTextHint.setVisibility(View.VISIBLE); @@ -291,15 +291,8 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, mSlowSendAnimator.cancel(); mTextHint.setVisibility(View.GONE); - float currentScale = mScreenshotView.getScaleX(); - mScreenshotView.setAlpha(0.0f); - mScreenshotView.setScaleX(1.0f); - mScreenshotView.setScaleY(1.0f); - // Make the clone visible for scaling to the background - mCloneView.setScaleX(currentScale); - mCloneView.setScaleY(currentScale); - mCloneView.setVisibility(View.VISIBLE); + float currentScale = mScreenshotView.getScaleX(); // Modify the fast clone parameters to match the current scale PropertyValuesHolder postX = PropertyValuesHolder.ofFloat("scaleX", @@ -387,8 +380,6 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, /** * Returns a screenshot of the current display contents. - * @param context Context. - * @return */ Bitmap createScreenshot() { // We need to orient the screenshot correctly (and the Surface api seems to @@ -398,6 +389,14 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, float[] dims = {mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels}; float degrees = getDegreesForRotation(mDisplay.getRotation()); + final int statusBarHeight = mContext.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.status_bar_height); + // Navbar has different sizes, depending on orientation + final int navBarHeight = mContext.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.navigation_bar_height); + final int navBarWidth = mContext.getResources().getDimensionPixelSize( + com.android.internal.R.dimen.navigation_bar_width); + boolean requiresRotation = (degrees > 0); if (requiresRotation) { // Get the dimensions of the device in its native orientation @@ -414,6 +413,7 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, return null; } + if (requiresRotation) { // Rotate the screenshot to the current orientation Bitmap ss = Bitmap.createBitmap(mDisplayMetrics.widthPixels, @@ -427,6 +427,24 @@ public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, bitmap = ss; } + // TODO this is somewhat device-specific; need generic solution. + // Crop off the status bar and the nav bar + // Portrait: 0, statusBarHeight, width, height - status - nav + // Landscape: 0, statusBarHeight, width - navBar, height - status + int newLeft = 0; + int newTop = statusBarHeight; + int newWidth = bitmap.getWidth(); + int newHeight = bitmap.getHeight(); + if (bitmap.getWidth() < bitmap.getHeight()) { + // Portrait mode: status bar is at the top, navbar bottom, width unchanged + newHeight = bitmap.getHeight() - statusBarHeight - navBarHeight; + } else { + // Landscape mode: status bar is at the top, navbar right + newHeight = bitmap.getHeight() - statusBarHeight; + newWidth = bitmap.getWidth() - navBarWidth; + } + bitmap = Bitmap.createBitmap(bitmap, newLeft, newTop, newWidth, newHeight); + return bitmap; } |