damonkohler / sl4a

SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device.
Apache License 2.0
2.44k stars 800 forks source link

passing items to dialogSetItem with BeanShell #218

Open damonkohler opened 9 years ago

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:27

What steps will reproduce the problem?
1. I cannot pass items to dialogSetItems. This is the code:
droid.call( "dialogCreateAlert", "Hi" );
droid.call( "dialogSetItem", arrayOfItems );
droid.call( "dialogShow" );
with:
a) arrayOfItems1 = new String[2]; arrayOfItems[0]="a"; arrayOfItems[1]="b";
b) arrayOfItems2 = new Vector(); arrayOfItems.addElement( "a" ); etc.
c) arrayOfItems3 = new JSONArray( arrayOfItems2 );
d) arrayOfItems4 = new JSONArray(); arrayOfItems5.put( "a" ); etc.
e) arrayOfItems5 = new JSONArray(); arrayOfItems6.put( arrayOfItems2 );

What is the expected output? What do you see instead?
The expected output is  dialog with a list of items "a", "b". 
Is see instead an empty dialog window with title "Hi".

What version of the product are you using? On what operating system?
HTC Legend, Android 2.1, Beanshell 2.0b4, beanshell_for_android_r1.apk, 
sl4a_r1.apk

Please provide any additional information below.
--

Original issue reported on code.google.com by andrea.i...@gmail.com on 6 Sep 2010 at 2:19

Copied from original issue: damonkohler/android-scripting#416

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:27

I trust you actually used dialogSetItems()? Above you have dialogSetItem()

Original comment by damonkoh...@gmail.com on 6 Sep 2010 at 7:58

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:27

I confirm I used droid.call( "dialogSetItems", arrayOfItems ); (sorry for the 
error in the text above).

Original comment by andrea.i...@gmail.com on 7 Sep 2010 at 7:25

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:27

The problem described above persists also with sl4a_r2.apk.

Original comment by andrea.i...@gmail.com on 9 Sep 2010 at 2:44

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:27

I have a work around to deal with this issue:

source("/sdcard/com.googlecode.bshforandroid/extras/bsh/android.bsh");
import org.json.*;

droid = Android();
droid.call("dialogCreateAlert", "Selection");

String[] aryItems = {"item1", "item2", "item3"};
items = new JSONArray( Arrays.asList(aryItems) );
// droid.call("dialogSetItems, items); // <-- won't show list

workaround = new JSONArray();
workaround.put(items);
droid.call("dialogSetItems", workaround); // <-- will show the list
droid.call("dialogShow");

The bug actually came from 
"/sdcard/com.googlecode.bshforandroid/extras/bsh/android.bsh"
in which the following method signature matches our droid.call("dialogSetItems, 
items) call directly :

  call(String method, JSONArray params) {
    JSONObject request = new JSONObject();
    request.put("id", id);
    request.put("method", method);
    request.put("params", params);
    out.write(request.toString() + "\n");
    out.flush();
    String data = in.readLine();
    if (data == null) {
      return null;
    }
    return new JSONObject(data);
  }

rather than the expected method signature :

  call(String method, Object arg1) {
    JSONArray args = new JSONArray();
    args.put(arg1);
    call(method, args);
  }

Anyway, the android.bsh is quite out-dated (beanshell for android r3). The max. 
number of parameters supported by it is still only 4 :

    call(String method, Object arg1, Object arg2, Object arg3, Object arg4){...}

but makeIntent() in the AndroidFacade takes 8 parameters !!!

Currently, I am using my patched android.bsh as in the attachment.

Original comment by kamfuk...@gmail.com on 31 Jul 2012 at 2:27

Attachments: