KyungJoon Lee
now browsing by tag
Help: How to set items’ background image by script?
We can set one item’s background image by hand. At the same time, we can set all item’s background image in the desktop/folder just by setting once.
By script, we can set one item’s background image like that:
item.setBoxBackground(image1, “n”); // set a normal bg image to image1.
Then how can we set the background image of all items in the destkop by not iterating all items? Is it not possible? We have to iterate its setting?
]]>Hack for closing all folders on launching an app
In a situation like that a folder has sub-folders and panels, and its sub-folders/panels which have shortcuts or so, if user taps an shorcut(in folder/panel) to launch , then all opened folders will be closed.
01 // Desktop’s onPaused event handler
02 if (LL.getEvent().getContainer().getView().hasWindowFocus()) {
02 if (LL.getEvent().getContainer().getView().getAlpha() == 1) {
03 LL.runAction(EventHandler.CLOSE_ALL_FOLDERS);
04 }
Line 02 is a hack.
When user enters into edit mode, and then add items by using “All apps”, desktop’s onPaused event is called. If line 02 doesnt exist, to-be-added apps wil be added to desktop, not to a folder/panel where user wanted to add.
]]>Include internet access permission defaultly
Current LL app has no internet access permission.
If we need to use internet access in script, then we should install extra APK from LL site.
How about this?
I guess you know supersu app for rooted Android.
This app checks an app requiring root permission and can allow or not by user. This mechanism is safer than allowing root permission globally at once like current LL’s extra permission.
For example, after we install that permission APK, we might forget the fact that we installed.
So from that, any scripts could access internet. We have no way to know unless looking thoroughly its contents one by one.
So I guess most of normal users might hesitate to install that APK, which is of all or nothing mechanism.
I heard from Marshmallow, user can toggle app’s permission. So please give LL internet access permission defaultly.
And then, when new script is installed/saved, LL checks whether that script has internet access functions. If so, LL alerts that facts. If possible, like supersu, LL could provide the way to toggle that permission to the script. (If toggling is too complex, at least just alerting is enough)
]]>Provide the way to tell desktop’s onLoad SOURCE
I’ve just found(learned) a desktop’s onLoad event is called even on
opening
If we enter that menu, we see a series of desktop’s thumbnailed images.
In that menu, all desktop’s onLoad events are called if they aren’t already loaded. It does make sense to call onLoad event at that moment.
I think most of onLoad event-handler-script of desktop do some initialization about desktop items like folder/panel etc.
But if onLoad is called even that menu scene, we dont’ have to initialize, moreover, we CAN’T initailze, because desktop’s sub items(folder,etc) is not instantiaed yet. That means NULL error-prone.
So I’d like to have a way to tell onLoad event’s SOURCE.
For now, all cases give C_LOADED value.
If a desktop is loaded for Config-desktop menu, then LL can give its source as other value. Then we can deal that case differently.
]]>setPosition exception right after desktop onloading
// script set to onLoad event of desktop.
//setTimeout(function() {
var dt = LL.getCurrentDesktop();
dt.setPosition(0, 0, 1, false); // go to home position with no animation, scale 100%.
//},5000);
Android.makeNewToast(‘Moved to home.’, true).show();
I know that on loading of desktop, its position moves to home automatically. So generally speaking we dont have to call it manually.
Anyway, apart from that, above script has no problem at all theoretically.
But if I make LL restart, then LL emits error popup saying
“Wrapped java.lang.NullPointerException” ( at setPositin line)
Of course, dt is not null at all.
So I delayed execution by setTimeout, but in no vain.
]]>onLoad event of desktop is being called twice at restarting LL
I set the desktop’s onLoad event handler to “Run Script”.
And that script has one line like “Android.makeNewToast(Date.now() + ” onLoad…”, true).show();
If I restart LL, then two toast messages are show with different date value.
Because it’s too weird, I tested it in newly installed LL in a virtual machine. However the same result was happened with successive two toast. That means onLoad was called twice at restarting LL.
Its bug? or my bad luck?
]]>Class for playing sound using local file or scripted data.
1. Class definition
========================================================
function SoundPlayer(scriptNameForSounds) {
LL.bindClass(‘java.io.File’);
LL.bindClass(‘java.io.FileInputStream’);
LL.bindClass(‘java.io.FileOutputStream’);
LL.bindClass(‘android.os.Environment’);
LL.bindClass(‘android.media.MediaPlayer’);
LL.bindClass(‘android.util.Base64’);
this.SCRIPT_NAME_FOR_SOUNDS = scriptNameForSounds;
this.PATH_SOUNDS = Environment.getExternalStorageDirectory() + ‘/LightningLauncher/Sounds’;
new File(this.PATH_SOUNDS).mkdir();
// Use one MediaPlayer for several instance of SoundPlayer.
if (self.mediaPlayer) {
this.mediaPlayer = self.mediaPlayer;
}
else {
this.mediaPlayer = self.mediaPlayer = new MediaPlayer();
}
SoundPlayer.prototype.play = function(name) {
try {
if (!name) {
throw ‘Error(SoundPlayer.play): No sound name entered.’;
}
var soundFile = new File(this.PATH_SOUNDS, name);
if (!soundFile.exists() || soundFile.length() == 0) {
if (!this.SCRIPT_NAME_FOR_SOUNDS) {
return; // No script for sounds and no file in
}
var scriptSounds = LL.getScriptByName(this.SCRIPT_NAME_FOR_SOUNDS);
if (!scriptSounds) { throw ‘Error(SoundPlayer.play): No ‘ + this.SCRIPT_NAME_FOR_SOUNDS + ‘ script’; }
var sounds = eval(scriptSounds.getText());
if (!sounds[name]) { throw ‘Error(SoundPlayer.play): No ‘ + name + ‘ in ‘ + this.SCRIPT_NAME_FOR_SOUNDS + ‘ script’; }
var fos = new FileOutputStream(soundFile);
fos.write(Base64.decode(sounds[name], Base64.DEFAULT));
fos.close();
}
var mp = this.mediaPlayer;
mp.reset();
mp.setDataSource(new FileInputStream(soundFile).getFD());
mp.prepare();
mp.start();
}
catch(e) {
// for debug. normally ignore all errors/exceptions silently.
// Android.makeNewToast(e, true).show();
}
}
}
========================================================
2. How to play local sound file (for normal end users)
– Place any sound files under ~LightningLauncher/Sounds folder.
In your script,
var player = new SoundPlayer();
player.play(‘click1.mp3’); // plays ~LL…/Sounds/click1.mp3
========================================================
3. How to play scripted sound file (for developers who want to distribute their own sound clips or open-sourced ones within scripts)
– Prepare sound clip.
– Encode it to MP3, or OGG for a small size. I use http://media.io site.
– Encode MP3/OGG.. to base64 form I use http://base64-encoding.online-domain-tools.com
– Create
// my_sounds_script_name
(function() {
return {
SOUND_NAME : ‘BASE64 String…’,
‘click2.mp3’ : ‘ZFSAACSD … =’,
‘click3.ogg’ : ‘DSDSW.ds … =’
};
})();
You can embed as many as BASE64’ed sound clip in script.
—
In your script using sounds,
var player = new SoundPlayer(SOUND_SCRIPT_NAME);
player.play(SOUND_NAME);
ie.
var player = new SoundPlayer(‘my_sounds_script_name’);
player.play(‘click1.mp3’);
player.play(‘click3.ogg’);
// If ~LL…/Sounds/click1.mp3 exists, then play that file.
// If not, it creates ‘click1.mp3’ file using
If you’ are to use sounds in several scripts, you had better cache SoundPlayer object, for example:
if (!self.mySoundPlayer) {
self.mySoundPlayer = new SoundPlayer(‘my_sound_script’);
}
self.mySoundPlayer.play(‘click.mp3’);
========================================================
Using this method, you can use sound effects and distribute them only using LL’s script feature.
]]>I’m not sure it’s bug or feature.
I’m not sure it’s bug or feature.
Anyway.
The folder ‘FolderX’ has horizontal RIGHT alignment.
And its right margin is set to 200px or so.
Under this condition, if I tap the area of folder’s margin, it blocks all tap event. So if I tap in upper circle area, play store app is open, but if I tap lower circle area, folder blocks tap. As a result, in the margin area of folder, we have no way to get any events.
In HTML(or other thing), in this case, only content area reacts to event. I think its bug.
]]>I’ve just learned script “item.setVisibility();” has no corresponding menu.
I know in edit menu for an item, there is Transparency option, but two are different afaik.
If I’d like to hide/show an item, where do I have to look in edit menu?
I think it has no way without using script for now. Right?
]]>