Week 3: 10/06 - 10/12
October 06, 2017
Lu Meng
What if the name of a place is too long to remember clearly when the user input the place? That is why we want to have this place autocomplete function in our app.
- Google Place API for Android is used to build the place autocomplete function. If it is the first time you use this API, you need to get a console and a key. And there is a default limit of 1,000 requests per 24 hour period enforced by Google Place API.
- To make the Google Play services APIs available to my app, I added "compile 'com.google.android.gms:play-services-places:<version number>'" in the "build.gradle" file in the "app" folder. The latest version of Google Play services is 11.4.2, but somehow this version didn't work in my Android Studio, so the version I used is 11.0.4. Then Android Studio will add Google Repository in its support repository in the SDK tools when it is opening the modified app. Or you can expend the support repository directly in "Tools" > "Android" > "SDK Manager".
Added the API key to the "AndroidManifest.xml" file of our app. Now we can finally use the Google Place API.
I added the place autocomplete fragment in the xml file where the user can search the places, then we have the place autocomplete function:
Taining Zhang
Finished Work
Use the ViewPager to show the images of places.
- Customize a Image page adapter by creating a class extends the PagerAdapter.
- Create customize ViewPager layout xml file.
How to do it ?
Create XML file
Add the PageViewer into the info activity xml file.
Write the customize style xml for the PageViewer
Write the customized adapter class which extents the PagerAdapter for the PageViewer.
public class ViewPagerAdapter extends PagerAdapter { private Context context; private LayoutInflater layoutInflater; private Bitmap[] images; public ViewPagerAdapter(Context context, Bitmap[] images) { this.context = context; this.images = images; } @Override public int getCount() { return images.length; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Object instantiateItem(ViewGroup container, int position) { layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.custom_layout, null); ImageView imageView = (ImageView) view.findViewById(R.id.imageView2); imageView.setImageBitmap(images[position]); ViewPager vp = (ViewPager) container; vp.addView(view, 0); return view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { ViewPager vp = (ViewPager) container; View view = (View) object; vp.removeView(view); } }
Problems
When I use the ViewPager, I don't know how to send the data from the current activity into the ViewPager. By customizing the adapter, I can pass the image data to the adapter by the customized constructor of the adapter.
Wanqing Chen
Finished Work
Create Firebase project in https://console.firebase.google.com/.
Download google-services.json
Enable Sign-In method: Email/Password
Import google-services.json into the android project, and then config build.gradle.
Project build.gradle
dependencies{ classpath 'com.google.gms:google-services:3.0.0' }
App build.gradle
dependencies{ apply plugin: 'com.google.gms:google-services' compile 'com.google.firebase:firebase-auth:9.4.0' }
Coding android app
Main Activity: Button Registration and Login
Registration Activity: navigate to login activity after successful registration
Login Activity
Add Internet permission to android manifest file
Problems
- When I tried to connect my Firebase account to Android Studio, there was a building error:
app:processDebugGoogleServices'. > Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/\ or updating the version of com.google.android.gms to 11.0.4.
I figured out that it must keep all google service library in same versions. So I changed code in build.gradle from :
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.firebase:firebase-database:10.0.1'
to:
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.firebase:firebase-database:11.0.4'
Then it works well.