+ All Categories
Home > Documents > Lecture 2 - The Wonderful World of Android

Lecture 2 - The Wonderful World of Android

Date post: 07-Dec-2015
Category:
Upload: ari-pribadi
View: 233 times
Download: 9 times
Share this document with a friend
Description:
aa
Popular Tags:
13
Lecture 2 - The Wonderful World of Android The Android experience revolves around the design of a beautiful UI that users find intuitive, easy to use and navigate through, and simple. The design of a great looking UI is an art and requires exceptionally good UI design skills. We will not teach that in this class but we will gain skills of putting together a nice, clean and simple UI. What this lecture will teach you: Quick tour of the phone and user interface Development cycle Android framework Standard UI Screens There are many parts of the UI that you are already using; that is the home, all apps and recent app screens. Home screen When you unlock the phone or touch the home button on the navigation bar you will be directed to the home screen, as shown below. Above the system bar you can see the the favorites tray with various icons of your favorite apps (e.g., phone, mail, all apps button, messaging and web).
Transcript
Page 1: Lecture 2 - The Wonderful World of Android

Lecture 2 - The Wonderful World of Android

The Android experience revolves around the design of a beautiful UI that users find intuitive, easy to use and navigate through, and simple. The design of a great looking UI is an art and requires exceptionally good UI design skills. We will not teach that in this class but we will gain skills of putting together a nice, clean and simple UI.

What this lecture will teach you:

Quick tour of the phone and user interface Development cycle

Android framework

Standard UI Screens

There are many parts of the UI that you are already using; that is the home, all apps and recent app screens.

Home screen

When you unlock the phone or touch the home button on the navigation bar you will be directed to the home screen, as shown below. Above the system bar you can see the the favorites tray with various icons of your favorite apps (e.g., phone, mail, all apps button, messaging and web).

Page 2: Lecture 2 - The Wonderful World of Android

All app screen

If you touch on the all apps button (circled above) in the favorite tray on the home screen you will come to the all apps screen. Users can swipe through multiple app and widget screens and drag and drop items to customize the all app screens.

Recent apps screen

Apps that have been used and are currently stopped can be viewed by touching the recent app button on the navigation bar, as circled in the screen above. You can switch back to an app that you have previously used by simply touching it. Note that applications are stacked in reverse chronological order with the most recently used app at the bottom.

Page 3: Lecture 2 - The Wonderful World of Android

Status bar and notification screen

As denoted in the screen above, the status bar displays notifications on the left and status on the right. Status includes time, battery, cell signal strength, bluetooth enabled. Notifications on the right show wifi, mail, bewell, voicemail, usb active, music. The phone informs me that there is stuff for me to look at -- mail to read, voicemail, etc. These are pending notification of events that the user should take a peek at.

If you drag or swipe down the status bar it provides a whole lot more information on these notifications -- they are expanded from the simple icons in the status bar. Some of the notifications can be dismissed by a swipe, others cannot. We will use the status bar to notify the user of events in the code we write in this course. In the following screenshot, you can see that the expanded notification shade tells me my phone is in low battery, there is a screenshot I recently took, and that the BeWell app is currently running in the background. If I click the circled clear button, the phone will dismiss all the notifications that are dismissible.

Page 4: Lecture 2 - The Wonderful World of Android

If you drag the notification shade further down, you will see a menu with many quick toggle buttons to change settings. You can also adjust the screen light here.

Page 5: Lecture 2 - The Wonderful World of Android

Facebook UI

Android allows you to design UIs using graphical tools and xml. It also provides a number of widgets and standard layouts for the design of simple clean UIs. Here is an example that shows some standard UI components that you will use.

Consider the Facebook app. It uses the action bar -- in fact it uses a split action bar with a main action bar -- as shown in the figure below. When the page is running on a narrow screen and you have a lot of action items to load, you can use a split action bar at the bottom of the screen. You are use to using this navigation scheme as a Facebook user.

Action bar

A quick note on the action bar. The action bar is configurable from app to app and provides a semi-standard way to build out a simple and clean app UI to handle user action and app navigation.

Page 6: Lecture 2 - The Wonderful World of Android

The action bar provides a common and consistent interface for Android users. It can be used and adapted by many apps. We will show the email app below. We will use action bars and the ActionBar APIs to set up some clean UIs.

Gmail UI

The second app is the gmail UI --shown below. This time the main action bar is a lot simpler, with a hamburger icon to the left serving as a navigation drawer. Many actions are hidden there.

This allows users to switch between different views of the gmail such as the outbox, recent, drafts, sent, started and show all labels. Check it out on your phone.

App development cycle

As coders you are aware of the development cycle of any software but the unique part of Android is the publishing part -- see the development cycle below.

Page 7: Lecture 2 - The Wonderful World of Android

Some factoids on Androids

Java: Android applications are written in Java filename.apk: The Android SDK tools compile the code—along with any data

and resource files (layouts, strings)—into an Android PacKage (filename.apk). When you download an app from Google Play or install it yourself (from email, using ADB) you are installing the apk file.

UI design: Android separates the UI design from the program so they can be developed independently. In this manner you could theoretically completely change the UI without changing a line of Java code (not true in reality). The UI is designed using a graphical tool or Extensible Markup Language - XML:``XML is is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable''

What's in an app: application components

When you develop apps you will be using five key building blocks -- some apps may have all these components and others not -- really depends on what type of app you are planning on building:

activities: An activity is the key execution component. You need at least one activity in an app that deals with the UI but you probably will have multiple activity. This is the entry point to the application -- think of main() in C. An

Page 8: Lecture 2 - The Wonderful World of Android

activity might handle one or more screens in terms of UI control. For example, the camera app might have one activity to allow you to focus and take a photo and the start another activity to manage the storage locally and presentation of the photo to view. Each activity is independent of each other but could be coupled by control or data.

MyRuns comprises many activities. We will implement a number of activities. An activity you create is implemented as a subclass of Activity.

fragments: Fragments are new to Android but very important in programming the UI. I think of them as mini-activities. In implementation there are considerable differences; for example, an activity has to be specified in the manifest, while fragments do not because they can only exist in the context of an activity and are coupled to the activity state. While fragments are strongly integrated into the UI you can use fragments without a view or UI components. Fragments can implement a number of application behaviors, such as, code to handle listeners, files, database, etc. These types of fragments can be thought of as invisible worker for the activity -- more later on this. For now we will just consider fragments when applied to the UI.

Some of the MyRuns activities that deal with the UI have a number of fragments -- we will implement a lot of fragments. A fragment you create is implemented as a subclass of Fragment.

services: MyRuns need to read the location (e.g., GPS, WiFi, cellular) periodically and pass the location to an activity. The code that periodically interacts with the location manager is a service: a component that runs in the background detached from the main application activities -- sort of does its own thing that wants to sync to exchange information. Typically services are long running programs that don't need to interact with the UI. Other examples of services could be music which the user is listening to while reading CS65 notes, the Dartmouth Biorhythm Project code runs as a service in the background. Typically an activity will control a service -- that is, start it, pause it, bind and get data from it.

A service you create is implemented as a subclass of Service.

content providers: Apps share data. The nice thing about Android is you can not only call internal apps such as the camera but you can get data from apps that you might need for your application. For example, I want to develop an app that reads your contact lists and add them to your social networks (not always a good idea). To do this you need to interact with the content provider

Page 9: Lecture 2 - The Wonderful World of Android

of the contacts information. And assuming the user give you permission (at the time of install) you can interact with the content provider to get the data. Not only can apps get data (send query get response) but they can update the data -- add a contact for example.

A content provider is implemented as a subclass of ContentProvider.

broadcast receivers: If an service for example (the MyRuns location service) has data it can initiate broadcasts (something like ``I got the location for anyone interested''). The other end of that are components (e.g., an activity) that are broadcast receivers. Typically, broadcast receivers don't interact with the UI but commonly create a status bar notification to alert the user when a broadcast event occurs. So the broadcast announcement/receiver infrastructure is a way to delegate a task and the make sure components interested in an event (e.g., download completed, email to read, missed call) get that event to process.

A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object.

Android software framework

Android has a complex and deep set of components in its framework. The best way to understand this abstract stack is to use it.

Each Android app runs in its own security sandbox:

The Android operating system is a multi-user Linux system in which each application is a different user.

By default, the system assigns each application a unique Linux user ID (the ID is used only by the system and is unknown to the application). The system sets permissions for all the files in an application so that only the user ID assigned to that application can access them.

Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.

By default, every application runs in its own Linux process. Android starts the process when any of the application's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other applications. Note that the following diagram is taken from the Android wiki page,

Page 10: Lecture 2 - The Wonderful World of Android

and since Android 5.0 Lollipop system, the Dalvik VM has been officially replaced by a new runtime called ART (Android RunTime).


Recommended