List of usage examples for android.os Handler postDelayed
public final boolean postDelayed(Runnable r, long delayMillis)
From source file:com.spoiledmilk.ibikecph.navigation.SMRouteNavigationActivity.java
protected void showStopDlg() { try {//from w ww .j a v a 2s . co m FragmentManager fm = getSupportFragmentManager(); FinishRouteDialog roteFinishDialog = new FinishRouteDialog(); roteFinishDialog.show(fm, "dialog_stop"); } catch (Exception e) { System.gc(); mapFragment.mapView.getTileProvider().clearTileCache(); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { try { FragmentManager fm = getSupportFragmentManager(); FinishRouteDialog roteFinishDialog = new FinishRouteDialog(); roteFinishDialog.show(fm, "dialog_stop"); } catch (Exception e) { finish(); } } }, 500); } }
From source file:com.mezcaldev.hotlikeme.ChatActivity.java
private void preloadDecryptedMessages() { if (!flagMessagesDecrypted) { positionMessages = 0;//from w ww. ja va 2 s . c o m decryptedMessages.clear(); mProgressBar.setVisibility(View.VISIBLE); Toast.makeText(getApplicationContext(), "Loading Messages", Toast.LENGTH_LONG).show(); handlerShowLoadingBar = new Handler(); runnableShowLoadingBar = new Runnable() { @Override public void run() { mProgressBar.setVisibility(View.INVISIBLE); if (mFirebaseAdapter != null) { mFirebaseAdapter.notifyDataSetChanged(); mMessageRecyclerView.setAdapter(mFirebaseAdapter); } } }; handlerShowLoadingBar.postDelayed(runnableShowLoadingBar, secondBigDelay); preloadMessages.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { if (!flagMessagesDecrypted) { decryptedMessages.add(dataSnapshot.child("text").getValue().toString()); Log.i(TAG, "Saving Encrypted Message"); } else if (!swipeRefreshLayout.isRefreshing()) { decryptedMessages .add(secureMessage.decrypt(dataSnapshot.child("text").getValue().toString())); Log.i(TAG, "Saving Decrypted Message"); } Log.i(TAG, "Position: " + positionMessages + " Total Messages: " + totalMessages); if (positionMessages == totalMessages - 1) { Log.e(TAG, "Updating the adapter on: " + positionMessages + "<---"); Handler handlerShowMessages = new Handler(); Runnable runnableShowMessages = new Runnable() { @Override public void run() { updateFireBaseRecyclerAdapter(); } }; handlerShowMessages.postDelayed(runnableShowMessages, bigDelay); decryptOnBackground = new DecryptOnBackground(); decryptOnBackground.execute(); //flagMessagesDecrypted = true; } else if (totalMessages == 0) { updateFireBaseRecyclerAdapter(); } //flagMessagesDecrypted = true; positionMessages++; } @Override public void onChildChanged(DataSnapshot dataSnapshot, String s) { updateViewWithDelay(50); } @Override public void onChildRemoved(DataSnapshot dataSnapshot) { updateViewWithDelay(50); } @Override public void onChildMoved(DataSnapshot dataSnapshot, String s) { updateViewWithDelay(50); } @Override public void onCancelled(DatabaseError databaseError) { } }); } else { updateFireBaseRecyclerAdapter(); } }
From source file:com.he5ed.lib.cloudprovider.apis.BoxApi.java
/** * Retry download operation due to file just uploaded * * @param file file to be downloaded/*www . j a v a 2s .c o m*/ * @param filename for the downloaded file, null for original filename */ private void delayDownloadFile(final CFile file, final String filename) { Handler delayHandler = new Handler(); delayHandler.postDelayed(new Runnable() { @Override public void run() { try { downloadFile(file, filename); } catch (RequestFailException e) { // no remedy e.printStackTrace(); Log.e(TAG, e.getMessage()); } } }, 500); }
From source file:com.example.map.BasicMapActivity.java
public void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) { final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); Projection proj = mMap.getProjection(); Point startPoint = proj.toScreenLocation(marker.getPosition()); final LatLng startLatLng = proj.fromScreenLocation(startPoint); final long duration = 500; final Interpolator interpolator = new LinearInterpolator(); handler.post(new Runnable() { @Override//from w ww . j a va2s . c om public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude; marker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMarker) { marker.setVisible(false); } else { marker.setVisible(true); } } } }); }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_client.ui.activity.MessagesActivity.java
private void showMessage(int msgResId) { messageTextView.setText(msgResId);//from w ww.j a v a2 s .c om messageTextView.setVisibility(View.VISIBLE); messageTextView.startAnimation(myAnimationDown); messageTextView.setClickable(false); messageTextView.clearAnimation(); final Handler h = new Handler(); h.postDelayed(new Runnable() { @Override public void run() { messageTextView.setVisibility(View.GONE); } }, 3000); }
From source file:com.example.android.recyclingbanks.MainActivity.java
public void onClick(View view) { int buttonId = view.getId(); String toastText = (String) view.getTag(); Boolean activated = buttonActivationMap.get(buttonId); //change button state activated = !activated;/*from www.j a v a2s . c o m*/ buttonActivationMap.put(buttonId, activated); if (activated == true) { // turning button on setButtonColor(buttonId, BUTTONonCOLOR); } else { // turning button off toastText = "Hiding " + toastText; setButtonColor(buttonId, BUTTONoffCOLOR); } // show toast, funkiness to make 650 milli secs final Toast toast = Toast.makeText(getApplicationContext(), toastText, Toast.LENGTH_SHORT); toast.show(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { toast.cancel(); } }, 650); // hide or show banks on map // TODO make asyncTask possibly. // TODO this isn't filtering CombinedBanks properly switch (buttonId) { case R.id.packagingBanks: // filter combinedBanks hideOrShowCombinedBanks(activated, 0); if (mPackagingBankMarkers.isEmpty()) { // if haven't already loaded the markers do so and display them mPackagingBankMarkers = addBankListToMap(mPackagingBanks); break; } // the markers HAVE been loaded, so flip their visibility hideOrShowBanks(mPackagingBankMarkers, activated); break; case R.id.paperBanks: hideOrShowCombinedBanks(activated, 1); if (mPaperBankMarkers.isEmpty()) { mPaperBankMarkers = addBankListToMap(mPaperBanks); break; } Log.e("onClick", "num pure paper banks? " + Integer.toString(mPaperBankMarkers.size())); hideOrShowBanks(mPaperBankMarkers, activated); break; case R.id.textileBanks: hideOrShowCombinedBanks(activated, 2); if (mTextileBankMarkers.isEmpty()) { mTextileBankMarkers = addBankListToMap(mTextileBanks); break; } hideOrShowBanks(mTextileBankMarkers, activated); return; case R.id.bottleBanks: hideOrShowCombinedBanks(activated, 3); if (mBottleBankMarkers.isEmpty()) { mBottleBankMarkers = addBankListToMap(mBottleBanks); break; } hideOrShowBanks(mBottleBankMarkers, activated); break; case R.id.cansBooksFoodBins: hideOrShowCombinedBanks(activated, 4); if (mOtherBankMarkers.isEmpty()) { mOtherBankMarkers = addBankListToMap(mOthers); break; } hideOrShowBanks(mOtherBankMarkers, activated); break; } return; }
From source file:org.egov.android.view.activity.CreateComplaintActivity.java
/** * Function used to show the image added to complaint in image view. A close icon is shown at * the top right corner of the image to delete it * /*from w w w . j a v a 2 s . co m*/ * @param imagePath */ @SuppressLint("InflateParams") private void _addImageView(String imagePath) { final ImageView image_container = (ImageView) findViewById(R.id.image_container); LinearLayout container = (LinearLayout) findViewById(R.id.container); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.add_photo, null); RelativeLayout inner_container = (RelativeLayout) view.findViewById(R.id.inner_container); LinearLayout.LayoutParams inner_container_params = new LinearLayout.LayoutParams(_dpToPix(100), _dpToPix(100)); inner_container.setLayoutParams(inner_container_params); ImageView image = (ImageView) view.findViewById(R.id.image); image.setImageBitmap(_getBitmapImage(imagePath)); image.setTag(imagePath); container.addView(inner_container); imageUrl.add(imagePath); image_container.setImageBitmap(_getBitmapImage(imagePath)); ImageView delete_icon = (ImageView) view.findViewById(R.id.delete_photo); delete_icon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { file_upload_limit--; RelativeLayout deleteView = (RelativeLayout) v.getParent(); ((LinearLayout) findViewById(R.id.container)).removeView(deleteView); ImageView image = (ImageView) deleteView.findViewById(R.id.image); _deleteFile(image.getTag().toString()); _reorderFiles(); } }); inner_container.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ImageView image = (ImageView) v.findViewById(R.id.image); ((ImageView) findViewById(R.id.image_container)) .setImageBitmap(_getBitmapImage(image.getTag().toString())); } }); Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hr_scroll); hsv.scrollTo(hsv.getWidth() + 600, 0); } }, 500); }
From source file:com.cranberrygame.cordova.plugin.ad.revmob.Util.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 . ja va 2 s . com*/ 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)); //overlap //http://stackoverflow.com/questions/11281562/android-admob-resize-on-landscape if (bannerView != null) { //if banner is showing RelativeLayout bannerViewLayout = (RelativeLayout) bannerView.getParent(); if (bannerViewLayout != null) { //bannerViewLayout.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; } }); }
From source file:com.sentaroh.android.Utilities.Dialog.SafFileSelectDialogFragment.java
private void restoreViewContents() { if (mDebugEnable) Log.v(APPLICATION_TAG, "restoreViewContents mSavedViewContentsValue=" + mSavedViewContentsValue); if (mSavedViewContentsValue == null) return;/*w w w .j a v a2 s. c o m*/ Handler hndl = new Handler(); hndl.postDelayed(new Runnable() { @Override public void run() { if (mCreateDirDialog != null) { Button btnCreate = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_create_btn); btnCreate.performClick(); final EditText etDir = (EditText) mCreateDirDialog.findViewById(R.id.single_item_input_dir); etDir.setText(mSavedViewContentsValue.createDialogEditText); etDir.setSelection(mSavedViewContentsValue.createDialogEditTextSelStart, mSavedViewContentsValue.createDialogEditTextSelEnd); } } }, 10); if (mSavedViewContentsValue.mainDailogListItems != null) { mTreeFilelistAdapter.setDataList(mSavedViewContentsValue.mainDailogListItems); mTreeFileListView.setSelectionFromTop(mSavedViewContentsValue.mainDailogListViewPos[0], mSavedViewContentsValue.mainDailogListViewPos[1]); } resetSavedViewContents(); }
From source file:com.HACK.codersbestfriend.MainActivity.java
public void startTimer(View view) { final Handler h = new Handler(); final Context c = this; String timeText = ((EditText) findViewById(R.id.timerEditText)).getText().toString(); if (!timerRunning) { if (!timeText.equals("")) { timerRunning = true;//from w w w.j a va 2 s .c o m ((TextView) findViewById(R.id.timer_error_text)).setText(""); final int time = Integer.parseInt(timeText); m_timerMenuItem.setTitle("" + time); Runnable r = new Runnable() { long m_startTime = System.currentTimeMillis(); long m_endTime = m_startTime + 1000 * time; @Override public void run() { if (System.currentTimeMillis() < m_endTime && timerRunning) { // if the time hasn't elapsed h.postDelayed(this, 1000); // update the actionBar m_timerMenuItem.setTitle( Long.toString(time + ((m_startTime - System.currentTimeMillis()) / 1000))); } else { if (timerRunning) { Toast.makeText(c, "Timer Done!", Toast.LENGTH_LONG).show(); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(500); } timerRunning = false; m_timerMenuItem.setTitle("Set Timer"); } } }; h.postDelayed(r, 1000); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(findViewById(R.id.timerEditText).getWindowToken(), 0); mCurrentFragment = new CodersBestFragment(R.layout.fragment_timer_stop); Bundle args = new Bundle(); mCurrentFragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(com.HACK.codersbestfriend.R.id.content_frame, mCurrentFragment, "fragmentTag") .commit(); } else { ((TextView) findViewById(R.id.timer_error_text)).setText("Enter a time!"); } } }