Posts

A Flash Light App in Sketchware

Image
To create a Torch Flashlight application for Android with Sketchware follow the steps given below. 1. Create a new project in Sketchware. In VIEW area add an ImageView imageview1 . Set it's width and height to 100, and scale type to FIT_XY. 2. Using Image Manager add two images  ic_flash_on_black  and  ic_flash_off_black . 3. Set  ic_flash_off_black  as the image of imageview1. 4. In Library manager switch on AppCompat and Design . 5. Add a Camera component . 6. Add two Boolean variables: flashLightStatus and hasCameraFlash . 7. Add two More Blocks: flashLightOn and flashLightOff . 8. In onCreate event, use add source directly block and put following code: hasCameraFlash = getPackageManager(). hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); 9. In More Block flashLightOn , use add source directly block and put following code: android.hardware.camera2.CameraManager cameraManager = (android.hardware.camera2.Camer...

Display url source code or online text file in android TextView

Image
To display an online text file or source code of any web url, in a TextView, we have to do following: Create a URL object from the String representation. Use openStream() method to open a connection to this URL and and get the InputStream for reading from that connection. Create a new BufferedReader , using a new InputStreamReader with the URL input stream. Read the text, using readLine() method of BufferedReader. But this cannot be done directly in an android project because android apps do not allow networking operation on its main UI thread. Therefore we need to use AsyncTask class, which allows us to perform background operations and publish results on the UI thread. To create such an online text file reader app in sketchware, follow the steps given below: 1. Create a new project in Sketchware. In VIEW area add a LinearV inside a ScrollV. In this add an EditText edittext1  (for writing URL), a Button button1 , and a TextView textview1  (for...

Speech Recognition: Speech to text in Sketchware

Image
We can implement Speech recognition using codes in add source directly block in Sketchware. Follow the steps below to implement Speech recognition in Sketchware. 1. Create a new android project in Sketchware. 2. In VIEW area add a Button button1 and an EditText edittext1 (or a TextView). 3. Add a new FilePicker component fp . 4. Add a new More Block extra . 5. To define this block extra , use an add source directly block and put following code in it: } public static final int REQ_CODE_SPEECH_INPUT = 1; { 6. In the event button1 onClick , use an add source directly block and put following code: Intent intent = new Intent(android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL, android.speech.RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); intent.putExtra(android.speech.RecognizerIntent.EXTRA_PROMPT, ...

Create a simple quiz app using Json in Sketchware

Image
To create a simple quiz app using Json String in Sketchware, follow the steps given below. 1. Create a json array containing all the questions and options. Each object in the array should contain a question with key ' ques ', four options for the question with keys ' a ', ' b ', ' c ' and ' d ', and the correct answer with key ' ans '. [ { "ques" : "The larynx in adults lies in front of hypopharynx opposite the...", "a" : "second to fifth cervical vertebrae", "b" : "fifth to seventh cervical vertebrae", "c" : "third to sixth cervical vertebrae", "d" : "first two cervical vertebrae", "ans" : "c" }, { "ques" : "Which of the following is the largest cartilage of larynx?", "a" : "thyroid cartilage", "b" : "cricoid cartilage", "c" : ...

Sort Firebase data for Android project

Image
If your firebase data contains same keys at each position, as shown in image below, then you can follow the steps below for sorting the data before displaying it in an app created in Sketchware. 1. In your Sketchware project, add a ListView listview1 . 2. Create a CustomView custom.xml . In this View add TextViews for displaying data at each position in Firebase database. 3. In properties of listview1 select custom.xml as customView. 4. Add a new List Map  maplist . 5. Add a FirebaseDB component with any name, and with data location same as in your Firebase database. ( fdb: results ) 6. Add ListView onBindCustomView event. In this event use blocks for displaying the data from List Map  maplist  in ListView listview1 . 7. Save and run the project. 8. Delete the installed app. 9. Export source code of this project. Unzip it in a folder on sdcard. 10. Open the project in AIDE. 11. In app level build.gradle  file, in dependencies, chang...

JSON syntax

Image
JSON syntax rules Data is in name/value pairs "My name"   :   "Sanjeev" Data is separated by commas { "name" : "Sanjeev" , "age" : "29" , "registration number" : "1628634" } Curly braces hold objects { "name" : "Sanjeev", "age" : "29", "registration number" : "1628634" } Square brackets hold arrays [ { "name" : "Sanjeev", "age" : "29" }, { "name" : "Ranju", "age" : "25" }, { "name" : "Anand", "age" : "16" }, { "name" : "Richa", "age" : "20" } ] A name/value pair consists of   a field   name or key   (in double quotes), followed by a   colon , followed by a   value . {   "name"   :   "Sanjeev"   } Types of Values in JSON In JSON,   values   must be one...

Loading images in WebView in Sketchware

Image
We can use WebView for loading images from any url or for loading images from drawable folder, assets folder, or resource folder of our app. 1. To load an image from a website in WebView, we can directly write the url of the image in the WebView loadUrl block. Even animated gifs can be loaded directly to WebView. WebView   webview1   loadUrl   http://.....jpg 2. We can modify the width and height of this image loaded in WebView by using following code in  WebView loadUrl  block: WebView   webview1   loadUrl   data:text/html,<img width=100% height="" src="(imageUrl)"> We can make it fit the width of the screen by setting width=100% in above code. 3. We can also load the images added using Image Manager in Sketchware (images in drawable folder) with following code: WebView   webview1   loadUrl   file:///android_res/drawable/image Note that in above code image is name of the image and has to be changed acc...