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.android.car.trust.CarBleTrustAgent.java

private void maybeStartBleUnlockService() {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Trying to open a Ble GATT server");
    }/*from ww  w .ja  v a 2  s  . co  m*/

    BluetoothManager btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothGattServer mGattServer = btManager.openGattServer(this, new BluetoothGattServerCallback() {
        @Override
        public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
            super.onConnectionStateChange(device, status, newState);
        }
    });

    // The BLE stack is started up before the trust agent service, however Gatt capabilities
    // might not be ready just yet. Keep trying until a GattServer can open up before proceeding
    // to start the rest of the BLE services.
    if (mGattServer == null) {
        Log.e(TAG, "Gatt not available, will try again...in " + BLE_RETRY_MS + "ms");

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                maybeStartBleUnlockService();
            }
        }, BLE_RETRY_MS);
    } else {
        mGattServer.close();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "GATT available, starting up UnlockService");
        }
        mCarUnlockService.start();
    }
}

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

private void hideActionBarDelayed(Handler handler) {
    handler.postDelayed(new Runnable() {
        public void run() {
            getSupportActionBar().hide();
        }//from  w  w w.  ja va 2s .  c o m
    }, 30000);
}

From source file:com.android.talkback.tutorial.TutorialLessonFragment.java

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

    MenuTransformer menuTransformer = mExercise.getContextMenuTransformer();
    MenuActionInterceptor menuActionInterceptor = mExercise.getContextMenuActionInterceptor();
    TalkBackService service = TalkBackService.getInstance();
    if (service != null) {
        MenuManager menuManager = service.getMenuManager();
        menuManager.setMenuTransformer(menuTransformer);
        menuManager.setMenuActionInterceptor(menuActionInterceptor);
    }//w ww  . j ava 2 s . c o m

    // We need to post the announcements delayed in order to ensure that the view changed
    // event gets sent beforehand. This makes the TalkBack speech response flow more logical.
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            View view = getView();
            if (view == null) {
                // Something terrible has happened, e.g. the fragment is gone.
                return;
            }

            view.announceForAccessibility(getTitle());
            view.announceForAccessibility(mPage.getSubtitle());
            mDescription.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
        }
    }, DELAY_BEFORE_ANNOUNCE_LESSON);
    mExercise.onInitialized(getActivity());
}

From source file:org.apache.cordova.AccelListener.java

/**
 * Start listening for acceleration sensor.
 * /*  www.  jav a2 s.  co  m*/
 * @return          status of listener
*/
private int start() {
    // If already starting or running, then just return
    if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) {
        return this.status;
    }

    this.setStatus(AccelListener.STARTING);

    // Get accelerometer from sensor manager
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);

    // If found, then register as listener
    if ((list != null) && (list.size() > 0)) {
        this.mSensor = list.get(0);
        this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI);
        this.setStatus(AccelListener.STARTING);
    } else {
        this.setStatus(AccelListener.ERROR_FAILED_TO_START);
        this.fail(AccelListener.ERROR_FAILED_TO_START,
                "No sensors found to register accelerometer listening to.");
        return this.status;
    }

    // Set a timeout callback on the main thread.
    Handler handler = new Handler(Looper.getMainLooper());
    handler.postDelayed(new Runnable() {
        public void run() {
            AccelListener.this.timeout();
        }
    }, 2000);

    return this.status;
}

From source file:com.devalladolid.musictoday.activities.BaseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        super.onBackPressed();
        return true;
    case R.id.action_settings:
        NavigationUtils.navigateToSettings(this);
        return true;
    case R.id.action_shuffle:
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override//from   w w w. ja v a 2 s . c o  m
            public void run() {
                MusicPlayer.shuffleAll(BaseActivity.this);
            }
        }, 80);

        return true;
    case R.id.action_search:
        NavigationUtils.navigateToSearch(this);
        return true;
    case R.id.action_equalizer:
        NavigationUtils.navigateToEqualizer(this);
        return true;

    }
    return super.onOptionsItemSelected(item);
}

From source file:com.devalladolid.musictoday.fragments.PlaylistFragment.java

public void updatePlaylists(final long id) {
    playlists = PlaylistLoader.getPlaylists(getActivity(), showAuto);
    playlistcount = playlists.size();//from  ww w  .  jav a2  s .  c o m

    if (isDefault) {
        adapter.notifyDataSetChanged();
        if (id != -1) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < playlists.size(); i++) {
                        long playlistid = playlists.get(i).id;
                        if (playlistid == id) {
                            pager.setCurrentItem(i);
                            break;
                        }
                    }
                }
            }, 200);
        }

    } else {
        mAdapter.updateDataSet(playlists);
    }
}

From source file:com.fat246.cybercar.activities.carmusics.BaseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        super.onBackPressed();
        return true;
    //            case R.id.action_settings:
    //                NavigationUtils.navigateToSettings(this);
    //                return true;
    case R.id.action_shuffle:
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override//from   w w w. jav  a  2  s  .c om
            public void run() {
                MusicPlayer.shuffleAll(BaseActivity.this);
            }
        }, 80);

        return true;
    case R.id.action_search:
        NavigationUtils.navigateToSearch(this);
        return true;
    case R.id.action_equalizer:
        NavigationUtils.navigateToEqualizer(this);
        return true;

    }
    return super.onOptionsItemSelected(item);
}

From source file:rebus.gitchat.ui.MainActivity.java

private void closeDrawer() {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override/*  w  w w. j av  a2 s.  c om*/
        public void run() {
            if (drawerLayout != null && drawerLayout.isDrawerOpen(GravityCompat.START))
                drawerLayout.closeDrawer(GravityCompat.START);
        }
    }, 400);
}

From source file:cn.edu.gdmec.t00385.lightsensor.LightSensorListener.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action                The action to execute.
 * @param args                 JSONArry of arguments for the plugin.
 * @param callbackS=Context     The callback id used when calling back into JavaScript.
 * @return                     True if the action was valid.
 * @throws JSONException /* www  .j a v  a2s .  co  m*/
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("start")) {
        this.start();
    } else if (action.equals("stop")) {
        this.stop();
    } else if (action.equals("getStatus")) {
        int i = this.getStatus();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i));
    } else if (action.equals("getLumen")) {
        // If not running, then this is an async call, so don't worry about waiting
        if (this.status != LightSensorListener.RUNNING) {
            int r = this.start();
            if (r == LightSensorListener.ERROR_FAILED_TO_START) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION,
                        LightSensorListener.ERROR_FAILED_TO_START));
                return true;
            }
            // Set a timeout callback on the main thread.
            Handler handler = new Handler(Looper.getMainLooper());
            handler.postDelayed(new Runnable() {
                public void run() {
                    LightSensorListener.this.timeout();
                }
            }, 2000);
        }
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, getCompassHeading()));
    } else if (action.equals("setTimeout")) {
        this.setTimeout(args.getLong(0));
    } else if (action.equals("getTimeout")) {
        long l = this.getTimeout();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, l));
    } else {
        // Unsupported action
        return false;
    }
    return true;
}

From source file:com.turman.oschina.ui.MainActivity.java

private void checkUpdate() {
    if (!mSharedPreferencesUtil.get(AppConfig.KEY_CHECK_UPDATE, true)) {
        return;/*from w w  w .  j  a  va  2s  . c  o  m*/
    }
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            //                new UpdateManager(MainActivity.this, false).checkUpdate();
        }
    }, 2000);
}