Tutorial - Hello World
Overview
This tutorial will guide you step by step on how to create your first 'Hello World' Raptor application from scratch
Note: You must complete your environment setup as described in the Setting up your environment page
Step 1 - Module Creation
Creating the Module
- Open Android Studio
- Create a new Module:
File->New Module
- Select the
Phone & Tablet Module
- Click 'Next'
- Enter your application details
- Set the minimum SDK to API 22
- Click 'Next'
- Select "Add No Activity"
- Click 'Next'
Updating Default Module Files
- Update AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.helloworld">
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
tools:ignore="GoogleAppIndexingWarning">
</application>
</manifest>
- Update build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.helloworld"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
}
repositories {
mavenCentral()
flatDir {
dirs '../../libs'
}
}
dependencies {
implementation(name: 'evsBase', ext: 'aar')
}
- Delete the content of style.xml:
<resources>
</resources>
Step 2 - Activity Creation
Creating the Activity
- Create new Activity:
File->New->Android->Empty Activity
- Enter the Activity details as follows:
- Check 'Launcher Activity'
- Un-check 'Backwards Compatibility'
- Verify Source Language: Java
- Click 'Finish'
Extending EvsBaseActivity
- Open the
HelloWorldActivity.java
file - Extend from EvsBaseActivity:
public class HelloWorldActivity extends EvsBaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
}
}
Adding some gestures handling
- Within the Activity class, override the
onTap()
method:
public class HelloWorldActivity extends EvsBaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
}
@Override
public void onTap() {
super.onTap();
EvsToast.show(this,"Nice Tap!\nSwipe down to Exit");
}
}
Setting your Activity Layout
- Open the Activity Layout xml
activity_hello_world.xml
- Edit the layout file as follows:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/black">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/mainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_horizontal|center_vertical"
android:text="@string/app_name"
android:textColor="@color/evsGreen"
android:textSize="25dp"/>
</LinearLayout>
</FrameLayout>
Step 3 - Update Module Manifest
- Update your Module manifest to include your activity
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.helloworld">
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".HelloWorldActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Step 4 - Install & Run
Your application is ready!
Connect your Raptor to your PC and run the application from Android Studio
In the select deployment target please select your raptor
After the application was loaded, tap the Raptor's touch pad to view the Toast
(the onTap()
method will be called) or Swipe down to exit the application
Good Luck!