forked from tidev/titanium-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowProxy.java
643 lines (577 loc) 路 20.7 KB
/
WindowProxy.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
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2013 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;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiActivity;
import org.appcelerator.titanium.TiActivityWindow;
import org.appcelerator.titanium.TiActivityWindows;
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.TiWindowProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.view.TiUIView;
import ti.modules.titanium.ui.widget.TiView;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;
import android.transition.ChangeBounds;
import android.transition.ChangeClipBounds;
import android.transition.ChangeImageTransform;
import android.transition.ChangeTransform;
import android.transition.Explode;
import android.transition.Fade;
import android.transition.Slide;
import android.transition.Transition;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
// clang-format off
@Kroll.proxy(creatableInModule = UIModule.class,
propertyAccessors = {
TiC.PROPERTY_MODAL,
TiC.PROPERTY_WINDOW_PIXEL_FORMAT,
TiC.PROPERTY_FLAG_SECURE
})
// clang-format on
public class WindowProxy extends TiWindowProxy implements TiActivityWindow
{
private static final String TAG = "WindowProxy";
private static final String PROPERTY_POST_WINDOW_CREATED = "postWindowCreated";
private static final int MSG_FIRST_ID = TiWindowProxy.MSG_LAST_ID + 1;
private static final int MSG_SET_PIXEL_FORMAT = MSG_FIRST_ID + 100;
private static final int MSG_SET_TITLE = MSG_FIRST_ID + 101;
private static final int MSG_SET_WIDTH_HEIGHT = MSG_FIRST_ID + 102;
protected static final int MSG_LAST_ID = MSG_FIRST_ID + 999;
private WeakReference<TiBaseActivity> windowActivity;
public WindowProxy()
{
super();
defaultValues.put(TiC.PROPERTY_WINDOW_PIXEL_FORMAT, PixelFormat.UNKNOWN);
defaultValues.put(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE, false);
}
@Override
protected KrollDict getLangConversionTable()
{
KrollDict table = new KrollDict();
table.put(TiC.PROPERTY_TITLE, TiC.PROPERTY_TITLEID);
return table;
}
@Override
public TiUIView createView(Activity activity)
{
TiUIView v = new TiView(this);
v.getLayoutParams().autoFillsHeight = true;
v.getLayoutParams().autoFillsWidth = true;
setView(v);
return v;
}
@Override
public void open(@Kroll.argument(optional = true) Object arg)
{
HashMap<String, Object> option = null;
if (arg instanceof HashMap) {
option = (HashMap<String, Object>) arg;
}
if (option != null) {
properties.putAll(option);
}
if (hasProperty(TiC.PROPERTY_ORIENTATION_MODES)) {
Object obj = getProperty(TiC.PROPERTY_ORIENTATION_MODES);
if (obj instanceof Object[]) {
orientationModes = TiConvert.toIntArray((Object[]) obj);
}
}
// The "top", "bottom", "left" and "right" properties do not work for heavyweight windows.
properties.remove(TiC.PROPERTY_TOP);
properties.remove(TiC.PROPERTY_BOTTOM);
properties.remove(TiC.PROPERTY_LEFT);
properties.remove(TiC.PROPERTY_RIGHT);
super.open(arg);
}
@Override
public void close(@Kroll.argument(optional = true) Object arg)
{
if (!(opened || opening)) {
return;
}
super.close(arg);
}
@Override
protected void handleOpen(KrollDict options)
{
Activity topActivity = TiApplication.getAppCurrentActivity();
// Don't open if app is closing or closed
if (topActivity == null || topActivity.isFinishing()) {
return;
}
Intent intent = new Intent(topActivity, TiActivity.class);
fillIntent(topActivity, intent);
int windowId = TiActivityWindows.addWindow(this);
intent.putExtra(TiC.INTENT_PROPERTY_USE_ACTIVITY_WINDOW, true);
intent.putExtra(TiC.INTENT_PROPERTY_WINDOW_ID, windowId);
boolean animated = TiConvert.toBoolean(options, TiC.PROPERTY_ANIMATED, true);
if (!animated) {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
topActivity.startActivity(intent);
topActivity.overridePendingTransition(0, 0);
} else if (options.containsKey(TiC.PROPERTY_ACTIVITY_ENTER_ANIMATION)
|| options.containsKey(TiC.PROPERTY_ACTIVITY_EXIT_ANIMATION)) {
topActivity.startActivity(intent);
int enterAnimation = TiConvert.toInt(options.get(TiC.PROPERTY_ACTIVITY_ENTER_ANIMATION), 0);
int exitAnimation = TiConvert.toInt(options.get(TiC.PROPERTY_ACTIVITY_EXIT_ANIMATION), 0);
topActivity.overridePendingTransition(enterAnimation, exitAnimation);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
topActivity.startActivity(intent, createActivityOptionsBundle(topActivity));
} else {
topActivity.startActivity(intent);
}
}
if (options.containsKey(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE)) {
setSustainedPerformanceMode((Boolean) options.get(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE));
}
}
@Override
protected void handleClose(KrollDict options)
{
boolean animated = TiConvert.toBoolean(options, TiC.PROPERTY_ANIMATED, true);
TiBaseActivity activity = (windowActivity != null) ? windowActivity.get() : null;
if (activity != null && !activity.isFinishing()) {
if (super.hasActivityTransitions()) {
activity.finishAfterTransition();
} else {
activity.finish();
}
if (!animated) {
activity.overridePendingTransition(0, 0);
} else if (options.containsKey(TiC.PROPERTY_ACTIVITY_ENTER_ANIMATION)
|| options.containsKey(TiC.PROPERTY_ACTIVITY_EXIT_ANIMATION)) {
int enterAnimation = TiConvert.toInt(options.get(TiC.PROPERTY_ACTIVITY_ENTER_ANIMATION), 0);
int exitAnimation = TiConvert.toInt(options.get(TiC.PROPERTY_ACTIVITY_EXIT_ANIMATION), 0);
activity.overridePendingTransition(enterAnimation, exitAnimation);
}
// Finishing an activity is not synchronous, so we remove the activity from the activity stack here
TiApplication.removeFromActivityStack(activity);
windowActivity = null;
}
}
@SuppressWarnings("unchecked")
@Override
public void windowCreated(TiBaseActivity activity, Bundle savedInstanceState)
{
windowActivity = new WeakReference<TiBaseActivity>(activity);
activity.setWindowProxy(this);
setActivity(activity);
// Handle the "activity" property.
ActivityProxy activityProxy = activity.getActivityProxy();
KrollDict options = null;
if (hasProperty(TiC.PROPERTY_ACTIVITY)) {
Object activityObject = getProperty(TiC.PROPERTY_ACTIVITY);
if (activityObject instanceof HashMap<?, ?>) {
options = new KrollDict((HashMap<String, Object>) activityObject);
activityProxy.handleCreationDict(options);
}
}
Window win = activity.getWindow();
// Handle the background of the window activity if it is a translucent activity.
// If it is a modal window, set a translucent dimmed background to the window.
// If the opacity is given, set a transparent background to the window. In this case, if no backgroundColor or
// backgroundImage is given, the window will be completely transparent.
boolean modal = TiConvert.toBoolean(getProperty(TiC.PROPERTY_MODAL), false);
Drawable background = null;
if (modal) {
background = new ColorDrawable(0x9F000000);
} else if (hasProperty(TiC.PROPERTY_OPACITY)) {
background = new ColorDrawable(0x00000000);
}
if (background != null) {
win.setBackgroundDrawable(background);
}
// Handle activity transitions
if (LOLLIPOP_OR_GREATER) {
applyActivityTransitions(win, properties);
}
// Handle the width and height of the window.
// TODO: If width / height is a percentage value, we can not get the dimension in pixel because
// the width / height of the decor view is not measured yet at this point. So we can not use the
// getAsPixels() method. Maybe we can use WindowManager.getDefaultDisplay.getRectSize(rect) to
// get the application display dimension.
if (hasProperty(TiC.PROPERTY_WIDTH) || hasProperty(TiC.PROPERTY_HEIGHT)) {
Object width = getProperty(TiC.PROPERTY_WIDTH);
Object height = getProperty(TiC.PROPERTY_HEIGHT);
View decorView = win.getDecorView();
if (decorView != null) {
int w = LayoutParams.MATCH_PARENT;
if (!(width == null || width.equals(TiC.LAYOUT_FILL))) {
TiDimension wDimension = TiConvert.toTiDimension(width, TiDimension.TYPE_WIDTH);
if (!wDimension.isUnitPercent()) {
w = wDimension.getAsPixels(decorView);
}
}
int h = LayoutParams.MATCH_PARENT;
if (!(height == null || height.equals(TiC.LAYOUT_FILL))) {
TiDimension hDimension = TiConvert.toTiDimension(height, TiDimension.TYPE_HEIGHT);
if (!hDimension.isUnitPercent()) {
h = hDimension.getAsPixels(decorView);
}
}
win.setLayout(w, h);
}
}
activity.getActivityProxy().getDecorView().add(this);
activity.addWindowToStack(this);
// Need to handle the cached activity proxy properties and url window in the JS side.
callPropertySync(PROPERTY_POST_WINDOW_CREATED, null);
}
@Override
public void onWindowActivityCreated()
{
// Fire the open event after setContentView() because getActionBar() need to be called
// after setContentView(). (TIMOB-14914)
opened = true;
opening = false;
fireEvent(TiC.EVENT_OPEN, null);
handlePostOpen();
super.onWindowActivityCreated();
}
@Override
protected Activity getWindowActivity()
{
return (windowActivity != null) ? windowActivity.get() : null;
}
private void fillIntent(Activity activity, Intent intent)
{
int windowFlags = 0;
if (hasProperty(TiC.PROPERTY_WINDOW_FLAGS)) {
windowFlags = TiConvert.toInt(getProperty(TiC.PROPERTY_WINDOW_FLAGS), 0);
}
//Set the fullscreen flag
if (hasProperty(TiC.PROPERTY_FULLSCREEN)) {
boolean flagVal = TiConvert.toBoolean(getProperty(TiC.PROPERTY_FULLSCREEN), false);
if (flagVal) {
windowFlags = windowFlags | WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
}
//Set the secure flag
if (hasProperty(TiC.PROPERTY_FLAG_SECURE)) {
boolean flagVal = TiConvert.toBoolean(getProperty(TiC.PROPERTY_FLAG_SECURE), false);
if (flagVal) {
windowFlags = windowFlags | WindowManager.LayoutParams.FLAG_SECURE;
}
}
//Stuff flags in intent
intent.putExtra(TiC.PROPERTY_WINDOW_FLAGS, windowFlags);
if (hasProperty(TiC.PROPERTY_WINDOW_SOFT_INPUT_MODE)) {
intent.putExtra(TiC.PROPERTY_WINDOW_SOFT_INPUT_MODE,
TiConvert.toInt(getProperty(TiC.PROPERTY_WINDOW_SOFT_INPUT_MODE), -1));
}
if (hasProperty(TiC.PROPERTY_EXIT_ON_CLOSE)) {
intent.putExtra(TiC.INTENT_PROPERTY_FINISH_ROOT,
TiConvert.toBoolean(getProperty(TiC.PROPERTY_EXIT_ON_CLOSE), false));
} else {
intent.putExtra(TiC.INTENT_PROPERTY_FINISH_ROOT, activity.isTaskRoot());
}
boolean modal = false;
if (hasProperty(TiC.PROPERTY_MODAL)) {
modal = TiConvert.toBoolean(getProperty(TiC.PROPERTY_MODAL), false);
if (modal) {
intent.setClass(activity, TiTranslucentActivity.class);
}
intent.putExtra(TiC.PROPERTY_MODAL, modal);
}
if (!modal && hasProperty(TiC.PROPERTY_OPACITY)) {
intent.setClass(activity, TiTranslucentActivity.class);
} else if (hasProperty(TiC.PROPERTY_BACKGROUND_COLOR)) {
int bgColor = TiConvert.toColor(properties, TiC.PROPERTY_BACKGROUND_COLOR);
if (Color.alpha(bgColor) < 0xFF) {
intent.setClass(activity, TiTranslucentActivity.class);
}
}
if (hasProperty(TiC.PROPERTY_WINDOW_PIXEL_FORMAT)) {
intent.putExtra(TiC.PROPERTY_WINDOW_PIXEL_FORMAT,
TiConvert.toInt(getProperty(TiC.PROPERTY_WINDOW_PIXEL_FORMAT), PixelFormat.UNKNOWN));
}
if (hasProperty(TiC.PROPERTY_EXTEND_SAFE_AREA)) {
boolean value = TiConvert.toBoolean(getProperty(TiC.PROPERTY_EXTEND_SAFE_AREA), false);
intent.putExtra(TiC.PROPERTY_EXTEND_SAFE_AREA, value);
}
// Set the theme property
if (hasProperty(TiC.PROPERTY_THEME)) {
String theme = TiConvert.toString(getProperty(TiC.PROPERTY_THEME));
if (theme != null) {
try {
intent.putExtra(TiC.PROPERTY_THEME,
TiRHelper.getResource("style." + theme.replaceAll("[^A-Za-z0-9_]", "_")));
} catch (Exception e) {
Log.w(TAG, "Cannot find the theme: " + theme);
}
}
}
// Set the splitActionBar property
if (hasProperty(TiC.PROPERTY_SPLIT_ACTIONBAR)) {
boolean splitActionBar = TiConvert.toBoolean(getProperty(TiC.PROPERTY_SPLIT_ACTIONBAR), false);
if (splitActionBar) {
intent.putExtra(TiC.PROPERTY_SPLIT_ACTIONBAR, splitActionBar);
}
}
}
@Override
public void onPropertyChanged(String name, Object value)
{
if (opening || opened) {
if (TiC.PROPERTY_WINDOW_PIXEL_FORMAT.equals(name)) {
getMainHandler().obtainMessage(MSG_SET_PIXEL_FORMAT, value).sendToTarget();
} else if (TiC.PROPERTY_TITLE.equals(name)) {
getMainHandler().obtainMessage(MSG_SET_TITLE, value).sendToTarget();
} else if (TiC.PROPERTY_TOP.equals(name) || TiC.PROPERTY_BOTTOM.equals(name)
|| TiC.PROPERTY_LEFT.equals(name) || TiC.PROPERTY_RIGHT.equals(name)) {
// The "top", "bottom", "left" and "right" properties do not work for heavyweight windows.
return;
} else if (TiC.PROPERTY_EXIT_ON_CLOSE.equals(name)) {
Activity activity = (windowActivity != null) ? (Activity) (windowActivity.get()) : null;
if (activity != null) {
Intent intent = activity.getIntent();
intent.putExtra(TiC.INTENT_PROPERTY_FINISH_ROOT, TiConvert.toBoolean(value));
}
}
}
super.onPropertyChanged(name, value);
}
// clang-format off
@Kroll.method
@Kroll.setProperty
public void setSustainedPerformanceMode(boolean mode)
// clang-format on
{
setProperty(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE, mode);
windowActivity.get().setSustainMode(mode);
}
// clang-format off
@Kroll.method
@Kroll.getProperty
public boolean getSustainedPerformanceMode()
// clang-format on
{
return TiConvert.toBoolean(getProperty(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE), false);
}
// clang-format off
@Override
@Kroll.setProperty(retain = false)
@Kroll.method
public void setWidth(Object width)
// clang-format on
{
if (opening || opened) {
Object current = getProperty(TiC.PROPERTY_WIDTH);
if (shouldFireChange(current, width)) {
Object height = getProperty(TiC.PROPERTY_HEIGHT);
if (TiApplication.isUIThread()) {
setWindowWidthHeight(width, height);
} else {
getMainHandler().obtainMessage(MSG_SET_WIDTH_HEIGHT, new Object[] { width, height }).sendToTarget();
}
}
}
super.setWidth(width);
}
// clang-format off
@Override
@Kroll.setProperty(retain = false)
@Kroll.method
public void setHeight(Object height)
// clang-format on
{
if (opening || opened) {
Object current = getProperty(TiC.PROPERTY_HEIGHT);
if (shouldFireChange(current, height)) {
Object width = getProperty(TiC.PROPERTY_WIDTH);
if (TiApplication.isUIThread()) {
setWindowWidthHeight(width, height);
} else {
getMainHandler().obtainMessage(MSG_SET_WIDTH_HEIGHT, new Object[] { width, height }).sendToTarget();
}
}
}
super.setHeight(height);
}
@Override
public boolean handleMessage(Message msg)
{
switch (msg.what) {
case MSG_SET_PIXEL_FORMAT: {
Activity activity = getWindowActivity();
if (activity != null) {
Window win = activity.getWindow();
if (win != null) {
win.setFormat(TiConvert.toInt((Object) (msg.obj), PixelFormat.UNKNOWN));
win.getDecorView().invalidate();
}
}
return true;
}
case MSG_SET_TITLE: {
Activity activity = getWindowActivity();
if (activity != null) {
activity.setTitle(TiConvert.toString((Object) (msg.obj), ""));
}
return true;
}
case MSG_SET_WIDTH_HEIGHT: {
Object[] obj = (Object[]) msg.obj;
setWindowWidthHeight(obj[0], obj[1]);
return true;
}
}
return super.handleMessage(msg);
}
private void setWindowWidthHeight(Object width, Object height)
{
Activity activity = getWindowActivity();
if (activity != null) {
Window win = activity.getWindow();
if (win != null) {
View decorView = win.getDecorView();
if (decorView != null) {
int w = LayoutParams.MATCH_PARENT;
if (!(width == null || width.equals(TiC.LAYOUT_FILL))) {
TiDimension wDimension = TiConvert.toTiDimension(width, TiDimension.TYPE_WIDTH);
if (!wDimension.isUnitPercent()) {
w = wDimension.getAsPixels(decorView);
}
}
int h = LayoutParams.MATCH_PARENT;
if (!(height == null || height.equals(TiC.LAYOUT_FILL))) {
TiDimension hDimension = TiConvert.toTiDimension(height, TiDimension.TYPE_HEIGHT);
if (!hDimension.isUnitPercent()) {
h = hDimension.getAsPixels(decorView);
}
}
win.setLayout(w, h);
}
}
}
}
/**
* Helper method to apply activity transitions.
* @param win The window holding the activity.
* @param props The property dictionary.
*/
private void applyActivityTransitions(Window win, KrollDict props)
{
if (LOLLIPOP_OR_GREATER) {
// Return and reenter transitions defaults to enter and exit transitions respectively only if they are not set.
// And setting a null transition makes the view unaccounted from transition.
if (props.containsKeyAndNotNull(TiC.PROPERTY_ENTER_TRANSITION)) {
win.setEnterTransition(createTransition(props, TiC.PROPERTY_ENTER_TRANSITION));
}
if (props.containsKeyAndNotNull(TiC.PROPERTY_EXIT_TRANSITION)) {
win.setExitTransition(createTransition(props, TiC.PROPERTY_EXIT_TRANSITION));
}
if (props.containsKeyAndNotNull(TiC.PROPERTY_RETURN_TRANSITION)) {
win.setReturnTransition(createTransition(props, TiC.PROPERTY_RETURN_TRANSITION));
}
if (props.containsKeyAndNotNull(TiC.PROPERTY_REENTER_TRANSITION)) {
win.setReenterTransition(createTransition(props, TiC.PROPERTY_REENTER_TRANSITION));
}
if (props.containsKeyAndNotNull(TiC.PROPERTY_SHARED_ELEMENT_ENTER_TRANSITION)) {
win.setSharedElementEnterTransition(
createTransition(props, TiC.PROPERTY_SHARED_ELEMENT_ENTER_TRANSITION));
}
if (props.containsKeyAndNotNull(TiC.PROPERTY_SHARED_ELEMENT_EXIT_TRANSITION)) {
win.setSharedElementExitTransition(
createTransition(props, TiC.PROPERTY_SHARED_ELEMENT_EXIT_TRANSITION));
}
if (props.containsKeyAndNotNull(TiC.PROPERTY_SHARED_ELEMENT_REENTER_TRANSITION)) {
win.setSharedElementReenterTransition(
createTransition(props, TiC.PROPERTY_SHARED_ELEMENT_REENTER_TRANSITION));
}
if (props.containsKeyAndNotNull(TiC.PROPERTY_SHARED_ELEMENT_RETURN_TRANSITION)) {
win.setSharedElementReturnTransition(
createTransition(props, TiC.PROPERTY_SHARED_ELEMENT_RETURN_TRANSITION));
}
}
}
/**
* Creates a transition for the supplied transition type.
* @param props The property dictionary.
* @param key The transition type
* @return A Transition or null if UIModule.TRANSITION_NONE or unknown transition is specified.
*/
@SuppressLint({ "InlinedApi", "RtlHardcoded" })
@Nullable
private Transition createTransition(KrollDict props, String key)
{
if (LOLLIPOP_OR_GREATER) {
Transition t = null;
final int transitionType = props.getInt(key);
switch (transitionType) {
case TiUIView.TRANSITION_EXPLODE:
t = new Explode();
break;
case TiUIView.TRANSITION_FADE_IN:
t = new Fade(Fade.IN);
break;
case TiUIView.TRANSITION_FADE_OUT:
t = new Fade(Fade.OUT);
break;
case TiUIView.TRANSITION_SLIDE_TOP:
t = new Slide(Gravity.TOP);
break;
case TiUIView.TRANSITION_SLIDE_RIGHT:
t = new Slide(Gravity.RIGHT);
break;
case TiUIView.TRANSITION_SLIDE_BOTTOM:
t = new Slide(Gravity.BOTTOM);
break;
case TiUIView.TRANSITION_SLIDE_LEFT:
t = new Slide(Gravity.LEFT);
break;
case TiUIView.TRANSITION_CHANGE_BOUNDS:
t = new ChangeBounds();
break;
case TiUIView.TRANSITION_CHANGE_CLIP_BOUNDS:
t = new ChangeClipBounds();
break;
case TiUIView.TRANSITION_CHANGE_TRANSFORM:
t = new ChangeTransform();
break;
case TiUIView.TRANSITION_CHANGE_IMAGE_TRANSFORM:
t = new ChangeImageTransform();
break;
default:
break;
}
return t;
} else {
return null;
}
}
@Override
public String getApiName()
{
return "Ti.UI.Window";
}
}