blob: 40a705c6826d92bfe6b8884c9599678339eb3cdc [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;
Daniel Sandler06c0e402013-08-08 10:40:34 -040021import android.content.Context;
Daniel Sandler5f839f82011-10-12 01:45:26 -040022import android.content.Intent;
Daniel Sandlerf89d5072012-05-12 00:20:10 -040023import android.graphics.Typeface;
Daniel Sandler2fdb68b2013-10-03 00:12:11 -040024import android.provider.Settings;
Daniel Sandlerf89d5072012-05-12 00:20:10 -040025import android.os.Build;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070026import android.os.Bundle;
Daniel Sandler5f839f82011-10-12 01:45:26 -040027import android.os.Handler;
Daniel Sandler06c0e402013-08-08 10:40:34 -040028import android.text.method.AllCapsTransformationMethod;
29import android.text.method.TransformationMethod;
Daniel Sandlerf89d5072012-05-12 00:20:10 -040030import android.util.DisplayMetrics;
31import android.view.Gravity;
Daniel Sandler5f839f82011-10-12 01:45:26 -040032import android.view.View;
Daniel Sandlerf89d5072012-05-12 00:20:10 -040033import android.view.ViewGroup;
Daniel Sandler80c3c4e2013-09-16 13:44:17 -040034import android.view.animation.AccelerateInterpolator;
35import android.view.animation.AnticipateOvershootInterpolator;
Daniel Sandler06c0e402013-08-08 10:40:34 -040036import android.view.animation.DecelerateInterpolator;
37import android.widget.FrameLayout;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070038import android.widget.ImageView;
Daniel Sandlerf89d5072012-05-12 00:20:10 -040039import android.widget.LinearLayout;
40import android.widget.TextView;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070041import android.widget.Toast;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070042
43public class PlatLogoActivity extends Activity {
Daniel Sandler06c0e402013-08-08 10:40:34 -040044 FrameLayout mContent;
Daniel Sandler5f839f82011-10-12 01:45:26 -040045 int mCount;
46 final Handler mHandler = new Handler();
Daniel Sandler80c3c4e2013-09-16 13:44:17 -040047 static final int BGCOLOR = 0xffed1d24;
Daniel Sandler5f839f82011-10-12 01:45:26 -040048
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070049 @Override
50 protected void onCreate(Bundle savedInstanceState) {
51 super.onCreate(savedInstanceState);
Jeff Brownc2346132012-04-13 01:55:38 -070052
Daniel Sandlerf89d5072012-05-12 00:20:10 -040053 DisplayMetrics metrics = new DisplayMetrics();
54 getWindowManager().getDefaultDisplay().getMetrics(metrics);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070055
Daniel Sandler06c0e402013-08-08 10:40:34 -040056 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 Sandler80c3c4e2013-09-16 13:44:17 -040060 mContent.setBackgroundColor(0xC0000000);
Daniel Sandlerf89d5072012-05-12 00:20:10 -040061
Daniel Sandler06c0e402013-08-08 10:40:34 -040062 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 Sandler80c3c4e2013-09-16 13:44:17 -040072 final View bg = new View(this);
73 bg.setBackgroundColor(BGCOLOR);
74 bg.setAlpha(0f);
75
Daniel Sandler06c0e402013-08-08 10:40:34 -040076 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 Sandler70966ec2013-10-13 15:20:52 -040082 letter.setText(String.valueOf(Build.ID).substring(0, 1));
Daniel Sandler06c0e402013-08-08 10:40:34 -040083
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 Sandler06c0e402013-08-08 10:40:34 -040092 tv.setTransformationMethod(new AllCapsTransformationMethod(this));
93 tv.setText("Android " + Build.VERSION.RELEASE);
94 tv.setVisibility(View.INVISIBLE);
95
Daniel Sandler80c3c4e2013-09-16 13:44:17 -040096 mContent.addView(bg);
Daniel Sandler06c0e402013-08-08 10:40:34 -040097 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 Sandler5f839f82011-10-12 01:45:26 -0400105
Daniel Sandler1a0c9142012-05-07 16:09:10 -0400106 mContent.setOnClickListener(new View.OnClickListener() {
Daniel Sandler80c3c4e2013-09-16 13:44:17 -0400107 int clicks;
Daniel Sandler5f839f82011-10-12 01:45:26 -0400108 @Override
Daniel Sandler1a0c9142012-05-07 16:09:10 -0400109 public void onClick(View v) {
Daniel Sandler80c3c4e2013-09-16 13:44:17 -0400110 clicks++;
111 if (clicks >= 6) {
112 mContent.performLongClick();
113 return;
Daniel Sandler06c0e402013-08-08 10:40:34 -0400114 }
Daniel Sandler80c3c4e2013-09-16 13:44:17 -0400115 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 Sandler1a0c9142012-05-07 16:09:10 -0400121 }
122 });
123
124 mContent.setOnLongClickListener(new View.OnLongClickListener() {
125 @Override
126 public boolean onLongClick(View v) {
Daniel Sandler80c3c4e2013-09-16 13:44:17 -0400127 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 Sandler2fdb68b2013-10-03 00:12:11 -0400155 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 Sandler1a0c9142012-05-07 16:09:10 -0400162 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 Sandler1a0c9142012-05-07 16:09:10 -0400168 } catch (ActivityNotFoundException ex) {
Daniel Sandler2fdb68b2013-10-03 00:12:11 -0400169 android.util.Log.e("PlatLogoActivity", "Couldn't catch a break.");
Daniel Sandler5f839f82011-10-12 01:45:26 -0400170 }
Daniel Sandler1a0c9142012-05-07 16:09:10 -0400171 finish();
Daniel Sandler5f839f82011-10-12 01:45:26 -0400172 return true;
173 }
174 });
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700175
Daniel Sandler5f839f82011-10-12 01:45:26 -0400176 setContentView(mContent);
Dianne Hackborn1ebccf52010-08-15 13:04:34 -0700177 }
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700178}