List of usage examples for android.os Handler postDelayed
public final boolean postDelayed(Runnable r, long delayMillis)
From source file:com.chao.facebookzc.widget.GraphObjectPagingLoader.java
private void startLoading(Request request, boolean skipRoundtripIfCached, long afterDelay) { this.skipRoundtripIfCached = skipRoundtripIfCached; appendResults = false;/*from w w w .j a v a 2 s .c om*/ nextRequest = null; currentRequest = request; currentRequest.setCallback(new Request.Callback() { @Override public void onCompleted(Response response) { requestCompleted(response); } }); // We are considered loading even if we have a delay. loading = true; final RequestBatch batch = putRequestIntoBatch(request, skipRoundtripIfCached); Runnable r = new Runnable() { @Override public void run() { Request.executeBatchAsync(batch); } }; if (afterDelay == 0) { r.run(); } else { Handler handler = new Handler(); handler.postDelayed(r, afterDelay); } }
From source file:org.mozilla.focus.widget.AnimatedProgressBar.java
private void animateClosing() { mIsRtl = (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL); mClosingAnimator.cancel();//www . ja v a2 s. c om final Handler handler = getHandler(); if (handler != null) { handler.postDelayed(new Runnable() { @Override public void run() { mClosingAnimator.start(); } }, CLOSING_DELAY); } }
From source file:com.morphoss.jumble.frontend.CategoryScreenActivity.java
@Override protected void onResume() { super.onResume(); myApp.resumeMusic();//from w w w . j a v a 2 s.c o m if (!Category.unlockedCategories.isEmpty()) { DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int height = displaymetrics.heightPixels; int width = displaymetrics.widthPixels; pga = new CategoryGridAdapter(this, width, height); new LoadCategoryTask().execute(); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { // Show the popup window of an unlocked level after 0.5s = // 500ms if (!Category.unlockedCategories.isEmpty()) { PopupWindowLevel(); } } }, 500); } }
From source file:com.tamuhack.bootcamp.MessagesFragment.java
/** * Call whenever you want the most recent list of messages *///from www .j av a2 s .co m private void fetchMessages() { ParseQuery<ParseObject> query = ParseQuery.getQuery("Messages"); query.setLimit(100); query.addDescendingOrder("createdAt"); query.include("poster"); query.findInBackground(new FindCallback<ParseObject>() { public void done(List<ParseObject> parseObjectList, ParseException e) { if (e == null) { // found some messages, print how many Log.d(TAG, "Retrieved " + parseObjectList.size() + " messages"); // create message objects so that we can use them later // to make the visible list in the adapter ArrayList<Message> messages = new ArrayList<Message>(); for (int i = parseObjectList.size() - 1; i >= 0; i--) { messages.add(new Message(parseObjectList.get(i))); } // did we get any new messages? if so we should scroll to the bottom boolean hasNewMessages = mAdapter.areListsDifferent(messages); if (hasNewMessages) { mAdapter.setMessages(messages); mRecyclerView.scrollToPosition(messages.size() - 1); Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(50); } // fetch messages again in a couple seconds Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { fetchMessages(); } }, 5000); } else { Log.d(TAG, "Error: " + e.getMessage()); showError(); } } }); }
From source file:com.crackingbits.bummer.MainActivity.java
public void fetchJenkins() { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override//ww w .ja v a 2 s.co m public void run() { if (isNetworkAvailable()) { getJenkinsJobs(); } fetchJenkins(); } }, 20000); }
From source file:com.crackingbits.bummer.MainActivity.java
public void fetchFreshdesk() { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override//www. j a v a 2s . com public void run() { if (isNetworkAvailable()) { getFreshDesk(); } fetchFreshdesk(); } }, 5 * 60 * 1000); }
From source file:hmatalonga.greenhub.ui.MainActivity.java
private void refreshStatus() { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override//from ww w . j av a2s . co m public void run() { EventBus.getDefault().post(new StatusEvent(Config.STATUS_IDLE)); } }, Config.REFRESH_STATUS_ERROR); }
From source file:com.megster.cordova.rfduino.RFduinoPlugin.java
private void findLowEnergyDevices(CallbackContext callbackContext, int scanSeconds) { // TODO skip if currently scanning peripherals.clear();//from www .j a v a 2 s . c o m discoverCallback = callbackContext; bluetoothAdapter.startLeScan(new UUID[] { Peripheral.RFDUINO_SERVICE_UUID }, this); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { LOG.d(TAG, "Stopping Scan"); RFduinoPlugin.this.bluetoothAdapter.stopLeScan(RFduinoPlugin.this); } }, scanSeconds * 1000); PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java
private void nativeRingtone(Context context, boolean hasSound) { if (hasSound) { final AudioManager.OnAudioFocusChangeListener listener = this; final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int result = audioManager.requestAudioFocus(listener, AudioManager.STREAM_NOTIFICATION, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mRingtone = RingtoneManager.getRingtone(context, notification); mRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION); mRingtone.play();/*from w ww .ja v a2 s .c om*/ final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { audioManager.abandonAudioFocus(listener); } }, AUDIO_FOCUS_DURATION); } } }
From source file:com.cranberrygame.cordova.plugin.ad.admob.AdmobSplit.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) protected void handleLayoutChangeOverlap() { //http://stackoverflow.com/questions/24539578/cordova-plugin-listening-to-device-orientation-change-is-it-possible //http://developer.android.com/reference/android/view/View.OnLayoutChangeListener.html //https://gitshell.com/lvxudong/A530_packages_app_Camera/blob/master/src/com/android/camera/ActivityBase.java //plugin.getWebView().addOnLayoutChangeListener(new View.OnLayoutChangeListener(){//only for ~cordova4 //plugin.getWebView().getRootView().addOnLayoutChangeListener(new View.OnLayoutChangeListener(){//only for ~cordova4 //plugin.getWebView().getView().addOnLayoutChangeListener(new View.OnLayoutChangeListener(){//only for cordova5~ getView(plugin.getWebView()).addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override//from w ww . j a va 2 s . c o m public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (left == oldLeft && top == oldTop && right == oldRight && bottom == oldBottom) { return; } Log.d(LOG_TAG, "onLayoutChange"); //Util.alert(cordova.getActivity(), "onLayoutChange"); int orientation = Util.getDisplayRotation(plugin.getCordova().getActivity()); if (orientation != lastOrientation) { Log.d(LOG_TAG, String.format("orientation: %d", orientation)); //Util.alert(cordova.getActivity(), String.format("orientation: %d", orientation)); if (bannerPreviousSize != null && bannerPreviousSize.equals("SMART_BANNER")) { Log.d(LOG_TAG, String.format("position: %s, size: %s", bannerPreviousPosition, bannerPreviousSize)); //Util.alert(cordova.getActivity(), String.format("position: %s, size: %s", position, size)); //split if (bannerView != null) { //if banner is showing ViewGroup parentView = (ViewGroup) bannerView.getParent(); if (parentView != null) { //parentView.removeView(bannerView); //bannerView.destroy(); //bannerView = null; Log.d(LOG_TAG, String.format("position: %s, size: %s", bannerPreviousPosition, bannerPreviousSize)); //Util.alert(cordova.getActivity(), String.format("position: %s, size: %s", position, size)); //http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay-in-android final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { _showBannerAd(bannerPreviousPosition, bannerPreviousSize); } }, 1);//after 1ms } } } } lastOrientation = orientation; } }); }