Skip to content

Commit

Permalink
Add support for accessibility label for actions bar items
Browse files Browse the repository at this point in the history
  • Loading branch information
deepueg committed May 5, 2020
1 parent f737f9f commit 0a85be2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand Down Expand Up @@ -384,7 +385,11 @@ private void updateNavBar(@NonNull NavigationBar navigationBar) {

actionBar.setTitle(navigationBar.getTitle());

updateHomeAsUpIndicator(navigationBar.getLeftButton(), actionBar);
NavigationBarLeftButton leftButton = navigationBar.getLeftButton();
updateHomeAsUpIndicator(leftButton, actionBar);
if (leftButton != null && !TextUtils.isEmpty(leftButton.getAdaLabel())) {
actionBar.setHomeActionContentDescription(leftButton.getAdaLabel());
}

if (mMenu != null && mFragment.getActivity() != null) {
MenuUtil.updateMenuItems(mMenu, navigationBar, mNavBarButtonClickListener, mMenuItemDataProvider, mFragment.getActivity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.StrictMode;
import android.util.Patterns;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.URLUtil;
Expand All @@ -31,6 +32,7 @@
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.MenuItemCompat;

import com.ernnavigationApi.ern.model.NavigationBar;
import com.ernnavigationApi.ern.model.NavigationBarButton;
Expand Down Expand Up @@ -113,6 +115,14 @@ private static MenuItem addButtonAsMenuItem(@NonNull NavigationBarButton button,
registerItemClickListener(menuItem, button, navBarButtonClickListener);
}

if (!TextUtils.isEmpty(button.getAdaLabel())) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
menuItem.setContentDescription(button.getAdaLabel());
} else {
MenuItemCompat.setContentDescription(menuItem, button.getAdaLabel());
}
}

return menuItem;
}

Expand Down

0 comments on commit 0a85be2

Please sign in to comment.