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:zxing.util.CaptureActivity.java

License:asdf

private void showToastByRunnable(final Context context, final CharSequence text, final int duration) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override//from w w w .j a  v a  2 s. c  o m
        public void run() {
            Toast.makeText(context, text, duration).show();
        }
    });
}

From source file:com.ushahidi.android.ui.fragment.ListDeploymentFragment.java

public void requestQuery(final String query) {
    Handler handler = new Handler();
    final Runnable filterDeployments = new Runnable() {
        public void run() {
            try {
                mRecyclerViewAdapter.getFilter().filter(query);
            } catch (Exception e) {
                refreshList();/*  w ww  .  jav  a  2 s  . c  o m*/
            }
        }
    };

    handler.post(filterDeployments);
}

From source file:com.licubeclub.zionhs.MainActivity.java

void networkTask() {
    SRL.setRefreshing(true);/*from  w  ww.ja  va 2 s . co m*/
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
        }
    };

    final Handler mHandler = new Handler();
    new Thread() {

        public void run() {
            mHandler.post(new Runnable() {

                public void run() {
                    // SRL.setRefreshing(true);
                }
            });
            try {
                lunchstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "2"); //Get Lunch Menu Date
                dinnerstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "3"); //Get Dinner Menu Date
            } catch (Exception e) {
            }

            try {
                int skipcount = 0;
                boolean skipped = false;
                schedulearray = new ArrayList<String>();
                dayarray = new ArrayList<String>();

                //                    ? ?? ? ??  
                Document doc = Jsoup.connect(URL).get();

                Elements rawdaydata = doc.select(".listDay"); //Get contents from the class,"listDay"
                for (Element el : rawdaydata) {
                    String daydata = el.text();
                    if (daydata.equals("") | daydata == null) {
                        if (skipped) {
                        } else {
                            skipcount++;
                        }
                    } else {
                        dayarray.add(daydata); // add value to ArrayList
                        skipped = true;
                    }
                }
                Log.d("Schedule", "Parsed Day Array" + dayarray);

                Elements rawscheduledata = doc.select(".listData"); //Get contents from tags,"a" which are in the class,"ellipsis"
                for (Element el : rawscheduledata) {
                    String scheduledata = el.text();
                    if (skipcount > 0) {
                        skipcount--;
                    } else {
                        schedulearray.add(scheduledata); // add value to ArrayList
                    }
                }
                Log.d("Schedule", "Parsed Schedule Array" + schedulearray);
                //                    SRL.setRefreshing(false);
            } catch (IOException e) {
                e.printStackTrace();
                //                    SRL.setRefreshing(false);

            }
            try {
                titlearray_np = new ArrayList<String>();
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=59")
                        .get();
                Elements rawdata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody"
                String titlestring = rawdata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                for (Element el : rawdata) {
                    String titledata = el.attr("title");
                    titlearray_np.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Array Strings" + titlearray_np);

            } catch (IOException e) {
                e.printStackTrace();

            }
            //Notices URL
            try {
                titlearray_n = new ArrayList<String>();
                // ? URL
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?" + "menugrp=110100&master=bbs&act=list&master_sid=58")
                        .get();
                //Get contents from tags,"a" which are in the class,"listbody"
                Elements rawmaindata = doc.select(".listbody a");
                String titlestring = rawmaindata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                // ??  ?
                for (Element el : rawmaindata) {
                    String titledata = el.attr("title");
                    titlearray_n.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Array Strings" + titlearray_n);

            } catch (IOException e) {
                e.printStackTrace();

            }

            mHandler.post(new Runnable() {
                public void run() {
                    //                        progressDialog.dismiss();
                    //                        SRL.setRefreshing(false);
                    if (AMorPM == Calendar.AM) {
                        MealString = lunchstring[DAYofWEEK - 1];
                    } else {
                        MealString = dinnerstring[DAYofWEEK - 1];
                    }
                    try {
                        ScheduleString = schedulearray.get(DAYofMONTH - 1);
                        NoticesParentString = titlearray_np.get(0);
                        NoticeString = titlearray_n.get(0);
                    } catch (Exception e) {
                        ScheduleString = getResources().getString(R.string.error);
                        NoticesParentString = getResources().getString(R.string.error);
                        NoticeString = getResources().getString(R.string.error);
                    }

                    if (MealString == null) {
                        MealString = getResources().getString(R.string.nodata);
                    } else if (MealString.equals("")) {
                        MealString = getResources().getString(R.string.nodata);
                    }
                    if (ScheduleString == null) {
                        ScheduleString = getResources().getString(R.string.nodata);
                    } else if (ScheduleString.equals("")) {
                        ScheduleString = getResources().getString(R.string.nodata);
                    }
                    SRL.setRefreshing(false);
                    handler.sendEmptyMessage(0);
                    setContentData();
                }
            });

        }
    }.start();

}

From source file:github.madmarty.madsonic.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  www. jav a 2s.  c o  m*/
        public void run() {
            downloadService.stopForeground(true);
        }
    });

    // Update widget
    MadsonicWidgetProvider.notifyInstances(context, downloadService, false);
}

From source file:com.mars.framework.volley.request.Request.java

/**
 * Notifies the request queue that this request has finished (successfully or with error).
 *
 * <p>Also dumps all events from this request's event log; for debugging.</p>
 *//*from  ww  w .  j a  v  a 2  s .c o m*/
public void finish(final String tag) {
    if (mRequestQueue != null) {
        mRequestQueue.finish(this);
    }
    if (MarkerLog.ENABLED) {
        final long threadId = Thread.currentThread().getId();
        if (Looper.myLooper() != Looper.getMainLooper()) {
            // If we finish marking off of the main thread, we need to
            // actually do it on the main thread to ensure correct ordering.
            Handler mainThread = new Handler(Looper.getMainLooper());
            mainThread.post(new Runnable() {
                @Override
                public void run() {
                    mEventLog.add(tag, threadId);
                    mEventLog.finish(this.toString());
                }
            });
            return;
        }

        mEventLog.add(tag, threadId);
        mEventLog.finish(this.toString());
    } else {
        long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime;
        if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) {
            VolleyLog.d("%d ms: %s", requestTime, this.toString());
        }
    }
}

From source file:com.facebook.FacebookActivityTestCase.java

protected void runOnBlockerThread(final Runnable runnable, boolean waitForCompletion) {
    Runnable runnableToPost = runnable;
    final ConditionVariable condition = waitForCompletion ? new ConditionVariable(!waitForCompletion) : null;

    if (waitForCompletion) {
        runnableToPost = new Runnable() {
            @Override/*  w  w w  .  j a  va2s .c om*/
            public void run() {
                runnable.run();
                condition.open();
            }
        };
    }

    TestBlocker blocker = getTestBlocker();
    Handler handler = blocker.getHandler();
    handler.post(runnableToPost);

    if (waitForCompletion) {
        boolean success = condition.block(10000);
        assertTrue(success);
    }
}

From source file:org.xbmc.android.remotesandbox.ui.SourcesFragment.java

@Override
public Loader<List<Source>> onCreateLoader(int id, Bundle args) {
    // This is called when a new Loader needs to be created. This
    // sample only has one Loader with no arguments, so it is simple.
    final Handler h = new Handler();
    return new ListLoader<Source>(getActivity(), new Worker<Source>() {
        @Override//from  w  w  w  .  j  ava2s  .c o  m
        public List<Source> doWork() {
            final FilesClient filesClient = new FilesClient();
            return filesClient.getMusicSources(new ErrorHandler() {
                @Override
                public void handleError(int code, final String message) {
                    Log.e(TAG, "ERROR " + code + ": " + message);
                    h.post(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getActivity(), "ERROR: " + message, Toast.LENGTH_LONG).show();
                        }
                    });
                }
            });
        }
    });
}

From source file:im.neon.contacts.ContactsManager.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (TextUtils.equals(key, PhoneNumberUtils.COUNTRY_CODE_PREF_KEY)) {
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override//from  w  w w  . j a v  a2  s.c  o m
            public void run() {
                onCountryCodeUpdate();
            }
        });
    }
}

From source file:org.xbmc.android.remotesandbox.ui.FilesFragment.java

@Override
public Loader<List<File>> onCreateLoader(int id, Bundle args) {
    // This is called when a new Loader needs to be created. This
    // sample only has one Loader with no arguments, so it is simple.
    final Handler h = new Handler();
    return new ListLoader<File>(getActivity(), new Worker<File>() {
        @Override/* w w w  .j a va  2 s .c o m*/
        public List<File> doWork() {
            final FilesClient filesClient = new FilesClient();
            return filesClient.getDirectory(mPath, new ErrorHandler() {
                @Override
                public void handleError(int code, final String message) {
                    Log.e(TAG, "ERROR " + code + ": " + message);
                    h.post(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getActivity(), "ERROR: " + message, Toast.LENGTH_LONG).show();
                        }
                    });
                }
            });
        }
    });
}

From source file:com.sentaroh.android.BluetoothWidget.Log.LogFileListDialogFragment.java

private void reInitViewWidget() {
    if (DEBUG_ENABLE)
        Log.v(APPLICATION_TAG, "reInitViewWidget");
    if (!mTerminateRequired) {
        Handler hndl = new Handler();
        hndl.post(new Runnable() {
            @Override/* w w  w .ja v  a2 s .co m*/
            public void run() {
                saveViewContents();
                initViewWidget();
                restoreViewContents();
                if (mLogFileManagementAdapter.isAnyItemSelected()) {
                    setContextButtonSelecteMode(mLogFileManagementAdapter);
                } else {
                    setContextButtonNormalMode(mLogFileManagementAdapter);
                }

            }
        });
    }
}