[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.
// pDirector->enableRetinaDisplay(true);
// sets opengl landscape mode
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// turn on display FPS
pDirector->setDisplayFPS(true);

View File

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

View File

@ -2,21 +2,20 @@ package org.cocos2dx.lib;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
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) {
if (mDebug) {
Log.d("Cocos2dxInputConnection", msg);
@ -26,59 +25,19 @@ class Cocos2dxInputConnection implements InputConnection {
private Cocos2dxGLSurfaceView mView;
Cocos2dxInputConnection(Cocos2dxGLSurfaceView view) {
super(view, false);
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
public boolean commitText(CharSequence text, int newCursorPosition) {
super.commitText(text, newCursorPosition);
if (null != mView) {
final String insertText = text.toString();
mView.insertText(insertText);
LogD("commitText: " + insertText);
}
return false;
}
@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;
return true;
}
@Override
@ -88,24 +47,6 @@ class Cocos2dxInputConnection implements InputConnection {
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
public boolean performEditorAction(int editorAction) {
LogD("performEditorAction: " + editorAction);
@ -113,45 +54,24 @@ class Cocos2dxInputConnection implements InputConnection {
final String insertText = "\n";
mView.insertText(insertText);
}
return false;
}
@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;
return true;
}
@Override
public boolean sendKeyEvent(KeyEvent event) {
LogD("sendKeyEvent: " + event.toString());
super.sendKeyEvent(event);
if (null != mView) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DEL:
mView.deleteBackward();
if (KeyEvent.ACTION_UP == event.getAction()) {
mView.deleteBackward();
}
break;
}
}
return false;
}
@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;
return true;
}
}
@ -183,7 +103,7 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
mainView = this;
}
public void onPause(){
public void onPause(){
queueEvent(new Runnable() {
@Override
public void run() {
@ -231,34 +151,22 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
}
imm.hideSoftInputFromWindow(mainView.getWindowToken(), 0);
}
@Override
public boolean onCheckIsTextEditor() {
if (null == mainView)
{
return false;
}
return true;
}
private Cocos2dxInputConnection ic;
@Override
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;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.initialSelStart = -1;
outAttrs.initialSelEnd = -1;
outAttrs.initialCapsMode = 1;
if (null == ic)
{
ic = new Cocos2dxInputConnection(this);
}
return ic;
}
return null;
if (null == ic)
{
ic = new Cocos2dxInputConnection(this);
}
return ic;
}
public void insertText(final String text) {

View File

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

View File

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

View File

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