diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/SupportTimePickerDialogFragment.java b/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/SupportTimePickerDialogFragment.java deleted file mode 100644 index 62a448c35..000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/SupportTimePickerDialogFragment.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.modules.timepicker; - -import javax.annotation.Nullable; - -import android.app.Dialog; -import android.app.TimePickerDialog.OnTimeSetListener; -import android.content.DialogInterface; -import android.content.DialogInterface.OnDismissListener; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; - -@SuppressWarnings("ValidFragment") -public class SupportTimePickerDialogFragment extends DialogFragment { - - @Nullable - private OnTimeSetListener mOnTimeSetListener; - @Nullable - private OnDismissListener mOnDismissListener; - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - final Bundle args = getArguments(); - return TimePickerDialogFragment.createDialog(args, getActivity(), mOnTimeSetListener); - } - - @Override - public void onDismiss(DialogInterface dialog) { - super.onDismiss(dialog); - if (mOnDismissListener != null) { - mOnDismissListener.onDismiss(dialog); - } - } - - public void setOnDismissListener(@Nullable OnDismissListener onDismissListener) { - mOnDismissListener = onDismissListener; - } - - public void setOnTimeSetListener(@Nullable OnTimeSetListener onTimeSetListener) { - mOnTimeSetListener = onTimeSetListener; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogFragment.java b/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogFragment.java index a76b3b41c..749e1002e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogFragment.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogFragment.java @@ -8,14 +8,13 @@ package com.facebook.react.modules.timepicker; import android.app.Dialog; -import android.app.DialogFragment; -import android.app.TimePickerDialog; import android.app.TimePickerDialog.OnTimeSetListener; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnDismissListener; import android.os.Build; import android.os.Bundle; +import android.support.v4.app.DialogFragment; import android.text.format.DateFormat; import java.util.Calendar; diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogModule.java index f61844587..79013b4f2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogModule.java @@ -7,13 +7,13 @@ package com.facebook.react.modules.timepicker; -import android.app.Activity; -import android.app.DialogFragment; -import android.app.FragmentManager; import android.app.TimePickerDialog.OnTimeSetListener; import android.content.DialogInterface; import android.content.DialogInterface.OnDismissListener; import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; import android.widget.TimePicker; import com.facebook.react.bridge.NativeModule; @@ -92,7 +92,7 @@ public class TimePickerDialogModule extends ReactContextBaseJavaModule { @ReactMethod public void open(@Nullable final ReadableMap options, Promise promise) { - Activity activity = getCurrentActivity(); + FragmentActivity activity = (FragmentActivity) getCurrentActivity(); if (activity == null) { promise.reject( ERROR_NO_ACTIVITY, @@ -101,39 +101,20 @@ public class TimePickerDialogModule extends ReactContextBaseJavaModule { } // We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity // (for apps that use it for legacy reasons). This unfortunately leads to some code duplication. - if (activity instanceof android.support.v4.app.FragmentActivity) { - android.support.v4.app.FragmentManager fragmentManager = - ((android.support.v4.app.FragmentActivity) activity).getSupportFragmentManager(); - android.support.v4.app.DialogFragment oldFragment = - (android.support.v4.app.DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG); - if (oldFragment != null) { - oldFragment.dismiss(); - } - SupportTimePickerDialogFragment fragment = new SupportTimePickerDialogFragment(); - if (options != null) { - Bundle args = createFragmentArguments(options); - fragment.setArguments(args); - } - TimePickerDialogListener listener = new TimePickerDialogListener(promise); - fragment.setOnDismissListener(listener); - fragment.setOnTimeSetListener(listener); - fragment.show(fragmentManager, FRAGMENT_TAG); - } else { - FragmentManager fragmentManager = activity.getFragmentManager(); - DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG); - if (oldFragment != null) { - oldFragment.dismiss(); - } - TimePickerDialogFragment fragment = new TimePickerDialogFragment(); - if (options != null) { - final Bundle args = createFragmentArguments(options); - fragment.setArguments(args); - } - TimePickerDialogListener listener = new TimePickerDialogListener(promise); - fragment.setOnDismissListener(listener); - fragment.setOnTimeSetListener(listener); - fragment.show(fragmentManager, FRAGMENT_TAG); + FragmentManager fragmentManager = activity.getSupportFragmentManager(); + DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG); + if (oldFragment != null) { + oldFragment.dismiss(); } + TimePickerDialogFragment fragment = new TimePickerDialogFragment(); + if (options != null) { + Bundle args = createFragmentArguments(options); + fragment.setArguments(args); + } + TimePickerDialogListener listener = new TimePickerDialogListener(promise); + fragment.setOnDismissListener(listener); + fragment.setOnTimeSetListener(listener); + fragment.show(fragmentManager, FRAGMENT_TAG); } private Bundle createFragmentArguments(ReadableMap options) {