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

Improves flexibility of Date and Time DialogFragmentDelegates #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import android.graphics.Paint;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.widget.TextView;

import io.doist.datetimepicker.R;

public class TextViewWithCircularIndicator extends TextView {
public class TextViewWithCircularIndicator extends AppCompatTextView {

private static final int SELECTED_CIRCLE_ALPHA = 60;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class DatePickerDialogFragment extends DialogFragment {
public static final String TAG = DatePickerDialogFragment.class.getName();

private DatePickerDialogFragmentDelegate mDelegate;
protected DatePickerDialogFragmentDelegate mDelegate;

public DatePickerDialogFragment() {
mDelegate = onCreateDatePickerDialogFragmentDelegate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class DatePickerDialogFragmentCompat extends DialogFragment {
public static final String TAG = DatePickerDialogFragmentCompat.class.getName();

private DatePickerDialogFragmentDelegate mDelegate;
protected DatePickerDialogFragmentDelegate mDelegate;

public DatePickerDialogFragmentCompat() {
mDelegate = onCreateDatePickerDialogFragmentDelegate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class DatePickerDialogFragmentDelegate extends PickerDialogFragmentDelega
private static final String KEY_MONTH_OF_YEAR = "month";
private static final String KEY_DAY_OF_MONTH = "day";

private DatePicker mDatePicker;
protected DatePicker mDatePicker;

private OnDateSetListener mOnDateSetListener;
protected OnDateSetListener mOnDateSetListener;

public static Bundle createArguments(int year, int monthOfYear, int dayOfMonth) {
Bundle arguments = new Bundle();
Expand Down Expand Up @@ -80,15 +80,19 @@ public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfM
mDatePicker.init(year, monthOfYear, dayOfMonth, this);
}

public void setOnDateSetListener(OnDateSetListener listener) {
mOnDateSetListener = listener;
public void updateDate(int year, int monthOfYear, int dayOfMonth) {
mDatePicker.updateDate(year, monthOfYear, dayOfMonth);
}

public DatePicker getDatePicker() {
return mDatePicker;
}

public void updateDate(int year, int monthOfYear, int dayOfMonth) {
mDatePicker.updateDate(year, monthOfYear, dayOfMonth);
public void setOnDateSetListener(OnDateSetListener listener) {
mOnDateSetListener = listener;
}

public OnDateSetListener getOnDateSetListener() {
return mOnDateSetListener;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class TimePickerDialogFragment extends DialogFragment {
public static final String TAG = TimePickerDialogFragment.class.getName();

private TimePickerDialogFragmentDelegate mDelegate;
protected TimePickerDialogFragmentDelegate mDelegate;

public TimePickerDialogFragment() {
mDelegate = onCreateTimePickerDialogFragmentDelegate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class TimePickerDialogFragmentCompat extends DialogFragment {
public static final String TAG = TimePickerDialogFragmentCompat.class.getName();

private TimePickerDialogFragmentDelegate mDelegate;
protected TimePickerDialogFragmentDelegate mDelegate;

public TimePickerDialogFragmentCompat() {
mDelegate = onCreateTimePickerDialogFragmentDelegate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class TimePickerDialogFragmentDelegate extends PickerDialogFragmentDelega
private static final String KEY_MINUTE = "minute";
private static final String KEY_IS_24_HOUR = "is24Hour";

private TimePicker mTimePicker;
protected TimePicker mTimePicker;

private OnTimeSetListener mOnTimeSetListener;
protected OnTimeSetListener mOnTimeSetListener;

public static Bundle createArguments(int hourOfDay, int minute, boolean is24Hour) {
Bundle arguments = new Bundle();
Expand Down Expand Up @@ -77,21 +77,25 @@ public void onClick(DialogInterface dialog, int which) {
});
}

public void setOnTimeSetListener(OnTimeSetListener listener) {
mOnTimeSetListener = listener;
}

@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// Do nothing.
}

public void updateTime(int hourOfDay, int minuteOfHour) {
mTimePicker.setCurrentHour(hourOfDay);
mTimePicker.setCurrentMinute(minuteOfHour);
}

public TimePicker getTimePicker() {
return mTimePicker;
}

public void updateTime(int hourOfDay, int minuteOfHour) {
mTimePicker.setCurrentHour(hourOfDay);
mTimePicker.setCurrentMinute(minuteOfHour);
public void setOnTimeSetListener(OnTimeSetListener listener) {
mOnTimeSetListener = listener;
}

public OnTimeSetListener getOnTimeSetListener() {
return mOnTimeSetListener;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,43 +339,9 @@ public RadialTimePickerView(Context context, AttributeSet attrs, int defStyleAtt
mPaintCenter.setAntiAlias(true);
mPaintCenter.setTextAlign(Paint.Align.CENTER);

mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint();
mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true);
mColorSelector[HOURS][SELECTOR_CIRCLE] = a.getColor(
R.styleable.TimePicker_numbersSelectorColor,
ContextCompat.getColor(context, R.color.timepicker_default_selector_color_material));

mPaintSelector[HOURS][SELECTOR_DOT] = new Paint();
mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true);
mColorSelector[HOURS][SELECTOR_DOT] = a.getColor(
setSelectorColor(a.getColor(
R.styleable.TimePicker_numbersSelectorColor,
ContextCompat.getColor(context, R.color.timepicker_default_selector_color_material));

mPaintSelector[HOURS][SELECTOR_LINE] = new Paint();
mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true);
mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2);
mColorSelector[HOURS][SELECTOR_LINE] = a.getColor(
R.styleable.TimePicker_numbersSelectorColor,
ContextCompat.getColor(context, R.color.timepicker_default_selector_color_material));

mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint();
mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true);
mColorSelector[MINUTES][SELECTOR_CIRCLE] = a.getColor(
R.styleable.TimePicker_numbersSelectorColor,
ContextCompat.getColor(context, R.color.timepicker_default_selector_color_material));

mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint();
mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true);
mColorSelector[MINUTES][SELECTOR_DOT] = a.getColor(
R.styleable.TimePicker_numbersSelectorColor,
ContextCompat.getColor(context, R.color.timepicker_default_selector_color_material));

mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint();
mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true);
mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2);
mColorSelector[MINUTES][SELECTOR_LINE] = a.getColor(
R.styleable.TimePicker_numbersSelectorColor,
ContextCompat.getColor(context, R.color.timepicker_default_selector_color_material));
ContextCompat.getColor(context, R.color.timepicker_default_selector_color_material)));

mPaintBackground.setColor(a.getColor(R.styleable.TimePicker_numbersBackgroundColor,
res.getColor(R.color.timepicker_default_numbers_background_color_material)));
Expand Down Expand Up @@ -431,6 +397,34 @@ public RadialTimePickerView(Context context, AttributeSet attrs, int defStyleAtt
setHapticFeedbackEnabled(true);
}

public void setSelectorColor(int color) {
mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint();
mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true);
mColorSelector[HOURS][SELECTOR_CIRCLE] = color;

mPaintSelector[HOURS][SELECTOR_DOT] = new Paint();
mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true);
mColorSelector[HOURS][SELECTOR_DOT] = color;

mPaintSelector[HOURS][SELECTOR_LINE] = new Paint();
mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true);
mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2);
mColorSelector[HOURS][SELECTOR_LINE] = color;

mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint();
mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true);
mColorSelector[MINUTES][SELECTOR_CIRCLE] = color;

mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint();
mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true);
mColorSelector[MINUTES][SELECTOR_DOT] = color;

mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint();
mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true);
mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2);
mColorSelector[MINUTES][SELECTOR_LINE] = color;
}

/**
* Measure the view to end up as a square, based on the minimum of the height and width.
*/
Expand Down