Thursday, September 16, 2010

PAW Runtime

PAW Runtime is basically a stripped down PAW Server that only listens to the loopback interface on a random port and with a WebView serving as browser frontend.
With this set-up it is possible to run PAW applications directly on the device.

Everything that's possible with PAW Server is also possible with the runtime version.

Overview


It enables users and programmers to directly develop applications on the device without the need to install a SDK on the PC.
Because the GUI is defined via HTML development of the interface is easy for people that know HTML/CSS and JavaScript.

There are of course limitations to this approach concerning speed and using all features of the platform, but for developing small applications or prototypes this should be sufficient.
What is not possible is to develop individual apps, all PAW Runtime apps reside in the /sdcard/paw-runtime directory and are accessible (when defined in the webconf/apps directory) from the main menu screen.

The runtime itself comes with no applications, but demo applications are available for download.
Below is the main menu with installed demo applications.

Menu

Let's have a look at the compass app shown in the first image.

All applications are stored in the /sdcard/paw-runtime/html folder. The application consists of a XHTML file and the corresponding jQuery scripts and images. Together with the demos comes a html/common folder that contains components (like JavaScript files) that can be reused.

Let's have a look at the XHTML file:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Compass</title>
<link rel="stylesheet" href="../common/css/default.css">
<script type="text/javascript" src="../common/js/jquery.js"></script>
<script type="text/javascript" src="../common/js/executeScript.js"></script>
<script type="text/javascript" src="js/jquery.rotate.js"></script>
<script type="text/javascript">
$(document).ready(function() {
updateCompass();
});

function updateCompass() {
executeScript('compassScript', null, 'compassRes');
$("#compassImg").rotate($("#compassRes").val() * -1, 'abs');
}
</script>
</head>
<body>
<center>
<h1>Compass</h1>
<img src="images/compass_rose.png" id="compassImg">
<p>
<div style="font-size: 30px; font-style: bold;" id="compass"></div>
</p>
</center>

<input type="hidden" id="compassRes" onChange="$('#compass').html($(this).val() + '°'); setTimeout('updateCompass();', 500);">

<!-- Script -->
<textarea id="compassScript" style="visibility:hidden; display: none;">
import de.fun2code.android.pawserver.AndroidInterface;

sensorListener = AndroidInterface.getSensorListener();
bearing = sensorListener.getOrientBearing();
$$.print(bearing);
</textarea>

</body>
</html>


The part that reads the bearing information of the device is surrounded by BeanShell <bsh>...</bsh> tags.
All the rest is standard HTML/JavaScript. A documentation of the functions provided by PAW comes bundled with the demo applications.

One last thing to do is to define the application's .conf file in the webconf/apps directory, so that the application is available from the main menu.

name=Compass
description=Displays Compass and Bearing
icon=compass/images/compass_rose.png
href=compass/compass.xhtml

APK Download: PawRuntime.apk
Demos Download: PawRuntime_Demos.zip
Eclipse Project: AndroidPawRuntime_Eclipse_Project.zip

Note: Files are based on PAW Server for Android 0.60 beta


The demos can be simply unpacked onto the /sdcard of the device.

PAW Runtime is currently in alpha state.
Comments are welcome...

24 comments:

  1. A short - maybe stupid - question, when i've allready installed the paw-webserver there is no need to install the runtime as well?
    Keep on doing your good work.
    Oliver

    ReplyDelete
  2. Hi Oliver,

    the underlying server has the same capabilities.
    So web apps will run on both versions.
    The reason for the runtime was that web apps should look more like native apps. On my old Android 1.5 device the browser only works if networking is available.
    Apart from that there are situations (speech to text, bar code scanning) where the app has to be brought into foreground. As an example ... when using a browser the PAW app will pop into foreground opening the barcode scanner, when scanning is finished the user will be stuck in the PAW app and not return to the browser as expected.
    Anyway ... the web apps will work in both environments.

    ReplyDelete
  3. Hi, i've tried to setup compass demo in paw server but an error ocuurs saying:
    error on line 19 at column 8: Opening and ending tag mismatch: link line 0 and head

    and the paw runtime not running on android 2.2.
    CEG

    ReplyDelete
  4. Hi CEG,
    this is strange. I tested PAW Runtime with a Nexus One which is running Android 2.2.

    ReplyDelete
  5. Very good concept, I'm developing the paw runtime webapp on the paw server +desktop editor & browser; and running it on paw runtime. The paw runtime is much better for the end-user.
    1 question: how can the paw runtime window be fullscreen?
    Thank You for the good work!
    Sztyopi

    ReplyDelete
  6. Fullscreen can be achieved by the following code:

    import android.view.WindowManager;
    import de.fun2code.android.pawserver.*;

    service = server.props.get("serviceContext");
    activity = service.getActivity();
    webview = activity.findViewById(de.fun2code.android.pawruntime.R.id.webview);

    webview.post(new Runnable() {
    public void run(){
    // Fullscreen ON
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    // Fullscreen OFF
    //activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    }
    });

    Hope that helps...

    ReplyDelete
  7. I've just uploaded a new version (0.16).
    This adds the following command:

    fullscreen(boolean)

    So the above code is no longer necessary!

    ReplyDelete
  8. Hi,

    I am a new Droid X user who is trying to install the PAW webserver on my sdcard.

    I was able to install the webserver itself. I was able to start it. I have not at this point instalkled the zipped files to the sdcard. After using the suggested http address provided by your app, my browser invariably times out.
    So, while PAW is installed, it effectively is not operational.

    I have a couple of questions:

    1. Exactly where on the sdcard should I extract the zip file.

    2. After extracting the zip file, what do I do next?

    ---- Do I then run the PAW webserver and insert the http://.... in the address portion of the browser

    ---Or, should I start my browser before starting PAW? Does it make any difference?

    3. Which file or files on the zipped file should I run?

    4. My purpose in installing PAW on my phone is to look at a (large) collection hyperlinked html and pdf of files I
    transfered to my sd card. Should these files be placed in a particular folder for purposes of PAW?

    5. I am using Opera Mini on my Droid X. Is this ok? Is there a better browser? Any suggested settings for the browser?

    Sorry for the probably stupid questions. Your help would be appreciated.

    Thanks!
    bestresearcher@gmail.com

    ReplyDelete
  9. Anyway to get the eclipse project or source for the PAW-runtime server? So savvy developers can bundle their own apps with the PAW-runtime engine?

    ReplyDelete
  10. Hi Brian,

    if there is interest in getting the Eclipse project, I'll clean things up and post the project.
    Just give me some time to do that...

    ReplyDelete
  11. Eclipse project has been added to the list of downloads.

    ReplyDelete
  12. Awesome! Thanks so much!! I'm downloading as I type this comment.

    ReplyDelete
  13. I like this app but why is it on a random port. I want to be able to connect via a web browser on a computer, and not on an android phone. How do you set the port. Is this possible.

    ReplyDelete
  14. If you would like to connect via another computer, please use the PAW server from the Android Market. The runtime is only meant for local connections.

    ReplyDelete
  15. Hi Jochen, you make great apps!

    My question is if i can use php with paw runtime?, i'm trying put a php file in the href of the .conf file, but when i run it, the app show me a 'not found' message. Is the runtime enabled to execute a php files or only with xhtml with bsh code?

    Thanks a lot Jochen!

    ReplyDelete
    Replies
    1. This is the first request to run PHP with the runtime version.
      In principle this should work.
      I'll have a look at it and will try to blog about it this week.

      Delete
  16. hi!
    i'd be interrested to... :)

    good job !

    ReplyDelete
  17. Absolutely brilliant. Yet, I can't seem to get the Runtime eclipse source to work properly.

    ReplyDelete
    Replies
    1. If you send me a mail (jochen[at]fun2code.de) describing the problems you have, I'll have a look at it.

      Delete
  18. Hi, Under what license is this awesome app. released ?

    ReplyDelete
    Replies
    1. You can use the runtime version and its source code freely for private or educational purposes.

      Delete
  19. Great idea, I'm creating the paw runtime webapp on the paw server +desktop manager & program; and running it on paw runtime. The paw runtime is much better for the end-client.

    designers web // Best Web Design

    ReplyDelete
  20. Replies
    1. JSPs won't run. PAW is not a Servlet container. You have to use i-jetty or the like.

      Delete

Note: Only a member of this blog may post a comment.