Skip to content

Instantly share code, notes, and snippets.

@arnaudbos
Last active December 20, 2015 01:19
Show Gist options
  • Save arnaudbos/6048586 to your computer and use it in GitHub Desktop.
Save arnaudbos/6048586 to your computer and use it in GitHub Desktop.
Android view easter egg
private static final int EASTER_EGG_COUNT = 7;
private static final long EASTER_EGG_DURATION = 1000;
/** Easter egg click counter */
private int mEasterEggClickCount = 0;
/** Easter egg first click timestamp */
private long mEasterEggStart = -1;
/**
* User clicked the CA icon.
* @param pView The view that has been clicked.
*/
public void onIconButtonClicked(View pView) {
long lClickTimestamp = Calendar.getInstance().getTimeInMillis();
this.mEasterEggClickCount += 1;
if (this.mEasterEggStart == -1) {
this.mSomeHiddenView = findViewById(R.id.some_hidden_view);
this.mEasterEggStart += 1;
}
if (this.mEasterEggStart == 0) {
this.mEasterEggStart = lClickTimestamp;
}
if (this.mEasterEggClickCount < EASTER_EGG_COUNT) {
if (lClickTimestamp - this.mEasterEggStart > EASTER_EGG_DURATION) {
this.mEasterEggStart = 0;
this.mEasterEggClickCount = 0;
}
}
else if (lClickTimestamp - this.mEasterEggStart < EASTER_EGG_DURATION) {
Toast.makeText(this, "Congrats! You've just found the easter egg!", Toast.LENGTH_SHORT).show();
this.mSomeHiddenView.setVisibility(View.VISIBLE);
}
else if (lClickTimestamp - this.mEasterEggStart > EASTER_EGG_DURATION) {
this.mEasterEggStart = 0;
this.mEasterEggClickCount = 0;
}
}
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:onClick="onIconButtonClicked"
android:src="@drawable/ic_launcher_web" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment