Example usage for android.os Handler sendMessage

List of usage examples for android.os Handler sendMessage

Introduction

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

Prototype

public final boolean sendMessage(Message msg) 

Source Link

Document

Pushes a message onto the end of the message queue after all pending messages before the current time.

Usage

From source file:it.cdpaf.helper.DrawableManager.java

public static void fetchDrawableOnThread(final Product product, final ImageView imageView, final Context ctx) {
    final String urlString = Const.IMAGE_URL + product.getPercorsoImmagine();
    if (drawableMap.containsKey(urlString)) {
        Log.d(ctx.getClass().getSimpleName(), "DRAWABLE MANAGER FDOT:" + "RIUSO, Size:" + drawableMap.size());
        imageView.setImageDrawable(drawableMap.get(urlString));
        return;//from ww w.  j a va2 s.c o m
        //product.setImmagine(drawableMap.get(urlString));
    }

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            Drawable dr = (Drawable) message.obj;
            imageView.setImageDrawable(dr);
            product.setImmagine(dr);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            //TODO : set imageView to a "pending" image
            Drawable d = ctx.getResources().getDrawable(R.drawable.blank);
            Message messagea = handler.obtainMessage(1, d);
            handler.sendMessage(messagea);
            Drawable drawable = fetchDrawable(urlString, ctx);

            Message messageb = handler.obtainMessage(1, drawable);
            handler.sendMessage(messageb);
        }
    };
    Log.i("DRAWABLE MANAGER:", "LANCIO FDOT, Size:" + drawableMap.size());
    thread.start();
}

From source file:it.cdpaf.helper.DrawableManager.java

public static ImageView fetchIvOnThread(String imagepath, int nthImage, final Context ctx) {
    final String urlString = Const.IMAGE_URL + imagepath;
    final Drawable resultDrawable;
    final ImageView imageView = new ImageView(ctx);

    String urlStringValid = "";
    if (nthImage == 0)
        urlStringValid = urlString;/*from w  w  w.ja  v  a  2  s  .c o  m*/
    else {
        String url = urlString + "_" + nthImage;
        String[] result = urlString.split(".j");
        String prima = result[0];
        String seconda = result[1];
        String jpg = ".j" + seconda;
        urlStringValid = prima + "_" + nthImage + jpg;
    }
    final String finalURl = urlStringValid;

    if (drawableMap.containsKey(urlStringValid)) {
        Log.d("ALL DRAWABLE", "INDIVIDUATO UN RIUSO : " + urlStringValid);
        resultDrawable = (drawableMap.get(urlStringValid));
        imageView.setImageDrawable(resultDrawable);
    } else {

        final Handler handler = new Handler() {
            @Override
            public void handleMessage(Message message) {
                Drawable resDrawable = ((Drawable) message.obj);
                imageView.setImageDrawable(resDrawable);
            }
        };

        Thread thread = new Thread() {
            @Override
            public void run() {
                //TODO : set imageView to a "pending" image
                Drawable drawable = fetchDrawable(finalURl, ctx);
                Message messageb = handler.obtainMessage(1, drawable);
                handler.sendMessage(messageb);
            }
        };
        Log.d("ALL DRAWABLE", "LANCIO UNA RICERCA : " + finalURl);
        thread.start();
    }

    return imageView;

}

From source file:Main.java

public static ResponseHandler<String> GetResponseHandlerInstance(final Handler handler) {
    final ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
        @Override/*from   w w  w .  j a  v a  2  s  .c  om*/
        public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            Message message = handler.obtainMessage();
            Bundle bundle = new Bundle();
            StatusLine status = response.getStatusLine();
            HttpEntity entity = response.getEntity();
            String result = null;
            if (entity != null) {
                try {
                    result = InputStreamToString(entity.getContent());
                    bundle.putString("RESPONSE", result);
                    message.setData(bundle);
                    handler.sendMessage(message);
                } catch (IOException e) {
                    bundle.putString("RESPONSE", "Error - " + e.getMessage());
                    message.setData(bundle);
                    handler.sendMessage(message);
                }
            } else {
                bundle.putString("RESPONSE", "Error - " + response.getStatusLine().getReasonPhrase());
                message.setData(bundle);
                handler.sendMessage(message);
            }
            return result;
        }
    };

    return responseHandler;
}

From source file:com.lovejoy777sarootool.rootool.preview.IconPreview.java

private static void queueJob(final File uri, final ImageView imageView) {
    /* Create handler in UI thread. */
    final Handler handler = new Handler() {
        @Override/*from  w  w  w  .j  av a  2s  . c o m*/
        public void handleMessage(Message msg) {
            String tag = imageViews.get(imageView);
            if (tag != null && tag.equals(uri.getAbsolutePath())) {
                if (msg.obj != null) {
                    imageView.setImageBitmap((Bitmap) msg.obj);
                } else {
                    imageView.setImageBitmap(null);
                }
            }
        }
    };

    pool.submit(new Runnable() {
        public void run() {
            final Bitmap bmp = getPreview(uri);
            Message message = Message.obtain();
            message.obj = bmp;

            handler.sendMessage(message);
        }
    });
}

From source file:com.hat.tools.HttpUtils.java

public static void SendRequest(String url, Handler handler) {
    HttpGet request = new HttpGet(url);
    HttpClient httpClient = new DefaultHttpClient();

    byte[] data = null;
    InputStream in = null;/*from w w  w.  j  av  a 2  s.c  o  m*/
    try {
        HttpResponse response = httpClient.execute(request);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            in = response.getEntity().getContent();
            byte[] buf = new byte[1024];
            int len = 0;
            while ((len = in.read(buf)) != -1) {
                out.write(buf, 0, len);
            }
            data = out.toByteArray();
            Message msg = new Message();
            msg.what = HTTP_FINISH;
            Bundle bundle = new Bundle();
            bundle.putByteArray("data", data);
            msg.setData(bundle);
            handler.sendMessage(msg);
            out.close();
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {

        try {
            if (in != null)
                in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:net.carlh.toast.State.java

private void changed(int p) {
    for (Handler h : handlers) {
        Message m = Message.obtain();//  w w  w  .j ava 2  s .  co m
        Bundle b = new Bundle();
        b.putInt("property", p);
        m.setData(b);
        h.sendMessage(m);
    }
}

From source file:com.example.hotspot.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    }// w  w  w  .  jav  a 2s. c  o  m

    final Handler handler = new Handler() {
        public void handleMessage(Message message) {
            imageView.setImageDrawable((Drawable) message.obj);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            Drawable drawable = fetchDrawable(urlString);
            Message message = handler.obtainMessage(1, drawable);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

From source file:com.novel.lightnovel.Utils.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    }//from  ww  w .  java  2  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() {
            Drawable drawable = fetchDrawable(urlString);
            Message message = handler.obtainMessage(1, drawable);
            handler.sendMessage(message);
        }
    };
    thread.start();
}

From source file:net.carlh.toast.Client.java

private void handler(JSONObject json) {
    try {//from   w  w w . j ava  2  s . c o  m
        if (json.has("type") && json.get("type").equals("pong")) {
            setConnected(true);
            pong.set(true);
        } else {
            for (Handler h : handlers) {
                Message m = Message.obtain();
                Bundle b = new Bundle();
                b.putString("json", json.toString());
                m.setData(b);
                h.sendMessage(m);
            }
        }
    } catch (JSONException e) {
    }
}

From source file:com.swavdev.tc.DrawableManager.java

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
    }//from  w  ww .  ja  v  a  2 s  .  co  m

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            imageView.setImageDrawable((Drawable) message.obj);
        }
    };
    executorService.submit(new Thread() {
        @Override
        public void run() {
            Drawable drawable = fetchDrawable(urlString);
            Message message = handler.obtainMessage(1, drawable);
            handler.sendMessage(message);

        }

    });
}