2016년 11월 16일 수요일

Making the lines in a multiline text box the text in a list of buttons


I have three buttons, call them A, B, and C (their current text is nothing) a button (call it ADD) and a multiline text box OR every item in a comma separated list (1,2,3, etc). This is what I want:
When I press button ADD that buttons A, B, and C take the name of the lines in the list :
1
2
3

(or 1,2,3 if CSV)

So that button A is renamed 1, B = 2 and C = 3. 

Possible? Been sitting all afternoon.


-- 
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

Taifun



So, what I'm trying to do is this:

1: When I add something (ONE LINE) in the text box, then press ADD, the first button gets that text. Second time (ONE LINE), the second button gets the text and the third time (again, one line) the third button gets the text. It works until the third button. What am I doing wrong? Is there an easier way?

2. If I copy MULTIPLE (3) lines in the textbox and press ADD I want the lines to get the text from the different lines. So if the textbox has the text:
1
2
3

If I then click ADD, I want the buttons to get the numbers 1, 2 and 3 in order. Do you understand?
 blocks.png
attached file: Texttobutton.aia


-- 
Change your 1,2,3 or 1\n2\n3 into a list by using a split block.
set buttonA.Text to select item 1 from list x
set buttonB.Text to select item 2 from list x
set buttonC.Text to select item 3 from list x

See Books and Tutorial section of this FAQ:

ABG


-- 
Can you please help me once more? I am a total beginner. So, I managed to do this: When ADD.longclick set button A,B,C text to a,b,c respectively (see picture)

What I have no clue about how to do is to make a new list x from the textbox with , or \n and select the index from the list. 
 blocks.png


-- 
See the How to Work with Lists section of the FAQ I mentioned.
ABG


--

Thanks! That was really helpful.

 So I've come this far now, any help would is appreciated. I still don't know how to make the split block list, can't find anything in the tutorials and I don't understand the built in help. See attached files.
 block(1).png
 Skärmbild_2016-11-17_06-52-16.png


attached file: Testtobutton.aia


--
use Do it to debug your blocks, see tip 4 here

it seems to be, you are working with a list of lists instead of a simple list
each bracket pair represents a list...


Taifun

-- 
Thank you for the DoIt help and I'm sorry for making another thread.

From the PDF you provided I got some answers. I still can't figure out how to make the multiline text different items in the list, but maybe someday I will.


-- 
you might want to provide a new screenshot of your relevant blocks including Do it results 
and a short description of the issue: how the result currently is and how it should be

Taifun


-- 
See attached for how to do the split.
You were wrapping the list that came out of the split block with an extra layer of list wrapping, that threw off the selects.

The Line Feed character is \n and you can do the same split as you did on a comma on a Line Feed to get a list.

ABG

-- 
See attached for how to do the split.
You were wrapping the list that came out of the split block with an extra layer of list wrapping, that threw off the selects.

The Line Feed character is \n and you can do the same split as you did on a comma on a Line Feed to get a list.

ABG

Skärmbild_2016-11-17_06-52-16.png 표시 중



-- 
Thank you sooo much, it works!


-- 
Is there any way I can have both , and \n? If I have both, neither work.


-- 
Is there any way I can have both , and \n? If I have both, neither work

There's a text block that can replace all \n with commas.
But think of a way to control your input better, so you don't have to deal with both.

On the other hand, is it possible you are being presented with a table when you get both , and \n ?
 If so, look at the csv-to-table block to turn it into a list of lists, if that's what is the shape of your data.

Maybe show us what the data looks like?

ABG


-- 
The app is supposed to be a grocery list, where the user puts a list of his/her groceries in the text box and the it generates buttons with each of the item as text. As I can't know if the user separates the items with commas or a new line, I want the option to be both :)

-- 
Use the replace all text block to change the Newlines to commas,
and run it thru a split at commas.

ABG

-- 
Oh, that's smart. Let me try!

--

How to automatically fill fields in a web page's form (when loaded in a webview)


Hi there, I'm taking a crack at my first app. One paper, it's pretty simple, and I've got most of the interface and basic logic figured out, but I'm stuck on one key step that might require an extension of some kind.

My app is pretty simple, it's for making it easy to enter the ticket lottery of a Broadway show. Normally you have to go to a webpage, click a link, and a form is opened in an iframe prompting you for your name, date of birth, etc. I'd like to have an app that stores my name, etc in TinyDB, and then opens the page in a webview. Once it loads the form, I want the fields to automatically be populated by the appropriate entries in TinyDB. If this is confusing, there's a free iOS app that does almost exactly this called Ham (https://itunes.apple.com/us/app/ham-lottery-app/id1088026752?mt=8)

Now, I can store the data easily in TinyDB through a settings screen that prompts for the various values. And I can see the class and IDs for each input field in the web page. But I don't see any obvious way to tell the app to put a TinyDB value into the corresponding an html input element when the iframe loads (or for that matter to get it to notice that the iframe has loaded). Any ideas how to accomplish this?

Thank you!

-- 
How to automatically fill fields in a web page's form (when loaded in a webview)
unfortunately that's not possible
but probably you can create your own screen using App Inventorcomponents and use the web component to send the data, as it is done in this example https://puravidaapps.com/spreadsheet.php

Taifun

-- 
Hi Taifun, thanks for the quick answer. One question about the approach you suggest:

The form I'd like to submit data to includes a Google reCAPTCHA element. The iOS app I reference fills out all the other fields automatically, then has the user handle the CAPTCHA manually. Do you see a way for the user to handle CAPTCHA using the method you're suggesting?

-- 
see this stackoverflow answer http://stackoverflow.com/a/26387263/1545993
Taifun

-- 
to prefill some fields on a webpage using the webviewer probably might be possible for older devices (API < 19), see also http://stackoverflow.com/a/13346730/1545993and http://stackoverflow.com/a/32115462/1545993

this is what the GoToUrl method is doing (copied from the sources)

  /**
   *  Load the given URL
   */
  @SimpleFunction(
      description = "Load the page at the given URL.")
  public void GoToUrl(String url) {
    webview.loadUrl(url);
  }


Taifun


-- 
I now found a solution, which runs fine on Android 7...
Enjoy!

Taifun

-- 
Awesome, thank you so much for not only considering the response, but creating a page dedicated to a detailed answer! This is above and beyond. I will take a crack at this right away.

-- 

It works great! Thank you again so much! There's only one snag I've run into and it's quite minor. I've figured out how to use this to fill in text fields and to select values for drop-down menus. There's just one checkbox I can't figure out how to automatically check (not the recaptcha, just a normal <input type="checkbox">). I'll look around and post if I find a solution, but does anyone else have any ideas?



-- 

bluetooh 507 error


I'm trying to make an app for an android.
I will be using the app on the $20 phone I've bought from walmart 'alcatel' android version 6.0.1, model 4060w. And connect it to the RaspberryPi3.
The app I created on MIT app inventor should be correct, but I keep getting 507 error message when I try to connect the bluetooth.
I just want a simple app that can 
1)connect to the raspberrypi via bluetooth.
2)receive message from raspberypi.
3)alert the user when message arrives on a pop-up box.
4)and then, have yes or no button to return.

First uploaded file is what I have so far.
Second uploaded file is what I want in the end.


 BT.png

 capture.png

-- 
See the Arduino and Bluetooth section of this FAQ

Also, the sequence in Clock1.Timer should be
 if Connected then
    if bytes available > 0 then
       global = BTClient.GetBytes(bytes available)
        process global      (better for debugging via Do It)

The 507 error has many threads, use the search box in this forum.

ABG

--
In the afterPicking you try to send a BT message before you actually connect. That cannot work.
Cheers, Ghica.

-- 

arrange items in listview


hi, i have this problem:
as you can see, this is a list that i create joining two values, the VALUE 1 before ":" and the VALUE 2 after ":"

no, since the two values are of different lenght, is it possible to arrange in a way that every value is in colum?

my ideas are:

1) split the two item in separated lists, and use two list views....the problem is to make a lookup in pairs maybe, and even if i want to delete or modify an element there will be  a problem
2) when i join the 2 values, i make something with length of words, so i can put the right length of space to make every values at the same distance

-- 

see this App Inventor Classic example http://stackoverflow.com/a/13309723/1545993
just convert it into App Inventor 2
or use 
Taifun

-- 
cool, i think it's the best solution
thanks


--
yes, i have some ideas
i'll keep the post updated


--
Do you have a fixed number of rows? If yes, you can create the columns with buttons, with no background, so they will look like clickable labels.

-- 
Not really, They are Very variable.
This evening i try to maKe something


--

just made this
the problem is that is still not alligned, maybe cause the different lenght of letters and "-"


tell me something :-(

-- 
Yes, unfortunately there's no monospace font for List Views or List Picker popups.

Fortunately, you only have two columns, which you can represent by:
TAG\n VALUEn

which would look like
------------
TAG
    VALUE
-------------

in the List View.

If you can't fix it, call it a feature.
This fits nicely in small cheap phones.

ABG

-- 
i was thinking to split TAG and TAGVALUE in two lists, i made it but the problem is that i cant scroll the two listview in the same time

-- 
There's an awkward way to combine an html label and a thin canvas into a ListView.

It's like a dog walking on two legs,
more like a bar bet.

ABG

-- 
seems interesting, for other stuff too 
thanx

-- 

found another approach

but he says "Segment: Start (1) + length (68.9375) - 1 exceeds text length (49).
Note: You will not see another error reported for 5 seconds."

?


-- 
Try rounding after you divide by 2.
And rename your procedure to dashes
ABG

-- 
rounded everything, but the same error

-- 
Time for Do Its on that segment operation.
Start from the right and work your way left.
Assign the x parameter temporarily into a new global temp_x in the procedure,
and use temp_x inside so you can apply the Do Its.
Parameters and locals evaporate before you can apply Do It to them.
Make it look like a pin cushion, then post it here.
For good measure, take the length of that long text, and compare it against the desired segment length.before you do the segment operation.
It's very finicky.
ABG

-- 
alas, 
look at that (hope i did not misunderstood the global temp_x)
-- 
See attached for how to inject a global variable into a value procedure for debugging.
After coding all the blocks, I started AIStarter, connected to the Emulator,
waited for it to warm up, then ran Do It on the call block.
This primed the global trace variable with the last x value, so
I could right-click-do-it inside the multiply block and in its parameters.

I see your comment bubbles are empty.
do_it.png 표시 중
Don't add comments to the blocks you want to trace; do-it adds them and fills them in.ABG


-- 
P.S.  I left a typo in my math to help show how Do It helps trace values.
Really.

ABG

-- 
JUST MADE IT!!!
it's not so precise, but it doesn't matter!!
NOW TELL ME THAT I'M SMART, i lot 7-8 hours of my life for that

as you can see, itworks even if the elements have a lenght > than listpicker width
maybe tomorrow i'll try to think a possibility when element have to go in 3 rows

-- 
i could i change the color of "TagName"? 

-- 
to make it easier i made lke you said, \n

it really good now, the problem is that if the second value (TAG VALUE) is too long, when he goes to another string it starts from the beginnins of the listpicker, on the left, and it'ìs not alligned to the first string, as you see in the 7th element

suggestion? not so important, but could be cool

-- 

Yail compiler error - DX execution failed... Help Please!


I posted this issue in the development section but maybe this place would have been more appropriate. Also, I thought I could reach more people here and since I need solution or work-around really urgently as I have to hand it out as my final thesis at my university in a few days, I decided to post my issue here again (really sorry for any possible inconviniences about this duplicated post).

I finished developping my app, on which I worked for the past 3 months, but now I cannot compile it. This is the error I get:

App Inventor is unable to compile this project. 
The compiler error output was 
________Preparing application icon
________Creating animation xml
________Determining BR names and actions
________Generating manifest file
________Attaching native libraries
________Attaching component assets
________Compiling source files
(compiling appinventor/ai_armai123mai/Test1_copy_4_copy/Screen1.yail to appinventor.ai_armai123mai.Test1_copy_4_copy.Screen1)
(compiling /tmp/runtime1791431272433290597.scm to com.google.youngandroid.runtime)
Kawa compile time: 2.197 seconds
________Invoking DX
YAIL compiler - DX execution failed.

Unfortunately, I have no clue how to deal with these error outputs. I never set up an application icon etc.

This .aia file is just a bit larger than 1 MB.
I have no warnings or errors shown in the blocks editor.
and I only use 1 screen.

The app works perfectly on my phone using the companion, so I acutally think the issue might not be as big as it seems maybe.

Is anybody capable to read the DX compiling error log behind this?

Taifun already told me that he succeeded in compiling without my extensions.

Unfortunately, those are absolutely essential to me and I doubt that I will have enough time to do extensive researches.

Does anybody have an idea on how I could achieve a faster solution? Maybe some work-arounds to get the app installed on some phones anyhow?

I am very grateful for any help.

Thank you a lot...


--

I have no clue how to solve your compile error, but a way to show your app on somebody's phone is to install the AI companion on their phone and run the app that way. They need to load that via their PC, if they have a google-id you just give them an .aia.
When the app is loaded, I think it will keep working for a while, even with the PC not near, but I do not know how long.

--
concerning DX execution failed generally there is SteveJG's monster list  https://groups.google.com/d/msg/mitappinventortest/fLiMEfPh09Q/1Ia0AaQEXogJ
and in your case see this recommendation from Evan
Looking at the contents of your AIX files, it appears you are placing all of your extensions in the same package, which makes the ant extensions script include all of them in any AIX you build. The current best practice is to have a package per extension that contains all classes required for the extension so you may want to split up your classes accordingly. You could also strip out the unneeded classes in files/AndroidRuntime.jar on a per-extension basis to ensure backwards compatibility by not changing the package name. However, it's probably best to perform the refactoring now to save future headaches.
alternatively build each extension separately

-- 
+1 to Taifun's response as this is the most likely culprit.

Arne,

If you have all of the sources checked out to build your extensions, you can also run a local copy of App Inventor (with the Google App Engine developer server) and a local copy of the build server. Then, when you build your app you will see the full stack trace in your console to assist in debugging your extension.

-- 
Big thanks to all of you guys for the fast responses and nice advices.

Taifun, you wrote that you succeeded in compiling after removing the extensions, so I guess we can assume for sure that the cause is related to those and only 25) of Steve's monster list would apply, which is, the same as what Evan is suspecting.

Yes, two of the three extensions use the same package (com.mr.ito) while only the tcp socket one is using com.mr.ito2. Actually, I was encountered strange "could not invoke method..." errors during runtime when certain methods of this one where called which made me think that splitting in different packages was not a good idea maybe, but okay, I can split them up and test that. I could also make a more simple appand try out one extension by another. If that doesn't help, I will try to get the AI2 running locally, so I can get a more detailed error output as Evan suggested.

It's very nice to have several options to go for now. Thank you a lot for this.

By the way, does anyone of you have AI2 locally installed? If so, may I ask you to try to compile the .aia and paste the error log here, maybe? Basically, it should just be about loading the .aia and tell it to compile, no? If not, I will do that in a few days, after I finished writing the thesis and keep you in touch.

-- 
instead of writing this, in the same time you could have fixed your extensions (just build them separately) and build your app again...

 If not, I will do that in a few days, after I finished writing the thesis and keep you in touch.

but as you said, it seems to be not so urgent anymore...

-- 
Well afaik I would have to make screenshots of all blocks and detach all the blocks which are connected to the extension blocks as they would get deleted too (thats how it was when I did that in the past) when I remove the old extensions. Then I would reassemble all the blocks with the new extensions. I think that could take some time and as I would like to hand out the script by tomorrow, I think I should do that first. Yes the .apk file is not that urgent anymore as I think my prof can use the companion also, but it would be nice if I could compile it during this week. So I will do that and keep you informed.

Btw I don't think I can simply upload the new .aix files and get the extensions updated without having to reassemble the blocks. When I did that in the past, I got that duplicate error because of the same extension name but different package name.

-- 
What about using the backpack to salvage your blocks, and what about renaming the extensions, so that you do not have the naming problem?

--
Well afaik I would have to make screenshots of all blocks and detach all the blocks which are connected to the extension blocks as they would get deleted too

no
just import the new version of an extension (without deleting the old version) and the new version will replace the old version magically

--
What about using the backpack to salvage your blocks, and what about renaming the extensions, so that you do not have the naming problem?



This sounds good. I didn't pay attention to that backpack function yet, but I think the time has come!

Well afaik I would have to make screenshots of all blocks and detach all the blocks which are connected to the extension blocks as they would get deleted too
no
just import the new version of an extension (without deleting the old version) and the new version will replace the old version magically

As I wrote, this didn't work for me in the past. Usually it does update the extension and I get that nice "Extension updated" notification without the need of changing anything, but therefore the extension name AND package name had to be the same. Otherwise I got that "duplicate name" error notification.
Anyways, I will try that again. Maybe my memories are wrong.

You guys will hear from me

-- 
 but therefore the extension name AND package name had to be the same

yes exactly
usually there is no need to change the package name
and if you change the package name, then the extension is considered a totally different extension

build the extensions separately (without changing the package name) upload them into your project (without deleting the old versions) and the new versions will replace the old versions
then build your project 

-- 
Yes but... I thought I have to change the package name in order to get rid of the DX compile error, wasn't that the point?

-- 
 You do not necessarily need to change the package name, but you do need to make sure that you will only have one copy of each class file across all of your extensions. This is not a requirement of App Inventorbut of the Android SDK (specifically the DX tool, which is why you get this error). Unfortunately, with the current iteration of the extensions code this requires some moving of class files around because it attempts to package every class file it finds into the built extension, even if you only intend to use one of the classes. One thing you could try (if you're not on Windows), is having a different extensions directory for each extension (e.g., extension_a, extension_b, extension_c) and then use symbolic links to have an "extension" link pointing to a particular extension to build. Taifun has supplied a lot of extensions and may be able to give better guidance on how to manage packaging multiple extensions for App Inventor.

-- 
a little time has passed, so I would like to post a update here.

Here come the good news:

1. I handed out the thesis in time (yay) and my prof told me it would be fine if I deliver the compiled .apk file until my presentation.

2. I checked everything out and got my app working (yaaay)!! This is what I did:

I made completely new and different directories for 2 of the extensions and assigned those new package names according to the directory paths. I also changed the components for those and adjusted the source codes.

3. I imported those and replaced all the blocks from the old extension files 1 by 1. Then, i deleted the old extensions from the project.

I kept everything from the first extension (TCPSocket).

Tadaa, compiling now went fine!

Thank you all so much for the great support. I'm really glad I didnt have to redesign all the extensions and the app I wrote!

Now I'm spending some time in fixing some little bugs and I'm right about to post a new issue. You guys will see my new post regarding this.

-- 


Problem saving canvas


I have programmed a drawing app with AI2 and it works as expected except the save canvas feature. Whether I save as .jpg or as .png, it gets the aspect ratio wrong (most of the time). The correct dimensions for my canvas are width 320 by height 355. However, most of the time it saves as 320x110. The save block is enclosed. Any thoughts on what could be going wrong?

Thanks, Bob
-- 
Post your canvas component settings. Also if you can, please post the aia file. It may happen that the canvas save works differently in different devices. Did you try it in a different device?
By the way, you can optimize your blocks a little by doing this:



-- 
Check for Screen1 extra real estate hogs like the Title Bar that might be throwing off size calculations.
They can be turned off.
ABG


-- 
Italo -- thanks for the optimization suggestion -- I like it. BTW, I am not sure what the aia file you requested is.
Abraham -- thanks for your suggestions as well.
Before I do anything more, I plan to build the app and run it directly on my device to rule out network communication problems. I will post the results and if the problem is not solved, I will post the canvas component settings and the aia (if you will tell me where to find it.

Thanks, Bob

-- 

 

-- 
I tried building the app and running it directly on my device (Alcatel One-Touch Pixi Pulsar), but did not solve the problem.
I changed the screen orientation property from unspecified to portrait -- did not solve the problem.

I eliminated the "when notifier.after text input" block and put the "canvas.save" block into the "when save(button).click" block as shown below and this did work. The saved file has the correct aspect ratio but of course the image filename is hard coded. I cannot see how to capture the filename as a variable that can be provided to the canvas.save block without using "when notifier.after text input".


I get the wrong aspect ratio when implemented as below:


As requested, I am including a screen capture of the canvas properties and have enclosed the aia file. BTW, I was unable to open the aia -- what application do you use to view this file?


Sorry for this very long reply but I'd really appreciate your help.


Bob


-- 
I think you are overloading Notifier1 with too many jobs.

Hire a new Notifier named NotifierFileName whose sole job is to ask for the file name,
and for its result event block build up the file name with a text JOIN then save the canvas
under the JOIN result.

This will reduce the number of rungs in your IF/THEN/ELSE ladder, a good thing.

ABG



--