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:com.taobao.weex.bridge.WXBridgeManager.java

void setTimeout(String callbackId, String time) {
    Message message = Message.obtain();
    message.what = WXJSBridgeMsgType.SET_TIMEOUT;
    TimerInfo timerInfo = new TimerInfo();
    timerInfo.callbackId = callbackId;//from  w w w  .  ja v a 2  s .c om
    timerInfo.time = (long) Float.parseFloat(time);
    message.obj = timerInfo;

    mJSHandler.sendMessageDelayed(message, timerInfo.time);
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossDeviceListFragment.java

public void Refresh() {
    try {//w  ww.j  a  v  a  2s  .  c  om
        if (null != dialog) {
            dialog.setTitle("Contacting Zenoss...");
            dialog.setMessage("Please wait:\nLoading Infrastructure....");
            //TODO make cancelable
            dialog.setCancelable(true);

            if (!dialog.isShowing()) {
                dialog.show();
            }
        } else {
            dialog = new ProgressDialog(getActivity());
            dialog.setTitle("Contacting Zenoss...");
            dialog.setMessage("Please wait:\nLoading Infrastructure....");
            dialog.setCancelable(false);
            dialog.show();
        }
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListFragment", "Refresh", e);
    }

    if (listOfDevices != null)
        listOfDevices.clear();

    ((Thread) new Thread() {
        public void run() {
            String MessageExtra = "";
            try {
                Message msg = new Message();
                Bundle bundle = new Bundle();

                /*ZenossAPI API = null;
                SharedPreferences settings = null;
                settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
                try
                {
                API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""));
                        
                }
                catch(ConnectTimeoutException cte)
                {
                if(cte.getMessage() != null)
                {
                        
                    bundle.putString("exception","The connection timed out;\r\n" + cte.getMessage().toString());
                    msg.setData(bundle);
                    msg.what = 0;
                    handler.sendMessage(msg);
                    //Toast.makeText(DeviceList.this, "The connection timed out;\r\n" + cte.getMessage().toString(), Toast.LENGTH_LONG).show();
                }
                else
                {
                    bundle.putString("exception","A time out error was encountered but the exception thrown contains no further information.");
                    msg.setData(bundle);
                    msg.what = 0;
                    handler.sendMessage(msg);
                    //Toast.makeText(DeviceList.this, "A time out error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                }
                }
                catch(Exception e)
                {
                if(e.getMessage() != null)
                {
                    bundle.putString("exception","An error was encountered;\r\n" + e.getMessage().toString());
                    msg.setData(bundle);
                    msg.what = 0;
                    handler.sendMessage(msg);
                    //Toast.makeText(DeviceList.this, "An error was encountered;\r\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show();
                }
                else
                {
                    bundle.putString("exception","An error was encountered but the exception thrown contains no further information.");
                    msg.setData(bundle);
                    msg.what = 0;
                    handler.sendMessage(msg);
                    //Toast.makeText(DeviceList.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                }
                }*/

                if (null == mService || !mBound) {
                    //Log.e("Refresh","Service was dead or something so sleeping");
                    try {
                        sleep(500);
                    } catch (Exception e) {
                        BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListFragment",
                                "RefreshThreadSleep", e);
                    }
                }

                if (null == mService || !mBound) {
                    bundle.putString("exception",
                            "There was an error binding to the Rhybudd internal service to query the API. Try pressing refresh.");
                    msg.setData(bundle);
                    msg.what = 0;
                    handler.sendMessage(msg);
                } else {
                    try {

                        if (null == mService.API) {
                            mService.PrepAPI(true, true);
                        }

                        ZenossCredentials credentials = new ZenossCredentials(getActivity());

                        if (mService.API.Login(credentials)) {
                            listOfDevices = mService.API.GetRhybuddDevices();
                        }

                        /*if(API != null)
                        {
                        listOfDevices = API.GetRhybuddDevices();
                        }*/
                        else {
                            listOfDevices = null;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        if (e.getMessage() != null)
                            MessageExtra = e.getMessage();

                        listOfDevices = null;
                    }

                    if (null != listOfDevices && listOfDevices.size() > 0) {
                        PopulateMetaLists();

                        //DeviceCount = listOfZenossDevices.size();
                        Message.obtain();
                        handler.sendEmptyMessage(1);

                        RhybuddDataSource datasource = new RhybuddDataSource(getActivity());
                        datasource.open();
                        datasource.UpdateRhybuddDevices(listOfDevices);
                        datasource.close();
                    } else {
                        //Message msg = new Message();
                        //Bundle bundle = new Bundle();
                        bundle.putString("exception",
                                "A query to both the local DB and Zenoss API returned no devices. "
                                        + MessageExtra);
                        msg.setData(bundle);
                        msg.what = 0;
                        handler.sendMessage(msg);
                    }

                }
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListFragment", "DBGetThread", e);
                //BugSenseHandler.log("DeviceList", e);
                Message msg = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("exception", e.getMessage());
                msg.setData(bundle);
                msg.what = 0;
                handler.sendMessage(msg);
            }
        }
    }).start();
}

From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java

/**
 * Check the keep alive timeout.// www .j  a  va  2  s  .  com
 * If we reached the timeout, we can assume, that we lost the connection
 */
private void checkKeepAlive() {
    if (mLastKeepAlive > 0 && (System.currentTimeMillis() - mLastKeepAlive) > KEEP_ALIVE_TIMEOUT) {
        // Check if we shall reconnect
        while (mLeftReconnects > 0) {
            closeSocket();
            if (super.createConnection(mRequestConnect)) {
                mLeftReconnects = MAX_RECONNECTS;
                break;
            }

            mLeftReconnects--;
        }

        // We tried, but the server isn't there anymore
        if (mLeftReconnects == 0) {
            Message msg = Message.obtain();
            msg.obj = new ClementineMessage(ErrorMessage.KEEP_ALIVE_TIMEOUT);
            msg.arg1 = PROCESS_PROTOC;
            mHandler.sendMessage(msg);
        }
    }
}

From source file:tw.jwzhuang.ipcamviewer.devices.CaptureActivity.java

private void add(final String contents) {

    try {//  w  ww . j  a v a  2 s .  c  o  m
        JSONObject jobj = new JSONObject(contents);
        Bundle data = new Bundle();
        data.putString("pwd", jobj.getString("pwd"));
        data.putString("ip", jobj.getString("ip"));

        Message message = Message.obtain();
        message.what = handler.ASKADD;
        message.setData(data);

        handler.sendMessage(message);
    } catch (JSONException e) {
        restartPreviewAfterDelay(0L);
    }
}

From source file:de.mrapp.android.util.multithreading.AbstractDataBinder.java

/**
 * Asynchronously executes a specific task in order to load data and to display it afterwards.
 *
 * @param task/*from   w  ww  . j  av  a 2  s . com*/
 *         The task, which should be executed, as an instance of the class {@link Task}. The
 *         task may not be null
 */
private void loadDataAsynchronously(@NonNull final Task<DataType, KeyType, ViewType, ParamType> task) {
    threadPool.submit(new Runnable() {

        @Override
        public void run() {
            if (!isCanceled()) {
                while (!notifyOnLoad(task.key, task.params)) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        break;
                    }
                }

                task.result = loadData(task);
                Message message = Message.obtain();
                message.obj = task;
                sendMessage(message);
            }
        }

    });
}

From source file:org.lytsing.android.weibo.ui.TimelineActivity.java

private void loadMoreData(final long maxId) {
    StatusesAPI statusAPI = new StatusesAPI(mAccessToken);
    statusAPI.friendsTimeline(0, maxId, PER_REQUEST_COUNT, 1, false, StatusesAPI.FEATURE_ALL, false,
            new RequestListener() {

                @Override//  w  ww. j  ava 2 s.  co m
                public void onComplete(String result) {
                    try {
                        Message msg = Message.obtain();
                        if (TextUtils.isEmpty(result) || result.contains("error_code")) {
                            msg.what = ERROR_CODE_RESPONSE;
                            JSONObject obj = new JSONObject(result);
                            msg.obj = obj.getString("error");
                        } else {
                            msg.what = ON_SUCC_RESPONSE;
                            Gson gson = new Gson();
                            WeiboObject response = gson.fromJson(result, WeiboObject.class);

                            for (Statuses status : response.statuses) {
                                mAdapter.addStatuses(status);
                                mMaxId = status.id - 1;
                            }

                            if (maxId == 0 && response.statuses.size() > 0) {
                                mSinceId = response.statuses.get(0).id;
                            }
                        }

                        mHandler.sendMessage(msg);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onWeiboException(final WeiboException e) {
                    Message msg = Message.obtain();
                    msg.what = ON_ERROR_RESPONSE;
                    msg.obj = e.getMessage();

                    mHandler.sendMessage(msg);
                }
            });
}

From source file:com.darshancomputing.BatteryIndicatorPro.CurrentInfoFragment.java

private void setDisableLocking(boolean b) {
    SharedPreferences.Editor editor = activity.sp_store.edit();
    editor.putBoolean(BatteryInfoService.KEY_DISABLE_LOCKING, b);
    editor.commit();//from   w  w  w .j a  v a2s.  c o m

    Message outgoing = Message.obtain();
    outgoing.what = BatteryInfoService.RemoteConnection.SERVICE_RELOAD_SETTINGS;
    try {
        serviceMessenger.send(outgoing);
    } catch (android.os.RemoteException e) {
    }

    updateLockscreenButton();

    if (activity.settings.getBoolean(SettingsActivity.KEY_FINISH_AFTER_TOGGLE_LOCK, false))
        activity.finish();
}

From source file:pl.poznan.put.cs.ify.app.MainActivity.java

public void login(String login, String passwd) {
    if (mService != null) {
        Message msg = Message.obtain();
        Bundle b = new Bundle();
        msg.what = ServiceHandler.REQUEST_LOGIN;
        b.putString(ServiceHandler.LOGIN, login);
        b.putString(ServiceHandler.PASSWD, passwd);
        msg.setData(b);//ww  w.j  a v  a 2 s. c o m
        try {
            mService.send(msg);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}

From source file:de.qspool.clementineremote.ui.fragments.GlobalSearchFragment.java

private void addSongsToPlaylist(LinkedList<SongSelectItem> l) {
    Message msg = Message.obtain();
    LinkedList<ClementineRemoteProtocolBuffer.SongMetadata> songs = new LinkedList<>();
    for (SongSelectItem item : l) {
        songs.add(GlobalSearchManager.getInstance().getRequest().getSongFromUrl(item.getUrl()));
    }/*from  www  . jav  a 2  s  .c om*/

    msg.obj = ClementineMessageFactory
            .buildInsertSongs(App.Clementine.getPlaylistManager().getActivePlaylistId(), songs);

    App.ClementineConnection.mHandler.sendMessage(msg);

    String text = getActivity().getResources().getQuantityString(R.plurals.songs_added, songs.size(),
            songs.size());
    Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
}

From source file:pl.poznan.put.cs.ify.app.MainActivity.java

public void logout() {
    Message msg = Message.obtain();
    Bundle b = new Bundle();
    msg.what = ServiceHandler.REQUEST_LOGOUT;
    try {/*from w ww  .j a  v  a 2 s .  c  o  m*/
        mService.send(msg);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}