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-10824] Use LayerDrawable in ActivityWindow #3776

Merged
merged 4 commits into from
Jan 28, 2013
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 @@ -24,7 +24,7 @@
import org.appcelerator.titanium.proxy.ActivityProxy;
import org.appcelerator.titanium.proxy.TiWindowProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiFileHelper;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement;
import org.appcelerator.titanium.view.TiUIView;
Expand Down Expand Up @@ -330,20 +330,21 @@ public void run() {
private void handleBackground(Drawable drawable, Object opacityValue, boolean post)
{
if (drawable != null) {
float opacity = 1f;

if (opacityValue != null) { // lightweight opacity will get handled via super because nativeView won't be null.
setActivityOpacity(drawable, TiConvert.toFloat(opacityValue), true);
try {
opacity = TiConvert.toFloat(opacityValue);
} catch (NumberFormatException e) {
opacity = 1f;
}
}

setActivityOpacity(drawable, opacity, true);
setActivityBackground(drawable, post);
}
}

private void handleBackgroundColor(Object value, boolean post)
{
Object opacity = proxy.getProperty(TiC.PROPERTY_OPACITY);
handleBackgroundColor(value, opacity, post);
}

private void setActivityOpacity(Drawable background, float opacity, boolean firstTime)
{
int alpha = Math.round(opacity * 255);
Expand All @@ -357,54 +358,41 @@ private void setActivityOpacity(Drawable background, float opacity, boolean firs
background.setAlpha(alpha);
}

private void handleBackgroundColor(Object value, Object opacityValue, boolean post)
{
if (value != null) {
Drawable cd = TiConvert.toColorDrawable(TiConvert.toString(value));
handleBackground(cd, opacityValue, post);

} else {
Log.w(TAG, "Unable to set opacity w/o a backgroundColor");
}
}

private void handleBackgroundImage(Object value, boolean post)
{
Object opacity = proxy.getProperty(TiC.PROPERTY_OPACITY);
handleBackgroundImage(value, opacity, post);
}

private void handleBackgroundImage(Object value, Object opacityValue, boolean post)
private void handleActivityBackgroundDrawable(Object bgColor, Object bgImage, Object opacityValue, boolean tile, boolean post)
{
if (value != null) {
String path = proxy.resolveUrl(null, TiConvert.toString(value));
TiFileHelper tfh = new TiFileHelper(TiApplication.getInstance());
Drawable bd = tfh.loadDrawable(path, false);
handleBackground(bd, opacityValue, post);
}
//Maximum of 2 drawables, color and image
String colorString = null;
if (bgColor != null) {
colorString = TiConvert.toString(bgColor);
}

String path = null;
if (bgImage != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This part of code is the same as the function TiUIHelper.buildBackgroundDrawable(). I think it's better to change that function to public and then use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

duh..Thanks. Updating now

path = proxy.resolveUrl(null, TiConvert.toString(bgImage));
}

Drawable bd = TiUIHelper.buildBackgroundDrawable(colorString, path, tile, null);
handleBackground(bd,opacityValue,post);
}

@Override
public void processProperties(KrollDict d)
{
// Prefer image to color.
if (d.containsKey(TiC.PROPERTY_BACKGROUND_IMAGE)) {
if (d.containsKey(TiC.PROPERTY_OPACITY)) {
handleBackgroundImage(d.get(TiC.PROPERTY_BACKGROUND_IMAGE), d.get(TiC.PROPERTY_OPACITY), true);

} else {
handleBackgroundImage(d.get(TiC.PROPERTY_BACKGROUND_IMAGE), true);

if (d.containsKey(TiC.PROPERTY_BACKGROUND_IMAGE) || d.containsKey(TiC.PROPERTY_BACKGROUND_COLOR) || d.containsKey(TiC.PROPERTY_OPACITY)) {
boolean tile = false;
if (d.containsKey(TiC.PROPERTY_BACKGROUND_REPEAT)) {
tile = TiConvert.toBoolean(d.get(TiC.PROPERTY_BACKGROUND_REPEAT));
}
handleActivityBackgroundDrawable(d.get(TiC.PROPERTY_BACKGROUND_COLOR), d.get(TiC.PROPERTY_BACKGROUND_IMAGE), d.get(TiC.PROPERTY_OPACITY), tile, true);

} else if (d.containsKey(TiC.PROPERTY_BACKGROUND_COLOR)) {
if (d.containsKey(TiC.PROPERTY_OPACITY)) {
handleBackgroundColor(d.get(TiC.PROPERTY_BACKGROUND_COLOR), d.get(TiC.PROPERTY_OPACITY), true);

} else {
handleBackgroundColor(d.get(TiC.PROPERTY_BACKGROUND_COLOR), true);
}
// Don't allow default processing.
d.remove(TiC.PROPERTY_BACKGROUND_IMAGE);
d.remove(TiC.PROPERTY_BACKGROUND_COLOR);
d.remove(TiC.PROPERTY_BACKGROUND_REPEAT);
}

if (d.containsKey(TiC.PROPERTY_TITLE)) {
String title = TiConvert.toString(d, TiC.PROPERTY_TITLE);

Expand Down Expand Up @@ -447,26 +435,32 @@ public void processProperties(KrollDict d)
}
}

// Don't allow default processing.
d.remove(TiC.PROPERTY_BACKGROUND_IMAGE);
d.remove(TiC.PROPERTY_BACKGROUND_COLOR);
super.processProperties(d);
}

@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
{
if (key.equals(TiC.PROPERTY_BACKGROUND_IMAGE)) {
if (newValue != null) {
handleBackgroundImage(newValue, false);

} else {
handleBackgroundColor(proxy.getProperty(TiC.PROPERTY_BACKGROUND_COLOR), false);
boolean tile = false;
Object prop = proxy.getProperty(TiC.PROPERTY_BACKGROUND_REPEAT);
if (prop != null) {
tile = TiConvert.toBoolean(prop);
}

handleActivityBackgroundDrawable(proxy.getProperty(TiC.PROPERTY_BACKGROUND_COLOR), newValue, proxy.getProperty(TiC.PROPERTY_OPACITY), tile, false);

} else if (key.equals(TiC.PROPERTY_BACKGROUND_COLOR)) {
handleBackgroundColor(newValue, false);

boolean tile = false;
Object prop = proxy.getProperty(TiC.PROPERTY_BACKGROUND_REPEAT);
if (prop != null) {
tile = TiConvert.toBoolean(prop);
}
handleActivityBackgroundDrawable(newValue, proxy.getProperty(TiC.PROPERTY_BACKGROUND_IMAGE), proxy.getProperty(TiC.PROPERTY_OPACITY), tile, false);

} else if (key.equals(TiC.PROPERTY_BACKGROUND_REPEAT)) {
boolean tile = TiConvert.toBoolean(newValue);
handleActivityBackgroundDrawable(proxy.getProperty(TiC.PROPERTY_BACKGROUND_COLOR), proxy.getProperty(TiC.PROPERTY_BACKGROUND_IMAGE), proxy.getProperty(TiC.PROPERTY_OPACITY), tile, false);

} else if (key.equals(TiC.PROPERTY_WIDTH) || key.equals(TiC.PROPERTY_HEIGHT)) {
Window w = windowActivity.getWindow();
int width = lastWidth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public static void setTextViewDIPPadding(TextView textView, int horizontalPaddin
textView.setPadding(rawHPadding, rawVPadding, rawHPadding, rawVPadding);
}

private static Drawable buildBackgroundDrawable(String color, String image, boolean tileImage, Drawable gradientDrawable)
public static Drawable buildBackgroundDrawable(String color, String image, boolean tileImage, Drawable gradientDrawable)
{
// Create an array of the layers that will compose this background.
// Note that the order in which the layers is important to get the
Expand Down