content: package com.google.android.material.timepicker;
  
  import android.app.Dialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.res.ColorStateList;
  import android.content.res.TypedArray;
  import android.os.Bundle;
  import android.text.TextUtils;
  import android.util.AttributeSet;
  import android.util.Pair;
  import android.util.TypedValue;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.ViewStub;
  import android.view.Window;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import androidx.core.view.ViewCompat;
  import androidx.fragment.app.DialogFragment;
  import com.google.android.material.R;
  import com.google.android.material.button.MaterialButton;
  import com.google.android.material.resources.MaterialAttributes;
  import com.google.android.material.shape.MaterialShapeDrawable;
  import com.google.android.material.timepicker.TimePickerView;
  import java.util.LinkedHashSet;
  import java.util.Set;
  
  public final class MaterialTimePicker extends DialogFragment implements TimePickerView.OnDoubleTapListener {
      public static final int INPUT_MODE_CLOCK = 0;
      static final String INPUT_MODE_EXTRA = "TIME_PICKER_INPUT_MODE";
      public static final int INPUT_MODE_KEYBOARD = 1;
      static final String NEGATIVE_BUTTON_TEXT_EXTRA = "TIME_PICKER_NEGATIVE_BUTTON_TEXT";
      static final String NEGATIVE_BUTTON_TEXT_RES_EXTRA = "TIME_PICKER_NEGATIVE_BUTTON_TEXT_RES";
      static final String OVERRIDE_THEME_RES_ID = "TIME_PICKER_OVERRIDE_THEME_RES_ID";
      static final String POSITIVE_BUTTON_TEXT_EXTRA = "TIME_PICKER_POSITIVE_BUTTON_TEXT";
      static final String POSITIVE_BUTTON_TEXT_RES_EXTRA = "TIME_PICKER_POSITIVE_BUTTON_TEXT_RES";
      static final String TIME_MODEL_EXTRA = "TIME_PICKER_TIME_MODEL";
      static final String TITLE_RES_EXTRA = "TIME_PICKER_TITLE_RES";
      static final String TITLE_TEXT_EXTRA = "TIME_PICKER_TITLE_TEXT";
      private TimePickerPresenter activePresenter;
      private Button cancelButton;
      private final Set<DialogInterface.OnCancelListener> cancelListeners = new LinkedHashSet();
      private int clockIcon;
      private final Set<DialogInterface.OnDismissListener> dismissListeners = new LinkedHashSet();
      /* access modifiers changed from: private */
      public int inputMode = 0;
      private int keyboardIcon;
      /* access modifiers changed from: private */
      public MaterialButton modeButton;
      /* access modifiers changed from: private */
      public final Set<View.OnClickListener> negativeButtonListeners = new LinkedHashSet();
      private CharSequence negativeButtonText;
      private int negativeButtonTextResId = 0;
      private int overrideThemeResId = 0;
      /* access modifiers changed from: private */
      public final Set<View.OnClickListener> positiveButtonListeners = new LinkedHashSet();
      private CharSequence positiveButtonText;
      private int positiveButtonTextResId = 0;
      private ViewStub textInputStub;
      private TimeModel time;
      private TimePickerClockPresenter timePickerClockPresenter;
      private TimePickerTextInputPresenter timePickerTextInputPresenter;
      private TimePickerView timePickerView;
      private int titleResId = 0;
      private CharSequence titleText;
  
      public static final class Builder {
          /* access modifiers changed from: private */
          public int inputMode;
          /* access modifiers changed from: private */
          public CharSequence negativeButtonText;
          /* access modifiers changed from: private */
          public int negativeButtonTextResId = 0;
          /* access modifiers changed from: private */
          public int overrideThemeResId = 0;
          /* access modifiers changed from: private */
          public CharSequence positiveButtonText;
          /* access modifiers changed from: private */
          public int positiveButtonTextResId = 0;
          /* access modifiers changed from: private */
          public TimeModel time = new TimeModel();
          /* access modifiers changed from: private */
          public CharSequence titleText;
          /* access modifiers changed from: private */
          public int titleTextResId = 0;
  
          public MaterialTimePicker build() {
              return MaterialTimePicker.newInstance(this);
          }
  
          public Builder setHour(int hour) {
              this.time.setHourOfDay(hour);
              return this;
          }
  
          public Builder setInputMode(int inputMode2) {
              this.inputMode = inputMode2;
              return this;
          }
  
          public Builder setMinute(int minute) {
              this.time.setMinute(minute);
              return this;
          }
  
          public Builder setNegativeButtonText(int negativeButtonTextResId2) {
              this.negativeButtonTextResId = negativeButtonTextResId2;
              return this;
          }
  
          public Builder setNegativeButtonText(CharSequence negativeButtonText2) {
              this.negativeButtonText = negativeButtonText2;
              return this;
          }
  
          public Builder setPositiveButtonText(int positiveButtonTextResId2) {
              this.positiveButtonTextResId = positiveButtonTextResId2;
              return this;
          }
  
          public Builder setPositiveButtonText(CharSequence positiveButtonText2) {
              this.positiveButtonText = positiveButtonText2;
              return this;
          }
  
          public Builder setTheme(int themeResId) {
              this.overrideThemeResId = themeResId;
              return this;
          }
  
          public Builder setTimeFormat(int format) {
              int i = this.time.hour;
              int i2 = this.time.minute;
              TimeModel timeModel = new TimeModel(format);
              this.time = timeModel;
              timeModel.setMinute(i2);
              this.time.setHourOfDay(i);
              return this;
          }
  
          public Builder setTitleText(int titleTextResId2) {
              this.titleTextResId = titleTextResId2;
              return this;
          }
  
          public Builder setTitleText(CharSequence charSequence) {
              this.titleText = charSequence;
              return this;
          }
      }
  
      private Pair<Integer, Integer> dataForMode(int mode) {
          switch (mode) {
              case 0:
                  return new Pair<>(Integer.valueOf(this.keyboardIcon), Integer.valueOf(R.string.material_timepicker_text_input_mode_description));
              case 1:
                  return new Pair<>(Integer.valueOf(this.clockIcon), Integer.valueOf(R.string.material_timepicker_clock_mode_description));
              default:
                  throw new IllegalArgumentException("no icon for mode: " + mode);
          }
      }
  
      private int getThemeResId() {
          int i = this.overrideThemeResId;
          if (i != 0) {
              return i;
          }
          TypedValue resolve = MaterialAttributes.resolve(requireContext(), R.attr.materialTimePickerTheme);
          if (resolve == null) {
              return 0;
          }
          return resolve.data;
      }
  
      private TimePickerPresenter initializeOrRetrieveActivePresenterForMode(int mode, TimePickerView timePickerView2, ViewStub textInputStub2) {
          if (mode == 0) {
              TimePickerClockPresenter timePickerClockPresenter2 = this.timePickerClockPresenter;
              if (timePickerClockPresenter2 == null) {
                  timePickerClockPresenter2 = new TimePickerClockPresenter(timePickerView2, this.time);
              }
              this.timePickerClockPresenter = timePickerClockPresenter2;
              return timePickerClockPresenter2;
          }
          if (this.timePickerTextInputPresenter == null) {
              this.timePickerTextInputPresenter = new TimePickerTextInputPresenter((LinearLayout) textInputStub2.inflate(), this.time);
          }
          this.timePickerTextInputPresenter.clearCheck();
          return this.timePickerTextInputPresenter;
      }
  
      /* access modifiers changed from: private */
      public static MaterialTimePicker newInstance(Builder options) {
          MaterialTimePicker materialTimePicker = new MaterialTimePicker();
          Bundle bundle = new Bundle();
          bundle.putParcelable(TIME_MODEL_EXTRA, options.time);
          bundle.putInt(INPUT_MODE_EXTRA, options.inputMode);
          bundle.putInt(TITLE_RES_EXTRA, options.titleTextResId);
          if (options.titleText != null) {
              bundle.putCharSequence(TITLE_TEXT_EXTRA, options.titleText);
          }
          bundle.putInt(POSITIVE_BUTTON_TEXT_RES_EXTRA, options.positiveButtonTextResId);
          if (options.positiveButtonText != null) {
              bundle.putCharSequence(POSITIVE_BUTTON_TEXT_EXTRA, options.positiveButtonText);
          }
          bundle.putInt(NEGATIVE_BUTTON_TEXT_RES_EXTRA, options.negativeButtonTextResId);
          if (options.negativeButtonText != null) {
              bundle.putCharSequence(NEGATIVE_BUTTON_TEXT_EXTRA, options.negativeButtonText);
          }
          bundle.putInt(OVERRIDE_THEME_RES_ID, options.overrideThemeResId);
          materialTimePicker.setArguments(bundle);
          return materialTimePicker;
      }
  
      private void restoreState(Bundle bundle) {
          if (bundle != null) {
              TimeModel timeModel = (TimeModel) bundle.getParcelable(TIME_MODEL_EXTRA);
              this.time = timeModel;
              if (timeModel == null) {
                  this.time = new TimeModel();
              }
              this.inputMode = bundle.getInt(INPUT_MODE_EXTRA, 0);
              this.titleResId = bundle.getInt(TITLE_RES_EXTRA, 0);
              this.titleText = bundle.getCharSequence(TITLE_TEXT_EXTRA);
              this.positiveButtonTextResId = bundle.getInt(POSITIVE_BUTTON_TEXT_RES_EXTRA, 0);
              this.positiveButtonText = bundle.getCharSequence(POSITIVE_BUTTON_TEXT_EXTRA);
              this.negativeButtonTextResId = bundle.getInt(NEGATIVE_BUTTON_TEXT_RES_EXTRA, 0);
              this.negativeButtonText = bundle.getCharSequence(NEGATIVE_BUTTON_TEXT_EXTRA);
              this.overrideThemeResId = bundle.getInt(OVERRIDE_THEME_RES_ID, 0);
          }
      }
  
      private void updateCancelButtonVisibility() {
          Button button = this.cancelButton;
          if (button != null) {
              button.setVisibility(isCancelable() ? 0 : 8);
          }
      }
  
      /* access modifiers changed from: private */
      public void updateInputMode(MaterialButton modeButton2) {
          if (modeButton2 != null && this.timePickerView != null && this.textInputStub != null) {
              TimePickerPresenter timePickerPresenter = this.activePresenter;
              if (timePickerPresenter != null) {
                  timePickerPresenter.hide();
              }
              TimePickerPresenter initializeOrRetrieveActivePresenterForMode = initializeOrRetrieveActivePresenterForMode(this.inputMode, this.timePickerView, this.textInputStub);
              this.activePresenter = initializeOrRetrieveActivePresenterForMode;
              initializeOrRetrieveActivePresenterForMode.show();
              this.activePresenter.invalidate();
              Pair<Integer, Integer> dataForMode = dataForMode(this.inputMode);
              modeButton2.setIconResource(((Integer) dataForMode.first).intValue());
              modeButton2.setContentDescription(getResources().getString(((Integer) dataForMode.second).intValue()));
              modeButton2.sendAccessibilityEvent(4);
          }
      }
  
      public boolean addOnCancelListener(DialogInterface.OnCancelListener listener) {
          return this.cancelListeners.add(listener);
      }
  
      public boolean addOnDismissListener(DialogInterface.OnDismissListener listener) {
          return this.dismissListeners.add(listener);
      }
  
      public boolean addOnNegativeButtonClickListener(View.OnClickListener listener) {
          return this.negativeButtonListeners.add(listener);
      }
  
      public boolean addOnPositiveButtonClickListener(View.OnClickListener listener) {
          return this.positiveButtonListeners.add(listener);
      }
  
      public void clearOnCancelListeners() {
          this.cancelListeners.clear();
      }
  
      public void clearOnDismissListeners() {
          this.dismissListeners.clear();
      }
  
      public void clearOnNegativeButtonClickListeners() {
          this.negativeButtonListeners.clear();
      }
  
      public void clearOnPositiveButtonClickListeners() {
          this.positiveButtonListeners.clear();
      }
  
      public int getHour() {
          return this.time.hour % 24;
      }
  
      public int getInputMode() {
          return this.inputMode;
      }
  
      public int getMinute() {
          return this.time.minute;
      }
  
      /* access modifiers changed from: package-private */
      public TimePickerClockPresenter getTimePickerClockPresenter() {
          return this.timePickerClockPresenter;
      }
  
      public final void onCancel(DialogInterface dialogInterface) {
          for (DialogInterface.OnCancelListener onCancel : this.cancelListeners) {
              onCancel.onCancel(dialogInterface);
          }
          super.onCancel(dialogInterface);
      }
  
      public void onCreate(Bundle bundle) {
          super.onCreate(bundle);
          restoreState(bundle == null ? getArguments() : bundle);
      }
  
      public final Dialog onCreateDialog(Bundle bundle) {
          Dialog dialog = new Dialog(requireContext(), getThemeResId());
          Context context = dialog.getContext();
          int resolveOrThrow = MaterialAttributes.resolveOrThrow(context, R.attr.colorSurface, MaterialTimePicker.class.getCanonicalName());
          MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable(context, (AttributeSet) null, R.attr.materialTimePickerStyle, R.style.Widget_MaterialComponents_TimePicker);
          TypedArray obtainStyledAttributes = context.obtainStyledAttributes((AttributeSet) null, R.styleable.MaterialTimePicker, R.attr.materialTimePickerStyle, R.style.Widget_MaterialComponents_TimePicker);
          this.clockIcon = obtainStyledAttributes.getResourceId(R.styleable.MaterialTimePicker_clockIcon, 0);
          this.keyboardIcon = obtainStyledAttributes.getResourceId(R.styleable.MaterialTimePicker_keyboardIcon, 0);
          obtainStyledAttributes.recycle();
          materialShapeDrawable.initializeElevationOverlay(context);
          materialShapeDrawable.setFillColor(ColorStateList.valueOf(resolveOrThrow));
          Window window = dialog.getWindow();
          window.setBackgroundDrawable(materialShapeDrawable);
          window.requestFeature(1);
          window.setLayout(-2, -2);
          materialShapeDrawable.setElevation(ViewCompat.getElevation(window.getDecorView()));
          return dialog;
      }
  
      public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
          ViewGroup viewGroup2 = (ViewGroup) layoutInflater.inflate(R.layout.material_timepicker_dialog, viewGroup);
          TimePickerView timePickerView2 = (TimePickerView) viewGroup2.findViewById(R.id.material_timepicker_view);
          this.timePickerView = timePickerView2;
          timePickerView2.setOnDoubleTapListener(this);
          this.textInputStub = (ViewStub) viewGroup2.findViewById(R.id.material_textinput_timepicker);
          this.modeButton = (MaterialButton) viewGroup2.findViewById(R.id.material_timepicker_mode_button);
          TextView textView = (TextView) viewGroup2.findViewById(R.id.header_title);
          int i = this.titleResId;
          if (i != 0) {
              textView.setText(i);
          } else if (!TextUtils.isEmpty(this.titleText)) {
              textView.setText(this.titleText);
          }
          updateInputMode(this.modeButton);
          Button button = (Button) viewGroup2.findViewById(R.id.material_timepicker_ok_button);
          button.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  for (View.OnClickListener onClick : MaterialTimePicker.this.positiveButtonListeners) {
                      onClick.onClick(v);
                  }
                  MaterialTimePicker.this.dismiss();
              }
          });
          int i2 = this.positiveButtonTextResId;
          if (i2 != 0) {
              button.setText(i2);
          } else if (!TextUtils.isEmpty(this.positiveButtonText)) {
              button.setText(this.positiveButtonText);
          }
          Button button2 = (Button) viewGroup2.findViewById(R.id.material_timepicker_cancel_button);
          this.cancelButton = button2;
          button2.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  for (View.OnClickListener onClick : MaterialTimePicker.this.negativeButtonListeners) {
                      onClick.onClick(v);
                  }
                  MaterialTimePicker.this.dismiss();
              }
          });
          int i3 = this.negativeButtonTextResId;
          if (i3 != 0) {
              this.cancelButton.setText(i3);
          } else if (!TextUtils.isEmpty(this.negativeButtonText)) {
              this.cancelButton.setText(this.negativeButtonText);
          }
          updateCancelButtonVisibility();
          this.modeButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  MaterialTimePicker materialTimePicker = MaterialTimePicker.this;
                  int unused = materialTimePicker.inputMode = materialTimePicker.inputMode == 0 ? 1 : 0;
                  MaterialTimePicker materialTimePicker2 = MaterialTimePicker.this;
                  materialTimePicker2.updateInputMode(materialTimePicker2.modeButton);
              }
          });
          return viewGroup2;
      }
  
      public void onDestroyView() {
          super.onDestroyView();
          this.activePresenter = null;
          this.timePickerClockPresenter = null;
          this.timePickerTextInputPresenter = null;
          TimePickerView timePickerView2 = this.timePickerView;
          if (timePickerView2 != null) {
              timePickerView2.setOnDoubleTapListener((TimePickerView.OnDoubleTapListener) null);
              this.timePickerView = null;
          }
      }
  
      public final void onDismiss(DialogInterface dialogInterface) {
          for (DialogInterface.OnDismissListener onDismiss : this.dismissListeners) {
              onDismiss.onDismiss(dialogInterface);
          }
          super.onDismiss(dialogInterface);
      }
  
      public void onDoubleTap() {
          this.inputMode = 1;
          updateInputMode(this.modeButton);
          this.timePickerTextInputPresenter.resetChecked();
      }
  
      public void onSaveInstanceState(Bundle bundle) {
          super.onSaveInstanceState(bundle);
          bundle.putParcelable(TIME_MODEL_EXTRA, this.time);
          bundle.putInt(INPUT_MODE_EXTRA, this.inputMode);
          bundle.putInt(TITLE_RES_EXTRA, this.titleResId);
          bundle.putCharSequence(TITLE_TEXT_EXTRA, this.titleText);
          bundle.putInt(POSITIVE_BUTTON_TEXT_RES_EXTRA, this.positiveButtonTextResId);
          bundle.putCharSequence(POSITIVE_BUTTON_TEXT_EXTRA, this.positiveButtonText);
          bundle.putInt(NEGATIVE_BUTTON_TEXT_RES_EXTRA, this.negativeButtonTextResId);
          bundle.putCharSequence(NEGATIVE_BUTTON_TEXT_EXTRA, this.negativeButtonText);
          bundle.putInt(OVERRIDE_THEME_RES_ID, this.overrideThemeResId);
      }
  
      public boolean removeOnCancelListener(DialogInterface.OnCancelListener listener) {
          return this.cancelListeners.remove(listener);
      }
  
      public boolean removeOnDismissListener(DialogInterface.OnDismissListener listener) {
          return this.dismissListeners.remove(listener);
      }
  
      public boolean removeOnNegativeButtonClickListener(View.OnClickListener listener) {
          return this.negativeButtonListeners.remove(listener);
      }
  
      public boolean removeOnPositiveButtonClickListener(View.OnClickListener listener) {
          return this.positiveButtonListeners.remove(listener);
      }
  
      /* access modifiers changed from: package-private */
      public void setActivePresenter(TimePickerPresenter presenter) {
          this.activePresenter = presenter;
      }
  
      public void setCancelable(boolean cancelable) {
          super.setCancelable(cancelable);
          updateCancelButtonVisibility();
      }
  
      public void setHour(int hour) {
          this.time.setHour(hour);
          TimePickerPresenter timePickerPresenter = this.activePresenter;
          if (timePickerPresenter != null) {
              timePickerPresenter.invalidate();
          }
      }
  
      public void setMinute(int minute) {
          this.time.setMinute(minute);
          TimePickerPresenter timePickerPresenter = this.activePresenter;
          if (timePickerPresenter != null) {
              timePickerPresenter.invalidate();
          }
      }
  }
  