Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android basics. About Android Linux based operating system Open source Designed for handheld devices Developed by Android Inc. Google (2005) Open Handset.

Similar presentations


Presentation on theme: "Android basics. About Android Linux based operating system Open source Designed for handheld devices Developed by Android Inc. Google (2005) Open Handset."— Presentation transcript:

1 Android basics

2 About Android Linux based operating system Open source Designed for handheld devices Developed by Android Inc. Google (2005) Open Handset Alliance (2007) Very successful system (75% sales in 2012)

3 Top mobile operating systems

4 Android basics Can run Java code on Dalvik VM Multi-user system (each application is a different user) Unique user ID Has its own virtual machine Has its own Linux process Principle of least privilege Applications can share data

5 Application components Building blocks of an application 4 types Activity Single screen with UI Service Backgroud process without UI Content provider Manages a shared set of application data Broadcast receiver Responds to system-wide broadcast announcements

6 Applications All components of an application runs in the same process The system tries to keep a process as long as possible Applications are stored in a stack The systems duty to destroy the applications The system uses importance hierarchy Foreground processes Visible process Service process Background process Empty process

7 Activity lifecycle

8 Android development Andriod SDK (http://developer.android.com/sdk) Java API libraries for different platforms SDK manager AVD Manager (emulator) Developer IDE Eclipse with ADT (Juno has it by default) Netbeans with NBAndroid plugin Android device USB Driver Enable USB debugging Useful link:

9 IDE basics NetBeans https://kenai.com/projects/nbandroid/pages/Install https://kenai.com/projects/nbandroid/pages/Intro Eclipse For ADT bundle everything is set up For Juno install is not required, for other existing Eclipse installs: packages.html Add platforms and packages packages.html

10 Set up virtual devices

11 Presets

12 API levels

13

14 New Project (NetBeans)

15 New Project

16

17 AndroidManifest.xml

18 Start a virtual device

19 MainActivity.java: setContentView(R.layout.main); Main.xml Build and run the project

20 OpenGL ES – MainActivity.java import android.app.Activity; import android.opengl.GLSurfaceView; import android.os.Bundle; public class MainActivity extends Activity { private GLSurfaceView public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGLView = new MainSurfaceView(this); setContentView(mGLView); }

21 OpenGL ES – MainSurfaceView.java package gamedev.android.UEngine.PlatformGame; import android.content.Context; import android.opengl.GLSurfaceView; public class MainSurfaceView extends GLSurfaceView { private MainRenderer mRenderer; public MainSurfaceView(Context context) { super(context); this.mRenderer = new MainRenderer(getContext()); setRenderer(this.mRenderer); }

22 OpenGL ES – MainRenderer.java package gamedev.android.UEngine.PlatformGame; import android.content.Context; import android.opengl.GLSurfaceView; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; public class MainRenderer implements GLSurfaceView.Renderer{ private Context context; public MainRenderer(Context context) { this.context = context; } public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glClearColor(0.5F, 0.5F, 1.0F, 1.0F); } public void onDrawFrame(GL10 gl) { gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT ); } public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); }

23 Build and run

24 Draw something - MainRenderer New imports import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; New data member protected FloatBuffer VB = null; public float rotAngle = 0;

25 Draw something - MainRenderer public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glClearColor(0.5F, 0.5F, 1.0F, 1.0F); float[] VCoords = { -1.0F, -1.0F, 0.0F, 1.0F, -1.0F, 0.0F, 1.0F, 1.0F, 0.0F, -1.0F, -1.0F, 0.0F, 1.0F, 1.0F, 0.0F, -1.0F, 1.0F, 0.0F }; ByteBuffer vbb = ByteBuffer.allocateDirect(VCoords.length * 4); vbb.order(ByteOrder.nativeOrder()); this.VB = vbb.asFloatBuffer(); this.VB.put(VCoords); this.VB.position(0); }

26 Draw something - MainRenderer public void onDrawFrame(GL10 gl) { gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT ); gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0,0,-6); gl.glColor4f(1, 0, 0, 1); gl.glRotatef(rotAngle, 0, 1, 0); gl.glEnableClientState(gl.GL_VERTEX_ARRAY); gl.glVertexPointer(3, gl.GL_FLOAT, 0, this.VB); gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6); gl.glDisableClientState(gl.GL_VERTEX_ARRAY); rotAngle += 2.5f; }

27 Draw something - MainRenderer public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); float ratio = (float) width / height; gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, -1, 1, 1.0f, 10); }

28 Build and run

29 Input handling - MainSurfaceView protected float lastX = -1; public boolean onTouchEvent(MotionEvent e) { float x = e.getX(); switch (e.getAction()) { case MotionEvent.ACTION_MOVE: float dx = lastX == -1 ? 0 : x - lastX; mRenderer.rotAngle += dx * 1.0f; break; } lastX = x; return true; } Also remove rotAngle += 2.5f; from MainRenderer.onDrawFrame

30 Build and run Quad can be rotated with the mouse in emulator

31 Orientation – Full screen Fix orientation to landscape (typical in games) Activity::onCreate(): setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); Set to full screen (typical in games) Activity::onCreate(): requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); Rotate emulator to landscape mode: Ctrl+F12

32 Compile and run

33


Download ppt "Android basics. About Android Linux based operating system Open source Designed for handheld devices Developed by Android Inc. Google (2005) Open Handset."

Similar presentations


Ads by Google