Search in sources :

Example 36 with Handler

use of android.os.Handler 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)

Example 37 with Handler

use of android.os.Handler in project platform_frameworks_base by android.

the class ViewPropertyAnimatorTest method testPlayingDelayedCancelMidDelay.

/**
     * Same as testPlayingDelayedCancel, but cancel during the startDelay period
     */
@MediumTest
public void testPlayingDelayedCancelMidDelay() throws Exception {
    mAnimator.setStartDelay(ANIM_DELAY);
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            try {
                // Set the listener to automatically timeout after an uncanceled animation
                // would have finished. This tests to make sure that we're not calling
                // the listeners with cancel/end callbacks since they won't be called
                // with the start event.
                mFutureListener = new FutureReleaseListener(mFuture, getTimeout());
                Handler handler = new Handler();
                mRunning = true;
                mAnimator.start();
                handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DELAY);
            } catch (junit.framework.AssertionFailedError e) {
                mFuture.setException(new RuntimeException(e));
            }
        }
    });
    mFuture.get(getTimeout() + 100, TimeUnit.MILLISECONDS);
}
Also used : Handler(android.os.Handler) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 38 with Handler

use of android.os.Handler in project platform_frameworks_base by android.

the class ViewPropertyAnimatorTest method testPlayingCancel.

/**
     * Verify that canceling an animator that is playing does the right thing.
     */
@MediumTest
public void testPlayingCancel() throws Exception {
    mFutureListener = new FutureReleaseListener(mFuture);
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            try {
                Handler handler = new Handler();
                mAnimator.setListener(mFutureListener);
                mRunning = true;
                mAnimator.start();
                handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
            } catch (junit.framework.AssertionFailedError e) {
                mFuture.setException(new RuntimeException(e));
            }
        }
    });
    mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
}
Also used : Handler(android.os.Handler) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 39 with Handler

use of android.os.Handler in project platform_frameworks_base by android.

the class ViewPropertyAnimatorTest method testPlayingDelayedCancel.

/**
     * Same as testPlayingCancel, but with a startDelayed animator
     */
@MediumTest
public void testPlayingDelayedCancel() throws Exception {
    mAnimator.setStartDelay(ANIM_DELAY);
    mFutureListener = new FutureReleaseListener(mFuture);
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            try {
                Handler handler = new Handler();
                mAnimator.setListener(mFutureListener);
                mRunning = true;
                mAnimator.start();
                handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
            } catch (junit.framework.AssertionFailedError e) {
                mFuture.setException(new RuntimeException(e));
            }
        }
    });
    mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
}
Also used : Handler(android.os.Handler) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 40 with Handler

use of android.os.Handler in project platform_frameworks_base by android.

the class EventsTest method testPlayingCancel.

/**
     * Verify that canceling an animator that is playing does the right thing.
     */
@MediumTest
public void testPlayingCancel() throws Exception {
    mFutureListener = new FutureReleaseListener(mFuture);
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            try {
                Handler handler = new Handler();
                mAnimator.addListener(mFutureListener);
                mRunning = true;
                mAnimator.start();
                handler.postDelayed(new Canceler(mAnimator, mFuture), ANIM_MID_DURATION);
            } catch (junit.framework.AssertionFailedError e) {
                mFuture.setException(new RuntimeException(e));
            }
        }
    });
    mFuture.get(getTimeout(), TimeUnit.MILLISECONDS);
}
Also used : Handler(android.os.Handler) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

Handler (android.os.Handler)1904 Message (android.os.Message)254 View (android.view.View)207 Intent (android.content.Intent)174 HandlerThread (android.os.HandlerThread)156 TextView (android.widget.TextView)118 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 ArrayList (java.util.ArrayList)97 Test (org.junit.Test)85 Context (android.content.Context)71 IntentFilter (android.content.IntentFilter)69 RemoteException (android.os.RemoteException)63 IOException (java.io.IOException)63 ComponentName (android.content.ComponentName)57 ImageView (android.widget.ImageView)57 Bundle (android.os.Bundle)56 RecyclerView (android.support.v7.widget.RecyclerView)54 Looper (android.os.Looper)53 File (java.io.File)46 ContentObserver (android.database.ContentObserver)44