[android] fixed #496 fixed #497: tests and HelloWorld work ok on Android3.0

This commit is contained in:
minggo 2011-05-19 11:26:57 +08:00
parent f44e8a76d0
commit 073260e0a9
6 changed files with 50 additions and 160 deletions

View File

@ -69,9 +69,6 @@ bool AppDelegate::applicationDidFinishLaunching()
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
// pDirector->enableRetinaDisplay(true); // pDirector->enableRetinaDisplay(true);
// sets opengl landscape mode
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// turn on display FPS // turn on display FPS
pDirector->setDisplayFPS(true); pDirector->setDisplayFPS(true);

View File

@ -6,7 +6,7 @@
<application android:label="@string/app_name" android:debuggable="true"> <application android:label="@string/app_name" android:debuggable="true">
<activity android:name=".ApplicationDemo" <activity android:name=".ApplicationDemo"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="portrait" android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -14,4 +14,8 @@
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
<supports-screens android:largeScreens="true"
android:smallScreens="true"
android:anyDensity="true"
android:normalScreens="true"/>
</manifest> </manifest>

View File

@ -2,21 +2,20 @@ package org.cocos2dx.lib;
import android.content.Context; import android.content.Context;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText; import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
class Cocos2dxInputConnection implements InputConnection { class Cocos2dxInputConnection extends BaseInputConnection {
private boolean mDebug = false; private static final boolean mDebug = false;
void LogD(String msg) { void LogD(String msg) {
if (mDebug) { if (mDebug) {
Log.d("Cocos2dxInputConnection", msg); Log.d("Cocos2dxInputConnection", msg);
@ -26,59 +25,19 @@ class Cocos2dxInputConnection implements InputConnection {
private Cocos2dxGLSurfaceView mView; private Cocos2dxGLSurfaceView mView;
Cocos2dxInputConnection(Cocos2dxGLSurfaceView view) { Cocos2dxInputConnection(Cocos2dxGLSurfaceView view) {
super(view, false);
mView = view; mView = view;
} }
@Override
public boolean beginBatchEdit() {
LogD("beginBatchEdit");
return false;
}
@Override
public boolean clearMetaKeyStates(int states) {
LogD("clearMetaKeyStates: " + states);
return false;
}
@Override
public boolean commitCompletion(CompletionInfo text) {
LogD("commitCompletion: " + text.getText().toString());
return false;
}
@Override @Override
public boolean commitText(CharSequence text, int newCursorPosition) { public boolean commitText(CharSequence text, int newCursorPosition) {
super.commitText(text, newCursorPosition);
if (null != mView) { if (null != mView) {
final String insertText = text.toString(); final String insertText = text.toString();
mView.insertText(insertText); mView.insertText(insertText);
LogD("commitText: " + insertText); LogD("commitText: " + insertText);
} }
return false; return true;
}
@Override
public boolean deleteSurroundingText(int leftLength, int rightLength) {
LogD("deleteSurroundingText: " + leftLength + "," + rightLength);
return false;
}
@Override
public boolean endBatchEdit() {
LogD("endBatchEdit");
return false;
}
@Override
public boolean finishComposingText() {
LogD("finishComposingText");
return false;
}
@Override
public int getCursorCapsMode(int reqModes) {
LogD("getCursorCapsMode: " + reqModes);
return 0;
} }
@Override @Override
@ -88,24 +47,6 @@ class Cocos2dxInputConnection implements InputConnection {
return new ExtractedText(); return new ExtractedText();
} }
@Override
public CharSequence getTextAfterCursor(int n, int flags) {
LogD("getTextAfterCursor: " + n + "," + flags);
return null;
}
@Override
public CharSequence getTextBeforeCursor(int n, int flags) {
LogD("getTextBeforeCursor: " + n + "," + flags);
return null;
}
@Override
public boolean performContextMenuAction(int id) {
Log.d("Cocos2dxInputConnection", "performContextMenuAction");
return false;
}
@Override @Override
public boolean performEditorAction(int editorAction) { public boolean performEditorAction(int editorAction) {
LogD("performEditorAction: " + editorAction); LogD("performEditorAction: " + editorAction);
@ -113,45 +54,24 @@ class Cocos2dxInputConnection implements InputConnection {
final String insertText = "\n"; final String insertText = "\n";
mView.insertText(insertText); mView.insertText(insertText);
} }
return false; return true;
}
@Override
public boolean performPrivateCommand(String action, Bundle data) {
LogD("performPrivateCommand: " + action + "," + data.toString());
return false;
}
@Override
public boolean reportFullscreenMode(boolean enabled) {
LogD("reportFullscreenMode: " + enabled);
return false;
} }
@Override @Override
public boolean sendKeyEvent(KeyEvent event) { public boolean sendKeyEvent(KeyEvent event) {
LogD("sendKeyEvent: " + event.toString()); LogD("sendKeyEvent: " + event.toString());
super.sendKeyEvent(event);
if (null != mView) { if (null != mView) {
switch (event.getKeyCode()) { switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DEL: case KeyEvent.KEYCODE_DEL:
mView.deleteBackward(); if (KeyEvent.ACTION_UP == event.getAction()) {
mView.deleteBackward();
}
break; break;
} }
} }
return false; return true;
}
@Override
public boolean setComposingText(CharSequence text, int newCursorPosition) {
LogD("setComposingText: " + text.toString() + "," + newCursorPosition);
return false;
}
@Override
public boolean setSelection(int start, int end) {
LogD("setSelection: " + start + "," + end);
return false;
} }
} }
@ -183,7 +103,7 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
mainView = this; mainView = this;
} }
public void onPause(){ public void onPause(){
queueEvent(new Runnable() { queueEvent(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -231,34 +151,22 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
} }
imm.hideSoftInputFromWindow(mainView.getWindowToken(), 0); imm.hideSoftInputFromWindow(mainView.getWindowToken(), 0);
} }
@Override
public boolean onCheckIsTextEditor() {
if (null == mainView)
{
return false;
}
return true;
}
private Cocos2dxInputConnection ic; private Cocos2dxInputConnection ic;
@Override @Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) { public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
if (onCheckIsTextEditor()) { outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI; //IME_ACTION_DONE
outAttrs.initialSelStart = -1;
outAttrs.initialSelEnd = -1;
outAttrs.initialCapsMode = 1;
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT; if (null == ic)
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI; {
outAttrs.initialSelStart = -1; ic = new Cocos2dxInputConnection(this);
outAttrs.initialSelEnd = -1; }
outAttrs.initialCapsMode = 1;
return ic;
if (null == ic)
{
ic = new Cocos2dxInputConnection(this);
}
return ic;
}
return null;
} }
public void insertText(final String text) { public void insertText(final String text) {

View File

@ -46,9 +46,9 @@ class BitmapDC
{ {
public: public:
BitmapDC() BitmapDC()
: m_pBitmap(NULL), :m_pPaint(NULL)
m_pPaint(NULL)
{ {
m_pBitmap = new SkBitmap();
} }
~BitmapDC(void) ~BitmapDC(void)
@ -94,27 +94,15 @@ public:
bool prepareBitmap(int nWidth, int nHeight) bool prepareBitmap(int nWidth, int nHeight)
{ {
// release bitmap m_pBitmap->reset();
if (m_pBitmap)
{
delete m_pBitmap;
m_pBitmap = NULL;
}
if (nWidth > 0 && nHeight > 0) if (nWidth > 0 && nHeight > 0)
{ {
/* create and init bitmap */
m_pBitmap = new SkBitmap();
if (! m_pBitmap)
{
return false;
}
/* use rgba8888 and alloc memory */ /* use rgba8888 and alloc memory */
m_pBitmap->setConfig(SkBitmap::kARGB_8888_Config, nWidth, nHeight); m_pBitmap->setConfig(SkBitmap::kARGB_8888_Config, nWidth, nHeight);
if (! m_pBitmap->allocPixels()) if (! m_pBitmap->allocPixels())
{ {
CC_SAFE_DELETE(m_pBitmap);
return false; return false;
} }

View File

@ -13,7 +13,12 @@
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
<supports-screens android:largeScreens="true"
android:smallScreens="true"
android:anyDensity="true"
android:normalScreens="true"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
</manifest> </manifest>

View File

@ -151,34 +151,22 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
} }
imm.hideSoftInputFromWindow(mainView.getWindowToken(), 0); imm.hideSoftInputFromWindow(mainView.getWindowToken(), 0);
} }
@Override
public boolean onCheckIsTextEditor() {
if (null == mainView)
{
return false;
}
return true;
}
private Cocos2dxInputConnection ic; private Cocos2dxInputConnection ic;
@Override @Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) { public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
if (onCheckIsTextEditor()) { outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI; //IME_ACTION_DONE
outAttrs.initialSelStart = -1;
outAttrs.initialSelEnd = -1;
outAttrs.initialCapsMode = 1;
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT; if (null == ic)
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI; //IME_ACTION_DONE {
outAttrs.initialSelStart = -1; ic = new Cocos2dxInputConnection(this);
outAttrs.initialSelEnd = -1; }
outAttrs.initialCapsMode = 1;
return ic;
if (null == ic)
{
ic = new Cocos2dxInputConnection(this);
}
return ic;
}
return null;
} }
public void insertText(final String text) { public void insertText(final String text) {