Posts

Crop image example in Sketchware

Image
1. Create a new project in Sketchware. 2. In  main.xml * Add a Button btn_pick * Below this, add an ImageView imageview1 . * Below this add a Linear Horizontal linear_buttons . Inside linear_buttons, add three Buttons: btn_rotate , btn_crop , btn_download . 3. Switch ON AppCompat and design. 4. In Java/Kotlin Manager add a new java file BitmapCacheUtils.java and put following codes in it. package com.my.newproject10; import android.content.ContentValues; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Build; import android.os.Environment; import android.provider.MediaStore; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class BitmapCacheUtils { private static fina...

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...