From e4e3faea060ec128092554fd5bf2ca9c8fa6131a Mon Sep 17 00:00:00 2001 From: Jens Date: Wed, 15 Mar 2023 23:27:27 +0100 Subject: [PATCH] copy to clipboard action --- .../java/com/jens/automation2/Action.java | 5 +++- .../java/com/jens/automation2/Actions.java | 19 +++++++++----- .../jens/automation2/ActivityManageRule.java | 16 ++++++++++++ .../com/jens/automation2/Miscellaneous.java | 24 +++++++++++++++++- app/src/main/res/drawable-hdpi/clipboard.png | Bin 0 -> 2615 bytes ...tivity_manage_action_copy_to_clipboard.xml | 5 ---- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values-nl/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- .../metadata/android/en-US/changelogs/127.txt | 3 ++- 14 files changed, 64 insertions(+), 22 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/clipboard.png diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index e83ea081..8e5a44a2 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -414,7 +414,7 @@ public class Action { returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ").replace(Action.intentPairSeparator, "/")); } - else if (this.getAction().equals(Action_Enum.setVariable)) + else if(this.getAction().equals(Action_Enum.setVariable) || this.getAction().equals(Action_Enum.copyToClipboard)) ; // it's completed further above already else if (parameter2 != null && parameter2.length() > 0) returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ")); @@ -629,6 +629,9 @@ public class Action case stopPhoneCall: Actions.endPhoneCall(context); break; + case copyToClipboard: + Actions.copyToClipboard(context, Miscellaneous.replaceVariablesInText(this.getParameter2(), context)); + break; default: Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3); break; diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index e6ccfa23..59db6c67 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -12,7 +12,6 @@ import android.bluetooth.BluetoothProfile; import android.content.ActivityNotFoundException; import android.content.ClipData; import android.content.ClipboardManager; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.media.AudioManager; @@ -21,7 +20,6 @@ import android.net.ConnectivityManager; import android.net.Uri; import android.net.wifi.WifiManager; import android.os.Build; -import android.os.Bundle; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.VibrationEffect; @@ -32,7 +30,6 @@ import android.telecom.TelecomManager; import android.telephony.SmsManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; -import android.text.TextUtils; import android.util.Log; import android.view.KeyEvent; import android.widget.Toast; @@ -56,7 +53,6 @@ import org.apache.http.impl.client.DefaultHttpClient; import java.io.BufferedReader; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -2302,9 +2298,18 @@ public class Actions public static void copyToClipboard(Context context, String text) { - ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText(text, url); - clipboard.setPrimaryClip(clip); + Miscellaneous.logEvent("i", "Clipboard", "Copying data to clipboard: " + text, 4); + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) + { + android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText(text); + } + else + { + android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + android.content.ClipData clip = android.content.ClipData.newPlainText("Data-from-Automation", text); + clipboard.setPrimaryClip(clip); + } } } \ No newline at end of file diff --git a/app/src/main/java/com/jens/automation2/ActivityManageRule.java b/app/src/main/java/com/jens/automation2/ActivityManageRule.java index 0fc387da..2795b131 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageRule.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageRule.java @@ -2035,6 +2035,20 @@ public class ActivityManageRule extends Activity this.refreshActionList(); } } + else if(requestCode == requestCodeActionCopyTextToClipboardEdit) + { + if(resultCode == RESULT_OK) + { + ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit); + + if(data.hasExtra(intentNameActionParameter2)) + { + ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2)); + } + + this.refreshActionList(); + } + } } protected AlertDialog getActionTypeDialog() @@ -2109,6 +2123,8 @@ public class ActivityManageRule extends Activity if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.SEND_SMS)) items.add(new Item(typesLong[i].toString(), R.drawable.message)); } + else if(types[i].toString().equals(Action_Enum.copyToClipboard.toString())) + items.add(new Item(typesLong[i].toString(), R.drawable.clipboard)); else items.add(new Item(typesLong[i].toString(), R.drawable.placeholder)); } diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index ef838767..3197d37a 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -616,10 +616,12 @@ public class Miscellaneous extends Service } if(source.contains("[serialnr]")) - if(Build.VERSION.SDK_INT > 8) + { + if (Build.VERSION.SDK_INT > 8) source = source.replace("[serialnr]", Secure.getString(context.getContentResolver(), Build.SERIAL)); else source = source.replace("[serialnr]", "serialUnknown"); + } if( source.contains("[d]") || @@ -740,6 +742,26 @@ public class Miscellaneous extends Service Miscellaneous.logEvent("w", "Variable replacement", "lastNotification was empty.", 3); } } + + while(source.contains("[variable-")) + { + int pos1 = source.indexOf("[variable-"); + int pos2 = source.indexOf("]", pos1); + + int posA = pos1 + "[variable-".length(); + int posB = source.indexOf("]", posA); + + String variableName = source.substring(posA, posB); + + String replacement; + + if(AutomationService.getInstance().variableMap.containsKey(variableName)) + replacement = AutomationService.getInstance().variableMap.get(variableName); + else + replacement = "unknownVariable"; + + source = source.substring(0, pos1) + replacement + source.substring(pos2); + } // Miscellaneous.logEvent("i", "URL after replace", source); diff --git a/app/src/main/res/drawable-hdpi/clipboard.png b/app/src/main/res/drawable-hdpi/clipboard.png new file mode 100644 index 0000000000000000000000000000000000000000..d42400f38e57adb2be3e925c7905527446fa46a4 GIT binary patch literal 2615 zcmV-73dr?|P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf6951U69E94oEQKA3Cu}EK~!i%)meE^ zRo5B+z5TI1co-@f5x0m!#3pFew3@gETySk-7L#aNXVTP8J9VbhM2#kzOefQ6|Lmmy zB-W%F_brG51`I_~Gm;RsktoO_@IVya25-ClzH{$;d8myG#|-`+-#zD^dpYNPzxzAi zIpW2LZnra5D~iGh>+{c^m+qgW8<)U z&rZdCcJ~K5*X25@GtzJ3t(VSr{Nr=fYeiBZm6){!_R9RHUz;4Cm<+v+pSI{Ybi~xb zlMNU-<`F!cJr*vPOE@jaAu@tdL_`zD<#9yHg}QoNt~-Odxr69>kXlkJ=E3H6cA@y- zM<@SssB4Poge2&-R0`}544FLX@o5;EYQZ(X6^)(*G&~?7nL#fN<#HlY&i~n!&*>TyIg3G-r==ADf^VcFLYb5N0(k5$NkOqU6 zO2Mp0f3h)m(o~dHHz8%j6pS1H7}AH0#*mEB7(FHng+<5E+uKXSLx*l6h?V1Xxyf8` zx!rW`hFeSd+)X6aes>X$_71H1&F?TGb3D?AXCr-NHiFg%akjP|>2@P(YQ8~fb;l;H z8&V*3D82K_IA!IUjX3^IC*~FW0zM)k+=8Bl)3MUy*t72-g28}V$Rk3{ML{j$A;>To z3@DhNk6AOG6vIxG(}Cm8kwd$Xo7#z8+qYuf2j5EdMJ_R`9#&p_Z9OW^yOB3{34H!u z1Ofpubi!~tUGN9|>WOe(jTPaT5oW|{w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