The Best from Google IOOndra Zahradník
@ondraz
Monday, May 27, 13
Agenda
• Gradle
• Volley
• Mobile Backend Starter
• Location
• Activity Recognition
• Games
• Google Play Console etc.
Monday, May 27, 13
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
Monday, May 27, 13
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
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
Gradle - Variants
• Free vs. Paid
• Multi-apk support
• Different runtimes,...
• Flavors = productFlavors
• Multi-flavor variants = flavorGroups
Monday, May 27, 13
Gradle Project Structure
/src /main
/java /eu/inmite.gradle.example
/res /drawables /values ... AndroidManifest.xml
/resources/paid /java ...
/src/instrumentTest
Monday, May 27, 13
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
Gradle Tasks
• assemble
• assembleDebug
• assembleRelease
• check
• deviceCheck
• build
• clean
Monday, May 27, 13
Volley
• Typical catches
• single-thread
• screen rotations = reloading
• not using recycled views
• Apache HTTP vs. URLConnection
Monday, May 27, 13
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
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
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
Mobile Backend Starter
• No code backend
• Google auth built in
• Google Cloud Messaging
• Continuous queries
Monday, May 27, 13
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
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
Geofencing
Monday, May 27, 13
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
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
Game API
Monday, May 27, 13
Game API
• G+ SSO
Monday, May 27, 13
Game API
• G+ SSO
• Achievements
Monday, May 27, 13
Game API
• G+ SSO
• Achievements
• Leaderboards
Monday, May 27, 13
Game API
• G+ SSO
• Achievements
• Leaderboards
• Cloud Save
Monday, May 27, 13
Game API
• G+ SSO
• Achievements
• Leaderboards
• Cloud Save
• Multiplayer
Monday, May 27, 13
Game API
• G+ SSO
• Achievements
• Leaderboards
• Cloud Save
• Multiplayer
• Works on Android, iOS, Web (except multi)
Monday, May 27, 13
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
Google Play Console
Monday, May 27, 13
Google Play Console
Monday, May 27, 13
Google Play Console
Monday, May 27, 13
Google Play Console
Monday, May 27, 13
Etc.
• In-app Purchase
• Simpler API for Google Cloud Messaging
• Cloud Connection Server = XMPP
• Synchronized notifications
• Google Play for Education
Monday, May 27, 13
Thank You!@ondraz
Monday, May 27, 13
Recommended