Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #33 from novoda/develop
Browse files Browse the repository at this point in the history
Merge 1.6.0 develop to master
  • Loading branch information
Ryan Feline authored Apr 20, 2018
2 parents 99965d3 + 5f3c3d9 commit 91983e7
Show file tree
Hide file tree
Showing 11 changed files with 701 additions and 73 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ext {
artifactsPublish = [
userOrg: 'novoda',
groupId: 'com.novoda',
version: '1.5.0',
version: '1.6.0',
website: 'https://github.com/novoda/accessibilitools'
]
}
267 changes: 267 additions & 0 deletions core/src/main/java/com/novoda/accessibility/ActionMenuItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
package com.novoda.accessibility;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.util.Log;
import android.view.*;

class ActionMenuItem implements MenuItem {

private static final String TAG = "accessibilitools";

private final Resources resources;
private final int id;

private CharSequence title;
private boolean enabled;
@Nullable
private OnMenuItemClickListener menuItemClickListener;

ActionMenuItem(Resources resources, int id, CharSequence title) {
this.resources = resources;
this.id = id;
this.title = title;
}

@Override
public int getItemId() {
return id;
}

@Override
public int getGroupId() {
throw new UnsupportedOperationException();
}

@Override
public int getOrder() {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setTitle(CharSequence title) {
this.title = title;
return this;
}

@Override
public ActionMenuItem setTitle(@StringRes int title) {
setTitle(resources.getString(title));
return this;
}

@Override
public CharSequence getTitle() {
return title;
}

@Override
public ActionMenuItem setTitleCondensed(@Nullable CharSequence title) {
if (title != null) {
throw new UnsupportedOperationException();
}
return this;
}

@Override
public CharSequence getTitleCondensed() {
return title;
}

@Override
public ActionMenuItem setIcon(Drawable icon) {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setIcon(int iconRes) {
if (iconRes != 0) {
throw new UnsupportedOperationException();
}
return this;
}

@Override
public Drawable getIcon() {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setIntent(Intent intent) {
throw new UnsupportedOperationException();
}

@Override
public Intent getIntent() {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setShortcut(char numericChar, char alphaChar) {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setNumericShortcut(char numericChar) {
Log.w(TAG, "setNumericShortcut(char) is not supported but is called by MenuInflater");
return this;
}

@Override
public char getNumericShortcut() {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setAlphabeticShortcut(char alphaChar) {
Log.w(TAG, "setAlphabeticShortcut(char) is not supported but is called by MenuInflater");
return this;
}

@Override
public char getAlphabeticShortcut() {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setCheckable(boolean checkable) {
if (checkable) {
throw new UnsupportedOperationException();
}
return this;
}

@Override
public boolean isCheckable() {
return false;
}

@Override
public ActionMenuItem setChecked(boolean checked) {
if (checked) {
throw new UnsupportedOperationException();
}
return this;
}

@Override
public boolean isChecked() {
return false;
}

@Override
public ActionMenuItem setVisible(boolean visible) {
if (!visible) {
throw new UnsupportedOperationException();
}
return this;
}

/**
* For our case, a menu item will always/only be visible if enabled.
*/
@Override
public boolean isVisible() {
return isEnabled();
}

@Override
public ActionMenuItem setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
}

@Override
public boolean isEnabled() {
return enabled;
}

@Override
public boolean hasSubMenu() {
return false;
}

@Nullable
@Override
public SubMenu getSubMenu() {
return null;
}

@Override
public ActionMenuItem setOnMenuItemClickListener(OnMenuItemClickListener menuItemClickListener) {
this.menuItemClickListener = menuItemClickListener;
return this;
}

@Nullable
@Override
public ContextMenu.ContextMenuInfo getMenuInfo() {
return null;
}

@Override
public void setShowAsAction(int actionEnum) {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setShowAsActionFlags(int actionEnum) {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setActionView(View view) {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setActionView(int resId) {
throw new UnsupportedOperationException();
}

@Override
public View getActionView() {
throw new UnsupportedOperationException();
}

@Override
public ActionMenuItem setActionProvider(ActionProvider actionProvider) {
throw new UnsupportedOperationException();
}

@Nullable
@Override
public ActionProvider getActionProvider() {
return null;
}

@Override
public boolean expandActionView() {
return false;
}

@Override
public boolean collapseActionView() {
return false;
}

@Override
public boolean isActionViewExpanded() {
return false;
}

@Override
public ActionMenuItem setOnActionExpandListener(OnActionExpandListener listener) {
throw new UnsupportedOperationException();
}

/**
* Returns true if action was invoked, else false.
*/
boolean invokeAction() {
return isEnabled() && menuItemClickListener != null && menuItemClickListener.onMenuItemClick(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,56 @@ public class ActionsAccessibilityDelegate extends AccessibilityDelegateCompat {

private final Resources resources;
private final Actions actions;
private final UsageHintsAccessibilityDelegate usageHintsAccessibilityDelegate;
private final UsageHints usageHints;

public ActionsAccessibilityDelegate(Resources resources, Actions actions) {
this(resources, actions, new UsageHintsAccessibilityDelegate(resources));
this(resources, actions, new UsageHints(resources));
}

public ActionsAccessibilityDelegate(Resources resources, Actions actions, UsageHintsAccessibilityDelegate usageHintsAccessibilityDelegate) {
public ActionsAccessibilityDelegate(Resources resources, Actions actions, UsageHints usageHints) {
this.resources = resources;
this.actions = actions;
this.usageHintsAccessibilityDelegate = usageHintsAccessibilityDelegate;
this.usageHints = usageHints;
}

/**
* Label describing the action that will be performed on click
*
* @deprecated Create UsageHints explicitly and pass via the constructor.
*/
@Deprecated
public void setClickLabel(@StringRes int clickLabel) {
usageHintsAccessibilityDelegate.setClickLabel(clickLabel);
usageHints.setClickLabel(clickLabel);
}

/**
* Label describing the action that will be performed on click
*
* @deprecated Create UsageHints explicitly and pass via the constructor.
*/
@Deprecated
public void setClickLabel(CharSequence clickLabel) {
usageHintsAccessibilityDelegate.setClickLabel(clickLabel);
usageHints.setClickLabel(clickLabel);
}

/**
* Label describing the action that will be performed on long click
*
* @deprecated Create UsageHints explicitly and pass via the constructor.
*/
@Deprecated
public void setLongClickLabel(@StringRes int longClickLabel) {
usageHintsAccessibilityDelegate.setLongClickLabel(longClickLabel);
usageHints.setLongClickLabel(longClickLabel);
}

/**
* Label describing the action that will be performed on long click
*
* @deprecated Create UsageHints explicitly and pass via the constructor.
*/
@Deprecated
public void setLongClickLabel(CharSequence longClickLabel) {
usageHintsAccessibilityDelegate.setLongClickLabel(longClickLabel);
usageHints.setLongClickLabel(longClickLabel);
}

@Override
Expand All @@ -58,8 +70,7 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCo
String label = resources.getString(action.getLabel());
info.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(action.getId(), label));
}

usageHintsAccessibilityDelegate.onInitializeAccessibilityNodeInfo(host, info);
usageHints.addClickEventUsageHints(host, info);
}

@Override
Expand Down
Loading

0 comments on commit 91983e7

Please sign in to comment.