Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa0a3b69 authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Stop animating when not showing.

We were eating too many jelly beans even when the screen was
off.

Also clean up touch offsets, rotation on fling, and main
platlogo asset.

Bug: 6541052
Change-Id: I34e49b8b7a95ce6daab929885130426a5ae58dc4
parent ed82973e
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -92,7 +92,7 @@ public class PlatLogoActivity extends Activity {
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        getWindowManager().getDefaultDisplay().getMetrics(metrics);


        mContent = new ImageView(this);
        mContent = new ImageView(this);
        mContent.setImageResource(com.android.internal.R.drawable.platlogo);
        mContent.setImageResource(com.android.internal.R.drawable.platlogo_alt);
        mContent.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        mContent.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        
        
        final int p = (int)(32 * metrics.density);
        final int p = (int)(32 * metrics.density);
@@ -102,7 +102,7 @@ public class PlatLogoActivity extends Activity {
            @Override
            @Override
            public void onClick(View v) {
            public void onClick(View v) {
                mToast.show();
                mToast.show();
                mContent.setImageResource(com.android.internal.R.drawable.platlogo_alt);
                mContent.setImageResource(com.android.internal.R.drawable.platlogo);
            }
            }
        });
        });


+5.07 KiB (43.5 KiB)
Loading image diff...
−5.07 KiB (38.4 KiB)
Loading image diff...
+1 −1
Original line number Original line Diff line number Diff line
@@ -55,7 +55,7 @@
        android:allowBackup="false"
        android:allowBackup="false"
        android:hardwareAccelerated="true"
        android:hardwareAccelerated="true"
        android:label="@string/app_label"
        android:label="@string/app_label"
        android:icon="@drawable/ic_launcher_settings">
        android:icon="@*android:drawable/platlogo">


        <!-- Broadcast receiver that gets the broadcast at boot time and starts
        <!-- Broadcast receiver that gets the broadcast at boot time and starts
             up everything else.
             up everything else.
+35 −50
Original line number Original line Diff line number Diff line
@@ -81,6 +81,10 @@ public class BeanBag extends Activity {
            return (float) Math.sqrt(x*x+y*y);
            return (float) Math.sqrt(x*x+y*y);
        }
        }


        static float clamp(float x, float a, float b) {
            return ((x<a)?a:((x>b)?b:x));
        }

        static float dot(float x1, float y1, float x2, float y2) {
        static float dot(float x1, float y1, float x2, float y2) {
            return x1*x2+y1+y2;
            return x1*x2+y1+y2;
        }
        }
@@ -149,6 +153,7 @@ public class BeanBag extends Activity {
            public boolean grabbed;
            public boolean grabbed;
            public float grabx, graby;
            public float grabx, graby;
            public long grabtime;
            public long grabtime;
            private float grabx_offset, graby_offset;


            public Bean(Context context, AttributeSet as) {
            public Bean(Context context, AttributeSet as) {
                super(context, as);
                super(context, as);
@@ -236,17 +241,20 @@ public class BeanBag extends Activity {
                switch (e.getAction()) {
                switch (e.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_DOWN:
                        grabbed = true;
                        grabbed = true;
                        grabx_offset = e.getRawX() - x;
                        graby_offset = e.getRawY() - y;
                        va = 0;
                        va = 0;
                        // fall
                        // fall
                    case MotionEvent.ACTION_MOVE:
                    case MotionEvent.ACTION_MOVE:
                        grabx = e.getRawX();
                        grabx = e.getRawX() - grabx_offset;
                        graby = e.getRawY();
                        graby = e.getRawY() - graby_offset;
                        grabtime = e.getEventTime();
                        grabtime = e.getEventTime();
                        break;
                        break;
                    case MotionEvent.ACTION_CANCEL:
                    case MotionEvent.ACTION_CANCEL:
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_UP:
                        grabbed = false;
                        grabbed = false;
                        va = randfrange(-5,5);
                        float a = randsign() * clamp(mag(vx, vy) * 0.33f, 0, 1080f);
                        va = randfrange(a*0.5f, a);
                        break;
                        break;
                }
                }
                return true;
                return true;
@@ -308,47 +316,6 @@ public class BeanBag extends Activity {
                            if (!(v2 instanceof Bean)) continue;
                            if (!(v2 instanceof Bean)) continue;
                            Bean nv2 = (Bean) v2;
                            Bean nv2 = (Bean) v2;
                            final float overlap = nv.overlap(nv2);
                            final float overlap = nv.overlap(nv2);
                            if (false && overlap < 0) {
                                // angle pointing from nv2 to nv
                                final float dx = nv.x - nv2.x;
                                final float dy = nv.y - nv2.y;
                                final float ang = (float) Math.atan2(dx, dy);

                                if (false) {
                                nv.vx -= Math.cos(ang) * overlap * 0.5f;
                                nv.vy -= Math.sin(ang) * overlap * 0.5f;
                                nv2.vx += Math.cos(ang) * overlap * 0.5f;
                                nv2.vy += Math.sin(ang) * overlap * 0.5f;
                                }


                                // first, move them apart
                                nv.x -= Math.cos(ang) * overlap/2;
                                nv.y -= Math.sin(ang) * overlap/2;
                                nv2.x += Math.cos(ang) * overlap/2;
                                nv2.y += Math.sin(ang) * overlap/2;

                                // next, figure out velocities
                                final float sap = 0f; // randfrange(0,0.25f);

                                final float mag1 = mag(nv.vx, nv.vy) * (1f-sap);
                                final float mag2 = mag(nv2.vx, nv2.vy) * (1f-sap);


                                // hacky way to transfer "momentum"
                                nv.vx = mag2 * (float)Math.cos(ang);
                                nv.vy = mag2 * (float)Math.sin(ang);
                                nv2.vx = -mag1 * (float)Math.cos(ang);
                                nv2.vy = -mag1 * (float)Math.sin(ang);

                                final float totalva = nv.va + nv2.va;
                                final float frac = randfrange(0.25f,0.75f);
                                nv.va = totalva * frac;
                                nv2.va = totalva * (1f-frac);
//                                nv.va += randfrange(-20,20);
//                                nv2.va += randfrange(-20,20);

                            }
                        }
                        }


                        nv.setRotation(nv.a);
                        nv.setRotation(nv.a);
@@ -375,17 +342,28 @@ public class BeanBag extends Activity {
            boardWidth = w;
            boardWidth = w;
            boardHeight = h;
            boardHeight = h;
//            android.util.Log.d("Nyandroid", "resized: " + w + "x" + h);
//            android.util.Log.d("Nyandroid", "resized: " + w + "x" + h);
        }

        public void startAnimation() {
            stopAnimation();
            if (mAnim == null) {
                post(new Runnable() { public void run() {
                post(new Runnable() { public void run() {
                    reset();
                    reset();
                mAnim.start();
                    startAnimation();
                } });
                } });
            } else {
                mAnim.start();
            }
        }
        }


        public void stopAnimation() {
            if (mAnim != null) mAnim.cancel();
        }


        @Override
        @Override
        protected void onDetachedFromWindow() {
        protected void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            super.onDetachedFromWindow();
            mAnim.cancel();
            stopAnimation();
        }
        }


        @Override
        @Override
@@ -428,12 +406,19 @@ public class BeanBag extends Activity {
                  WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
                  WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                );
                );
        mBoard = new Board(this, null);
        setContentView(mBoard);
    }

    @Override
    public void onPause() {
        super.onPause();
        mBoard.stopAnimation();
    }
    }


    @Override
    @Override
    public void onResume() {
    public void onResume() {
        super.onResume();
        super.onResume();
        mBoard = new Board(this, null);
        mBoard.startAnimation();
        setContentView(mBoard);
    }
    }
}
}