diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java | 390 |
1 files changed, 195 insertions, 195 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java index d40747918a..2da3bedcbf 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java @@ -32,217 +32,217 @@ import com.mapbox.mapboxsdk.testapp.R; public class MyLocationTintActivity extends AppCompatActivity implements LocationListener { - private MapView mapView; - private MapboxMap mapboxMap; - private boolean firstRun; + private MapView mapView; + private MapboxMap mapboxMap; + private boolean firstRun; - private static final int PERMISSIONS_LOCATION = 0; + private static final int PERMISSIONS_LOCATION = 0; - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_my_location_dot_color); + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_my_location_dot_color); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayShowHomeEnabled(true); - } + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowHomeEnabled(true); + } - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(new OnMapReadyCallback() { + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + + // enable location updates + toggleGps(!mapboxMap.isMyLocationEnabled()); + + // add some padding + final MyLocationViewSettings myLocationViewSettings = mapboxMap.getMyLocationViewSettings(); + myLocationViewSettings.setPadding(0, 500, 0, 0); + + // enable tracking + TrackingSettings settings = mapboxMap.getTrackingSettings(); + settings.setDismissLocationTrackingOnGesture(false); + settings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); + + // handle default button clicks + ViewUtils.attachClickListener( + MyLocationTintActivity.this, + R.id.default_user_dot_coloring_button, + new View.OnClickListener() { @Override - public void onMapReady(MapboxMap map) { - mapboxMap = map; - - // enable location updates - toggleGps(!mapboxMap.isMyLocationEnabled()); - - // add some padding - final MyLocationViewSettings myLocationViewSettings = mapboxMap.getMyLocationViewSettings(); - myLocationViewSettings.setPadding(0, 500, 0, 0); - - // enable tracking - TrackingSettings settings = mapboxMap.getTrackingSettings(); - settings.setDismissLocationTrackingOnGesture(false); - settings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); - - // handle default button clicks - ViewUtils.attachClickListener( - MyLocationTintActivity.this, - R.id.default_user_dot_coloring_button, - new View.OnClickListener() { - @Override - public void onClick(View view) { - myLocationViewSettings.setAccuracyTintColor(ContextCompat.getColor( - MyLocationTintActivity.this, R.color.mapbox_my_location_ring)); - myLocationViewSettings.setForegroundTintColor(ContextCompat.getColor( - MyLocationTintActivity.this, R.color.mapbox_blue)); - myLocationViewSettings.setBackgroundTintColor(Color.WHITE); - } - }); - - // handle tint user dot button clicks - ViewUtils.attachClickListener( - MyLocationTintActivity.this, - R.id.tint_user_dot_button, - new View.OnClickListener() { - @Override - public void onClick(View view) { - myLocationViewSettings.setAccuracyTintColor( - ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_green)); - myLocationViewSettings.setForegroundTintColor( - ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_green)); - myLocationViewSettings.setBackgroundTintColor(Color.WHITE); - } - }); - - // handle tint accuracy ring button clicks - ViewUtils.attachClickListener( - MyLocationTintActivity.this, - R.id.user_accuracy_ring_tint_button, - new View.OnClickListener() { - @Override - public void onClick(View view) { - myLocationViewSettings.setAccuracyTintColor( - ContextCompat.getColor(MyLocationTintActivity.this, R.color.accent)); - myLocationViewSettings.setForegroundTintColor( - ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_blue)); - myLocationViewSettings.setBackgroundTintColor(Color.WHITE); - } - }); - - ViewUtils.attachClickListener( - MyLocationTintActivity.this, - R.id.user_dot_transparent_button, - new View.OnClickListener() { - @Override - public void onClick(View view) { - myLocationViewSettings.setForegroundTintColor(Color.TRANSPARENT); - myLocationViewSettings.setBackgroundTintColor(Color.TRANSPARENT); - } - } - ); + public void onClick(View view) { + myLocationViewSettings.setAccuracyTintColor(ContextCompat.getColor( + MyLocationTintActivity.this, R.color.mapbox_blue)); + myLocationViewSettings.setForegroundTintColor(ContextCompat.getColor( + MyLocationTintActivity.this, R.color.mapbox_blue)); + myLocationViewSettings.setBackgroundTintColor(Color.WHITE); } - }); - - } - - @Override - public void onLocationChanged(Location location) { - if (mapboxMap != null && firstRun) { - mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location), 15)); - firstRun = false; - } - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - LocationServices.getLocationServices(this).addLocationListener(this); - } + }); - @Override - public void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - public void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - LocationServices.getLocationServices(this).removeLocationListener(this); - mapView.onStop(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } + // handle tint user dot button clicks + ViewUtils.attachClickListener( + MyLocationTintActivity.this, + R.id.tint_user_dot_button, + new View.OnClickListener() { + @Override + public void onClick(View view) { + myLocationViewSettings.setAccuracyTintColor( + ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_green)); + myLocationViewSettings.setForegroundTintColor( + ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_green)); + myLocationViewSettings.setBackgroundTintColor(Color.WHITE); + } + }); - @Override - protected void onDestroy() { - super.onDestroy(); - mapView.onDestroy(); - } + // handle tint accuracy ring button clicks + ViewUtils.attachClickListener( + MyLocationTintActivity.this, + R.id.user_accuracy_ring_tint_button, + new View.OnClickListener() { + @Override + public void onClick(View view) { + myLocationViewSettings.setAccuracyTintColor( + ContextCompat.getColor(MyLocationTintActivity.this, R.color.accent)); + myLocationViewSettings.setForegroundTintColor( + ContextCompat.getColor(MyLocationTintActivity.this, R.color.mapbox_blue)); + myLocationViewSettings.setBackgroundTintColor(Color.WHITE); + } + }); - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); + ViewUtils.attachClickListener( + MyLocationTintActivity.this, + R.id.user_dot_transparent_button, + new View.OnClickListener() { + @Override + public void onClick(View view) { + myLocationViewSettings.setForegroundTintColor(Color.TRANSPARENT); + myLocationViewSettings.setBackgroundTintColor(Color.TRANSPARENT); + } + } + ); + } + }); + + } + + @Override + public void onLocationChanged(Location location) { + if (mapboxMap != null && firstRun) { + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location), 15)); + firstRun = false; } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - onBackPressed(); - return true; - default: - return super.onOptionsItemSelected(item); - } + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + LocationServices.getLocationServices(this).addLocationListener(this); + } + + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + LocationServices.getLocationServices(this).removeLocationListener(this); + mapView.onStop(); + } + + @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); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + default: + return super.onOptionsItemSelected(item); } - - @UiThread - public void toggleGps(boolean enableGps) { - if (enableGps) { - if ((ContextCompat.checkSelfPermission(this, - Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) - || (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) - != PackageManager.PERMISSION_GRANTED)) { - ActivityCompat.requestPermissions(this, new String[]{ - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_LOCATION); - } else { - enableLocation(true); - } - } else { - enableLocation(false); - } + } + + @UiThread + public void toggleGps(boolean enableGps) { + if (enableGps) { + if ((ContextCompat.checkSelfPermission(this, + Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) + || (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) + != PackageManager.PERMISSION_GRANTED)) { + ActivityCompat.requestPermissions(this, new String[] { + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_LOCATION); + } else { + enableLocation(true); + } + } else { + enableLocation(false); } - - private void enableLocation(boolean enabled) { - if (enabled) { - mapboxMap.setMyLocationEnabled(true); - if (mapboxMap.getMyLocation() != null) { - mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom( - new LatLng(mapboxMap.getMyLocation().getLatitude(), - mapboxMap.getMyLocation().getLongitude()), 15)); - } - } else { - mapboxMap.setMyLocationEnabled(false); - } + } + + private void enableLocation(boolean enabled) { + if (enabled) { + mapboxMap.setMyLocationEnabled(true); + if (mapboxMap.getMyLocation() != null) { + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom( + new LatLng(mapboxMap.getMyLocation().getLatitude(), + mapboxMap.getMyLocation().getLongitude()), 15)); + } + } else { + mapboxMap.setMyLocationEnabled(false); } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (requestCode == PERMISSIONS_LOCATION) { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - enableLocation(true); - } - } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + if (requestCode == PERMISSIONS_LOCATION) { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + enableLocation(true); + } } + } - private static class ViewUtils { + private static class ViewUtils { - public static void attachClickListener( - @NonNull Activity activity, @IdRes int buttonId, @Nullable View.OnClickListener clickListener) { - View view = activity.findViewById(buttonId); - if (view != null) { - view.setOnClickListener(clickListener); - } - } + public static void attachClickListener( + @NonNull Activity activity, @IdRes int buttonId, @Nullable View.OnClickListener clickListener) { + View view = activity.findViewById(buttonId); + if (view != null) { + view.setOnClickListener(clickListener); + } } + } } |