Esempio n. 1
0
 /**
  * Set the tint of the ordering button.
  *
  * @param button
  * @param tint
  */
 private static void setButtonTint(Button button, ColorStateList tint) {
   if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP
       && button instanceof AppCompatButton) {
     ((AppCompatButton) button).setSupportBackgroundTintList(tint);
   } else {
     ViewCompat.setBackgroundTintList(button, tint);
   }
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.password_dialog_fragment, container, false);
    this.presenter = new EditPasswordPresenterImpl(this);

    this.currentPass = (EditText) v.findViewById(R.id.current_password);
    this.newPass = (EditText) v.findViewById(R.id.password);
    this.rePass = (EditText) v.findViewById(R.id.re_password);
    this.errorMessage = (TextView) v.findViewById(R.id.error);

    AppCompatButton submit = (AppCompatButton) v.findViewById(R.id.submit);
    ColorStateList csl =
        ColorStateList.valueOf(ContextCompat.getColor(getActivity(), R.color.teal));
    submit.setSupportBackgroundTintList(csl);
    submit.setOnClickListener(this);
    return v;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootview = inflater.inflate(R.layout.fragment_reach_kitchen, container, false);

    pref =
        getActivity()
            .getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    editor = pref.edit();
    editor.putString("state", "ReachKitchen");
    editor.apply();

    header = (TextView) rootview.findViewById(R.id.kitchenAddHeader);
    textView = (TextView) rootview.findViewById(R.id.kitchenAddText);
    noNetText = (TextView) rootview.findViewById(R.id.noNetText);
    buttonReached = (AppCompatButton) rootview.findViewById(R.id.kitchenReachedButton);
    progressBar = (ProgressBar) rootview.findViewById(R.id.fetchingProgressBar);

    Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fontawesome-webfont.ttf");
    buttonReached.setTypeface(font);

    ColorStateList csl =
        new ColorStateList(
            new int[][] {new int[0]},
            new int[] {ContextCompat.getColor(getContext(), R.color.colorAccent)});
    buttonReached.setSupportBackgroundTintList(csl);

    noNetText.setVisibility(View.GONE);

    if (pref.getString(this.getString(R.string.kitchenName), null) == null) {
      Log.d(
          "shreyDebug", "empty pref " + pref.getString(this.getString(R.string.kitchenName), null));
      progressBar.setVisibility(View.VISIBLE);
      buttonReached.setVisibility(View.GONE);
      header.setVisibility(View.GONE);
      textView.setVisibility(View.GONE);
      fetchKitchenAddress();
    } else {
      kitchenName = pref.getString(this.getString(R.string.kitchenName), null);
      kitchenAddress = pref.getString(this.getString(R.string.kitchenAddress), null);
      header.setText(kitchenName);
      textView.setText(kitchenAddress);
      header.setVisibility(View.VISIBLE);
      textView.setVisibility(View.VISIBLE);
      progressBar.setVisibility(View.GONE);
      buttonReached.setVisibility(View.VISIBLE);
    }

    buttonReached.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (retry) {
              header.setVisibility(View.GONE);
              textView.setVisibility(View.GONE);
              buttonReached.setVisibility(View.GONE);
              noNetText.setVisibility(View.GONE);
              progressBar.setVisibility(View.VISIBLE);

              Runnable runnable =
                  new Runnable() {
                    @Override
                    public void run() {
                      fetchKitchenAddress();
                    }
                  };
              handler.postDelayed(runnable, 3000);

            } else {
              Intent intent = new Intent(getActivity(), LeaveKitchen.class);
              intent.putExtra("kitchenName", kitchenName);
              intent.putExtra("kitchenAddress", kitchenAddress);
              startActivity(intent);
            }
          }
        });
    return rootview;
  }