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(Handler h, int what, Object obj) 

Source Link

Document

Same as #obtain() , but sets the values of the target, what, and obj members.

Usage

From source file:com.android.example.notificationlistener.Listener.java

@Override
public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap) {
    Message.obtain(mHandler, MSG_CANCEL, new Delta(sbn, rankingMap)).sendToTarget();
}

From source file:com.adampmarshall.speedo.LocationActivity.java

private void updateUILocation(Location location) {
    // We're sending the update to a handler which then updates the UI with
    // the new//  w w w  .  ja v  a  2  s  . c om
    // location.
    Message.obtain(mHandler, UPDATE_SPEED, Math.round(location.getSpeed() * 3.6) + "").sendToTarget();

}

From source file:org.unchiujar.umbra2.services.LocationService.java

private void sendLocation(Location location) {
    LOGGER.debug("Location changed: {}", location);
    for (int i = mClients.size() - 1; i >= 0; i--) {

        try {//www. j ava2  s . com
            // Send data as an Integer
            mClients.get(i).send(Message.obtain(null, MSG_LOCATION_CHANGED, location));

        } catch (RemoteException e) {
            // The client is dead. Remove it from the list; we are going
            // through the list from
            // back to front so this is safe to do inside the loop.
            mClients.remove(i);
        }
    }

    Message message = Message.obtain();
    message.obj = location;

    try {
        mMessenger.send(message);
    } catch (RemoteException e) {
        LOGGER.error("Error sending location", e);
    }

}

From source file:com.sorin.cloudcog.xivelypull.LocationActivity.java

private void updateUILocation(Location location) {
    // We're sending the update to a handler which then updates the UI with
    // the new/*from  w  w w.  j ava  2  s  .c o  m*/
    // location.
    Message.obtain(mHandler, UPDATE_LATLNG, location.getLatitude() + ", " + location.getLongitude())
            .sendToTarget();

    // Bypass reverse-geocoding only if the Geocoder service is available on
    // the device.
    if (mGeocoderAvailable)
        doReverseGeocoding(location);
}

From source file:com.chess.genesis.net.NetworkClient.java

private boolean relogin() {
    if (socket.getIsLoggedIn())
        return true;

    final Pref pref = new Pref(context);
    final String username = pref.getString(R.array.pf_username);
    final String password = pref.getString(R.array.pf_passhash);

    JSONObject json = new JSONObject();

    try {/*from w w  w.  j av  a 2 s  . c o m*/
        try {
            json.put(_REQUEST, _LOGIN);
            json.put(_USERNAME, username);
            json.put(_PASSHASH, Crypto.LoginKey(socket, password));
        } catch (final JSONException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    } catch (final SocketException e) {
        try {
            json.put(_RESULT, _ERROR);
            json.put(_REASON, CANT_CONTACT_MSG);
            socket.logError(context, e, json);
        } catch (final JSONException j) {
            throw new RuntimeException(j.getMessage(), j);
        }
        error = true;
    } catch (final IOException e) {
        try {
            json.put(_RESULT, _ERROR);
            json.put(_REASON, LOST_CONNECTION_MSG);
            socket.logError(context, e, request);
        } catch (final JSONException j) {
            throw new RuntimeException(j.getMessage(), j);
        }
        error = true;
    }
    if (error) {
        callback.sendMessage(Message.obtain(callback, fid, json));
        return false;
    }

    // Send login request
    json = send_request(json);

    try {
        if (!json.getString(_RESULT).equals(_OK)) {
            callback.sendMessage(Message.obtain(callback, fid, json));
            return false;
        }
        socket.setIsLoggedIn(true);
        return true;
    } catch (final JSONException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:eu.andlabs.studiolounge.gcp.GCPService.java

private void dispatchMessage(int what, Object thing) {
    try {//from w  w  w.  j a  v  a2s .  c  om
        mApp.send(Message.obtain(mHandler, what, thing));
    } catch (RemoteException e) {
        log("Error: " + e.toString());
    }
}

From source file:com.uproot.trackme.LocationActivity.java

private void updateUILocation(Location location) {
    // We're sending the update to a handler which then updates the UI with
    // the new//from w ww. j  av  a2s. c o  m
    // location.
    Message.obtain(mHandler, UPDATE_LATLNG, location.getLatitude() + ", " + location.getLongitude())
            .sendToTarget();

    // Bypass reverse-geocoding only if the Geocoder service is available on
    // the device.
    if (mGeocoderAvailable)
        doReverseGeocoding(location);

}

From source file:com.chess.genesis.net.NetworkClient.java

@Override
public synchronized void run() {
    if (fid == LOGIN)
        login_setup();//from   w  ww.  j a  v  a  2s  .  c  om

    if (error || (loginRequired && !relogin())) {
        error = false;
        socket.disconnect();
        return;
    }

    final JSONObject json = send_request(request);
    if (error) {
        error = false;
        socket.disconnect();
    }

    callback.sendMessage(Message.obtain(callback, fid, json));
}

From source file:vit.riviera.LocationActivity.java

private void updateUILocation(Location location) {
    // We're sending the update to a handler which then updates the UI with the new
    // location./*from  w  w  w  . jav  a  2s.  c om*/
    Message.obtain(mHandler, UPDATE_LATLNG, location.getLatitude() + ", " + location.getLongitude())
            .sendToTarget();

    lati = Double.toString(location.getLatitude());
    longi = Double.toString(location.getLongitude());
    System.out.println(lati);
    System.out.println(longi);
    System.out.println("a");

    // Bypass reverse-geocoding only if the Geocoder service is available on the device.
    if (mGeocoderAvailable)
        doReverseGeocoding(location);
}

From source file:net.gaast.giggity.ScheduleViewActivity.java

private void loadScheduleAsync(final String url, final Fetcher.Source source) {
    final LoadProgress prog = new LoadProgress(this, true);
    prog.setDone(new LoadProgressDoneInterface() {
        @Override//from  w ww.j a  v a2  s  . c o  m
        public void done() {
            onScheduleLoaded();
        }
    });
    prog.show();

    Thread loader = new Thread() {
        @Override
        public void run() {
            try {
                sched = app.getSchedule(url, source, prog.getHandler());
                prog.getHandler().sendEmptyMessage(LoadProgress.DONE);
            } catch (Throwable t) {
                t.printStackTrace();
                prog.getHandler().sendMessage(Message.obtain(prog.getHandler(), 0, t));
            }
        }
    };

    loader.start();
}