Posts

Showing posts from June, 2020

Firebase Query to search data with value of a key

Image
The example in this post uses Firebase Query to search for a specific username, entered by user in an EditText, in a list of all users. 1. The data to be searched is shown in image below. We will search the value of key "username". 2. In View area of your project, add an EditText edittext1 , a Button button1 , and a ListView listview1 . 3. Create a Custom View user.xml . In this page, add an ImageView imageview1 and a TextView textview1 to display the details retrieved. The ImageView here has width and height 40 and scale type CENTER_CROP. The linear containing them has Gravity center_vertical. 4. For listview1 select user.xml as CustomView. 5. Create a FirebaseDb component ( user ) specifying the data location ( users ) to be searched. 6. Add a String variable query , and a List Map result_users . 7. In onCreate event use FirebaseDb stop listening. 8. In button1 onClick , set String query to text in  edittext1 . Then

Replacing a color in image

Image
To select a color in an image and replace it with a new color, follow the steps given below. 1. In main.xml, add two Buttons button_pick and button_replace , add an ImageView imageview1 , add two LinearLayout linear_getcolor and linear_setcolor , add an EditText edittext1 , and add a ProgressBar progressbar1 . 2. Create a FilePicker imagepicker : image/* for picking image. 3. Create a String variable path and five number variables width , height , w , h , and n . 4. In onCreate , use blocks to make ProgressBar Gone, and setOnTouchListener for imageview1 . The code used is imageview1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int eid = event.getAction(); switch (eid) { case MotionEvent.ACTION_MOVE: int x = (int)event.getX(); int y = (int)event.getY(); if (bitmap != null){ if (x<width && x>0 && y<height && y>0){ colorint = bitmap.getPixel(x, y); linear_getc

Firebase Login/Register with email verification

Image
To verify the email address of a user registered in your firebase app in Sketchware, follow the steps given below. 1. In main.xml , add three EditText fields, edit_email , edit_username , and edit_password , and add two Buttons register and login . 2. Add a FirebaseAuth component fauth , a FirebaseDb component user:users , and an Intent component i . 3. Add a Map Variable map , a String variable username , and a Boolean variable emailVerified . 4. Create a new page verify_email.xml . 5. In MainActivity.java , in onCreate event, if user is logged in and email is verified move to ChatActivity or the home page of your app and Finish Activity. And if user is logged in and email in not verified move to VerifyEmailActivity . See image below. The code use in add source directly block: emailVerified = fauth.getCurrentUser().isEmailVerified(); 6. In the event register button onClick , if length of text in all EditText fields is more than 0, set String username to edit_

Convert a View to pdf in Sketchware

Image
To convert a LinearLayout along with its contents, into a pdf document, follow the steps given below. 1. Create a new project in Sketchware. 2. In View area add a LinearV linear1 . Inside linear1 , add contents for the pdf document page. For linear1 , set background colour to WHITE or something else. 3. Create a String variable path . 4. Create a more block extra . In more block extra use following codes and blocks: // Create OptionsMenu. } private static final int PDF = 1; @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(Menu.NONE, PDF, 0, "toPdf").setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); return true; } // Add code for menu item selection. @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case PDF: // Create pdf document and add linear1 as a page to it. try { android.graphics.pdf.PdfDocument document = new android.graphics.pdf.PdfDocument(); android.graphics.pdf.PdfDocume