Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Adding full screen toggle example #1311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import com.mapbox.mapboxandroiddemo.examples.labs.CalendarIntegrationActivity;
import com.mapbox.mapboxandroiddemo.examples.labs.ChangeAttributionColorActivity;
import com.mapbox.mapboxandroiddemo.examples.labs.DashedLineDirectionsPickerActivity;
import com.mapbox.mapboxandroiddemo.examples.labs.FullScreenToggleActivity;
import com.mapbox.mapboxandroiddemo.examples.labs.HomeScreenWidgetActivity;
import com.mapbox.mapboxandroiddemo.examples.labs.IndoorMapActivity;
import com.mapbox.mapboxandroiddemo.examples.labs.InsetMapActivity;
Expand Down Expand Up @@ -1388,6 +1389,14 @@ private void initializeModels() {
null,
R.string.activity_lab_baseball_spray_chart_url, true, BuildConfig.MIN_SDK_VERSION));

exampleItemModels.add(new ExampleItemModel(
R.id.nav_lab,
R.string.activity_lab_full_screen_toggle_title,
R.string.activity_lab_full_screen_toggle_description,
new Intent(MainActivity.this, FullScreenToggleActivity.class),
null,
R.string.activity_lab_full_screen_toggle_url, true, BuildConfig.MIN_SDK_VERSION));

exampleItemModels.add(new ExampleItemModel(
R.id.nav_dds,
R.string.activity_dds_geojson_line_title,
Expand Down
7 changes: 7 additions & 0 deletions MapboxAndroidDemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
</activity>
<activity
android:name=".examples.labs.FullScreenToggleActivity"
android:label="@string/activity_lab_full_screen_toggle_title">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
</activity>
<activity
android:name=".examples.labs.SharedPreferencesActivity"
android:label="@string/activity_lab_shared_preferences_title">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package com.mapbox.mapboxandroiddemo.examples.labs;

import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.mapbox.mapboxandroiddemo.R;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.geometry.LatLng;
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;

public class FullScreenToggleActivity extends AppCompatActivity implements MapboxMap.OnMapLongClickListener {

private MapView mapView;
private MapboxMap mapboxMap;
private boolean hasBeenGivenFullScreenToggleInstruction = false;
private boolean isFullScreen = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// 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));

// This contains the MapView in XML and needs to be called after the access token is configured.
setContentView(R.layout.activity_lab_full_screen_toggle);

mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
FullScreenToggleActivity.this.mapboxMap = mapboxMap;
mapboxMap.addOnMapLongClickListener(FullScreenToggleActivity.this);
FloatingActionButton fullScreenToggleFab = findViewById(R.id.full_screen_toggle_fab);
fullScreenToggleFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
fullScreenToggleFab.hide();
adjustToolbars(isFullScreen);
if (!hasBeenGivenFullScreenToggleInstruction) {
Toast.makeText(FullScreenToggleActivity.this,
R.string.full_screen_toggle_instruction, Toast.LENGTH_SHORT).show();
hasBeenGivenFullScreenToggleInstruction = true;
}
}
});
}
});
}
});
}

@Override
public boolean onMapLongClick(@NonNull LatLng point) {
if (hasBeenGivenFullScreenToggleInstruction) {
adjustToolbars(isFullScreen);
}
return true;
}


/**
* Adjusts the visibility of the SupportActionBar and notification bars for the map to be full screen or not.
* ActionBar isn't checked for because the current minimum SDK level for this app is 16, which is when the
* SupportActionBar was introduced.
*
* @param showToolbars whether or not the toolbars should be displayed in order for the map to be full screen
* or not.
*/
private void adjustToolbars(boolean showToolbars) {
if (getSupportActionBar() != null) {
if (showToolbars) {
getSupportActionBar().show();
} else {
getSupportActionBar().hide();
}
}
getWindow().clearFlags(showToolbars ? WindowManager.LayoutParams.FLAG_FULLSCREEN :
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(showToolbars ? WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN :
WindowManager.LayoutParams.FLAG_FULLSCREEN);
isFullScreen = !showToolbars;
}

// Add the mapView lifecycle to the activity's lifecycle methods
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}

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

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

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

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

@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null) {
mapboxMap.removeOnMapLongClickListener(this);
}
mapView.onDestroy();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
11 changes: 5 additions & 6 deletions MapboxAndroidDemo/src/main/res/layout/activity_inset_map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:maps="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
Expand All @@ -22,9 +21,9 @@
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="bottom|end"
android:layout_marginBottom="90dp"
android:layout_marginEnd="175dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="90dp"
app:cardCornerRadius="2dp"
app:cardElevation="2dp">

Expand All @@ -38,11 +37,11 @@
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/show_bounds_toggle_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
app:srcCompat="@drawable/ic_swap_horiz_white_24dp"
android:layout_marginRight="16dp"
android:layout_height="wrap_content"/>
android:layout_marginBottom="16dp"
app:srcCompat="@drawable/ic_swap_horiz_white_24dp" />

</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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"
mapbox:mapbox_cameraTargetLat="17.44495446"
mapbox:mapbox_cameraTargetLng="9.899203657"
mapbox:mapbox_cameraZoom="2" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/full_screen_toggle_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:srcCompat="@drawable/ic_swap_horiz_white_24dp" />

</FrameLayout>
3 changes: 3 additions & 0 deletions MapboxAndroidDemo/src/main/res/values/activity_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,7 @@
<!-- Circle icon toggling on click-->
<string name="tap_on_map_to_toggle_instruction">Tap on a circle and then marker to toggle. Tap elsewhere to reset to circles.</string>

<!-- Full screen toggle -->
<string name="full_screen_toggle_instruction">Long press on the map to condense the map.</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<string name="activity_lab_shared_preferences_description">Use the Android system\'s SharedPreferences to save and retrieve information such as coordinates.</string>
<string name="activity_lab_biometric_fingerprint_description">Use the Android system\'s fingerprint unlock to reveal "personal" data on a map.</string>
<string name="activity_lab_baseball_spray_chart_description">Use the Maps SDK and filters to explore baseball data.</string>
<string name="activity_lab_full_screen_toggle_description">Toggle between showing a smaller map and a full screen map.</string>
<string name="activity_china_simple_china_mapview_description">Show an accurate and government-approved China map in your app using the Mapbox Maps SDK.</string>
<string name="activity_china_simple_china_bounds_checker_description">Use the China plugin to determine whether or not the device is inside of China.</string>
<string name="activity_china_mixed_china_and_global_style_description">Load a China style if the device is in China. Load a global/.com style if not.</string>
Expand Down
1 change: 1 addition & 0 deletions MapboxAndroidDemo/src/main/res/values/titles_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@
<string name="activity_lab_change_attribution_color_title">Style attribution</string>
<string name="activity_lab_shared_preferences_title">Saving to SharedPreferences</string>
<string name="activity_lab_biometric_fingerprint_title">Biometric fingerprint</string>
<string name="activity_lab_full_screen_toggle_title">Fullscreen toggle</string>
</resources>
1 change: 1 addition & 0 deletions MapboxAndroidDemo/src/main/res/values/urls_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<string name="activity_lab_shared_preferences_url" translatable="false">https://i.imgur.com/znxAhDG.png</string>
<string name="activity_lab_biometric_fingerprint_url" translatable="false">https://i.imgur.com/iQZzMIR.png</string>
<string name="activity_lab_baseball_spray_chart_url" translatable="false">https://i.imgur.com/1j7WVoO.png</string>
<string name="activity_lab_full_screen_toggle_url" translatable="false">https://i.imgur.com/I5iR4Vr.png</string>
<string name="activity_china_simple_china_mapview_url" translatable="false">https://i.imgur.com/KwoEynZ.png</string>
<string name="activity_china_simple_china_bounds_checker_url" translatable="false">https://i.imgur.com/fIFWqJu.png</string>
<string name="activity_china_mixed_china_and_global_style_url" translatable="false">https://i.imgur.com/XBS1WAn.png</string>
Expand Down