Posts

Showing posts from August, 2017

Use of List String blocks in Sketchware android projects

Image
A string list is an ordered collection of strings, where user has precise control over where in list each string is added. Use of list blocks in Sketchware projects is described below.

Adding elements to list

Elements can be add to a list one by one, and they take the position as per the sequence in which they are added.
For example, if we add Google, Yahoo, Amazon, YouTube, and Android to a list, they will take positions 0, 1, 2, 3, and 4 respectively.
If a very large number of elements are to be added to the list, as in some kind of word game, then multiple more blocks can be used to add elements to the list, and the more blocks can be used in a sequence in the event where list is to be created.
The images below show an example.



An important aspect of lists is that they allow duplicate elements and they allow multiple null elements.

Using List elements in Spinner or ListView

Elements added to a list can be shown in Spinner or ListView by setting their data to the list, as shown in th…

How to open any other App or website from your app?

Image
Intent can be used to open urls or other apps from android app.

To open URLs from app

1. In order to link to a url from your app, which means on clicking a button or on any other event the url opens in default browser in mobile, first add an intent component in LOGIC area of Sketchware project.
2. Next, on button click event, add following blocks:
Intent setAction ACTION_VIEW,
Intent setData URL of website to be opened
StartActivity Intent

To open other apps in mobile from app

1. Other apps in mobile can be opened using the package name of those apps. If the app is not installed on mobile, then it will not open. Below is an example to open Snapseed photo editor app from a Sketchware app.

2. In order to open other apps directly on button click, add an intent component as shown above.

3. Next, on button click event, add following blocks:
Intent setAction ACTION_VIEW,
Intent setData android-app://com.niksoftware.snapseed(package name of the app)
StartActivity Intent

How to add .gif image or animation in Sketchware project?

Image
GIF images can be used in Sketchware projects by loading in webview. To load a GIF image or animation in webview follow the steps below.

1. Add a webview in VIEW area of the project, at a location where the GIF image is supposed to appear. Set the layout_width and layout_height of webview to wrap_content.

2. Save and exit the project.

3. Open ES File Explorer, and add the GIF image (suppose it's name is spin.GIF) to folder:
sdcard/.sketchware/resources/sounds/639(specific to project)/
4. Open the resource file of the same project, located at sdcard/.sketchware/data/629(specific to project)/resource, using ES Note Editor.
5. In resource file, under @sounds add name of the GIF image as following code:
{"resFullName":"spin.GIF","resName":"spin","resType":1}
6. Save the file, and open the project in Sketchware.

7. In LOGIC area under onCreate event, add the block WebView loadUrl, and write:
file:///android_res/raw/spin.GIF
8. Save and ru…

How to add a common share button in Sketchware?

Image
Sharing text contents or URLs from a Sketchware App is possible using intent, but the data can only be shared using individual urls to emails, facebook, twitter, and other sites which provide a sharing option, individually. But in order to implement a common share button for sharing content, some code is to be added in the project using add source directly block.

Follow the steps below to add a share button in Sketchware App.

1. Suppose you want to share the contents of field Edittext1 as title and of field Edittext2​ as main content. For sharing the contents, first insert a button or an imageview with share icon.

2. In LOGIC area, in the onClick event for button, which is to be used as share button, add two string variables a and b.

3. Set string variable a to contents of Edittext1 field, and variable b to contents of Edittext2 field.
4. Add the following code in add source directly block:
Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("text/plain"); i…

Create Stopwatch App in Android using Sketchware

Image
Timer component and number variables can be used to add a Stopwatch to your Android App created in Sketchware. To create a Stopwatch App in Sketchware follow the steps below.

1. Start a new project in Sketchware. Fill app name, package name and app icon.

2. In VIEW area, insert a Textview and a Button widget. In Textview properties set layout_gravity as center_horizontal, text as 00:00:00.00, and text_size as 40sp. In Button properties set layout_gravity as center_horizontal, text as Start/Stop/Reset and text_size as 20sp.

3. In LOGIC area add a new timer component t.
4. In onCreate event, add five number variables, one each for hour, minutes, seconds, and milliseconds, and an extra variable for managing Button Click. Set all these number variables to 0.

5. Suppose the five number variables are named as h, m, s, ms, and start.

6. Then in Button​ onClick event use if..then..else control as shown in the image below.

This will change variable start to 1 on first Click, 2 on second click…

Play/pause button for mediaplayer and soundpool

Image
Sometimes the user is playing your game in an office or in a classroom, he may like to switch off the game sounds. And sometimes he may like to switch off sounds to save battery. So it is important to have to a play/pause button for the sounds in your app.

To use a mediaplayer for background sound in Sketchware, in onCreate event use MediaPlayer create, set looping and start blocks.
For using soundpool, add a number variable 'sound'. Then use soundpool create max stream count (5) (*if you have five different sounds). Then one by one add the five sounds to the number variable 'sound' using the block soundID...load...
And then wherever the sound is to be played, set number variable 'sound' to StreamID SoundPool name play sound ID ... 1+ times.

Now, in order to create a play/pause button for both the Mediaplayer and the soundpool together, follow the steps given below.

1. Add an Imageview and two images, one for sound on and other for sound off.

2. Create a new b…

How to write a large paragraph in Sketchware?

Image
Though you can write limited characters in text properties of TextView if you want to write larger paragraphs, or copy multiple paragraphs at once, you can follow any of the methods below:
Method 1: Large paragraphs in a TextView
• Insert a TextView widget in View area of your project.
• Then in Logic area under onCreate event, use the block TextView textview1 setText ......., and in the space for text paste the complete paragraph you want to display. Watch the video below to understand better.

Method 2Large paragraphs in a WebView
• Convert your text to HTML. An easy way is to copy your complete text in Blogger and then copy it's HTML version.
• Insert a WebView in View area of your project.
• Then in Logic area under onCreate event, use the block WebView webview1 loadUrl......., and in the space for text, write data:text/html, <html>Paste your HTML code here</html>
• Using this method you can write words with different fonts, colors, sizes and styles in the same par…