PlatLogoActivity.java revision c2346134bb519a54d50655cbef940fc3fdec60a9
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.os.Bundle; 23import android.os.Handler; 24import android.os.Vibrator; 25import android.view.MotionEvent; 26import android.view.View; 27import android.view.ViewConfiguration; 28import android.widget.ImageView; 29import android.widget.Toast; 30 31public class PlatLogoActivity extends Activity { 32 Vibrator mZzz; 33 Toast mToast; 34 ImageView mContent; 35 int mCount; 36 final Handler mHandler = new Handler(); 37 38 Runnable mSuperLongPress = new Runnable() { 39 public void run() { 40 mCount++; 41 mZzz.vibrate(50 * mCount); 42 final float scale = 1f + 0.25f * mCount * mCount; 43 mContent.setScaleX(scale); 44 mContent.setScaleY(scale); 45 46 if (mCount <= 3) { 47 mHandler.postDelayed(mSuperLongPress, ViewConfiguration.getLongPressTimeout()); 48 } else { 49 try { 50 startActivity(new Intent(Intent.ACTION_MAIN) 51 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 52 | Intent.FLAG_ACTIVITY_CLEAR_TASK 53 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) 54 .setClassName("com.android.systemui","com.android.systemui.Nyandroid")); 55 } catch (ActivityNotFoundException ex) { 56 android.util.Log.e("PlatLogoActivity", "Couldn't find platlogo screensaver."); 57 } 58 finish(); 59 } 60 } 61 }; 62 63 @Override 64 protected void onCreate(Bundle savedInstanceState) { 65 super.onCreate(savedInstanceState); 66 67 mZzz = (Vibrator)getSystemService(VIBRATOR_SERVICE); 68 mToast = Toast.makeText(this, "Android 4.0: Ice Cream Sandwich", Toast.LENGTH_SHORT); 69 70 mContent = new ImageView(this); 71 mContent.setImageResource(com.android.internal.R.drawable.platlogo); 72 mContent.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 73 74 mContent.setOnTouchListener(new View.OnTouchListener() { 75 @Override 76 public boolean onTouch(View v, MotionEvent event) { 77 final int action = event.getAction(); 78 if (action == MotionEvent.ACTION_DOWN) { 79 mContent.setPressed(true); 80 mHandler.removeCallbacks(mSuperLongPress); 81 mCount = 0; 82 mHandler.postDelayed(mSuperLongPress, 2*ViewConfiguration.getLongPressTimeout()); 83 } else if (action == MotionEvent.ACTION_UP) { 84 if (mContent.isPressed()) { 85 mContent.setPressed(false); 86 mHandler.removeCallbacks(mSuperLongPress); 87 mToast.show(); 88 } 89 } 90 return true; 91 } 92 }); 93 94 setContentView(mContent); 95 } 96} 97