final DisplayMetrics dm = getResources().getDisplayMetrics();
final float dp = dm.density;
final int size = (int)
(Math.min(Math.min(dm.widthPixels, dm.heightPixels), 600*dp) - 100*dp);
final View stick = new View(this) {
Paint mPaint = new Paint();
Path mShadow = new Path();
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
setWillNotDraw(false);
setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRect(0, getHeight() / 2, getWidth(), getHeight());
}
});
}
@Override
public void onDraw(Canvas c) {
final int w = c.getWidth();
final int h = c.getHeight() / 2;
c.translate(0, h);
final GradientDrawable g = new GradientDrawable();
g.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT);
g.setGradientCenter(w * 0.75f, 0);
g.setColors(new int[] { 0xFFFFFFFF, 0xFFAAAAAA });
g.setBounds(0, 0, w, h);
g.draw(c);
mPaint.setColor(0xFFAAAAAA);
mShadow.reset();
mShadow.moveTo(0,0);
mShadow.lineTo(w, 0);
mShadow.lineTo(w, size/2 + 1.5f*w);
mShadow.lineTo(0, size/2);
mShadow.close();
c.drawPath(mShadow, mPaint);
}
};
mLayout.addView(stick, new FrameLayout.LayoutParams((int) (32 * dp),
ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER_HORIZONTAL));
stick.setAlpha(0f);
final ImageView im = new ImageView(this);
im.setTranslationZ(20);
im.setScaleX(0);
im.setScaleY(0);
final Drawable platlogo = getDrawable(com.android.internal.R.drawable.platlogo);
platlogo.setAlpha(0);
im.setImageDrawable(platlogo);
im.setBackground(makeRipple());
im.setClickable(true);
final ShapeDrawable highlight = new ShapeDrawable(new OvalShape());
highlight.getPaint().setColor(0x10FFFFFF);
highlight.setBounds((int)(size*.15f), (int)(size*.15f),
(int)(size*.6f), (int)(size*.6f));
im.getOverlay().add(highlight);
im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mTapCount == 0) {
im.animate()
.translationZ(40)
.scaleX(1)
.scaleY(1)
.setInterpolator(mInterpolator)
.setDuration(700)
.setStartDelay(500)
.start();
final ObjectAnimator a = ObjectAnimator.ofInt(platlogo, "alpha", 0, 255);
a.setInterpolator(mInterpolator);
a.setStartDelay(1000);
a.start();
stick.animate()
.translationZ(20)
.alpha(1)
.setInterpolator(mInterpolator)
.setDuration(700)
.setStartDelay(750)
.start();
im.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (mTapCount < 5) return false;
final ContentResolver cr = getContentResolver();
if (Settings.System.getLong(cr, Settings.System.EGG_MODE, 0)
== 0) {
// For posterity: the moment this user unlocked the easter egg
Settings.System.putLong(cr,
Settings.System.EGG_MODE,
System.currentTimeMillis());
}
im.post(new Runnable() {
@Override
public void run() {
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"));
} catch (ActivityNotFoundException ex) {
Log.e("PlatLogoActivity", "No more eggs.");
}
finish();
}
});
return true;
}
});
} else {
im.setBackground(makeRipple());
}
mTapCount++;
}
});
// Enable hardware keyboard input for TV compatibility.
im.setFocusable(true);
im.requestFocus();
im.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode != KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
++mKeyCount;
if (mKeyCount > 2) {
if (mTapCount > 5) {
im.performLongClick();
} else {
im.performClick();
}
}
return true;
} else {
return false;
}
}
});
mLayout.addView(im, new FrameLayout.LayoutParams(size, size, Gravity.CENTER));
im.animate().scaleX(0.3f).scaleY(0.3f)
.setInterpolator(mInterpolator)
.setDuration(500)
.setStartDelay(800)
.start();