Skip to content

Commit

Permalink
added baato service to integrate search api
Browse files Browse the repository at this point in the history
  • Loading branch information
Ichchhie committed Feb 27, 2020
1 parent 8dc8ab9 commit d80e20c
Show file tree
Hide file tree
Showing 17 changed files with 1,116 additions and 29 deletions.
13 changes: 12 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}

dependencies {
Expand All @@ -28,7 +32,14 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

//toaster library
implementation 'com.github.Ichchhie:Toaster-Library:0.2.0'
implementation 'com.github.Ichchhie:Toaster-Library:0.3.0'

implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.2'){
exclude group: 'group_name', module: 'module_name'
}

// implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.42.5'
// implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.5'
//graphhopper navigation
// implementation 'com.graphhopper.navigation:navigation-android:0.1.0'
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,152 @@
package com.kathmandulivinglabs.osmnavigationapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

//import com.kathmandulivinglabs.navigationlibrary.ToasterMessage;
import com.google.android.material.snackbar.Snackbar;
import com.kathmandulivinglabs.navigationlibrary.BaatoUtil;
import com.kathmandulivinglabs.navigationlibrary.ToasterMessage;
import com.kathmandulivinglabs.navigationlibrary.models.Geometry;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute;
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute;

public class MainActivity extends AppCompatActivity {
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback,
MapboxMap.OnMapLongClickListener, Callback<DirectionsResponse> {

private static final String TAG = "apple";
private MapboxMap mapboxMap;
private MapView mapView;
private NavigationMapRoute navigationMapRoute;
String encoded = "wv{gD_`lhOQvAO^c@h@Yj@IZKhADXj@|ABrAElB@NLLp@LHFDJJvDb@pBx@~B`AjBBP@fCArBW|KSxEQbHGbAYhBKVmA`C}A`EuBrGcAxC}@hBA^BJb@`@dBr@tBbAh@RdDbBs@fCYxAmBnKy@`F_Gj[]zBS~AWjDC~AA|BBbBj@|JpB~YRrDbAjONlDD~AAbCuArj@o@nSkB~w@CzB{@x\\e@rLa@jN@zBO|DE|EQjBKp@W~@Sf@o@dAs@x@i@d@_@RkAj@_AP_AJmCDkBD}IDoFF_ETc@@iARyAf@UKa@_@YKk@KuBGu@Kq@MkA[k@SsB{@wCwAgAo@g@SsDiBa@OcJmE{IcEiAm@kJmEmAc@U?QA[IUK]EmI_@wBCk@Dm@FiCt@k@ViNvJ_BlAcAj@{@Xc@JuALsGN{@F_@Da@NeAn@WXWb@]fAIf@Al@Bt@`AvKVhDDpAMjB[jASb@yAzBiAvAuCfEYxAe@SmE}AsGeA_FiBwG_CsB_@sGq@{AWcA]eASuC{@g@IiDs@_BWy@FiG`BqCx@sFvA{JlC_APq@DqA?[CcAOgCg@qFqAgGkA{@Gk@@i@Dg@Je@NmAl@_^~R^p@lAlAdAv@^T~Al@t@l@F?b@MjChANBl@ATIDCFl@APNH?Ho@`CTf@HJ`@FJN?Je@fA[d@CJBJHJ@POv@HPFVd@ZBJAJa@v@bAf@JjAw@`@yAf@s@d@SHQAAf@c@C@p@YAm@R?n@SPkAPAB?|@g@HCLaAB";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, getString(R.string.mapbox_access_token));
setContentView(R.layout.activity_main);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
ToasterMessage.s(this, "Hello Good Morning");
Geometry geometry = BaatoUtil.getGeoJsonFromEncodedPolyLine(encoded);
NavigationRoute.builder(this)
.accessToken(Mapbox.getAccessToken())
.origin(Point.fromLngLat(85.4278774, 27.6721352))
.destination(Point.fromLngLat(85.3346386, 27.7340328))
.alternatives(true)
.build()
.getRoute(this);
Log.d("hello", "onCreate: " + geometry.coordinates);
}

@Override
public boolean onMapLongClick(@NonNull LatLng point) {
return false;
}

// ToasterMessage.s(this,"Hello Good Morning");
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
initializeLocationComponent(mapboxMap);
navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap);
mapboxMap.addOnMapLongClickListener(this);
Snackbar.make(mapView, "Long press to select route", Snackbar.LENGTH_SHORT).show();
});
}

@SuppressWarnings("MissingPermission")
private void initializeLocationComponent(MapboxMap mapboxMap) {
LocationComponent locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(this, mapboxMap.getStyle());
locationComponent.setLocationComponentEnabled(true);
locationComponent.setRenderMode(RenderMode.COMPASS);
locationComponent.setCameraMode(CameraMode.TRACKING);
locationComponent.zoomWhileTracking(10d);
}

@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
if (response.isSuccessful()
&& response.body() != null
&& !response.body().routes().isEmpty()) {
List<DirectionsRoute> routes = response.body().routes();
navigationMapRoute.addRoutes(routes);
}
}

@Override
public void onFailure(Call<DirectionsResponse> call, Throwable t) {
Log.d(TAG, "onFailure: " + t.getMessage());
}

@Override
public void onResume() {
super.onResume();
mapView.onResume();
}

@Override
protected void onStart() {
super.onStart();
mapView.onStart();
if (navigationMapRoute != null) {
navigationMapRoute.onStart();
}
}

@Override
protected void onStop() {
super.onStop();
mapView.onStop();
if (navigationMapRoute != null) {
navigationMapRoute.onStop();
}
}

@Override
public void onPause() {
super.onPause();
mapView.onPause();
}

@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}

@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}

}
17 changes: 7 additions & 10 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:mapbox_cameraZoom="12" />

</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<resources>
<string name="app_name">OSM Navigation App</string>
<String name="encoded_polyline">wv{gD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C~AA|BBbBj@|JpB~YRrDbAjONlDD~AAbCuArj@o@nSkB~w@CzB{@x\e@rLa@jN@zBO|DE|EQjBKp@W~@Sf@o@dAs@x@i@d@_@RkAj@_AP_AJmCDkBD}IDoFF_ETc@@iARyAf@UKa@_@YKk@KuBGu@Kq@MkA[k@SsB{@wCwAgAo@g@SsDiBa@OcJmE{IcEiAm@kJmEmAc@U?QA[IUK]EmI_@wBCk@Dm@FiCt@k@ViNvJ_BlAcAj@{@Xc@JuALsGN{@F_@Da@NeAn@WXWb@]fAIf@Al@Bt@`AvKVhDDpAMjB[jASb@yAzBiAvAuCfEYxAe@SmE}AsGeA_FiBwG_CsB_@sGq@{AWcA]eASuC{@g@IiDs@_BWy@FiG`BqCx@sFvA{JlC_APq@DqA?[CcAOgCg@qFqAgGkA{@Gk@@i@Dg@Je@NmAl@_^~R^p@lAlAdAv@^T~Al@t@l@F?b@MjChANBl@ATIDCFl@APNH?Ho@`CTf@HJ`@FJN?Je@fA[d@CJBJHJ@POv@HPFVd@ZBJAJa@v@bAf@JjAw@`@yAf@s@d@SHQAAf@c@C@p@YAm@R?n@SPkAPAB?|@g@HCLaAB</string>
</resources>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ allprojects {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://mapbox.bintray.com/mapbox' }

}
}
Expand Down
4 changes: 4 additions & 0 deletions toasterlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
}
6 changes: 5 additions & 1 deletion toasterlibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kathmandulivinglabs.navigationlibrary" />
package="com.kathmandulivinglabs.navigationlibrary" >

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.kathmandulivinglabs.navigationlibrary.application;

import android.app.Application;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class App extends Application {
private static TinyDB tinyDB;

@Override
public void onCreate() {
super.onCreate();
//tiny db config
tinyDB = new TinyDB(getApplicationContext());
}


public static TinyDB db() {
return tinyDB;
}

public static Retrofit retrofit(final String token) {
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://178.128.59.143/api/v1/")
.addConverterFactory(GsonConverterFactory.create());

OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder();
okHttpBuilder.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
Request request = original.newBuilder()
.header("Authorization", "Bearer " + token)
.method(original.method(), original.body())
.build();

return chain.proceed(request);
}
});
builder.client(okHttpBuilder.build());
Retrofit retrofit = builder.build();
return retrofit;
}

public static boolean isConnectedToNetwork(Context context) {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

boolean isConnected = false;
if (connectivityManager != null) {
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
isConnected = (activeNetwork != null) && (activeNetwork.isConnectedOrConnecting());
}
return isConnected;
}
}
Loading

0 comments on commit d80e20c

Please sign in to comment.