Advertisement
Guest User

Untitled

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