Lecture Notes
Week 1 - Monday Notes
- Intro to Course
- Get the Big Nerd Ranch textbook now! Read chapters 1-6 and Build all of the projects! Do the study guides!
- Intro to Android Studio
- Android keyboard shortcut PDFs have been posted to mycourses
java
folder has code
res/layout/
folder has XML files that describe UI
res/values/strings.xml
contains localized string data
res/values/dimens.xml
is a place to set default margins and other layout values
res/drawable/
is where to put bitmap images or shape files (XML draw files)
res/raw/
is where to put sound files
res/mipmap/
is where to put application icon files
- A full listing of resource types is here: http://developer.android.com/guide/topics/resources/providing-resources.html
- Assets at
app/assets/
are another way to store and load application files - see chapter 18 of the BNR book.
- Android View v. Project View (the actual file structure)
- Under project view,
app/libs
is where you can put external libraries
- build.gradle (Module: app) is written in groovy and configures the project build. These values can be changed either by Android Studio, or by you directly.(Gradle is a build automation tool that is utilized by Android SDK.)
- You can read about Gradle build options here: https://developer.android.com/tools/building/configuring-gradle.html
AndroidManifest.xml
- this file presents essential information about your app to the Android system, information the system must have before it can run any of the app's code. See this page: http://developer.android.com/guide/topics/manifest/manifest-intro.html
- Check out File > Project Structure... then choose app and then the Dependencies tab to see where you can also import code libraries.
- Check out Tools > Android > SDK Manager - to keep your Android APIs up to date.
- Check out Tools > Android > AVD Manager - to manage your Android virtual devices.
- Check out Tools > Android > Android Device Manager - to launch an app that will help you profile and debug apps running on a device.
- Android Studio utilizes Android Debug Bridge (
adb
), which is a command-line tool for communicating with (i.e. installing apps on, browsing files, ...) Android devices and emulators. Once we all have Android devices we can use, the prof show you how to use the adb
tool. (The end of Chapter 1 shows you one way to do this with the gradlew
tool)
Week 1 - Wednesday Notes
Chapter 1 BNR- Your First Android Application
- In this chapter, you build your first app, GeoQuiz. We will walk through the building of some of this app:
- Create a new app with an Activity. An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the
Activity
class takes care of creating a window for you in which you can place your UI with setContentView(View)
. While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows or embedded inside of another activity. http://developer.android.com/reference/android/app/Activity.html
RelativeLayout
is a subclass of ViewGroup
, which is a subclass of View
. (A View
occupies a rectangular area on the screen and is responsible for drawing and event handling.) RelativeLayout
is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent.
- Docs for
RelativeLayout
are here: http://developer.android.com/reference/android/widget/RelativeLayout.html and http://developer.android.com/guide/topics/ui/layout/relative.html and http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
RelativeLayouts
can be slow sometimes because of the "two-passes" that are necessary to render them, but they can also be faster than complicated LinearLayouts
: http://www.crittercism.com/blog/android-performance-tip-1
- Widgets are subclasses of
View
and are things that the user can see and interact with like buttons, images, text fields, etc
- We'll go ahead and use this chapter's layout, which is a
LinearLayout
. LinearLayouts
arrange children in a single column or single row. The direction of the row can be set by calling setOrientation()
. By default, each view is layed out horizontally.
- Docs for
RelativeLayout
are here: http://developer.android.com/reference/android/widget/LinearLayout.html and http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html and http://developer.android.com/guide/topics/ui/layout/linear.html
- Android layouts can also be dynamically generated. More on layouts here: http://developer.android.com/guide/topics/ui/declaring-layout.html and http://www.tutorialspoint.com/android/android_user_interface_layouts.htm
Quick aside on units of measurement
- Continuing with GeoQuiz:
- Let's identify the XML elements and attributes in the Layout file, and the parent/child relationships of the View hierarchy.
- Let's look at how string resources are stored and looked up.
- The linkage between the java code and the layout file is set with a call to
setContentView()
- let's find that.
- Now we see
R.java
for the first time - let's look at that file. It's located at app/build/generated/source/r/debug
or can be found using global search Command/ctrl-shift-O - it contains all of your project resource ids (in inner classes named layout
and string
and id
and others) - don't modify this file!
- Now we'll give the buttons an id, and wire them up with
findViewById()
- their identifiers are under R.id
- Note the alt-enter/option-enter shortcut to import classes.
** That's enough for now - finish up chapter 1 on your own, and get working on chapter 2 & 3; there is a Study Guide forthcoming before Friday. PS - Be sure to bring your textbook to class Friday**