PlatLogoActivity.java revision c89deae0a7bed0b54e3152df3a52bca6f8dd0cd4
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.internal.app; 18 19import android.app.Activity; 20import android.content.ActivityNotFoundException; 21import android.content.ContentResolver; 22import android.content.Context; 23import android.content.Intent; 24import android.graphics.Color; 25import android.graphics.Typeface; 26import android.os.Build; 27import android.os.Bundle; 28import android.provider.Settings; 29import android.util.AttributeSet; 30import android.util.DisplayMetrics; 31import android.view.Gravity; 32import android.view.View; 33import android.widget.FrameLayout; 34import android.widget.TextView; 35 36public class PlatLogoActivity extends Activity { 37 private static class Torso extends FrameLayout { 38 boolean mAnimate = false; 39 TextView mText; 40 41 public Torso(Context context) { 42 this(context, null); 43 } 44 public Torso(Context context, AttributeSet attrs) { 45 this(context, attrs, 0); 46 } 47 public Torso(Context context, AttributeSet attrs, int flags) { 48 super(context, attrs, flags); 49 50 for (int i=0; i<2; i++) { 51 final View v = new View(context); 52 v.setBackgroundColor(i % 2 == 0 ? Color.BLUE : Color.RED); 53 addView(v); 54 } 55 56 mText = new TextView(context); 57 mText.setTextColor(Color.BLACK); 58 mText.setTextSize(14 /* sp */); 59 mText.setTypeface(Typeface.create("monospace", Typeface.BOLD)); 60 61 addView(mText, new FrameLayout.LayoutParams( 62 FrameLayout.LayoutParams.MATCH_PARENT, 63 FrameLayout.LayoutParams.WRAP_CONTENT, 64 Gravity.BOTTOM | Gravity.LEFT 65 )); 66 } 67 68 private Runnable mRunnable = new Runnable() { 69 @Override 70 public void run() { 71 mText.setText(String.format("android_%s.flv - build %s", 72 Build.VERSION.CODENAME, 73 Build.VERSION.INCREMENTAL)); 74 final int N = getChildCount(); 75 final float parentw = getMeasuredWidth(); 76 final float parenth = getMeasuredHeight(); 77 for (int i=0; i<N; i++) { 78 final View v = getChildAt(i); 79 if (v instanceof TextView) continue; 80 81 final int w = (int) (Math.random() * parentw); 82 final int h = (int) (Math.random() * parenth); 83 v.setLayoutParams(new FrameLayout.LayoutParams(w, h)); 84 85 v.setX((float) Math.random() * (parentw - w)); 86 v.setY((float) Math.random() * (parenth - h)); 87 } 88 89 if (mAnimate) postDelayed(this, 1000); 90 } 91 }; 92 @Override 93 protected void onAttachedToWindow() { 94 mAnimate = true; 95 post(mRunnable); 96 } 97 @Override 98 protected void onDetachedFromWindow() { 99 mAnimate = false; 100 removeCallbacks(mRunnable); 101 } 102 } 103 104 @Override 105 protected void onCreate(Bundle savedInstanceState) { 106 super.onCreate(savedInstanceState); 107 108 final Torso t = new Torso(this); 109 t.setBackgroundColor(Color.WHITE); 110 111 t.getChildAt(0) 112 .setOnLongClickListener(new View.OnLongClickListener() { 113 @Override 114 public boolean onLongClick(View v) { 115 final ContentResolver cr = getContentResolver(); 116 if (Settings.System.getLong(cr, Settings.System.EGG_MODE, 0) 117 == 0) { 118 // For posterity: the moment this user unlocked the easter egg 119 Settings.System.putLong(cr, 120 Settings.System.EGG_MODE, 121 System.currentTimeMillis()); 122 } 123 try { 124 startActivity(new Intent(Intent.ACTION_MAIN) 125 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 126 | Intent.FLAG_ACTIVITY_CLEAR_TASK 127 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) 128 .addCategory("com.android.internal.category.PLATLOGO")); 129 } catch (ActivityNotFoundException ex) { 130 android.util.Log.e("PlatLogoActivity", "Couldn't catch a break."); 131 } 132 finish(); 133 return true; 134 } 135 }); 136 137 setContentView(t); 138 } 139} 140