Skip to content

Commit

Permalink
Merge pull request #3043 from krowley/timob-10712-2
Browse files Browse the repository at this point in the history
[TIMOB-10712] Android: label 'opacity' property won't change for TableVi...
  • Loading branch information
billdawson committed Oct 2, 2012
2 parents 7133e70 + 2059f41 commit 09cbaa3
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public void processProperties(KrollDict d)
super.processProperties(d);

TextView tv = (TextView) getNativeView();

// Clear any text style left over here if view is recycled
TiUIHelper.styleText(tv, null, null, null);

// Only accept one, prefer text to title.
if (d.containsKey(TiC.PROPERTY_HTML)) {
tv.setText(Html.fromHtml(TiConvert.toString(d, TiC.PROPERTY_HTML)), TextView.BufferType.SPANNABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ public int getItemViewType(int position) {
return rowTypes.get(item.className);
}

/*
* IMPORTANT NOTE:
* getView() is called by the Android framework whenever it needs a view.
* The call to getView() could come on a measurement pass or on a layout
* pass. It's not possible to tell from the arguments whether the framework
* is calling getView() for a measurement pass or for a layout pass. Therefore,
* it is important that getView() and all methods call by getView() only create
* the views and fill them in with the appropriate data. What getView() and the
* methods call by getView MUST NOT do is to make any associations between
* proxies and views. Those associations must be made only for the views
* that are used for layout, and should be driven from the onLayout() callback.
*/
public View getView(int position, View convertView, ViewGroup parent) {
Item item = (Item) getItem(position);
TiBaseTableViewItem v = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.common.Log;
Expand Down Expand Up @@ -97,7 +98,11 @@ protected TiViewProxy addViewToOldRow(int index, TiUIView titleView, TiViewProxy
return label;
}

protected void refreshControls()
/*
* Create views for measurement or for layout. For each view, apply the
* properties from the appropriate proxy to the view.
*/
protected void createControls()
{
ArrayList<TiViewProxy> proxies = getRowProxy().getControls();
int len = proxies.size();
Expand All @@ -123,8 +128,15 @@ protected void refreshControls()
}
if (view == null) {
// In some cases the TiUIView for this proxy has been reassigned to another proxy
// We don't want to actually release it though, just reassign by creating a new view
view = proxy.forceCreateView();
// We don't want to actually release it though, just reassign by creating a new view.
//
// Not setting modelListener from here because this could be a measurement pass or
// a layout pass through getView(), which means that the view we have here may
// not be the one that gets displayed on the screen. So we don't want to make
// any view-proxy association at this point. We only want to make that association
// on a layout pass (i.e. when onLayout() gets called).
//
view = proxy.forceCreateView(false); // false means don't set modelListener
clearChildViews(proxy);
if (i >= views.size()) {
views.add(view);
Expand All @@ -134,9 +146,8 @@ protected void refreshControls()
}

View v = view.getOuterView();
view.setProxy(proxy);
view.processProperties(proxy.getProperties());
applyChildProxies(proxy, view);
applyChildProperties(proxy, view);
if (v.getParent() == null) {
content.addView(v, view.getLayoutParams());
}
Expand All @@ -151,17 +162,14 @@ protected void clearChildViews(TiViewProxy parent)
}
}

protected void applyChildProxies(TiViewProxy viewProxy, TiUIView view)
protected void applyChildProperties(TiViewProxy viewProxy, TiUIView view)
{
int i = 0;
TiViewProxy childProxies[] = viewProxy.getChildren();
for (TiUIView childView : view.getChildren()) {
TiViewProxy childProxy = childProxies[i];
childView.setProxy(childProxy);
//Since we wipe out children's views earlier we need to reset them.
childProxy.setView(childView);
childView.processProperties(childProxy.getProperties());
applyChildProxies(childProxy, childView);
applyChildProperties(childProxy, childView);
i++;
}
}
Expand Down Expand Up @@ -273,9 +281,11 @@ public void setRowData(TableViewRowProxy rp) {
content.setLayoutArrangement(TiConvert.toString(props, TiC.PROPERTY_LAYOUT));
}

// hasControls() means that the proxy has children
if (rp.hasControls()) {
refreshControls();
createControls();
} else {
// no children means that this is an old-style row
refreshOldStyleRow();
}
}
Expand Down Expand Up @@ -355,9 +365,18 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
// Make this association here to avoid doing it on measurement passes
// Make these associations here to avoid doing them on measurement passes
TableViewRowProxy rp = getRowProxy();
rp.setTableViewItem(this);
if (this.item.proxy.getChildren().length == 0) {
// old-style row
TiUIView childView = views.get(0);
childView.processProperties(filterProperties(rp.getProperties()));
childView.setProxy(rp);
}
else {
associateProxies(this.item.proxy.getChildren(), views);
}

int contentLeft = left;
int contentRight = right;
Expand Down Expand Up @@ -460,4 +479,21 @@ public void release() {
}

}

protected void associateProxies(TiViewProxy[] proxies, List<TiUIView> views)
{
int i = 0;
for (TiUIView view : views) {
if (proxies.length < (i+1)) {
break;
}
TiViewProxy proxy = proxies[i];
proxy.setView(view);
view.setProxy(proxy);
proxy.setModelListener(view);
associateProxies(proxy.getChildren(), view.getChildren());
i++;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -393,32 +393,42 @@ public void setView(TiUIView view)
{
this.view = view;
}

public TiUIView forceCreateView(boolean enableModelListener)
{
view = null;
return getOrCreateView(enableModelListener);
}

public TiUIView forceCreateView()
{
view = null;
return getOrCreateView();
return forceCreateView(true);
}

/**
* Creates or retrieves the view associated with this proxy.
* @return a TiUIView instance.
* @module.api
*/
public TiUIView getOrCreateView()
public TiUIView getOrCreateView(boolean enableModelListener)
{
if (activity == null || view != null) {
return view;
}

if (TiApplication.isUIThread()) {
return handleGetView();
return handleGetView(enableModelListener);
}

return (TiUIView) TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_GETVIEW), 0);
}

/**
* Creates or retrieves the view associated with this proxy.
* @return a TiUIView instance.
* @module.api
*/
public TiUIView getOrCreateView()
{
return getOrCreateView(true);
}

protected TiUIView handleGetView()
protected TiUIView handleGetView(boolean enableModelListener)
{
if (view == null) {
Log.d(TAG, "getView: " + getClass().getSimpleName(), Log.DEBUG_MODE);
Expand All @@ -432,15 +442,23 @@ protected TiUIView handleGetView()
Log.w(TAG, "Activity is null", Log.DEBUG_MODE);
}
}
realizeViews(view);
realizeViews(view, enableModelListener);
view.registerForTouch();
}
return view;
}

protected TiUIView handleGetView()
{
return handleGetView(true);
}

public void realizeViews(TiUIView view)
public void realizeViews(TiUIView view, boolean enableModelListener)
{
setModelListener(view);
if (enableModelListener)
{
setModelListener(view);
}

// Use a copy so bundle can be modified as it passes up the inheritance
// tree. Allows defaults to be added and keys removed.
Expand All @@ -461,6 +479,11 @@ public void realizeViews(TiUIView view)
}
}
}

public void realizeViews(TiUIView view)
{
realizeViews(view, true);
}

public void releaseViews()
{
Expand Down

0 comments on commit 09cbaa3

Please sign in to comment.