Posts

Simple car racing android game in Sketchware

Image
To create a simple car racing game in sketchware follow the steps given below.

1. Create a new project in Sketchware.

2. In VIEW area of main.xml add a TextView textview3 for displaying score of previous game, a TextView textview4 for displaying high score, and a Button button1 for starting game.

3. In MainActivity, add a Shared Preferences component sp:sp.

4. Add onStart event and put blocks to set the text of textview3 and textview4.

5. Create a new page page2.xml.

6. On button1 click use intent to move to page2.

7. On page2.xml add a LinearV linear1 with padding 0 and width and height MATCH_PARENT.

8. In Page2Activity, add a Shared Preferences component sp:sp.

9. Create a number variable highscore.

10. In onCreate event of Page2Activity, use blocks to set the value of number variable highscore, and use codes to create a new GameView and add it to linear1, as shown in image below.

The code used in the add source directly block is:
GameView bcv = new GameView(this);
linear1.addView(bc…

Showing Images in GridView

Image
Here we create an app in Sketchware which will display the images picked using FilePicker in a GridView. And on clicking the GridView item, it will display a dialog box asking if we want to delete the image. To create such app, follow the steps given below.

1. Create a new project in Sketchware.

2. In VIEW area add a Button button1 and a LinearV linear1.

3. Add a FilePicker component picker with mime type image/*.

4. Create a number variable n, a List Map maplist, and a List String slist.

5. In the event on button1 Click , use the block
FilePicker picker pick files.
This will open the gallery when button1 is clicked, and allow users to pick images.

6. In EVENT area add a new event FilePicker onFilesPicked under Component section.

7. In the event FilePicker onFilesPicked use the blocks as shown in image below, to get the path of selected images to maplist.
Then use codes to display the selected images in gridview1.
gridview1.setAdapter(new ImageAdapter(getBaseContext()));
((BaseAdapter)gr…

Create a Stopwatch App using Chronometer in Sketchware

Image
To create a Stopwatch App in sketchware using Chronometer, follow the steps given below.

1. Create a new project in Sketchware.

2. In VIEW area add a LinearV with width and height as match_parent, and gravity as center_horizontal, center_vertical.
• Inside this add a LinearH linear2 with width 240, height 240, padding 20, magin 8, and gravity center_horizontal, center_vertical.
• Below linear2, add two Buttons start_button and pause_button. Set their margins as 8 and text as START and PAUSE respectively.

3. Create a more block extra.

4. In the more block extra, use an add source directly blocks and put codes to declare a long variable timeWhenStopped, and a Chronometer stopclock.
}
private long timeWhenStopped = 0;
private Chronometer stopclock;
{

5. Add 5 number variables mode, ZERO, RUNNING, STOPPED, PAUSED.

6. In onCreate event, set ZERO to 0, RUNNING to 1, STOPPED to 2, PAUSED to 3, and mode to ZERO.

After this use an add source directly block and put codes to set a GradientDrawable …

Admob rewarded video Ads in Sketchware

Image
To integrate Admob Rewarded Video Ads to a Sketchware project, follow the steps given below.

Prerequisites
An Android project (Sketchware project)Account in Admob
Always place the test ad unit ID before placing your ad unit ID. App ID and ad unit ID can be obtained by registering the app on Admob. But for using test ads no registration is required.
Do not click on your own Ads.

1. Create an android project in Sketchware.

2. Add the app to your Admob account. For your app, generate an ad unit ID for Rewarded Video Ads.

3. In Sketchware project, navigate to Library Manager and open Admob settings.
i. Click on Add manually and add the ad unit ID generated on Admob website, or use test ad unit ID ca-app-pub-3940256099942544/5224354917.


ii. If you are not using any banner or interstitial ad units, select the same ad unit ID for both banner and interstitial ads.
iii. Add Test Device automatically shown by Sketchware.
iv. Save it.
v. Switch ON Admob and AppCompat and design.

4. In this exampl…

Create Bluetooth ON/OFF Switch

Image
To create a Bluetooth ON/OFF switch in Sketchware android project follow the steps given below.

1. In VIEW area of your sketchware android project, insert a LinearH and inside it insert a Switch switch1.
For switch1 write text as 'Bluetooth', set width as match_parent, and set gravity as left.

2. Add a BluetoothConnect component bt.

3. Add onResume event and here use blocks to set the checked state of switch1 as per the state of bluetooth.
4. Create a more block setBluetooth<enable> and define it by putting following code in an add source directly block.

android.bluetooth.BluetoothAdapter bluetoothAdapter = android.bluetooth.BluetoothAdapter.getDefaultAdapter();
boolean isEnabled = bluetoothAdapter.isEnabled();
if (_enable && !isEnabled) {
bluetoothAdapter.enable();
} else if(!_enable && isEnabled) {
bluetoothAdapter.disable();
}

5. In switch1 onCheckChanged use block the setBluetooth Block to set the bluetooth on or off according to the checked state of switch…

Create Android Digital Clock App in Sketchware

Image
To create a simple Digital Clock android app in sketchware, or to display time in your android app, follow the instructions given below.

1. Create a new android project in Sketchware.

2. In VIEW area add a LinearV linear1. For linear1 set gravity to center_vertical.
Inside linear1, add a LinearH linear2.

3. In LOGIC area, open onCreate event. Insert an add source directly block from operator section. In this add source directly block put codes provided below.
TextClock clock = new TextClock(this);
clock.setTextSize(50);
clock.setTextColor(Color.RED);
clock.setFormat24Hour("dd MMM yyyy hh:mm:ss cccc");
linear2.addView(clock);

This code creates a new TextClockclock. Then sets the text size and text color for the TextClock, sets the format for the TextClock, and adds the TextClock to linear2.

For symbols which can be used in clock format visit http://www.sketchwarehelp.com/2017/07/list-of-calendar-format-symbols-valid.html?m=1 

4. Save and run the project. Install the app generated…

Age Calculator App in Sketchware

Image
To create an Age Calculator App using DatePickerDialog in Sketchware follow the steps given below.

1. In VIEW area of your sketchware android project, insert a LinearH and inside it insert an EditText edittext1 for displaying Date of Birth, and an ImageView imageview1, for displaying calendar symbol.
Insert another LinearH and inside it insert an EditText edittext2, for displaying the age.

2. Create a more block extra.

3. In the more block extra use add source directly block and put following code.
}

// Define showDatePickerDialog(View).
public void showDatePickerDialog(View v) {
// Create and show a new DatePickerFragment.
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}

// Define a DialogFragment class DatePickerFragment.
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
// Define a new Calendar for present date
Calendar now = Calendar.getInstance();
@Override
p…

TimePickerDialog in Sketchware

Image
To create a TimePickerDialog in Sketchware android project follow the steps given below.

1. In VIEW area of your sketchware android project, insert a LinearH and inside it insert a TextView textview1, and a Button button1.
For textview1 write text as '00:00'.

2. Create a more block extra.

3. In the more block extra use add source directly block and put following code.
}

public static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
return new TimePickerDialog(getActivity(), this, hour, minute, android.text.format.DateFormat.is24HourFormat(getActivity()));
}

public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
TextView textview101 = getActivity().findViewById(R.id.textview1);
textview101.setText(hourOfDay + ":" + minute);
}

* This cod…

Automatic text switching using ViewFlipper in Sketchware

Image
In Sketchware, to display a list of sentences one by one by automatically switching to next sentence every few seconds, follow the steps given below.

1. In Sketchware project, in main.xml add a LinearLayout linear1, with width and height as MATCH_PARENT. Set a beautiful image as background of linear1.

2. Add a CustomView customview.xml. In this add a TextView textview1, with text size 40, width and height MATCH_PARENT, and gravity center_horizontal, center_vertical.

3. Add a String List string_list.

4. In onCreate, one by one add sentences to this list.

5. After adding items to string_list, use add source directly block and put following code in it.
ViewFlipper viewFlipper = new ViewFlipper(this);

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(20, 20, 20, 20);
layoutParams.gravity = Gravity.CENTER;

viewFlipper.setLayoutParams(layoutParams);
viewFlipper.setFlipInterval(…

Download a file from a web link in Sketchware

Image
To download a file from any web url, we have to do following:
Define an AsyncTask which can do the download in background, i.e. in a thread different from the main UI thread. We need this because downloading large files on main thread may consume more memory and may lead the app to crash.Use HttpURLConnection to openConnection() for the url and create an InputStream for downloading the url.Create an OutputStream and write data from InputStream to File path in sdcard.Show download progress using onProgressUpdate method of AsyncTask.In onPreExecute() method of AsyncTask make ProgressBar VISIBLE.In onPostExecute method of AsyncTask, make ProgressBar GONE. To create such an app in Sketchware which can download file from link provided, follow the steps given below.
1. Create a new project in Sketchware. In VIEW area add an EditText edittext1 and a Button button1. Add a LinearH progresslinear, inside this add a circular ProgressBar progressbar1 and a LinearV containing a TextView textview2,…