Android Development

You're No Filthy F@#&ing Casual

android logo

By Drew Lopreiato

Assumptions

You know Java.

java logo

You've heard of Android before.

android being used

You're familiar with Java Standard Library.
java.io
java.lang
java.util
etc...

            

Tonight's Goals

The structure of Android.

The structure of an app.

Efficiently use Android documentation.

Disclaimer

I don't know everything about Android.

Common Sense should prevail.

The color orange enrages me.

Disclaimer

I don't know everything about Android.

Common Sense should prevail.

The color orange enrages me.

Android Design

Versioning 3 - 10

Cupcake
Version:1.5 API:3
cupcake
Donut
Version:1.6 API:4
donut
Eclair
Version:2.0 API:5-7
eclair
Froyo
Version:2.2 API:8
froyo
Gingerbread
Version:2.3 API:9-10
gingerbread

Versioning 11 - 21

Honeycomb
Version:3.0 API:11-13
honeycomb
Ice Cream
Sandwich
Version:4.0 API:14-15
icecreamsandwich
Jelly Bean
Version:4.1 API:16-18
jellybean
KitKat
Version:4.4 API:19-20
kitkat
Lollipop
Version:5.0 API:21
lollipop

Interactive Design Elements

Notification

home screen notification example notification tray example

Dialog

dialog example

Toasts

toast example

Widgets

widget example

Buttons

button example

Text Field

textfield example

Checkbox

checkbox example

Radio Button

radio example

Toggle Button

toggle button example

Spinner

spinner example

Picker

picker example

Structural Design Elements

Action Bar

Navigation Drawer

Tabs

Lists

lists

Scrolling

Options Menu

Overview Screen

overview screen

Themes

original theme holodark theme material theme material theme

Somewhat Unkown/Unused Features

NFC (Near Field Communication)

Wi-Fi Peer-to-Peer

Android Application Architecture

Activity

Provides a screen with which users can interact in order to do something

Task

Collection of Activities
Saved Back Stack

overview screen

Intent

Start an Activity

Start a Service

Broadcast a Message

Components of an Intent

  • Component Name (Optional)
  • Category
  • Action
  • Data
  • Extras
  • Flags

Services

Does background processing

Music Playing
Network Transactions

Android Lifecycle

android lifecycle

Android Lifecycle

android lifecycle with explanation

Making Your First App

Android Studio

ide download page

Your Phone

phone settings about phone tapping build number your a developer! good work! here are the dev options
android studio start screen
android studio new project
android studio minimum sdk
android studio start activity
android studio activity options

XML

Describes data
Really Inefficiently and Unreliably
<stuff_i_hate>
  <thing>
    <name>Pitbull</name>
    <description>
      For writing the lyrics "Or should I say, I saw, I conquered, I came"
    </description>
  </thing>
  <thing>
    <name>XML</name>
    <description>
      Extremely lengthy, could have used quotation marks but NOOOOOO that'd be too convenient.
    </description>
  </thing>
  <thing>
    <name>West Cookies</name>
    <description>
      Under-cooked Cookies != Good Cookies
    </description>
  </thing>
</stuff_i_hate>

            

Creating your GUI

Layouts & Views

layout xml editor

Why God, Why XML?!

Well defined and can describe both hierarchy and properties

Separation of View and Model

Configurability

Types of Layouts

  • Frame
  • Linear
  • Table
  • Grid
  • Relative

Common Widgets

  • TextView
  • EditText
  • Most Aforementioned Components

Building a Layout

layout graphical editor

Component Properties

  • Width & Height
  • Padding
  • Background/Object Colors
  • ID

Getting your app to do stuff

Like take input, and give output

And possibly even process data, and talk to the network

The Activity Code

public class MainACMActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_acm);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main_acm, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
              
            
android lifecycle

Implementing a Lifecycle Function

@Override
public void onStop() {
    super.onStop();

    System.out.println("Hammer time");
}
              
            

Resource Referencing : The Folder

res folder completely expanded

Resource Referencing: The Code

  userNameField = (EditText) findViewById(R.id.userName);
              
            
  userNameField.getText().toString();
              
            

Data Storage

Shared Preferences

public static final String PREFERENCE_FILE = "MyPrefsFile";
            
int toYourAddress = distanceCalculator(...);

SharedPreferences settings = getSharedPreferences(PREFERENCE_FILE, 0);
SharedPreferences.Editor prefEditor = settings.edit();
prefEditor.putInt("toYA", toYourAddress);
            
SharedPreferences uptownFunk = getSharedPreferences(PREFERENCE_FILE, 0);
int distanceToYourAddress = uptownFunk.getInt("toYA", DEFAULT_INT);
// Don't beleive me? Just watch.
            

Internal/External Storage

FileOutputStream fileStream =
    openFileOutput(FILENAME, Context.MODE_PRIVATE);
fileStream.write(data.getBytes());
fileStream.close();
            
FileInputStream fileStream =
    openFileInput(FILENAME, Context.MODE_PRIVATE);
something = fileStream.read();
fileStream.close();
            
new File(
    getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
    "myPicture.png");
            

Database

SQLite Logo

Knowledge Required: SQL

Network

java.net.*
android.net.*
            

Adapters

private ListView listView;
private ArrayList<String> footballGamePlaylist;

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...

    // fill data
    footballGamePlaylist = new ArrayList<String>();
    for (int i = 0; i < 50; i++) {
        footballGamePlaylist.add("We Dem Boyz");
    }

    // prepare adapter
    ArrayAdapter<String> adapter;
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, footballGamePlaylist);

    // connect adapter
    listView.setAdapter(adapter);
}
    
          

And don't forget...

Not everything needs to extend an Android class.

The Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="us.lopreiato.acm_presentation" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainACMActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

          

Thank you

Visit my Github for the source where I left more comments.
http://github.com/dLopreiato

Made with reveal.js