Tech Talk about my traineeship in Aicas GmbH, which talks abouot an emulator for android apps.
You can find the project at: https://github.com/ammirate/android-wrapper
4. 4
Main question
– Why is not already possible?
Android applications are based on Java but they use own
APIs, that are not compilable by JamaicaVM.
javax.swing.JCompone
nt android.view.View
?
Issues
5. 5
Java code execution
– Windows, Linux and other OS
HARDWARE
(Intel, AMD, ARM)
Operating System
(Windows, Linux, QNX)
Jamaica Runtime Environment
Java API
Class
Jamaica
Virtual
Machine
public class Hello
{
public static void main(String
args[])
{
System.out.println(“Hello World”);
}
}
Issues
6. 6
Java code execution
– Android
HARDWARE
(Intel, ARM)
Linux Kernel
Android API
Class
Dalvik
Virtual
Machine
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle bundle)
{
super.onCreate(savedInstanceState);
TextView textView = (TextView)
findViewById(R.id.textView1);
textView.setText("Hello World");
}
}
Android Runtime Environment
Issues
15. 15
Incompatibilities - 3
Graphics components are not created in the source code but are
declared in the activity_main.xml file.
Incompatibilities with JamaicaVM
16. 16
Proposed Solution
Adapter Design Pattern
– Adapter pattern (also known as Wrapper) allows classes that normally
could not work together, because of incompatible interfaces, to work
together.
Proposed Solution
26. 26
Draw graphic components into the screen
Two phases:
➢Draw graphic components written in the xml
➢Add components to the screen
AndroidWrapper solution - Graphic manager
31. 31
Activity
The Activity adaptee class is responsible to instantiate a
GraphicDrawer and get the graphic from it.
protected void onCreate(Bundle bundle)
{
graphicDrawer = new GraphicDrawer(bundle);
graphicDrawer.generateGraphic();
}
layout1
button1button1
radio1
radio2
text1
group1
AndroidWrapper solution - Wrapper
32. 32
AndroidWrapper
Two simple tasks:
1. Class R =
Class mainActivity =
File xmlFile =
R.java
activity_main.xml
MainActivity.java
2. public static void main(String arg[])
{
mainActivity.onCreate(new
Bundle(R,xmlFile))
}
AndroidWrapper solution - Wrapper
34. 34
Adaptee classes
To work correctly, the Adapter must find the JamaicaVM version of the
classes requested by the MainActivity.
JamaicaRE
android.app.Activity
android.widget.TextView
...
MainActivity.java
import android.app.Activity;
import android.widget.TextView;
....
public void onCreate()
{
......
.....
}
.....
AndroidWrapper solution
37. 37
Negative aspect
Reproduce the whole Android Runtime Environment:
● The number of the classes is very enormous
● The complexity is not always low
AndroidWrapper solution – Adaptee classes
38. 38
– not always:
Three scenarios:
1) Need to write the class from zero
2) Wrap the class with an equivalent one
3) Use the original class
Adaptee classes - complexity
AndroidWrapper solution
39. 39
Mercury
Adaptee classes
1) Write a class from zero
Example: android.widget.ListView
Venus
Earth
Mars
....
JPanel JScrollBar
JLabel
AndroidWrapper solution
40. 40
Adaptee classes
2) Wrap the class with an equivalent one
Example: android.widget.Button
public Class Button extends
JButton
{
public Button(String text)
{
super(text);
}
....
}
AndroidWrapper solution
41. 41
Adaptee classes
3) Use the original class
- When Android classes use only objects of Java
e.g android.util.TextUtils
AndroidWrapper solution
javax.swing
java.awt
java.tools
java.rmi
...
java.io
java.tools
java.util
java.lang
android.app
android.graphics
android.os
android.content
Android API
Java API
47. 47
Adaptee classes
Complexity for reproduce the whole Android Runtime Environment
Complexity
Activity
Classes
Textutils Button TextView
low
medium
high
Parcelable Resources
Use original class
Wrap with equivalent class
Write from zero
average
complexity
...
AndroidWrapper solution