Posts

Showing posts from November, 2017

Code for drawing in any View with finger

Image
To draw using finger in any LinearLayout , set the padding of the LinearLayout​ to 0 and add following code in onCreate event using add source directly block. dv = new DrawingView(this); linear2 .addView(dv); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.GREEN); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); } DrawingView dv; private Paint mPaint; private Canvas mCanvas; public class DrawingView extends View { public int width; public int height; private Bitmap mBitmap; private Path mPath; private Paint mBitmapPaint; Context context; private Paint circlePaint; private Path circlePath; public DrawingView(Context c) { super(c); context=c; mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); circlePaint = new Paint(); circlePath = new Path(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePa

Get list of app icons and app names of all installed apps in Sketchware

Image
We can create a list of app names, app icons, app versions and app package names from information received using PackageInfo class. Follow the steps below to create a list of all installed apps, with app name, app icons, package name, version name and version code. 1. In VIEW area of your sketchware project, in main.xml add a ListView. 2. Add a new CustomView custm.xml and in this add an ImageView and four TextViews. 3. For the ImageView​ set width and height as 60dp and scale_type as FIT_XY. 4. In main.xml, for ListView select custm as customView. 5. In LOGIC area, add four List String (list11, list12, list13, and list14), add a List Map (list1), and an Intent component i. These four will act as list of app name, package name, version name, and version code. 6. In  onCreate  event, add an add source directly block. Inside the block add following code. List<android.content.pm.PackageInfo> listn = getApplicationContext().getPackageManager().g

Check if an app is installed, and get it's version in Sketchware

Image
We can check if an app is installed or not by using it's package name in simple codes in Sketchware. Check if an app is installed or not We can get information about any installed app from it's package name, by using PackageManager and PackageInfo methods. PackageInfo provides Overall information about the contents of a package. This corresponds to all the information collected from AndroidManifest.xml. In onCreate event in LOGIC of your app, use an add source directly block and add following code: boolean isAppInstalled = appInstalledOrNot(" com.besome.sketch "); if(isAppInstalled) { showMessage(" Sketchware app is installed "); } else { showMessage(" Sketchware is not installed ");} Create a More Block  extra . In the more block  extra , use an  add source directly  block and put following codes: } private boolean appInstalledOrNot(String uri) { android.content.pm.PackageManager pm = getPackageManager(); try { pm.getPackageI

Launch Camera from Sketchware App and get image to ImageView

Image
Sketchware introduced Camera component in it's new update, version 3.0.0. Camera component in Sketchware can be used to launch camera from a Sketchware App and get the captured image to ImageView. To learn how, follow the steps given below. 1. In VIEW area of your sketchware project add an ImageView imageview1 and a Button button1 . Set layout_width and layout_height of ImageView to 300, and choose scale_type of ImageView as FIT_CENTER. 2. In LOGIC area of your sketchware project, add a new Camera component cam . 3. In  onButtonClick  event use the block Camera  cam  take picture . This will launch the camera to take a picture. 4. Add a new event Camera onPictureTaken . Here use the block ImageView imageview1 set image from file path filePath . This will display the captured image in ImageView. 5. Save and run the project. Now if you click the Button, it will open camera, and the captured image will be displayed in ImageView. Watch this video for

Create Imageview with rounded corners in Sketchware

Image
To create an ImageView showing image with rounded corners follow the steps given below. 1. In your Sketchware android project, add an ImageView imageview1 , and set your desired image in imageview1. 2. In LOGIC area of your project, in onCreate event, add two add source directly blocks. 3. In the first add source directly block , add the following code which creates a bitmap image from imageview1. Bitmap bm = ((android.graphics.drawable.BitmapDrawable) imageview1 .getDrawable()).getBitmap(); 4. Then apply class getRoundedCornerBitmap(Bitmap, int) to round the corners of bitmap image, and then set it as image of imageview1, using following code in the same block. imageview1 .setImageBitmap(getRoundedCornerBitmap( bm , 360 )); Note that in above code, imageview1 is id of Imageview and it should be changed as per the id of your Imageview. The underlined text 360 is the extent to which the corners are rounded. It can be changed between 0 and 360 as per the requireme

Control device media volume using Seekbar in Sketchware App

Image
The Seekbar can be set to control media volume of device, when any media is playing, with the use of simple codes in add source directly block in Sketchware. In your Sketchware project, in   VIEW area add a TextView ( textview1 ) and a SeekBar ( seekbar1 ). Set the progress of Seekbar to 12. In LOGIC area, in onCreate event add following code in end using add source directly block: audioManager = (AudioManager) getSystemService(Context. AUDIO_SERVICE); seekbar1.setMax(audioManager. getStreamMaxVolume( AudioManager.STREAM_MUSIC)); Create a More block and put following code in it using an add source directly block. } AudioManager audioManager; private void nothing() { In Seekbar onProgressChanged event add following code using add source directly block: textview1.setText("Music Volume : " + _progressValue); audioManager.setStreamVolume( AudioManager.STREAM_MUSIC, _progressValue, 0); That's all. Save and run the project. You sh

How to create an image from a View and save it in Sketchware

Image
Using codes in add source directly block in Sketchware, we can create bitmap images from any View (like EditText, TextView, LinearLayout, WebView, etc.) in android app. The bitmap images can then be saved to externalcache or to external storage if the permissions to WRITE EXTERNAL STORAGE is added. To Create an app which can create images from any View and share it, follow the steps given below. 1. Start a new Sketchware project. In VIEW area add an LinearLayout ( linear1 ) containing things to be converted to an image, and a Button ( button1 ) for converting linear1 to image.. If you want to preview the image add an ImageView also. 2. In LOGIC area of project, create a More Block  saveView[View:view]. Here use an add source directly block and add following code: Bitmap returnedBitmap = Bitmap.createBitmap(_view.getWidth(), _view.getHeight(),Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(returnedBitmap); android.graphics.drawable.Drawable bgDrawable =_view.getBack

How to prevent automatic checking of checkbox on scrolling in Custom ListView in Sketchware?

Image
In  Custom ListView , if you use Checkbox , you will notice that when you you check a few CheckBoxes in the ListView and scroll down you find more CheckBoxes already checked. The problem is same if you use switch in Custom ListView, or try to change color of selected items in custom ListView. The solution is to save the checked position in file: shared preferences , and onCustomBind , set the checked state of Checkbox as per the Saved state in file: shared preferences. Suppose you have a custom listview and you have used CheckBox in CustomView to create a list with multiple choice mode. If you select an item and scroll down you will see more automatically selected items. To prevent this follow the steps below. 1. Add file: shared preferences component to your sketchware project. 2. In onBindCustomView​ event , set checked state of CheckBox to true or false depending on the value of File key specific to position in list, as shown in image below. 3. Next, in onBindCu

Codes for modifying Action Bar in Sketchware

Image
We can modify the Action Bar or Title bar in our Sketchware project, by using simple codes in onCreate method. Below I provide a few of those codes. Change title of Action Bar ActionBar ab = getActionBar(); ab.setTitle(" Title "); Replace the underlined text with the title you want to set. Change subtitle of Action Bar ActionBar ab = getActionBar(); ab.setSubtitle(" s​ubtitle "); Replace the underlined text with the subtitle you want to set. Show App icon in Action Bar ActionBar ab = getActionBar(); ab.setDisplayShowHomeEnabled(true); Set an image as icon in Action Bar Add the image to be displayed in Action Bar using Image Manager in your sketchware android project. Then add the following code in onCreate event. ActionBar ab = getActionBar(); ab.setIcon(getDrawable(R.drawable. imagename )); ab.setDisplayShowHomeEnabled(true); Replace the underlined text with name of the image added using Image Manager. Use Custom view in Action