From 134ebebb93c7b49793f0da64beda9e513f8f755d Mon Sep 17 00:00:00 2001 From: valef Date: Sun, 5 Jan 2014 22:54:50 +0700 Subject: [PATCH] Added ShortcutActivity class to respond to homescreen shortcut intent. It will show file dialog and return path to selected file as intent response. --- .../org/ppsspp/ppsspp/ShortcutActivity.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 android/src/org/ppsspp/ppsspp/ShortcutActivity.java diff --git a/android/src/org/ppsspp/ppsspp/ShortcutActivity.java b/android/src/org/ppsspp/ppsspp/ShortcutActivity.java new file mode 100644 index 0000000000..5f7ad0731c --- /dev/null +++ b/android/src/org/ppsspp/ppsspp/ShortcutActivity.java @@ -0,0 +1,64 @@ +package org.ppsspp.ppsspp; + +import java.io.File; + +import com.henrikrydgard.libnative.NativeActivity; + +import android.app.Activity; +import android.content.Intent; +import android.content.Intent.ShortcutIconResource; +import android.os.Bundle; +import android.os.Environment; + +/** + * This class will respond to android.intent.action.CREATE_SHORTCUT intent from + * launcher homescreen. Register this class in AndroidManifest.xml. + */ +public class ShortcutActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Show file selector dialog here. + SimpleFileChooser fileDialog = new SimpleFileChooser(this, + Environment.getExternalStorageDirectory(), + onFileSelectedListener); + fileDialog.showDialog(); + } + + // 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 + // homescreen. Set our app as target Context. Set Main activity as + // target class. Add any parameter to extra. + Intent shortcutIntent = new Intent(this, PpssppActivity.class); + shortcutIntent.putExtra(NativeActivity.SHORTCUT_EXTRA_KEY, path); + + // 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)); + + ShortcutIconResource iconResource = Intent.ShortcutIconResource + .fromContext(this, R.drawable.ic_launcher); + responseIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, + iconResource); + + setResult(RESULT_OK, responseIntent); + + // Must call finish for result to be returned immediately + finish(); + } + + // Event when a file is selected on file dialog. + private SimpleFileChooser.FileSelectedListener onFileSelectedListener = new SimpleFileChooser.FileSelectedListener() { + public void onFileSelected(File file) { + // create shortcut using file path + respondToShortcutRequest(file.getAbsolutePath()); + } + }; + +}