Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android)(8_1_X): set ListItem properties into proxy properties #10979

Merged
merged 4 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion android/modules/ui/res/layout/titanium_ui_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:layout_gravity="right"
android:contentDescription="One of the following images: checkmark, child, or disclosure"
android:focusable="false"
android:focusableInTouchMode="false"
android:maxHeight="17dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
}
ViewCompat.setImportantForAccessibility(listView, importance);
} else {
listView.setContentDescription(composeContentDescription());
listView.setContentDescription(getProxy().composeContentDescription());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can getProxy() return null?

}
}
}
Expand Down Expand Up @@ -335,9 +335,9 @@ public void onCancel(DialogInterface dlg)
// can also be used.
ListView listView = dialog.getListView();
if (listView != null) {
listView.setContentDescription(composeContentDescription());
int importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
if (proxy != null) {
listView.setContentDescription(proxy.composeContentDescription());
Object propertyValue = proxy.getProperty(TiC.PROPERTY_ACCESSIBILITY_HIDDEN);
if (propertyValue != null && TiConvert.toBoolean(propertyValue)) {
importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.HashMap;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiC;
Expand Down Expand Up @@ -665,8 +666,10 @@ public void populateViews(KrollDict data, TiBaseListViewItem cellContent, TiList
DataItem dataItem = template.getDataItem(binding);
ViewItem viewItem = views.get(binding);
TiUIView view = viewItem.getView();
KrollProxy viewProxy = null;
//update extra event data for views
if (view != null) {
viewProxy = view.getProxy();
appendExtraEventData(view, itemIndex, sectionIndex, binding, itemId);
}
//if binding is contain in data given to us, process that data, otherwise
Expand All @@ -675,12 +678,18 @@ public void populateViews(KrollDict data, TiBaseListViewItem cellContent, TiList
KrollDict properties = new KrollDict((HashMap) data.get(binding));
KrollDict diffProperties = viewItem.generateDiffProperties(properties);
if (!diffProperties.isEmpty()) {
if (viewProxy != null && viewProxy.getProperties() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract temp var to assign viewProxy.getProperties() value to?

viewProxy.getProperties().putAll(diffProperties);
}
view.processProperties(diffProperties);
}

} else if (dataItem != null && view != null) {
KrollDict diffProperties = viewItem.generateDiffProperties(dataItem.getDefaultProperties());
if (!diffProperties.isEmpty()) {
if (viewProxy != null && viewProxy.getProperties() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

viewProxy.getProperties().putAll(diffProperties);
}
view.processProperties(diffProperties);
}
} else {
Expand Down
55 changes: 52 additions & 3 deletions android/titanium/src/java/org/appcelerator/kroll/KrollProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
*/
package org.appcelerator.kroll;

import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.AsyncResult;
import org.appcelerator.kroll.common.Log;
Expand All @@ -35,6 +32,7 @@
import android.os.Looper;
import android.os.Message;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Pair;

import org.json.JSONObject;
Expand Down Expand Up @@ -978,6 +976,57 @@ public boolean doFireEvent(String event, Object data)
return krollObject.fireEvent(source, event, krollData, bubbles, reportSuccess, code, message);
}

/**
* Our view proxy supports three properties to match iOS regarding
* the text that is read aloud (or otherwise communicated) by the
* assistive technology: accessibilityLabel, accessibilityHint
* and accessibilityValue.
*
* We combine these to create the single Android property contentDescription.
* (e.g., View.setContentDescription(...));
*/
public String composeContentDescription()
{
if (properties == null) {
return null;
}

final String punctuationPattern = "^.*\\p{Punct}\\s*$";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract to a constant so it's compiled once?

StringBuilder buffer = new StringBuilder();
String label = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_LABEL));
String hint = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_HINT));
String value = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_VALUE));

if (!TextUtils.isEmpty(label)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three small blocks are identical, extract to a method? Only wrinkle is the extra space prefix/suffix added if previous value was not empty...

buffer.append(composeContentSegment(TiC.PROPERTY_ACCESSIBILITY_LABEL));
buffer.append(composeContentSegment(TiC.PROPERTY_ACCESSIBILITY_HINT));
buffer.append(composeContentSegment(TiC.PROPERTY_ACCESSIBILITY_VALUE));

buffer.append(label);
if (!label.matches(punctuationPattern)) {
buffer.append(".");
}
}

if (!TextUtils.isEmpty(value)) {
if (buffer.length() > 0) {
buffer.append(" ");
}
buffer.append(value);
if (!value.matches(punctuationPattern)) {
buffer.append(".");
}
}

if (!TextUtils.isEmpty(hint)) {
if (buffer.length() > 0) {
buffer.append(" ");
}
buffer.append(hint);
if (!hint.matches(punctuationPattern)) {
buffer.append(".");
}
}

return buffer.toString();
}

public void firePropertyChanged(String name, Object oldValue, Object newValue)
{
if (modelListener != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutParams;
import org.appcelerator.titanium.view.TiGradientDrawable.GradientType;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
Expand All @@ -50,7 +49,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.util.Pair;
import android.util.SparseArray;
import android.util.TypedValue;
Expand Down Expand Up @@ -2149,68 +2147,12 @@ private void applyContentDescription()
if (proxy == null || nativeView == null) {
return;
}
String contentDescription = composeContentDescription();
String contentDescription = getProxy().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
* assistive technology: accessibilityLabel, accessibilityHint
* and accessibilityValue.
*
* We combine these to create the single Android property contentDescription.
* (e.g., View.setContentDescription(...));
*/
protected String composeContentDescription()
{
if (proxy == null) {
return null;
}

KrollDict properties = proxy.getProperties();
if (properties == null) {
return null;
}

final String punctuationPattern = "^.*\\p{Punct}\\s*$";
StringBuilder buffer = new StringBuilder();
String label = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_LABEL));
String hint = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_HINT));
String value = TiConvert.toString(properties.get(TiC.PROPERTY_ACCESSIBILITY_VALUE));

if (!TextUtils.isEmpty(label)) {
buffer.append(label);
if (!label.matches(punctuationPattern)) {
buffer.append(".");
}
}

if (!TextUtils.isEmpty(value)) {
if (buffer.length() > 0) {
buffer.append(" ");
}
buffer.append(value);
if (!value.matches(punctuationPattern)) {
buffer.append(".");
}
}

if (!TextUtils.isEmpty(hint)) {
if (buffer.length() > 0) {
buffer.append(" ");
}
buffer.append(hint);
if (!hint.matches(punctuationPattern)) {
buffer.append(".");
}
}

return buffer.toString();
}

private void applyAccessibilityProperties()
{
if (nativeView != null) {
Expand Down