Posts

Add menu in actionbar in Sketchware

Image
1) Create a sketchware project. 2) Add a more block extra . 3) In that more block extra do as below:- 4) Code used in First ASD block is:- } @Override public boolean onCreateOptionsMenu (Menu menu){ menu.add(0,0,0,"Settings"); menu.add(0,1,1,"Profile"); menu.add(0,2,2,"About"); menu.add(0,3,3,"Rate now"); return true; 5) Code used in Second ASD block is:- } @Override public boolean onOptionsItemSelected(MenuItem item){ switch (item.getItemId()){ case 0: _settings(); break; case 1: _profile(); break; case 2: _about(); break; case 3:  _rate(); break; } return super.onOptionsItemSelected(item); 6) Since I added 4 menus there is only 4 cases. 7) Then add 4 more blocks. In here I am created settings , profile , about , rate . That,s all. Save and run project...

Share any file from External Storage in sketchware

Image
1) Create a new sketchware project. 2) Add a Button with id button1 . 3) Add a FilePicker with name g and with file type */* . 4) In button1 onClick event do as below:- 5) Add a string variable with name myFilePath :- 6) In on FilePicked event to get file path add a listString str . Set String myFilePath to get at 0 at List String : filePath Then Do as below:- 7) Code used in the ASD block is:- Intent intentShareFile = new Intent(Intent.ACTION_SEND); intentShareFile.setType("application/*"); intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+myFilePath)); startActivity(Intent.createChooser(intentShareFile, "Share File")); That's all. Save and run project...

Swipe Refresh Listview in Chat app

Image
1) Create a new sketchware project. 2) Drag and Drop Linear Layout with id linear1 and height match_parent . 3) Drag Drop ListView with id wb inside that Linear Layout linear1 . 4) Create a new custom xml layout. Add a TextView with id textview1 . 5) Enable AppCompat and Design Library and also Firebase Library. 6) In ListView add custom view as your Custom View. 7) Add a Firebase Component with name as your choice and a ListMap map . 8)In wb  BindCustomView add as your choice. 9)In on Create event do as below:- First ASD code is:- final android.support.v4.widget.SwipeRefreshLayout sr = new android.support.v4.widget.SwipeRefreshLayout(this); sr.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.MATCH_PARENT)); linear1.addView(sr); linear1.removeView(wb); linear1.post(new Runnable() { @Override public void run() { sr.addView(wb); } });  sr.setOnRe

Swipe Refresh WebView In sketchware

Image
1) Create a new sketchware project. 2) Drag and Drop a Linear Layout with id linear1 and height match_parent . 3) Drag and Drop a WebView with id wb inside that Linear Layout linear1 . 4) Enable the AppCompat and Design Library. 5) In Oncreate event do as below:- 6) Code used in ASD block is :- final android.support.v4.widget.SwipeRefreshLayout sr = new android.support.v4.widget.SwipeRefreshLayout(this); sr.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.MATCH_PARENT)); linear1.addView(sr); wb.getSettings().setJavaScriptEnabled(true); linear1.removeView(wb); linear1.post(new Runnable() { @Override public void run() {sr.addView(wb); } }); wb.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { sr.setRefreshing(false); }}); sr.setOnRefreshListener( new android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener() { @Ove

How to zip files in Sketchware

Image
1) Create a new Sketchware project. 2) Add two Buttons with id button1 and button2 and a EditText with id edittext1 Then change the text of button1 and button2 to  Zip files and folders and Unzip files . Then add a file picker component and three string variables source , destination and path . Then Create a more block zip with two strings source and destination . And add another more block Unzip with one string path . 3) In button1 (To Zip folder)   on click event do as below:- 4) In button2 (To Unzip File) on click event do as below:- 5) In onfilepicked event do as below :- 6) In more more zip paste the below code:- try { java.util.zip.ZipOutputStream os = new java.util.zip.ZipOutputStream(new java.io.FileOutputStream(_destination)); zip(os, _source, null); os.close(); } catch(java.io.IOException e) {} } private void zip(java.util.zip.ZipOutputStream os, String filePath, String name) throws java.io.IOException { java.io.File file = new java.io.File(fi

How to add an introduction in sketchware

Image
Watch the below video and follow instructions. Code used in this video is:- linear1.setOnTouchListener(new View.OnTouchListener() {@Override public boolean onTouch(View p1, MotionEvent p2){ switch(p2.getAction()) { case MotionEvent.ACTION_DOWN: f = p2.getX();break; case MotionEvent.ACTION_UP: t = p2.getX();if (((f - t) < -250)) {_SlideLeft();} if (((t - f) < -250)) {_SlideRight();}break;}return true;}});

How to Share an image from imageview to any app.

1) Create a new sketchware project or use an existing project. 2) For sharing images from imageview1 , set a button as button1 to initiate sharing. 3) In button1 onClick event add a ASD block and paste the below code:- Bitmap bm = ((android.graphics.drawable.BitmapDrawable) imageview1.getDrawable()).getBitmap(); try { java.io.File file = new java.io.File(getExternalCacheDir() + "/image.jpg"); java.io.OutputStream out = new java.io.FileOutputStream(file); bm.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (Exception e) { showMessage(e.toString()); } Intent iten = new Intent(android.content.Intent.ACTION_SEND); iten.setType("*/*"); iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(getExternalCacheDir() + "/image.jpg"))); startActivity(Intent.createChooser(iten, "Send image")); If the above code crashes consider adding WRITE EXTERNAL STORAGE by adding a more block as nothing and a bl