Example usage for android.os Handler post

List of usage examples for android.os Handler post

Introduction

In this page you can find the example usage for android.os Handler post.

Prototype

public final boolean post(Runnable r) 

Source Link

Document

Causes the Runnable r to be added to the message queue.

Usage

From source file:app.android.example.com.commontcents.ListContentFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View recyclerView = inflater.inflate(R.layout.item_list, container, false);

    final ProgressBar progressBar = (ProgressBar) recyclerView.findViewById(R.id.progress_bar);
    progressBar.setScaleY(3f);/*  ww w.  j ava2  s .  com*/

    final Handler mHandler = new Handler();

    mHandler.post(new Runnable() {
        public void run() {
            progressBar.incrementProgressBy(10 * poolCounter.getCount());
            progressBar.setProgress(progressBar.getProgress());
        }
    });

    return recyclerView;
}

From source file:github.daneren2005.dsub.util.Util.java

public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService,
        Handler handler) {
    // Remove notification and remove the service from the foreground
    handler.post(new Runnable() {
        @Override/*from  w w  w.ja v  a2 s  .c  om*/
        public void run() {
            downloadService.stopForeground(true);
        }
    });

    // Update widget
    DSubWidgetProvider.getInstance().notifyChange(context, downloadService, false);
}

From source file:org.tanrabad.survey.presenter.maps.MarkerDropInAnimator.java

public void start() {
    long duration = calculateDropInDuration(marker);
    LatLng startLatLng = startLatLng(marker);
    Handler handler = new Handler();
    handler.post(new MarkerAnimationRunnable(handler, startLatLng, marker.getPosition(), duration));
}

From source file:com.example.gcmandroid.GcmService.java

private void sendNotification(final String msg) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override/*  w w w  .  j  a  v a 2  s.  co m*/
        public void run() {
            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
            if (MainActivity.mTextView != null) {
                MainActivity.mTextView.setText(msg);
            }
        }
    });
}

From source file:com.massivcode.weatherinfoexam.fragment.CurrentWeatherInfoFragment.java

public void setData(final WeatherInfo weatherInfo) {
    final WeatherInfo.Weather weather = weatherInfo.weather.get(0);

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override// w w w  .j ava 2  s.  com
        public void run() {
            mSunrise.setText(weatherInfo.sys.sunrise);
            mSunset.setText(weatherInfo.sys.sunset);
            mWindSpeed.setText(weatherInfo.wind.speed);
            mWindDeg.setText(weatherInfo.wind.deg);
            mWeather.setText(weather.description);
            mTemp.setText(weatherInfo.main.temp);
            mPressure.setText(weatherInfo.main.pressure);
            mHumidity.setText(weatherInfo.main.humidity);
            mVisibility.setText(weatherInfo.visibility);
        }
    });

}

From source file:emu.project64.GalleryActivity.java

public static void RomListAddItem(String FullFileName, String FileName, String GoodName, int TextColor) {
    GalleryItem item = new GalleryItem(mActiveGalleryActivity, GoodName, FileName, FullFileName, TextColor);
    mGalleryItems.add(item);/*from   w w  w  .j av a2 s .  c o  m*/
    if (mActiveGalleryActivity != null && mActiveGalleryActivity.mProgress != null) {
        Handler h = new Handler(Looper.getMainLooper());
        final String ProgressText = new String(FileName);
        final String ProgressSubText = new String(FullFileName);
        final String ProgressMessage = new String("Added " + GoodName);

        h.post(new Runnable() {
            public void run() {
                mActiveGalleryActivity.mProgress.setText(ProgressText);
                mActiveGalleryActivity.mProgress.setSubtext(ProgressSubText);
                mActiveGalleryActivity.mProgress.setMessage(ProgressMessage);
            }
        });
    }
}

From source file:com.example.etsmith.gcmupstream.MyGcmListenerService.java

@Override
public void onMessageReceived(String from, final Bundle data) {
    super.onMessageReceived(from, data);

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        public void run() {
            Toast.makeText(getApplicationContext(), "Message Received: " + data.toString(), Toast.LENGTH_SHORT)
                    .show();/*w w  w. j  a va2s .co m*/
        }
    });

    for (String dataTag : data.keySet()) {
        if (!dataTag.equals(Constants.NOTIFICATION_BUNDLE)) {
            Log.d(TAG, dataTag + ": " + data.getString(dataTag));
        } else {
            Bundle bundle = data.getBundle(dataTag);
            for (String bundleTag : bundle.keySet()) {
                Log.d(TAG, bundleTag + ": " + data.getString(bundleTag));
            }
        }
    }

    String action = data.getString(Constants.ACTION);
    String status = data.getString(Constants.STATUS);

    if (Constants.REGISTER_NEW_CLIENT.equals(action) && Constants.STATUS_REGISTERED.equals(status)) {
        Log.d(TAG, "Registration Success");
    } else if (Constants.UNREGISTER_CLIENT.equals(action) && Constants.STATUS_UNREGISTERED.equals(status)) {
        //            token = "";
        Log.d(TAG, "Unregistration Success");
    } else if (from.startsWith(Constants.TOPIC_ROOT)) {
        Log.d(TAG, "Topic message: " + data.toString());
    } else {
        Log.d(TAG, "Other type of action: " + data.toString());
    }
}

From source file:org.thialfihar.android.apg.service.ApgIntentServiceHandler.java

public void showProgressDialog(FragmentActivity activity) {
    // TODO: This is a hack!, see http://bit.ly/1n53EXo
    final FragmentManager manager = activity.getSupportFragmentManager();
    Handler handler = new Handler();
    handler.post(new Runnable() {
        public void run() {
            mProgressDialogFragment.show(manager, "progressDialog");
        }//  w w w.j  a  va  2 s . c  om
    });
}

From source file:com.datasnap.android.request.RequestThread.java

/**
 * Performs the request to the server./* ww  w .  ja va2  s.com*/
 *
 * @param batch the action batch to send
 */
public void send(final Batch batch, final RequestCallback callback) {

    Handler handler = handler();

    handler.post(new Runnable() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();

            // send the actual request
            HttpResponse response = requester.send(batch);

            long duration = System.currentTimeMillis() - start;
            Analytics.getStatistics().updateRequestTime(duration);

            boolean success = false;

            if (response == null) {
                // there's been an error
                Logger.w("Failed to make request to the server.");
            } else if (response.getStatusLine().getStatusCode() != 200) {
                try {
                    // there's been a server error
                    Logger.e("Received a failed response from the server. %s",
                            EntityUtils.toString(response.getEntity()));
                } catch (ParseException e) {
                    Logger.w(e, "Failed to parse the response from the server.");
                } catch (IOException e) {
                    Logger.w(e, "Failed to read the response from the server.");
                }
            } else {

                Logger.d("Successfully sent a batch to the server");

                success = true;
            }

            if (callback != null)
                callback.onRequestCompleted(success);
        }
    });
}

From source file:au.com.zacher.popularmovies.activity.fragment.FragmentBase.java

public void setViewState(final ViewState state) {
    Handler mainHandler = new Handler(this.parent.getMainLooper());
    mainHandler.post(new Runnable() {
        @Override//w w w  .  j ava 2 s . co  m
        public void run() {
            switch (state) {
            case ERROR:
                FragmentBase.this.progressBar.setVisibility(View.GONE);
                FragmentBase.this.getMainViewItem().setVisibility(View.GONE);
                FragmentBase.this.noInternetSection.setVisibility(View.VISIBLE);
                break;

            case IN_PROGRESS:
                FragmentBase.this.progressBar.setVisibility(View.VISIBLE);
                FragmentBase.this.getMainViewItem().setVisibility(View.GONE);
                FragmentBase.this.noInternetSection.setVisibility(View.GONE);
                break;

            case SUCCESS:
                FragmentBase.this.progressBar.setVisibility(View.GONE);
                FragmentBase.this.getMainViewItem().setVisibility(View.VISIBLE);
                FragmentBase.this.noInternetSection.setVisibility(View.GONE);
                break;
            }
        }
    });
}