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

[TIMOB-25284] Android: Fixed bug where images from "res" folder fail to load. (Introduced in 6.2.0.) #9434

Merged
merged 2 commits into from
Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void setBigLargeIcon(Object icon)
@Kroll.method @Kroll.setProperty
public void setBigPicture(Object picture)
{
TiDrawableReference source = TiDrawableReference.fromObject(this.getActivity(), picture);
TiDrawableReference source = TiDrawableReference.fromObject(this, picture);

// Check for decodeRetries
if (hasProperty(TiC.PROPERTY_DECODE_RETRIES)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void setLogo(Object object) {
*/
private void handleSetLogo(Object object) {
logo = object;
TiDrawableReference tiDrawableReference = TiDrawableReference.fromObject(proxy.getActivity(), object);
TiDrawableReference tiDrawableReference = TiDrawableReference.fromObject(proxy, object);
((Toolbar) getNativeView()).setLogo(tiDrawableReference.getDrawable());
}

Expand Down Expand Up @@ -264,7 +264,7 @@ public void setNavigationIcon(Object object) {
*/
private void handleSetNavigationIcon(Object object) {
navigationIcon = object;
TiDrawableReference tiDrawableReference = TiDrawableReference.fromObject(proxy.getActivity(), object);
TiDrawableReference tiDrawableReference = TiDrawableReference.fromObject(proxy, object);
((Toolbar) getNativeView()).setNavigationIcon(tiDrawableReference.getDrawable());
}

Expand Down Expand Up @@ -294,7 +294,7 @@ public void setOverflowMenuIcon(Object object) {
*/
private void handleSetOverflowMenuIcon(Object object) {
overflowMenuIcon = object;
TiDrawableReference tiDrawableReference = TiDrawableReference.fromObject(proxy.getActivity(), object);
TiDrawableReference tiDrawableReference = TiDrawableReference.fromObject(proxy, object);
((Toolbar) getNativeView()).setOverflowIcon(tiDrawableReference.getDrawable());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,10 @@ private void setImageSource(Object object)
imageSources = new ArrayList<TiDrawableReference>();
if (object instanceof Object[]) {
for (Object o : (Object[]) object) {
imageSources.add(TiDrawableReference.fromObject(getProxy().getActivity(), o));
imageSources.add(TiDrawableReference.fromObject(getProxy(), o));
}
} else {
imageSources.add(TiDrawableReference.fromObject(getProxy().getActivity(), object));
imageSources.add(TiDrawableReference.fromObject(getProxy(), object));
}
}

Expand All @@ -689,7 +689,7 @@ private void setDefaultImageSource(Object object)
} else if (object instanceof String) {
defaultImageSource = TiDrawableReference.fromUrl(proxy, (String) object);
} else {
defaultImageSource = TiDrawableReference.fromObject(proxy.getActivity(), object);
defaultImageSource = TiDrawableReference.fromObject(proxy, object);
}
}

Expand Down Expand Up @@ -809,7 +809,7 @@ public void processProperties(KrollDict d)
// processProperties is also called from TableView, we need check if we changed before re-creating the
// bitmap
boolean changeImage = true;
TiDrawableReference source = TiDrawableReference.fromObject(getProxy().getActivity(), d.get(TiC.PROPERTY_IMAGE));
TiDrawableReference source = TiDrawableReference.fromObject(getProxy(), d.get(TiC.PROPERTY_IMAGE));
if (imageSources != null && imageSources.size() == 1) {
if (imageSources.get(0).equals(source)) {
changeImage = false;
Expand Down Expand Up @@ -861,7 +861,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
view.setEnableZoomControls(TiConvert.toBoolean(newValue));
} else if (key.equals(TiC.PROPERTY_IMAGE)) {
if ((oldValue == null && newValue != null) || (oldValue != null && !oldValue.equals(newValue))) {
TiDrawableReference source = TiDrawableReference.fromObject(getProxy().getActivity(), newValue);
TiDrawableReference source = TiDrawableReference.fromObject(getProxy(), newValue);
Object autoRotate = proxy.getProperty(TiC.PROPERTY_AUTOROTATE);
if (autoRotate != null && TiConvert.toBoolean(autoRotate)) {
view.setOrientation(source.getOrientation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,35 @@ public static TiDrawableReference fromDictionary(Activity activity, HashMap dict
return fromObject(activity, null);
}
}

/**
* Does its best to determine the type of reference (url, blob, etc) based on object parameter.
* <p>
* Uses the given proxy to resolve relative paths to an image file, if applicable.
* @param proxy Used to acquire an activty and resolve relative paths if given object is a string path.
* @param object Reference to the image to be loaded such as a file, path, blob, etc.
* @return Returns an instance of TiDrawableReference wrapping the given object.
* @module.api
*/
public static TiDrawableReference fromObject(KrollProxy proxy, Object object)
{
// Attempt to fetch an activity from the given proxy.
Activity activity = null;
if (proxy != null) {
activity = proxy.getActivity();
}

// If given object is a string:
// - Resolve its relative path, if applicable.
// - Convert the string to a URL.
if ((proxy != null) && (object instanceof String)) {
object = proxy.resolveUrl(null, (String)object);
}

// Create a drawable reference from the given object.
return TiDrawableReference.fromObject(activity, object);
}

/**
* Does its best to determine the type of reference (url, blob, etc) based on object parameter.
* @param activity the referenced activity.
Expand Down