Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Change Log
## Version 1.3 *(15.2.2021)*

* Adding number of days to display functionality
* Fix bug in selectDay

## Version 1.2 *(11.6.2016)*

Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

In chronological order:

* [Your name or handle] <[email or website]>
* [Brief summary of your changes]
* Tony Awino <[tonyawino](https://github.com\/tonyawino)>
* Adding number of days to display functionality
* Fix bug in selectDay
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:4.1.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -14,6 +15,7 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
}
}
Expand Down
13 changes: 7 additions & 6 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "23.0.3"
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "solar.blaz.date.week.example"
minSdkVersion 15
targetSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
Expand All @@ -20,8 +20,9 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile project(':week-date-picker')
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'org.threeten:threetenbp:1.3.1'
implementation project(':week-date-picker')

testCompile 'junit:junit:4.12'
testImplementation 'junit:junit:4.12'
}
3 changes: 2 additions & 1 deletion example/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
app:wdp_labelPadding="5dp"
app:wdp_dayBackground="@drawable/date_picker_day_bg"
app:wdp_indicatorDrawable="@drawable/date_picker_indicator"
app:wdp_firstDayOfWeek="monday"/>
app:wdp_firstDayOfWeek="monday"
app:wdp_numDaysToDisplay="7"/>

</LinearLayout>
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
18 changes: 9 additions & 9 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
}

dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
}
}
Expand All @@ -14,15 +14,15 @@ apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

group = 'solar.blaz'
version = '1.2'
version = '1.3'

android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "23.0.3"
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
targetSdkVersion 30
versionCode 3
versionName project.version
}
Expand All @@ -36,13 +36,13 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'org.threeten:threetenbp:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'org.threeten:threetenbp:1.3.1'
}

bintray {
user = bintrayUser
key = bintrayKey
//user = bintrayUser
//key = bintrayKey

publish = true

Expand Down
26 changes: 17 additions & 9 deletions library/src/main/java/solar/blaz/date/week/WeekDatePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.text.TextDirectionHeuristicCompat;
import android.support.v4.text.TextDirectionHeuristicsCompat;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.text.TextDirectionHeuristicCompat;
import androidx.core.text.TextDirectionHeuristicsCompat;
import android.text.BoringLayout;
import android.text.Layout;
import android.text.TextPaint;
Expand Down Expand Up @@ -81,6 +81,7 @@ public class WeekDatePicker extends View {
private final DayOfWeek firstDayOfWeek;
private final BoringLayout[] layouts = new BoringLayout[3 * 7]; // we are drawing 3 weeks at a time on screen
private final BoringLayout[] dayLabelLayouts = new BoringLayout[7];
private final int numDaysToDisplay;

@Nullable private final CharSequence[] labelNames;

Expand Down Expand Up @@ -198,6 +199,13 @@ public WeekDatePicker(Context context, AttributeSet attrs, int defStyle) {

int dayOfWeek = a.getInt(R.styleable.WeekDatePicker_wdp_firstDayOfWeek, DayOfWeek.SUNDAY.getValue());
firstDayOfWeek = DayOfWeek.of(dayOfWeek);
int numDays = a.getInt(R.styleable.WeekDatePicker_wdp_numDaysToDisplay, 7);
if (numDays<=7 && numDays>0) {
numDaysToDisplay = numDays;
}
else {
numDaysToDisplay=7;
}

} finally {
a.recycle();
Expand Down Expand Up @@ -271,7 +279,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
measuredWidth = width;
}

int totalHeight = (int) (labelTextHeight + measuredWidth / 7 / 3 * 2 + labelPadding);
int totalHeight = (int) (labelTextHeight + measuredWidth / numDaysToDisplay / 3 * 2 + labelPadding);

if (heightMode == MeasureSpec.AT_MOST) {
height = Math.min(heightSize, totalHeight);
Expand Down Expand Up @@ -316,7 +324,7 @@ private void drawWeek(Canvas canvas, int layoutIndex, int weekOffset) {
int centerY = layouts[0].getHeight() / 2;
float dateLineOffset = circleRadius - centerY;

for (int i = 0; i < 7; i++) {
for (int i = 0; i < numDaysToDisplay; i++) {

int itemIndex = weekOffset * 7 + i;
BoringLayout layout = layouts[layoutIndex + i];
Expand Down Expand Up @@ -817,7 +825,7 @@ public void setDateIndicator(@NonNull LocalDate date, boolean enabled) {
}

private int getDayForDate(@NonNull LocalDate date) {
return firstDay.until(date).getDays();
return (int) (date.toEpochDay() - firstDay.toEpochDay());
}

@Override
Expand All @@ -837,7 +845,7 @@ private int getDayPositionFromTouch(float x) {
int weekPositionFromTouch = getWeekPositionFromTouch(x);
int position = weekPositionFromTouch * 7 + getRelativeDayPositionFromTouch(x);
if (weekPositionFromTouch < 0) {
position += 6;
position += (numDaysToDisplay-1);
}
return position;
}
Expand Down Expand Up @@ -945,7 +953,7 @@ private void calculateItemSize(int w, int h) {
int items = 1;
int totalPadding = ((int) dividerSize * (items - 1));
weekWidth = (w - totalPadding) / items;
dayWidth = weekWidth / 7;
dayWidth = weekWidth / numDaysToDisplay;

scrollToItem(selectedWeek);

Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<enum name="sunday" value="7" />
<enum name="monday" value="1" />
</attr>
<attr name="wdp_numDaysToDisplay" format="integer"/>
</declare-styleable>

<attr name="weekDatePickerStyle" format="reference" />
Expand Down