mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-06 09:06:55 +00:00
Android: Use the game title as the shortcut title.
This way when you have more than one, it's not just "PPSSPP" on each of them.
This commit is contained in:
parent
6320a875ad
commit
76cd5bf876
@ -1069,3 +1069,27 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
|
||||
WLOG("Render loop function exited.");
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" jstring Java_org_ppsspp_ppsspp_ShortcutActivity_queryGameName(JNIEnv *env, jclass, jstring jpath) {
|
||||
std::string path = GetJavaString(env, jpath);
|
||||
std::string result = "";
|
||||
|
||||
GameInfoCache *cache = new GameInfoCache();
|
||||
GameInfo *info = cache->GetInfo(nullptr, path, 0);
|
||||
// Wait until it's done: this is synchronous, unfortunately.
|
||||
if (info) {
|
||||
cache->WaitUntilDone(info);
|
||||
if (info->fileType != FILETYPE_UNKNOWN) {
|
||||
result = info->GetTitle();
|
||||
|
||||
// Pretty arbitrary, but the home screen will often truncate titles.
|
||||
// Let's remove "The " from names since it's common in English titles.
|
||||
if (result.length() > strlen("The ") && startsWithNoCase(result, "The ")) {
|
||||
result = result.substr(strlen("The "));
|
||||
}
|
||||
}
|
||||
}
|
||||
delete cache;
|
||||
|
||||
return env->NewStringUTF(result.c_str());
|
||||
}
|
||||
|
@ -5,4 +5,7 @@
|
||||
<string name="app_name">PPSSPP</string>
|
||||
<string name="shortcut_name">PPSSPP game</string>
|
||||
|
||||
</resources>
|
||||
<string name="bad_disc_title">Unsupported disc</string>
|
||||
<string name="bad_disc_message">The file you selected wasn\'t recognized as a game.</string>
|
||||
|
||||
</resources>
|
||||
|
@ -18,7 +18,7 @@ public class PpssppActivity extends NativeActivity {
|
||||
private static boolean m_hasNoNativeBinary = false;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
static void CheckABIAndLoadLibrary() {
|
||||
public static void CheckABIAndLoadLibrary() {
|
||||
if (Build.CPU_ABI.equals("armeabi")) {
|
||||
m_hasUnsupportedABI = true;
|
||||
} else {
|
||||
@ -73,13 +73,13 @@ public class PpssppActivity extends NativeActivity {
|
||||
// (from app drawer or file explorer).
|
||||
Intent intent = getIntent();
|
||||
String action = intent.getAction();
|
||||
if(Intent.ACTION_VIEW.equals(action))
|
||||
{
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
String path = intent.getData().getPath();
|
||||
super.setShortcutParam(path);
|
||||
Toast.makeText(getApplicationContext(), path, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
super.setShortcutParam(getIntent().getStringExtra(SHORTCUT_EXTRA_KEY));
|
||||
}
|
||||
else super.setShortcutParam(getIntent().getStringExtra(SHORTCUT_EXTRA_KEY));
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
@ -3,10 +3,12 @@ package org.ppsspp.ppsspp;
|
||||
import java.io.File;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.content.Intent.ShortcutIconResource;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Looper;
|
||||
|
||||
/**
|
||||
* This class will respond to android.intent.action.CREATE_SHORTCUT intent from
|
||||
@ -25,6 +27,8 @@ public class ShortcutActivity extends Activity {
|
||||
fileDialog.showDialog();
|
||||
}
|
||||
|
||||
public static native String queryGameName(String path);
|
||||
|
||||
// Create shortcut as response for ACTION_CREATE_SHORTCUT intent.
|
||||
private void respondToShortcutRequest(String path) {
|
||||
// This is Intent that will be sent when user execute our shortcut on
|
||||
@ -33,12 +37,18 @@ public class ShortcutActivity extends Activity {
|
||||
Intent shortcutIntent = new Intent(this, PpssppActivity.class);
|
||||
shortcutIntent.putExtra(PpssppActivity.SHORTCUT_EXTRA_KEY, path);
|
||||
|
||||
PpssppActivity.CheckABIAndLoadLibrary();
|
||||
String name = queryGameName(path);
|
||||
if (name.equals("")) {
|
||||
showBadGameMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
// This is Intent that will be returned by this method, as response to
|
||||
// ACTION_CREATE_SHORTCUT. Wrap shortcut intent inside this intent.
|
||||
Intent responseIntent = new Intent();
|
||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources()
|
||||
.getString(R.string.app_name));
|
||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
|
||||
ShortcutIconResource iconResource = Intent.ShortcutIconResource
|
||||
.fromContext(this, R.drawable.ic_launcher);
|
||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
||||
@ -50,6 +60,29 @@ public class ShortcutActivity extends Activity {
|
||||
finish();
|
||||
}
|
||||
|
||||
private void showBadGameMessage() {
|
||||
new Thread() {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ShortcutActivity.this);
|
||||
builder.setMessage(getResources().getString(R.string.bad_disc_message));
|
||||
builder.setTitle(getResources().getString(R.string.bad_disc_title));
|
||||
builder.create().show();
|
||||
Looper.loop();
|
||||
}
|
||||
}.start();
|
||||
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
// Event when a file is selected on file dialog.
|
||||
private SimpleFileChooser.FileSelectedListener onFileSelectedListener = new SimpleFileChooser.FileSelectedListener() {
|
||||
public void onFileSelected(File file) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user