Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Add button to easily switch to SD card directory. #13885

Merged
merged 6 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Common/File/PathBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ bool PathBrowser::CanNavigateUp() {
}
#endif
*/
if (path_ == "/") {
if (path_ == "/" || path_ == "") {
return false;
}
return true;
Expand Down
8 changes: 8 additions & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ void System_SendMessage(const char *command, const char *parameter);
PermissionStatus System_GetPermissionStatus(SystemPermission permission);
void System_AskForPermission(SystemPermission permission);

std::vector<std::string> System_GetExternalStorageDirs();

// This will get muddy with multi-screen support :/ But this will always be the type of the main device.
enum SystemDeviceType {
DEVICE_TYPE_MOBILE = 0, // phones and pads
Expand All @@ -55,6 +57,11 @@ enum SystemProperty {
SYSPROP_CLIPBOARD_TEXT,
SYSPROP_GPUDRIVER_VERSION,

// Separate SD cards or similar.
// Need hacky solutions to get at this.
SYSPROP_HAS_ADDITIONAL_STORAGE,
SYSPROP_ADDITIONAL_STORAGE_DIRS,

SYSPROP_HAS_FILE_BROWSER,
SYSPROP_HAS_FOLDER_BROWSER,
SYSPROP_HAS_IMAGE_BROWSER,
Expand Down Expand Up @@ -95,6 +102,7 @@ enum SystemProperty {
};

std::string System_GetProperty(SystemProperty prop);
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop);
int System_GetPropertyInt(SystemProperty prop);
float System_GetPropertyFloat(SystemProperty prop);
bool System_GetPropertyBool(SystemProperty prop);
Expand Down
4 changes: 4 additions & 0 deletions Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,10 @@ void TextView::Draw(UIContext &dc) {
dc.DrawTextRect(text_.c_str(), bounds_.Offset(1.0f, 1.0f), shadowColor, textAlign_);
}
dc.DrawTextRect(text_.c_str(), bounds_, textColor, textAlign_);
if (small_) {
// If we changed font style, reset it.
dc.SetFontStyle(dc.theme->uiFont);
}
if (clip) {
dc.PopScissor();
}
Expand Down
7 changes: 7 additions & 0 deletions Qt/QtMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ std::string System_GetProperty(SystemProperty prop) {
}
}

std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
switch (prop) {
default:
return std::vector<std::string>();
}
}

int System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
#if defined(SDL)
Expand Down
7 changes: 7 additions & 0 deletions SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ std::string System_GetProperty(SystemProperty prop) {
}
}

std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
switch (prop) {
default:
return std::vector<std::string>();
}
}

int System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
Expand Down
42 changes: 34 additions & 8 deletions UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,29 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) {
return UI::EVENT_DONE;
}

UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) {
#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH) || defined(USING_QT_UI) || defined(USING_WIN_UI) || PPSSPP_PLATFORM(UWP)
if (System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) {
System_SendMessage("browse_folder", "");
UI::EventReturn GameBrowser::BrowseClick(UI::EventParams &e) {
System_SendMessage("browse_folder", "");
return UI::EVENT_DONE;
}

UI::EventReturn GameBrowser::StorageClick(UI::EventParams &e) {
std::vector<std::string> storageDirs = System_GetPropertyStringVec(SYSPROP_ADDITIONAL_STORAGE_DIRS);
if (storageDirs.empty()) {
// Shouldn't happen - this button shouldn't be clickable.
return UI::EVENT_DONE;
}
if (storageDirs.size() == 1) {
SetPath(storageDirs[0]);
} else {
SetPath(g_Config.memStickDirectory);
// TODO: We should popup a dialog letting the user choose one.
SetPath(storageDirs[0]);
}
return UI::EVENT_DONE;
}

UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) {
#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH) || defined(USING_WIN_UI) || PPSSPP_PLATFORM(UWP)
SetPath(g_Config.memStickDirectory);
#else
SetPath(getenv("HOME"));
#endif
Expand Down Expand Up @@ -656,10 +672,12 @@ void GameBrowser::Refresh() {
if (browseFlags_ & BrowseFlags::NAVIGATE) {
topBar->Add(new Spacer(2.0f));
topBar->Add(new TextView(path_.GetFriendlyPath().c_str(), ALIGN_VCENTER | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, 64.0f, 1.0f)));
topBar->Add(new Choice(ImageID("I_HOME"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::HomeClick);
if (System_GetPropertyBool(SYSPROP_HAS_ADDITIONAL_STORAGE)) {
topBar->Add(new Choice(ImageID("I_SDCARD"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::StorageClick);
}
if (System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) {
topBar->Add(new Choice(mm->T("Browse", "Browse..."), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::HomeClick);
} else {
topBar->Add(new Choice(mm->T("Home"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::HomeClick);
topBar->Add(new Choice(mm->T("Browse", "Browse..."), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick);
}
} else {
topBar->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 64.0f, 1.0f)));
Expand Down Expand Up @@ -762,6 +780,7 @@ void GameBrowser::Refresh() {
gameList_->Add(new DirButton("..", *gridStyle_, new UI::LinearLayoutParams(UI::FILL_PARENT, UI::FILL_PARENT)))->
OnClick.Handle(this, &GameBrowser::NavigateClick);
}

// Add any pinned paths before other directories.
auto pinnedPaths = GetPinnedPaths();
for (auto it = pinnedPaths.begin(), end = pinnedPaths.end(); it != end; ++it) {
Expand Down Expand Up @@ -1079,6 +1098,13 @@ void MainScreen::CreateViews() {
logos->Add(new ImageView(ImageID("I_ICON"), IS_DEFAULT, new AnchorLayoutParams(64, 64, 10, 10, NONE, NONE, false)));
}
logos->Add(new ImageView(ImageID("I_LOGO"), IS_DEFAULT, new LinearLayoutParams(Margins(-12, 0, 0, 0))));

#if defined(USING_WIN_UI) || defined(USING_QT_UI) || PPSSPP_PLATFORM(UWP)
if (!g_Config.bFullScreen) {
logos->Add(new ImageView(ImageID("I_FULLSCREEN"), IS_DEFAULT, new AnchorLayoutParams(64, 64, NONE, 0, 0, NONE, false)));
}
#endif

rightColumnItems->Add(logos);
TextView *ver = rightColumnItems->Add(new TextView(versionString, new LinearLayoutParams(Margins(70, -6, 0, 0))));
ver->SetSmall(true);
Expand Down
2 changes: 2 additions & 0 deletions UI/MainScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class GameBrowser : public UI::LinearLayout {
UI::EventReturn NavigateClick(UI::EventParams &e);
UI::EventReturn LayoutChange(UI::EventParams &e);
UI::EventReturn LastClick(UI::EventParams &e);
UI::EventReturn BrowseClick(UI::EventParams &e);
UI::EventReturn StorageClick(UI::EventParams &e);
UI::EventReturn HomeClick(UI::EventParams &e);
UI::EventReturn PinToggleClick(UI::EventParams &e);
UI::EventReturn GridSettingsClick(UI::EventParams &e);
Expand Down
7 changes: 7 additions & 0 deletions UWP/PPSSPP_UWPMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ std::string System_GetProperty(SystemProperty prop) {
}
}

std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
switch (prop) {
default:
return std::vector<std::string>();
}
}

int System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
Expand Down
7 changes: 7 additions & 0 deletions Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ std::string System_GetProperty(SystemProperty prop) {
}
}

std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
switch (prop) {
default:
return std::vector<std::string>();
}
}

// Ugly!
extern WindowsAudioBackend *winAudioBackend;

Expand Down
Binary file modified android/assets/ui_atlas.meta
Binary file not shown.
Binary file modified android/assets/ui_atlas.zim
Binary file not shown.
43 changes: 36 additions & 7 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <thread>
#include <atomic>

#include <android/log.h>

#ifndef _MSC_VER
#include <jni.h>
#include <android/native_window_jni.h>
Expand Down Expand Up @@ -122,6 +124,8 @@ std::string langRegion;
std::string mogaVersion;
std::string boardName;

std::vector<std::string> g_additionalStorageDirs;

static float left_joystick_x_async;
static float left_joystick_y_async;
static float right_joystick_x_async;
Expand Down Expand Up @@ -364,6 +368,15 @@ std::string System_GetProperty(SystemProperty prop) {
}
}

std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
switch (prop) {
case SYSPROP_ADDITIONAL_STORAGE_DIRS:
return g_additionalStorageDirs;
default:
return std::vector<std::string>();
}
}

int System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_SYSTEMVERSION:
Expand Down Expand Up @@ -410,6 +423,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
return androidVersion >= 23; // 6.0 Marshmallow introduced run time permissions.
case SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE:
return sustainedPerfSupported; // 7.0 introduced sustained performance mode as an optional feature.
case SYSPROP_HAS_ADDITIONAL_STORAGE:
return !g_additionalStorageDirs.empty();
case SYSPROP_HAS_BACK_BUTTON:
return true;
case SYSPROP_HAS_IMAGE_BROWSER:
Expand Down Expand Up @@ -530,16 +545,19 @@ static void parse_args(std::vector<std::string> &args, const std::string value)
}
}

// Need to use raw Android logging before NativeInit.
#define EARLY_LOG(...) __android_log_print(ANDROID_LOG_INFO, "PPSSPP", __VA_ARGS__)

extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
(JNIEnv *env, jclass, jstring jmodel, jint jdeviceType, jstring jlangRegion, jstring japkpath,
jstring jdataDir, jstring jexternalDir, jstring jlibraryDir, jstring jcacheDir, jstring jshortcutParam,
jstring jdataDir, jstring jexternalStorageDir, jstring jadditionalStorageDirs, jstring jlibraryDir, jstring jcacheDir, jstring jshortcutParam,
jint jAndroidVersion, jstring jboard) {
setCurrentThreadName("androidInit");

// Makes sure we get early permission grants.
ProcessFrameCommands(env);

INFO_LOG(SYSTEM, "NativeApp.init() -- begin");
EARLY_LOG("NativeApp.init() -- begin");
PROFILE_INIT();

renderer_inited = false;
Expand All @@ -559,9 +577,18 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
systemName = GetJavaString(env, jmodel);
langRegion = GetJavaString(env, jlangRegion);

INFO_LOG(SYSTEM, "NativeApp.init(): device name: '%s'", systemName.c_str());
EARLY_LOG("NativeApp.init(): device name: '%s'", systemName.c_str());

std::string externalStorageDir = GetJavaString(env, jexternalStorageDir);
std::string additionalStorageDirsString = GetJavaString(env, jadditionalStorageDirs);

if (!additionalStorageDirsString.empty()) {
SplitString(additionalStorageDirsString, ':', g_additionalStorageDirs);
for (auto &str : g_additionalStorageDirs) {
EARLY_LOG("Additional storage: %s", str.c_str());
}
}

std::string externalDir = GetJavaString(env, jexternalDir);
std::string user_data_path = GetJavaString(env, jdataDir);
if (user_data_path.size() > 0)
user_data_path += "/";
Expand All @@ -570,8 +597,8 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
std::string cacheDir = GetJavaString(env, jcacheDir);
std::string buildBoard = GetJavaString(env, jboard);
boardName = buildBoard;
INFO_LOG(SYSTEM, "NativeApp.init(): External storage path: %s", externalDir.c_str());
INFO_LOG(SYSTEM, "NativeApp.init(): Launch shortcut parameter: %s", shortcut_param.c_str());
EARLY_LOG("NativeApp.init(): External storage path: %s", externalStorageDir.c_str());
EARLY_LOG("NativeApp.init(): Launch shortcut parameter: %s", shortcut_param.c_str());

std::string app_name;
std::string app_nice_name;
Expand Down Expand Up @@ -600,7 +627,9 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
}
}

NativeInit((int)args.size(), &args[0], user_data_path.c_str(), externalDir.c_str(), cacheDir.c_str());
NativeInit((int)args.size(), &args[0], user_data_path.c_str(), externalStorageDir.c_str(), cacheDir.c_str());

// No need to use EARLY_LOG anymore.

retry:
// Now that we've loaded config, set javaGL.
Expand Down
Loading