11
Wikitude Application development in Android Wikitude is an information-based AR application has been developed by the Germany Company Geo Mobilizy. Wikitude API has been released for other apps. (2009). Using the API WIKITUDE the application sends the data as locations and descriptions, and Wikitude application displays the information as accurate as possible using GPS from you device. What you need: We need an environment for develop this application; in this tutorial I’ll use Eclipse. Notice that I assume that you know the basics of android, how to create an android virtual device (included in SDK tools) and how to run any application in this emulator. If not, you can search a tutorial for these basics aspects; you can find it in http://developer.android.com/guide/developing/projects/projects- eclipse.html After read the lines above, let’s get the tools: Eclipse Classic (http://www.eclipse.org/downloads ) Android SDK (http://developer.android.com/sdk/index.html ) ADT Plugin for eclipse (http://developer.android.com/sdk/eclipse- adt.html#installing)* *Read all information provided in that link, also provides a tutorial for how to integrate the plugin in eclipse environment. WIKITUDE application for you mobile (Obtained from the Android Market*). *UPDATE: Now in 2012 you can get it from Google Play. WIKITUDE API (http://www.wikitude.org/wp-content/uploads/2010/03/Wikitude-API- 1.1.zip ) Wikitude API documentation and samples has been encapsulated.

Wikitude Application Development in Android

Embed Size (px)

Citation preview

Page 1: Wikitude Application Development in Android

Wikitude Application development in Android

Wikitude is an information-based AR application has been developed by the Germany Company Geo Mobilizy.

Wikitude API has been released for other apps. (2009).

Using the API WIKITUDE the application sends the data as locations and descriptions, and Wikitude application displays the information as accurate as possible using GPS from you device.

What you need:We need an environment for develop this application; in this tutorial I’ll use Eclipse. Notice that I assume that you know the basics of android, how to create an android virtual device (included in SDK tools) and how to run any application in this emulator. If not, you can search a tutorial for these basics aspects; you can find it in http://developer.android.com/guide/developing/projects/projects-eclipse.html

After read the lines above, let’s get the tools:

Eclipse Classic (http://www.eclipse.org/downloads) Android SDK (http://developer.android.com/sdk/index.html) ADT Plugin for eclipse (http://developer.android.com/sdk/eclipse-adt.html#installing)*

*Read all information provided in that link, also provides a tutorial for how to integrate the plugin in eclipse environment.

WIKITUDE application for you mobile (Obtained from the Android Market*).*UPDATE: Now in 2012 you can get it from Google Play.

WIKITUDE API (http://www.wikitude.org/wp-content/uploads/2010/03/Wikitude-API-1.1.zip)

Wikitude API documentation and samples has been encapsulated.

BasicOpenARDemo.zip

Unzip and save to a directory of your choice. After unzip, open as a project of Eclipse.

Page 2: Wikitude Application Development in Android

FILE NEW ANDROID PROJECT

Set the project name, en content select “Create project from existing source” and select the directory obtained from .zip file.

This tutorial was written in 2009, because this uses Android 1.1 (obsolete) you can try other recent API levels for you project under own risk.

Now we have to incorporate Wikitude API into our project folder, it is a library for calling the wikitudearintent.jar and this are in the lib directory of BasicOpenARDemo.

To do this:

Right-click in project folder in eclipse Properties Java Build Path Libraries Add external JARs

Page 3: Wikitude Application Development in Android

Now in the follow lines you have the code for the activity. Depending on the version of Java is so out of place red error @Override, and then click Delete.

package org.openintents.samples.BasicOpenARDemo;

import java.io.File;import java.util.ArrayList;import java.util.List;

import org.openintents.intents.AbstractWikitudeARIntent;import org.openintents.intents.Wikitude3dARIntent;import org.openintents.intents.WikitudeARIntent;import org.openintents.intents.WikitudePOI;

import android.app.Activity;import android.app.AlertDialog;import android.app.Dialog;import android.content.ActivityNotFoundException;import android.content.DialogInterface;import android.content.res.Resources;import android.os.Bundle;import android.os.Environment;import android.view.View;import android.widget.Button;

/** * This sample application demonstrates the basic usage of the Wikitude Open AR (augmented reality) API.<br/>

Page 4: Wikitude Application Development in Android

 * The basic usage is to create a list of POIs (points of interest) that is sent to the AR application through intent * extras.<br/> * Optional extras can be set to customize the icons or the title bar. *  * @author Martin Lechner, Mobilizy GmbH., [email protected] */public class BasicOpenARDemoActivity extends Activity {

    /** the callback-intent after pressing any buttons */    private static final String CALLBACK_INTENT = "wikitudeapi.mycallbackactivity";    /** the id of the dialog which will be created when the modelfile cannot be located */    private static final int DIALOG_NO_MODEL_FILE_ON_SD = 1;    /** the model ile name */    private static final String modelFileName = Environment.getExternalStorageDirectory() + "/wtc_old_triang.obj";    /** the latitude of the origin (0/0/0) of the model */    private static final float modelCenterLatitude = 47.822f;    /** the longitude of the origin (0/0/0) of the model */    private static final float modelCenterLongitude = 13.045f;    /** the altitude of the origin (0/0/0) of the model */    private static final float modelCenterAltitude = 470;

    /**     * {@inheritDoc}     */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        // We hook up 3 different buttons.        Button b = (Button) findViewById(R.id.button1);        b.setOnClickListener(new View.OnClickListener() {            public void onClick(View v) {                BasicOpenARDemoActivity.this.startARViewBasic();            }        });

        b = (Button) findViewById(R.id.button2);        b.setOnClickListener(new View.OnClickListener() {            public void onClick(View v) {                BasicOpenARDemoActivity.this.startARViewWithIcons();            }        });

        b = (Button) findViewById(R.id.button3);        b.setOnClickListener(new View.OnClickListener() {            public void onClick(View v) {                BasicOpenARDemoActivity.this.startARViewWithCustomTitle();            }        });

Page 5: Wikitude Application Development in Android

        b = (Button) findViewById(R.id.button4);        b.setOnClickListener(new View.OnClickListener() {            public void onClick(View v) {                BasicOpenARDemoActivity.this.start3dARView();            }        });    }

    /**     * starts the basic AR view     */    private void startARViewBasic() {

        // Create the basic intent        WikitudeARIntent intent = prepareIntent();

        // And launch the intent        try {            intent.startIntent(this);        } catch (ActivityNotFoundException e) {            AbstractWikitudeARIntent.handleWikitudeNotFound(this);        }    }

    /**     * does the same as the basic AR view above, but adds custom icons to the POIs     */    void startARViewWithIcons() {

        // Create the basic intent        WikitudeARIntent intent = prepareIntent();

        // Optionally add a title        intent.addTitleText("AR app with custom icons");        intent.setPrintMarkerSubText(false);

        // Optionally: Add icons        addIcons(intent);

        // And launch the intent        try {            intent.startIntent(this);        } catch (ActivityNotFoundException e) {            AbstractWikitudeARIntent.handleWikitudeNotFound(this);        }    }

    /**     * does the same as the basic AR view above, but adds custom icons to the POIs and a graphical title image     */    void startARViewWithCustomTitle() {

Page 6: Wikitude Application Development in Android

        // Create the basic intent        WikitudeARIntent intent = prepareIntent();

        intent.setPrintMarkerSubText(false);

        // Optionally: Add icons        addIcons(intent);

        // Optionally: Put a custom graphical title:       intent.addTitleImageResource(this.getResources().getResourceName(R.drawable.custom_title_bar));

        // Optionally, one could set URIs:        // Use Android's content provider or create your own        // to host your custom images.        // intent.addTitleImageUri("content://com.IconCP/ANY_ICON_PATH.jpeg");

        // And launch the intent        try {            intent.startIntent(this);        } catch (ActivityNotFoundException e) {            AbstractWikitudeARIntent.handleWikitudeNotFound(this);        }    }

    /**     * starts the 3D AR view     */    private void start3dARView() {

        // Create the basic intent        Wikitude3dARIntent intent = new Wikitude3dARIntent(this.getApplication(), null, null);

        File file = new File(modelFileName);        if (!file.exists()) {           this.showDialog(BasicOpenARDemoActivity.DIALOG_NO_MODEL_FILE_ON_SD);        } else {            intent.setModelPathFileSystem(modelFileName);            intent.setModelOrigin(modelCenterLatitude, modelCenterLongitude, modelCenterAltitude);            intent.setMetersWorth1000Points(1);

            // And launch the intent            try {                intent.startIntent(this);            } catch (ActivityNotFoundException e) {                AbstractWikitudeARIntent.handleWikitudeNotFound(this);            }        }    }

Page 7: Wikitude Application Development in Android

    /**     * prepares a Wikitude AR Intent (e.g. adds the POIs to the view)     *      * @return the prepared intent     */    private WikitudeARIntent prepareIntent() {        // create the intent        WikitudeARIntent intent = new WikitudeARIntent(this.getApplication(), null, null);        // add the POIs        this.addPois(intent);        // add one menu item        intent.setMenuItem1("My menu item", BasicOpenARDemoActivity.CALLBACK_INTENT);        intent.setPrintMarkerSubText(true);        return intent;    }

    /**     * adds hard-coded POIs to the intent     *      * @param intent     *            the intent     */    private void addPois(WikitudeARIntent intent) {        WikitudePOI poi1 = new WikitudePOI(35.683333, 139.766667, 36, "Tokyo", "Tokyo is the capital of Japan.");        poi1.setLink("http://www.tourism.metro.tokyo.jp/");        poi1.setDetailAction(BasicOpenARDemoActivity.CALLBACK_INTENT);        WikitudePOI poi2 = new WikitudePOI(41.9, 12.5, 14, "Rome",                "Rome is the capital of Italy and the country's largest and most populous city, with over 2.7 million residents.");        poi2.setDetailAction(BasicOpenARDemoActivity.CALLBACK_INTENT);        WikitudePOI poi3 = new WikitudePOI(40.716667, -74, 1, "New York",                "New York is the most populous city in the United States, and the center of the New York metropolitan area.");        poi3.setDetailAction(BasicOpenARDemoActivity.CALLBACK_INTENT);        WikitudePOI poi4 = new WikitudePOI(48.208333, 16.373056, 220, "Vienna",                "Vienna is the capital of the Republic of Austria.");        poi4.setDetailAction(BasicOpenARDemoActivity.CALLBACK_INTENT);        List<WikitudePOI> pois = new ArrayList<WikitudePOI>();

        pois.add(poi1);        pois.add(poi2);        pois.add(poi3);        pois.add(poi4);        intent.addPOIs(pois);

        ((BasicOpenARDemoApplication) this.getApplication()).setPois(pois);    }

    /**     * helper-method to add icons to the intent.     *      * @param intent

Page 8: Wikitude Application Development in Android

     *            the intent     */    private void addIcons(WikitudeARIntent intent) {        ArrayList<WikitudePOI> pois = intent.getPOIs();

        Resources res = getResources();       pois.get(0).setIconresource(res.getResourceName(R.drawable.flag_japan));       pois.get(1).setIconresource(res.getResourceName(R.drawable.flag_italy));        pois.get(2).setIconresource(res.getResourceName(R.drawable.flag_usa));       pois.get(3).setIconresource(res.getResourceName(R.drawable.flag_austria));        // to use this, make sure you have the file present on the sdcard        // pois.get(3).setIconuri("content://com.IconCP/sdcard/flag_austria.png");    }

    /**     * {@inheritDoc}     */    protected Dialog onCreateDialog(int dialogId) {        String message = this.getString(R.string.modelfile_not_found, modelFileName);        return new AlertDialog.Builder(this).setTitle(R.string.modelfile_not_found_title).setMessage(message)                .setPositiveButton("OK", new DialogInterface.OnClickListener() {                    public void onClick(DialogInterface dialog, int whichButton) {                        // do nothing, just dismiss the dialog                    }                }).create();    }}

You can add more POIs (Points of interest) with this format:

WikitudePOI poi1 = new WikitudePOI();

You are noticed that the follow line contains: (longitude, latitude, altitude, name, description). In the other lines, you can add a link to this POI

 WikitudePOI poi1 = new WikitudePOI(35.683333, 139.766667, 36, "Tokyo", "Tokyo is the capital of Japan."); poi1.setLink("http://www.tourism.metro.tokyo.jp/"); poi1.setDetailAction(BasicOpenARDemoActivity.CALLBACK_INTENT);

Even, you can add icons as shown at follow:

ArrayList<WikitudePOI> pois = intent.getPOIs();Resources res = getResources();pois.get(0).setIconresource(res.getResourceName(R.drawable.flag_japan));

Page 9: Wikitude Application Development in Android

The class .setIconresource add an icon for you POI. You can search for the class R.drawable that contains a lot of images of you can use.

That’s all. You have a great AR app with WIKITUDE API.

Have fun!