关于android4.0.4中彩蛋的实现
情况:
在android4.0.4的系统设置-关于手机-Android版本,连续快速点击几下,就会出现一个机器人,长按住机器人不放,机器人会一直变大,然后出现一堆机器从屏幕上飞过
觉得有点意思,于是想看看是怎么实现的,电脑上有android4.0的代码。
系统设置-关于手机的代码:
packages/apps/Settings/src/com/android/settings/DeviceInfoSettings.java
其中,点击选项的处理如下:
long[] mHits = new long[3];
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (preference.getKey().equals(KEY_FIRMWARE_VERSION)) {
System.arraycopy(mHits, 1, mHits, 0, mHits.length-1);
mHits[mHits.length-1] = SystemClock.uptimeMillis();
if (mHits[0] >= (SystemClock.uptimeMillis()-500)) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("android",
com.android.internal.app.PlatLogoActivity.class.getName());
try {
startActivity(intent);
} catch (Exception e) {
Log.e(LOG_TAG, "Unable to start activity " + intent.toString());
}
}
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
这里可以看到对固件版本选项有特殊处理:
if (preference.getKey().equals(KEY_FIRMWARE_VERSION)) {
//如果点击的是固件版本,则记录下最近三次点击的时间;
//如果三次点击的总时间少于500ms,则启动com.android.internal.app.PlatLogoActivity
}
再看PlatLogoActivity的实现:
public class PlatLogoActivity extends Activity {
Toast mToast;
ImageView mContent;
Vibrator mZzz = new Vibrator();
int mCount;
final Handler mHandler = new Handler();
Runnable mSuperLongPress = new Runnable() {
public void run() {
mCount++;
mZzz.vibrate(50 * mCount);
final float scale = 1f + 0.25f * mCount * mCount;
mContent.setScaleX(scale);
mContent.setScaleY(scale);
if (mCount <= 3) {
mHandler.postDelayed(mSuperLongPress, ViewConfiguration.getLongPressTimeout());
} else {
try {
startActivity(new Intent(Intent.ACTION_MAIN)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
.setClassName("com.android.systemui","com.android.systemui.Nyandroid"));
} catch (ActivityNotFoundException ex) {
android.util.Log.e("PlatLogoActivity", "Couldn't find platlogo screensaver.");
}
finish();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mToast = Toast.makeText(this, "Android 4.0: Ice Cream Sandwich", Toast.LENGTH_SHORT);
mContent = new ImageView(this);
mContent.setImageResource(com.android.internal.R.drawable.platlogo);
mContent.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
mContent.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
mContent.setPressed(true);
mHandler.removeCallbacks(mSuperLongPress);
mCount = 0;
m
补充:移动开发 , Android ,