Search in sources :

Example 1 with PhotoViewerVisibilityChangeEvent

use of com.bourke.glimmr.fragments.viewer.PhotoViewerFragment.PhotoViewerVisibilityChangeEvent in project glimmr by brk3.

the class PhotoViewerActivity method startSlideshow.

private void startSlideshow() {
    final Handler handler = new Handler();
    SharedPreferences defaultSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    final int delay_m = Integer.parseInt(defaultSharedPrefs.getString(Constants.KEY_SLIDESHOW_INTERVAL, "3")) * 1000;
    if (BuildConfig.DEBUG)
        Log.d(TAG, "slideshow delay: " + delay_m);
    mTimer = new Timer();
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    mTimer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            handler.post(new Runnable() {

                @Override
                public void run() {
                    int currentPosition = mPager.getCurrentItem();
                    currentPosition++;
                    if (currentPosition >= mAdapter.getCount()) {
                        currentPosition = 0;
                    }
                    mPager.setCurrentItem(currentPosition);
                }
            });
        }
    }, delay_m, delay_m);
    BusProvider.getInstance().post(new PhotoViewerVisibilityChangeEvent(!mActionBar.isShowing(), this));
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) SharedPreferences(android.content.SharedPreferences) Handler(android.os.Handler) PhotoViewerVisibilityChangeEvent(com.bourke.glimmr.fragments.viewer.PhotoViewerFragment.PhotoViewerVisibilityChangeEvent)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 Handler (android.os.Handler)1 PhotoViewerVisibilityChangeEvent (com.bourke.glimmr.fragments.viewer.PhotoViewerFragment.PhotoViewerVisibilityChangeEvent)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1