Skip to content

Commit

Permalink
Merge pull request #5012 from pingwang2011/timob-15775
Browse files Browse the repository at this point in the history
timob-15775: Android: border properties broken for Label
  • Loading branch information
hieupham007 committed Nov 25, 2013
2 parents 96326ef + 3f989a1 commit 1b2bc65
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions android/modules/ui/src/java/ti/modules/titanium/ui/WindowProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.TiTranslucentActivity;
import org.appcelerator.titanium.proxy.ActivityProxy;
import org.appcelerator.titanium.proxy.DecorViewProxy;
Expand All @@ -34,6 +35,7 @@
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Message;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;

Expand Down Expand Up @@ -272,9 +274,14 @@ public void windowCreated(TiBaseActivity activity) {

// Handle the width and height of the window.
if (hasProperty(TiC.PROPERTY_WIDTH) || hasProperty(TiC.PROPERTY_HEIGHT)) {
int w = TiConvert.toInt(getProperty(TiC.PROPERTY_WIDTH), LayoutParams.MATCH_PARENT);
int h = TiConvert.toInt(getProperty(TiC.PROPERTY_HEIGHT), LayoutParams.MATCH_PARENT);
win.setLayout(w, h);
Object width = getProperty(TiC.PROPERTY_WIDTH);
Object height = getProperty(TiC.PROPERTY_HEIGHT);
View decorView = win.getDecorView();
if (decorView != null) {
int w = width == null ? LayoutParams.MATCH_PARENT : TiConvert.toTiDimension(width, TiDimension.TYPE_WIDTH).getAsPixels(decorView);
int h = height == null ? LayoutParams.MATCH_PARENT : TiConvert.toTiDimension(height, TiDimension.TYPE_HEIGHT).getAsPixels(decorView);
win.setLayout(w, h);
}
}

activity.getActivityProxy().getDecorView().add(this);
Expand Down Expand Up @@ -336,7 +343,7 @@ private void fillIntent(Activity activity, Intent intent)
@Override
public void onPropertyChanged(String name, Object value)
{
if (!lightweight) {
if ((opening || opened) && !lightweight) {
if (TiC.PROPERTY_WINDOW_PIXEL_FORMAT.equals(name)) {
getMainHandler().obtainMessage(MSG_SET_PIXEL_FORMAT, value).sendToTarget();
} else if (TiC.PROPERTY_TITLE.equals(name)) {
Expand All @@ -355,15 +362,15 @@ public void onPropertyChanged(String name, Object value)
@Kroll.setProperty(retain=false) @Kroll.method
public void setWidth(Object width)
{
if (!lightweight) {
// We know it's a HW window only when it's opening/opened.
if ((opening || opened) && !lightweight) {
Object current = getProperty(TiC.PROPERTY_WIDTH);
if (shouldFireChange(current, width)) {
int w = TiConvert.toInt(width, LayoutParams.MATCH_PARENT);
int h = TiConvert.toInt(getProperty(TiC.PROPERTY_HEIGHT), LayoutParams.MATCH_PARENT);
Object height = getProperty(TiC.PROPERTY_HEIGHT);
if (TiApplication.isUIThread()) {
setWindowWidthHeight(w, h);
setWindowWidthHeight(width, height);
} else {
getMainHandler().obtainMessage(MSG_SET_WIDTH_HEIGHT, w, h).sendToTarget();
getMainHandler().obtainMessage(MSG_SET_WIDTH_HEIGHT, new Object[]{width, height}).sendToTarget();
}
}
}
Expand All @@ -374,15 +381,15 @@ public void setWidth(Object width)
@Kroll.setProperty(retain=false) @Kroll.method
public void setHeight(Object height)
{
if (!lightweight) {
// We know it's a HW window only when it's opening/opened.
if ((opening || opened) && !lightweight) {
Object current = getProperty(TiC.PROPERTY_HEIGHT);
if (shouldFireChange(current, height)) {
int h = TiConvert.toInt(height, LayoutParams.MATCH_PARENT);
int w = TiConvert.toInt(getProperty(TiC.PROPERTY_WIDTH), LayoutParams.MATCH_PARENT);
Object width = getProperty(TiC.PROPERTY_WIDTH);
if (TiApplication.isUIThread()) {
setWindowWidthHeight(w, h);
setWindowWidthHeight(width, height);
} else {
getMainHandler().obtainMessage(MSG_SET_WIDTH_HEIGHT, w, h).sendToTarget();
getMainHandler().obtainMessage(MSG_SET_WIDTH_HEIGHT, new Object[]{width, height}).sendToTarget();
}
}
}
Expand Down Expand Up @@ -412,20 +419,26 @@ public boolean handleMessage(Message msg)
return true;
}
case MSG_SET_WIDTH_HEIGHT: {
setWindowWidthHeight(msg.arg1, msg.arg2);
Object[] obj = (Object[]) msg.obj;
setWindowWidthHeight(obj[0], obj[1]);
return true;
}
}
return super.handleMessage(msg);
}

private void setWindowWidthHeight(int w, int h)
private void setWindowWidthHeight(Object width, Object height)
{
Activity activity = getWindowActivity();
if (activity != null) {
Window win = activity.getWindow();
if (win != null) {
win.setLayout(w, h);
View decorView = win.getDecorView();
if (decorView != null) {
int w = width == null ? LayoutParams.MATCH_PARENT : TiConvert.toTiDimension(width, TiDimension.TYPE_WIDTH).getAsPixels(decorView);
int h = height == null ? LayoutParams.MATCH_PARENT : TiConvert.toTiDimension(height, TiDimension.TYPE_HEIGHT).getAsPixels(decorView);
win.setLayout(w, h);
}
}
}
}
Expand Down

0 comments on commit 1b2bc65

Please sign in to comment.