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 00000000..d42400f3
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/clipboard.png differ
diff --git a/app/src/main/res/layout/activity_manage_action_copy_to_clipboard.xml b/app/src/main/res/layout/activity_manage_action_copy_to_clipboard.xml
index 08670312..7cc02e07 100644
--- a/app/src/main/res/layout/activity_manage_action_copy_to_clipboard.xml
+++ b/app/src/main/res/layout/activity_manage_action_copy_to_clipboard.xml
@@ -35,11 +35,6 @@
android:layout_height="wrap_content"
android:text="@string/urlLegend" />
-
-