LL - Help

Home

Create script

Default: None

A script to create the view for this custom item. It should return an instance of android.view.View. This view will be attached to a FrameLayout with the LayoutParams MATCH_PARENT/MATCH_PARENT if none is set on the view (result of FrameLayout.generateDefaultLayoutParams()).

This script has no access to LL.getEvent() but instead the variable "item" refers to the Custom View object for which the view is being created. The variable "data" stores scripts optional execution data.

Displaying an alert or any other window that requires user interaction is not supported, the script will be canceled and no view will be created.

Sample script: set the music volume with a seek bar in your desktop


LL.bindClass("android.media.AudioManager");
LL.bindClass("android.widget.SeekBar");
LL.bindClass("android.widget.FrameLayout");
LL.bindClass("android.view.Gravity");

var context = LL.getContext();

var mgr = context.getSystemService(Context.AUDIO_SERVICE);
var stream = AudioManager.STREAM_MUSIC; // see http://developer.android.com/reference/android/media/AudioManager.html for other streams

var seekBar = new SeekBar(context);
seekBar.setMax(mgr.getStreamMaxVolume(stream));
seekBar.setProgress(mgr.getStreamVolume(stream));
seekBar.setOnSeekBarChangeListener({
  onProgressChanged: function(seekBar, progress, fromUser) {
    if(fromUser) {
      mgr.setStreamVolume(stream, progress, AudioManager.FLAG_PLAY_SOUND);
    }
  }
});

// let the bar extend horizontally but not vertically, center it in the view
var lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER;
seekBar.setLayoutParams(lp);

// prevent the desktop to scroll when the thumb position is moved
item.setHorizontalGrab(true);

return seekBar;