forked from tidev/titanium-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TiTableViewRowProxyItem.java
680 lines (607 loc) · 21.6 KB
/
TiTableViewRowProxyItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2016 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 ti.modules.titanium.ui.widget.tableview;
import java.util.ArrayList;
import java.util.HashMap;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollPropertyChange;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiUIView;
import ti.modules.titanium.ui.LabelProxy;
import ti.modules.titanium.ui.TableViewProxy;
import ti.modules.titanium.ui.TableViewRowProxy;
import ti.modules.titanium.ui.widget.TiUILabel;
import ti.modules.titanium.ui.widget.TiUITableView;
import ti.modules.titanium.ui.widget.tableview.TableViewModel.Item;
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.support.v4.view.ViewCompat;
import android.view.View;
import android.widget.ImageView;
public class TiTableViewRowProxyItem extends TiBaseTableViewItem
{
private static final String TAG = "TitaniumTableViewItem";
// Only check this once, since we potentially use this information
// every time we add a row. No sense checking it each time.
private static boolean ICS_OR_GREATER = (Build.VERSION.SDK_INT >= TiC.API_LEVEL_ICE_CREAM_SANDWICH);
private static final String LEFT_MARGIN = "6dp";
private static final String RIGHT_MARGIN = "6dp";
private static final int MIN_HEIGHT = 48;
private BitmapDrawable hasChildDrawable, hasCheckDrawable;
private ImageView leftImage;
private ImageView rightImage;
private TiCompositeLayout content;
private ArrayList<TiUIView> views;
private TiDimension height = null;
private Item item;
private Object selectorSource;
private Drawable selectorDrawable;
public TiTableViewRowProxyItem(Activity activity)
{
super(activity);
this.handler = new Handler(this);
this.leftImage = new ImageView(activity);
leftImage.setVisibility(GONE);
addView(leftImage, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
this.content = new TiCompositeLayout(activity);
addView(content, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
this.rightImage = new ImageView(activity);
rightImage.setVisibility(GONE);
addView(rightImage, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
protected TableViewRowProxy getRowProxy()
{
return (TableViewRowProxy) item.proxy;
}
public void setRowData(Item item)
{
this.item = item;
TableViewRowProxy rp = getRowProxy();
if (this != rp.getTableViewRowProxyItem()) {
rp.setTableViewItem(this);
}
setRowData(rp);
}
public Item getRowData()
{
return this.item;
}
protected TiViewProxy addViewToOldRow(int index, TiUIView titleView, TiViewProxy newViewProxy)
{
Log.w(TAG, newViewProxy + " was added an old style row, reusing the title TiUILabel", Log.DEBUG_MODE);
LabelProxy label = new LabelProxy();
label.handleCreationDict(titleView.getProxy().getProperties());
label.setView(titleView);
label.setModelListener(titleView);
titleView.setProxy(label);
getRowProxy().getControls().add(index, label);
views.add(newViewProxy.getOrCreateView());
return label;
}
/*
* Check if the two proxies are compatible outerView wise
*/
private boolean checkBorderProps(TiViewProxy oldProxy, TiViewProxy newProxy)
{
KrollDict oldProperties = oldProxy.getProperties();
KrollDict newProperties = newProxy.getProperties();
boolean oldHasBorder = oldProperties.containsKeyAndNotNull(TiC.PROPERTY_BORDER_COLOR)
|| oldProperties.containsKeyAndNotNull(TiC.PROPERTY_BORDER_RADIUS)
|| oldProperties.containsKeyAndNotNull(TiC.PROPERTY_BORDER_WIDTH);
boolean newHasBorder = newProperties.containsKeyAndNotNull(TiC.PROPERTY_BORDER_COLOR)
|| newProperties.containsKeyAndNotNull(TiC.PROPERTY_BORDER_RADIUS)
|| newProperties.containsKeyAndNotNull(TiC.PROPERTY_BORDER_WIDTH);
return (oldHasBorder == newHasBorder);
}
/*
* Check the view heirarchy
*/
private boolean checkViewHeirarchy(TiViewProxy oldProxy, TiViewProxy newProxy)
{
if (oldProxy == newProxy) {
return true;
}
if (oldProxy.getClass() != newProxy.getClass()) {
//Check for type
return false;
} else if (!checkBorderProps(oldProxy, newProxy)) {
//Ensure they have compatible border props
return false;
} else {
//Check children recursively
TiViewProxy[] oldChildren = oldProxy.getChildren();
TiViewProxy[] newChildren = newProxy.getChildren();
if (oldChildren.length != newChildren.length) {
return false;
} else {
int len = oldChildren.length;
for (int i = 0; i < len; i++) {
if (!checkViewHeirarchy(oldChildren[i], newChildren[i])) {
return false;
}
}
}
}
//ok, all passed. Return true
return true;
}
/*
* Check if views can be reused.
*/
private boolean canUseExistingViews(ArrayList<TiViewProxy> proxies)
{
int len = proxies.size();
if (views != null && views.size() == len) {
for (int i = 0; i < len; i++) {
TiUIView view = views.get(i);
if (view.getProxy() == null) {
return false;
} else if (!checkViewHeirarchy(view.getProxy(), proxies.get(i))) {
return false;
}
}
return true;
}
return false;
}
private ArrayList<KrollPropertyChange> getChangeSet(KrollDict oldProps, KrollDict newProps)
{
ArrayList<KrollPropertyChange> propertyChanges = new ArrayList<KrollPropertyChange>();
/*
//First get the values that changed from the oldProps to the newProps
for (String name : oldProps.keySet()) {
Object oldValue = oldProps.get(name);
Object newValue = newProps.get(name);
if (!(oldValue == null && newValue == null)) {
if ((oldValue == null && newValue != null) || (newValue == null && oldValue != null) || (!oldValue.equals(newValue))) {
KrollPropertyChange pch = new KrollPropertyChange(name, oldValue, newValue);
propertyChanges.add(pch);
}
}
}
//Second get the properties that are only in the newProps
for (String name : newProps.keySet()) {
if (!oldProps.containsKey(name)) {
KrollPropertyChange pch = new KrollPropertyChange(name, null, newProps.get(name));
propertyChanges.add(pch);
}
}
*/
/*
What we should do is above. But since we do not handle null values
properly in our SDK, we'll do it the short way which is an optimized
version of doing processProperties.
*/
for (String name : newProps.keySet()) {
Object oldValue = oldProps.get(name);
Object newValue = newProps.get(name);
if (!(oldValue == null && newValue == null)) {
if ((oldValue == null && newValue != null) || (newValue == null && oldValue != null)
|| (!oldValue.equals(newValue))) {
KrollPropertyChange pch = new KrollPropertyChange(name, oldValue, newValue);
propertyChanges.add(pch);
}
}
}
return propertyChanges;
}
/*
* Create views for measurement or for layout. For each view, apply the
* properties from the appropriate proxy to the view.
*/
protected void createControls()
{
TableViewRowProxy parent = getRowProxy();
ArrayList<TiViewProxy> proxies = parent.getControls();
int len = proxies.size();
if (!canUseExistingViews(proxies)) {
content.removeAllViews();
if (views == null) {
views = new ArrayList<TiUIView>(len);
} else {
views.clear();
}
for (int i = 0; i < len; i++) {
TiViewProxy proxy = proxies.get(i);
TiBaseTableViewItem.clearChildViews(proxy);
TiUIView view = proxy.forceCreateView();
views.add(view);
View v = view.getOuterView();
if (v.getParent() == null) {
content.addView(v, view.getLayoutParams());
}
}
} else {
//Ok the view heirarchies are the same.
//Transfer over the views and modelListeners from the old proxies to the new proxies
for (int i = 0; i < len; i++) {
TiUIView view = views.get(i);
TiViewProxy oldProxy = view.getProxy();
TiViewProxy newProxy = proxies.get(i);
if (oldProxy != newProxy) {
newProxy.transferView(view, oldProxy);
view.setParent(parent);
view.propertiesChanged(getChangeSet(oldProxy.getProperties(), newProxy.getProperties()), newProxy);
//Need to apply child properties.
applyChildProperties(newProxy, view);
}
}
//Reset the content height and width so that it is calculated based on the children
LayoutParams p = content.getLayoutParams();
p.height = -1;
p.width = -1;
content.setLayoutParams(p);
}
}
protected void applyChildProperties(TiViewProxy viewProxy, TiUIView view)
{
int i = 0;
TiViewProxy childProxies[] = viewProxy.getChildren();
for (TiUIView childView : view.getChildren()) {
TiViewProxy childProxy = childProxies[i];
TiViewProxy oldProxy = childView.getProxy();
if (childProxy != oldProxy) {
childProxy.transferView(childView, oldProxy);
childView.setParent(viewProxy);
childView.propertiesChanged(getChangeSet(oldProxy.getProperties(), childProxy.getProperties()),
childProxy);
applyChildProperties(childProxy, childView);
}
i++;
}
}
protected void refreshOldStyleRow()
{
TableViewRowProxy rp = getRowProxy();
if (!rp.hasProperty(TiC.PROPERTY_TOUCH_ENABLED)) {
// We have traditionally always made the label untouchable, but since
// version 3.0.0 we support explore-by-touch on ICS and above, so for
// accessibility purposes we should not be disabling touch if
// accessibility is currently turned on.
if (!ICS_OR_GREATER || !TiApplication.getInstance().getAccessibilityManager().isEnabled()) {
rp.setProperty(TiC.PROPERTY_TOUCH_ENABLED, false);
}
}
// Check if this was a regular row and the control was removed
// if so, cleanup the views
if (views != null && views.size() > 0) {
TiUIView rv = views.get(0);
if (!(rv instanceof TiUILabel)) {
content.removeAllViews();
views.clear();
views = null;
}
}
if (views == null) {
views = new ArrayList<TiUIView>();
views.add(new TiUILabel(rp));
}
TiUILabel t = (TiUILabel) views.get(0);
t.setProxy(rp);
t.processProperties(filterProperties(rp.getProperties()));
View v = t.getOuterView();
if (v.getParent() == null) {
TiCompositeLayout.LayoutParams params = (TiCompositeLayout.LayoutParams) t.getLayoutParams();
if (params.optionLeft == null) {
params.optionLeft = new TiDimension(LEFT_MARGIN, TiDimension.TYPE_LEFT);
}
if (params.optionRight == null) {
params.optionRight = new TiDimension(RIGHT_MARGIN, TiDimension.TYPE_RIGHT);
}
params.autoFillsWidth = true;
content.addView(v, params);
}
}
public void setRowData(TableViewRowProxy rp)
{
// hasControls = rp.hasControls();
Object newSelectorSource = null;
if (rp.hasProperty(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE)) {
newSelectorSource = rp.getProperty(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE);
} else if (rp.hasProperty(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR)) {
newSelectorSource = rp.getProperty(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR);
}
if (newSelectorSource == null || selectorSource != null && !selectorSource.equals(newSelectorSource)) {
selectorDrawable = null;
}
selectorSource = newSelectorSource;
if (selectorSource != null) {
TableViewProxy tableViewProxy = rp.getTable();
if (tableViewProxy != null) {
TiUITableView tableView = tableViewProxy.getTableView();
if (tableViewProxy != null) {
TiTableView view = tableView.getTableView();
if (view != null) {
view.enableCustomSelector();
}
}
}
}
setBackgroundFromProxy(rp);
// Handle right image
boolean clearRightImage = true;
// It's one or the other, check or child. If you set them both, child's gonna win.
HashMap<String, Object> props = rp.getProperties();
if (props.containsKey(TiC.PROPERTY_HAS_CHECK)) {
if (TiConvert.toBoolean(props, TiC.PROPERTY_HAS_CHECK)) {
if (hasCheckDrawable == null) {
hasCheckDrawable = createHasCheckDrawable();
}
rightImage.setImageDrawable(hasCheckDrawable);
rightImage.setVisibility(VISIBLE);
clearRightImage = false;
}
}
if (props.containsKey(TiC.PROPERTY_HAS_CHILD)) {
if (TiConvert.toBoolean(props, TiC.PROPERTY_HAS_CHILD)) {
if (hasChildDrawable == null) {
hasChildDrawable = createHasChildDrawable();
}
rightImage.setImageDrawable(hasChildDrawable);
rightImage.setVisibility(VISIBLE);
clearRightImage = false;
}
}
if (props.containsKey(TiC.PROPERTY_RIGHT_IMAGE)) {
String path = TiConvert.toString(props, TiC.PROPERTY_RIGHT_IMAGE);
String url = rp.resolveUrl(null, path);
Drawable d = loadDrawable(url);
if (d != null) {
rightImage.setImageDrawable(d);
rightImage.setVisibility(VISIBLE);
clearRightImage = false;
}
}
if (clearRightImage) {
rightImage.setImageDrawable(null);
rightImage.setVisibility(GONE);
}
// Handle left image
if (props.containsKey(TiC.PROPERTY_LEFT_IMAGE)) {
String path = TiConvert.toString(props, TiC.PROPERTY_LEFT_IMAGE);
String url = rp.resolveUrl(null, path);
Drawable d = loadDrawable(url);
if (d != null) {
leftImage.setImageDrawable(d);
leftImage.setVisibility(VISIBLE);
}
} else {
leftImage.setImageDrawable(null);
leftImage.setVisibility(GONE);
}
if (props.containsKey(TiC.PROPERTY_HEIGHT)) {
if (!props.get(TiC.PROPERTY_HEIGHT).equals(TiC.SIZE_AUTO)
&& !props.get(TiC.PROPERTY_HEIGHT).equals(TiC.LAYOUT_SIZE)) {
height =
TiConvert.toTiDimension(TiConvert.toString(props, TiC.PROPERTY_HEIGHT), TiDimension.TYPE_HEIGHT);
}
}
if (content == null) {
this.content = new TiCompositeLayout(getRowProxy().getActivity());
addView(content, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
if (props.containsKey(TiC.PROPERTY_LAYOUT)) {
content.setLayoutArrangement(TiConvert.toString(props, TiC.PROPERTY_LAYOUT));
}
if (props.containsKey(TiC.PROPERTY_HORIZONTAL_WRAP)) {
content.setEnableHorizontalWrap(TiConvert.toBoolean(props, TiC.PROPERTY_HORIZONTAL_WRAP));
}
// hasControls() means that the proxy has children
if (rp.hasControls()) {
createControls();
} else {
// no children means that this is an old-style row
refreshOldStyleRow();
}
if (ICS_OR_GREATER) {
Object accessibilityHiddenVal = rp.getProperty(TiC.PROPERTY_ACCESSIBILITY_HIDDEN);
if (accessibilityHiddenVal != null) {
boolean hidden = TiConvert.toBoolean(accessibilityHiddenVal);
if (hidden) {
ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
} else {
ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
}
}
}
}
protected boolean hasView(TiUIView view)
{
if (views == null)
return false;
for (TiUIView v : views) {
if (v == view) {
return true;
}
}
return false;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int w = MeasureSpec.getSize(widthMeasureSpec);
int wMode = MeasureSpec.getMode(widthMeasureSpec);
int h = MeasureSpec.getSize(heightMeasureSpec);
int hMode = MeasureSpec.getMode(heightMeasureSpec);
int imageHMargin = 0;
int leftImageWidth = 0;
int leftImageHeight = 0;
if (leftImage != null && leftImage.getVisibility() != View.GONE) {
measureChild(leftImage, widthMeasureSpec, heightMeasureSpec);
leftImageWidth = leftImage.getMeasuredWidth();
leftImageHeight = leftImage.getMeasuredHeight();
imageHMargin += new TiDimension(LEFT_MARGIN, TiDimension.TYPE_LEFT).getAsPixels(this);
}
int rightImageWidth = 0;
int rightImageHeight = 0;
if (rightImage != null && rightImage.getVisibility() != View.GONE) {
measureChild(rightImage, widthMeasureSpec, heightMeasureSpec);
rightImageWidth = rightImage.getMeasuredWidth();
rightImageHeight = rightImage.getMeasuredHeight();
imageHMargin += new TiDimension(RIGHT_MARGIN, TiDimension.TYPE_RIGHT).getAsPixels(this);
}
int adjustedWidth = w - leftImageWidth - rightImageWidth - imageHMargin;
// int adjustedWidth = w;
if (content != null) {
// If there is a child view, we don't set a minimum height for the row.
// Otherwise, we set a minimum height.
boolean hasChildView = ((TableViewRowProxy) item.proxy).hasControls();
if (hasChildView) {
content.setMinimumHeight(0);
} else {
content.setMinimumHeight(
TiConvert.toTiDimension(MIN_HEIGHT, TiDimension.TYPE_HEIGHT).getAsPixels(this));
}
measureChild(content, MeasureSpec.makeMeasureSpec(adjustedWidth, wMode), heightMeasureSpec);
if (hMode == MeasureSpec.UNSPECIFIED) {
TableViewProxy table = ((TableViewRowProxy) item.proxy).getTable();
int minRowHeight = -1;
if (table != null && table.hasProperty(TiC.PROPERTY_MIN_ROW_HEIGHT)) {
minRowHeight =
TiConvert
.toTiDimension(TiConvert.toString(table.getProperty(TiC.PROPERTY_MIN_ROW_HEIGHT)),
TiDimension.TYPE_HEIGHT)
.getAsPixels(this);
}
if (height == null) {
// If measure spec is not specified, height should behave as Ti.UI.SIZE
if (hMode == 0) {
h = Math.max(content.getMeasuredHeight(), Math.max(leftImageHeight, rightImageHeight));
} else {
h = Math.max(
h, Math.max(content.getMeasuredHeight(), Math.max(leftImageHeight, rightImageHeight)));
}
h = Math.max(h, minRowHeight);
} else {
h = Math.max(minRowHeight, height.getAsPixels(this));
}
// Make sure the height is greater than 1 (not 0 since image views default to 1)
if (hasChildView && h > 1) {
content.getLayoutParams().height = h;
}
if (Log.isDebugModeEnabled()) {
Log.d(TAG, "Row content measure (" + adjustedWidth + "x" + h + ")", Log.DEBUG_MODE);
}
measureChild(content, MeasureSpec.makeMeasureSpec(adjustedWidth, wMode),
MeasureSpec.makeMeasureSpec(h, hMode));
}
}
setMeasuredDimension(w, Math.max(h, Math.max(leftImageHeight, rightImageHeight)));
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
// Make these associations here to avoid doing them on measurement passes
getRowProxy().setTableViewItem(this);
int contentLeft = left;
int contentRight = right;
bottom = bottom - top;
top = 0;
int height = bottom - top;
if (leftImage != null && leftImage.getVisibility() != GONE) {
int w = leftImage.getMeasuredWidth();
int h = leftImage.getMeasuredHeight();
int leftMargin = new TiDimension(LEFT_MARGIN, TiDimension.TYPE_LEFT).getAsPixels(this);
contentLeft += w + leftMargin;
int offset = (height - h) / 2;
leftImage.layout(left + leftMargin, top + offset, left + leftMargin + w, top + offset + h);
}
if (rightImage != null && rightImage.getVisibility() != GONE) {
int w = rightImage.getMeasuredWidth();
int h = rightImage.getMeasuredHeight();
int rightMargin = new TiDimension(RIGHT_MARGIN, TiDimension.TYPE_RIGHT).getAsPixels(this);
contentRight -= w + rightMargin;
int offset = (height - h) / 2;
rightImage.layout(right - w - rightMargin, top + offset, right - rightMargin, top + offset + h);
}
// if (hasControls) {
// contentLeft = left + new TiDimension(LEFT_MARGIN, TiDimension.TYPE_LEFT).getAsPixels(this);
// contentRight = right - new TiDimension(RIGHT_MARGIN, TiDimension.TYPE_RIGHT).getAsPixels(this);
// }
if (content != null) {
content.layout(contentLeft, top, contentRight, bottom);
}
if (changed) {
TiUIHelper.firePostLayoutEvent(getRowProxy());
}
}
private static String[] filteredProperties =
new String[] { TiC.PROPERTY_BACKGROUND_IMAGE, TiC.PROPERTY_BACKGROUND_COLOR,
TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE, TiC.PROPERTY_BACKGROUND_SELECTED_COLOR };
private KrollDict filterProperties(KrollDict d)
{
if (d == null)
return new KrollDict();
KrollDict filtered = new KrollDict(d);
for (int i = 0; i < filteredProperties.length; i++) {
if (filtered.containsKey(filteredProperties[i])) {
filtered.remove(filteredProperties[i]);
}
}
return filtered;
}
@Override
public boolean hasSelector()
{
TableViewRowProxy rowProxy = getRowProxy();
return rowProxy.hasProperty(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE)
|| rowProxy.hasProperty(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR);
}
@Override
public Drawable getSelectorDrawable()
{
TableViewRowProxy rowProxy = getRowProxy();
if (selectorDrawable == null && selectorSource != null) {
if (rowProxy.hasProperty(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE)) {
String path = TiConvert.toString(rowProxy.getProperty(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE));
String url = rowProxy.resolveUrl(null, path);
selectorDrawable = loadDrawable(url);
} else if (rowProxy.hasProperty(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR)) {
int color = TiConvert.toColor(rowProxy.getProperty(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR).toString());
selectorDrawable = new TiTableViewColorSelector(color);
}
}
return selectorDrawable;
}
@Override
public void release()
{
if (views != null) {
for (TiUIView view : views) {
view.release();
}
views.clear();
views = null;
}
if (item != null) {
item = null;
}
if (content != null) {
content.removeAllViews();
content = null;
}
if (hasCheckDrawable != null) {
hasCheckDrawable.setCallback(null);
hasCheckDrawable = null;
}
if (hasChildDrawable != null) {
hasChildDrawable.setCallback(null);
hasChildDrawable = null;
}
super.release();
}
}