Example usage for android.os Message obtain

List of usage examples for android.os Message obtain

Introduction

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

Prototype

public static Message obtain() 

Source Link

Document

Return a new Message instance from the global pool.

Usage

From source file:id.nci.stm_9.FileDialogFragment.java

/**
 * Send message back to handler which is initialized in a activity
 * /*from  ww  w  .jav a2s . c o m*/
 * @param what
 *            Message integer you want to send
 */
private void sendMessageToHandler(Integer what, Bundle data) {
    Message msg = Message.obtain();
    msg.what = what;
    if (data != null) {
        msg.setData(data);
    }

    try {
        mMessenger.send(msg);
    } catch (RemoteException e) {
        Log.w("Stm-9", "Exception sending message, Is handler present?", e);
    } catch (NullPointerException e) {
        Log.w("Stm-9", "Messenger is null!", e);
    }
}

From source file:com.kanchi.periyava.old.Activity.MainActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    loadLanguage(LANGUAGE.ENGLISH);/*from   w  ww .j  a v  a 2s  .  com*/
    setContentView(R.layout.activity_main);
    context = this;
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
    initComponents(savedInstanceState);

    /* Retrieve a PendingIntent that will perform a broadcast */
    Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, alarmIntent, 0);

    UserProfile.getInstance();
    PreferenceData.getInstance(context);
    GeneralSetting.getInstance();

    Message msg = Message.obtain();
    msg.what = ConstValues.WELCOME;
    getFlowHandler().sendMessage(msg);

}

From source file:com.jwork.dhammapada.SearchFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    log.v(this, "onOptionsItemSelected(" + item.getItemId() + ")");
    Message message;//from   w  ww  .  ja va2 s  .  com
    switch (item.getItemId()) {
    case android.R.id.home:
        message = Message.obtain();
        message.what = Constant.WHAT_GOTO_BACK;
        message.obj = this;
        controller.executeMessage(message);
        break;
    case 99:
        break;
    default:
        //         Toast.makeText(getActivity(), "Unknown", Toast.LENGTH_SHORT).show();
        break;
    }
    return true;
}

From source file:com.jwork.spycamera.CameraTaskService.java

@Override
public void onDestroy() {
    log.v(this, "onDestroy()");
    super.onDestroy();
    running = false;//from   w  ww  . ja  v  a 2 s. co  m
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(NOTIFICATION_ID);

    if (state == WHAT_START_AUTOSHOT) {
        Message backMsg = Message.obtain();
        backMsg.what = MainController.WHAT_STOP_AUTOSHOOT;
        try {
            outMessenger.send(backMsg);
        } catch (android.os.RemoteException e1) {
            log.w(this, e1);
        }
    } else if (state == WHAT_START_VIDEO_RECORDING) {
        Message backMsg = Message.obtain();
        backMsg.what = MainController.WHAT_STOP_VIDEO;
        try {
            outMessenger.send(backMsg);
        } catch (android.os.RemoteException e1) {
            log.w(this, e1);
        }
    } else if (state == WHAT_START_FACESHOT) {
        Message backMsg = Message.obtain();
        backMsg.what = MainController.WHAT_STOP_FACESHOOT;
        try {
            outMessenger.send(backMsg);
        } catch (android.os.RemoteException e1) {
            log.w(this, e1);
        }
    }

    setState(WHAT_STOP);
}

From source file:com.darshancomputing.alockblock.ALockBlockService.java

private static void sendClientMessage(Messenger clientMessenger, int what, Bundle data) {
    Message outgoing = Message.obtain();
    outgoing.what = what;/*from w w  w .  j a v a 2s .  com*/
    outgoing.replyTo = messenger;
    outgoing.setData(data);
    try {
        clientMessenger.send(outgoing);
    } catch (android.os.RemoteException e) {
    }
}

From source file:com.jwork.dhammapada.ChapterFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    log.v(this, "onListItemClick(pos:" + position + "|id:" + id);
    Message message = Message.obtain();
    message.what = Constant.WHAT_SELECT_CHAPTER;
    message.obj = v.getTag();//w  w  w. j  a v a2 s  .  com
    controller.executeMessage(message);
}

From source file:pw.dedominic.csc311_final_project.MainActivity.java

/**
 * This function is called after Login View finishes.
 * This function builds the UI views that make up this activity.
 */// w  w  w  .j a  va 2  s.  c om
public void initializeViews() {
    // list view init
    PLAYER_LIST = new ArrayAdapter<String>(this, R.layout.activity_text);
    mListView = (ListView) findViewById(R.id.listView);
    mListView.setAdapter(PLAYER_LIST);
    mListView.setOnItemClickListener(this);

    mTextView = (TextView) findViewById(R.id.textView);

    // map view init
    mMapView = (MapView) findViewById(R.id.mapView);
    mMapView.update_map();

    // get data now
    mHttpGetHandler.handleMessage(Message.obtain());
    mUploadLocation.handleMessage(Message.obtain());

    mBluetoothService = new BluetoothService(mBluetoothListener);
    mBluetoothService.listen();

    mInNodeTimer.handleMessage(Message.obtain());
}

From source file:cn.caimatou.canting.utils.http.asynchttp.AsyncHttpResponseHandler.java

protected Message obtainMessage(int responseMessage, Object response) {
    Message msg = null;//w  w  w .j  a  v  a  2s . c om
    if (handler != null) {
        msg = this.handler.obtainMessage(responseMessage, response);
    } else {
        msg = Message.obtain();
        msg.what = responseMessage;
        msg.obj = response;
    }
    return msg;
}

From source file:com.hfs.materialhome.MainActivity.java

private void initRecyclerView() {
    recyclerView = (RecyclerView) findViewById(R.id.recycler);
    mLayoutManager = new GridLayoutManager(this, 2);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.addOnScrollListener(new OnRecyclerViewScrollListener<ViewModel>() {
        @Override//  www.  j a va2s .  c o m
        public void onStart() {
            mAdapter.setFooterView(R.layout.item_foot);
            if (mAdapter.hasHeader()) {
                recyclerView.smoothScrollToPosition(mAdapter.getItemCount() + 1);
            } else {
                recyclerView.smoothScrollToPosition(mAdapter.getItemCount());
            }
        }

        @Override
        public void onLoadMore() {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Log.e("TAG", "?");
                        Thread.sleep(5000);
                        //onFinish()
                        onFinish(arrayList);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }

        @Override
        public void onFinish(List<ViewModel> contents) {
            Message message = Message.obtain();
            message.obj = contents;
            mHandler.sendMessage(message);
            setLoadingMore(false);
        }
    });

}

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

public void dispatchEvents(String eventName, String eventData) {
    if (this.isPresence()) {
        if (eventName.equalsIgnoreCase("pusher_internal:subscription_succeeded")) {
            JSONArray users = null;/*from w  w w  .j av a  2s  . co  m*/
            try {
                users = new JSONArray(eventData);
            } catch (JSONException e) {
                users = new JSONArray();
                //e.printStackTrace();
            }
            for (int i = 0; i < users.length(); i++) {
                try {
                    JSONObject user = users.getJSONObject(i);
                    String user_id = user.getString("user_id");
                    Map<String, String> user_info_map = new HashMap<String, String>();
                    //user_info_map.put("user_id", user_id);

                    if (user.has("user_info")) {
                        JSONObject user_info_json = user.getJSONObject("user_info");
                        Iterator<String> iter = (Iterator<String>) user_info_json.keys();
                        while (iter.hasNext()) {
                            String key = iter.next();
                            String value;
                            try {
                                value = user_info_json.getString(key);
                                user_info_map.put(key, value);
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
                    this.mLocalUsers.put(user_id, user_info_map);

                } catch (JSONException e) {
                    //e.printStackTrace();
                }
            }
        }
        if (eventName.equalsIgnoreCase("pusher_internal:member_added")) {
            JSONObject user = null;
            try {
                user = new JSONObject(eventData);
                String user_id = user.getString("user_id");
                JSONObject user_info_json = user.getJSONObject("user_info");
                Map<String, String> user_info_map = new HashMap<String, String>();
                //user_info_map.put("user_id", user_id);
                Iterator<String> iter = (Iterator<String>) user_info_json.keys();
                while (iter.hasNext()) {
                    String key = iter.next();
                    String value;
                    try {
                        value = user_info_json.getString(key);
                        user_info_map.put(key, value);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                this.mLocalUsers.put(user_id, user_info_map);
            } catch (JSONException e) {
                //e.printStackTrace();
            }

        }
        if (eventName.equalsIgnoreCase("pusher_internal:member_removed")) {
            JSONObject user = null;
            try {
                user = new JSONObject(eventData);
                this.mLocalUsers.remove(user.getString("user_id"));
            } catch (JSONException e) {
                //e.printStackTrace();
            }
        }
    }

    Bundle payload = new Bundle();
    payload.putString("eventName", eventName);
    payload.putString("eventData", eventData);
    payload.putString("channelName", mName);

    Message msg = Message.obtain();
    msg.setData(payload);

    for (PusherCallback callback : mGlobalCallbacks) {
        callback.sendMessage(msg);
    }

    /* do we have a callback bound to that event? */
    if (mLocalCallbacks.containsKey(eventName)) {
        /* execute each callback */
        for (PusherCallback callback : mLocalCallbacks.get(eventName)) {
            callback.sendMessage(msg);
        }
    }
}