Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package grinasi.grinasia.com.guide;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.design.widget.TextInputLayout;
- import android.support.v4.view.ViewPager;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.text.TextUtils;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import grinasi.grinasia.com.guide.Adapter.SignupViewPagerAdapter;
- import grinasi.grinasia.com.guide.Fragments.Fragment_Register;
- /**
- * Created by coder on 20-Dec-16.
- */
- public class Register extends AppCompatActivity {
- private Toolbar toolbar;
- private ViewPager signUpViewPager;
- private Button Next, Back, Begin;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.viewpager_register_2);
- toolbar = (Toolbar) findViewById(R.id.toolbar1);
- setSupportActionBar(toolbar);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setDisplayShowTitleEnabled(false);
- signUpViewPager = (ViewPager) findViewById(R.id.viewpager1);
- Next = (Button) findViewById(R.id.btnNext);
- Back = (Button) findViewById(R.id.btnback);
- Begin = (Button) findViewById(R.id.btnstart);
- setupViewPager(signUpViewPager);
- signUpViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
- @Override
- public void onPageSelected(int position) {
- if (position == 1){
- Back.setVisibility(View.GONE);
- }
- if (position == 4){
- Next.setVisibility(View.GONE);
- }
- }
- @Override
- public void onPageScrollStateChanged(int state) {
- }
- });
- Next.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- int position = signUpViewPager.getCurrentItem();
- }
- });
- Begin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (view==Begin){
- Intent intent = new Intent(Register.this, MainActivity.class);
- startActivity(intent);
- }
- }
- });
- }
- private void setupViewPager(ViewPager viewPager){
- SignupViewPagerAdapter adapter = new SignupViewPagerAdapter(getSupportFragmentManager());
- adapter.addFragment(new Fragment_Register());
- //adapter.addFragment(new Fragment Register_1());
- //adapter.addFragment(new Register_next_after());
- //adapter.addFragment(new Register_finish());
- viewPager.setAdapter(adapter);
- }
- private void validateUserInput(int viewPagerPosition){
- if (viewPagerPosition == 0) {
- TextInputLayout txtLayoutUsername = (TextInputLayout) findViewById(R.id.txtInputUserName);
- TextInputLayout txtLayoutPassword = (TextInputLayout) findViewById(R.id.txtInputPassword);
- TextInputLayout txtLayoutConfirmPassword = (TextInputLayout) findViewById(R.id.txtInputConfirmPassword);
- txtLayoutUsername.setErrorEnabled(false);
- txtLayoutPassword.setErrorEnabled(false);
- txtLayoutConfirmPassword.setErrorEnabled(false);
- EditText txtUser = (EditText) findViewById(R.id.edUser);
- EditText txtPassword = (EditText) findViewById(R.id.edPassword);
- EditText txtConfirmPassword = (EditText) findViewById(R.id.edConfirmPassword);
- if (TextUtils.isEmpty(txtUser.getText().toString()) || TextUtils.isEmpty(txtPassword.getText().toString())
- || TextUtils.isEmpty(txtConfirmPassword.getText().toString())){
- if (TextUtils.isEmpty(txtUser.getText().toString())){
- showValidation(txtLayoutUsername, txtUser, "Username is required");
- }
- if (TextUtils.isEmpty(txtPassword.getText().toString())){
- showValidation(txtLayoutPassword, txtPassword, "Password is required");
- }
- if (TextUtils.isEmpty(txtConfirmPassword.getText().toString())){
- showValidation(txtLayoutConfirmPassword, txtConfirmPassword, "Please confirm your password");
- }
- return;
- } else {
- if (!TextUtils.equals(txtPassword.getText().toString(), txtConfirmPassword.getText().toString())){
- showValidation(txtLayoutConfirmPassword, txtConfirmPassword, "Password do not match");
- return;
- } else {
- if (txtPassword.getText().toString().length() < 8){
- showValidation(txtLayoutPassword, txtPassword, "Password must be minimum 8 character");
- return;
- }
- if (txtPassword.getText().toString().contains(txtUser.getText().toString())){
- showValidation(txtLayoutPassword, txtPassword, "Password cannot contain your username");
- return;
- }
- }
- }
- signUpViewPager.setCurrentItem(viewPagerPosition + 1);
- } else if (viewPagerPosition == 1) {
- TextInputLayout txtLayoutNama = (TextInputLayout) findViewById(R.id.txtInputName);
- TextInputLayout txtLayoutAlamat = (TextInputLayout) findViewById(R.id.txtInputAddress);
- TextInputLayout txtLayoutNomor = (TextInputLayout) findViewById(R.id.txtInputPhone);
- TextInputLayout txtLayoutSIM = (TextInputLayout) findViewById(R.id.txtInputPhoneSIM);
- txtLayoutNama.setErrorEnabled(false);
- txtLayoutAlamat.setErrorEnabled(false);
- txtLayoutNomor.setErrorEnabled(false);
- txtLayoutSIM.setErrorEnabled(false);
- EditText txtUsername = (EditText) findViewById(R.id.edName);
- EditText txtAlamat = (EditText) findViewById(R.id.edAddress);
- EditText txtNumberTelepon = (EditText) findViewById(R.id.edNumber_telephone);
- EditText txtSIM = (EditText) findViewById(R.id.edSIM_phone);
- if (TextUtils.isEmpty(txtUsername.getText().toString()) || TextUtils.isEmpty(txtAlamat.getText().toString())
- || TextUtils.isEmpty(txtNumberTelepon.getText().toString())|| TextUtils.isEmpty(txtSIM.getText().toString())){
- if (TextUtils.isEmpty(txtUsername.getText().toString())){
- showValidation(txtLayoutNama, txtUsername, "Username is required");
- }
- if (TextUtils.isEmpty(txtAlamat.getText().toString())){
- showValidation(txtLayoutAlamat, txtAlamat, "Password is required");
- }
- if (TextUtils.isEmpty(txtNumberTelepon.getText().toString())){
- showValidation(txtLayoutNomor, txtNumberTelepon, "Number Telephone is required");
- }
- if (TextUtils.isEmpty(txtSIM.getText().toString())){
- showValidation(txtLayoutSIM, txtSIM, "Number Phone SIM is required");
- }
- return;
- }
- signUpViewPager.setCurrentItem(viewPagerPosition + 1);
- } else if (viewPagerPosition == 1){
- TextInputLayout txtLayoutName_Company = (TextInputLayout) findViewById(R.id.txtInputName_company);
- TextInputLayout txtLayoutAddress_Company = (TextInputLayout) findViewById(R.id.txtInputAddress_company);
- TextInputLayout txtLayoutNumber_Company = (TextInputLayout) findViewById(R.id.txtInputPhone_company);
- TextInputLayout txtLayoutNumberAkte = (TextInputLayout) findViewById(R.id.txtInputNumber_Akte);
- TextInputLayout txtLayoutNumberSIUP = (TextInputLayout) findViewById(R.id.txtInputNumberSIUP);
- TextInputLayout txtLayoutNumberTDP = (TextInputLayout) findViewById(R.id.txtInputNumberTDP);
- TextInputLayout txtLayoutNumberNPWP = (TextInputLayout) findViewById(R.id.txtInputNumberNPWP);
- txtLayoutName_Company.setErrorEnabled(false);
- txtLayoutAddress_Company.setErrorEnabled(false);
- txtLayoutNumber_Company.setErrorEnabled(false);
- txtLayoutNumberAkte.setErrorEnabled(false);
- txtLayoutNumberSIUP.setErrorEnabled(false);
- txtLayoutNumberTDP.setErrorEnabled(false);
- txtLayoutNumberNPWP.setErrorEnabled(false);
- EditText txtNama_Company = (EditText) findViewById(R.id.edName_Company);
- EditText txtAlamat_Company = (EditText) findViewById(R.id.edAddress_Company);
- EditText txtTelepon_Company= (EditText) findViewById(R.id.edNumber_telephone);
- EditText txtNumber_Akte = (EditText) findViewById(R.id.edNumber_Akte);
- EditText txtNumber_SIUP = (EditText) findViewById(R.id.edNumber_SIUP);
- EditText txtNumber_TDP = (EditText) findViewById(R.id.edNumber_TDP);
- EditText txtNumber_NPWP = (EditText) findViewById(R.id.edNumber_NPWP);
- if (TextUtils.isEmpty(txtNama_Company.getText().toString())
- || TextUtils.isEmpty(txtAlamat_Company.getText().toString())
- || TextUtils.isEmpty(txtTelepon_Company.getText().toString())
- || TextUtils.isEmpty(txtNumber_Akte.getText().toString())
- || TextUtils.isEmpty(txtNumber_SIUP.getText().toString())
- || TextUtils.isEmpty(txtNumber_TDP.getText().toString())
- || TextUtils.isEmpty(txtNumber_NPWP.getText().toString())){
- if (TextUtils.isEmpty(txtNama_Company.getText().toString())){
- showValidation(txtLayoutName_Company, txtNama_Company, "Name Perusahaan is required");
- }
- if (TextUtils.isEmpty(txtAlamat_Company.getText().toString())){
- showValidation(txtLayoutAddress_Company, txtAlamat_Company, "Alamat Perusahaan is required");
- }
- if (TextUtils.isEmpty(txtTelepon_Company.getText().toString())){
- showValidation(txtLayoutNumber_Company, txtTelepon_Company, "Nomor Telepon is required");
- }
- if (TextUtils.isEmpty(txtNumber_Akte.getText().toString())){
- showValidation(txtLayoutNumberAkte, txtNumber_Akte, "Nomor Akte is required");
- }
- if (TextUtils.isEmpty(txtNumber_SIUP.getText().toString())){
- showValidation(txtLayoutNumberSIUP, txtNumber_SIUP, "Nomor SIUP is required");
- }
- if (TextUtils.isEmpty(txtNumber_TDP.getText().toString())){
- showValidation(txtLayoutNumberTDP, txtNumber_TDP, "Nomor TDP is required");
- }
- if (TextUtils.isEmpty(txtNumber_NPWP.getText().toString())){
- showValidation(txtLayoutNumberNPWP, txtNumber_NPWP, "Nomor NPWP is required");
- }
- return;
- }
- signUpViewPager.setCurrentItem(viewPagerPosition + 1);
- }
- }
- private void showValidation(TextInputLayout textInputLayout, EditText editText, String errorMessage) {
- textInputLayout.setErrorEnabled(true);
- textInputLayout.setError(errorMessage);
- editText.setError(errorMessage);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement