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.animation.Animator; 20 import android.animation.ObjectAnimator; 21 import android.annotation.Nullable; 22 import android.app.Activity; 23 import android.content.ActivityNotFoundException; 24 import android.content.ContentResolver; 25 import android.content.Intent; 26 import android.content.res.ColorStateList; 27 import android.graphics.Canvas; 28 import android.graphics.Color; 29 import android.graphics.ColorFilter; 30 import android.graphics.Outline; 31 import android.graphics.Paint; 32 import android.graphics.Path; 33 import android.graphics.PixelFormat; 34 import android.graphics.PorterDuff; 35 import android.graphics.PorterDuffColorFilter; 36 import android.graphics.drawable.Drawable; 37 import android.graphics.drawable.GradientDrawable; 38 import android.graphics.drawable.RippleDrawable; 39 import android.graphics.drawable.ShapeDrawable; 40 import android.graphics.drawable.shapes.OvalShape; 41 import android.os.Bundle; 42 import android.provider.Settings; 43 import android.util.DisplayMetrics; 44 import android.util.Log; 45 import android.util.MathUtils; 46 import android.view.Gravity; 47 import android.view.KeyEvent; 48 import android.view.View; 49 import android.view.ViewGroup; 50 import android.view.ViewOutlineProvider; 51 import android.view.animation.PathInterpolator; 52 import android.widget.FrameLayout; 53 import android.widget.ImageView; 54 55 public class PlatLogoActivity extends Activity { 56 public static final boolean FINISH = true; 57 58 FrameLayout mLayout; 59 int mTapCount; 60 int mKeyCount; 61 PathInterpolator mInterpolator = new PathInterpolator(0f, 0f, 0.5f, 1f); 62 63 @Override 64 protected void onCreate(Bundle savedInstanceState) { 65 super.onCreate(savedInstanceState); 66 67 mLayout = new FrameLayout(this); 68 setContentView(mLayout); 69 } 70 71 @Override 72 public void onAttachedToWindow() { 73 final DisplayMetrics dm = getResources().getDisplayMetrics(); 74 final float dp = dm.density; 75 final int size = (int) 76 (Math.min(Math.min(dm.widthPixels, dm.heightPixels), 600*dp) - 100*dp); 77 78 final ImageView im = new ImageView(this); 79 final int pad = (int)(40*dp); 80 im.setPadding(pad, pad, pad, pad); 81 im.setTranslationZ(20); 82 im.setScaleX(0.5f); 83 im.setScaleY(0.5f); 84 im.setAlpha(0f); 85 86 im.setBackground(new RippleDrawable( 87 ColorStateList.valueOf(0xFF776677), 88 getDrawable(com.android.internal.R.drawable.platlogo), 89 null)); 90 im.setOutlineProvider(new ViewOutlineProvider() { 91 @Override 92 public void getOutline(View view, Outline outline) { 93 final int w = view.getWidth(); 94 final int h = view.getHeight(); 95 outline.setOval((int)(w*.125), (int)(h*.125), (int)(w*.96), (int)(h*.96)); 96 } 97 }); 98 im.setElevation(12f*dp); 99 im.setClickable(true); 100 im.setOnClickListener(new View.OnClickListener() { 101 @Override 102 public void onClick(View v) { 103 im.setOnLongClickListener(new View.OnLongClickListener() { 104 @Override 105 public boolean onLongClick(View v) { 106 if (mTapCount < 5) return false; 107 108 final ContentResolver cr = getContentResolver(); 109 if (Settings.System.getLong(cr, Settings.System.EGG_MODE, 0) 110 == 0) { 111 // For posterity: the moment this user unlocked the easter egg 112 try { 113 Settings.System.putLong(cr, 114 Settings.System.EGG_MODE, 115 System.currentTimeMillis()); 116 } catch (RuntimeException e) { 117 Log.e("PlatLogoActivity", "Can't write settings", e); 118 } 119 } 120 im.post(new Runnable() { 121 @Override 122 public void run() { 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 Log.e("PlatLogoActivity", "No more eggs."); 131 } 132 if (FINISH) finish(); 133 } 134 }); 135 return true; 136 } 137 }); 138 mTapCount++; 139 } 140 }); 141 142 // Enable hardware keyboard input for TV compatibility. 143 im.setFocusable(true); 144 im.requestFocus(); 145 im.setOnKeyListener(new View.OnKeyListener() { 146 @Override 147 public boolean onKey(View v, int keyCode, KeyEvent event) { 148 if (keyCode != KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { 149 ++mKeyCount; 150 if (mKeyCount > 2) { 151 if (mTapCount > 5) { 152 im.performLongClick(); 153 } else { 154 im.performClick(); 155 } 156 } 157 return true; 158 } else { 159 return false; 160 } 161 } 162 }); 163 164 mLayout.addView(im, new FrameLayout.LayoutParams(size, size, Gravity.CENTER)); 165 166 im.animate().scaleX(1f).scaleY(1f).alpha(1f) 167 .setInterpolator(mInterpolator) 168 .setDuration(500) 169 .setStartDelay(800) 170 .start(); 171 } 172 } 173