Skip to content

soheil-mohammadi/PersianDatePicker

Repository files navigation

PersianDatePicker

An material android library for Persian date picker :) It works for api +14 ;)

Version 2.2.5 released!

Added English Lanuage :) In this version we added beauty animations and improve codes . enjoy it :)

HOW TO USE THIS LIBRARY ?!

Add the dependency :

	dependencies {
	       compile 'com.soheil-mohammadi:PersianDatePickerModule:2.2.5'
	}

This library has two options !

Option 1 :

It can used by showing a material dialog with animations for detecting persian date picker ! ==> Dialog Date Picker

Option 2 :

It can used by showing a material custom view that can for paging dates for detecting persian date picker ! ==> View Date Picker

Dialog Date Picker :

In the xml layout file :
<LinearLayout android:layout_width="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    tools:context="com.picker.date.persian.parisa.soheil.persiandatepicker.MainActivity"
    xmlns:android="http://schemas.android.com/apk/res/android">


    <TextView
        android:id="@+id/txt_show_dialog"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        style="@style/TextAppearance.Design.Hint"
        android:text="show me dialog !"
        android:gravity="center"/>


</LinearLayout>

In the MainActivity.java file :

public class MainActivity extends AppCompatActivity implements  DayClickListenerPersianDatePicker{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         TextView txt_show_dialog =  findViewById(R.id.txt_show_dialog);
         txt_show_dialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 DatePickerPersian datePickerPersian = DatePickerPersian.get_instance();
                datePickerPersian.show_Dialog(this ,DatePickerPersian.TRANSALATE_ANIM , null  , 0 ,R.color.colorPrimary, this);
            }
        });
    }

    @Override
    public void on_click(int year, int month, int day) {
        Toast.makeText(this, year + "/" + month +"/" + day , Toast.LENGTH_SHORT).show();
    }
}

In the above we first define a simple TextView for showing dialog date picker with onClickListener . so in the MainActivity.java in onclick event of TextView we init dialog date picker then call show_dialog method for this !

show_dialog method :

param 1 : this needs an context .
param 2 : it need an style for dialog . you can use predefine style in date picker persian :) . so you will have two options : 1- DatePickerPersian.TRANSALATE_ANIM -- 2- DatePickerPersian.ROTATE_ANIM This styles have beauty animtions for your dialog :)
param 3: it needs a Typeface font for customing dialog font . if you set it to null it will use default typeface :)
param 4: it needs an custom color for header background of your dialog . if you set it to zero it will use default color :)
param 5 : it needs an custom color for month texts background of your dialog . if you set it to zero it will use default color :)
param 6: it needs a listener for when user detect a specific date . we do it with implemention of activity from DayClickListenerPersianDatePicker then pass this activity to method ! you must implement on_click method . this pass year , month and day of that user selected it !

View Date Picker :

In the xml layout file :
<LinearLayout android:layout_width="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/linear"
    android:orientation="vertical"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.picker.date.persian.parisa.soheil.persiandatepicker.MainActivity"
    xmlns:android="http://schemas.android.com/apk/res/android">


    <com.picker.date.persian.parisa.soheil.persiandatepicker.DatePickerPersianView
        android:id="@+id/date_picker_persian"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

In the MainActivity.java file :

public class MainActivity extends AppCompatActivity implements  DayClickListenerPersianDatePicker{


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DatePickerPersianView date_picker_persian = (DatePickerPersianView) findViewById(R.id.date_picker_persian);
        date_picker_persian.set_support_fragmentManager(getSupportFragmentManager());
    }


    @Override
    public void on_click(int year, int month, int day) {
        Toast.makeText(this, year + "/" + month +"/" + day , Toast.LENGTH_SHORT).show();
    }
}

In the above we define a DatePickerPersianView for showing View date picker in xml layout file . so in the MainActivity.java in onCreate method we init it then call set_support_fragmentManager method . it needs a FragmentManager! Then we needs a listener for when user detect a specific date . we do it with implemention of activity from DayClickListenerPersianDatePicker! this pass year , month and day of that user selected it !


##Contact : You can send your comments for improve this library to me ;) Email : mad4r20@gmail.com
Telegram : Soheil Mohammadi


Good Luck :)

About

An material android library for Persian date picker :)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages