Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement map api #12

Open
wants to merge 8 commits into
base: Google-Maps-Directions-using-an-Intent-end
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.idea/
.DS_Store
/build
/captures
Expand Down
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<a href='https://www.youtube.com/playlist?list=PLgCYzUzKIBE-SZUrVOsbYMzH7tPigT3gi' target='_blank'><img class='header-img' src='https://s3.amazonaws.com/codingwithmitch-static-and-media/media/Google+Maps+and+Directions/1.png' /></a>

<h1><a href='https://www.youtube.com/playlist?list=PLgCYzUzKIBE-SZUrVOsbYMzH7tPigT3gi' target='_blank'>Google Maps and Directions API</a></h1>
<h3>Watch the course on YouTube: <a href='https://www.youtube.com/playlist?list=PLgCYzUzKIBE-SZUrVOsbYMzH7tPigT3gi' target='_blank'>here</a>.</h3>
<h3>Watch the <a href='https://www.youtube.com/watch?v=RQxY7rrZATU' target='_blank'>Course Demo</a>.</h3>

<h3>What you'll learn:</h3>
<ol>
<li>Enabling the Google Maps SDK for Android</li>
<li>Enabling the Google Directions API for Android</li>
<li>MapView objects</li>
<li>Animating and moving the camera view</li>
<li>Setting view bounds on a google map</li>
<li>Building a thread that retrieves coordinates from a database</li>
<li>Building a service that inserts coordinates into a database</li>
<li>Create custom map markers with images</li>
<li>Get real time gps updates of users (Like Uber does)</li>
<li>How to use marker cluster to make custom map markers</li>
<li>Retrieving distance and travel time information using the directions API</li>
<li>Adding Polylines to a google map</li>
<li>Determining the fastest route</li>
<li>Opening the Google Maps application using an intent and uri</li>
</ol>



7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@ dependencies {
implementation 'com.google.firebase:firebase-auth:16.0.2'
// Firestore Firestore
implementation 'com.google.firebase:firebase-firestore:17.0.4'

// glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

// Circle ImageView
implementation 'de.hdodenhof:circleimageview:2.2.0'
}
apply plugin: 'com.google.gms.google-services'
42 changes: 0 additions & 42 deletions app/google-services.json

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</activity>
<activity android:name=".ui.RegisterActivity" />
<activity android:name=".ui.ChatroomActivity" />
<activity android:name=".ui.ProfileActivity"/>

</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.codingwithmitch.googlemaps2018.adapters;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.codingwithmitch.googlemaps2018.R;


import java.util.ArrayList;

public class ImageListRecyclerAdapter extends RecyclerView.Adapter<ImageListRecyclerAdapter.ViewHolder>{

private ArrayList<Integer> mImages = new ArrayList<>();
private ImageListRecyclerClickListener mImageListRecyclerClickListener;
private Context mContext;

public ImageListRecyclerAdapter(Context context, ArrayList<Integer> images, ImageListRecyclerClickListener imageListRecyclerClickListener) {
mContext = context;
mImages = images;
mImageListRecyclerClickListener = imageListRecyclerClickListener;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_image_list_item, parent, false);
final ViewHolder holder = new ViewHolder(view, mImageListRecyclerClickListener);
return holder;
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

RequestOptions requestOptions = new RequestOptions()
.placeholder(R.drawable.cwm_logo)
.error(R.drawable.cwm_logo);

Glide.with(mContext)
.setDefaultRequestOptions(requestOptions)
.load(mImages.get(position))
.into(((ViewHolder)holder).image);
}

@Override
public int getItemCount() {
return mImages.size();
}

public class ViewHolder extends RecyclerView.ViewHolder implements
View.OnClickListener
{
ImageView image;
ImageListRecyclerClickListener mClickListener;

public ViewHolder(View itemView, ImageListRecyclerClickListener clickListener) {
super(itemView);
image = itemView.findViewById(R.id.image);
mClickListener = clickListener;
itemView.setOnClickListener(this);
}

@Override
public void onClick(View v) {
mClickListener.onImageSelected(getAdapterPosition());
}
}

public interface ImageListRecyclerClickListener{
void onImageSelected(int position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
import android.os.Parcel;
import android.os.Parcelable;

public class User implements Parcelable {
public class User implements Parcelable{

private String email;
private String user_id;
private String username;
private String avatar;

public User(String email, String user_id, String username) {
public User(String email, String user_id, String username, String avatar) {
this.email = email;
this.user_id = user_id;
this.username = username;
this.avatar = avatar;
}

public User() {
Expand All @@ -23,6 +25,7 @@ protected User(Parcel in) {
email = in.readString();
user_id = in.readString();
username = in.readString();
avatar = in.readString();
}

public static final Creator<User> CREATOR = new Creator<User>() {
Expand All @@ -37,6 +40,18 @@ public User[] newArray(int size) {
}
};

public String getAvatar() {
return avatar;
}

public void setAvatar(String avatar) {
this.avatar = avatar;
}

public static Creator<User> getCREATOR() {
return CREATOR;
}

public String getEmail() {
return email;
}
Expand Down Expand Up @@ -67,6 +82,7 @@ public String toString() {
"email='" + email + '\'' +
", user_id='" + user_id + '\'' +
", username='" + username + '\'' +
", avatar='" + avatar + '\'' +
'}';
}

Expand All @@ -80,5 +96,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(email);
dest.writeString(user_id);
dest.writeString(username);
dest.writeString(avatar);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,24 @@ private void clearMessage(){
}

private void inflateUserListFragment(){
if(mUserListFragment == null){
mUserListFragment = UserListFragment.newInstance();
}

hideSoftKeyboard();

UserListFragment fragment = UserListFragment.newInstance();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(getString(R.string.intent_user_list), mUserList);
mUserListFragment.setArguments(bundle);
fragment.setArguments(bundle);

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.slide_in_up, R.anim.slide_out_up);
transaction.replace(R.id.user_list_container, mUserListFragment, getString(R.string.fragment_user_list));
transaction.replace(R.id.user_list_container, fragment, getString(R.string.fragment_user_list));
transaction.addToBackStack(getString(R.string.fragment_user_list));
transaction.commit();
}

private void hideSoftKeyboard(){
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}


private void getIncomingIntent(){
if(getIntent().hasExtra(getString(R.string.intent_chatroom))){
Expand Down Expand Up @@ -289,12 +292,15 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case android.R.id.home:{
if(mUserListFragment.isVisible()){
getSupportFragmentManager().popBackStack();
}
else{
finish();
UserListFragment fragment =
(UserListFragment) getSupportFragmentManager().findFragmentByTag(getString(R.string.fragment_user_list));
if(fragment != null){
if(fragment.isVisible()){
getSupportFragmentManager().popBackStack();
return true;
}
}
finish();
return true;
}
case R.id.action_chatroom_user_list:{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.codingwithmitch.googlemaps2018.ui;

public interface IProfile {

void onImageSelected(int resource);
}
Loading