Categories
discuss

Does jFreeChart work/comple in Android 2.x

Does jFreeChart compile and run in Android 2.2 or above? I tried to run it and received missing swing class errors. There does not seem to be any definitive answer on the web. The answer to this question is either 1) Yes, I use it all the time, here are the steps or 2) No, It doesn’t work because _.

I just want to put this issue to rest and get a definitive answer. So please don’t suggest other chart packages.

Thanks

Fish

Answer

JFreeChart will not compile/run in Android as is because it relies on swing packages. Swing components are not used by Android, and not included in Android’s version of Java.

Categories
discuss

SMS URL on Android

I was wanting to know if Android had a similar feature to the iPhone in that you can use an HTML A tag to send an SMS by setting the HREF attribute to the phone number you want to send the message to and prefixing it with “SMS:”, i.e. href="SMS:02313213"

I’ve had a look around and can’t seem to find anything that suggests it is available on Android.

Answer

I found the following which may help you:

https://www.rfc-editor.org/rfc/rfc5724

You can check sub-section 2.5 or 2.6 of this RFC to give you some additional pointers on formulating a proper SMS URL.

Eg. using formal URI-spec as detailed in sub-section 2.2 of rfc5724:

<a href="sms:+19725551212?body=hello%20there">SMS Me</a>  

Notice the ‘escaped’ character for the ‘space’ in the example above.

Hopefully the Android browser will permit you to generate XHTML forms based on this syntax. I believe they will (if I have some time over the next day, I shall give it a try on my Galaxy S).

Categories
discuss

Can SharedPreferences be shared among different Android applications?

As I checked in APIs description for getSharedPreferences(String, int),Second attribute is defining accessibility mode and can take 0 or MODE_PRIVATE for the default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions.

But there is this small note in API description:

Note: currently this class
(android.content.SharedPreferences)
does not support use across multiple
processes. This will be added later.

Moreover in Mark L. Murphy book “beginning Android 2” he mentioned:

(Eventually, preferences might be
shareable across applications, but
that is not supported as of the time
of this writing)

Im so confused! does this mean that MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE of getSharedPrefrences is there but NOT SUPPORTED YET in latest API level???

Thanks!
Migan

Answer

My book reference is based upon that comment.

Moreover, making any file MODE_WORLD_READABLE or (worse) MODE_WORLD_WRITEABLE is a bad idea. You lose any hope of security.

If you wish to share data between two applications, there are a myriad of solutions, such as:

  • service with an API exposed by AIDL
  • service with an API exposed via commands sent via startService() and responses sent via a Messenger or createPendingResult() PendingIntent or something
  • content provider
  • broadcast Intents

All of those allow you to define permissions for integration and let you control the granularity of access.

Categories
discuss

What is the real benefit of using canvas for games?

I’m currently reading up on the canvas, but I’m finding it hard to find practical benefits of using canvas, when a lot can be done using simple css overlays/JavaScript (+ jquery lib).

This is probably because I don’t know the FULL practicalities of using canvas.

Looking at this game:
http://www.pirateslovedaisies.com/

Could someone help explain how and why canvas is being used as opposed to just css?

Answer

This is a 4k js/canvas demo I wrote to experiment with the 2d context (here is a video if your browser doesn’t work). I tested it only on chrome, opera, firefox, safari and nexus one browser.

Note that no external resources are loaded (i.e. the texture and the raytraced envmap are built dynamically), so this is just a single self-contained 4096 bytes HTML file.

You can do something like that with DIVs?

But indeed I agree that the game you linked IMO could be done also with DIVs; apparently there are no transformations – not even in the falling daisy loading scene – and the action areas for the pirates are just circles. Not sure but could be that even shooting only happens at fixed angles.

Canvas could have been used instead for:

  • Drawing general sloped lines and polygons (the map could be created dinamically from a compact description or could have been generated randomly). Shooting could be done at any angle…
  • Procedural image creation (e.g. textures or special pixel effects)
  • Gradients, texture mapping
  • General 2d matrix transforms

Of course a game using an image+DIVs approach is probably way easier to make (a lot of photoshop and simple xy animation).

Categories
discuss

Rails root_path in application.js

How can I get my hands on the project’s root_path in my application.js file?

I need it for a js plugin (codemirror) that needs to load other JS files. It’s all fine and dandy if I say “/javascripts/needed_file.js”, but what if I deploy my project to “/custom”.

The code needs to do its magic all over the project and I would like it to be UJS, so it needs to be in a static javascript file.

Any solutions/simple hacks?

Answer

There’s no beautiful solution. I’d try one of these approaches:

  • Inspect window.location.pathname. Determine from this whether running from root or from a prefix url.

  • Add something like <script type="text/javascript" charset="utf-8">var ROOT_PATH = '<%= Rails.root_path %>';</script> somewhere to the top of your layout file.

  • Use this quite hackish function (I suspect that it might break with some of the HTML5 script attributes):

    function urlOfCurrentFile() {
      var scripts = document.getElementsByTagName("script");
      return scripts[scripts.length - 1].src;
    }
    
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..