Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-26599
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjsamir authored May 9, 2019
2 parents 1551e11 + 20a3a74 commit 97e365e
Show file tree
Hide file tree
Showing 10 changed files with 546 additions and 143 deletions.
13 changes: 6 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,20 @@ def unitTests(os, nodeVersion, npmVersion, testSuiteBranch) {
archiveArtifacts 'mocha_*.crash'
sh 'rm -f mocha_*.crash'
} else {
// gather crash reports/tombstones for Android
sh 'adb -e pull /data/tombstones'
sh label: 'gather crash reports/tombstones for Android', returnStatus: true, script: 'adb -e pull /data/tombstones'
archiveArtifacts 'tombstones/'
sh 'rm -f tombstones/'
// wipe tombstones and re-build dir with proper permissions/ownership on emulator
sh 'adb -e shell rm -rf /data/tombstones'
sh 'adb -e shell mkdir -m 771 /data/tombstones'
sh 'adb -e shell chown system:system /data/tombstones'
sh returnStatus: true, script: 'adb -e shell rm -rf /data/tombstones'
sh returnStatus: true, script: 'adb -e shell mkdir -m 771 /data/tombstones'
sh returnStatus: true, script: 'adb -e shell chown system:system /data/tombstones'
}
throw e
} finally {
// Kill the emulators!
if ('android'.equals(os)) {
sh 'adb -e shell am force-stop com.appcelerator.testApp.testing'
sh 'adb -e uninstall com.appcelerator.testApp.testing'
sh returnStatus: true, script: 'adb -e shell am force-stop com.appcelerator.testApp.testing'
sh returnStatus: true, script: 'adb -e uninstall com.appcelerator.testApp.testing'
killAndroidEmulators()
} // if
} // finally
Expand Down
Binary file modified android/titanium/lib/aps-analytics.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,9 @@ public class TiC
*/
public static final String PROPERTY_BACKGROUND_PREFIX = "background";

/**
* @module.api
*/
public static final String PROPERTY_BACKGROUND_REPEAT = "backgroundRepeat";

/**
Expand Down Expand Up @@ -2721,6 +2724,9 @@ public class TiC
*/
public static final String PROPERTY_RETURN_KEY_TYPE = "returnKeyType";

/**
* @module.api
*/
public static final String PROPERTY_REVERSE = "reverse";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import java.lang.ref.WeakReference;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
Expand Down Expand Up @@ -42,9 +40,6 @@
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
Expand All @@ -57,44 +52,50 @@
// clang-format off
@Kroll.proxy(propertyAccessors = {
// background properties
"backgroundImage",
"backgroundRepeat",
"backgroundSelectedImage",
"backgroundFocusedImage",
"backgroundDisabledImage",
"backgroundColor",
"backgroundSelectedColor",
"backgroundFocusedColor",
"backgroundDisabledColor",
"backgroundPadding",
"backgroundGradient",
TiC.PROPERTY_BACKGROUND_IMAGE,
TiC.PROPERTY_BACKGROUND_REPEAT,
TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE,
TiC.PROPERTY_BACKGROUND_FOCUSED_IMAGE,
TiC.PROPERTY_BACKGROUND_DISABLED_IMAGE,
TiC.PROPERTY_BACKGROUND_COLOR,
TiC.PROPERTY_BACKGROUND_SELECTED_COLOR,
TiC.PROPERTY_BACKGROUND_FOCUSED_COLOR,
TiC.PROPERTY_BACKGROUND_DISABLED_COLOR,
TiC.PROPERTY_BACKGROUND_PADDING,
TiC.PROPERTY_BACKGROUND_GRADIENT,
// border properties
"borderColor", "borderRadius", "borderWidth",
TiC.PROPERTY_BORDER_COLOR,
TiC.PROPERTY_BORDER_RADIUS,
TiC.PROPERTY_BORDER_WIDTH,
// layout / dimension (size/width/height have custom accessors)
"left", "top", "right", "bottom", "layout", "zIndex",
TiC.PROPERTY_LEFT,
TiC.PROPERTY_TOP,
TiC.PROPERTY_RIGHT,
TiC.PROPERTY_BOTTOM,
TiC.PROPERTY_LAYOUT,
TiC.PROPERTY_ZINDEX,
// accessibility
TiC.PROPERTY_ACCESSIBILITY_HINT,
TiC.PROPERTY_ACCESSIBILITY_LABEL,
TiC.PROPERTY_ACCESSIBILITY_VALUE,
TiC.PROPERTY_ACCESSIBILITY_HIDDEN,
// others
"focusable",
"touchEnabled",
"visible",
"enabled",
"opacity",
"softKeyboardOnFocus",
"transform",
"elevation",
"touchTestId",
"translationX",
"translationY",
"translationZ",
"rotation",
"rotationX",
"rotationY",
"scaleX",
"scaleY",
TiC.PROPERTY_FOCUSABLE,
TiC.PROPERTY_TOUCH_ENABLED,
TiC.PROPERTY_VISIBLE,
TiC.PROPERTY_ENABLED,
TiC.PROPERTY_OPACITY,
TiC.PROPERTY_SOFT_KEYBOARD_ON_FOCUS,
TiC.PROPERTY_TRANSFORM,
TiC.PROPERTY_ELEVATION,
TiC.PROPERTY_TRANSLATION_X,
TiC.PROPERTY_TRANSLATION_Y,
TiC.PROPERTY_TRANSLATION_Z,
TiC.PROPERTY_ROTATION,
TiC.PROPERTY_ROTATION_X,
TiC.PROPERTY_ROTATION_Y,
TiC.PROPERTY_SCALE_X,
TiC.PROPERTY_SCALE_Y,
TiC.PROPERTY_TOUCH_FEEDBACK,
TiC.PROPERTY_TOUCH_FEEDBACK_COLOR,
TiC.PROPERTY_TRANSITION_NAME,
Expand Down Expand Up @@ -1019,66 +1020,91 @@ public TiViewProxy getParent()
if (this.parent == null) {
return null;
}

return this.parent.get();
}

// clang-format off
@Kroll.method
@Kroll.getProperty
public String getBackgroundDisabledColor()
// clang-format on
public String getBackgroundColor()
// clang - format on
{
// Return property if available.
if (getProperties().containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_COLOR)) {
return getProperties().getString(TiC.PROPERTY_BACKGROUND_COLOR);
}
// Try to get the background drawable if one is available.
TiBackgroundDrawable backgroundDrawable = getOrCreateView().getBackground();
// If only backgroundColor is defined then no ColorStateList is created, we resort to only the color defined.
if (backgroundDrawable == null) {
View view = getOrCreateView().getNativeView();
if (view != null) {
if (view.getBackground() instanceof ColorDrawable) {
return TiUIHelper.hexStringFrom(((ColorDrawable) view.getBackground()).getColor());
}
}
return null;
}
// It shouldn't matter if we request the color for DEFAULT_STATE_1 or DEFAULT_STATE_2. They are the same.
return TiUIHelper.getBackgroundColorForState(backgroundDrawable, TiUIHelper.BACKGROUND_DEFAULT_STATE_1);
}

// clang-format off
@Kroll.method
@Kroll.getProperty
public String getBackgroundSelectedColor()
// clang - format on
{
// Return property if available.
if (getProperties().containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR)) {
return getProperties().getString(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR);
}
TiUIView view = getOrCreateView();
if (view == null) {
return null;
}
// Try to get the background drawable if one is available.
TiBackgroundDrawable backgroundDrawable = view.getBackground();
// Guard for views without color state backgrounds.
if (backgroundDrawable == null) {
return null;
} else {
try {
// Get the backgroundDrawable background as a StateListDrawable.
StateListDrawable stateListDrawable = ((StateListDrawable) backgroundDrawable.getBackground());
// Get the reflection methods.
Method getStateDrawableIndexMethod =
StateListDrawable.class.getMethod("getStateDrawableIndex", int[].class);
Method getStateDrawableMethod = StateListDrawable.class.getMethod("getStateDrawable", int.class);
// Get the disabled state's (as defined in TiUIHelper) index.
int index =
(int) getStateDrawableIndexMethod.invoke(stateListDrawable, TiUIHelper.BACKGROUND_DISABLED_STATE);
// Get the drawable at the index.
Drawable drawable = (Drawable) getStateDrawableMethod.invoke(stateListDrawable, index);
// Try to get the 0 index of the result.
if (drawable instanceof LayerDrawable) {
Drawable drawableFromLayer = ((LayerDrawable) drawable).getDrawable(0);
// Cast it as a ColorDrawable.
if (drawableFromLayer instanceof ColorDrawable) {
// Transcript the color int to HexString.
String strColor =
String.format("#%08X", 0xFFFFFFFF & ((ColorDrawable) drawableFromLayer).getColor());
return strColor;
} else {
Log.w(TAG, "Background drawable of unexpected type. Expected - ColorDrawable. Found - "
+ drawableFromLayer.getClass().toString());
return null;
}
} else {
Log.w(TAG, "Background drawable of unexpected type. Expected - LayerDrawable. Found - "
+ drawable.getClass().toString());
return null;
}
} catch (NoSuchMethodException e) {
Log.w(TAG, "Unable to get a method for reflection.");
} catch (IllegalAccessException e) {
Log.w(TAG, "Unable to access a method for reflection.");
} catch (InvocationTargetException e) {
Log.w(TAG, "Unable to invoke a method for reflection.");
}
}
return TiUIHelper.getBackgroundColorForState(backgroundDrawable, TiUIHelper.BACKGROUND_SELECTED_STATE);
}

// clang-format off
@Kroll.method
@Kroll.getProperty
public String getBackgroundFocusedColor()
// clang - format on
{
// Return property if available.
if (getProperties().containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_FOCUSED_COLOR)) {
return getProperties().getString(TiC.PROPERTY_BACKGROUND_FOCUSED_COLOR);
}
// Try to get the background drawable if one is available.
TiBackgroundDrawable backgroundDrawable = getOrCreateView().getBackground();
if (backgroundDrawable == null) {
return null;
}
return TiUIHelper.getBackgroundColorForState(backgroundDrawable, TiUIHelper.BACKGROUND_FOCUSED_STATE);
}

// clang-format off
@Kroll.method
@Kroll.getProperty
public String getBackgroundDisabledColor()
// clang - format on
{
// Return property if available.
if (getProperties().containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_DISABLED_COLOR)) {
return getProperties().getString(TiC.PROPERTY_BACKGROUND_DISABLED_COLOR);
}
// Try to get the background drawable if one is available.
TiBackgroundDrawable backgroundDrawable = getOrCreateView().getBackground();
if (backgroundDrawable == null) {
return null;
}
return TiUIHelper.getBackgroundColorForState(backgroundDrawable, TiUIHelper.BACKGROUND_DISABLED_STATE);
}

public void setParent(TiViewProxy parent)
Expand Down Expand Up @@ -1118,8 +1144,9 @@ public void setActivity(Activity activity)
public TiViewProxy[] getChildren()
// clang-format on
{
if (children == null)
if (children == null) {
return new TiViewProxy[0];
}
return children.toArray(new TiViewProxy[children.size()]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.appcelerator.titanium.view.TiUIView;

import android.app.Activity;
import android.graphics.drawable.PaintDrawable;
import android.support.v7.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
Expand Down Expand Up @@ -642,15 +643,15 @@ public static Drawable buildBackgroundDrawable(String color, Drawable imageDrawa
return new LayerDrawable(layers.toArray(new Drawable[layers.size()]));
}

private static final int[] BACKGROUND_DEFAULT_STATE_1 = { android.R.attr.state_window_focused,
android.R.attr.state_enabled };
private static final int[] BACKGROUND_DEFAULT_STATE_2 = { android.R.attr.state_enabled };
private static final int[] BACKGROUND_SELECTED_STATE = { android.R.attr.state_window_focused,
android.R.attr.state_enabled,
android.R.attr.state_pressed };
private static final int[] BACKGROUND_FOCUSED_STATE = { android.R.attr.state_focused,
android.R.attr.state_window_focused,
android.R.attr.state_enabled };
public static final int[] BACKGROUND_DEFAULT_STATE_1 = { android.R.attr.state_window_focused,
android.R.attr.state_enabled };
public static final int[] BACKGROUND_DEFAULT_STATE_2 = { android.R.attr.state_enabled };
public static final int[] BACKGROUND_SELECTED_STATE = { android.R.attr.state_window_focused,
android.R.attr.state_enabled,
android.R.attr.state_pressed };
public static final int[] BACKGROUND_FOCUSED_STATE = { android.R.attr.state_focused,
android.R.attr.state_window_focused,
android.R.attr.state_enabled };
public static final int[] BACKGROUND_DISABLED_STATE = { -android.R.attr.state_enabled };

public static StateListDrawable buildBackgroundDrawable(String image, boolean tileImage, String color,
Expand Down Expand Up @@ -1221,4 +1222,61 @@ public static Uri getRedirectUri(Uri mUri) throws MalformedURLException, IOExcep
}
return mUri;
}

/**
* Helper method for getting the actual color values for Views with defined custom backgrounds
* that take advantage of color state lists.
*/
public static String getBackgroundColorForState(TiBackgroundDrawable backgroundDrawable, int[] state)
{
try {
// TiBackgroundDrawable's background can be either PaintDrawable or StateListDrawable.
// Handle the cases separately.
Drawable simpleDrawable = backgroundDrawable.getBackground();
if (simpleDrawable instanceof PaintDrawable) {
// For backwards compatibility return null if the required state is not the default one.
if (state != TiUIHelper.BACKGROUND_DEFAULT_STATE_1) {
return null;
}
return hexStringFrom(((PaintDrawable) simpleDrawable).getPaint().getColor());
} else if (simpleDrawable instanceof StateListDrawable) {
// Get the backgroundDrawable background as a StateListDrawable.
StateListDrawable stateListDrawable = (StateListDrawable) simpleDrawable;
// Get the reflection methods.
Method getStateDrawableIndexMethod =
StateListDrawable.class.getMethod("getStateDrawableIndex", int[].class);
Method getStateDrawableMethod = StateListDrawable.class.getMethod("getStateDrawable", int.class);
// Get the disabled state's (as defined in TiUIHelper) index.
int index = (int) getStateDrawableIndexMethod.invoke(stateListDrawable, state);
// Get the drawable at the index.
Drawable drawable = (Drawable) getStateDrawableMethod.invoke(stateListDrawable, index);
// Try to get the 0 index of the result.
if (drawable instanceof LayerDrawable) {
Drawable drawableFromLayer = ((LayerDrawable) drawable).getDrawable(0);
// Cast it as a ColorDrawable.
if (drawableFromLayer instanceof ColorDrawable) {
// Transcript the color int to HexString.
String strColor = hexStringFrom(((ColorDrawable) drawableFromLayer).getColor());
return strColor;
} else {
Log.w(TAG, "Background drawable of unexpected type. Expected - ColorDrawable. Found - "
+ drawableFromLayer.getClass().toString());
return null;
}
} else {
Log.w(TAG, "Background drawable of unexpected type. Expected - LayerDrawable. Found - "
+ drawable.getClass().toString());
return null;
}
}
} catch (Exception e) {
Log.w(TAG, e.toString());
}
return null;
}

public static String hexStringFrom(int colorInt)
{
return String.format("#%08X", 0xFFFFFFFF & colorInt);
}
}
Loading

0 comments on commit 97e365e

Please sign in to comment.