Skip to content

Commit

Permalink
Add feature in pull request #18 and upgrade gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmidmozaffar authored and J-Jamet committed Jun 12, 2017
1 parent fbab567 commit f73eee6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ protected void onCreate(Bundle savedInstanceState) {
if(dateTimeFragment == null) {
dateTimeFragment = SwitchDateTimeDialogFragment.newInstance(
getString(R.string.label_datetime_dialog),
getString(R.string.positive_button_datetime_picker),
getString(R.string.negative_button_datetime_picker)
getString(android.R.string.ok),
getString(android.R.string.cancel)
);
}

Expand Down Expand Up @@ -100,4 +100,4 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putCharSequence(STATE_TEXTVIEW, textView.getText());
super.onSaveInstanceState(savedInstanceState);
}
}
}
1 change: 0 additions & 1 deletion sample/src/main/res/layout/activity_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@
android:layout_below="@+id/button"
android:layout_centerHorizontal="true" />


</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
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;
Expand Down Expand Up @@ -124,24 +125,26 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
mNegativeButton = getArguments().getString(TAG_NEGATIVE_BUTTON);
}

if (savedInstanceState != null) {
if (!assignDefaultDateTimeCalendar && savedInstanceState != null) {
// Restore value from saved state
dateTimeCalendar.setTime(new Date(savedInstanceState.getLong(STATE_DATETIME)));
}

// Init values with current time if setDefault is not used
if(year == UNDEFINED_TIME_VALUE)
if(assignDefaultDateTimeCalendar || year == UNDEFINED_TIME_VALUE)
year = dateTimeCalendar.get(Calendar.YEAR);
if(month == UNDEFINED_TIME_VALUE)
if(assignDefaultDateTimeCalendar || month == UNDEFINED_TIME_VALUE)
month = dateTimeCalendar.get(Calendar.MONTH);
if(day == UNDEFINED_TIME_VALUE)
if(assignDefaultDateTimeCalendar || day == UNDEFINED_TIME_VALUE)
day = dateTimeCalendar.get(Calendar.DAY_OF_MONTH);
if(hourOfDay == UNDEFINED_TIME_VALUE)
if(assignDefaultDateTimeCalendar || hourOfDay == UNDEFINED_TIME_VALUE)
hourOfDay = dateTimeCalendar.get(Calendar.HOUR_OF_DAY);
if(minute == UNDEFINED_TIME_VALUE)
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 "
Expand Down Expand Up @@ -311,7 +314,7 @@ public void onYearSelected(View view, int yearPicker) {
}
db.setView(dateTimeLayout);
if(mPositiveButton == null)
mPositiveButton = getString(R.string.positive_button_datetime_picker);
mPositiveButton = getString(android.R.string.ok);
db.setPositiveButton(mPositiveButton, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Expand All @@ -322,7 +325,7 @@ public void onClick(DialogInterface dialog, int which) {
}
});
if(mNegativeButton == null)
mNegativeButton = getString(R.string.negative_button_datetime_picker);
mNegativeButton = getString(android.R.string.cancel);
db.setNegativeButton(mNegativeButton, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -503,6 +506,7 @@ public int getMinute() {
*/
public void setDefaultDateTime(Date date) {
this.dateTimeCalendar.setTime(date);
this.assignDefaultDateTimeCalendar = true;
}

/**
Expand Down
1 change: 1 addition & 0 deletions switchdatetime/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<!-- Title -->
<string name="label_datetime_dialog">DateTime</string>

<!-- deprecated, use android.R.string.ok and android.R.string.cancel instead -->
<string name="positive_button_datetime_picker">OK</string>
<string name="negative_button_datetime_picker">Cancel</string>

Expand Down

0 comments on commit f73eee6

Please sign in to comment.