Reformat to Android style guidelines

Change-Id: Ib9d7e39464a246dbaae38e00fbb325f153f89f65
This commit is contained in:
Mathias Agopian
2010-08-16 16:13:24 -07:00
parent a7c85d9235
commit a37be42f9f

View File

@@ -72,8 +72,8 @@ public class AccelerometerPlayActivity extends Activity {
mDisplay = mWindowManager.getDefaultDisplay();
// Create a bright wake lock
mWakeLock = mPowerManager.newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass().getName());
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass()
.getName());
// instantiate our simulation view and set it as the activity's content
mSimulationView = new SimulationView(this);
@@ -112,8 +112,7 @@ public class AccelerometerPlayActivity extends Activity {
class SimulationView extends View implements SensorEventListener {
// diameter of the balls in meters
private static final float sBallDiameter = 0.004f;
private static final float sBallDiameter2 = sBallDiameter
* sBallDiameter;
private static final float sBallDiameter2 = sBallDiameter * sBallDiameter;
// friction of the virtual table and air
private static final float sFriction = 0.1f;
@@ -166,39 +165,28 @@ public class AccelerometerPlayActivity extends Activity {
final float gy = -sy * m;
/*
* <20>F = mA <=> A = <20>F / m
*
* We could simplify the code by completely eliminating "m" (the
* mass) from all the equations, but it would hide the concepts
* from this sample code.
* <20>F = mA <=> A = <20>F / m We could simplify the code by
* completely eliminating "m" (the mass) from all the equations,
* but it would hide the concepts from this sample code.
*/
final float invm = 1.0f / m;
final float ax = gx * invm;
final float ay = gy * invm;
/*
* Time-corrected Verlet integration
*
* The position Verlet integrator is defined as
*
* x(t+<2B>t) = x(t) + x(t) - x(t-<2D>t) + a(t)<29>t<EFBFBD>2
*
* However, the above equation doesn't handle variable <20>t very
* well, a time-corrected version is needed:
*
* x(t+<2B>t) = x(t) + (x(t) - x(t-<2D>t)) * (<28>t/<2F>t_prev) + a(t)<29>t<EFBFBD>2
*
*
* We also add a simple friction term (f) to the equation:
*
* x(t+<2B>t) = x(t) + (1-f) * (x(t) - x(t-<2D>t)) * (<28>t/<2F>t_prev) +
* a(t)<29>t<EFBFBD>2
* Time-corrected Verlet integration The position Verlet
* integrator is defined as x(t+<2B>t) = x(t) + x(t) - x(t-<2D>t) +
* a(t)<29>t<EFBFBD>2 However, the above equation doesn't handle variable
* <20>t very well, a time-corrected version is needed: x(t+<2B>t) =
* x(t) + (x(t) - x(t-<2D>t)) * (<28>t/<2F>t_prev) + a(t)<29>t<EFBFBD>2 We also add
* a simple friction term (f) to the equation: x(t+<2B>t) = x(t) +
* (1-f) * (x(t) - x(t-<2D>t)) * (<28>t/<2F>t_prev) + a(t)<29>t<EFBFBD>2
*/
final float dTdT = dT * dT;
final float x = mPosX + mOneMinusFriction * dTC
* (mPosX - mLastPosX) + mAccelX * dTdT;
final float y = mPosY + mOneMinusFriction * dTC
* (mPosY - mLastPosY) + mAccelY * dTdT;
final float x = mPosX + mOneMinusFriction * dTC * (mPosX - mLastPosX) + mAccelX
* dTdT;
final float y = mPosY + mOneMinusFriction * dTC * (mPosY - mLastPosY) + mAccelY
* dTdT;
mLastPosX = mPosX;
mLastPosY = mPosY;
mPosX = x;
@@ -254,8 +242,7 @@ public class AccelerometerPlayActivity extends Activity {
private void updatePositions(float sx, float sy, long timestamp) {
final long t = timestamp;
if (mLastT != 0) {
final float dT = (float) (t - mLastT)
* (1.0f / 1000000000.0f);
final float dT = (float) (t - mLastT) * (1.0f / 1000000000.0f);
if (mLastDeltaT != 0) {
final float dTC = dT / mLastDeltaT;
final int count = mBalls.length;
@@ -309,8 +296,7 @@ public class AccelerometerPlayActivity extends Activity {
dd = dx * dx + dy * dy;
// simulate the spring
final float d = (float) Math.sqrt(dd);
final float c = (0.5f * (sBallDiameter - d))
/ d;
final float c = (0.5f * (sBallDiameter - d)) / d;
curr.mPosX -= dx * c;
curr.mPosY -= dy * c;
ball.mPosX += dx * c;
@@ -348,8 +334,7 @@ public class AccelerometerPlayActivity extends Activity {
* of the acceleration. As an added benefit, we use less power and
* CPU resources.
*/
mSensorManager.registerListener(this, mAccelerometer,
SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
}
public void stopSimulation() {
@@ -358,8 +343,7 @@ public class AccelerometerPlayActivity extends Activity {
public SimulationView(Context context) {
super(context);
mAccelerometer = mSensorManager
.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
@@ -369,18 +353,15 @@ public class AccelerometerPlayActivity extends Activity {
mMetersToPixelsY = mYDpi / 0.0254f;
// rescale the ball so it's about 0.5 cm on screen
Bitmap ball = BitmapFactory.decodeResource(getResources(),
R.drawable.ball);
Bitmap ball = BitmapFactory.decodeResource(getResources(), R.drawable.ball);
final int dstWidth = (int) (sBallDiameter * mMetersToPixelsX + 0.5f);
final int dstHeight = (int) (sBallDiameter * mMetersToPixelsY + 0.5f);
mBitmap = Bitmap
.createScaledBitmap(ball, dstWidth, dstHeight, true);
mBitmap = Bitmap.createScaledBitmap(ball, dstWidth, dstHeight, true);
Options opts = new Options();
opts.inDither = true;
opts.inPreferredConfig = Bitmap.Config.RGB_565;
mWood = BitmapFactory.decodeResource(getResources(),
R.drawable.wood, opts);
mWood = BitmapFactory.decodeResource(getResources(), R.drawable.wood, opts);
}
@Override
@@ -400,13 +381,10 @@ public class AccelerometerPlayActivity extends Activity {
/*
* record the accelerometer data, the event's timestamp as well as
* the current time. The latter is needed so we can calculate the
* "present" time during rendering.
*
* In this application, we need to take into account how the
* screen is rotated with respect to the sensors (which always
* return data in a coordinate space aligned to with the screen
* in its native orientation).
*
* "present" time during rendering. In this application, we need to
* take into account how the screen is rotated with respect to the
* sensors (which always return data in a coordinate space aligned
* to with the screen in its native orientation).
*/
switch (mDisplay.getRotation()) {
@@ -447,8 +425,7 @@ public class AccelerometerPlayActivity extends Activity {
*/
final ParticleSystem particleSystem = mParticleSystem;
final long now = mSensorTimeStamp
+ (System.nanoTime() - mCpuTimeStamp);
final long now = mSensorTimeStamp + (System.nanoTime() - mCpuTimeStamp);
final float sx = mSensorX;
final float sy = mSensorY;