-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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-10080: Android: Parity for Ti.Blob methods #2833
Changes from 2 commits
44d71ff
83332da
e58b09f
1604510
8a3b5e4
243a9fa
82bb820
f0de1f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -936,6 +936,25 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP | |
} else { | ||
super.propertyChanged(key, oldValue, newValue, proxy); | ||
} | ||
|
||
View parentView = getParentView(); | ||
if (key.equals(TiC.PROPERTY_WIDTH)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what we talked about, it looks like you want to do this in a separate 'if' block because you are relying on logic from the super class that deals with height/width. If that is the case, can we move this whole block into the 'else' statement above to make this more clear. Also a comment on why you are doing this would be nice. |
||
if (TiC.LAYOUT_FILL.equals(TiConvert.toString(newValue)) && parentView != null) { | ||
// Use the parent's width when it's fill | ||
requestedWidth = TiConvert.toTiDimension(parentView.getMeasuredWidth(), TiDimension.TYPE_WIDTH); | ||
} else { | ||
requestedWidth = TiConvert.toTiDimension(newValue, TiDimension.TYPE_WIDTH); | ||
} | ||
setImage(true); | ||
} else if (key.equals(TiC.PROPERTY_HEIGHT)) { | ||
// Use the parent's height when it's fill | ||
if (TiC.LAYOUT_FILL.equals(TiConvert.toString(newValue)) && parentView != null) { | ||
requestedHeight = TiConvert.toTiDimension(parentView.getMeasuredHeight(), TiDimension.TYPE_HEIGHT); | ||
} else { | ||
requestedHeight = TiConvert.toTiDimension(newValue, TiDimension.TYPE_HEIGHT); | ||
} | ||
setImage(true); | ||
} | ||
} | ||
|
||
public void onDestroy(Activity activity) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
package org.appcelerator.titanium.util; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.appcelerator.kroll.common.Log; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.graphics.Path; | ||
import android.graphics.Path.Direction; | ||
import android.graphics.RectF; | ||
|
||
/** | ||
* Utility class for image manipulations. | ||
*/ | ||
public class TiImageHelper | ||
{ | ||
private static final String TAG = "TiImageHelper"; | ||
|
||
/** | ||
* Add an alpha channel to the given image if it does not already have one. | ||
* | ||
* @param image | ||
* the image to add an alpha channel to. | ||
* @return a copy of the given image with an alpha channel. If the image already have the alpha channel, return the | ||
* image itself. | ||
*/ | ||
public static Bitmap imageWithAlpha(Bitmap image) | ||
{ | ||
if (image == null) { | ||
return null; | ||
} | ||
if (image.hasAlpha()) { | ||
return image; | ||
} | ||
return image.copy(Bitmap.Config.ARGB_8888, true); | ||
} | ||
|
||
/** | ||
* Create a copy of the given image with rounded corners and a transparent border around its edges. | ||
* | ||
* @param image | ||
* the image to add rounded corners to. | ||
* @param cornerRadius | ||
* the radius of the rounded corners. | ||
* @param borderSize | ||
* the size of the border to be added. | ||
* @return a copy of the given image with rounded corners and a transparent border. If the cornerRadius <= 0 or | ||
* borderSize < 0, return the image itself. | ||
*/ | ||
public static Bitmap imageWithRoundedCorner(Bitmap image, float cornerRadius, float borderSize) | ||
{ | ||
if (image == null) { | ||
return null; | ||
} | ||
if (cornerRadius <= 0 || borderSize < 0) { | ||
Log.w(TAG, "Unable to add rounded corners. Invalid corner radius or borderSize for imageWithRoundedCorner"); | ||
return image; | ||
} | ||
|
||
int width = image.getWidth(); | ||
int height = image.getHeight(); | ||
Bitmap imageRoundedCorner = Bitmap.createBitmap(width + (int) (borderSize * 2), height + (int) (borderSize * 2), | ||
Bitmap.Config.ARGB_8888); | ||
Canvas canvas = new Canvas(imageRoundedCorner); | ||
|
||
Path clipPath = new Path(); | ||
RectF imgRect = new RectF(borderSize, borderSize, width + borderSize, height + borderSize); | ||
|
||
float radii[] = new float[8]; | ||
Arrays.fill(radii, cornerRadius); | ||
clipPath.addRoundRect(imgRect, radii, Direction.CW); | ||
|
||
// This still happens sometimes when hw accelerated so, catch and warn | ||
try { | ||
canvas.clipPath(clipPath); | ||
} catch (Exception e) { | ||
Log.e(TAG, "Unable to create the image with rounded corners. clipPath failed on canvas: " + e.getMessage()); | ||
canvas.clipRect(imgRect); | ||
} | ||
|
||
canvas.drawBitmap(imageWithAlpha(image), borderSize, borderSize, null); | ||
return imageRoundedCorner; | ||
} | ||
|
||
/** | ||
* Add a transparent border to the given image around its edges. | ||
* | ||
* @param image | ||
* the image to add a transparent border to. | ||
* @param borderSize | ||
* the size of the border to be added. | ||
* @return a copy of the given image with a transparent border. If the borderSize <= 0, return the image itself. | ||
*/ | ||
public static Bitmap imageWithTransparentBorder(Bitmap image, int borderSize) | ||
{ | ||
if (image == null) { | ||
return null; | ||
} | ||
if (borderSize <= 0) { | ||
Log.w(TAG, "Unable to add a transparent border. Invalid border size for imageWithTransparentBorder."); | ||
return image; | ||
} | ||
|
||
int width = image.getWidth(); | ||
int height = image.getHeight(); | ||
Bitmap imageBorder = Bitmap.createBitmap(width + borderSize * 2, height + borderSize * 2, Bitmap.Config.ARGB_8888); | ||
Canvas canvas = new Canvas(imageBorder); | ||
canvas.drawBitmap(imageWithAlpha(image), borderSize, borderSize, null); | ||
return imageBorder; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I understand the point of this is to avoid having the line in two places, I think we should avoid hitting the getParentView() call every single time that propertyChange is called. Please move this inside the if and else if blocks so we only hit it when we need it.