Skip to content

Creating Accessibility Menu Modules

Aaron Vontell edited this page Apr 30, 2017 · 2 revisions

Introduction

One of the most useful features of AMA is the ability to provide the user with a menu which allows for accessible customization of the app itself. Developers bind data and views to this menu, which allows the menu to customize the app as the user interacts with it. Below are the steps on how to create your own page (which we will call a service) within the AMA library. Note that all relevant classes and packages mentioned are within the menu package, located here.

1) Create a new package for your service

The first step in this process is to keep your code organized; within the services package, create a new package for your service. For example, currently the services package has packages for sizing, language, and navigation.

2) Create your service's menu module

The core logic of your service will occur within a MenuModule class. Within the package created in step 1, create a new class MyServiceMenuModule. Have this class implement MenuModule (which can be found here). This menu module will essentially tell the menu what the title of the module is, whether it is enabled, and also all logic specific to this service.

3) Add NavigatorContent for displaying in the menu

While the menu module created in the previous step contains logic for the service itself, we now need to build out the logic for displaying information in the menu (i.e. what the layout is going to be, what information we will display, etc...). Within the same package, create a MyServiceNavigatorContent which implements NavigatorContent. Within the constructor, you should take in both a Context and a MyServiceMenuModule, saving both in private variables. You will also need to load a layout to display using a LayoutInflater, which you can then save and modify within other methods of this class. For a good example on how to setup the NavigatorContent component, see the NavigationNavigatorContent here.

4) Define any extra POJOs

With the core components of the module written out, you should now take the time to implement any extra objects that you may need for your menu module, and place them into the same package. For example, the Navigation menu module uses an IntentEntry object, which is defined in the navigation package.

5) Define an icon for this service

Since each page within the menu has an icon associated with it, you should define an icon to use within the DefaultMenuAdapter class (which can be found here. Within the getTabView(), you can use the position of the page within the menu to determine which icon to use (note that the position is determined in step 7)

Coming soon: Icons will be defined directly within the MenuModule, that way no modifications will be needed in DefaultMenuAdapter

6) Instantiate your service within the config class

In order to enable your service to be displayed within the menu, you will need to instantiate it within the MenuConfig class, which is in the menu package found here. Create a private variable for your MenuModule, and instantiate it within the MenuConfig constructor. Also create a getter for this MenuModule.

7) Create the menu adapter

For our last step, within the menu package there is a MenuViewParser which constructs the actual menu. In order for your service's NavigatorContent to appear, you will need to construct it within the buildDefaultMenuAdapter() method at the bottom of the class (which can be found here). This will be in the following form:

demoMenu.put(config.getMyServiceMenuModule().getTitle(), new MyServiceNavigatorContent(context, config.getMyServiceMenuModule()));

That's it! You will now be able to see your service within the accessibility menu.

If you make cool services for the accessibility menu, make a pull request; we would love to take a look at it!