PhoneRegisterLayout.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package com.yyrh.ui;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.graphics.Paint;
  5. import android.os.CountDownTimer;
  6. import android.text.method.HideReturnsTransformationMethod;
  7. import android.text.method.PasswordTransformationMethod;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.CheckBox;
  11. import android.widget.EditText;
  12. import android.widget.ImageView;
  13. import android.widget.TextView;
  14. import com.yyrh.constant.SDKSettings;
  15. import com.yyrh.constant.URLConstants;
  16. import com.yyrh.networking.NetRequestApi;
  17. import com.yyrh.sdk.SDKEntry;
  18. import com.yyrh.sdk.YyrhSdkManager;
  19. import com.yyrh.ui.floatmenu.WvPageListDialog;
  20. import com.yyrh.utils.ResourceUtil;
  21. import com.yyrh.utils.SignUtils;
  22. import com.yyrh.utils.TosUtil;
  23. import com.yyrh.utils.Utils;
  24. import static com.yyrh.constant.URLConstants.RSAKEY;
  25. public class PhoneRegisterLayout implements View.OnClickListener {
  26. private Context context;
  27. private ConstantDialog constantDialog;
  28. private EditText et_user_phone,et_user_code,et_user_pwd;
  29. private Button btn_get_code,et_reg_compete_btn;
  30. private ImageView down_eye_btn,close_btn;
  31. private boolean isShowPwd = false;
  32. private CheckBox cb_register;
  33. private TextView tv_tip,tv_private_policy;
  34. public PhoneRegisterLayout(Context context, ConstantDialog constantDialog){
  35. this.context = context;
  36. this.constantDialog = constantDialog;
  37. if (SDKSettings.isLandscape){
  38. constantDialog.setContentView(ResourceUtil.getLayoutId(context, "xy_phone_register_dialog"));
  39. }else{
  40. constantDialog.setContentView(ResourceUtil.getLayoutId(context, "xy_phone_register_dialog_protrait"));
  41. }
  42. et_user_phone = constantDialog.findViewById(ResourceUtil.getId(context, "et_user_phone"));
  43. et_user_code = constantDialog.findViewById(ResourceUtil.getId(context, "et_user_code"));
  44. et_user_pwd = constantDialog.findViewById(ResourceUtil.getId(context, "et_user_pwd"));
  45. btn_get_code = constantDialog.findViewById(ResourceUtil.getId(context, "btn_get_code"));
  46. et_reg_compete_btn = constantDialog.findViewById(ResourceUtil.getId(context, "et_reg_compete_btn"));
  47. down_eye_btn = constantDialog.findViewById(ResourceUtil.getId(context, "down_eye_btn"));
  48. cb_register = constantDialog.findViewById(ResourceUtil.getId(context, "cb_register"));
  49. close_btn = constantDialog.findViewById(ResourceUtil.getId(context, "close_btn"));
  50. tv_tip = constantDialog.findViewById(ResourceUtil.getId(context, "tv_tip"));
  51. tv_tip.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
  52. tv_tip.getPaint().setAntiAlias(true);
  53. tv_private_policy = constantDialog.findViewById(ResourceUtil.getId(context, "tv_private_policy"));
  54. tv_private_policy.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
  55. tv_private_policy.getPaint().setAntiAlias(true);
  56. tv_private_policy.setOnClickListener(this);
  57. down_eye_btn.setOnClickListener(this);
  58. btn_get_code.setOnClickListener(this);
  59. close_btn.setOnClickListener(this);
  60. tv_tip.setOnClickListener(this);
  61. et_reg_compete_btn.setOnClickListener(this);
  62. }
  63. @Override
  64. public void onClick(View v) {
  65. int id = v.getId();
  66. if (id == ResourceUtil.getId(context, "btn_get_code")) {
  67. String phone = et_user_phone.getText().toString();
  68. if (phone.length() < 10) {
  69. new TosUtil(context,"blue", context.getString(ResourceUtil.getStringId(context, "xy_pls_input_right_phone"))).show();
  70. // ToastUtil.show(context, context.getString(ResourceUtil.getStringId(context, "xy_pls_input_right_phone")));
  71. return;
  72. }
  73. getPhoneCaptcha((Activity) context,phone,"register");
  74. }else if (id == ResourceUtil.getId(context, "et_reg_compete_btn")) {
  75. registerWithPhone((Activity) context);
  76. }else if (id == ResourceUtil.getId(context, "close_btn")) {
  77. new RegisterLayout(context,constantDialog);
  78. }else if (id == ResourceUtil.getId(context, "tv_tip")) {
  79. String url = SDKSettings.UserCentUrl + URLConstants.USERPROTOCOLWEB + "gcp_code=" + SDKSettings.gcp_code
  80. + "&game_code=" + SDKSettings.game_code;
  81. new WvPageListDialog(context,ResourceUtil.getStyleId(context,"xy_base_dialog"),"用户服务协议",url).show();
  82. }else if (id == ResourceUtil.getId(context, "tv_private_policy")) {
  83. String url = SDKSettings.UserCentUrl + URLConstants.USERPOLICYWEB + "gcp_code=" + SDKSettings.gcp_code
  84. + "&game_code=" + SDKSettings.game_code;
  85. new WvPageListDialog(context,ResourceUtil.getStyleId(context,"xy_base_dialog"),"隐私政策",url).show();
  86. } else if (id == ResourceUtil.getId(context, "down_eye_btn")) {
  87. if (!isShowPwd) {
  88. isShowPwd = true;
  89. et_user_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
  90. down_eye_btn.setImageResource(ResourceUtil.getMipmapId(context, "xy_eye_icon_select"));
  91. } else {
  92. isShowPwd = false;
  93. et_user_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
  94. down_eye_btn.setImageResource(ResourceUtil.getMipmapId(context, "xy_eye_icon_normal"));
  95. }
  96. }
  97. }
  98. private void getPhoneCaptcha(Activity activity, String phone, String action){
  99. NetRequestApi.getPhoneCaptcha(activity, phone, action, new CaptchaCallback() {
  100. @Override
  101. public void onGetSuccess(String msg) {
  102. getCodeSuccess();
  103. new TosUtil(context,"green",context.getString(ResourceUtil.getStringId(context, "xy_send_code_success"))).show();
  104. // ToastUtil.show(context,context.getString(ResourceUtil.getStringId(context, "xy_send_code_success")));
  105. }
  106. @Override
  107. public void onGetFailed(String msg) {
  108. new TosUtil(context,"blue",msg).show();
  109. }
  110. });
  111. }
  112. private void registerWithPhone(final Activity activity){
  113. String code = et_user_code.getText().toString();
  114. final String account = et_user_phone.getText().toString();
  115. final String pwd = et_user_pwd.getText().toString();
  116. String userInfo ="";
  117. if(account.length() < 10 || Utils.judgeStrNull(account))
  118. {
  119. new TosUtil(context,"blue", context.getString(ResourceUtil.getStringId(context, "xy_pls_input_right_phone"))).show();
  120. return;
  121. }
  122. if(pwd.length() < 6 || Utils.judgeStrNull(pwd))
  123. {
  124. new TosUtil(context,"blue", context.getString(ResourceUtil.getStringId(context, "xy_pwd_limit_6"))).show();
  125. return;
  126. }
  127. if(code.length() < 4 || Utils.judgeStrNull(code))
  128. {
  129. new TosUtil(context,"blue", context.getString(ResourceUtil.getStringId(context, "xy_pls_input_right_code"))).show();
  130. return;
  131. }
  132. if (!cb_register.isChecked()){
  133. new TosUtil(context, "blue",context.getString(ResourceUtil.getStringId(context, "xy_pls_checked_reg_tip"))).show();
  134. return;
  135. }
  136. try {
  137. userInfo = SignUtils.encryptRsaByPublicKey(RSAKEY,account+"|"+ pwd);
  138. } catch (Exception e) {
  139. // TODO Auto-generated catch block
  140. e.printStackTrace();
  141. }
  142. registerInterval();
  143. NetRequestApi.registerWithPhone(activity,code,userInfo, new PhoneRegisterCallback() {
  144. @Override
  145. public void onRegisterSuccess(String msg) {
  146. constantDialog.dismiss();
  147. YyrhSdkManager.defaultManager(context).saveUserLoginInfo(context,account,pwd,msg);
  148. SDKEntry.getSdkInstance().adSdkCallback.onRegisterSuccess(account);
  149. }
  150. @Override
  151. public void onRegisterFailed(String msg) {
  152. new TosUtil(context,"blue", msg).show();
  153. }
  154. });
  155. }
  156. private void getCodeSuccess() {
  157. btn_get_code.setEnabled(false);
  158. btn_get_code.setText("60s");
  159. btn_get_code.setBackgroundResource(ResourceUtil.getDrawableId(context,"xy_radius_main_color_1dp"));
  160. TimeCount time = new TimeCount(60000, 1000);
  161. time.start();
  162. }
  163. class TimeCount extends CountDownTimer {
  164. public TimeCount(long millisInFuture, long countDownInterval) {
  165. super(millisInFuture, countDownInterval);
  166. // TODO Auto-generated constructor stub
  167. }
  168. @Override
  169. public void onTick(long millisUntilFinished) {
  170. // TODO Auto-generated method stub
  171. btn_get_code.setText(millisUntilFinished / 1000 + "s");
  172. }
  173. @Override
  174. public void onFinish() {
  175. // TODO Auto-generated method stub
  176. btn_get_code.setEnabled(true);
  177. btn_get_code.setBackgroundResource(ResourceUtil.getDrawableId(context,"xy_radius_main_color_1dp"));
  178. btn_get_code.setText(ResourceUtil.getStringId(context, "xy_get_phone_code"));
  179. }
  180. }
  181. public interface CaptchaCallback {
  182. void onGetSuccess(String msg);
  183. void onGetFailed(String msg);
  184. }
  185. public interface PhoneRegisterCallback {
  186. void onRegisterSuccess(String msg);
  187. void onRegisterFailed(String msg);
  188. }
  189. private void registerInterval() {
  190. et_reg_compete_btn.setEnabled(false);
  191. et_reg_compete_btn.setText("3s");
  192. et_reg_compete_btn.setBackgroundResource(ResourceUtil.getDrawableId(context,"xy_radius_deepgray_bg"));
  193. RegTimeCount time = new RegTimeCount(3000, 1000);
  194. time.start();
  195. }
  196. class RegTimeCount extends CountDownTimer {
  197. public RegTimeCount(long millisInFuture, long countDownInterval) {
  198. super(millisInFuture, countDownInterval);
  199. // TODO Auto-generated constructor stub
  200. }
  201. @Override
  202. public void onTick(long millisUntilFinished) {
  203. // TODO Auto-generated method stub
  204. et_reg_compete_btn.setText(millisUntilFinished / 1000 + "s");
  205. }
  206. @Override
  207. public void onFinish() {
  208. // TODO Auto-generated method stub
  209. et_reg_compete_btn.setEnabled(true);
  210. et_reg_compete_btn.setBackgroundResource(ResourceUtil.getDrawableId(context,"xy_radius_main_color_bg"));
  211. et_reg_compete_btn.setText(ResourceUtil.getStringId(context, "xy_register_success"));
  212. }
  213. }
  214. }