This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from novoda/develop
Merge 1.6.0 develop to master
- Loading branch information
Showing
11 changed files
with
701 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
267 changes: 267 additions & 0 deletions
267
core/src/main/java/com/novoda/accessibility/ActionMenuItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.