示例#1
0
            public void OnSensorChanged(SensorEvent e)
            {
                try
                {
                    now = e.Timestamp;
                    x   = e.Values[0];
                    y   = e.Values[1];
                    z   = e.Values[2];

                    if (lastUpdate == 0)
                    {
                        lastUpdate = now;
                        lastShake  = now;
                        lastX      = x;
                        lastY      = y;
                        lastZ      = z;
                    }
                    else
                    {
                        timeDiff = now - lastUpdate;
                        if (timeDiff <= 0)
                        {
                            return;
                        }

                        force = Math.Abs(x + y + z - lastX - lastY - lastZ);
                        if (Float.Compare(force, Threshold) > 0)
                        {
                            if (now - lastShake >= Interval)
                            {
                                listener.OnShake(force);
                            }

                            lastShake = now;
                        }
                        lastX      = x;
                        lastY      = y;
                        lastZ      = z;
                        lastUpdate = now;
                    }
                }
                finally
                {
                    listener.OnAccelerationChanged(x, y, z);
                }
            }