blob: 8cdaf91ca1c9c49233e5c6fa5b50d340f4ceaf00 [file] [log] [blame]
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001/*
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;
Daniel Sandler5f839f82011-10-12 01:45:26 -040020import android.content.ActivityNotFoundException;
21import android.content.Intent;
Daniel Sandlerf89d5072012-05-12 00:20:10 -040022import android.graphics.Typeface;
Daniel Sandler2fdb68b2013-10-03 00:12:11 -040023import android.provider.Settings;
Daniel Sandlerf89d5072012-05-12 00:20:10 -040024import android.os.Build;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070025import android.os.Bundle;
Daniel Sandler5f839f82011-10-12 01:45:26 -040026import android.os.Handler;
Daniel Sandler06c0e402013-08-08 10:40:34 -040027import android.text.method.AllCapsTransformationMethod;
Daniel Sandlerf89d5072012-05-12 00:20:10 -040028import android.util.DisplayMetrics;
29import android.view.Gravity;
Daniel Sandler5f839f82011-10-12 01:45:26 -040030import android.view.View;
Daniel Sandler80c3c4e2013-09-16 13:44:17 -040031import android.view.animation.AccelerateInterpolator;
32import android.view.animation.AnticipateOvershootInterpolator;
Daniel Sandler06c0e402013-08-08 10:40:34 -040033import android.view.animation.DecelerateInterpolator;
34import android.widget.FrameLayout;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070035import android.widget.ImageView;
Daniel Sandlerf89d5072012-05-12 00:20:10 -040036import android.widget.TextView;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070037
38public class PlatLogoActivity extends Activity {
Daniel Sandler06c0e402013-08-08 10:40:34 -040039 FrameLayout mContent;
Daniel Sandler5f839f82011-10-12 01:45:26 -040040 int mCount;
41 final Handler mHandler = new Handler();
Daniel Sandler80c3c4e2013-09-16 13:44:17 -040042 static final int BGCOLOR = 0xffed1d24;
Daniel Sandler5f839f82011-10-12 01:45:26 -040043
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070044 @Override
45 protected void onCreate(Bundle savedInstanceState) {
46 super.onCreate(savedInstanceState);
Jeff Brownc2346132012-04-13 01:55:38 -070047
Daniel Sandlerf89d5072012-05-12 00:20:10 -040048 DisplayMetrics metrics = new DisplayMetrics();
49 getWindowManager().getDefaultDisplay().getMetrics(metrics);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070050
Daniel Sandler06c0e402013-08-08 10:40:34 -040051 Typeface bold = Typeface.create("sans-serif", Typeface.BOLD);
52 Typeface light = Typeface.create("sans-serif-light", Typeface.NORMAL);
53
54 mContent = new FrameLayout(this);
Daniel Sandler80c3c4e2013-09-16 13:44:17 -040055 mContent.setBackgroundColor(0xC0000000);
Daniel Sandlerf89d5072012-05-12 00:20:10 -040056
Daniel Sandler06c0e402013-08-08 10:40:34 -040057 final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
58 FrameLayout.LayoutParams.WRAP_CONTENT,
59 FrameLayout.LayoutParams.WRAP_CONTENT);
60 lp.gravity = Gravity.CENTER;
61
62 final ImageView logo = new ImageView(this);
63 logo.setImageResource(com.android.internal.R.drawable.platlogo);
64 logo.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
65 logo.setVisibility(View.INVISIBLE);
66
Daniel Sandler80c3c4e2013-09-16 13:44:17 -040067 final View bg = new View(this);
68 bg.setBackgroundColor(BGCOLOR);
69 bg.setAlpha(0f);
70
Daniel Sandler06c0e402013-08-08 10:40:34 -040071 final TextView letter = new TextView(this);
72
73 letter.setTypeface(bold);
74 letter.setTextSize(300);
75 letter.setTextColor(0xFFFFFFFF);
76 letter.setGravity(Gravity.CENTER);
Daniel Sandler70966ec2013-10-13 15:20:52 -040077 letter.setText(String.valueOf(Build.ID).substring(0, 1));
Daniel Sandler06c0e402013-08-08 10:40:34 -040078
79 final int p = (int)(4 * metrics.density);
80
81 final TextView tv = new TextView(this);
82 if (light != null) tv.setTypeface(light);
83 tv.setTextSize(30);
84 tv.setPadding(p, p, p, p);
85 tv.setTextColor(0xFFFFFFFF);
86 tv.setGravity(Gravity.CENTER);
Daniel Sandler06c0e402013-08-08 10:40:34 -040087 tv.setTransformationMethod(new AllCapsTransformationMethod(this));
88 tv.setText("Android " + Build.VERSION.RELEASE);
89 tv.setVisibility(View.INVISIBLE);
90
Daniel Sandler80c3c4e2013-09-16 13:44:17 -040091 mContent.addView(bg);
Daniel Sandler06c0e402013-08-08 10:40:34 -040092 mContent.addView(letter, lp);
93 mContent.addView(logo, lp);
94
95 final FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(lp);
96 lp2.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
97 lp2.bottomMargin = 10*p;
98
99 mContent.addView(tv, lp2);
Daniel Sandler5f839f82011-10-12 01:45:26 -0400100
Daniel Sandler1a0c9142012-05-07 16:09:10 -0400101 mContent.setOnClickListener(new View.OnClickListener() {
Daniel Sandler80c3c4e2013-09-16 13:44:17 -0400102 int clicks;
Daniel Sandler5f839f82011-10-12 01:45:26 -0400103 @Override
Daniel Sandler1a0c9142012-05-07 16:09:10 -0400104 public void onClick(View v) {
Daniel Sandler80c3c4e2013-09-16 13:44:17 -0400105 clicks++;
106 if (clicks >= 6) {
107 mContent.performLongClick();
108 return;
Daniel Sandler06c0e402013-08-08 10:40:34 -0400109 }
Daniel Sandler80c3c4e2013-09-16 13:44:17 -0400110 letter.animate().cancel();
111 final float offset = (int)letter.getRotation() % 360;
112 letter.animate()
113 .rotationBy((Math.random() > 0.5f ? 360 : -360) - offset)
114 .setInterpolator(new DecelerateInterpolator())
115 .setDuration(700).start();
Daniel Sandler1a0c9142012-05-07 16:09:10 -0400116 }
117 });
118
119 mContent.setOnLongClickListener(new View.OnLongClickListener() {
120 @Override
121 public boolean onLongClick(View v) {
Daniel Sandler80c3c4e2013-09-16 13:44:17 -0400122 if (logo.getVisibility() != View.VISIBLE) {
123 bg.setScaleX(0.01f);
124 bg.animate().alpha(1f).scaleX(1f).setStartDelay(500).start();
125 letter.animate().alpha(0f).scaleY(0.5f).scaleX(0.5f)
126 .rotationBy(360)
127 .setInterpolator(new AccelerateInterpolator())
128 .setDuration(1000)
129 .start();
130 logo.setAlpha(0f);
131 logo.setVisibility(View.VISIBLE);
132 logo.setScaleX(0.5f);
133 logo.setScaleY(0.5f);
134 logo.animate().alpha(1f).scaleX(1f).scaleY(1f)
135 .setDuration(1000).setStartDelay(500)
136 .setInterpolator(new AnticipateOvershootInterpolator())
137 .start();
138 tv.setAlpha(0f);
139 tv.setVisibility(View.VISIBLE);
140 tv.animate().alpha(1f).setDuration(1000).setStartDelay(1000).start();
141 return true;
142 }
143 return false;
144 }
145 });
146
147 logo.setOnLongClickListener(new View.OnLongClickListener() {
148 @Override
149 public boolean onLongClick(View v) {
Daniel Sandler2fdb68b2013-10-03 00:12:11 -0400150 if (Settings.System.getLong(getContentResolver(), Settings.System.EGG_MODE, 0)
151 == 0) {
152 // For posterity: the moment this user unlocked the easter egg
153 Settings.System.putLong(getContentResolver(),
154 Settings.System.EGG_MODE,
155 System.currentTimeMillis());
156 }
Daniel Sandler1a0c9142012-05-07 16:09:10 -0400157 try {
158 startActivity(new Intent(Intent.ACTION_MAIN)
159 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
160 | Intent.FLAG_ACTIVITY_CLEAR_TASK
161 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
162 .addCategory("com.android.internal.category.PLATLOGO"));
Daniel Sandler1a0c9142012-05-07 16:09:10 -0400163 } catch (ActivityNotFoundException ex) {
Daniel Sandler2fdb68b2013-10-03 00:12:11 -0400164 android.util.Log.e("PlatLogoActivity", "Couldn't catch a break.");
Daniel Sandler5f839f82011-10-12 01:45:26 -0400165 }
Daniel Sandler1a0c9142012-05-07 16:09:10 -0400166 finish();
Daniel Sandler5f839f82011-10-12 01:45:26 -0400167 return true;
168 }
169 });
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700170
Daniel Sandler5f839f82011-10-12 01:45:26 -0400171 setContentView(mContent);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700172 }
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700173}