mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04: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
4 changed files with 67 additions and 7 deletions
|
@ -1069,3 +1069,27 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
|
||||||
WLOG("Render loop function exited.");
|
WLOG("Render loop function exited.");
|
||||||
return true;
|
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="app_name">PPSSPP</string>
|
||||||
<string name="shortcut_name">PPSSPP game</string>
|
<string name="shortcut_name">PPSSPP game</string>
|
||||||
|
|
||||||
|
<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>
|
</resources>
|
|
@ -18,7 +18,7 @@ public class PpssppActivity extends NativeActivity {
|
||||||
private static boolean m_hasNoNativeBinary = false;
|
private static boolean m_hasNoNativeBinary = false;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
static void CheckABIAndLoadLibrary() {
|
public static void CheckABIAndLoadLibrary() {
|
||||||
if (Build.CPU_ABI.equals("armeabi")) {
|
if (Build.CPU_ABI.equals("armeabi")) {
|
||||||
m_hasUnsupportedABI = true;
|
m_hasUnsupportedABI = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -73,13 +73,13 @@ public class PpssppActivity extends NativeActivity {
|
||||||
// (from app drawer or file explorer).
|
// (from app drawer or file explorer).
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if(Intent.ACTION_VIEW.equals(action))
|
if (Intent.ACTION_VIEW.equals(action)) {
|
||||||
{
|
|
||||||
String path = intent.getData().getPath();
|
String path = intent.getData().getPath();
|
||||||
super.setShortcutParam(path);
|
super.setShortcutParam(path);
|
||||||
Toast.makeText(getApplicationContext(), path, Toast.LENGTH_SHORT).show();
|
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);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,12 @@ package org.ppsspp.ppsspp;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.Intent.ShortcutIconResource;
|
import android.content.Intent.ShortcutIconResource;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will respond to android.intent.action.CREATE_SHORTCUT intent from
|
* This class will respond to android.intent.action.CREATE_SHORTCUT intent from
|
||||||
|
@ -25,6 +27,8 @@ public class ShortcutActivity extends Activity {
|
||||||
fileDialog.showDialog();
|
fileDialog.showDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static native String queryGameName(String path);
|
||||||
|
|
||||||
// Create shortcut as response for ACTION_CREATE_SHORTCUT intent.
|
// Create shortcut as response for ACTION_CREATE_SHORTCUT intent.
|
||||||
private void respondToShortcutRequest(String path) {
|
private void respondToShortcutRequest(String path) {
|
||||||
// This is Intent that will be sent when user execute our shortcut on
|
// 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);
|
Intent shortcutIntent = new Intent(this, PpssppActivity.class);
|
||||||
shortcutIntent.putExtra(PpssppActivity.SHORTCUT_EXTRA_KEY, path);
|
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
|
// This is Intent that will be returned by this method, as response to
|
||||||
// ACTION_CREATE_SHORTCUT. Wrap shortcut intent inside this intent.
|
// ACTION_CREATE_SHORTCUT. Wrap shortcut intent inside this intent.
|
||||||
Intent responseIntent = new Intent();
|
Intent responseIntent = new Intent();
|
||||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources()
|
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
|
||||||
.getString(R.string.app_name));
|
|
||||||
ShortcutIconResource iconResource = Intent.ShortcutIconResource
|
ShortcutIconResource iconResource = Intent.ShortcutIconResource
|
||||||
.fromContext(this, R.drawable.ic_launcher);
|
.fromContext(this, R.drawable.ic_launcher);
|
||||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
||||||
|
@ -50,6 +60,29 @@ public class ShortcutActivity extends Activity {
|
||||||
finish();
|
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.
|
// Event when a file is selected on file dialog.
|
||||||
private SimpleFileChooser.FileSelectedListener onFileSelectedListener = new SimpleFileChooser.FileSelectedListener() {
|
private SimpleFileChooser.FileSelectedListener onFileSelectedListener = new SimpleFileChooser.FileSelectedListener() {
|
||||||
public void onFileSelected(File file) {
|
public void onFileSelected(File file) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue