From 3d0b5bf45505ffadf310ff642e8d8805d8e94fd7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 27 Aug 2012 10:21:43 +0800 Subject: [PATCH] fixed some warnings in java codes for android port. --- .../org/cocos2dx/lib/Cocos2dxActivity.java | 40 ++++++++++++------- .../org/cocos2dx/lib/Cocos2dxBitmap.java | 3 -- .../cocos2dx/lib/Cocos2dxEditBoxDialog.java | 28 +++++++++++-- .../src/org/cocos2dx/hellolua/HelloLua.java | 1 - 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxActivity.java index 832a356748..952d5148fb 100644 --- a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxActivity.java @@ -1,5 +1,5 @@ /**************************************************************************** -Copyright (c) 2010-2011 cocos2d-x.org +Copyright (c) 2010-2012 cocos2d-x.org http://www.cocos2d-x.org @@ -24,11 +24,12 @@ THE SOFTWARE. package org.cocos2dx.lib; +import java.lang.ref.WeakReference; + import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; -import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -57,6 +58,28 @@ public class Cocos2dxActivity extends Activity{ private static native void nativeSetPaths(String apkPath); private static native void nativeSetEditboxText(byte[] text); + + static class ShowDialogHandler extends Handler { + WeakReference mActivity; + + ShowDialogHandler(Cocos2dxActivity activity) { + mActivity = new WeakReference(activity); + } + + @Override + public void handleMessage(Message msg) { + Cocos2dxActivity theActivity = mActivity.get(); + switch(msg.what) { + case HANDLER_SHOW_DIALOG: + theActivity.showDialog(((DialogMessage)msg.obj).title, ((DialogMessage)msg.obj).message); + break; + case HANDLER_SHOW_EDITBOX_DIALOG: + theActivity.onShowEditBoxDialog((EditBoxMessage)msg.obj); + break; + } + } + }; + public Cocos2dxGLSurfaceView getGLView() { return mGLView; } @@ -80,18 +103,7 @@ public class Cocos2dxActivity extends Activity{ // init bitmap context Cocos2dxBitmap.setContext(this); - handler = new Handler(){ - public void handleMessage(Message msg){ - switch(msg.what){ - case HANDLER_SHOW_DIALOG: - showDialog(((DialogMessage)msg.obj).title, ((DialogMessage)msg.obj).message); - break; - case HANDLER_SHOW_EDITBOX_DIALOG: - onShowEditBoxDialog((EditBoxMessage)msg.obj); - break; - } - } - }; + handler = new ShowDialogHandler(this); } public static String getDeviceModel(){ diff --git a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxBitmap.java b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxBitmap.java index faf7d14db0..395400b779 100644 --- a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxBitmap.java +++ b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxBitmap.java @@ -36,11 +36,8 @@ import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.Paint.Align; import android.graphics.Paint.FontMetricsInt; -import android.text.Spannable; -import android.text.SpannableString; import android.text.TextPaint; import android.text.TextUtils; -import android.text.style.StyleSpan; import android.util.Log; public class Cocos2dxBitmap{ diff --git a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java index 3b187c6d42..66e94e242c 100755 --- a/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java +++ b/cocos2dx/platform/android/java/src_common/org/cocos2dx/lib/Cocos2dxEditBoxDialog.java @@ -1,11 +1,32 @@ +/**************************************************************************** +Copyright (c) 2010-2012 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + package org.cocos2dx.lib; import android.app.Dialog; import android.content.Context; -import android.graphics.Canvas; -import android.graphics.ColorFilter; import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.text.InputFilter; @@ -13,7 +34,6 @@ import android.text.InputType; import android.util.Log; import android.util.TypedValue; import android.view.KeyEvent; -import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; diff --git a/samples/HelloLua/proj.android/src/org/cocos2dx/hellolua/HelloLua.java b/samples/HelloLua/proj.android/src/org/cocos2dx/hellolua/HelloLua.java index 6390034f79..1f44f9aba8 100644 --- a/samples/HelloLua/proj.android/src/org/cocos2dx/hellolua/HelloLua.java +++ b/samples/HelloLua/proj.android/src/org/cocos2dx/hellolua/HelloLua.java @@ -30,7 +30,6 @@ import org.cocos2dx.lib.Cocos2dxRenderer; import android.app.ActivityManager; import android.content.Context; import android.content.pm.ConfigurationInfo; -import android.opengl.GLSurfaceView; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent;