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:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void publishCityBBS(final String typeId, final String city, final String longtitude,
        final String latitede, final String title, final String content, final String pics, final String sound,
        final String address) {
    new Thread() {
        Message msg = Message.obtain();

        @Override// w ww .  j a  v  a  2  s.co  m
        public void run() {
            String data = "&userid=" + user.getUserId() + "&phone=" + user.getUserPhone() + "&typeid=" + typeId
                    + "&city=" + city + "&longitude=" + longtitude + "&latitude=" + latitede + "&title=" + title
                    + "&content=" + content + "&picurl=" + pics + "&sound=" + sound + "&address=" + address;
            String result_data = NetUtil.getResponse(PUBLISH_CITY_BBS, data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.PUBLISH_CITY_BBS;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void activityRegister(final String id, final String content) {
    new Thread() {
        Message msg = Message.obtain();

        @Override/* ww  w  .  jav  a2  s.  co  m*/
        public void run() {
            String data = "&userid=" + user.getUserId() + "&id=" + id + "&content=" + content;
            String result_data = NetUtil.getResponse(ACTIVITY_REGISTER, data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.ACTIVITY_REGISTER;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void checkRegisterActivity(final String id) {
    new Thread() {
        Message msg = Message.obtain();

        @Override/*w  w w  . j a  v a2  s  .c  om*/
        public void run() {
            String data = "&userid=" + user.getUserId() + "&id=" + id;
            String result_data = NetUtil.getResponse(CHECK_ACTIVITY_REGISTER, data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.CHECK_ACTIVITY_REGISTER;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:cgeo.geocaching.cgeocaches.java

@Override
public Loader<SearchResult> onCreateLoader(int type, Bundle extras) {
    if (type >= CacheListLoaderType.values().length) {
        throw new IllegalArgumentException("invalid loader type " + type);
    }//from   w  w  w.  jav a  2 s.  c  o  m
    CacheListLoaderType enumType = CacheListLoaderType.values()[type];
    AbstractSearchLoader loader = null;
    switch (enumType) {
    case OFFLINE:
        listId = Settings.getLastList();
        if (listId <= StoredList.TEMPORARY_LIST_ID) {
            listId = StoredList.STANDARD_LIST_ID;
            title = res.getString(R.string.stored_caches_button);
        } else {
            final StoredList list = cgData.getList(listId);
            // list.id may be different if listId was not valid
            listId = list.id;
            title = list.title;
        }

        loader = new OfflineGeocacheListLoader(this.getBaseContext(), coords, listId);

        break;
    case HISTORY:
        title = res.getString(R.string.caches_history);
        loader = new HistoryGeocacheListLoader(app, coords);
        break;
    case NEAREST:
        title = res.getString(R.string.caches_nearby);
        loader = new CoordsGeocacheListLoader(app, coords);
        break;
    case COORDINATE:
        title = coords.toString();
        loader = new CoordsGeocacheListLoader(app, coords);
        break;
    case KEYWORD:
        final String keyword = extras.getString(Intents.EXTRA_KEYWORD);
        title = keyword;
        loader = new KeywordGeocacheListLoader(app, keyword);
        break;
    case ADDRESS:
        final String address = extras.getString(Intents.EXTRA_ADDRESS);
        if (StringUtils.isNotBlank(address)) {
            title = address;
        } else {
            title = coords.toString();
        }
        if (coords != null) {
            loader = new CoordsGeocacheListLoader(app, coords);
        } else {
            loader = new AddressGeocacheListLoader(app, address);
        }
        break;
    case USERNAME:
        final String username = extras.getString(Intents.EXTRA_USERNAME);
        title = username;
        loader = new UsernameGeocacheListLoader(app, username);
        break;
    case OWNER:
        final String ownerName = extras.getString(Intents.EXTRA_USERNAME);
        title = ownerName;
        loader = new OwnerGeocacheListLoader(app, ownerName);
        break;
    case MAP:
        //TODO Build Nullloader
        title = res.getString(R.string.map_map);
        search = (SearchResult) extras.get(Intents.EXTRA_SEARCH);
        replaceCacheListFromSearch();
        loadCachesHandler.sendMessage(Message.obtain());
        break;
    case REMOVE_FROM_HISTORY:
        title = res.getString(R.string.caches_history);
        loader = new RemoveFromHistoryLoader(app, extras.getStringArray(Intents.EXTRA_CACHELIST), coords);
        break;
    case NEXT_PAGE:
        loader = new NextPageGeocacheListLoader(app, search);
        break;
    }
    setTitle(title);
    showProgress(true);
    showFooterLoadingCaches();

    if (loader != null) {
        loader.setRecaptchaHandler(new SearchHandler(this, res, loader));
    }
    return loader;
}

From source file:com.ape.camera2raw.Camera2RawFragment.java

/**
 * Shows a {@link Toast} on the UI thread.
 *
 * @param text The message to show.// ww w  . ja v a 2s  .  c om
 */
private void showToast(String text) {
    // We show a Toast by sending request message to mMessageHandler. This makes sure that the
    // Toast is shown on the UI thread.
    Message message = Message.obtain();
    message.obj = text;
    mMessageHandler.sendMessage(message);
}

From source file:cgeo.geocaching.CacheListActivity.java

@Override
public Loader<SearchResult> onCreateLoader(final int type, final Bundle extras) {
    if (type >= CacheListLoaderType.values().length) {
        throw new IllegalArgumentException("invalid loader type " + type);
    }/*from  w  w w.  j  ava2  s.  c  o m*/
    final CacheListLoaderType enumType = CacheListLoaderType.values()[type];
    AbstractSearchLoader loader = null;
    switch (enumType) {
    case OFFLINE:
        // open either the requested or the last list
        if (extras.containsKey(Intents.EXTRA_LIST_ID)) {
            listId = extras.getInt(Intents.EXTRA_LIST_ID);
        } else {
            listId = Settings.getLastDisplayedList();
        }
        if (listId == PseudoList.ALL_LIST.id) {
            title = res.getString(R.string.list_all_lists);
        } else if (listId <= StoredList.TEMPORARY_LIST.id) {
            listId = StoredList.STANDARD_LIST_ID;
            title = res.getString(R.string.stored_caches_button);
        } else {
            final StoredList list = DataStore.getList(listId);
            // list.id may be different if listId was not valid
            if (list.id != listId) {
                showToast(getString(R.string.list_not_available));
            }
            listId = list.id;
            title = list.title;
        }

        loader = new OfflineGeocacheListLoader(this, coords, listId);

        break;
    case HISTORY:
        title = res.getString(R.string.caches_history);
        listId = PseudoList.HISTORY_LIST.id;
        loader = new HistoryGeocacheListLoader(this, coords);
        break;
    case NEAREST:
        title = res.getString(R.string.caches_nearby);
        loader = new CoordsGeocacheListLoader(this, coords);
        break;
    case COORDINATE:
        title = coords.toString();
        loader = new CoordsGeocacheListLoader(this, coords);
        break;
    case KEYWORD:
        final String keyword = extras.getString(Intents.EXTRA_KEYWORD);
        title = listNameMemento.rememberTerm(keyword);
        if (keyword != null) {
            loader = new KeywordGeocacheListLoader(this, keyword);
        }
        break;
    case ADDRESS:
        final String address = extras.getString(Intents.EXTRA_ADDRESS);
        if (StringUtils.isNotBlank(address)) {
            title = listNameMemento.rememberTerm(address);
        } else {
            title = coords.toString();
        }
        loader = new CoordsGeocacheListLoader(this, coords);
        break;
    case FINDER:
        final String username = extras.getString(Intents.EXTRA_USERNAME);
        title = listNameMemento.rememberTerm(username);
        if (username != null) {
            loader = new FinderGeocacheListLoader(this, username);
        }
        break;
    case OWNER:
        final String ownerName = extras.getString(Intents.EXTRA_USERNAME);
        title = listNameMemento.rememberTerm(ownerName);
        if (ownerName != null) {
            loader = new OwnerGeocacheListLoader(this, ownerName);
        }
        break;
    case MAP:
        //TODO Build Null loader
        title = res.getString(R.string.map_map);
        search = (SearchResult) extras.get(Intents.EXTRA_SEARCH);
        replaceCacheListFromSearch();
        loadCachesHandler.sendMessage(Message.obtain());
        break;
    case NEXT_PAGE:
        loader = new NextPageGeocacheListLoader(this, search);
        break;
    case POCKET:
        final String guid = extras.getString(Intents.EXTRA_POCKET_GUID);
        title = listNameMemento.rememberTerm(extras.getString(Intents.EXTRA_NAME));
        loader = new PocketGeocacheListLoader(this, guid);
        break;
    }
    // if there is a title given in the activity start request, use this one instead of the default
    if (extras != null && StringUtils.isNotBlank(extras.getString(Intents.EXTRA_TITLE))) {
        title = extras.getString(Intents.EXTRA_TITLE);
    }
    if (loader != null && extras != null && extras.getSerializable(BUNDLE_ACTION_KEY) != null) {
        final AfterLoadAction action = (AfterLoadAction) extras.getSerializable(BUNDLE_ACTION_KEY);
        loader.setAfterLoadAction(action);
    }
    updateTitle();
    showProgress(true);
    showFooterLoadingCaches();

    return loader;
}

From source file:jmri.enginedriver.threaded_application.java

public boolean sendMsgDelay(Handler h, long delayMs, int msgType, String msgBody, int msgArg1, int msgArg2) {
    boolean sent = false;
    if (h != null) {
        Message msg = Message.obtain();
        msg.what = msgType;// www.jav a2 s  .  c om
        msg.obj = new String(msgBody);
        msg.arg1 = msgArg1;
        msg.arg2 = msgArg2;
        try {
            sent = h.sendMessageDelayed(msg, delayMs);
        } catch (Exception e) {
        }
        if (!sent)
            msg.recycle();
    }
    return sent;
}