Author Topic: [DEV] - (DEPRECATED) show points on map  (Read 7274 times)

Offline menion

  • Administrator
  • Professor of Locus
  • *****
  • Posts: 9860
  • Thanked: 43 times
    • View Profile
    • http://www.asamm.com
  • Device: SGS7
[DEV] - (DEPRECATED) show points on map
« on: November 16, 2010, 07:14:40 »
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)

Code: [Select]
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]
      « Last Edit: January 01, 1970, 01:00:00 by Guest »
      Ideas, wishes, problems
      Advanced topics, public discussion, sharing of knowledges, testing beta versions: you're here!
       

      Offline menion

      • Administrator
      • Professor of Locus
      • *****
      • Posts: 9860
      • Thanked: 43 times
        • View Profile
        • http://www.asamm.com
      • Device: SGS7
      [DEV] - is Locus instaled?
      « Reply #1 on: December 09, 2010, 13:59:20 »
      Simple method is to check, if Locus allowed to handle points and is in system ...

      use this
      Code: [Select]
      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;
          }
      }
      « Last Edit: January 01, 1970, 01:00:00 by Guest »
      Ideas, wishes, problems
      Advanced topics, public discussion, sharing of knowledges, testing beta versions: you're here!
       

      Offline cborlasa78

      • Newbie
      • *
      • Posts: 5
        • View Profile
      Re: [DEV] - show points on map (updated 19.4.2011)
      « Reply #2 on: June 18, 2011, 04:47:02 »
      simple methods are very good. so that everyone can comprehend easliy
      « Last Edit: January 01, 1970, 01:00:00 by Guest »
      <a href="http://badabingbaby.com/">USB flash drives</a>
       

      Offline evanjones246

      • Newbie
      • *
      • Posts: 1
        • View Profile
      Re: [DEV] - is Locus instaled?
      « Reply #3 on: March 12, 2012, 20:34:56 »
      +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
      Code: [Select]
      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
      « Last Edit: March 17, 2012, 01:27:33 by evanjones246 »
       

      Offline menion

      • Administrator
      • Professor of Locus
      • *****
      • Posts: 9860
      • Thanked: 43 times
        • View Profile
        • http://www.asamm.com
      • Device: SGS7
      Re: [DEV] - (DEPRECATED) show points on map
      « Reply #4 on: March 13, 2012, 08:04:14 »
      hi,
        if you wanna use such features, I highly recommend use Locus API which already include this feature and much more ...
      « Last Edit: January 01, 1970, 01:00:00 by Guest »
      Ideas, wishes, problems
      Advanced topics, public discussion, sharing of knowledges, testing beta versions: you're here!