List of usage examples for android.os Handler postDelayed
public final boolean postDelayed(Runnable r, long delayMillis)
From source file:Main.java
public static void lockForOneSec(final View view) { if (!view.isClickable()) return;//from w w w .j a va 2s .co m view.setClickable(false); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (view == null) return; view.setClickable(true); } }, 1000); }
From source file:Main.java
public static void scheduleDelayedTask(Runnable task, long delay) { Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(task, delay); }
From source file:Main.java
public static void postOnUi(Context ctx, Runnable task, long delayMs) { Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(task, delayMs); }
From source file:com.owncloud.android.ui.notifications.NotificationUtils.java
public static void cancelWithDelay(final NotificationManager notificationManager, final int notificationId, long delayInMillis) { HandlerThread thread = new HandlerThread( "NotificationDelayerThread_" + (new Random(System.currentTimeMillis())).nextInt(), Process.THREAD_PRIORITY_BACKGROUND); thread.start();//from w w w .j av a 2s . c o m Handler handler = new Handler(thread.getLooper()); handler.postDelayed(new Runnable() { public void run() { notificationManager.cancel(notificationId); ((HandlerThread) Thread.currentThread()).getLooper().quit(); } }, delayInMillis); }
From source file:com.spoiledmilk.ibikecph.util.Util.java
public static void launchNoConnectionDialog(Context ctx) { final Dialog dialog = new Dialog(ctx); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dialog_no_connection); TextView text = (TextView) dialog.findViewById(R.id.textNetworkError); text.setTypeface(IbikeApplication.getNormalFont()); text.setText(IbikeApplication.getString("network_error_text")); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.show();/*w w w.j a va2 s. c o m*/ final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { try { dialog.dismiss(); } catch (Exception e) { // dialog not attached to window } } }, 3000); }
From source file:com.appnexus.opensdk.ANNativeAdResponse.java
/** * Process the metadata of native response from ad server * * @param metaData JsonObject that contains info of native ad * @return ANNativeResponse if no issue happened during processing *//*from ww w. j a va 2 s.c o m*/ static ANNativeAdResponse create(JSONObject metaData) { if (metaData == null) { return null; } JSONArray impTrackerJson = JsonUtil.getJSONArray(metaData, KEY_IMP_TRACK); ArrayList<String> imp_trackers = JsonUtil.getStringArrayList(impTrackerJson); if (imp_trackers == null) { return null; } ANNativeAdResponse response = new ANNativeAdResponse(); response.imp_trackers = imp_trackers; response.title = JsonUtil.getJSONString(metaData, KEY_TITLE); response.description = JsonUtil.getJSONString(metaData, KEY_DESCRIPTION); JSONArray main_media = JsonUtil.getJSONArray(metaData, KEY_MAIN_MEDIA); if (main_media != null) { int l = main_media.length(); for (int i = 0; i < l; i++) { JSONObject media = JsonUtil.getJSONObjectFromArray(main_media, i); if (media != null) { String label = JsonUtil.getJSONString(media, KEY_IMAGE_LABEL); if (label != null && label.equals(VALUE_DEFAULT_IMAGE)) { response.imageUrl = JsonUtil.getJSONString(media, KEY_IMAGE_URL); break; } } } } ; response.iconUrl = JsonUtil.getJSONString(metaData, KEY_ICON); response.socialContext = JsonUtil.getJSONString(metaData, KEY_CONTEXT); response.callToAction = JsonUtil.getJSONString(metaData, KEY_CTA); response.clickUrl = JsonUtil.getJSONString(metaData, KEY_CLICK_URL); response.clickFallBackUrl = JsonUtil.getJSONString(metaData, KEY_CLICK_FALLBACK_URL); JSONObject rating = JsonUtil.getJSONObject(metaData, KEY_RATING); response.rating = new Rating(JsonUtil.getJSONDouble(rating, KEY_RATING_VALUE), JsonUtil.getJSONDouble(rating, KEY_RATING_SCALE)); JSONArray clickTrackerJson = JsonUtil.getJSONArray(metaData, KEY_CLICK_TRACK); response.click_trackers = JsonUtil.getStringArrayList(clickTrackerJson); JSONObject custom = JsonUtil.getJSONObject(metaData, KEY_CUSTOM); response.nativeElements = JsonUtil.getStringObjectHashMap(custom); Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(response.expireRunnable, Settings.NATIVE_AD_RESPONSE_EXPIRATION_TIME); return response; }
From source file:org.restcomm.app.qoslib.Utils.QosAPI.java
public static void showQoSPanel(final Activity activity) { try {/*w ww.j a va2 s. c om*/ AlertDialog.Builder builder1 = new AlertDialog.Builder(activity); CharSequence qosInfo = getQosInfo(activity); builder1.setMessage(qosInfo); builder1.setTitle("QOS Info"); builder1.setCancelable(true); final AlertDialog alert11 = builder1.create(); alert11.show(); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { CharSequence qosInfo = getQosInfo(activity); if (alert11.isShowing()) { try { alert11.setMessage(qosInfo); handler.postDelayed(this, 1000); } catch (Exception e) { } } } }, 1000); } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "CreateDevInfoAlertDialog", "exeption", e); } }
From source file:com.mods.grx.settings.utils.Utils.java
public static void send_bc2(final Context context) { Runnable BC = new Runnable() { @Override//from ww w.ja va 2s .co m public void run() { Intent intent = new Intent(); try { intent.setAction(context.getResources().getString(R.string.gs_grxBc2)); context.sendBroadcast(intent); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show(); } } }; Handler handler = new Handler(); handler.removeCallbacks(BC); handler.postDelayed(BC, Long.valueOf(400)); }
From source file:com.desno365.mods.DesnoUtils.java
public static void collapseTextView(ViewGroup container, final TextView tv, int collapsedHeight) { if (Build.VERSION.SDK_INT >= 19) { int lines = tv.getLineCount(); // animation TransitionManager.beginDelayedTransition(container, new AutoTransition() .setDuration(SharedConstants.CHANGELOG_TEXT_ANIMATION_DURATION_PER_LINE * lines)); // collapse the view by setting the collapsed height DesnoUtils.setViewHeight(tv, collapsedHeight); // restore initial state of the TextView when the animation finishes Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override/*from w w w . j a va 2 s . c o m*/ public void run() { DesnoUtils.setViewHeight(tv, ViewGroup.LayoutParams.WRAP_CONTENT); tv.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES); } }, SharedConstants.CHANGELOG_TEXT_ANIMATION_DURATION_PER_LINE * lines + 100); } else { // no animation without the new APIs :/ tv.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES); } }
From source file:com.example.android.testing.notes.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/*www. ja v a2s.c o m*/ public void run() { List<Note> notes = new ArrayList<>(NOTES_SERVICE_DATA.values()); callback.onLoaded(notes); } }, SERVICE_LATENCY_IN_MILLIS); }