Example usage for android.os Message getData

List of usage examples for android.os Message getData

Introduction

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

Prototype

public Bundle getData() 

Source Link

Document

Obtains a Bundle of arbitrary data associated with this event, lazily creating it if necessary.

Usage

From source file:at.andreasrohner.spartantimelapserec.BackgroundService.java

@Override
public boolean handleMessage(Message m) {
    String status = m.getData().getString("status");
    String tag = m.getData().getString("tag");
    String msg = m.getData().getString("msg");

    String name = getString(R.string.app_name);

    if ("error".equals(status)) {
        Log.e(tag, "Error: " + msg);

        final Context context = getApplicationContext();
        final String text = name + " Error: " + msg;

        surfaceView.post(new Runnable() {
            @Override/* www .j a  va 2s  .c  om*/
            public void run() {
                Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
                toast.show();
            }
        });
    }

    stopSelf();
    return true;
}

From source file:ibp.plugin.nsd.NSDPlugin.java

private void initNsd(CallbackContext callbackContext) {
    final CallbackContext cbc = callbackContext;
    initNsdCB = callbackContext;// w  ww .  j  a va  2  s  . c  o  m
    try {
        if (null == mHandler) {
            mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    String type = msg.getData().getString("type");
                    String message = msg.getData().getString("msg");

                    JSONObject data = new JSONObject();
                    try {
                        data.put("type", new String(type));
                        data.put("data", new String(message));
                    } catch (JSONException e) {
                    }
                    PluginResult result = new PluginResult(PluginResult.Status.OK, data);
                    result.setKeepCallback(true);
                    cbc.sendPluginResult(result);
                }
            };
            if (null == mNsdHelper) {
                mNsdHelper = new NSDHelper(cordova.getActivity(), mHandler);
                mNsdHelper.initializeNsd();
            }
            PluginResult result = new PluginResult(PluginResult.Status.OK, "initNsd: success.");
            result.setKeepCallback(true);
            callbackContext.sendPluginResult(result);
        } else {
            PluginResult result = new PluginResult(PluginResult.Status.ERROR,
                    "initNsd: Nsd Has been Initialized.");
            callbackContext.sendPluginResult(result);
        }
    } catch (Exception e) {
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, "initNsd Exception: " + e);
        callbackContext.sendPluginResult(result);
    }
}

From source file:com.variable.demo.api.fragment.ThermaFragment.java

@Override
public void onTemperatureReading(ThermaSensor sensor, SensorReading<Float> reading) {
    Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_THERMA_TEMPERATURE);
    m.getData().putFloat(MessageConstants.FLOAT_VALUE_KEY, reading.getValue());

    final Context thiscontext = this.getActivity();
    final String serialnumOne = sensor.getSerialNumber();
    final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", "");
    final String scan = Float.toString(reading.getValue());
    String json = "temperature;" + serialnum + ";" + scan;

    // POST to variable dashboard
    Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false);
    Ion.with(thiscontext).load(/*from  w w  w  .  j av a2  s. co m*/
            "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]="
                    + json)
            .setLogging("MyLogs", Log.DEBUG).asString().withResponse()
            .setCallback(new FutureCallback<Response<String>>() {
                @Override
                public void onCompleted(Exception e, Response<String> result) {
                    if (e == null) {
                        Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString());
                    } else {
                        Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION");
                        e.printStackTrace();
                    }
                }
            });
    m.sendToTarget();

}

From source file:org.planetmono.dcuploader.SignOnGallog.java

public Runnable getMethodSignOn(final Application app, final Bundle b, final Handler resultHandler) {
    return new Runnable() {
        public void run() {
            String id, password;//from   w w  w  .  ja  va  2  s  .  c  om

            id = b.getString("id");
            password = b.getString("password");

            Message m = resultHandler.obtainMessage();
            Bundle bm = m.getData();

            Log.d(Application.TAG, "logging in...");

            HttpPost post = new HttpPost(SIGNON_URL);
            List<NameValuePair> vlist = new ArrayList<NameValuePair>();
            vlist.add(new BasicNameValuePair("user_id", id));
            vlist.add(new BasicNameValuePair("password", password));
            vlist.add(new BasicNameValuePair("x", "0"));
            vlist.add(new BasicNameValuePair("y", "0"));
            vlist.add(new BasicNameValuePair("s_url", "about:blank"));
            try {
                post.setEntity(new UrlEncodedFormEntity(vlist));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            post.setHeader("Origin", SIGNON_BASE_URL);
            post.setHeader("Referer", SIGNON_PAGE_URL);

            HttpResponse response = null;
            try {
                response = app.sendPostRequest(post);
            } catch (Exception e) {
                e.printStackTrace();

                bm.putBoolean("result", false);
                bm.putString("resultString", " ");
                resultHandler.sendMessage(m);
                return;
            }

            HttpEntity entity = response.getEntity();
            BufferedReader r;
            try {
                r = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));

                while (true) {
                    String line = r.readLine();
                    if (line == null)
                        break;

                    if (line.contains(" ")
                            || line.contains("?? ? ")) {
                        bm.putBoolean("result", false);
                        bm.putString("resultString", "? ");
                        resultHandler.sendMessage(m);
                        entity.consumeContent();
                        return;
                    } else if (line.contains("about:blank")) {
                        /* successful */
                        bm.putBoolean("result", true);
                        bm.putInt("method", getMethodId());
                        resultHandler.sendMessage(m);
                        entity.consumeContent();
                        return;
                    }
                }
            } catch (Exception e) {
                bm.putBoolean("result", false);
                bm.putString("resultString", " ");
                resultHandler.sendMessage(m);

                try {
                    entity.consumeContent();
                } catch (IOException e1) {
                }

                return;
            }

            try {
                entity.consumeContent();
            } catch (IOException e) {
            }

            /* abnormal status. */
            bm.putBoolean("result", false);
            bm.putString("resultString", "   .");
            resultHandler.sendMessage(m);
        }
    };
}

From source file:com.grass.caishi.cc.service.BaseIntentService.java

public void doInbackground(Message msg) {

    Bundle b = msg.getData();
    SendBean send = (SendBean) b.getSerializable("send");
    RequestParams params = new RequestParams();
    params.put("title", send.getTitle());
    params.put("text", send.getText());
    params.put("act_id", send.getAct_id());
    params.put("iss_next", send.getIss_next());
    ArrayList<String> images = send.getImg_list();
    if (images != null && images.size() > 0) {
        for (int i = 0; i < images.size(); i++) {
            File file = new File(images.get(i));
            try {
                params.put("img" + i, file, "image/jpeg");
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();/*from   w  ww.  j  a  va  2 s. c  o m*/
            }
        }
    }

    HttpRestClient.post(Constant.SEND_MATCH_DO, params, new TextHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, String responseString) {
            // TODO Auto-generated method stub
            if (CommonUtils.isNullOrEmpty(responseString)) {
                Toast.makeText(getApplicationContext(), "???", Toast.LENGTH_SHORT).show();
                return;
            }
            Map<String, Object> m = JsonToMapList.getMap(responseString);
            if (m != null && !CommonUtils.isNullOrEmpty(m.get("data")) && m.get("ok").toString().equals("1")) {
                intent.putExtra("progress", 100);
                intent.putExtra("do", UP_FINSH);
                intent.putExtra("data", m.get("data").toString());
                sendBroadcast(intent);
            }
            // filelist.remove(0);
            // if (filelist.size() == 0) {
            // intent.putExtra("progress", 100);
            // intent.putExtra("do", UP_CLEAR);
            // sendBroadcast(intent);
            // }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            // TODO Auto-generated method stub
            Toast.makeText(getApplicationContext(), "?", Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:com.variable.demo.api.fragment.ClimaFragment.java

@Override
public void onClimaLightUpdate(ClimaSensor clima, SensorReading<Float> lightLevel) {
    Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_CLIMA_LIGHT);
    m.getData().putFloat(MessageConstants.FLOAT_VALUE_KEY, lightLevel.getValue());
    // convert the UTF
    final Context thiscontext = this.getActivity();
    final DecimalFormat formatter = new DecimalFormat("0.00");
    final String serialnumOne = clima.getSerialNumber();
    final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", "");
    final String scann = formatter.format(lightLevel.getValue());
    String json = "light;" + serialnum + ";" + scann;

    // POST to variable dashboard
    Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false);
    Ion.with(thiscontext).load(/*  ww  w  .  j  a  v a2s. co  m*/
            "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]="
                    + json)
            .setLogging("MyLogs", Log.DEBUG).asString().withResponse()
            .setCallback(new FutureCallback<Response<String>>() {
                @Override
                public void onCompleted(Exception e, Response<String> result) {
                    if (e == null) {
                        Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString());
                    } else {
                        Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION");
                        e.printStackTrace();
                    }
                }
            });
    m.sendToTarget();
}

From source file:com.variable.demo.api.fragment.ClimaFragment.java

@Override
public void onClimaHumidityUpdate(ClimaSensor clima, SensorReading<Float> humidityLevel) {
    Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_CLIMA_HUMIDITY);
    m.getData().putFloat(MessageConstants.FLOAT_VALUE_KEY, humidityLevel.getValue());
    // convert the UTF
    final Context thiscontext = this.getActivity();
    final DecimalFormat formatter = new DecimalFormat("0.00");
    final String serialnumOne = clima.getSerialNumber();
    final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", "");
    final String scann = formatter.format(humidityLevel.getValue());
    String json = "humidity;" + serialnum + ";" + scann;

    // POST to variable dashboard
    Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false);
    Ion.with(thiscontext).load(/*from w w w. j av  a  2s.com*/
            "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]="
                    + json)
            .setLogging("MyLogs", Log.DEBUG).asString().withResponse()
            .setCallback(new FutureCallback<Response<String>>() {
                @Override
                public void onCompleted(Exception e, Response<String> result) {
                    if (e == null) {
                        Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString());
                    } else {
                        Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION");
                        e.printStackTrace();
                    }
                }
            });
    m.sendToTarget();
}

From source file:com.variable.demo.api.fragment.ClimaFragment.java

@Override
public void onClimaPressureUpdate(ClimaSensor clima, SensorReading<Integer> kPa) {
    Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_CLIMA_PRESSURE);
    m.getData().putFloat(MessageConstants.FLOAT_VALUE_KEY, kPa.getValue());
    // convert the UTF
    final Context thiscontext = this.getActivity();
    final DecimalFormat formatter = new DecimalFormat("0.00");
    final String serialnumOne = clima.getSerialNumber();
    final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", "");
    final String scann = formatter.format(kPa.getValue());
    String json = "pressure;" + serialnum + ";" + scann;

    // POST to variable dashboard
    Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false);
    Ion.with(thiscontext).load(/* w ww.  jav a 2s . co  m*/
            "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]="
                    + json)
            .setLogging("MyLogs", Log.DEBUG).asString().withResponse()
            .setCallback(new FutureCallback<Response<String>>() {
                @Override
                public void onCompleted(Exception e, Response<String> result) {
                    if (e == null) {
                        Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString());
                    } else {
                        Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION");
                        e.printStackTrace();
                    }
                }
            });
    m.sendToTarget();
}

From source file:com.variable.demo.api.fragment.ClimaFragment.java

@Override
public void onClimaTemperatureUpdate(ClimaSensor clima, SensorReading<Float> temperature) {
    Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_CLIMA_TEMPERATURE);
    m.getData().putFloat(MessageConstants.FLOAT_VALUE_KEY, temperature.getValue());
    // convert the UTF
    final Context thiscontext = this.getActivity();
    final DecimalFormat formatter = new DecimalFormat("0.00");
    final String serialnumOne = clima.getSerialNumber();
    final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", "");
    final String scann = formatter.format(temperature.getValue());
    String json = "temperature;" + serialnum + ";" + scann;

    // POST to variable dashboard
    Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false);
    Ion.with(thiscontext).load(/*  w  w  w .  j av a  2s .c  om*/
            "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]="
                    + json)
            .setLogging("MyLogs", Log.DEBUG).asString().withResponse()
            .setCallback(new FutureCallback<Response<String>>() {
                @Override
                public void onCompleted(Exception e, Response<String> result) {
                    if (e == null) {
                        Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString());
                    } else {
                        Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION");
                        e.printStackTrace();
                    }
                }
            });
    m.sendToTarget();
}

From source file:org.sufficientlysecure.keychain.ui.DecryptFragment.java

protected void showPassphraseDialog(long keyId) {
    PassphraseDialogFragment.show(getActivity(), keyId, new Handler() {
        @Override//from www .j a v  a2s.  c  om
        public void handleMessage(Message message) {
            if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
                String passphrase = message.getData()
                        .getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE);
                decryptStart(passphrase);
            }
        }
    });
}