private void initUI() {

    firebaseAuth = FirebaseAuth.getInstance();

    if (firebaseAuth.getCurrentUser() != null) {
      startActivity(new Intent(this, MainActivity.class));
      finish();
    }

    tilEmail = (TextInputLayout) findViewById(R.id.tilEmail);
    clGeneral = (CoordinatorLayout) findViewById(R.id.clGeneral);
    tilPassword = (TextInputLayout) findViewById(R.id.tilPassword);
    tieEmail = (TextInputEditText) findViewById(R.id.tieEmail);
    tiePassword = (TextInputEditText) findViewById(R.id.tiePassword);
    btnLogin = (AppCompatButton) findViewById(R.id.btnLogin);
    lblRecoveryPassword = (AppCompatTextView) findViewById(R.id.lblRecoveryPassword);
    lblCreateAccount = (AppCompatTextView) findViewById(R.id.lblCreateAccount);

    btnLogin.setOnClickListener(this);
    lblRecoveryPassword.setOnClickListener(this);
    lblCreateAccount.setOnClickListener(this);

    tieEmail.addTextChangedListener(new CustomTextWatcher(tieEmail));
    tiePassword.addTextChangedListener(new CustomTextWatcher(tiePassword));

    tiePassword.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_GO) {
              btnLogin.performClick();
              return true;
            }
            return false;
          }
        });
  }
Esempio n. 2
0
  /** *** CAST THE LAYOUT ELEMENTS **** */
  private void castLayoutElements() {

    /* CATEGORY SELECTOR */
    spnMenuCategory = (AppCompatSpinner) findViewById(R.id.spnMenuCategory);
    AppCompatTextView txtAddNewCategory = (AppCompatTextView) findViewById(R.id.txtAddNewCategory);

    /* MENU / DISH DETAILS */
    inputDishName = (TextInputLayout) findViewById(R.id.inputDishName);
    edtDishName = (AppCompatEditText) findViewById(R.id.edtDishName);
    inputDishDescription = (TextInputLayout) findViewById(R.id.inputDishDescription);
    edtDishDescription = (AppCompatEditText) findViewById(R.id.edtDishDescription);
    inputDishPrice = (TextInputLayout) findViewById(R.id.inputDishPrice);
    edtDishPrice = (AppCompatEditText) findViewById(R.id.edtDishPrice);
    RadioGroup rdgDishType = (RadioGroup) findViewById(R.id.rdgDishType);
    spnServes = (AppCompatSpinner) findViewById(R.id.spnServes);
    imgvwAddPhoto = (AppCompatImageView) findViewById(R.id.imgvwAddPhoto);

    /** CHANGE THE MEAL TYPE * */
    rdgDishType.setOnCheckedChangeListener(
        new RadioGroup.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {

            switch (checkedId) {
              case R.id.rdbtnVeg:
                /** SET THE DISH TYPE TO "VEG" * */
                MEAL_TYPE = "Veg";
                break;
              case R.id.rdbtnNonVeg:
                /** SET THE DISH TYPE TO "NON-VEG" * */
                MEAL_TYPE = "Non-veg";
                break;
              default:
                break;
            }
          }
        });

    /** *** CREATE A NEW CATEGORY **** */
    txtAddNewCategory.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent newCategory = new Intent(MenuCreator.this, CategoryCreator.class);
            startActivityForResult(newCategory, ACTION_REQUEST_NEW_CATEGORY);
          }
        });

    /** *** SELECT A PHOTO FOR THE DISH **** */
    imgvwAddPhoto.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            EasyImage.openChooser(MenuCreator.this, "Pick Image Source", true);
          }
        });

    /** POPULATE THE SPINNER * */
    String[] strServes = getResources().getStringArray(R.array.menuServes);
    final List<String> arrServes;
    arrServes = Arrays.asList(strServes);
    spnServes.setAdapter(
        new MenuServesAdapter(MenuCreator.this, R.layout.custom_spinner_row, arrServes));

    /** CHANGE THE MENU SERVES NUMBER * */
    spnServes.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            //                Toast.makeText(getApplication(), arrServes.get(position),
            // Toast.LENGTH_SHORT).show();
            MEAL_SERVES = arrServes.get(position);
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });
  }