Creating A Vaandroid Application From Scratch

This tutorial creates a basic Vaandroid application.

Overview

This tutorial creates a Vaandroid application that contains a text input field, and button. When the button is pressed, an alert message is displayed.

We will use the Vaandroid Gradle Plugin to make the process super easy.

Create The Gradle Project

Create an empty folder containing 2 files: settings.gradle and build.gradle. This is a basic Gradle project setup with 1 plugin, the Vaandroid Gradle plugin, applied.

settings.gradle

pluginManagement {
    repositories {
        maven { url 'https://repo.twelvetone.tv' }
        gradlePluginPortal()
    }
}

build.gradle

plugins {
    id 'vaandroid.plugin' version '1.0'
}

repositories {
    mavenLocal()
    mavenCentral()
}

vaandroid {
    // Not required if you use Gradle project group and name as your package name
    pkg = 'com.test.mypackage'
}

Create The Application

Run the create_vaandroid_application task. It will create the following files:

  • AndroidManifest.xml
  • A res directory with various Android resources
  • MySampleActivity.java
  • R.java (withing the generated directory)

In addition, there are 2 Vaandroid specific files

  • vaandroid.xml
  • PluginImpl.java

If all goes well, you should have an application in the /build/libs directory.

Launch The Server

Run the launch_cloud_server task. A server will be built and launched in a terminal window.

Open a web brower to [https://localhost:8443] to view the server. Click the ''Login Button'' to navigate to the home screen.

Run deploy_to_cloud_server to install your new app. This task simply copies your jar file into the build/karaf/deploy directory. You should see your application appear on the home screen.

Update The Application Layout

Replace the contents of /res/layout/activity_template.xml with the following standard Android layout code. Then run deploy_to_cloud_server.

{CODE(colors="xml")}<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp">

<EditText
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine"
    android:lines="3"
    />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Submit"/>

{CODE}

Update The Application Logic

Replace MySampleActivity with this code, and then run deploy_to_cloud_server.

{CODE(wrap="0" colors="groovy")}package tv.twelvetone.vaandroid.test.my_sample_application

import android.os.Bundle import android.widget.Button import android.widget.TextView import android.widget.Toast import tv.twelvetone.vaandroid.api.android.VaandroidActivity

class MySampleActivity extends VaandroidActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState) setContentView R.layout.activity_template

    TextView textView = findViewById(R.id.text)
    Button button = findViewById(R.id.button)

    button.setOnClickListener({
        Toast.makeText(this, textView.getText(), Toast.LENGTH_SHORT).show()
    })
}

}{CODE}