Skip to content

Commit 76c7a82

Browse files
author
Paul Ruiz
committed
Places API and Vector Drawables
1 parent 0f8f7ce commit 76c7a82

File tree

67 files changed

+1605
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1605
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#Fri Apr 10 11:34:18 MDT 2015
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

PlacesAPI/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

PlacesAPI/app/build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 21
5+
buildToolsVersion "21.1.2"
6+
7+
defaultConfig {
8+
applicationId "com.tutsplus.placesapi"
9+
minSdkVersion 14
10+
targetSdkVersion 21
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
compile 'com.android.support:appcompat-v7:22.0.0'
25+
compile 'com.google.android.gms:play-services:7.0.0'
26+
}

PlacesAPI/app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/paulruiz/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.tutsplus.placesapi;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.tutsplus.placesapi" >
4+
5+
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
6+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
7+
8+
<uses-feature
9+
android:glEsVersion="0x00020000"
10+
android:required="true"/>
11+
12+
<application
13+
android:allowBackup="true"
14+
android:icon="@mipmap/ic_launcher"
15+
android:label="@string/app_name"
16+
android:theme="@style/AppTheme" >
17+
18+
<meta-data
19+
android:name="com.google.android.geo.API_KEY"
20+
android:value="@string/google_api_key" />
21+
<meta-data
22+
android:name="com.google.android.gms.version"
23+
android:value="@integer/google_play_services_version" />
24+
25+
<activity
26+
android:name=".MainActivity"
27+
android:label="@string/app_name" >
28+
<intent-filter>
29+
<action android:name="android.intent.action.MAIN" />
30+
31+
<category android:name="android.intent.category.LAUNCHER" />
32+
</intent-filter>
33+
</activity>
34+
</application>
35+
36+
</manifest>
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.tutsplus.placesapi;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.ArrayAdapter;
9+
import android.widget.Filter;
10+
import android.widget.TextView;
11+
import android.widget.Toast;
12+
13+
import com.google.android.gms.common.api.GoogleApiClient;
14+
import com.google.android.gms.common.api.ResultCallback;
15+
import com.google.android.gms.location.places.AutocompleteFilter;
16+
import com.google.android.gms.location.places.AutocompletePrediction;
17+
import com.google.android.gms.location.places.AutocompletePredictionBuffer;
18+
import com.google.android.gms.location.places.Place;
19+
import com.google.android.gms.location.places.Places;
20+
import com.google.android.gms.maps.model.LatLng;
21+
import com.google.android.gms.maps.model.LatLngBounds;
22+
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
import java.util.concurrent.TimeUnit;
26+
27+
/**
28+
* Created by paulruiz on 4/12/15.
29+
*/
30+
public class AutoCompleteAdapter extends ArrayAdapter<AutoCompletePlace> {
31+
32+
private GoogleApiClient mGoogleApiClient;
33+
34+
public AutoCompleteAdapter( Context context ) {
35+
super(context, 0);
36+
}
37+
38+
@Override
39+
public View getView( int position, View convertView, ViewGroup parent ) {
40+
ViewHolder holder;
41+
42+
if( convertView == null ) {
43+
holder = new ViewHolder();
44+
convertView = LayoutInflater.from( getContext() ).inflate( android.R.layout.simple_list_item_1, parent, false );
45+
holder.text = (TextView) convertView.findViewById( android.R.id.text1 );
46+
convertView.setTag( holder );
47+
} else {
48+
holder = (ViewHolder) convertView.getTag();
49+
}
50+
51+
holder.text.setText( getItem( position ).getDescription() );
52+
53+
return convertView;
54+
}
55+
56+
public void setGoogleApiClient(GoogleApiClient googleApiClient) {
57+
this.mGoogleApiClient = googleApiClient;
58+
}
59+
60+
private class ViewHolder {
61+
TextView text;
62+
}
63+
64+
@Override
65+
public Filter getFilter() {
66+
return new Filter() {
67+
@Override
68+
protected FilterResults performFiltering(CharSequence constraint) {
69+
70+
if( mGoogleApiClient == null || !mGoogleApiClient.isConnected() ) {
71+
Toast.makeText( getContext(), "Not connected", Toast.LENGTH_SHORT ).show();
72+
return null;
73+
}
74+
75+
clear();
76+
77+
displayPredictiveResults( constraint.toString() );
78+
79+
return null;
80+
}
81+
82+
@Override
83+
protected void publishResults(CharSequence constraint, FilterResults results) {
84+
notifyDataSetChanged();
85+
}
86+
};
87+
}
88+
89+
private void displayPredictiveResults( String query )
90+
{
91+
//Southwest corner to Northeast corner.
92+
LatLngBounds bounds = new LatLngBounds( new LatLng( 39.906374, -105.122337 ), new LatLng( 39.949552, -105.068779 ) );
93+
94+
//Filter: https://developers.google.com/places/supported_types#table3
95+
List<Integer> filterTypes = new ArrayList<Integer>();
96+
filterTypes.add( Place.TYPE_ESTABLISHMENT );
97+
98+
Places.GeoDataApi.getAutocompletePredictions( mGoogleApiClient, query, bounds, AutocompleteFilter.create( filterTypes ) )
99+
.setResultCallback (
100+
new ResultCallback<AutocompletePredictionBuffer>() {
101+
@Override
102+
public void onResult( AutocompletePredictionBuffer buffer ) {
103+
104+
if( buffer == null )
105+
return;
106+
107+
if( buffer.getStatus().isSuccess() ) {
108+
for( AutocompletePrediction prediction : buffer ) {
109+
//Add as a new item to avoid IllegalArgumentsException when buffer is released
110+
add( new AutoCompletePlace( prediction.getPlaceId(), prediction.getDescription() ) );
111+
}
112+
}
113+
114+
//Prevent memory leak by releasing buffer
115+
buffer.release();
116+
}
117+
}, 60, TimeUnit.SECONDS );
118+
}
119+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.tutsplus.placesapi;
2+
3+
/**
4+
* Created by paulruiz on 4/12/15.
5+
* Representation of a place from the autocomplete call
6+
*/
7+
public class AutoCompletePlace {
8+
9+
private String id;
10+
private String description;
11+
12+
public AutoCompletePlace( String id, String description ) {
13+
this.id = id;
14+
this.description = description;
15+
}
16+
17+
public String getDescription() {
18+
return description;
19+
}
20+
21+
public void setDescription( String description ) {
22+
this.description = description;
23+
}
24+
25+
public String getId() {
26+
return id;
27+
}
28+
29+
public void setId( String id ) {
30+
this.id = id;
31+
}
32+
}

0 commit comments

Comments
 (0)