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.bluros.music.activities.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    sMainActivity = this;
    action = getIntent().getAction();// ww w  . j ava 2 s .  c  om

    isDarkTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    navigationMap.put(Constants.NAVIGATE_LIBRARY, navigateLibrary);
    navigationMap.put(Constants.NAVIGATE_PLAYLIST, navigatePlaylist);
    navigationMap.put(Constants.NAVIGATE_QUEUE, navigateQueue);
    navigationMap.put(Constants.NAVIGATE_NOWPLAYING, navigateNowplaying);
    navigationMap.put(Constants.NAVIGATE_ALBUM, navigateAlbum);
    navigationMap.put(Constants.NAVIGATE_ARTIST, navigateArtist);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    panelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    View header = navigationView.inflateHeaderView(R.layout.nav_header);

    albumart = (ImageView) header.findViewById(R.id.album_art);
    songtitle = (TextView) header.findViewById(R.id.song_title);
    songartist = (TextView) header.findViewById(R.id.song_artist);

    setPanelSlideListeners(panelLayout);

    navDrawerRunnable.postDelayed(new Runnable() {
        @Override
        public void run() {
            setupDrawerContent(navigationView);
            setupNavigationIcons(navigationView);
        }
    }, 700);

    if (MusicUtils.isMarshmallow()) {
        checkPermissionAndThenLoad();
    } else {
        loadEverything();
    }

    addBackstackListener();

    if (Intent.ACTION_VIEW.equals(action)) {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                MusicPlayer.clearQueue();
                MusicPlayer.openFile(getIntent().getData().getPath());
                MusicPlayer.playOrPause();
                navigateNowplaying.run();
            }
        }, 350);
    }
}

From source file:com.ht117.dina.activities.MainActivity.java

private void updatePosition(final MenuItem menuItem) {
    runnable = null;//from  w  w  w.  j a  v  a2 s.  co  m

    switch (menuItem.getItemId()) {
    case R.id.nav_library:
        runnable = navigateLibrary;

        break;
    case R.id.nav_playlists:
        runnable = navigatePlaylist;

        break;
    case R.id.nav_folders:
        runnable = navigateFolder;

        break;
    case R.id.nav_nowplaying:
        NavigationUtils.navigateToNowplaying(MainActivity.this, false);
        break;
    case R.id.nav_queue:
        runnable = navigateQueue;

        break;
    case R.id.nav_settings:
        NavigationUtils.navigateToSettings(MainActivity.this);
        break;
    }

    if (runnable != null) {
        menuItem.setChecked(true);
        mDrawerLayout.closeDrawers();
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                runnable.run();
            }
        }, 350);
    }
}

From source file:com.HACK.codersbestfriend.MainActivity.java

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

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item,
            getResources().getStringArray(R.array.nav_items)));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {//ww  w.  j ava  2s.  co m
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        mCurrentFragment = new CodersBestFragment(R.layout.home);
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, mCurrentFragment, "fragmentTag")
                .commit();

        Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {
            public void run() {
                selectItem(0);
            }
        }, 1000);
    } else {
        mCurrentFragment = getFragmentManager().findFragmentByTag("fragmentTag");
    }

    mDbAdapter = new CodersBFDatabaseAdapter(this);
    mDbAdapter.open();

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    screenWidth = dm.widthPixels;
    screenHeight = dm.heightPixels;
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentSearch.java

private void endFragment() {
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override/*from  w  w  w.  j ava2s .c  o m*/
        public void run() {
            getActivity().getSupportFragmentManager().popBackStack(null,
                    FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    }, 300);
}

From source file:com.example.mapdemo.MyLocationDemoActivity.java

public void updateMap(boolean gambi) {
    mMap.clear();//from   ww  w  . j a v a  2 s .c o m

    for (String car : cars.keySet()) {
        mMap.addMarker(new MarkerOptions().position(cars.get(car).getLatLng()).title(car)
                .icon(BitmapDescriptorFactory.fromResource(cars.get(car).color)));
        if (!gambi && cars.get(car).isLeader()) {
            line.add(cars.get(car).getLatLng());
            line.width(5).color(Color.RED);
            mMap.addPolyline(line);
        }
    }

    try {
        mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(CarData.getLatLngBounds(), 100));
    } catch (Exception ex) {
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(CarData.getLatLngBounds(), 100));
            }
        }, 1000);
    }

}

From source file:paulscode.android.mupen64plusae.SplashActivity.java

public void requestPermissions() {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
            || ContextCompat.checkSelfPermission(this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)
                || ActivityCompat.shouldShowRequestPermissionRationale(this,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            //Show dialog asking for permissions
            new AlertDialog.Builder(this).setTitle(getString(R.string.assetExtractor_permissions_title))
                    .setMessage(getString(R.string.assetExtractor_permissions_rationale))
                    .setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            actuallyRequestPermissions();
                        }//from w  ww .  j a v a  2s  .c  o m

                    }).setNegativeButton(getString(android.R.string.cancel), new OnClickListener() {
                        //Show dialog stating that the app can't continue without proper permissions
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            new AlertDialog.Builder(SplashActivity.this)
                                    .setTitle(getString(R.string.assetExtractor_error))
                                    .setMessage(getString(R.string.assetExtractor_failed_permissions))
                                    .setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            SplashActivity.this.finish();
                                        }

                                    }).setCancelable(false).show();
                        }
                    }).setCancelable(false).show();
        } else {
            // No explanation needed, we can request the permission.
            actuallyRequestPermissions();
        }
    } else {
        // Extract the assets in a separate thread and launch the menu activity
        // Handler.postDelayed ensures this runs only after activity has resumed
        final Handler handler = new Handler();
        handler.postDelayed(extractAssetsTaskLauncher, SPLASH_DELAY);
    }
}

From source file:paulscode.android.mupen64plusae.SplashActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case PERMISSION_REQUEST: {
        // If request is cancelled, the result arrays are empty.
        boolean good = true;
        if (permissions.length != NUM_PERMISSIONS || grantResults.length != NUM_PERMISSIONS) {
            good = false;// w  w  w. ja  v a  2s .  co  m
        }

        for (int i = 0; i < grantResults.length && good; i++) {
            if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
                good = false;
            }
        }

        if (!good) {
            // permission denied, boo! Disable the app.
            new AlertDialog.Builder(SplashActivity.this).setTitle(getString(R.string.assetExtractor_error))
                    .setMessage(getString(R.string.assetExtractor_failed_permissions))
                    .setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            SplashActivity.this.finish();
                        }

                    }).setCancelable(false).show();
        } else {
            //Permissions already granted, continue
            // Extract the assets in a separate thread and launch the menu activity
            // Handler.postDelayed ensures this runs only after activity has resumed
            final Handler handler = new Handler();
            handler.postDelayed(extractAssetsTaskLauncher, SPLASH_DELAY);
        }
        return;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}

From source file:com.application.treasurehunt.ScanQRCodeActivity.java

private void saveScanResult() {

    if (mScanResultTask != null) {
        return;//from   w w w. j  ava2s .c o  m
    }

    mScanResultTask = new SaveScanResultTask();
    mScanResultTask.execute((String) null);

    Handler handlerForUserTask = new Handler();
    handlerForUserTask.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (mScanResultTask != null) {
                if (mScanResultTask.getStatus() == AsyncTask.Status.RUNNING) {
                    mScanDialog.cancel();
                    mScanResultTask.cancel(true);
                    Toast.makeText(ScanQRCodeActivity.this, mConnectionTimeout, Toast.LENGTH_LONG).show();
                }
            }
        }
    }, 20000);
}

From source file:com.example.haber.ui.activity.CallActivity.java

private void callOutSIP() {
    LogUtil.i(TAG, MyApplication.instance.currentBasicGWConfigEntity.getEp_ptl());
    if (MyApplication.instance.currentBasicGWConfigEntity.getEp_ptl().equals("SIP")) {
        callOut();/*from w  w  w  .ja v a 2 s. c o m*/
    } else {
        Tools.showProgressDialog(this, "?");
        BasicGWConfigEntity entity = new BasicGWConfigEntity();
        entity.setEp_ptl("SIP");
        generalSettingBiz.configBasicGWEpPtl(entity);
        LogUtil.i(TAG, entity.getEp_ptl());
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                callOutSIP();
            }
        }, 1000);
    }
}

From source file:com.example.haber.ui.activity.CallActivity.java

private void callOut323() {
    LogUtil.i(TAG, MyApplication.instance.currentBasicGWConfigEntity.getEp_ptl());
    if (MyApplication.instance.currentBasicGWConfigEntity.getEp_ptl().equals("H323")) {
        callOut();//from w  ww .j a v a  2  s  . c  om
    } else {
        Tools.showProgressDialog(this, "?");
        BasicGWConfigEntity entity = new BasicGWConfigEntity();
        entity.setEp_ptl("H323");
        generalSettingBiz.configBasicGWEpPtl(entity);
        LogUtil.i(TAG, entity.getEp_ptl());
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                callOut323();
            }
        }, 1000);
    }
}