[DEV] - (DEPRECATED) show points on map

Started by Menion, November 16, 2010, 07:14:40

0 Members and 7 Guests are viewing this topic.

Menion

Simple solution for using Locus as external viewer of points from other applications!

6.7.2011 - This method is DEPRECATED - use new API instead - viewtopic.php?f=29&t=767

[s:ounfezv9]19.4.2011 - New update of calling method - version 2

working for version >= 1.5.3

simple code example says more then few pages of words (use commentary as helping solution)

private void callLocus() {
ByteArrayOutputStream baos = null;
DataOutputStream dos = null;
try {
   baos = new ByteArrayOutputStream();
   dos = new DataOutputStream(baos);

   // version
   dos.writeInt(2);

   // write objects names
   dos.writeUTF("Points from my application");
   
   // write category count - here I write three categories. Categories are defined as
                    // array of points that share same map icon!
   dos.writeInt(3);
   
   // write categories
   writeCategory(dos);
   writeCategory(dos);
   writeCategory(dos);
   
   // flush data to output stream
   dos.flush();
   
   // create intent with right calling method
   Intent intent = new Intent();
   intent.setAction(Intent.ACTION_VIEW);
   intent.setData(Uri.parse("menion.points:extraDataSomeName"));
 
   // here put data into intent
   intent.putExtra("extraDataSomeName", baos.toByteArray());

   // finally start activity
   startActivity(intent);
} catch (Exception e) {
   Log.e(TAG, "callLocus()", e);
} finally {
try {
if (baos != null) {
baos.close();
baos = null;
}
if (dos != null) {
dos .close();
dos = null;
}
} catch (Exception e) {
// catch not needed
}
}
}

private void writeCategory(DataOutputStream dos) {
try {
// convert resource to byte array
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_gc_wherigo);
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
byte[] image = baos2.toByteArray();
baos2.close();

// write image data or size '0' and no data if use default image of Locus (currently just red dot)
                       - so if you want write image use this
                        dos.writeInt(image.length); // image size
dos.write(image); // image data
                        - and if you don't want use only this
                        dos.writeInt(0);

// write all points now
int pointCount = 1000;
dos.writeInt(pointCount);
for (int i = 0; i < pointCount; i++) {
// write item name
dos.writeUTF("name_" + (i + 1));
// write item description
dos.writeUTF("some description with <html>tags</html>!");
// extra values (describe below - optional)
dos.writeUTF("");
// write latitude
dos.writeDouble(50.0 + 0.01 * i);
// write longitude
dos.writeDouble(14.0 + 0.01 * i);
}
} catch (Exception e) {
   Log.e(TAG, "writeCategory()", e);
}
}

Extra values written in code can be used for extending possibilities which user can do with point

currently supported:
    Call-back - "intent;ButtonName;com.super.application;com.super.application.Main;returnData;someStringData"
      intent - just identifier
        ButtonName - String that shows on button
        com.super.application - The name of the package that the component exists in
        com.super.application.Main - The name of the class inside of com.super.application that implements the component.
        returnData - String uder which data will be stored. Can be retrieved by String data = getIntent.getStringExtra("returnData");
        someStringData - data stored in intent at returnData StringExtra place
      [/list]
      [/list]

      Actual application that use this feature
      c:geo[/s:ounfezv9]
      - Official help (ideas, questions, problems): help.locusmap.eu
      - Advanced topics, sharing of knowledges: you're here!
      - LM 4 Beta download, LM 4 Release download
      •  

      Menion

      #1
      Simple method is to check, if Locus allowed to handle points and is in system ...

      use this
      public static boolean isLocusAvailable(Activity activity) {
          try {
              // set intent
              final PackageManager packageManager = activity.getPackageManager();
              final Intent intent = new Intent(Intent.ACTION_VIEW);
              intent.setData(Uri.parse("menion.points:x"));

              // return true or false
              return packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
          } catch (Exception e) {
              return false;
          }
      }
      - Official help (ideas, questions, problems): help.locusmap.eu
      - Advanced topics, sharing of knowledges: you're here!
      - LM 4 Beta download, LM 4 Release download
      •  

      cborlasa78

      #2
      simple methods are very good. so that everyone can comprehend easliy
      <a href="http://badabingbaby.com/">USB flash drives</a>
      •  

      evanjones246

      #3
      +1... I just tried this and it worked perfectly. thanks for sharing this very helpful information. :)
      Quote from: "menion"Simple method is to check, if Locus allowed to handle points and is in system ...

      use this
      public static boolean isLocusAvailable(Activity activity) {
          try {
              // set intent
              final PackageManager packageManager = activity.getPackageManager();
              final Intent intent = new Intent(Intent.ACTION_VIEW);
              intent.setData(Uri.parse("menion.points:x"));

              // return true or false
              return packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
          } catch (Exception e) {
              return false;
          }
      }
      Las Vegas Show Guide Vegas Shows
      •  

      Menion

      #4
      hi,
        if you wanna use such features, I highly recommend use Locus API which already include this feature and much more ...
      - Official help (ideas, questions, problems): help.locusmap.eu
      - Advanced topics, sharing of knowledges: you're here!
      - LM 4 Beta download, LM 4 Release download
      •