Wednesday, February 27, 2019

How to make a Flash Light App in Sketchware App?

1) Create a New project in sketchware.

2) In view area add a LinearLayout as linear1 and set it's layout to center horizontal and center vertical.
Then add Imageview as imageview1. Set it's width and height to 100dp and scale type to FIT_XY.
Then on image manager add two images
ic_flash_on_black and ic_flash_off_black.
Set imageview1 to ic_flash_off_black.


3) In library manager switch on AppCompat and Design.
4) Add a Camera component.
5) Add two Boolean Variables as flashLightStatus and hasCameraFlash.
6) Add two more blocks as flashLightOn and flashLightOff.
7) In OnCreate event add a add source directly block with code:

hasCameraFlash = getPackageManager(). hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

8) In More block flashLightOn add a add source directly block with code:
android.hardware.camera2.CameraManager cameraManager = (android.hardware.camera2.CameraManager) getSystemService(Context.CAMERA_SERVICE);

try {

String cameraId = cameraManager.getCameraIdList()[0]; cameraManager.setTorchMode(cameraId, true);

flashLightStatus = true; imageview1.setImageResource(R.drawable.ic_flash_on_black); } catch (android.hardware.camera2.CameraAccessException e) { }


9) On more block flashLightOff  add a add source directly block with code:
android.hardware.camera2.CameraManager cameraManager = (android.hardware.camera2.CameraManager) getSystemService(Context.CAMERA_SERVICE);

try {

String cameraId = cameraManager.getCameraIdList()[0]; cameraManager.setTorchMode(cameraId, false);

flashLightStatus = false; imageview1.setImageResource(R.drawable.ic_flash_off_black); } catch (android.hardware.camera2.CameraAccessException e) { }


Sign up today and earn money.
10) Add imageview1 click event and add following block as shown below.



That's all.
Save and run project.

Convert linear view to pdf document in Sketchware.

1) Create a New project.

2) Add EditText as id= "edittext1", a Button as id ="button"  with text"Save" and a Linear Layout as id ="linear1".

3) In that Linear Add an another EditText as id="edittext2".Set linear1 background colour WHITE.

4) Then Create a String variable as path.

5) On button1 click event add add source directly block with code:-
try{ android.graphics.pdf.PdfDocument document = new android.graphics.pdf.PdfDocument(); android.graphics.pdf.PdfDocument.PageInfo pageInfo = new android.graphics.pdf.PdfDocument.PageInfo.Builder(linear1.getWidth(), linear1.getHeight(), 1).create(); android.graphics.pdf.PdfDocument.Page page = document.startPage(pageInfo); Canvas canvas = page.getCanvas(); Paint paint = new Paint(); canvas.drawPaint(paint); linear1.draw(canvas); document.finishPage(page); 

6) Then Set string path to as image below.

7) Add write string block to enable storage permission.
Sign up today and earn money.

8) Then Add add source directly block with code:-
java.io.File myFile = new
java.io.File(path); java.io.FileOutputStream fOut = new java.io.FileOutputStream(myFile); java.io.OutputStreamWriter myOutWriter = new java.io.OutputStreamWriter(fOut); document.writeTo(fOut); document.close(); myOutWriter.close(); fOut.close(); Toast.makeText(getBaseContext(), "File Saved", Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();}

9) Save and run project.

How to Enable Own Download in Sketchware app.

1) Create a New project.
2) In View area add WebView as webview1
3) Add more block as download_path
with String as file_path

Sign up today and earn money.
4) On create Activity event add as shown
Here I am used "/Webview/Download/" folder for download folder.
You can change it to your choice by changing all text"/Webview/Download/" .
Codes below copy to the add source directly block as shown above.

webview1.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype));
request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
HTML Video embed

Learn Eclipse


java.io.File aatv = new java.io.File(Environment.getExternalStorageDirectory().getPath() + "/Webview/Download");

if(!aatv.exists()){if (!aatv.mkdirs()){ Log.e("TravellerLog ::","Problem creating Image folder");}} request.setDestinationInExternalPublicDir("/Webview/Download", URLUtil.guessFileName(url, contentDisposition, mimetype));

DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
showMessage("Downloading File....");
//Notif if success
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
showMessage("Download Complete!");
unregisterReceiver(this);
}};
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
});
5) add on back pressed as shown

6)At last on more block download_path add as shown below.

That's all.
Save and run project.

How to Check Latest Version in sketchware with Firebase Database?

1) Create a new project in Sketchware.
2) Add Firebase library in library.
Make sure the rules in your Firebase database are read and write true.
Sign up today and earn money.
3) Add Firebase Database component as
version:version
4) Add String variables as package_name, your_version, latest_version and Add map variable as map
5) Then OnCreate event set string package_name to your app package. In this tutorial I am using sketchware.check.version
6) Then below set string block add two add source directly block. First code is
try {
android.content.pm.PackageInfo pinfo = getPackageManager().getPackageInfo( package_name, android.content.pm.PackageManager.GET_ACTIVITIES);
your_version = pinfo.versionName; }
catch (Exception e){ showMessage(e.toString()); }

Second code is
DatabaseReference rootRef = _firebase.getReference(); rootRef.child("version").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.exists()) { } else {

7) Then add following block.
8) Then add add source directly block with code
} }
@Override
public void onCancelled(DatabaseError _error) { } });
After doing above instructions your OnCreate event will look like
9) Then add a list map as map1
10) Then OnChildAdded event of Firebase Database component version:version
Do as below

Code used is
version.child("app").child("v").setValue(your_version);

That's all
Save and run project.

Enable Fullscreen for Youtube videos in WebView Sketchware

1) Create a New project in Sketchware App.


2) In View area add WebView as webview1.

3) Add more block as full.

4) Copy the below code to more block in add source directly
}

public class CustomWebClient extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout frame;

// Initially mOriginalOrientation is set to Landscape
private int mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
private int mOriginalSystemUiVisibility;

// Constructor for CustomWebClient
public CustomWebClient() {}

public Bitmap getDefaultVideoPoster() {
if (MainActivity.this == null) {
return null; }
return BitmapFactory.decodeResource(MainActivity.this.getApplicationContext().getResources(), 2130837573); }

public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback viewCallback) {
if (this.mCustomView != null) {
onHideCustomView();
return; }
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = MainActivity.this.getWindow().getDecorView().getSystemUiVisibility();
// When CustomView is shown screen orientation changes to mOriginalOrientation (Landscape).
MainActivity.this.setRequestedOrientation(this.mOriginalOrientation);
// After that mOriginalOrientation is set to portrait.
this.mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
this.mCustomViewCallback = viewCallback; ((FrameLayout)MainActivity.this.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1)); MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(3846);
}

public void onHideCustomView() {
((FrameLayout)MainActivity.this.getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
// When CustomView is hidden, screen orientation is set to mOriginalOrientation (portrait).
MainActivity.this.setRequestedOrientation(this.mOriginalOrientation);
// After that mOriginalOrientation is set to landscape.
this.mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
}

{


5) Then on Create activity event
Copy the below code
webview1.setWebChromeClient(new CustomWebClient());
Then drag the block as shown in the picture.

6) Then on back pressed event
Do as shown in the picture.

7) That's All
Save and run project.