├── README.md
├── autotoolsfunctions.js
├── autotoolsfunctions.js.bak
├── autotoolsstyle.css
└── demos
├── bubble
├── instructions.html
└── page.html
├── cardlist
└── cardlist.html
├── functions
└── functiondemo.html
├── input
└── page.html
├── loading
├── bounce.css
├── bounce.html
├── chasingdots.css
├── chasingdots.html
├── circle.css
├── circle.html
├── colorcircles.css
├── colorcircles.html
├── cubegrid.css
├── cubegrid.html
├── doublebounce.css
├── doublebounce.html
├── fadingcircle.css
├── fadingcircle.html
├── foldingcube.css
├── foldingcube.html
├── googlematerialbounce.css
├── googlematerialbounce.html
├── googlematerialpreloader.css
├── googlematerialpreloader.html
├── instructions.html
├── pacman.css
├── pacman.html
├── page.html
├── pulse.css
├── pulse.html
├── redvortex.css
├── redvortex.html
├── rotatingplane.css
├── rotatingplane.html
├── shrinkinghexagon.css
├── shrinkinghexagon.html
├── simpledots.css
├── simpledots.html
├── spinningflower.css
├── spinningflower.html
├── stairs.css
├── stairs.html
├── test.html
├── threebounce.css
├── threebounce.html
├── uphill.css
├── uphill.html
├── wanderingcubes.css
├── wanderingcubes.html
├── wave.css
└── wave.html
└── updating
└── page.html
/README.md:
--------------------------------------------------------------------------------
1 | # AutoToolsWebScreens
2 | Stuff injected into every AutoTools web Screens that you can use in your own Web Screen presets
3 |
4 | # Quick Start
5 | Look at [this](demos/input/page.html) example on how to create a simple Web Screen with an input field.
6 | You'll learn how to make a Web Screen send out an AutoApps command and what a basic page structure looks like.
7 | You can even use the [direct link](https://raw.githubusercontent.com/joaomgcd/AutoToolsWebScreens/master/demos/input/page.html) of the file as the **Source** in the AutoTools Web Screen action and see it action on your Android device.
8 |
9 | # Full Tutorial
10 | If you want a step by step tutorial on how to create your own Web Screen check [here](http://forum.joaoapps.com/index.php?resources/full-overview-on-creating-an-autotools-web-screen.284/).
11 |
12 | # How To Use
13 | Look into each file and stuff will be documented :)
14 |
15 | If you want to try out the demos you can do so by using the direct raw Github URL as the Source in the **AutoTools Web Screen** action. For example, to use the card list demo, use [this](https://raw.githubusercontent.com/joaomgcd/AutoToolsWebScreens/master/demos/cardlist/cardlist.html) as the source.
16 |
17 | # Web Screen Variables
18 | You can create custom variables for a page used as an AutoTools Web Screen.
19 |
20 | To do this include a special tag in the pages head section with the following format:
21 |
22 | **<meta name="autotoolswebscreen" type="variablejs" group="Title" id="titleFromTasker" label="Title" description="Title to show at the top." hint="YouTube" />**
23 |
24 | Let's break it down:
25 |
26 | * **name** - is always **autotoolswebscreen**
27 | * **type** - can be **variablejs** (will create a JavaScript variable) or **variablehtml** (will replace an html element with the specified ID)
28 | * **group** - is used to group variables together in the AutoTools Web Screen Tasker configuration screen
29 | * **id** - the name of the JavaScript variable or HTML element to create/replace
30 | * **label** - title of the option in the configuration screen
31 | * **description** - summary of the option in the configuration screen
32 | * **hint** - placeholder text of the option in the configuration screen
33 |
34 | Here are other possible fields for this ***<meta>** tag
35 |
36 | * **subtype** - can be **boolean** to make the option in Tasker a switch instead of a text input. In JavaScript will create a variable with either true or false
37 | * **defaultValue** - pre-filled value for the field
38 | * **options** - If set, will create an options field in the AutoTools Web Screen Tasker configuration screen instead of a direct text input field. Set to a comma separated list of values.
39 | * **isIcon** - if **true** then the input field in the AutoTools Web Screen Tasker configuration screen will prompt the user to browse for an icon
40 | * **isIcons** - same as above but supports multiple icons
41 | * **isImage** and **isImages** - same as above but for generic images
42 | * **isColor** - same as above but to browse for a color
43 | * **isFile** - same as above but to browse for a file of any type
44 | * **attribute (HTML Variable Only)** - allows you to specify an attribute to set instead of setting the inner HTML of an element (for example, setting the **href** of an **a** element)
45 |
46 | [Here](demos/cardlist/cardlist.html)'s an example of a screen where multiple variables are used. Take a look at the source code of the page for some examples.
47 |
48 | # Web Screen Functions
49 | AutoTools automatically creates some convenience JavaScript functions for you so it's easier to do certain things with the data from Web Screen Variables.
50 |
51 | You can check out all of the functions [here](autotoolsfunctions.js).
52 |
53 | Here are a few of the main ones:
54 |
55 | * **AutoTools.sendCommand(command, prefix, hapticFeedback)** - Allows you to send an AutoApps command. **prefix** is optional and if present will prepend **=:=** to the command. Example: **<div onclick="AutoTools.sendCommand('hello!')">Say Hello</div>** will send the "hello" command when clicked. If you set the third parameter to true it'll perform haptic feedback with the command.
56 | * **AutoTools.isSet(varName)** - returns true if the Web Screen Variable with the provide name is set, false otherwise
57 | * **AutoTools.setDefault(varName,value)** - sets the variable with name **varName** to the value **value** if it's not set from Tasker
58 | * **AutoTools.setDefaultValues(valuesObject)** - accepts an object like **{"var1":"value1","var2":"value2"}** and calls the **AutoTools.setDefault** function for each of the names and values in the object, so you can set all your default values in one call. Check [the source of this page](demos/functions/functiondemo.html) for an example on how to use this.
59 | * **AutoTools.hide(element)** - hides an element on the page
60 | * **AutoTools.show(element)** - shows an element on the page
61 | * **AutoTools.variablesToElements(variableNamesArray, rootElementsId, rootElementClass, itemTransformer)** - converts AutoTools Web Screen variables to HTML elements on a list. **itemTransformer** is optional and if present will be called for every element that's created. Check [the source of this page](demos/functions/functiondemo.html) for an example on how to use this.
62 |
63 | # Updating Values
64 |
65 | Instead of doing a full refresh every time AutoTools allows you to update stuff on the page. This is done by AutoTools calling the
66 | ```
67 | autoToolsUpdateValues(values)
68 | ```
69 | function when it wants to update values so you need to declare it on the page if you want to support updating.
70 | **values** will contain an object with properties named after the Web Screen variables declared on the page. So, for example, if you declare a **title** and a **text** variable on the page, you'll get an object like
71 |
72 | ```
73 | {
74 | "title":"Some Title",
75 | "text:"some text"
76 | }
77 | ```
78 | You can then update the values on the page how ever you please based on this object.
79 |
80 | The **Update** option will only show in the Tasker configuration screen if the **autoToolsUpdateValues()** function is present on the main **Source** page.
81 |
82 | Check out [this](demos/updating/page.html) demo for a working web screen with the updating feature.
83 | # Debugging
84 |
85 | You can use
86 | ```
87 | console.debug("log message");
88 | ```
89 | to make logs show up in the AutoTools logs if **System Logs** are enabled in the main AutoTools app under **Logs And Alerts**.
90 |
91 | If there's an error message in the console and the **Close On Error** option is set in Tasker the screen will close.
92 |
--------------------------------------------------------------------------------
/autotoolsfunctions.js:
--------------------------------------------------------------------------------
1 | /**
2 | * These functions will automatically be injected into every page that is loaded with the AutoTools Web Screen action in Tasker.
3 | * You can use them freely in your own web screens! :)
4 | * If you want you can copy these to your web screen for easy testing on your PC.
5 | * Only the functions that call AutoToolsAndroid functions will not work on your PC, like the AutoTools.say function for example.
6 | */
7 |
8 | /**
9 | * Create base AutoTools object that will contain everything else
10 | */
11 | var AutoTools = {};
12 |
13 | /**
14 | * Send an AutoApps command from JavaScript.
15 | * @param {string} command - The command you want to send
16 | * @param {string} [prefix] - An optional prefix that will be prepended to the command. If it exists command will have the prefix=:=command format
17 | * @param {boolean} [hapticFeedback] - If true, will perform a short vibration with the command
18 | */
19 | AutoTools.sendCommand = function(command, prefix, hapticFeedback){
20 | if(!command){
21 | return;
22 | }
23 | if(!prefix){
24 | prefix = null;
25 | }
26 | console.log("Sending command: " + command+";"+prefix);
27 | AutoToolsAndroid.sendCommand(command, prefix, hapticFeedback);
28 | }
29 |
30 | /**
31 | * Easily assign a command to an HTML element
32 | * @param {string} selector - The CSS selector for the element. For example, to specify an element with the id "link", you should pass in "#link"
33 | * @param {string} command - The command you want to send
34 | * @param {string} [prefix] - An optional prefix that will be prepended to the command. If it exists command will have the prefix=:=command format
35 | */
36 | AutoTools.commandOnClick = function(selector, command, prefix){
37 | document.querySelector(selector).onclick = e => AutoTools.sendCommand(command, prefix);
38 | }
39 | /**
40 | * Change a color dynamically. Got it from here: https://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color-or-rgb-and-blend-colors
41 | * Example use: Have color #ff0000 (red) and want a 30% darker shade of red, would call AutoTools.shadeBlendConvert(-0.3, "#ff0000");
42 | */
43 | AutoTools.shadeBlendConvert = function(p, from, to) {
44 | if(typeof(p)!="number"||p<-1||p>1||typeof(from)!="string"||(from[0]!='r'&&from[0]!='#')||(typeof(to)!="string"&&typeof(to)!="undefined"))return null;
45 | var sbcRip=function(d){
46 | var l=d.length,RGB=new Object();
47 | if(l>9){
48 | d=d.split(",");
49 | if(d.length<3||d.length>4)return null;
50 | RGB[0]=i(d[0].slice(4)),RGB[1]=i(d[1]),RGB[2]=i(d[2]),RGB[3]=d[3]?parseFloat(d[3]):-1;
51 | }else{
52 | if(l==8||l==6||l<4)return null;
53 | if(l<6)d="#"+d[1]+d[1]+d[2]+d[2]+d[3]+d[3]+(l>4?d[4]+""+d[4]:"");
54 | d=i(d.slice(1),16),RGB[0]=d>>16&255,RGB[1]=d>>8&255,RGB[2]=d&255,RGB[3]=l==9||l==5?r(((d>>24&255)/255)*10000)/10000:-1;
55 | }
56 | return RGB;}
57 | var i=parseInt,r=Math.round,h=from.length>9,h=typeof(to)=="string"?to.length>9?true:to=="c"?!h:false:h,b=p<0,p=b?p*-1:p,to=to&&to!="c"?to:b?"#000000":"#FFFFFF",f=sbcRip(from),t=sbcRip(to);
58 | if(!f||!t)return null;
59 | if(h)return "rgb("+r((t[0]-f[0])*p+f[0])+","+r((t[1]-f[1])*p+f[1])+","+r((t[2]-f[2])*p+f[2])+(f[3]<0&&t[3]<0?")":","+(f[3]>-1&&t[3]>-1?r(((t[3]-f[3])*p+f[3])*10000)/10000:t[3]<0?f[3]:t[3])+")");
60 | else return "#"+(0x100000000+(f[3]>-1&&t[3]>-1?r(((t[3]-f[3])*p+f[3])*255):t[3]>-1?r(t[3]*255):f[3]>-1?r(f[3]*255):255)*0x1000000+r((t[0]-f[0])*p+f[0])*0x10000+r((t[1]-f[1])*p+f[1])*0x100+r((t[2]-f[2])*p+f[2])).toString(16).slice(f[3]>-1||t[3]>-1?1:3);
61 | };
62 |
63 | /**
64 | * Brighten the color of a property in a CSS rule
65 | * @param {Object} rule - The cssRule object you want to change
66 | * @param {string} propertyName - The property you want to change ("background-color" for example)
67 | * @param {string} percent - Value from 0 to 100 you want to change
68 | * @param {boolean} darken - If true will darken the color instead of brightening it
69 | */
70 | AutoTools.increaseBrightnessRule = function(rule, propertyName, percent, darken){
71 | var originalColor = rule.style.getPropertyValue(propertyName);
72 | if(!originalColor){
73 | return;
74 | }
75 | originalColor = originalColor.trim();
76 | var newColor = AutoTools.shadeBlendConvert(percent/100,originalColor);
77 | rule.style.setProperty(propertyName, newColor);
78 | return newColor;
79 | };
80 |
81 | /**
82 | * Check if the value of a Web Screen Variable was set from Tasker
83 | * @param {string} value - Name of the variable you want to check
84 | */
85 | AutoTools.isSet = value => {
86 | value = window[value];
87 | if(value === undefined || value === null){
88 | return false;
89 | }
90 | var toClass = {}.toString.call(value);
91 | if(toClass == "[object Boolean]"){
92 | return true;
93 | }
94 | return toClass == "[object String]";
95 | };
96 | /**
97 | * Set the value of a Web Screen variable if it hasn't been set already from Tasker
98 | * @param {string} variable - The name of the variable you want to set
99 | * @param {string} value - The value you want to set if it hasn't been set from Tasker
100 | */
101 | AutoTools.setDefault = (variable, value) => {
102 | if(!AutoTools.isSet(variable)){
103 | window[variable] = value;
104 | }
105 | };
106 | /**
107 | * As above but for setting multiple values
108 | * @param {Object} values - Object to set default values of.
109 | * For example, using
110 | * AutoTools.setDefault("title","My Title");
111 | * AutoTools.setDefault("text","my text");
112 | * Is the same as using
113 | * AutoTools.setDefaultValues({
114 | "title": "My Title",
115 | "text":"my text"
116 | });
117 | */
118 | AutoTools.setDefaultValues = (values) => {
119 | for(var varName in values){
120 | var value = values[varName];
121 | AutoTools.setDefault(varName, value);
122 | }
123 | };
124 |
125 | /**
126 | * Will convert a list of comma separated Web Screen variables into a nice JSON object.
127 | * @param {...string} fields - Names of the Web Screen Variables to convert
128 | * For example if have
129 | * - variable "title" with value = "Title1,Title2,Title3"
130 | * - variable "text" with value = "text1,text2,text3"
131 | * And use
132 | * AutoTools.fieldsToObject("title","text");
133 | * It'll return an array of objects like this:
134 | [
135 | {
136 | "title": "Title1",
137 | "text": "Text1"
138 | },
139 | {
140 | "title": "Title2",
141 | "text": "text2"
142 | },
143 | {
144 | "title": "Title3",
145 | "text": "text3"
146 | }
147 | ]
148 | * This is much easier to use in JavaScript :)
149 | */
150 | AutoTools.fieldsToObject = (...fields) => {
151 | var first = fields[0];
152 | var result = [];
153 | /*if(!AutoTools.isSet(first)){
154 | return result;
155 | }*/
156 | var length = null;
157 | var separator = ",";
158 | if(AutoTools.isSet("itemSeparator")){
159 | separator = itemSeparator;
160 | }
161 | for(var field of fields){
162 | if(!AutoTools.isSet(field)){
163 | continue;
164 | }
165 | var value = window[field];
166 | var split = value.split(separator);
167 | if(length == null){
168 | length = split.length;
169 | }
170 | for (var i = 0; i < length; i++) {
171 | if(result.length<=i){
172 | result.push({});
173 | }
174 | var current = result[i];
175 | current[field] = split[i];
176 | }
177 | }
178 | return result;
179 | };
180 |
181 | /**
182 | * Will hide an element on the page
183 | * @param {HTMLElement} element - The element you want to hide
184 | */
185 | AutoTools.hide = element => element.classList.add("hidden");
186 |
187 | /**
188 | * Will show an element on the page
189 | * @param {HTMLElement} element - The element you want to show
190 | */
191 | AutoTools.show = element => element.classList.remove("hidden");
192 |
193 | /**
194 | * Will convert an array object into HTML elements on the page. It will map each property in the object with elements with the same class name. Check this page for a concrete example: https://www.dropbox.com/s/ia2m4quij24h13q/functiondemo.html?dl=1
195 | * @param {string} rootElementsId - The ID of the HTML element where you want to insert the HTML elements
196 | * @param {string} rootElementClass - The class of the HTML element that you want to clone for each item in the input array
197 | * @param {Object[]} input - The array that contains properties that will be mapped to each replicated HTML element
198 | * @param {Function} [itemTransformer] - Optional transformer that will be called for each element on the page
199 | */
200 | AutoTools.objectToElements = function(rootElementsId, rootElementClass, input, itemTransformer){
201 | var setByClass = (root,className,value,prop) => {
202 | var element = root.querySelector(`.${className}`);
203 | if(!element){
204 | return;
205 | }
206 | if(!value){
207 | AutoTools.hide(element);
208 | return element;
209 | }
210 | AutoTools.show(element);
211 | if(!prop){
212 | var tagName = element.tagName;
213 | if(tagName == "IMG"){
214 | prop = "src";
215 | }else if(tagName == "A"){
216 | prop = "href";
217 | }else if(tagName == "INPUT"){
218 | if(element.type == "checkbox"){
219 | prop = "checked";
220 | value = value == "false" ? false : true;
221 | }
222 | }else{
223 | prop = "innerHTML";
224 | }
225 | }
226 | element[prop] = value;
227 | return element;
228 | };
229 | var listRoot = document.querySelector("#"+rootElementsId);
230 | var elementToClone = document.querySelector("."+rootElementClass);
231 | AutoTools.hide(elementToClone);
232 | var rootElement = elementToClone.cloneNode(true);
233 | AutoTools.show(rootElement);
234 | listRoot.innerHTML = "";
235 | if(itemTransformer && itemTransformer.onclick){
236 | var styleNoPointerEvents = document.createElement("style");
237 | styleNoPointerEvents.innerHTML = `
238 | .${rootElementClass}{
239 | cursor: pointer;
240 | }
241 | .${rootElementClass} *{
242 | pointer-events: none;
243 | }`;
244 | document.querySelector("head").appendChild(styleNoPointerEvents);
245 | }
246 | for(var item of input){
247 |
248 | var resultElement = rootElement.cloneNode(true);
249 | resultElement.item = item;
250 | var itemObject = {"parent":resultElement};
251 | for(var prop in item){
252 | var value = item[prop];
253 | var setElement = setByClass(resultElement,prop,value);
254 | itemObject[prop] = {"value":value,"element":setElement};
255 | }
256 | if(itemTransformer){
257 | if(itemTransformer.item){
258 | itemTransformer.item(itemObject);
259 | }
260 | if(itemTransformer.onclick){
261 | resultElement.onclick = e => itemTransformer.onclick(e.target.item);
262 | }
263 | if(itemTransformer.events){
264 | for(var event of itemTransformer.events){
265 | var eventName = event.name;
266 | if(!eventName){
267 | continue;
268 | }
269 | var handler = event.handler;
270 | if(!handler){
271 | continue;
272 | }
273 | var cssQuery = event.query;
274 | var elementForEvent = resultElement;
275 | if(cssQuery){
276 | elementForEvent = resultElement.querySelector(cssQuery);
277 | if(!elementForEvent){
278 | continue;
279 | }
280 | elementForEvent.style["pointer-events"] = "auto";
281 | }
282 | elementForEvent.addEventListener(eventName,e => handler(e.target));
283 | }
284 | }
285 | }
286 | if(itemObject.elementToAdd){
287 | resultElement = itemObject.elementToAdd;
288 | }
289 | if(itemObject.elementRoot){
290 | listRoot = itemObject.elementRoot;
291 | }
292 | listRoot.appendChild(resultElement);
293 | }
294 | }
295 | /**
296 | * Will convert Web Screen variables into HTML elements on the page. It will map each variable with elements with the same class name. Check this page for a concrete example: https://www.dropbox.com/s/ia2m4quij24h13q/functiondemo.html?dl=1
297 | * @param {string[]} webscreenVariables - Array of variable names that you want to map to the HTML element
298 | * @param {string} rootElementsId - The ID of the HTML element where you want to insert the HTML elements
299 | * @param {string} rootElementClass - The class of the HTML element that you want to clone for each item in the input array
300 | * @param {Function} [itemTransformer] - Optional transformer that will be called for each element on the page
301 | */
302 | AutoTools.variablesToElements = function(webscreenVariables, rootElementsId, rootElementClass, itemTransformer){
303 | var input = AutoTools.fieldsToObject(...webscreenVariables);
304 | AutoTools.objectToElements(rootElementsId,rootElementClass, input, itemTransformer);
305 | }
306 | /**
307 | * Will say some text out loud on your Android device
308 | * @param {string} text - Text you want to say
309 | * @param {string} [language] - Optional language. Will default to your device's language
310 | */
311 | AutoTools.say = (text,language) => AutoToolsAndroid.say(text,language);
312 | /**
313 | * Will return info about the user that's logged in to AutoTools (usually you). Try it here with the "userId" set to "me" to see what kind of output you get: https://developers.google.com/+/web/api/rest/latest/people/get
314 | */
315 | AutoTools.getUserInfo = () => JSON.parse(AutoToolsAndroid.getUserInfo());
316 | /**
317 | * Will make your phone vibrate with the given vibration pattern.
318 | * @param {string} vibration - Vibration Pattern. Same as Tasker's vibrate pattern
319 | */
320 | AutoTools.vibrate = (vibration) => AutoToolsAndroid.vibrate(vibration);
321 | /**
322 | * Will make your phone vibrate shortly
323 | */
324 | AutoTools.hapticFeedback = () => AutoToolsAndroid.hapticFeedback();
325 | /**
326 | * Will change the width of the Web Screen if it's an overlay or a dialog
327 | * @param {string} width - in dp or "fill" to fill the entire width of the screen
328 | */
329 | AutoTools.setWidth = (width) => AutoToolsAndroid.setWidth(width);
330 | /**
331 | * Will change the height of the Web Screen if it's an overlay or a dialog
332 | * @param {string} height - in dp or "fill" to fill the entire height of the screen
333 | */
334 | AutoTools.setHeight = (width) => AutoToolsAndroid.setHeight(width);
335 | /**
336 | * Will change the size of the Web Screen if it's an overlay or a dialog
337 | * @param {string} width - in dp or "fill" to fill the entire width of the screen
338 | * @param {string} height - in dp or "fill" to fill the entire height of the screen
339 | */
340 | AutoTools.setSize = (width,height) => AutoToolsAndroid.setSize(width,height);
341 |
342 | AutoTools.GRAVITY_BOTTOM = 80;
343 | AutoTools.GRAVITY_CENTER = 17;
344 | AutoTools.GRAVITY_TOP = 48;
345 | AutoTools.GRAVITY_RIGHT = 5;
346 | AutoTools.GRAVITY_LEFT = 3;
347 |
348 | /**
349 | * Will change the size of the Web Screen if it's an overlay or a dialog
350 | * @param {string} width - in dp or "fill" to fill the entire width of the screen
351 | * @param {string} height - in dp or "fill" to fill the entire height of the screen
352 | * @param {string} x - offset in dp
353 | * @param {string} y - offset in dp
354 | * @param {int} gravity - flag for gravity: combination of any of the GRAVITY flags above
355 | */
356 | AutoTools.setLayout = (width, height, x, y, gravity) => AutoToolsAndroid.setLayout(width, height, x, y, gravity);
357 |
358 | AutoTools.FLAG_NOT_FOCUSABLE = 8;
359 | AutoTools.FLAG_LAYOUT_NO_LIMITS = 512;
360 | AutoTools.FLAG_TURN_SCREEN_ON = 2097152;
361 | AutoTools.FLAG_ALT_FOCUSABLE_IM = 131072;
362 | AutoTools.FLAG_NOT_TOUCH_MODAL = 32;
363 |
364 | /**
365 | * Will set overlay flags manually. Can be used to adjust if web screen requires input at runtime
366 | * @param {int} flags - flags to set. Check here: https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html
367 | */
368 | AutoTools.setWindowFlags = (flags) => AutoToolsAndroid.setWindowFlags(flags);
369 |
370 | /**
371 | * Will show a toast with the given text
372 | * @param {string} text - text to show in the toast
373 | */
374 | AutoTools.showToast = (text) => AutoToolsAndroid.showToast(text);
375 |
376 | /**
377 | * Will get the Tasker input that was used to show the screen
378 | */
379 | AutoTools.getInput = () => JSON.parse(AutoToolsAndroid.getInput());
380 |
381 | /**
382 | * Will get the Tasker input that was used to show the screen
383 | */
384 | AutoTools.getTextInput = (title,message,initialText) => AutoToolsAndroid.getTextInput(title,message,initialText);
385 |
386 | /**
387 | * Will open the URL on your Android device in an external app
388 | */
389 | AutoTools.browseUrl = url => AutoToolsAndroid.browseUrl(url);
390 |
391 | /**
392 | * Will get the location of the overlay (as an object with two properties: x and y. Like {x:100,y:200}) f the screen is shown in overlay mode. If not, will return null.
393 | */
394 | AutoTools.getOverlayPosition = () => {
395 | var point = AutoToolsAndroid.getOverlayPosition();
396 | if(!point){
397 | return point;
398 | }
399 | return JSON.parse(point);
400 | }
401 |
402 | /**
403 | * Will create a new style element in the header of the page with the contents passed in as parameter
404 | * @param {string} css - css text to add in a style element
405 | */
406 | AutoTools.addStyle = (css) => {
407 | var sheet = document.createElement('style')
408 | sheet.innerHTML = css;
409 | document.head.appendChild(sheet);
410 | }
411 |
412 | /**
413 | * Will return the input with the suffix 'px' if it's a number, otherwise will return the input
414 | * @param {string} dimension - either a number or any other type of dimension
415 | */
416 | AutoTools.getPixelsOrDimension = (dimension) => {
417 | if(!isNaN(new Number(dimension))){
418 | return dimension+"px";
419 | }
420 | return dimension;
421 | }
422 |
423 | /**
424 | * Check if a certain flag is set
425 | * @param {int} flags - flags to check
426 | * @param {int} flagToCheck - flag to check
427 | */
428 | AutoTools.checkFlag = (flags, flagToCheck) => {
429 | if ((flags & flagToCheck) == flagToCheck){
430 | return true;
431 | }
432 | return false;
433 | }
434 |
435 |
436 | AutoTools.DRAG_LOCK_ALL = "0";
437 | AutoTools.DRAG_LOCK_HORIZONTAL = "1";
438 | AutoTools.DRAG_LOCK_VERTICAL = "2";
439 | AutoTools.DRAG_LOCK_NONE = "3";
440 |
441 | /**
442 | * Enable or disable vertical dragging in overlays
443 | * @param {boolean} enable - select if you want to enable or disable it
444 | */
445 | AutoTools.setDragInY = enable => AutoToolsAndroid.setDragInY(enable);
446 |
447 | /**
448 | * Enable or disable horizontal dragging in overlays
449 | * @param {boolean} enable - select if you want to enable or disable it
450 | */
451 | AutoTools.setDragInX = enable => AutoToolsAndroid.setDragInX(enable);
452 |
453 | AutoTools.FLING_TO_DISMISS_NONE = "0";
454 | AutoTools.FLING_TO_DISMISS_ALL = "1";
455 | AutoTools.FLING_TO_DISMISS_UP = "2";
456 | AutoTools.FLING_TO_DISMISS_RIGHT = "3";
457 | AutoTools.FLING_TO_DISMISS_DOWN = "4";
458 | AutoTools.FLING_TO_DISMISS_LEFT = "5";
459 | AutoTools.FLING_TO_DISMISS_UP_AND_DOWN = "6";
460 | AutoTools.FLING_TO_DISMISS_LEFT_AND_RIGHT = "7";
461 | /**
462 | * Enable or disable fling to dismiss on negative X
463 | * @param {boolean} enable - select if you want to enable or disable it
464 | */
465 | AutoTools.setflingOnNegativeX = enable => AutoToolsAndroid.setflingOnNegativeX(enable);
466 |
467 | /**
468 | * Enable or disable fling to dismiss on positive X
469 | * @param {boolean} enable - select if you want to enable or disable it
470 | */
471 | AutoTools.setflingOnPositiveX = enable => AutoToolsAndroid.setflingOnPositiveX(enable);
472 |
473 | /**
474 | * Enable or disable fling to dismiss on negative Y
475 | * @param {boolean} enable - select if you want to enable or disable it
476 | */
477 | AutoTools.setflingOnNegativeY = enable => AutoToolsAndroid.setflingOnNegativeY(enable);
478 |
479 | /**
480 | * Enable or disable fling to dismiss on positive Y
481 | * @param {boolean} enable - select if you want to enable or disable it
482 | */
483 | AutoTools.setflingOnPositiveY = enable => AutoToolsAndroid.setflingOnPositiveY(enable);
484 |
485 | /**
486 | * Check if fling to dismiss is enabled for left
487 | * @param {string} fling - current fling to dismiss value
488 | */
489 | AutoTools.checkFlingLeft = fling => fling == AutoTools.FLING_TO_DISMISS_LEFT || fling == AutoTools.FLING_TO_DISMISS_LEFT_AND_RIGHT || fling == AutoTools.FLING_TO_DISMISS_ALL;
490 | /**
491 | * Check if fling to dismiss is enabled for right
492 | * @param {string} fling - current fling to dismiss value
493 | */
494 | AutoTools.checkFlingRight = fling => fling == AutoTools.FLING_TO_DISMISS_RIGHT || fling == AutoTools.FLING_TO_DISMISS_LEFT_AND_RIGHT || fling == AutoTools.FLING_TO_DISMISS_ALL;
495 | /**
496 | * Check if fling to dismiss is enabled for up
497 | * @param {string} fling - current fling to dismiss value
498 | */
499 | AutoTools.checkFlingUp = fling => fling == AutoTools.FLING_TO_DISMISS_UP || fling == AutoTools.FLING_TO_DISMISS_UP_AND_DOWN || fling == AutoTools.FLING_TO_DISMISS_ALL;
500 | /**
501 | * Check if fling to dismiss is enabled for down
502 | * @param {string} fling - current fling to dismiss value
503 | */
504 | AutoTools.checkFlingDown = fling => fling == AutoTools.FLING_TO_DISMISS_DOWN || fling == AutoTools.FLING_TO_DISMISS_UP_AND_DOWN || fling == AutoTools.FLING_TO_DISMISS_ALL;
505 |
506 | /**
507 | * Sleep for some time. Should be called with the await keyword
508 | * @param {int} time - ms to wait
509 | */
510 | AutoTools.sleep = async time => new Promise(resolve=>setTimeout(resolve,time));
511 |
512 | /**
513 | * Add a click and long click listener to a DOM element
514 | * @param {HTMLElement} element - DOM element to attach listeners to
515 | * @param {Function} callbackClick - optional function to run when element is clicked
516 | * @param {Function} callbackLongClick - optional function to run when element is long clicked
517 | * @param {int} longClickTime - time to wait until a long click is acknowledged
518 | */
519 | AutoTools.onclickandlongclick = function(element, callbackClick, callbackLongClick,longClickTime){
520 | var longpress = false;
521 | var presstimer = null;
522 | var longtarget = null;
523 | if(!longClickTime)longClickTime=500;
524 |
525 | var cancel = function(e) {
526 | if (presstimer !== null) {
527 | clearTimeout(presstimer);
528 | presstimer = null;
529 | }
530 |
531 | this.classList.remove("longpress");
532 | };
533 |
534 | var click = function(e) {
535 | if (presstimer !== null) {
536 | clearTimeout(presstimer);
537 | presstimer = null;
538 | }
539 |
540 | this.classList.remove("longpress");
541 |
542 | if (longpress) {
543 | return false;
544 | }
545 | if(callbackClick)callbackClick(e);
546 | };
547 |
548 | var start = function(e) {
549 |
550 | if (e.type === "click" && e.button !== 0) {
551 | return;
552 | }
553 |
554 | longpress = false;
555 |
556 | this.classList.add("longpress");
557 |
558 | presstimer = setTimeout(function() {
559 | if(callbackLongClick)callbackLongClick(e);
560 | longpress = true;
561 | }, longClickTime);
562 |
563 | return false;
564 | };
565 |
566 | element.addEventListener("mousedown", start);
567 | element.addEventListener("touchstart", start);
568 | element.addEventListener("click", click);
569 | element.addEventListener("mouseout", cancel);
570 | element.addEventListener("touchend", cancel);
571 | element.addEventListener("touchleave", cancel);
572 | element.addEventListener("touchcancel", cancel);
573 | }
574 |
575 |
--------------------------------------------------------------------------------
/autotoolsfunctions.js.bak:
--------------------------------------------------------------------------------
1 | /**
2 | * These functions will automatically be injected into every page that is loaded with the AutoTools Web Screen action in Tasker.
3 | * You can use them freely in your own web screens! :)
4 | * If you want you can copy these to your web screen for easy testing on your PC.
5 | * Only the functions that call AutoToolsAndroid functions will not work on your PC, like the AutoTools.say function for example.
6 | */
7 |
8 | /**
9 | * Create base AutoTools object that will contain everything else
10 | */
11 | var AutoTools = {};
12 |
13 | /**
14 | * Send an AutoApps command from JavaScript.
15 | * @param {string} command - The command you want to send
16 | * @param {string} [prefix] - An optional prefix that will be prepended to the command. If it exists command will have the prefix=:=command format
17 | * @param {boolean} [hapticFeedback] - If true, will perform a short vibration with the command
18 | */
19 | AutoTools.sendCommand = function(command, prefix, hapticFeedback){
20 | if(!command){
21 | return;
22 | }
23 | if(!prefix){
24 | prefix = null;
25 | }
26 | console.log("Sending command: " + command+";"+prefix);
27 | AutoToolsAndroid.sendCommand(command, prefix, hapticFeedback);
28 | }
29 |
30 | /**
31 | * Easily assign a command to an HTML element
32 | * @param {string} selector - The CSS selector for the element. For example, to specify an element with the id "link", you should pass in "#link"
33 | * @param {string} command - The command you want to send
34 | * @param {string} [prefix] - An optional prefix that will be prepended to the command. If it exists command will have the prefix=:=command format
35 | */
36 | AutoTools.commandOnClick = function(selector, command, prefix){
37 | document.querySelector(selector).onclick = e => AutoTools.sendCommand(command, prefix);
38 | }
39 | /**
40 | * Change a color dynamically. Got it from here: https://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color-or-rgb-and-blend-colors
41 | * Example use: Have color #ff0000 (red) and want a 30% darker shade of red, would call AutoTools.shadeBlendConvert(-0.3, "#ff0000");
42 | */
43 | AutoTools.shadeBlendConvert = function(p, from, to) {
44 | if(typeof(p)!="number"||p<-1||p>1||typeof(from)!="string"||(from[0]!='r'&&from[0]!='#')||(typeof(to)!="string"&&typeof(to)!="undefined"))return null;
45 | var sbcRip=function(d){
46 | var l=d.length,RGB=new Object();
47 | if(l>9){
48 | d=d.split(",");
49 | if(d.length<3||d.length>4)return null;
50 | RGB[0]=i(d[0].slice(4)),RGB[1]=i(d[1]),RGB[2]=i(d[2]),RGB[3]=d[3]?parseFloat(d[3]):-1;
51 | }else{
52 | if(l==8||l==6||l<4)return null;
53 | if(l<6)d="#"+d[1]+d[1]+d[2]+d[2]+d[3]+d[3]+(l>4?d[4]+""+d[4]:"");
54 | d=i(d.slice(1),16),RGB[0]=d>>16&255,RGB[1]=d>>8&255,RGB[2]=d&255,RGB[3]=l==9||l==5?r(((d>>24&255)/255)*10000)/10000:-1;
55 | }
56 | return RGB;}
57 | var i=parseInt,r=Math.round,h=from.length>9,h=typeof(to)=="string"?to.length>9?true:to=="c"?!h:false:h,b=p<0,p=b?p*-1:p,to=to&&to!="c"?to:b?"#000000":"#FFFFFF",f=sbcRip(from),t=sbcRip(to);
58 | if(!f||!t)return null;
59 | if(h)return "rgb("+r((t[0]-f[0])*p+f[0])+","+r((t[1]-f[1])*p+f[1])+","+r((t[2]-f[2])*p+f[2])+(f[3]<0&&t[3]<0?")":","+(f[3]>-1&&t[3]>-1?r(((t[3]-f[3])*p+f[3])*10000)/10000:t[3]<0?f[3]:t[3])+")");
60 | else return "#"+(0x100000000+(f[3]>-1&&t[3]>-1?r(((t[3]-f[3])*p+f[3])*255):t[3]>-1?r(t[3]*255):f[3]>-1?r(f[3]*255):255)*0x1000000+r((t[0]-f[0])*p+f[0])*0x10000+r((t[1]-f[1])*p+f[1])*0x100+r((t[2]-f[2])*p+f[2])).toString(16).slice(f[3]>-1||t[3]>-1?1:3);
61 | };
62 |
63 | /**
64 | * Brighten the color of a property in a CSS rule
65 | * @param {Object} rule - The cssRule object you want to change
66 | * @param {string} propertyName - The property you want to change ("background-color" for example)
67 | * @param {string} percent - Value from 0 to 100 you want to change
68 | * @param {boolean} darken - If true will darken the color instead of brightening it
69 | */
70 | AutoTools.increaseBrightnessRule = function(rule, propertyName, percent, darken){
71 | var originalColor = rule.style.getPropertyValue(propertyName);
72 | if(!originalColor){
73 | return;
74 | }
75 | originalColor = originalColor.trim();
76 | var newColor = AutoTools.shadeBlendConvert(percent/100,originalColor);
77 | rule.style.setProperty(propertyName, newColor);
78 | return newColor;
79 | };
80 |
81 | /**
82 | * Check if the value of a Web Screen Variable was set from Tasker
83 | * @param {string} value - Name of the variable you want to check
84 | */
85 | AutoTools.isSet = value => {
86 | value = window[value];
87 | if(value === undefined || value === null){
88 | return false;
89 | }
90 | var toClass = {}.toString.call(value);
91 | if(toClass == "[object Boolean]"){
92 | return true;
93 | }
94 | return toClass == "[object String]";
95 | };
96 | /**
97 | * Set the value of a Web Screen variable if it hasn't been set already from Tasker
98 | * @param {string} variable - The name of the variable you want to set
99 | * @param {string} value - The value you want to set if it hasn't been set from Tasker
100 | */
101 | AutoTools.setDefault = (variable, value) => {
102 | if(!AutoTools.isSet(variable)){
103 | window[variable] = value;
104 | }
105 | };
106 | /**
107 | * As above but for setting multiple values
108 | * @param {Object} values - Object to set default values of.
109 | * For example, using
110 | * AutoTools.setDefault("title","My Title");
111 | * AutoTools.setDefault("text","my text");
112 | * Is the same as using
113 | * AutoTools.setDefaultValues({
114 | "title": "My Title",
115 | "text":"my text"
116 | });
117 | */
118 | AutoTools.setDefaultValues = (values) => {
119 | for(var varName in values){
120 | var value = values[varName];
121 | AutoTools.setDefault(varName, value);
122 | }
123 | };
124 |
125 | /**
126 | * Will convert a list of comma separated Web Screen variables into a nice JSON object.
127 | * @param {...string} fields - Names of the Web Screen Variables to convert
128 | * For example if have
129 | * - variable "title" with value = "Title1,Title2,Title3"
130 | * - variable "text" with value = "text1,text2,text3"
131 | * And use
132 | * AutoTools.fieldsToObject("title","text");
133 | * It'll return an array of objects like this:
134 | [
135 | {
136 | "title": "Title1",
137 | "text": "Text1"
138 | },
139 | {
140 | "title": "Title2",
141 | "text": "text2"
142 | },
143 | {
144 | "title": "Title3",
145 | "text": "text3"
146 | }
147 | ]
148 | * This is much easier to use in JavaScript :)
149 | */
150 | AutoTools.fieldsToObject = (...fields) => {
151 | var first = fields[0];
152 | var result = [];
153 | /*if(!AutoTools.isSet(first)){
154 | return result;
155 | }*/
156 | var length = null;
157 | var separator = ",";
158 | if(AutoTools.isSet("itemSeparator")){
159 | separator = itemSeparator;
160 | }
161 | for(var field of fields){
162 | if(!AutoTools.isSet(field)){
163 | continue;
164 | }
165 | var value = window[field];
166 | var split = value.split(separator);
167 | if(length == null){
168 | length = split.length;
169 | }
170 | for (var i = 0; i < length; i++) {
171 | if(result.length<=i){
172 | result.push({});
173 | }
174 | var current = result[i];
175 | current[field] = split[i];
176 | }
177 | }
178 | return result;
179 | };
180 |
181 | /**
182 | * Will hide an element on the page
183 | * @param {HTMLElement} element - The element you want to hide
184 | */
185 | AutoTools.hide = element => element.classList.add("hidden");
186 |
187 | /**
188 | * Will show an element on the page
189 | * @param {HTMLElement} element - The element you want to show
190 | */
191 | AutoTools.show = element => element.classList.remove("hidden");
192 |
193 | /**
194 | * Will convert an array object into HTML elements on the page. It will map each property in the object with elements with the same class name. Check this page for a concrete example: https://www.dropbox.com/s/ia2m4quij24h13q/functiondemo.html?dl=1
195 | * @param {string} rootElementsId - The ID of the HTML element where you want to insert the HTML elements
196 | * @param {string} rootElementClass - The class of the HTML element that you want to clone for each item in the input array
197 | * @param {Object[]} input - The array that contains properties that will be mapped to each replicated HTML element
198 | * @param {Function} [itemTransformer] - Optional transformer that will be called for each element on the page
199 | */
200 | AutoTools.objectToElements = function(rootElementsId, rootElementClass, input, itemTransformer){
201 | var setByClass = (root,className,value,prop) => {
202 | var element = root.querySelector(`.${className}`);
203 | if(!element){
204 | return;
205 | }
206 | if(!value){
207 | AutoTools.hide(element);
208 | return element;
209 | }
210 | AutoTools.show(element);
211 | if(!prop){
212 | var tagName = element.tagName;
213 | if(tagName == "IMG"){
214 | prop = "src";
215 | }else if(tagName == "A"){
216 | prop = "href";
217 | }else if(tagName == "INPUT"){
218 | if(element.type == "checkbox"){
219 | prop = "checked";
220 | value = value == "false" ? false : true;
221 | }
222 | }else{
223 | prop = "innerHTML";
224 | }
225 | }
226 | element[prop] = value;
227 | return element;
228 | };
229 | var listRoot = document.querySelector("#"+rootElementsId);
230 | var elementToClone = document.querySelector("."+rootElementClass);
231 | AutoTools.hide(elementToClone);
232 | var rootElement = elementToClone.cloneNode(true);
233 | AutoTools.show(rootElement);
234 | listRoot.innerHTML = "";
235 | if(itemTransformer && itemTransformer.onclick){
236 | var styleNoPointerEvents = document.createElement("style");
237 | styleNoPointerEvents.innerHTML = `
238 | .${rootElementClass}{
239 | cursor: pointer;
240 | }
241 | .${rootElementClass} *{
242 | pointer-events: none;
243 | }`;
244 | document.querySelector("head").appendChild(styleNoPointerEvents);
245 | }
246 | for(var item of input){
247 |
248 | var resultElement = rootElement.cloneNode(true);
249 | resultElement.item = item;
250 | var itemObject = {"parent":resultElement};
251 | for(var prop in item){
252 | var value = item[prop];
253 | var setElement = setByClass(resultElement,prop,value);
254 | itemObject[prop] = {"value":value,"element":setElement};
255 | }
256 | if(itemTransformer){
257 | if(itemTransformer.item){
258 | itemTransformer.item(itemObject);
259 | }
260 | if(itemTransformer.onclick){
261 | resultElement.onclick = e => itemTransformer.onclick(e.target.item);
262 | }
263 | if(itemTransformer.events){
264 | for(var event of itemTransformer.events){
265 | var eventName = event.name;
266 | if(!eventName){
267 | continue;
268 | }
269 | var handler = event.handler;
270 | if(!handler){
271 | continue;
272 | }
273 | var cssQuery = event.query;
274 | var elementForEvent = resultElement;
275 | if(cssQuery){
276 | elementForEvent = resultElement.querySelector(cssQuery);
277 | if(!elementForEvent){
278 | continue;
279 | }
280 | elementForEvent.style["pointer-events"] = "auto";
281 | }
282 | elementForEvent.addEventListener(eventName,e => handler(e.target));
283 | }
284 | }
285 | }
286 | if(itemObject.elementToAdd){
287 | resultElement = itemObject.elementToAdd;
288 | }
289 | if(itemObject.elementRoot){
290 | listRoot = itemObject.elementRoot;
291 | }
292 | listRoot.appendChild(resultElement);
293 | }
294 | }
295 | /**
296 | * Will convert Web Screen variables into HTML elements on the page. It will map each variable with elements with the same class name. Check this page for a concrete example: https://www.dropbox.com/s/ia2m4quij24h13q/functiondemo.html?dl=1
297 | * @param {string[]} webscreenVariables - Array of variable names that you want to map to the HTML element
298 | * @param {string} rootElementsId - The ID of the HTML element where you want to insert the HTML elements
299 | * @param {string} rootElementClass - The class of the HTML element that you want to clone for each item in the input array
300 | * @param {Function} [itemTransformer] - Optional transformer that will be called for each element on the page
301 | */
302 | AutoTools.variablesToElements = function(webscreenVariables, rootElementsId, rootElementClass, itemTransformer){
303 | var input = AutoTools.fieldsToObject(...webscreenVariables);
304 | AutoTools.objectToElements(rootElementsId,rootElementClass, input, itemTransformer);
305 | }
306 | /**
307 | * Will say some text out loud on your Android device
308 | * @param {string} text - Text you want to say
309 | * @param {string} [language] - Optional language. Will default to your device's language
310 | */
311 | AutoTools.say = (text,language) => AutoToolsAndroid.say(text,language);
312 | /**
313 | * Will return info about the user that's logged in to AutoTools (usually you). Try it here with the "userId" set to "me" to see what kind of output you get: https://developers.google.com/+/web/api/rest/latest/people/get
314 | */
315 | AutoTools.getUserInfo = () => JSON.parse(AutoToolsAndroid.getUserInfo());
316 | /**
317 | * Will make your phone vibrate with the given vibration pattern.
318 | * @param {string} vibration - Vibration Pattern. Same as Tasker's vibrate pattern
319 | */
320 | AutoTools.vibrate = (vibration) => AutoToolsAndroid.vibrate(vibration);
321 | /**
322 | * Will make your phone vibrate shortly
323 | */
324 | AutoTools.hapticFeedback = () => AutoToolsAndroid.hapticFeedback();
325 | /**
326 | * Will change the width of the Web Screen if it's an overlay or a dialog
327 | * @param {string} width - in dp or "fill" to fill the entire width of the screen
328 | */
329 | AutoTools.setWidth = (width) => AutoToolsAndroid.setWidth(width);
330 | /**
331 | * Will change the height of the Web Screen if it's an overlay or a dialog
332 | * @param {string} height - in dp or "fill" to fill the entire height of the screen
333 | */
334 | AutoTools.setHeight = (width) => AutoToolsAndroid.setHeight(width);
335 | /**
336 | * Will change the size of the Web Screen if it's an overlay or a dialog
337 | * @param {string} width - in dp or "fill" to fill the entire width of the screen
338 | * @param {string} height - in dp or "fill" to fill the entire height of the screen
339 | */
340 | AutoTools.setSize = (width,height) => AutoToolsAndroid.setSize(width,height);
341 |
342 | AutoTools.GRAVITY_BOTTOM = 80;
343 | AutoTools.GRAVITY_CENTER = 17;
344 | AutoTools.GRAVITY_TOP = 48;
345 | AutoTools.GRAVITY_RIGHT = 5;
346 | AutoTools.GRAVITY_LEFT = 3;
347 |
348 | /**
349 | * Will change the size of the Web Screen if it's an overlay or a dialog
350 | * @param {string} width - in dp or "fill" to fill the entire width of the screen
351 | * @param {string} height - in dp or "fill" to fill the entire height of the screen
352 | * @param {string} x - offset in dp
353 | * @param {string} y - offset in dp
354 | * @param {int} gravity - flag for gravity: combination of any of the GRAVITY flags above
355 | */
356 | AutoTools.setLayout = (width, height, x, y, gravity) => AutoToolsAndroid.setLayout(width, height, x, y, gravity);
357 |
358 | AutoTools.FLAG_NOT_FOCUSABLE = 8;
359 | AutoTools.FLAG_LAYOUT_NO_LIMITS = 512;
360 | AutoTools.FLAG_TURN_SCREEN_ON = 2097152;
361 | AutoTools.FLAG_ALT_FOCUSABLE_IM = 131072;
362 | AutoTools.FLAG_NOT_TOUCH_MODAL = 32;
363 |
364 | /**
365 | * Will set overlay flags manually. Can be used to adjust if web screen requires input at runtime
366 | * @param {int} flags - flags to set. Check here: https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html
367 | */
368 | AutoTools.setWindowFlags = (flags) => AutoToolsAndroid.setWindowFlags(flags);
369 |
370 | /**
371 | * Will show a toast with the given text
372 | * @param {string} text - text to show in the toast
373 | */
374 | AutoTools.showToast = (text) => AutoToolsAndroid.showToast(text);
375 |
376 | /**
377 | * Will get the Tasker input that was used to show the screen
378 | */
379 | AutoTools.getInput = () => JSON.parse(AutoToolsAndroid.getInput());
380 |
381 | /**
382 | * Will get the Tasker input that was used to show the screen
383 | */
384 | AutoTools.getTextInput = (title,message,initialText) => AutoToolsAndroid.getTextInput(title,message,initialText);
385 |
386 | /**
387 | * Will open the URL on your Android device in an external app
388 | */
389 | AutoTools.browseUrl = url => AutoToolsAndroid.browseUrl(url);
390 |
391 | /**
392 | * Will get the location of the overlay (as an object with two properties: x and y. Like {x:100,y:200}) f the screen is shown in overlay mode. If not, will return null.
393 | */
394 | AutoTools.getOverlayPosition = () => {
395 | var point = AutoToolsAndroid.getOverlayPosition();
396 | if(!point){
397 | return point;
398 | }
399 | return JSON.parse(point);
400 | }
401 |
402 | /**
403 | * Will create a new style element in the header of the page with the contents passed in as parameter
404 | * @param {string} css - css text to add in a style element
405 | */
406 | AutoTools.addStyle = (css) => {
407 | var sheet = document.createElement('style')
408 | sheet.innerHTML = css;
409 | document.head.appendChild(sheet);
410 | }
411 |
412 | /**
413 | * Will return the input with the suffix 'px' if it's a number, otherwise will return the input
414 | * @param {string} dimension - either a number or any other type of dimension
415 | */
416 | AutoTools.getPixelsOrDimension = (dimension) => {
417 | if(!isNaN(new Number(dimension))){
418 | return dimension+"px";
419 | }
420 | return dimension;
421 | }
422 |
423 | /**
424 | * Check if a certain flag is set
425 | * @param {int} flags - flags to check
426 | * @param {int} flagToCheck - flag to check
427 | */
428 | AutoTools.checkFlag = (flags, flagToCheck) => {
429 | if ((flags & flagToCheck) == flagToCheck){
430 | return true;
431 | }
432 | return false;
433 | }
434 |
435 |
436 | AutoTools.DRAG_LOCK_ALL = "0";
437 | AutoTools.DRAG_LOCK_HORIZONTAL = "1";
438 | AutoTools.DRAG_LOCK_VERTICAL = "2";
439 | AutoTools.DRAG_LOCK_NONE = "3";
440 |
441 | /**
442 | * Enable or disable vertical dragging in overlays
443 | * @param {boolean} enable - select if you want to enable or disable it
444 | */
445 | AutoTools.setDragInY = enable => AutoToolsAndroid.setDragInY(enable);
446 |
447 | /**
448 | * Enable or disable horizontal dragging in overlays
449 | * @param {boolean} enable - select if you want to enable or disable it
450 | */
451 | AutoTools.setDragInX = enable => AutoToolsAndroid.setDragInX(enable);
452 |
453 | AutoTools.FLING_TO_DISMISS_NONE = "0";
454 | AutoTools.FLING_TO_DISMISS_ALL = "1";
455 | AutoTools.FLING_TO_DISMISS_UP = "2";
456 | AutoTools.FLING_TO_DISMISS_RIGHT = "3";
457 | AutoTools.FLING_TO_DISMISS_DOWN = "4";
458 | AutoTools.FLING_TO_DISMISS_LEFT = "5";
459 | AutoTools.FLING_TO_DISMISS_UP_AND_DOWN = "6";
460 | AutoTools.FLING_TO_DISMISS_LEFT_AND_RIGHT = "7";
461 | /**
462 | * Enable or disable fling to dismiss on negative X
463 | * @param {boolean} enable - select if you want to enable or disable it
464 | */
465 | AutoTools.setflingOnNegativeX = enable => AutoToolsAndroid.setflingOnNegativeX(enable);
466 |
467 | /**
468 | * Enable or disable fling to dismiss on positive X
469 | * @param {boolean} enable - select if you want to enable or disable it
470 | */
471 | AutoTools.setflingOnPositiveX = enable => AutoToolsAndroid.setflingOnPositiveX(enable);
472 |
473 | /**
474 | * Enable or disable fling to dismiss on negative Y
475 | * @param {boolean} enable - select if you want to enable or disable it
476 | */
477 | AutoTools.setflingOnNegativeY = enable => AutoToolsAndroid.setflingOnNegativeY(enable);
478 |
479 | /**
480 | * Enable or disable fling to dismiss on positive Y
481 | * @param {boolean} enable - select if you want to enable or disable it
482 | */
483 | AutoTools.setflingOnPositiveY = enable => AutoToolsAndroid.setflingOnPositiveY(enable);
484 |
485 | /**
486 | * Check if fling to dismiss is enabled for left
487 | * @param {string} fling - current fling to dismiss value
488 | */
489 | AutoTools.checkFlingLeft = fling => fling == AutoTools.FLING_TO_DISMISS_LEFT || fling == AutoTools.FLING_TO_DISMISS_LEFT_AND_RIGHT || fling == AutoTools.FLING_TO_DISMISS_ALL;
490 | /**
491 | * Check if fling to dismiss is enabled for right
492 | * @param {string} fling - current fling to dismiss value
493 | */
494 | AutoTools.checkFlingRight = fling => fling == AutoTools.FLING_TO_DISMISS_RIGHT || fling == AutoTools.FLING_TO_DISMISS_LEFT_AND_RIGHT || fling == AutoTools.FLING_TO_DISMISS_ALL;
495 | /**
496 | * Check if fling to dismiss is enabled for up
497 | * @param {string} fling - current fling to dismiss value
498 | */
499 | AutoTools.checkFlingUp = fling => fling == AutoTools.FLING_TO_DISMISS_UP || fling == AutoTools.FLING_TO_DISMISS_UP_AND_DOWN || fling == AutoTools.FLING_TO_DISMISS_ALL;
500 | /**
501 | * Check if fling to dismiss is enabled for down
502 | * @param {string} fling - current fling to dismiss value
503 | */
504 | AutoTools.checkFlingDown = fling => fling == AutoTools.FLING_TO_DISMISS_DOWN || fling == AutoTools.FLING_TO_DISMISS_UP_AND_DOWN || fling == AutoTools.FLING_TO_DISMISS_ALL;
505 |
506 | /**
507 | * Sleep for some time. Should be called with the await keyword
508 | * @param {int} time - ms to wait
509 | */
510 | AutoTools.sleep = async time => new Promise(resolve=>setTimeout(resolve,time));
511 |
512 | /**
513 | * Add a click and long click listener to a DOM element
514 | * @param {HTMLElement} element - DOM element to attach listeners to
515 | * @param {Function} callbackClick - optional function to run when element is clicked
516 | * @param {Function} callbackLongClick - optional function to run when element is long clicked
517 | * @param {int} longClickTime - time to wait until a long click is acknowledged
518 | */
519 | AutoTools.onclickandlongclick = function(element, callbackClick, callbackLongClick,longClickTime){
520 | var longpress = false;
521 | var presstimer = null;
522 | var longtarget = null;
523 | if(!longClickTime)longClickTime=500;
524 |
525 | var cancel = function(e) {
526 | if (presstimer !== null) {
527 | clearTimeout(presstimer);
528 | presstimer = null;
529 | }
530 |
531 | this.classList.remove("longpress");
532 | };
533 |
534 | var click = function(e) {
535 | if (presstimer !== null) {
536 | clearTimeout(presstimer);
537 | presstimer = null;
538 | }
539 |
540 | this.classList.remove("longpress");
541 |
542 | if (longpress) {
543 | return false;
544 | }
545 | if(callbackClick)callbackClick(e);
546 | };
547 |
548 | var start = function(e) {
549 | console.log(e);
550 |
551 | if (e.type === "click" && e.button !== 0) {
552 | return;
553 | }
554 |
555 | longpress = false;
556 |
557 | this.classList.add("longpress");
558 |
559 | presstimer = setTimeout(function() {
560 | if(callbackLongClick)callbackLongClick(e);
561 | longpress = true;
562 | }, longClickTime);
563 |
564 | return false;
565 | };
566 |
567 | element.addEventListener("mousedown", start);
568 | element.addEventListener("touchstart", start);
569 | element.addEventListener("click", click);
570 | element.addEventListener("mouseout", cancel);
571 | element.addEventListener("touchend", cancel);
572 | element.addEventListener("touchleave", cancel);
573 | element.addEventListener("touchcancel", cancel);
574 | }
575 |
576 |
--------------------------------------------------------------------------------
/autotoolsstyle.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Class used by the hide() and show() functions
3 | */
4 | .hidden{
5 | display: none !important;
6 | }
--------------------------------------------------------------------------------
/demos/bubble/instructions.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
Bubble
12 |
Show an interactive image/icon as a floating overlay
13 |
You can click on it to perform an AutoApps command
14 |
To change the size of the bubble change the Window Size in Window Settings->Width and Height
15 |
If you set the Overlay Settings->Drag Movements to Horizontal Only or Vertical Only you can then also set swipe commands
16 |
If you enable the Update option the bubble's position will be kept and only the image and other properties will be updated