Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.71 KB | None | 0 0
  1. package grinasi.grinasia.com.guide;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.design.widget.TextInputLayout;
  6. import android.support.v4.view.ViewPager;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.support.v7.widget.Toolbar;
  9. import android.text.TextUtils;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13.  
  14. import grinasi.grinasia.com.guide.Adapter.SignupViewPagerAdapter;
  15. import grinasi.grinasia.com.guide.Fragments.Fragment_Register;
  16.  
  17. /**
  18. * Created by coder on 20-Dec-16.
  19. */
  20.  
  21. public class Register extends AppCompatActivity {
  22.  
  23. private Toolbar toolbar;
  24. private ViewPager signUpViewPager;
  25. private Button Next, Back, Begin;
  26.  
  27. @Override
  28. protected void onCreate(Bundle savedInstanceState) {
  29. super.onCreate(savedInstanceState);
  30. setContentView(R.layout.viewpager_register_2);
  31.  
  32. toolbar = (Toolbar) findViewById(R.id.toolbar1);
  33. setSupportActionBar(toolbar);
  34.  
  35. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  36. getSupportActionBar().setDisplayShowTitleEnabled(false);
  37.  
  38. signUpViewPager = (ViewPager) findViewById(R.id.viewpager1);
  39. Next = (Button) findViewById(R.id.btnNext);
  40. Back = (Button) findViewById(R.id.btnback);
  41. Begin = (Button) findViewById(R.id.btnstart);
  42.  
  43. setupViewPager(signUpViewPager);
  44.  
  45. signUpViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  46. @Override
  47. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  48. }
  49.  
  50. @Override
  51. public void onPageSelected(int position) {
  52. if (position == 1){
  53. Back.setVisibility(View.GONE);
  54. }
  55. if (position == 4){
  56. Next.setVisibility(View.GONE);
  57. }
  58. }
  59.  
  60. @Override
  61. public void onPageScrollStateChanged(int state) {
  62.  
  63. }
  64. });
  65.  
  66. Next.setOnClickListener(new View.OnClickListener() {
  67. @Override
  68. public void onClick(View view) {
  69. int position = signUpViewPager.getCurrentItem();
  70.  
  71. }
  72. });
  73.  
  74. Begin.setOnClickListener(new View.OnClickListener() {
  75. @Override
  76. public void onClick(View view) {
  77. if (view==Begin){
  78. Intent intent = new Intent(Register.this, MainActivity.class);
  79. startActivity(intent);
  80. }
  81. }
  82. });
  83. }
  84.  
  85. private void setupViewPager(ViewPager viewPager){
  86. SignupViewPagerAdapter adapter = new SignupViewPagerAdapter(getSupportFragmentManager());
  87. adapter.addFragment(new Fragment_Register());
  88. //adapter.addFragment(new Fragment Register_1());
  89. //adapter.addFragment(new Register_next_after());
  90. //adapter.addFragment(new Register_finish());
  91. viewPager.setAdapter(adapter);
  92. }
  93.  
  94. private void validateUserInput(int viewPagerPosition){
  95. if (viewPagerPosition == 0) {
  96.  
  97. TextInputLayout txtLayoutUsername = (TextInputLayout) findViewById(R.id.txtInputUserName);
  98. TextInputLayout txtLayoutPassword = (TextInputLayout) findViewById(R.id.txtInputPassword);
  99. TextInputLayout txtLayoutConfirmPassword = (TextInputLayout) findViewById(R.id.txtInputConfirmPassword);
  100.  
  101. txtLayoutUsername.setErrorEnabled(false);
  102. txtLayoutPassword.setErrorEnabled(false);
  103. txtLayoutConfirmPassword.setErrorEnabled(false);
  104.  
  105. EditText txtUser = (EditText) findViewById(R.id.edUser);
  106. EditText txtPassword = (EditText) findViewById(R.id.edPassword);
  107. EditText txtConfirmPassword = (EditText) findViewById(R.id.edConfirmPassword);
  108.  
  109. if (TextUtils.isEmpty(txtUser.getText().toString()) || TextUtils.isEmpty(txtPassword.getText().toString())
  110. || TextUtils.isEmpty(txtConfirmPassword.getText().toString())){
  111. if (TextUtils.isEmpty(txtUser.getText().toString())){
  112. showValidation(txtLayoutUsername, txtUser, "Username is required");
  113. }
  114. if (TextUtils.isEmpty(txtPassword.getText().toString())){
  115. showValidation(txtLayoutPassword, txtPassword, "Password is required");
  116. }
  117.  
  118. if (TextUtils.isEmpty(txtConfirmPassword.getText().toString())){
  119. showValidation(txtLayoutConfirmPassword, txtConfirmPassword, "Please confirm your password");
  120. }
  121.  
  122. return;
  123. } else {
  124.  
  125. if (!TextUtils.equals(txtPassword.getText().toString(), txtConfirmPassword.getText().toString())){
  126. showValidation(txtLayoutConfirmPassword, txtConfirmPassword, "Password do not match");
  127. return;
  128. } else {
  129. if (txtPassword.getText().toString().length() < 8){
  130. showValidation(txtLayoutPassword, txtPassword, "Password must be minimum 8 character");
  131. return;
  132. }
  133.  
  134. if (txtPassword.getText().toString().contains(txtUser.getText().toString())){
  135. showValidation(txtLayoutPassword, txtPassword, "Password cannot contain your username");
  136. return;
  137. }
  138. }
  139.  
  140. }
  141. signUpViewPager.setCurrentItem(viewPagerPosition + 1);
  142. } else if (viewPagerPosition == 1) {
  143.  
  144. TextInputLayout txtLayoutNama = (TextInputLayout) findViewById(R.id.txtInputName);
  145. TextInputLayout txtLayoutAlamat = (TextInputLayout) findViewById(R.id.txtInputAddress);
  146. TextInputLayout txtLayoutNomor = (TextInputLayout) findViewById(R.id.txtInputPhone);
  147. TextInputLayout txtLayoutSIM = (TextInputLayout) findViewById(R.id.txtInputPhoneSIM);
  148.  
  149. txtLayoutNama.setErrorEnabled(false);
  150. txtLayoutAlamat.setErrorEnabled(false);
  151. txtLayoutNomor.setErrorEnabled(false);
  152. txtLayoutSIM.setErrorEnabled(false);
  153.  
  154. EditText txtUsername = (EditText) findViewById(R.id.edName);
  155. EditText txtAlamat = (EditText) findViewById(R.id.edAddress);
  156. EditText txtNumberTelepon = (EditText) findViewById(R.id.edNumber_telephone);
  157. EditText txtSIM = (EditText) findViewById(R.id.edSIM_phone);
  158.  
  159. if (TextUtils.isEmpty(txtUsername.getText().toString()) || TextUtils.isEmpty(txtAlamat.getText().toString())
  160. || TextUtils.isEmpty(txtNumberTelepon.getText().toString())|| TextUtils.isEmpty(txtSIM.getText().toString())){
  161.  
  162. if (TextUtils.isEmpty(txtUsername.getText().toString())){
  163. showValidation(txtLayoutNama, txtUsername, "Username is required");
  164. }
  165. if (TextUtils.isEmpty(txtAlamat.getText().toString())){
  166. showValidation(txtLayoutAlamat, txtAlamat, "Password is required");
  167. }
  168.  
  169. if (TextUtils.isEmpty(txtNumberTelepon.getText().toString())){
  170. showValidation(txtLayoutNomor, txtNumberTelepon, "Number Telephone is required");
  171. }
  172. if (TextUtils.isEmpty(txtSIM.getText().toString())){
  173. showValidation(txtLayoutSIM, txtSIM, "Number Phone SIM is required");
  174. }
  175.  
  176. return;
  177.  
  178. }
  179. signUpViewPager.setCurrentItem(viewPagerPosition + 1);
  180. } else if (viewPagerPosition == 1){
  181.  
  182. TextInputLayout txtLayoutName_Company = (TextInputLayout) findViewById(R.id.txtInputName_company);
  183. TextInputLayout txtLayoutAddress_Company = (TextInputLayout) findViewById(R.id.txtInputAddress_company);
  184. TextInputLayout txtLayoutNumber_Company = (TextInputLayout) findViewById(R.id.txtInputPhone_company);
  185. TextInputLayout txtLayoutNumberAkte = (TextInputLayout) findViewById(R.id.txtInputNumber_Akte);
  186. TextInputLayout txtLayoutNumberSIUP = (TextInputLayout) findViewById(R.id.txtInputNumberSIUP);
  187. TextInputLayout txtLayoutNumberTDP = (TextInputLayout) findViewById(R.id.txtInputNumberTDP);
  188. TextInputLayout txtLayoutNumberNPWP = (TextInputLayout) findViewById(R.id.txtInputNumberNPWP);
  189.  
  190. txtLayoutName_Company.setErrorEnabled(false);
  191. txtLayoutAddress_Company.setErrorEnabled(false);
  192. txtLayoutNumber_Company.setErrorEnabled(false);
  193. txtLayoutNumberAkte.setErrorEnabled(false);
  194. txtLayoutNumberSIUP.setErrorEnabled(false);
  195. txtLayoutNumberTDP.setErrorEnabled(false);
  196. txtLayoutNumberNPWP.setErrorEnabled(false);
  197.  
  198. EditText txtNama_Company = (EditText) findViewById(R.id.edName_Company);
  199. EditText txtAlamat_Company = (EditText) findViewById(R.id.edAddress_Company);
  200. EditText txtTelepon_Company= (EditText) findViewById(R.id.edNumber_telephone);
  201. EditText txtNumber_Akte = (EditText) findViewById(R.id.edNumber_Akte);
  202. EditText txtNumber_SIUP = (EditText) findViewById(R.id.edNumber_SIUP);
  203. EditText txtNumber_TDP = (EditText) findViewById(R.id.edNumber_TDP);
  204. EditText txtNumber_NPWP = (EditText) findViewById(R.id.edNumber_NPWP);
  205.  
  206. if (TextUtils.isEmpty(txtNama_Company.getText().toString())
  207. || TextUtils.isEmpty(txtAlamat_Company.getText().toString())
  208. || TextUtils.isEmpty(txtTelepon_Company.getText().toString())
  209. || TextUtils.isEmpty(txtNumber_Akte.getText().toString())
  210. || TextUtils.isEmpty(txtNumber_SIUP.getText().toString())
  211. || TextUtils.isEmpty(txtNumber_TDP.getText().toString())
  212. || TextUtils.isEmpty(txtNumber_NPWP.getText().toString())){
  213.  
  214. if (TextUtils.isEmpty(txtNama_Company.getText().toString())){
  215. showValidation(txtLayoutName_Company, txtNama_Company, "Name Perusahaan is required");
  216. }
  217. if (TextUtils.isEmpty(txtAlamat_Company.getText().toString())){
  218. showValidation(txtLayoutAddress_Company, txtAlamat_Company, "Alamat Perusahaan is required");
  219. }
  220. if (TextUtils.isEmpty(txtTelepon_Company.getText().toString())){
  221. showValidation(txtLayoutNumber_Company, txtTelepon_Company, "Nomor Telepon is required");
  222. }
  223. if (TextUtils.isEmpty(txtNumber_Akte.getText().toString())){
  224. showValidation(txtLayoutNumberAkte, txtNumber_Akte, "Nomor Akte is required");
  225. }
  226. if (TextUtils.isEmpty(txtNumber_SIUP.getText().toString())){
  227. showValidation(txtLayoutNumberSIUP, txtNumber_SIUP, "Nomor SIUP is required");
  228. }
  229. if (TextUtils.isEmpty(txtNumber_TDP.getText().toString())){
  230. showValidation(txtLayoutNumberTDP, txtNumber_TDP, "Nomor TDP is required");
  231. }
  232. if (TextUtils.isEmpty(txtNumber_NPWP.getText().toString())){
  233. showValidation(txtLayoutNumberNPWP, txtNumber_NPWP, "Nomor NPWP is required");
  234. }
  235. return;
  236. }
  237. signUpViewPager.setCurrentItem(viewPagerPosition + 1);
  238.  
  239. }
  240. }
  241.  
  242. private void showValidation(TextInputLayout textInputLayout, EditText editText, String errorMessage) {
  243. textInputLayout.setErrorEnabled(true);
  244.  
  245. textInputLayout.setError(errorMessage);
  246. editText.setError(errorMessage);
  247. }
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement