Skip to content

Commit

Permalink
Add start with specific view, change theme declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Nov 29, 2016
1 parent bb25fc9 commit b17cc9b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
10 changes: 8 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ 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.0'
compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.1'
}
```

## Usage

### SimpleDateFormat for Day and Month
You can specify a particular [*SimpleDateFormat*](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) for value of Day and Month with **setSimpleDateFormat(SimpleDateFormat format)**
You can specify a particular [*SimpleDateFormat*](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) for value of Day and Month with **setSimpleDateMonthAndDayFormat(SimpleDateFormat format)**
Warning, the format must satisfy the regular expression : **(M|w|W|D|d|F|E|u|\s)***
, for example *dd MMMM*

Expand All @@ -43,6 +43,11 @@ By default, time is in 12 hours mode, If you want a 24-hour display, use:
`dateTimeFragment.set24HoursMode(true);`
before the "show"

### Start with a specific view
For launch Dialog with a specific view, call :
`dateTimeFragment.startAtTimeView();`, `dateTimeFragment.startAtCalendarView();` or `dateTimeFragment.startAtYearView();`
before the "show"

### Style
You can customize the style to change color, bold, etc... of each element.
In your *styles.xml*, for example
Expand Down Expand Up @@ -137,6 +142,7 @@ SwitchDateTimeDialogFragment dateTimeDialogFragment = SwitchDateTimeDialogFragme
);
// Assign values
dateTimeFragment.startAtCalendarView();
dateTimeFragment.set24HoursMode(true);
dateTimeFragment.setDefaultHourOfDay(15);
dateTimeFragment.setDefaultMinute(20);
Expand Down
8 changes: 5 additions & 3 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kunzisoft.switchdatetimesample">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true">
<activity android:name="com.kunzisoft.switchdatetimesample.Sample">
<activity
android:name="com.kunzisoft.switchdatetimesample.Sample"
android:theme="@style/Theme.SwitchDateTime" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {

// Assign values we want
final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy HH:mm", java.util.Locale.getDefault());
dateTimeFragment.startAtCalendarView();
dateTimeFragment.set24HoursMode(true);
dateTimeFragment.setDefaultHourOfDay(15);
dateTimeFragment.setDefaultMinute(20);
Expand Down
3 changes: 1 addition & 2 deletions switchdatetime/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.SwitchDateTime">
android:supportsRtl="true">
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
private int minute = UNDEFINED_TIME_VALUE;

private boolean is24HoursMode = false;
private int startAtPosition = 0;

private SimpleDateFormat dayAndMonthSimpleDate;
private SimpleDateFormat yearSimpleDate;
Expand Down Expand Up @@ -184,6 +185,7 @@ public void onAnimationEnd(Animation animation) {
@Override
public void onAnimationRepeat(Animation animation) {}
});
viewSwitcher.setDisplayedChild(startAtPosition);

// Button for switch between Hours/Minutes, Calendar and YearList
ImageButton buttonSwitch = (ImageButton) dateTimeLayout.findViewById(R.id.button_switch);
Expand Down Expand Up @@ -329,6 +331,27 @@ private void assignAllValuesToCalendar() {
dateTimeCalendar.set(Calendar.SECOND, 0);
}

/**
* Define "Time" as the first view to show
*/
public void startAtTimeView() {
startAtPosition = 0;
}

/**
* Define "Calendar" as the first view to show
*/
public void startAtCalendarView() {
startAtPosition = 1;
}

/**
* Define "Year" as the first view to show
*/
public void startAtYearView() {
startAtPosition = 2;
}

/**
* Assign default year at start
* @param year
Expand Down

0 comments on commit b17cc9b

Please sign in to comment.