Skip to main content

Posts

Showing posts from September, 2020

UPI Payment Integration Android

                                 In this tutorial we will learn how to integrate upi payment gateway in our app. In gradle file add this dependency:- // EasyUpiPayment Library implementation 'com.shreyaspatil:EasyUpiPayment:3.0.0' Note:- Minimum Sdk must not be below 19 In MainActivity.java class file add these lines of codes:- package com.deftskill.upiintegration; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Toast; import com.shreyaspatil.easyupipayment.EasyUpiPayment; import com.shreyaspatil.easyupipayment.listener.PaymentStatusListener; import com.shreyaspatil.easyupipayment.model.PaymentApp; import com.shreyaspatil.easyupipayment.model.TransactionDetails; import java.util.ArrayList; public class MainActivity extends AppCompatActivity implements PaymentStatusListener {     private EasyUpiPayment easyUpiPayment; ...

How to Restore Variable when the Device is Rotated

When there are runtime configuration changes in your Android phone, like changing the screen orientation or the device’s language, your whole app process will be destroyed and recreated from scratch and together with it, all member variables will be reset. The system already takes care of default views like the text in an EditText field or the scrolling position of a RecyclerView or ListView. But we have to restore the variables of our activity ourselves and we do this by overriding onSaveInstanceState and passing the values to the outState Bundle. After the Activity has been recreated, there are 2 places where we can get our values back: onCreate or onRestoreInstanceState, which both get passed the savedInstanceState Bundle. In MainActivity.class file add these lines of codes:- public class MainActivity extends AppCompatActivity { private TextView mTextViewCount ; private int mCount ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreat...

AsyncTask+Weakreference

                                                              In this Tutorial we will learn, how to use the AsyncTask class, which makes it easier to do operations on a background thread and publish the results on the UI/main thread, without having to manipulate threads and handlers ourselves. For this we will subclass Asynctask, define 3 generic types for the params, the progress and the result and override 4 methods: onPreExecute, where we do preparations on the UI thread, doInBackground where we do the heavy work on a background thread, onProgressUpdate where we publish the progress to the UI thread (for example to a ProgressBar), and onPostExecute where we get back the result from the background task. In order to not leak memory by holding onto a strong reference to our MainActivity, we will make the AsyncTask static and keep a W...

Modal Bottom Sheet

In this tutorial we will learn, how to create a modal bottom sheet, by subclassing BottomSheetDialogFragment. Our sheet will have a custom layout and it will be able to communicate back to the underlying activity over an interface. In Main.Activity.java class file add these lines of codes:- import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity implements ExampleBottomSheetDialog.BottomSheetListener{ private TextView mTextView ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. activity_main ); mTextView = findViewById(R.id. text_view_button_clicked ); Button buttonOpenBottomSheet = findViewById(R.id. button_open_bottom_sheet ); buttonOpenBottomSheet.setOnClickListener( new View.OnClickListener() { ...

TimeSquare/CalenderPickerView

  In this Tutorial,we will use the TimeSquare library to create a CalendarPickerView, which is a nice alternative to the standard DatePickerDialog. We can set a minDate and a maxDate for the range and get our selected date back by setting an OnDateSelectedListener on it. We will format this date by using the DateFormat class and also get the single year, month and day with the help of the Calendar class. You can also select and return more than 1 date by setting the mode to SelectionMode.RANGE and then get a List of dates back by calling getSelectedDates. We have to add dependency in gradle file add these  dependency:- implementation 'com.squareup:android-times-square:1.6.5@aar' In activity_main.xml file add these lines of codes:- <? xml version ="1.0" encoding ="utf-8" ?> < androidx.constraintlayout.widget.ConstraintLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res...