Skip to content

Commit

Permalink
Moving the GoogleKey server side is now possible and took into account
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasSeguy-Android2EE committed Apr 16, 2019
1 parent d7d050a commit c41a76a
Show file tree
Hide file tree
Showing 15 changed files with 746 additions and 652 deletions.
6 changes: 6 additions & 0 deletions GDirectionsApiUtils/app/gradle_nexus_release.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
//The open source file
//apply from: 'gradle_nexus_release_var.gradle'
//TODO but if you are me use this one:
apply from: 'gradle_nexus_release_var_def.gradle'



//When CatBus blocks the release go in builds_hooks.gradle and uncomment the comments about catbus

uploadArchives {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,11 @@ project.ext {

//Define where to deploy
//--------------------------------------
NEXUS_USERNAME = "ACMS"
NEXUS_PASSWORD ='@cms$$123'
NEXUS_URL = "https://nexus.kamereon.org"
NEXUS_USERNAME = "UserName"
NEXUS_PASSWORD ='Password'
NEXUS_URL = "https://nexus.organization.org"

SNAPSHOT_REPOSITORY_URL = "https://nexus.kamereon.org/repository/maven-snapshots"
RELEASE_REPOSITORY_URL = "https://nexus.kamereon.org/repository/android_releases"
SNAPSHOT_REPOSITORY_URL = "https://nexus.organization.org/repository/maven-snapshots"
RELEASE_REPOSITORY_URL = "https://nexus.organization.org/repository/android_releases"

//Define your GPG for signing your archives
//-----------------------------------------
//signing.keyId=9CF79442
//signing.password=sylpheo_acms
//signing.secretKeyRingFile=./gpg_key.asc

//Reference:
//http://zserge.com/blog/gradle-maven-publish.html
//https://github.com/A-CMS/alliance-platform-parent/blob/master/pom.xml
//https://maven.apache.org/scm/git.html
}
1 change: 1 addition & 0 deletions GDirectionsApiUtils/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<!--<meta-data-->
<!--android:name="com.google.android.geo.API_KEY"-->
<!--android:value="AIzaSyCkmF88VZEneajCLRXP50NB7Fla3pFG3oE" />-->
<!--You should use your key, this key will be closed soon (april 2019)-->

</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* <ul>
* <li>GoogleMapSample</li>
* <li>com.android2ee.formation.librairies.google.map.utils.direction</li>
Expand Down Expand Up @@ -31,6 +31,7 @@
package com.android2ee.formation.librairies.google.map.utils.direction;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.util.Log;

import com.android2ee.formation.librairies.google.map.utils.direction.com.IGDirectionServer;
Expand Down Expand Up @@ -61,7 +62,8 @@

/**
* @author Mathias Seguy (Android2EE)
* @goals This class aims to make a layer over the Direction Api.
* This class aims to make a layer over the Direction Api.
*
* To have a Google Direction and Draw it You just have to:
* <ul>
* <li>Implements the DCACallBack and its method public void onDirectionLoaded(GDirection
Expand All @@ -85,32 +87,36 @@
* GDirectionsApiUtils.drawGDirection(direction, mMap);</br>
* }
*/
@SuppressWarnings({"DanglingJavadoc", "WeakerAccess"})
public class GDirectionsApiUtils {

/***********************************************************
* Attributes
* Constants/Keys
**********************************************************/
private static final String TAG = "GDirectionsApiUtils";

private static WeakReference<DCACallBack> callbackWeakRef;

private static LatLngBounds.Builder latLngBuilder;
private static LatLngBounds bounds;
@SuppressWarnings("unused")
public static final String BASE_GDIR_URL = "https://maps.googleapis.com/";

/******************************************************************************************/
/** Public Method **************************************************************************/
/******************************************************************************************/
/***********************************************************
* Attributes
**********************************************************/
private static WeakReference<DCACallBack> callbackWeakRef;

/***********************************************************
* Business Methods
**********************************************************/
/**
* Draw on the given map the given GDirection object
*
* @param direction The google direction to draw
* @param map The map to draw on
*/
@SuppressWarnings("unused")
public static void drawGDirection(GDirection direction, GoogleMap map) {
drawGDirection(direction, map, null);
}


/**
* Draw on the given map the given GDirection object
*
Expand All @@ -122,7 +128,7 @@ public static void drawGDirection(GDirection direction, GoogleMap map, GDirectio
// The polyline option to create polyline
PolylineOptions lineOptions = null;
// index of GDPoint within the current GDPath
int i = 0;
int i;
// index of the current GDPath
int pathIndex = 0;
// index of the current GDLegs
Expand Down Expand Up @@ -226,7 +232,7 @@ public static void drawGDirectionWithoutPathMarker(GDirection direction, GoogleM
} else {
maxDotsDisplayed = GDirectionMapsOptions.MAX_DOTS_DISPLAYED_DEFAULT;
}
latLngBuilder = new LatLngBounds.Builder();
LatLngBounds.Builder latLngBuilder = new LatLngBounds.Builder();
//Was there but unused so I use it
GDirection reducedDirection = GDirectionsApiUtils.reduce(direction, maxDotsDisplayed);

Expand Down Expand Up @@ -269,19 +275,17 @@ public static void drawGDirectionWithoutPathMarker(GDirection direction, GoogleM
}
}

bounds = latLngBuilder.build();
LatLngBounds bounds = latLngBuilder.build();

map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
map.addPolyline(lineOptions.addAll(pathList));

reducedDirection = null;
if (lineOptions != null) {
map.addPolyline(lineOptions.addAll(pathList));
}
}

/**
* The goal of this method is to reduce the number of point to draw
* according to the value of MapOtion.maxDotsDisplayed
*
* @param gDir
*/
public static GDirection reduce(GDirection gDir, int maxDotsDisplayed) {
int gWeight = gDir.getWeight();
Expand All @@ -300,7 +304,6 @@ public static GDirection reduce(GDirection gDir, int maxDotsDisplayed) {
GDPath currentPath;
ArrayList<GDPoint> currentPointList;

// int currentPathIndex = 1;
//We browse every legs
for (GDLegs legs : gDir.getLegsList()) {
//for each leg, we find eth number of path
Expand Down Expand Up @@ -337,26 +340,33 @@ public static GDirection reduce(GDirection gDir, int maxDotsDisplayed) {
* Find the direction between two points on the maps (direction is the path to follow to go from
* start to end points)
*
* @param callback The DCACallBack to prevent when data have been retrieve and built. It will receive
* a GDirection
* @param data builder GDirection
* @param serverBaseUrl The server URL to be called (without the endpoint path)
* @param callback The DCACallBack to prevent when data have been retrieve and built.
* It will receive a GDirection
* @param data Built GDirection
*/
public static void getDirection(final DCACallBack callback, GDirectionData data) {
callbackWeakRef = new WeakReference<DCACallBack>(callback);
loadGDirections(data);
public static void getDirection(String serverBaseUrl,
final DCACallBack callback,
GDirectionData data) {
callbackWeakRef = new WeakReference<>(callback);
loadGDirections(serverBaseUrl, data);
}

/**
* Make the real job of loading directions
*
* @param data
* @param serverBaseUrl The server URL to be called (without the endpoint path)
* @param data Built GDirection
*/
private static void loadGDirections(GDirectionData data) {
IGDirectionServer gDirectionServer = RetrofitBuilder.getBaseRetrofit().create(IGDirectionServer.class);
private static void loadGDirections(@NonNull String serverBaseUrl,
@NonNull GDirectionData data) {
IGDirectionServer gDirectionServer = RetrofitBuilder
.getBaseRetrofit(serverBaseUrl)
.create(IGDirectionServer.class);

Call<List<GDirection>> call = gDirectionServer.getGDirections(
data.getStart().latitude + "," + data.getStart().longitude,
data.getEnd().latitude + "," + data.getEnd().longitude,
false,
data.getMode().toString(),
data.getWaypoints(),
data.isAlternative(),
Expand All @@ -366,10 +376,10 @@ private static void loadGDirections(GDirectionData data) {
data.getRegion(),
data.getDeparture_time(),
data.getArrival_time(),
data.getGoogleApiKey()
data.getGoogle_api_key()
);
call.enqueue(new Callback<List<GDirection>>() {

call.enqueue(new Callback<List<GDirection>>() {
@Override
public void onResponse(Call<List<GDirection>> call, Response<List<GDirection>> response) {
DCACallBack callBack = callbackWeakRef.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;

/**
* Created by Safi on 02/05/2017.
* Updated by Anthony St. on 22/01/2019.
*/
public interface IGDirectionServer {
public final String BASE_URL = "https://maps.googleapis.com/";

@GET("maps/api/directions/json")
Call<List<GDirection>> getGDirections(
@Query("origin") String origin,//data.getStart().latitude + ","+ data.getStart().longitude
@Query("destination") String destination,//data.getEnd().latitude + "," + data.getEnd().longitude
@Query("sensor") boolean sensor,//"&sensor=false"
@Query("mode") String mode,//data.getMode()
@Query("waypoints") String waypoints,//data.getWaypoints()
@Query("alternatives") boolean alternatives,//data.isAlternative()
@Query("avoid") String avoid,//data.getAvoid()
@Query("language") String language,//data.getLanguage()
@Query("units") String units,//data.getUs()
@Query("region") String region,//data.getRegion()
@Query("departure_time") String departure_time,//data.getDeparture_time()
@Query("arrival_time") String arrival_time,//data.getArrival_time()
@Query("key") String googleApiKey//data.getArrival_time()
@Query("origin") String origin, //data.getStart().latitude + ","+ data.getStart().longitude
@Query("destination") String destination, //data.getEnd().latitude + "," + data.getEnd().longitude
@Query("mode") String mode, //data.getMode()
@Query("waypoints") String waypoints, //data.getWaypoints()
@Query("alternatives") boolean alternatives, //data.isAlternative()
@Query("avoid") String avoid, //data.getAvoid()
@Query("language") String language, //data.getLanguage()
@Query("units") String units, //data.getUs()
@Query("region") String region, //data.getRegion()
@Query("departure_time") String departure_time, //data.getDeparture_time()
@Query("arrival_time") String arrival_time, //data.getArrival_time()
@Query("key") String googleApiKey //data.getGoogle_api_key()
);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android2ee.formation.librairies.google.map.utils.direction.com;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

Expand All @@ -9,17 +10,18 @@
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;

import static com.android2ee.formation.librairies.google.map.utils.direction.com.IGDirectionServer.BASE_URL;
import static okhttp3.logging.HttpLoggingInterceptor.Level.BODY;
import static okhttp3.logging.HttpLoggingInterceptor.Level.NONE;

@SuppressWarnings("DanglingJavadoc")
public class RetrofitBuilder {
private static final String TAG = "GD_RetrofitBuilder";

/***********************************************************
* Constants / Keys.
**********************************************************/
private static final String TAG = "GD_RetrofitBuilder";

private static Retrofit baseRetrofit = null;
/**
* Default Cache size when not provided
Expand All @@ -35,12 +37,10 @@ public class RetrofitBuilder {
**********************************************************/
/**
* This method will be remove in a close future. Please use the new method.
*
* @return
*/
public static Retrofit getBaseRetrofit() {
public static Retrofit getBaseRetrofit(@NonNull String serverBaseUrl) {
if (baseRetrofit == null) {
baseRetrofit = buildRetrofit(BASE_URL);
baseRetrofit = buildRetrofit(serverBaseUrl);
}
return baseRetrofit;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ protected static Retrofit buildRetrofit(String baseUrl, OkHttpClient.Builder bui
private static Retrofit buildRetrofit(String baseUrl, @Nullable OkHttpClient.Builder builder, @Nullable String cacheName, int cacheSize) {
if (builder == null) {
builder = new OkHttpClient.Builder()
.addInterceptor(provideHttpLoggingInterceptor());
.addInterceptor(provideHttpLoggingInterceptor());
}
// if(cacheName==null){
// addCache(builder, defaultCacheName, defaultCacheSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class GDPoint implements Parcelable{

/**
* The builder
* @param coordinate retrieve from JSon
*/
public GDPoint(double lat,double lng) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

import com.google.android.gms.maps.model.LatLng;

import java.util.List;

/**
* @author Mathias Seguy (Android2EE)
* @goals
Expand Down Expand Up @@ -72,9 +72,6 @@ public class GDirection implements Parcelable{
public GDirection() {
}

/**
* @param pathsList
*/
public GDirection(List<GDLegs> legsList) {
super();
this.mLegsList = legsList;
Expand Down
Loading

0 comments on commit c41a76a

Please sign in to comment.