| | |
| | | package com.moral.screen.activity; |
| | | |
| | | import android.content.Intent; |
| | | import android.content.SearchRecentSuggestionsProvider; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | | import android.widget.Button; |
| | | import android.widget.EditText; |
| | | |
| | | import com.lzy.okgo.cache.CacheMode; |
| | | import com.moral.screen.MainApp; |
| | | import com.moral.screen.R; |
| | | import com.moral.screen.base.BaseActivity; |
| | | import com.moral.screen.common.API; |
| | | import com.moral.screen.httputils.HttpCallBack; |
| | | |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.HashMap; |
| | | |
| | | /** |
| | | * 登录界面 |
| | |
| | | */ |
| | | |
| | | public class LoginActivity extends BaseActivity { |
| | | private Button bt_sure; |
| | | private EditText et_phone, et_pwd; |
| | | |
| | | @Override |
| | | protected void getBundleExtras(Bundle extras) { |
| | | |
| | |
| | | |
| | | @Override |
| | | protected void initViews() { |
| | | bt_sure = findView(R.id.bt_sure); |
| | | et_phone = findView(R.id.et_phone); |
| | | et_pwd = findView(R.id.et_pwd); |
| | | et_phone.setText("admin"); |
| | | et_pwd.setText("123456"); |
| | | } |
| | | |
| | | @Override |
| | | protected void initListener() { |
| | | |
| | | bt_sure.setOnClickListener(this); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | protected void processClick(View view) { |
| | | switch (view.getId()) { |
| | | case R.id.bt_sure: |
| | | String phone = et_phone.getText().toString(); |
| | | if (TextUtils.isEmpty(phone)) { |
| | | mToatUtils.showSingletonToast("请输入手机号码"); |
| | | return; |
| | | } |
| | | String password = et_pwd.getText().toString(); |
| | | if (TextUtils.isEmpty(password)) { |
| | | mToatUtils.showSingletonToast("请输入密码"); |
| | | return; |
| | | } |
| | | login(phone, password); |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | protected void onErrorPageClick() { |
| | | |
| | | } |
| | | |
| | | private void login(String phone, String password) { |
| | | HashMap<String, String> params = new HashMap<>(); |
| | | params.put("account", phone); |
| | | params.put("password", password); |
| | | mHttpUtils.doGet(API.LOGIN, params, CacheMode.DEFAULT, true, new HttpCallBack() { |
| | | @Override |
| | | public void onSuccess(String res, String msg) { |
| | | if (progressDialog.isShowing()) { |
| | | progressDialog.dismiss(); |
| | | } |
| | | try { |
| | | JSONObject json = new JSONObject(res); |
| | | int organizationId = json.optInt("organizationId"); |
| | | MainApp.theApp.orgId = organizationId; |
| | | MainApp.theApp.mSharedPreferencesUtil.saveOrgId(organizationId); |
| | | Intent intent = new Intent(LoginActivity.this, MapActivity.class); |
| | | startActivity(intent); |
| | | finish(); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void showLoadingDialog() { |
| | | progressDialog.setTitleText("正在登录..."); |
| | | progressDialog.show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onFail(int errno, String s) { |
| | | mToatUtils.showSingletonToast(s); |
| | | if (progressDialog.isShowing()) { |
| | | progressDialog.dismiss(); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |