forked from tidev/titanium-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TiToolbar.java
828 lines (769 loc) 路 25.4 KB
/
TiToolbar.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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
package ti.modules.titanium.ui.widget;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.AsyncResult;
import org.appcelerator.kroll.common.TiMessenger;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiDrawableReference;
import org.appcelerator.titanium.view.TiToolbarStyleHandler;
import org.appcelerator.titanium.view.TiUIView;
public class TiToolbar extends TiUIView implements Handler.Callback
{
//region private primitive fields
private final int BACKGROUND_TRANSLUCENT_VALUE = 92;
private final int BACKGROUND_SOLID_VALUE = 255;
//endregion
//region private Object fields
private Handler mainHandler = new Handler(Looper.getMainLooper(), this);
private Toolbar toolbar;
private Object logo = null;
private Object navigationIcon = null;
private Object overflowMenuIcon = null;
private TiViewProxy[] viewProxiesArray;
//endregion
//region common message types
private final int TOOLBAR_SET_COLOR = 10001;
private final int TOOLBAR_SET_TRANSLUCENCY = 10002;
private final int TOOLBAR_SET_BACKGROUND_EXTENDED = 10003;
//endregion
//region Android only message types
private final int TOOLBAR_SHOW_OVERFLOW_MENU = 10004;
private final int TOOLBAR_HIDE_OVERFLOW_MENU = 10005;
private final int TOOLBAR_SET_LOGO = 10006;
private final int TOOLBAR_SET_NAVIGATION_ICON = 10007;
private final int TOOLBAR_SET_OVERFLOW_MENU_ICON = 10008;
private final int TOOLBAR_DISMISS_POPUP_MENUS = 10009;
private final int TOOLBAR_SET_TITLE = 10010;
private final int TOOLBAR_SET_TITLE_TEXT_COLOR = 10011;
private final int TOOLBAR_SET_SUBTITLE = 10012;
private final int TOOLBAR_SET_SUBTITLE_TEXT_COLOR = 10013;
private final int TOOLBAR_COLLAPSE_ACTION_VEIW = 10014;
private final int TOOLBAR_SET_CONTENT_INSET_END_WITH_ACTIONS = 10015;
private final int TOOLBAR_SET_CONTENT_INSET_START_WITH_NAVIGATION = 10016;
private final int TOOLBAR_SET_CONTENT_INSETS_ABSOLUTE = 10017;
private final int TOOLBAR_SET_CONTENT_INSETS_RELATIVE = 10018;
//endregion
/**
* Constructs a TiUIView object with the associated proxy.
* @param proxy the associated proxy.
* @module.api
*/
public TiToolbar(TiViewProxy proxy)
{
super(proxy);
toolbar = new Toolbar(proxy.getActivity()) {
@Override
protected void onConfigurationChanged(Configuration newConfig)
{
// If auto-sized, then resize toolbar height and font size to what's defined in XML.
// Note: Typically, the default height is 56dp in portrait and 48dp in landscape.
TiCompositeLayout.LayoutParams params = TiToolbar.this.getLayoutParams();
boolean isAutoSized = (params != null) ? params.hasAutoSizedHeight() : true;
if (isAutoSized) {
TiToolbarStyleHandler styleHandler = new TiToolbarStyleHandler(this);
styleHandler.onConfigurationChanged(newConfig);
}
super.onConfigurationChanged(newConfig);
}
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets)
{
// Give toolbar a copy of insets and ignore returned "consumed" insets which is set to all zeros.
// Returning zero insets prevents other child views in the hierarchy from receiving system insets,
// which prevents their setFitsSystemWindows(true) from working. (Such as a 2nd toolbar.)
WindowInsets clonedInsets = (insets != null) ? new WindowInsets(insets) : null;
super.onApplyWindowInsets(clonedInsets);
return insets;
}
@Override
protected boolean fitSystemWindows(Rect insets)
{
// Do custom inset handling if "extendBackground" was applied to toolbar.
if ((insets != null) && getFitsSystemWindows()) {
// Determine if we need to pad the top or bottom based on toolbar's y-axis position.
boolean isPaddingTop = true;
TiCompositeLayout.LayoutParams params = TiToolbar.this.getLayoutParams();
if (params != null) {
if ((params.optionTop == null) && (params.optionCenterY == null)) {
if ((params.optionBottom != null) && (params.optionBottom.getAsPixels(this) <= 0)) {
// Toolbar is docked to the bottom of the view. So, pad the bottom instead.
isPaddingTop = false;
}
}
}
// Create a new insets object with either the top or bottom inset padding stripped off.
// Note: We never want the toolbar to pad both the top and bottom.
// Especially when toolbar is docked to top of view but using a translucent navigation bar.
insets = new Rect(insets);
if (isPaddingTop) {
insets.bottom = 0;
} else {
insets.top = 0;
}
}
// Apply insets to toolbar. (Google blindly pads the view based on these insets.)
super.fitSystemWindows(insets);
// Returning false prevents given insets from being consumed.
// Allows other views with setFitsSystemWindows(true) to receive insets. (Such as a 2nd toolbar.)
return false;
}
};
setNativeView(toolbar);
}
/**
* Adds custom views in the toolbar
* @param proxies View proxies to be used
*/
public void setItems(TiViewProxy[] proxies)
{
if (proxies != null) {
for (int i = 0; i < proxies.length; i++) {
toolbar.addView(convertLayoutParamsForView(proxies[i].getOrCreateView()));
}
}
}
/**
* Sets the background color of the toolbar
* @param color String in Titanium color format
*/
public void setToolbarColor(String color)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_COLOR), color);
} else {
handleBackgroundColor(color);
}
}
/**
* Handler for background color change.
* @param color String in Titanium color format
*/
private void handleBackgroundColor(String color)
{
toolbar.setBackgroundColor((TiColorHelper.parseColor(color)));
if (proxy.hasProperty(TiC.PROPERTY_TRANSLUCENT)) {
if ((Boolean) proxy.getProperty(TiC.PROPERTY_TRANSLUCENT)) {
toolbar.getBackground().setAlpha(BACKGROUND_TRANSLUCENT_VALUE);
}
}
}
/**
* Sets up the Toolbar to extend behind the Status Bar.
* This is useful when the Toolbar instance is set as a support bar in an activity
* and it positioned at the very top of it.
*/
public void setToolbarExtendBackground()
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_BACKGROUND_EXTENDED));
} else {
handleBackgroundExtended();
}
}
/**
* Handler for extending the background.
*/
private void handleBackgroundExtended()
{
// This feature is only supported on Android 4.4 or higher.
if (Build.VERSION.SDK_INT < 19) {
return;
}
// Fetch the currently displayed activity window and its root decor view.
// Note: Will be null if all activities have just been destroyed.
Activity activity = TiApplication.getAppCurrentActivity();
if (activity == null) {
return;
}
Window window = activity.getWindow();
if (window == null) {
return;
}
View decorView = window.getDecorView();
if (decorView == null) {
return;
}
// Set up root content views to allow top status bar to overlap them.
decorView.setFitsSystemWindows(false);
if (activity instanceof TiBaseActivity) {
View view = ((TiBaseActivity) activity).getLayout();
if (view != null) {
view.setFitsSystemWindows(false);
}
}
// Set up toolbar so that it's title and buttons won't be overlapped by the status bar.
// Note that the toolbar will automatically pad its background beneath the status bar as well.
toolbar.setFitsSystemWindows(true);
// Set flags so that the current window will allow drawing behind the status bar.
int flags = decorView.getSystemUiVisibility();
flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
decorView.setSystemUiVisibility(flags);
if (Build.VERSION.SDK_INT >= 21) {
window.setStatusBarColor(Color.TRANSPARENT);
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
// Request window to re-fit its views.
toolbar.requestFitSystemWindows();
}
/**
* Sets whether the Toolbar's background is translucent.
* Achieved by setting the alpha of the background to 36%.
* @param value Boolean value to set to translucency.
*/
public void setTranslucent(boolean value)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_TRANSLUCENCY), value);
} else {
handleTranslucency(value);
}
}
/**
* Handler for translucency change
* @param value Boolean value to set to translucency.
*/
private void handleTranslucency(boolean value)
{
toolbar.getBackground().setAlpha(value ? BACKGROUND_TRANSLUCENT_VALUE : BACKGROUND_SOLID_VALUE);
}
/**
* Changes the LayoutParams type of custom views added to the Toolbar.
* Width and height are preserved.
* They need to be of type Toolbar.LayoutParams.
* @param source
* @return
*/
private View convertLayoutParamsForView(TiUIView source)
{
View res = source.getNativeView();
TiDimension widthDimension = source.getLayoutParams().optionWidth;
int width = widthDimension != null ? widthDimension.getAsPixels(toolbar) : Toolbar.LayoutParams.WRAP_CONTENT;
TiDimension heightDimension = source.getLayoutParams().optionHeight;
int height = heightDimension != null ? heightDimension.getAsPixels(toolbar) : Toolbar.LayoutParams.WRAP_CONTENT;
res.setLayoutParams(new Toolbar.LayoutParams(width, height));
return res;
}
/**
* Shows the overflow menu if there is one.
*/
public void showOverFlowMenu()
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SHOW_OVERFLOW_MENU));
} else {
handleShowOverFlowMenu();
}
}
/**
* Handles overflow menu show.
*/
private void handleShowOverFlowMenu()
{
((Toolbar) getNativeView()).showOverflowMenu();
}
/**
* Hides the overflow menu if there is one.
*/
public void hideOverFlowMenu()
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_HIDE_OVERFLOW_MENU));
} else {
handleHideOverFlowMenu();
}
}
/**
* Handles overflow menu hide.
*/
private void handleHideOverFlowMenu()
{
((Toolbar) getNativeView()).hideOverflowMenu();
}
/**
* Sets the Toolbar's logo image.
* @param object Image to load. It can be passed as a Blob, File or path to a resource.
*/
public void setLogo(Object object)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_LOGO), object);
} else {
handleSetLogo(object);
}
}
/**
* Handles the logo change.
* @param object
*/
private void handleSetLogo(Object object)
{
logo = object;
TiDrawableReference tiDrawableReference = TiDrawableReference.fromObject(proxy, object);
((Toolbar) getNativeView()).setLogo(tiDrawableReference.getDrawable());
}
/**
* Return the current logo in the format it was passed
* @return
*/
public Object getLogo()
{
return logo;
}
/**
* Sets the Toolbar's navigation icon.
* @param object Image to load. It can be passed as a Blob, File or path to a resource.
*/
public void setNavigationIcon(Object object)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_NAVIGATION_ICON), object);
} else {
handleSetNavigationIcon(object);
}
}
/**
* Handles the navigation icon change.
* @param object
*/
private void handleSetNavigationIcon(Object object)
{
navigationIcon = object;
TiDrawableReference tiDrawableReference = TiDrawableReference.fromObject(proxy, object);
((Toolbar) getNativeView()).setNavigationIcon(tiDrawableReference.getDrawable());
}
/**
* Returns the currently set navigation icon in the format it was set.
* @return
*/
public Object getNavigationIcon()
{
return navigationIcon;
}
/**
* Sets the overflow menu icon.
* @param object Image to load. It can be passed as a Blob, File or path to a resource.
*/
public void setOverflowMenuIcon(Object object)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_OVERFLOW_MENU_ICON), object);
} else {
handleSetOverflowMenuIcon(object);
}
}
/**
* Handles overflow menu icon change
* @param object
*/
private void handleSetOverflowMenuIcon(Object object)
{
overflowMenuIcon = object;
TiDrawableReference tiDrawableReference = TiDrawableReference.fromObject(proxy, object);
((Toolbar) getNativeView()).setOverflowIcon(tiDrawableReference.getDrawable());
}
/**
* Returns the overflow menu icon in the format it was set.
* @return
*/
public Object getOverflowMenuIcon()
{
return overflowMenuIcon;
}
/**
* Closes all action views expanded and hides overflow menu.
*/
public void dismissPopupMenus()
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage((TOOLBAR_DISMISS_POPUP_MENUS)));
} else {
handleDismissPopupMenus();
}
}
/**
* Handles closing all action views expanded and hiding overflow menu.
*/
private void handleDismissPopupMenus()
{
((Toolbar) getNativeView()).dismissPopupMenus();
}
/**
* Sets the Toolbar title
* @param value String to be used as title.
*/
private void setTitle(String value)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_TITLE), value);
} else {
handleSetTitle(value);
}
}
/**
* Handles title change
* @param value
*/
private void handleSetTitle(String value)
{
toolbar.setTitle(value);
}
/**
* Sets title's text color
* @param value Color in any format supported by Titanium.
*/
private void setTitleTextColor(String value)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_TITLE_TEXT_COLOR), value);
} else {
handleSetTitleTextColor(value);
}
}
/**
* Handles title's text color change.
* @param value
*/
private void handleSetTitleTextColor(String value)
{
toolbar.setTitleTextColor(TiColorHelper.parseColor(value));
}
/**
* Sets subtitle.
* @param value String to be used as title.
*/
private void setSubtitle(String value)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_SUBTITLE), value);
} else {
handleSetSubtitle(value);
}
}
/**
* Handles subtitle change.
* @param value
*/
private void handleSetSubtitle(String value)
{
toolbar.setSubtitle(value);
}
/**
* Sets subtitle's text color
* @param value Color in any format supported by Titanium.
*/
private void setSubtitleTextColor(String value)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_SUBTITLE_TEXT_COLOR), value);
} else {
handleSetSubtitleTextColor(value);
}
}
/**
* Handles subtitle's text color change.
* @param value
*/
private void handleSetSubtitleTextColor(String value)
{
toolbar.setSubtitleTextColor(TiColorHelper.parseColor(value));
}
/**
* Saves the proxy objects of the views passed as custom items.
* Sets them as current custom views.
* @param value
*/
private void setViewProxiesArray(Object[] value)
{
viewProxiesArray = new TiViewProxy[value.length];
for (int i = 0; i < value.length; i++) {
viewProxiesArray[i] = (TiViewProxy) value[i];
}
setItems(viewProxiesArray);
}
/**
* Closes custom views's added in the toolbar.
*/
public void collapseActionView()
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_COLLAPSE_ACTION_VEIW));
} else {
handleCollapseActionView();
}
}
/**
* Handles closing custom view.
*/
private void handleCollapseActionView()
{
toolbar.collapseActionView();
}
public void setContentInsetEndWithActions(int value)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_CONTENT_INSET_END_WITH_ACTIONS),
value);
} else {
handleSetContentInsetEndWithActions(value);
}
}
private void handleSetContentInsetEndWithActions(int value)
{
toolbar.setContentInsetEndWithActions(value);
}
public void setContentInsetStartWithNavigation(int value)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(
mainHandler.obtainMessage(TOOLBAR_SET_CONTENT_INSET_START_WITH_NAVIGATION), value);
} else {
handleSetContentInsetStartWithNavigation(value);
}
}
private void handleSetContentInsetStartWithNavigation(int value)
{
toolbar.setContentInsetStartWithNavigation(value);
}
public void setContentInsetsAbsolute(int insetLeft, int insetRight)
{
Integer[] values = new Integer[] { insetLeft, insetRight };
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_CONTENT_INSETS_ABSOLUTE), values);
} else {
handleSetContentInsetsAbsolute(values);
}
}
private void handleSetContentInsetsAbsolute(Integer values[])
{
toolbar.setContentInsetsAbsolute(values[0], values[1]);
}
public void setContentInsetsRelative(int insetLeft, int insetRight)
{
Integer[] values = new Integer[] { insetLeft, insetRight };
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(mainHandler.obtainMessage(TOOLBAR_SET_CONTENT_INSETS_RELATIVE), values);
} else {
handleSetContentInsetsRelative(values);
}
}
private void handleSetContentInsetsRelative(Integer values[])
{
toolbar.setContentInsetsAbsolute(values[0], values[1]);
}
@Override
public void processProperties(KrollDict d)
{
//region process common properties
if (d.containsKey(TiC.PROPERTY_BAR_COLOR)) {
setToolbarColor(d.getString(TiC.PROPERTY_BAR_COLOR));
}
if (d.containsKey(TiC.PROPERTY_EXTEND_BACKGROUND)) {
if (d.getBoolean(TiC.PROPERTY_EXTEND_BACKGROUND)) {
setToolbarExtendBackground();
}
}
if (d.containsKey(TiC.PROPERTY_ITEMS)) {
setViewProxiesArray(((Object[]) d.get(TiC.PROPERTY_ITEMS)));
}
if (d.containsKey(TiC.PROPERTY_TRANSLUCENT)) {
setTranslucent(d.getBoolean(TiC.PROPERTY_TRANSLUCENT));
}
//endregion
//region Android only properties
if (d.containsKey(TiC.PROPERTY_LOGO)) {
setLogo(d.get(TiC.PROPERTY_LOGO));
}
if (d.containsKey(TiC.PROPERTY_NAVIGATION_ICON)) {
setNavigationIcon(d.get(TiC.PROPERTY_NAVIGATION_ICON));
}
if (d.containsKey(TiC.PROPERTY_OVERFLOW_ICON)) {
setOverflowMenuIcon(d.get(TiC.PROPERTY_OVERFLOW_ICON));
}
if (d.containsKey(TiC.PROPERTY_TITLE)) {
setTitle(d.getString(TiC.PROPERTY_TITLE));
}
if (d.containsKey(TiC.PROPERTY_TITLE_TEXT_COLOR)) {
setTitleTextColor(d.getString(TiC.PROPERTY_TITLE_TEXT_COLOR));
}
if (d.containsKey(TiC.PROPERTY_SUBTITLE)) {
setSubtitle(d.getString(TiC.PROPERTY_SUBTITLE));
}
if (d.containsKey(TiC.PROPERTY_SUBTITLE_TEXT_COLOR)) {
setSubtitleTextColor(d.getString(TiC.PROPERTY_SUBTITLE_TEXT_COLOR));
}
if (d.containsKey(TiC.PROPERTY_SUBTITLE_TEXT_COLOR)) {
setSubtitleTextColor(d.getString(TiC.PROPERTY_SUBTITLE_TEXT_COLOR));
}
if (d.containsKey(TiC.PROPERTY_CONTENT_INSET_END_WITH_ACTIONS)) {
if (toolbar != null) {
setContentInsetEndWithActions(d.getInt(TiC.PROPERTY_CONTENT_INSET_END_WITH_ACTIONS));
}
}
if (d.containsKey(TiC.PROPERTY_CONTENT_INSET_START_WITH_NAVIGATION)) {
if (toolbar != null) {
setContentInsetStartWithNavigation(d.getInt(TiC.PROPERTY_CONTENT_INSET_START_WITH_NAVIGATION));
}
}
//end region
super.processProperties(d);
}
@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
{
super.propertyChanged(key, oldValue, newValue, proxy);
if (key.equals(TiC.PROPERTY_BAR_COLOR)) {
setToolbarColor(((String) newValue));
}
if (key.equals(TiC.PROPERTY_TRANSLUCENT)) {
setTranslucent(((Boolean) newValue));
}
if (key.equals(TiC.PROPERTY_ITEMS)) {
setItems(((TiViewProxy[]) newValue));
}
if (key.equals(TiC.PROPERTY_LOGO)) {
setLogo(newValue);
}
if (key.equals(TiC.PROPERTY_NAVIGATION_ICON)) {
setNavigationIcon(newValue);
}
if (key.equals(TiC.PROPERTY_OVERFLOW_ICON)) {
setOverflowMenuIcon(newValue);
}
if (key.equals(TiC.PROPERTY_TITLE)) {
setTitle((String) newValue);
}
if (key.equals(TiC.PROPERTY_TITLE_TEXT_COLOR)) {
setTitleTextColor((String) newValue);
}
if (key.equals(TiC.PROPERTY_SUBTITLE)) {
setSubtitle((String) newValue);
}
if (key.equals(TiC.PROPERTY_SUBTITLE_TEXT_COLOR)) {
setSubtitleTextColor((String) newValue);
}
if (key.equals(TiC.PROPERTY_CONTENT_INSET_END_WITH_ACTIONS)) {
setContentInsetEndWithActions((Integer) newValue);
}
if (key.equals(TiC.PROPERTY_CONTENT_INSET_START_WITH_NAVIGATION)) {
setContentInsetStartWithNavigation((Integer) newValue);
}
}
@Override
public boolean handleMessage(Message msg)
{
switch (msg.what) {
case TOOLBAR_SET_COLOR:
AsyncResult resultBackgroundColor = (AsyncResult) msg.obj;
handleBackgroundColor((String) resultBackgroundColor.getArg());
resultBackgroundColor.setResult(null);
return true;
case TOOLBAR_SET_TRANSLUCENCY:
AsyncResult resultTranslucency = (AsyncResult) msg.obj;
handleTranslucency((Boolean) resultTranslucency.getArg());
resultTranslucency.setResult(null);
return true;
case TOOLBAR_SET_BACKGROUND_EXTENDED:
AsyncResult resultBackgroundExtended = (AsyncResult) msg.obj;
handleBackgroundExtended();
resultBackgroundExtended.setResult(null);
return true;
case TOOLBAR_SHOW_OVERFLOW_MENU:
AsyncResult resultShowOverflow = (AsyncResult) msg.obj;
handleShowOverFlowMenu();
resultShowOverflow.setResult(null);
return true;
case TOOLBAR_HIDE_OVERFLOW_MENU:
AsyncResult resultHideOverflow = (AsyncResult) msg.obj;
handleHideOverFlowMenu();
resultHideOverflow.setResult(null);
return true;
case TOOLBAR_SET_LOGO:
AsyncResult resultSetLogo = (AsyncResult) msg.obj;
handleSetLogo(resultSetLogo.getArg());
resultSetLogo.setResult(null);
return true;
case TOOLBAR_SET_NAVIGATION_ICON:
AsyncResult resultSetNavigationIcon = (AsyncResult) msg.obj;
handleSetNavigationIcon(resultSetNavigationIcon.getArg());
resultSetNavigationIcon.setResult(null);
return true;
case TOOLBAR_SET_OVERFLOW_MENU_ICON:
AsyncResult resultSetOverflowMenuIcon = (AsyncResult) msg.obj;
handleSetOverflowMenuIcon(resultSetOverflowMenuIcon.getArg());
resultSetOverflowMenuIcon.setResult(null);
return true;
case TOOLBAR_DISMISS_POPUP_MENUS:
AsyncResult resultDismissPopupMenus = ((AsyncResult) msg.obj);
handleDismissPopupMenus();
resultDismissPopupMenus.setResult(null);
return true;
case TOOLBAR_SET_TITLE:
AsyncResult setTitleResult = ((AsyncResult) msg.obj);
handleSetTitle(((String) setTitleResult.getArg()));
setTitleResult.setResult(null);
return true;
case TOOLBAR_SET_TITLE_TEXT_COLOR:
AsyncResult setTitleTextColorResult = ((AsyncResult) msg.obj);
handleSetTitleTextColor(((String) setTitleTextColorResult.getArg()));
setTitleTextColorResult.setResult(null);
return true;
case TOOLBAR_SET_SUBTITLE:
AsyncResult setSubtitleResult = ((AsyncResult) msg.obj);
handleSetSubtitle(((String) setSubtitleResult.getArg()));
setSubtitleResult.setResult(null);
return true;
case TOOLBAR_SET_SUBTITLE_TEXT_COLOR:
AsyncResult setSubtitleTextColorResult = ((AsyncResult) msg.obj);
handleSetSubtitleTextColor(((String) setSubtitleTextColorResult.getArg()));
setSubtitleTextColorResult.setResult(null);
return true;
case TOOLBAR_COLLAPSE_ACTION_VEIW:
AsyncResult collapseActionViewResult = ((AsyncResult) msg.obj);
handleCollapseActionView();
collapseActionViewResult.setResult(null);
return true;
case TOOLBAR_SET_CONTENT_INSET_END_WITH_ACTIONS:
AsyncResult setContentInsetEndWithActionResult = ((AsyncResult) msg.obj);
handleSetContentInsetEndWithActions((Integer) setContentInsetEndWithActionResult.getArg());
setContentInsetEndWithActionResult.setResult(null);
return true;
case TOOLBAR_SET_CONTENT_INSET_START_WITH_NAVIGATION:
AsyncResult setContentInsetStartWithNavigationResult = ((AsyncResult) msg.obj);
handleSetContentInsetStartWithNavigation((Integer) setContentInsetStartWithNavigationResult.getArg());
setContentInsetStartWithNavigationResult.setResult(null);
return true;
case TOOLBAR_SET_CONTENT_INSETS_ABSOLUTE:
AsyncResult setContentInsetsAbsoluteResult = ((AsyncResult) msg.obj);
handleSetContentInsetsAbsolute((Integer[]) setContentInsetsAbsoluteResult.getArg());
setContentInsetsAbsoluteResult.setResult(null);
return true;
case TOOLBAR_SET_CONTENT_INSETS_RELATIVE:
AsyncResult setContentInsetsRelativeResult = ((AsyncResult) msg.obj);
handleSetContentInsetsRelative(((Integer[]) setContentInsetsRelativeResult.getArg()));
setContentInsetsRelativeResult.setResult(null);
return true;
default:
return false;
}
}
}