Skip to content

Commit 81de5a0

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Stop animating when not showing." into jb-dev
2 parents 85aea36 + aa0a3b6 commit 81de5a0

File tree

5 files changed

+38
-53
lines changed

5 files changed

+38
-53
lines changed

core/java/com/android/internal/app/PlatLogoActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected void onCreate(Bundle savedInstanceState) {
9292
getWindowManager().getDefaultDisplay().getMetrics(metrics);
9393

9494
mContent = new ImageView(this);
95-
mContent.setImageResource(com.android.internal.R.drawable.platlogo);
95+
mContent.setImageResource(com.android.internal.R.drawable.platlogo_alt);
9696
mContent.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
9797

9898
final int p = (int)(32 * metrics.density);
@@ -102,7 +102,7 @@ protected void onCreate(Bundle savedInstanceState) {
102102
@Override
103103
public void onClick(View v) {
104104
mToast.show();
105-
mContent.setImageResource(com.android.internal.R.drawable.platlogo_alt);
105+
mContent.setImageResource(com.android.internal.R.drawable.platlogo);
106106
}
107107
});
108108

5.07 KB
Loading
-5.07 KB
Loading

packages/SystemUI/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
android:allowBackup="false"
5656
android:hardwareAccelerated="true"
5757
android:label="@string/app_label"
58-
android:icon="@drawable/ic_launcher_settings">
58+
android:icon="@*android:drawable/platlogo">
5959

6060
<!-- Broadcast receiver that gets the broadcast at boot time and starts
6161
up everything else.

packages/SystemUI/src/com/android/systemui/BeanBag.java

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ static float mag(float x, float y) {
8181
return (float) Math.sqrt(x*x+y*y);
8282
}
8383

84+
static float clamp(float x, float a, float b) {
85+
return ((x<a)?a:((x>b)?b:x));
86+
}
87+
8488
static float dot(float x1, float y1, float x2, float y2) {
8589
return x1*x2+y1+y2;
8690
}
@@ -149,6 +153,7 @@ public class Bean extends ImageView {
149153
public boolean grabbed;
150154
public float grabx, graby;
151155
public long grabtime;
156+
private float grabx_offset, graby_offset;
152157

153158
public Bean(Context context, AttributeSet as) {
154159
super(context, as);
@@ -236,17 +241,20 @@ public boolean onTouchEvent(MotionEvent e) {
236241
switch (e.getAction()) {
237242
case MotionEvent.ACTION_DOWN:
238243
grabbed = true;
244+
grabx_offset = e.getRawX() - x;
245+
graby_offset = e.getRawY() - y;
239246
va = 0;
240247
// fall
241248
case MotionEvent.ACTION_MOVE:
242-
grabx = e.getRawX();
243-
graby = e.getRawY();
249+
grabx = e.getRawX() - grabx_offset;
250+
graby = e.getRawY() - graby_offset;
244251
grabtime = e.getEventTime();
245252
break;
246253
case MotionEvent.ACTION_CANCEL:
247254
case MotionEvent.ACTION_UP:
248255
grabbed = false;
249-
va = randfrange(-5,5);
256+
float a = randsign() * clamp(mag(vx, vy) * 0.33f, 0, 1080f);
257+
va = randfrange(a*0.5f, a);
250258
break;
251259
}
252260
return true;
@@ -308,47 +316,6 @@ public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime)
308316
if (!(v2 instanceof Bean)) continue;
309317
Bean nv2 = (Bean) v2;
310318
final float overlap = nv.overlap(nv2);
311-
if (false && overlap < 0) {
312-
// angle pointing from nv2 to nv
313-
final float dx = nv.x - nv2.x;
314-
final float dy = nv.y - nv2.y;
315-
final float ang = (float) Math.atan2(dx, dy);
316-
317-
if (false) {
318-
nv.vx -= Math.cos(ang) * overlap * 0.5f;
319-
nv.vy -= Math.sin(ang) * overlap * 0.5f;
320-
nv2.vx += Math.cos(ang) * overlap * 0.5f;
321-
nv2.vy += Math.sin(ang) * overlap * 0.5f;
322-
}
323-
324-
325-
// first, move them apart
326-
nv.x -= Math.cos(ang) * overlap/2;
327-
nv.y -= Math.sin(ang) * overlap/2;
328-
nv2.x += Math.cos(ang) * overlap/2;
329-
nv2.y += Math.sin(ang) * overlap/2;
330-
331-
// next, figure out velocities
332-
final float sap = 0f; // randfrange(0,0.25f);
333-
334-
final float mag1 = mag(nv.vx, nv.vy) * (1f-sap);
335-
final float mag2 = mag(nv2.vx, nv2.vy) * (1f-sap);
336-
337-
338-
// hacky way to transfer "momentum"
339-
nv.vx = mag2 * (float)Math.cos(ang);
340-
nv.vy = mag2 * (float)Math.sin(ang);
341-
nv2.vx = -mag1 * (float)Math.cos(ang);
342-
nv2.vy = -mag1 * (float)Math.sin(ang);
343-
344-
final float totalva = nv.va + nv2.va;
345-
final float frac = randfrange(0.25f,0.75f);
346-
nv.va = totalva * frac;
347-
nv2.va = totalva * (1f-frac);
348-
// nv.va += randfrange(-20,20);
349-
// nv2.va += randfrange(-20,20);
350-
351-
}
352319
}
353320

354321
nv.setRotation(nv.a);
@@ -375,17 +342,28 @@ protected void onSizeChanged (int w, int h, int oldw, int oldh) {
375342
boardWidth = w;
376343
boardHeight = h;
377344
// android.util.Log.d("Nyandroid", "resized: " + w + "x" + h);
378-
post(new Runnable() { public void run() {
379-
reset();
345+
}
346+
347+
public void startAnimation() {
348+
stopAnimation();
349+
if (mAnim == null) {
350+
post(new Runnable() { public void run() {
351+
reset();
352+
startAnimation();
353+
} });
354+
} else {
380355
mAnim.start();
381-
} });
356+
}
382357
}
383358

359+
public void stopAnimation() {
360+
if (mAnim != null) mAnim.cancel();
361+
}
384362

385363
@Override
386364
protected void onDetachedFromWindow() {
387365
super.onDetachedFromWindow();
388-
mAnim.cancel();
366+
stopAnimation();
389367
}
390368

391369
@Override
@@ -428,12 +406,19 @@ public void onStart() {
428406
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
429407
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
430408
);
409+
mBoard = new Board(this, null);
410+
setContentView(mBoard);
411+
}
412+
413+
@Override
414+
public void onPause() {
415+
super.onPause();
416+
mBoard.stopAnimation();
431417
}
432418

433419
@Override
434420
public void onResume() {
435421
super.onResume();
436-
mBoard = new Board(this, null);
437-
setContentView(mBoard);
422+
mBoard.startAnimation();
438423
}
439424
}

0 commit comments

Comments
 (0)