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:org.andrico.andrico.UiHandler.java

@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    Log.d(LOG, "what:" + msg.what);
    Log.d(LOG, "result: " + msg.getData().getString("result"));
}

From source file:org.zywx.wbpalmstar.plugin.uexCalendarView.EUExCalendarView.java

private void handleOpen(Message msg) {
    String[] params = msg.getData().getStringArray(ECalendarViewUtils.CALENDAR_PARAMS_KEY_FUNCTION);
    if (params == null || params.length != 1) {
        return;/* w w w.jav  a 2  s  .c  om*/
    }
    try {
        JSONObject json = new JSONObject(params[0]);
        int x = Integer.parseInt(json.getString(ECalendarViewUtils.CALENDAR_PARAMS_KEY_X));
        int y = Integer.parseInt(json.getString(ECalendarViewUtils.CALENDAR_PARAMS_KEY_Y));
        int w = Integer.parseInt(json.getString(ECalendarViewUtils.CALENDAR_PARAMS_KEY_W));
        int h = Integer.parseInt(json.getString(ECalendarViewUtils.CALENDAR_PARAMS_KEY_H));
        String id = json.optString(ECalendarViewUtils.CALENDAR_PARAMS_KEY_ID, DEFAULT_VIEW_ID);
        myCalendarView = new CalendarView(mContext);
        myCalendarView.setBackgroundColor(Color.WHITE);
        myCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {

            @Override
            public void onSelectedDayChange(CalendarView calendarView, int year, int month, int day) {
                callBack(year, month + 1, day);
            }

        });
        android.widget.AbsoluteLayout.LayoutParams layoutParams = new android.widget.AbsoluteLayout.LayoutParams(
                w, h, x, y);
        addViewToWebView(myCalendarView, layoutParams, id);
    } catch (Exception e) {
    }
}

From source file:org.sufficientlysecure.keychain.service.ServiceProgressHandler.java

@Override
public void handleMessage(Message message) {
    Bundle data = message.getData();

    MessageStatus status = MessageStatus.fromInt(message.arg1);
    switch (status) {
    case OKAY://from w ww . j a v a2  s.c  o  m
        dismissAllowingStateLoss();

        break;

    case EXCEPTION:
        dismissAllowingStateLoss();

        // show error from service
        if (data.containsKey(DATA_ERROR)) {
            Notify.create(mActivity, mActivity.getString(R.string.error_message, data.getString(DATA_ERROR)),
                    Notify.Style.ERROR).show();
        }

        break;

    case UPDATE_PROGRESS:
        if (data.containsKey(DATA_PROGRESS) && data.containsKey(DATA_PROGRESS_MAX)) {

            String msg = null;
            int progress = data.getInt(DATA_PROGRESS);
            int max = data.getInt(DATA_PROGRESS_MAX);

            // update progress from service
            if (data.containsKey(DATA_MESSAGE)) {
                msg = data.getString(DATA_MESSAGE);
            } else if (data.containsKey(DATA_MESSAGE_ID)) {
                msg = mActivity.getString(data.getInt(DATA_MESSAGE_ID));
            }

            onSetProgress(msg, progress, max);

        }

        break;

    case PREVENT_CANCEL:
        setPreventCancel(true);
        break;

    default:
        Log.e(Constants.TAG, "unknown handler message!");
        break;
    }
}

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

public Runnable getMethodSignOn(final Application app, final Bundle b, final Handler resultHandler) {
    return new Runnable() {
        public void run() {
            Message m = resultHandler.obtainMessage();
            Bundle bm = m.getData();

            Log.d("dcuploader", "authenticating...");

            String encdata = b.getString("enc_data");
            String name = b.getString("name");
            String code1 = b.getString("code1");
            String code2 = b.getString("code2");

            HttpPost post = new HttpPost(AUTH_URL);
            List<NameValuePair> vlist = new ArrayList<NameValuePair>();
            vlist.add(new BasicNameValuePair("enc_data", encdata));
            vlist.add(new BasicNameValuePair("result_code", "1"));
            vlist.add(new BasicNameValuePair("contract_type", "S"));
            vlist.add(new BasicNameValuePair("au_chk", "F"));
            vlist.add(new BasicNameValuePair("name", name));
            vlist.add(new BasicNameValuePair("juminid1", code1));
            vlist.add(new BasicNameValuePair("juminid2", code2));
            try {
                post.setEntity(new UrlEncodedFormEntity(vlist));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();//from  www  . j a v  a2s  .co  m
            }

            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(), "EUC-KR"));

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

                    if (line.contains(" ??  ")) {
                        bm.putBoolean("result", false);
                        bm.putString("resultString", "?? ");
                        resultHandler.sendMessage(m);
                        return;
                    }
                }
            } catch (Exception e) {
                bm.putBoolean("result", false);
                bm.putString("resultString", " ");
                resultHandler.sendMessage(m);

                return;
            }

            /* abnormal status. traffic limit exceeded? */
            bm.putBoolean("result", true);
            resultHandler.sendMessage(m);
        }
    };
}

From source file:com.pusher.PusherModule.java

@Kroll.method(runOnUiThread = true)
public void connect() {
    mHandler = new Handler() {
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            Bundle bundleData = msg.getData();
            if (bundleData.getString("type").contentEquals("pusher")) {
                try {
                    JSONObject message = new JSONObject(bundleData.getString("message"));
                    Log.d("Pusher Message", message.toString());

                    if (message.getString("event").equals("connection_established")) {
                        PusherModule.this.fireEvent("connected", null);
                    }/*w w w  .  j ava2  s  . c  om*/

                    if (PusherModule.this.hasListeners(message.getString("event"))) {
                        KrollDict event = new KrollDict();
                        event.put("name", message.getString("event"));

                        JSONObject data = new JSONObject(message.getString("data"));
                        event.put("data", KrollDict.fromJSON(data));

                        PusherModule.this.fireEvent(message.getString("event"), event);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            if (bundleData.getString("type").contentEquals("pusher:disconnected")) {
                PusherModule.this.fireEvent("disconnected", null);
            }
        }
    };

    mPusher = new Pusher(mReconnectAutomatically, mReconnectDelay);
    mPusher.addHandler(mHandler);
    mPusher.connect(mPusherKey);
}

From source file:com.android.wako.net.BaseRequest.java

public void sendData() {
    if (!Constants.IS_STOP_REQUEST) {
        Message msg = new Message();
        msg.obj = ret;/*from  w w  w.j  a  v a2s . c om*/
        msg.getData().putSerializable("callback", callBack);
        resultHandler.sendMessage(msg);
    }
}

From source file:com.emorym.android_pusher.DeprecatedPusherSampleActivity.java

/** Called when the activity is first created. */
@Override/*from   ww w  .j a  va 2 s.  com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.main);

    // This Handler is going to deal with incoming messages
    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle bundleData = msg.getData();
            if (bundleData.getString("type").contentEquals("pusher")) {
                try {
                    JSONObject message = new JSONObject(bundleData.getString("message"));

                    Log.d("Pusher Message", message.toString());

                    Toast.makeText(mContext, message.toString(), Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    };

    mPusher = new Pusher(mHandler);
    mPusher.connect(PUSHER_APP_KEY);

    // Setup some toggles to subscribe/unsubscribe from our 2 test channels
    final ToggleButton test1 = (ToggleButton) findViewById(R.id.toggleButton1);
    final ToggleButton test2 = (ToggleButton) findViewById(R.id.toggleButton2);

    final Button send = (Button) findViewById(R.id.send_button);

    test1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (test1.isChecked())
                mPusher.subscribe(PUSHER_CHANNEL_1);
            else
                mPusher.unsubscribe(PUSHER_CHANNEL_1);
        }
    });

    test2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (test2.isChecked())
                mPusher.subscribe(PUSHER_CHANNEL_2);
            else
                mPusher.unsubscribe(PUSHER_CHANNEL_2);
        }
    });

    send.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText channelName = (EditText) findViewById(R.id.channel_name);
            EditText eventName = (EditText) findViewById(R.id.event_name);
            EditText eventData = (EditText) findViewById(R.id.event_data);

            try {
                JSONObject data = new JSONObject();
                data.put("data", eventData.getText().toString());
                mPusher.send(eventName.getText().toString(), data, channelName.getText().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:ru.gelin.android.weather.notification.skin.impl.BaseWeatherNotificationReceiver.java

protected void notifyHandler(Weather weather) {
    synchronized (BaseWeatherNotificationReceiver.class) { //monitor of static methods
        if (handler == null) {
            return;
        }/* w  w w .j  av  a  2  s. co m*/
        Message message = handler.obtainMessage();
        Bundle bundle = message.getData();
        bundle.putParcelable(WEATHER_KEY, new ParcelableWeather2(weather));
        message.sendToTarget();
    }
}

From source file:org.zywx.wbpalmstar.plugin.chatkeyboard.EUExChatKeyboard.java

private void handleOpen(Message msg) {
    String[] params = msg.getData().getStringArray(CHATKEYBOARD_FUN_PARAMS_KEY);
    if (params == null || params.length < 1)
        return;/*  ww  w.  java  2s . c  om*/
    try {
        if (mChatKeyboardView != null) {
            return;
        }
        JSONObject json = new JSONObject(params[0]);
        mChatKeyboardView = new ACEChatKeyboardView(mContext, json, this);

        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        // lp.bottomMargin=json.optInt("bottom",0);
        addView2CurrentWindow(mChatKeyboardView, lp);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.noah.lol.network.RequestNetwork.java

protected void asyncRequestGet(final String url, final NetworkListener<String> listener) {

    if (url == null) {
        return;// w w w. j  a va2  s.c o  m
    }

    try {
        environmentCheck();
    } catch (EnvironmentException e) {
        if (listener != null) {
            e.setStatus(BAD_REQUEST_ENVIRONMENT_CONFIG);
            listener.onNetworkFail(BAD_REQUEST_ENVIRONMENT_CONFIG, e);
        }
        return;
    }

    final Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            Bundle bundle = msg.getData();
            switch (msg.what) {
            case REQUEST_SUCCESS:
                String responseBody = bundle.getString(RESPONSE_KEY);

                if (listener != null && responseBody != null) {
                    listener.onSuccess(responseBody);
                }
                break;
            case REQUEST_FAIL:
                NetworkException e = (NetworkException) bundle.getSerializable(EXCEPTION_KEY);
                if (listener != null) {
                    listener.onNetworkFail(e.getStatus(), e);
                }
                break;
            }
        }
    };

    new Thread(new Runnable() {

        @Override
        public void run() {

            String responseBody = null;
            Message message = new Message();

            try {
                responseBody = syncRequestGet(url);
                Bundle bundle = new Bundle();
                bundle.putString(RESPONSE_KEY, responseBody);
                message = Message.obtain(handler, REQUEST_SUCCESS);
                message.setData(bundle);
                handler.sendMessage(message);
            } catch (NetworkException e) {
                Bundle bundle = new Bundle();
                bundle.putSerializable(EXCEPTION_KEY, e);
                message = Message.obtain(handler, REQUEST_FAIL);
                message.setData(bundle);
                handler.sendMessage(message);
                e.printStackTrace();
            }

        }
    }).start();

}