diff options
author | Andres Morales <anmorales@google.com> | 2014-10-14 00:35:26 +0000 |
---|---|---|
committer | Andres Morales <anmorales@google.com> | 2014-10-14 13:33:51 -0700 |
commit | 65ba8d0d2adb1d1994a0c40d11e28d9ca85f50d9 (patch) | |
tree | 3e82239b49ac9b5afaff1e0d3ca8080e4e4fd735 | |
parent | 1ed9fb37431002d39d9e34c6a73b3d0397827ef5 (diff) | |
download | android_packages_apps_Nfc-65ba8d0d2adb1d1994a0c40d11e28d9ca85f50d9.tar.gz android_packages_apps_Nfc-65ba8d0d2adb1d1994a0c40d11e28d9ca85f50d9.tar.bz2 android_packages_apps_Nfc-65ba8d0d2adb1d1994a0c40d11e28d9ca85f50d9.zip |
Revert "Do Beam UI outside NFC persistent process"
This reverts commit 018e05b5f55cd444835e8dd751b30eaaccd2c9ff.
Change-Id: Iec6610b7b08d003c81adbfd0ec368bd245e10330
-rwxr-xr-x | AndroidManifest.xml | 4 | ||||
-rw-r--r-- | src/com/android/nfc/FireflyRenderer.java | 16 | ||||
-rw-r--r-- | src/com/android/nfc/P2pEventManager.java | 207 | ||||
-rw-r--r-- | src/com/android/nfc/SendUi.java (renamed from src/com/android/nfc/SendUiService.java) | 258 |
4 files changed, 137 insertions, 348 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c1d6cbed..56ef3d41 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -128,9 +128,5 @@ <service android:name=".handover.HandoverService" android:process=":handover" /> - - <service android:name=".SendUiService" - android:process=":sendui" - /> </application> </manifest> diff --git a/src/com/android/nfc/FireflyRenderer.java b/src/com/android/nfc/FireflyRenderer.java index 1b73f307..40c931d1 100644 --- a/src/com/android/nfc/FireflyRenderer.java +++ b/src/com/android/nfc/FireflyRenderer.java @@ -24,12 +24,6 @@ import android.graphics.SurfaceTexture; import android.opengl.GLUtils; import android.util.Log; -import javax.microedition.khronos.egl.EGL10; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.egl.EGLContext; -import javax.microedition.khronos.egl.EGLDisplay; -import javax.microedition.khronos.egl.EGLSurface; -import javax.microedition.khronos.opengles.GL10; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -37,6 +31,13 @@ import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.ShortBuffer; +import javax.microedition.khronos.egl.EGL10; +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.egl.EGLContext; +import javax.microedition.khronos.egl.EGLDisplay; +import javax.microedition.khronos.egl.EGLSurface; +import javax.microedition.khronos.opengles.GL10; + public class FireflyRenderer { private static final String LOG_TAG = "NfcFireflyThread"; @@ -347,9 +348,6 @@ public class FireflyRenderer { if (mEglContext != null) { mEgl.eglDestroyContext(mEglDisplay, mEglContext); } - - mEgl.eglTerminate(mEglDisplay); - mEgl.eglReleaseThread(); } private EGLConfig chooseEglConfig() { diff --git a/src/com/android/nfc/P2pEventManager.java b/src/com/android/nfc/P2pEventManager.java index b51f07d3..f5db5443 100644 --- a/src/com/android/nfc/P2pEventManager.java +++ b/src/com/android/nfc/P2pEventManager.java @@ -17,39 +17,25 @@ package com.android.nfc; import android.app.NotificationManager; -import android.content.ComponentName; import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; import android.content.res.Configuration; -import android.os.Bundle; -import android.os.Handler; -import android.os.IBinder; -import android.os.Message; -import android.os.Messenger; -import android.os.RemoteException; import android.os.Vibrator; -import android.util.Log; /** * Manages vibration, sound and animation for P2P events. */ -public class P2pEventManager implements P2pEventListener { +public class P2pEventManager implements P2pEventListener, SendUi.Callback { static final String TAG = "NfcP2pEventManager"; static final boolean DBG = true; static final long[] VIBRATION_PATTERN = {0, 100, 10000}; - private static final int RETRY_DELAY_MILLIS = 100; - private static final long SERVICE_WAIT_TIMEOUT_MILLIS = 10000; final Context mContext; final NfcService mNfcService; final P2pEventListener.Callback mCallback; final Vibrator mVibrator; final NotificationManager mNotificationManager; - Messenger mService; - - boolean mBinding; + final SendUi mSendUi; // only used on UI thread boolean mSending; @@ -57,69 +43,7 @@ public class P2pEventManager implements P2pEventListener { boolean mNdefReceived; boolean mInDebounce; - static final int MSG_ON_BEAM_CANCELLED = 1; - static final int MSG_ON_SEND_CONFIRMED = 2; - static final int MSG_RETRY_SEND_MESSAGE = 3; - - private final Messenger mMessenger; - private final Handler mHandler = new MessageHandler(); - - class MessageHandler extends Handler { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_ON_SEND_CONFIRMED: - onSendConfirmed(); - break; - case MSG_ON_BEAM_CANCELLED: - onBeamCanceled(); - break; - case MSG_RETRY_SEND_MESSAGE: - trySendMessage((Message) msg.obj, false); - break; - default: - Log.e(TAG, "unhandled message: " + msg.what); - break; - } - } - } - - private Object mLock = new Object(); - private ServiceConnection mConnection = new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - synchronized (mLock) { - mBinding = false; - mService = new Messenger(service); - Log.d(TAG, "Service bound"); - - // Register client - Message msg = Message.obtain(null, SendUiService.MSG_REGISTER_CLIENT); - msg.replyTo = mMessenger; - try { - mService.send(msg); - mLock.notifyAll(); - } catch (RemoteException ex) { - Log.e(TAG, "unable to communicate with SendUiService", ex); - mService = null; - mContext.unbindService(this); - bindServiceLocked(); - } - } - } - - @Override - public void onServiceDisconnected(ComponentName name) { - synchronized (mLock) { - Log.v(TAG, "service disconnected"); - mService = null; - mBinding = true; // service crashed, will re-bind automatically - } - } - }; - public P2pEventManager(Context context, P2pEventListener.Callback callback) { - mMessenger = new Messenger(mHandler); mNfcService = NfcService.getInstance(); mContext = context; mCallback = callback; @@ -128,22 +52,15 @@ public class P2pEventManager implements P2pEventListener { Context.NOTIFICATION_SERVICE); mSending = false; - bindServiceLocked(); // don't need to acquire the lock as we're in the constructor - } - - private boolean bindServiceLocked() { - if (mService != null || mBinding) return true; - final int uiModeType = mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK; if (uiModeType == Configuration.UI_MODE_TYPE_APPLIANCE) { - return false; + // "Appliances" don't intrinsically have a way of confirming this, so we + // don't use the UI and just autoconfirm where necessary. + // Don't instantiate SendUi or else we'll use memory and never reclaim it. + mSendUi = null; } else { - mBinding = true; - Log.v(TAG, "Binding service..."); - mContext.bindService(new Intent(mContext, SendUiService.class), mConnection, - Context.BIND_SHOWING_UI | Context.BIND_AUTO_CREATE); - return true; + mSendUi = new SendUi(context, this); } } @@ -155,7 +72,9 @@ public class P2pEventManager implements P2pEventListener { mInDebounce = false; mVibrator.vibrate(VIBRATION_PATTERN, -1); - trySendMessage(Message.obtain(null, SendUiService.MSG_TAKE_SCREENSHOT), true); + if (mSendUi != null) { + mSendUi.takeScreenshot(); + } } @Override @@ -166,20 +85,24 @@ public class P2pEventManager implements P2pEventListener { mInDebounce = false; mVibrator.vibrate(VIBRATION_PATTERN, -1); - trySendMessage(Message.obtain(null, SendUiService.MSG_TAKE_SCREENSHOT), true); - trySendMessage(Message.obtain(null, - SendUiService.MSG_SHOW_PRESEND, /* promptToTap */ 1, 0), true); + if (mSendUi != null) { + mSendUi.takeScreenshot(); + mSendUi.showPreSend(true); + } } @Override public void onP2pTimeoutWaitingForLink() { - trySendMessage(Message.obtain( - null, SendUiService.MSG_FINISH, SendUiService.FINISH_SCALE_UP, 0), true); + if (mSendUi != null) { + mSendUi.finish(SendUi.FINISH_SCALE_UP); + } } @Override public void onP2pSendConfirmationRequested() { - if (!trySendMessage(Message.obtain(null, SendUiService.MSG_SHOW_PRESEND), true)) { + if (mSendUi != null) { + mSendUi.showPreSend(false); + } else { mCallback.onP2pSendConfirmed(); } } @@ -188,8 +111,9 @@ public class P2pEventManager implements P2pEventListener { public void onP2pSendComplete() { mNfcService.playSound(NfcService.SOUND_END); mVibrator.vibrate(VIBRATION_PATTERN, -1); - trySendMessage(Message.obtain(null, - SendUiService.MSG_FINISH, SendUiService.FINISH_SEND_SUCCESS, 0), true); + if (mSendUi != null) { + mSendUi.finish(SendUi.FINISH_SEND_SUCCESS); + } mSending = false; mNdefSent = true; } @@ -198,13 +122,8 @@ public class P2pEventManager implements P2pEventListener { public void onP2pHandoverNotSupported() { mNfcService.playSound(NfcService.SOUND_ERROR); mVibrator.vibrate(VIBRATION_PATTERN, -1); - Message msg = Message.obtain( - null, SendUiService.MSG_FINISH, SendUiService.FINISH_SCALE_UP, 0); - Bundle bundle = new Bundle(); - bundle.putString(SendUiService.EXTRA_TOAST_MESSAGE, + mSendUi.finishAndToast(SendUi.FINISH_SCALE_UP, mContext.getString(R.string.beam_handover_not_supported)); - msg.setData(bundle); - trySendMessage(msg, true); mSending = false; mNdefSent = false; } @@ -213,15 +132,16 @@ public class P2pEventManager implements P2pEventListener { public void onP2pReceiveComplete(boolean playSound) { mVibrator.vibrate(VIBRATION_PATTERN, -1); if (playSound) mNfcService.playSound(NfcService.SOUND_END); - // TODO we still don't have a nice receive solution - // The sanest solution right now is just to scale back up what we had - // and start the new activity. It is not perfect, but at least it is - // consistent behavior. All other variants involve making the old - // activity screenshot disappear, and then removing the animation - // window hoping the new activity has started by then. This just goes - // wrong too often and can look weird. - trySendMessage(Message.obtain( - null, SendUiService.MSG_FINISH, SendUiService.FINISH_SCALE_UP, 0), true); + if (mSendUi != null) { + // TODO we still don't have a nice receive solution + // The sanest solution right now is just to scale back up what we had + // and start the new activity. It is not perfect, but at least it is + // consistent behavior. All other variants involve making the old + // activity screenshot disappear, and then removing the animation + // window hoping the new activity has started by then. This just goes + // wrong too often and can look weird. + mSendUi.finish(SendUi.FINISH_SCALE_UP); + } mNdefReceived = true; } @@ -231,25 +151,27 @@ public class P2pEventManager implements P2pEventListener { mNfcService.playSound(NfcService.SOUND_ERROR); mSending = false; } - if (!mNdefSent && !mNdefReceived) { - trySendMessage(Message.obtain( - null, SendUiService.MSG_FINISH, SendUiService.FINISH_SCALE_UP, 0), true); + if (!mNdefSent && !mNdefReceived && mSendUi != null) { + mSendUi.finish(SendUi.FINISH_SCALE_UP); } mInDebounce = false; } + @Override public void onSendConfirmed() { if (!mSending) { - trySendMessage(Message.obtain(null, SendUiService.MSG_SHOW_START_SEND), true); + if (mSendUi != null) { + mSendUi.showStartSend(); + } mCallback.onP2pSendConfirmed(); } mSending = true; } - public void onBeamCanceled() { - trySendMessage(Message.obtain(null, SendUiService.MSG_FINISH, - SendUiService.FINISH_SCALE_UP, 0), true); + @Override + public void onCanceled() { + mSendUi.finish(SendUi.FINISH_SCALE_UP); mCallback.onP2pCanceled(); } @@ -257,7 +179,9 @@ public class P2pEventManager implements P2pEventListener { public void onP2pSendDebounce() { mInDebounce = true; mNfcService.playSound(NfcService.SOUND_ERROR); - trySendMessage(Message.obtain(null, SendUiService.MSG_SHOW_SEND_HINT), true); + if (mSendUi != null) { + mSendUi.showSendHint(); + } } @Override @@ -265,44 +189,11 @@ public class P2pEventManager implements P2pEventListener { if (mInDebounce) { mVibrator.vibrate(VIBRATION_PATTERN, -1); mNfcService.playSound(NfcService.SOUND_START); - trySendMessage(Message.obtain(null, SendUiService.MSG_SHOW_START_SEND), true); - } - mInDebounce = false; - } - - private boolean trySendMessage(Message message, boolean retry) { - synchronized (mLock) { - // service should already be bound, but make sure anyway - if (bindServiceLocked()) { - while (mBinding) { - try { - mLock.wait(SERVICE_WAIT_TIMEOUT_MILLIS); - if (mService == null) { - // bail out if waited for timeout but service never came up - return false; - } - } catch (InterruptedException e) {} - } - - try { - mService.send(message); - } catch (RemoteException e) { - Log.e(TAG, "unable to communicate with SendUiService", e); - if (retry) { - Message msg = Message.obtain(null, MSG_RETRY_SEND_MESSAGE); - msg.obj = message; - mHandler.sendMessageDelayed(msg, RETRY_DELAY_MILLIS); - } else { - mService = null; - bindServiceLocked(); - } - } - - return true; - } else { - return false; + if (mSendUi != null) { + mSendUi.showStartSend(); } } + mInDebounce = false; } } diff --git a/src/com/android/nfc/SendUiService.java b/src/com/android/nfc/SendUi.java index f03b7178..dec529c4 100644 --- a/src/com/android/nfc/SendUiService.java +++ b/src/com/android/nfc/SendUi.java @@ -16,16 +16,16 @@ package com.android.nfc; +import com.android.internal.policy.PolicyManager; + import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.animation.TimeAnimator; import android.app.ActivityManager; -import android.app.Service; import android.app.StatusBarManager; import android.content.Context; -import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.graphics.Bitmap; @@ -35,12 +35,6 @@ import android.graphics.PixelFormat; import android.graphics.SurfaceTexture; import android.os.AsyncTask; import android.os.Binder; -import android.os.Handler; -import android.os.IBinder; -import android.os.Message; -import android.os.Messenger; -import android.os.Process; -import android.os.RemoteException; import android.util.DisplayMetrics; import android.util.Log; import android.view.ActionMode; @@ -64,7 +58,6 @@ import android.view.animation.DecelerateInterpolator; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; -import com.android.internal.policy.PolicyManager; /** * This class is responsible for handling the UI animation @@ -89,10 +82,9 @@ import com.android.internal.policy.PolicyManager; * * All methods of this class must be called on the UI thread */ -public class SendUiService extends Service - implements Animator.AnimatorListener, View.OnTouchListener, TimeAnimator.TimeListener, - TextureView.SurfaceTextureListener, android.view.Window.Callback { - static final String TAG = "SendUiService"; +public class SendUi implements Animator.AnimatorListener, View.OnTouchListener, + TimeAnimator.TimeListener, TextureView.SurfaceTextureListener, android.view.Window.Callback { + static final String TAG = "SendUi"; static final float INTERMEDIATE_SCALE = 0.6f; @@ -132,32 +124,22 @@ public class SendUiService extends Service static final int STATE_SENDING = 8; static final int STATE_COMPLETE = 9; - static final int MSG_TAKE_SCREENSHOT = 1; - static final int MSG_SHOW_PRESEND = 2; - static final int MSG_SHOW_START_SEND = 3; - static final int MSG_SHOW_SEND_HINT = 4; - static final int MSG_FINISH = 5; - static final int MSG_REGISTER_CLIENT = 6; - static final int MSG_RETRY_REPLY = 7; - - static final String EXTRA_TOAST_MESSAGE = "android.nfc.extra.sendui.TOAST_MESSAGE"; - - private static final int RETRY_DELAY_MILLIS = 100; - // all members are only used on UI thread - WindowManager mWindowManager; - Display mDisplay; - DisplayMetrics mDisplayMetrics; - Matrix mDisplayMatrix; - WindowManager.LayoutParams mWindowLayoutParams; - LayoutInflater mLayoutInflater; - StatusBarManager mStatusBarManager; - View mScreenshotLayout; - ImageView mScreenshotView; - ImageView mBlackLayer; - TextureView mTextureView; - TextView mTextHint; - TextView mTextRetry; + final WindowManager mWindowManager; + final Context mContext; + final Display mDisplay; + final DisplayMetrics mDisplayMetrics; + final Matrix mDisplayMatrix; + final WindowManager.LayoutParams mWindowLayoutParams; + final LayoutInflater mLayoutInflater; + final StatusBarManager mStatusBarManager; + final View mScreenshotLayout; + final ImageView mScreenshotView; + final ImageView mBlackLayer; + final TextureView mTextureView; + final TextView mTextHint; + final TextView mTextRetry; + final Callback mCallback; // The mFrameCounter animation is purely used to count down a certain // number of (vsync'd) frames. This is needed because the first 3 @@ -168,17 +150,17 @@ public class SendUiService extends Service // Wait for hw surface => start frame counter => start pre-animation after 3 frames // For platforms where no hw acceleration can be used, the pre-animation // is started immediately. - TimeAnimator mFrameCounterAnimator; - - ObjectAnimator mPreAnimator; - ObjectAnimator mSlowSendAnimator; - ObjectAnimator mFastSendAnimator; - ObjectAnimator mFadeInAnimator; - ObjectAnimator mHintAnimator; - ObjectAnimator mScaleUpAnimator; - ObjectAnimator mAlphaDownAnimator; - ObjectAnimator mAlphaUpAnimator; - AnimatorSet mSuccessAnimatorSet; + final TimeAnimator mFrameCounterAnimator; + + final ObjectAnimator mPreAnimator; + final ObjectAnimator mSlowSendAnimator; + final ObjectAnimator mFastSendAnimator; + final ObjectAnimator mFadeInAnimator; + final ObjectAnimator mHintAnimator; + final ObjectAnimator mScaleUpAnimator; + final ObjectAnimator mAlphaDownAnimator; + final ObjectAnimator mAlphaUpAnimator; + final AnimatorSet mSuccessAnimatorSet; // Besides animating the screenshot, the Beam UI also renders // fireflies on platforms where we can do hardware-acceleration. @@ -187,8 +169,8 @@ public class SendUiService extends Service // that animation becoming janky. Likewise, the fireflies are // stopped in their tracks as soon as we finish the animation, // to make the finishing animation smooth. - boolean mHardwareAccelerated; - FireflyRenderer mFireflyRenderer; + final boolean mHardwareAccelerated; + final FireflyRenderer mFireflyRenderer; String mToastString; Bitmap mScreenshotBitmap; @@ -203,67 +185,24 @@ public class SendUiService extends Service int mSurfaceWidth; int mSurfaceHeight; - private final Messenger mMessenger; - private final Handler mHandler = new MessageHandler(); - Messenger mClient; - - class MessageHandler extends Handler { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_TAKE_SCREENSHOT: - takeScreenshot(); - break; - case MSG_SHOW_PRESEND: - boolean promptToTap = (msg.arg1 != 0); - showPreSend(promptToTap); - break; - case MSG_SHOW_START_SEND: - showStartSend(); - break; - case MSG_FINISH: - if (msg.obj != null) { - finishAndToast(msg.arg1, (String) msg.obj); - } else { - finish(msg.arg1); - } - break; - case MSG_SHOW_SEND_HINT: - showSendHint(); - break; - case MSG_REGISTER_CLIENT: - mClient = msg.replyTo; - break; - case MSG_RETRY_REPLY: - tryReply(msg.arg1, false); - break; - default: - Log.e(TAG, "unhandled message: " + msg.what); - break; - } - } + interface Callback { + public void onSendConfirmed(); + public void onCanceled(); } - @Override - public IBinder onBind(Intent intent) { - return mMessenger.getBinder(); - } + public SendUi(Context context, Callback callback) { + mContext = context; + mCallback = callback; - public SendUiService() { - mMessenger = new Messenger(mHandler); - } - - @Override - public void onCreate() { - super.onCreate(); mDisplayMetrics = new DisplayMetrics(); mDisplayMatrix = new Matrix(); - mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); - mStatusBarManager = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); + mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE); mDisplay = mWindowManager.getDefaultDisplay(); - mLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mLayoutInflater = (LayoutInflater) + context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mScreenshotLayout = mLayoutInflater.inflate(R.layout.screenshot, null); mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.screenshot); @@ -286,8 +225,8 @@ public class SendUiService extends Service ViewGroup.LayoutParams.MATCH_PARENT, 0, 0, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_FULLSCREEN - | hwAccelerationFlags - | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, + | hwAccelerationFlags + | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.OPAQUE); mWindowLayoutParams.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; @@ -305,7 +244,8 @@ public class SendUiService extends Service PropertyValuesHolder postX = PropertyValuesHolder.ofFloat("scaleX", SEND_SCREENSHOT_SCALE); PropertyValuesHolder postY = PropertyValuesHolder.ofFloat("scaleY", SEND_SCREENSHOT_SCALE); - PropertyValuesHolder alphaDown = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f); + PropertyValuesHolder alphaDown = PropertyValuesHolder.ofFloat("alpha", + new float[]{1.0f, 0.0f}); mSlowSendAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, postX, postY); mSlowSendAnimator.setInterpolator(new DecelerateInterpolator()); @@ -317,13 +257,10 @@ public class SendUiService extends Service mFastSendAnimator.setDuration(FAST_SEND_DURATION_MS); mFastSendAnimator.addListener(this); - PropertyValuesHolder scaleUpX = - PropertyValuesHolder.ofFloat("scaleX", SCALE_UP_SCREENSHOT_SCALE); - PropertyValuesHolder scaleUpY = - PropertyValuesHolder.ofFloat("scaleY", SCALE_UP_SCREENSHOT_SCALE); + PropertyValuesHolder scaleUpX = PropertyValuesHolder.ofFloat("scaleX", SCALE_UP_SCREENSHOT_SCALE); + PropertyValuesHolder scaleUpY = PropertyValuesHolder.ofFloat("scaleY", SCALE_UP_SCREENSHOT_SCALE); - mScaleUpAnimator = ObjectAnimator.ofPropertyValuesHolder( - mScreenshotView, scaleUpX, scaleUpY); + mScaleUpAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, scaleUpX, scaleUpY); mScaleUpAnimator.setInterpolator(new DecelerateInterpolator()); mScaleUpAnimator.setDuration(SCALE_UP_DURATION_MS); mScaleUpAnimator.addListener(this); @@ -356,15 +293,15 @@ public class SendUiService extends Service // Create a Window with a Decor view; creating a window allows us to get callbacks // on key events (which require a decor view to be dispatched). - setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen); - Window window = PolicyManager.makeNewWindow(this); + mContext.setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen); + Window window = PolicyManager.makeNewWindow(mContext); window.setCallback(this); window.requestFeature(Window.FEATURE_NO_TITLE); mDecor = window.getDecorView(); window.setContentView(mScreenshotLayout, mWindowLayoutParams); if (mHardwareAccelerated) { - mFireflyRenderer = new FireflyRenderer(this); + mFireflyRenderer = new FireflyRenderer(context); } else { mFireflyRenderer = null; } @@ -410,7 +347,7 @@ public class SendUiService extends Service // Update display metrics mDisplay.getRealMetrics(mDisplayMetrics); - final int statusBarHeight = getResources().getDimensionPixelSize( + final int statusBarHeight = mContext.getResources().getDimensionPixelSize( com.android.internal.R.dimen.status_bar_height); mBlackLayer.setVisibility(View.GONE); @@ -424,9 +361,9 @@ public class SendUiService extends Service mScreenshotLayout.requestFocus(); if (promptToNfcTap) { - mTextHint.setText(getResources().getString(R.string.ask_nfc_tap)); + mTextHint.setText(mContext.getResources().getString(R.string.ask_nfc_tap)); } else { - mTextHint.setText(getResources().getString(R.string.touch)); + mTextHint.setText(mContext.getResources().getString(R.string.touch)); } mTextHint.setAlpha(0.0f); mTextHint.setVisibility(View.VISIBLE); @@ -438,7 +375,7 @@ public class SendUiService extends Service // So we have to use SENSOR_LANDSCAPE or SENSOR_PORTRAIT to make sure // we lock in portrait / landscape and have the sensor determine // which way is up. - int orientation = getResources().getConfiguration().orientation; + int orientation = mContext.getResources().getConfiguration().orientation; switch (orientation) { case Configuration.ORIENTATION_LANDSCAPE: @@ -475,15 +412,17 @@ public class SendUiService extends Service // Update the starting scale - touchscreen-mashers may trigger // this before the pre-animation completes. float currentScale = mScreenshotView.getScaleX(); - PropertyValuesHolder postX = PropertyValuesHolder.ofFloat("scaleX", currentScale, 0.0f); - PropertyValuesHolder postY = PropertyValuesHolder.ofFloat("scaleY", currentScale, 0.0f); + PropertyValuesHolder postX = PropertyValuesHolder.ofFloat("scaleX", + new float[] {currentScale, 0.0f}); + PropertyValuesHolder postY = PropertyValuesHolder.ofFloat("scaleY", + new float[] {currentScale, 0.0f}); mSlowSendAnimator.setValues(postX, postY); float currentAlpha = mBlackLayer.getAlpha(); if (mBlackLayer.isShown() && currentAlpha > 0.0f) { - PropertyValuesHolder alphaDown = - PropertyValuesHolder.ofFloat("alpha", currentAlpha, 0.0f); + PropertyValuesHolder alphaDown = PropertyValuesHolder.ofFloat("alpha", + new float[] {currentAlpha, 0.0f}); mAlphaDownAnimator.setValues(alphaDown); mAlphaDownAnimator.start(); } @@ -537,27 +476,27 @@ public class SendUiService extends Service if (finishMode == FINISH_SCALE_UP) { mBlackLayer.setVisibility(View.GONE); PropertyValuesHolder scaleUpX = PropertyValuesHolder.ofFloat("scaleX", - currentScale, 1.0f); + new float[] {currentScale, 1.0f}); PropertyValuesHolder scaleUpY = PropertyValuesHolder.ofFloat("scaleY", - currentScale, 1.0f); + new float[] {currentScale, 1.0f}); PropertyValuesHolder scaleUpAlpha = PropertyValuesHolder.ofFloat("alpha", - currentAlpha, 1.0f); + new float[] {currentAlpha, 1.0f}); mScaleUpAnimator.setValues(scaleUpX, scaleUpY, scaleUpAlpha); mScaleUpAnimator.start(); } else if (finishMode == FINISH_SEND_SUCCESS){ // Modify the fast send parameters to match the current scale PropertyValuesHolder postX = PropertyValuesHolder.ofFloat("scaleX", - currentScale, 0.0f); + new float[] {currentScale, 0.0f}); PropertyValuesHolder postY = PropertyValuesHolder.ofFloat("scaleY", - currentScale, 0.0f); + new float[] {currentScale, 0.0f}); PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", - currentAlpha, 0.0f); + new float[] {currentAlpha, 0.0f}); mFastSendAnimator.setValues(postX, postY, alpha); // Reset the fadeIn parameters to start from alpha 1 PropertyValuesHolder fadeIn = PropertyValuesHolder.ofFloat("alpha", - 0.0f, 1.0f); + new float[] {0.0f, 1.0f}); mFadeInAnimator.setValues(fadeIn); mSlowSendAnimator.cancel(); @@ -568,37 +507,26 @@ public class SendUiService extends Service void dismiss() { if (mState < STATE_W4_TOUCH) return; - // Immediately set to IDLE, to prevent .cancel() calls // below from immediately calling into dismiss() again. // (They can do so on the same thread). mState = STATE_IDLE; mSurface = null; mFrameCounterAnimator.cancel(); - mFrameCounterAnimator.removeAllListeners(); mPreAnimator.cancel(); - mPreAnimator.removeAllListeners(); mSlowSendAnimator.cancel(); - mSlowSendAnimator.removeAllListeners(); mFastSendAnimator.cancel(); - mFastSendAnimator.removeAllListeners(); mSuccessAnimatorSet.cancel(); - mSuccessAnimatorSet.removeAllListeners(); mScaleUpAnimator.cancel(); - mScaleUpAnimator.removeAllListeners(); mAlphaUpAnimator.cancel(); - mAlphaUpAnimator.removeAllListeners(); mAlphaDownAnimator.cancel(); - mAlphaDownAnimator.removeAllListeners(); mWindowManager.removeView(mDecor); mStatusBarManager.disable(StatusBarManager.DISABLE_NONE); mScreenshotBitmap = null; if (mToastString != null) { - Toast.makeText(this, mToastString, Toast.LENGTH_LONG).show(); + Toast.makeText(mContext, mToastString, Toast.LENGTH_LONG).show(); } - mToastString = null; - Process.killProcess(Process.myPid() ); } /** @@ -647,7 +575,7 @@ public class SendUiService extends Service Log.e(TAG, "Invalid state on screenshot completion: " + Integer.toString(mState)); } } - } + }; /** * Returns a screenshot of the current display contents. @@ -657,21 +585,21 @@ public class SendUiService extends Service // take screenshots only in the natural orientation of the device :!) mDisplay.getRealMetrics(mDisplayMetrics); - boolean hasNavBar = getResources().getBoolean( + boolean hasNavBar = mContext.getResources().getBoolean( com.android.internal.R.bool.config_showNavigationBar); float[] dims = {mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels}; float degrees = getDegreesForRotation(mDisplay.getRotation()); - final int statusBarHeight = getResources().getDimensionPixelSize( + final int statusBarHeight = mContext.getResources().getDimensionPixelSize( com.android.internal.R.dimen.status_bar_height); // Navbar has different sizes, depending on orientation - final int navBarHeight = hasNavBar ? getResources().getDimensionPixelSize( + final int navBarHeight = hasNavBar ? mContext.getResources().getDimensionPixelSize( com.android.internal.R.dimen.navigation_bar_height) : 0; - final int navBarHeightLandscape = hasNavBar ? getResources().getDimensionPixelSize( + final int navBarHeightLandscape = hasNavBar ? mContext.getResources().getDimensionPixelSize( com.android.internal.R.dimen.navigation_bar_height_landscape) : 0; - final int navBarWidth = hasNavBar ? getResources().getDimensionPixelSize( + final int navBarWidth = hasNavBar ? mContext.getResources().getDimensionPixelSize( com.android.internal.R.dimen.navigation_bar_width) : 0; boolean requiresRotation = (degrees > 0); @@ -786,7 +714,7 @@ public class SendUiService extends Service mFrameCounterAnimator.cancel(); mPreAnimator.cancel(); - tryReply(P2pEventManager.MSG_ON_SEND_CONFIRMED, true); + mCallback.onSendConfirmed(); return true; } @@ -829,11 +757,11 @@ public class SendUiService extends Service mBlackLayer.setVisibility(View.VISIBLE); mTextHint.setVisibility(View.GONE); - mTextRetry.setText(getResources().getString(R.string.beam_try_again)); + mTextRetry.setText(mContext.getResources().getString(R.string.beam_try_again)); mTextRetry.setVisibility(View.VISIBLE); PropertyValuesHolder alphaUp = PropertyValuesHolder.ofFloat("alpha", - mBlackLayer.getAlpha(), 0.9f); + new float[] {mBlackLayer.getAlpha(), 0.9f}); mAlphaUpAnimator.setValues(alphaUp); mAlphaUpAnimator.start(); } @@ -842,7 +770,7 @@ public class SendUiService extends Service public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_BACK) { - tryReply(P2pEventManager.MSG_ON_BEAM_CANCELLED, false); + mCallback.onCanceled(); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { @@ -853,30 +781,6 @@ public class SendUiService extends Service } } - private void tryReply(int what, boolean retry) { - if (mClient != null) { - Message message = Message.obtain(null, what); - try { - mClient.send(message); - } catch (RemoteException e) { - if (retry) { - Log.e(TAG, "failed to communicate with NFC process, retrying", e); - Message msg = Message.obtain(null, MSG_RETRY_REPLY); - msg.arg1 = message.what; - mHandler.sendMessageDelayed(msg, RETRY_DELAY_MILLIS); - } else { - Log.e(TAG, "failed to communicate with NFC process, aborting"); - Process.killProcess(Process.myPid()); - } - } - } else { - // should never happen as the remote unbinds if it fails to register mClient - // kill the process in case it's somehow in a runaway state taking up memory - Log.e(TAG, "inconsistent state in SendUiService, killing"); - Process.killProcess(Process.myPid()); - } - } - @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { return false; |