Skip to content

Commit

Permalink
Merge pull request #3287 from billdawson/timob-11411
Browse files Browse the repository at this point in the history
TIMOB-11411 Android: Apply accessibility properties to the OptionDialog's underlying Android ...
  • Loading branch information
pingwang2011 committed Oct 25, 2012
2 parents 0a6a80f + dc6ecc1 commit 71c9858
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.support.v4.view.ViewCompat;
import android.widget.ListView;

public class TiUIDialog extends TiUIView
{
Expand Down Expand Up @@ -221,10 +223,25 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
if (newValue != null) {
processView((TiViewProxy) newValue);
} else {
proxy.setProperty(TiC.PROPERTY_ANDROID_VIEW, null, false);
proxy.setProperty(TiC.PROPERTY_ANDROID_VIEW, null);
}
} else if (key.equals(TiC.PROPERTY_PERSISTENT) && newValue != null) {
dialogWrapper.setPersistent(TiConvert.toBoolean(newValue));
} else if (key.indexOf("accessibility") == 0) {
if (dialog != null) {
ListView listView = dialog.getListView();
if (listView != null) {
if (key.equals(TiC.PROPERTY_ACCESSIBILITY_HIDDEN)) {
int importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
if (newValue != null && TiConvert.toBoolean(newValue)) {
importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
}
ViewCompat.setImportantForAccessibility(listView, importance);
} else {
listView.setContentDescription(composeContentDescription());
}
}
}
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand All @@ -245,9 +262,27 @@ public void onCancel(DialogInterface dlg) {
}
});
dialog = getBuilder().create();

// Initially apply accessibility properties here, the first time
// the dialog actually becomes available. After this, propertyChanged
// can also be used.
ListView listView = dialog.getListView();
if (listView != null) {
listView.setContentDescription(composeContentDescription());
int importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
if (proxy != null) {
Object propertyValue = proxy.getProperty(TiC.PROPERTY_ACCESSIBILITY_HIDDEN);
if (propertyValue != null && TiConvert.toBoolean(propertyValue)) {
importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
}
}
ViewCompat.setImportantForAccessibility(listView, importance);
}

dialogWrapper.setDialog(dialog);
builder = null;
}

try {
Activity dialogActivity = dialogWrapper.getActivity();
if (dialogActivity != null && !dialogActivity.isFinishing()) {
Expand Down Expand Up @@ -285,7 +320,7 @@ private void createBuilder()
if (currentActivity != null) {
this.builder = new AlertDialog.Builder(currentActivity);
this.builder.setCancelable(true);

//Native dialogs are persistent by default.
TiBaseActivity dialogActivity = (TiBaseActivity)currentActivity;
dialogWrapper = dialogActivity.new DialogWrapper(null, true, new WeakReference<TiBaseActivity>(dialogActivity));
Expand All @@ -306,7 +341,7 @@ public void handleEvent(int id)
data.put(TiC.PROPERTY_BUTTON, false);
// If an option was selected and the user accepted it, update the proxy.
if (proxy.hasProperty(TiC.PROPERTY_OPTIONS)) {
proxy.setProperty(TiC.PROPERTY_SELECTED_INDEX, id, false);
proxy.setProperty(TiC.PROPERTY_SELECTED_INDEX, id);
}
}
data.put(TiC.EVENT_PROPERTY_INDEX, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.util.Pair;
import android.util.SparseArray;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.KeyEvent;
Expand Down Expand Up @@ -459,7 +460,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
layoutNativeView();
} else if (key.equals(TiC.PROPERTY_SIZE)) {
if (newValue instanceof HashMap) {
HashMap<String, Object> d = (HashMap) newValue;
@SuppressWarnings("unchecked")
HashMap<String, Object> d = (HashMap<String, Object>) newValue;
propertyChanged(TiC.PROPERTY_WIDTH, oldValue, d.get(TiC.PROPERTY_WIDTH), proxy);
propertyChanged(TiC.PROPERTY_HEIGHT, oldValue, d.get(TiC.PROPERTY_HEIGHT), proxy);
}else if (newValue != null){
Expand Down Expand Up @@ -624,7 +626,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
}

} else if (key.indexOf("accessibility") == 0 && !key.equals(TiC.PROPERTY_ACCESSIBILITY_HIDDEN)) {
composeContentDescription();
applyContentDescription();

} else if (key.equals(TiC.PROPERTY_ACCESSIBILITY_HIDDEN)) {
applyAccessibilityHidden(newValue);
Expand Down Expand Up @@ -984,7 +986,7 @@ private void handleBorderProperty(String property, Object value)
}
}

private static HashMap<Integer, String> motionEvents = new HashMap<Integer,String>();
private static SparseArray<String> motionEvents = new SparseArray<String>();
static
{
motionEvents.put(MotionEvent.ACTION_DOWN, TiC.EVENT_TOUCH_START);
Expand Down Expand Up @@ -1514,6 +1516,17 @@ private void resetPostAnimationValues()
animatedAlpha = Float.MIN_VALUE; // we use min val to signal no val.
}

private void applyContentDescription()
{
if (proxy == null || nativeView == null) {
return;
}
String contentDescription = composeContentDescription();
if (contentDescription != null) {
nativeView.setContentDescription(contentDescription);
}
}

/**
* Our view proxy supports three properties to match iOS regarding
* the text that is read aloud (or otherwise communicated) by the
Expand All @@ -1523,10 +1536,10 @@ private void resetPostAnimationValues()
* We combine these to create the single Android property contentDescription.
* (e.g., View.setContentDescription(...));
*/
private void composeContentDescription()
protected String composeContentDescription()
{
if (nativeView == null || proxy == null) {
return;
if (proxy == null) {
return null;
}

final String punctuationPattern = "^.*\\p{Punct}\\s*$";
Expand Down Expand Up @@ -1565,13 +1578,13 @@ private void composeContentDescription()
}
}

nativeView.setContentDescription(buffer.toString());
return buffer.toString();
}

private void applyAccessibilityProperties()
{
if (nativeView != null) {
composeContentDescription();
applyContentDescription();
applyAccessibilityHidden();
}

Expand Down

0 comments on commit 71c9858

Please sign in to comment.