Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] deprecate MapboxMapOptions empty constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPaczos committed May 23, 2019
1 parent 37d9dfa commit aad904c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public class MapboxMapOptions implements Parcelable {

/**
* Creates a new MapboxMapOptions object.
* @deprecated Use {@link #createFromAttributes(Context, AttributeSet)} instead.
*/
@Deprecated
public MapboxMapOptions() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// configure inital map state
MapboxMapOptions options = new MapboxMapOptions()
MapboxMapOptions options = MapboxMapOptions.createFromAttributes(this, null)
.attributionTintColor(RED_COLOR)
.compassFadesWhenFacingNorth(false)
.camera(new CameraPosition.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

private MapboxMapOptions createFragmentOptions() {
MapboxMapOptions options = new MapboxMapOptions();
MapboxMapOptions options = MapboxMapOptions.createFromAttributes(this, null);

options.scrollGesturesEnabled(false);
options.zoomGesturesEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.testapp.activity.fragment

import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
Expand Down Expand Up @@ -36,10 +37,10 @@ class NestedViewPagerActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_recyclerview)
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = ItemAdapter(LayoutInflater.from(this), supportFragmentManager)
recyclerView.adapter = ItemAdapter(this, LayoutInflater.from(this), supportFragmentManager)
}

class ItemAdapter(private val inflater: LayoutInflater, private val fragmentManager: FragmentManager) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class ItemAdapter(private val context: Context, private val inflater: LayoutInflater, private val fragmentManager: FragmentManager) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private val items = listOf(
"one", "two", "three", ViewPagerItem(), "four", "five", "six", "seven", "eight", "nine", "ten",
Expand All @@ -57,7 +58,7 @@ class NestedViewPagerActivity : AppCompatActivity() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return if (viewType == TYPE_VIEWPAGER) {
val viewPager = inflater.inflate(R.layout.item_viewpager, parent, false) as ViewPager
mapHolder = ViewPagerHolder(viewPager, fragmentManager)
mapHolder = ViewPagerHolder(context, viewPager, fragmentManager)
return mapHolder as ViewPagerHolder
} else {
TextHolder(inflater.inflate(android.R.layout.simple_list_item_1, parent, false) as TextView)
Expand Down Expand Up @@ -90,9 +91,9 @@ class NestedViewPagerActivity : AppCompatActivity() {
}

class ViewPagerItem
class ViewPagerHolder(private val viewPager: ViewPager, fragmentManager: FragmentManager) : RecyclerView.ViewHolder(viewPager) {
class ViewPagerHolder(context: Context, private val viewPager: ViewPager, fragmentManager: FragmentManager) : RecyclerView.ViewHolder(viewPager) {
init {
viewPager.adapter = MapPagerAdapter(fragmentManager)
viewPager.adapter = MapPagerAdapter(context, fragmentManager)
viewPager.setOnTouchListener { view, motionEvent ->
// Disallow the touch request for recyclerView scroll
view.parent.requestDisallowInterceptTouchEvent(true)
Expand All @@ -102,10 +103,10 @@ class NestedViewPagerActivity : AppCompatActivity() {
}
}

class MapPagerAdapter(fm: FragmentManager?) : FragmentStatePagerAdapter(fm) {
class MapPagerAdapter(private val context: Context, fm: FragmentManager?) : FragmentStatePagerAdapter(fm) {

override fun getItem(position: Int): Fragment {
val options = MapboxMapOptions()
val options = MapboxMapOptions.createFromAttributes(context, null)
options.textureMode(true)
options.doubleTapGesturesEnabled(false)
options.rotateGesturesEnabled(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

private MapboxMapOptions createFragmentOptions() {
MapboxMapOptions options = new MapboxMapOptions();
MapboxMapOptions options = MapboxMapOptions.createFromAttributes(this, null);

options.scrollGesturesEnabled(false);
options.zoomGesturesEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.mapboxsdk.testapp.activity.fragment

import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
Expand All @@ -21,7 +22,7 @@ class ViewPagerActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_viewpager)
viewPager.adapter = MapFragmentAdapter(supportFragmentManager)
viewPager.adapter = MapFragmentAdapter(this, supportFragmentManager)
}

override fun onRestoreInstanceState(savedInstanceState: Bundle) {
Expand All @@ -37,14 +38,14 @@ class ViewPagerActivity : AppCompatActivity() {
}
}

internal class MapFragmentAdapter(fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {
internal class MapFragmentAdapter(private val context: Context, fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {

override fun getCount(): Int {
return NUM_ITEMS
}

override fun getItem(position: Int): Fragment? {
val options = MapboxMapOptions()
val options = MapboxMapOptions.createFromAttributes(context, null)
options.textureMode(true)
options.camera(
CameraPosition.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void addMapFragment() {
int fragmentCount = fragmentManager.getBackStackEntryCount();

FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
MainMapFragment mainMapFragment = MainMapFragment.newInstance(fragmentCount);
MainMapFragment mainMapFragment = MainMapFragment.newInstance(this, fragmentCount);
if (fragmentCount == 0) {
fragmentTransaction.add(R.id.fragment_container, mainMapFragment, TAG_MAIN_FRAGMENT);
} else {
Expand All @@ -104,7 +104,7 @@ private void toggleBottomSheetMapFragment() {

private void addBottomSheetMapFragment() {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.fragment_container_bottom, BottomSheetFragment.newInstance(), TAG_BOTTOM_FRAGMENT);
fragmentTransaction.add(R.id.fragment_container_bottom, BottomSheetFragment.newInstance(this), TAG_BOTTOM_FRAGMENT);
fragmentTransaction.commit();
}

Expand All @@ -128,12 +128,12 @@ public static class MainMapFragment extends Fragment implements OnMapReadyCallba

private MapView map;

public static MainMapFragment newInstance(int mapCounter) {
public static MainMapFragment newInstance(Context context, int mapCounter) {
MainMapFragment mapFragment = new MainMapFragment();
Bundle bundle = new Bundle();
bundle.putInt("mapcounter", mapCounter);
mapFragment.setArguments(bundle);
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
MapboxMapOptions mapboxMapOptions = MapboxMapOptions.createFromAttributes(context, null);
mapFragment.setArguments(MapFragmentUtils.createFragmentArgs(mapboxMapOptions));
return mapFragment;
}
Expand Down Expand Up @@ -209,9 +209,9 @@ public static class BottomSheetFragment extends Fragment implements OnMapReadyCa

private MapView map;

public static BottomSheetFragment newInstance() {
public static BottomSheetFragment newInstance(Context context) {
BottomSheetFragment mapFragment = new BottomSheetFragment();
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
MapboxMapOptions mapboxMapOptions = MapboxMapOptions.createFromAttributes(context, null);
mapboxMapOptions.renderSurfaceOnTop(true);
mapFragment.setArguments(MapFragmentUtils.createFragmentArgs(mapboxMapOptions));
return mapFragment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void setupMapView(Bundle savedInstanceState) {
}

protected MapboxMapOptions setupMapboxMapOptions() {
return new MapboxMapOptions();
return MapboxMapOptions.createFromAttributes(this, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_map_fragment);

if (savedInstanceState == null) {
MapboxMapOptions options = new MapboxMapOptions();
MapboxMapOptions options = MapboxMapOptions.createFromAttributes(this, null);
options.camera(new CameraPosition.Builder()
.target(MACHU_PICCHU)
.zoom(ZOOM_IN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_symbollayer);

// Create map configuration
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
MapboxMapOptions mapboxMapOptions = MapboxMapOptions.createFromAttributes(this, null);
mapboxMapOptions.camera(new CameraPosition.Builder().target(
new LatLng(52.35273, 4.91638))
.zoom(13)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void setupBackground() {
}

private void setupMapView(Bundle savedInstanceState) {
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
MapboxMapOptions mapboxMapOptions = MapboxMapOptions.createFromAttributes(this, null);
mapboxMapOptions.translucentTextureSurface(true);
mapboxMapOptions.textureMode(true);
mapboxMapOptions.camera(new CameraPosition.Builder()
Expand Down

0 comments on commit aad904c

Please sign in to comment.