Advertisement
Guest User

Untitled

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