-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPopoverProxy.java
160 lines (136 loc) · 5.62 KB
/
PopoverProxy.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
/**
* This file was auto-generated by the Titanium Module SDK helper for Android
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2017 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.popover;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import com.skydoves.balloon.ArrowOrientation;
import com.skydoves.balloon.ArrowPositionRules;
import com.skydoves.balloon.Balloon;
import com.skydoves.balloon.BalloonAnimation;
import com.skydoves.balloon.BalloonSizeSpec;
import com.skydoves.balloon.OnBalloonClickListener;
import com.skydoves.balloon.OnBalloonDismissListener;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiUIView;
import ti.modules.titanium.ui.ViewProxy;
// This proxy can be created by calling TiPopover.createExample({message: "hello world"})
@Kroll.proxy(creatableInModule = TiPopoverModule.class)
public class PopoverProxy extends TiViewProxy {
// Standard Debugging variables
private static final String LCAT = "ExampleProxy";
private static final boolean DBG = TiConfig.LOGD;
Balloon balloon = null;
View targetView;
int direction;
int arrowColor;
int arrowSize;
ViewProxy contentView = null;
View customView = null;
ViewProxy view = null;
PopoverView pview;
// Constructor
public PopoverProxy() {
super();
}
@Override
public TiUIView createView(Activity activity) {
pview = new PopoverView(this);
return pview;
}
// Handle creation options
@Override
public void handleCreationDict(KrollDict options) {
super.handleCreationDict(options);
arrowColor = TiConvert.toColor((String) options.get("arrowColor"));
arrowSize = TiConvert.toInt(options.get("arrowSize"), 10);
}
// Methods
@Kroll.method
public void show(KrollDict options) {
LifecycleOwner lifecycle = (LifecycleOwner) TiApplication.getAppCurrentActivity();
if (pview != null && customView == null) {
customView = pview.getPopView().getRootView();
}
ViewGroup parentView = (ViewGroup) customView.getParent();
if (parentView != null) {
parentView.removeView(customView);
}
if (options.containsKey("view")) {
view = (ViewProxy) options.get("view");
targetView = view.getOrCreateView().getNativeView();
}
direction = options.getInt("direction");
ArrowOrientation orientation = ArrowOrientation.BOTTOM;
if (direction == TiPopoverModule.POPOVER_ARROW_DIRECTION_DOWN) {
orientation = ArrowOrientation.BOTTOM;
} else if (direction == TiPopoverModule.POPOVER_ARROW_DIRECTION_UP) {
orientation = ArrowOrientation.TOP;
} else if (direction == TiPopoverModule.POPOVER_ARROW_DIRECTION_LEFT) {
orientation = ArrowOrientation.RIGHT;
} else if (direction == TiPopoverModule.POPOVER_ARROW_DIRECTION_RIGHT) {
orientation = ArrowOrientation.LEFT;
}
if (balloon != null) {
balloon.dismiss();
balloon.clearAllPreferences();
balloon = null;
}
Balloon.Builder balloonBuilder = new Balloon.Builder(TiApplication.getAppCurrentActivity())
.setArrowSize(arrowSize)
.setArrowOrientation(orientation)
.setArrowPositionRules(ArrowPositionRules.ALIGN_BALLOON)
.setArrowPosition(0.5f)
.setWidth(BalloonSizeSpec.WRAP)
.setHeight(BalloonSizeSpec.WRAP)
.setCornerRadius(4f)
.setAlpha(0.9f)
.setArrowColor(arrowColor)
.setOnBalloonClickListener(new OnBalloonClickListener() {
@Override
public void onBalloonClick(@NonNull View view) {
fireEvent("click", new KrollDict());
}
})
.setOnBalloonDismissListener(new OnBalloonDismissListener() {
@Override
public void onBalloonDismiss() {
fireEvent("close", new KrollDict());
}
})
.setBalloonAnimation(BalloonAnimation.ELASTIC)
.setLifecycleOwner(lifecycle);
if (customView != null) {
balloonBuilder.setLayout(customView);
}
balloon = balloonBuilder.build();
if (targetView != null) {
if (direction == TiPopoverModule.POPOVER_ARROW_DIRECTION_DOWN) {
balloon.showAlignTop(targetView);
} else if (direction == TiPopoverModule.POPOVER_ARROW_DIRECTION_UP) {
balloon.showAlignBottom(targetView);
} else if (direction == TiPopoverModule.POPOVER_ARROW_DIRECTION_LEFT) {
balloon.showAlignLeft(targetView);
} else if (direction == TiPopoverModule.POPOVER_ARROW_DIRECTION_RIGHT) {
balloon.showAlignRight(targetView);
} else {
balloon.showAsDropDown(targetView);
}
} else {
Log.e(LCAT, "You must set attachTo");
}
}
}