Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 800491b

Browse files
committed
deprecate previous handler that not contains negative param
1 parent ef6f9fa commit 800491b

File tree

12 files changed

+76
-35
lines changed

12 files changed

+76
-35
lines changed

library/src/main/java/com/codetroopers/betterpickers/hmspicker/HmsPickerBuilder.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class HmsPickerBuilder {
1919
private Fragment targetFragment;
2020
private int mReference;
2121
private Vector<HmsPickerDialogHandler> mHmsPickerDialogHandlers = new Vector<HmsPickerDialogHandler>();
22+
private Vector<HmsPickerDialogFragment.HmsPickerDialogHandlerV2> mHmsPickerDialogHandlerV2s = new Vector<HmsPickerDialogFragment.HmsPickerDialogHandlerV2>();
2223
private int mHours;
2324
private int mMinutes;
2425
private int mSeconds;
@@ -84,6 +85,32 @@ public HmsPickerBuilder setReference(int reference) {
8485
return this;
8586
}
8687

88+
/**
89+
* @param handler an Object implementing the appropriate Picker Handler
90+
* @return the current Builder object
91+
* @Deprecated : use HmsPickerDialogHandlerV2 that return negative/positive status
92+
* <p/>
93+
* Attach universal objects as additional handlers for notification when the Picker is set. For most use cases, this
94+
* method is not necessary as attachment to an Activity or Fragment is done automatically. If, however, you would
95+
* like additional objects to subscribe to this Picker being set, attach Handlers here.
96+
*/
97+
public HmsPickerBuilder addHmsPickerDialogHandler(HmsPickerDialogHandler handler) {
98+
this.mHmsPickerDialogHandlers.add(handler);
99+
return this;
100+
}
101+
102+
/**
103+
* @param handler the Object to remove
104+
* @return the current Builder object
105+
* @Deprecated : use HmsPickerDialogHandlerV2 that return negative/positive status
106+
* <p/>
107+
* Remove objects previously added as handlers.
108+
*/
109+
public HmsPickerBuilder removeHmsPickerDialogHandler(HmsPickerDialogHandler handler) {
110+
this.mHmsPickerDialogHandlers.remove(handler);
111+
return this;
112+
}
113+
87114
/**
88115
* Attach universal objects as additional handlers for notification when the Picker is set. For most use cases, this
89116
* method is not necessary as attachment to an Activity or Fragment is done automatically. If, however, you would
@@ -92,8 +119,8 @@ public HmsPickerBuilder setReference(int reference) {
92119
* @param handler an Object implementing the appropriate Picker Handler
93120
* @return the current Builder object
94121
*/
95-
public HmsPickerBuilder addHmsPickerDialogHandler(HmsPickerDialogHandler handler) {
96-
this.mHmsPickerDialogHandlers.add(handler);
122+
public HmsPickerBuilder addHmsPickerDialogHandler(HmsPickerDialogFragment.HmsPickerDialogHandlerV2 handler) {
123+
this.mHmsPickerDialogHandlerV2s.add(handler);
97124
return this;
98125
}
99126

@@ -103,15 +130,15 @@ public HmsPickerBuilder addHmsPickerDialogHandler(HmsPickerDialogHandler handler
103130
* @param handler the Object to remove
104131
* @return the current Builder object
105132
*/
106-
public HmsPickerBuilder removeHmsPickerDialogHandler(HmsPickerDialogHandler handler) {
107-
this.mHmsPickerDialogHandlers.remove(handler);
133+
public HmsPickerBuilder removeHmsPickerDialogHandler(HmsPickerDialogFragment.HmsPickerDialogHandlerV2 handler) {
134+
this.mHmsPickerDialogHandlerV2s.remove(handler);
108135
return this;
109136
}
110137

111138
/**
112139
* Set some initial values for the picker
113140
*
114-
* @param hours the initial hours value
141+
* @param hours the initial hours value
115142
* @param minutes the initial minutes value
116143
* @param seconds the initial seconds value
117144
* @return the current Builder object
@@ -168,6 +195,7 @@ public void show() {
168195
fragment.setTargetFragment(targetFragment, 0);
169196
}
170197
fragment.setHmsPickerDialogHandlers(mHmsPickerDialogHandlers);
198+
fragment.setHmsPickerDialogHandlersV2(mHmsPickerDialogHandlerV2s);
171199

172200
if ((mHours | mMinutes | mSeconds) != 0) {
173201
fragment.setTime(mHours, mMinutes, mSeconds);

library/src/main/java/com/codetroopers/betterpickers/hmspicker/HmsPickerDialogFragment.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public class HmsPickerDialogFragment extends DialogFragment {
3030
private int mTheme = -1;
3131
private ColorStateList mTextColor;
3232
private int mDialogBackgroundResId;
33+
@Deprecated
3334
private Vector<HmsPickerDialogHandler> mHmsPickerDialogHandlers = new Vector<HmsPickerDialogHandler>();
35+
private Vector<HmsPickerDialogHandlerV2> mHmsPickerDialogHandlerV2s = new Vector<HmsPickerDialogHandlerV2>();
3436
private int mHours;
3537
private int mMinutes;
3638
private int mSeconds;
@@ -112,6 +114,10 @@ public void onClick(View view) {
112114
for (HmsPickerDialogHandler handler : mHmsPickerDialogHandlers) {
113115
handler.onDialogHmsSet(mReference, mPicker.getHours(), mPicker.getMinutes(), mPicker.getSeconds());
114116
}
117+
for (HmsPickerDialogHandlerV2 handler : mHmsPickerDialogHandlerV2s) {
118+
handler.onDialogHmsSet(mReference, mPicker.isNegative(), mPicker.getHours(), mPicker.getMinutes(), mPicker.getSeconds());
119+
}
120+
115121
final Activity activity = getActivity();
116122
final Fragment fragment = getTargetFragment();
117123

@@ -156,22 +162,34 @@ public interface HmsPickerDialogHandlerV2 {
156162
}
157163

158164
/**
165+
* @Deprecated : use HmsPickerDialogHandlerV2 that return negative/positive status
159166
* This interface allows objects to register for the Picker's set action.
160167
*/
168+
@Deprecated
161169
public interface HmsPickerDialogHandler {
162170

171+
@Deprecated
163172
void onDialogHmsSet(int reference, int hours, int minutes, int seconds);
164173
}
165174

166175
/**
167-
* Attach a Vector of handlers to be notified in addition to the Fragment's Activity and target Fragment.
168-
*
169176
* @param handlers a Vector of handlers
177+
* @Deprecated : use HmsPickerDialogHandlerV2 that return negative/positive status
178+
* Attach a Vector of handlers to be notified in addition to the Fragment's Activity and target Fragment.
170179
*/
180+
@Deprecated
171181
public void setHmsPickerDialogHandlers(Vector<HmsPickerDialogHandler> handlers) {
172182
mHmsPickerDialogHandlers = handlers;
173183
}
174184

185+
/**
186+
* @param handlers a Vector of handlers
187+
* Attach a Vector of handlers to be notified in addition to the Fragment's Activity and target Fragment.
188+
*/
189+
public void setHmsPickerDialogHandlersV2(Vector<HmsPickerDialogHandlerV2> handlers) {
190+
mHmsPickerDialogHandlerV2s = handlers;
191+
}
192+
175193
public void setTime(int hours, int minutes, int seconds) {
176194
this.mHours = hours;
177195
this.mMinutes = minutes;

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
</intent-filter>
266266
</activity>
267267
<activity
268-
android:name=".activity.hmspicker.SampleHmsBasicNegativeDurationUsage"
268+
android:name=".activity.hmspicker.SampleHmsNegativeDurationUsage"
269269
android:label="HMS/Negative Duration">
270270
<intent-filter>
271271
<action android:name="android.intent.action.MAIN" />

sample/src/main/java/com/codetroopers/betterpickers/sample/activity/hmspicker/SampleHmsBasicUsage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* User: derek Date: 3/17/13 Time: 3:59 PM
1515
*/
16-
public class SampleHmsBasicUsage extends BaseSampleActivity implements HmsPickerDialogFragment.HmsPickerDialogHandler {
16+
public class SampleHmsBasicUsage extends BaseSampleActivity implements HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
1717

1818
private TextView mResultTextView;
1919

@@ -39,7 +39,7 @@ public void onClick(View v) {
3939
}
4040

4141
@Override
42-
public void onDialogHmsSet(int reference, int hours, int minutes, int seconds) {
43-
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, hours, minutes, seconds));
42+
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
43+
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, hours, minutes, seconds, isNegative));
4444
}
4545
}

sample/src/main/java/com/codetroopers/betterpickers/sample/activity/hmspicker/SampleHmsListAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void onCreate(Bundle savedInstanceState) {
3333
list.setAdapter(new SampleAdapter(this, getSupportFragmentManager()));
3434
}
3535

36-
private class SampleAdapter extends BaseAdapter implements HmsPickerDialogFragment.HmsPickerDialogHandler {
36+
private class SampleAdapter extends BaseAdapter implements HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
3737

3838
private ArrayList<Hms> mHmses;
3939
private LayoutInflater mInflater;
@@ -115,7 +115,7 @@ public void onClick(View v) {
115115
}
116116

117117
@Override
118-
public void onDialogHmsSet(int reference, int hours, int minutes, int seconds) {
118+
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
119119
Hms hms = new Hms();
120120
hms.hours = hours;
121121
hms.minutes = minutes;

sample/src/main/java/com/codetroopers/betterpickers/sample/activity/hmspicker/SampleHmsMultipleHandlers.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
/**
1515
* User: derek Date: 3/17/13 Time: 3:59 PM
1616
*/
17-
public class SampleHmsMultipleHandlers extends BaseSampleActivity
18-
implements HmsPickerDialogFragment.HmsPickerDialogHandler {
17+
public class SampleHmsMultipleHandlers extends BaseSampleActivity implements HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
1918

2019
private TextView mResultTextView;
2120

@@ -51,7 +50,7 @@ public void onDialogHmsSet(int reference, int hours, int minutes, int seconds) {
5150
}
5251

5352
@Override
54-
public void onDialogHmsSet(int reference, int hours, int minutes, int seconds) {
55-
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, hours, minutes, seconds));
53+
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
54+
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, hours, minutes, seconds, isNegative));
5655
}
5756
}

sample/src/main/java/com/codetroopers/betterpickers/sample/activity/hmspicker/SampleHmsMultipleReferences.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
/**
1313
* User: derek Date: 3/17/13 Time: 3:59 PM
1414
*/
15-
public class SampleHmsMultipleReferences extends BaseSampleActivity
16-
implements HmsPickerDialogFragment.HmsPickerDialogHandler {
15+
public class SampleHmsMultipleReferences extends BaseSampleActivity implements HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
1716

1817
private static final int BUTTON_ONE_REFERENCE = 0;
1918
private static final int BUTTON_TWO_REFERENCE = 1;
@@ -82,7 +81,7 @@ public void onClick(View v) {
8281
}
8382

8483
@Override
85-
public void onDialogHmsSet(int reference, int hours, int minutes, int seconds) {
84+
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
8685
Button buttonToSet;
8786
switch (reference) {
8887
case BUTTON_ONE_REFERENCE:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* User: derek Date: 3/17/13 Time: 3:59 PM
1515
*/
16-
public class SampleHmsBasicNegativeDurationUsage extends BaseSampleActivity implements HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
16+
public class SampleHmsNegativeDurationUsage extends BaseSampleActivity implements HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
1717

1818
private TextView mResultTextView;
1919

@@ -41,7 +41,7 @@ public void onClick(View v) {
4141

4242
@Override
4343
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
44-
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, (isNegative ? -1 : 1) * hours, (isNegative ? -1 : 1) * minutes, (isNegative ? -1 : 1) * seconds));
44+
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, hours, minutes, seconds, isNegative));
4545
}
4646

4747
}

sample/src/main/java/com/codetroopers/betterpickers/sample/activity/hmspicker/SampleHmsThemeCustom.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
/**
1414
* User: derek Date: 3/17/13 Time: 3:59 PM
1515
*/
16-
public class SampleHmsThemeCustom extends BaseSampleActivity
17-
implements HmsPickerDialogFragment.HmsPickerDialogHandler {
16+
public class SampleHmsThemeCustom extends BaseSampleActivity implements HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
1817

1918
private TextView mResultTextView;
2019

@@ -40,7 +39,7 @@ public void onClick(View v) {
4039
}
4140

4241
@Override
43-
public void onDialogHmsSet(int reference, int hours, int minutes, int seconds) {
44-
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, hours, minutes, seconds));
42+
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
43+
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, hours, minutes, seconds, isNegative));
4544
}
4645
}

sample/src/main/java/com/codetroopers/betterpickers/sample/activity/hmspicker/SampleHmsThemeLight.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
/**
1414
* User: derek Date: 3/17/13 Time: 3:59 PM
1515
*/
16-
public class SampleHmsThemeLight extends BaseSampleActivity
17-
implements HmsPickerDialogFragment.HmsPickerDialogHandler {
16+
public class SampleHmsThemeLight extends BaseSampleActivity implements HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
1817

1918
private TextView mResultTextView;
2019

@@ -40,7 +39,7 @@ public void onClick(View v) {
4039
}
4140

4241
@Override
43-
public void onDialogHmsSet(int reference, int hours, int minutes, int seconds) {
44-
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, hours, minutes, seconds));
42+
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
43+
mResultTextView.setText(getString(R.string.hms_picker_result_value_multiline, hours, minutes, seconds, isNegative));
4544
}
4645
}

0 commit comments

Comments
 (0)