Sandbox

// test code here!
print((200 * 7)/2)

print("hello from iOS team")

var question = "Ready to write your first lines of Swift code?"
print(question)

var response = "Yeah! I'm ready!"
print(response)
var numberOfServingsForRecipe = 4
var desiredNumberOfServings = 8

var servingsFactor = desiredNumberOfServings/numberOfServingsForRecipe

var poundsOfTomatoesForRecipe = 2
var amountToUseToday = poundsOfTomatoesForRecipe * servingsFactor

print(amountToUseToday)

Drawing to code

step1: select the views
step2: position the views
step3: style the views

what view group should you use
-LinearLayout
-RelativeLayout : relative positioning, overlap

The drawable folder
android:src=”@drawable/androidparty”

Position the view
Style the view

Trouble shooting

android studio strouble shooting
https://docs.google.com/document/d/1w1Xn_hnSAODAAtdRDp7haYPBtEwX_l7Htpf8Wpgbu6w/pub?embedded=true

Linear layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:paddingBottom="@dimen/activity_vertical_margin"
	android:paddingLeft="@dimen/activity_horizontal_margin"
	android:paddingRight="@dimen/activity_horizontal_margin"
	android:paddingTop="@dimen/activity_vertical_margin"
	tools:context="com.xxx.myapplication.MainActivity">

	<TextView
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="Hello world!" />
</RelativeLayout>

Relative Layout

top edge, left edge, right edge, buttom edge
relative to parent

android:layout_alignParentTop=”true”
android:layout_alignParentBottom=”false”
android:layout_alignParentLeft=”true”
android:layout_alignParentRight=”true”

<RelativeLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:padding="16dp">

	<TextView
		android:text="I'm in this corner"
		android:layout_height="wrap_content"
		android:layout_width="wrap_content"
		android:layout_alignParentBottom="true"
		android:layout_alignParentLeft="true" />

    <TextView
        android:text="No, up here"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true" />
 
    <TextView
        android:text="Wait, I’m here"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" />
 
    <TextView
        android:text="Actually, I’m here"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true" />

</RelativeLayout>

Simple image view

<ImageView
	android:src="@drawable/cake"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:scaleType="center"/>
<ImageView
	android:src="@drawable/cake"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:scaleType="centerCrop"/>

textView android, use google search
https://developer.android.com/reference/android/widget/TextView.html

capitalize

<TextView
	android:text="Oh the possibilites of TextView"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:textSize="36sp"
	android:textAllCaps="false"/>

LinearLayout

<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content">

<TextView
	android:text="I'm a lonely TextView"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content" />

<TextView
	android:text="I'm a lonely TextView"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content" />

</LinearLayout>

android orientation
https://developer.android.com/reference/android/widget/LinearLayout.html

200dp, wrap_content, match_parent

wrap_content

<TextView
	android:text="wait, today's your birthday?"
	android:background="@android:color/darker_gray"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content" />

font size

<TextView
	android:text="wait, today's your birthday?"
	android:background="@android:color/darker_gray"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:textSize="56sp" />

appearance

<TextView
	android:text="wait, today's your birthday?"
	android:background="@android:color/darker_gray"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:textAppearance="?android:textAppearanceSmall" />

google design spec style color
https://material.io/guidelines/style/color.html

text color and background color

<TextView
	android:text="wait, today's your birthday?"
	android:background="#ECEFF1"
	android:textColor="#616161"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:textAppearance="?android:textAppearanceSmall" />

Using a TextView

<TextView
	android:text="Happy Birthday!"
	android:background="@android:color/darker_gray"
	android:layout_width="150dp"
	android:layout_height="75dp" />

-weird angle brackets
-don’t know what “android:text” means
-says Happy Birthday which appears on phone

XML Syntax

<LinearLayout
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:orientation="vertical">

	<TextView
		android:text="Happy Birthday"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content" />

	<TextView
		android:text="You're the best!"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content" />

</LinearLayout>

Attribute Name, Attribute value in “Quotations”
TextView has default values if you’re ok with default values, don’t set them here.

negative correlation

How much two variable related each other.
always use correlation in statistic.
x= 3, 4, 5
y= 8, 5, 3

r = Σi[(xi-x)(yi-y)] / √Σi[(xi-x)(yi-y)]
x=1/N Σ Xi
y=1/N Σ Yi

x-x -1, 0, 1
y-y 3, 0, -3

= -6 / √ 2 * 18
= -1

x= 3, 4, 5
y= 8, 5, 8
r= 0

x= 3, 4, 5 xμ = 4
y= 8, 3, 7 yμ = 6

x-x -1, 0, 1
y-y 2, -3, 1

= -1 / √ 2 * 14
= -0.189

Correlation

Correlation
r = 1 positive linear
r = 0 no relation within the data
r = -1 negative linear

b = 4
a = -3
y = 4x – 3
r is positive

correlation efficient
value between -1 and 1

r = Σi[(xi-x)(yi-y)] / √Σi[(xi-x)(yi-y)]
x=1/N Σ Xi
y=1/N Σ Yi

if it is
x 3, 4, 5
y 7, 8, 9

2 / √2 * 2 = 1
we know r is between -1 and 1.

x= 3, 4, 5
y= 2, 5, 8
x-x -1, 0, 1
y-y -3, 0, 3

= 6 / √ 2 * 6
= 1

Hypothesis Testing

sample -> statistic -> information -> statistic -> decision

weight loss 90% guaranteed
Yes 11, No 4
H0: p = 0.9
H1: p < 0.9 critical regions Null hypothesis [python] from math import sqrt def mean(l); return float(sum(l))/len(l) def var(l): m = mean(l) return sum([(x-m)**2 for x in l])/len(l) def factor(l): return 1.96 def conf(l): return factor(l) * sqrt(val(l)/ len(l)) def test(l, h): m = mean(l) c = conf(l) return abs(h-m) <= c l = [199, 200, 201, 202, 203, 204] print mean(l) print conf(l) [/python] 95% confidence candidate A 55 candidate B 45 1.96√p(1-p)/n = 1.96√.55-.44/100 = 9.75 Candidate A: 55 +/- 9.75