Merge "OK, now it's a release." into klp-dev
@@ -18,91 +18,96 @@ package com.android.internal.app;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.text.method.AllCapsTransformationMethod;
|
||||||
|
import android.text.method.TransformationMethod;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.animation.DecelerateInterpolator;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class PlatLogoActivity extends Activity {
|
public class PlatLogoActivity extends Activity {
|
||||||
Toast mToast;
|
FrameLayout mContent;
|
||||||
ImageView mContent;
|
|
||||||
int mCount;
|
int mCount;
|
||||||
final Handler mHandler = new Handler();
|
final Handler mHandler = new Handler();
|
||||||
|
|
||||||
private View makeView() {
|
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
|
||||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
|
||||||
|
|
||||||
LinearLayout view = new LinearLayout(this);
|
|
||||||
view.setOrientation(LinearLayout.VERTICAL);
|
|
||||||
view.setLayoutParams(
|
|
||||||
new ViewGroup.LayoutParams(
|
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
||||||
));
|
|
||||||
final int p = (int)(8 * metrics.density);
|
|
||||||
view.setPadding(p, p, p, p);
|
|
||||||
|
|
||||||
Typeface light = Typeface.create("sans-serif-light", Typeface.NORMAL);
|
|
||||||
Typeface normal = Typeface.create("sans-serif", Typeface.BOLD);
|
|
||||||
|
|
||||||
final float size = 14 * metrics.density;
|
|
||||||
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
||||||
lp.gravity = Gravity.CENTER_HORIZONTAL;
|
|
||||||
lp.bottomMargin = (int) (-4*metrics.density);
|
|
||||||
|
|
||||||
TextView tv = new TextView(this);
|
|
||||||
if (light != null) tv.setTypeface(light);
|
|
||||||
tv.setTextSize(1.25f*size);
|
|
||||||
tv.setTextColor(0xFFFFFFFF);
|
|
||||||
tv.setShadowLayer(4*metrics.density, 0, 2*metrics.density, 0x66000000);
|
|
||||||
tv.setText("Android " + Build.VERSION.RELEASE);
|
|
||||||
view.addView(tv, lp);
|
|
||||||
|
|
||||||
tv = new TextView(this);
|
|
||||||
if (normal != null) tv.setTypeface(normal);
|
|
||||||
tv.setTextSize(size);
|
|
||||||
tv.setTextColor(0xFFFFFFFF);
|
|
||||||
tv.setShadowLayer(4*metrics.density, 0, 2*metrics.density, 0x66000000);
|
|
||||||
tv.setText("JELLY BEAN");
|
|
||||||
view.addView(tv, lp);
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
mToast = Toast.makeText(this, "", Toast.LENGTH_LONG);
|
|
||||||
mToast.setView(makeView());
|
|
||||||
|
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
|
|
||||||
mContent = new ImageView(this);
|
Typeface bold = Typeface.create("sans-serif", Typeface.BOLD);
|
||||||
mContent.setImageResource(com.android.internal.R.drawable.platlogo_alt);
|
Typeface light = Typeface.create("sans-serif-light", Typeface.NORMAL);
|
||||||
mContent.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
||||||
|
mContent = new FrameLayout(this);
|
||||||
|
|
||||||
final int p = (int)(32 * metrics.density);
|
final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
|
||||||
mContent.setPadding(p, p, p, p);
|
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
lp.gravity = Gravity.CENTER;
|
||||||
|
|
||||||
|
final ImageView logo = new ImageView(this);
|
||||||
|
logo.setImageResource(com.android.internal.R.drawable.platlogo);
|
||||||
|
logo.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||||
|
logo.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
final TextView letter = new TextView(this);
|
||||||
|
|
||||||
|
letter.setTypeface(bold);
|
||||||
|
letter.setTextSize(300);
|
||||||
|
letter.setTextColor(0xFFFFFFFF);
|
||||||
|
letter.setGravity(Gravity.CENTER);
|
||||||
|
letter.setShadowLayer(12*metrics.density, 0, 0, 0xC085F985);
|
||||||
|
letter.setText(String.valueOf(Build.VERSION.RELEASE).substring(0, 1));
|
||||||
|
|
||||||
|
final int p = (int)(4 * metrics.density);
|
||||||
|
|
||||||
|
final TextView tv = new TextView(this);
|
||||||
|
if (light != null) tv.setTypeface(light);
|
||||||
|
tv.setTextSize(30);
|
||||||
|
tv.setPadding(p, p, p, p);
|
||||||
|
tv.setTextColor(0xFFFFFFFF);
|
||||||
|
tv.setGravity(Gravity.CENTER);
|
||||||
|
tv.setShadowLayer(4 * metrics.density, 0, 2 * metrics.density, 0x66000000);
|
||||||
|
tv.setTransformationMethod(new AllCapsTransformationMethod(this));
|
||||||
|
tv.setText("Android " + Build.VERSION.RELEASE);
|
||||||
|
tv.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
mContent.addView(letter, lp);
|
||||||
|
mContent.addView(logo, lp);
|
||||||
|
|
||||||
|
final FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(lp);
|
||||||
|
lp2.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
||||||
|
lp2.bottomMargin = 10*p;
|
||||||
|
|
||||||
|
mContent.addView(tv, lp2);
|
||||||
|
|
||||||
mContent.setOnClickListener(new View.OnClickListener() {
|
mContent.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mToast.show();
|
if (logo.getVisibility() != View.VISIBLE) {
|
||||||
mContent.setImageResource(com.android.internal.R.drawable.platlogo);
|
letter.animate().alpha(0.25f).scaleY(0.75f).scaleX(0.75f).setDuration(2000)
|
||||||
|
.start();
|
||||||
|
logo.setAlpha(0f);
|
||||||
|
logo.setVisibility(View.VISIBLE);
|
||||||
|
logo.animate().alpha(1f).setDuration(1000).setStartDelay(500).start();
|
||||||
|
tv.setAlpha(0f);
|
||||||
|
tv.setVisibility(View.VISIBLE);
|
||||||
|
tv.animate().alpha(1f).setDuration(1000).setStartDelay(1000).start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,9 +120,8 @@ public class PlatLogoActivity extends Activity {
|
|||||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
|
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
|
||||||
.addCategory("com.android.internal.category.PLATLOGO"));
|
.addCategory("com.android.internal.category.PLATLOGO"));
|
||||||
//.setClassName("com.android.systemui","com.android.systemui.BeanBag"));
|
|
||||||
} catch (ActivityNotFoundException ex) {
|
} catch (ActivityNotFoundException ex) {
|
||||||
android.util.Log.e("PlatLogoActivity", "Couldn't find a bag of beans.");
|
android.util.Log.e("PlatLogoActivity", "Couldn't find a piece of pie.");
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 841 B After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 511 B After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 259 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 882 B After Width: | Height: | Size: 1.8 KiB |
@@ -985,7 +985,6 @@
|
|||||||
<java-symbol type="drawable" name="jog_tab_target_gray" />
|
<java-symbol type="drawable" name="jog_tab_target_gray" />
|
||||||
<java-symbol type="drawable" name="picture_emergency" />
|
<java-symbol type="drawable" name="picture_emergency" />
|
||||||
<java-symbol type="drawable" name="platlogo" />
|
<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_sync_error" />
|
||||||
<java-symbol type="drawable" name="stat_notify_wifi_in_range" />
|
<java-symbol type="drawable" name="stat_notify_wifi_in_range" />
|
||||||
<java-symbol type="drawable" name="stat_notify_rssi_in_range" />
|
<java-symbol type="drawable" name="stat_notify_rssi_in_range" />
|
||||||
|
|||||||
@@ -188,37 +188,6 @@
|
|||||||
android:taskAffinity="com.android.systemui.net"
|
android:taskAffinity="com.android.systemui.net"
|
||||||
android:excludeFromRecents="true" />
|
android:excludeFromRecents="true" />
|
||||||
|
|
||||||
<!-- started from ... somewhere -->
|
|
||||||
<activity
|
|
||||||
android:name=".BeanBag"
|
|
||||||
android:exported="true"
|
|
||||||
android:label="BeanBag"
|
|
||||||
android:icon="@drawable/redbean2"
|
|
||||||
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="com.android.internal.category.PLATLOGO" />
|
|
||||||
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<!-- Beans in space -->
|
|
||||||
<service
|
|
||||||
android:name=".BeanBagDream"
|
|
||||||
android:exported="true"
|
|
||||||
android:label="@string/jelly_bean_dream_name"
|
|
||||||
android:enabled="false"
|
|
||||||
>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.service.dreams.DreamService" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<activity android:name=".Somnambulator"
|
<activity android:name=".Somnambulator"
|
||||||
android:label="@string/start_dreams"
|
android:label="@string/start_dreams"
|
||||||
android:icon="@mipmap/ic_launcher_dreams"
|
android:icon="@mipmap/ic_launcher_dreams"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 16 KiB |
@@ -1,412 +0,0 @@
|
|||||||
/*);
|
|
||||||
* 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.TimeAnimator;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.ColorMatrix;
|
|
||||||
import android.graphics.ColorMatrixColorFilter;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
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.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 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) {
|
|
||||||
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;
|
|
||||||
private float grabx_offset, graby_offset;
|
|
||||||
|
|
||||||
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;
|
|
||||||
grabx_offset = e.getRawX() - x;
|
|
||||||
graby_offset = e.getRawY() - y;
|
|
||||||
va = 0;
|
|
||||||
// fall
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
|
||||||
grabx = e.getRawX() - grabx_offset;
|
|
||||||
graby = e.getRawY() - graby_offset;
|
|
||||||
grabtime = e.getEventTime();
|
|
||||||
break;
|
|
||||||
case MotionEvent.ACTION_CANCEL:
|
|
||||||
case MotionEvent.ACTION_UP:
|
|
||||||
grabbed = false;
|
|
||||||
float a = randsign() * clamp(mag(vx, vy) * 0.33f, 0, 1080f);
|
|
||||||
va = randfrange(a*0.5f, a);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startAnimation() {
|
|
||||||
stopAnimation();
|
|
||||||
if (mAnim == null) {
|
|
||||||
post(new Runnable() { public void run() {
|
|
||||||
reset();
|
|
||||||
startAnimation();
|
|
||||||
} });
|
|
||||||
} else {
|
|
||||||
mAnim.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopAnimation() {
|
|
||||||
if (mAnim != null) mAnim.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDetachedFromWindow() {
|
|
||||||
super.onDetachedFromWindow();
|
|
||||||
stopAnimation();
|
|
||||||
}
|
|
||||||
|
|
||||||
@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();
|
|
||||||
|
|
||||||
// ACHIEVEMENT UNLOCKED
|
|
||||||
PackageManager pm = getPackageManager();
|
|
||||||
pm.setComponentEnabledSetting(new ComponentName(this, BeanBagDream.class),
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
|
|
||||||
|
|
||||||
getWindow().addFlags(
|
|
||||||
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
|
||||||
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
|
||||||
);
|
|
||||||
mBoard = new Board(this, null);
|
|
||||||
setContentView(mBoard);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
mBoard.stopAnimation();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
mBoard.startAnimation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.service.dreams.DreamService;
|
|
||||||
|
|
||||||
import com.android.systemui.BeanBag.Board;
|
|
||||||
|
|
||||||
public class BeanBagDream extends DreamService {
|
|
||||||
|
|
||||||
private Board mBoard;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttachedToWindow() {
|
|
||||||
super.onAttachedToWindow();
|
|
||||||
setInteractive(true);
|
|
||||||
setFullscreen(true);
|
|
||||||
mBoard = new Board(this, null);
|
|
||||||
setContentView(mBoard);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDreamingStarted() {
|
|
||||||
super.onDreamingStarted();
|
|
||||||
mBoard.startAnimation();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDreamingStopped() {
|
|
||||||
mBoard.stopAnimation();
|
|
||||||
super.onDreamingStopped();
|
|
||||||
}
|
|
||||||
}
|
|
||||||