Skip to first unread message
Assigned to scottfr...@gmail.com by taifu...@gmail.com

Jack Woolford

unread,
Sep 26, 2014, 2:59:23 AM9/26/14
to
Howdy,

So I'm so close to finishing but currently when I use SetBackgroundPixelColor it seems to draw a circle at the given location not a square/fill the area? I assume I'm just confused as to what SetBackgroundPixelColor is meant to do but can't find detailed enough documentation that explains it. I've looked at this documentation here: http://appinventor.mit.edu/explore/content/basic.html but none of the methods seem to do exactly what I would like it to do. Once I've got this solved I'm pretty certain I will have a working Conway's Game of Life with adjustable grid size...Hopefully haha.

Anyway any help would be appreciated,

Thanks.

Edit: I think I need to add more detail to what I'm trying to do. I am currently creating a grid on a canvas, I generate it on a touch of the canvas. From there it goes into doing quite a lot of things, eventually it gets to the part I'm up to and tries to generate filled squares in that grid but instead creates a random circle on the top of multiple squares. Anyway I didn't want to upload the code really because I'm sort of wanting to do a test and see what happens putting such an app on the app store for $0.99 just for the fun of it (hopefully you can sell apps made in App Inventor (from what I've read there seems to be no reason why I couldn't)). Although it isn't anywhere near finished yet so it will probably be fine. So the code is now attached. 

Oh go to screen3 for the problem code.

Edit: Also I found this link but the Google Group seems to be gone thus I can't access the link mentioned on this webpage: http://androidforums.com/app-inventor/560233-how-draw-polygons.html
GameOfLife8.aia

Taifun

unread,
Sep 26, 2014, 10:38:05 AM9/26/14
to mitappinv...@googlegroups.com
I you are asking for help, I recommend you to make it as easy for others to be able to help you ...
You probably will get more feedback then...

which means in your case post a screenshot of your relevant blocks...

To download the aia file, upload it to  App Inventor, open it, do some bug hunting for you, etc... this takes time, and most people will not do that...
Thank you.

Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

Jack Woolford

unread,
Sep 26, 2014, 11:44:53 AM9/26/14
to
Sorry, I shouldn't have assumed so much. See I mainly uploaded the file so people could see what exactly it was doing, how it was making a grid etc. Attached is the blocks in question. I'm pretty sure these are the relevant blocks, as they are the only blocks drawing anything.

Edit: If I don't reply it is because I've gone to bed, becoming rather early in the morning here in Australia.Thanks.


PTherSetBackgroundPixelColor.png
SetBackgroundPixelColor.png

Greg Jensen

unread,
Sep 26, 2014, 7:03:37 PM9/26/14
to mitappinv...@googlegroups.com
A square is a line that is exactly as wide as it is long.
Why not draw short wide lines? Or is it the animation effect you're after?  
For the later your code is setting pixels from a list of coordinates.  To see why it's 'drawing' circles instead of squares we'd need to inspect the elements in that list.
Show us the code that creates the list of co-ordinates.

Scott Ferguson

unread,
Sep 26, 2014, 8:21:29 PM9/26/14
to

If  you use DrawPoint with the LineWidth set to the size of the square then you can draw a filled rectangle easily.

For example, say you have a canvas named MyCanvas.
Then the following will draw a red square with sides of length 50 at location 10,10.

Set MyCanvas.PaintColor to [red color block here]
Set MyCanvas.LineWidth to 50
MyCanvas.DrawPoint (10,10)
---
sf
 

Jack Woolford

unread,
Sep 27, 2014, 2:45:33 AM9/27/14
to mitappinv...@googlegroups.com
Thanks Greg and Scott now I can draw a square, only problem is not to where I want it to...

By the way Scott you might recognise some of my code as it was originally part of StarClusters but has been modified quite a bit and stripped back. So yes now I can draw a square where I touch the screen but it doesn't exactly fill a particular given square on the grid I generated. See the other problem will be I'm going to make the grid adjustable to whatever amount of rows * columns the person wants. Although that shouldn't hinder it too much I don't think will just need to use a variable. I also used part of MazeMaker to generate the grid.

Anyway below is the code that generates a grid which I believe is the code in question that I need to get x and y coordinates from to generate a square starting from that corner. I just can't seem to work out how I've tried just using my Global X and Global Y values and dividing them by 100 to get the x and y coordinates but that doesn't work... I'm sure it doesn't work because I'm missing something though.

Thanks.
TimerThatDrawsGrid.png
ProcedureThatSetsVariablesForTimer.png

Jack Woolford

unread,
Sep 27, 2014, 6:21:01 AM9/27/14
to
Before I make another thread, I have some more questions someone might be able to answer. Seeing as the main people here seem to have been using App Inventor for a long time and are geniuses at it.

So first of al my main question is can I somehow make a less sensitive swipe motion to change screens, or to bring down a menu. I have already implemented both of these things just when I swipe down to bring the down the top menu it often changes to the next screen as it notices the slight movement to the left or right. I've tried both canvas.dragged and canvas.flung but both seem to be slightly too sensitive. Anyway attached is the code for swiping left or right, up or down.

Another question I have is can I run App Inventor code in a separate thread, like CPU thread? Reason being I need to scan the grid/board and it is rather slow, so I thought if there is another thread available in the CPU it could open that up and run it separately thus hopefully processing it faster. 

Which brings me to another question is there a way even third party that gives you the ability to determine the amount of RAM/CPU power given to an App Inventor app, even GPU power I guess (why not add that as well haha)?

I know the above are probably a bit over the top for an App Inventor app but as I search more I find there really isn't any you can't do with App Inventor it just requires some of the source code being edited or some hacky tricks, or someone to think it up basically. Like for example I wanted to remove the title bar that doesn't have an option to be removed but AppToMArket allows you to remove it. I wanted to make a UI like Facebook's/Twitter's app and again after some searching have almost completely duplicated it in App Inventor. Now I'm so chuffed I'm looking into Blocky which is similar to App Inventor but can convert blocks directly to JavaScript/Python/Dart, so I could convert code to Python and the use Cython to convert it to C++...Allowing major processing speed ups. For App Inventor there is AppInvetor-Java-Translation which I haven't tried yet but hopefully allows me to convert App Inventor apps directly to Java code allowing more editing...Which might actually allow me to do the RAM/CPU/GPU allocation I mentioned, hmm... Anyway any ideas that require changing App Inventor's source code I will push to the main repository of code if other people want that feature, andI can work out what it was that was changed etc. Oh another example is I wanted to copy screens and the solution was a rather hacking method of opening the .aia file and changing every mention of Screen1 to Screen2 and pasting that in the .aia file which worked perfectly.

Anyway you guys are great, thanks again!
SwipeCode.png

Jack Woolford

unread,
Sep 27, 2014, 8:08:07 AM9/27/14
to
Okay, so I now know how to turn App Inventor 2 code into Java code, not byte code proper Java code with classes etc. 

Here are the steps for those who are interested:

Step 1:

  1. Make a new folder and copy over the .apk file that you want to decode.

  2. Now rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it. Now you can access the classes.dex files, etc. At this stage you are able to see drawables but not xml and java files, so continue.

Step 2:

  1. Now extract this .zip file in the same folder (or NEW FOLDER).

  2. Download dex2jar and extract it to the same folder (or NEW FOLDER).

  3. Move the classes.dex file into the dex2jar folder.

  4. Now open command prompt and change directory to that folder (or NEW FOLDER). Then write d2j-dex2jar classes.dex and press enter. You now have the classes.dex.dex2jar file in the same folder.

  5. Download java decompiler, double click on jd-gui, click on open file, and open classes.dex.dex2jar file from that folder: now you get class files.

  6. Save all of these class files (In jd-gui, click File -> Save All Sources) by src name. At this stage you get the java source but the .xml files are still unreadable, so continue.

Step 3:

Now open another new folder

  1. Put in the .apk file which you want to decode

  2. Download the latest version of apktool AND apktool install window (both can be downloaded from the same link) and place them in the same folder

  3. Download framework-res.apk and put it in the same folder (Not all apk file need this file, but it doesn't hurt)

  4. Open a command window

  5. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk

  6. apktool d myApp.apk (where myApp.apk denotes the filename that you want to decode)

now you get a file folder in that folder and can easily read the apk's xml files.

Step 4:

It's not any step just copy contents of both folder(in this case both new folder)to the single one

and enjoy the source code...

Those steps are from Stackoverflow here: https://stackoverflow.com/questions/3593420/is-there-a-way-to-get-the-source-code-from-an-apk-file/6081365#6081365 . I can verify it does work attached is the Java source code of my current project, whether the code can be compiled into Java byte code I am yet to find out or into another .apk but I'm pretty sure it will work it's just messy though. Anyway hopefully that helps someone, as all the old App Inventor to Java translation tools no longer work and this is fairly easy although sure you have to download a lot of files to get it to work but it works!

classes-dex2jar.src.zip

Ahmed Salama

unread,
Sep 27, 2014, 8:08:26 AM9/27/14
to mitappinv...@googlegroups.com
Hi Jack
Try use canvas. TouchDown & canvas. TouchUp
To get x1,y1&x2,y2 then you could get the direction of swipe
It works with me very smooth

Jack Woolford

unread,
Sep 27, 2014, 8:48:40 AM9/27/14
to mitappinv...@googlegroups.com
Thanks for the suggestion Ahmed, I hadn't tried canvas.TouchDown or canvas.TouchUp. I would mark this as complete but I'm still having the same problem if I swipe up or down it notices I don't move up or down in a perfect line and slightly move to the left or right which activates the canvas.flung that opens screen1 or screen2... 

I have buttons that open the other screens but would love to keep the swipe left or right to change screens as well. The only option I think I might have is making my menu bar static so you don't need to swipe down or swipe up to bring that menu down. Thus it would be more like the Facebook/Twitter app with the menu bar at the top that is static instead of the Google+ app...

Anyway thanks again.

Min Zarni Aung

unread,
Sep 27, 2014, 9:43:21 PM9/27/14
to mitappinv...@googlegroups.com
Hi Jack!

If you want to detect only left or right flung, you can use another if-then condition inside canvas.flung. You have to use X-Y position and Heading in canvas.flung event. Use X position to detect left or right and Heading degree to eleminate up-down event. Good Luck!
Great work with decompiling apk. Keep on.

Reply all
Reply to author
Forward
0 new messages