Skip to content

Commit

Permalink
Merge pull request #2660 from ayeung/timob-9994
Browse files Browse the repository at this point in the history
TIMOB-9994: Added postlayout events for various controls/wigets
  • Loading branch information
vishalduggal committed Jul 31, 2012
2 parents e382067 + 73ad002 commit 1df662c
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ public TiUIButton(final TiViewProxy proxy) {
if (DBG) {
Log.d(LCAT, "Creating a button");
}
Button btn = new Button(proxy.getActivity());
Button btn = new Button(proxy.getActivity())
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};
btn.setPadding(8, 0, 8, 0);
btn.setGravity(Gravity.CENTER);
setNativeView(btn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class TiUIImageView extends TiUIView implements OnLifecycleEvent, Handler

private Timer timer;
private Animator animator;
private Object[] images;
private Loader loader;
private Thread loaderThread;
private AtomicBoolean animating = new AtomicBoolean(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@ public class TiUILabel extends TiUIView
private static final String LCAT = "TiUILabel";
private static final boolean DBG = TiConfig.LOGD;

public TiUILabel(TiViewProxy proxy) {
public TiUILabel(final TiViewProxy proxy)
{
super(proxy);
if (DBG) {
Log.d(LCAT, "Creating a text label");
}
TextView tv = new TextView(getProxy().getActivity());
TextView tv = new TextView(getProxy().getActivity())
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);

if (proxy != null && proxy.hasListeners(TiC.EVENT_POST_LAYOUT)) {
proxy.fireEvent(TiC.EVENT_POST_LAYOUT, null, false);
}
}
};
tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
tv.setPadding(0, 0, 0, 0);
tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import android.view.Gravity;
Expand All @@ -24,11 +25,19 @@ public class TiUIProgressBar extends TiUIView {
private ProgressBar progress;
private LinearLayout view;

public TiUIProgressBar(TiViewProxy proxy)
public TiUIProgressBar(final TiViewProxy proxy)
{
super(proxy);

view = new LinearLayout(proxy.getActivity());
view = new LinearLayout(proxy.getActivity())
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};
view.setOrientation(LinearLayout.VERTICAL);
label = new TextView(proxy.getActivity());
label.setGravity(Gravity.TOP | Gravity.LEFT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
* 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.
*/
Expand All @@ -16,6 +16,7 @@
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiFileHelper;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import android.graphics.Rect;
Expand All @@ -41,7 +42,8 @@ public class TiUISlider extends TiUIView

private SoftReference<Drawable> thumbDrawable;

public TiUISlider(TiViewProxy proxy) {
public TiUISlider(final TiViewProxy proxy)
{
super(proxy);
if (DBG) {
Log.d(LCAT, "Creating a seekBar");
Expand All @@ -53,7 +55,15 @@ public TiUISlider(TiViewProxy proxy) {
this.max = 1;
this.pos = 0;

SeekBar seekBar = new SeekBar(proxy.getActivity());
SeekBar seekBar = new SeekBar(proxy.getActivity())
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};
seekBar.setOnSeekBarChangeListener(this);
setNativeView(seekBar);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,44 @@ public void onCheckedChanged(CompoundButton btn, boolean value) {
proxy.fireEvent(TiC.EVENT_CHANGE, data);
}

protected void setStyle(int style) {
protected void setStyle(int style)
{
CompoundButton currentButton = (CompoundButton) getNativeView();
CompoundButton button = null;

switch (style) {
case AndroidModule.SWITCH_STYLE_CHECKBOX:
if (!(currentButton instanceof CheckBox)) {
button = new CheckBox(proxy.getActivity());
}
break;

case AndroidModule.SWITCH_STYLE_TOGGLEBUTTON:
if (!(currentButton instanceof ToggleButton)) {
button = new ToggleButton(proxy.getActivity());
}
break;
case AndroidModule.SWITCH_STYLE_CHECKBOX:
if (!(currentButton instanceof CheckBox)) {
button = new CheckBox(proxy.getActivity())
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};
}
break;

default:
return;
case AndroidModule.SWITCH_STYLE_TOGGLEBUTTON:
if (!(currentButton instanceof ToggleButton)) {
button = new ToggleButton(proxy.getActivity())
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};
}
break;

default:
return;
}

if (button != null) {
setNativeView(button);
updateButton(button, proxy.getProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public boolean onCheckIsTextEditor () {
}
return true;
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}

}

public TiUIText(TiViewProxy proxy, boolean field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import android.app.Activity;
Expand All @@ -34,14 +35,22 @@ public TiUIDatePicker(TiViewProxy proxy)
{
super(proxy);
}
public TiUIDatePicker(TiViewProxy proxy, Activity activity)
public TiUIDatePicker(final TiViewProxy proxy, Activity activity)
{
this(proxy);
if (DBG) {
Log.d(LCAT, "Creating a date picker");
}

DatePicker picker = new DatePicker(activity);
DatePicker picker = new DatePicker(activity)
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};
setNativeView(picker);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
* 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.
*/
Expand All @@ -23,6 +23,7 @@
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import android.app.Activity;
Expand Down Expand Up @@ -59,7 +60,7 @@ public TiUIDateSpinner(TiViewProxy proxy, Activity activity)
this(proxy);
createNativeView(activity);
}

private void createNativeView(Activity activity)
{
// defaults
Expand All @@ -79,7 +80,15 @@ private void createNativeView(Activity activity)
dayWheel.setItemSelectedListener(this);
yearWheel.setItemSelectedListener(this);

LinearLayout layout = new LinearLayout(activity);
LinearLayout layout = new LinearLayout(activity)
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};
layout.setOrientation(LinearLayout.HORIZONTAL);

if (proxy.hasProperty("dayBeforeMonth")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import ti.modules.titanium.ui.PickerColumnProxy;
Expand All @@ -32,10 +33,18 @@ public TiUINativePicker(TiViewProxy proxy)
{
super(proxy);
}
public TiUINativePicker(TiViewProxy proxy, Activity activity)
public TiUINativePicker(final TiViewProxy proxy, Activity activity)
{
this(proxy);
Spinner spinner = new Spinner(activity);
Spinner spinner = new Spinner(activity)
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};
setNativeView(spinner);
refreshNativeView();
preselectRows();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
* 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.
*/
Expand All @@ -15,6 +15,7 @@
import org.appcelerator.kroll.common.TiConfig;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import android.app.Activity;
Expand All @@ -35,14 +36,22 @@ public TiUITimePicker(TiViewProxy proxy)
{
super(proxy);
}
public TiUITimePicker(TiViewProxy proxy, Activity activity)
public TiUITimePicker(final TiViewProxy proxy, Activity activity)
{
this(proxy);
if (DBG) {
Log.d(LCAT, "Creating a time picker");
}

TimePicker picker = new TimePicker(activity);
TimePicker picker = new TimePicker(activity)
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};
picker.setIs24HourView(false);
picker.setOnTimeChangedListener(this);
setNativeView(picker);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* 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.
*/
Expand All @@ -10,6 +10,7 @@
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;

import ti.modules.titanium.ui.widget.TiUIText;
import android.view.Gravity;
Expand Down Expand Up @@ -58,7 +59,15 @@ public void onClick(View view)
}
});

RelativeLayout layout = new RelativeLayout(proxy.getActivity());
RelativeLayout layout = new RelativeLayout(proxy.getActivity())
{
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
TiUIHelper.firePostLayoutEvent(proxy);
}
};

layout.setGravity(Gravity.NO_GRAVITY);
layout.setPadding(0,0,0,0);
Expand Down

0 comments on commit 1df662c

Please sign in to comment.