├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── shaygan
│ │ │ └── datepicker
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── shaygan
│ │ │ └── datepicker
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── shaygan
│ │ └── datepicker
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── datepickerpersian
├── .gitignore
├── src
│ ├── main
│ │ ├── assets
│ │ │ └── bsans.ttf
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── shadow_top.xml
│ │ │ │ ├── dialog_rounded_bg.xml
│ │ │ │ ├── selector_pickerview_btn.xml
│ │ │ │ ├── ic_mult.xml
│ │ │ │ └── ic_tick.xml
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── attrs.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── colors.xml
│ │ │ └── layout
│ │ │ │ ├── model_day.xml
│ │ │ │ ├── custom_tab_item.xml
│ │ │ │ ├── item_picker.xml
│ │ │ │ ├── fragment_date_picker.xml
│ │ │ │ ├── layout_persian_date_picker.xml
│ │ │ │ └── layout_persian_dare_range_picker.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── waspar
│ │ │ └── persiandatepicker
│ │ │ ├── SetCurrentItem.java
│ │ │ ├── util
│ │ │ ├── InitDate.java
│ │ │ └── ShamsiDate.java
│ │ │ ├── wheel
│ │ │ ├── LoopRunnable.java
│ │ │ ├── MessageHandler.java
│ │ │ ├── LoopViewGestureListener.java
│ │ │ ├── TimerWheel.java
│ │ │ ├── WheelOptions.java
│ │ │ ├── LoopTimerTask.java
│ │ │ ├── WheelPickerView.java
│ │ │ └── LoopView.java
│ │ │ ├── adapter
│ │ │ ├── TabAdapterDatePicker.java
│ │ │ └── TabAdapterDateRangePicker.java
│ │ │ ├── fragment
│ │ │ ├── DateFragment.java
│ │ │ ├── FromDateFragment.java
│ │ │ └── TillDateFragment.java
│ │ │ ├── PersianDatePicker.java
│ │ │ └── PersianDateRangePicker.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── waspar
│ │ │ └── persiandatepicker
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── waspar
│ │ └── persiandatepicker
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── capture.gif
├── .idea
├── caches
│ ├── gradle_models.ser
│ └── build_file_checksums.ser
├── encodings.xml
├── vcs.xml
├── runConfigurations.xml
├── gradle.xml
├── assetWizardSettings.xml
├── misc.xml
└── codeStyles
│ └── Project.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/datepickerpersian/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':datepickerpersian'
2 |
--------------------------------------------------------------------------------
/capture.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/capture.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DatePicker
3 |
4 |
--------------------------------------------------------------------------------
/.idea/caches/gradle_models.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/.idea/caches/gradle_models.ser
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/datepickerpersian/src/main/assets/bsans.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/datepickerpersian/src/main/assets/bsans.ttf
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/datepickerpersian/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Far5had70/PersianDateRangePicker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/drawable/shadow_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/SetCurrentItem.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker;
2 |
3 | public class SetCurrentItem {
4 | public static int To = 0;
5 | public static int From = 1;
6 | }
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 22 12:58:05 IRST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/drawable/dialog_rounded_bg.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/drawable/selector_pickerview_btn.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/layout/model_day.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/layout/custom_tab_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/drawable/ic_mult.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/test/java/com/shaygan/datepicker/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.shaygan.datepicker;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/datepickerpersian/src/test/java/com/waspar/persiandatepicker/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/drawable/ic_tick.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Date Picker Persian
3 | cancel
4 | submit
5 | y
6 | m
7 | day
8 | h
9 | m
10 | s
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/util/InitDate.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.util;
2 |
3 | public class InitDate {
4 |
5 | public static String inputPersianDate(int Day , int Month , int Year){
6 |
7 | String month;
8 | String day;
9 |
10 | if (Month <= 9) {
11 | month = "0" + Month;
12 | } else {
13 | month = String.valueOf(Month);
14 | }
15 |
16 | if (Day <= 9) {
17 | day = "0" + Day;
18 | } else {
19 | day = String.valueOf(Day);
20 | }
21 | return Year + "/" + month + "/" + day;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/layout/item_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/datepickerpersian/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/shaygan/datepicker/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.shaygan.datepicker;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.shaygan.datepicker", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/datepickerpersian/src/androidTest/java/com/waspar/persiandatepicker/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.waspar.persiandatepicker.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/wheel/LoopRunnable.java:
--------------------------------------------------------------------------------
1 | // Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
2 | // Jad home page: http://www.geocities.com/kpdus/jad.html
3 | // Decompiler options: braces fieldsfirst space lnc
4 |
5 | package com.waspar.persiandatepicker.wheel;
6 |
7 | /**
8 | * Referenced classes of package com.qingchifan.view:
9 | * LoopView, LoopListener
10 | */
11 | public class LoopRunnable implements Runnable {
12 |
13 | public interface LoopListener {
14 | void onItemSelect(int item);
15 | }
16 |
17 | private final LoopView mLoopView;
18 |
19 | LoopRunnable(LoopView loopview) {
20 | super();
21 | mLoopView = loopview;
22 | }
23 |
24 | public final void run() {
25 | LoopListener listener = mLoopView.loopListener;
26 | int i = LoopView.getSelectItem(mLoopView);
27 | listener.onItemSelect(i);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #057dff
7 | #c2daf5
8 | #f5f5f5
9 | #000000
10 | #a8a8a8
11 | #2a2a2a
12 | #d5d5d5
13 | #60000000
14 | #1eed17
15 | #91d198
16 | #ffffff
17 | #c3ffffff
18 | #FF58AE61
19 |
20 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.shaygan.datepicker"
7 | minSdkVersion 16
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation project(':datepickerpersian')
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation 'com.android.support:appcompat-v7:27.1.1'
25 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
29 | }
30 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/adapter/TabAdapterDatePicker.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import com.waspar.persiandatepicker.fragment.DateFragment;
8 | import com.waspar.persiandatepicker.fragment.FromDateFragment;
9 | import com.waspar.persiandatepicker.fragment.TillDateFragment;
10 |
11 | public class TabAdapterDatePicker extends FragmentPagerAdapter {
12 |
13 | private int numOfTabs;
14 |
15 | public TabAdapterDatePicker(FragmentManager fm, int numOfTabs) {
16 | super(fm);
17 | this.numOfTabs = numOfTabs;
18 | }
19 |
20 | @Override
21 | public Fragment getItem(int position) {
22 | switch (position) {
23 | case 0:
24 | return new DateFragment();
25 | default:
26 | return null;
27 | }
28 | }
29 |
30 | @Override
31 | public int getCount() {
32 | return numOfTabs;
33 | }
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/wheel/MessageHandler.java:
--------------------------------------------------------------------------------
1 | // Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
2 | // Jad home page: http://www.geocities.com/kpdus/jad.html
3 | // Decompiler options: braces fieldsfirst space lnc
4 |
5 | package com.waspar.persiandatepicker.wheel;
6 |
7 | import android.os.Handler;
8 | import android.os.Message;
9 |
10 | /**
11 | * Referenced classes of package com.qingchifan.view:
12 | * LoopView
13 | */
14 | public class MessageHandler extends Handler {
15 |
16 | private final LoopView a;
17 |
18 | MessageHandler(LoopView loopview) {
19 | super();
20 | a = loopview;
21 | }
22 |
23 | public final void handleMessage(Message paramMessage) {
24 | if (paramMessage.what == 1000)
25 | this.a.invalidate();
26 | while (true) {
27 | if (paramMessage.what == 2000)
28 | LoopView.b(a);
29 | else if (paramMessage.what == 3000)
30 | this.a.c();
31 | super.handleMessage(paramMessage);
32 | return;
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/wheel/LoopViewGestureListener.java:
--------------------------------------------------------------------------------
1 | // Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
2 | // Jad home page: http://www.geocities.com/kpdus/jad.html
3 | // Decompiler options: braces fieldsfirst space lnc
4 |
5 | package com.waspar.persiandatepicker.wheel;
6 |
7 | import android.view.MotionEvent;
8 |
9 | //
10 |
11 | /**
12 | * Referenced classes of package com.qingchifan.view:
13 | * LoopView
14 | */
15 | public class LoopViewGestureListener extends android.view.GestureDetector.SimpleOnGestureListener {
16 |
17 | private final LoopView loopView;
18 |
19 | LoopViewGestureListener(LoopView loopview) {
20 | super();
21 | loopView = loopview;
22 | }
23 |
24 | public final boolean onDown(MotionEvent motionevent) {
25 | if (loopView.timer != null) {
26 | loopView.timer.cancel();
27 | }
28 | return true;
29 | }
30 |
31 | public final boolean onFling(MotionEvent motionevent, MotionEvent motionevent1, float f, float f1) {
32 | loopView.b(f1);
33 | return true;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/adapter/TabAdapterDateRangePicker.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import com.waspar.persiandatepicker.fragment.FromDateFragment;
8 | import com.waspar.persiandatepicker.fragment.TillDateFragment;
9 |
10 | public class TabAdapterDateRangePicker extends FragmentPagerAdapter {
11 |
12 | private int numOfTabs;
13 |
14 | public TabAdapterDateRangePicker(FragmentManager fm, int numOfTabs) {
15 | super(fm);
16 | this.numOfTabs = numOfTabs;
17 | }
18 |
19 | @Override
20 | public Fragment getItem(int position) {
21 | switch (position) {
22 | case 0:
23 | return new TillDateFragment();
24 | case 1:
25 | return new FromDateFragment();
26 | default:
27 | return null;
28 | }
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return numOfTabs;
34 | }
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/.idea/assetWizardSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/datepickerpersian/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 16
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'com.android.support:appcompat-v7:27.1.1'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
34 | implementation 'com.android.support:design:27.1.1'
35 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
36 | }
37 |
38 | //git init
39 | //git remote add origin https://github.com/xxx/yyy.git
40 | //git add .
41 | //git commit -m "first commit"
42 | //git push -u origin master
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
28 |
29 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/layout/fragment_date_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
21 |
22 |
30 |
31 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/wheel/TimerWheel.java:
--------------------------------------------------------------------------------
1 | // Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
2 | // Jad home page: http://www.geocities.com/kpdus/jad.html
3 | // Decompiler options: braces fieldsfirst space lnc
4 |
5 | package com.waspar.persiandatepicker.wheel;
6 |
7 | import java.util.Timer;
8 | import java.util.TimerTask;
9 |
10 | /**
11 | * TimerWheel.
12 | */
13 | public class TimerWheel extends TimerTask {
14 |
15 | private int a;
16 | private int b;
17 | private final int c;
18 | private final Timer timer;
19 | private final LoopView loopView;
20 |
21 | TimerWheel(LoopView loopview, int i, Timer timer) {
22 | super();
23 | loopView = loopview;
24 | c = i;
25 | this.timer = timer;
26 | a = 0x7fffffff;
27 | b = 0;
28 | }
29 |
30 | public final void run() {
31 | if (a == 0x7fffffff) {
32 | if (c < 0) {
33 | if ((float) (-c) > (loopView.l * (float) loopView.h) / 2.0F) {
34 | a = (int) (-loopView.l * (float) loopView.h - (float) c);
35 | } else {
36 | a = -c;
37 | }
38 | } else if ((float) c > (loopView.l * (float) loopView.h) / 2.0F) {
39 | a = (int) (loopView.l * (float) loopView.h - (float) c);
40 | } else {
41 | a = -c;
42 | }
43 | }
44 | b = (int) ((float) a * 0.1F);
45 | if (b == 0) {
46 | if (a < 0) {
47 | b = -1;
48 | } else {
49 | b = 1;
50 | }
51 | }
52 | if (Math.abs(a) <= 0) {
53 | timer.cancel();
54 | loopView.handler.sendEmptyMessage(3000);
55 | } else {
56 | LoopView loopview = loopView;
57 | loopview.totalScrollY = loopview.totalScrollY + b;
58 | loopView.handler.sendEmptyMessage(1000);
59 | a = a - b;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | <<<<<<< HEAD
29 |
30 | =======
31 |
32 | >>>>>>> 3ba0f9349272e90f3cbbd556230b01e807059c83
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/wheel/WheelOptions.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.wheel;
2 |
3 | import com.waspar.persiandatepicker.R;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | /**
8 | * WheelOptions.
9 | *
10 | * @author DaoLQ
11 | */
12 | public class WheelOptions {
13 | private final WheelPickerView view;
14 | private LoopView mLoopView;
15 | private int mLoop = 0;
16 |
17 | private WheelPickerView.OnOptionChangedListener mOnOptionChangedListener;
18 |
19 | public WheelOptions(WheelPickerView view) {
20 | super();
21 | this.view = view;
22 | }
23 |
24 | public void setOnOptionChangedListener(
25 | WheelPickerView.OnOptionChangedListener listener) {
26 | this.mOnOptionChangedListener = listener;
27 | }
28 |
29 | public void setPicker(final List items) {
30 | List mOptionsItems = items == null ? new ArrayList() : items;
31 | mLoopView = (LoopView) view.findViewById(R.id.loopView);
32 | mLoopView.setArrayList(mOptionsItems);
33 | mLoopView.setNotLoop();
34 | mLoopView.setListener(new LoopRunnable.LoopListener() {
35 | @Override
36 | public void onItemSelect(int item) {
37 | // mLoop++;
38 | // if (mLoop < items.size() / 2) {
39 | // return;
40 | // }
41 | doItemChange();
42 | }
43 | });
44 | assert items != null;
45 | setCurrentItems(items.size() / 2);
46 | }
47 |
48 | public void doItemChange() {
49 | if (mOnOptionChangedListener != null) {
50 | int option1 = mLoopView.getCurrentItem();
51 | mOnOptionChangedListener.onOptionChanged(view, option1);
52 | }
53 | }
54 |
55 | public void setCyclic(boolean cyclic) {
56 | mLoopView.setCyclic(cyclic);
57 | }
58 |
59 | public int getCurrentItems() {
60 | return mLoopView.getCurrentItem();
61 | }
62 |
63 | public void setCurrentItems(int option1) {
64 | mLoopView.setCurrentItem(option1);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/wheel/LoopTimerTask.java:
--------------------------------------------------------------------------------
1 | // Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
2 | // Jad home page: http://www.geocities.com/kpdus/jad.html
3 | // Decompiler options: braces fieldsfirst space lnc
4 |
5 | package com.waspar.persiandatepicker.wheel;
6 |
7 | import java.util.Timer;
8 | import java.util.TimerTask;
9 |
10 | /**
11 | * Referenced classes of package com.qingchifan.view:
12 | * LoopView
13 | */
14 | public class LoopTimerTask extends TimerTask {
15 |
16 | private float a;
17 | private final float b;
18 | private final Timer mTimer;
19 | private final LoopView mLoopView;
20 |
21 | LoopTimerTask(LoopView loopview, float f, Timer timer) {
22 | super();
23 | mLoopView = loopview;
24 | b = f;
25 | this.mTimer = timer;
26 | a = 5.147484E+02F;
27 | }
28 |
29 | @Override
30 | public final void run() {
31 | if (a == 5.147484E+02F) {
32 | if (Math.abs(b) > 2000F) {
33 | if (b > 0.0F) {
34 | a = 2000F;
35 | } else {
36 | a = -2000F;
37 | }
38 | } else {
39 | a = b;
40 | }
41 | }
42 | if (Math.abs(a) >= 0.0F && Math.abs(a) <= 20F) {
43 | mTimer.cancel();
44 | mLoopView.handler.sendEmptyMessage(2000);
45 | return;
46 | }
47 | int i = (int) ((a * 10F) / 1000F);
48 | LoopView loopview = mLoopView;
49 | loopview.totalScrollY = loopview.totalScrollY - i;
50 | if (!mLoopView.isLoop) {
51 | if (mLoopView.totalScrollY <= (int) ((float) (-mLoopView.position) * (mLoopView.l * (float) mLoopView.h))) {
52 | a = 40F;
53 | mLoopView.totalScrollY = (int) ((float) (-mLoopView.position) * (mLoopView.l * (float) mLoopView.h));
54 | } else if (mLoopView.totalScrollY >= (int) ((float) (mLoopView.arrayList.size() - 1 - mLoopView.position) * (mLoopView.l * (float) mLoopView.h))) {
55 | mLoopView.totalScrollY = (int) ((float) (mLoopView.arrayList.size() - 1 - mLoopView.position) * (mLoopView.l * (float) mLoopView.h));
56 | a = -40F;
57 | }
58 | }
59 | if (a < 0.0F) {
60 | a = a + 20F;
61 | } else {
62 | a = a - 20F;
63 | }
64 | mLoopView.handler.sendEmptyMessage(1000);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/wheel/WheelPickerView.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.wheel;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.os.Build;
7 | import android.util.AttributeSet;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.widget.FrameLayout;
11 |
12 | import com.waspar.persiandatepicker.R;
13 |
14 | import java.util.List;
15 |
16 |
17 | public class WheelPickerView extends FrameLayout {
18 |
19 | public interface OnOptionChangedListener {
20 | void onOptionChanged(WheelPickerView view, int option);
21 | }
22 |
23 | private WheelOptions wheelOptions;
24 | private LoopView item;
25 |
26 | public WheelPickerView(Context context) {
27 | this(context, null);
28 | }
29 |
30 | public WheelPickerView(Context context, AttributeSet attrs) {
31 | this(context, attrs, 0);
32 | }
33 |
34 | public WheelPickerView(Context context, AttributeSet attrs, int defStyleAttr) {
35 | super(context, attrs, defStyleAttr);
36 | setAttributeSet(context, attrs);
37 | }
38 |
39 | private void setAttributeSet(Context context, AttributeSet attrs) {
40 | View parentView = LayoutInflater.from(context).inflate(R.layout.item_picker, this);
41 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.WheelPickerView);
42 | item = (LoopView) parentView.findViewById(R.id.loopView);
43 | int textColor = typedArray.getColor(R.styleable.WheelPickerView_itemTextColorr, getResources().getColor(android.R.color.darker_gray));
44 | item.setTextColor(textColor);
45 | int textColorSelected = typedArray.getColor(R.styleable.WheelPickerView_itemTextColorrSelect, getResources().getColor(android.R.color.black));
46 | item.setTextColorSelected(textColorSelected);
47 | int textSize = typedArray.getDimensionPixelOffset(R.styleable.WheelPickerView_itemTextSize, getResources().getDimensionPixelOffset(R.dimen.activity_horizontal_margin));
48 | item.setTextSize(textSize);
49 | typedArray.recycle();
50 | wheelOptions = new WheelOptions(this);
51 | }
52 |
53 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
54 | public WheelPickerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
55 | super(context, attrs, defStyleAttr, defStyleRes);
56 | setAttributeSet(context, attrs);
57 | }
58 |
59 | public void setPicker(List optionsItems) {
60 | wheelOptions.setPicker(optionsItems);
61 | }
62 |
63 | public void setSelectOptions(int option) {
64 | wheelOptions.setCurrentItems(option);
65 | }
66 |
67 | public void setCyclic(boolean cyclic) {
68 | wheelOptions.setCyclic(cyclic);
69 | }
70 |
71 | public void setCurrentItems(int option) {
72 | wheelOptions.setCurrentItems(option);
73 | }
74 |
75 | public void settextColor(int textColor) {
76 | item.setTextColor(textColor);
77 | }
78 |
79 | public void setTextColorSelected(int textColorSelected) {
80 | item.setTextColorSelected(textColorSelected);
81 | }
82 |
83 | public void setTextSize(int textSize) {
84 | item.setTextSize(textSize);
85 | }
86 |
87 | public int getCurrentItems() {
88 | return wheelOptions.getCurrentItems();
89 | }
90 |
91 | public void setOnOptionChangedListener(OnOptionChangedListener listener) {
92 | this.wheelOptions.setOnOptionChangedListener(listener);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Persian Date Range Picker
2 |
3 |
4 |
5 | PersianDateRangePicker is a dynamic library that allows user to select a date range.
6 |
7 |
8 |
9 | # Features
10 |
11 | Background (color)
12 |
13 | Text (size , color)
14 |
15 | TypeFace(directory: Assets/sampleFont.ttf)
16 |
17 |
18 |
19 |
20 | # Installation
21 |
22 | Step 1. Add the JitPack repository to your build file
23 |
24 |
25 | Add it in your root build.gradle at the end of repositories:
26 |
27 | ```gradle
28 | dependencies {
29 | implementation 'com.github.Far5had70:PersianDateRangePicker:4.6.0'
30 | }
31 | ```
32 |
33 |
34 | Step 2. Add the dependency
35 | ```gradle
36 | allprojects {
37 | repositories {
38 | ...
39 | maven { url 'https://jitpack.io' }
40 | }
41 | }
42 | ```
43 |
44 |
45 |
46 |
47 | ## Demo
48 |
49 | You can try it out here [Sample Application](https://github.com/Far5had70/PersianDateRangePicker/blob/master/app/src/main/java/com/shaygan/datepicker/MainActivity.java)
50 |
51 |
52 |
53 |
54 | # Usage
55 |
56 |
57 |
58 | **Date Range Picker:**
59 |
60 | ```java
61 | Typeface face = Typeface.createFromAsset(getAssets(), "bsans.ttf");
62 | FragmentManager fragmentManager = getSupportFragmentManager();
63 | PersianDateRangePicker persianDateRangePicker = new PersianDateRangePicker()
64 | .setInitTillDate(InitDate.inputPersianDate(1, 3, 1397))
65 | .setInitFromDate(InitDate.inputPersianDate(1, 1, 1397))
66 | .setBackgroundColor(getResources().getColor(R.color.green))
67 | .setButtonTextColor(getResources().getColor(R.color.white))
68 | .setTabTextColor(getResources().getColor(R.color.white))
69 | .setTabSelectedTextColor(getResources().getColor(R.color.white))
70 | .setTabIndicatorColor(getResources().getColor(R.color.white))
71 | .setWheelTextColor(getResources().getColor(R.color.white_smoke))
72 | .setWheelTextColorSelected(getResources().getColor(R.color.white))
73 | .setWheelTextSize(20)
74 | .setCornerRadius(40)
75 | .setTypeface(face)
76 | .setDoneText("تائید")
77 | .setCanselText("انصراف")
78 | .setDoneDrawable(getResources().getDrawable(R.drawable.ic_tick))
79 | .setCanselDeawable(getResources().getDrawable(R.drawable.ic_mult))
80 | .setCurrentItem(SetCurrentItem.From)
81 | .setListener(new PersianDateRangePicker.RangeDate() {
82 | @Override
83 | public void From(int day, int month, int year) {
84 | Toast.makeText(MainActivity.this, ""+day+" "+month+" "+year, Toast.LENGTH_SHORT).show();
85 | }
86 |
87 | @Override
88 | public void TillDate(int day, int month, int year) {
89 | Toast.makeText(MainActivity.this, ""+day+" "+month+" "+year, Toast.LENGTH_SHORT).show();
90 |
91 | }
92 |
93 | @Override
94 | public void cansel() {
95 |
96 | }
97 | });
98 | persianDateRangePicker.show(fragmentManager, "PersianDateRangePicker");
99 | ```
100 |
101 |
102 |
103 | **Date Picker:**
104 |
105 | ```java
106 | Typeface face = Typeface.createFromAsset(getAssets(), "bsans.ttf");
107 | FragmentManager fragmentManager = getSupportFragmentManager();
108 | PersianDatePicker persianDateRangePicker = new PersianDatePicker()
109 | .setInitFromDate(InitDate.inputPersianDate(1, 1, 1397))
110 | .setBackgroundColor(getResources().getColor(R.color.green))
111 | .setButtonTextColor(getResources().getColor(R.color.white))
112 | .setTabTextColor(getResources().getColor(R.color.white))
113 | .setTabSelectedTextColor(getResources().getColor(R.color.white))
114 | .setTabIndicatorColor(getResources().getColor(R.color.white))
115 | .setWheelTextColor(getResources().getColor(R.color.white_smoke))
116 | .setWheelTextColorSelected(getResources().getColor(R.color.white))
117 | .setWheelTextSize(20)
118 | .setCornerRadius(40)
119 | .setTypeface(face)
120 | .setDoneText("تائید")
121 | .setCanselText("انصراف")
122 | .setDoneDrawable(getResources().getDrawable(R.drawable.ic_tick))
123 | .setCanselDeawable(getResources().getDrawable(R.drawable.ic_mult))
124 | .setListener(new PersianDatePicker.PickDate() {
125 | @Override
126 | public void Date(int day, int month, int year) {
127 | Toast.makeText(MainActivity.this, ""+day+" "+month+" "+year, Toast.LENGTH_SHORT).show();
128 | }
129 |
130 | @Override
131 | public void Cansel() {
132 |
133 | }
134 | });
135 | persianDateRangePicker.show(fragmentManager,"PersianDateRangePicker");
136 | ```
137 |
138 |
139 |
140 |
141 | # Developed By
142 |
143 | Farshad Asgharzadeh
144 |
145 | For contact, shoot me an email at ferik800@gmail.com
146 |
--------------------------------------------------------------------------------
/app/src/main/java/com/shaygan/datepicker/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.shaygan.datepicker;
2 |
3 | import android.graphics.Typeface;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.Toast;
10 | import com.waspar.persiandatepicker.PersianDatePicker;
11 | import com.waspar.persiandatepicker.PersianDateRangePicker;
12 | import com.waspar.persiandatepicker.SetCurrentItem;
13 | import com.waspar.persiandatepicker.util.InitDate;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | Button datePicker = findViewById(R.id.datePicker);
23 | Button dateRangePicker = findViewById(R.id.dateRangePicker);
24 |
25 | datePicker.setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View v) {
28 | datePicker();
29 | }
30 | });
31 |
32 | dateRangePicker.setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View v) {
35 | dateRangePicker();
36 | }
37 | });
38 | }
39 |
40 | private void dateRangePicker() {
41 |
42 | Typeface face = Typeface.createFromAsset(getAssets(), "bsans.ttf");
43 | FragmentManager fragmentManager = getSupportFragmentManager();
44 | PersianDateRangePicker persianDateRangePicker = new PersianDateRangePicker()
45 | .setInitTillDate(InitDate.inputPersianDate(1, 3, 1397))
46 | .setInitFromDate(InitDate.inputPersianDate(1, 1, 1397))
47 | .setBackgroundColor(getResources().getColor(R.color.green))
48 | .setButtonTextColor(getResources().getColor(R.color.white))
49 | .setTabTextColor(getResources().getColor(R.color.white))
50 | .setTabSelectedTextColor(getResources().getColor(R.color.white))
51 | .setTabIndicatorColor(getResources().getColor(R.color.white))
52 | .setWheelTextColor(getResources().getColor(R.color.white_smoke))
53 | .setWheelTextColorSelected(getResources().getColor(R.color.white))
54 | .setWheelTextSize(20)
55 | .setCornerRadius(40)
56 | .setTypeface(face)
57 | .setDoneText("تائید")
58 | .setCanselText("انصراف")
59 | .setDoneDrawable(getResources().getDrawable(R.drawable.ic_tick))
60 | .setCanselDeawable(getResources().getDrawable(R.drawable.ic_mult))
61 | .setCurrentItem(SetCurrentItem.From)
62 | .setListener(new PersianDateRangePicker.RangeDate() {
63 | @Override
64 | public void From(int day, int month, int year) {
65 | Toast.makeText(MainActivity.this, ""+day+" "+month+" "+year, Toast.LENGTH_SHORT).show();
66 | }
67 |
68 | @Override
69 | public void TillDate(int day, int month, int year) {
70 | Toast.makeText(MainActivity.this, ""+day+" "+month+" "+year, Toast.LENGTH_SHORT).show();
71 |
72 | }
73 |
74 | @Override
75 | public void cansel() {
76 |
77 | }
78 | });
79 | persianDateRangePicker.show(fragmentManager, "PersianDateRangePicker");
80 |
81 | }
82 |
83 | private void datePicker() {
84 |
85 | Typeface face = Typeface.createFromAsset(getAssets(), "bsans.ttf");
86 | FragmentManager fragmentManager = getSupportFragmentManager();
87 | PersianDatePicker persianDateRangePicker = new PersianDatePicker()
88 | .setInitFromDate(InitDate.inputPersianDate(1, 1, 1397))
89 | .setBackgroundColor(getResources().getColor(R.color.green))
90 | .setButtonTextColor(getResources().getColor(R.color.white))
91 | .setTabTextColor(getResources().getColor(R.color.white))
92 | .setTabSelectedTextColor(getResources().getColor(R.color.white))
93 | .setTabIndicatorColor(getResources().getColor(R.color.white))
94 | .setWheelTextColor(getResources().getColor(R.color.white_smoke))
95 | .setWheelTextColorSelected(getResources().getColor(R.color.white))
96 | .setWheelTextSize(20)
97 | .setCornerRadius(40)
98 | .setTypeface(face)
99 | .setDoneText("تائید")
100 | .setCanselText("انصراف")
101 | .setDoneDrawable(getResources().getDrawable(R.drawable.ic_tick))
102 | .setCanselDeawable(getResources().getDrawable(R.drawable.ic_mult))
103 | .setListener(new PersianDatePicker.PickDate() {
104 | @Override
105 | public void Date(int day, int month, int year) {
106 | Toast.makeText(MainActivity.this, ""+day+" "+month+" "+year, Toast.LENGTH_SHORT).show();
107 | }
108 |
109 | @Override
110 | public void Cansel() {
111 |
112 | }
113 | });
114 | persianDateRangePicker.show(fragmentManager,"PersianDateRangePicker");
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/layout/layout_persian_date_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
23 |
24 |
29 |
30 |
31 |
32 |
37 |
38 |
39 |
40 |
41 |
50 |
51 |
55 |
56 |
57 |
64 |
65 |
71 |
72 |
77 |
78 |
87 |
88 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
106 |
107 |
112 |
113 |
122 |
123 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/fragment/DateFragment.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.waspar.persiandatepicker.R;
10 | import com.waspar.persiandatepicker.util.ShamsiDate;
11 | import com.waspar.persiandatepicker.wheel.WheelPickerView;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import static com.waspar.persiandatepicker.PersianDatePicker.WheelTextColor;
17 | import static com.waspar.persiandatepicker.PersianDatePicker.WheelTextColorSelected;
18 | import static com.waspar.persiandatepicker.PersianDatePicker.WheelTextSize;
19 | import static com.waspar.persiandatepicker.PersianDatePicker.day;
20 | import static com.waspar.persiandatepicker.PersianDatePicker.month;
21 | import static com.waspar.persiandatepicker.PersianDatePicker.year;
22 |
23 | public class DateFragment extends Fragment {
24 |
25 | private WheelPickerView Day_WheelPicker, Month_WheelPicker, Year_WheelPicker;
26 | ShamsiDate shamsiDate = new ShamsiDate();
27 |
28 | public static DateFragment newInstance() {
29 | DateFragment fragment = new DateFragment();
30 | return fragment;
31 | }
32 |
33 | @Override
34 | public void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | }
37 |
38 | @Override
39 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
40 | Bundle savedInstanceState) {
41 | View view = inflater.inflate(R.layout.fragment_date_picker, container, false);
42 | init(view);
43 | setupWheelPickerDay(day);
44 | setupWheelPickerMonth(month);
45 | setupWheelPickerYear(year);
46 | setSizeAndColor();
47 | return view;
48 | }
49 |
50 | private void setSizeAndColor() {
51 |
52 |
53 | if (WheelTextColor != -1) {
54 | Day_WheelPicker.settextColor(WheelTextColor);
55 | Month_WheelPicker.settextColor(WheelTextColor);
56 | Year_WheelPicker.settextColor(WheelTextColor);
57 | }
58 |
59 | if (WheelTextColorSelected != -1) {
60 | Day_WheelPicker.setTextColorSelected(WheelTextColorSelected);
61 | Month_WheelPicker.setTextColorSelected(WheelTextColorSelected);
62 | Year_WheelPicker.setTextColorSelected(WheelTextColorSelected);
63 | }
64 |
65 | if (WheelTextSize != -1) {
66 | Day_WheelPicker.setTextSize(WheelTextSize*3);
67 | Month_WheelPicker.setTextSize(WheelTextSize*3);
68 | Year_WheelPicker.setTextSize(WheelTextSize*3);
69 | }
70 | }
71 |
72 |
73 | private void setupWheelPickerDay(final String days) {
74 | final List strings = new ArrayList<>();
75 | int dayy = Integer.parseInt(days);
76 | int ii = 0;
77 | int monthSize = 0;
78 | if (month.equals("1")||month.equals("2")||month.equals("3")||month.equals("4")||month.equals("5")||month.equals("6")){
79 | monthSize = 31;
80 | }else if (month.equals("7")||month.equals("8")||month.equals("9")||month.equals("10")||month.equals("11")){
81 | monthSize = 30;
82 | }else {
83 | monthSize = 29;
84 | }
85 | for (int i = 1; i <= monthSize; i++) {
86 | strings.add("" + i);
87 | if (i == dayy){
88 | ii = i-1;
89 | }
90 | }
91 | Day_WheelPicker.setPicker(strings);
92 | Day_WheelPicker.setCurrentItems(ii);
93 | Day_WheelPicker.setCyclic(true);
94 | Day_WheelPicker.setOnOptionChangedListener(new WheelPickerView.OnOptionChangedListener() {
95 | @Override
96 | public void onOptionChanged(WheelPickerView view, int option) {
97 | day = strings.get(option);
98 | }
99 | });
100 | }
101 |
102 | private void setupWheelPickerMonth(String months) {
103 | List strings = new ArrayList<>();
104 | strings.add("فروردین");
105 | strings.add("اردیبهشت");
106 | strings.add("خرداد");
107 | strings.add("تیر");
108 | strings.add("مرداد");
109 | strings.add("شهریور");
110 | strings.add("مهر");
111 | strings.add("آبان");
112 | strings.add("آذر");
113 | strings.add("دی");
114 | strings.add("بهمن");
115 | strings.add("اسفند");
116 | int ii = Integer.parseInt(months);
117 | ii = ii-1;
118 | Month_WheelPicker.setPicker(strings);
119 | Month_WheelPicker.setCurrentItems(ii);
120 | Month_WheelPicker.setCyclic(true);
121 | Month_WheelPicker.setOnOptionChangedListener(new WheelPickerView.OnOptionChangedListener() {
122 | @Override
123 | public void onOptionChanged(WheelPickerView view, int option) {
124 | month = String.valueOf(option+1);
125 | setupWheelPickerDay(day);
126 | }
127 | });
128 | }
129 |
130 | private void setupWheelPickerYear(String yearrr) {
131 | final List strings = new ArrayList<>();
132 | int yearr = Integer.parseInt(yearrr);
133 | int ii = 0;
134 | for (int i = (shamsiDate.getCurrentShamsiyear()-100); i <= shamsiDate.getCurrentShamsiyear(); i++) {
135 | strings.add("" + i);
136 | if (i == yearr){
137 | ii = i-(shamsiDate.getCurrentShamsiyear()-100);
138 | }
139 | }
140 | Year_WheelPicker.setPicker(strings);
141 | Year_WheelPicker.setCurrentItems(ii);
142 | Year_WheelPicker.setCyclic(true);
143 | Year_WheelPicker.setOnOptionChangedListener(new WheelPickerView.OnOptionChangedListener() {
144 | @Override
145 | public void onOptionChanged(WheelPickerView view, int option) {
146 | year = strings.get(option);
147 | }
148 | });
149 | }
150 |
151 | private void init(View view) {
152 | Day_WheelPicker = view.findViewById(R.id.wheelPickerDay);
153 | Month_WheelPicker = view.findViewById(R.id.wheelPickerMonth);
154 | Year_WheelPicker = view.findViewById(R.id.wheelPickerYear);
155 | }
156 |
157 | }
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/fragment/FromDateFragment.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.waspar.persiandatepicker.R;
10 | import com.waspar.persiandatepicker.util.ShamsiDate;
11 | import com.waspar.persiandatepicker.wheel.WheelPickerView;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import static com.waspar.persiandatepicker.PersianDateRangePicker.WheelTextColor;
17 | import static com.waspar.persiandatepicker.PersianDateRangePicker.WheelTextColorSelected;
18 | import static com.waspar.persiandatepicker.PersianDateRangePicker.WheelTextSize;
19 | import static com.waspar.persiandatepicker.PersianDateRangePicker.day;
20 | import static com.waspar.persiandatepicker.PersianDateRangePicker.month;
21 | import static com.waspar.persiandatepicker.PersianDateRangePicker.year;
22 |
23 | public class FromDateFragment extends Fragment {
24 |
25 | private WheelPickerView Day_WheelPicker, Month_WheelPicker, Year_WheelPicker;
26 | ShamsiDate shamsiDate = new ShamsiDate();
27 |
28 | public static FromDateFragment newInstance() {
29 | FromDateFragment fragment = new FromDateFragment();
30 | return fragment;
31 | }
32 |
33 | @Override
34 | public void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | }
37 |
38 | @Override
39 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
40 | Bundle savedInstanceState) {
41 | View view = inflater.inflate(R.layout.fragment_date_picker, container, false);
42 | init(view);
43 | setupWheelPickerDay(day);
44 | setupWheelPickerMonth(month);
45 | setupWheelPickerYear(year);
46 | setSizeAndColor();
47 | return view;
48 | }
49 |
50 | private void setSizeAndColor() {
51 |
52 |
53 | if (WheelTextColor != -1) {
54 | Day_WheelPicker.settextColor(WheelTextColor);
55 | Month_WheelPicker.settextColor(WheelTextColor);
56 | Year_WheelPicker.settextColor(WheelTextColor);
57 | }
58 |
59 | if (WheelTextColorSelected != -1) {
60 | Day_WheelPicker.setTextColorSelected(WheelTextColorSelected);
61 | Month_WheelPicker.setTextColorSelected(WheelTextColorSelected);
62 | Year_WheelPicker.setTextColorSelected(WheelTextColorSelected);
63 | }
64 |
65 | if (WheelTextSize != -1) {
66 | Day_WheelPicker.setTextSize(WheelTextSize*3);
67 | Month_WheelPicker.setTextSize(WheelTextSize*3);
68 | Year_WheelPicker.setTextSize(WheelTextSize*3);
69 | }
70 | }
71 |
72 |
73 | private void setupWheelPickerDay(final String days) {
74 | final List strings = new ArrayList<>();
75 | int dayy = Integer.parseInt(days);
76 | int ii = 0;
77 | int monthSize = 0;
78 | if (month.equals("1")||month.equals("2")||month.equals("3")||month.equals("4")||month.equals("5")||month.equals("6")){
79 | monthSize = 31;
80 | }else if (month.equals("7")||month.equals("8")||month.equals("9")||month.equals("10")||month.equals("11")){
81 | monthSize = 30;
82 | }else {
83 | monthSize = 29;
84 | }
85 | for (int i = 1; i <= monthSize; i++) {
86 | strings.add("" + i);
87 | if (i == dayy){
88 | ii = i-1;
89 | }
90 | }
91 | Day_WheelPicker.setPicker(strings);
92 | Day_WheelPicker.setCurrentItems(ii);
93 | Day_WheelPicker.setCyclic(true);
94 | Day_WheelPicker.setOnOptionChangedListener(new WheelPickerView.OnOptionChangedListener() {
95 | @Override
96 | public void onOptionChanged(WheelPickerView view, int option) {
97 | day = strings.get(option);
98 | }
99 | });
100 | }
101 |
102 | private void setupWheelPickerMonth(String months) {
103 | List strings = new ArrayList<>();
104 | strings.add("فروردین");
105 | strings.add("اردیبهشت");
106 | strings.add("خرداد");
107 | strings.add("تیر");
108 | strings.add("مرداد");
109 | strings.add("شهریور");
110 | strings.add("مهر");
111 | strings.add("آبان");
112 | strings.add("آذر");
113 | strings.add("دی");
114 | strings.add("بهمن");
115 | strings.add("اسفند");
116 | int ii = Integer.parseInt(months);
117 | ii = ii-1;
118 | Month_WheelPicker.setPicker(strings);
119 | Month_WheelPicker.setCurrentItems(ii);
120 | Month_WheelPicker.setCyclic(true);
121 | Month_WheelPicker.setOnOptionChangedListener(new WheelPickerView.OnOptionChangedListener() {
122 | @Override
123 | public void onOptionChanged(WheelPickerView view, int option) {
124 | month = String.valueOf(option+1);
125 | setupWheelPickerDay(day);
126 | }
127 | });
128 | }
129 |
130 | private void setupWheelPickerYear(String yearrr) {
131 | final List strings = new ArrayList<>();
132 | int yearr = Integer.parseInt(yearrr);
133 | int ii = 0;
134 | for (int i = (shamsiDate.getCurrentShamsiyear()-100); i <= shamsiDate.getCurrentShamsiyear(); i++) {
135 | strings.add("" + i);
136 | if (i == yearr){
137 | ii = i-(shamsiDate.getCurrentShamsiyear()-100);
138 | }
139 | }
140 | Year_WheelPicker.setPicker(strings);
141 | Year_WheelPicker.setCurrentItems(ii);
142 | Year_WheelPicker.setCyclic(true);
143 | Year_WheelPicker.setOnOptionChangedListener(new WheelPickerView.OnOptionChangedListener() {
144 | @Override
145 | public void onOptionChanged(WheelPickerView view, int option) {
146 | year = strings.get(option);
147 | }
148 | });
149 | }
150 |
151 | private void init(View view) {
152 | Day_WheelPicker = view.findViewById(R.id.wheelPickerDay);
153 | Month_WheelPicker = view.findViewById(R.id.wheelPickerMonth);
154 | Year_WheelPicker = view.findViewById(R.id.wheelPickerYear);
155 | }
156 |
157 | }
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/fragment/TillDateFragment.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.waspar.persiandatepicker.R;
10 | import com.waspar.persiandatepicker.util.ShamsiDate;
11 | import com.waspar.persiandatepicker.wheel.WheelPickerView;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import static com.waspar.persiandatepicker.PersianDateRangePicker.WheelTextColor;
17 | import static com.waspar.persiandatepicker.PersianDateRangePicker.WheelTextColorSelected;
18 | import static com.waspar.persiandatepicker.PersianDateRangePicker.WheelTextSize;
19 | import static com.waspar.persiandatepicker.PersianDateRangePicker.dayUntil;
20 | import static com.waspar.persiandatepicker.PersianDateRangePicker.monthUntil;
21 | import static com.waspar.persiandatepicker.PersianDateRangePicker.yearUntil;
22 |
23 | public class TillDateFragment extends Fragment {
24 |
25 | private WheelPickerView Day_WheelPicker, Month_WheelPicker, Year_WheelPicker;
26 | ShamsiDate shamsiDate = new ShamsiDate();
27 |
28 | public static TillDateFragment newInstance() {
29 | TillDateFragment fragment = new TillDateFragment();
30 | return fragment;
31 | }
32 |
33 | @Override
34 | public void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | }
37 |
38 | @Override
39 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
40 | Bundle savedInstanceState) {
41 | View view = inflater.inflate(R.layout.fragment_date_picker, container, false);
42 | init(view);
43 | setupWheelPickerDay(dayUntil);
44 | setupWheelPickerMonth(monthUntil);
45 | setupWheelPickerYear(yearUntil);
46 | setSizeAndColor();
47 | return view;
48 | }
49 |
50 | private void setSizeAndColor() {
51 |
52 |
53 | if (WheelTextColor != -1) {
54 | Day_WheelPicker.settextColor(WheelTextColor);
55 | Month_WheelPicker.settextColor(WheelTextColor);
56 | Year_WheelPicker.settextColor(WheelTextColor);
57 | }
58 |
59 | if (WheelTextColorSelected != -1) {
60 | Day_WheelPicker.setTextColorSelected(WheelTextColorSelected);
61 | Month_WheelPicker.setTextColorSelected(WheelTextColorSelected);
62 | Year_WheelPicker.setTextColorSelected(WheelTextColorSelected);
63 | }
64 |
65 | if (WheelTextSize != -1) {
66 | Day_WheelPicker.setTextSize(WheelTextSize*3);
67 | Month_WheelPicker.setTextSize(WheelTextSize*3);
68 | Year_WheelPicker.setTextSize(WheelTextSize*3);
69 | }
70 | }
71 |
72 | private void setupWheelPickerDay(String day) {
73 | final List strings = new ArrayList<>();
74 | int dayy = Integer.parseInt(day);
75 | int ii = 0;
76 | int monthSize = 0;
77 | if (monthUntil.equals("1")||monthUntil.equals("2")||monthUntil.equals("3")||monthUntil.equals("4")||monthUntil.equals("5")||monthUntil.equals("6")){
78 | monthSize = 31;
79 | }else if (monthUntil.equals("7")||monthUntil.equals("8")||monthUntil.equals("9")||monthUntil.equals("10")||monthUntil.equals("11")){
80 | monthSize = 30;
81 | }else {
82 | monthSize = 29;
83 | }
84 | for (int i = 1; i <= monthSize; i++) {
85 | strings.add("" + i);
86 | if (i == dayy){
87 | ii = i-1;
88 | }
89 | }
90 | Day_WheelPicker.setPicker(strings);
91 | Day_WheelPicker.setCurrentItems(ii);
92 | Day_WheelPicker.setCyclic(true);
93 | Day_WheelPicker.setOnOptionChangedListener(new WheelPickerView.OnOptionChangedListener() {
94 | @Override
95 | public void onOptionChanged(WheelPickerView view, int option) {
96 | dayUntil = strings.get(option);
97 | }
98 | });
99 | }
100 |
101 |
102 | private void setupWheelPickerMonth(String month) {
103 | List strings = new ArrayList<>();
104 | strings.add("فروردین");
105 | strings.add("اردیبهشت");
106 | strings.add("خرداد");
107 | strings.add("تیر");
108 | strings.add("مرداد");
109 | strings.add("شهریور");
110 | strings.add("مهر");
111 | strings.add("آبان");
112 | strings.add("آذر");
113 | strings.add("دی");
114 | strings.add("بهمن");
115 | strings.add("اسفند");
116 | int ii = Integer.parseInt(month);
117 | ii = ii-1;
118 | Month_WheelPicker.setPicker(strings);
119 | Month_WheelPicker.setCurrentItems(ii);
120 | Month_WheelPicker.setCyclic(true);
121 | Month_WheelPicker.setOnOptionChangedListener(new WheelPickerView.OnOptionChangedListener() {
122 | @Override
123 | public void onOptionChanged(WheelPickerView view, int option) {
124 | monthUntil = String.valueOf(option+1);
125 | setupWheelPickerDay(dayUntil);
126 | }
127 | });
128 | }
129 |
130 | private void setupWheelPickerYear(String year) {
131 | final List strings = new ArrayList<>();
132 | int yearr = Integer.parseInt(year);
133 | int ii = 0;
134 | for (int i = (shamsiDate.getCurrentShamsiyear()-100); i <= shamsiDate.getCurrentShamsiyear(); i++) {
135 | strings.add("" + i);
136 | if (i == yearr){
137 | ii = i-(shamsiDate.getCurrentShamsiyear()-100);
138 | }
139 | }
140 | Year_WheelPicker.setPicker(strings);
141 | Year_WheelPicker.setCurrentItems(ii);
142 | Year_WheelPicker.setCyclic(true);
143 | Year_WheelPicker.setOnOptionChangedListener(new WheelPickerView.OnOptionChangedListener() {
144 | @Override
145 | public void onOptionChanged(WheelPickerView view, int option) {
146 | yearUntil = strings.get(option);
147 | }
148 | });
149 | }
150 |
151 | private void init(View view) {
152 | Day_WheelPicker = view.findViewById(R.id.wheelPickerDay);
153 | Month_WheelPicker = view.findViewById(R.id.wheelPickerMonth);
154 | Year_WheelPicker = view.findViewById(R.id.wheelPickerYear);
155 | }
156 |
157 | }
--------------------------------------------------------------------------------
/datepickerpersian/src/main/res/layout/layout_persian_dare_range_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
73 |
74 |
79 |
80 |
85 |
86 |
87 |
88 |
93 |
94 |
95 |
96 |
97 |
106 |
107 |
111 |
112 |
113 |
120 |
121 |
127 |
128 |
133 |
134 |
143 |
144 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
162 |
163 |
168 |
169 |
178 |
179 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/util/ShamsiDate.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.util;
2 |
3 | import java.util.Date;
4 | import java.util.Locale;
5 |
6 | public class ShamsiDate {
7 |
8 | private class SolarCalendar {
9 |
10 | public String strWeekDay = "";
11 | public String strMonth = "";
12 |
13 | int date;
14 | int month;
15 | int year;
16 |
17 | public SolarCalendar()
18 | {
19 | Date MiladiDate = new Date();
20 | calcSolarCalendar(MiladiDate);
21 | }
22 |
23 | public SolarCalendar(Date MiladiDate)
24 | {
25 | calcSolarCalendar(MiladiDate);
26 | }
27 |
28 | private void calcSolarCalendar(Date MiladiDate) {
29 |
30 | int ld;
31 |
32 | int miladiYear = MiladiDate.getYear() + 1900;
33 | int miladiMonth = MiladiDate.getMonth() + 1;
34 | int miladiDate = MiladiDate.getDate();
35 | int WeekDay = MiladiDate.getDay();
36 |
37 | int[] buf1 = new int[12];
38 | int[] buf2 = new int[12];
39 |
40 | buf1[0] = 0;
41 | buf1[1] = 31;
42 | buf1[2] = 59;
43 | buf1[3] = 90;
44 | buf1[4] = 120;
45 | buf1[5] = 151;
46 | buf1[6] = 181;
47 | buf1[7] = 212;
48 | buf1[8] = 243;
49 | buf1[9] = 273;
50 | buf1[10] = 304;
51 | buf1[11] = 334;
52 |
53 | buf2[0] = 0;
54 | buf2[1] = 31;
55 | buf2[2] = 60;
56 | buf2[3] = 91;
57 | buf2[4] = 121;
58 | buf2[5] = 152;
59 | buf2[6] = 182;
60 | buf2[7] = 213;
61 | buf2[8] = 244;
62 | buf2[9] = 274;
63 | buf2[10] = 305;
64 | buf2[11] = 335;
65 |
66 | if ((miladiYear % 4) != 0) {
67 | date = buf1[miladiMonth - 1] + miladiDate;
68 |
69 | if (date > 79) {
70 | date = date - 79;
71 | if (date <= 186) {
72 | switch (date % 31) {
73 | case 0:
74 | month = date / 31;
75 | date = 31;
76 | break;
77 | default:
78 | month = (date / 31) + 1;
79 | date = (date % 31);
80 | break;
81 | }
82 | year = miladiYear - 621;
83 | } else {
84 | date = date - 186;
85 |
86 | switch (date % 30) {
87 | case 0:
88 | month = (date / 30) + 6;
89 | date = 30;
90 | break;
91 | default:
92 | month = (date / 30) + 7;
93 | date = (date % 30);
94 | break;
95 | }
96 | year = miladiYear - 621;
97 | }
98 | } else {
99 | if ((miladiYear > 1996) && (miladiYear % 4) == 1) {
100 | ld = 11;
101 | } else {
102 | ld = 10;
103 | }
104 | date = date + ld;
105 |
106 | switch (date % 30) {
107 | case 0:
108 | month = (date / 30) + 9;
109 | date = 30;
110 | break;
111 | default:
112 | month = (date / 30) + 10;
113 | date = (date % 30);
114 | break;
115 | }
116 | year = miladiYear - 622;
117 | }
118 | } else {
119 | date = buf2[miladiMonth - 1] + miladiDate;
120 |
121 | if (miladiYear >= 1996) {
122 | ld = 79;
123 | } else {
124 | ld = 80;
125 | }
126 | if (date > ld) {
127 | date = date - ld;
128 |
129 | if (date <= 186) {
130 | switch (date % 31) {
131 | case 0:
132 | month = (date / 31);
133 | date = 31;
134 | break;
135 | default:
136 | month = (date / 31) + 1;
137 | date = (date % 31);
138 | break;
139 | }
140 | year = miladiYear - 621;
141 | } else {
142 | date = date - 186;
143 |
144 | switch (date % 30) {
145 | case 0:
146 | month = (date / 30) + 6;
147 | date = 30;
148 | break;
149 | default:
150 | month = (date / 30) + 7;
151 | date = (date % 30);
152 | break;
153 | }
154 | year = miladiYear - 621;
155 | }
156 | }
157 |
158 | else {
159 | date = date + 10;
160 |
161 | switch (date % 30) {
162 | case 0:
163 | month = (date / 30) + 9;
164 | date = 30;
165 | break;
166 | default:
167 | month = (date / 30) + 10;
168 | date = (date % 30);
169 | break;
170 | }
171 | year = miladiYear - 622;
172 | }
173 |
174 | }
175 |
176 | switch (month) {
177 | case 1:
178 | strMonth = "فروردين";
179 | break;
180 | case 2:
181 | strMonth = "ارديبهشت";
182 | break;
183 | case 3:
184 | strMonth = "خرداد";
185 | break;
186 | case 4:
187 | strMonth = "تير";
188 | break;
189 | case 5:
190 | strMonth = "مرداد";
191 | break;
192 | case 6:
193 | strMonth = "شهريور";
194 | break;
195 | case 7:
196 | strMonth = "مهر";
197 | break;
198 | case 8:
199 | strMonth = "آبان";
200 | break;
201 | case 9:
202 | strMonth = "آذر";
203 | break;
204 | case 10:
205 | strMonth = "دي";
206 | break;
207 | case 11:
208 | strMonth = "بهمن";
209 | break;
210 | case 12:
211 | strMonth = "اسفند";
212 | break;
213 | }
214 |
215 | switch (WeekDay) {
216 |
217 | case 0:
218 | strWeekDay = "يکشنبه";
219 | break;
220 | case 1:
221 | strWeekDay = "دوشنبه";
222 | break;
223 | case 2:
224 | strWeekDay = "سه شنبه";
225 | break;
226 | case 3:
227 | strWeekDay = "چهارشنبه";
228 | break;
229 | case 4:
230 | strWeekDay = "پنج شنبه";
231 | break;
232 | case 5:
233 | strWeekDay = "جمعه";
234 | break;
235 | case 6:
236 | strWeekDay = "شنبه";
237 | break;
238 | }
239 |
240 | }
241 |
242 | }
243 |
244 | public String getCurrentShamsidate() {
245 | Locale loc = new Locale("en_US");
246 | ShamsiDate util = new ShamsiDate();
247 | SolarCalendar sc = util.new SolarCalendar();
248 | return String.valueOf(sc.year) + "/" + String.format(loc, "%02d",
249 | sc.month) + "/" + String.format(loc, "%02d", sc.date);
250 | }
251 | public int getCurrentShamsiday() {
252 | Locale loc = new Locale("en_US");
253 | ShamsiDate util = new ShamsiDate();
254 | SolarCalendar sc = util.new SolarCalendar();
255 | return Integer.parseInt(String.format(loc, "%02d", sc.date));
256 | }
257 | public int getCurrentShamsimonth() {
258 | Locale loc = new Locale("en_US");
259 | ShamsiDate util = new ShamsiDate();
260 | SolarCalendar sc = util.new SolarCalendar();
261 | return Integer.parseInt(String.format(loc, "%02d", sc.month));
262 | }
263 | public int getCurrentShamsiyear() {
264 | Locale loc = new Locale("en_US");
265 | ShamsiDate util = new ShamsiDate();
266 | SolarCalendar sc = util.new SolarCalendar();
267 | return Integer.parseInt(String.valueOf(sc.year));
268 | }
269 | public int getCurrentShamsiPickString() {
270 | Locale loc = new Locale("en_US");
271 | ShamsiDate util = new ShamsiDate();
272 | SolarCalendar sc = util.new SolarCalendar();
273 | return Integer.parseInt(String.valueOf(sc.year));
274 | }
275 |
276 | }
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/PersianDatePicker.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.graphics.Color;
5 | import android.graphics.Typeface;
6 | import android.graphics.drawable.ColorDrawable;
7 | import android.graphics.drawable.Drawable;
8 | import android.graphics.drawable.GradientDrawable;
9 | import android.os.Bundle;
10 | import android.support.design.widget.TabLayout;
11 | import android.support.v4.app.DialogFragment;
12 | import android.support.v4.view.ViewPager;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.view.Window;
17 | import android.view.WindowManager;
18 | import android.widget.ImageView;
19 | import android.widget.TextView;
20 | import com.waspar.persiandatepicker.adapter.TabAdapterDatePicker;
21 | import com.waspar.persiandatepicker.util.ShamsiDate;
22 |
23 | @SuppressLint("ValidFragment")
24 | public class PersianDatePicker extends DialogFragment implements View.OnClickListener {
25 |
26 | private TabLayout tabLayout;
27 | private ViewPager viewPager;
28 | private TabAdapterDatePicker adapter;
29 | private View Cansel, Ok;
30 | private TextView DoneTxt, CanselTxt;
31 | private String DoneText , CanselText;
32 | private ShamsiDate shamsiDate = new ShamsiDate();
33 | private ImageView DoneImg , CanselImg;
34 |
35 | private int backgroundColor = -1;
36 | private int ButtonTextColor = -1;
37 | private int TabTextColor = -1;
38 | private int TabSelectedTextColor = -1;
39 | private int TabIndicatorColor = -1;
40 |
41 | public static int WheelTextColor = -1;
42 | public static int WheelTextColorSelected = -1;
43 | public static int WheelTextSize = -1;
44 | public int CornerRadius = 20;
45 |
46 | private Drawable DoneDrawable;
47 | private Drawable CanselDeawable;
48 |
49 | public static Typeface typeface;
50 |
51 | public static String day;
52 | public static String month;
53 | public static String year;
54 |
55 | private PickDate rangeDate;
56 | private String InitFromDate;
57 | private View view, root;
58 |
59 | @Override
60 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
61 | view = inflater.inflate(R.layout.layout_persian_date_picker, container, false);
62 | getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
63 | getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
64 | init(view);
65 | setupTab();
66 | if (InitFromDate == null) {
67 | InitFromDate = shamsiDate.getCurrentShamsidate();
68 | }
69 | //
70 | // if (backgroundColor != -1) {
71 | // tabLayout.setBackgroundColor(backgroundColor);
72 | //
73 | // getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);
74 | //
75 | // GradientDrawable bgShape = new GradientDrawable();
76 | // bgShape.setCornerRadii(new float[]{80, 80, 80, 80, 80, 80, 80, 80});
77 | // bgShape.setCornerRadius(80);
78 | // bgShape.setColor(backgroundColor);
79 | // root.setBackground(bgShape);
80 | // tabLayout.setBackground(bgShape);
81 | // }
82 |
83 | if (ButtonTextColor != -1) {
84 | DoneTxt.setTextColor(ButtonTextColor);
85 | CanselTxt.setTextColor(ButtonTextColor);
86 | }
87 |
88 | if (typeface != null){
89 | DoneTxt.setTypeface(typeface);
90 | CanselTxt.setTypeface(typeface);
91 | }
92 |
93 | if (TabIndicatorColor != -1) {
94 | tabLayout.setSelectedTabIndicatorColor(TabIndicatorColor);
95 | }
96 |
97 | if (DoneText != null){
98 | DoneTxt.setText(DoneText);
99 | }
100 |
101 | if (CanselText != null){
102 | CanselTxt.setText(CanselText);
103 | }
104 |
105 | if (DoneDrawable != null){
106 | DoneImg.setImageDrawable(DoneDrawable);
107 | }
108 |
109 | if (CanselDeawable != null){
110 | CanselImg.setImageDrawable(CanselDeawable);
111 | }
112 |
113 | String[] from = InitFromDate.split("/");
114 | day = from[2];
115 | month = from[1];
116 | year = from[0];
117 |
118 | return view;
119 | }
120 |
121 | private void init(View view) {
122 | viewPager = view.findViewById(R.id.viewPager);
123 | tabLayout = view.findViewById(R.id.tab_layout);
124 | Cansel = view.findViewById(R.id.cansel);
125 | DoneImg = view.findViewById(R.id.img_tick);
126 | CanselImg = view.findViewById(R.id.img_mult);
127 | root = view.findViewById(R.id.root);
128 | DoneTxt = view.findViewById(R.id.layout_persian_dare_range_picker_done_txt);
129 | CanselTxt = view.findViewById(R.id.layout_persian_dare_range_picker_cansel_txt);
130 | Cansel.setOnClickListener(this);
131 | Ok = view.findViewById(R.id.ok);
132 | Ok.setOnClickListener(this);
133 | }
134 |
135 | @Override
136 | public void onResume() {
137 | super.onResume();
138 | ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
139 | params.width = WindowManager.LayoutParams.MATCH_PARENT - 1;
140 | params.height = WindowManager.LayoutParams.WRAP_CONTENT;
141 | getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
142 | GradientDrawable bgShape = new GradientDrawable();
143 | bgShape.setCornerRadius(CornerRadius);
144 | if (backgroundColor != -1) {
145 | bgShape.setColor(backgroundColor);
146 | } else {
147 | bgShape.setColor(getActivity().getResources().getColor(R.color.white));
148 | }
149 | root.setBackground(bgShape);
150 |
151 | GradientDrawable bgShape2 = new GradientDrawable();
152 | bgShape2.setCornerRadius(CornerRadius);
153 | if (backgroundColor != -1) {
154 | bgShape2.setColor(backgroundColor);
155 | } else {
156 | bgShape2.setColor(getActivity().getResources().getColor(R.color.white));
157 | }
158 | tabLayout.setBackground(bgShape2);
159 | }
160 |
161 | @Override
162 | public void onClick(View v) {
163 | int i = v.getId();
164 | if (i == R.id.cansel) {
165 | canselButton();
166 | } else if (i == R.id.ok) {
167 | okButton();
168 | }
169 | }
170 |
171 | private void canselButton() {
172 | rangeDate.Cansel();
173 | dismiss();
174 | }
175 |
176 | private void okButton() {
177 | rangeDate.Date(Integer.parseInt(day), Integer.parseInt(month), Integer.parseInt(year));
178 | dismiss();
179 | }
180 |
181 | private void setupTab() {
182 | adapter = new TabAdapterDatePicker(getChildFragmentManager(), tabLayout.getTabCount());
183 | viewPager.setAdapter(adapter);
184 | viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
185 | viewPager.setCurrentItem(1);
186 | tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
187 | @Override
188 | public void onTabSelected(TabLayout.Tab tab) {
189 | switch (tab.getPosition()) {
190 | case 0:
191 | viewPager.setCurrentItem(0);
192 | break;
193 | case 1:
194 | viewPager.setCurrentItem(1);
195 | break;
196 | }
197 | }
198 |
199 | @Override
200 | public void onTabUnselected(TabLayout.Tab tab) {
201 |
202 | }
203 |
204 | @Override
205 | public void onTabReselected(TabLayout.Tab tab) {
206 |
207 | }
208 | });
209 | tabLayout.setTabTextColors(TabTextColor , TabSelectedTextColor);
210 | }
211 |
212 | public interface PickDate {
213 | void Date(int day, int month, int year);
214 | void Cansel();
215 | }
216 |
217 | public PersianDatePicker setInitFromDate(String InitFromDate) {
218 | this.InitFromDate = InitFromDate;
219 | return this;
220 | }
221 |
222 | public PersianDatePicker setBackgroundColor(int backgroundColor) {
223 | this.backgroundColor = backgroundColor;
224 | return this;
225 | }
226 |
227 | public PersianDatePicker setButtonTextColor(int ButtonTextColor) {
228 | this.ButtonTextColor = ButtonTextColor;
229 | return this;
230 | }
231 |
232 | public PersianDatePicker setTabTextColor(int TabTextColor) {
233 | this.TabTextColor = TabTextColor;
234 | return this;
235 | }
236 |
237 | public PersianDatePicker setTabSelectedTextColor(int TabSelectedTextColor) {
238 | this.TabSelectedTextColor = TabSelectedTextColor;
239 | return this;
240 | }
241 |
242 | public PersianDatePicker setTabIndicatorColor(int TabIndicatorColor) {
243 | this.TabIndicatorColor = TabIndicatorColor;
244 | return this;
245 | }
246 |
247 | public PersianDatePicker setWheelTextColor(int WheelTextColor) {
248 | this.WheelTextColor = WheelTextColor;
249 | return this;
250 | }
251 |
252 | public PersianDatePicker setWheelTextColorSelected(int WheelTextColorSelected) {
253 | this.WheelTextColorSelected = WheelTextColorSelected;
254 | return this;
255 | }
256 |
257 | public PersianDatePicker setWheelTextSize(int WheelTextSize) {
258 | this.WheelTextSize = WheelTextSize;
259 | return this;
260 | }
261 |
262 | public PersianDatePicker setTypeface(Typeface typeface) {
263 | this.typeface = typeface;
264 | return this;
265 | }
266 |
267 | public PersianDatePicker setDoneText(String DoneText) {
268 | this.DoneText = DoneText;
269 | return this;
270 | }
271 |
272 | public PersianDatePicker setCanselText(String CanselText) {
273 | this.CanselText = CanselText;
274 | return this;
275 | }
276 |
277 | public PersianDatePicker setDoneDrawable(Drawable DoneDrawable) {
278 | this.DoneDrawable = DoneDrawable;
279 | return this;
280 | }
281 |
282 | public PersianDatePicker setCanselDeawable(Drawable CanselDeawable) {
283 | this.CanselDeawable = CanselDeawable;
284 | return this;
285 | }
286 |
287 | public PersianDatePicker setListener(PickDate pickDate) {
288 | this.rangeDate = pickDate;
289 | return this;
290 | }
291 |
292 | public PersianDatePicker setCornerRadius(int CornerRadius) {
293 | this.CornerRadius = CornerRadius;
294 | return this;
295 | }
296 |
297 | }
298 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/PersianDateRangePicker.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.graphics.Color;
5 | import android.graphics.Typeface;
6 | import android.graphics.drawable.ColorDrawable;
7 | import android.graphics.drawable.Drawable;
8 | import android.graphics.drawable.GradientDrawable;
9 | import android.support.design.widget.TabLayout;
10 | import android.support.v4.app.DialogFragment;
11 | import android.os.Bundle;
12 | import android.support.v4.content.ContextCompat;
13 | import android.support.v4.view.ViewPager;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.view.Window;
18 | import android.view.WindowManager;
19 | import android.widget.ImageView;
20 | import android.widget.TextView;
21 |
22 | import com.waspar.persiandatepicker.adapter.TabAdapterDateRangePicker;
23 | import com.waspar.persiandatepicker.util.ShamsiDate;
24 |
25 | @SuppressLint("ValidFragment")
26 | public class PersianDateRangePicker extends DialogFragment implements View.OnClickListener {
27 |
28 | private TabLayout tabLayout;
29 | private ViewPager viewPager;
30 | private TabAdapterDateRangePicker adapter;
31 | private View Cansel, Ok;
32 | private TextView DoneTxt, CanselTxt;
33 | private String DoneText, CanselText;
34 | private ShamsiDate shamsiDate = new ShamsiDate();
35 | private ImageView DoneImg, CanselImg;
36 | //private TextView dateFromTv , dateToTv;
37 |
38 | private int backgroundColor = -1;
39 | private int ButtonTextColor = -1;
40 | private int TabTextColor = -1;
41 | private int TabSelectedTextColor = -1;
42 | private int TabIndicatorColor = -1;
43 |
44 | public static int WheelTextColor = -1;
45 | public static int WheelTextColorSelected = -1;
46 | public static int WheelTextSize = -1;
47 | public int SetCurrentItem = 1;
48 | public int CornerRadius = 20;
49 |
50 | private Drawable DoneDrawable;
51 | private Drawable CanselDeawable;
52 |
53 | public static Typeface typeface;
54 |
55 | public static String day;
56 | public static String month;
57 | public static String year;
58 | public static String dayUntil;
59 | public static String monthUntil;
60 | public static String yearUntil;
61 |
62 | private RangeDate rangeDate;
63 | private String InitFromDate;
64 | private String InitTillDate;
65 | private View view, root, root2;
66 |
67 | @Override
68 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
69 | view = inflater.inflate(R.layout.layout_persian_dare_range_picker, container, false);
70 | getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
71 | getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
72 | init();
73 | setupTab();
74 | if (InitFromDate == null) {
75 | InitFromDate = shamsiDate.getCurrentShamsidate();
76 | }
77 | if (InitTillDate == null) {
78 | InitTillDate = shamsiDate.getCurrentShamsidate();
79 | }
80 |
81 | if (ButtonTextColor != -1) {
82 | DoneTxt.setTextColor(ButtonTextColor);
83 | CanselTxt.setTextColor(ButtonTextColor);
84 | }
85 |
86 | if (typeface != null) {
87 | DoneTxt.setTypeface(typeface);
88 | CanselTxt.setTypeface(typeface);
89 | // dateToTv.setTypeface(typeface);
90 | // dateFromTv.setTypeface(typeface);
91 | }
92 |
93 | if (TabIndicatorColor != -1) {
94 | tabLayout.setSelectedTabIndicatorColor(TabIndicatorColor);
95 | }
96 |
97 | if (DoneText != null) {
98 | DoneTxt.setText(DoneText);
99 | }
100 |
101 | if (CanselText != null) {
102 | CanselTxt.setText(CanselText);
103 | }
104 |
105 | if (DoneDrawable != null) {
106 | DoneImg.setImageDrawable(DoneDrawable);
107 | }
108 |
109 | if (CanselDeawable != null) {
110 | CanselImg.setImageDrawable(CanselDeawable);
111 | }
112 |
113 | String[] from = InitFromDate.split("/");
114 | String[] till = InitTillDate.split("/");
115 | day = from[2];
116 | month = from[1];
117 | year = from[0];
118 | dayUntil = till[2];
119 | monthUntil = till[1];
120 | yearUntil = till[0];
121 |
122 | return view;
123 | }
124 |
125 | private void init() {
126 | viewPager = view.findViewById(R.id.viewPager);
127 | tabLayout = view.findViewById(R.id.tab_layout);
128 | // dateFromTv = view.findViewById(R.id.textView);
129 | // dateToTv = view.findViewById(R.id.textView2);
130 | DoneImg = view.findViewById(R.id.img_tick);
131 | CanselImg = view.findViewById(R.id.img_mult);
132 | Cansel = view.findViewById(R.id.cansel);
133 | root = view.findViewById(R.id.root);
134 | root2 = view.findViewById(R.id.root2);
135 | DoneTxt = view.findViewById(R.id.layout_persian_dare_range_picker_done_txt);
136 | CanselTxt = view.findViewById(R.id.layout_persian_dare_range_picker_cansel_txt);
137 | Cansel.setOnClickListener(this);
138 | Ok = view.findViewById(R.id.ok);
139 | Ok.setOnClickListener(this);
140 | // dateFromTv.setOnClickListener(this);
141 | // dateToTv.setOnClickListener(this);
142 | }
143 |
144 | @Override
145 | public void onResume() {
146 | super.onResume();
147 | ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
148 | params.width = WindowManager.LayoutParams.MATCH_PARENT - 1;
149 | params.height = WindowManager.LayoutParams.WRAP_CONTENT;
150 | getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
151 | GradientDrawable bgShape = new GradientDrawable();
152 | bgShape.setCornerRadius(CornerRadius);
153 | if (backgroundColor != -1) {
154 | bgShape.setColor(backgroundColor);
155 | } else {
156 | bgShape.setColor(getActivity().getResources().getColor(R.color.white));
157 | }
158 | root.setBackground(bgShape);
159 | root2.setBackground(bgShape);
160 |
161 | GradientDrawable bgShape2 = new GradientDrawable();
162 | bgShape2.setCornerRadius(CornerRadius);
163 | if (backgroundColor != -1) {
164 | bgShape2.setColor(backgroundColor);
165 | } else {
166 | bgShape2.setColor(getActivity().getResources().getColor(R.color.white));
167 | }
168 | tabLayout.setBackground(bgShape2);
169 |
170 | }
171 |
172 | @Override
173 | public void onClick(View v) {
174 | int i = v.getId();
175 | if (i == R.id.cansel) {
176 | canselButton();
177 | } else if (i == R.id.ok) {
178 | okButton();
179 | }
180 | }
181 |
182 | private void canselButton() {
183 | rangeDate.cansel();
184 | dismiss();
185 | }
186 |
187 | private void okButton() {
188 | rangeDate.From(Integer.parseInt(day), Integer.parseInt(month), Integer.parseInt(year));
189 | rangeDate.TillDate(Integer.parseInt(dayUntil), Integer.parseInt(monthUntil), Integer.parseInt(yearUntil));
190 | dismiss();
191 | }
192 |
193 | private void setupTab() {
194 | adapter = new TabAdapterDateRangePicker(getChildFragmentManager(), 2);
195 | viewPager.setAdapter(adapter);
196 | viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
197 | viewPager.setCurrentItem(SetCurrentItem);
198 | if (SetCurrentItem == 1){
199 | viewPager.setCurrentItem(SetCurrentItem);
200 | }else {
201 | viewPager.setCurrentItem(SetCurrentItem);
202 | }
203 | viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
204 | @Override
205 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
206 |
207 | }
208 |
209 | @Override
210 | public void onPageSelected(int position) {
211 | if (position == 0) {
212 | viewPager.setCurrentItem(0);
213 | } else if (position == 1) {
214 | viewPager.setCurrentItem(1);
215 | }
216 | }
217 |
218 | @Override
219 | public void onPageScrollStateChanged(int state) {
220 |
221 | }
222 | });
223 | tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
224 | @Override
225 | public void onTabSelected(TabLayout.Tab tab) {
226 | switch (tab.getPosition()) {
227 | case 0:
228 | viewPager.setCurrentItem(0);
229 | break;
230 | case 1:
231 | viewPager.setCurrentItem(1);
232 | break;
233 | }
234 | }
235 |
236 | @Override
237 | public void onTabUnselected(TabLayout.Tab tab) {
238 |
239 | }
240 |
241 | @Override
242 | public void onTabReselected(TabLayout.Tab tab) {
243 |
244 | }
245 | });
246 | tabLayout.setTabTextColors(TabTextColor , TabSelectedTextColor);
247 | }
248 |
249 | public interface RangeDate {
250 | void From(int day, int month, int year);
251 |
252 | void TillDate(int day, int month, int year);
253 |
254 | void cansel();
255 | }
256 |
257 | public PersianDateRangePicker setInitFromDate(String InitFromDate) {
258 | this.InitFromDate = InitFromDate;
259 | return this;
260 | }
261 |
262 | public PersianDateRangePicker setInitTillDate(String InitTillDate) {
263 | this.InitTillDate = InitTillDate;
264 | return this;
265 | }
266 |
267 | public PersianDateRangePicker setBackgroundColor(int backgroundColor) {
268 | this.backgroundColor = backgroundColor;
269 | return this;
270 | }
271 |
272 | public PersianDateRangePicker setButtonTextColor(int ButtonTextColor) {
273 | this.ButtonTextColor = ButtonTextColor;
274 | return this;
275 | }
276 |
277 | public PersianDateRangePicker setTabTextColor(int TabTextColor) {
278 | this.TabTextColor = TabTextColor;
279 | return this;
280 | }
281 |
282 | public PersianDateRangePicker setTabSelectedTextColor(int TabSelectedTextColor) {
283 | this.TabSelectedTextColor = TabSelectedTextColor;
284 | return this;
285 | }
286 |
287 | public PersianDateRangePicker setTabIndicatorColor(int TabIndicatorColor) {
288 | this.TabIndicatorColor = TabIndicatorColor;
289 | return this;
290 | }
291 |
292 | public PersianDateRangePicker setWheelTextColor(int WheelTextColor) {
293 | this.WheelTextColor = WheelTextColor;
294 | return this;
295 | }
296 |
297 | public PersianDateRangePicker setWheelTextColorSelected(int WheelTextColorSelected) {
298 | this.WheelTextColorSelected = WheelTextColorSelected;
299 | return this;
300 | }
301 |
302 | public PersianDateRangePicker setWheelTextSize(int WheelTextSize) {
303 | this.WheelTextSize = WheelTextSize;
304 | return this;
305 | }
306 |
307 | public PersianDateRangePicker setTypeface(Typeface typeface) {
308 | this.typeface = typeface;
309 | return this;
310 | }
311 |
312 | public PersianDateRangePicker setDoneText(String DoneText) {
313 | this.DoneText = DoneText;
314 | return this;
315 | }
316 |
317 | public PersianDateRangePicker setCanselText(String CanselText) {
318 | this.CanselText = CanselText;
319 | return this;
320 | }
321 |
322 | public PersianDateRangePicker setDoneDrawable(Drawable DoneDrawable) {
323 | this.DoneDrawable = DoneDrawable;
324 | return this;
325 | }
326 |
327 | public PersianDateRangePicker setCanselDeawable(Drawable CanselDeawable) {
328 | this.CanselDeawable = CanselDeawable;
329 | return this;
330 | }
331 |
332 | public PersianDateRangePicker setCurrentItem(int SetCurrentItem) {
333 | this.SetCurrentItem = SetCurrentItem;
334 | return this;
335 | }
336 |
337 | public PersianDateRangePicker setListener(RangeDate rangeDate) {
338 | this.rangeDate = rangeDate;
339 | return this;
340 | }
341 |
342 | public PersianDateRangePicker setCornerRadius(int CornerRadius) {
343 | this.CornerRadius = CornerRadius;
344 | return this;
345 | }
346 |
347 | }
348 |
--------------------------------------------------------------------------------
/datepickerpersian/src/main/java/com/waspar/persiandatepicker/wheel/LoopView.java:
--------------------------------------------------------------------------------
1 | package com.waspar.persiandatepicker.wheel;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Rect;
7 | import android.graphics.Typeface;
8 | import android.os.Handler;
9 | import android.util.AttributeSet;
10 | import android.view.GestureDetector;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 |
14 | import com.waspar.persiandatepicker.PersianDatePicker;
15 | import com.waspar.persiandatepicker.PersianDateRangePicker;
16 | import com.waspar.persiandatepicker.fragment.DateFragment;
17 |
18 | import java.util.List;
19 | import java.util.Timer;
20 |
21 |
22 | /**
23 | * LoopView
24 | *
25 | * @author DaoLQ
26 | */
27 | public class LoopView extends View {
28 | Timer timer;
29 | int totalScrollY;
30 | Handler handler;
31 | LoopRunnable.LoopListener loopListener;
32 | private GestureDetector gestureDetector;
33 | private GestureDetector.SimpleOnGestureListener simpleOnGestureListener;
34 | private Context context;
35 | private Paint paintA;
36 | private Paint paintB;
37 | private Paint paintC;
38 | List arrayList;
39 | private int textSize;
40 | private int g;
41 | int h;
42 | private int colorGray;
43 | private int colorBlack;
44 | private int colorGrayLight;
45 | float l;
46 | boolean isLoop;
47 | private int n;
48 | private int o;
49 | private int mCurrentItem;
50 | int position;
51 | private int r;
52 | private int s;
53 | private int t;
54 | private int u;
55 | private float x;
56 | private float y;
57 | private float z;
58 | private Rect mRectBound = new Rect();
59 |
60 | public LoopView(Context context) {
61 | super(context);
62 | initLoopView(context);
63 | }
64 |
65 | public LoopView(Context context, AttributeSet attributeset) {
66 | super(context, attributeset);
67 | initLoopView(context);
68 | }
69 |
70 | public LoopView(Context context, AttributeSet attributeset, int i1) {
71 | super(context, attributeset, i1);
72 | initLoopView(context);
73 | }
74 |
75 | public void setTextSize(int textSize) {
76 | this.textSize = textSize;
77 | }
78 |
79 | public void setTextColor(int color) {
80 | this.colorGray = color;
81 | }
82 |
83 | public void setTextColorSelected(int color) {
84 | this.colorBlack = color;
85 | }
86 |
87 | private void initLoopView(Context context) {
88 | textSize = 0;
89 | colorGray = 0xffafafaf;
90 | colorBlack = 0xff313131;
91 | colorGrayLight = 0xffc5c5c5;
92 | l = 2.0F;
93 | isLoop = true;
94 | position = -1;
95 | r = 9;
96 | x = 0.0F;
97 | y = 0.0F;
98 | z = 0.0F;
99 | totalScrollY = 0;
100 | simpleOnGestureListener = new LoopViewGestureListener(this);
101 | handler = new MessageHandler(this);
102 | this.context = context;
103 | setTextSize(20F);
104 | }
105 |
106 | static int getSelectItem(LoopView loopview) {
107 | return loopview.getCurrentItem();
108 | }
109 |
110 | static void b(LoopView loopview) {
111 | loopview.f();
112 | }
113 |
114 | private void d() {
115 | if (arrayList == null) {
116 | return;
117 | }
118 | paintA = new Paint();
119 | paintA.setColor(colorGray);
120 | paintA.setAntiAlias(true);
121 | paintA.setTextSize(textSize);
122 | paintB = new Paint();
123 | paintB.setColor(colorBlack);
124 | paintB.setAntiAlias(true);
125 | paintB.setTextScaleX(1.05F);
126 | paintB.setTextSize(textSize);
127 | if (PersianDateRangePicker.typeface != null){
128 | paintA.setTypeface(PersianDateRangePicker.typeface);
129 | paintB.setTypeface(PersianDateRangePicker.typeface);
130 | // paintC.setTypeface(typeface);
131 | }
132 | if (PersianDatePicker.typeface != null){
133 | paintA.setTypeface(PersianDatePicker.typeface);
134 | paintB.setTypeface(PersianDatePicker.typeface);
135 | // paintC.setTypeface(typeface);
136 | }
137 | paintB.setTextSize(textSize);
138 | paintC = new Paint();
139 | paintC.setColor(colorGrayLight);
140 | paintC.setAntiAlias(true);
141 | paintC.setTextSize(textSize);
142 | if (android.os.Build.VERSION.SDK_INT >= 11) {
143 | setLayerType(1, null);
144 | }
145 | gestureDetector = new GestureDetector(context, simpleOnGestureListener);
146 | gestureDetector.setIsLongpressEnabled(false);
147 | e();
148 | t = (int) ((float) h * l * (float) (r - 1));
149 | s = (int) ((double) (t * 2) / Math.PI);
150 | u = (int) ((double) t / Math.PI);
151 | n = (int) (((float) s - l * (float) h) / 2.0F);
152 | o = (int) (((float) s + l * (float) h) / 2.0F);
153 | if (position == -1) {
154 | if (isLoop) {
155 | position = (arrayList.size() + 1) / 2;
156 | } else {
157 | position = 0;
158 | }
159 | }
160 | mCurrentItem = position;
161 | }
162 |
163 | private void e() {
164 | Rect rect = new Rect();
165 | for (int i1 = 0; i1 < arrayList.size(); i1++) {
166 | String s1 = (String) arrayList.get(i1);
167 | paintB.getTextBounds(s1, 0, s1.length(), rect);
168 | int j1 = rect.width();
169 | if (j1 > g) {
170 | g = j1;
171 | }
172 | paintB.getTextBounds("\u661F\u671F", 0, 2, rect);
173 | j1 = rect.height();
174 | if (j1 > h) {
175 | h = j1;
176 | }
177 | }
178 |
179 | }
180 |
181 | private void f() {
182 | int i1 = (int) ((float) totalScrollY % (l * (float) h));
183 | Timer timer = new Timer();
184 | this.timer = timer;
185 | timer.schedule(new TimerWheel(this, i1, timer), 0L, 10L);
186 | }
187 |
188 | public final void setNotLoop() {
189 | isLoop = false;
190 | }
191 |
192 | public final void setCyclic(boolean cyclic) {
193 | isLoop = cyclic;
194 | }
195 |
196 | private void setTextSize(float size) {
197 | if (size > 0.0F) {
198 | textSize = (int) (context.getResources().getDisplayMetrics().density * size);
199 | }
200 | }
201 |
202 | public final void setCurrentItem(int position) {
203 | this.position = position;
204 | totalScrollY = 0;
205 | f();
206 | invalidate();
207 | }
208 |
209 | public final void setListener(LoopRunnable.LoopListener loopListener) {
210 | this.loopListener = loopListener;
211 | }
212 |
213 | public final void setArrayList(List arraylist) {
214 | arrayList = arraylist;
215 | d();
216 | invalidate();
217 | }
218 |
219 | public final int getCurrentItem() {
220 | if (mCurrentItem <= 0) {
221 | return 0;
222 | }
223 | return mCurrentItem;
224 | }
225 |
226 | final void b(float f1) {
227 | Timer timer = new Timer();
228 | this.timer = timer;
229 | timer.schedule(new LoopTimerTask(this, f1, timer), 0L, 50L);
230 | }
231 |
232 | final void c() {
233 | if (loopListener != null) {
234 | (new Handler()).postDelayed(new LoopRunnable(this), 200L);
235 | }
236 | }
237 |
238 | protected void onDraw(Canvas canvas) {
239 | String as[];
240 | if (arrayList == null) {
241 | super.onDraw(canvas);
242 | return;
243 | }
244 | as = new String[r];
245 | int w = (int) ((float) totalScrollY / (l * (float) h));
246 | mCurrentItem = position + w % arrayList.size();
247 | int i1;
248 | if (!isLoop) {
249 | if (mCurrentItem < 0) {
250 | mCurrentItem = 0;
251 | }
252 | if (mCurrentItem > arrayList.size() - 1) {
253 | mCurrentItem = arrayList.size() - 1;
254 | }
255 | } else {
256 | if (mCurrentItem < 0) {
257 | mCurrentItem = arrayList.size() + mCurrentItem;
258 | }
259 | if (mCurrentItem > arrayList.size() - 1) {
260 | mCurrentItem = mCurrentItem - arrayList.size();
261 | }
262 | }
263 | int j2 = (int) ((float) totalScrollY % (l * (float) h));
264 | int k1 = 0;
265 | while (k1 < r) {
266 | int l1 = mCurrentItem - (4 - k1);
267 | if (isLoop) {
268 | i1 = l1;
269 | if (l1 < 0) {
270 | i1 = l1 + arrayList.size();
271 | }
272 | l1 = i1;
273 | if (i1 > arrayList.size() - 1) {
274 | l1 = i1 - arrayList.size();
275 | }
276 | as[k1] = (String) arrayList.get(l1);
277 | } else if (l1 < 0) {
278 | as[k1] = "";
279 | } else if (l1 > arrayList.size() - 1) {
280 | as[k1] = "";
281 | } else {
282 | as[k1] = (String) arrayList.get(l1);
283 | }
284 | k1++;
285 | }
286 | canvas.drawLine(0.0F, n, getWidth(), n, paintC);
287 | canvas.drawLine(0.0F, o, getWidth(), o, paintC);
288 | int j1 = 0;
289 | while (j1 < r) {
290 | canvas.save();
291 | double d1 = ((double) ((float) (h * j1) * l - (float) j2) * 3.1415926535897931D) / (double) t;
292 | float f1 = (float) (90D - (d1 / 3.1415926535897931D) * 180D);
293 | if (f1 >= 90F || f1 <= -90F) {
294 | canvas.restore();
295 | } else {
296 | int i2 = (int) ((double) u - Math.cos(d1) * (double) u - (Math.sin(d1) * (double) h) / 2D);
297 | canvas.translate(0.0F, i2);
298 | canvas.scale(1.0F, (float) Math.sin(d1));
299 |
300 | String str = as[j1];
301 |
302 | int zoomTextSize;
303 | double zoom = ((double) textSize - str.length() * 2) / textSize * 1.2;
304 | zoomTextSize = (int) (textSize * zoom);
305 | if (zoomTextSize < 10) {
306 | zoomTextSize = 10;
307 | }
308 | paintA.setTextSize(zoomTextSize);
309 | paintB.setTextSize(zoomTextSize);
310 |
311 | int startX = (int) (n + (getLeft() * 0.5));
312 |
313 | paintB.getTextBounds(str, 0, str.length(), mRectBound);
314 |
315 | int itemWidth = mRectBound.width();
316 | int maxWidth = getWidth();
317 |
318 | maxWidth -= 2 * startX;
319 |
320 | if (itemWidth > 0) {
321 | startX += (maxWidth - itemWidth) * 0.5;
322 | }
323 |
324 | if (i2 <= n && h + i2 >= n) {
325 | canvas.save();
326 | canvas.clipRect(0, 0, getWidth(), n - i2);
327 | canvas.drawText(as[j1], startX, h, paintA);
328 | canvas.restore();
329 | canvas.save();
330 | canvas.clipRect(0, n - i2, getWidth(), (int) ((float) h * l));
331 | canvas.drawText(as[j1], startX, h, paintB);
332 | canvas.restore();
333 | } else if (i2 <= o && h + i2 >= o) {
334 | canvas.save();
335 | canvas.clipRect(0, 0, getWidth(), o - i2);
336 | canvas.drawText(as[j1], startX, h, paintB);
337 | canvas.restore();
338 | canvas.save();
339 | canvas.clipRect(0, o - i2, getWidth(), (int) ((float) h * l));
340 | canvas.drawText(as[j1], startX, h, paintA);
341 | canvas.restore();
342 | } else if (i2 >= n && h + i2 <= o) {
343 | canvas.clipRect(0, 0, getWidth(), (int) ((float) h * l));
344 | canvas.drawText(as[j1], startX, h, paintB);
345 | } else {
346 | canvas.clipRect(0, 0, getWidth(), (int) ((float) h * l));
347 | canvas.drawText(as[j1], startX, h, paintA);
348 | }
349 | canvas.restore();
350 | }
351 | j1++;
352 | }
353 | super.onDraw(canvas);
354 | }
355 |
356 | protected void onMeasure(int i1, int j1) {
357 | d();
358 | setMeasuredDimension(i1, s);
359 | }
360 |
361 | public boolean onTouchEvent(MotionEvent motionevent) {
362 | switch (motionevent.getAction()) {
363 | case MotionEvent.ACTION_DOWN:
364 | x = motionevent.getRawY();
365 | break;
366 | case MotionEvent.ACTION_MOVE:
367 | y = motionevent.getRawY();
368 | z = x - y;
369 | x = y;
370 | totalScrollY = (int) ((float) totalScrollY + z);
371 | if (!isLoop) {
372 | if (totalScrollY > (int) ((float) (-position) * (l * (float) h))) {
373 | break; /* Loop/switch isn't completed */
374 | }
375 | totalScrollY = (int) ((float) (-position) * (l * (float) h));
376 | }
377 | break;
378 | case MotionEvent.ACTION_UP:
379 | default:
380 | if (!gestureDetector.onTouchEvent(motionevent) && motionevent.getAction() == 1) {
381 | f();
382 | }
383 | return true;
384 | }
385 |
386 | if (totalScrollY < (int) ((float) (arrayList.size() - 1 - position) * (l * (float) h))) {
387 | invalidate();
388 | } else {
389 | totalScrollY = (int) ((float) (arrayList.size() - 1 - position) * (l * (float) h));
390 | invalidate();
391 | }
392 |
393 | if (!gestureDetector.onTouchEvent(motionevent) && motionevent.getAction() == 1) {
394 | f();
395 | }
396 | return true;
397 | }
398 | }
399 |
--------------------------------------------------------------------------------