Skip to content

Instantly share code, notes, and snippets.

@worstkiller
Created September 3, 2017 11:21
Show Gist options
  • Save worstkiller/614148cc7f87165f02d08c0a16e97f98 to your computer and use it in GitHub Desktop.
Save worstkiller/614148cc7f87165f02d08c0a16e97f98 to your computer and use it in GitHub Desktop.
Passwordless authentication androidbuffer.com
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageButton;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;
public class SmsSendFragment extends Fragment implements View.OnClickListener {
private EditText editTextPhone;
public static SmsSendFragment getInstance() {
return new SmsSendFragment();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_sms_send, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
AppCompatImageButton appCompatImageButton = view.findViewById(R.id.imageViewSend);
editTextPhone = view.findViewById(R.id.editTextPhone);
setButtonListener(appCompatImageButton);
}
private void setButtonListener(AppCompatImageButton appCompatImageButton) {
//set the button onclick listener
appCompatImageButton.setOnClickListener(this);
}
private boolean validate(int length) {
//validate the phone number length
if (length < 10) {
return false;
} else {
return true;
}
}
@Override
public void onClick(View view) {
//here handle the button click
if (validate(editTextPhone.length())) {
getFragmentManager().
beginTransaction().
replace(R.id.frameLayoutContainer, SmsAuthFragment.getInstance(editTextPhone.getText().toString())).
addToBackStack(SmsAuthFragment.class.getCanonicalName()).
commit();
} else {
Toast.makeText(getActivity(), R.string.text_phone_valid, Toast.LENGTH_SHORT).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment