Merge "Ice cream is SO over." into jb-dev
@@ -29,64 +29,43 @@ import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class PlatLogoActivity extends Activity {
|
||||
Vibrator mZzz;
|
||||
Toast mToast;
|
||||
ImageView mContent;
|
||||
int mCount;
|
||||
final Handler mHandler = new Handler();
|
||||
|
||||
Runnable mSuperLongPress = new Runnable() {
|
||||
public void run() {
|
||||
mCount++;
|
||||
mZzz.vibrate(50 * mCount);
|
||||
final float scale = 1f + 0.25f * mCount * mCount;
|
||||
mContent.setScaleX(scale);
|
||||
mContent.setScaleY(scale);
|
||||
|
||||
if (mCount <= 3) {
|
||||
mHandler.postDelayed(mSuperLongPress, ViewConfiguration.getLongPressTimeout());
|
||||
} else {
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_MAIN)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
|
||||
.setClassName("com.android.systemui","com.android.systemui.Nyandroid"));
|
||||
} catch (ActivityNotFoundException ex) {
|
||||
android.util.Log.e("PlatLogoActivity", "Couldn't find platlogo screensaver.");
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mZzz = (Vibrator)getSystemService(VIBRATOR_SERVICE);
|
||||
mToast = Toast.makeText(this, "Android 4.0: Ice Cream Sandwich", Toast.LENGTH_SHORT);
|
||||
mToast = Toast.makeText(this, "Android X.X: Jelly Bean", Toast.LENGTH_SHORT);
|
||||
|
||||
mContent = new ImageView(this);
|
||||
mContent.setImageResource(com.android.internal.R.drawable.platlogo);
|
||||
mContent.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
|
||||
mContent.setOnTouchListener(new View.OnTouchListener() {
|
||||
mContent.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
final int action = event.getAction();
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
mContent.setPressed(true);
|
||||
mHandler.removeCallbacks(mSuperLongPress);
|
||||
mCount = 0;
|
||||
mHandler.postDelayed(mSuperLongPress, 2*ViewConfiguration.getLongPressTimeout());
|
||||
} else if (action == MotionEvent.ACTION_UP) {
|
||||
if (mContent.isPressed()) {
|
||||
mContent.setPressed(false);
|
||||
mHandler.removeCallbacks(mSuperLongPress);
|
||||
mToast.show();
|
||||
}
|
||||
public void onClick(View v) {
|
||||
mToast.show();
|
||||
mContent.setImageResource(com.android.internal.R.drawable.platlogo_alt);
|
||||
}
|
||||
});
|
||||
|
||||
mContent.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_MAIN)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
|
||||
.addCategory("com.android.internal.category.PLATLOGO"));
|
||||
//.setClassName("com.android.systemui","com.android.systemui.BeanBag"));
|
||||
} catch (ActivityNotFoundException ex) {
|
||||
android.util.Log.e("PlatLogoActivity", "Couldn't find a bag of beans.");
|
||||
}
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
Before Width: | Height: | Size: 771 B After Width: | Height: | Size: 841 B |
|
Before Width: | Height: | Size: 362 B After Width: | Height: | Size: 414 B |
|
Before Width: | Height: | Size: 471 B After Width: | Height: | Size: 511 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 38 KiB |
BIN
core/res/res/drawable-nodpi/platlogo_alt.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 903 B After Width: | Height: | Size: 882 B |
@@ -980,6 +980,7 @@
|
||||
<java-symbol type="drawable" name="jog_tab_target_gray" />
|
||||
<java-symbol type="drawable" name="picture_emergency" />
|
||||
<java-symbol type="drawable" name="platlogo" />
|
||||
<java-symbol type="drawable" name="platlogo_alt" />
|
||||
<java-symbol type="drawable" name="stat_notify_sync_error" />
|
||||
<java-symbol type="drawable" name="stat_notify_wifi_in_range" />
|
||||
<java-symbol type="drawable" name="stat_sys_gps_on" />
|
||||
|
||||
@@ -161,18 +161,19 @@
|
||||
|
||||
<!-- started from ... somewhere -->
|
||||
<activity
|
||||
android:name=".Nyandroid"
|
||||
android:name=".BeanBag"
|
||||
android:exported="true"
|
||||
android:label="Nyandroid"
|
||||
android:icon="@drawable/nyandroid04"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
|
||||
android:label="BeanBag"
|
||||
android:icon="@drawable/redbeandroid"
|
||||
android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"
|
||||
android:hardwareAccelerated="true"
|
||||
android:launchMode="singleInstance"
|
||||
android:excludeFromRecents="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<!-- <category android:name="android.intent.category.DREAM" />-->
|
||||
<category android:name="com.android.internal.category.PLATLOGO" />
|
||||
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
BIN
packages/SystemUI/res/drawable-nodpi/jandycane.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 622 B |
|
Before Width: | Height: | Size: 574 B |
|
Before Width: | Height: | Size: 615 B |
|
Before Width: | Height: | Size: 574 B |
|
Before Width: | Height: | Size: 576 B |
|
Before Width: | Height: | Size: 568 B |
|
Before Width: | Height: | Size: 614 B |
|
Before Width: | Height: | Size: 566 B |
|
Before Width: | Height: | Size: 610 B |
|
Before Width: | Height: | Size: 566 B |
|
Before Width: | Height: | Size: 560 B |
|
Before Width: | Height: | Size: 560 B |
BIN
packages/SystemUI/res/drawable-nodpi/redbean0.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
packages/SystemUI/res/drawable-nodpi/redbean1.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
packages/SystemUI/res/drawable-nodpi/redbean2.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
packages/SystemUI/res/drawable-nodpi/redbeandroid.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
<animation-list
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:oneshot="false">
|
||||
<item android:drawable="@drawable/nyandroid00" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid01" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid02" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid03" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid04" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid05" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid06" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid07" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid08" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid09" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid10" android:duration="80" />
|
||||
<item android:drawable="@drawable/nyandroid11" android:duration="80" />
|
||||
</animation-list>
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
<animation-list
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:oneshot="false">
|
||||
<item android:drawable="@drawable/star0" android:duration="200" />
|
||||
<item android:drawable="@drawable/star1" android:duration="200" />
|
||||
<item android:drawable="@drawable/star2" android:duration="200" />
|
||||
<item android:drawable="@drawable/star3" android:duration="200" />
|
||||
<item android:drawable="@drawable/star4" android:duration="200" />
|
||||
<item android:drawable="@drawable/star5" android:duration="200" />
|
||||
</animation-list>
|
||||
|
||||
439
packages/SystemUI/src/com/android/systemui/BeanBag.java
Normal file
@@ -0,0 +1,439 @@
|
||||
/*);
|
||||
* Copyright (C) 2012 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.drawable.BitmapDrawable;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
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.view.animation.AnimationUtils;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
public class BeanBag extends Activity {
|
||||
final static boolean DEBUG = false;
|
||||
|
||||
public static class Board extends FrameLayout
|
||||
{
|
||||
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 boolean flip() {
|
||||
return sRNG.nextBoolean();
|
||||
}
|
||||
|
||||
static float mag(float x, float y) {
|
||||
return (float) Math.sqrt(x*x+y*y);
|
||||
}
|
||||
|
||||
static float dot(float x1, float y1, float x2, float y2) {
|
||||
return x1*x2+y1+y2;
|
||||
}
|
||||
|
||||
static <E> E pick(E[] array) {
|
||||
if (array.length == 0) return null;
|
||||
return array[sRNG.nextInt(array.length)];
|
||||
}
|
||||
|
||||
static int pickInt(int[] array) {
|
||||
if (array.length == 0) return 0;
|
||||
return array[sRNG.nextInt(array.length)];
|
||||
}
|
||||
|
||||
static int NUM_BEANS = 40;
|
||||
static float MIN_SCALE = 0.2f;
|
||||
static float MAX_SCALE = 1f;
|
||||
|
||||
static float LUCKY = 0.001f;
|
||||
|
||||
static int MAX_RADIUS = (int)(576 * MAX_SCALE);
|
||||
|
||||
static int BEANS[] = {
|
||||
R.drawable.redbean0,
|
||||
R.drawable.redbean0,
|
||||
R.drawable.redbean0,
|
||||
R.drawable.redbean0,
|
||||
R.drawable.redbean1,
|
||||
R.drawable.redbean1,
|
||||
R.drawable.redbean2,
|
||||
R.drawable.redbean2,
|
||||
R.drawable.redbeandroid,
|
||||
};
|
||||
|
||||
static int COLORS[] = {
|
||||
0xFF00CC00,
|
||||
0xFFCC0000,
|
||||
0xFF0000CC,
|
||||
0xFFFFFF00,
|
||||
0xFFFF8000,
|
||||
0xFF00CCFF,
|
||||
0xFFFF0080,
|
||||
0xFF8000FF,
|
||||
0xFFFF8080,
|
||||
0xFF8080FF,
|
||||
0xFFB0C0D0,
|
||||
0xFFDDDDDD,
|
||||
0xFF333333,
|
||||
};
|
||||
|
||||
public class Bean extends ImageView {
|
||||
public static final float VMAX = 1000.0f;
|
||||
public static final float VMIN = 100.0f;
|
||||
|
||||
public float x, y, a;
|
||||
|
||||
public float va;
|
||||
public float vx, vy;
|
||||
|
||||
public float r;
|
||||
|
||||
public float z;
|
||||
|
||||
public int h,w;
|
||||
|
||||
public boolean grabbed;
|
||||
public float grabx, graby;
|
||||
public long grabtime;
|
||||
|
||||
public Bean(Context context, AttributeSet as) {
|
||||
super(context, as);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("<bean (%.1f, %.1f) (%d x %d)>",
|
||||
getX(), getY(), getWidth(), getHeight());
|
||||
}
|
||||
|
||||
private void pickBean() {
|
||||
int beanId = pickInt(BEANS);
|
||||
if (randfrange(0,1) <= LUCKY) {
|
||||
beanId = R.drawable.jandycane;
|
||||
}
|
||||
BitmapDrawable bean = (BitmapDrawable) getContext().getResources().getDrawable(beanId);
|
||||
Bitmap beanBits = bean.getBitmap();
|
||||
h=beanBits.getHeight();
|
||||
w=beanBits.getWidth();
|
||||
|
||||
if (DEBUG) {
|
||||
bean.setAlpha(0x80);
|
||||
}
|
||||
this.setImageDrawable(bean);
|
||||
|
||||
Paint pt = new Paint();
|
||||
final int color = pickInt(COLORS);
|
||||
ColorMatrix CM = new ColorMatrix();
|
||||
float[] M = CM.getArray();
|
||||
// we assume the color information is in the red channel
|
||||
/* R */ M[0] = (float)((color & 0x00FF0000) >> 16) / 0xFF;
|
||||
/* G */ M[5] = (float)((color & 0x0000FF00) >> 8) / 0xFF;
|
||||
/* B */ M[10] = (float)((color & 0x000000FF)) / 0xFF;
|
||||
pt.setColorFilter(new ColorMatrixColorFilter(M));
|
||||
setLayerType(View.LAYER_TYPE_HARDWARE, (beanId == R.drawable.jandycane) ? null : pt);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
pickBean();
|
||||
|
||||
final float scale = lerp(MIN_SCALE,MAX_SCALE,z);
|
||||
setScaleX(scale); setScaleY(scale);
|
||||
|
||||
r = 0.3f*Math.max(h,w)*scale;
|
||||
|
||||
a=(randfrange(0,360));
|
||||
va = randfrange(-30,30);
|
||||
|
||||
vx = randfrange(-40,40) * z;
|
||||
vy = randfrange(-40,40) * z;
|
||||
final float boardh = boardHeight;
|
||||
final float boardw = boardWidth;
|
||||
//android.util.Log.d("BeanBag", "reset: w="+w+" h="+h);
|
||||
if (flip()) {
|
||||
x=(vx < 0 ? boardw+2*r : -r*4f);
|
||||
y=(randfrange(0, boardh-3*r)*0.5f + ((vy < 0)?boardh*0.5f:0));
|
||||
} else {
|
||||
y=(vy < 0 ? boardh+2*r : -r*4f);
|
||||
x=(randfrange(0, boardw-3*r)*0.5f + ((vx < 0)?boardw*0.5f:0));
|
||||
}
|
||||
}
|
||||
|
||||
public void update(float dt) {
|
||||
if (grabbed) {
|
||||
// final float interval = (SystemClock.uptimeMillis() - grabtime) / 1000f;
|
||||
vx = (vx * 0.75f) + ((grabx - x) / dt) * 0.25f;
|
||||
x = grabx;
|
||||
vy = (vy * 0.75f) + ((graby - y) / dt) * 0.25f;;
|
||||
y = graby;
|
||||
} else {
|
||||
x = (x + vx * dt);
|
||||
y = (y + vy * dt);
|
||||
a = (a + va * dt);
|
||||
}
|
||||
}
|
||||
|
||||
public float overlap(Bean other) {
|
||||
final float dx = (x - other.x);
|
||||
final float dy = (y - other.y);
|
||||
return mag(dx, dy) - r - other.r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent e) {
|
||||
switch (e.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
grabbed = true;
|
||||
va = 0;
|
||||
// fall
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
grabx = e.getRawX();
|
||||
graby = e.getRawY();
|
||||
grabtime = e.getEventTime();
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP:
|
||||
grabbed = false;
|
||||
va = randfrange(-5,5);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
TimeAnimator mAnim;
|
||||
private int boardWidth;
|
||||
private int boardHeight;
|
||||
|
||||
public Board(Context context, AttributeSet as) {
|
||||
super(context, as);
|
||||
|
||||
setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
|
||||
|
||||
setWillNotDraw(!DEBUG);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
for(int i=0; i<NUM_BEANS; i++) {
|
||||
Bean nv = new Bean(getContext(), null);
|
||||
addView(nv, wrap);
|
||||
nv.z = ((float)i/NUM_BEANS);
|
||||
nv.z *= nv.z;
|
||||
nv.reset();
|
||||
nv.x = (randfrange(0, boardWidth));
|
||||
nv.y = (randfrange(0, boardHeight));
|
||||
}
|
||||
|
||||
if (mAnim != null) {
|
||||
mAnim.cancel();
|
||||
}
|
||||
mAnim = new TimeAnimator();
|
||||
mAnim.setTimeListener(new TimeAnimator.TimeListener() {
|
||||
private long lastPrint = 0;
|
||||
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
|
||||
if (DEBUG && totalTime - lastPrint > 5000) {
|
||||
lastPrint = totalTime;
|
||||
for (int i=0; i<getChildCount(); i++) {
|
||||
android.util.Log.d("BeanBag", "bean " + i + ": " + getChildAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<getChildCount(); i++) {
|
||||
View v = getChildAt(i);
|
||||
if (!(v instanceof Bean)) continue;
|
||||
Bean nv = (Bean) v;
|
||||
nv.update(deltaTime / 1000f);
|
||||
|
||||
for (int j=i+1; j<getChildCount(); j++) {
|
||||
View v2 = getChildAt(j);
|
||||
if (!(v2 instanceof Bean)) continue;
|
||||
Bean nv2 = (Bean) v2;
|
||||
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.setX(nv.x-nv.getPivotX());
|
||||
nv.setY(nv.y-nv.getPivotY());
|
||||
|
||||
if ( nv.x < - MAX_RADIUS
|
||||
|| nv.x > boardWidth + MAX_RADIUS
|
||||
|| nv.y < -MAX_RADIUS
|
||||
|| nv.y > boardHeight + MAX_RADIUS)
|
||||
{
|
||||
nv.reset();
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG) invalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged (int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w,h,oldw,oldh);
|
||||
boardWidth = w;
|
||||
boardHeight = h;
|
||||
// android.util.Log.d("Nyandroid", "resized: " + w + "x" + h);
|
||||
post(new Runnable() { public void run() {
|
||||
reset();
|
||||
mAnim.start();
|
||||
} });
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mAnim.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaque() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c) {
|
||||
if (DEBUG) {
|
||||
//android.util.Log.d("BeanBag", "onDraw");
|
||||
Paint pt = new Paint();
|
||||
pt.setAntiAlias(true);
|
||||
pt.setStyle(Paint.Style.STROKE);
|
||||
pt.setColor(0xFFFF0000);
|
||||
pt.setStrokeWidth(4.0f);
|
||||
c.drawRect(0, 0, getWidth(), getHeight(), pt);
|
||||
pt.setColor(0xFFFFCC00);
|
||||
pt.setStrokeWidth(1.0f);
|
||||
for (int i=0; i<getChildCount(); i++) {
|
||||
Bean b = (Bean) getChildAt(i);
|
||||
final float a = (360-b.a)/180f*3.14159f;
|
||||
final float tx = b.getTranslationX();
|
||||
final float ty = b.getTranslationY();
|
||||
c.drawCircle(b.x, b.y, b.r, pt);
|
||||
c.drawCircle(tx, ty, 4, pt);
|
||||
c.drawLine(b.x, b.y, (float)(b.x+b.r*Math.sin(a)), (float)(b.y+b.r*Math.cos(a)), pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Board mBoard;
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
getWindow().addFlags(
|
||||
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mBoard = new Board(this, null);
|
||||
setContentView(mBoard);
|
||||
}
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
/*);
|
||||
* 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> 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("<cat (%.1f, %.1f) (%d x %d)>",
|
||||
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<NUM_CATS; i++) {
|
||||
FlyingCat nv = new FlyingCat(getContext(), null);
|
||||
addView(nv, wrap);
|
||||
nv.z = ((float)i/NUM_CATS);
|
||||
nv.z *= nv.z;
|
||||
nv.reset();
|
||||
nv.setX(randfrange(0,Board.this.getWidth()));
|
||||
final AnimationDrawable anim = (AnimationDrawable) nv.getDrawable();
|
||||
postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
anim.start();
|
||||
}}, (int) randfrange(0, 1000));
|
||||
}
|
||||
|
||||
if (mAnim != null) {
|
||||
mAnim.cancel();
|
||||
}
|
||||
mAnim = new TimeAnimator();
|
||||
mAnim.setTimeListener(new TimeAnimator.TimeListener() {
|
||||
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
|
||||
// setRotation(totalTime * 0.01f); // not as cool as you would think
|
||||
// android.util.Log.d("Nyandroid", "t=" + totalTime);
|
||||
|
||||
for (int i=0; i<getChildCount(); i++) {
|
||||
View v = getChildAt(i);
|
||||
if (!(v instanceof FlyingCat)) continue;
|
||||
FlyingCat nv = (FlyingCat) v;
|
||||
nv.update(deltaTime / 1000f);
|
||||
final float catWidth = nv.getWidth() * nv.getScaleX();
|
||||
final float catHeight = nv.getHeight() * nv.getScaleY();
|
||||
if ( nv.getX() + catWidth < -2
|
||||
|| nv.getX() > getWidth() + 2
|
||||
|| nv.getY() + catHeight < -2
|
||||
|| nv.getY() > getHeight() + 2)
|
||||
{
|
||||
nv.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged (int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w,h,oldw,oldh);
|
||||
// android.util.Log.d("Nyandroid", "resized: " + w + "x" + h);
|
||||
post(new Runnable() { public void run() {
|
||||
reset();
|
||||
mAnim.start();
|
||||
} });
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mAnim.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaque() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private Board mBoard;
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
getWindow().addFlags(
|
||||
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mBoard = new Board(this, null);
|
||||
setContentView(mBoard);
|
||||
|
||||
mBoard.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
|
||||
@Override
|
||||
public void onSystemUiVisibilityChange(int vis) {
|
||||
if (0 == (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)) {
|
||||
Nyandroid.this.finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserInteraction() {
|
||||
// android.util.Log.d("Nyandroid", "finishing on user interaction");
|
||||
finish();
|
||||
}
|
||||
}
|
||||