From bbeaf11fd95584450017e505c227a34094c0f7f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Chaqu=C3=A9s?= Date: Sun, 6 Aug 2017 15:52:29 +0200 Subject: [PATCH 1/4] - Update Build Tools Version to 25.0.3 - Update Support Library Version to 25.4.0 - Add neutral button --- build.gradle | 8 +- sample/build.gradle | 19 ++-- .../switchdatetimesample/Sample.java | 106 +++++++++++------- .../src/main/res/layout/activity_sample.xml | 10 +- sample/src/main/res/values/strings.xml | 2 + switchdatetime/build.gradle | 23 ++-- .../SwitchDateTimeDialogFragment.java | 29 +++++ 7 files changed, 124 insertions(+), 73 deletions(-) diff --git a/build.gradle b/build.gradle index c2eea8e..f456794 100644 --- a/build.gradle +++ b/build.gradle @@ -1,20 +1,16 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { repositories { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath "com.android.tools.build:gradle:2.3.3" } } allprojects { repositories { jcenter() + maven { url "https://maven.google.com" } } } diff --git a/sample/build.gradle b/sample/build.gradle index c8d5d4a..f13d8eb 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,30 +1,27 @@ -apply plugin: 'com.android.application' +apply plugin: "com.android.application" android { compileSdkVersion 25 - buildToolsVersion "25.0.2" + buildToolsVersion "25.0.3" defaultConfig { applicationId "com.kunzisoft.switchdatetimepicker.sample" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } } +def supportVersion = "25.4.0" + dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - compile 'com.android.support:appcompat-v7:25.3.1' - testCompile 'junit:junit:4.12' - compile project(path: ':switchdatetime') + compile fileTree(dir: "libs", include: ["*.jar"]) + compile "com.android.support:appcompat-v7:$supportVersion" + compile project(path: ":switchdatetime") } diff --git a/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java b/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java index 600ef06..e5f467c 100644 --- a/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java +++ b/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java @@ -41,59 +41,81 @@ protected void onCreate(Bundle savedInstanceState) { textView.setText(savedInstanceState.getCharSequence(STATE_TEXTVIEW)); } - // Construct SwitchDateTimePicker - dateTimeFragment = (SwitchDateTimeDialogFragment) getSupportFragmentManager().findFragmentByTag(TAG_DATETIME_FRAGMENT); - if(dateTimeFragment == null) { - dateTimeFragment = SwitchDateTimeDialogFragment.newInstance( - getString(R.string.label_datetime_dialog), - getString(android.R.string.ok), - getString(android.R.string.cancel) - ); - } - - // Assign values we want - final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy HH:mm", java.util.Locale.getDefault()); - dateTimeFragment.startAtCalendarView(); - dateTimeFragment.set24HoursMode(false); - dateTimeFragment.setMinimumDateTime(new GregorianCalendar(2015, Calendar.JANUARY, 1).getTime()); - dateTimeFragment.setMaximumDateTime(new GregorianCalendar(2025, Calendar.DECEMBER, 31).getTime()); - dateTimeFragment.setDefaultDateTime(new GregorianCalendar(2017, Calendar.MARCH, 4, 15, 20).getTime()); - // Or assign each element, default element is the current moment - // dateTimeFragment.setDefaultHourOfDay(15); - // dateTimeFragment.setDefaultMinute(20); - // dateTimeFragment.setDefaultDay(4); - // dateTimeFragment.setDefaultMonth(Calendar.MARCH); - // dateTimeFragment.setDefaultYear(2017); - - // Define new day and month format - try { - dateTimeFragment.setSimpleDateMonthAndDayFormat(new SimpleDateFormat("MMMM dd", Locale.getDefault())); - } catch (SwitchDateTimeDialogFragment.SimpleDateMonthAndDayFormatException e) { - Log.e(TAG, e.getMessage()); - } - - // Set listener for date - dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() { + Button buttonView = (Button) findViewById(R.id.button); + buttonView.setOnClickListener(new View.OnClickListener() { @Override - public void onPositiveButtonClick(Date date) { - textView.setText(myDateFormat.format(date)); - } + public void onClick(View view) { + dateTimeFragment = SwitchDateTimeDialogFragment.newInstance( + getString(R.string.label_datetime_dialog), + getString(android.R.string.ok), + getString(android.R.string.cancel) + ); + setupDatetimeFragment(); - @Override - public void onNegativeButtonClick(Date date) { - textView.setText(""); + dateTimeFragment.show(getSupportFragmentManager(), TAG_DATETIME_FRAGMENT); } }); - Button buttonView = (Button) findViewById(R.id.button); - buttonView.setOnClickListener(new View.OnClickListener() { + Button neutralButtonView = (Button) findViewById(R.id.button_neutral); + neutralButtonView.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View view) { + public void onClick(View v) { + dateTimeFragment = SwitchDateTimeDialogFragment.newInstance( + getString(R.string.label_datetime_dialog), + getString(android.R.string.ok), + getString(android.R.string.cancel), + getString(R.string.clean) + ); + setupDatetimeFragment(); + dateTimeFragment.show(getSupportFragmentManager(), TAG_DATETIME_FRAGMENT); } }); } + private void setupDatetimeFragment() { + if (dateTimeFragment != null) { + // Assign values we want + final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy HH:mm", java.util.Locale.getDefault()); + dateTimeFragment.startAtCalendarView(); + dateTimeFragment.set24HoursMode(false); + dateTimeFragment.setMinimumDateTime(new GregorianCalendar(2015, Calendar.JANUARY, 1).getTime()); + dateTimeFragment.setMaximumDateTime(new GregorianCalendar(2025, Calendar.DECEMBER, 31).getTime()); + dateTimeFragment.setDefaultDateTime(new GregorianCalendar(2017, Calendar.MARCH, 4, 15, 20).getTime()); + // Or assign each element, default element is the current moment + // dateTimeFragment.setDefaultHourOfDay(15); + // dateTimeFragment.setDefaultMinute(20); + // dateTimeFragment.setDefaultDay(4); + // dateTimeFragment.setDefaultMonth(Calendar.MARCH); + // dateTimeFragment.setDefaultYear(2017); + + // Define new day and month format + try { + dateTimeFragment.setSimpleDateMonthAndDayFormat(new SimpleDateFormat("MMMM dd", Locale.getDefault())); + } catch (SwitchDateTimeDialogFragment.SimpleDateMonthAndDayFormatException e) { + Log.e(TAG, e.getMessage()); + } + + // Set listener for date + dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() { + @Override + public void onPositiveButtonClick(Date date) { + textView.setText(myDateFormat.format(date)); + } + + @Override + public void onNegativeButtonClick(Date date) { + + } + + @Override + public void onNeutralButtonClick(Date date) { + textView.setText(""); + } + }); + } + } + @Override public void onSaveInstanceState(Bundle savedInstanceState) { // Save the current textView diff --git a/sample/src/main/res/layout/activity_sample.xml b/sample/src/main/res/layout/activity_sample.xml index 696c0f6..455065d 100644 --- a/sample/src/main/res/layout/activity_sample.xml +++ b/sample/src/main/res/layout/activity_sample.xml @@ -16,11 +16,19 @@ android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> +