Praktikum Entwicklung von Mediensystemen mit Android

32
LFE Medieninformatik Prof. Dr. Heinrich Hußmann (Dozent), Alexander De Luca, Gregor Broll (supervisors) Praktikum Entwicklung von Mediensystemen mit Android Implementing a User Interface

Transcript of Praktikum Entwicklung von Mediensystemen mit Android

Page 1: Praktikum Entwicklung von Mediensystemen mit Android

LFE Medieninformatik Prof. Dr. Heinrich Hußmann (Dozent), Alexander De Luca, Gregor Broll (supervisors)

Praktikum Entwicklung vonMediensystemen mit AndroidImplementing a User Interface

Page 2: Praktikum Entwicklung von Mediensystemen mit Android

Outline

• Introduction• Layouting Components using XML• Common Layout Objects• Hooking into a Screen Element• Listening for UI Notifications• Applying a Theme to Your Application

Page 3: Praktikum Entwicklung von Mediensystemen mit Android

Introduction

• ActivityBasic functional unit of an Android applicationBut by itself, it does not have any presence on the screen

• Views and ViewgroupsBasic units of user interface expression on the Android platform

Page 4: Praktikum Entwicklung von Mediensystemen mit Android

ViewsIntroduction

• android.view.ViewStores layout and content for a specific rectangular area of the screenHandles measuring and layout, drawing, focus change, scrolling, and key/gesturesBase class for widgets

TextEditTextInputMethodMovementMethodButtonRadioButtonCheckboxScrollView

Page 5: Praktikum Entwicklung von Mediensystemen mit Android

ViewgroupsIntroduction

• android.view.ViewgroupContains and manages a subordinate set of views and other viewgroupsBase class for layouts

Page 6: Praktikum Entwicklung von Mediensystemen mit Android

Tree-Structured UIIntroduction

• An Activity in AndroidDefined using a tree of view and viewgroup nodes

• setContentView() methodCalled by the Activity to attach the tree to the screen for rendering

Page 7: Praktikum Entwicklung von Mediensystemen mit Android

LayoutParamsIntroduction

• Every viewgroup class uses a nested class that extends ViewGroup.LayoutParams

Contains property types that defines the child’s size and position

Page 8: Praktikum Entwicklung von Mediensystemen mit Android

Programmatic UI Layout

• Programmatic UI LayoutConstructing and building the applications UI directly from source codeDisadvantage

small changes in layout can have a big effect on the source code

Page 9: Praktikum Entwicklung von Mediensystemen mit Android

Upgrading UI to XML Layout

• XML-based LayoutInspired by web development model where the presentation of the application’s UI is separated from the logicTwo files to edit

Java file – application logicXML file – user interface

Page 10: Praktikum Entwicklung von Mediensystemen mit Android

Upgrading UI to XML Layout

Page 11: Praktikum Entwicklung von Mediensystemen mit Android

Upgrading UI to XML Layout

Page 12: Praktikum Entwicklung von Mediensystemen mit Android
Page 13: Praktikum Entwicklung von Mediensystemen mit Android

Common Layout Objects

• FrameLayout• LinearLayout• TableLayout• AbsoluteLayout• RelativeLayout

Page 14: Praktikum Entwicklung von Mediensystemen mit Android

FrameLayoutCommon Layout Objects

• Simplest layout object • Intended as a blank reserved space on your screen

that you can later fill with a single object Example: a picture that you'll swap out

• All child elements are pinned to the top left corner of the screen

• Cannot specify a location for a child element

Page 15: Praktikum Entwicklung von Mediensystemen mit Android

LinearLayoutCommon Layout Objects

• Aligns all children in a single direction —vertically or horizontally

All children are stacked one after the other

a vertical list will only have one child per row (no matter how wide they are)a horizontal list will only be one row high (the height of the tallest child, plus padding)

Page 16: Praktikum Entwicklung von Mediensystemen mit Android

TableLayoutCommon Layout Objects

• Positions its children into rows and columns

• Does not display border lines for their rows, columns, or cells

• Cells cannot span columns, as they can in HTML

Page 17: Praktikum Entwicklung von Mediensystemen mit Android

AbsoluteLayoutCommon Layout Objects

• Enables children to specify exact x/y coordinates to display on the screen

(0,0) is the upper left cornervalues increase as you move down or to the right

• Overlapping elements are allowed (although not recommended)

• NOTE:It is generally recommended NOT to use AbsoluteLayout UNLESS you have good reasons to use itIt is because it is fairly rigid and does not work well with different device displays

Page 18: Praktikum Entwicklung von Mediensystemen mit Android

RelativeLayoutCommon Layout Objects

• Lets children specify their position relative to each other (specified by ID), or to the parent

Page 19: Praktikum Entwicklung von Mediensystemen mit Android

Online Referencehttp://developer.android.com/guide/tutorials/views/index.html

Page 20: Praktikum Entwicklung von Mediensystemen mit Android

Hooking into a Screen Element

Text field

Button

Page 21: Praktikum Entwicklung von Mediensystemen mit Android

Hooking into a Screen Element

Page 22: Praktikum Entwicklung von Mediensystemen mit Android

@+id syntax:Creates a resource number in the R class (R.java file) if one doesn't exist, or uses it if it does exist.

Any String value(no spaces)

Hooking into a Screen Element

Page 23: Praktikum Entwicklung von Mediensystemen mit Android

Hooking into a Screen Element

Page 24: Praktikum Entwicklung von Mediensystemen mit Android

Hooking into a Screen Element

Page 25: Praktikum Entwicklung von Mediensystemen mit Android

Hooking into a Screen Element

Page 26: Praktikum Entwicklung von Mediensystemen mit Android

Listening for UI Notifications

Page 27: Praktikum Entwicklung von Mediensystemen mit Android

Applying a Theme to Your Application

• Default theme: android.R.style.Themehttp://developer.android.com/reference/android/R.style.html

• Two ways to set the themeAdding the theme attribute in AndroidManifest.xmlCalling setTheme() inside the onCreate() method

Page 28: Praktikum Entwicklung von Mediensystemen mit Android

Editing AndroidManifest.xmlApplying a Theme to Your Application

• Adding the theme attribute in AndroidManifest.xml

Page 29: Praktikum Entwicklung von Mediensystemen mit Android

Calling setTheme()Applying a Theme to Your Application

• Calling setTheme() inside the onCreate() method

Page 30: Praktikum Entwicklung von Mediensystemen mit Android

Theme_Black Theme_Light

Page 31: Praktikum Entwicklung von Mediensystemen mit Android

Exercise•Chatting with Myself Application

ComponentsImageText that displays the NameDrop down box that displays the

statusoAvailableoBusyoAway

Text Area that displays messagesoFormat for the output is

□ChatterName:The Message

Text Field where the user can type the messageSend Button

oWhen Pressed□Message typed on the text field is displayed on the text area□Text field is cleared

•Any improvements on the design or additional functionality is encouraged

Page 32: Praktikum Entwicklung von Mediensystemen mit Android

Fragen?Viel Spaß!