mdevcamp - the best from google io

34
The Best from Google IO Ondra Zahradník @ondraz Monday, May 27, 13

Upload: ondraz

Post on 09-May-2015

512 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: mDevCamp - The Best from Google IO

The Best from Google IOOndra Zahradník

@ondraz

Monday, May 27, 13

Page 2: mDevCamp - The Best from Google IO

Agenda

• Gradle

• Volley

• Mobile Backend Starter

• Location

• Activity Recognition

• Games

• Google Play Console etc.

Monday, May 27, 13

Page 3: mDevCamp - The Best from Google IO

Gradle

• Dependency mgmt.

• Library support

• Reuse of code and resources

• Build variants

• Testing, CI, SCM automation

• Use Gradle 1.6 and android plugin 0.4!

• Android Studio integration

Monday, May 27, 13

Page 4: mDevCamp - The Best from Google IO

Monday, May 27, 13

Page 5: mDevCamp - The Best from Google IO

Gradle Build Script

//configuration for gradle buildbuildscript { repositories { maven { url 'http://repo1.maven.org/maven2' } }

dependencies { classpath 'com.android.tools.build:gradle:0.4' }}

//gradle android pluginapply plugin: 'android'

//android DSLandroid { compileSdkVersion 17 buildToolsVersion "17.0.0"}

Monday, May 27, 13

Page 6: mDevCamp - The Best from Google IO

Gradle BuildType

• Defines how app is build

• Signing, proguard on/off, zipalign

• Package name suffix signingConfigs { inmite { storeFile file("inmite.keystore") keyAlias "inmite_android" } } buildTypes { debug { packageNameSuffix ".debug" versionNameSuffix "-debug" } release { signingConfig signingConfigs.inmite } }

Monday, May 27, 13

Page 7: mDevCamp - The Best from Google IO

Gradle - Variants

• Free vs. Paid

• Multi-apk support

• Different runtimes,...

• Flavors = productFlavors

• Multi-flavor variants = flavorGroups

Monday, May 27, 13

Page 8: mDevCamp - The Best from Google IO

Gradle Project Structure

/src /main

/java /eu/inmite.gradle.example

/res /drawables /values ... AndroidManifest.xml

/resources/paid /java ...

/src/instrumentTest

Monday, May 27, 13

Page 9: mDevCamp - The Best from Google IO

Gradle Libraries

• binary .aar package in existing repos

• supports proguard

• custom lint rules come later

//dependence on an external jar library//configurations - compile, instrumentTestCompile// debugCompile, releaseCompiledependencies { compile files('libs/android-support-v4.jar') compile 'com.google.guava:guava:14.0.1'}

Monday, May 27, 13

Page 10: mDevCamp - The Best from Google IO

Gradle Tasks

• assemble

• assembleDebug

• assembleRelease

• check

• deviceCheck

• build

• clean

Monday, May 27, 13

Page 11: mDevCamp - The Best from Google IO

Volley

• Typical catches

• single-thread

• screen rotations = reloading

• not using recycled views

• Apache HTTP vs. URLConnection

Monday, May 27, 13

Page 12: mDevCamp - The Best from Google IO

Volley

• Yet another networking library?

• 4 threads in background, prioritization

• mem/disk cache

• request cancellation

• !NetworkImageView!

• Network layers - OkHttp, URLConnection, ApacheHttp, SPDY,...

Monday, May 27, 13

Page 13: mDevCamp - The Best from Google IO

Volley - Request

mRequestQueue = ((Application) getApplication()).getRequestQueue();mImageLoader = new ImageLoader(mRequestQueue, new BitmapLRUCache());

mRequestQueue.add( new JsonObjectRequest( "https://dl.dropboxusercontent.com/u/5296640/a.json", null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { try { final JSONArray urls = (JSONArray) jsonObject.getJSONArray("images"); final String[] data = new String[urls.length()]; for (int i = 0; i < urls.length(); i++) { data[i] = urls.getString(i); } mImageAdapter = new ImageAdapter(data); setListAdapter(mImageAdapter); } catch (JSONException e) { Toast.makeText(..., getString(R.string.parse_error), ...).show(); } } }, null));

Monday, May 27, 13

Page 14: mDevCamp - The Best from Google IO

Volley - NetworkImageView

@Overridepublic View getView(int i, View view, ViewGroup viewGroup) { ...

final ViewHolder vh = (ViewHolder) view.getTag(); vh.iv.setImageUrl(data[i], mImageLoader); return view;}

private class ViewHolder { NetworkImageView iv;}

Monday, May 27, 13

Page 15: mDevCamp - The Best from Google IO

Mobile Backend Starter

• No code backend

• Google auth built in

• Google Cloud Messaging

• Continuous queries

Monday, May 27, 13

Page 16: mDevCamp - The Best from Google IO

Beyond the Blue Dot

• Contextual apps

• Fused location provider = sensors in play

• ListenersmLocationClient = new LocationClient(this, this, this);mLocationClient.connect();

Location location = mLocationClient.getLastLocation();

LocationRequest mLocationRequest = LocationRequest.create().setInterval(5000).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

mLocationClient.requestLocationUpdates(mLocationRequest,

mLocationListener);

Monday, May 27, 13

Page 17: mDevCamp - The Best from Google IO

Beyond the Blue Dot

• PendingIntentmLocationClient = new LocationClient(this, this, this);mLocationClient.connect();

LocationRequest mLocationRequest = LocationRequest.create().setInterval(5000).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

PendingIntent pi = PendingIntent.getService(this, 0, new Intent("com.example.location"), 0);mLocationClient.requestLocationUpdates(mLocationRequest, pi);

Monday, May 27, 13

Page 18: mDevCamp - The Best from Google IO

Geofencing

Monday, May 27, 13

Page 19: mDevCamp - The Best from Google IO

Geofencing

PendingIntent pi = PendingIntent.getService(this, 0, new Intent("com.example.location"), 0);

Geofence geofence = new Geofence.Builder() .setRequestId("id") .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER) .setCircularRegion(10,10,10) .setExpirationDuration(1000).build();

final List<Geofence> gfcs = new ArrayList<Geofence>();gfcs.add(geofence);

mLocationClient.addGeofences(gfcs, pi,new LocationClient.OnAddGeofencesResultListener() {

@Override public void onAddGeofencesResult(int i, String[] strings) { if (i != LocationStatusCodes.SUCCESS) { Toast.makeText(

MyActivity.this,"Cannot add geofences",Toast.LENGTH_SHORT).show();

} } });

Monday, May 27, 13

Page 20: mDevCamp - The Best from Google IO

Activity Recognition

• Riding, walking, cycling, still, tilting// Connect to the ActivityRecognitionServiceActivityRecognitionClient mActivityRecognitionClient = new ActivityRecognitionClient(this, this, this);mActivityRecognitionClient.connect(); // Called when a connection to the ActivityRecognitionService//has been established.public void onConnected(Bundle connectionHint) { Intent intent = new Intent(this, MyIntentService.class); PendingIntent callbackIntent = PendingIntent.getService( this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mActivityRecognitionClient.requestActivityUpdates( 30000, callbackIntent); }

Monday, May 27, 13

Page 21: mDevCamp - The Best from Google IO

Game API

Monday, May 27, 13

Page 22: mDevCamp - The Best from Google IO

Game API

• G+ SSO

Monday, May 27, 13

Page 23: mDevCamp - The Best from Google IO

Game API

• G+ SSO

• Achievements

Monday, May 27, 13

Page 24: mDevCamp - The Best from Google IO

Game API

• G+ SSO

• Achievements

• Leaderboards

Monday, May 27, 13

Page 25: mDevCamp - The Best from Google IO

Game API

• G+ SSO

• Achievements

• Leaderboards

• Cloud Save

Monday, May 27, 13

Page 26: mDevCamp - The Best from Google IO

Game API

• G+ SSO

• Achievements

• Leaderboards

• Cloud Save

• Multiplayer

Monday, May 27, 13

Page 27: mDevCamp - The Best from Google IO

Game API

• G+ SSO

• Achievements

• Leaderboards

• Cloud Save

• Multiplayer

• Works on Android, iOS, Web (except multi)

Monday, May 27, 13

Page 28: mDevCamp - The Best from Google IO

Game API

• G+ SSO

• Achievements

• Leaderboards

• Cloud Save

• Multiplayer

• Works on Android, iOS, Web (except multi)

• Quota 20mil req/day and 5req/sec/user

Monday, May 27, 13

Page 29: mDevCamp - The Best from Google IO

Google Play Console

Monday, May 27, 13

Page 30: mDevCamp - The Best from Google IO

Google Play Console

Monday, May 27, 13

Page 31: mDevCamp - The Best from Google IO

Google Play Console

Monday, May 27, 13

Page 32: mDevCamp - The Best from Google IO

Google Play Console

Monday, May 27, 13

Page 33: mDevCamp - The Best from Google IO

Etc.

• In-app Purchase

• Simpler API for Google Cloud Messaging

• Cloud Connection Server = XMPP

• Synchronized notifications

• Google Play for Education

Monday, May 27, 13

Page 34: mDevCamp - The Best from Google IO

Thank You!@ondraz

Monday, May 27, 13