now browsing by tag
Yesterday i upgraded nu oneplus 5 tot oxygenOS 5.0.1 (android 8.0.0) and met floating desktop doesn’t work anynore.
So I’m trying to make a launch animation with bindings, but something weird is happening.
I have this script on the tap event:
function setAndClearTimeout(func, timeout){
var id = setTimeout(function(){
clearTimeout(id);
func();
}, timeout);
}
getVariables().edit()
.setInteger(“itId”, getEvent().getItem().getId())
// .commit()
//getVariables().edit()
.setFloat(“launchScale”, 0.75)
.commit();
setAndClearTimeout(function(){
getVariables().edit()
.setInteger(“itId”, 0)
.setFloat(“launchScale”, 1)
.commit();
}, 1000);
With this binding on an item
$itId === item.getId() ? animate(“$launchScale”) : 1
What happens is: the item scale snaps to 0.75 en then back to 1 without animation. If I uncomment the lines
// .commit()
//getVariables().edit()
The downscaling is animated, but the upscaling is not (what i want on this case)
Does anybody know why the first method doesn’t work and the second does?
]]>I wrote a script to use as a launch animation that scales an item up and then down again (kinda like a bounce).
function fillOptions(options, defaults){
options = options || {};
for(var p in defaults){
if(typeof options[p] === “undefined”)
options[p] = defaults[p]
}
return options;
}
function setAndClearTimeout(func, timeout){
var id = setTimeout(function(){
clearTimeout(id);
func();
}, timeout);
}
function animScale(it, newScale, duration, options){
options = fillOptions(options, {animType: null, clearBindings: true});
var varName = “scaleAnim”;
var form = “animate(‘$”+varName+”‘, “+duration;
if(options.animType!==null)
form += ‘, “‘+options.animType+'”‘;
form += ‘)’;
var prop = it.getProperties();
var onGrid = prop.getBoolean(“i.onGrid”);
if(onGrid){
it.setBinding(“s.iconScale”, form, true)
}else{
it.setBinding(“t.sx”, form, true);
it.setBinding(“t.sy“, form, true)
}
LL.setVariableFloat(varName, newScale);
setAndClearTimeout(function after(){
if(options.preciseFinish){
if(onGrid){
prop.edit().setFloat(“s.iconScale”, newScale).commit()
}else{
it.setScale(newScale, newScale);
}
}
if(options.clearBindings){
if(onGrid){
it.unsetBinding(“s.iconScale”)
}else{
it.unsetBinding(“t.sx”);
it.unsetBinding(“t.sy“);
}
}
if(options.after){
options.after()
}
}, duration)
}
function bounce(it, duration, scaleIncrease, options){
options = fillOptions(options, {after: null});
var itProp = it.getProperties()
, itScale;
if(itProp.getBoolean(“i.onGrid”)){
itScale = itProp.getFloat(“s.iconScale”)
}else{
itScale = it.getScaleX()
}
animScale(it, itScale+scaleIncrease, duration/2, {animType:”de”, clearBindings:false, after: function(){
animScale(it, itScale, duration/2, {animType:”ac”, after: options.after, preciseFinish: true});
}});
}
var e = getEvent();
var it = e.getItem();
bounce(it, 100, 0.25, {after: function(){
setAndClearTimeout(function(){
if(it.getIntent().getAction() == “android.intent.action.MAIN”){
getActiveScreen().runAction(EventHandler.RUN_SCRIPT, it, getScriptByName(“Scaling Animation”).getId());
}else{
it.launch()
}
},0)
}});
]]>Is it just me or does saving/loading styles with a panel not work anymore? (App not responding)
I noticed LL using a quite a lot of battery recently and it has to do with scripts.
Quite some time ago, someone posted a script with which you can execute a root command.
The code also contains helpers for multithreading, which might deserve their own little spotlight as well.
Although i’ve learnt a lot about Javascript, I certainly don’t think i’m an expert yet, so if you have any suggestions for improvements or questions, please put them in the comments
Anyways here it is:
bindClass(‘java.lang.Runtime’);
bindClass(‘java.io.BufferedReader’);
bindClass(‘java.io.InputStreamReader’);
bindClass(‘java.io.DataOutputStream’);
bindClass(“java.lang.Thread”);
bindClass(“android.os.Handler”);
bindClass(“android.os.Looper”);
// initalize some global variables
var threads = []
, GUIHandler = new Handler();
/**
* This callback will be called when the executing of the command(s) is finished
*
* @callback finishedCallback
* @param {string[]} An array of the lines the command(s) returned
*/
/**
* This callback will be called when a command is executed.
*
* @callback executedCallback
*/
/**
* Runs a command in the terminal
* @param cmds {string|string[]} – The command or array of commmands to be executed.
* @param [asRoot=false] {boolean} – If the command(s) should be executed as root or not.
* @param [newThread=true] {boolean} – If the executing of commands should happen in a new thread or not. (useful for root commands)
* @param [callback] {finishedCallback} – The callback that handles the output.
* @param [onExecuted] {executedCallback} – A callback that will be called when a command is executed. useful for multiple commands that take some time)
* @returns {string[]||string[][]} – (only if asRoot == false && newThread == false) Returns an array of the lines written in the terminal or an array of arrays if multiple commands were executed.
*/
function runCmd(cmds, asRoot, newThread, callback, onExecuted){
var handler = getHandler()
, output, process, reader, writer;
// set optional arguments
if(asRoot == null)
asRoot = false;
if(newThread == null)
newThread = true;
/**
* Helper function for executing the command(s). Gets its parameters from the parent function.
* @returns {string[]||string[][]} – (only if asRoot == false && newThread == false) Returns an array of the lines written in the terminal or an array of arrays if multiple commands were executed.
*/
function execCmd(){
/**
* Checks if the command is a string and if not alerts the user.
* @param cmd {string}
* @returns {boolean}
*/
function checkCmd(cmd){
if(typeof(cmd) === “string”){
return true;
}else
handleGUIEdit(function(){
alert(cmd + ” is not a string!”);
});
return false;
}
/**
* Actually executes command.
* @param cmd {string}
* @param writer {DataOutputStream} – The writer to write the command to.
* @returns {boolean} If the command was actually written or not.
*/
function exec(cmd, writer){
if(checkCmd(cmd)){
writer.writeBytes(cmd + “\n”);
writer.flush();
return true;
}
return false;
}
/**
* Read the output from the reader.
* @param reader {BufferedReader}
* @returns {Array} An array of lines that were outputted by the
*/
function readOutput(reader){
var tmp, output = [];
while((tmp = reader.readLine()) != null)
output.push(tmp);
return output.length == 1 ? output[0] : output;
}
/**
* Executes the callback and if the callback is not a function alerts the user.
* @param callback
* @param output {Array} – The argument that is passed to the callback
*/
function handleCallback(callback, output){
if(typeof callback == “function”){
handler.post(function(){
callback(output);
});
}else if(callback){
handleGUIEdit(function(){
alert(callback + ” is not a function!”);
});
}
}
try{
if(asRoot){
process = Runtime.getRuntime().exec(“su”);
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
writer = new DataOutputStream(process.getOutputStream());
if(isArray(cmds)){
output = [];
cmds.forEach(function(cmd){
if(exec(cmd, writer)){
handleCallback(onExecuted);
}
});
exec(“exit”, writer);
writer.close();
output = readOutput(reader);
handleCallback(callback, output);
}else{
var succes = exec(cmds, writer);
exec(“exit”, writer);
writer.close();
if(succes){
output = readOutput(reader);
handleCallback(onExecuted);
handleCallback(callback, output);
}
}
reader.close();
process.waitFor();
}else{
if(isArray(cmds)){
var outputs = [];
cmds.forEach(function(cmd){
if(checkCmd(cmd)){
process = Runtime.getRuntime().exec(cmd);
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
output = readOutput(reader);
reader.close();
outputs.push(output);
handleCallback(onExecuted);
handleCallback(callback, output);
}
});
process.waitFor();
return outputs;
}else{
process = Runtime.getRuntime().exec(cmds);
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
output = readOutput(reader);
reader.close();
process.waitFor();
handleCallback(onExecuted);
handleCallback(callback, output);
return output;
}
}
}catch(err){
handleGUIEdit(function(){
alert(“At line ” + err.lineNumber + “: ” + err);
});
}
}
if(asRoot && isArray(callback))
throw new Error(“Multiple callbacks are not possible in su mode. Use onExecuteds instead.”);
if(newThread){
startNewBackgroundThread(function(){
execCmd();
});
}else{
return execCmd();
}
}
/**
* Checks if an object is an array.
* @param object
* @returns {boolean}
*/
function isArray(object){
return Object.prototype.toString.call(object) == ‘[object Array]’;
}
/**
* If this function is executed in a thread that is the main GUI thread, execute func, or else execute func in the main GUI thread. (Android doesn’t like it when you change the GUI outside of the main GUI thread)
* @param func {function}
*/
function handleGUIEdit(func){
if(Looper.getMainLooper().getThread() == Thread.currentThread()){
func();
}else{
GUIHandler.post(func);
}
}
/**
* Starts a new background thread with func.
* @param func {function} – The function the thread executes.
*/
function startNewBackgroundThread(func){
var thread = new Thread(function(){
func();
// if a looper was initialized in func, make sure the thread can die by stopping the thread when the Looper idles.
if(threads[Thread.currentThread().getId()].prepared == true){
Looper.myLooper().getQueue().addIdleHandler(function(){
Looper.myLooper().quitSafely();
});
Looper.loop();
}
});
thread.setUncaughtExceptionHandler(function(th, ex){
handleGUIEdit(function(){
alert(ex.getMessage());
})
});
threads[thread.getId()] = {};
thread.start();
}
/**
* Gets a handler for the current thread and initializes a looper if necessary.
* @returns {Handler}
*/
function getHandler(){
if(Looper.getMainLooper().getThread() == Thread.currentThread()){
return GUIHandler;
}else{
var threadId = Thread.currentThread().getId();
if(threads[threadId].prepared != true){
Looper.prepare();
threads[threadId].prepared = true;
}
return new Handler();
}
}
]]>Pierre Hébert found a bug in the stable ll14:
Running this crashes ll:
if(confirm(“test1”)){
if(confirm(“test2”)){}
}
It didn’t do that in 14b7
Seems to be something with a nullpointer exception
Phone: ecoo 304
Rom: stock android 4.4.4
]]>Question: is it possible to get the container in which the menu was opened?
The value of item is set to the item from which the menu was opened if it is an item menu, so this would make sense for containers too.
]]>There seems to be weird behavior with custom views: when you do getCurrentScript() in a script that causes a custom…
So for example:
alert(getActiveScreen().getContainerById(7).getItemByName(“testCV”).getView().getText())
alert(getCurrentScript().getName())
Will display the text in the textview of the custom view, but after that the name of the creation script of that custom view instead of the name of the script that runs this.
]]>Does somebody know a way execute a task via a script that doesn’t freeze LL while it’s being executed?
Thanks in advance 🙂
]]>