From 93536997cd877628a1d674d496af8ec60b121a98 Mon Sep 17 00:00:00 2001 From: xiushu <461474853@qq.com> Date: Sun, 30 Apr 2017 02:06:37 +0800 Subject: [PATCH 1/2] UI: Allow choosing bgs (android) --- UI/NativeApp.cpp | 4 +++ .../src/org/ppsspp/ppsspp/NativeActivity.java | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 89b86fa24a..fcd2824aad 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -859,6 +859,10 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) { inputboxValue.clear(); } if (msg == "bgImage_updated") { + if (!value.empty()) { + std::string dest = GetSysDirectory(DIRECTORY_SYSTEM) + (endsWithNoCase(value, ".jpg") ? "background.jpg" : "background.png"); + File::Copy(value, dest); + } UIBackgroundShutdown(); UIBackgroundInit(*uiContext); } diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index ad298c1aff..861729f5e7 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -21,6 +21,7 @@ import android.content.pm.ConfigurationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; +import android.database.Cursor; import android.graphics.PixelFormat; import android.graphics.Point; import android.media.AudioManager; @@ -29,6 +30,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Vibrator; +import android.provider.MediaStore; import android.text.InputType; import android.util.DisplayMetrics; import android.util.Log; @@ -89,6 +91,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { private boolean isXperiaPlay; private boolean shuttingDown; + private static int RESULT_LOAD_IMAGE = 1; // Allow for multiple connected gamepads but just consider them the same for now. // Actually this is not entirely true, see the code. @@ -911,6 +914,24 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { return NativeApp.keyUp(0, keyCode); } } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { + Uri selectedImage = data.getData(); + String[] filePathColumn = { MediaStore.Images.Media.DATA }; + + Cursor cursor = getContentResolver().query(selectedImage, + filePathColumn, null, null, null); + cursor.moveToFirst(); + + int columnIndex = cursor.getColumnIndex(filePathColumn[0]); + String picturePath = cursor.getString(columnIndex); + cursor.close(); + NativeApp.sendMessage("bgImage_updated" , picturePath); + } + } @TargetApi(11) @SuppressWarnings("deprecation") @@ -976,6 +997,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { dlg.show(); } + public boolean processCommand(String command, String params) { SurfaceView surfView = javaGL ? mGLSurfaceView : mSurfaceView; if (command.equals("launchBrowser")) { @@ -1003,6 +1025,16 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { Log.e(TAG, e.toString()); return false; } + } else if (command.equals("bgImage_browse")) { + try { + Intent i = new Intent(Intent.ACTION_PICK, + android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + startActivityForResult(i, RESULT_LOAD_IMAGE); + return true; + } catch (Exception e) { // For example, android.content.ActivityNotFoundException + Log.e(TAG, e.toString()); + return false; + } } else if (command.equals("sharejpeg")) { try { Intent share = new Intent(Intent.ACTION_SEND); From c3a6d5a39249ef5a38cc387500fbdd39a3bd4d9b Mon Sep 17 00:00:00 2001 From: xiushu <461474853@qq.com> Date: Sun, 30 Apr 2017 02:09:52 +0800 Subject: [PATCH 2/2] Remove blank line --- android/src/org/ppsspp/ppsspp/NativeActivity.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 861729f5e7..cddb25f0fd 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -917,15 +917,12 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; - Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); - int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close();