Last active
December 20, 2015 01:19
-
-
Save arnaudbos/6048586 to your computer and use it in GitHub Desktop.
Android view easter egg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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