From 2c9787643dbbf4582c8bfecde8f4a0ad0f61aecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 22 Mar 2023 22:40:13 +0100 Subject: [PATCH] Move the twitter special-case URL handling to java --- UI/MiscScreens.cpp | 4 -- .../src/org/ppsspp/ppsspp/NativeActivity.java | 46 ++++++++++--------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index c99684bbe0..d6a5c4fecc 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -846,11 +846,7 @@ UI::EventReturn CreditsScreen::OnSupport(UI::EventParams &e) { } UI::EventReturn CreditsScreen::OnTwitter(UI::EventParams &e) { -#ifdef __ANDROID__ - System_SendMessage("showTwitter", "PPSSPP_emu"); -#else System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://twitter.com/#!/PPSSPP_emu"); -#endif return UI::EVENT_DONE; } diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index bd6857bef4..439f8a2b7a 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -1319,14 +1319,31 @@ public abstract class NativeActivity extends Activity { public boolean processCommand(String command, String params) { SurfaceView surfView = javaGL ? mGLSurfaceView : mSurfaceView; if (command.equals("launchBrowser")) { - try { - Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(params)); - startActivity(i); - return true; - } catch (Exception e) { - // No browser? - Log.e(TAG, e.toString()); - return false; + // Special case for twitter + if (params.startsWith("https://twitter.com/#!/")) { + try { + String twitter_user_name = params.replaceFirst("https://twitter.com/#!/", ""); + try { + Log.i(TAG, "Launching twitter directly: " + twitter_user_name); + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + twitter_user_name))); + } catch (Exception e) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/#!/" + twitter_user_name))); + } + return true; + } catch (Exception e) { // For example, android.content.ActivityNotFoundException + Log.e(TAG, e.toString()); + return false; + } + } else { + try { + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(params)); + startActivity(i); + return true; + } catch (Exception e) { + // No browser? + Log.e(TAG, e.toString()); + return false; + } } } else if (command.equals("launchEmail")) { try { @@ -1410,19 +1427,6 @@ public abstract class NativeActivity extends Activity { Log.e(TAG, e.toString()); return false; } - } else if (command.equals("showTwitter")) { - try { - String twitter_user_name = params; - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + twitter_user_name))); - } catch (Exception e) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/#!/" + twitter_user_name))); - } - return true; - } catch (Exception e) { // For example, android.content.ActivityNotFoundException - Log.e(TAG, e.toString()); - return false; - } } else if (command.equals("launchMarket")) { // Don't need this, can just use launchBrowser with a market: // http://stackoverflow.com/questions/3442366/android-link-to-market-from-inside-another-app