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 d

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 I

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.setT

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 variab

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 o

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 2 :  Large 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, size

How to make an image zoomable and fit screen width in WebView

Image
We can make an image fit screen by setting scale_type as FIT_XY under image properties. But it is difficult to zoom an image in imageview in Sketchware. In order to make an image zoomable, we have to insert code to make the WebView zoomable, and then load the image in webview. To insert a zoomable image which fits screen​, follow the steps below. Step 1 . In your Sketchware project, insert a webview in View area. Step 2 . Go to Image Manager  and add an image ' myimage.jpg '. Step 3 . Use block Webview loadUrl and write file:///android_res/drawable/my image.jpg Step 4 . Use block add source directly  and write the following code: webview1.getSettings().setBuiltInZoomControls(true);webview1.getSettings().setDisplayZoomControls(false); webview1.getSettings().setLoadWithOverviewMode(true); webview1.getSettings().setUseWideViewPort(true); The code above enables pinch zoom in WebView. It is applicable to anything loaded in WebView and not just the image. It