If you own a cat, you probably own a laser pointer. Endless entertainment can be found by watching your cat chase around a speck of light.

Now you can experience laser pointer excitement every time you charge your Android phone.

Android Daydreams

Daydreams are basically screensavers that run while your phone is charging. They provide a bit of visual entertainment while your phone is idle.

Code

AnimatorListenerAdapter

    private final AnimatorListener mAnimListener = new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            // Start animation again
            try {
                elusiveDotAnimation();
            } catch(Exception e) {
                Log.e(TAG, e.getMessage());
            }
        }

    };

onAttachedToWindow

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();

        //read preferences
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        boolean prefInteractive = prefs.getBoolean(getString(R.string.pref_dream_interactive_key), false);
        boolean prefFullscreen = prefs.getBoolean(getString(R.string.pref_dream_fullscreen_key), false);

        // set screen preferences
        setInteractive(prefInteractive);
        setFullscreen(prefFullscreen);

        // Set the content view, just like you would with an Activity.
        setContentView(R.layout.dot_daydream);

        //red_dot
        mImageView = (ImageView)findViewById(R.id.dream_image);
        mImageView.setImageResource(R.drawable.reddot);
    }

elusiveDotAnimation

    private void elusiveDotAnimation() {
        // Refresh Size of Window
        getWindowManager().getDefaultDisplay().getSize(mPointSize);

        final int windowWidth = mPointSize.x;
        final int windowHeight = mPointSize.y;

        // Move ImageView to random y value
        mImageView.setTranslationX(mLastX);
        mImageView.setTranslationY(mLastY);

        //get new random positions
        int xRange = windowWidth - mImageView.getWidth();
        int yRange = windowHeight - mImageView.getHeight();
        mLastX = randInt(0, xRange);
        mLastY = randInt(0, yRange);

        // Create an Animator and keep a reference to it
        int randDuration = randInt(200, 1500);
        mAnimator = mImageView.animate()
                .translationX(mLastX)
                .translationY(mLastY)
                .setDuration(randDuration)
                .setListener(mAnimListener)
                .setInterpolator(sInterpolator);

        // Start the animation
        mAnimator.start();
    }

Download

Get it on Google Play