Posts

ViewPager2 with Fragments in Sketchware

Image
1. Create a new project in Sketchware. 2. In  main.xml  add a TabLayout tablayout1 and a ViewPager viewpager1 . 3. Convert ViewPager to  androidx.viewpager2.widget.ViewPager2 . 4. Switch On AppCompat and design and Material3 Manager. 5. Add three new views of type Fragment: animals_fragment , fishes_fragment , and insects_fragment . Their corresponding java files will be AnimalsFragmentActivity.java , FishesFragmentActivity.java , and InsectsFragmentActivity.java  (See images below). 6. Configure your fragments as you like. 7. Add a new Java file  ViewPagerAdapter.java . Add following codes in it. package com.my.newproject18; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.viewpager2.adapter.FragmentStateAdapter; import java.util.ArrayList; import java.util.List; public class ViewPagerAdapter extends FragmentStateAdapter { private final List<Fragment> fragme...

Loading pdfs from Google Drive

Image
This post shows how to download pdf files from Google Drive to app data directory and then copy it to cache and load it in WebView. 1. Create a new project in Sketchware pro (package name in my project is com.my.newbooks). 2. Add all pdfs which you want in your app to google drive and make their access public. 3. In  main.xml  add a GridView gridview1 , and a FloatingActionButton _fab . 4. Create a Custom View grid_item.xml with an ImageView imageview1 with fixed height 200dp and scale_type fit_center. Add a TextView text_filename and ImageView image_delete . 5. Select grid_item.xml as custom view of gridview1. 6. Add two images download icon and delete icon. 7. Create a new page download.xml , and in this add a SeekBar seekbar1 and a ListView listview1 . 8. Create a Custom View downloadlist_item.xml with a TextView textview1 and an ImageView imageview1 with download icon. 9. Select downloadlist_item.xml as custom view of listview1. 10. In MainActivity.java , add an Int...

Car racing game in Sketchware

Image
1. In main.xml , add two TextViews text_score and text_hs . Also add a Button button1 . 2. Add a SharedPreferences component sp:sp , and an Intent component intent . 3. Add onStart event and put blocks as shown below. 4. Create a new page game.xml . 5. In the event button1 onClick , use Intent to move to GameActivity. 6. Add two images in drawable folder with names car_yellow and car_blue . In Resource manager, in drawable folder, create a new file car_yellow.xml and put following codes in it. <?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="200dp" android:height="400dp" android:viewportWidth="80" android:viewportHeight="160"> <path android:fillColor="#FFEB3B" android:strokeColor="#222222" android:strokeWidth="1" android:strokeLineJoin="ro...

Pdf.js with open, print and save enabled

Image
This post shows how to use Pdf.js in Sketchware project with OPEN, PRINT AND SAVE enabled. 1. Create a new project in Sketchware pro (package name in my project is com.pdf.onweb). In  main.xml  add a WebView  pdfWebView . 2. Switch On AppCompat and design. 3. Download  pdf.js  from following link: https://github.com/mozilla/pdf.js/releases/download/v5.4.296/pdfjs-5.4.296-dist.zip or https://mozilla.github.io/pdf.js/getting_started/#download 4. Extract the contents of the downloaded zip file. 5. In Sketchware pro project, in  Asset Manager , add a sample pdf file and rename it as  sample.pdf . Also, create a new folder  pdfjs . 6. In  pdfjs folder  import all the contents extracted from the downloaded zip file. 7. In assets folder, for showing custom error page, add error.html . Below is a sample error.html page. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" conte...

Create list of all installed apps

Image
1. This post describes how to create an app which shows a list of all installed apps. 2. In main.xml add a RecyclerView. 3. Switch on AppCompat and design. 4. Create a custom view recycler_item.xml . In this put an ImageView imageview1 , and put three TextViews text_label , text_package , and text_category . 5. For RecyclerView select recycler_item.xml as Custom View. 6. Create a Map List maplist . 7. Add following imports . import android.content.pm.PackageManager; import android.content.pm.ApplicationInfo; 8. In onCreate , get all apps and add to maplist. PackageManager pm = this.getPackageManager(); List<ApplicationInfo> apps = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo ai : apps) { int category = ApplicationInfo.CATEGORY_UNDEFINED; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { category = ai.category; } HashMap<String, Object> map = new HashMap<>(); ...