diff options
3 files changed, 29 insertions, 32 deletions
diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java index 4070f955f..54e6363ce 100644 --- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java +++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java @@ -56,6 +56,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.BufferedWriter; import java.net.URI; import java.net.URISyntaxException; import java.nio.ByteBuffer; @@ -1105,10 +1106,9 @@ public class LOActivity extends AppCompatActivity { File clipboardFile = new File(getApplicationContext().getCacheDir(), CLIPBOARD_FILE_PATH); LokClipboardData clipboardData = null; - if (clipboardFile.exists()) { - clipboardData = new LokClipboardData(); - clipboardData.loadFromFile(clipboardFile); - } + if (clipboardFile.exists()) + clipboardData = LokClipboardData.createFromFile(clipboardFile); + if (clipboardData != null) { LOActivity.this.setClipboardContent(clipboardData); LOActivity.this.postUnoCommand(".uno:Paste", null, false); diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/lok/LokClipboardData.java b/android/lib/src/main/java/org/libreoffice/androidlib/lok/LokClipboardData.java index 3d98b5dfe..85fc62710 100644 --- a/android/lib/src/main/java/org/libreoffice/androidlib/lok/LokClipboardData.java +++ b/android/lib/src/main/java/org/libreoffice/androidlib/lok/LokClipboardData.java @@ -4,17 +4,21 @@ import android.util.Base64; import android.util.JsonReader; import android.util.JsonWriter; +import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; -import java.io.FileWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -public class LokClipboardData { +public class LokClipboardData implements Serializable { public ArrayList<LokClipboardEntry> clipboardEntries = new ArrayList<LokClipboardEntry>(); public String getText() { @@ -37,16 +41,11 @@ public class LokClipboardData { public boolean writeToFile(File file) { try { - FileWriter fileWriter = new FileWriter(file.getAbsoluteFile()); - JsonWriter writer = new JsonWriter(fileWriter); - writer.setIndent(" "); - writer.beginObject(); - for (LokClipboardEntry entry : clipboardEntries) { - writer.name(entry.mime); - writer.value(Base64.encodeToString(entry.data, Base64.DEFAULT)); - } - writer.endObject(); - writer.close(); + FileOutputStream fileStream = new FileOutputStream(file.getAbsoluteFile()); + ObjectOutputStream oos = new ObjectOutputStream(fileStream); + oos.writeObject(this); + oos.close(); + fileStream.close(); } catch (IOException e) { e.printStackTrace(); return false; @@ -54,25 +53,21 @@ public class LokClipboardData { return true; } - public boolean loadFromFile(File file) { + public static LokClipboardData createFromFile(File file) { try { - clipboardEntries.clear(); - - FileReader fileReader= new FileReader(file.getAbsoluteFile()); - JsonReader reader = new JsonReader(fileReader); - reader.beginObject(); - while (reader.hasNext()) { - LokClipboardEntry entry = new LokClipboardEntry(); - entry.mime = reader.nextName(); - entry.data = Base64.decode(reader.nextString(), Base64.DEFAULT); - clipboardEntries.add(entry); - } - reader.endObject(); + FileInputStream fileStream = new FileInputStream(file.getAbsoluteFile()); + ObjectInputStream ois = new ObjectInputStream(fileStream); + LokClipboardData data = (LokClipboardData)ois.readObject(); + ois.close(); + fileStream.close(); + return data; } catch (IOException e) { e.printStackTrace(); - return false; + return null; + } catch (ClassNotFoundException e) { + e.printStackTrace(); + return null; } - return true; } public LokClipboardEntry getBest() { diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/lok/LokClipboardEntry.java b/android/lib/src/main/java/org/libreoffice/androidlib/lok/LokClipboardEntry.java index 3593f0394..c1c01a657 100644 --- a/android/lib/src/main/java/org/libreoffice/androidlib/lok/LokClipboardEntry.java +++ b/android/lib/src/main/java/org/libreoffice/androidlib/lok/LokClipboardEntry.java @@ -1,6 +1,8 @@ package org.libreoffice.androidlib.lok; -public class LokClipboardEntry { +import java.io.Serializable; + +public class LokClipboardEntry implements Serializable { public String mime; public byte[] data; } |