Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Monday, June 2, 2014

App development with GWT, Cordova and Netbeans Part 4

This is the forth part of my blog series on how to develop mobile apps with GWT, Cordova and Netbeans. The initial description can be found here.
In the previous parts we did create a MGWT project and did put a "Hello world" button on the screen and finaly did build the native apps for android and windows phone.

Web apps are all nice, but often you wish to access some features of your mobile device which is not available to web applications. Some common things are the camera, sensors and so on.

With cordova/phonegap we fortunally can use these devices via native plugins.
Just a warning: Any plugin you use must be available on all target platforms, otherwise you will get in troubles. (There are ways to handle such situations, but they are outside the scope of this tutorial)

The first step to allow such access, is to teel the maven pom.xml that we wish to use phonegap "features".
Just add this dependency in your pom.xml file:

<dependency>
    <groupId>com.googlecode.gwtphonegap</groupId>
    <artifactId>gwtphonegap</artifactId>
    <version>2.4.0.0</version>
</dependency>


The second think to change, is you index.html file.
There you have to specify that cordova.js is started, so the html<->native bridge is activated.

Somewhere in your index.html you have the line which starts the gwt java script.
It looks like this:
<script type="text/javascript" language="javascript" src="mgwt1/mgwt1.nocache.js"></script>

Before that line, add the call to the cordova.js file, so the phonegap environment is initialized.

It should then look like this:

<script type="text/javascript" language="javascript" src="cordova.js"></script>
<script type="text/javascript" language="javascript" src="mgwt1/mgwt1.nocache.js"></script>

It is important that the cordova.js in loaded before the GWT script, because the initialisation order is important.

Finally you must tell the phonegap build service to include some native plugins, otherwise the cordova.js will be missing in the package.
For this add these lines to your src/main/phonegap-build/config.xml:

<feature name="http://api.phonegap.com/1.0/notification"/>
<feature name="http://api.phonegap.com/1.0/device"/>
<gap:plugin name="org.apache.cordova.device" version="0.2.8" />
<gap:plugin name="org.apache.cordova.dialogs" version="0.2.6" />

With these four lines you include the device information features (You can retrieve the platform informations) and show native notifications.

In the start() method of your "java" class, you add the initialisation of the phonegap environment.

PhoneGap phoneGap = GWT.create(PhoneGap.class);
boolean isPhoneGap= phoneGap.isPhoneGapDevice();
           
if (isPhoneGap)
{
    phoneGap.addHandler(new PhoneGapAvailableHandler()
    {
        @Override
        public void onPhoneGapAvailable(PhoneGapAvailableEvent event)
        {
            // Here you have the native "bridge" up and running
        }
    });
   phoneGap.addHandler(new PhoneGapTimeoutHandler()
   {
       @Override
       public void onPhoneGapTimeout(PhoneGapTimeoutEvent event) 
       {
           //can not start phonegap - something is for with your setup
       }
    });
}
The last step required, is tell GWT to use the phonegap API too.
So in your <project.gwt.xml uncomment this line:

<inherits name="com.googlecode.gwtphonegap.PhoneGap"/>

With this you now have access to all the features as described here.
Of course you need to speicfy access rights for you app, otherwise you will not be allowed to interact with the native phone system. (Camera etc.)

You can download the sample project from this place.

I hope you enjoyed this tutorial.
If you struggle somewhere, please drop me a note, so I can enhance the tutorial.


App development with GWT, Cordova and Netbeans Part 3

This is the first part of my blog series on how to develop mobile apps with GWT, Cordova and Netbeans. The initial description can be found here.
In the previous parts we did create a MGWT project and did put a "Hello world" button on the screen.
This is shown just nice on any browser, but is not yet a native mobile app.
In this part we will use the adobe phonegap build service to package our small web app as a native app which can be put in a app store of the big players.
Packaging the app for the different target systems is a tedious work, since you must install the different SDK, in the correct versions. And you can't develop all version on a single platform. For example iOS apps need a OS-X system to build them.

Fortunally there exists a build service from adobe which allows you to upload your web app as zip file (or take the source from a git repository) and then build the app for all the target platforms you wish.

The free version of the service allows you to build one private app and as many opensource apps as you wish.
If you need to build more private (or better closed source ) apps, then you can buy a upgrade for $9.99/Month which allows you to build up to 25 private applications.

We will continue with the free account and use this to build our closed source app, directly from inside netbeans. So you won't have to upload the zip file manually and can fully automate your builds.

The first step to build a native app, is extending the maven build to include the build service. Fortunally Chris has written a maven plugin which handles this very well.

In your pom.xml you just add the dependency to the new plugin:

<plugin>
    <groupId>com.github.chrisprice</groupId>
    <artifactId>phonegap-build-maven-plugin</artifactId>
    <version>0.0.7</version>
    <executions>
        <execution>
            <id>phonegap-build</id>
            <goals>
                <goal>clean</goal>
                <goal>build</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
   
    <platforms>            
            <!-- <platform>ios</platform> -->
       
    <platform>android</platform> 
            <platform>winphone</platform>
        </platforms>
    </configuration>                                   
</plugin>

With this your build process will push the zip file to the adobe build service and retrieve the final platform packages.
Since the build service is password protected, you need to specify your credentials.

This can simply be done by specifying which server should be used for building in your pom.xml file. (Almost on top of it)

<properties>
    <gwtversion>2.5.0</gwtversion>
    <phonegap-build.server>phonegap-build</phonegap-build.server>
</properties>

The second part is to specify your personal credentials. As it's a bad idea to put them in the pom.xml, you should put them in default maven settings file.
The maven settings file is called settings.xml and is usually located in the .m2 directory of the users home folder.

The content should look like this:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <servers>
        <server>
            <id>phonegap-build</id>
            <username>yourlogin@adobe.com</username>
            <password>MySecurePassword</password>
        </server>
    </servers>
</settings>



The last step before starting the build is to specify a config.xml file, to instruct the build service what should be done.
This file is located under src/main/phonegap-build and should have this content:

<?xml version="1.0" encoding="UTF-8"?>
    <widget xmlns = "http://www.w3.org/ns/widgets"
        xmlns:gap = "http://phonegap.com/ns/1.0"
        id        = "org.company.project"
        versionCode=""
        version   = "1.0.0">
        <name>My test project</name>
        <description></description>
        <author href="http://www.aarboard.ch" email="support@aarboard.ch">André Schild</author>
        <preference name="phonegap-version" value="3.4.0" />
        <preference name="orientation" value="default" />
        <preference name="fullscreen" value="true" />
        <preference name="target-device" value="universal" />
        <preference name="webviewbounce" value="true" />
        <preference name="prerendered-icon" value="true" />
        <preference name="stay-in-webview" value="true" />
        <preference name="ios-statusbarstyle" value="black-opaque" />
        <preference name="detect-data-types" value="true" />
        <preference name="exit-on-suspend" value="true" />
        <preference name="show-splash-screen-spinner" value="true" />
        <preference name="auto-hide-splash-screen" value="true" />
        <preference name="EnableViewportScale" value="false" />
        <preference name="MediaPlaybackRequiresUserAction" value="false" />
        <preference name="AllowInlineMediaPlayback" value="false" />
        <preference name="BackupWebStorage" value="cloud" />
        <preference name="TopActivityIndicator" value="gray" />
        <preference name="KeyboardDisplayRequiresUserAction" value="true" />
        <preference name="HideKeyboardFormAccessoryBar" value="false" />
        <preference name="SuppressesIncrementalRendering" value="false" />
        <preference name="android-minSdkVersion" value="7" />
        <preference name="android-installLocation" value="auto" />
        <preference name="SplashScreenDelay" value="5000" />
        <preference name="ErrorUrl" value=""/>
        <preference name="BackgroundColor" value=""/>
        <preference name="KeepRunning" value="false"/>
        <preference name="DisallowOverscroll" value="false"/>
        <preference name="LoadUrlTimeoutValue" value="20000" />
        <preference name="disable-cursor" value="true" />
        <gap:platform name="android" />
        <gap:platform name="winphone" />
        <access origin="http://127.0.0.1*" />
    </widget>


You can now rebuild your project and should have the two app packages in the target/phonegap-build folder.
One is a .apk file for android, the other a .xap file for windows phone.

You could now transfer these files to your mobile device and test them, or you can go to the adobe build service page and scan the QR code from there.


If you modify your code, you can then just rebuild the app and reinstall it on your phone.
If subsequent builds fail, then you have to specify which APP number to use. Otherwise the build service thinks you wish to cretae multiple private apps.

To prevent this, you note the app id from the build service (see screenshot above) and then add this to your pom.xml file in the plugin section.

    </platforms>
    <appId>9xxxxxx</appId>                            </configuration>                   

As you may have noted, we did now build the app for Android and Windows phone. When you wish to build your app for iOS, then you need a developer account from apple. This account costs $99.-/Year.
You have to create a account here and then register for iOS development. You will then receive a signing key, with which you have to sign ANY iOS application you develop. There is no other way to install software on your iOS devices (unless you root the device)

In the next and last part of the serie we will look at what is required to access native features for your mobile device. In short you need to integrate the cordova plugins and initialize them correctly.

App development with GWT, Cordova and Netbeans Part 2

This is the second part of my blog series on how to develop mobile apps with GWT, Cordova and Netbeans. The initial description can be found here.

In the first part we did create a basic MGWT project from a maven template and did run it in the web browser of our choise.
It did just display a grey divider line on the screen, similiar to this.

Now we wish to show some real content on the page. For this we need to mobify the main class of the application.
The main application class is defined in your <project>.gwt.xml file.
Look for the  <entry-point> xml tag, this is where your application starts.

You can now open this java file and search for the start() method.
The simplest way to get our hello world is to modify the start() method to only show a button with hello world as caption.

So your start() method should look like this:

private void start() {
       
      //set viewport and other settings for mobile
            MGWT.applySettings(MGWTSettings.getAppSetting());
            LayoutPanel mainPanel= new LayoutPanel();
            mainPanel.setWidth("100%");
            Button button = new Button("Hello world");
            button.setWidth("100%");
            mainPanel.add(button);
            RootPanel.get().add(mainPanel);       
    }


Don't delete the onModuleLoad method, this one is required.
After a rebuild und run of the project, you should now see the "Hello world" button on your browser, similar to this printscreen.


Initial description
Part 1
In the next part we will now go to the magic, and put this in a android and windows phone app.

Quickstart mobile app development with GWT, Cordova and Netbeans

Mobile app development is a fast moving target. You have many options on how to develop mobile apps.

The most sophisticated way is to write native apps for each platform...
Of course you will need to master the different languages and development environments. And since you will have to develop the same functionality for several platforms, you will code it multiple times in different languages.
Happy you if you find a customer willing to pay for it.

If you wish to use the "write once run anywhere" system, then you will be landing on web apps. Fortunally today mobile devices are in most cases fast enough to run you web app without feeling slugish. So you basically can write a html 5 website and make it available as a app.
For this you can use the phonegap / cordova framework.

If you need access to some native parts of the mobile device (Sensors, camera etc.) then you can use many of the available plugins which then allows you to access these hardware specific features.

Even better, you can use the adobe build service to build the whole application from your html/javascript sources.

If you come from the java world, then writing javascript isn't that sexy, you could then use GWT to write your web app in java and let the compiler generate java script stuff from it.
The performance of the generated code is very good, you will have a hard time to make such optimized java script code.

In this blog post serie I will guide you through the process of creating a project in netbeans, which you can then use to build your mobile application from your familiar ide.

Such apps are able to run under iOS, Android and Windows Phone. Of course platform specific features will only be available on the specific platform.

So let's start with Part 1 of the tutorial
Step 2 - Modify content
Step 3 - Build native apps 

Tuesday, August 23, 2011

Yet another mobile OS is history

In the last days HP announced that they stop working on their WebOS.

Not so big a problem for me, since I currently work on Android.



My personal OS history on the desktop is:
  • TI-99/4A
  • Atari/ST
  • Windows NT 3.x
  • Different Windows NT+ versions (Up to Windows 7)
  • Various Linux versions, mainly Ubuntu on Laptops

The history on my PDA/Phones is:
  • PalmOS on a Palm III
  • Symbian (On various SE Phones up to the P1i)
  • iOS (For 2 weeks)
  • Android

What is interesting, is the fact that PalmOS, Symbian and now WebOS all stopped existing in 2011.

PalmOS had a very good start and a lot of applications, but they did stop development when they had a very big market share. They missed the jump into multitasking...

Symbian, was a very promising system, but always had multiple GUI systems. So if you did develop a application for a Nokia Symbian, it did not run on a SE Symbian system.
When apple did then publish it's first (very limited) iPhone, Nokia and SE got hysteric and did mess up things. SE left the Symbian community and Nokia wanted to make it open source, with a single GUI system. But that step did take 1-2 years before even developers could start working on it...

I think still think that symbian has many advantages over iOS/Android, but due to such a weird GUI and horrible mobile data charges in the past, had no chance to survive.
And the Nokia company did a horrible job in press communication, so all developers started looking for other systems. (If you look at Nokia and the current "work" on MeeGo you see many paralels :( )

I'm not sure Nokia will be a big player in the future, this realy depends on what will happen with WM7.

iOS, yes, good marketing, sell a phone which does not even provide MMS, video conferences etc. But a cheap data plan, that did made the trick.
Personally I can't identify myself with iXXX products, but a valuable product, but too much in control of apple.

So we are reaching Android,
when it was becoming clear that Symbian will have not future (About 1 year after the launch of the P1i) I looked out for alternatives, there where only iOS and Android (Ok, Android only promising at the horizont at that time)
After two weeks of testing a iPhone 3 I returned to my P1i and waited for Android 2.x
The HTC device then came with a nice data plan, and it was love to the device. At first touching the screen was a bit strange, but now it works. (But I still miss the keyboard sometimes)
The main advantage of Android is, that I can write and install a application, without having to ask steve if he shows me his grace and allows my application.
Also I don't think that one phone model covers the need of all people of this world.

The main drawback of Android is currently the various versions and the (missing) updates.
Here Google has to make sure that the users get the updates. I had to wait many month for getting Gingerbread on my phone and even that was unsure.
In that area, the iPhone is better situated, of course, only one brand and 2 current phone models to support.

So what the future will bring us?
  • More iPhone/iOS devices, but only a few at a time
  • Even much more Android devices
  • WindowsMobile devices... there will be such devices but I'm not certain that they will have a big market share. MS has enough money to push WM in the next years, but is that enough ?
  • Blackberry, no, I don't think they have a big future with their own OS
  • Other OS ? No, what for ? 

iOS covers the needs of the "All-in-one" liking users
Android covers the needs of all liking the diversity of the world
WindowsMobile if you still think it works best together with your desktop
There just is no need for yet another mobile OS, and if you see how much the different competitors fight against each other with patetents, then a startup just has no place (And no finance) in these ridiculous patent fights.

What do you think, has another mobile OS chances to reach a considerable market share ?

Wednesday, April 27, 2011

Wuala now also available for Android

The secure online storage system Wuala (by Lacie) has just released the Android version of the client software.

Now you can access your files from Windows, OS-X, Linux, iOS and Android (And public files via Webinterface)