Example usage for android.os Handler postDelayed

List of usage examples for android.os Handler postDelayed

Introduction

In this page you can find the example usage for android.os Handler postDelayed.

Prototype

public final boolean postDelayed(Runnable r, long delayMillis) 

Source Link

Document

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

Usage

From source file:com.mfinatti.truckfinder.data.TrucksServiceApiImpl.java

@Override
public void getAllTrucks(final TrucksServiceCallback callback) {
    // Simulate network by delaying the execution.
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override//from  w  w  w .ja  va  2s.co m
        public void run() {
            List<Truck> Trucks = new ArrayList<>(TRUCKS_SERVICE_DATA.values());
            callback.onLoaded(Trucks);
        }
    }, SERVICE_LATENCY_IN_MILLIS);
}

From source file:com.willowtreeapps.spurceexampleapp.SplashActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    logoImageView = (ImageView) findViewById(R.id.ivLogo);
    logoImageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.spruce_logo));

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override/*from   w ww . j a va  2  s  .c  o m*/
        public void run() {
            startActivity(new Intent(SplashActivity.this, SpruceActivity.class));
            finish();
        }
    }, SPLASH_TIMEOUT);

}

From source file:com.example.notesapp.data.NotesServiceApiImpl.java

@Override
public void getAllNotes(final NotesServiceCallback callback) {
    // Simulate network by delaying the execution.
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override//w w w . j  a  v a 2s .c  om
        public void run() {

            callback.onLoaded(NotesServiceApiEndpoint.getInstance().loadPersistedNotes());
        }
    }, SERVICE_LATENCY_IN_MILLIS);
}

From source file:com.LogIn.Visualization.Visualization.java

protected void onResume() {
    super.onResume();
    final ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
    if (vp != null) {
        vp.setAdapter(new AdvancedPagerAdapter());
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override//from   w w w  .  ja  v a  2s  . c  om
            public void run() {
                vp.setCurrentItem(Utility.getDaysDiff());
            }
        }, 100);
    }
}

From source file:com.example.android.leanback.BrowseErrorSupportActivity.java

private void testError() {
    mErrorSupportFragment = new ErrorSupportFragment();
    getSupportFragmentManager().beginTransaction().add(R.id.main_frame, mErrorSupportFragment).commit();

    mSpinnerSupportFragment = new SpinnerSupportFragment();
    getSupportFragmentManager().beginTransaction().add(R.id.main_frame, mSpinnerSupportFragment).commit();

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override/*from w w  w. java  2s  . c  o m*/
        public void run() {
            if (getSupportFragmentManager().isDestroyed()) {
                return;
            }
            getSupportFragmentManager().beginTransaction().remove(mSpinnerSupportFragment).commit();
            mErrorSupportFragment.setErrorContent(getResources());
        }
    }, 3000);
}

From source file:com.pinkwerther.support.ads.PinkwertherAds.java

@Override
public void init(final PinkwertherSupport pwSupport, Bundle bundle) {
    this.pwSupport = pwSupport;
    mAds = getDefaultBanner();/*from w ww.  j a  va 2  s.co  m*/
    if (mAds != null)
        pwSupport.getSupportFragmentManager().beginTransaction().replace(R.id.advertisement, mAds).commit();
    mCommercials = getCommercialBanner();
    if (mCommercials != null) {
        mCommercials.setOnInitializedListener(new OnFinishedListener() {
            @Override
            public void finished() {
                pwSupport.getSupportFragmentManager().beginTransaction().remove(mAds).commit();
            }
        });
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                pwSupport.getSupportFragmentManager().beginTransaction().replace(R.id.commercial, mCommercials)
                        .commit();
            }
        }, getCommercialWaitTime());
    }
}

From source file:com.jimandreas.android.designlibdemo.SettingsActivity.java

public void doRestart() {
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override/*from  ww w . j  ava 2 s.  com*/
        public void run() {
            recreate();
        }
    }, 300);
}

From source file:com.snowdream.wallpaper.ImageGridActivity.java

public void switchContent(final Fragment fragment) {
    mContent = fragment;//from ww  w  .j  ava2s. c om
    getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
    Handler h = new Handler();
    h.postDelayed(new Runnable() {
        public void run() {
            getSlidingMenu().showContent();
        }
    }, 50);
}

From source file:com.android.deskclock.Utils.java

public static void setMidnightUpdater(Handler handler, Runnable runnable) {
    String timezone = TimeZone.getDefault().getID();
    if (handler == null || runnable == null || timezone == null) {
        return;/* www  .  j  av  a  2  s  .c o  m*/
    }
    long now = System.currentTimeMillis();
    Time time = new Time(timezone);
    time.set(now);
    long runInMillis = ((24 - time.hour) * 3600 - time.minute * 60 - time.second + 1) * 1000;
    handler.removeCallbacks(runnable);
    handler.postDelayed(runnable, runInMillis);
}

From source file:com.android.deskclock.Utils.java

public static void setQuarterHourUpdater(Handler handler, Runnable runnable) {
    String timezone = TimeZone.getDefault().getID();
    if (handler == null || runnable == null || timezone == null) {
        return;/*from  w  w w .ja v a 2  s  . co  m*/
    }
    long runInMillis = getAlarmOnQuarterHour() - System.currentTimeMillis();
    // Ensure the delay is at least one second.
    if (runInMillis < 1000) {
        runInMillis = 1000;
    }
    handler.removeCallbacks(runnable);
    handler.postDelayed(runnable, runInMillis);
}