PROGRAMMING APPLICATIONS DECLARATIVE GUIS

Size: px
Start display at page:

Download "PROGRAMMING APPLICATIONS DECLARATIVE GUIS"

Transcription

1 PROGRAMMING APPLICATIONS DECLARATIVE GUIS

2

3

4

5 DIVING RIGHT IN

6

7 Eclipse? Plugin deprecated :-(

8 Making a new project

9

10

11 This keeps things simple

12 or clone

13 or clone

14 or clone

15 or clone

16 or clone

17 or clone

18 Try it now:

19 Try it now:

20 Try it now:

21

22 Really, an Android application is just a set of files in folders

23 I find the Android view most useful

24

25

26 <manifest xmlns:android=" res/android" package="uk.co.martinchapman.programmaticui"> <application android:allowbackup="true" android:supportsrtl="true" </application> </manifest> ANDROIDMANIFEST.XML

27 <manifest xmlns:android=" res/android" package="uk.co.martinchapman.programmaticui"> <application android:allowbackup="true" android:supportsrtl="true" </application> </manifest> ANDROIDMANIFEST.XML

28 STOLEN WITH <3 FROM W3SCHOOLS

29 STOLEN WITH <3 FROM W3SCHOOLS

30 STOLEN WITH <3 FROM W3SCHOOLS

31 STOLEN WITH <3 FROM W3SCHOOLS

32 STOLEN WITH <3 FROM W3SCHOOLS

33 Not used by the parser, simply used to `declare the namespace uniquely STOLEN WITH <3 FROM W3SCHOOLS

34 <manifest xmlns:android=" res/android" package="uk.co.martinchapman.programmaticui"> <application android:allowbackup="true" android:supportsrtl="true" </application> </manifest> ANDROIDMANIFEST.XML

35 <manifest xmlns:android=" res/android" package="uk.co.martinchapman.programmaticui"> <application android:allowbackup="true" android:supportsrtl="true" </application> </manifest> ANDROIDMANIFEST.XML

36 <manifest xmlns:android=" res/android" package="uk.co.martinchapman.programmaticui"> <application android:allowbackup="true" android:supportsrtl="true" </application> </manifest> Whenever we see symbol, we re typically referring to a resource file. ANDROIDMANIFEST.XML

37

38

39

40 Anything else that needs to be drawn should be placed in the drawable folder

41 <manifest xmlns:android=" res/android" package="uk.co.martinchapman.programmaticui"> <application android:allowbackup="true" android:supportsrtl="true" </application> </manifest> ANDROIDMANIFEST.XML

42

43 <resources> <!-- Base application theme. --> <style name="apptheme" parent="theme.appcompat.light.darkactionbar"> <!-- Customize your theme here. --> <item <item <item </style> </resources> <?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorprimary">#3f51b5</color> <color name="colorprimarydark">#303f9f</color> <color name="coloraccent">#ff4081</color> </resources>

44 <resources> <!-- Base application theme. --> <style name="apptheme" parent="theme.appcompat.light.darkactionbar"> <!-- Customize your theme here. --> <item <item <item </style> </resources> <?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorprimary">#3f51b5</color> <color name="colorprimarydark">#303f9f</color> <color name="coloraccent">#ff4081</color> </resources> More about the string resource later

45 <manifest xmlns:android=" res/android" package="uk.co.martinchapman.programmaticui"> <application android:allowbackup="true" android:supportsrtl="true" </application> </manifest> ANDROIDMANIFEST.XML

46 <manifest xmlns:android=" res/android" package="uk.co.martinchapman.programmaticui"> <application android:allowbackup="true" android:supportsrtl="true" </application> </manifest> ANDROIDMANIFEST.XML

47

48 WHAT MAKES AN ANDROID APP?

49 A collection of Screens

50 What is a Screen?

51 Every Android app is a collection of Screens, and each screen is comprised of an Activity and a Layout. What is a Screen?

52 What is an Activity?

53 What is an Activity? An Activity is a single, defined feature that a user can interact with, which is usually associated with an individual Screen in an application.

54 What is an Activity? An Activity is a single, defined feature that a user can interact with, which is usually associated with an individual Screen in an application.

55

56

57

58 What is a layout?

59 Part of the activity? What is a layout?

60

61

62 package uk.co.martinchapman.programmaticui; import android.app.activity; import android.os.bundle; /** * Created by Martin on 07/03/16. */ public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } } PROGRAMMATIC.JAVA

63 package uk.co.martinchapman.programmaticui; import android.app.activity; import android.os.bundle; /** * Created by Martin on 07/03/16. */ public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } } PROGRAMMATIC.JAVA

64

65 Just a Java class, but becomes an Activity through inheritance

66 Just a Java class, but becomes an Activity through inheritance Encapsulates the complexities of application initialisation (UI drawing etc.)

67 package uk.co.martinchapman.programmaticui; import android.app.activity; import android.os.bundle; /** * Created by Martin on 07/03/16. */ public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } } More about this in the final version of Snake PROGRAMMATIC.JAVA

68 Specifies that this is the main Activity of the app, and that it can be used to launch the app. <activity android:name=".programmatic"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> ANDROIDMANIFEST.XML

69 <activity android:name=".programmatic"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> Intents are used by Activities to send messages to one another ANDROIDMANIFEST.XML

70 HOW DO WE RUN AN APPLICATION?

71 1 2 3

72 1 2 3

73

74

75

76

77 Smaller and designed to run on a register-based processor

78

79

80

81

82

83

84 If you close the emulator, you re going to be waiting for a little while!

85 If I were to run my application now

86 If I were to run my application now NOTE: It can be tricky to get the emulator setup correctly. Don t worry if you can t actually run anything today.

87 What if we want a UI that looks like this?

88 HOW WOULD WE DO THIS IN SWING?

89 EXERCISE: Take a few minutes to code a Swing GUI that resembles this screenshot

90 setlayout(new BorderLayout()); JPanel centre = new JPanel(); centre.setlayout(new GridLayout(0, 1)); JPanel centretop = new JPanel(); centretop.setlayout(new FlowLayout(FlowLayout.CENTER)); centretop.add(new JLabel("Hello World")); JPanel centrebottom = new JPanel(); centrebottom.setlayout(new FlowLayout(FlowLayout.CENTER)); centrebottom.add(new JButton("HELLO WORLD")); centre.add(centretop); centre.add(centrebottom); add(centre, BorderLayout.CENTER);

91 package uk.co.martinchapman.programmaticui; import android.app.activity; import android.content.res.resources; import android.os.bundle; import android.util.typedvalue; import android.widget.button; import android.widget.relativelayout; import android.widget.textview; /** * Created by Martin on 07/03/16. */ public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); Button button = new Button(this); button.settext("hello World"); button.setid(r.id.one); TextView textview = new TextView(this); textview.settext("hello World"); Translating this to an Android Activity PROGRAMMATIC.JAVA

92 Feels like Swing! button.setid(r.id.one); TextView textview = new TextView(this); textview.settext("hello World"); textview.setid(r.id.two); RelativeLayout layout = new RelativeLayout(this); RelativeLayout.LayoutParams buttonparams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); buttonparams.addrule(relativelayout.center_horizontal); buttonparams.addrule(relativelayout.center_vertical); RelativeLayout.LayoutParams textparams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); PROGRAMMATIC.JAVA

93 } } textparams.addrule(relativelayout.above, button.getid()); textparams.addrule(relativelayout.center_horizontal); layout.addview(button, buttonparams); layout.addview(textview, textparams); setcontentview(layout); But what s wrong with this for a mobile device? PROGRAMMATIC.JAVA

94 WHAT ARE THE DRAWBACKS OF PROGRAMMATICALLY SPECIFYING AN ANDROID LAYOUT?

95 WHAT ARE THE DRAWBACKS OF PROGRAMMATICALLY SPECIFYING AN ANDROID LAYOUT? Difficult to account for orientation and screen resolution The former must be done with IF statements, while the latter usually requires a conversion from density pixels to regular pixels, in line with the format required by the relevant methods

96 WHAT ARE THE DRAWBACKS OF PROGRAMMATICALLY SPECIFYING AN ANDROID LAYOUT? Difficult to account for orientation and screen resolution The former must be done with IF statements, while the latter usually requires a conversion from density pixels to regular pixels, in line with the format required by the relevant methods Difficult to account for localisation Successful applications will be used in many different countries

97 WHAT ARE THE DRAWBACKS OF PROGRAMMATICALLY SPECIFYING AN ANDROID LAYOUT?

98 WHAT ARE THE DRAWBACKS OF PROGRAMMATICALLY SPECIFYING AN ANDROID LAYOUT? Lots to write Reminiscent of an intricate Swing GUI

99 WHAT ARE THE DRAWBACKS OF PROGRAMMATICALLY SPECIFYING AN ANDROID LAYOUT? Lots to write Reminiscent of an intricate Swing GUI Poor separation in our application What about everything we just learned about MVC?

100 Let s update our definition What is a layout?

101 Let s update our definition A layout describes the appearance of the screen, in a file that is both separate from our Java Activity, and written in a different language. What is a layout?

102 Let s update our definition A layout describes the appearance of the screen, in a file that is both separate from our Java Activity, and written in a different language. What is a layout?

103

104 By having a separate file, we can achieve a conceptual separation between presentation and control

105 Poor separation in our application What about everything we just learned about MVC? By having a separate file, we can achieve a conceptual separation between presentation and control

106 There is one important thing to take away from this though package uk.co.martinchapman.programmaticui; import android.app.activity; import android.content.res.resources; import android.os.bundle; import android.util.typedvalue; import android.widget.button; import android.widget.relativelayout; import android.widget.textview; /** * Created by Martin on 07/03/16. */ public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); Button button = new Button(this); button.settext("hello World"); button.setid(r.id.one); TextView textview = new TextView(this); textview.settext("hello World"); PROGRAMMATIC.JAVA

107 There is one important thing to take away from this though package uk.co.martinchapman.programmaticui; import android.app.activity; import android.content.res.resources; import android.os.bundle; import android.util.typedvalue; import android.widget.button; import android.widget.relativelayout; import android.widget.textview; /** * Created by Martin on 07/03/16. */ public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); Button button = new Button(this); button.settext("hello World"); button.setid(r.id.one); TextView textview = new TextView(this); textview.settext("hello World"); PROGRAMMATIC.JAVA

108 There is one important thing to take away from this though package uk.co.martinchapman.programmaticui; import android.app.activity; import android.content.res.resources; import android.os.bundle; import android.util.typedvalue; import android.widget.button; import android.widget.relativelayout; import android.widget.textview; /** * Created by Martin on 07/03/16. */ public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); Button button = new Button(this); button.settext("hello World"); button.setid(r.id.one); TextView textview = new TextView(this); textview.settext("hello World"); PROGRAMMATIC.JAVA

109 There is one important thing to take away from this though package uk.co.martinchapman.programmaticui; import android.app.activity; import android.content.res.resources; import android.os.bundle; import android.util.typedvalue; import android.widget.button; import android.widget.relativelayout; import android.widget.textview; /** * Created by Martin on 07/03/16. */ public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); Button button = new Button(this); button.settext("hello World"); button.setid(r.id.one); TextView textview = new TextView(this); textview.settext("hello World"); A new set of names to learn PROGRAMMATIC.JAVA

110

111

112

113

114

115

116

117

118 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_PROGRAMMATIC.XML

119 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> Before, we made the view elements ourselves, now we are instructing Android <TextView about which elements we want on our android:layout_width="wrap_content" screen. Hence the term declarative GUI. android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_PROGRAMMATIC.XML

120 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> Before, we made the view elements ourselves, now we are instructing Android <TextView about which elements we want on our android:layout_width="wrap_content" screen. Hence the term declarative GUI. android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button Lots to write android:layout_width="wrap_content" android:layout_height="wrap_content" Reminiscent of an intricate Swing GUI android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_PROGRAMMATIC.XML

121

122

123

124 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_PROGRAMMATIC.XML

125 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_PROGRAMMATIC.XML

126 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_PROGRAMMATIC.XML

127 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_PROGRAMMATIC.XML

128 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_PROGRAMMATIC.XML

129

130

131

132 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_PROGRAMMATIC.XML

133 What s wrong with this? package uk.co.martinchapman.programmaticui; import android.app.activity; import android.content.res.resources; import android.os.bundle; import android.util.typedvalue; import android.widget.button; import android.widget.relativelayout; import android.widget.textview; /** * Created by Martin on 07/03/16. */ public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); Button button = new Button(this); button.settext("hello World"); button.setid(r.id.one); TextView textview = new TextView(this); textview.settext("hello World"); PROGRAMMATIC.JAVA

134 The solution?

135 The solution?

136 <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">programmatic</string> <string name="hello_world">hello world!</string> </resources> STRINGS.XML

137 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> Flexibility to change multiple parts of our program from a single source and ACTIVITY_PROGRAMMATIC.XML

138 Allows us to specify multiple string files for each location STRINGS.XML (DA)

139 Allows us to specify multiple string files for each location Difficult to account for localisation Successful applications will be used in many different countries STRINGS.XML (DA)

140 What s the alternative? if ( Locale.getDefault().getDisplayLanguage().equals("English") ) { }... This might seem simple but PROGRAMMATIC.JAVA

141 When we decide to implement an Android GUI programmatically, we become responsible for responding to all states of the device US ANDROID

142 Let s explore the implications of this responsibility further. This is how a declarative layout allows us to account for different screen orientations

143 What s the alternative? private int getscreenorientation() { int rotation = getwindowmanager().getdefaultdisplay().getrotation(); DisplayMetrics dm = getresources().getdisplaymetrics(); int width = dm.widthpixels; int height = dm.heightpixels; int orientation; PROGRAMMATIC.JAVA

144 /* If this phone rotates normally, i.e. when it is in portrait, or reverse portrait, the height is greater than the width and when it is is landscape, or reverse landscape, the width is greater than the height: */ if ( ( rotation == Surface.ROTATION_0 rotation == Surface.ROTATION_180 ) && height > width ( rotation == Surface.ROTATION_90 rotation == Surface.ROTATION_270) && width > height ) { switch(rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; default: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; } } PROGRAMMATIC.JAVA

145 /* Otherwise, the device's natural orientation must be landscape, or the device is square: */ else { switch(rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; default: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; } } return orientation; } I don t think we want this responsibility! PROGRAMMATIC.JAVA

146 When we declare the GUI we want to use in different conditions (e.g. portrait and landscape) we are able to let Android decide when a device is in a certain state. US ANDROID

147 When we declare the GUI we want to use in different conditions (e.g. portrait and landscape) we are able to let Android decide when a device is in a certain state. It is particularly important that we delegate this task in a mobile environment, when it may be difficult to accurately detect a device s state, programmatically. US ANDROID

148 When we declare the GUI we want to use in different conditions (e.g. portrait and landscape) we are able to let Android decide when a device is in a certain state. With different versions of Android, it s also important not to assume a consistent interface for detecting the relevant conditions. US ANDROID

149 Finally <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> Expands to fit the text inside it ACTIVITY_PROGRAMMATIC.XML

150 wrap_content match_parent ACTIVITY_PROGRAMMATIC.XML

151 Finally <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> Enables us to create the desired layout ACTIVITY_PROGRAMMATIC.XML

152

153 But before we run our app, we need to tell our android which layout to load public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_programmatic); } PROGRAMMATIC.JAVA

154 But before we run our app, we need to tell our android which layout to load public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_programmatic); } We call this inflating the GUI. PROGRAMMATIC.JAVA

155 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="16dp" android:paddingleft="16dp" android:paddingright="16dp" android:paddingtop="16dp" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button One small addition android:layout_width="wrap_content" android:layout_height="wrap_content" ACTIVITY_PROGRAMMATIC.XML

156 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" > We could take this <TextView even further android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <resources> /> <dimen name="activity_horizontal_margin">16dp</ dimen> <dimen name="activity_vertical_margin">16dp</dimen> <Button </resources> android:layout_width="wrap_content" android:layout_height="wrap_content" ACTIVITY_PROGRAMMATIC.XML

157

158 What s the alternative? public class Programmatic extends Activity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); RelativeLayout layout = new RelativeLayout(this); layout.setpadding(dptopixels(16), dptopixels(16), dptopixels(16), dptopixels(16)); } private int dptopixels(int dp) { float scale = getresources().getdisplaymetrics().density; return Math.round(dp * scale); } PROGRAMMATIC.JAVA

159 WHAT A DECLARATIVE GUI GIVE US A natural separation between the view and the model Simple, intuitive XML code A straightforward way to indicate how our GUI, and its content, should change according to variables in the device Language Orientation An accurate way to handle device resolution

160 So do we ever need to specify an Android GUI programatically?

161 1. XML is well tuned to static interfaces. Programmatic UIs are better suited to the dynamic addition of views. 2. The slight processing overhead associated with inflating the UI might be noticeable with a large number of views (debated; lots of pre-parsing) So do we ever need to specify an Android GUI programatically?

162

163

164

165

166 Clone repo:

167

168

169

170

171 Exercise: write a declarative XML file that describes this interface

172 Spinner Exercise: write a declarative XML file that describes this interface

173 Spinner Exercise: write a declarative XML file that describes this interface

174 Spinner Exercise: write a declarative XML file that describes this interface android:entries="@array/genres"/>

175 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" ACTIVITY_FIND_FILM.XML

176 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" ACTIVITY_FIND_FILM.XML

177 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" ACTIVITY_FIND_FILM.XML

178 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <Spinner <resources> android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <string name="app_name">filmadviser</string> <string-array name="genres"> <item>horror</item> <item>action</item> <item>comedy</item> <item>romance</item> </string-array> </resources> <TextView android:layout_width="wrap_content" STRINGS.XML ACTIVITY_FIND_FILM.XML

179 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" ACTIVITY_FIND_FILM.XML

180 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" ACTIVITY_FIND_FILM.XML

181 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" ACTIVITY_FIND_FILM.XML

182 <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <resources> <string name="app_name">filmadviser</string> <string-array name="genres"> <item>horror</item> <item>action</item> <item>comedy</item> <item>romance</item> </string-array> <string name="find_film">find Film</string> </resources> <TextView android:layout_width="wrap_content" ACTIVITY_FIND_FILM.XML

183 <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_FIND_FILM.XML

184

185 That s it for our discussion of Views and Layouts. The declarative XML in intuitive enough to determine how to do most things (with help from the API). Our focus now will be making an application that does something interesting, and thus allows us to test our Java problem solving skills.

186 But first some more Android specifics HOW DO WE GET AN ANDROID APPLICATION TO DO SOMETHING?

187 In Swing?

188 In Swing? search.addactionlistener(new ActionListener() public void actionperformed(actionevent e) {... } });

189 Let s go back to our example

190

191 android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_FIND_FILM.XML

192 android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="onclickfindfilm" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> ACTIVITY_FIND_FILM.XML

193 android:layout_height="match_parent"> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="onclickfindfilm" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </RelativeLayout> Looks in the current Activity ACTIVITY_FIND_FILM.XML

194 package uk.co.martinchapman.filmadviser; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; public class FindFilmActivity extends AppCompatActivity protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_find_film); } public void onclickfindfilm(view view) {... } } FINDFILMACTIVITY.JAVA

195 package uk.co.martinchapman.filmadviser; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; public class FindFilmActivity extends AppCompatActivity { To (potentially) help us with future processing, a copy of the View calling this method is passed. protected void oncreate(bundle savedinstancestate) { } super.oncreate(savedinstancestate); setcontentview(r.layout.activity_find_film); public void onclickfindfilm(view view) { }... FINDFILMACTIVITY.JAVA

196 package uk.co.martinchapman.filmadviser; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; public class FindFilmActivity extends AppCompatActivity { To (potentially) help us with future processing, a copy of the View calling this method is passed. protected void oncreate(bundle savedinstancestate) { } super.oncreate(savedinstancestate); setcontentview(r.layout.activity_find_film); public void onclickfindfilm(view view) { }... Similar to passing an event in Swing. FINDFILMACTIVITY.JAVA

197 package uk.co.martinchapman.filmadviser; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; public class FindFilmActivity extends AppCompatActivity { To (potentially) help us with future processing, a copy of the View calling this method is protected void oncreate(bundle savedinstancestate) { } super.oncreate(savedinstancestate); setcontentview(r.layout.activity_find_film); public void onclickfindfilm(view view) {... Return type not considered part of } method signature } Similar to passing an event in Swing. FINDFILMACTIVITY.JAVA

198 Our program s aim: 1. Take what is written in the drop-down (Spinner). 2. Select a random film of that genre. 3. Display it on the UI.

199 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); } FINDFILMACTIVITY.JAVA

200 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); } FINDFILMACTIVITY.JAVA

201 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); } FINDFILMACTIVITY.JAVA

202 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); } FINDFILMACTIVITY.JAVA

203 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); } FINDFILMACTIVITY.JAVA

204 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); } FINDFILMACTIVITY.JAVA

205 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); } FINDFILMACTIVITY.JAVA

206 <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" />

207 <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> I need someway to uniquely identify each view Map<Integer,View> viewbyid; I ve been instructed to create a Spinner Spinner aspinner = new Spinner(); Associate this Spinner with its ID from the R file viewbyid.put(r.id.aspinner, aspinner); Offer my user some way to get this Spinner back, when they supply an ID (via the R file) public View findviewbyid(int id) { return (viewbyid.get(id)) }

208 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); TextView textview = (TextView) findviewbyid(r.id.films); } FINDFILMACTIVITY.JAVA

209 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); TextView textview = (TextView) findviewbyid(r.id.films); } textview.settext(getfilm(spinner.getselecteditem() + "")); FINDFILMACTIVITY.JAVA

210 public void onclickfindfilm(view view) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); TextView textview = (TextView) findviewbyid(r.id.films); } textview.settext(getfilm(spinner.getselecteditem() + "")); FINDFILMACTIVITY.JAVA

211 public String getfilm(string genre) { ArrayList<String> horror = new ArrayList<String>(Arrays.asList(new String[]{"", ""})); ArrayList<String> action = new ArrayList<String>(Arrays.asList(new String[]{"", ""})); ArrayList<String> comedy = new ArrayList<String>(Arrays.asList(new String[]{"", ""})); ArrayList<String> romance = new ArrayList<String>(Arrays.asList(new String[]{"", ""})); switch ( genre ) { case "Horror": return horror.get((int)(math.random() * horror.size())); case "Action": return action.get((int)(math.random() * action.size())); case "Comedy": return comedy.get((int)(math.random() * comedy.size())); case "Romance": return romance.get((int)(math.random() * romance.size())); default: return "No Recommendation"; } } Important to remember that this is still just a Java program, so many of the things we want to achieve in an Activity, we can implement in a familiar way. FINDFILMACTIVITY.JAVA

212

213 What s wrong with this? Hard to reconcile both efficiency and flexibility, if we want to associate similar, yet varying, actions to different views.

214 What s wrong with this?

215 What s wrong with this? Imagine if we have a set of buttons that increment a total

216 What s wrong with this? Imagine if we have a set of buttons that increment a total public void onclickaddone(view view) {... } public void onclickaddtwo(view view) {... } public void onclickaddthree(view view) {... } Unless we can get the increment amounts from the view, we would need different event handlers for each.

217 What s wrong with this? Perhaps more importantly, it contradicts the natural notion of separating the view from the model (and control) that is brought by having a separate layout file.

218 The solution? Revert back to a familiar form of event handling button.setonclicklistener(new View.OnClickListener() { public void onclick(view v) {... }); } Some slightly altered syntax

219 The solution? We can then have all the flexibility we had previously button.setonclicklistener(new addn(5)); private class addn implements View.OnClickListener { private int n; public addn(int n) { } } this.n = n; public void onclick(view v) {... } Use Java solutions

220 Reformatting our FilmAdviser event handler Button button = (Button)findViewById(R.id.find_film); button.setonclicklistener(new View.OnClickListener() { public void onclick(view v) { Spinner spinner = (Spinner) findviewbyid(r.id.genre); TextView textview = (TextView) findviewbyid(r.id.films); textview.settext(getfilm(spinner.getselecteditem() + "")); } }); FINDFILMACTIVITY.JAVA

221 That s it for our discussion of Event Handlers. The similarity of the syntax to Swing should enable you to achieve most things. Our focus now will be making an application that allows us to test our Java problem solving skills.

222

223

224 REMEMBER

225 REMEMBER As with all live programming examples, if you want to understand them fully, you need to go away and look over them yourself, add comments and rewrite parts; I m not expecting you to fully understand this in the lecture.

226 REMEMBER As with all live programming examples, if you want to understand them fully, you need to go away and look over them yourself, add comments and rewrite parts; I m not expecting you to fully understand this in the lecture. Use the versions of code provided on Github (link also on KEATS) to catch up if you fall behind.

227 REMEMBER As with all live programming examples, if you want to understand them fully, you need to go away and look over them yourself, add comments and rewrite parts; I m not expecting you to fully understand this in the lecture. Use the versions of code provided on Github (link also on KEATS) to catch up if you fall behind. This is only one way of implementing a solution, and not necessarily the best, especially in respect of model-viewcontroller. Some deviations for clarity and experimentation.

228 Clone repo:

229

230 THE MODEL

231 public class Coordinate { private int x; private int y; public Coordinate() {} public Coordinate( int x, int y ) { this.x = x; this.y = y; } public int getx() { return x; } public int gety() { return y; } COORDINATE.JAVA - ALL VERSIONS

232 } public int gety() { } return y; public boolean equals(coordinate other) { } if (x == other.x && y == other.y) { } return true; return public String tostring() { } return "Coordinate: [" + x + "," + y + "]"; COORDINATE.JAVA - ALL VERSIONS

233 SNAKE.JAVA - V1

234 import java.util.arraylist; // Remember use of Coordinate from local package /** * Created 0 by Martin on 14/03/16. */ public class Snake { 1 // What information do we need to store about the snake? } SNAKE.JAVA - V1

235 import java.util.arraylist; // Remember use of Coordinate from local package /** * Created 0 by Martin on 14/03/16. */ public class Snake { 1 // What information do we need to store about the snake? } EXERCISE: Determine some attributes for the snake 7 SNAKE.JAVA - V1

236 import java.util.arraylist; public class Snake { /* We'll need to store the head of the snake separately, as this is the part of the snake the `meets' things. We'll also need to display it. This is really just a symbolic field, that is pointed to the first entry on the trail */ private Coordinate head; public Coordinate gethead() { return head; } /* We'll need to store the whole of the snake, to display it and to check for things such as collisions. */ private ArrayList<Coordinate> snaketrail; public ArrayList<Coordinate> gettrail() { return snaketrail; } SNAKE.JAVA - V2

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs EMBEDDED SYSTEMS PROGRAMMING 2015-16 Application Tip: Switching UIs THE PROBLEM How to switch from one UI to another Each UI is associated with a distinct class that controls it Solution shown: two UIs,

More information

Android Application Development. By : Shibaji Debnath

Android Application Development. By : Shibaji Debnath Android Application Development By : Shibaji Debnath About Me I have over 10 years experience in IT Industry. I have started my career as Java Software Developer. I worked in various multinational company.

More information

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches EMBEDDED SYSTEMS PROGRAMMING 2016-17 UI Specification: Approaches UIS: APPROACHES Programmatic approach: UI elements are created inside the application code Declarative approach: UI elements are listed

More information

Intents. Your first app assignment

Intents. Your first app assignment Intents Your first app assignment We will make this. Decidedly lackluster. Java Code Java Code XML XML Preview XML Java Code Java Code XML Buttons that work

More information

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar Mobile Application Development Higher Diploma in Science in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology

More information

Fragment Example Create the following files and test the application on emulator or device.

Fragment Example Create the following files and test the application on emulator or device. Fragment Example Create the following files and test the application on emulator or device. File: AndroidManifest.xml

More information

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State EMBEDDED SYSTEMS PROGRAMMING 2016-17 Application Tip: Saving State THE PROBLEM How to save the state (of a UI, for instance) so that it survives even when the application is closed/killed The state should

More information

EMBEDDED SYSTEMS PROGRAMMING Application Basics

EMBEDDED SYSTEMS PROGRAMMING Application Basics EMBEDDED SYSTEMS PROGRAMMING 2015-16 Application Basics APPLICATIONS Application components (e.g., UI elements) are objects instantiated from the platform s frameworks Applications are event driven ( there

More information

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept. MAD ASSIGNMENT NO 3 Submitted by: Rehan Asghar BSSE 7 15126 AUGUST 25, 2017 SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept. MainActivity.java File package com.example.tutorialspoint; import android.manifest;

More information

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Software Practice 3 Before we start Today s lecture Today s Task Team organization 1 Software Practice 3 Before we start Today s lecture Today s Task Team organization Prof. Hwansoo Han T.A. Jeonghwan Park 43 2 Lecture Schedule Spring 2017 (Monday) This schedule can be changed M A R

More information

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation EMBEDDED SYSTEMS PROGRAMMING 2016-17 Application Tip: Managing Screen Orientation ORIENTATIONS Portrait Landscape Reverse portrait Reverse landscape ON REVERSE PORTRAIT Android: all four orientations are

More information

Android - JSON Parser Tutorial

Android - JSON Parser Tutorial Android - JSON Parser Tutorial JSON stands for JavaScript Object Notation.It is an independent data exchange format and is the best alternative for XML. This chapter explains how to parse the JSON file

More information

EMBEDDED SYSTEMS PROGRAMMING Android Services

EMBEDDED SYSTEMS PROGRAMMING Android Services EMBEDDED SYSTEMS PROGRAMMING 2016-17 Android Services APP COMPONENTS Activity: a single screen with a user interface Broadcast receiver: responds to system-wide broadcast events. No user interface Service:

More information

Android UI Development

Android UI Development Android UI Development Android UI Studio Widget Layout Android UI 1 Building Applications A typical application will include: Activities - MainActivity as your entry point - Possibly other activities (corresponding

More information

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2 Workshop 1. Compare different layout by using Change Layout button (Page 1 5) Relative Layout Linear Layout (Horizontal) Linear Layout (Vertical) Frame Layout 2. Revision on basic programming skill - control

More information

Create Parent Activity and pass its information to Child Activity using Intents.

Create Parent Activity and pass its information to Child Activity using Intents. Create Parent Activity and pass its information to Child Activity using Intents. /* MainActivity.java */ package com.example.first; import android.os.bundle; import android.app.activity; import android.view.menu;

More information

Arrays of Buttons. Inside Android

Arrays of Buttons. Inside Android Arrays of Buttons Inside Android The Complete Code Listing. Be careful about cutting and pasting.

More information

Mobile Software Development for Android - I397

Mobile Software Development for Android - I397 1 Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, 2015-2016 EMAIL: AKAVER@ITCOLLEGE.EE WEB: HTTP://ENOS.ITCOLLEGE.EE/~AKAVER/2015-2016/DISTANCE/ANDROID SKYPE: AKAVER Timetable

More information

LifeStreet Media Android Publisher SDK Integration Guide

LifeStreet Media Android Publisher SDK Integration Guide LifeStreet Media Android Publisher SDK Integration Guide Version 1.12.0 Copyright 2015 Lifestreet Corporation Contents Introduction... 3 Downloading the SDK... 3 Choose type of SDK... 3 Adding the LSM

More information

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB) Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB) In this exercise, we will create a simple Android application that uses IBM Bluemix Cloudant NoSQL DB. The application

More information

University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World

University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World Before you do anything read all of the following red paragraph! For this lab you

More information

Basic GUI elements - exercises

Basic GUI elements - exercises Basic GUI elements - exercises https://developer.android.com/studio/index.html LIVE DEMO Please create a simple application, which will be used to calculate the area of basic geometric figures. To add

More information

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Diving into Android. By Jeroen Tietema. Jeroen Tietema, Diving into Android By Jeroen Tietema Jeroen Tietema, 2015 1 Requirements 4 Android SDK 1 4 Android Studio (or your IDE / editor of choice) 4 Emulator (Genymotion) or a real device. 1 See https://developer.android.com

More information

Tabel mysql. Kode di PHP. Config.php. Service.php

Tabel mysql. Kode di PHP. Config.php. Service.php Tabel mysql Kode di PHP Config.php Service.php Layout Kode di Main Activity package com.example.mini.webandroid; import android.app.progressdialog; import android.os.asynctask; import android.support.v7.app.appcompatactivity;

More information

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept. MAD ASSIGNMENT NO 2 Submitted by: Rehan Asghar BSSE 7 15126 AUGUST 25, 2017 SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept. Android Widgets There are given a lot of android widgets with simplified

More information

Getting Started With Android Feature Flags

Getting Started With Android Feature Flags Guide Getting Started With Android Feature Flags INTRO When it comes to getting started with feature flags (Android feature flags or just in general), you have to understand that there are degrees of feature

More information

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering Getting Started Dr. Miguel A. Labrador Department of Computer Science & Engineering labrador@csee.usf.edu http://www.csee.usf.edu/~labrador 1 Goals Setting up your development environment Android Framework

More information

Group B: Assignment No 8. Title of Assignment: To verify the operating system name and version of Mobile devices.

Group B: Assignment No 8. Title of Assignment: To verify the operating system name and version of Mobile devices. Group B: Assignment No 8 Regularity (2) Performance(5) Oral(3) Total (10) Dated Sign Title of Assignment: To verify the operating system name and version of Mobile devices. Problem Definition: Write a

More information

Android Navigation Drawer for Sliding Menu / Sidebar

Android Navigation Drawer for Sliding Menu / Sidebar Android Navigation Drawer for Sliding Menu / Sidebar by Kapil - Tuesday, December 15, 2015 http://www.androidtutorialpoint.com/material-design/android-navigation-drawer-for-sliding-menusidebar/ YouTube

More information

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface? MOBILE COMPUTING CSE 40814/60814 Fall 2015 How many of you have implemented a command-line user interface? 1 How many of you have implemented a graphical user interface? HTML/CSS Java Swing.NET Framework

More information

Statistics http://www.statista.com/topics/840/smartphones/ http://www.statista.com/topics/876/android/ http://www.statista.com/statistics/271774/share-of-android-platforms-on-mobile-devices-with-android-os/

More information

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar Mobile Application Development Higher Diploma in Science in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology

More information

Java & Android. Java Fundamentals. Madis Pink 2016 Tartu

Java & Android. Java Fundamentals. Madis Pink 2016 Tartu Java & Android Java Fundamentals Madis Pink 2016 Tartu 1 Agenda» Brief background intro to Android» Android app basics:» Activities & Intents» Resources» GUI» Tools 2 Android» A Linux-based Operating System»

More information

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology Android App Development Mr. Michaud ICE Programs Georgia Institute of Technology Android Operating System Created by Android, Inc. Bought by Google in 2005. First Android Device released in 2008 Based

More information

Android Basics. Android UI Architecture. Android UI 1

Android Basics. Android UI Architecture. Android UI 1 Android Basics Android UI Architecture Android UI 1 Android Design Constraints Limited resources like memory, processing, battery à Android stops your app when not in use Primarily touch interaction à

More information

Fragments. Lecture 11

Fragments. Lecture 11 Fragments Lecture 11 Situational layouts Your app can use different layouts in different situations Different device type (tablet vs. phone vs. watch) Different screen size Different orientation (portrait

More information

Android - Widgets Tutorial

Android - Widgets Tutorial Android - Widgets Tutorial A widget is a small gadget or control of your android application placed on the home screen. Widgets can be very handy as they allow you to put your favourite applications on

More information

EMBEDDED SYSTEMS PROGRAMMING Android NDK

EMBEDDED SYSTEMS PROGRAMMING Android NDK EMBEDDED SYSTEMS PROGRAMMING 2015-16 Android NDK WHAT IS THE NDK? The Android NDK is a set of cross-compilers, scripts and libraries that allows to embed native code into Android applications Native code

More information

Solving an Android Threading Problem

Solving an Android Threading Problem Home Java News Brief Archive OCI Educational Services Solving an Android Threading Problem Introduction by Eric M. Burke, Principal Software Engineer Object Computing, Inc. (OCI) By now, you probably know

More information

Android Beginners Workshop

Android Beginners Workshop Android Beginners Workshop at the M O B IL E M O N D AY m 2 d 2 D E V E L O P E R D A Y February, 23 th 2010 Sven Woltmann, AndroidPIT Sven Woltmann Studied Computer Science at the TU Ilmenau, 1994-1999

More information

Android Workshop: Model View Controller ( MVC):

Android Workshop: Model View Controller ( MVC): Android Workshop: Android Details: Android is framework that provides java programmers the ability to control different aspects of smart devices. This interaction happens through the Android SDK (Software

More information

Produced by. Mobile Application Development. Eamonn de Leastar

Produced by. Mobile Application Development. Eamonn de Leastar Mobile Application Development Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie A First

More information

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar Mobile Application Development Higher Diploma in Science in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology

More information

Manifest.xml. Activity.java

Manifest.xml. Activity.java Dr.K.Somasundaram Ph.D Professor Department of Computer Science and Applications Gandhigram Rural Institute, Gandhigram, Tamil Nadu-624302, India ka.somasundaram@gmail.com Manifest.xml

More information

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server. CSE 660 Lab 7 Submitted by: Arumugam Thendramil Pavai 1)Simple Remote Calculator Server is created using ServerSocket class of java Server.java import java.io.ioexception; import java.net.serversocket;

More information

EMBEDDED SYSTEMS PROGRAMMING Android NDK

EMBEDDED SYSTEMS PROGRAMMING Android NDK EMBEDDED SYSTEMS PROGRAMMING 2014-15 Android NDK WHAT IS THE NDK? The Android NDK is a set of cross-compilers, scripts and libraries that allows to embed native code into Android applications Native code

More information

SD Module-1 Android Dvelopment

SD Module-1 Android Dvelopment SD Module-1 Android Dvelopment Experiment No: 05 1.1 Aim: Download Install and Configure Android Studio on Linux/windows platform. 1.2 Prerequisites: Microsoft Windows 10/8/7/Vista/2003 32 or 64 bit Java

More information

ELET4133: Embedded Systems. Topic 15 Sensors

ELET4133: Embedded Systems. Topic 15 Sensors ELET4133: Embedded Systems Topic 15 Sensors Agenda What is a sensor? Different types of sensors Detecting sensors Example application of the accelerometer 2 What is a sensor? Piece of hardware that collects

More information

Vienos veiklos būsena. Theory

Vienos veiklos būsena. Theory Vienos veiklos būsena Theory While application is running, we create new Activities and close old ones, hide the application and open it again and so on, and Activity can process all these events. It is

More information

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator. Simple Android Application for Native Calculator Aim: To develop a Simple Android Application for Native Calculator. Procedure: Creating a New project: Open Android Stdio and then click on File -> New

More information

COMP61242: Task /04/18

COMP61242: Task /04/18 COMP61242: Task 2 1 16/04/18 1. Introduction University of Manchester School of Computer Science COMP61242: Mobile Communications Semester 2: 2017-18 Laboratory Task 2 Messaging with Android Smartphones

More information

Android/Java Lightning Tutorial JULY 30, 2018

Android/Java Lightning Tutorial JULY 30, 2018 Android/Java Lightning Tutorial JULY 30, 2018 Java Android uses java as primary language Resource : https://github.mit.edu/6178-2017/lec1 Online Tutorial : https://docs.oracle.com/javase/tutorial/java/nutsandbolts/inde

More information

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE) PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE) Network Connection Web Service K Candra Brata andra.course@gmail.com Mobille App Lab 2015-2016 Network Connection http://developer.android.com/training/basics/network-ops/connecting.html

More information

android-espresso #androidespresso

android-espresso #androidespresso android-espresso #androidespresso Table of Contents About 1 Chapter 1: Getting started with android-espresso 2 Remarks 2 Examples 2 Espresso setup instructions 2 Checking an Options Menu items (using Spoon

More information

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126 M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126 Submitted to: Sir Waqas Asghar MAY 23, 2017 SUBMITTED BY: REHAN ASGHAR Intent in Android What are Intent? An Intent is a messaging object you can use to request

More information

South Africa

South Africa South Africa 2013 Lecture 6: Layouts, Menus, Views http://aiti.mit.edu Create an Android Virtual Device Click the AVD Icon: Window -> AVD Manager -> New Name & start the virtual device (this may take a

More information

Hello World. Lesson 1. Android Developer Fundamentals. Android Developer Fundamentals. Layouts, and. NonCommercial

Hello World. Lesson 1. Android Developer Fundamentals. Android Developer Fundamentals. Layouts, and. NonCommercial Hello World Lesson 1 This work is licensed This under work a Creative is is licensed Commons under a a Attribution-NonCommercial Creative 4.0 Commons International Attribution- License 1 NonCommercial

More information

Multiple Activities. Many apps have multiple activities

Multiple Activities. Many apps have multiple activities Intents Lecture 7 Multiple Activities Many apps have multiple activities An activity A can launch another activity B in response to an event The activity A can pass data to B The second activity B can

More information

User Interface Development. CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr.

User Interface Development. CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr. User Interface Development CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr. Rajiv Ramnath 1 Outline UI Support in Android Fragments 2 UI Support in the Android

More information

<uses-permission android:name="android.permission.internet"/>

<uses-permission android:name=android.permission.internet/> Chapter 11 Playing Video 11.1 Introduction We have discussed how to play audio in Chapter 9 using the class MediaPlayer. This class can also play video clips. In fact, the Android multimedia framework

More information

Android Programs Day 5

Android Programs Day 5 Android Programs Day 5 //Android Program to demonstrate the working of Options Menu. 1. Create a New Project. 2. Write the necessary codes in the MainActivity.java to create OptionMenu. 3. Add the oncreateoptionsmenu()

More information

Developed and taught by well-known Contact author and developer. At public for details venues or onsite at your location.

Developed and taught by well-known Contact author and developer. At public for details venues or onsite at your location. 2011 Marty Hall Android Programming Basics Originals of Slides and Source Code for Examples: http://www.coreservlets.com/android-tutorial/ Customized Java EE Training: http://courses.coreservlets.com/

More information

Getting started: Installing IDE and SDK. Marco Ronchetti Università degli Studi di Trento

Getting started: Installing IDE and SDK. Marco Ronchetti Università degli Studi di Trento Getting started: Installing IDE and SDK Marco Ronchetti Università degli Studi di Trento Alternative: Android Studio http://developer.android.com/develop/index.html 2 Tools behind the scenes dx allows

More information

Custom Views in Android Tutorial

Custom Views in Android Tutorial Custom Views in Android Tutorial The Android platform provides an extensive range of user interface items that are sufficient for the needs of most apps. However, there may be occasions on which you feel

More information

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation 1. Location Services 1.1 GPS Location 1. Create the Android application with the following attributes. Application Name: MyLocation Project Name: Package Name: MyLocation com.example.mylocation 2. Put

More information

EMBEDDED SYSTEMS PROGRAMMING Android NDK

EMBEDDED SYSTEMS PROGRAMMING Android NDK EMBEDDED SYSTEMS PROGRAMMING 2017-18 Android NDK WHAT IS THE NDK? The Android NDK is a set of cross-compilers, scripts and libraries that allows to embed native code into Android applications Native code

More information

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences ITU- FAO- DOA- TRCSL Training on Innovation & Application Development for E- Agriculture Shared Preferences 11 th - 15 th December 2017 Peradeniya, Sri Lanka Shahryar Khan & Imran Tanveer, ITU Experts

More information

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters Mobile Programming Lecture 5 Composite Views, Activities, Intents and Filters Lecture 4 Review How do you get the value of a string in the strings.xml file? What are the steps to populate a Spinner or

More information

Introduction to Android Development

Introduction to Android Development Introduction to Android Development What is Android? Android is the customizable, easy to use operating system that powers more than a billion devices across the globe - from phones and tablets to watches,

More information

COMP4521 EMBEDDED SYSTEMS SOFTWARE

COMP4521 EMBEDDED SYSTEMS SOFTWARE COMP4521 EMBEDDED SYSTEMS SOFTWARE LAB 1: DEVELOPING SIMPLE APPLICATIONS FOR ANDROID INTRODUCTION Android is a mobile platform/os that uses a modified version of the Linux kernel. It was initially developed

More information

Upon completion of the second part of the lab the students will have:

Upon completion of the second part of the lab the students will have: ETSN05, Fall 2017, Version 2.0 Software Development of Large Systems Lab 2 1. INTRODUCTION The goal of lab 2 is to introduce students to the basics of Android development and help them to create a starting

More information

M.A.D Assignment # 1

M.A.D Assignment # 1 Submitted by: Rehan Asghar Roll no: BSSE (7) 15126 M.A.D Assignment # 1 Submitted to: Sir Waqas Asghar Submitted by: M. Rehan Asghar 4/25/17 Roll no: BSSE 7 15126 XML Code: Calculator Android App

More information

Our First Android Application

Our First Android Application Mobile Application Development Lecture 04 Imran Ihsan Our First Android Application Even though the HelloWorld program is trivial in introduces a wealth of new ideas the framework, activities, manifest,

More information

Lampiran Program : Res - Layout Activity_main.xml

More information

Learn about Android Content Providers and SQLite

Learn about Android Content Providers and SQLite Tampa Bay Android Developers Group Learn about Android Content Providers and SQLite Scott A. Thisse March 20, 2012 Learn about Android Content Providers and SQLite What are they? How are they defined?

More information

Security model. Marco Ronchetti Università degli Studi di Trento

Security model. Marco Ronchetti Università degli Studi di Trento Security model Marco Ronchetti Università degli Studi di Trento Security model 2 Android OS is a multi-user Linux in which each application is a different user. By default, the system assigns each application

More information

Fragments. Lecture 10

Fragments. Lecture 10 Fragments Lecture 10 Situa2onal layouts Your app can use different layouts in different situa2ons Different device type (tablet vs. phone vs. watch) Different screen size Different orienta2on (portrait

More information

Computer Science E-76 Building Mobile Applications

Computer Science E-76 Building Mobile Applications Computer Science E-76 Building Mobile Applications Lecture 3: [Android] The SDK, Activities, and Views February 13, 2012 Dan Armendariz danallan@mit.edu 1 http://developer.android.com Android SDK and NDK

More information

Figure 2.10 demonstrates the creation of a new project named Chapter2 using the wizard.

Figure 2.10 demonstrates the creation of a new project named Chapter2 using the wizard. 44 CHAPTER 2 Android s development environment Figure 2.10 demonstrates the creation of a new project named Chapter2 using the wizard. TIP You ll want the package name of your applications to be unique

More information

INTRODUCTION TO ANDROID

INTRODUCTION TO ANDROID INTRODUCTION TO ANDROID 1 Niv Voskoboynik Ben-Gurion University Electrical and Computer Engineering Advanced computer lab 2015 2 Contents Introduction Prior learning Download and install Thread Android

More information

CS 4330/5390: Mobile Application Development Exam 1

CS 4330/5390: Mobile Application Development Exam 1 1 Spring 2017 (Thursday, March 9) Name: CS 4330/5390: Mobile Application Development Exam 1 This test has 8 questions and pages numbered 1 through 7. Reminders This test is closed-notes and closed-book.

More information

Developing For Android

Developing For Android Wirtschaftsuniversität Wien Developing For Android From 0 to 100 on Mobile and Wearable Devices Author: Gerald Urschitz Supervisor: Ronny G. Flatscher January 7, 2016 I, Gerald Urschitz, declare that this

More information

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar Mobile Application Development Higher Diploma in Science in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology

More information

Java Basics A Simple Hit the Zombies Game

Java Basics A Simple Hit the Zombies Game Lecture #3 Introduction Java Basics A Simple Hit the Zombies Game The previous lecture provided a guided tour to explore the basics of Android Studio and how to use it to create a project to build an Android

More information

CMSC436: Fall 2013 Week 3 Lab

CMSC436: Fall 2013 Week 3 Lab CMSC436: Fall 2013 Week 3 Lab Objectives: Familiarize yourself with the Activity class, the Activity lifecycle, and the Android reconfiguration process. Create and monitor a simple application to observe

More information

Tutorial: Setup for Android Development

Tutorial: Setup for Android Development Tutorial: Setup for Android Development Adam C. Champion CSE 5236: Mobile Application Development Autumn 2017 Based on material from C. Horstmann [1], J. Bloch [2], C. Collins et al. [4], M.L. Sichitiu

More information

Learning Android Canvas

Learning Android Canvas Learning Android Canvas Mir Nauman Tahir Chapter No. 4 "NinePatch Images" In this package, you will find: A Biography of the author of the book A preview chapter from the book, Chapter NO.4 "NinePatch

More information

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs Overview MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs Lecture: MVC Model View Controller What is an App? Android Activity Lifecycle Android Debugging Fixing Rotations & Landscape Layouts Localization

More information

Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna Programming with Android: Introduction Layouts Luca Bedogni Marco Di Felice Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna Views: outline Main difference between a Drawable and

More information

Eventually, you'll be returned to the AVD Manager. From there, you'll see your new device.

Eventually, you'll be returned to the AVD Manager. From there, you'll see your new device. Let's get started! Start Studio We might have a bit of work to do here Create new project Let's give it a useful name Note the traditional convention for company/package names We don't need C++ support

More information

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling Mobile Programming Lecture 2 Layouts, Widgets, Toasts, and Event Handling Lecture 1 Review How to edit XML files in Android Studio? What holds all elements (Views) that appear to the user in an Activity?

More information

CSCU9YH Development with Android

CSCU9YH Development with Android CSCU9YH Development with Android Computing Science and Mathematics University of Stirling 1 Android Context 3 Smartphone Market share Source: http://www.idc.com/promo/smartphone-market-share/os 4 Smartphone

More information

Applications. Marco Ronchetti Università degli Studi di Trento

Applications. Marco Ronchetti Università degli Studi di Trento Applications Marco Ronchetti Università degli Studi di Trento Android Applications An Android application typically consists of one or more related, loosely bound activities for the user to interact with.

More information

Simple Currency Converter

Simple Currency Converter Simple Currency Converter Implementing a simple currency converter: USD Euro Colon (CR) Note. Naive implementation using the rates 1 Costa Rican Colon = 0.001736 U.S. dollars 1 Euro = 1.39900 U.S. dollars

More information

ANDROID USER INTERFACE

ANDROID USER INTERFACE 1 ANDROID USER INTERFACE Views FUNDAMENTAL UI DESIGN Visual interface element (controls or widgets) ViewGroup Contains multiple widgets. Layouts inherit the ViewGroup class Activities Screen being displayed

More information

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen Gill Cleeren Agenda Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen Lists and navigation Navigating from master to detail Optimizing the application Preparing

More information

A Crash Course to Android Mobile Platform

A Crash Course to Android Mobile Platform Enterprise Application Development using J2EE Shmulik London Lecture #2 A Crash Course to Android Mobile Platform Enterprise Application Development Using J2EE / Shmulik London 2004 Interdisciplinary Center

More information