List of usage examples for android.os Handler sendMessage
public final boolean sendMessage(Message msg)
From source file:com.mindprotectionkit.freephone.RedPhoneService.java
public void setCallStateHandler(Handler handler) { this.handler = handler; if (handler != null) { for (Message message : bufferedEvents) { handler.sendMessage(message); }/*from w w w . j a v a 2 s . co m*/ bufferedEvents.clear(); } }
From source file:com.nachiket.titan.LibraryPagerAdapter.java
/** * Set the sort mode for the current adapter. Current adapter must be a * MediaAdapter. Saves this sort mode to preferences and updates the list * associated with the adapter to display the new sort mode. * * @param mode The sort mode. See {@link MediaAdapter#setSortMode(int)} for * details.// w w w .ja va 2 s.c om */ public void setSortMode(int mode) { MediaAdapter adapter = (MediaAdapter) mCurrentAdapter; if (mode == adapter.getSortMode()) return; adapter.setSortMode(mode); requestRequery(adapter); // Force a new FastScroller to be created so the scroll sections // are updated. ListView view = mLists[mTabOrder[mCurrentPage]]; view.setFastScrollEnabled(false); enableFastScroll(view); Handler handler = mWorkerHandler; handler.sendMessage(handler.obtainMessage(MSG_SAVE_SORT, adapter)); }
From source file:de.jerleo.samsung.knox.firewall.MainActivity.java
private void applyRules() { // Get context final Context context = this; // Show progress final ProgressDialog progress = new ProgressDialog(this); // Finish message final Toast completed = Toast.makeText(this, getString(R.string.firewall_rules_complete), Toast.LENGTH_SHORT);/*from www . j a v a 2 s. co m*/ progress.setIndeterminate(true); progress.setProgress(0); progress.show(); // Handler to dismiss progress @SuppressLint("HandlerLeak") final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); progress.dismiss(); completed.show(); } }; // Apply firewall rules new Thread(new Runnable() { @Override public void run() { progress.setMessage(getString(R.string.firewall_rules_create)); Firewall.createRules(context); handler.sendMessage(handler.obtainMessage()); } }).start(); }
From source file:com.nachiket.titan.LibraryPagerAdapter.java
@Override public boolean handleMessage(Message message) { switch (message.what) { case MSG_RUN_QUERY: { LibraryAdapter adapter = (LibraryAdapter) message.obj; int index = adapter.getMediaType(); Handler handler = mUiHandler; handler.sendMessage(handler.obtainMessage(MSG_COMMIT_QUERY, index, 0, adapter.query())); break;/*w w w . j a v a2 s. com*/ } case MSG_COMMIT_QUERY: { int index = message.arg1; mAdapters[index].commitQuery(message.obj); int pos; if (mSavedPositions == null) { pos = 0; } else { pos = mSavedPositions[index]; mSavedPositions[index] = 0; } mLists[index].setSelection(pos); break; } case MSG_SAVE_SORT: { MediaAdapter adapter = (MediaAdapter) message.obj; SharedPreferences.Editor editor = PlaybackService.getSettings(mActivity).edit(); editor.putInt(String.format("sort_%d_%d", adapter.getMediaType(), adapter.getLimiterType()), adapter.getSortMode()); editor.commit(); break; } case MSG_REQUEST_REQUERY: requestRequery((LibraryAdapter) message.obj); break; default: return false; } return true; }
From source file:org.privatenotes.sync.web.SnowySyncMethod.java
public void getAuthUri(final String server, final Handler handler) { execInThread(new Runnable() { public void run() { // Reset the authentication credentials OAuthConnection auth = new OAuthConnection(); Uri authUri = null;//from w ww .j a v a 2s. c o m try { authUri = auth.getAuthorizationUrl(server); } catch (UnknownHostException e) { Log.e(TAG, "Internet connection not available"); sendMessage(NO_INTERNET); } Message message = new Message(); message.obj = authUri; handler.sendMessage(message); } }); }
From source file:com.andrewshu.android.reddit.threads.BitmapManager.java
public void fetchBitmapOnThread(final String urlString, final ImageView imageView, final ProgressBar indeterminateProgressBar, final Activity act) { SoftReference<Bitmap> ref = mCache.get(urlString); if (ref != null && ref.get() != null) { imageView.setImageBitmap(ref.get()); return;//from w w w.j ava2s. com } final Runnable progressBarShow = new Runnable() { public void run() { if (indeterminateProgressBar != null) { imageView.setVisibility(View.GONE); indeterminateProgressBar.setVisibility(View.VISIBLE); } } }; final Runnable progressBarHide = new Runnable() { public void run() { if (indeterminateProgressBar != null) { indeterminateProgressBar.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); } } }; final Handler handler = new Handler() { @Override public void handleMessage(Message message) { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarHide); imageView.setImageBitmap((Bitmap) message.obj); } }; Thread thread = new Thread() { @Override public void run() { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarShow); Bitmap bitmap = fetchBitmap(urlString); Message message = handler.obtainMessage(1, bitmap); handler.sendMessage(message); } }; thread.start(); }
From source file:com.temboo.example.YouTubeResultView.java
/** * A utility method to retrieve the thumbnail image on a separate thread, and populate * the image view with that thumbnail/*from w ww . jav a 2s. c o m*/ * @param urlString - the URL of the thumbnail to retrieve * @param imageView - the view to populate with the thumbnail */ private void fetchDrawableOnThread(final String urlString, final ImageView imageView) { final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(urlString); HttpResponse response = httpClient.execute(request); InputStream is = response.getEntity().getContent(); Drawable drawable = Drawable.createFromStream(is, "src"); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } catch (Exception e) { Toast.makeText(getContext(), "An error occurred retrieving the video thumbnail", Toast.LENGTH_LONG).show(); } } }; thread.start(); }
From source file:com.binroot.fatpita.BitmapManager2.java
public void fetchBitmapOnThread(final String urlString, final ImageView imageView, final ProgressBar indeterminateProgressBar, final Activity act, final int sample) { SoftReference<Bitmap> ref = mCache.get(urlString); if (ref != null && ref.get() != null) { imageView.setImageBitmap(ref.get()); return;/* w w w.ja v a 2 s . c o m*/ } final Runnable progressBarShow = new Runnable() { public void run() { if (indeterminateProgressBar != null) { imageView.setVisibility(View.GONE); indeterminateProgressBar.setVisibility(View.VISIBLE); } } }; final Runnable progressBarHide = new Runnable() { public void run() { if (indeterminateProgressBar != null) { indeterminateProgressBar.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); } } }; final Handler handler = new Handler() { @Override public void handleMessage(Message message) { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarHide); imageView.setImageBitmap((Bitmap) message.obj); } }; Thread thread = new Thread() { @Override public void run() { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarShow); Bitmap bitmap = fetchBitmap(urlString, sample); Message message = handler.obtainMessage(1, bitmap); handler.sendMessage(message); } }; thread.start(); }
From source file:it.fdev.utils.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final DrawableManagerListener listener) { if (drawableMap.containsKey(urlString)) { listener.onLoadingComplete(drawableMap.get(urlString)); }//from w w w. j a v a 2 s. c o m final Handler handler = new Handler() { @Override public void handleMessage(Message message) { listener.onLoadingComplete((Drawable) message.obj); } }; final Handler errorHandler = new Handler() { @Override public void handleMessage(Message message) { listener.onLoadingError(); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); if (drawable != null) { Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } else { Message message = new Message(); errorHandler.sendMessage(message); } } }; thread.start(); }
From source file:mp.teardrop.LibraryPagerAdapter.java
@Override public boolean handleMessage(Message message) { switch (message.what) { case MSG_RUN_QUERY: { //we are on the worker thread here LibraryAdapter adapter = (LibraryAdapter) message.obj; Handler handler = mUiHandler; handler.sendMessage( handler.obtainMessage(MSG_COMMIT_QUERY, adapter.getMediaType(), 0, adapter.query())); break;//from ww w .j av a2 s . c om } case MSG_COMMIT_QUERY: { //we are on the UI thread here int index = message.arg1; if (index == MediaUtils.TYPE_UNIFIED) { //MediaInfoHolder mih = (MediaInfoHolder) message.obj; mAdapters[index].commitQuery(message.obj); //showInLocalLibrary(mih); } else { mAdapters[index].commitQuery(message.obj); int pos; if (mSavedPositions == null) { pos = 0; } else { pos = mSavedPositions[index]; mSavedPositions[index] = 0; } ListView listView = (ListView) mContainingLayouts[index].findViewById(R.id.actual_list_view); listView.setSelection(pos); } ((ListView) mContainingLayouts[getCurrentType()].findViewById(R.id.actual_list_view)) .smoothScrollToPosition(0); ; break; } case MSG_SAVE_SORT: { MediaAdapter adapter = (MediaAdapter) message.obj; SharedPreferences.Editor editor = PlaybackService.getSettings(mActivity).edit(); editor.putInt(String.format("sort_%d_%d", adapter.getMediaType(), adapter.getLimiterType()), adapter.getSortMode()); editor.commit(); break; } case MSG_REQUEST_REQUERY: requestRequery((LibraryAdapter) message.obj); break; default: return false; } return true; }