Git Product home page Git Product logo

persiandaterangepicker's Introduction

PersianDateRangePicker

Build Status

Select range of dates and times in the Persian Calender

Project Setup and Dependencies

  • JDK 8
  • Android SDK Build tools 28.0.3
  • Supports API Level +17
  • AppCompat & Design libraries androidx v:1.0.0

A quick overview

  • compatible with API Level +17
  • RTL support
  • Custom Font support

Preview

Demo

You can download the latest demo APK from here: https://github.com/bkhezry/PersianDateRangePicker/blob/master/assets/PersianDateRangePicker.apk

Screenshots

Setup

1. Provide the gradle dependency

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Add the dependency:

dependencies {
	implementation 'com.github.bkhezry:PersianDateRangePicker:1.2.6'
}

Using the Pickers

  1. Implement an PersianDatePickerDialog.OnDateSetListener or PersianTimePickerDialog.OnTimeSetListener
  2. Create a PersianDatePickerDialog using the supplied factory

Implement an OnDateSetListener

In order to receive the date set in the picker, you will need to implement the OnDateSetListener interfaces. Typically this will be the Activity or Fragment that creates the Pickers.

or

Implement an OnTimeSetListener

In order to receive the time set in the picker, you will need to implement the OnTimeSetListener interfaces. Typically this will be the Activity or Fragment that creates the Pickers.

//new onDateSet
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth,int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) {
String monthString = String.valueOf(monthOfYear + 1);
    if (monthOfYear < 9) {
      monthString = "0" + monthString;
    }
    String dayString = String.valueOf(dayOfMonth);
    if (dayOfMonth < 10) {
      dayString = "0" + dayString;
    }
    String monthStringEnd = String.valueOf(monthOfYearEnd + 1);
    if (monthOfYearEnd < 9) {
      monthStringEnd = "0" + monthStringEnd;
    }
    String dayStringEnd = String.valueOf(dayOfMonthEnd);
    if (dayOfMonthEnd < 10) {
      dayStringEnd = "0" + dayStringEnd;
    }
    fromDate.setText(String.format("%s/%s/%s", LanguageUtils.getPersianNumbers(String.valueOf(year)), LanguageUtils.getPersianNumbers(monthString), LanguageUtils.getPersianNumbers(dayString)));
    toDate.setText(String.format("%s/%s/%s", LanguageUtils.getPersianNumbers(String.valueOf(yearEnd)), LanguageUtils.getPersianNumbers(monthStringEnd), LanguageUtils.getPersianNumbers(dayStringEnd)));
}

@Override
public void onTimeSet(PersianRadialPickerLayout view, int year, int monthOfYear, int dayOfMonth,int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) {
      String hourString = String.valueOf(hourOfDay);
    if (hourOfDay < 10) {
      hourString = "0" + hourString;
    }
    String minuteString = String.valueOf(minute);
    if (minute < 10) {
      minuteString = "0" + minuteString;
    }
    String hourStringEnd = String.valueOf(hourOfDayEnd);
    if (hourOfDayEnd < 10) {
      hourStringEnd = "0" + hourStringEnd;
    }
    String minuteStringEnd = String.valueOf(minuteEnd);
    if (minuteEnd < 10) {
      minuteStringEnd = "0" + minuteStringEnd;
    }
    fromTime.setText(String.format("%s:%s", LanguageUtils.getPersianNumbers(hourString), LanguageUtils.getPersianNumbers(minuteString)));
    toTime.setText(String.format("%s:%s", LanguageUtils.getPersianNumbers(hourStringEnd), LanguageUtils.getPersianNumbers(minuteStringEnd)));

}

Create a PersianDatePickerDialog` using the supplied factory

You will need to create a new instance of PersianDatePickerDialog using the static newInstance() method, supplying proper default values and a callback. Once the dialogs are configured, you can call show().

  PersianDate now = new PersianDate();
  PersianDatePickerDialog dpd = PersianDatePickerDialog.newInstance(
    MainActivity.this,
    now.getPersianYear(),
    now.getPersianMonth(),
    now.getPersianDay()
  );
  dpd.setTypeface(fontName);
  dpd.show(getFragmentManager(), "PersianDatePickerDialog");

Create a PersianTimePickerDialog` using the supplied factory

You will need to create a new instance of PersianTimePickerDialog using the static newInstance() method, supplying proper default values and a callback. Once the dialogs are configured, you can call show().

   PersianDate now = new PersianDate();
   PersianTimePickerDialog tpd = PersianTimePickerDialog.newInstance(
     MainActivity.this,
     now.get(PersianDate.HOUR_OF_DAY),
     now.get(PersianDate.MINUTE),
     true
   );
   tpd.setTypeface(fontName);
   tpd.setOnCancelListener(new DialogInterface.OnCancelListener() {
     @Override
     public void onCancel(DialogInterface dialogInterface) {
       Log.d("TimePicker", "Dialog was cancelled");
     }
   });
   tpd.show(getFragmentManager(), "PersianTimePickerDialog");

Credits

  • PersianMaterialDateTimePicker- GitHub
  • MaterialDateRangePicker- GitHub

Developed By

License

Copyright 2018 Behrouz Khezry

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

persiandaterangepicker's People

Contributors

bkhezry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

persiandaterangepicker's Issues

پیشنهاد توسعه

سلام پیشنهادی دارم برای افزودن قابلیت نمایش رویداد به برنامه ای که توسعه دادید

الان که همه ی سیستم ها به اینترنت متصل هستند پیشنهاد میکنم ارتباط با ای پی آي های تقویم رو هم در این سورس خوب پیاده سازی کنید
خودم از این سرویس زیاد استفاده میکنم


وب سرویس تقویم فارسی

اطلاعات خوبی ارائه میده مثل وقایع و مناسبت های هر روز و دریافت رویداد در حالت شمسی و قمری و میلادی

Custom font

سلام ، چطور میشه از یک فونت دلخواه استفاده کرد ؟

change library from mohammad

tnx for your fantastic code.
can u help me to resolve this please?
i use library that mohamad created(com.mohamadamin:persianmaterialdatetimepicker:1.2.1)
now i want to change my code and use your library but i dont know that how can edite my "onDateSet".
this is my code:

`@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
String symbol = "-";
String date = Utility.getPersianData(year, monthOfYear, dayOfMonth , symbol);

    monthOfYear++;

    if (request == SELECT_FROM)
    {
        dateFrom = Utility.getGlobalData(year, monthOfYear, dayOfMonth, symbol);
        btnFrom.setText(date);
    }
    else if (request == SELECT_TO)
    {
        dateTo = Utility.getGlobalData(year, monthOfYear, dayOfMonth, symbol);
        btnTO.setText(date);
    }
    if (dateFrom!=null && dateTo!=null)
    {
        if (Utility.hasPermission(dateFrom,dateTo,symbol))
            dateIsSelected = true;
        else {
            dateIsSelected = false;
            Toast.makeText(getApplicationContext(), "بازه انتخابی اشتباه است", Toast.LENGTH_LONG).show();
        }
    }
}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.