Skip to content

Commit

Permalink
add dismiss listener to all pickers
Browse files Browse the repository at this point in the history
  • Loading branch information
fchauveau committed Dec 11, 2016
1 parent dfb85fd commit 581ec03
Show file tree
Hide file tree
Showing 26 changed files with 954 additions and 153 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.codetroopers.betterpickers;

import android.content.DialogInterface;

public interface OnDialogDismissListener {

void onDialogDismiss(DialogInterface dialoginterface);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import android.widget.TextView;

import com.codetroopers.betterpickers.HapticFeedbackController;
import com.codetroopers.betterpickers.OnDialogDismissListener;
import com.codetroopers.betterpickers.R;
import com.codetroopers.betterpickers.Utils;
import com.codetroopers.betterpickers.calendardatepicker.MonthAdapter.CalendarDay;
Expand Down Expand Up @@ -144,11 +145,6 @@ public interface OnDateChangedListener {
public void onDateChanged();
}

public static interface OnDialogDismissListener {

public abstract void onDialogDismiss(DialogInterface dialoginterface);
}

public CalendarDatePickerDialogFragment() {
// Empty constructor required for dialog fragment.
mStyleResId = R.style.BetterPickersRadialTimePickerDialog_PrimaryColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.v4.app.FragmentTransaction;
import android.util.Log;

import com.codetroopers.betterpickers.OnDialogDismissListener;
import com.codetroopers.betterpickers.datepicker.DatePickerDialogFragment.DatePickerDialogHandler;

import java.util.Vector;
Expand All @@ -23,6 +24,7 @@ public class DatePickerBuilder {
private Boolean yearOptional = false;
private int mReference = -1;
private Vector<DatePickerDialogHandler> mDatePickerDialogHandlers = new Vector<DatePickerDialogHandler>();
private OnDialogDismissListener mOnDismissListener;

/**
* Attach a FragmentManager. This is required for creation of the Fragment.
Expand Down Expand Up @@ -141,6 +143,12 @@ public DatePickerBuilder removeDatePickerDialogHandler(DatePickerDialogHandler h
return this;
}


public DatePickerBuilder setOnDismissListener(OnDialogDismissListener onDismissListener) {
this.mOnDismissListener = onDismissListener;
return this;
}

/**
* Instantiate and show the Picker
*/
Expand All @@ -163,6 +171,7 @@ public void show() {
fragment.setTargetFragment(targetFragment, 0);
}
fragment.setDatePickerDialogHandlers(mDatePickerDialogHandlers);
fragment.setOnDismissListener(mOnDismissListener);
fragment.show(ft, "date_dialog");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codetroopers.betterpickers.datepicker;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.os.Bundle;
Expand All @@ -11,6 +12,7 @@
import android.view.ViewGroup;
import android.widget.Button;

import com.codetroopers.betterpickers.OnDialogDismissListener;
import com.codetroopers.betterpickers.R;

import java.util.Vector;
Expand Down Expand Up @@ -40,6 +42,7 @@ public class DatePickerDialogFragment extends DialogFragment {
private ColorStateList mTextColor;
private int mDialogBackgroundResId;
private Vector<DatePickerDialogHandler> mDatePickerDialogHandlers = new Vector<DatePickerDialogHandler>();
private OnDialogDismissListener mDismissCallback;

/**
* Create an instance of the Picker (used internally)
Expand All @@ -52,7 +55,7 @@ public class DatePickerDialogFragment extends DialogFragment {
* @return a Picker!
*/
public static DatePickerDialogFragment newInstance(int reference, int themeResId, Integer monthOfYear,
Integer dayOfMonth, Integer year, Boolean yearOptional) {
Integer dayOfMonth, Integer year, Boolean yearOptional) {
final DatePickerDialogFragment frag = new DatePickerDialogFragment();
Bundle args = new Bundle();
args.putInt(REFERENCE_KEY, reference);
Expand Down Expand Up @@ -160,12 +163,16 @@ public void onClick(View view) {
return view;
}

/**
* This interface allows objects to register for the Picker's set action.
*/
public interface DatePickerDialogHandler {
@Override
public void onDismiss(DialogInterface dialoginterface) {
super.onDismiss(dialoginterface);
if (mDismissCallback != null) {
mDismissCallback.onDialogDismiss(dialoginterface);
}
}

void onDialogDateSet(int reference, int year, int monthOfYear, int dayOfMonth);
public void setOnDismissListener(OnDialogDismissListener ondialogdismisslistener) {
mDismissCallback = ondialogdismisslistener;
}

/**
Expand All @@ -176,4 +183,12 @@ public interface DatePickerDialogHandler {
public void setDatePickerDialogHandlers(Vector<DatePickerDialogHandler> handlers) {
mDatePickerDialogHandlers = handlers;
}

/**
* This interface allows objects to register for the Picker's set action.
*/
public interface DatePickerDialogHandler {

void onDialogDateSet(int reference, int year, int monthOfYear, int dayOfMonth);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.v4.app.FragmentTransaction;
import android.util.Log;

import com.codetroopers.betterpickers.OnDialogDismissListener;
import com.codetroopers.betterpickers.expirationpicker.ExpirationPickerDialogFragment.ExpirationPickerDialogHandler;

import java.util.Vector;
Expand All @@ -22,6 +23,7 @@ public class ExpirationPickerBuilder {
private Integer year;
private int mReference = -1;
private Vector<ExpirationPickerDialogHandler> mExpirationPickerDialogHandlers = new Vector<ExpirationPickerDialogHandler>();
private OnDialogDismissListener mOnDismissListener;

/**
* Attach a FragmentManager. This is required for creation of the Fragment.
Expand Down Expand Up @@ -150,6 +152,12 @@ public void show() {
fragment.setTargetFragment(targetFragment, 0);
}
fragment.setExpirationPickerDialogHandlers(mExpirationPickerDialogHandlers);
fragment.setOnDismissListener(mOnDismissListener);
fragment.show(ft, "expiration_dialog");
}

public ExpirationPickerBuilder setOnDismissListener(OnDialogDismissListener onDismissListener) {
this.mOnDismissListener = onDismissListener;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codetroopers.betterpickers.expirationpicker;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.os.Bundle;
Expand All @@ -11,6 +12,7 @@
import android.view.ViewGroup;
import android.widget.Button;

import com.codetroopers.betterpickers.OnDialogDismissListener;
import com.codetroopers.betterpickers.R;

import java.util.Vector;
Expand All @@ -37,6 +39,7 @@ public class ExpirationPickerDialogFragment extends DialogFragment {
private int mDialogBackgroundResId;
private Vector<ExpirationPickerDialogHandler> mExpirationPickerDialogHandlers = new Vector<ExpirationPickerDialogHandler>();
private ColorStateList mTextColor;
private OnDialogDismissListener mDismissCallback;

/**
* Create an instance of the Picker (used internally)
Expand Down Expand Up @@ -161,6 +164,19 @@ public void onClick(View view) {
return view;
}


@Override
public void onDismiss(DialogInterface dialoginterface) {
super.onDismiss(dialoginterface);
if (mDismissCallback != null) {
mDismissCallback.onDialogDismiss(dialoginterface);
}
}

public void setOnDismissListener(OnDialogDismissListener ondialogdismisslistener) {
mDismissCallback = ondialogdismisslistener;
}

/**
* This interface allows objects to register for the Picker's set action.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.support.v4.app.FragmentTransaction;
import android.util.Log;

import com.codetroopers.betterpickers.OnDialogDismissListener;

import java.util.Vector;

/**
Expand All @@ -21,6 +23,7 @@ public class HmsPickerBuilder {
private int mMinutes;
private int mSeconds;
private Integer plusMinusVisibility;
private OnDialogDismissListener mOnDismissListener;

/**
* Set the visibility of the +/- button. This takes an int corresponding to Android's View.VISIBLE, View.INVISIBLE,
Expand Down Expand Up @@ -171,11 +174,16 @@ public void show() {
if ((mHours | mMinutes | mSeconds) != 0) {
fragment.setTime(mHours, mMinutes, mSeconds);
}

fragment.setOnDismissListener(mOnDismissListener);
fragment.show(ft, "hms_dialog");
}

private static int bounded(int i, int min, int max) {
return Math.min(Math.max(i, min), max);
}

public HmsPickerBuilder setOnDismissListener(OnDialogDismissListener onDismissListener) {
this.mOnDismissListener = onDismissListener;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codetroopers.betterpickers.hmspicker;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.os.Bundle;
Expand All @@ -11,14 +12,15 @@
import android.view.ViewGroup;
import android.widget.Button;

import com.codetroopers.betterpickers.OnDialogDismissListener;
import com.codetroopers.betterpickers.R;

import java.util.Vector;

/**
* Dialog to set alarm time.
*/
public class HmsPickerDialogFragment extends DialogFragment {
public class HmsPickerDialogFragment extends DialogFragment {

private static final String REFERENCE_KEY = "HmsPickerDialogFragment_ReferenceKey";
private static final String THEME_RES_ID_KEY = "HmsPickerDialogFragment_ThemeResIdKey";
Expand All @@ -35,6 +37,7 @@ public class HmsPickerDialogFragment extends DialogFragment {
private int mMinutes;
private int mSeconds;
private int mPlusMinusVisibility = View.INVISIBLE;
private OnDialogDismissListener mDismissCallback;

/**
* Create an instance of the Picker (used internally)
Expand Down Expand Up @@ -102,7 +105,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
HmsPickerDialogFragment.this.dismiss();
}
});
doneButton.setTextColor(mTextColor);
Expand Down Expand Up @@ -141,14 +144,27 @@ public void onClick(View view) {
return view;
}


@Override
public void onDismiss(DialogInterface dialoginterface) {
super.onDismiss(dialoginterface);
if (mDismissCallback != null) {
mDismissCallback.onDialogDismiss(dialoginterface);
}
}

public void setOnDismissListener(OnDialogDismissListener ondialogdismisslistener) {
mDismissCallback = ondialogdismisslistener;
}

public interface HmsPickerDialogHandlerV2 {

void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds);
}

/**
* @param handlers a Vector of handlers
* Attach a Vector of handlers to be notified in addition to the Fragment's Activity and target Fragment.
* Attach a Vector of handlers to be notified in addition to the Fragment's Activity and target Fragment.
*/
public void setHmsPickerDialogHandlersV2(Vector<HmsPickerDialogHandlerV2> handlers) {
mHmsPickerDialogHandlerV2s = handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.v4.app.FragmentTransaction;
import android.util.Log;

import com.codetroopers.betterpickers.OnDialogDismissListener;
import com.codetroopers.betterpickers.numberpicker.NumberPickerDialogFragment.NumberPickerDialogHandlerV2;

import java.math.BigDecimal;
Expand All @@ -28,6 +29,7 @@ public class NumberPickerBuilder {
private Integer currentNumberValue;
private Double currentDecimalValue;
private Integer currentSignValue;
private OnDialogDismissListener mOnDismissListener;

/**
* Attach a FragmentManager. This is required for creation of the Fragment.
Expand Down Expand Up @@ -220,6 +222,12 @@ public void show() {
fragment.setTargetFragment(targetFragment, 0);
}
fragment.setNumberPickerDialogHandlersV2(mNumberPickerDialogHandlersV2);
fragment.setOnDismissListener(mOnDismissListener);
fragment.show(ft, "number_dialog");
}

public NumberPickerBuilder setOnDismissListener(OnDialogDismissListener onDismissListener) {
this.mOnDismissListener = onDismissListener;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codetroopers.betterpickers.numberpicker;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.os.Bundle;
Expand All @@ -11,6 +12,7 @@
import android.view.ViewGroup;
import android.widget.Button;

import com.codetroopers.betterpickers.OnDialogDismissListener;
import com.codetroopers.betterpickers.R;

import java.math.BigDecimal;
Expand Down Expand Up @@ -49,6 +51,8 @@ public class NumberPickerDialogFragment extends DialogFragment {
private int mPlusMinusVisibility = View.VISIBLE;
private int mDecimalVisibility = View.VISIBLE;
private Vector<NumberPickerDialogHandlerV2> mNumberPickerDialogHandlersV2 = new Vector<NumberPickerDialogHandlerV2>();
private OnDialogDismissListener mDismissCallback;


/**
* Create an instance of the Picker (used internally)
Expand Down Expand Up @@ -237,6 +241,18 @@ private boolean isSmaller(BigDecimal number) {
return number.compareTo(mMinNumber) < 0;
}

@Override
public void onDismiss(DialogInterface dialoginterface) {
super.onDismiss(dialoginterface);
if (mDismissCallback != null) {
mDismissCallback.onDialogDismiss(dialoginterface);
}
}

public void setOnDismissListener(OnDialogDismissListener ondialogdismisslistener) {
mDismissCallback = ondialogdismisslistener;
}

/**
* This interface allows objects to register for the Picker's set action.
*/
Expand All @@ -252,4 +268,9 @@ public interface NumberPickerDialogHandlerV2 {
public void setNumberPickerDialogHandlersV2(Vector<NumberPickerDialogHandlerV2> handlers) {
this.mNumberPickerDialogHandlersV2 = handlers;
}

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
}
}
Loading

0 comments on commit 581ec03

Please sign in to comment.