blob: c9a9377885cd7c832b233516fd0bfd5c8263ba56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.testapp.R;
/**
* Test activity showcasing showing a Map inside of a DialogFragment.
* <p>
* Uses the deprecated TextureView API to workaround the issue of seeing a grey background before the gl surface.
* </p>
*/
public class MapInDialogActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_in_dialog);
Button button = findViewById(R.id.button_open_dialog);
button.setOnClickListener(view -> {
FragmentManager fm = getSupportFragmentManager();
MapDialogFragment editNameDialogFragment = MapDialogFragment.newInstance("Map Dialog");
editNameDialogFragment.show(fm, "fragment_dialog_map");
});
}
public static class MapDialogFragment extends DialogFragment {
private MapView mapView;
public MapDialogFragment() {
}
public static MapDialogFragment newInstance(String title) {
MapDialogFragment frag = new MapDialogFragment();
Bundle args = new Bundle();
args.putString("title", title);
frag.setArguments(args);
return frag;
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_dialog_map, container);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mapView = view.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.OUTDOORS));
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new Dialog(getActivity(), getTheme()) {
@Override
public void dismiss() {
if (mapView != null && !mapView.isDestroyed()) {
mapView.onPause();
mapView.onStop();
mapView.onDestroy();
mapView = null;
}
super.dismiss();
}
};
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
if (mapView != null) {
mapView.onPause();
}
}
@Override
public void onStop() {
super.onStop();
if (mapView != null) {
mapView.onStop();
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (mapView != null) {
mapView.onDestroy();
}
}
@Override
public void onLowMemory() {
super.onLowMemory();
if (mapView != null) {
mapView.onLowMemory();
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mapView != null) {
mapView.onSaveInstanceState(outState);
}
}
}
}
|