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 REVEAL_THE_NAME = false; 57 public static final boolean FINISH = false; 58 59 FrameLayout mLayout; 60 int mTapCount; 61 int mKeyCount; 62 PathInterpolator mInterpolator = new PathInterpolator(0f, 0f, 0.5f, 1f); 63 64 @Override 65 protected void onCreate(Bundle savedInstanceState) { 66 super.onCreate(savedInstanceState); 67 68 mLayout = new FrameLayout(this); 69 setContentView(mLayout); 70 } 71 72 @Override 73 public void onAttachedToWindow() { 74 final DisplayMetrics dm = getResources().getDisplayMetrics(); 75 final float dp = dm.density; 76 final int size = (int) 77 (Math.min(Math.min(dm.widthPixels, dm.heightPixels), 600*dp) - 100*dp); 78 79 final ImageView im = new ImageView(this); 80 final int pad = (int)(40*dp); 81 im.setPadding(pad, pad, pad, pad); 82 im.setTranslationZ(20); 83 im.setScaleX(0.5f); 84 im.setScaleY(0.5f); 85 im.setAlpha(0f); 86 87 im.setBackground(new RippleDrawable( 88 ColorStateList.valueOf(0xFFFFFFFF), 89 getDrawable(com.android.internal.R.drawable.platlogo), 90 null)); 91 // im.setOutlineProvider(new ViewOutlineProvider() { 92 // @Override 93 // public void getOutline(View view, Outline outline) { 94 // outline.setOval(0, 0, view.getWidth(), view.getHeight()); 95 // } 96 // }); 97 im.setClickable(true); 98 im.setOnClickListener(new View.OnClickListener() { 99 @Override 100 public void onClick(View v) { 101 im.setOnLongClickListener(new View.OnLongClickListener() { 102 @Override 103 public boolean onLongClick(View v) { 104 if (mTapCount < 5) return false; 105 106 if (REVEAL_THE_NAME) { 107 final Drawable overlay = getDrawable( 108 com.android.internal.R.drawable.platlogo_m); 109 overlay.setBounds(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); 110 im.getOverlay().clear(); 111 im.getOverlay().add(overlay); 112 overlay.setAlpha(0); 113 ObjectAnimator.ofInt(overlay, "alpha", 0, 255) 114 .setDuration(500) 115 .start(); 116 } 117 118 final ContentResolver cr = getContentResolver(); 119 if (Settings.System.getLong(cr, Settings.System.EGG_MODE, 0) 120 == 0) { 121 // For posterity: the moment this user unlocked the easter egg 122 try { 123 Settings.System.putLong(cr, 124 Settings.System.EGG_MODE, 125 System.currentTimeMillis()); 126 } catch (RuntimeException e) { 127 Log.e("PlatLogoActivity", "Can't write settings", e); 128 } 129 } 130 im.post(new Runnable() { 131 @Override 132 public void run() { 133 try { 134 startActivity(new Intent(Intent.ACTION_MAIN) 135 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 136 | Intent.FLAG_ACTIVITY_CLEAR_TASK 137 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) 138 .addCategory("com.android.internal.category.PLATLOGO")); 139 } catch (ActivityNotFoundException ex) { 140 Log.e("PlatLogoActivity", "No more eggs."); 141 } 142 if (FINISH) finish(); 143 } 144 }); 145 return true; 146 } 147 }); 148 mTapCount++; 149 } 150 }); 151 152 // Enable hardware keyboard input for TV compatibility. 153 im.setFocusable(true); 154 im.requestFocus(); 155 im.setOnKeyListener(new View.OnKeyListener() { 156 @Override 157 public boolean onKey(View v, int keyCode, KeyEvent event) { 158 if (keyCode != KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { 159 ++mKeyCount; 160 if (mKeyCount > 2) { 161 if (mTapCount > 5) { 162 im.performLongClick(); 163 } else { 164 im.performClick(); 165 } 166 } 167 return true; 168 } else { 169 return false; 170 } 171 } 172 }); 173 174 mLayout.addView(im, new FrameLayout.LayoutParams(size, size, Gravity.CENTER)); 175 176 im.animate().scaleX(1f).scaleY(1f).alpha(1f) 177 .setInterpolator(mInterpolator) 178 .setDuration(500) 179 .setStartDelay(800) 180 .start(); 181 } 182 } 183