/*); * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui; import android.animation.AnimatorSet; import android.animation.PropertyValuesHolder; import android.animation.ObjectAnimator; import android.animation.TimeAnimator; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.graphics.drawable.AnimationDrawable; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; import android.graphics.RectF; import android.os.Handler; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Pair; import android.view.Gravity; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.ImageView; import java.util.HashMap; import java.util.Random; public class Nyandroid extends Activity { final static boolean DEBUG = false; public static class Board extends FrameLayout { public static final boolean FIXED_STARS = true; public static final int NUM_CATS = 20; static Random sRNG = new Random(); static float lerp(float a, float b, float f) { return (b-a)*f + a; } static float randfrange(float a, float b) { return lerp(a, b, sRNG.nextFloat()); } static int randsign() { return sRNG.nextBoolean() ? 1 : -1; } static E pick(E[] array) { if (array.length == 0) return null; return array[sRNG.nextInt(array.length)]; } public class FlyingCat extends ImageView { public static final float VMAX = 1000.0f; public static final float VMIN = 100.0f; public float v, vr; public float dist; public float z; public ComponentName component; public FlyingCat(Context context, AttributeSet as) { super(context, as); setImageResource(R.drawable.nyandroid_anim); // @@@ if (DEBUG) setBackgroundColor(0x80FF0000); } public String toString() { return String.format("", getX(), getY(), getWidth(), getHeight()); } public void reset() { final float scale = lerp(0.1f,2f,z); setScaleX(scale); setScaleY(scale); setX(-scale*getWidth()+1); setY(randfrange(0, Board.this.getHeight()-scale*getHeight())); v = lerp(VMIN, VMAX, z); dist = 0; // android.util.Log.d("Nyandroid", "reset cat: " + this); } public void update(float dt) { dist += v * dt; setX(getX() + v * dt); } } TimeAnimator mAnim; public Board(Context context, AttributeSet as) { super(context, as); setLayerType(View.LAYER_TYPE_HARDWARE, null); setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); setBackgroundColor(0xFF003366); } private void reset() { // android.util.Log.d("Nyandroid", "board reset"); removeAllViews(); final ViewGroup.LayoutParams wrap = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); if (FIXED_STARS) { for(int i=0; i<20; i++) { ImageView fixedStar = new ImageView(getContext(), null); if (DEBUG) fixedStar.setBackgroundColor(0x8000FF80); fixedStar.setImageResource(R.drawable.star_anim); // @@@ addView(fixedStar, wrap); final float scale = randfrange(0.1f, 1f); fixedStar.setScaleX(scale); fixedStar.setScaleY(scale); fixedStar.setX(randfrange(0, getWidth())); fixedStar.setY(randfrange(0, getHeight())); final AnimationDrawable anim = (AnimationDrawable) fixedStar.getDrawable(); postDelayed(new Runnable() { public void run() { anim.start(); }}, (int) randfrange(0, 1000)); } } for(int i=0; i