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 17 package com.android.internal.app; 18 19 import android.app.Activity; 20 import android.content.ActivityNotFoundException; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.graphics.Typeface; 24 import android.provider.Settings; 25 import android.os.Build; 26 import android.os.Bundle; 27 import android.os.Handler; 28 import android.text.method.AllCapsTransformationMethod; 29 import android.text.method.TransformationMethod; 30 import android.util.DisplayMetrics; 31 import android.view.Gravity; 32 import android.view.View; 33 import android.view.ViewGroup; 34 import android.view.animation.AccelerateInterpolator; 35 import android.view.animation.AnticipateOvershootInterpolator; 36 import android.view.animation.DecelerateInterpolator; 37 import android.widget.FrameLayout; 38 import android.widget.ImageView; 39 import android.widget.LinearLayout; 40 import android.widget.TextView; 41 import android.widget.Toast; 42 43 public class PlatLogoActivity extends Activity { 44 FrameLayout mContent; 45 int mCount; 46 final Handler mHandler = new Handler(); 47 static final int BGCOLOR = 0xffed1d24; 48 49 @Override 50 protected void onCreate(Bundle savedInstanceState) { 51 super.onCreate(savedInstanceState); 52 53 DisplayMetrics metrics = new DisplayMetrics(); 54 getWindowManager().getDefaultDisplay().getMetrics(metrics); 55 56 Typeface bold = Typeface.create("sans-serif", Typeface.BOLD); 57 Typeface light = Typeface.create("sans-serif-light", Typeface.NORMAL); 58 59 mContent = new FrameLayout(this); 60 mContent.setBackgroundColor(0xC0000000); 61 62 final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( 63 FrameLayout.LayoutParams.WRAP_CONTENT, 64 FrameLayout.LayoutParams.WRAP_CONTENT); 65 lp.gravity = Gravity.CENTER; 66 67 final ImageView logo = new ImageView(this); 68 logo.setImageResource(com.android.internal.R.drawable.platlogo); 69 logo.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 70 logo.setVisibility(View.INVISIBLE); 71 72 final View bg = new View(this); 73 bg.setBackgroundColor(BGCOLOR); 74 bg.setAlpha(0f); 75 76 final TextView letter = new TextView(this); 77 78 letter.setTypeface(bold); 79 letter.setTextSize(300); 80 letter.setTextColor(0xFFFFFFFF); 81 letter.setGravity(Gravity.CENTER); 82 letter.setText(String.valueOf(Build.ID).substring(0, 1)); 83 84 final int p = (int)(4 * metrics.density); 85 86 final TextView tv = new TextView(this); 87 if (light != null) tv.setTypeface(light); 88 tv.setTextSize(30); 89 tv.setPadding(p, p, p, p); 90 tv.setTextColor(0xFFFFFFFF); 91 tv.setGravity(Gravity.CENTER); 92 tv.setTransformationMethod(new AllCapsTransformationMethod(this)); 93 tv.setText("Android " + Build.VERSION.RELEASE); 94 tv.setVisibility(View.INVISIBLE); 95 96 mContent.addView(bg); 97 mContent.addView(letter, lp); 98 mContent.addView(logo, lp); 99 100 final FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(lp); 101 lp2.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; 102 lp2.bottomMargin = 10*p; 103 104 mContent.addView(tv, lp2); 105 106 mContent.setOnClickListener(new View.OnClickListener() { 107 int clicks; 108 @Override 109 public void onClick(View v) { 110 clicks++; 111 if (clicks >= 6) { 112 mContent.performLongClick(); 113 return; 114 } 115 letter.animate().cancel(); 116 final float offset = (int)letter.getRotation() % 360; 117 letter.animate() 118 .rotationBy((Math.random() > 0.5f ? 360 : -360) - offset) 119 .setInterpolator(new DecelerateInterpolator()) 120 .setDuration(700).start(); 121 } 122 }); 123 124 mContent.setOnLongClickListener(new View.OnLongClickListener() { 125 @Override 126 public boolean onLongClick(View v) { 127 if (logo.getVisibility() != View.VISIBLE) { 128 bg.setScaleX(0.01f); 129 bg.animate().alpha(1f).scaleX(1f).setStartDelay(500).start(); 130 letter.animate().alpha(0f).scaleY(0.5f).scaleX(0.5f) 131 .rotationBy(360) 132 .setInterpolator(new AccelerateInterpolator()) 133 .setDuration(1000) 134 .start(); 135 logo.setAlpha(0f); 136 logo.setVisibility(View.VISIBLE); 137 logo.setScaleX(0.5f); 138 logo.setScaleY(0.5f); 139 logo.animate().alpha(1f).scaleX(1f).scaleY(1f) 140 .setDuration(1000).setStartDelay(500) 141 .setInterpolator(new AnticipateOvershootInterpolator()) 142 .start(); 143 tv.setAlpha(0f); 144 tv.setVisibility(View.VISIBLE); 145 tv.animate().alpha(1f).setDuration(1000).setStartDelay(1000).start(); 146 return true; 147 } 148 return false; 149 } 150 }); 151 152 logo.setOnLongClickListener(new View.OnLongClickListener() { 153 @Override 154 public boolean onLongClick(View v) { 155 if (Settings.System.getLong(getContentResolver(), Settings.System.EGG_MODE, 0) 156 == 0) { 157 // For posterity: the moment this user unlocked the easter egg 158 Settings.System.putLong(getContentResolver(), 159 Settings.System.EGG_MODE, 160 System.currentTimeMillis()); 161 } 162 try { 163 startActivity(new Intent(Intent.ACTION_MAIN) 164 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 165 | Intent.FLAG_ACTIVITY_CLEAR_TASK 166 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) 167 .addCategory("com.android.internal.category.PLATLOGO")); 168 } catch (ActivityNotFoundException ex) { 169 android.util.Log.e("PlatLogoActivity", "Couldn't catch a break."); 170 } 171 finish(); 172 return true; 173 } 174 }); 175 176 setContentView(mContent); 177 } 178 } 179