Skip to content

Commit 41da188

Browse files
committed
Merge branch 'headless-develop' of github.com:spritebuilder/cocos2d-swift into headless-develop
2 parents 15f76a8 + 8e8a648 commit 41da188

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

cocos2d-tests-android/Headless/tests/CCTextFieldTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ - (void) setupTextFieldBasicTest
3434
textField.preferredSize = CGSizeMake(0.5, 50);
3535
textField.positionType = CCPositionTypeNormalized;
3636
textField.position = ccp(0.5f, 0.8f);
37-
textField.padding = 6;
37+
textField.padding = 10;
3838
textField.anchorPoint = ccp(0.5f, 0.5f);
3939
textField.string = @"Hello!";
4040

cocos2d-ui/Platform/Android/CCPlatformTextFieldAndroid.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#import "CCDirector.h"
1515
#import "CCEditText.h"
1616

17-
17+
1818
@implementation CCPlatformTextFieldAndroid {
1919
CCEditText *_editText;
2020
}
@@ -50,29 +50,28 @@ - (void) onExitTransitionDidStart
5050
- (void) positionInControl:(CCControl *)control padding:(float)padding {
5151
CGPoint worldPos = [control convertToWorldSpace:CGPointZero];
5252
CGPoint viewPos = [[CCDirector sharedDirector] convertToUI:worldPos];
53-
viewPos.x += padding;
54-
// viewPos.y += padding;
53+
5554

5655
CGFloat scale = [[CCDirector sharedDirector] contentScaleFactor];
5756

5857
viewPos.x *= scale;
5958
viewPos.y *= scale;
6059

6160
CGSize size = control.contentSizeInPoints;
62-
size.width -= padding * 2;
63-
size.height -= padding * 2;
6461
size.width *= scale;
6562
size.height *= scale ;
66-
viewPos.y -= size.height + padding *scale;
67-
63+
viewPos.y -= size.height;
64+
6865

6966
CGRect frame = CGRectZero;
7067
frame.origin = viewPos;
7168
frame.size = size;
69+
int nativePadding = (int)padding*scale;
7270
dispatch_async(dispatch_get_main_queue(), ^{
7371
AndroidViewGroupLayoutParams *oldParams = [_editText layoutParams];
7472
AndroidRelativeLayoutLayoutParams *params = [[AndroidRelativeLayoutLayoutParams alloc] initWithWidth:frame.size.width height:frame.size.height];
7573
[params setMargins:frame.origin.x top:frame.origin.y right:0 bottom:0];
74+
[_editText setPadding:nativePadding top:nativePadding right:nativePadding bottom:nativePadding];
7675
[_editText setLayoutParams:params];
7776
[_editText setImeOptions:AndroidEditorInfoIME_FLAG_NO_EXTRACT_UI];
7877

@@ -82,7 +81,7 @@ - (void) positionInControl:(CCControl *)control padding:(float)padding {
8281
if ([[weakSelf delegate] respondsToSelector:@selector(platformTextFieldDidFinishEditing:)]) {
8382
[[weakSelf delegate] platformTextFieldDidFinishEditing:weakSelf];
8483
}
85-
84+
8685
}];
8786
});
8887
}
@@ -106,12 +105,12 @@ - (void)setFontSize:(float)fontSize {
106105
dispatch_async(dispatch_get_main_queue(), ^{
107106
// AndroidDisplayMetrics *metrics = [[AndroidDisplayMetrics alloc] init];
108107
// [[CCActivity currentActivity].windowManager.defaultDisplay getMetrics:metrics];
109-
108+
110109
[_editText setTextSizeDouble:fontSize];
111-
110+
112111
});
113-
114-
112+
113+
115114
}
116115

117116
- (void)setString:(NSString *)string {

cocos2d/CCConfiguration.m

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,34 @@ -(NSInteger) runningDevice
146146
NSInteger ret=-1;
147147

148148
#if __CC_PLATFORM_ANDROID
149-
if([CCDirector sharedDirector].contentScaleFactor > 1.0)
150-
{
151-
ret = CCDeviceiPhoneRetinaDisplay;
152-
}
153-
else
154-
{
155-
ret = CCDeviceiPhone;
149+
150+
151+
AndroidDisplayMetrics *metrics = [[AndroidDisplayMetrics alloc] init];
152+
[[CCActivity currentActivity].windowManager.defaultDisplay getMetrics:metrics];
153+
double yInches= metrics.heightPixels/metrics.ydpi;
154+
double xInches= metrics.widthPixels/metrics.xdpi;
155+
double diagonalInches = sqrt(xInches*xInches + yInches*yInches);
156+
if (diagonalInches<=6){
157+
158+
159+
if([CCDirector sharedDirector].contentScaleFactor > 1.0)
160+
{
161+
ret = CCDeviceiPhoneRetinaDisplay;
162+
}
163+
else
164+
{
165+
ret = CCDeviceiPhone;
166+
}
167+
} else {
168+
if([CCDirector sharedDirector].contentScaleFactor > 1.0)
169+
{
170+
ret = CCDeviceiPadRetinaDisplay;
171+
}
172+
else
173+
{
174+
ret = CCDeviceiPad;
175+
}
176+
156177
}
157178
#elif __CC_PLATFORM_IOS
158179

external/ObjectAL/OALSimpleAudio.m

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -659,31 +659,11 @@ - (void) unloadAllEffects
659659
return nil;
660660
}
661661

662-
#if 0 // __CC_PLATFORM_ANDROID
663-
// TODO: we are creating a player and throwing it away each time, and not taking into account if it was preloaded.
664-
// think about checking for preload and implement the player's asyncPrepare finish listener
665-
AndroidAssetFileDescriptor *assetFd = [[[CCActivity currentActivity] assets] openFdWithFileName:filePath];
666-
667-
if (assetFd.fileDescriptor && [assetFd.fileDescriptor valid]) {
668-
AndroidMediaPlayer *player = [[AndroidMediaPlayer alloc] init];
669-
[player reset];
670-
[player setDataSource:assetFd.fileDescriptor offset:assetFd.startOffset length:assetFd.length];
671-
#warning TODO: note sure how to set on finished listener for player and call the player's release() (not objc release) in the callback to close fd
672-
[player prepare];
673-
[player start];
674-
}
675-
676-
if (assetFd) {
677-
[assetFd close];
678-
}
679-
// TODO: convert to ALSoundSource and return
680-
#else
681662
ALBuffer* buffer = [self internalPreloadEffect:filePath reduceToMono:NO];
682663
if(nil != buffer)
683664
{
684665
return [channel play:buffer gain:volume pitch:pitch pan:pan loop:loop];
685666
}
686-
#endif
687667
return nil;
688668
}
689669

0 commit comments

Comments
 (0)