List of usage examples for android.os Handler post
public final boolean post(Runnable r)
From source file:com.sentaroh.android.TextFileBrowser.FileViewerFragment.java
@SuppressWarnings("unused") private void setUiMsg(final TextView tv_msg, Handler handler, final String msg) { handler.post(new Runnable() { @Override/* www .j av a 2 s . c o m*/ public void run() { tv_msg.setVisibility(TextView.VISIBLE); tv_msg.setText(msg); } }); }
From source file:com.mrcaps.taskswidget.TasksHelper.java
public static void refreshAuthTokenImpl3(final Context context, final boolean invalidate, final Runnable continuation) { final Handler handl = getHandler(); //doing this in the same thread leads to deadlock. new Thread(new Runnable() { public void run() { GoogleLoginServiceBlockingHelper helper = null; try { helper = new GoogleLoginServiceBlockingHelper(context); String googleAcct = helper.getAccount(true); Log.v(TAG, "Google account is " + googleAcct); account = googleAcct;//from w ww.j av a 2 s . c om if (invalidate) { long now = System.currentTimeMillis(); Log.v(TAG, "Auth Token Invalidation Requested"); if (now - lastInvalidation > invalidationDelta) { Log.v(TAG, "Invalidating Auth Token"); try { String intoken = helper.getAuthToken(googleAcct, SERVICE_NAME); helper.invalidateAuthToken(intoken); } catch (AuthenticationException e) { Log.e(TAG, "Couldn't invalidate token", e); } lastInvalidation = now; } } try { String token = helper.getAuthToken(googleAcct, SERVICE_NAME); Log.v(TAG, "Got auth token:" + token); authToken = token; } catch (AuthenticationException e) { Log.e(TAG, "Couldn't authenticate", e); handl.post(new Runnable() { @Override public void run() { Toast.makeText(context, "Error: could not authenticate with Google account", Toast.LENGTH_SHORT).show(); } }); } } catch (GoogleLoginServiceNotFoundException e) { Log.e(TAG, "Couldn't find login service - please contact us!", e); handl.post(new Runnable() { @Override public void run() { Toast.makeText(context, "Error: could not find Google Login service - please contact us!", Toast.LENGTH_SHORT).show(); } }); } finally { if (helper != null) { helper.close(); } continuation.run(); } } }).start(); }
From source file:org.addhen.smssync.presentation.view.ui.fragment.MessageFragment.java
public void requestQuery(final String query) { Handler handler = new Handler(); final Runnable filterDeployments = new Runnable() { public void run() { try { mMessageAdapter.getFilter().filter(query); } catch (Exception e) { reloadMessages();//www. j av a 2 s . co m } } }; handler.post(filterDeployments); }
From source file:net.bible.android.view.activity.StartupActivity.java
/** Called when the activity is first created. */ @Override/* www. ja v a2s . co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.startup_view); // do not show an actionBar/title on the splash screen getSupportActionBar().hide(); TextView versionTextView = (TextView) findViewById(R.id.versionText); String versionMsg = BibleApplication.getApplication().getString(R.string.version_text, CommonUtils.getApplicationVersionName()); versionTextView.setText(versionMsg); //See if any errors occurred during app initialisation, especially upgrade tasks int abortErrorMsgId = BibleApplication.getApplication().getErrorDuringStartup(); // check for SD card // it would be great to check in the Application but how to show dialog from Application? if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { abortErrorMsgId = R.string.no_sdcard_error; } // show fatal startup msg and close app if (abortErrorMsgId != 0) { Dialogs.getInstance().showErrorMsg(abortErrorMsgId, new Callback() { @Override public void okay() { // this causes the blue splashscreen activity to finish and since it is the top the app closes finish(); } }); // this aborts further initialisation but leaves blue splashscreen activity return; } // allow call back and continuation in the ui thread after JSword has been initialised final Handler uiHandler = new Handler(); final Runnable uiThreadRunnable = new Runnable() { @Override public void run() { postBasicInitialisationControl(); } }; // initialise JSword in another thread (takes a long time) then call main ui thread Handler to continue // this allows the splash screen to be displayed and an hourglass to run new Thread() { public void run() { try { // allow the splash screen to be displayed immediately CommonUtils.pauseMillis(1); // force Sword to initialise itself Initialisation.getInstance().initialiseNow(); } finally { // switch back to ui thread to continue uiHandler.post(uiThreadRunnable); } } }.start(); }
From source file:com.trackdroid.activities.ShowInMapActivity.java
@Override public boolean onMarkerClick(final Marker marker) { if (marker.equals(mPerth)) { // This causes the marker at Perth to bounce into position when it // is clicked. final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); final long duration = 1500; final Interpolator interpolator = new BounceInterpolator(); handler.post(new Runnable() { @Override/*from www.j av a 2 s . co m*/ public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0); marker.setAnchor(0.5f, 1.0f + 2 * t); if (t > 0.0) { // Post again 16ms later. handler.postDelayed(this, 16); } } }); } else if (marker.equals(mAdelaide)) { // This causes the marker at Adelaide to change color and alpha. marker.setIcon(BitmapDescriptorFactory.defaultMarker(mRandom.nextFloat() * 360)); marker.setAlpha(mRandom.nextFloat()); } // We return false to indicate that we have not consumed the event and // that we wish // for the default behavior to occur (which is for the camera to move // such that the // marker is centered and for the marker's info window to open, if it // has one). return false; }
From source file:com.microsoft.rightsmanagement.sampleapp.MsipcTaskFragment.java
/** * Update task status.// w w w.j a v a 2s.co m * * @param taskStatus the task status */ private void updateTaskStatus(final TaskStatus taskStatus) { if (taskStatus.mPostToCaller) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { if (mTaskEventCallback != null) { mLatestUnpostedTaskStatus = null; mTaskEventCallback.onMsipcTaskUpdate(taskStatus); } else { mLatestUnpostedTaskStatus = taskStatus; } } }); } }
From source file:com.androzic.location.LocationService.java
private void updateGpsStatus(final int status, final int fsats, final int tsats) { gpsStatus = status;//from w w w.ja va 2s .com updateNotification(); final Handler handler = new Handler(); for (final ILocationListener callback : locationCallbacks) { handler.post(new Runnable() { @Override public void run() { callback.onGpsStatusChanged(LocationManager.GPS_PROVIDER, status, fsats, tsats); } }); } final int n = locationRemoteCallbacks.beginBroadcast(); for (int i = 0; i < n; i++) { final ILocationCallback callback = locationRemoteCallbacks.getBroadcastItem(i); try { callback.onGpsStatusChanged(LocationManager.GPS_PROVIDER, status, fsats, tsats); } catch (RemoteException e) { Log.e(TAG, "Status broadcast error", e); } } locationRemoteCallbacks.finishBroadcast(); Log.d(TAG, "GPS status dispatched: " + (locationCallbacks.size() + n)); }
From source file:com.androzic.location.LocationService.java
private void updateProvider(final String provider, final boolean enabled) { if (LocationManager.GPS_PROVIDER.equals(provider)) updateNotification();// w ww. j a v a2 s .co m final Handler handler = new Handler(); for (final ILocationListener callback : locationCallbacks) { handler.post(new Runnable() { @Override public void run() { if (enabled) callback.onProviderEnabled(provider); else callback.onProviderDisabled(provider); } }); } final int n = locationRemoteCallbacks.beginBroadcast(); for (int i = 0; i < n; i++) { final ILocationCallback callback = locationRemoteCallbacks.getBroadcastItem(i); try { if (enabled) callback.onProviderEnabled(provider); else callback.onProviderDisabled(provider); } catch (RemoteException e) { Log.e(TAG, "Provider broadcast error", e); } } locationRemoteCallbacks.finishBroadcast(); Log.d(TAG, "Provider status dispatched: " + (locationCallbacks.size() + n)); }
From source file:com.bellman.bible.android.view.activity.StartupActivity.java
/** * Called when the activity is first created. */// w ww .j a va 2 s. c om @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.startup_view); mIntent = getIntent(); // do not show an actionBar/title on the splash screen getSupportActionBar().hide(); //get the linear layout // pHolder = (LinearLayout) findViewById(R.id.progress_holder); // TextView versionTextView = (TextView) findViewById(R.id.versionText); // String versionMsg = CurrentActivityHolder.getInstance().getApplication().getString(R.string.version_text, CommonUtils.getApplicationVersionName()); // versionTextView.setText(versionMsg); //See if any errors occurred during app initialisation, especially upgrade tasks // TODO: 8/15/2016 Remember changes made here int abortErrorMsgId = 0;//BibleApplication.getApplication(.getErrorDuringStartup(); // check for SD card // it would be great to check in the Application but how to show dialog from Application? if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { abortErrorMsgId = R.string.no_sdcard_error; } // show fatal startup msg and close app if (abortErrorMsgId != 0) { Dialogs.getInstance().showErrorMsg(abortErrorMsgId, new Callback() { @Override public void okay() { // this causes the blue splashscreen activity to finish and since it is the top the app closes finish(); } }); // this aborts further initialisation but leaves blue splashscreen activity return; } // allow call back and continuation in the ui thread after JSword has been initialised final Handler uiHandler = new Handler(); final Runnable uiThreadRunnable = new Runnable() { @Override public void run() { postBasicInitialisationControl(); } }; // initialise JSword in another thread (takes a long time) then call main ui thread Handler to continue // this allows the splash screen to be displayed and an hourglass to run new Thread() { public void run() { try { // allow the splash screen to be displayed immediately CommonUtils.pauseMillis(1); // force Sword to initialise itself Initialisation.getInstance().initialiseNow(); } finally { // switch back to ui thread to continue uiHandler.post(uiThreadRunnable); } } }.start(); }
From source file:com.adjust.sdk.ActivityHandler.java
private void launchAttributionListener() { if (adjustConfig.onAttributionChangedListener == null) { return;//from w w w . ja v a 2 s . c o m } Handler handler = new Handler(adjustConfig.context.getMainLooper()); Runnable runnable = new Runnable() { @Override public void run() { adjustConfig.onAttributionChangedListener.onAttributionChanged(attribution); } }; handler.post(runnable); }