diff options
author | Martijn Coenen <maco@google.com> | 2011-08-18 14:30:02 +0200 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2011-08-18 18:05:56 +0200 |
commit | d2a536159030a932486e6dfd93999f9e43f3566f (patch) | |
tree | 52793266326675f0b296c818a5a7655765c59302 /src/com/android/nfc | |
parent | 9cd9f72aeee9baeedc39ec197ed8fc09e403d0e7 (diff) | |
download | packages_apps_nfc-d2a536159030a932486e6dfd93999f9e43f3566f.zip packages_apps_nfc-d2a536159030a932486e6dfd93999f9e43f3566f.tar.gz packages_apps_nfc-d2a536159030a932486e6dfd93999f9e43f3566f.tar.bz2 |
Latest ShareTap UI: low-pass filter and animations.
Change-Id: If0c04284e1e6f1126f85a8bb58014ce553f4e52b
Diffstat (limited to 'src/com/android/nfc')
-rw-r--r-- | src/com/android/nfc/HoldingItWrongUi.java | 14 | ||||
-rw-r--r-- | src/com/android/nfc/P2pEventManager.java | 33 | ||||
-rwxr-xr-x | src/com/android/nfc/P2pLinkManager.java | 6 |
3 files changed, 39 insertions, 14 deletions
diff --git a/src/com/android/nfc/HoldingItWrongUi.java b/src/com/android/nfc/HoldingItWrongUi.java index e915662..429421d 100644 --- a/src/com/android/nfc/HoldingItWrongUi.java +++ b/src/com/android/nfc/HoldingItWrongUi.java @@ -19,14 +19,17 @@ package com.android.nfc; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.graphics.drawable.AnimationDrawable; import android.view.View; import android.view.WindowManager; +import android.widget.ImageView; import com.android.nfc3.R; public class HoldingItWrongUi implements DialogInterface.OnDismissListener { AlertDialog mDialog; + ImageView mImageView; /** Must call from UI thread */ public void show(Context context) { @@ -36,6 +39,10 @@ public class HoldingItWrongUi implements DialogInterface.OnDismissListener { View v = View.inflate(context, R.layout.holding_it_wrong, null); + mImageView = (ImageView) v.findViewById(R.id.image); + mImageView.setBackgroundResource(R.drawable.sharetap_anim); + + AlertDialog.Builder b = new AlertDialog.Builder(context); b.setCancelable(false); b.setView(v); @@ -44,6 +51,13 @@ public class HoldingItWrongUi implements DialogInterface.OnDismissListener { d.setOnDismissListener(this); d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); d.show(); + mImageView.post(new Runnable() { + @Override + public void run() { + AnimationDrawable anim = (AnimationDrawable) mImageView.getBackground(); + anim.start(); + } + }); mDialog = d; } diff --git a/src/com/android/nfc/P2pEventManager.java b/src/com/android/nfc/P2pEventManager.java index 66d8a92..70ad549 100644 --- a/src/com/android/nfc/P2pEventManager.java +++ b/src/com/android/nfc/P2pEventManager.java @@ -70,12 +70,24 @@ public class P2pEventManager implements P2pEventListener, SendUi.Callback { * 100 indicates the device must be exactly face-down. */ static final int THRESHOLD_PERCENT = 75; + /** + * Alpha (smoothing) factor of the low-pass filter. + * Decreasing helps latency in case the device is already + * tilted from the beginning, but makes the filter more sensitive + * to large changes. + */ + static final float LPF_ALPHA = 0.9f; + /** + * Mininum number of samples to take before acting on them. + */ + static final int MINIMUM_SAMPLES = 10; final SensorManager mSensorManager; final Sensor mSensor; // Only used on UI thread boolean mSensorEnabled; float mLastValue; + int mNumSamples; public TiltDetector(Context context) { mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); @@ -87,8 +99,9 @@ public class P2pEventManager implements P2pEventListener, SendUi.Callback { return; } mSensorEnabled = true; - mLastValue = Float.MIN_VALUE; - mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_UI); + mLastValue = 0; + mNumSamples = 0; + mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_FASTEST); } public void disable() { if (!mSensorEnabled) { @@ -103,19 +116,21 @@ public class P2pEventManager implements P2pEventListener, SendUi.Callback { if (!mSensorEnabled) { return; } - final float z = event.values[2]; + final float z = LPF_ALPHA * mLastValue + (1 - LPF_ALPHA) * event.values[2]; final boolean triggered = 100.0 * z / SensorManager.GRAVITY_EARTH > THRESHOLD_PERCENT; - //TODO: apply a low pass filter so we get something closer to real gravity + mNumSamples++; if (DBG) Log.d(TAG, "z=" + z + (triggered ? " TRIGGERED" : "")); - if (mLastValue == Float.MIN_VALUE && !triggered) { - // Received first value, and you're holding it wrong - mHoldingItWrongUi.show(mContext); + if (mNumSamples == MINIMUM_SAMPLES) { + if (!triggered) { + // Received first value, and you're holding it wrong + mHoldingItWrongUi.show(mContext); + } } - mLastValue = z; - if (triggered) { + if (triggered && mNumSamples >= MINIMUM_SAMPLES) { disable(); onSendConfirmed(); } + mLastValue = z; return; } @Override diff --git a/src/com/android/nfc/P2pLinkManager.java b/src/com/android/nfc/P2pLinkManager.java index c3f9fc6..75c2d0d 100755 --- a/src/com/android/nfc/P2pLinkManager.java +++ b/src/com/android/nfc/P2pLinkManager.java @@ -96,11 +96,7 @@ public class P2pLinkManager implements Handler.Callback, P2pEventListener.Callba // TODO dynamically assign SAP values static final int NDEFPUSH_SAP = 0x10; - static final int LINK_DEBOUNCE_MS = 750; - - static final int STATE_WAITING = 0; - static final int STATE_SUCCESS = 1; - static final int STATE_FAILURE = 2; + static final int LINK_DEBOUNCE_MS = 500; static final int MSG_DEBOUNCE_TIMEOUT = 1; static final int MSG_RECEIVE_COMPLETE = 2; |