List of usage examples for android.os Handler post
public final boolean post(Runnable r)
From source file:org.ntpsync.service.NtpSyncService.java
private void handleResult(final Message message) { Log.d(Constants.TAG, "Handle message directly in NtpSyncService..."); // we need a looper to get toasts displayed from service! Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { public void run() { DateFormat df = DateFormat.getDateTimeInstance(); switch (message.arg1) { case NtpSyncService.RETURN_GENERIC_ERROR: Toast.makeText(getApplicationContext(), getString(R.string.app_name) + ": " + getString(R.string.return_generic_error), Toast.LENGTH_LONG).show(); break; case NtpSyncService.RETURN_OKAY: Bundle returnData = message.getData(); final Date newTime = (Date) returnData.getSerializable(NtpSyncService.MESSAGE_DATA_TIME); Toast.makeText(//ww w .ja v a2 s.com getApplicationContext(), getString(R.string.app_name) + ": " + getString(R.string.return_set_time) + " " + df.format(newTime), Toast.LENGTH_LONG).show(); break; case NtpSyncService.RETURN_SERVER_TIMEOUT: Toast.makeText(getApplicationContext(), getString(R.string.app_name) + ": " + getString(R.string.return_timeout), Toast.LENGTH_LONG).show(); break; case NtpSyncService.RETURN_NO_ROOT: Toast.makeText(getApplicationContext(), getString(R.string.app_name) + ": " + getString(R.string.return_no_root), Toast.LENGTH_LONG).show(); break; default: break; } } }); }
From source file:com.xbm.android.matisse.ui.MatisseActivity.java
@Override public void onAlbumLoad(final Cursor cursor) { mAlbumsAdapter.swapCursor(cursor);//from w w w . j ava2s . com // select default album. Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { cursor.moveToPosition(mAlbumCollection.getCurrentSelection()); mAlbumsSpinner.setSelection(MatisseActivity.this, mAlbumCollection.getCurrentSelection()); Album album = Album.valueOf(cursor); if (album.isAll() && SelectionSpec.getInstance().capture) { album.addCaptureCount(); } onAlbumSelected(album); } }); }
From source file:org.apache.cordova.nodialogspeechrecognizer.SpeechRecognizer.java
/** * Fire an intent to start the speech recognition activity. * * @param args/*from w ww. j ava2 s.c o m*/ * Argument array with the following string args: [req code][number * of matches][prompt string] */ private void startSpeechRecognitionActivity(JSONArray args) { int maxMatches = 1; String prompt = ""; String language = Locale.getDefault().toString(); try { if (args.length() > 0) { // Maximum number of matches, 0 means the recognizer decides String temp = args.getString(0); maxMatches = Integer.parseInt(temp); } if (args.length() > 1) { // Optional text prompt prompt = args.getString(1); } if (args.length() > 2) { // Optional language specified language = args.getString(2); } } catch (Exception e) { Log.e(LOG_TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString())); } // Create the intent and set parameters final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, cordova.getActivity().getPackageName()); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); if (maxMatches > 0) intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches); if (!prompt.equals("")) intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt); try { Handler loopHandler = new Handler(Looper.getMainLooper()); loopHandler.post(new Runnable() { @Override public void run() { speech.startListening(intent); } }); } catch (Exception e) { Log.e("error", "er", e); } // cordova.startActivityForResult(this, intent, REQUEST_CODE); }
From source file:fr.cph.chicago.fragment.drawer.NavigationDrawerFragment.java
/** * Select item/*from w w w . j a v a 2 s . c o m*/ * * @param position * the position * @param backPressed * if back pressed */ public void selectItem(final int position, boolean backPressed) { mCurrentSelectedPosition = position; mPendingRunnable = new Runnable() { @Override public void run() { if (mCallbacks != null) { mCallbacks.onNavigationDrawerItemSelected(position); } } }; if (backPressed) { Handler mHandler = new Handler(); mHandler.post(mPendingRunnable); mPendingRunnable = null; } if (mDrawerListView != null) { mDrawerListView.setItemChecked(position, true); } if (mDrawerLayout != null) { mDrawerLayout.closeDrawer(mFragmentContainerView); } else { mCallbacks.onNavigationDrawerItemSelected(position); } // if (mCallbacks != null) { // mCallbacks.onNavigationDrawerItemSelected(position); // } }
From source file:org.schabi.newpipe.VideoItemListFragment.java
private void postNewErrorToast(Handler h, final String message) { h.post(new Runnable() { @Override// w ww . jav a 2 s. co m public void run() { setListShown(true); Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(); } }); }
From source file:com.ferid.app.frequentcontacts.selectnumber.SelectNumberActivity.java
/** * Run time searching// ww w.ja v a2s . c om * @param searchText */ private void searchEngine(final String searchText) { Handler handler = new Handler(); handler.post(new Runnable() { @Override public void run() { ArrayList<Contact> tmpList = new ArrayList<>(); //first, add names that start with searchText for (Contact location : wholeArrayList) { if (location.getName().toLowerCase().startsWith(searchText.toLowerCase())) { tmpList.add(location); } } //then, add names that contain searchText for (Contact location : wholeArrayList) { if (location.getName().toLowerCase().contains(searchText.toLowerCase()) && !location.getName().toLowerCase().startsWith(searchText.toLowerCase())) { tmpList.add(location); } } numberList.clear(); numberList.addAll(tmpList); adapter.notifyDataSetChanged(); } }); }
From source file:org.schabi.newpipe.VideoItemListFragment.java
private void postNewNothingFoundToast(Handler h, final int stringResource) { h.post(new Runnable() { @Override//from w w w.j a v a 2 s . c om public void run() { setListShown(true); Toast.makeText(getActivity(), getString(stringResource), Toast.LENGTH_LONG).show(); } }); }
From source file:at.andreasrohner.spartantimelapserec.BackgroundService.java
@Override public void surfaceCreated(final SurfaceHolder surfaceHolder) { handlerThread = new HandlerThread("recordingVideo"); handlerThread.start();//www . java 2s. c o m Context context = getApplicationContext(); Handler handler = new Handler(handlerThread.getLooper(), this); recorder = Recorder.getInstance(settings, surfaceHolder, context, handler, wakeLock); handler.post(new Runnable() { @Override public void run() { recorder.start(); } }); }
From source file:pl.openrnd.connection.rest.ConnectionHandler.java
private void notifyTakingTooLong(final Request request) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override//from w ww. j a va2s. c o m public void run() { if (mOnRequestConnectionListener != null) { mOnRequestConnectionListener.onRequestTakingTooLong(request); } } }); }
From source file:com.applivery.applvsdklib.ui.views.update.MustUpdateViewImpl.java
private void updatProcessTextView(final double percent, Handler handler) { Runnable myRunnable = new Runnable() { @Override//from w ww . ja va2s . com public void run() { progressBar.setProgress(Double.valueOf(percent).intValue()); } }; handler.post(myRunnable); }