This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding attribution color change example
- Loading branch information
Showing
7 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
.../main/java/com/mapbox/mapboxandroiddemo/examples/labs/ChangeAttributionColorActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package com.mapbox.mapboxandroiddemo.examples.labs; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
|
||
import com.mapbox.mapboxandroiddemo.R; | ||
import com.mapbox.mapboxsdk.Mapbox; | ||
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 androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.core.content.ContextCompat; | ||
|
||
/** | ||
* Adjust the Maps SDK's attribution ImageView color so that it matches the map style or app UI | ||
*/ | ||
public class ChangeAttributionColorActivity extends AppCompatActivity implements OnMapReadyCallback { | ||
|
||
private MapView mapView; | ||
private ImageView attributionView; | ||
private int index = 0; | ||
private int[] attributionColors; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
attributionColors = new int[] { | ||
Color.RED, | ||
Color.BLUE, | ||
Color.YELLOW, | ||
ContextCompat.getColor(this, R.color.colorAccent), // a runtime app UI color | ||
ContextCompat.getColor(this, R.color.colorPrimaryDark), // a runtime app UI color | ||
Color.parseColor("#1e7019"), // dark green | ||
}; | ||
|
||
// Mapbox access token is configured here. This needs to be called either in your application | ||
// object or in the same activity which contains the mapview. | ||
Mapbox.getInstance(this, getString(R.string.access_token)); | ||
|
||
setContentView(R.layout.activity_lab_change_attribution_info_button_color); | ||
|
||
mapView = findViewById(R.id.mapView); | ||
mapView.onCreate(savedInstanceState); | ||
mapView.getMapAsync(this); | ||
} | ||
|
||
@Override | ||
public void onMapReady(@NonNull final MapboxMap mapboxMap) { | ||
mapboxMap.setStyle(Style.LIGHT, new Style.OnStyleLoaded() { | ||
@Override | ||
public void onStyleLoaded(@NonNull Style style) { | ||
// Get the ImageView from the MapView | ||
attributionView = mapView.findViewById(R.id.attributionView); | ||
|
||
// Change the color when the floating action button is clicked | ||
findViewById(R.id.switch_attribution_color_fab).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
if (index == attributionColors.length - 1) { | ||
|
||
mapboxMap.setStyle(Style.LIGHT); | ||
index = 0; | ||
} | ||
|
||
// Adjust map to the Maps SDK's Dark style | ||
if (index == 2) { | ||
mapboxMap.setStyle(Style.DARK); | ||
} | ||
|
||
// Adjust map to a custom monochrome dark green style to match the | ||
// "i" attribution's dark green color | ||
if (index == 4) { | ||
mapboxMap.setStyle(new Style.Builder().fromUri("mapbox://styles/appsatmapboxcom/ck0cyq1lt0bbo1cmwkpf2w7g9")); | ||
} | ||
|
||
if (index == 5) { | ||
mapboxMap.setStyle(new Style.Builder().fromUri("mapbox://styles/appsatmapboxcom/ck0cyq1lt0bbo1cmwkpf2w7g9")); | ||
} | ||
|
||
// Change the color of the "i" attribution button | ||
attributionView.setColorFilter(attributionColors[index]); | ||
|
||
index++; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
mapView.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@Override | ||
public void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
mapView.onDestroy(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
MapboxAndroidDemo/src/main/res/layout/activity_lab_change_attribution_info_button_color.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:mapbox="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
<com.google.android.material.floatingactionbutton.FloatingActionButton | ||
android:id="@+id/switch_attribution_color_fab" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|right" | ||
android:layout_marginEnd="16dp" | ||
android:layout_marginRight="16dp" | ||
android:layout_marginBottom="16dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:srcCompat="@drawable/ic_swap_horiz_white_24dp" | ||
mapbox:fabSize="normal" /> | ||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters