diff options
author | Anton Yabchinskiy <arn@bestmx.ru> | 2015-07-29 23:01:36 +0300 |
---|---|---|
committer | Anton Yabchinskiy <arn@bestmx.ru> | 2015-07-29 23:01:36 +0300 |
commit | dc8df8a91a995796f0f330bf6bb6b209f6dfce08 (patch) | |
tree | 46cfe09124703b07860754d6b44e0289422e0573 /platform/android | |
parent | 16746f157f83d666079ba3266acec13d35b84c3f (diff) | |
parent | 922356b903061cda7591090bf19e8346c3a78cf5 (diff) |
Merge branch 'master' of github.com:okamstudio/godot
Diffstat (limited to 'platform/android')
29 files changed, 291 insertions, 112 deletions
diff --git a/platform/android/AndroidManifest.xml.template b/platform/android/AndroidManifest.xml.template index d31bdbfa53..c95c86c060 100644 --- a/platform/android/AndroidManifest.xml.template +++ b/platform/android/AndroidManifest.xml.template @@ -7,7 +7,7 @@ > <supports-screens android:smallScreens="true" android:normalScreens="true" - android:largeScreens="true" + android:largeScreens="false" android:xlargeScreens="true"/> <application android:label="@string/godot_project_name_string" android:icon="@drawable/icon" android:allowBackup="false" $$ADD_APPATTRIBUTE_CHUNKS$$ > @@ -15,7 +15,7 @@ android:label="@string/godot_project_name_string" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleTask" - android:screenOrientation="portrait" + android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize"> <intent-filter> @@ -200,6 +200,6 @@ $$ADD_PERMISSION_CHUNKS$$ <uses-permission android:name="godot.custom.18"/> <uses-permission android:name="godot.custom.19"/> -<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="15"/> +<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19"/> </manifest> diff --git a/platform/android/android_native_app_glue.h b/platform/android/android_native_app_glue.h index fe8684b5d2..f5ba27ae66 100644 --- a/platform/android/android_native_app_glue.h +++ b/platform/android/android_native_app_glue.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,7 +26,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ - * Copyright (C) 2010 The Android Open Source Project +/* Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/platform/android/audio_driver_jandroid.cpp b/platform/android/audio_driver_jandroid.cpp index 6e3f6f9505..1a3a1cb563 100644 --- a/platform/android/audio_driver_jandroid.cpp +++ b/platform/android/audio_driver_jandroid.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/audio_driver_jandroid.h b/platform/android/audio_driver_jandroid.h index f102acf154..bf8584051d 100644 --- a/platform/android/audio_driver_jandroid.h +++ b/platform/android/audio_driver_jandroid.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index 4c0c095e10..a08bc8943c 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/audio_driver_opensl.h b/platform/android/audio_driver_opensl.h index d852928ab8..e9d7c7a7ea 100644 --- a/platform/android/audio_driver_opensl.h +++ b/platform/android/audio_driver_opensl.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/dir_access_android.cpp b/platform/android/dir_access_android.cpp index 80311e5a08..ca1e58da3f 100644 --- a/platform/android/dir_access_android.cpp +++ b/platform/android/dir_access_android.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/dir_access_android.h b/platform/android/dir_access_android.h index 57683542fa..cbbcdb71bb 100644 --- a/platform/android/dir_access_android.h +++ b/platform/android/dir_access_android.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index 98f20b2636..2b5fc6a50a 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,11 +31,15 @@ #include "dir_access_jandroid.h" #include "file_access_jandroid.h" #include "thread_jandroid.h" +#include "print_string.h" + + jobject DirAccessJAndroid::io=NULL; jclass DirAccessJAndroid::cls=NULL; jmethodID DirAccessJAndroid::_dir_open=NULL; jmethodID DirAccessJAndroid::_dir_next=NULL; jmethodID DirAccessJAndroid::_dir_close=NULL; +jmethodID DirAccessJAndroid::_dir_is_dir=NULL; DirAccess *DirAccessJAndroid::create_fs() { @@ -67,43 +71,18 @@ String DirAccessJAndroid::get_next(){ if (!str) return ""; - int sl = env->GetStringLength(str); - if (sl==0) { - env->DeleteLocalRef((jobject)str); - return ""; - } - - CharString cs; - cs.resize(sl+1); - env->GetStringRegion(str,0,sl,(jchar*)&cs[0]); - cs[sl]=0; - - String ret; - ret.parse_utf8(&cs[0]); + String ret = String::utf8(env->GetStringUTFChars( (jstring)str, NULL )); env->DeleteLocalRef((jobject)str); - return ret; } bool DirAccessJAndroid::current_is_dir() const{ - JNIEnv *env = ThreadAndroid::get_env(); - String sd; - if (current_dir=="") - sd=current; - else - sd=current_dir+"/"+current; - - jstring js = env->NewStringUTF(sd.utf8().get_data()); - - int res = env->CallIntMethod(io,_dir_open,js); - if (res<=0) - return false; - env->CallObjectMethod(io,_dir_close,res); + JNIEnv *env = ThreadAndroid::get_env(); + return env->CallBooleanMethod(io,_dir_is_dir,id); - return true; } bool DirAccessJAndroid::current_is_hidden() const { @@ -142,24 +121,31 @@ Error DirAccessJAndroid::change_dir(String p_dir){ String new_dir; + if (p_dir!="res://" && p_dir.length()>1 && p_dir.ends_with("/")) + p_dir=p_dir.substr(0,p_dir.length()-1); + if (p_dir.begins_with("/")) new_dir=p_dir.substr(1,p_dir.length()); else if (p_dir.begins_with("res://")) new_dir=p_dir.substr(6,p_dir.length()); - else //relative - new_dir=new_dir+"/"+p_dir; + else if (current_dir=="") + new_dir=p_dir; + else + new_dir=current_dir.plus_file(p_dir); + //print_line("new dir is: "+new_dir); //test if newdir exists new_dir=new_dir.simplify_path(); jstring js = env->NewStringUTF(new_dir.utf8().get_data()); int res = env->CallIntMethod(io,_dir_open,js); + env->DeleteLocalRef(js); if (res<=0) return ERR_INVALID_PARAMETER; env->CallObjectMethod(io,_dir_close,res); - + current_dir=new_dir; return OK; } @@ -176,7 +162,7 @@ bool DirAccessJAndroid::file_exists(String p_file){ if (current_dir=="") sd=p_file; else - sd=current_dir+"/"+p_file; + sd=current_dir.plus_file(p_file); FileAccessJAndroid *f = memnew(FileAccessJAndroid); bool exists = f->file_exists(sd); @@ -190,12 +176,19 @@ bool DirAccessJAndroid::dir_exists(String p_dir) { JNIEnv *env = ThreadAndroid::get_env(); String sd; + + if (current_dir=="") sd=p_dir; - else - sd=current_dir+"/"+p_dir; + else { + if (p_dir.is_rel_path()) + sd=current_dir.plus_file(p_dir); + else + sd=fix_path(p_dir); + } + + String path=sd.simplify_path(); - String path=fix_path(sd).simplify_path(); if (path.begins_with("/")) path=path.substr(1,path.length()); else if (path.begins_with("res://")) @@ -203,6 +196,7 @@ bool DirAccessJAndroid::dir_exists(String p_dir) { jstring js = env->NewStringUTF(path.utf8().get_data()); int res = env->CallIntMethod(io,_dir_open,js); + env->DeleteLocalRef(js); if (res<=0) return false; @@ -256,6 +250,10 @@ void DirAccessJAndroid::setup( jobject p_io) { if(_dir_close != 0) { __android_log_print(ANDROID_LOG_INFO,"godot","*******GOT METHOD _dir_close ok!!"); } + _dir_is_dir = env->GetMethodID(cls, "dir_is_dir", "(I)Z"); + if(_dir_is_dir != 0) { + __android_log_print(ANDROID_LOG_INFO,"godot","*******GOT METHOD _dir_is_dir ok!!"); + } // (*env)->CallVoidMethod(env,obj,aMethodID, myvar); } diff --git a/platform/android/dir_access_jandroid.h b/platform/android/dir_access_jandroid.h index 0a696506e6..7b6242ca32 100644 --- a/platform/android/dir_access_jandroid.h +++ b/platform/android/dir_access_jandroid.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -47,6 +47,7 @@ class DirAccessJAndroid : public DirAccess { static jmethodID _dir_open; static jmethodID _dir_next; static jmethodID _dir_close; + static jmethodID _dir_is_dir; int id; diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 8199e7c622..0f9ce8081f 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -186,6 +186,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { bool apk_expansion; bool remove_prev; bool use_32_fb; + bool immersive; + bool export_arm; + bool export_x86; String apk_expansion_salt; String apk_expansion_pkey; int orientation; @@ -222,6 +225,8 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { static void _device_poll_thread(void *ud); + String get_package_name(); + String get_project_name() const; void _fix_manifest(Vector<uint8_t>& p_manifest); void _fix_resources(Vector<uint8_t>& p_manifest); @@ -280,8 +285,14 @@ bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant& icon=p_value; else if (n=="package/signed") _signed=p_value; + else if (n=="architecture/arm") + export_arm=p_value; + else if (n=="architecture/x86") + export_x86=p_value; else if (n=="screen/use_32_bits_view") use_32_fb=p_value; + else if (n=="screen/immersive_mode") + immersive=p_value; else if (n=="screen/orientation") orientation=p_value; else if (n=="screen/support_small") @@ -306,7 +317,7 @@ bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant& apk_expansion_pkey=p_value; else if (n.begins_with("permissions/")) { - String what = n.get_slice("/",1).to_upper(); + String what = n.get_slicec('/',1).to_upper(); bool state = p_value; if (state) perms.insert(what); @@ -314,7 +325,7 @@ bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant& perms.erase(what); } else if (n.begins_with("user_permissions/")) { - int which = n.get_slice("/",1).to_int(); + int which = n.get_slicec('/',1).to_int(); ERR_FAIL_INDEX_V(which,MAX_USER_PERMISSIONS,false); user_perms[which]=p_value; @@ -347,8 +358,14 @@ bool EditorExportPlatformAndroid::_get(const StringName& p_name,Variant &r_ret) r_ret=icon; else if (n=="package/signed") r_ret=_signed; + else if (n=="architecture/arm") + r_ret=export_arm; + else if (n=="architecture/x86") + r_ret=export_x86; else if (n=="screen/use_32_bits_view") r_ret=use_32_fb; + else if (n=="screen/immersive_mode") + r_ret=immersive; else if (n=="screen/orientation") r_ret=orientation; else if (n=="screen/support_small") @@ -373,11 +390,11 @@ bool EditorExportPlatformAndroid::_get(const StringName& p_name,Variant &r_ret) r_ret=apk_expansion_pkey; else if (n.begins_with("permissions/")) { - String what = n.get_slice("/",1).to_upper(); + String what = n.get_slicec('/',1).to_upper(); r_ret = perms.has(what); } else if (n.begins_with("user_permissions/")) { - int which = n.get_slice("/",1).to_int(); + int which = n.get_slicec('/',1).to_int(); ERR_FAIL_INDEX_V(which,MAX_USER_PERMISSIONS,false); r_ret=user_perms[which]; } else @@ -398,7 +415,10 @@ void EditorExportPlatformAndroid::_get_property_list( List<PropertyInfo> *p_list p_list->push_back( PropertyInfo( Variant::STRING, "package/name") ); p_list->push_back( PropertyInfo( Variant::STRING, "package/icon",PROPERTY_HINT_FILE,"png") ); p_list->push_back( PropertyInfo( Variant::BOOL, "package/signed") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "architecture/arm") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "architecture/x86") ); p_list->push_back( PropertyInfo( Variant::BOOL, "screen/use_32_bits_view") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "screen/immersive_mode") ); p_list->push_back( PropertyInfo( Variant::INT, "screen/orientation",PROPERTY_HINT_ENUM,"Landscape,Portrait") ); p_list->push_back( PropertyInfo( Variant::BOOL, "screen/support_small") ); p_list->push_back( PropertyInfo( Variant::BOOL, "screen/support_normal") ); @@ -635,11 +655,11 @@ void EditorExportPlatformAndroid::_fix_manifest(Vector<uint8_t>& p_manifest) { int iofs=ofs+8; - uint32_t string_count=decode_uint32(&p_manifest[iofs]); - uint32_t styles_count=decode_uint32(&p_manifest[iofs+4]); + string_count=decode_uint32(&p_manifest[iofs]); + styles_count=decode_uint32(&p_manifest[iofs+4]); uint32_t string_flags=decode_uint32(&p_manifest[iofs+8]); - uint32_t string_data_offset=decode_uint32(&p_manifest[iofs+12]); - uint32_t styles_offset=decode_uint32(&p_manifest[iofs+16]); + string_data_offset=decode_uint32(&p_manifest[iofs+12]); + styles_offset=decode_uint32(&p_manifest[iofs+16]); /* printf("string count: %i\n",string_count); printf("flags: %i\n",string_flags); @@ -738,7 +758,7 @@ void EditorExportPlatformAndroid::_fix_manifest(Vector<uint8_t>& p_manifest) { if (tname=="manifest" && attrname=="package") { print_line("FOUND PACKAGE"); - string_table[attr_value]=package; + string_table[attr_value]=get_package_name(); } //print_line("tname: "+tname); @@ -762,19 +782,21 @@ void EditorExportPlatformAndroid::_fix_manifest(Vector<uint8_t>& p_manifest) { if (tname=="activity" && /*nspace=="android" &&*/ attrname=="screenOrientation") { + encode_uint32(orientation==0?0:1,&p_manifest[iofs+16]); + /* print_line("FOUND screen orientation"); if (attr_value==0xFFFFFFFF) { WARN_PRINT("Version name in a resource, should be plaintext") } else { string_table[attr_value]=(orientation==0?"landscape":"portrait"); - } + }*/ } if (tname=="application" && /*nspace=="android" &&*/ attrname=="label") { print_line("FOUND application"); if (attr_value==0xFFFFFFFF) { - WARN_PRINT("Application name in a resource, should be plaintext.") + WARN_PRINT("Application name in a resource, should be plaintext (but you can ignore this).") } else { String aname = get_project_name(); @@ -785,7 +807,7 @@ void EditorExportPlatformAndroid::_fix_manifest(Vector<uint8_t>& p_manifest) { print_line("FOUND activity name"); if (attr_value==0xFFFFFFFF) { - WARN_PRINT("Activity name in a resource, should be plaintext") + WARN_PRINT("Activity name in a resource, should be plaintext (but you can ignore this)") } else { String aname; if (this->name!="") { @@ -829,23 +851,19 @@ void EditorExportPlatformAndroid::_fix_manifest(Vector<uint8_t>& p_manifest) { WARN_PRINT("Screen res name in a resource, should be plaintext") } else if (attrname=="smallScreens") { - print_line("SMALLSCREEN"); - string_table[attr_value]=screen_support[SCREEN_SMALL]?"true":"false"; + encode_uint32(screen_support[SCREEN_SMALL]?0xFFFFFFFF:0,&p_manifest[iofs+16]); } else if (attrname=="mediumScreens") { - print_line("MEDSCREEN"); - string_table[attr_value]=screen_support[SCREEN_NORMAL]?"true":"false"; + encode_uint32(screen_support[SCREEN_NORMAL]?0xFFFFFFFF:0,&p_manifest[iofs+16]); } else if (attrname=="largeScreens") { - print_line("LARGECREEN"); - string_table[attr_value]=screen_support[SCREEN_LARGE]?"true":"false"; + encode_uint32(screen_support[SCREEN_LARGE]?0xFFFFFFFF:0,&p_manifest[iofs+16]); } else if (attrname=="xlargeScreens") { - print_line("XLARGECREEN"); - string_table[attr_value]=screen_support[SCREEN_XLARGE]?"true":"false"; + encode_uint32(screen_support[SCREEN_XLARGE]?0xFFFFFFFF:0,&p_manifest[iofs+16]); } } @@ -1041,6 +1059,8 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d char fname[16384]; ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0); + bool skip=false; + String file=fname; Vector<uint8_t> data; @@ -1093,20 +1113,31 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d } } + if (file=="lib/x86/libgodot_android.so" && !export_x86) { + skip=true; + } + + if (file=="lib/armeabi/libgodot_android.so" && !export_arm) { + skip=true; + } + print_line("ADDING: "+file); - zipOpenNewFileInZip(apk, - file.utf8().get_data(), - NULL, - NULL, - 0, - NULL, - 0, - NULL, - Z_DEFLATED, - Z_DEFAULT_COMPRESSION); - zipWriteInFileInZip(apk,data.ptr(),data.size()); - zipCloseFileInZip(apk); + if (!skip) { + zipOpenNewFileInZip(apk, + file.utf8().get_data(), + NULL, + NULL, + 0, + NULL, + 0, + NULL, + Z_DEFLATED, + Z_DEFAULT_COMPRESSION); + + zipWriteInFileInZip(apk,data.ptr(),data.size()); + zipCloseFileInZip(apk); + } ret = unzGoToNextFile(pkg); } @@ -1140,7 +1171,7 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d if (apk_expansion) { - String apkfname="main."+itos(version_code)+"."+package+".obb"; + String apkfname="main."+itos(version_code)+"."+get_package_name()+".obb"; String fullpath=p_path.get_base_dir().plus_file(apkfname); FileAccess *pf = FileAccess::open(fullpath,FileAccess::WRITE); if (!pf) { @@ -1171,6 +1202,8 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d if (use_32_fb) cl.push_back("-use_depth_32"); + if (immersive) + cl.push_back("-use_immersive"); if (cl.size()) { //add comandline @@ -1483,7 +1516,7 @@ Error EditorExportPlatformAndroid::run(int p_device, bool p_dumb) { args.push_back("-s"); args.push_back(devices[p_device].id); args.push_back("uninstall"); - args.push_back(package); + args.push_back(get_package_name()); err = OS::get_singleton()->execute(adb,args,true,NULL,NULL,&rv); #if 0 @@ -1521,7 +1554,7 @@ Error EditorExportPlatformAndroid::run(int p_device, bool p_dumb) { args.push_back("-a"); args.push_back("android.intent.action.MAIN"); args.push_back("-n"); - args.push_back(package+"/com.android.godot.Godot"); + args.push_back(get_package_name()+"/com.android.godot.Godot"); err = OS::get_singleton()->execute(adb,args,true,NULL,NULL,&rv); if (err || rv!=0) { @@ -1533,12 +1566,37 @@ Error EditorExportPlatformAndroid::run(int p_device, bool p_dumb) { return OK; } +String EditorExportPlatformAndroid::get_package_name() { + + String pname = package; + String basename = Globals::get_singleton()->get("application/name"); + basename=basename.to_lower(); + + String name; + bool first=true; + for(int i=0;i<basename.length();i++) { + CharType c = basename[i]; + if (c>='0' && c<='9' && first) { + continue; + } + if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) { + name+=String::chr(c); + first=false; + } + } + if (name=="") + name="noname"; + + pname=pname.replace("$genname",name); + return pname; + +} EditorExportPlatformAndroid::EditorExportPlatformAndroid() { version_code=1; version_name="1.0"; - package="com.android.noname"; + package="org.godotengine.$genname"; name=""; _signed=true; apk_expansion=false; @@ -1547,6 +1605,11 @@ EditorExportPlatformAndroid::EditorExportPlatformAndroid() { orientation=0; remove_prev=true; use_32_fb=true; + immersive=true; + + export_arm=true; + export_x86=false; + device_thread=Thread::create(_device_poll_thread,this); devices_changed=true; @@ -1626,8 +1689,11 @@ bool EditorExportPlatformAndroid::can_export(String *r_error) const { EditorExportPlatformAndroid::~EditorExportPlatformAndroid() { + quit_request=true; Thread::wait_to_finish(device_thread); + memdelete(device_lock); + memdelete(device_thread); } diff --git a/platform/android/file_access_android.cpp b/platform/android/file_access_android.cpp index f1a2bf5882..da3a37fb42 100644 --- a/platform/android/file_access_android.cpp +++ b/platform/android/file_access_android.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/file_access_android.h b/platform/android/file_access_android.h index 080ab1a6ce..f477920ae9 100644 --- a/platform/android/file_access_android.h +++ b/platform/android/file_access_android.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/file_access_jandroid.cpp b/platform/android/file_access_jandroid.cpp index e1dec4f601..971d4f84ab 100644 --- a/platform/android/file_access_jandroid.cpp +++ b/platform/android/file_access_jandroid.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -67,7 +67,6 @@ Error FileAccessJAndroid::_open(const String& p_path, int p_mode_flags) { jstring js = env->NewStringUTF(path.utf8().get_data()); int res = env->CallIntMethod(io,_file_open,js,p_mode_flags&WRITE?true:false); - env->DeleteLocalRef(js); if (res<=0) diff --git a/platform/android/file_access_jandroid.h b/platform/android/file_access_jandroid.h index 3cbeab5ffc..13ac4e17b8 100644 --- a/platform/android/file_access_jandroid.h +++ b/platform/android/file_access_jandroid.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/godot_android.cpp b/platform/android/godot_android.cpp index 673ff91641..388ff06c10 100644 --- a/platform/android/godot_android.cpp +++ b/platform/android/godot_android.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/java/res/drawable/icon.png b/platform/android/java/res/drawable/icon.png Binary files differindex 050a1cf930..78757e9035 100644 --- a/platform/android/java/res/drawable/icon.png +++ b/platform/android/java/res/drawable/icon.png diff --git a/platform/android/java/src/com/android/godot/Godot.java b/platform/android/java/src/com/android/godot/Godot.java index 1fd37c98cd..9b9b1ab2ad 100644 --- a/platform/android/java/src/com/android/godot/Godot.java +++ b/platform/android/java/src/com/android/godot/Godot.java @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -110,6 +110,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC private Button mWiFiSettingsButton; private boolean use_32_bits=false; + private boolean use_immersive=false; private boolean mStatePaused; private int mState; @@ -374,6 +375,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC mRemoteService.onClientUpdated(mDownloaderClientStub.getMessenger()); } + + @Override protected void onCreate(Bundle icicle) { @@ -402,6 +405,19 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC boolean has_extra = i< command_line.length -1; if (command_line[i].equals("-use_depth_32")) { use_32_bits=true; + } else if (command_line[i].equals("-use_immersive")) { + use_immersive=true; + if(Build.VERSION.SDK_INT >= 19.0){ // check if the application runs on an android 4.4+ + window.getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar + | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); + + UiChangeListener(); + } } else if (command_line[i].equals("-use_apk_expansion")) { use_apk_expansion=true; } else if (has_extra && command_line[i].equals("-apk_expansion_md5")) { @@ -560,6 +576,16 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC mView.onResume(); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); GodotLib.focusin(); + if(use_immersive && Build.VERSION.SDK_INT >= 19.0){ // check if the application runs on an android 4.4+ + Window window = getWindow(); + window.getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar + | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); + } for(int i=0;i<singleton_count;i++) { @@ -570,10 +596,43 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC } + public void UiChangeListener() { + final View decorView = getWindow().getDecorView(); + decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() { + @Override + public void onSystemUiVisibilityChange(int visibility) { + if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { + decorView.setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); + } + } + }); + } + @Override public void onSensorChanged(SensorEvent event) { - float x = event.values[0]; - float y = event.values[1]; - float z = event.values[2]; + Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); + int displayRotation = display.getRotation(); + + float[] adjustedValues = new float[3]; + final int axisSwap[][] = { + { 1, -1, 0, 1 }, // ROTATION_0 + {-1, -1, 1, 0 }, // ROTATION_90 + {-1, 1, 0, 1 }, // ROTATION_180 + { 1, 1, 1, 0 } }; // ROTATION_270 + + final int[] as = axisSwap[displayRotation]; + adjustedValues[0] = (float)as[0] * event.values[ as[2] ]; + adjustedValues[1] = (float)as[1] * event.values[ as[3] ]; + adjustedValues[2] = event.values[2]; + + float x = adjustedValues[0]; + float y = adjustedValues[1]; + float z = adjustedValues[2]; GodotLib.accelerometer(x,y,z); } @@ -688,7 +747,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC //} } break; case MotionEvent.ACTION_POINTER_UP: { - int pointer_idx = event.getActionIndex(); + final int indexPointUp = event.getActionIndex(); + final int pointer_idx = event.getPointerId(indexPointUp); GodotLib.touch(4,pointer_idx,evcount,arr); //System.out.printf("%d - s.up at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx)); } break; diff --git a/platform/android/java/src/com/android/godot/GodotIO.java b/platform/android/java/src/com/android/godot/GodotIO.java index ff0eb5edcc..addceb1528 100644 --- a/platform/android/java/src/com/android/godot/GodotIO.java +++ b/platform/android/java/src/com/android/godot/GodotIO.java @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -271,6 +271,7 @@ public class GodotIO { public String[] files; public int current; + public String path; } public int last_dir_id=1; @@ -281,6 +282,7 @@ public class GodotIO { AssetDir ad = new AssetDir(); ad.current=0; + ad.path=path; try { ad.files = am.list(path); @@ -290,6 +292,7 @@ public class GodotIO { return -1; } + //System.out.printf("Opened dir: %s\n",path); ++last_dir_id; dirs.put(last_dir_id,ad); @@ -297,6 +300,32 @@ public class GodotIO { } + public boolean dir_is_dir(int id) { + if (!dirs.containsKey(id)) { + System.out.printf("dir_next: invalid dir id: %d\n",id); + return false; + } + AssetDir ad = dirs.get(id); + //System.out.printf("go next: %d,%d\n",ad.current,ad.files.length); + int idx = ad.current; + if (idx>0) + idx--; + + if (idx>=ad.files.length) + return false; + String fname = ad.files[idx]; + + try { + if (ad.path.equals("")) + am.open(fname); + else + am.open(ad.path+"/"+fname); + return false; + } catch (Exception e) { + return true; + } + } + public String dir_next(int id) { if (!dirs.containsKey(id)) { @@ -305,8 +334,12 @@ public class GodotIO { } AssetDir ad = dirs.get(id); - if (ad.current>=ad.files.length) + //System.out.printf("go next: %d,%d\n",ad.current,ad.files.length); + + if (ad.current>=ad.files.length) { + ad.current++; return ""; + } String r = ad.files[ad.current]; ad.current++; return r; diff --git a/platform/android/java/src/com/android/godot/GodotLib.java b/platform/android/java/src/com/android/godot/GodotLib.java index 6e2462b4f1..71c31e9f83 100644 --- a/platform/android/java/src/com/android/godot/GodotLib.java +++ b/platform/android/java/src/com/android/godot/GodotLib.java @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/java/src/com/android/godot/GodotView.java b/platform/android/java/src/com/android/godot/GodotView.java index bd81b7f9af..ad0354e624 100644 --- a/platform/android/java/src/com/android/godot/GodotView.java +++ b/platform/android/java/src/com/android/godot/GodotView.java @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp index 349db08e36..3158254781 100644 --- a/platform/android/java_glue.cpp +++ b/platform/android/java_glue.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -437,6 +437,7 @@ public: } + int ac = E->get().argtypes.size(); if (ac<p_argcount) { @@ -455,7 +456,6 @@ public: } - for(int i=0;i<p_argcount;i++) { if (!Variant::can_convert(p_args[i]->get_type(),E->get().argtypes[i])) { @@ -476,6 +476,10 @@ public: JNIEnv *env = ThreadAndroid::get_env(); + int res = env->PushLocalFrame(16); + + ERR_FAIL_COND_V(res!=0,Variant()); + //print_line("argcount "+String::num(p_argcount)); List<jobject> to_erase; for(int i=0;i<p_argcount;i++) { @@ -568,6 +572,7 @@ public: print_line("failure.."); + env->PopLocalFrame(NULL); ERR_FAIL_V(Variant()); } break; } @@ -576,6 +581,8 @@ public: env->DeleteLocalRef(to_erase.front()->get()); to_erase.pop_front(); } + + env->PopLocalFrame(NULL); //print_line("success"); return ret; @@ -1613,11 +1620,15 @@ JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_method(JNIEnv * env, jobj JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_callobject(JNIEnv * env, jobject p_obj, jint ID, jstring method, jobjectArray params) { - String str_method = env->GetStringUTFChars( method, NULL ); - Object* obj = ObjectDB::get_instance(ID); ERR_FAIL_COND(!obj); + int res = env->PushLocalFrame(16); + ERR_FAIL_COND(res!=0); + + String str_method = env->GetStringUTFChars( method, NULL ); + + int count = env->GetArrayLength(params); Variant* vlist = (Variant*)alloca(sizeof(Variant) * count); Variant** vptr = (Variant**)alloca(sizeof(Variant*) * count); @@ -1637,15 +1648,22 @@ JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_callobject(JNIEnv * env, Variant::CallError err; obj->call(str_method, (const Variant**)vptr, count, err); // something + + env->PopLocalFrame(NULL); + }; JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_calldeferred(JNIEnv * env, jobject p_obj, jint ID, jstring method, jobjectArray params) { - String str_method = env->GetStringUTFChars( method, NULL ); Object* obj = ObjectDB::get_instance(ID); ERR_FAIL_COND(!obj); + int res = env->PushLocalFrame(16); + ERR_FAIL_COND(res!=0); + + String str_method = env->GetStringUTFChars( method, NULL ); + int count = env->GetArrayLength(params); Variant args[VARIANT_ARG_MAX]; @@ -1666,6 +1684,8 @@ JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_calldeferred(JNIEnv * env obj->call_deferred(str_method, args[0],args[1],args[2],args[3],args[4]); // something + env->PopLocalFrame(NULL); + }; //Main::cleanup(); diff --git a/platform/android/java_glue.h b/platform/android/java_glue.h index 379718a23e..57a4cc8651 100644 --- a/platform/android/java_glue.h +++ b/platform/android/java_glue.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index f00e9c2d77..612148418b 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -163,7 +163,8 @@ void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_ // physics_server = memnew( PhysicsServerSW ); physics_server->init(); - physics_2d_server = memnew( Physics2DServerSW ); + //physics_2d_server = memnew( Physics2DServerSW ); + physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>(); physics_2d_server->init(); input = memnew( InputDefault ); diff --git a/platform/android/os_android.h b/platform/android/os_android.h index bea5371bbc..7a5a55653f 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -37,6 +37,7 @@ #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" #include "servers/audio/audio_server_sw.h" #include "servers/physics_2d/physics_2d_server_sw.h" +#include "servers/physics_2d/physics_2d_server_wrap_mt.h" #include "servers/visual/rasterizer.h" diff --git a/platform/android/platform_config.h b/platform/android/platform_config.h index 38fc934ae4..1e7d066bb9 100644 --- a/platform/android/platform_config.h +++ b/platform/android/platform_config.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/project.properties.template b/platform/android/project.properties.template index d81b72b525..00cacd72bc 100644 --- a/platform/android/project.properties.template +++ b/platform/android/project.properties.template @@ -12,4 +12,4 @@ # Project target. #android.library=true -target=android-15 +target=android-19 diff --git a/platform/android/thread_jandroid.cpp b/platform/android/thread_jandroid.cpp index ec6bef89a0..9314a1c013 100644 --- a/platform/android/thread_jandroid.cpp +++ b/platform/android/thread_jandroid.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/platform/android/thread_jandroid.h b/platform/android/thread_jandroid.h index 38b4be01ec..051f4e2c3d 100644 --- a/platform/android/thread_jandroid.h +++ b/platform/android/thread_jandroid.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ |