Saturday, August 30, 2014

cordova phonegap in android sendPluginResult big data

1.what

i want to return big data (big than 8k) to javascript,but cordova said parse error.

 

2.fixed

in java:

if (action.equals("fetch_installed_apps")) {
class MyRunnable implements Runnable{
public CallbackContext callbackContext;
public void run() {
JSONArray ary = PackageHelper.fetch_installed_apps();
JSONArray ary2;
PluginResult pluginResult;
PluginResult.Status status = PluginResult.Status.OK;
int num = 10;
try{
for(int i=0,c=(ary.length()+num-1)/num;i<c;++i){
ary2 = new JSONArray();
for(int j=i*num,c2=Math.min(j+num, ary.length());j<c2;++j){
ary2.put(ary.get(j));
}
pluginResult = new PluginResult(status, ary2);
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);
}
}catch(Exception e){
e.printStackTrace();
}
ary2 = new JSONArray();
pluginResult = new PluginResult(status, ary2);
pluginResult.setKeepCallback(false);
callbackContext.sendPluginResult(pluginResult);
}
};
MyRunnable runnable = new MyRunnable();
runnable.callbackContext = callbackContext;
cordova.getThreadPool().execute(runnable);

PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);

return true;
}


in javascript:



        fetch_installed_apps:function(successCallback, errorCallback) {
var data = [];
return exec(function(items){
if(items && items.length){
for(var i=0,c=items.length;i<c;++i)
data.push(items[i]);
}
else{
successCallback(data);
}
}, errorCallback, "PkrssPlugin", "fetch_installed_apps", []);
},


3. last



thanks your read!

Monday, August 25, 2014

cocos2d-x 3.2 C++ modify android to play .mid file by mediaplayer–or 3.0 develop log

because in android,media player support midi,but cocos2d-x 3.2 code not support. now i found fixed it method:


modify cocos2d\cocos\platform\android\java\src\org\cocos2dx\lib\Cocos2dxMusic.java fn:public void playBackgroundMusic(final String pPath, final boolean isLoop) ln: 118
old:
this.mBackgroundMediaPlayer.stop();

this.mBackgroundMediaPlayer.setLooping(isLoop);
this.mBackgroundMediaPlayer.prepare();
this.mBackgroundMediaPlayer.seekTo(0);
=>
new:
if(this.mCurrentPath.indexOf(".mid")>0){
this.mBackgroundMediaPlayer.setLooping(isLoop);
// this.mBackgroundMediaPlayer.prepareAsync();
}else{
this.mBackgroundMediaPlayer.stop();

this.mBackgroundMediaPlayer.setLooping(isLoop);
this.mBackgroundMediaPlayer.prepare();
this.mBackgroundMediaPlayer.seekTo(0);
}




last:


thanks your read!

Wednesday, August 6, 2014

android develop log 2 - custom control xml and code

1.android control set style by code

answer:



I do not believe you can set the style programatically. To get around this you can create a template layout xml file with the style assigned, for example in res/layout create tvtemplate.xml as with the following content:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is a template"
style="@style/my_style" />

then inflate this to instantiate your new TextView:

TextView myText = (TextView)getLayoutInflater().inflate(R.layout.tvtemplate, null);

Hope this helps.



2.android remote icon from tabhost control


answer:


create one tab class:

public class NoIconTab extends LinearLayout {
public NoIconTab(Context c, int drawable, String label) {
super(c);

TextView tv = new TextView(c);

tv.setTextColor(getResources().getColorStateList(R.color.tab_text_color));
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
tv.setGravity(0x01);

setOrientation(LinearLayout.VERTICAL);

if (drawable != 0) {
ImageView iv = new ImageView(c);
iv.setImageResource(drawable);
addView(iv);
}
addView(tv);
}
}




then used it by code:

mTabHost.addTab(mTabHost.newTabSpec("call_log")
.setIndicator(new NoIconTab(this,0,this.getResources().getString(R.string.scene)))
.setContent(intent));

Saturday, August 2, 2014

cocos2d-x 3.0 c++ compile error and fixed develop log

 


> cocos new Snake -p com.pkrss.snake -l cpp -d Project

// need many timers.
> cocos compile -p android -m release --ap 10

 

error: Couldn't find the gcc toolchain.
log:
ndk-r10 is not support cocos2d-x 3.2,and release ndk-r9

error:
Android NDK: Invalid APP_STL value: c++_static
log:
edit project dir\proj.android\jni\Application.mk
old:
APP_STL := c++_static
new:
APP_STL := gnustl_static

error:
"Compile thumb : chipmunk_static <= cpCollision.c
C:/Users/deliang/AppData/Local/Temp/cpCollision-276362.s: Assembler messages:
C:/Users/Administrator/AppData/Local/Temp/cpCollision-334565.s:2151: Error: cannot honor width suffix -- `ldr r4,[r1],#4'
log:
used ndk-r9d,not used ndk-r10 now.

error:
build.xml:46: sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var
log:
it say, build so have error. you can retry many timer: > cocos compile -p android -m release --ap 10

error:
make.exe: *** No rule to make target `D:/setup/develop/android/android-ndk-r9-windows-x86_64/android-ndk-r9/sources/android/cpufeatures/cpu-features.c', needed by `obj/local/armeabi/objs/cpufeatures/cpu-features.o'.  Stop.
log:
delete obj/cpu-features.*
rebuld.

error:
The import org.cocos2dx.lib cannot be resolved    AppActivity.java    /Snake/src/org/cocos2dx/cpp    line 29    Java Problem
log:
import exist project to android project from dir: cocos2d-x dir\cocos2d\cocos\platform\android\java

 

want:
add google analytics to cocos2d-x 3.0:
log:
1.copy libGoogleAnalyticsV2.jar to libs/
2.modify org.cocos2dx.cpp.AppActivity:
      public void onStart() {
        super.onStart();
        EasyTracker.getInstance().activityStart(this);
      }

      public void onStop() {
        EasyTracker.getInstance().activityStop(this);
       
        super.onStop();
      }

want:
add google admob to cocos2d-x 3.0,when application exit show fullscreen advertisement:
log: