陈奇
2018-11-30 c40ab5711d9025a5e25a85b5b24be72cfa90e375
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package com.moral.yunfushao.activity;
 
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
 
import com.lzy.okgo.cache.CacheMode;
import com.moral.andbrickslib.utils.FastJsonTools;
import com.moral.andbrickslib.utils.StatusBarUtil;
import com.moral.yunfushao.MainActivity;
import com.moral.yunfushao.MainApp;
import com.moral.yunfushao.R;
import com.moral.yunfushao.base.BaseActivity;
import com.moral.yunfushao.common.API;
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 java.util.HashMap;
import java.util.Map;
 
/**
 * Created by haijiang on 2017/5/9.
 */
 
public class LoginActivity extends BaseActivity {
    private Button bt_sure, 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) {
 
    }
 
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.translucentStatusBar(LoginActivity.this);
        regToWx();
    }
 
    private void regToWx() {
        iwxapi = WXAPIFactory.createWXAPI(this, "app_id", true);
        iwxapi.registerApp("app_id");
    }
 
    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
    protected int getLayoutId() {
        return R.layout.ac_login_layout;
    }
 
    @Override
    protected void initViews() {
        bt_sure = findView(R.id.bt_sure);
        tv_forget = findView(R.id.tv_forget);
        tv_register = findView(R.id.tv_register);
        et_phone = findView(R.id.et_phone);
        et_pwd = findView(R.id.et_pwd);
        weixinlogin = findView(R.id.weixinlogin);
        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
    protected void initListener() {
        bt_sure.setOnClickListener(this);
        tv_forget.setOnClickListener(this);
        tv_register.setOnClickListener(this);
        weixinlogin.setOnClickListener(this);
    }
 
    @Override
    protected void initData() {
 
    }
 
    @Override
    protected void processClick(View view) {
        switch (view.getId()) {
            case R.id.bt_sure:
                String userphone = et_phone.getText().toString().trim();
                String password = et_pwd.getText().toString().trim();
                if (TextUtils.isEmpty(userphone)) {
                    mToatUtils.showSingletonToast("请输入手机号");
                    return;
                }
                if (TextUtils.isEmpty(password)) {
                    mToatUtils.showSingletonToast("请输入密码");
                    return;
                }
                login(userphone, password);
                break;
            case R.id.tv_forget:
                Intent intent = new Intent(LoginActivity.this, ForgetPasswordActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_register:
                Intent intentRgister = new Intent(LoginActivity.this, RegisterActivity.class);
                startActivity(intentRgister);
                break;
            case R.id.weixinlogin:
                weixinlogin();
                break;
        }
    }
 
    private void weixinlogin() {
        sendReq();
    }
 
    @Override
    protected void onErrorPageClick() {
 
    }
 
    private void login(String tel, final String pwd) {
        String url = API.LOGIN;
        Map<String, String> params = new HashMap<>();
        params.put("phone", tel);
        params.put("password", pwd);
        HttpUtils.doPost(url, params, CacheMode.DEFAULT, true, new HttpCallBack() {
            @Override
            public void onSuccess(String res, String msg) {
                mToatUtils.showSingletonToast(msg);
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                User user = FastJsonTools.getJson(res, User.class);
                if (user != null) {
                    MainApp.theApp.sharedPreferencesUtil.saveLoginInfo(user);
                    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();
                }
            }
 
            @Override
            public void showLoadingDialog() {
                progressDialog.setTitleText("正在登陆...");
                progressDialog.show();
            }
 
            @Override
            public void onFail(int errno, String s) {
                mToatUtils.showSingletonToast(s);
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
            }
        });
    }
}