|
17 | 17 | package com.android.internal.app; |
18 | 18 |
|
19 | 19 | import android.app.Activity; |
| 20 | +import android.content.ActivityNotFoundException; |
| 21 | +import android.content.Intent; |
20 | 22 | import android.os.Bundle; |
| 23 | +import android.os.Handler; |
| 24 | +import android.os.Vibrator; |
21 | 25 | import android.view.MotionEvent; |
| 26 | +import android.view.View; |
| 27 | +import android.view.ViewConfiguration; |
22 | 28 | import android.widget.ImageView; |
23 | 29 | import android.widget.Toast; |
24 | 30 |
|
25 | 31 | public class PlatLogoActivity extends Activity { |
26 | 32 | Toast mToast; |
| 33 | + ImageView mContent; |
| 34 | + Vibrator mZzz = new Vibrator(); |
| 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 | + }; |
27 | 62 |
|
28 | 63 | @Override |
29 | 64 | protected void onCreate(Bundle savedInstanceState) { |
30 | 65 | super.onCreate(savedInstanceState); |
31 | 66 |
|
32 | | - mToast = Toast.makeText(this, "REZZZZZZZ...", Toast.LENGTH_SHORT); |
| 67 | + mToast = Toast.makeText(this, "Android 4.0: Ice Cream Sandwich", Toast.LENGTH_SHORT); |
33 | 68 |
|
34 | | - ImageView content = new ImageView(this); |
35 | | - content.setImageResource(com.android.internal.R.drawable.platlogo); |
36 | | - content.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
37 | | - |
38 | | - setContentView(content); |
39 | | - } |
| 69 | + mContent = new ImageView(this); |
| 70 | + mContent.setImageResource(com.android.internal.R.drawable.platlogo); |
| 71 | + mContent.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
40 | 72 |
|
41 | | - @Override |
42 | | - public boolean dispatchTouchEvent(MotionEvent ev) { |
43 | | - if (ev.getAction() == MotionEvent.ACTION_UP) { |
44 | | - mToast.show(); |
45 | | - } |
46 | | - return super.dispatchTouchEvent(ev); |
| 73 | + mContent.setOnTouchListener(new View.OnTouchListener() { |
| 74 | + @Override |
| 75 | + public boolean onTouch(View v, MotionEvent event) { |
| 76 | + final int action = event.getAction(); |
| 77 | + if (action == MotionEvent.ACTION_DOWN) { |
| 78 | + mContent.setPressed(true); |
| 79 | + mHandler.removeCallbacks(mSuperLongPress); |
| 80 | + mCount = 0; |
| 81 | + mHandler.postDelayed(mSuperLongPress, 2*ViewConfiguration.getLongPressTimeout()); |
| 82 | + } else if (action == MotionEvent.ACTION_UP) { |
| 83 | + if (mContent.isPressed()) { |
| 84 | + mContent.setPressed(false); |
| 85 | + mHandler.removeCallbacks(mSuperLongPress); |
| 86 | + mToast.show(); |
| 87 | + } |
| 88 | + } |
| 89 | + return true; |
| 90 | + } |
| 91 | + }); |
| 92 | + |
| 93 | + setContentView(mContent); |
47 | 94 | } |
48 | 95 | } |
0 commit comments