14
14
#import " CCDirector.h"
15
15
#import " CCEditText.h"
16
16
17
- extern void objc_retain (id );
18
-
19
-
20
- typedef void (^CCPlatformTextFieldAndroidTextViewOnEditorActionListenerCompletionBlock)(void );
21
-
22
-
23
- BRIDGE_CLASS (" org.cocos2d.CCPlatformTextFieldAndroidTextViewOnEditorActionListener" )
24
- @interface CCPlatformTextFieldAndroidTextViewOnEditorActionListener : JavaObject<AndroidTextViewOnEditorActionListener>
25
- - (BOOL )onEditorAction:(AndroidTextView *)v actionId:(int32_t )actionId keyEvent:(AndroidKeyEvent *)event;
26
-
27
- @end
28
- @implementation CCPlatformTextFieldAndroidTextViewOnEditorActionListener {
29
- CCPlatformTextFieldAndroidTextViewOnEditorActionListenerCompletionBlock _completionBlock;
30
- }
31
-
32
- - (id ) initWithCompletionBlock : (CCPlatformTextFieldAndroidTextViewOnEditorActionListenerCompletionBlock)completionBlock {
33
- if (self = [super init ]) {
34
- _completionBlock = [completionBlock copy ];
35
- }
36
- return self;
37
-
38
- }
39
-
40
- @bridge(callback) onEditorAction:actionId:keyEvent: = onEditorAction;
41
- - (BOOL )onEditorAction : (AndroidTextView *)v actionId : (int32_t )actionId keyEvent : (AndroidKeyEvent *)event {
42
- if (actionId == AndroidEditorInfoIME_ACTION_SEARCH ||
43
- actionId == AndroidEditorInfoIME_ACTION_DONE
44
- // || [event action] == KeyEvent.ACTION_DOWN && [event keyCode] == ANDROID_KEYCODE_ENTER
45
- ) {
46
- _completionBlock ();
47
- } else {
48
- NSLog (@" nothing" );
49
- }
50
- return NO ;
51
- }
52
-
53
- @end
54
17
55
18
@implementation CCPlatformTextFieldAndroid {
56
19
CCEditText *_editText;
@@ -68,6 +31,11 @@ - (id) init {
68
31
return self;
69
32
}
70
33
34
+ - (void )dealloc
35
+ {
36
+ _editText = nil ;
37
+ }
38
+
71
39
72
40
- (void )onEnterTransitionDidFinish {
73
41
[super onEnterTransitionDidFinish ];
@@ -106,13 +74,16 @@ - (void) positionInControl:(CCControl *)control padding:(float)padding {
106
74
AndroidRelativeLayoutLayoutParams *params = [[AndroidRelativeLayoutLayoutParams alloc ] initWithWidth: frame.size.width height: frame.size.height];
107
75
[params setMargins: frame.origin.x top: frame.origin.y right: 0 bottom: 0 ];
108
76
[_editText setLayoutParams: params];
77
+ [_editText setImeOptions: AndroidEditorInfoIME_FLAG_NO_EXTRACT_UI];
78
+
109
79
110
- [_editText setOnEditorActionListener: [[CCPlatformTextFieldAndroidTextViewOnEditorActionListener alloc ] initWithCompletionBlock: ^{
111
- if ([[self delegate ] respondsToSelector: @selector (platformTextFieldDidFinishEditing: )]) {
112
- [[self delegate ] platformTextFieldDidFinishEditing: self ];
80
+ __weak id weakSelf = self;
81
+ [_editText setCompletionBlock: ^{
82
+ if ([[weakSelf delegate ] respondsToSelector: @selector (platformTextFieldDidFinishEditing: )]) {
83
+ [[weakSelf delegate ] platformTextFieldDidFinishEditing: weakSelf];
113
84
}
114
85
115
- }]] ;
86
+ }];
116
87
});
117
88
}
118
89
@@ -153,4 +124,6 @@ - (void)setString:(NSString *)string {
153
124
- (NSString *)string {
154
125
return _editText.text ;
155
126
}
127
+
128
+
156
129
@end
0 commit comments