Posts

Showing posts from April, 2025

Simple java.time.LocalDate examples

Add following imports: import java.time.LocalDate; import java.time.ZoneId; import java.time.format.DateTimeFormatter; Following are examples for displaying date: // Get current LocalDate LocalDate date = LocalDate.now(); // e.g., 28 April 2025 // Format LocalDate DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy"); String formattedDate = date.format(formatter); // "28 April 2025" // Display LocalDate textview2.setText(date.toString()); // Result: "2025-04-28" (ISO format) textview3.setText(formattedDate); // Result: "28 April 2025" // LocalDate of a specific time zone ZoneId zone1 = ZoneId.of("Asia/Kolkata"); // or ZoneId.of("+05:30") LocalDate date2 = LocalDate.now(zone1); textview4.setText(date2.format(formatter)); // Result: "28 April 2025" (same date if system time zone matches, otherwise adjusted) // LocalDate from year, month, and day of month LocalDate date3 = LocalDate....

Flash light app in Sketchware pro

Image
 Follow the steps given below to create a Flash light android app in Sketchware pro. 1. Create a new app in Sketchware pro. 2. Switch on AppCompat and Design. 3. In View area (main.xml), add a Linear Vertical with gravity set to center_horizontal and center_vertical. Inside this add an ImageView imageview1 . 4. In image manager, add two images ic_flash_on_black and ic_flash_off_black . 5. For imageview1, select ic_flash_off_black as image. 6. In MainActivity, add import event and add following imports in it. import android.hardware.camera2.CameraManager; import android.hardware.camera2.CameraAccessException; 7. Add Camera Component cam. 8. Create two boolean variables hasCameraFlash and flashLightStatus and add a String variable cameraId . 9. Add a custom variable cameraManager of type CameraManager. 10. In onCreate , define hasCameraFlash, cameraManager, and cameraId. Register a callback for cameraManager CameraManager.TorchCallback to listen for changes in the flashlight stat...