Presentation is loading. Please wait.

Presentation is loading. Please wait.

Objects First with Java

Similar presentations


Presentation on theme: "Objects First with Java"— Presentation transcript:

1 Objects First with Java
Class Business © David J. Barnes and Michael Kölling

2 Android Introduction Android is an operating system that runs on mobile platforms “smartphones” & tablets Cars Watches Cameras Based on Linux Open source, free

3 History Android, Inc founded in 2003, financed by Google
Google bought the company in 2005 Android release Android in 2007 First handset in 2008 Releases are named after desserts/snacks (current is “Marshmallow” – Android 6.0.1)

4 Issues on Android Platforms
Platforms are battery powered, restricted in CPU and memory Screens are small compared to desktops Policies When an app is no longer in use, the system will suspend it in memory (consume no resources) When memory is low, the system will kill apps and processes that have been inactive for a while

5 Environment Android Development Kit is free
Hooks into Eclipse or Android Studio Emulators are useful

6 User Interface The UI for an Android app is built using a hierarchy of View  and ViewGroup objects.  View objects are usually UI widgets such as buttons or textfields  ViewGroup objects are invisible view containers that define how the child views are laid out, such as in a grid or a vertical list.

7 Assumed Methods Android programming is very object oriented
There are lots of assumed methods initially defined as empty that govern app behavior.

8 Activity An Activity is the main object in an Android app. Lifecycle:

9 Example

10 XML HTML-like syntax that is used for many things, especially specification languages HTML is actually a specialized XML Tag-based language <blah> … </blah>

11 Example: activity_main
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>

12 AndroidManifest.xml Basic app specification file Contains info on:
Permissions Version minimums Icons

13 Example: Walk through Eclipse

14 Event Programming in Android
Same idea, different methods, clunky implementation Might want to take special actions to make the code look nice

15 Listeners OnClickListener is the analog to ActionListener in Java
Others: OnLongClickListener KeyListener Many built-in listeners just need methods defined

16 Example (note pattern)
LinearLayout container = (LinearLayout) dialog.findViewById(R.id.new_class_dialog_button_container); EditText et = (EditText) dialog.findViewById(R.id.new_class_name); et.setText(""); et = (EditText) dialog.findViewById(R.id.new_class_nickname); Button button = (Button) container.findViewById(R.id.create_new_button); button.setOnClickListener(new createNewClassDialogAction(dialog)); button = (Button) container.findViewById(R.id.cancel_new_button); button.setOnClickListener(new cancelDialogAction(dialog));

17 Stupid: showDialog When a dialog needs to be display, you would call “showDialog(DIALOGNUMBER)” Then define “onCreateDialog(int dialognum)” Amounts to a big if…then…else… combination Really bad code

18 Exercise

19 Look at complex example


Download ppt "Objects First with Java"

Similar presentations


Ads by Google