LogoLogo
CMSGitHubSupportBook a demo
  • Documentation
  • Academy
  • Help Center
  • Welcome
  • SDKS & Frameworks
    • Web
      • Getting Started
        • Prerequisites
          • MapsIndoors
          • Map Engine Provider
            • Option 1: Get your Mapbox Access Token
            • Option 2: Get your Google Maps API Keys​
          • Map Engine Setup
        • Getting Started: MapsIndoors
      • Map Visualization
        • Highlight, Hover and Select
        • Remove Labels from Buildings and Venues
        • Change Building Outline
        • Managing Collisions Based on Zoom Level
        • 3D Maps
          • Managing your 3D Maps
        • Base Map Styling - Google Maps
        • Managing feature visibility for Mapbox
      • Wayfinding
        • Directions
        • Directions Service
          • Tailoring the directions to your specific needs
        • Directions Renderer
          • Customizing the Route Animation
        • Multi-stop navigation
          • Custom Icons
        • User's Location as Point of Origin
      • Search
        • Search Operations
        • Searching
        • Using External ID, Geospatial Joins
        • Utilizing MapsIndoors Web Components and Other Searches
      • Map Management
      • Data Visualization
        • Display Heatmap Overlay
      • Other guides
        • Authentication
          • Single Sign-On
            • SSO Configuration
            • SSO Authorisation
          • 2-Factor Authentication
          • Password Reset
        • Application User Roles
        • Custom Properties
        • Display Language
        • Language
        • User Positioning
          • Show User's Location aka. Blue Dot
          • Using Cisco DNA Spaces
        • Working with Events
        • Turn Off Collisions Based on Zoom Level
        • Remove Labels from Buildings and Venues for Web
        • Synchronizing data for a subset of venues
        • Custom Floor Selector
      • Display Rules in Practice
      • Offline Data
      • Managing map visibility
    • Android
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
        • Enable Live Data
        • Integrating MapsIndoors into your own App
        • Migrating from V3 to V4
          • Migrating to Mapbox V11
      • Directions
        • Directions Service
        • Directions Renderer
          • User's Location as Point of Origin
        • Wayfinding Instructions
          • See Route Element Details
        • Using multi-stop navigation
      • Searching
        • Searching on a Map
        • Creating a Search Experience
      • Switching Solutions
      • Caching & Offline Data
      • Display Language
      • Displaying Objects
        • Application User Roles
        • Getting a Polygon from a Location
        • Location Clustering
        • Location Data Sources
        • Location Details
        • Turn Off Collisions Based on Zoom Level
        • Enabling and Disabling features on the map
      • Change Building Outline Color
      • Event Logging
      • Configuring a menu with AppConfig
      • Display Heatmap Overlay
      • Custom Properties
      • Custom Floor Selector
      • External IDs
      • User Positioning
        • Show User's Location aka. Blue Dot
        • Using Cisco DNA Spaces
        • Using Google Fused Location Provider
        • Using Indoor Atlas
      • Authentication
        • Single Sign-On
          • SSO Configuration
          • SSO Authorisation
        • 2-Factor Authentication
        • Password Reset
      • Display Rules in Practice
        • Label styling through Display Rules
      • Highlight and Select
    • iOS
      • Getting Started
        • Prerequisites
        • Set Up Your Environment
        • Display a Map
        • Search
        • Getting Directions
        • Migrating from v3 to v4
      • Directions
        • Directions Renderer
          • User's Location as Point of Origin
        • Wayfinding Instructions
          • See Route Element Details
        • Directions Service
        • Using multi-stop navigation
      • Searching
        • Searching on a Map
        • Creating a Search Experience
      • Caching & Offline Data
      • Displaying Objects
        • Application User Roles
        • Getting a Polygon from a Location
        • Location Details
        • Turn Off Collisions Based on Zoom Level
        • Enabling and Disabling features on the map
      • Custom Floor Selector
      • Change Building Outline Color
      • Custom Map Padding
      • Custom Properties
      • Display Rules in Practice
        • Label styling through Display Rules
      • Switching Solutions
      • Show User's Location aka. Blue Dot
        • Using Indoor Atlas
        • Using Cisco DNA Spaces
      • Highlight and Select
      • Display Language
    • React Native
      • Getting Started
        • Prerequisites
        • Project Setup
        • Displaying a Map
        • Creating a Search Experience
        • Getting Directions
        • Enabling Live Data
      • Showing Blue Dot
    • Flutter
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
      • Migration Guide
    • Integration API
      • Integration API Access
        • Access with Swagger
        • Access with Postman
        • Access with Python
        • Client credentials flow
      • Data Description
      • Reverse Geocoding
      • Route Access
      • OpenAPI Specification
    • Built-In Map Edits
      • Getting started
      • Authentication
      • Release notes
      • Reference docs
  • Products
    • Product Overview
    • CMS
      • Interface Overview
      • Display Rules
      • Media Library
        • 2D Models and Icons
        • 3D Models
      • Editing Data
      • Solution Settings
      • Settings
      • Data Concepts
      • User Roles
      • Route Network
        • Barrier Route Element
        • Door Route Element
      • Additional Location Details
    • Map Template
      • Getting Started
        • Web Component
        • React Component
      • Configuration
        • Query Parameters
      • Customization
      • Deploying Map Template to a cloud storage provider
      • 2D/3D Visibility Switch
      • External customization of the Map Template
      • Location Details configuration
      • Kiosk
        • QR code configuration
  • Other
    • Design
      • Standard MapsIndoors Map Style
      • Using a Custom Mapbox MapStyle
    • Changelog
      • Web SDK
        • V4
        • V3
      • Android SDK
        • V4
        • V3
      • iOS SDK
        • V4
        • V3
      • React Native SDK
      • Flutter SDK
      • MI Components
      • Map Template
    • Glossary
  • Legacy Docs
    • Android SDK V3
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
        • Enable Live Data
        • Integrating MapsIndoors into your own App
    • iOS SDK V3
      • Getting Started
        • Prerequisites
        • Set Up Your Environment
        • Display a Map
        • Search
        • Directions
        • Live Data
        • Integrating MapsIndoors into your own App
      • Inspect Route Element for iOS v3
      • Using Cisco DNA Spaces
      • Using Indoor Atlas
      • Switching Solutions
      • Show User's Location aka. Blue Dot
      • Application User Roles
      • Getting a Polygon from a Location
      • Location Details
  • MapsIndoors SDK Firewall
  • Google Analytics & Logging
  • Reference Docs
    • Web SDK
    • Android SDK
    • iOS SDK
    • React Native SDK
    • Flutter SDK
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. SDKS & Frameworks
  2. Android

Configuring a menu with AppConfig

Last updated 1 year ago

Was this helpful?

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 . If you just want to follow this guide, the getting started code can be found here for /.

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_list can be seen .

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.

public class MenuItemAdapter extends RecyclerView.Adapter<ViewHolder> {

    private final List<MPMenuInfo> mMenuInfos;
    private final MapsActivity mMapActivity;

    MenuItemAdapter(List<MPMenuInfo> menuInfoList, MapsActivity activity) {
        mMenuInfos = menuInfoList;
        mMapActivity = activity;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        //Setting the the text on the text view to the name of the location
        holder.text.setText(mMenuInfos.get(position).getName());
        ...
    }

    @Override
    public int getItemCount() {
        return mMenuInfos.size();
    }

}

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.

// if there exists an icon for this menuItem, then we will use it
if (mMenuInfos.get(position).getIconUrl() != null) {
    // As we need to download the image, it has to be offloaded from the main thread
    new Thread(() -> {
        Bitmap image;
        try {
            // Usually we would not want to re-download the image every time, but that is not important for this guide
            URL url = new URL(mMenuInfos.get(position).getIconUrl());
            image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        } catch(IOException ignored) {
            return;
        }
        //Set the image while on the main thread
        new Handler(Looper.getMainLooper()).post(() -> {
            holder.imageView.setImageBitmap(image);
        });

    }).start();
}

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.

// When a category is selected, we want to filter the map s.t. it only shows the locations in that
// category
holder.itemView.setOnClickListener(view -> {
    // empty query, we do not need to query anything specific
    MPQuery query = new MPQuery.Builder().build();
    // filter created on the selected category key
    MPFilter filter = new MPFilter.Builder().setCategories(Collections.singletonList(mMenuInfos.get(position).getCategoryKey())).build();
    MapsIndoors.getLocationsAsync(query, filter, (locations, error) -> {
        if (error == null && locations != null) {
            mMapActivity.getMapControl().setFilter(locations, MPFilterBehavior.DEFAULT)
        }
    });
});

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.

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    //ClickListener to start a search, when the user clicks the search button
    searchBtn.setOnClickListener(view -> {
        /*
        if (mSearchTxtField.getText().length() != 0) {
            //There is text inside the search field. So lets do the search.
            search(mSearchTxtField.getText().toString());
            //Making sure keyboard is closed.
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
        */
        // Lets hijack the searchbutton
        mMenuFragment = MenuFragment.newInstance(MapsIndoors.getAppConfig().getMenuInfo("mainmenu"), this);
        //Make a transaction to the bottomsheet
        addFragmentToBottomSheet(mMenuFragment);
    });
    ...
}

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.

@Override
public void onDestroyView() {
    // When we close the menu fragment we want to display all locations again, not just whichever were selected last
    mMapActivity.getMapControl().clearFilter();
    super.onDestroyView();
}

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.

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.

class MenuFragment : Fragment() {
    private lateinit var mMenuInfos: List<MPMenuInfo?>
    private lateinit var mMapActivity: MapsActivity


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        // For the brevity of this guide, we will reuse the bottom sheet used in the searchFragment
        return inflater.inflate(R.layout.fragment_search, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val recyclerView = view as RecyclerView
        recyclerView.layoutManager = LinearLayoutManager(context)
        recyclerView.adapter = MenuItemAdapter(mMenuInfos, mMapActivity)
    }

    companion object {
        fun newInstance(menuInfos: List<MPMenuInfo?>, mapsActivity: MapsActivity): MenuFragment {
            val fragment = MenuFragment()
            fragment.mMenuInfos = menuInfos
            fragment.mMapActivity = mapsActivity
            return fragment
        }
    }
}

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.

internal class MenuItemAdapter(
    private val mMenuInfos: List<MPMenuInfo?>,
    private val mMapActivity: MapsActivity?
) : RecyclerView.Adapter<ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(LayoutInflater.from(parent.context), parent)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        //Setting the the text on the text view to the name of the location
        holder.text.text = mMenuInfos[position]?.name
        ...

    }

    override fun getItemCount(): Int {
        return mMenuInfos.size
    }
}

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.

// if there exists an icon for this menuItem, then we will use it
val iconUrl = mMenuInfos[position]?.iconUrl
if (iconUrl != null) {
    // As we need to download the image, it has to be offloaded from the main thread
    Thread {
        val image: Bitmap = try {
            val url = URL(iconUrl)
            BitmapFactory.decodeStream(url.openConnection().getInputStream())
        } catch (ignored: IOException) {
            return@Thread
        }
        //Set the image while on the main thread
        Handler(Looper.getMainLooper()).post {
            holder.imageView.setImageBitmap(
                image
            )
        }
    }.start()
}

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.

// When a category is selected, we want to filter the map s.t. it only shows the locations in that
// category
holder.itemView.setOnClickListener { view ->
    // empty query, we do not need to query anything specific
    val query = MPQuery.Builder().build()
    // filter created on the selected category key
    val filter = MPFilter.Builder().setCategories(
        listOf(
            mMenuInfos[position]?.categoryKey
        )
    ).build()
    MapsIndoors.getLocationsAsync(
        query, filter
    ) { locations: List<MPLocation?>?, error: MIError? ->
        if (error == null && locations != null) {
            mMapActivity?.getMapControl()?.setFilter(locations, MPFilterBehavior.DEFAULT)
        }
    }
}

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.

override fun onCreate(savedInstanceState: Bundle?) {
    ...
    //ClickListener to start a search, when the user clicks the search button
    var searchBtn = findViewById<ImageButton>(R.id.search_btn)
    searchBtn.setOnClickListener {
        /*
        if (mSearchTxtField.text?.length != 0) {
            //There is text inside the search field. So lets do the search.
            search(mSearchTxtField.text.toString())
        }
        //Making sure keyboard is closed.
        imm.hideSoftInputFromWindow(it.windowToken, 0)
        */

        // Lets hijack the searchbutton
        mMenuFragment = MenuFragment.newInstance(MapsIndoors.getAppConfig()?.getMenuInfo("mainmenu")!!, this)
        //Make a transaction to the bottomsheet
        addFragmentToBottomSheet(mMenuFragment)
    }
    ...
}

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.

override fun onDestroyView() {
    // When we close the menu fragment we want to display all locations again, not just whichever were selected last
    mMapActivity.getMapControl().clearFilter()
    super.onDestroyView()
}

If you have not followed the getting started guide, the code can be seen here for /.

The code shown in this guide can be found here for /. -->

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 . If you just want to follow this guide, the getting started code can be found here for /.

If you have not followed the getting started guide, the code for fragment_search_list can be seen .

If you have not followed the getting started guide, the code can be seen here for /.

The code shown in this guide can be found here for /. -->

here
java
kotlin
here
java
kotlin
java
kotlin
here
java
kotlin
here
java
kotlin
java
kotlin