Example usage for android.os Message Message

List of usage examples for android.os Message Message

Introduction

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

Prototype

public Message() 

Source Link

Document

Constructor (but the preferred way to get a Message is to call #obtain() Message.obtain() ).

Usage

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 ww  . jav a2  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:com.ryan.ryanreader.common.General.java

/**
 * Message//from  w w  w  .  jav a 2s .c  o  m
 * 
 * @param what
 * @param obj
 * @return
 */
public static Message handlerMessage(int what, Object obj) {
    final Message msg = new Message();
    msg.what = what;
    msg.obj = obj;
    return msg;
}

From source file:com.huison.DriverAssistant_Web.util.LoginHelper.java

private static void sendMsg(Activity activity, int flag) {
    Message msg = new Message();
    msg.what = flag;/* www. j a v  a  2 s  .co m*/
    msg.obj = activity;
    HomeActivity.handler.sendMessage(msg);
}

From source file:com.norman0406.slimgress.API.Interface.RequestResult.java

public RequestResult(Handler handler) {
    mResultHandler = handler;
    mMessage = new Message();
}

From source file:com.spoiledmilk.ibikecph.login.HTTPAccountHandler.java

public static Message performRegister(final UserData userData, Context context) {
    Message message = new Message();
    JsonNode result = null;/*from   ww w.  j  av  a2 s  . c  o m*/
    JSONObject jsonPOST = new JSONObject();
    JSONObject jsonUser = new JSONObject();
    JSONObject jsonImagePath = new JSONObject();
    try {
        jsonImagePath.put("filename", userData.getImageName());
        jsonImagePath.put("original_filename", userData.getImageName());
        jsonImagePath.put("file", userData.getBase64Image());
        jsonUser.put("name", userData.getName());
        jsonUser.put("email", userData.getEmail());
        jsonUser.put("email_confirmation", userData.getEmail());
        jsonUser.put("password", userData.getPassword());
        jsonUser.put("password_confirmation", userData.getPassword());
        if (userData.getBase64Image() != null && !userData.getBase64Image().trim().equals(""))
            jsonUser.put("image_path", jsonImagePath);
        jsonUser.put("account_source", context.getResources().getString(R.string.account_source));
        jsonPOST.put("user", jsonUser);
        result = HttpUtils.postToServer(Config.API_SERVER_REGISTER, jsonPOST);
        message = HttpUtils.JSONtoMessage(result);
        message.getData().putInt("type", REGISTER_USER);
    } catch (JSONException e) {
        LOG.e(e.getLocalizedMessage());
        message.getData().putInt("type", ERROR);
    }
    return message;
}

From source file:net.evecom.androidecssp.activity.EventListActivity.java

/**
 * /*from www. j ava 2 s.com*/
 */
private void initlist() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Message message = new Message();

            try {
                resutArray = connServerForResultPost("jfs/ecssp/mobile/eventCtr/getEnentList", null);
            } catch (ClientProtocolException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            } catch (IOException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            }
            if (resutArray.length() > 0) {
                try {
                    eventInfos = getObjsInfo(resutArray);
                    if (null == eventInfos) {
                        message.what = MESSAGETYPE_02;
                    } else {
                        message.what = MESSAGETYPE_01;
                    }
                } catch (JSONException e) {
                    message.what = MESSAGETYPE_02;
                    Log.e("mars", e.getMessage());
                }
            } else {
                message.what = MESSAGETYPE_02;
            }
            Log.v("mars", resutArray);
            eventListHandler.sendMessage(message);

        }
    }).start();

}

From source file:com.rsimiao.exemplosloopj.UsuarioWS.java

public void buscar(final Handler handler) {

    try {/*ww  w  .j a  va2s . com*/
        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();
    }

}

From source file:org.quantumbadger.redreader.common.General.java

public static Message handlerMessage(int what, Object obj) {
    final Message msg = new Message();
    msg.what = what;/*www  . j a  v a2 s  . co  m*/
    msg.obj = obj;
    return msg;
}

From source file:net.evecom.androidecssp.activity.ProjectListActivity.java

/**
 * /*from w w w. j  a v a2  s .c  o  m*/
 */
private void initlist() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Message message = new Message();

            try {
                HashMap<String, String> hashMap = new HashMap<String, String>();
                hashMap.put("eventId", eventInfo.get("id").toString());
                resutArray = connServerForResultPost("jfs/ecssp/mobile/taskresponseCtr/getAllProjectByeventId",
                        hashMap);
            } catch (ClientProtocolException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            } catch (IOException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            }
            if (resutArray.length() > 0) {
                try {
                    projectInfos = getObjsInfo(resutArray);
                    if (null == projectInfos) {
                        message.what = MESSAGETYPE_02;
                    } else {
                        message.what = MESSAGETYPE_01;
                    }
                } catch (JSONException e) {
                    message.what = MESSAGETYPE_02;
                    Log.e("mars", e.getMessage());
                }
            } else {
                message.what = MESSAGETYPE_02;
            }
            Log.v("mars", resutArray);
            projectListHandler.sendMessage(message);

        }
    }).start();

}

From source file:net.evecom.androidecssp.activity.event.EventListActivity.java

/**
 * /*from   ww w . j ava  2s . c om*/
 */
private void initlist() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Message message = new Message();

            try {
                HashMap<String, String> entityMap = new HashMap<String, String>();
                entityMap.put("pagesize", HttpUtil.getPageSize(instance));
                if (!ifqueryallevents) {
                    String deptid = ShareUtil.getString(instance, "PASSNAME", "orgid", "");
                    entityMap.put("deptid", deptid);
                }
                resutArray = connServerForResultPost("jfs/ecssp/mobile/eventCtr/getEnentList", entityMap);
            } catch (ClientProtocolException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            } catch (IOException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            }
            if (resutArray.length() > 0) {
                try {
                    eventInfos = getObjsInfo(resutArray);
                    if (null == eventInfos) {
                        message.what = MESSAGETYPE_02;
                    } else {
                        message.what = MESSAGETYPE_01;
                    }
                } catch (JSONException e) {
                    message.what = MESSAGETYPE_02;
                    Log.e("mars", e.getMessage());
                }
            } else {
                message.what = MESSAGETYPE_02;
            }
            Log.v("mars", resutArray);
            eventListHandler.sendMessage(message);

        }
    }).start();

}