Configuring a menu with AppConfig
AppConfig contains elements that are useful for any app developer using the SDK. This guide will showcase how to use AppConfig to create a menu of location categories.
This guide uses code from the "Getting Started" guide. If you have not completed it yet, it is highly recommended to complete it in order to achieve a better understanding of the MapsIndoors SDK. The guide can be found here. If you just want to follow this guide, the getting started code can be found here for java/kotlin.
First, make a new fragment for the menu, and call it MenuFragment, this fragment will take a list of MPMenuInfo which will become the elements of the menu.
If you have not followed the getting started guide, the code for
fragment_search_listcan be seen here.
public class MenuFragment extends Fragment {
private List<MPMenuInfo> mMenuInfos = null;
private MapsActivity mMapActivity = null;
public static MenuFragment newInstance(List<MPMenuInfo> menuInfos, MapsActivity mapsActivity) {
final MenuFragment fragment = new MenuFragment();
fragment.mMenuInfos = menuInfos;
fragment.mMapActivity = mapsActivity;
return fragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
// For the brevity of this guide, we will reuse the bottom sheet used in the searchFragment
return inflater.inflate(R.layout.fragment_search_list, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
final RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(new MenuItemAdapter(mMenuInfos, mMapActivity));
}
}Next make an adapter for this list of MPMenuInfo. In this example the adapter reuses the ViewHolder created for the search experience in the getting started guide. For now, Just set the name of the item in onBindViewHolder, the icon and click listener will be set later.
If you have not followed the getting started guide, the code can be seen here for java/kotlin.
The icon for the MPMenuInfo is saved as an URL, as such it has to be downloaded to be displayed. Open a network connection in a background thread and download the image as a stream and save it in a Bitmap, then update the item's view back on the Main thread.
This is a very rudimentary example, and should not be replicated in production code, see it as an exercise to implement a better way to download and display the icons.
To show which locations belong to the category of the selected MPMenuInfo, call MapsIndoors.getLocationsAsync(MPQuery, MPFilter, OnLocationsReadyListener). The MPQuery can just be empty as nothing specific needs to be queried. Set the category on the MPFilter, this has to be the category key MPMenuInfo.getCategoryKey(), as this key is shared with locations in the SDK.
Finally, in the OnLocationsReadyListener call MapControl.setFilter(List<MPLocation>, MPFilterBehavior) as this will filter the map to only show the selected locations.
Then, in order to show the menu, hijack the search icon's onClickListener method. The MPMenuInfo can be fetched via MapsIndoors.getAppConfig().getMenuInfo(String), and will give a menu corresponding to the inputted String, in this guide "mainmenu" has been used as it is the default.
Finally to clear the category filter from the map call MapControl.clearFilter(), in this example it is called when closing the menu sheet, it the onDestroyView method of MenuFragment.
The code shown in this guide can be found here for java/kotlin. -->
AppConfig contains elements that are useful for any app developer using the SDK. This guide will showcase how to use AppConfig to create a menu of location categories.
This guide uses code from the "Getting Started" guide. If you have not completed it yet, it is highly recommended to complete it in order to achieve a better understanding of the MapsIndoors SDK. The guide can be found here. If you just want to follow this guide, the getting started code can be found here for java/kotlin.
First, make a new fragment for the menu, and call it MenuFragment, this fragment will take a list of MPMenuInfo which will become the elements of the menu.
If you have not followed the getting started guide, the code for
fragment_search_listcan be seen here.
Next make an adapter for this list of MPMenuInfo. In this example the adapter reuses the ViewHolder created for the search experience in the getting started guide. For now, Just set the name of the item in onBindViewHolder, the icon and click listener will be set later.
If you have not followed the getting started guide, the code can be seen here for java/kotlin.
The icon for the MPMenuInfo is saved as an URL, as such it has to be downloaded to be displayed. Open a network connection in a background thread and download the image as a stream and save it in a Bitmap, then update the item's view back on the Main thread.
This is a very rudimentary example, and should not be replicated in production code, see it as an exercise to implement a better way to download and display the icons.
To show which locations belong to the category of the selected MPMenuInfo, call MapsIndoors.getLocationsAsync(MPQuery, MPFilter, OnLocationsReadyListener). The MPQuery can just be empty as nothing specific needs to be queried. Set the category on the MPFilter, this has to be the category key MPMenuInfo.getCategoryKey(), as this key is shared with locations in the SDK.
Finally, in the OnLocationsReadyListener call MapControl.setFilter(List<MPLocation>, MPFilterBehavior) as this will filter the map to only show the selected locations.
Then, in order to show the menu, hijack the search icon's onClickListener method. The MPMenuInfo can be fetched via MapsIndoors.getAppConfig().getMenuInfo(String), and will give a menu corresponding to the inputted String, in this guide "mainmenu" has been used as it is the default.
Finally to clear the category filter from the map call MapControl.clearFilter(), in this example it is called when closing the menu sheet, it the onDestroyView method of MenuFragment.
The code shown in this guide can be found here for java/kotlin. -->
Last updated
Was this helpful?