Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 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; |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 20 | import android.content.ActivityNotFoundException; |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 21 | import android.content.Context; |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 22 | import android.content.Intent; |
Daniel Sandler | f89d507 | 2012-05-12 00:20:10 -0400 | [diff] [blame] | 23 | import android.graphics.Typeface; |
Daniel Sandler | 2fdb68b | 2013-10-03 00:12:11 -0400 | [diff] [blame] | 24 | import android.provider.Settings; |
Daniel Sandler | f89d507 | 2012-05-12 00:20:10 -0400 | [diff] [blame] | 25 | import android.os.Build; |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 26 | import android.os.Bundle; |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 27 | import android.os.Handler; |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 28 | import android.text.method.AllCapsTransformationMethod; |
| 29 | import android.text.method.TransformationMethod; |
Daniel Sandler | f89d507 | 2012-05-12 00:20:10 -0400 | [diff] [blame] | 30 | import android.util.DisplayMetrics; |
| 31 | import android.view.Gravity; |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 32 | import android.view.View; |
Daniel Sandler | f89d507 | 2012-05-12 00:20:10 -0400 | [diff] [blame] | 33 | import android.view.ViewGroup; |
Daniel Sandler | 80c3c4e | 2013-09-16 13:44:17 -0400 | [diff] [blame] | 34 | import android.view.animation.AccelerateInterpolator; |
| 35 | import android.view.animation.AnticipateOvershootInterpolator; |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 36 | import android.view.animation.DecelerateInterpolator; |
| 37 | import android.widget.FrameLayout; |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 38 | import android.widget.ImageView; |
Daniel Sandler | f89d507 | 2012-05-12 00:20:10 -0400 | [diff] [blame] | 39 | import android.widget.LinearLayout; |
| 40 | import android.widget.TextView; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 41 | import android.widget.Toast; |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 42 | |
| 43 | public class PlatLogoActivity extends Activity { |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 44 | FrameLayout mContent; |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 45 | int mCount; |
| 46 | final Handler mHandler = new Handler(); |
Daniel Sandler | 80c3c4e | 2013-09-16 13:44:17 -0400 | [diff] [blame] | 47 | static final int BGCOLOR = 0xffed1d24; |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 48 | |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 49 | @Override |
| 50 | protected void onCreate(Bundle savedInstanceState) { |
| 51 | super.onCreate(savedInstanceState); |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 52 | |
Daniel Sandler | f89d507 | 2012-05-12 00:20:10 -0400 | [diff] [blame] | 53 | DisplayMetrics metrics = new DisplayMetrics(); |
| 54 | getWindowManager().getDefaultDisplay().getMetrics(metrics); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 55 | |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 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); |
Daniel Sandler | 80c3c4e | 2013-09-16 13:44:17 -0400 | [diff] [blame] | 60 | mContent.setBackgroundColor(0xC0000000); |
Daniel Sandler | f89d507 | 2012-05-12 00:20:10 -0400 | [diff] [blame] | 61 | |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 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 | |
Daniel Sandler | 80c3c4e | 2013-09-16 13:44:17 -0400 | [diff] [blame] | 72 | final View bg = new View(this); |
| 73 | bg.setBackgroundColor(BGCOLOR); |
| 74 | bg.setAlpha(0f); |
| 75 | |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 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); |
Daniel Sandler | 70966ec | 2013-10-13 15:20:52 -0400 | [diff] [blame] | 82 | letter.setText(String.valueOf(Build.ID).substring(0, 1)); |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 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); |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 92 | tv.setTransformationMethod(new AllCapsTransformationMethod(this)); |
| 93 | tv.setText("Android " + Build.VERSION.RELEASE); |
| 94 | tv.setVisibility(View.INVISIBLE); |
| 95 | |
Daniel Sandler | 80c3c4e | 2013-09-16 13:44:17 -0400 | [diff] [blame] | 96 | mContent.addView(bg); |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 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); |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 105 | |
Daniel Sandler | 1a0c914 | 2012-05-07 16:09:10 -0400 | [diff] [blame] | 106 | mContent.setOnClickListener(new View.OnClickListener() { |
Daniel Sandler | 80c3c4e | 2013-09-16 13:44:17 -0400 | [diff] [blame] | 107 | int clicks; |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 108 | @Override |
Daniel Sandler | 1a0c914 | 2012-05-07 16:09:10 -0400 | [diff] [blame] | 109 | public void onClick(View v) { |
Daniel Sandler | 80c3c4e | 2013-09-16 13:44:17 -0400 | [diff] [blame] | 110 | clicks++; |
| 111 | if (clicks >= 6) { |
| 112 | mContent.performLongClick(); |
| 113 | return; |
Daniel Sandler | 06c0e40 | 2013-08-08 10:40:34 -0400 | [diff] [blame] | 114 | } |
Daniel Sandler | 80c3c4e | 2013-09-16 13:44:17 -0400 | [diff] [blame] | 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(); |
Daniel Sandler | 1a0c914 | 2012-05-07 16:09:10 -0400 | [diff] [blame] | 121 | } |
| 122 | }); |
| 123 | |
| 124 | mContent.setOnLongClickListener(new View.OnLongClickListener() { |
| 125 | @Override |
| 126 | public boolean onLongClick(View v) { |
Daniel Sandler | 80c3c4e | 2013-09-16 13:44:17 -0400 | [diff] [blame] | 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) { |
Daniel Sandler | 2fdb68b | 2013-10-03 00:12:11 -0400 | [diff] [blame] | 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 | } |
Daniel Sandler | 1a0c914 | 2012-05-07 16:09:10 -0400 | [diff] [blame] | 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")); |
Daniel Sandler | 1a0c914 | 2012-05-07 16:09:10 -0400 | [diff] [blame] | 168 | } catch (ActivityNotFoundException ex) { |
Daniel Sandler | 2fdb68b | 2013-10-03 00:12:11 -0400 | [diff] [blame] | 169 | android.util.Log.e("PlatLogoActivity", "Couldn't catch a break."); |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 170 | } |
Daniel Sandler | 1a0c914 | 2012-05-07 16:09:10 -0400 | [diff] [blame] | 171 | finish(); |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 172 | return true; |
| 173 | } |
| 174 | }); |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 175 | |
Daniel Sandler | 5f839f8 | 2011-10-12 01:45:26 -0400 | [diff] [blame] | 176 | setContentView(mContent); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 177 | } |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 178 | } |