SE 390: Software Engineering for Mobile Devices

idleheadedceleryΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 3 χρόνια και 10 μήνες)

70 εμφανίσεις

SE 390: Software Engineering for Mobile Devices

Week 14: Course Review

Copyright © Steven W. Johnson

February 1, 2013

Review the course
(Android only)

Preparation for final exam


Week 14:

2

Founded
(2003)
by:

Andy Rubin
(Danger)

Rich Miner
(Wildfire Communications)

Nick Sears
(T
-
Mobile)

Chris White
(WebTV)

What is Android?

3

http://www.ebellking.com

Linux
-
based operating system
(Linux OS
2.60)

Development platform
(SDK)
for mobile devices

Original: OS for touch screen devices
(phones)

Bought out by Google in 2005
(due to iPhone?)

Android
was and is open source

Major OS for handheld
devices

Distributed 2007

Devices sold with Android: 2008

What is Android?

4

Lots of ways to make Android applications:

Android Development Kit
(command line tool)

Android IDE
(AIDE)

Eclipse

Maven
(plugin from Apache)

Visual Studio
(in C/C#)

What is Android?

5

What is Android?

6

2003

2005

2007

2010

iPhone

1999

Apple has contained issues:

apple has limited products

control
iOS
, software

centrally managed

Android’s problems uncontained:

updates to the OS

device incompatibilities

driven by innovation, marketplace

What is Android?

7

Open source: ‘pure capitalism’

Apple: ‘pure socialism


Google/Nexus: “Blended approach”

What is Android?

8

Android apps written using:

Java

XML

What is Android
?

9

RTE

Dalvik

VM

Core files in Android:

What is Android
?

10

layout/main.xml

class.java

AndroidManifest.xml

Goal: minimize Java, maximize XML

Method: replace Java with XML

How is Android built?

11

class.java

layout.xml

AndroidManifest.xml

arrays.xml

colors.xml

strings.xml

styles.xml

Images go in
/res/
drawable

folder

Image types:

.
png

(preferred)

.jpg

Images called by file name only

Image file names: numbers, lower case letters

File called by name only; not extension

How is Android built?

12

Organization of resources

Don’t mess with folder structure

‘res’ folder holds resources

animations

images

menus

values folder:

strings.xml

colors.xml

How is Android built?

13

Compilation settings:

How is Android built?

14

L
ayout describes how elements are added

Layout used is defined in /res/layout

linear

relative

table

grid view

tab

list view

Layouts:

15

No layout:

elements stack on top of each other

Layouts:

16

Linear:

laid out in a single row or column
(not both)

Layouts:

17

<
LinearLayout




android:orientation
=
"
vertical" >


</
LinearLayout
>

main.xml

Layouts:

18

<
LinearLayout

xmlns:android
="http://schemas.android.com/
apk
/res/android"


android:layout_width
="
fill_parent
"



android:layout_height
="
fill_parent
"


android:orientation
="horizontal" >





<
Button
android:id
="@+id/button1"


android:layout_width
="
wrap_content
"


android:layout_height
="
wrap_content
"


android:text
=“@string/one"
/>





<
Button
android:id
="@+id/button2"


android:layout_width
="
wrap_content
"


android:layout_height
="
wrap_content
"


android:text
=“@string/two"
/>




</
LinearLayout

Click me

No, click me

Relative:

In relation to another element; parent element

Layouts:

19

Relative:

In relation to another element; parent element

Layouts:

20

text1

text2

text3

text4

Text2:

android:layout_alignLeft
=
"@+
id/text1“

android:layout_marginTop
=
"17dp"

Text3:

android:layout_alignLeft
=
"@+
id/text1"

android:layout_marginTop
=
"17dp"

Text4:

android:layout_alignTop
=
"@+id/text3"

android:layout_marginLeft
=
“51dp"

Table:

like an HTML table

create “td” elements

e
ach ‘td’ has row/column

fill

Layouts:

21

<
TableLayout
>



<
TableRow
></
TableRow
>

</
TableLayout

Table can be managed with
stretchColumns

Forces table to fill screen; elements to fill cell

Layouts:

22

stretchColumns
=
"1"

http://androidcaps.blogspot.com/2012/05/androidstretchcolumns
-
tablelayout.html

Width is controlled by:

parent element

contents

Widths:

23

match_parent

or

fill_parent

wrap_content

Android: four sizes to consider

Pixel densities listed
(“bucketed” densities):

ldpi


120px per inch

mdpi


160px per inch

hdpi


240px per inch

xhdpi


320px per inch

Problem: varying sizes on different devices

dp
:

24

If measurement in pixels, different lengths

Example: 320 pixel line defined in pixels:

ldpi

120px

2.67”

mdpi

160px

2”

hdpi

240px

1.33”

xhdpi

320px

1”

dp
:

25

Pseudo
-
measure
(not real measures):

px
: a pixel or picture element

sp
: scale
-
independent pixel

dp
/dip: density
-
independent pixel

sp
/
dp
/dip are Android measures

Draws the same shape regardless of pixel density

Distance relative to 160 pixels per inch

dp
:

26

dp
: a consistent measurement system

dp
: considers pixel density of the rendering unit

length
(
px
)
= ratio *
dp


dp

= length
(
px
)

/ ratio

160dp
= 1” on all devices


80dp
= ½” on all devices



dp
:

27

Size

Density

Unit density/160

dp

Line length(
px
)

ldpi

120px

1”

ㄲ1⼱㘰

ㄶ1

ㄲばx

mdpi

160px

1”

ㄶ〯ㄶ1

ㄶ1

ㄶばx

桤灩

㈴ばx

1”

㈴〯ㄶ2

ㄶ1

㈴ばx

硨x灩

㌲ばx

1”

㌲〯ㄶ3

ㄶ1

㌲ばx

same idea as
dp
;
sp

for font size only

Scalable
(independent)
pixels

Scales to normal font size of device

Based in 160 = 1”

20sp = 12px font size
(96px)

sp

=
px

* ratio * scale
(if used
)

Scale is determined by end user

sp
:

28

sp
:

29

Text on page

zoom/view = 1

20sp (12px or 8 lines to inch)

320ppi device: 20 * 320/160 * 1 = 40px

Text on page

zoom/view = 1.2

20sp (12px or 8 lines to inch)

320ppi device: 20 * 320/160 * 1.2 = 48px

Text on page

EditText
:

Element definitions:

30

<
EditText


android:id
=
"@+id/editText2"


android:layout_width
=
"
match_parent
"


android:layout_height
=
"
wrap_content
"


android:layout_gravity
=
"center"


android:gravity
=
"center"


android:text
=
"@string/text"



android:background
="@string/purple"


android:ems
=
"
10"



<
requestfocus

/>

/>

Importing classes

Each widget requires a class definition

Class components:

31

import
android.os.Bundle
;

import
android.app.Activity
;

import
android.view.Menu
; //optional


import
android.view.View
;

import
android.widget.Button
;

import
android.widget.EditText
;

import
android.widget.TextView
;

Class components

32

EditText

inputdata
;

TextView

outputdata
;

Button
button
;


public
class Main extends Activity {


@Override

protected void
onCreate
(Bundle
savedInstanceState
) {


super.onCreate
(
savedInstanceState
);


setContentView
(
R.layout.
main
);



inputdata

= (
EditText
)
findViewById
(
R.id.
textinput
);


outputdata

= (
TextView
)
findViewById
(
R.id.
answer
);


button
= (Button)
findViewById
(
R.id.
button
);




button.setOnClickListener
(new
Button.OnClickListener
() {



public
void
onClick
(View v) {



String
answer =
inputdata.getText
().
toString
();



outputdata.setText
(answer
);



}


});

}

Styles and themes:

33

Android 4
(API v11):
new design trend ‘
holo


goal: help with the design issues

give apps consistent look and feel

same style as other Google initiatives

Idea: structure is defined; change attributes

all apps have a similar look and feel

http://theultralinx.com/2012/11/android
-
apps
-
holo
-
theme
-
concepts.html

Styles and themes:

34

AndroidManifest

determines versions supported

a
nd themes used


<application


android:allowBackup
=
"true"


android:icon
=
"@
drawable
/
ic_launcher
"


android:label
=
"@string/
app_name
"


android:theme
=
"@style/
AppTheme
" >


<activity


android:name
=
"
com.example.themes.MainActivity
"


android:label
=
"@string/
app_name
" >


<intent
-
filter>


<action
android:name
=
"
android.intent.action.MAIN
" />



<category
android:name
=
"
android.intent.category.LAUNCHER
" />


</intent
-
filter>


</activity>


</application>


</manifest>

Styles and themes:

35

Also defines number of activities


<application


android:allowBackup
=
"true"


android:icon
=
"@
drawable
/
ic_launcher
"


android:label
=
"@string/
app_name
"


android:theme
=
"@style/
AppTheme
" >


<activity


android:name
=
"
com.example.themes.MainActivity
"


android:label
=
"@string/
app_name
" >


<intent
-
filter>


<action
android:name
=
"
android.intent.action.MAIN
" />



<category
android:name
=
"
android.intent.category.LAUNCHER
" />


</intent
-
filter>


</activity>


</application>


</manifest>

Styles and themes:

36

Give a common look, feel to Views

Style data held on ‘styles.xml’ in style tag

<?xml version=“1.0” encoding=“utf
-
8”?>

<resources>


<style name=“
base_text
”>


<item name=“
android:textSize
”>20sp</item>


<item name=“
android:textColor
”>#111</item>


</
style>



<style name=“
small_text
” parent=“
base_text
”>



<
item name=“
android:textSize
”>12sp
</item
>


</style>

</
resources>

Style:

A defined XML resource
(not part of the layout)


Styles and themes:

37

<
TextView





android:layout_width
="
fill_parent
"





android:layout_height
="
wrap_content
"





android:textColor
="#00FF00"





android:typeface
="
mistral"



android:textSize
="40sp" // 1/4”



//
android:textSize
="24px" //1/4” @ 96ppi



//style="@
android:style
/
TextAppearance.Large
"





android:text
="@
string/line1"
/>

<string name="line1">Today is Tuesday</string>

Today is Tuesday

Colors:

38

Described using 6 hex characters or 8

6: normal RGB color

8: alpha
-
alpha
-
RGB

‘FF’ is fully opaque

‘00’ is fully transparent

#FF0000

#FFFF0000

No ability to directly use system fonts

Android will accept any TrueType font

Must load the font file into your app.

Typeface object used to define/use

Font accessed by .java class; used by layout.xml

Fonts and Android

39

.java class:


Typeface font =
Typeface.createFromAsset
(
getAssets
(), "Ravie.ttf");

TextView

tv
=(
TextView
)
findViewById
(R.id.textView0
);

tv.setTypeface
(font);

Drawing rounded corners and gradients:

Gradients & rounded rectangles:

40

/res/
drawable
/rounded_corner_box.xml


<?
xml version="1.0" encoding="utf
-
8"?>

<
shape
xmlns:android
="http://schemas.android.com/
apk
/res/android"

android:shape
="rectangle">


<
gradient
android:startColor
="#80000000"

android:endColor
="#80FFFFFF"

android:angle
="45"/>


<
padding

android:left
="7dp"

android:top
="7dp"

android:right
="7dp"

android:bottom
="7dp" />


<
corners
android:radius
="8dp" />

</
shape>

android:background
="@
drawable
/
rounded_corner_box
"

Can’t assume full attention on mobile devices

Interface and messaging must be even better

Exception handling:

41

Dialogs, Alerts,
DialogAlerts
:

like confirm boxes

may turn on services
(Internet connection)

Popups
: a branch in the workflow

captures a single selection from user

no buttons; merely
(single)
selection
choices

Toasts:

like timed alert boxes

lightweight
feedback in a timed
popup

Exception handling:

42

Misused, overused, and fell out of favor

Original use: cover up slow loading speeds

Today:

mainly branding of a site
(logo)

use on ego site

Splash screens:

43

A design conundrum
(problem):

which page is the ‘main’ page?

auto
-
loading page is ‘main’

if use a splash page, it must be ‘main’

Splash screens:

44

A design conundrum
(problem):

app should start in less than 2 seconds

not enough time for a splash screen

If you need a splash screen, program too large

Splash screen: poor design attempting to cover

up poor programming

Splash screens:

45

Based in ‘sandbox’:

guarantees user experience not degraded

cannot harm other software

cannot access other data

Android security model:

Android based in Linux

privilege
-
separated OS

security by isolation

each app has its own system identity

Android security model:

46

Android security model:

47

app

app

app

app

OS

Android security model:

48

Application/resources not shared:

apps cannot communicate with OS

apps cannot communicate with other
apps

Corruption in one entity cannot spread to others


Android security model:

49

Data stored by app is tied to the app’s user ID

Android security model:

50

ID = 4R78vx85

ID = D584e467

ID = D584e467

Name:
firstName

Value: ??

ID = 4R78vx85

Name:
firstName

Value: Steve

Android security model:

51

Application/resources not shared:

apps cannot get to user data

apps
cannot
directly access services

Hey router!

Tell H
ırsız

Hulya

at IP 123.5.5.1

the credit card number is

123456

Okay!!

Permissions used to:

access to resources/data not in the sandbox

pass data out of sandbox; through a resource

Default: Android apps have no permissions

Several permissions can be requested

Android asks for consent on installation

Permissions:

52

Used to describe an intention:

open another activity

Passive data object
(a group of instructions):

d
escription of a future action

passes action’s necessary data:

data types

flags

constants

More on intents:

53

SE 390: Software Engineering for Mobile Devices

Week 14: Course Review

Copyright © Steven W. Johnson

February 1, 2013