123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- package com.yyrh.ui;
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.Paint;
- import android.os.CountDownTimer;
- import android.text.method.HideReturnsTransformationMethod;
- import android.text.method.PasswordTransformationMethod;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.yyrh.constant.SDKSettings;
- import com.yyrh.constant.URLConstants;
- import com.yyrh.networking.NetRequestApi;
- import com.yyrh.sdk.SDKEntry;
- import com.yyrh.sdk.YyrhSdkManager;
- import com.yyrh.ui.floatmenu.WvPageListDialog;
- import com.yyrh.utils.ResourceUtil;
- import com.yyrh.utils.SignUtils;
- import com.yyrh.utils.TosUtil;
- import com.yyrh.utils.Utils;
- import static com.yyrh.constant.URLConstants.RSAKEY;
- public class PhoneRegisterLayout implements View.OnClickListener {
- private Context context;
- private ConstantDialog constantDialog;
- private EditText et_user_phone,et_user_code,et_user_pwd;
- private Button btn_get_code,et_reg_compete_btn;
- private ImageView down_eye_btn,close_btn;
- private boolean isShowPwd = false;
- private CheckBox cb_register;
- private TextView tv_tip,tv_private_policy;
- public PhoneRegisterLayout(Context context, ConstantDialog constantDialog){
- this.context = context;
- this.constantDialog = constantDialog;
- if (SDKSettings.isLandscape){
- constantDialog.setContentView(ResourceUtil.getLayoutId(context, "xy_phone_register_dialog"));
- }else{
- constantDialog.setContentView(ResourceUtil.getLayoutId(context, "xy_phone_register_dialog_protrait"));
- }
- et_user_phone = constantDialog.findViewById(ResourceUtil.getId(context, "et_user_phone"));
- et_user_code = constantDialog.findViewById(ResourceUtil.getId(context, "et_user_code"));
- et_user_pwd = constantDialog.findViewById(ResourceUtil.getId(context, "et_user_pwd"));
- btn_get_code = constantDialog.findViewById(ResourceUtil.getId(context, "btn_get_code"));
- et_reg_compete_btn = constantDialog.findViewById(ResourceUtil.getId(context, "et_reg_compete_btn"));
- down_eye_btn = constantDialog.findViewById(ResourceUtil.getId(context, "down_eye_btn"));
- cb_register = constantDialog.findViewById(ResourceUtil.getId(context, "cb_register"));
- close_btn = constantDialog.findViewById(ResourceUtil.getId(context, "close_btn"));
- tv_tip = constantDialog.findViewById(ResourceUtil.getId(context, "tv_tip"));
- tv_tip.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
- tv_tip.getPaint().setAntiAlias(true);
- tv_private_policy = constantDialog.findViewById(ResourceUtil.getId(context, "tv_private_policy"));
- tv_private_policy.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
- tv_private_policy.getPaint().setAntiAlias(true);
- tv_private_policy.setOnClickListener(this);
- down_eye_btn.setOnClickListener(this);
- btn_get_code.setOnClickListener(this);
- close_btn.setOnClickListener(this);
- tv_tip.setOnClickListener(this);
- et_reg_compete_btn.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- int id = v.getId();
- if (id == ResourceUtil.getId(context, "btn_get_code")) {
- String phone = et_user_phone.getText().toString();
- if (phone.length() < 10) {
- new TosUtil(context,"blue", context.getString(ResourceUtil.getStringId(context, "xy_pls_input_right_phone"))).show();
- // ToastUtil.show(context, context.getString(ResourceUtil.getStringId(context, "xy_pls_input_right_phone")));
- return;
- }
- getPhoneCaptcha((Activity) context,phone,"register");
- }else if (id == ResourceUtil.getId(context, "et_reg_compete_btn")) {
- registerWithPhone((Activity) context);
- }else if (id == ResourceUtil.getId(context, "close_btn")) {
- new RegisterLayout(context,constantDialog);
- }else if (id == ResourceUtil.getId(context, "tv_tip")) {
- String url = SDKSettings.UserCentUrl + URLConstants.USERPROTOCOLWEB + "gcp_code=" + SDKSettings.gcp_code
- + "&game_code=" + SDKSettings.game_code;
- new WvPageListDialog(context,ResourceUtil.getStyleId(context,"xy_base_dialog"),"用户服务协议",url).show();
- }else if (id == ResourceUtil.getId(context, "tv_private_policy")) {
- String url = SDKSettings.UserCentUrl + URLConstants.USERPOLICYWEB + "gcp_code=" + SDKSettings.gcp_code
- + "&game_code=" + SDKSettings.game_code;
- new WvPageListDialog(context,ResourceUtil.getStyleId(context,"xy_base_dialog"),"隐私政策",url).show();
- } else if (id == ResourceUtil.getId(context, "down_eye_btn")) {
- if (!isShowPwd) {
- isShowPwd = true;
- et_user_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
- down_eye_btn.setImageResource(ResourceUtil.getMipmapId(context, "xy_eye_icon_select"));
- } else {
- isShowPwd = false;
- et_user_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
- down_eye_btn.setImageResource(ResourceUtil.getMipmapId(context, "xy_eye_icon_normal"));
- }
- }
- }
- private void getPhoneCaptcha(Activity activity, String phone, String action){
- NetRequestApi.getPhoneCaptcha(activity, phone, action, new CaptchaCallback() {
- @Override
- public void onGetSuccess(String msg) {
- getCodeSuccess();
- new TosUtil(context,"green",context.getString(ResourceUtil.getStringId(context, "xy_send_code_success"))).show();
- // ToastUtil.show(context,context.getString(ResourceUtil.getStringId(context, "xy_send_code_success")));
- }
- @Override
- public void onGetFailed(String msg) {
- new TosUtil(context,"blue",msg).show();
- }
- });
- }
- private void registerWithPhone(final Activity activity){
- String code = et_user_code.getText().toString();
- final String account = et_user_phone.getText().toString();
- final String pwd = et_user_pwd.getText().toString();
- String userInfo ="";
- if(account.length() < 10 || Utils.judgeStrNull(account))
- {
- new TosUtil(context,"blue", context.getString(ResourceUtil.getStringId(context, "xy_pls_input_right_phone"))).show();
- return;
- }
- if(pwd.length() < 6 || Utils.judgeStrNull(pwd))
- {
- new TosUtil(context,"blue", context.getString(ResourceUtil.getStringId(context, "xy_pwd_limit_6"))).show();
- return;
- }
- if(code.length() < 4 || Utils.judgeStrNull(code))
- {
- new TosUtil(context,"blue", context.getString(ResourceUtil.getStringId(context, "xy_pls_input_right_code"))).show();
- return;
- }
- if (!cb_register.isChecked()){
- new TosUtil(context, "blue",context.getString(ResourceUtil.getStringId(context, "xy_pls_checked_reg_tip"))).show();
- return;
- }
- try {
- userInfo = SignUtils.encryptRsaByPublicKey(RSAKEY,account+"|"+ pwd);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- registerInterval();
- NetRequestApi.registerWithPhone(activity,code,userInfo, new PhoneRegisterCallback() {
- @Override
- public void onRegisterSuccess(String msg) {
- constantDialog.dismiss();
- YyrhSdkManager.defaultManager(context).saveUserLoginInfo(context,account,pwd,msg);
- SDKEntry.getSdkInstance().adSdkCallback.onRegisterSuccess(account);
- }
- @Override
- public void onRegisterFailed(String msg) {
- new TosUtil(context,"blue", msg).show();
- }
- });
- }
- private void getCodeSuccess() {
- btn_get_code.setEnabled(false);
- btn_get_code.setText("60s");
- btn_get_code.setBackgroundResource(ResourceUtil.getDrawableId(context,"xy_radius_main_color_1dp"));
- TimeCount time = new TimeCount(60000, 1000);
- time.start();
- }
- class TimeCount extends CountDownTimer {
- public TimeCount(long millisInFuture, long countDownInterval) {
- super(millisInFuture, countDownInterval);
- // TODO Auto-generated constructor stub
- }
- @Override
- public void onTick(long millisUntilFinished) {
- // TODO Auto-generated method stub
- btn_get_code.setText(millisUntilFinished / 1000 + "s");
- }
- @Override
- public void onFinish() {
- // TODO Auto-generated method stub
- btn_get_code.setEnabled(true);
- btn_get_code.setBackgroundResource(ResourceUtil.getDrawableId(context,"xy_radius_main_color_1dp"));
- btn_get_code.setText(ResourceUtil.getStringId(context, "xy_get_phone_code"));
- }
- }
- public interface CaptchaCallback {
- void onGetSuccess(String msg);
- void onGetFailed(String msg);
- }
- public interface PhoneRegisterCallback {
- void onRegisterSuccess(String msg);
- void onRegisterFailed(String msg);
- }
- private void registerInterval() {
- et_reg_compete_btn.setEnabled(false);
- et_reg_compete_btn.setText("3s");
- et_reg_compete_btn.setBackgroundResource(ResourceUtil.getDrawableId(context,"xy_radius_deepgray_bg"));
- RegTimeCount time = new RegTimeCount(3000, 1000);
- time.start();
- }
- class RegTimeCount extends CountDownTimer {
- public RegTimeCount(long millisInFuture, long countDownInterval) {
- super(millisInFuture, countDownInterval);
- // TODO Auto-generated constructor stub
- }
- @Override
- public void onTick(long millisUntilFinished) {
- // TODO Auto-generated method stub
- et_reg_compete_btn.setText(millisUntilFinished / 1000 + "s");
- }
- @Override
- public void onFinish() {
- // TODO Auto-generated method stub
- et_reg_compete_btn.setEnabled(true);
- et_reg_compete_btn.setBackgroundResource(ResourceUtil.getDrawableId(context,"xy_radius_main_color_bg"));
- et_reg_compete_btn.setText(ResourceUtil.getStringId(context, "xy_register_success"));
- }
- }
- }
|