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:org.apache.cordova.CompassListener.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 /*from www  .jav a2 s  .  c o 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("getHeading")) {
        // If not running, then this is an async call, so don't worry about waiting
        if (this.status != CompassListener.RUNNING) {
            int r = this.start();
            if (r == CompassListener.ERROR_FAILED_TO_START) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION,
                        CompassListener.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() {
                    CompassListener.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.mifos.mifosxdroid.online.DashboardActivity.java

public void startNavigationClickActivity(final Intent intent) {
    android.os.Handler handler = new android.os.Handler();
    handler.postDelayed(new Runnable() {
        @Override/*ww  w .  j  ava2 s .  co m*/
        public void run() {
            startActivity(intent);

        }
    }, 500);
}

From source file:com.evandroid.musica.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. j av a2 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;

    case R.id.action_lyrics:
        //TODO
        Toast.makeText(BaseActivity.this, "Lyrics feature will be back soon!", Toast.LENGTH_SHORT).show();
        return true;

    }
    return super.onOptionsItemSelected(item);
}

From source file:com.money.manager.ex.reports.PayeeReportFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    super.onLoadFinished(loader, data);
    switch (loader.getId()) {
    case ID_LOADER:
        if (data == null)
            return;

        //parse cursor for calculate total
        double totalAmount = 0;
        while (data.moveToNext()) {
            totalAmount += data.getDouble(data.getColumnIndex("TOTAL"));
        }//from  w  w w. ja  v a2  s .c  o  m

        CurrencyService currencyService = new CurrencyService(getContext());

        TextView txtColumn2 = (TextView) mFooterListView.findViewById(R.id.textViewColumn2);
        txtColumn2.setText(currencyService.getBaseCurrencyFormatted(MoneyFactory.fromDouble(totalAmount)));

        // solve bug chart
        if (data.getCount() > 0) {
            getListView().removeFooterView(mFooterListView);
            getListView().addFooterView(mFooterListView);
        }
        // handler to show chart
        if (((PayeesReportActivity) getActivity()).mIsDualPanel) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    showChart();
                }
            }, 1 * 1000);
        }
    }
}

From source file:com.rohan.app.fragments.SongsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_recyclerview, container, false);

    /*if (savedInstanceState == null) {
            /* ww  w  .  ja va2 s . co m*/
    if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.RECORD_AUDIO)
            || ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.MODIFY_AUDIO_SETTINGS)) {
        AlertDialog.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (which == DialogInterface.BUTTON_POSITIVE) {
                    requestPermissions();
                } else if (which == DialogInterface.BUTTON_NEGATIVE) {
                    //permissionsNotGranted();
                }
            }
        };
        new AlertDialog.Builder(getActivity())
                .setTitle(getString(R.string.title_permissions))
                .setMessage(Html.fromHtml(getString(R.string.message_permissions)))
                .setPositiveButton(getString(R.string.btn_next), onClickListener)
                .setNegativeButton(getString(R.string.btn_cancel), onClickListener)
                .show();
    } else {
        requestPermissions();
    }
            
    }*/

    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    FastScroller fastScroller = (FastScroller) rootView.findViewById(R.id.fastscroller);
    fastScroller.setRecyclerView(recyclerView);
    audioVisualization = (AudioVisualization) rootView.findViewById(R.id.visualizer_view);

    fab.attachToRecyclerView(recyclerView);
    fab.setColorNormal(getResources().getColor(R.color.colorAccent));
    fab.setColorPressed(getResources().getColor(R.color.widget_pause));
    fab.setColorRipple(getResources().getColor(R.color.window_background));

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    MusicPlayer.shuffleAll(getActivity());
                }
            }, 80);
        }
    });

    new loadSongs().execute("");
    ((BaseActivity) getActivity()).setMusicStateListenerListener(this);

    /*if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED
        && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.MODIFY_AUDIO_SETTINGS) == PackageManager.PERMISSION_GRANTED) {
            
    requestPermissions();
            
    }*/

    return rootView;
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.SurveyFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ImageButton infoButton = (ImageButton) view.findViewById(R.id.info);
    infoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(final View view) {
            // Set info button not clickable when it was first clicked
            view.setClickable(false);/*from  w  w  w  . j a  v  a2  s . c om*/
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    final Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            view.setClickable(true);
                        }
                    }, 100);

                }
            });
            ApptentiveInternal.getInstance().showAboutInternal(getActivity(), false);
        }
    });
    scrollView = (ApptentiveNestedScrollView) view.findViewById(R.id.survey_scrollview);
    scrollView.setOnScrollChangeListener(this);

    /* Android's ScrollView (when scrolled or fling'd) by default always set the focus to an EditText when
     * it's one of it's children.
     * The following is needed to change this behavior such that touching outside EditText would take
     * away the focus
     */
    scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    scrollView.setFocusable(true);
    scrollView.setFocusableInTouchMode(true);
    scrollView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.requestFocusFromTouch();
            Util.hideSoftKeyboard(getContext(), v);
            return false;
        }
    });

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

}

From source file:com.bluros.music.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  .j a 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;
    case R.id.menu_sleep_mode:
        SleepModeDialog.show(getSupportFragmentManager());
        return true;
    case R.id.action_remote_search:
        RemoteSelectDialog remoteSelectDialog = new RemoteSelectDialog();
        remoteSelectDialog.show(getFragmentManager(), RemoteSelectDialog.FRAGMENT_NAME);
        return true;

    }
    return super.onOptionsItemSelected(item);
}

From source file:com.ultrafunk.network_info.service.NetworkStateService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if ((intent != null) && (intent.getAction() != null)) {
        final String action = intent.getAction();

        //   Log.e(this.getClass().getSimpleName(), "onStartCommand(): " + action);

        if (Constants.ACTION_UPDATE_SERVICE_STATE.equals(action)) {
            initEnabledWidgets(new EnabledWidgets(
                    intent.getBooleanExtra(Constants.EXTRA_ENABLED_WIDGETS_MOBILE_DATA, false),
                    intent.getBooleanExtra(Constants.EXTRA_ENABLED_WIDGETS_WIFI, false)));
        } else {/*from   www. j a v a 2  s  .c  om*/
            final Handler handler = new Handler();

            if (Constants.ACTION_WIFI_CONNECTING.equals(action)) {
                handler.postDelayed(new Runnable() {
                    public void run() {
                        WifiInfo wifiInfo = wifiManager.getConnectionInfo();

                        if ((wifiInfo != null) && (wifiInfo.getSupplicantState() == SupplicantState.SCANNING))
                            localBroadcastManager.sendBroadcastSync(new Intent(Constants.ACTION_WIFI_SCANNING));
                    }
                }, 5 * 1000);
            } else if (Constants.ACTION_WIFI_CONNECTED.equals(action)) {
                handler.postDelayed(new Runnable() {
                    public void run() {
                        WifiInfo wifiInfo = wifiManager.getConnectionInfo();

                        if ((wifiInfo != null) && (wifiInfo.getLinkSpeed() != -1))
                            localBroadcastManager
                                    .sendBroadcastSync(new Intent(Constants.ACTION_WIFI_LINK_SPEED));
                    }
                }, 3 * 1000);
            } else if (Constants.ACTION_DATA_CONNECTED.equals(action)) {
                handler.postDelayed(new Runnable() {
                    public void run() {
                        isWaitingForDataUsage = false;

                        if (telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED)
                            localBroadcastManager
                                    .sendBroadcastSync(new Intent(Constants.ACTION_DATA_USAGE_UPDATE));
                    }
                }, 500);
            }
        }
    }

    return Service.START_STICKY;
}

From source file:com.google.cloud.solutions.griddler.android.ui.game.GameActivity.java

/**
 * Updates the UI appropriately when a question has been answered correctly
 *///from ww w. j a v a 2  s  . c  o m
@Override
public void onQuestionAnswered() {
    board.getWords().get(board.getCurrentQuestionIndex()).setCompleted(true);
    gameModel.getCurrentPlayer().addAnswerIndex(board.getCurrentQuestionIndex());

    // advance to next available question
    if (board.getAllQuestionsCompleted()) {
        goToGameState(GameStateType.FINISHED);
    } else {
        goToGameState(GameStateType.QUESTION_TRANSITIONING);

        // clear letters
        board.getGridLayout().clearSelectedLetters();

        board.setCurrentWordIndex(board.getIndexOfNextUnansweredQuestion());
        for (IGameView view : views) {
            view.onQuestionAnswered();
        }

        Handler h = new Handler();
        h.postDelayed(new Runnable() {
            @Override
            public void run() {
                for (IGameView view : views) {
                    view.updateUI();
                }
                goToGameState(GameStateType.PLAYING);
            }
        }, 1000);
    }
}

From source file:net.olejon.mdapp.DiseasesAndTreatmentsActivity.java

private void showSearch() {
    mToolbarSearchLayout.setVisibility(View.VISIBLE);
    mToolbarSearchEditText.requestFocus();

    Handler handler = new Handler();

    handler.postDelayed(new Runnable() {
        @Override//from  w  w w  .ja v a  2  s .com
        public void run() {
            mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0);
        }
    }, 125);
}