| | |
| | | import android.content.Intent; |
| | | import android.content.SharedPreferences; |
| | | import android.os.Bundle; |
| | | import android.text.Editable; |
| | | import android.text.TextWatcher; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | import android.widget.EditText; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.wpc.library.util.GetManifestDataUtil; |
| | | import com.wpc.library.util.common.StringUtils; |
| | | import com.xiaomi.mipush.sdk.MiPushClient; |
| | | import com.yeshi.ec.rebate.myapplication.BasicTextHttpResponseHandler; |
| | |
| | | import com.yeshi.ec.rebate.myapplication.ui.dialog.ShapeLoadingDialog; |
| | | import com.yeshi.ec.rebate.myapplication.ui.invite.ShareBrowserActivity; |
| | | import com.yeshi.ec.rebate.myapplication.util.KeFuUtil; |
| | | import com.yeshi.ec.rebate.myapplication.util.SystemParamsUtil; |
| | | import com.yeshi.ec.rebate.myapplication.util.TopStatusSettings; |
| | | import com.yeshi.ec.rebate.myapplication.util.umengCustomEvent.UserCustomEvent; |
| | | import com.yeshi.ec.rebate.myapplication.util.user.UserUtil; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | |
| | | import de.greenrobot.event.EventBus; |
| | | |
| | |
| | | public final static int TYPE_BIND = 2;//绑定 |
| | | public final static int TYPE_BIND_WITHOUT_LOGINED = 3;//未登录绑定 |
| | | private ImageView iv_close, iv_contact_kefu, iv_login_tb; |
| | | private TextView tv_user_agreement, tv_privacy_policies; |
| | | private TextView tv_user_agreement, tv_privacy_policies, tv_login; |
| | | LinearLayout ll_user_agreement; |
| | | ShapeLoadingDialog pd; |
| | | String uid; |
| | |
| | | String key;//微信登录尚未绑定手机时回传的标识 |
| | | |
| | | private static String TAG = "LoginSelectActivity"; |
| | | private LinearLayout ll_phone; |
| | | private TextView tv_send_code, tv_login_phone; |
| | | private EditText et_phone, et_code; |
| | | |
| | | //设置视图 |
| | | private void setView(boolean onlining) { |
| | | if (onlining) { |
| | | ll_phone.setVisibility(View.VISIBLE); |
| | | tv_login.setVisibility(View.GONE); |
| | | } else { |
| | | ll_phone.setVisibility(View.GONE); |
| | | tv_login.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | setContentView(R.layout.activity_login); |
| | | |
| | | pd = new ShapeLoadingDialog.Builder(this).build(); |
| | | |
| | | TopStatusSettings.setStatusViewAndDeepColorNoView(this); |
| | | // tv_user_agreement.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); |
| | | initData(getIntent()); |
| | | String from = getIntent().getStringExtra("from"); |
| | | UserCustomEvent.userLogin(this, StringUtils.isEmpty(from) ? "其它" : from); |
| | | EventBus.getDefault().register(this); |
| | | String onlining = ""; |
| | | String channel = GetManifestDataUtil.getAppMetaData(this, "UMENG_CHANNEL"); |
| | | if ("QQ".equalsIgnoreCase(channel)) { |
| | | onlining = SystemParamsUtil.getParam(this, "onlining"); |
| | | } |
| | | |
| | | setView("1".equalsIgnoreCase(onlining) ? true : false); |
| | | } |
| | | |
| | | private void initData(Intent intent) { |
| | |
| | | init(intent); |
| | | addListener(); |
| | | } |
| | | |
| | | Timer timer = null; |
| | | |
| | | @Override |
| | | protected void onNewIntent(Intent intent) { |
| | |
| | | 初始化控件 |
| | | */ |
| | | private void init(Intent intent) { |
| | | ll_phone = findViewById(R.id.ll_phone); |
| | | tv_send_code = findViewById(R.id.tv_send_code); |
| | | tv_login_phone = findViewById(R.id.tv_login_phone); |
| | | et_phone = findViewById(R.id.et_phone); |
| | | et_code = findViewById(R.id.et_code); |
| | | iv_close = findViewById(R.id.iv_close); |
| | | iv_contact_kefu = findViewById(R.id.iv_contact_kefu); |
| | | tv_user_agreement = findViewById(R.id.tv_user_agreement); |
| | |
| | | tv_privacy_policies = findViewById(R.id.tv_privacy_policies); |
| | | iv_login_tb = findViewById(R.id.iv_login_tb); |
| | | ll_user_agreement = findViewById(R.id.ll_user_agreement); |
| | | findViewById(R.id.tv_login).setOnClickListener(this); |
| | | tv_login = findViewById(R.id.tv_login); |
| | | tv_login.setOnClickListener(this); |
| | | iv_login_tb.setOnClickListener(this); |
| | | SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE); |
| | | sp.edit().putBoolean("first", true).commit(); |
| | | uid = intent.getStringExtra("uid"); |
| | | key = intent.getStringExtra("key"); |
| | | getUserConfig(); |
| | | |
| | | tv_login_phone.setOnClickListener(this); |
| | | tv_send_code.setOnClickListener(this); |
| | | |
| | | et_code.addTextChangedListener(new TextWatcher() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | setSetLoginPhoneState(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | et_phone.addTextChangedListener(new TextWatcher() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) { |
| | | setSendCodeState(); |
| | | setSetLoginPhoneState(); |
| | | } |
| | | }); |
| | | setSendCodeState(); |
| | | setSetLoginPhoneState(); |
| | | } |
| | | |
| | | private void setSetLoginPhoneState() { |
| | | //是手机号码 |
| | | if (StringUtils.isMobileNumber(et_phone.getText() + "") && et_code.getText() != null && !StringUtils.isEmpty(et_code.getText() + "")) { |
| | | tv_login_phone.setBackgroundResource(R.drawable.shape_mobile_login_light); |
| | | tv_login_phone.setEnabled(true); |
| | | } else { |
| | | tv_login_phone.setBackgroundResource(R.drawable.shape_mobile_login); |
| | | tv_login_phone.setEnabled(false); |
| | | } |
| | | } |
| | | |
| | | private void setSendCodeState() { |
| | | if (StringUtils.isMobileNumber(et_phone.getText() + "") && lastTime == 0) { |
| | | tv_send_code.setEnabled(true); |
| | | tv_send_code.setTextColor(getResources().getColor(R.color.theme)); |
| | | } else { |
| | | tv_send_code.setEnabled(false); |
| | | tv_send_code.setTextColor(getResources().getColor(R.color.gray)); |
| | | } |
| | | } |
| | | |
| | | |
| | | int lastTime = 0; |
| | | |
| | | /* |
| | | *添加监听 |
| | |
| | | } |
| | | }); |
| | | break; |
| | | |
| | | case R.id.tv_send_code://发送验证码 |
| | | if (timer != null) { |
| | | timer.cancel(); |
| | | timer = null; |
| | | } |
| | | Toast.makeText(this, "验证码已发送,请注意查收", Toast.LENGTH_SHORT); |
| | | lastTime = 60; |
| | | setSendCodeState(); |
| | | timer = new Timer(); |
| | | timer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | tv_send_code.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (lastTime > 0) { |
| | | lastTime--; |
| | | tv_send_code.setText(lastTime + "s重发"); |
| | | if (lastTime <= 0) { |
| | | lastTime = 0; |
| | | setSendCodeState(); |
| | | timer.cancel(); |
| | | tv_send_code.setText("发送验证码"); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }, 0, 1000); |
| | | |
| | | |
| | | break; |
| | | |
| | | case R.id.tv_login_phone://登录 |
| | | loginPhone(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void loginPhone() { |
| | | ShoppingApi.loginNew(getApplicationContext(), et_code.getText() + "", et_phone.getText() + "", "", "1", new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onStart() { |
| | | super.onStart(); |
| | | if (!pd.isShowing()) |
| | | pd.show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.optString("code").equalsIgnoreCase("0")) { |
| | | Gson gson = new GsonBuilder().serializeNulls().create(); |
| | | JSONObject data = jsonObject.optJSONObject("data"); |
| | | final UserInfo info = gson.fromJson(data.optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() { |
| | | }.getType()); |
| | | SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sp.edit(); |
| | | editor.putBoolean("isLogin", true); |
| | | editor.putBoolean("isFirstInput", false); |
| | | editor.putString("uid", info.getId()); |
| | | editor.putString("openid", info.getOpenid()); |
| | | editor.putString("portrait", info.getPortrait()); |
| | | editor.commit(); |
| | | |
| | | MiPushClient.setAlias(getApplicationContext(), info.getId(), null); |
| | | |
| | | //保存邀请码 |
| | | String inviteCode = data.optString("inviteCode"); |
| | | UserUtil.setInviteCode(getApplicationContext(), inviteCode, info.getId()); |
| | | Toast.makeText(getApplicationContext(), "恭喜你,登录成功", Toast.LENGTH_SHORT).show(); |
| | | setResult(100); |
| | | finish(); |
| | | } else { |
| | | Toast.makeText(getApplicationContext(), jsonObject.optString("msg"), Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | if (pd.isShowing()) |
| | | pd.dismiss(); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |