diff --git a/ReadMe.md b/ReadMe.md
index dc43d4b..9ddca42 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -28,7 +28,7 @@ Add the JitPack repository in your build.gradle at the end of repositories:
And add the dependency
```
dependencies {
- compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.7'
+ compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.8'
}
```
@@ -137,6 +137,35 @@ dateTimeDialogFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment
// Show
dateTimeDialogFragment.show(getSupportFragmentManager(), "dialog_time");
```
+
+#### Neutral button
+
+
+
+To use with a neutral button, initialize with another parameter and implement the *OnButtonWithNeutralClickListener* :
+```
+SwitchDateTimeDialogFragment dateTimeDialogFragment = SwitchDateTimeDialogFragment.newInstance(
+ "Title example",
+ "OK",
+ "Cancel",
+ "Clean"
+);
+
+dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonWithNeutralClickListener() {
+ @Override
+ public void onPositiveButtonClick(Date date) {
+ }
+
+ @Override
+ public void onNegativeButtonClick(Date date) {
+ }
+
+ @Override
+ public void onNeutralButtonClick(Date date) {
+ }
+});
+```
+
## Bonus
You can follow the project live on https://www.livecoding.tv/kunzisoft/
diff --git a/art/screen3.jpg b/art/screen3.jpg
new file mode 100644
index 0000000..3225846
Binary files /dev/null and b/art/screen3.jpg differ
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..9b0034c 100644
--- a/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java
+++ b/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java
@@ -47,23 +47,17 @@ protected void onCreate(Bundle savedInstanceState) {
dateTimeFragment = SwitchDateTimeDialogFragment.newInstance(
getString(R.string.label_datetime_dialog),
getString(android.R.string.ok),
- getString(android.R.string.cancel)
+ getString(android.R.string.cancel),
+ getString(R.string.clean) // Optional
);
}
- // Assign values we want
+ // Init format
final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy HH:mm", java.util.Locale.getDefault());
- dateTimeFragment.startAtCalendarView();
+ // Assign unmodifiable values
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 {
@@ -73,7 +67,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
// Set listener for date
- dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {
+ // Or use dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {
+ dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonWithNeutralClickListener() {
@Override
public void onPositiveButtonClick(Date date) {
textView.setText(myDateFormat.format(date));
@@ -81,6 +76,12 @@ public void onPositiveButtonClick(Date date) {
@Override
public void onNegativeButtonClick(Date date) {
+ // Do nothing
+ }
+
+ @Override
+ public void onNeutralButtonClick(Date date) {
+ // Optional if neutral button does'nt exists
textView.setText("");
}
});
@@ -89,6 +90,9 @@ public void onNegativeButtonClick(Date date) {
buttonView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
+ // Re-init each time
+ dateTimeFragment.startAtCalendarView();
+ dateTimeFragment.setDefaultDateTime(new GregorianCalendar(2017, Calendar.MARCH, 4, 15, 20).getTime());
dateTimeFragment.show(getSupportFragmentManager(), TAG_DATETIME_FRAGMENT);
}
});
diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml
index c1269d3..a3c77ca 100644
--- a/sample/src/main/res/values/strings.xml
+++ b/sample/src/main/res/values/strings.xml
@@ -1,4 +1,6 @@
Switch DateTime Picker
Open DateTime Dialog
+ Open DateTime Dialog with Neutral Button
+ Clean
diff --git a/switchdatetime/build.gradle b/switchdatetime/build.gradle
index e8e80f3..af05044 100644
--- a/switchdatetime/build.gradle
+++ b/switchdatetime/build.gradle
@@ -1,32 +1,29 @@
-apply plugin: 'com.android.library'
+apply plugin: "com.android.library"
android {
compileSdkVersion 25
- buildToolsVersion "25.0.2"
+ buildToolsVersion "25.0.3"
defaultConfig {
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'
- compile 'com.android.support:recyclerview-v7:25.3.1'
- compile 'com.prolificinteractive:material-calendarview:1.4.3'
- testCompile 'junit:junit:4.12'
+ compile fileTree(dir: "libs", include: ["*.jar"])
+ compile "com.android.support:appcompat-v7:$supportVersion"
+ compile "com.android.support:recyclerview-v7:$supportVersion"
+ compile "com.prolificinteractive:material-calendarview:1.4.3"
}
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java
index d3c0ccd..59479ae 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java
@@ -23,6 +23,7 @@
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import com.prolificinteractive.materialcalendarview.OnDateSelectedListener;
+import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@@ -40,6 +41,9 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
private static final String TAG = "SwitchDateTimeDialogFrg";
private static final String STATE_DATETIME = "STATE_DATETIME";
+ private static final String STATE_CURRENT_POSITION = "STATE_CURRENT_POSITION";
+
+ private static final int UNDEFINED_POSITION = -1;
private Calendar dateTimeCalendar = Calendar.getInstance();
private Calendar minimumDateTime = new GregorianCalendar(1970, 1, 1);
private Calendar maximumDateTime = new GregorianCalendar(2200, 1, 1);
@@ -47,22 +51,17 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
private static final String TAG_LABEL = "LABEL";
private static final String TAG_POSITIVE_BUTTON = "POSITIVE_BUTTON";
private static final String TAG_NEGATIVE_BUTTON = "NEGATIVE_BUTTON";
+ private static final String TAG_NEUTRAL_BUTTON = "NEUTRAL_BUTTON";
private String mLabel;
private String mPositiveButton;
private String mNegativeButton;
+ private String mNeutralButton;
private OnButtonClickListener mListener;
- private final static int UNDEFINED_TIME_VALUE = -1;
- private int year = UNDEFINED_TIME_VALUE;
- private int month = UNDEFINED_TIME_VALUE;
- private int day = UNDEFINED_TIME_VALUE;
- private int hourOfDay = UNDEFINED_TIME_VALUE;
- private int minute = UNDEFINED_TIME_VALUE;
- private boolean assignDefaultDateTimeCalendar;
-
private boolean is24HoursMode = false;
- private int startAtPosition = 0;
+ private int startAtPosition = UNDEFINED_POSITION;
+ private int currentPosition = 0;
private int alertStyleId;
private SimpleDateFormat dayAndMonthSimpleDate;
@@ -87,12 +86,26 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
* @return DialogFragment
*/
public static SwitchDateTimeDialogFragment newInstance(String label, String positiveButton, String negativeButton) {
+ return newInstance(label, positiveButton, negativeButton, null);
+ }
+
+ /**
+ * Create a new instance of SwitchDateTimeDialogFragment
+ * @param label Title of dialog
+ * @param positiveButton Text for positive button
+ * @param negativeButton Text for negative button
+ * @return DialogFragment
+ */
+ public static SwitchDateTimeDialogFragment newInstance(String label, String positiveButton, String negativeButton, String neutralButton) {
SwitchDateTimeDialogFragment switchDateTimeDialogFragment = new SwitchDateTimeDialogFragment();
// Add arguments
Bundle args = new Bundle();
args.putString(TAG_LABEL, label);
args.putString(TAG_POSITIVE_BUTTON, positiveButton);
args.putString(TAG_NEGATIVE_BUTTON, negativeButton);
+ if (neutralButton != null) {
+ args.putString(TAG_NEUTRAL_BUTTON, neutralButton);
+ }
switchDateTimeDialogFragment.setArguments(args);
return switchDateTimeDialogFragment;
@@ -108,8 +121,9 @@ public void setOnButtonClickListener(OnButtonClickListener onButtonClickListener
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
- // Save the current datetime
+ // Save the current datetime and position
savedInstanceState.putLong(STATE_DATETIME, dateTimeCalendar.getTimeInMillis());
+ savedInstanceState.putInt(STATE_CURRENT_POSITION, currentPosition);
timePicker.onSaveInstanceState(savedInstanceState);
super.onSaveInstanceState(savedInstanceState);
@@ -123,28 +137,14 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
mLabel = getArguments().getString(TAG_LABEL);
mPositiveButton = getArguments().getString(TAG_POSITIVE_BUTTON);
mNegativeButton = getArguments().getString(TAG_NEGATIVE_BUTTON);
+ mNeutralButton = getArguments().getString(TAG_NEUTRAL_BUTTON);
}
- if (!assignDefaultDateTimeCalendar && savedInstanceState != null) {
- // Restore value from saved state
+ if(savedInstanceState != null) {
+ currentPosition = savedInstanceState.getInt(STATE_CURRENT_POSITION);
dateTimeCalendar.setTime(new Date(savedInstanceState.getLong(STATE_DATETIME)));
}
- // Init values with current time if setDefault is not used
- if(assignDefaultDateTimeCalendar || year == UNDEFINED_TIME_VALUE)
- year = dateTimeCalendar.get(Calendar.YEAR);
- if(assignDefaultDateTimeCalendar || month == UNDEFINED_TIME_VALUE)
- month = dateTimeCalendar.get(Calendar.MONTH);
- if(assignDefaultDateTimeCalendar || day == UNDEFINED_TIME_VALUE)
- day = dateTimeCalendar.get(Calendar.DAY_OF_MONTH);
- if(assignDefaultDateTimeCalendar || hourOfDay == UNDEFINED_TIME_VALUE)
- hourOfDay = dateTimeCalendar.get(Calendar.HOUR_OF_DAY);
- if(assignDefaultDateTimeCalendar || minute == UNDEFINED_TIME_VALUE)
- minute = dateTimeCalendar.get(Calendar.MINUTE);
- assignAllValuesToCalendar();
-
- assignDefaultDateTimeCalendar = false;
-
// Throw exception if default select date isn't between minimumDateTime and maximumDateTime
if(dateTimeCalendar.before(minimumDateTime) || dateTimeCalendar.after(maximumDateTime))
throw new RuntimeException("Default date " + dateTimeCalendar.getTime() + " must be between "
@@ -152,7 +152,6 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
LayoutInflater inflater = LayoutInflater.from(getActivity());
getActivity().getTheme().applyStyle(R.style.Theme_SwitchDateTime, false);
- //getActivity().setTheme(R.style.Theme_SwitchDateTime);
View dateTimeLayout = inflater.inflate(R.layout.dialog_switch_datetime_picker,
(ViewGroup) getActivity().findViewById(R.id.datetime_picker));
@@ -176,6 +175,7 @@ public void onAnimationStart(Animation animation) {
@Override
public void onAnimationEnd(Animation animation) {
blockAnimationIn = false;
+ currentPosition = viewSwitcher.getDisplayedChild();
}
@Override
@@ -195,7 +195,11 @@ public void onAnimationEnd(Animation animation) {
@Override
public void onAnimationRepeat(Animation animation) {}
});
- viewSwitcher.setDisplayedChild(startAtPosition);
+
+ // Defined the start position
+ if(startAtPosition != UNDEFINED_POSITION)
+ currentPosition = startAtPosition;
+ viewSwitcher.setDisplayedChild(currentPosition);
// Button for switch between Hours/Minutes, Calendar and YearList
ImageButton buttonSwitch = (ImageButton) dateTimeLayout.findViewById(R.id.button_switch);
@@ -232,27 +236,22 @@ public void onClick(View view) {
yearSimpleDate = new SimpleDateFormat("yyyy", Locale.getDefault());
// Init headers
- yearHeaderValues.setText(String.valueOf(year));
+ yearHeaderValues.setText(yearSimpleDate.format(dateTimeCalendar.getTime()));
monthAndDayHeaderValues.setText(dayAndMonthSimpleDate.format(dateTimeCalendar.getTime()));
// Construct TimePicker
SwitchTimePicker.OnTimeSelectedListener onTimeSelectedListener = new SwitchTimePicker.OnTimeSelectedListener() {
@Override
public void onTimeSelected(int hourOfDayTime, int minuteTime) {
- hourOfDay = hourOfDayTime;
- minute = minuteTime;
dateTimeCalendar.set(Calendar.HOUR_OF_DAY, hourOfDayTime);
dateTimeCalendar.set(Calendar.MINUTE, minuteTime);
}
};
// Init time with saved elements
- if(savedInstanceState == null)
- timePicker = new SwitchTimePicker(getContext(), onTimeSelectedListener);
- else
- timePicker = new SwitchTimePicker(getContext(), onTimeSelectedListener, savedInstanceState);
+ timePicker = new SwitchTimePicker(getContext(), onTimeSelectedListener, savedInstanceState);
timePicker.setIs24HourMode(is24HoursMode);
- timePicker.setHourOfDay(hourOfDay);
- timePicker.setMinute(minute);
+ timePicker.setHourOfDay(dateTimeCalendar.get(Calendar.HOUR_OF_DAY));
+ timePicker.setMinute(dateTimeCalendar.get(Calendar.MINUTE));
timePicker.onCreateView(dateTimeLayout, savedInstanceState);
timePicker.setOnClickTimeListener(onTimeClickListener);
@@ -268,16 +267,11 @@ public void onTimeSelected(int hourOfDayTime, int minuteTime) {
@Override
public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay calendarDay, boolean selected) {
Date currentDate = calendarDay.getDate();
- year = calendarDay.getYear();
- month = calendarDay.getMonth();
- day = calendarDay.getDay();
-
- dateTimeCalendar.set(Calendar.YEAR, year);
- dateTimeCalendar.set(Calendar.MONTH, month);
- dateTimeCalendar.set(Calendar.DAY_OF_MONTH, day);
- listPickerYearView.assignCurrentYear(year);
-
- yearHeaderValues.setText(String.valueOf(year));
+ dateTimeCalendar.set(Calendar.YEAR, calendarDay.getYear());
+ dateTimeCalendar.set(Calendar.MONTH, calendarDay.getMonth());
+ dateTimeCalendar.set(Calendar.DAY_OF_MONTH, calendarDay.getDay());
+ listPickerYearView.assignCurrentYear(calendarDay.getYear());
+ yearHeaderValues.setText(yearSimpleDate.format(dateTimeCalendar.getTime()));
monthAndDayHeaderValues.setText(dayAndMonthSimpleDate.format(currentDate));
}
});
@@ -287,14 +281,12 @@ public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull Calend
listPickerYearView = (ListPickerYearView) dateTimeLayout.findViewById(R.id.yearPicker);
listPickerYearView.setMinYear(minimumDateTime.get(Calendar.YEAR));
listPickerYearView.setMaxYear(maximumDateTime.get(Calendar.YEAR));
- listPickerYearView.assignCurrentYear(year);
+ listPickerYearView.assignCurrentYear(dateTimeCalendar.get(Calendar.YEAR));
listPickerYearView.setDatePickerListener(new OnYearSelectedListener() {
@Override
public void onYearSelected(View view, int yearPicker) {
- year = yearPicker;
-
- dateTimeCalendar.set(Calendar.YEAR, year);
- yearHeaderValues.setText(String.valueOf(year));
+ dateTimeCalendar.set(Calendar.YEAR, yearPicker);
+ yearHeaderValues.setText(yearSimpleDate.format(dateTimeCalendar.getTime()));
// Unfortunately, we have lags here and thread isn't a solution :/
materialCalendarView.setCurrentDate(dateTimeCalendar.getTime());
@@ -319,7 +311,6 @@ public void onYearSelected(View view, int yearPicker) {
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(mListener !=null) {
- assignAllValuesToCalendar();
mListener.onPositiveButtonClick(dateTimeCalendar.getTime());
}
}
@@ -331,46 +322,49 @@ public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) {
// Close dialog
if(mListener !=null) {
- assignAllValuesToCalendar();
mListener.onNegativeButtonClick(dateTimeCalendar.getTime());
}
}
});
-
+ if (mNeutralButton != null) {
+ db.setNeutralButton(mNeutralButton, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (mListener != null) {
+ if(mListener instanceof OnButtonWithNeutralClickListener)
+ ((OnButtonWithNeutralClickListener) mListener).onNeutralButtonClick(dateTimeCalendar.getTime());
+ }
+ }
+ });
+ }
return db.create();
}
- /**
- * Assign each value of time in calendar
- */
- private void assignAllValuesToCalendar() {
- dateTimeCalendar.set(Calendar.YEAR, year);
- dateTimeCalendar.set(Calendar.MONTH, month);
- dateTimeCalendar.set(Calendar.DAY_OF_MONTH, day);
- dateTimeCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
- dateTimeCalendar.set(Calendar.MINUTE, minute);
- dateTimeCalendar.set(Calendar.SECOND, 0);
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ super.onDismiss(dialog);
+ startAtPosition = UNDEFINED_POSITION;
}
/**
* Define "Time" as the first view to show
*/
public void startAtTimeView() {
- startAtPosition = 0;
+ startAtPosition = HeaderViewsPosition.VIEW_HOURS_AND_MINUTES.getPosition();
}
/**
* Define "Calendar" as the first view to show
*/
public void startAtCalendarView() {
- startAtPosition = 1;
+ startAtPosition = HeaderViewsPosition.VIEW_MONTH_AND_DAY.getPosition();
}
/**
* Define "Year" as the first view to show
*/
public void startAtYearView() {
- startAtPosition = 2;
+ startAtPosition = HeaderViewsPosition.VIEW_YEAR.getPosition();
}
/**
@@ -378,7 +372,7 @@ public void startAtYearView() {
* @param year
*/
public void setDefaultYear(int year) {
- this.year = year;
+ this.dateTimeCalendar.set(Calendar.YEAR, year);
}
@Deprecated
@@ -396,7 +390,7 @@ public void setYear(int year) {
* @param month
*/
public void setDefaultMonth(int month) {
- this.month = month;
+ this.dateTimeCalendar.set(Calendar.MONTH, month);
}
@Deprecated
@@ -413,7 +407,7 @@ public void setMonth(int month) {
* @param day
*/
public void setDefaultDay(int day) {
- this.day = day;
+ this.dateTimeCalendar.set(Calendar.DAY_OF_MONTH, day);
}
@Deprecated
@@ -430,7 +424,7 @@ public void setDay(int day) {
* @param hourOfDay
*/
public void setDefaultHourOfDay(int hourOfDay) {
- this.hourOfDay = hourOfDay;
+ this.dateTimeCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
}
@Deprecated
@@ -447,7 +441,7 @@ public void setHour(int hour) {
* @param minute
*/
public void setDefaultMinute(int minute) {
- this.minute = minute;
+ this.dateTimeCalendar.set(Calendar.MINUTE, minute);
}
@Deprecated
@@ -464,7 +458,7 @@ public void setMinute(int minute) {
* @return
*/
public int getYear() {
- return year;
+ return this.dateTimeCalendar.get(Calendar.YEAR);
}
/**
@@ -473,7 +467,7 @@ public int getYear() {
* @return
*/
public int getMonth() {
- return month;
+ return this.dateTimeCalendar.get(Calendar.MONTH);
}
/**
@@ -481,7 +475,7 @@ public int getMonth() {
* @return
*/
public int getDay() {
- return day;
+ return this.dateTimeCalendar.get(Calendar.DAY_OF_MONTH);
}
/**
@@ -489,7 +483,7 @@ public int getDay() {
* @return
*/
public int getHourOfDay() {
- return hourOfDay;
+ return this.dateTimeCalendar.get(Calendar.HOUR_OF_DAY);
}
/**
@@ -497,7 +491,7 @@ public int getHourOfDay() {
* @return
*/
public int getMinute() {
- return minute;
+ return this.dateTimeCalendar.get(Calendar.MINUTE);
}
/**
@@ -506,7 +500,6 @@ public int getMinute() {
*/
public void setDefaultDateTime(Date date) {
this.dateTimeCalendar.setTime(date);
- this.assignDefaultDateTimeCalendar = true;
}
/**
@@ -595,6 +588,13 @@ public interface OnButtonClickListener {
void onNegativeButtonClick(Date date);
}
+ /**
+ * Callback class for assign action on positive, negative and neutral button
+ */
+ public interface OnButtonWithNeutralClickListener extends OnButtonClickListener {
+ void onNeutralButtonClick(Date date);
+ }
+
/**
* Enumeration of header views
*/
@@ -627,6 +627,8 @@ public void onClick(View view) {
Utils.animLabelElement(view);
if(viewSwitcher.getDisplayedChild() != positionView)
viewSwitcher.setDisplayedChild(positionView);
+
+ startAtPosition = positionView;
}
}
}
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/TextCircularIndicatorView.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/TextCircularIndicatorView.java
index 11bffbd..ebb8aea 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/TextCircularIndicatorView.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/TextCircularIndicatorView.java
@@ -5,11 +5,9 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
-import android.os.Build;
import android.support.annotation.ColorInt;
-import android.support.annotation.RequiresApi;
+import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
-import android.widget.TextView;
import com.kunzisoft.switchdatetime.R;
@@ -17,7 +15,7 @@
* TextView with circular colored background
* @author JJamet
*/
-public class TextCircularIndicatorView extends TextView {
+public class TextCircularIndicatorView extends AppCompatTextView {
private int mCircleColor = Color.BLUE;
private Paint mCirclePaint = new Paint();
@@ -35,12 +33,6 @@ public TextCircularIndicatorView(Context context, AttributeSet attrs, int defSty
init(attrs);
}
- @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
- public TextCircularIndicatorView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- init(attrs);
- }
-
/**
* Initialize constructor
* @param attrs
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/YearPickerAdapter.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/YearPickerAdapter.java
index bf973c9..23cd8f4 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/YearPickerAdapter.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/YearPickerAdapter.java
@@ -8,8 +8,12 @@
import com.kunzisoft.switchdatetime.R;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.List;
+import java.util.Locale;
/**
* Adapter for manage elements of ListPickerYearView
@@ -22,6 +26,9 @@ class YearPickerAdapter extends RecyclerView.Adapter listYears;
private Integer selectedYear;
private int positionSelectedYear;
@@ -34,6 +41,8 @@ class YearPickerAdapter extends RecyclerView.Adapter();
this.selectedYear = UNDEFINED;
+ this.yearFormat = new SimpleDateFormat("yyyy", Locale.getDefault());
+ this.calendar = Calendar.getInstance();
}
@Override
@@ -62,7 +71,9 @@ public TextIndicatorViewHolder onCreateViewHolder(ViewGroup parent, int viewType
@Override
public void onBindViewHolder(TextIndicatorViewHolder holder, int position) {
Integer currentYear = listYears.get(position);
- holder.textView.setText(String.valueOf(currentYear));
+
+ calendar.set(Calendar.YEAR, currentYear);
+ holder.textView.setText(yearFormat.format(calendar.getTime()));
if(onClickYearListener != null)
holder.container.setOnClickListener(new BufferYearClickListener(currentYear, position));
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/RadialPickerLayout.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/RadialPickerLayout.java
index 4cd6c2b..2220756 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/RadialPickerLayout.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/RadialPickerLayout.java
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
@@ -48,6 +49,8 @@
import com.kunzisoft.switchdatetime.time.widget.RadialSelectorView;
import com.kunzisoft.switchdatetime.time.widget.RadialTextsView;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
public class RadialPickerLayout extends FrameLayout implements OnTouchListener {
@@ -578,24 +581,26 @@ public void setCurrentItemShowing(int index, boolean animate) {
mCurrentItemShowing = index;
if (animate && (index != lastIndex)) {
- ObjectAnimator[] anims = new ObjectAnimator[4];
- if (index == MINUTE_INDEX) {
- anims[0] = mHourRadialTextsView.getDisappearAnimator();
- anims[1] = mHourRadialSelectorView.getDisappearAnimator();
- anims[2] = mMinuteRadialTextsView.getReappearAnimator();
- anims[3] = mMinuteRadialSelectorView.getReappearAnimator();
- } else {
- anims[0] = mHourRadialTextsView.getReappearAnimator();
- anims[1] = mHourRadialSelectorView.getReappearAnimator();
- anims[2] = mMinuteRadialTextsView.getDisappearAnimator();
- anims[3] = mMinuteRadialSelectorView.getDisappearAnimator();
+ List animators = new ArrayList<>();
+ switch(index) {
+ case MINUTE_INDEX :
+ animators.add(mHourRadialTextsView.getDisappearAnimator());
+ animators.add(mHourRadialSelectorView.getDisappearAnimator());
+ animators.add(mMinuteRadialTextsView.getReappearAnimator());
+ animators.add(mMinuteRadialSelectorView.getReappearAnimator());
+ break;
+ case HOUR_INDEX :
+ animators.add(mHourRadialTextsView.getReappearAnimator());
+ animators.add(mHourRadialSelectorView.getReappearAnimator());
+ animators.add(mMinuteRadialTextsView.getDisappearAnimator());
+ animators.add(mMinuteRadialSelectorView.getDisappearAnimator());
+ break;
}
-
if (mTransition != null && mTransition.isRunning()) {
mTransition.end();
}
mTransition = new AnimatorSet();
- mTransition.playTogether(anims);
+ mTransition.playTogether(animators);
mTransition.start();
} else {
if (Build.VERSION.SDK_INT >= 11) {
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/SwitchTimePicker.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/SwitchTimePicker.java
index dae58d3..211a71f 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/SwitchTimePicker.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/SwitchTimePicker.java
@@ -73,9 +73,7 @@ public class SwitchTimePicker implements RadialPickerLayout.OnValueSelectedListe
private int mCurrentViewShow;
private TextView mHourView;
- private TextView mHourSpaceView;
private TextView mMinuteView;
- private TextView mMinuteSpaceView;
private TextView mAmPmTextView;
private View mAmPmHitspace;
private RadialPickerLayout mTimePicker;
@@ -180,15 +178,16 @@ public View onCreateView(final View view,
final Resources resources = mContext.getResources();
mHourPickerDescription = resources.getString(R.string.hour_picker_description);
mSelectHours = resources.getString(R.string.select_hours);
+
mMinutePickerDescription = resources.getString(R.string.minute_picker_description);
mSelectMinutes = resources.getString(R.string.select_minutes);
mHourView = (TextView) view.findViewById(R.id.hours);
mHourView.setOnKeyListener(keyboardListener);
- mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
- mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
+
mMinuteView = (TextView) view.findViewById(R.id.minutes);
mMinuteView.setOnKeyListener(keyboardListener);
+
mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
mAmPmTextView.setOnKeyListener(keyboardListener);
@@ -238,7 +237,7 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
// TODO bug
- //setCurrentItemShowing(MINUTE_INDEX, true, false, true);
+ setCurrentItemShowing(MINUTE_INDEX, true, false, true);
mTimePicker.tryVibrate();
if(onClickTimeListener != null)
onClickTimeListener.onClick(mMinuteView);
@@ -366,7 +365,6 @@ private void attributeHour(int value, boolean announce) {
CharSequence text = String.format(format, value);
mHourView.setText(text);
- mHourSpaceView.setText(text);
if (announce) {
Utils.tryAccessibilityAnnounce(mTimePicker, text);
}
@@ -385,7 +383,6 @@ private void attributeMinute(int value) {
CharSequence text = String.format(Locale.getDefault(), "%02d", value);
Utils.tryAccessibilityAnnounce(mTimePicker, text);
mMinuteView.setText(text);
- mMinuteSpaceView.setText(text);
}
// Show either Hours or Minutes.
@@ -627,10 +624,8 @@ private void updateDisplay(boolean allowEmptyDisplay) {
String minuteStr = (values[1] == -1) ? mDoublePlaceholderText :
String.format(minuteFormat, values[1]).replace(' ', mPlaceholderText);
mHourView.setText(hourStr);
- mHourSpaceView.setText(hourStr);
//mHourView.setTextColor(mColor);
mMinuteView.setText(minuteStr);
- mMinuteSpaceView.setText(minuteStr);
//mMinuteView.setTextColor(mColor);
if (!mIs24HourMode) {
updateAmPmDisplay(values[2]);
diff --git a/switchdatetime/src/main/res/layout-ldrtl-v17/time_header_label.xml b/switchdatetime/src/main/res/layout-ldrtl-v17/time_header_label.xml
index d9b44a7..26c3d59 100644
--- a/switchdatetime/src/main/res/layout-ldrtl-v17/time_header_label.xml
+++ b/switchdatetime/src/main/res/layout-ldrtl-v17/time_header_label.xml
@@ -16,45 +16,9 @@
-->
-
-
-
-
-
-
+
+
+ style="@style/Theme.SwitchDateTime.TimeLabelText" />
-
-
-
+ style="@style/Theme.SwitchDateTime.TimeLabelText" />
+
+ style="@style/Theme.SwitchDateTime.TimeLabelAmPm" />
\ No newline at end of file
diff --git a/switchdatetime/src/main/res/layout/time_header_label.xml b/switchdatetime/src/main/res/layout/time_header_label.xml
index 1b8b7be..f187f31 100644
--- a/switchdatetime/src/main/res/layout/time_header_label.xml
+++ b/switchdatetime/src/main/res/layout/time_header_label.xml
@@ -16,48 +16,10 @@
-->
-
-
-
-
-
-
+
+
+
+ style="@style/Theme.SwitchDateTime.TimeLabelText" />
-
-
-
+ style="@style/Theme.SwitchDateTime.TimeLabelText" />
+
+ style="@style/Theme.SwitchDateTime.TimeLabelAmPm" />
\ No newline at end of file