Example usage for android.os Message setData

List of usage examples for android.os Message setData

Introduction

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

Prototype

public void setData(Bundle data) 

Source Link

Document

Sets a Bundle of arbitrary data values.

Usage

From source file:com.nextgis.mobile.map.RemoteTMSLayer.java

protected static void create(final MapBase map, String layerName, String layerUrl, int tmsType) {
    String sErr = map.getContext().getString(R.string.error_occurred);
    try {/*from   ww  w . java 2  s . c o m*/
        File outputPath = map.cretateLayerStorage();
        //create layer description file
        JSONObject oJSONRoot = new JSONObject();
        oJSONRoot.put(JSON_NAME_KEY, layerName);
        oJSONRoot.put(JSON_URL_KEY, layerUrl);
        oJSONRoot.put(JSON_VISIBILITY_KEY, true);
        oJSONRoot.put(JSON_TYPE_KEY, LAYERTYPE_TMS);
        oJSONRoot.put(JSON_TMSTYPE_KEY, tmsType);

        //send message to handler to show error or add new layer

        File file = new File(outputPath, LAYER_CONFIG);
        FileUtil.createDir(outputPath);
        FileUtil.writeToFile(file, oJSONRoot.toString());

        if (map.getMapEventsHandler() != null) {
            Bundle bundle = new Bundle();
            bundle.putBoolean(BUNDLE_HASERROR_KEY, false);
            bundle.putString(BUNDLE_MSG_KEY, map.getContext().getString(R.string.message_layer_added));
            bundle.putInt(BUNDLE_TYPE_KEY, MSGTYPE_LAYER_ADDED);
            bundle.putSerializable(BUNDLE_PATH_KEY, outputPath);

            Message msg = new Message();
            msg.setData(bundle);
            map.getMapEventsHandler().sendMessage(msg);
        }
        return;

    } catch (FileNotFoundException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    } catch (JSONException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    } catch (IOException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    }
    //if we here something wrong occurred
    Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
}

From source file:com.nextgis.mobile.map.LocalGeoJsonLayer.java

protected static void create(final MapBase map, String layerName, List<Feature> features, int layerType)
        throws JSONException, IOException {

    GeoEnvelope extents = new GeoEnvelope();
    for (Feature feature : features) {
        //update bbox
        extents.merge(feature.getGeometry().getEnvelope());
    }//from  w  w  w  . ja  v a2s .  co  m

    Feature feature = features.get(0);
    int geometryType = feature.getGeometry().getType();
    List<Field> fields = feature.getFields();

    //create layer description file
    JSONObject oJSONRoot = new JSONObject();
    oJSONRoot.put(JSON_NAME_KEY, layerName);
    oJSONRoot.put(JSON_VISIBILITY_KEY, true);
    oJSONRoot.put(JSON_TYPE_KEY, layerType);
    oJSONRoot.put(JSON_MAXLEVEL_KEY, 50);
    oJSONRoot.put(JSON_MINLEVEL_KEY, 0);

    //add geometry type
    oJSONRoot.put(JSON_GEOMETRY_TYPE_KEY, geometryType);

    //add bbox
    JSONObject oJSONBBox = extents.toJSON();
    oJSONRoot.put(JSON_BBOX_KEY, oJSONBBox);

    //add fields description
    JSONArray oJSONFields = new JSONArray();
    for (Field field : fields) {
        oJSONFields.put(field.toJSON());
    }
    oJSONRoot.put(JSON_FIELDS_KEY, oJSONFields);

    // store layer description to file
    File outputPath = map.cretateLayerStorage();
    File file = new File(outputPath, LAYER_CONFIG);
    FileUtil.createDir(outputPath);
    FileUtil.writeToFile(file, oJSONRoot.toString());

    //store GeoJson to file
    store(features, outputPath);

    if (map.getMapEventsHandler() != null) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BUNDLE_HASERROR_KEY, false);
        bundle.putString(BUNDLE_MSG_KEY, map.getContext().getString(R.string.message_layer_added));
        bundle.putInt(BUNDLE_TYPE_KEY, MSGTYPE_LAYER_ADDED);
        bundle.putSerializable(BUNDLE_PATH_KEY, outputPath);

        Message msg = new Message();
        msg.setData(bundle);
        map.getMapEventsHandler().sendMessage(msg);
    }
}

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  www.j  a  v a2 s . c o m*/
    outgoing.replyTo = messenger;
    outgoing.setData(data);
    try {
        clientMessenger.send(outgoing);
    } catch (android.os.RemoteException e) {
    }
}

From source file:applab.search.client.JsonSimpleParser.java

/**
 * Call this each time to increment the progress bar by one level
 *//*from w  w w .j av  a  2s.co m*/
static void incrementProgressLevel() {
    Message message = progressHandler.obtainMessage();
    bundle.putInt("node", ++progressLevel);
    Log.d(LOG_TAG, "Processed : " + progressLevel + " of " + nodeCount);
    message.setData(bundle);
    progressHandler.sendMessage(message);
}

From source file:thproject.test.com.myapplication.SongRecognitionActivity.java

public static void exitSongRecognition() {
    Message msg = new Message();
    Bundle data = new Bundle();
    data.putString("action", "exit");
    msg.setData(data);
    handler.sendMessage(msg);/*from   www .j a v  a  2 s  . c  om*/
}

From source file:thproject.test.com.myapplication.SongRecognitionActivity.java

public static void startAlbumDialog() {
    Message msg = new Message();
    Bundle data = new Bundle();
    data.putString("action", "albums");
    msg.setData(data);
    handler.sendMessage(msg);/*  w w  w. j  av a  2s  .  co  m*/
}

From source file:thproject.test.com.myapplication.SongRecognitionActivity.java

public static void signalTrackScraping(List<String> a) {
    selectedTracks = a;// w  w w . j  a  v  a 2  s .  c  o m
    Message msg = new Message();
    Bundle data = new Bundle();
    data.putString("action", "scrape");
    msg.setData(data);
    handler.sendMessage(msg);
}

From source file:thproject.test.com.myapplication.SongRecognitionActivity.java

public static void showProgress() {
    Message msg = new Message();
    Bundle data = new Bundle();
    data.putString("action", "showprogress");
    msg.setData(data);
    handler.sendMessage(msg);/*  www  . ja v  a  2s . co m*/
}

From source file:thproject.test.com.myapplication.SongRecognitionActivity.java

public static void stopProgress() {
    Message msg = new Message();
    Bundle data = new Bundle();
    data.putString("action", "stopprogress");
    msg.setData(data);
    handler.sendMessage(msg);//w  w  w  .j  av a2 s.c  o  m

}

From source file:thproject.test.com.myapplication.SongRecognitionActivity.java

public static void startTracksDialog(int a) {
    Message msg = new Message();
    Bundle data = new Bundle();
    data.putString("action", "tracks");
    data.putInt("albumIndex", a);
    msg.setData(data);
    handler.sendMessage(msg);//from w  w w  . ja va2 s .c om
}