com.mapbox.mapboxsdk.Mapbox Java Examples

The following examples show how to use com.mapbox.mapboxsdk.Mapbox. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TabbedMainActivity.java    From ShapeOfView with Apache License 2.0 8 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.shape_of_view_tabbed_activity_main);
    ButterKnife.bind(this);
    Mapbox.getInstance(this, "pk.eyJ1IjoiY2hpY2tpbm5pY2siLCJhIjoiY2pka3U2YTdiMDE1YTJ4cjA0YzVyYnpoMSJ9.xlyPakmrR_N4bNqIGe6AKg");
    viewPager.setAdapter(new FakeAdapter(getSupportFragmentManager()));

    tabLayout.setupWithViewPager(viewPager);

    TabIndicatorFollower.setupWith(tabLayout, triangle);
    mapView = (MapView) findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);

    RxLifecycle.with(this).onResume().subscribe(event -> mapView.onResume());
    RxLifecycle.with(this).onPause().subscribe(event -> mapView.onPause());
    RxLifecycle.with(this).onStop().subscribe(event -> mapView.onStop());
    RxLifecycle.with(this).onDestroy().subscribe(event -> mapView.onDestroy());
}
 
Example #2
Source File: NavigationApplication.java    From graphhopper-navigation-android with MIT License 8 votes vote down vote up
@Override
public void onCreate() {
  super.onCreate();

  // Leak canary
  if (LeakCanary.isInAnalyzerProcess(this)) {
    return;
  }
  LeakCanary.install(this);

  if (BuildConfig.DEBUG) {
    Timber.plant(new Timber.DebugTree());
  }

  // Set access token
  String mapboxAccessToken = Utils.getMapboxAccessToken(getApplicationContext());
  if (TextUtils.isEmpty(mapboxAccessToken) || mapboxAccessToken.equals(DEFAULT_MAPBOX_ACCESS_TOKEN)) {
    Log.w(LOG_TAG, "Warning: access token isn't set.");
  }

  Mapbox.getInstance(getApplicationContext(), mapboxAccessToken);
}
 
Example #3
Source File: App.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Timber.plant(BuildConfig.DEBUG ? new DebugTree() : new ReleaseTree());
    ProcessLifecycleOwner.get().getLifecycle().addObserver(this);

    if (BuildConfig.DEBUG)
        Stetho.initializeWithDefaults(this);

    Mapbox.getInstance(this, BuildConfig.MAPBOX_ACCESS_TOKEN);

    Fabric.with(this, new Crashlytics());

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        upgradeSecurityProviderSync();

    setUpAppComponent();
    setUpServerComponent();
    setUpRxPlugin();
}
 
Example #4
Source File: MapActivity.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
public static void lazyMapboxInit(Context context) {
    try {
        Mapbox.getInstance(context, BuildConfig.MAP_ACCESS_TOKEN);

        // disable telemetry. these functions are currently partly redundant,
        // however, implementations may change
        // and the two explicit calls seems to have worked in the past,
        // see https://github.com/mapbox/mapbox-gl-native/issues/13304
        TelemetryEnabler.updateTelemetryState(TelemetryEnabler.State.DISABLED);
        TelemetryDefinition telemetry = Mapbox.getTelemetry();
        if (telemetry != null) {
            telemetry.setUserTelemetryRequestState(false);
        }
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}
 
Example #5
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-example with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_launcher);
    Mapbox.getInstance(this.getApplicationContext(), getString(R.string.mapbox_access_token));
    Telemetry.disableOnUserRequest();
    ButterKnife.bind(this);
    mapView.setStyleUrl(getString(R.string.map_view_styleUrl));
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(this);
    localeUtils = new LocaleUtils();
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle("");
    }
    showFirstStartIfNecessary();
}
 
Example #6
Source File: Utils.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
/**
 * <p>
 * Returns the Mapbox access token set in the app resources.
 * </p>
 * It will first search for a token in the Mapbox object. If not found it
 * will then attempt to load the access token from the
 * {@code res/values/dev.xml} development file.
 *
 * @param context The {@link Context} of the {@link android.app.Activity} or {@link android.app.Fragment}.
 * @return The Mapbox access token or null if not found.
 */
public static String getMapboxAccessToken(@NonNull Context context) {
  try {
    // Read out AndroidManifest
    String token = Mapbox.getAccessToken();
    if (token == null || token.isEmpty()) {
      throw new IllegalArgumentException();
    }
    return token;
  } catch (Exception exception) {
    // Use fallback on string resource, used for development
    int tokenResId = context.getResources()
      .getIdentifier("mapbox_access_token", "string", context.getPackageName());
    return tokenResId != 0 ? context.getString(tokenResId) : null;
  }
}
 
Example #7
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
private void fetchRoute() {
  NavigationRoute.Builder builder = NavigationRoute.builder(this)
    .accessToken(Mapbox.getAccessToken())
    .origin(currentLocation)
    .destination(destination)
    .alternatives(true);
  setFieldsFromSharedPreferences(builder);
  builder.build()
    .getRoute(new SimplifiedCallback() {
      @Override
      public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        if (validRouteResponse(response)) {
          hideLoading();
          route = response.body().routes().get(0);
          if (route.distance() > 25d) {
            launchRouteBtn.setEnabled(true);
            mapRoute.addRoutes(response.body().routes());
            boundCameraToRoute();
          } else {
            Snackbar.make(mapView, R.string.error_select_longer_route, Snackbar.LENGTH_SHORT).show();
          }
        }
      }
    });
  loading.setVisibility(View.VISIBLE);
}
 
Example #8
Source File: RerouteActivity.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  setTheme(R.style.NavigationViewLight);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_reroute);
  ButterKnife.bind(this);

  mapView.onCreate(savedInstanceState);
  mapView.getMapAsync(this);

  // Initialize MapboxNavigation and add listeners
  MapboxNavigationOptions options = MapboxNavigationOptions.builder().isDebugLoggingEnabled(true).build();
  navigation = new MapboxNavigation(getApplicationContext(), Mapbox.getAccessToken(), options);
  navigation.addNavigationEventListener(this);
  navigation.addMilestoneEventListener(this);
}
 
Example #9
Source File: MockNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_mock_navigation);
  ButterKnife.bind(this);

  mapView.onCreate(savedInstanceState);
  mapView.getMapAsync(this);

  Context context = getApplicationContext();
  CustomNavigationNotification customNotification = new CustomNavigationNotification(context);
  MapboxNavigationOptions options = MapboxNavigationOptions.builder()
    .navigationNotification(customNotification)
    .build();

  navigation = new MapboxNavigation(this, Mapbox.getAccessToken(), options);

  navigation.addMilestone(new RouteMilestone.Builder()
    .setIdentifier(BEGIN_ROUTE_MILESTONE)
    .setInstruction(new BeginRouteInstruction())
    .setTrigger(
      Trigger.all(
        Trigger.lt(TriggerProperty.STEP_INDEX, 3),
        Trigger.gt(TriggerProperty.STEP_DISTANCE_TOTAL_METERS, 200),
        Trigger.gte(TriggerProperty.STEP_DISTANCE_TRAVELED_METERS, 75)
      )
    ).build());
  customNotification.register(new MyBroadcastReceiver(navigation), context);
}
 
Example #10
Source File: NavigationFragment.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute(Point origin, Point destination) {
  NavigationRoute.builder(getContext())
    .accessToken(Mapbox.getAccessToken())
    .origin(origin)
    .destination(destination)
    .build()
    .getRoute(new SimplifiedCallback() {
      @Override
      public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        directionsRoute = response.body().routes().get(0);
        startNavigation();
      }
    });
}
 
Example #11
Source File: WaypointNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute(Point origin, Point destination) {
  NavigationRoute.builder(this)
    .accessToken(Mapbox.getAccessToken())
    .origin(origin)
    .destination(destination)
    .alternatives(true)
    .build()
    .getRoute(new SimplifiedCallback() {
      @Override
      public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        startNavigation(response.body().routes().get(0));
      }
    });
}
 
Example #12
Source File: ComponentNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void initializeNavigation(MapboxMap mapboxMap) {
  navigation = new MapboxNavigation(this, Mapbox.getAccessToken());
  navigation.setLocationEngine(locationEngine);
  navigation.setCameraEngine(new DynamicCamera(mapboxMap));
  navigation.addProgressChangeListener(this);
  navigation.addMilestoneEventListener(this);
  navigation.addOffRouteListener(this);
  navigationMap.addProgressChangeListener(navigation);
}
 
Example #13
Source File: RerouteActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void getRoute(Point origin, Point destination, Float bearing) {
  Double heading = bearing == null ? null : bearing.doubleValue();
  NavigationRoute.builder(this)
    .origin(origin, heading, 90d)
    .destination(destination)
    .accessToken(Mapbox.getAccessToken())
    .build().getRoute(this);
}
 
Example #14
Source File: EmbeddedNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute() {
  NavigationRoute.builder(this)
    .accessToken(Mapbox.getAccessToken())
    .origin(ORIGIN)
    .destination(DESTINATION)
    .alternatives(true)
    .build()
    .getRoute(new SimplifiedCallback() {
      @Override
      public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        DirectionsRoute directionsRoute = response.body().routes().get(0);
        startNavigation(directionsRoute);
      }
    });
}
 
Example #15
Source File: NavigationMapRouteActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
public void requestDirectionsRoute(Point origin, Point destination) {
  MapboxDirections directions = MapboxDirections.builder()
    .origin(origin)
    .destination(destination)
    .accessToken(Mapbox.getAccessToken())
    .profile(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC)
    .overview(DirectionsCriteria.OVERVIEW_FULL)
    .annotations(DirectionsCriteria.ANNOTATION_CONGESTION)
    .alternatives(true)
    .steps(true)
    .build();

  directions.enqueueCall(this);
}
 
Example #16
Source File: OnNavigationReadyIdlingResource.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void fetchRoute(Context context) {
  Point origin = Point.fromLngLat(-77.033987, 38.900123);
  Point destination = Point.fromLngLat(-77.044818, 38.848942);
  NavigationRoute.builder(context)
    .accessToken(Mapbox.getAccessToken())
    .origin(origin)
    .destination(destination)
    .build().getRoute(this);
}
 
Example #17
Source File: NavigationViewModel.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
public NavigationViewModel(Application application) {
  super(application);
  this.accessToken = Mapbox.getAccessToken();
  initializeConnectivityManager(application);
  initializeNavigationRouteEngine();
  initializeNavigationLocationEngine();
  routeUtils = new RouteUtils();
  localeUtils = new LocaleUtils();
}
 
Example #18
Source File: ComponentNavigationActivity.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private void initializeSpeechPlayer() {
  String english = Locale.US.getLanguage();
  String accessToken = Mapbox.getAccessToken();
  SpeechPlayerProvider speechPlayerProvider = new SpeechPlayerProvider(getApplication(), english, true, accessToken);
  speechPlayer = new NavigationSpeechPlayer(speechPlayerProvider);
}
 
Example #19
Source File: MapwizeFragment.java    From mapwize-ui-android with MIT License 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Mapbox.getInstance(container.getContext(), "pk.mapwize");
    return inflater.inflate(R.layout.mapwize_fragment, container, false);
}