Android L01 - Warm Up

106
Cloud Interaction Design Android

Transcript of Android L01 - Warm Up

Page 1: Android L01 - Warm Up

CloudInteraction Design

Android

Page 2: Android L01 - Warm Up

READ

Page 3: Android L01 - Warm Up

It’s no longer about Building

Page 4: Android L01 - Warm Up

Learn and Measure Don’t just Build

Page 5: Android L01 - Warm Up

Why do you want this?

Page 6: Android L01 - Warm Up

IMPACT.

Page 7: Android L01 - Warm Up

Web apps

vs.Native apps

Page 8: Android L01 - Warm Up

iOS

vs.Android

Page 9: Android L01 - Warm Up

Objective-C/ Swiftvs.

Java

Page 10: Android L01 - Warm Up
Page 11: Android L01 - Warm Up
Page 12: Android L01 - Warm Up

HTML5 and JavaScript

<!DOCTYPE   html><html>  <head>  <link rel="stylesheet"   href="styles.css"><meta  charset="utf-­‐-­‐8"><script src="scripts.js"></script>

<title>hello,   world</title></head><body>hello, world  </body>

</html>

Page 13: Android L01 - Warm Up

JavaScript

<script  type="text/JavaScript">  function  loadFile(url){

var script   = document.createElement('SCRIPT');script.src =   url;  document.getElementsByTagName('HEAD')[0].appendChild(script);

}</script>

Page 14: Android L01 - Warm Up

XML Simple Email

<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't  forget  me  this  weekend!

</body></note>

Page 15: Android L01 - Warm Up

Ajax andXMLHttpRequest

Page 16: Android L01 - Warm Up

jQueryhttp://jquery.com/

Page 17: Android L01 - Warm Up

Frameworks• jQuery Mobile• PhoneGap• Sencha Touch• Xamarin• AngularJS + iconic• … etc

Page 18: Android L01 - Warm Up

Gaming

Page 19: Android L01 - Warm Up

Games (OpenGL, Metal and the rest)

Page 20: Android L01 - Warm Up

How we are gonna do it.

Page 21: Android L01 - Warm Up

Googling StackOVerFlow

Page 22: Android L01 - Warm Up

Android

Page 23: Android L01 - Warm Up

Cloud

Page 24: Android L01 - Warm Up

User ExperienceInteraction Design

Page 25: Android L01 - Warm Up

User Experience

Page 26: Android L01 - Warm Up

User Experience

Page 27: Android L01 - Warm Up

Java Primer

Page 28: Android L01 - Warm Up

InstallJRE, JDK

Page 29: Android L01 - Warm Up

JavaJVM – Java Virtual Machine

Page 30: Android L01 - Warm Up

APIhttp://java.sun.com/javase/6/docs/api/

Tutorial http://java.sun.com/docs/books/tutorial/java/TOC.html

Page 31: Android L01 - Warm Up

JavaWrite once, run anywhere

Page 32: Android L01 - Warm Up

JavaWrite once, run anywhere

Page 33: Android L01 - Warm Up

Reserved Words

abstract continue for new switch

assert*** default goto* package synchronized

boolean do if private this

break double implements protected throw

byte else import public throws

case enum**** instanceof return transient

catch extends int short try

char final interface static void

class finally long strictfp** volatile

const* float native super while

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html

Page 34: Android L01 - Warm Up

Primitive Types

byteshortintlongfloatdoublebooleanchar

Page 35: Android L01 - Warm Up

Variables Naming

• Subsequent characters also can be numbers• Case sensitive• No spaces• Examples:

namefirstNamephoneNumber

Page 36: Android L01 - Warm Up

Arrays

int[]  grades;grades  =  new  int[15];

Control flowif  (boolean)  {

//  perform  this  code}  else  {

//  otherwise,  run  this}

Page 37: Android L01 - Warm Up

Referencing

int hoursePower =  100;

Car  myCar =  new  Car(hoursePower );Car  yourCar =  new  Car(hoursePower +  50);

myCar =  yourCar;

Print(myCar.HorsePower);

Page 38: Android L01 - Warm Up

Packagesvs

Namespaces

Page 39: Android L01 - Warm Up

void  main(string[]  args)

Page 40: Android L01 - Warm Up

Instance vs Classmethods

void  shootBall(Point  point)static  void  main(string[]  args)

Page 41: Android L01 - Warm Up

Inheritance and Polymorphismextends,  super,  @Override

Page 42: Android L01 - Warm Up

Some diff.protected in a form of package scope not class scope

Page 43: Android L01 - Warm Up

Some diff.final  vs const vs readonly

Page 44: Android L01 - Warm Up

interfaces

Page 45: Android L01 - Warm Up

Collections

Page 46: Android L01 - Warm Up

Example

ArrayList<String>   arrList =  new  ArrayList<String>();arrList.add(“A”);arrList.add(“AB”);arrList.add(“ABC”);arrList.add(“ABCD”);//  using  indicesarrList.set(0,   arrList.get(1));arrList.set(1,   “foo”);

Page 47: Android L01 - Warm Up

Example

• What does the following mean?

ArrayList<String>   A1;//  bla blaList<String>  list  =  new  ArrayList<String>(A1);

Page 48: Android L01 - Warm Up

for-each

• Looping by indices• for-each, parallel execution

for  (Object  o  :  collection)  System.out.println(o);

Page 49: Android L01 - Warm Up

Collection Operations

List<Type>   list1  =  new  ArrayList<Type>();//  …List<Type>   list2  =  new  ArrayList<Type>();//  …List<Type>   list3  =  new  ArrayList<Type>(list1);  list3.addAll(list2);

Page 50: Android L01 - Warm Up

List Algorithms

• sort — sorts a List using a merge sort algorithm, which provides a fast, stable sort. (A stable sort is one that does not reorder equal elements.)

• shuffle — randomly permutes the elements in a List.• reverse — reverses the order of the elements in a List.• rotate — rotates all the elements in a List by a specified distance.• swap — swaps the elements at specified positions in a List.• replaceAll — replaces all occurrences of one specified value with

another.• fill — overwrites every element in a List with the specified value.• copy — copies the source List into the destination List.• binarySearch — searches for an element in an ordered List using the

binary search algorithm.• indexOfSubList — returns the index of the first sublist of one List that

is equal to another.• lastIndexOfSubList — returns the index of the last sublist of

one List that is equal to another.

See more @ http://docs.oracle.com/javase/tutorial/collections/interfaces/list.html

Page 51: Android L01 - Warm Up

Iterators

Page 52: Android L01 - Warm Up

Lambdajlambda expression

Page 53: Android L01 - Warm Up

LambdajLINQ-like

Page 54: Android L01 - Warm Up

Lambdajhttps://github.com/ooxi/lambdaj

Page 55: Android L01 - Warm Up

Multithreadingsynchronized,  wait,  notify,  notifyall

Page 56: Android L01 - Warm Up

IntoAndroid!

Page 57: Android L01 - Warm Up
Page 58: Android L01 - Warm Up
Page 59: Android L01 - Warm Up

IDEsEclipse, Android Studio

Page 60: Android L01 - Warm Up

Android versions and versions and versions

Page 61: Android L01 - Warm Up

Android Developerhttp://developer.android.com

Page 62: Android L01 - Warm Up
Page 63: Android L01 - Warm Up
Page 64: Android L01 - Warm Up

Tools

• android - Android SDK manager. Create/delete/view Android Virtual Devices and update the SDK with new platforms/add-ons.

• ddms - Dalvik Debug Monitor Server. Screen caps, thread/heap info, process/state info, ..

• emulator - The application responsible for opening AVDs instances.

• sqlite3 - manage SQLite databases.

Page 65: Android L01 - Warm Up

SDK – Cont.

• # adb - Android Debug Bridge. A client/server program that manages the state of an emulated device.

• # aapt - Android Asset Packaging Tool.• # dx - The converter; converts .class files to Android

bytecode.

Page 66: Android L01 - Warm Up

Creating Your First Android App

Page 67: Android L01 - Warm Up

Create Project with Android Studio

• Build SDK is the platform version against which you will compile your app. By default, this is set to the latest version of Android available in your SDK.

• Minimum Required SDK is the lowest version of Android that your app supports

Page 68: Android L01 - Warm Up

Hello World

Page 69: Android L01 - Warm Up

Hello World

Page 70: Android L01 - Warm Up

Activity Life Cyclehttp://developer.android.com/reference/android/app/Activity.html

Page 71: Android L01 - Warm Up

File System

Page 72: Android L01 - Warm Up

File System

Page 73: Android L01 - Warm Up

Conventions

Page 74: Android L01 - Warm Up

USB Debugging

Page 75: Android L01 - Warm Up

Try it. Just run it.

Page 76: Android L01 - Warm Up

activity_main.xml<RelativeLayoutxmlns: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"  >

<TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:text="@string/hello_world"tools:context=".MainActivity"  />

</RelativeLayout>

Page 77: Android L01 - Warm Up

Adding your first button

• res > values > strings• Add toggle_message to strings file.• And in the activity_main.xml file<Button

android:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/textView1"android:layout_centerHorizontal="true"android:layout_marginBottom="18dp"android:text="@string/toggle_message"   />

Page 78: Android L01 - Warm Up

Adding your first button

• res > values > strings• Add toggle_message to strings file.• And in the activity_main.xml file<Button

android:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/textView1"android:layout_centerHorizontal="true"android:layout_marginBottom="18dp"android:text="@string/toggle_message"   />

Page 79: Android L01 - Warm Up

Adding your first button

• res > values > strings• Add toggle_message to strings file.• And in the activity_main.xml file<Button

android:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/textView1"android:layout_centerHorizontal="true"android:layout_marginBottom="18dp"android:text="@string/toggle_message"   />

Page 80: Android L01 - Warm Up

Adding a Click Event

• MainActivity.javapublic  void  toggleMessageOnClick(View  view)  {

TextView textView =  (TextView)findViewById(R.id.textView1);textView.setText("Bonjour  Monde!");

}

• activity_main.xml<Button

android:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/textView1"android:layout_centerHorizontal="true"android:layout_marginBottom="18dp"android:text="@string/toggle_message“android:onClick="toggleMessageOnClick"  />

Page 81: Android L01 - Warm Up

[OR] Adding a Click Event

• MainActivity.java@Override        protected  void  onCreate(Bundle  savedInstanceState)  {                            

super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);                Button  btn =  (Button)findViewById(R.id.button1);btn.setOnClickListener(new  onClickListener()  {                    

@Override                        public  void  onClick(View  arg0){                                

TextView textView =  (TextView)findViewById(R.id.textView1);                                textView.setText("Bonjour  Monde!");                        

}                });

}

• activity_main.xml<Button

..android:onClick="toggleMessageOnClick"  />

Page 82: Android L01 - Warm Up

[OR] Adding a Click Event

Page 83: Android L01 - Warm Up

Run and see!

Page 84: Android L01 - Warm Up

Debug

Page 85: Android L01 - Warm Up

Debug LoggingLog.d(“MY_TAG",  ”Any  message  here.");

Page 86: Android L01 - Warm Up

UIElements

Page 87: Android L01 - Warm Up
Page 88: Android L01 - Warm Up
Page 89: Android L01 - Warm Up
Page 90: Android L01 - Warm Up
Page 91: Android L01 - Warm Up
Page 92: Android L01 - Warm Up
Page 93: Android L01 - Warm Up
Page 94: Android L01 - Warm Up
Page 95: Android L01 - Warm Up

What do you think is better/faster?

Page 96: Android L01 - Warm Up

What do you think is better/faster?

faster slower

Page 97: Android L01 - Warm Up
Page 98: Android L01 - Warm Up

Menushttp://developer.android.com/guide/topics/ui/menus.html

Page 99: Android L01 - Warm Up

Menus

Options Menu Context menu Popup Menu

Page 100: Android L01 - Warm Up

References

Page 101: Android L01 - Warm Up

READ

Page 102: Android L01 - Warm Up

Always!http://developer.android.com/

Page 103: Android L01 - Warm Up

Attend Harvard’s OpenCourseWare 201[2]!Building Mobile Applications, http://cs76.tv/2012/spring/

Mobile Software Engineering, http://cs164.tv/2012/spring/

Or Lynda, Udacity, Coursera

Page 104: Android L01 - Warm Up
Page 105: Android L01 - Warm Up

Design Patterns, Gang of four

Page 106: Android L01 - Warm Up