List of usage examples for android.os Handler sendMessage
public final boolean sendMessage(Message msg)
From source file:ac.robinson.mediaphone.activity.TemplateBrowserActivity.java
private void postUpdateTemplateIcons() { mPendingIconsUpdate = true;//w ww . j a v a 2 s .com Handler handler = mScrollHandler; handler.removeMessages(R.id.msg_update_template_icons); Message message = handler.obtainMessage(R.id.msg_update_template_icons, TemplateBrowserActivity.this); handler.sendMessage(message); }
From source file:com.mytutor.search.ImageLoader.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { Log.d("IMG 1", "Getting Image"); imageView.setImageDrawable(drawableMap.get(urlString)); }//from w w w . j a va 2s. c o m final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:com.fabbychat.utils.DrawableManager.java
public void fetchDrawableOnThread(final DrawableProducer dp, final ImageView imageView) { String key = dp.getKey();/*from ww w . ja v a2 s .c o m*/ if (drawableMap.containsKey(key)) { Drawable d = drawableMap.get(key); if (d != null) { imageView.setImageDrawable(drawableMap.get(key)); } return; } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(dp); if (drawable != null) { Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } } }; thread.start(); }
From source file:eu.loopit.f2011.library.BitmapManager.java
public void fetchBitmapOnThread(final String urlString, final ImageView imageView, final Bitmap defaultImage) { if (bitmapMap.containsKey(urlString)) { imageView.setImageBitmap(bitmapMap.get(urlString)); }/* w ww . j a v a 2 s .c o m*/ final Handler handler = new Handler() { @Override public void handleMessage(Message message) { if (message.obj != null) { imageView.setImageBitmap((Bitmap) message.obj); } } }; Thread thread = new Thread() { @Override public void run() { Bitmap bitmap = fetchBitmap(urlString, defaultImage); Message message = handler.obtainMessage(1, bitmap); handler.sendMessage(message); } }; thread.start(); }
From source file:org.neugierig.proximo.AsyncBackend.java
public void startQuery(final Query query, final APIResultCallback callback) { final int MSG_RESULT = 0; final int MSG_EXCEPTION = 1; final Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case MSG_RESULT: callback.onAPIResult(msg.obj); break; case MSG_EXCEPTION: callback.onException((Exception) msg.obj); break; }//from w ww. j av a 2 s . c om } }; Thread thread = new Thread(new Runnable() { public void run() { try { Object result = query.runQuery(mBackend); handler.sendMessage(handler.obtainMessage(MSG_RESULT, result)); } catch (Exception exn) { handler.sendMessage(handler.obtainMessage(MSG_EXCEPTION, (Object) exn)); } } }, "Network Fetch"); thread.start(); }
From source file:net.patchingzone.ru4real.nuevo.TorchActivityPlugin.java
/** Called when the activity is first created. */ @Override/*from w w w . ja v a2s. c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.camera_flash); button = findViewById(R.id.button); disablePhoneSleep(); // turnLightOn(); Log.i(TAG, "onCreate"); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.arg1 == 0) { turnLightOff(); } else { turnLightOn(); } } }; int flashVal = 1; Message m = new Message(); m.arg1 = flashVal; mHandler.sendMessage(m); }
From source file:com.oonusave.coupon.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); return;/* ww w . java 2 s. c o m*/ } if (urlString != null && "".equalsIgnoreCase(urlString)) { return; } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); drawableMap.put(urlString, drawable); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:it.fdev.utils.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); }// w ww .ja v a2 s . c o m final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; 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); } } }; thread.start(); }
From source file:org.microg.gms.gcm.McsService.java
private void sendOutputStream(int what, int arg, Object obj) { McsOutputStream os = outputStream;//from w w w. j a v a2 s . c o m if (os != null && os.isAlive()) { Handler outputHandler = os.getHandler(); if (outputHandler != null) outputHandler.sendMessage(outputHandler.obtainMessage(what, arg, 0, obj)); } }
From source file:com.rsimiao.exemplosloopj.UsuarioWS.java
public void buscar(final Handler handler) { try {/* www. j a v a 2s .c om*/ RequestParams parametros = new RequestParams(); parametros.add("limite", "todos"); Wscliente.post(url, parametros, new AsyncHttpResponseHandler() { @Override public void onFailure(int code, Header[] header, byte[] conteudo, Throwable arg3) { //voc pode colocar aqui seu tratamento de erro Log.d("WS USUARIO", "DEU ERRO"); Message msg = new Message(); msg.what = 0; //defino um identificador para a msg coloco 1 para sucesso e 0 para erro. handler.sendMessage(msg); } @Override public void onSuccess(int code, Header[] header, byte[] conteudo) { try { JSONObject json = new JSONObject(new String(conteudo)); List<Usuario> usuarios = new ArrayList<Usuario>(); //sua lgica para tratar o json recebido (no precisa ser desse modo jurstico) if (json.has("status") && json.getString("status").equalsIgnoreCase("success")) { JSONArray jUsrs = json.getJSONArray("usuarios"); for (int i = 0; i < jUsrs.length(); i++) { Usuario u = new Usuario(); u.setNome(jUsrs.getJSONObject(i).getString("nome")); u.setUsuario(jUsrs.getJSONObject(i).getString("usuario")); u.setLogged(jUsrs.getJSONObject(i).getBoolean("islogged")); usuarios.add(u); } Message msg = new Message(); msg.what = 1; //defino um identificador para a msg coloco 1 para sucesso e 0 para erro. msg.obj = usuarios; handler.sendMessage(msg); } } catch (JSONException e) { e.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } }