灭霸-个人冲刺第七天
1, 昨天的成就:
a) 完成的任务:框架搭建,确定失物招领页面布局
b) 所花时间:7h
c) 还剩余1h
2, 遇到的困难:
a) 由于前期框架没有想好,很多页面跳转都要更改,例如JAVA文件的函数,要重新更改。
3, 今天的任务:
a) 框架整理
b) 算法初步实现
1 package com.weicent.android.csma.ui; 2 3 import android.content.Intent; 4 import android.os.Bundle; 5 import android.view.KeyEvent; 6 import android.view.View; 7 import android.widget.EditText; 8 9 import com.ab.activity.AbActivity; 10 import com.ab.fragment.AbDialogFragment; 11 import com.ab.fragment.AbLoadDialogFragment; 12 import com.ab.util.AbDialogUtil; 13 import com.ab.util.AbStrUtil; 14 import com.weicent.android.csma.R; 15 import com.weicent.android.csma.data.Global; 16 import com.weicent.android.csma.data.NetWorkWeb; 17 import com.weicent.android.csma.data.ResultHandlerForJson; 18 import com.weicent.android.csma.data.model.result.Users; 19 import com.weicent.android.csma.data.result.model.ResUsers; 20 import com.weicent.android.csma.support.T; 21 22 import org.apache.http.Header; 23 24 import butterknife.Bind; 25 import butterknife.ButterKnife; 26 import butterknife.OnClick; 27 28 /** 29 * 登录 30 */ 31 public class LoginActivity extends AbActivity { 32 33 @Bind(R.id.textName) 34 EditText textName; 35 @Bind(R.id.textPwd) 36 EditText textPwd; 37 private long exitTime = 0; 38 39 @Override 40 protected void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 setContentView(R.layout.activity_login); 43 ButterKnife.bind(this); 44 } 45 46 //操作事件 47 @OnClick({R.id.btnSign, R.id.btnLogin}) 48 public void onClick(View view) { 49 switch (view.getId()) { 50 case R.id.btnSign://注册 51 sign(); 52 break; 53 case R.id.btnLogin://登录 54 login(); 55 break; 56 } 57 } 58 59 //注册 60 private void sign() { 61 startActivity(new Intent(this, SignActivity.class)); 62 } 63 64 //登录 65 private void login() { 66 final AbLoadDialogFragment dialogFragment = AbDialogUtil.showLoadDialog(this, R.drawable.ic_load, "正在登录,请稍候..."); 67 dialogFragment.setTextColor(R.color.black); 68 dialogFragment.setAbDialogOnLoadListener(new AbDialogFragment.AbDialogOnLoadListener() { 69 @Override 70 public void onLoad() { 71 NetWorkWeb.getInstance().doRequest(Global.URL_USERS_SERVLET, new ResultHandlerForJson<ResUsers>(ResUsers.class) { 72 73 @Override 74 public void onSuccess(int statusCode, Header[] headers, ResUsers resultJson) { 75 dialogFragment.loadFinish(); 76 if (resultJson.errorcode == 0) { 77 NetWorkWeb.getInstance().doLogResultModelString("MineServlet first", resultJson.data); 78 if (resultJson.data != null && !AbStrUtil.isEmpty(resultJson.data.usersName)) { 79 Users model = new Users(); 80 model.setAll(resultJson.data.usersName, resultJson.data.usersPwd, resultJson.data.id); 81 if (model != null) { 82 startActivity(new Intent(LoginActivity.this, MainActivity.class)); 83 LoginActivity.this.finish(); 84 } 85 } else { 86 T.showShort(LoginActivity.this, "登录失败,请重试"); 87 } 88 89 } else { 90 T.showShort(LoginActivity.this, resultJson.errormsg); 91 } 92 } 93 94 @Override 95 public void onFailure(int statusCode, Header[] headers, String resultString, Throwable throwable) { 96 T.showShort(LoginActivity.this, "登录失败,请重试"); 97 } 98 99 @Override 100 public void onFinish() { 101 dialogFragment.loadFinish(); 102 } 103 }, "{\"usersName\":\"" + textName.getText().toString().trim() + "\"" + 104 ",\"usersPwd\":\"" + textPwd.getText().toString().trim() + "\"}", 5); 105 } 106 }); 107 } 108 109 /** 110 * 按键点击事件处理 111 * 112 * @param keyCode 113 * @param event 114 * @return 115 */ 116 @Override 117 public boolean onKeyDown(int keyCode, KeyEvent event) { 118 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { 119 if ((System.currentTimeMillis() - exitTime) > 2000) { 120 T.showLong(LoginActivity.this, "再按一次退出程序"); 121 exitTime = System.currentTimeMillis(); 122 } else { 123 this.finish(); 124 System.exit(0); 125 } 126 return true; 127 } 128 return super.onKeyDown(keyCode, event); 129 } 130 131 @Override 132 protected void onDestroy() { 133 super.onDestroy(); 134 if (NetWorkWeb.getInstance().getHttpClient() == null) { 135 // AbLogUtil.d("cancelAllRequests", " is null"); 136 return; 137 } else { 138 NetWorkWeb.getInstance().getHttpClient().cancelAllRequests(true);//关闭所有请求 139 // AbLogUtil.d("cancelAllRequests"," is ok"); 140 } 141 } 142 }