| | |
| | | package com.moral.yunfushao.activity; |
| | | |
| | | import android.animation.ObjectAnimator; |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.support.annotation.Nullable; |
| | |
| | | import android.view.View; |
| | | import android.widget.Button; |
| | | import android.widget.EditText; |
| | | import android.widget.ImageView; |
| | | import android.widget.TextView; |
| | | |
| | | import com.lzy.okgo.cache.CacheMode; |
| | | import com.moral.andbrickslib.utils.FastJsonTools; |
| | | import com.moral.andbrickslib.utils.NetworkUtil; |
| | | import com.moral.andbrickslib.utils.StatusBarUtil; |
| | | import com.moral.yunfushao.MainActivity; |
| | | import com.moral.yunfushao.MainApp; |
| | |
| | | import com.moral.yunfushao.httputils.HttpCallBack; |
| | | import com.moral.yunfushao.httputils.HttpUtils; |
| | | import com.moral.yunfushao.model.User; |
| | | import com.tencent.mm.opensdk.modelmsg.SendAuth; |
| | | import com.tencent.mm.opensdk.openapi.IWXAPI; |
| | | import com.tencent.mm.opensdk.openapi.WXAPIFactory; |
| | | import com.moral.yunfushao.utils.SharedPreferencesUtil; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | */ |
| | | |
| | | public class LoginActivity extends BaseActivity { |
| | | private Button bt_sure, weixinlogin; |
| | | private Button bt_sure; |
| | | private ImageView weixinlogin; |
| | | private TextView tv_forget, tv_register; |
| | | private EditText et_phone, et_pwd; |
| | | private IWXAPI iwxapi; |
| | | private ObjectAnimator animator; |
| | | |
| | | @Override |
| | | protected void getBundleExtras(Bundle extras) { |
| | |
| | | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | StatusBarUtil.translucentStatusBar(LoginActivity.this); |
| | | regToWx(); |
| | | |
| | | int type = SharedPreferencesUtil.getUtil(this).getLoginInfo().getLogin_type(); |
| | | |
| | | if (!NetworkUtil.isAvailable(this)) { |
| | | return; |
| | | } |
| | | switch (type) { |
| | | case 1: |
| | | //手机登陆 |
| | | goHome(); |
| | | break; |
| | | case 2: |
| | | //微信登陆 |
| | | sendReq(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void regToWx() { |
| | | iwxapi = WXAPIFactory.createWXAPI(this, "app_id", true); |
| | | iwxapi.registerApp("app_id"); |
| | | private void goHome() { |
| | | if (!TextUtils.isEmpty(MainApp.userId)) { |
| | | Intent intent = new Intent(this, MainActivity.class); |
| | | startActivity(intent); |
| | | } else { |
| | | Intent intent = new Intent(this, LoginActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | finish(); |
| | | } |
| | | |
| | | private void sendReq() { |
| | | //授权 |
| | | SendAuth.Req req = new SendAuth.Req(); |
| | | req.scope = "snsapi_userinfo"; |
| | | req.state = "wechat_sdk_demo_test"; |
| | | iwxapi.sendReq(req); |
| | | System.out.println("chenqi fasongcehngqo"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | |
| | | et_phone = findView(R.id.et_phone); |
| | | et_pwd = findView(R.id.et_pwd); |
| | | weixinlogin = findView(R.id.weixinlogin); |
| | | |
| | | |
| | | // et_phone.setText("18362724160"); |
| | | // et_pwd.setText("123456"); |
| | | initAnimator(); |
| | | } |
| | | |
| | | private void initAnimator() { |
| | | // ObjectAnimator an = ObjectAnimator.ofFloat(bt_sure, "translationX", 500f, 0f); |
| | | // an.start(); |
| | | //// ObjectAnimator translationY = ObjectAnimator.ofFloat(bt_sure, "rotation", 360f, 0f); |
| | | // ObjectAnimator scaleY = ObjectAnimator.ofFloat(bt_sure, "scaleY", 0f, 1f); |
| | | // ObjectAnimator scaleX = ObjectAnimator.ofFloat(bt_sure, "scaleX", 0f, 1f); |
| | | // |
| | | // AnimatorSet oo = new AnimatorSet(); |
| | | // oo.playTogether(scaleY, scaleX); |
| | | // oo.setDuration(500); |
| | | // oo.start(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | private void login(String tel, final String pwd) { |
| | | String url = API.LOGIN; |
| | | final String url = API.LOGIN; |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("phone", tel); |
| | | params.put("password", pwd); |
| | |
| | | User user = FastJsonTools.getJson(res, User.class); |
| | | if (user != null) { |
| | | MainApp.theApp.sharedPreferencesUtil.saveLoginInfo(user); |
| | | user.setLogin_type(1); |
| | | MainApp.theApp.userId = user.get_id(); |
| | | Intent intent = new Intent(getApplicationContext(), MainActivity.class); |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putBoolean("islogin", true); |
| | | intent.putExtras(bundle); |
| | | startActivity(intent); |
| | | finish(); |
| | | jumpMain(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | protected void onStop() { |
| | | super.onStop(); |
| | | finish(); |
| | | } |
| | | |
| | | private void jumpMain() { |
| | | Intent intent = new Intent(getApplicationContext(), MainActivity.class); |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putBoolean("islogin", true); |
| | | intent.putExtras(bundle); |
| | | startActivity(intent); |
| | | finish(); |
| | | } |
| | | } |