PlatLogoActivity.java revision 6090995951c6e2e4dcf38102f01793f8a94166e1
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
17package com.android.internal.app;
18
19import android.app.Activity;
20import android.content.ActivityNotFoundException;
21import android.content.Intent;
22import android.graphics.Typeface;
23import android.provider.Settings;
24import android.os.Build;
25import android.os.Bundle;
26import android.os.Handler;
27import android.text.method.AllCapsTransformationMethod;
28import android.util.DisplayMetrics;
29import android.view.Gravity;
30import android.view.View;
31import android.view.animation.AccelerateInterpolator;
32import android.view.animation.AnticipateOvershootInterpolator;
33import android.view.animation.DecelerateInterpolator;
34import android.widget.FrameLayout;
35import android.widget.ImageView;
36import android.widget.TextView;
37
38public class PlatLogoActivity extends Activity {
39    FrameLayout mContent;
40    int mCount;
41    final Handler mHandler = new Handler();
42    static final int BGCOLOR = 0xffed1d24;
43
44    @Override
45    protected void onCreate(Bundle savedInstanceState) {
46        super.onCreate(savedInstanceState);
47
48        DisplayMetrics metrics = new DisplayMetrics();
49        getWindowManager().getDefaultDisplay().getMetrics(metrics);
50
51        Typeface bold = Typeface.create("sans-serif", Typeface.BOLD);
52        Typeface light = Typeface.create("sans-serif-light", Typeface.NORMAL);
53
54        mContent = new FrameLayout(this);
55        mContent.setBackgroundColor(0xC0000000);
56
57        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
67        final View bg = new View(this);
68        bg.setBackgroundColor(BGCOLOR);
69        bg.setAlpha(0f);
70
71        final TextView letter = new TextView(this);
72
73        letter.setTypeface(bold);
74        letter.setTextSize(300);
75        letter.setTextColor(0xFFFFFFFF);
76        letter.setGravity(Gravity.CENTER);
77        letter.setText(String.valueOf(Build.ID).substring(0, 1));
78
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);
87        tv.setTransformationMethod(new AllCapsTransformationMethod(this));
88        tv.setText("Android " + Build.VERSION.RELEASE);
89        tv.setVisibility(View.INVISIBLE);
90
91        mContent.addView(bg);
92        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);
100
101        mContent.setOnClickListener(new View.OnClickListener() {
102            int clicks;
103            @Override
104            public void onClick(View v) {
105                clicks++;
106                if (clicks >= 6) {
107                    mContent.performLongClick();
108                    return;
109                }
110                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();
116            }
117        });
118
119        mContent.setOnLongClickListener(new View.OnLongClickListener() {
120            @Override
121            public boolean onLongClick(View v) {
122                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) {
150                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                }
157                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"));
163                } catch (ActivityNotFoundException ex) {
164                    android.util.Log.e("PlatLogoActivity", "Couldn't catch a break.");
165                }
166                finish();
167                return true;
168            }
169        });
170
171        setContentView(mContent);
172    }
173}
174