Transcript lec02

Lecture 2 agenda
flip teaching
install p4merge
rename project packages
review git
review Android Studio (Vinny)
layouts and resources
java event model
labGeoQuizz chapters 1-3
flipping the classroom explained
http://en.wikipedia.org/wiki/Flip_teaching
Flip teaching (or flipped classroom) is a form of blended
learning in which students watch lectures online and work
on problem sets with other students in class.
This approach allows teachers to spend more time
interacting with students instead of lecturing. This is also
known as backwards classroom, reverse instruction, flipping
the classroom and reverse teaching
Installing an external diff/merge tool:
http://www.perforce.com/downloads/PerforceSoftware-Version-Management/complete_list/Customer
http://www.perforce.com/downloads/
click on Software Version Managment
click on Customer Downloads
p4Merge +
Mac: SourceTree || Preferences || Diff || P4Merge
Open each project and rename your package from
jstudent to first-initial-last-name
Then push your changes.
GIT architecture
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
add/reset/commit:
move files from working-dir to stage-dir(aka index)
git add .
git add res/.
git add src/.
git add res/values/strings.xml
move files from stage-dir(aka index) to working-dir
git reset HEAD .
git reset head res/.
git reset head src/.
git reset head res/values/strings.xml
git commit -m “your commit message.”
Reverting (does the exact opposite)
git revert 0da8 --no-edit
git revert head --no-edit
git revert head~3 --no-edit
To clear all local changes since last push
git reset --hard origin/master
To delete a remote branch
git push origin :branchName
Amending:
Every commit is associated with a sha-1 hash. That hash
is derived from 1/ the file changes in that commit and
2/ the previous commit.
You can not change any commit unless that commit is at
the head. Since no other commits depend on the head,
you may safely change the head.
To change the head, use
git commit --amend -m “your message”
git commit --amend --no-edit
Branching:
To list the branches in a project:
git branch
git branch -r
git branch --all
To create a branch:
git checkout -b branchName c39b
git checkout -b branchName
To delete a branch:
git branch -D branchName
To checkout a branch:
git checkout 7afe
git checkout master
Pushing to remotes:
To see the remotes:
git remote -v show
To push to a remote:
git push origin master
git push --all
To clear all local changes since last push
git reset --hard origin/master
Android Studio
Default keymap:
http://android.cs.uchicago.edu/content/slides/keymap.pdf
File || settings || keymap
Java Review
Class
Objects
Class
Objects
Spot the “class” here
Java Primitives (integers)
Type
Signed?
byte
signed
8
short
signed
16
int
long
signed
signed
Bits Bytes Lowest
Highest
7
1 -2
-128
27-1
+127
15
2 -2
-32,768
215-1
32,767
32
-231
4 -2,147,483,648
231-1
2,147,483,647
64
-263
263-1
-9,
8 223,372,036,854 9,223,372,036,85
4,775,807
,775,808
How Java Stores positive Integers
-2(bits -1) to 2(bits -1) – 1
•0001 0011
•The above is a binary representation of the
number 19 stored in a byte (8 bits).
•The range of a byte is: -128 to 127.
Java Primitives (others)
Type
Signed?
boolean
n/a
char
unsigned
Unicode
float
signed
exponent
and
mantissa
double
signed
exponent
and
mantissa
Bits Bytes Lowest
1
16
32
64
Highest
1 false
true
2 0
'\u0000'
216-1
'\uffff'
4 ±1.4012984643
2481707e-45
±3.40282346638
528860e+38
with 6 to 7
significant digits
of accuracy.
8 ±4.9406564584
1246544e-324
±1.79769313486
231570e+308
with 14 to 15
significant digits
of accuracy.
Primitives versus Objects
memory
Primitives
Objects
Variables store values and are
allocated memory depending on their
type. How much?...refer to Java
Primitives slide.
References store memory
addresses. The size of the allocation
for the object reference is VM specific,
but is usually the native pointer size;
32bits in 32-bit VM, and 64bits in a 64bit VM.
Garbage collected when out-of-scope.
Garbage collected when out-of-scope.
Passed into methods by value
Passed into methods by reference
(value of the address is passed)
primitive
pass by value
Action: Tell my accountant how
much I intend to spend on a new
car next year. Change in bank
account: no change.
object
pass by reference
Action: Swipe debit card and enter
pin at the Bently dealership.
Change in bank account: -125k.
Java version versus release number
1.5
1.6
1.7
Java 5
Java 6
Java 7
mix-up between engineering and marketing at Sun (now
Oracle)
If a tree falls in a forest and no one is around to hear it, does it make a sound?
Event-Source
(Button)
No Event-Listener
listening
Event
(onClick)
No Catcher
No Event Listener
Event-Listener listening
Event-Source
(Button)
Event
(onClick)
OnClickListener
Any Object
Catcher ready to catch
Wrong Event
Event source not
registered
Event-Source
(Button)
Event-Listener listening OnClickListener
Event
(onClick)
OnMouse
-Listener
Any Object
Event
(onMouse)
Catcher ready to catch
Resources in Android
R.java is a table
In Android, there's a res directory,
which stands for resources.
ldpi is 0.75x dimensions of mdpi
mdpi is 1x dimensions of mdpi
hdpi is 1.5x dimensions of mdpi
xhdpi is 2x dimensinons of mdpi
go to vidoes/resources01 time 3:50
strings.xml
<string name="earth">Earth</string>
<string name="moon">Moon</string>
<string-array name="system">
<item>@string/earth</item>
<item>@string/moon</item>
</string-array>
colors.xml
<color name="gray">#eaeaea</color>
<color name="titlebackgroundcolor">#00abd7</color>
<color name="titlecolor">#666666</color>
<color name="opaque_red">#f00</color>
<color name="translucent_red">#80ff0000</color>
#RGB
#ARGB
#RRGGBB
#AARRGGBB
dimens.xml
<dimen name="textview_height">25dp</dimen>
<dimen name="textview_width">150dp</dimen>
<dimen name="ball_radius">30dp</dimen>
<dimen name="font_size">16sp</dimen>
bools.xml
<bool name="screen_small">true</bool>
<bool name="adjust_view_bounds">true</bool>
dp stands for density independent pixels
It's relative to a 160 dpi screen. So 1dp is one pixel on a 160dpi
screen.
Don't worry about calculating the dp's. Android does that for you.
Add resources from the Add Resources from the graphical editor and also
manually.
#FFFFFF white
getResources(). getStringArray(R.array.whatever)