From ca4bec35399185dc57e250b54d5308abbc4f464e Mon Sep 17 00:00:00 2001 From: Eder Bastos Date: Sun, 10 May 2015 10:46:46 -0400 Subject: [PATCH] Don't show "Error" when a blank string is returned from a native method. --- .../activities/AddDirectoryActivity.java | 8 ++ .../activities/GameGridActivity.java | 23 +++- Source/Core/DolphinWX/MainAndroid.cpp | 107 +++++++++--------- 3 files changed, 78 insertions(+), 60 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AddDirectoryActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AddDirectoryActivity.java index 3a282f6433..04e6ffb9f6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AddDirectoryActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AddDirectoryActivity.java @@ -15,6 +15,10 @@ import org.dolphinemu.dolphinemu.BuildConfig; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.adapters.FileAdapter; +/** + * An Activity that shows a list of files and folders, allowing the user to tell the app which folder(s) + * contains the user's games. + */ public class AddDirectoryActivity extends Activity implements FileAdapter.FileClickListener { public static final String KEY_CURRENT_PATH = BuildConfig.APPLICATION_ID + ".path"; @@ -74,6 +78,7 @@ public class AddDirectoryActivity extends Activity implements FileAdapter.FileCl return super.onOptionsItemSelected(item); } + @Override protected void onSaveInstanceState(Bundle outState) { @@ -83,6 +88,9 @@ public class AddDirectoryActivity extends Activity implements FileAdapter.FileCl outState.putString(KEY_CURRENT_PATH, mAdapter.getPath()); } + /** + * Tell the GameGridActivity that launched this Activity that the user picked a folder. + */ @Override public void finishSuccessfully() { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/GameGridActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/GameGridActivity.java index 14633d1277..e5a8572e5b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/GameGridActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/GameGridActivity.java @@ -3,16 +3,11 @@ package org.dolphinemu.dolphinemu.activities; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.database.Cursor; -import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.preference.PreferenceManager; -import android.provider.DocumentsContract; -import android.provider.OpenableColumns; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; -import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.View; @@ -32,6 +27,10 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +/** + * The main Activity of the Lollipop style UI. Shows a grid of games on tablets & landscape phones, + * shows a list of games on portrait phones. + */ public final class GameGridActivity extends Activity { private static final int REQUEST_ADD_DIRECTORY = 1; @@ -83,21 +82,33 @@ public final class GameGridActivity extends Activity } } + /** + * Callback from AddDirectoryActivity. Applies any changes necessary to the GameGridActivity. + * + * @param requestCode + * @param resultCode + * @param result + */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent result) { + // If the user picked a file, as opposed to just backing out. if (resultCode == RESULT_OK) { + // Sanity check to make sure the Activity that just returned was the AddDirectoryActivity; + // other activities might use this callback in the future (don't forget to change Javadoc!) if (requestCode == REQUEST_ADD_DIRECTORY) { String path = result.getStringExtra(AddDirectoryActivity.KEY_CURRENT_PATH); + // Store this path as a preference. + // TODO Use SQLite instead. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); editor.putString(AddDirectoryActivity.KEY_CURRENT_PATH, path); - // Using commit in order to block so the next method has the correct data to load. + // Using commit, not apply, in order to block so the next method has the correct data to load. editor.commit(); mAdapter.setGameList(getGameList()); diff --git a/Source/Core/DolphinWX/MainAndroid.cpp b/Source/Core/DolphinWX/MainAndroid.cpp index a38f312f49..44e9f370d7 100644 --- a/Source/Core/DolphinWX/MainAndroid.cpp +++ b/Source/Core/DolphinWX/MainAndroid.cpp @@ -219,7 +219,7 @@ static std::string GetTitle(std::string filename) return name; } - return std::string ("Error"); + return std::string (""); } static std::string GetDescription(std::string filename) @@ -256,7 +256,7 @@ static std::string GetDescription(std::string filename) return descriptions.cbegin()->second; } - return std::string ("Error"); + return std::string (""); } static std::string GetGameId(std::string filename) @@ -271,7 +271,7 @@ static std::string GetGameId(std::string filename) return id; } - return std::string ("Error"); + return std::string (""); } static std::string GetApploaderDate(std::string filename) @@ -286,7 +286,7 @@ static std::string GetApploaderDate(std::string filename) return date; } - return std::string ("Error"); + return std::string (""); } static u64 GetFileSize(std::string filename) @@ -349,17 +349,17 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv * JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv *env, jobject obj) { -PowerPC::Start(); + PowerPC::Start(); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv *env, jobject obj) { -PowerPC::Pause(); + PowerPC::Pause(); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv *env, jobject obj) { -Core::Stop(); -updateMainFrameEvent.Set(); // Kick the waiting event + Core::Stop(); + updateMainFrameEvent.Set(); // Kick the waiting event } JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(JNIEnv *env, jobject obj, jstring jDevice, jint Button, jint Action) { @@ -367,7 +367,7 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePa } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(JNIEnv *env, jobject obj, jstring jDevice, jint Axis, jfloat Value) { -ButtonManager::GamepadAxisEvent(GetJString(env, jDevice), Axis, Value); + ButtonManager::GamepadAxisEvent(GetJString(env, jDevice), Axis, Value); } JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetBanner(JNIEnv *env, jobject obj, jstring jFile) @@ -437,12 +437,12 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Supports JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv *env, jobject obj) { -Core::SaveScreenShot(); + Core::SaveScreenShot(); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_eglBindAPI(JNIEnv *env, jobject obj, jint api) { -eglBindAPI(api); + eglBindAPI(api); } JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetConfig(JNIEnv *env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jDefault) @@ -460,59 +460,58 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetConfig return env->NewStringUTF(value.c_str()); } -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetConfig(JNIEnv *env, jobject obj, jstring jFile, jstring jSection, jstring jKey, -jstring jValue) +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetConfig(JNIEnv *env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jValue) { -IniFile ini; -std::string file = GetJString(env, jFile); -std::string section = GetJString(env, jSection); -std::string key = GetJString(env, jKey); -std::string value = GetJString(env, jValue); + IniFile ini; + std::string file = GetJString(env, jFile); + std::string section = GetJString(env, jSection); + std::string key = GetJString(env, jKey); + std::string value = GetJString(env, jValue); -ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string(file)); + ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string(file)); -ini.GetOrCreateSection(section)->Set(key, value); -ini.Save(File::GetUserPath(D_CONFIG_IDX) + std::string(file)); + ini.GetOrCreateSection(section)->Set(key, value); + ini.Save(File::GetUserPath(D_CONFIG_IDX) + std::string(file)); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetFilename(JNIEnv *env, jobject obj, jstring jFile) { -g_filename = GetJString(env, jFile); + g_filename = GetJString(env, jFile); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv *env, jobject obj, jint slot) { -State::Save(slot); + State::Save(slot); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv *env, jobject obj, jint slot) { -State::Load(slot); + State::Load(slot); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_CreateUserFolders(JNIEnv *env, jobject obj) { -File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX)); -File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX)); -File::CreateFullPath(File::GetUserPath(D_WIIUSER_IDX)); -File::CreateFullPath(File::GetUserPath(D_CACHE_IDX)); -File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX)); -File::CreateFullPath(File::GetUserPath(D_DUMPTEXTURES_IDX)); -File::CreateFullPath(File::GetUserPath(D_HIRESTEXTURES_IDX)); -File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX)); -File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX)); -File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX)); -File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX)); -File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + USA_DIR DIR_SEP); -File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + EUR_DIR DIR_SEP); -File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + JAP_DIR DIR_SEP); + File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX)); + File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX)); + File::CreateFullPath(File::GetUserPath(D_WIIUSER_IDX)); + File::CreateFullPath(File::GetUserPath(D_CACHE_IDX)); + File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX)); + File::CreateFullPath(File::GetUserPath(D_DUMPTEXTURES_IDX)); + File::CreateFullPath(File::GetUserPath(D_HIRESTEXTURES_IDX)); + File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX)); + File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX)); + File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX)); + File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX)); + File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + USA_DIR DIR_SEP); + File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + EUR_DIR DIR_SEP); + File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + JAP_DIR DIR_SEP); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory(JNIEnv *env, jobject obj, jstring jDirectory) { -std::string directory = GetJString(env, jDirectory); -g_set_userpath = directory; -UICommon::SetUserDirectory(directory); + std::string directory = GetJString(env, jDirectory); + g_set_userpath = directory; + UICommon::SetUserDirectory(directory); } JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv *env, jobject obj) @@ -522,24 +521,24 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDi JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj, jobject _surf) { -surf = ANativeWindow_fromSurface(env, _surf); + surf = ANativeWindow_fromSurface(env, _surf); -// Install our callbacks -OSD::AddCallback(OSD::OSD_INIT, ButtonManager::Init); -OSD::AddCallback(OSD::OSD_SHUTDOWN, ButtonManager::Shutdown); + // Install our callbacks + OSD::AddCallback(OSD::OSD_INIT, ButtonManager::Init); + OSD::AddCallback(OSD::OSD_SHUTDOWN, ButtonManager::Shutdown); -RegisterMsgAlertHandler(&MsgAlert); + RegisterMsgAlertHandler(&MsgAlert); -UICommon::SetUserDirectory(g_set_userpath); -UICommon::Init(); + UICommon::SetUserDirectory(g_set_userpath); + UICommon::Init(); -// No use running the loop when booting fails -if ( BootManager::BootCore( g_filename.c_str() ) ) -while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN) -updateMainFrameEvent.Wait(); + // No use running the loop when booting fails + if ( BootManager::BootCore( g_filename.c_str() ) ) + while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN) + updateMainFrameEvent.Wait(); -UICommon::Shutdown(); -ANativeWindow_release(surf); + UICommon::Shutdown(); + ANativeWindow_release(surf); }