Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-28396
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaysingh-axway committed Mar 16, 2021
2 parents a4e0a51 + c01e72e commit 601ea70
Show file tree
Hide file tree
Showing 21 changed files with 318 additions and 1,274 deletions.
2 changes: 1 addition & 1 deletion android/cli/lib/android-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class AndroidManifest {
if (sourceElement.hasAttributes()) {
for (let index = 0; index < sourceElement.attributes.length; index++) {
const sourceAttribute = sourceElement.attributes.item(index);
destinationElement.setAttribute(sourceAttribute.name, sourceAttribute.value);
destinationElement.setAttributeNode(sourceAttribute.cloneNode());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,39 @@ public void setNativeView(View view)
}

@Override
public void add(TiUIView child)
{
// TODO: This could be improved to prevent the need for swapping native views.
// Our `nativeView` is currently set as our TableViewHolder view as a workaround
// for allowing events/properties to set on our holder instead of our row content.
// Temporarily swap our native view back to original content while new child is added.
final View nativeView = getNativeView();
if (nativeView != null) {
setNativeView(this.content);
super.add(child);
setNativeView(nativeView);
} else {
super.add(child);
}
}

@Override
public void remove(TiUIView child)
{
// TODO: This could be improved to prevent the need for swapping native views.
// Our `nativeView` is currently set as our TableViewHolder view as a workaround
// for allowing events/properties to set on our holder instead of our row content.
// Temporarily swap our native view back to original content while new child is removed.
final View nativeView = getNativeView();
if (nativeView != null) {
setNativeView(this.content);
super.remove(child);
setNativeView(nativeView);
} else {
super.remove(child);
}
}

protected boolean canApplyTouchFeedback(@NonNull KrollDict props)
{
// Prevent TiUIView from overriding `touchFeedback` effect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
import ti.modules.titanium.ui.AttributedStringProxy;
import ti.modules.titanium.ui.UIModule;

import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;

import com.google.android.material.button.MaterialButton;

public class TiUIButton extends TiUIView
Expand All @@ -38,6 +43,7 @@ public class TiUIButton extends TiUIView
private static final float DEFAULT_SHADOW_RADIUS = 1f;

private int defaultColor;
private ColorStateList defaultRippleColor;
private float shadowRadius = DEFAULT_SHADOW_RADIUS;
private float shadowX = 0f;
private float shadowY = 0f;
Expand All @@ -49,6 +55,7 @@ public TiUIButton(final TiViewProxy proxy)

Log.d(TAG, "Creating a button", Log.DEBUG_MODE);

// Fetch the material button style to use.
int styleId = UIModule.BUTTON_STYLE_FILLED;
styleId = TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_STYLE), styleId);
switch (styleId) {
Expand All @@ -73,24 +80,51 @@ public TiUIButton(final TiViewProxy proxy)
break;
}

MaterialButton btn = new MaterialButton(proxy.getActivity(), null, styleId) {
@Override
public boolean onFilterTouchEventForSecurity(MotionEvent event)
{
boolean isTouchAllowed = super.onFilterTouchEventForSecurity(event);
if (!isTouchAllowed) {
fireSyncEvent(TiC.EVENT_TOUCH_FILTERED, dictFromEvent(event));
}
return isTouchAllowed;
}
// Determine if a background drawable will be applied to the button.
boolean hasCustomBackground
= hasImage(proxy.getProperties())
|| hasColorState(proxy.getProperties())
|| hasBorder(proxy.getProperties())
|| hasGradient(proxy.getProperties());

// Create and set up the button.
// Note: MaterialButton does not support replacing its background drawable. Will log a nasty warning.
AppCompatButton btn;
if (hasCustomBackground) {
btn = new AppCompatButton(proxy.getActivity()) {
@Override
public boolean onFilterTouchEventForSecurity(MotionEvent event)
{
boolean isTouchAllowed = super.onFilterTouchEventForSecurity(event);
if (!isTouchAllowed) {
fireSyncEvent(TiC.EVENT_TOUCH_FILTERED, dictFromEvent(event));
}
return isTouchAllowed;
}
};
} else {
btn = new MaterialButton(proxy.getActivity(), null, styleId) {
@Override
public boolean onFilterTouchEventForSecurity(MotionEvent event)
{
boolean isTouchAllowed = super.onFilterTouchEventForSecurity(event);
if (!isTouchAllowed) {
fireSyncEvent(TiC.EVENT_TOUCH_FILTERED, dictFromEvent(event));
}
return isTouchAllowed;
}
};
this.defaultRippleColor = ((MaterialButton) btn).getRippleColor();
}
btn.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
public void onLayoutChange(
View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
TiUIHelper.firePostLayoutEvent(getProxy());
}
};
});
btn.setGravity(Gravity.CENTER);
defaultColor = btn.getCurrentTextColor();
btn.setEllipsize(TextUtils.TruncateAt.MIDDLE);
Expand All @@ -105,7 +139,7 @@ public void processProperties(KrollDict d)

boolean needShadow = false;

MaterialButton btn = (MaterialButton) getNativeView();
AppCompatButton btn = (AppCompatButton) getNativeView();
if (d.containsKey(TiC.PROPERTY_IMAGE)) {
Object value = d.get(TiC.PROPERTY_IMAGE);
TiDrawableReference drawableRef = null;
Expand All @@ -124,6 +158,18 @@ public void processProperties(KrollDict d)
// for the button, but if we set a background color, it will not look centered unless we reset the padding.
btn.setPadding(8, 0, 8, 0);
}
if ((btn instanceof MaterialButton) && d.containsKey(TiC.PROPERTY_TOUCH_FEEDBACK)) {
// We only override MaterialButton's native ripple effect if "touchFeedback" property is defined.
ColorStateList colorStateList = null;
if (TiConvert.toBoolean(d, TiC.PROPERTY_TOUCH_FEEDBACK, false)) {
if (d.containsKeyAndNotNull(TiC.PROPERTY_TOUCH_FEEDBACK_COLOR)) {
colorStateList = ColorStateList.valueOf(TiConvert.toColor(d, TiC.PROPERTY_TOUCH_FEEDBACK_COLOR));
} else {
colorStateList = this.defaultRippleColor;
}
}
((MaterialButton) btn).setRippleColor(colorStateList);
}
if (d.containsKey(TiC.PROPERTY_TITLE)) {
btn.setText(d.getString(TiC.PROPERTY_TITLE));
}
Expand Down Expand Up @@ -189,7 +235,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
if (Log.isDebugModeEnabled()) {
Log.d(TAG, "Property: " + key + " old: " + oldValue + " new: " + newValue, Log.DEBUG_MODE);
}
MaterialButton btn = (MaterialButton) getNativeView();

AppCompatButton btn = (AppCompatButton) getNativeView();
if (key.equals(TiC.PROPERTY_TITLE)) {
btn.setText((String) newValue);
} else if (key.equals(TiC.PROPERTY_ATTRIBUTED_STRING) && newValue instanceof AttributedStringProxy) {
Expand All @@ -215,6 +262,21 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
Drawable image = drawableRef.getDrawable();
btn.setCompoundDrawablesWithIntrinsicBounds(image, null, null, null);
}
} else if ((btn instanceof MaterialButton)
&& (key.equals(TiC.PROPERTY_TOUCH_FEEDBACK) || key.equals(TiC.PROPERTY_TOUCH_FEEDBACK_COLOR))) {
// Only override MaterialButton's native ripple effect if "touchFeedback" property is defined.
if (proxy.hasProperty(TiC.PROPERTY_TOUCH_FEEDBACK)) {
ColorStateList colorStateList = null;
if (TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_TOUCH_FEEDBACK), false)) {
if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_TOUCH_FEEDBACK_COLOR)) {
String colorString = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_TOUCH_FEEDBACK_COLOR));
colorStateList = ColorStateList.valueOf(TiConvert.toColor(colorString));
} else {
colorStateList = this.defaultRippleColor;
}
}
((MaterialButton) btn).setRippleColor(colorStateList);
}
} else if (key.equals(TiC.PROPERTY_SHADOW_OFFSET)) {
if (newValue instanceof HashMap) {
HashMap dict = (HashMap) newValue;
Expand All @@ -239,6 +301,16 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
}
}

@Override
protected boolean canApplyTouchFeedback(@NonNull KrollDict props)
{
// If we're using MaterialButton, then we must use its setRippleColor() method instead.
if (getNativeView() instanceof MaterialButton) {
return false;
}
return super.canApplyTouchFeedback(props);
}

private void setAttributedStringText(AttributedStringProxy attrString)
{
MaterialButton btn = (MaterialButton) getNativeView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.appcelerator.titanium.view.TiUIView;
import ti.modules.titanium.ui.android.AndroidModule;
import ti.modules.titanium.ui.widget.tabgroup.TiUIAbstractTabGroup;
import ti.modules.titanium.ui.widget.tabgroup.TiUITabLayoutTabGroup;

public class TiUITabbedBar extends TiUIView implements MenuItem.OnMenuItemClickListener, TabLayout.OnTabSelectedListener
{
Expand Down Expand Up @@ -224,6 +225,7 @@ private void addItem(Object value)
if (value != null) {
if (value instanceof Drawable) {
tab.setIcon(((Drawable) value));
TiUITabLayoutTabGroup.scaleIconToFit(tab);
} else {
tab.setText(value.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public KrollDict generateScrollPayload()
final int firstVisibleSectionIndex = proxy.getIndexOfSection(firstVisibleSection);
payload.put(TiC.PROPERTY_FIRST_VISIBLE_SECTION_INDEX, firstVisibleSectionIndex);
} else {

// Could not obtain section, mark as undefined.
payload.put(TiC.PROPERTY_FIRST_VISIBLE_SECTION, null);
payload.put(TiC.PROPERTY_FIRST_VISIBLE_SECTION_INDEX, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiFileHelper;
import org.appcelerator.titanium.util.TiUIHelper;

import java.lang.ref.WeakReference;
Expand All @@ -45,7 +44,6 @@ public abstract class TiRecyclerViewHolder extends RecyclerView.ViewHolder
protected static Drawable moreDrawable;

protected static Resources resources;
protected static TiFileHelper fileHelper;

protected WeakReference<TiViewProxy> proxy;

Expand Down Expand Up @@ -102,11 +100,6 @@ public TiRecyclerViewHolder(final Context context, final ViewGroup viewGroup)
} else {
Log.w(TAG, "Could not obtain context resources instance.");
}
if (fileHelper == null) {

// Obtain file helper instance.
fileHelper = new TiFileHelper(context);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

Expand Down Expand Up @@ -326,8 +327,9 @@ public void updateTabIcon(int index)
return;
}

Drawable drawable = TiUIHelper.getResourceDrawable(tabProxy.getProperty(TiC.PROPERTY_ICON));
this.mTabLayout.getTabAt(index).setIcon(drawable);
TabLayout.Tab tab = this.mTabLayout.getTabAt(index);
tab.setIcon(TiUIHelper.getResourceDrawable(tabProxy.getProperty(TiC.PROPERTY_ICON)));
scaleIconToFit(tab);
}

@Override
Expand Down Expand Up @@ -409,4 +411,19 @@ public void selectTab(int tabIndex)
updateIconTint();
updateTabBackgroundDrawable(tabIndex);
}

public static void scaleIconToFit(TabLayout.Tab tab)
{
if ((tab == null) || (tab.view == null)) {
return;
}

for (int childIndex = 0; childIndex < tab.view.getChildCount(); childIndex++) {
View childView = tab.view.getChildAt(childIndex);
if (childView instanceof ImageView) {
((ImageView) childView).setScaleType(ImageView.ScaleType.FIT_CENTER);
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,23 @@ public void bind(final TableViewRowProxy proxy, final boolean selected)
return;
}

// Set maximum row height.
final String rawMaxHeight = properties.optString(TiC.PROPERTY_MAX_ROW_HEIGHT,
tableViewProperties.getString(TiC.PROPERTY_MAX_ROW_HEIGHT));
final TiDimension maxHeightDimension = TiConvert.toTiDimension(rawMaxHeight, TiDimension.TYPE_HEIGHT);
final int maxHeight = rawMaxHeight != null ? maxHeightDimension.getAsPixels(itemView) : -1;
if (maxHeight > -1) {
nativeRowView.measure(0, 0);

// Enforce max row height.
if (nativeRowView.getMeasuredHeight() > maxHeight) {
rowView.getLayoutParams().optionHeight = maxHeightDimension;
}
}

// Set minimum row height.
final String rawMinHeight = properties.optString(TiC.PROPERTY_MIN_ROW_HEIGHT, "0");
final String rawMinHeight = properties.optString(TiC.PROPERTY_MIN_ROW_HEIGHT,
tableViewProperties.getString(TiC.PROPERTY_MIN_ROW_HEIGHT));
final int minHeight = TiConvert.toTiDimension(rawMinHeight, TiDimension.TYPE_HEIGHT).getAsPixels(itemView);
this.container.setMinimumHeight(minHeight);

Expand Down Expand Up @@ -209,15 +224,19 @@ public void bind(final TableViewRowProxy proxy, final boolean selected)
// Handle row left and right images.
if (properties.containsKeyAndNotNull(TiC.PROPERTY_LEFT_IMAGE)) {
final String url = properties.getString(TiC.PROPERTY_LEFT_IMAGE);
final Drawable drawable = fileHelper.loadDrawable(url, false);
this.leftImage.setImageDrawable(drawable);
this.leftImage.setVisibility(View.VISIBLE);
final Drawable drawable = TiUIHelper.getResourceDrawable((Object) url);
if (drawable != null) {
this.leftImage.setImageDrawable(drawable);
this.leftImage.setVisibility(View.VISIBLE);
}
}
if (properties.containsKeyAndNotNull(TiC.PROPERTY_RIGHT_IMAGE)) {
final String url = properties.getString(TiC.PROPERTY_RIGHT_IMAGE);
final Drawable drawable = fileHelper.loadDrawable(url, false);
this.rightImage.setImageDrawable(drawable);
this.rightImage.setVisibility(View.VISIBLE);
final Drawable drawable = TiUIHelper.getResourceDrawable((Object) url);
if (drawable != null) {
this.rightImage.setImageDrawable(drawable);
this.rightImage.setVisibility(View.VISIBLE);
}
} else {
final boolean hasCheck = properties.optBoolean(TiC.PROPERTY_HAS_CHECK, false);
final boolean hasChild = properties.optBoolean(TiC.PROPERTY_HAS_CHILD, false);
Expand Down Expand Up @@ -314,7 +333,6 @@ public void bind(final TableViewRowProxy proxy, final boolean selected)
// Add row to content.
this.content.addView(nativeRowView, rowView.getLayoutParams());
this.content.setVisibility(View.VISIBLE);

}
if (properties.containsKeyAndNotNull(TiC.PROPERTY_TITLE)
&& proxy.getChildren().length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ public void update()
final boolean filterAnchored = properties.optBoolean(TiC.PROPERTY_FILTER_ANCHORED, false);
final String filterAttribute = properties.optString(TiC.PROPERTY_FILTER_ATTRIBUTE, TiC.PROPERTY_TITLE);
int filterResultsCount = 0;
int index = 0;
int filteredIndex = 0;

String query = this.filterQuery;
if (query != null && caseInsensitive) {
Expand Down Expand Up @@ -468,8 +470,6 @@ public void update()
this.rows.add(row);
}

int index = 0;
int filteredIndex = 0;
for (int i = 0; i < rows.length; i++) {
final TableViewRowProxy row = rows[i];

Expand Down

0 comments on commit 601ea70

Please sign in to comment.