added a prefernces screen to handle media card selection on Android devices. Contains actual fix for 4297.

Added a place marker to allow volume change during app.  Right now it's either loud or off.  There isn't a way to allow the volume to gradually go up and odwn based on the values set in settings.
This commit is contained in:
techdragon.nguyen@gmail.com
2012-03-01 03:24:34 +00:00
parent 8b8020134d
commit 6124280f24
13 changed files with 604 additions and 97 deletions
+8 -2
View File
@@ -16,6 +16,9 @@ User folder is the only one that is really needed to guarantee both read and wri
The content that users should not be touching.
*/
#if defined(ANDROID)
#include "../../include/PrecompiledHeader.h"
#endif
#ifdef WIN32
#pragma warning(disable : 4786)
@@ -113,8 +116,10 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
systemPath = [[documentsDirectory stringByAppendingString: @"/Res/"] cStringUsingEncoding:1];
#elif defined (ANDROID)
userPath = "/sdcard/Wagic/Res/";
userPath = JGE::GetInstance()->getFileSystemLocation();
systemPath = "";
DebugTrace("User path " << userPath);
#elif defined (QT_CONFIG)
QDir dir(QDir::homePath());
dir.cd(USERDIR);
@@ -165,7 +170,7 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
systemPath += '/';
}
mUserFSPath = userPath;
mUserFSPath = userPath;
MAKEDIR(userPath.c_str());
mSystemFSPath = systemPath;
@@ -178,6 +183,7 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
mPassword = NULL;
mFileSize = 0;
mCurrentFileInZip = NULL;
};
void JFileSystem::Destroy()
+43 -18
View File
@@ -619,48 +619,68 @@ void JGE::SendCommand(std::string command, float& x, float& y, float& width, flo
#if defined (ANDROID)
int getJNIEnv(JNIEnv *env)
JNIEnv * JGE::getJNIEnv()
{
JNIEnv *env;
int status = mJavaVM->GetEnv((void **)&env, JNI_VERSION_1_4);
if(status < 0)
if(status == JNI_ERR)
{
DebugTrace("Failed to get JNI environment, assuming native thread");
status = mJavaVM->AttachCurrentThread(&env, NULL);
if(status < 0)
if(status == JNI_ERR)
{
LogNativeToAndroidExt("callback_handler: failed to attach current thread");
return JNI_ERR;
DebugTrace("callback_handler: failed to attach current thread");
return NULL;
}
}
return JNI_VERSION_1_4;
else if (status == JNI_EDETACHED)
{
DebugTrace("env is detached. trying to attach it to the current thread");
jint attachSuccess = mJavaVM->AttachCurrentThread(&env,NULL);
if(attachSuccess == 0)
{
return env;
}
else
{
return NULL;
}//end if/els
}
else if (status == JNI_OK)
{
return env;
}
return NULL;
}
string JGE::getFileSystemLocation()
{
char result[512];
JNIEnv * env;
if (getJNIEnv(env) == JNI_ERR)
JNIEnv * env = getJNIEnv();
if (env == NULL)
{
DebugTrace("An Error Occurred in getting the JNI Environment whie trying to get the system folder location. Defaulting to /mnt/sdcard/net.wagic.app/Wagic");
return "/mnt/sdcard/net.wagic.app/Wagic";
};
jmethodID methodId = env->GetStaticMethodID(mJNIClass, "getSystemFolderPath", "()Ljava/lang/String;");
jclass jniClass = env->FindClass("org/libsdl/app/SDLActivity");
jmethodID methodId = env->GetStaticMethodID( jniClass, "getSystemFolderPath", "()Ljava/lang/String;");
if (methodId == 0)
{
DebugTrace("An Error Occurred in getting the JNI methodID for getSystemFolderPath. Defaulting to /mnt/sdcard/net.wagic.app/Wagic");
return "/mnt/sdcard/net.wagic.app/Wagic";
};
jstring systemPath = (jstring) env->CallStaticObjectMethod(mJNIClass, methodId);
string retVal = "/mnt/sdcard/net.wagic.app/Wagic/";
// Now convert the Java String to C++ char array
jstring systemPath = (jstring) env->CallStaticObjectMethod(jniClass, methodId);
// Now convert the Java String to C++ char array
const char* cstr = env->GetStringUTFChars(systemPath, 0);
string val (cstr);
retVal = val;
string retVal (cstr);
env->ReleaseStringUTFChars(systemPath, cstr);
env->DeleteLocalRef(systemPath);
env->DeleteLocalRef(systemPath);
return retVal;
}
@@ -672,6 +692,11 @@ void JGE::SetJNIEnv(JNIEnv * env, jclass cls)
midSendCommand = mJNIEnv->GetStaticMethodID(mJNIClass,"jgeSendCommand","(Ljava/lang/String;)V");
}
void JGE::setJVM( JavaVM *vm)
{
mJavaVM = vm;
}
void JGE::sendJNICommand(string command)
{
if (midSendCommand) {
+17 -4
View File
@@ -22,7 +22,7 @@ static SLObjectItf outputMixObject = NULL;
//////////////////////////////////////////////////////////////////////////
JMusic::JMusic()
: playerObject(0), playInterface(0), seekInterface(0)
: playerObject(0), playInterface(0), seekInterface(0), musicVolumeInterface(0)
{
}
@@ -42,6 +42,7 @@ JMusic::~JMusic()
playerObject = NULL;
playInterface = NULL;
seekInterface = NULL;
musicVolumeInterface = NULL;
}
}
@@ -194,9 +195,13 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
DebugTrace("result " << result);
// get the volume interface
//result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_VOLUME, &musicVolumeInterface);
//result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_VOLUME, (void *)&music->musicVolumeInterface);
DebugTrace("result " << result);
}
mCurrentMusic = music;
return music;
}
@@ -207,6 +212,8 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping)
{
SLresult result;
//(*music->musicVolumeInterface)->SetVolumeLevel(music->musicVolumeInterface, -1 * mVolume);
// enable whole file looping
result = (*music->seekInterface)->SetLoop(music->seekInterface,
looping?SL_BOOLEAN_TRUE:SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN);
@@ -250,10 +257,13 @@ void JSoundSystem::SetVolume(int volume)
void JSoundSystem::SetMusicVolume(int volume)
{
mVolume = volume;
//(*mCurrentMusic->musicVolumeInterface)->SetVolumeLevel(mCurrentMusic->musicVolumeInterface, -1 * mVolume);
}
void JSoundSystem::SetSfxVolume(int volume){
mSampleVolume = volume;
//(*mCurrentSample->sampleVolumeInterface)->SetVolumeLevel(mCurrentSample->sampleVolumeInterface, -1 * mSampleVolume);
SetMusicVolume(mVolume);
}
@@ -296,8 +306,11 @@ JSample *JSoundSystem::LoadSample(const char *fileName)
DebugTrace("result " << result);
// get the volume interface
//result = (*sample->playerObject)->GetInterface(sample->playerObject, SL_IID_VOLUME, &sampleVolumeInterface);
//result = (*sample->playerObject)->GetInterface(sample->playerObject, SL_IID_VOLUME, &sample->sampleVolumeInterface);
}
mCurrentSample = sample;
return sample;
}
@@ -307,7 +320,7 @@ void JSoundSystem::PlaySample(JSample *sample)
if(sample && sample->playerObject && sample->playInterface)
{
SLresult result;
//(*sample->sampleVolumeInterface)->SetVolumeLevel(sample->sampleVolumeInterface, mSampleVolume);
result = (*sample->playInterface)->SetPlayState(sample->playInterface,
SL_PLAYSTATE_PLAYING);
}