mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Android: Add support to copy strings to clipboard
This commit is contained in:
parent
d95ae30717
commit
9a193261f4
3 changed files with 23 additions and 0 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include "Common/File/FileUtil.h"
|
#include "Common/File/FileUtil.h"
|
||||||
#include "Common/StringUtils.h"
|
#include "Common/StringUtils.h"
|
||||||
#include "Common/System/System.h"
|
#include "Common/System/System.h"
|
||||||
|
#include "Common/System/OSD.h"
|
||||||
#include "Common/System/Request.h"
|
#include "Common/System/Request.h"
|
||||||
#include "Common/System/NativeApp.h"
|
#include "Common/System/NativeApp.h"
|
||||||
#include "Core/Config.h"
|
#include "Core/Config.h"
|
||||||
|
@ -161,6 +162,8 @@ void GameScreen::CreateViews() {
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
snprintf(buffer, sizeof(buffer), "%08X", crc);
|
snprintf(buffer, sizeof(buffer), "%08X", crc);
|
||||||
System_CopyStringToClipboard(buffer);
|
System_CopyStringToClipboard(buffer);
|
||||||
|
// Success indication. Not worth a translatable string.
|
||||||
|
g_OSD.Show(OSDType::MESSAGE_SUCCESS, buffer, 1.0f);
|
||||||
return UI::EVENT_DONE;
|
return UI::EVENT_DONE;
|
||||||
});
|
});
|
||||||
tvCRCCopy_->SetVisibility(crcVisibility);
|
tvCRCCopy_->SetVisibility(crcVisibility);
|
||||||
|
|
|
@ -499,6 +499,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
|
||||||
case SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE:
|
case SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE:
|
||||||
return sustainedPerfSupported; // 7.0 introduced sustained performance mode as an optional feature.
|
return sustainedPerfSupported; // 7.0 introduced sustained performance mode as an optional feature.
|
||||||
case SYSPROP_HAS_TEXT_INPUT_DIALOG:
|
case SYSPROP_HAS_TEXT_INPUT_DIALOG:
|
||||||
|
return androidVersion >= 11; // honeycomb
|
||||||
|
case SYSPROP_HAS_TEXT_CLIPBOARD:
|
||||||
return true;
|
return true;
|
||||||
case SYSPROP_HAS_OPEN_DIRECTORY:
|
case SYSPROP_HAS_OPEN_DIRECTORY:
|
||||||
return false; // We have this implemented but it may or may not work depending on if a file explorer is installed.
|
return false; // We have this implemented but it may or may not work depending on if a file explorer is installed.
|
||||||
|
@ -1114,6 +1116,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
|
||||||
case SystemRequestType::RECREATE_ACTIVITY:
|
case SystemRequestType::RECREATE_ACTIVITY:
|
||||||
PushCommand("recreate", param1);
|
PushCommand("recreate", param1);
|
||||||
return true;
|
return true;
|
||||||
|
case SystemRequestType::COPY_TO_CLIPBOARD:
|
||||||
|
PushCommand("copy_to_clipboard", param1);
|
||||||
|
return true;
|
||||||
case SystemRequestType::INPUT_TEXT_MODAL:
|
case SystemRequestType::INPUT_TEXT_MODAL:
|
||||||
{
|
{
|
||||||
std::string serialized = StringFromFormat("%d:@:%s:@:%s", requestId, param1.c_str(), param2.c_str());
|
std::string serialized = StringFromFormat("%d:@:%s:@:%s", requestId, param1.c_str(), param2.c_str());
|
||||||
|
|
|
@ -7,6 +7,8 @@ import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.UiModeManager;
|
import android.app.UiModeManager;
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -1666,10 +1668,23 @@ public abstract class NativeActivity extends Activity {
|
||||||
NativeApp.reportException(e, params);
|
NativeApp.reportException(e, params);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (command.equals("copy_to_clipboard")) {
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||||
|
copyStringToClipboard(params);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Unknown string command " + command);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
|
private void copyStringToClipboard(String text) {
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clip = ClipData.newPlainText("Copied Text", text);
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@Override
|
@Override
|
||||||
public void recreate() {
|
public void recreate() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue