Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Title click listener #512

Merged
merged 5 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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 library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ android {
versionCode project.ext.versionCodeInt
versionName version
}

lintOptions {
abortOnError false
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
private OnDateSelectedListener listener;
private OnMonthChangedListener monthListener;
private OnRangeSelectedListener rangeListener;

private OnClickListener titleListener;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this being used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope


CharSequence calendarContentDescription;
private int accentColor = 0;
Expand Down Expand Up @@ -262,7 +262,6 @@ public MaterialCalendarView(Context context, AttributeSet attrs) {
buttonFuture.setContentDescription(getContext().getString(R.string.next));
pager = new CalendarPager(getContext());

title.setOnClickListener(onClickListener);
buttonPast.setOnClickListener(onClickListener);
buttonFuture.setOnClickListener(onClickListener);

Expand Down Expand Up @@ -1357,6 +1356,24 @@ public void setOnRangeSelectedListener(OnRangeSelectedListener listener) {
this.rangeListener = listener;
}

/**
* Add listener to the title.
*
* @param listener thing to be notified
*/
public void setOnTitleClickListener(final OnClickListener listener) {
if (listener != null) {
title.setOnClickListener(listener);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with setting the listener to null if it should already be guarding for null listeners

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there something wrong with setting anull click listener?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no, that's how you remove it! I will cleanup, thanks

}
}

/**
* Remove listener from title view.
*/
public void removeOnTitleClickListener() {
title.setOnClickListener(null);
}

/**
* Dispatch date change events to a listener, if set
*
Expand Down
4 changes: 4 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ android {
versionCode project.ext.versionCodeInt
versionName version
}

lintOptions {
abortOnError false
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
Expand Down Expand Up @@ -43,6 +44,14 @@ protected void onCreate(Bundle savedInstanceState) {
currentTileSize = MaterialCalendarView.DEFAULT_TILE_SIZE_DP;
currentTileWidth = MaterialCalendarView.DEFAULT_TILE_SIZE_DP;
currentTileHeight = MaterialCalendarView.DEFAULT_TILE_SIZE_DP;

widget.setOnTitleClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
Toast.makeText(DynamicSettersActivity.this, "Today is the day", Toast.LENGTH_SHORT)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string resources? or does it not matter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.show();
}
});
}

@OnClick(R.id.button_other_dates)
Expand Down