Skip to content

Commit

Permalink
Attempt fix unable to copy error...
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Aug 11, 2020
1 parent 638a587 commit a25089f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
36 changes: 15 additions & 21 deletions app/src/main/java/java/awt/datatransfer/Clipboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,28 @@

import net.kdt.pojavlaunch.Tools;
import java.awt.mod.*;
import android.os.*;

public class Clipboard extends Object
{
private final Activity mActivity;
public static Context mSystemCtx;
public static ClipboardManager mClipboardAndroidMgr;
public Clipboard() {
mActivity = ModdingKit.getCurrentActivity();
// mActivity = ModdingKit.getCurrentActivity();
mSystemCtx = ModdingKit.getSystemContext();
mClipboardAndroidMgr = (ClipboardManager) mSystemCtx.getSystemService(Context.CLIPBOARD_SERVICE);
}

public synchronized void setContents(final Transferable contents, ClipboardOwner owner) {
try {
mActivity.runOnUiThread(new Runnable(){

new Handler().post(new Runnable(){
@Override
public void run()
{
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Minecraft", ((StringSelection) contents).getString());
clipboard.setPrimaryClip(clip);
public void run() {
ClipData clip = ClipData.newPlainText("Clipboard", ((StringSelection) contents).getString());
mClipboardAndroidMgr.setPrimaryClip(clip);

Toast.makeText(mActivity, "Copied to clipboard!", Toast.LENGTH_SHORT).show();
Toast.makeText(mSystemCtx, "Copied to clipboard!", Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}

private Transferable clipboardText;
Expand All @@ -41,15 +38,12 @@ public synchronized Transferable getContents(Object requestor) {
try {
clipboardPasted = false;

mActivity.runOnUiThread(new Runnable(){

new Handler().post(new Runnable(){
@Override
public void run()
{
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
clipboardText = new StringSelection(clipboard.getText().toString());
public void run() {
clipboardText = new StringSelection(mClipboardAndroidMgr.getText().toString());
clipboardPasted = true;
Toast.makeText(mActivity, "Paste from clipboard", Toast.LENGTH_SHORT).show();
Toast.makeText(mSystemCtx, "Paste from clipboard", Toast.LENGTH_SHORT).show();
}
});

Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/java/awt/mod/ModdingKit.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package java.awt.mod;

import android.app.*;
import android.content.*;
import android.graphics.*;
import java.awt.image.*;
import java.lang.reflect.*;
import java.util.*;
import net.kdt.pojavlaunch.*;

public class ModdingKit
{
public static Activity getCurrentActivity()
{
public static Context getSystemContext() {
try {
// ActivityThread.currentActivityThread().getSystemContext();
Class activityThreadClass = Class.forName("android.app.ActivityThread");
Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null);
return (Context) activityThreadClass.getDeclaredMethod("getSystemContext").invoke(activityThread);
} catch (Throwable th) {
return null;
}
}

public static Activity getCurrentActivity() {
try {
Class activityThreadClass = Class.forName("android.app.ActivityThread");
Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null);
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.lang.reflect.*;
import dalvik.system.*;
import optifine.*;
import android.text.*;
import java.awt.*;
import javax.xml.transform.*;
import java.awt.datatransfer.*;
Expand Down Expand Up @@ -220,7 +219,11 @@ public void onClick(DialogInterface p1, int p2)
{
StringSelection errData = new StringSelection(errMsg);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(errData, null);


ClipboardManager cmgr = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Error", Log.getStackTraceString(e));
cmgr.setPrimaryClip(clip);

if(exitIfOk) {
if (ctx instanceof MainActivity) {
MainActivity.fullyExit();
Expand Down

0 comments on commit a25089f

Please sign in to comment.