[关闭]
@myron-lee 2015-01-15T14:51:00.000000Z 字数 2913 阅读 1291

1月15日

每日记录


1.爱家政客户版完善

1.修改 ContactActivity,使其显示服务器上的数据

网络请求使用 Volley。暂时不进行缓存。利用数据库缓存不够方便。
使用 Volley 的模板代码

  1. final ProgressAndResultDialog progressAndResultDialog = new ProgressAndResultDialog(this);
  2. progressAndResultDialog.showProgress("正在刷新公告...");
  3. StringRequest refreshNoticeRequest = new StringRequest(Request.Method.POST, URL.REFRESH_MESSAGE, new Response.Listener<String>() {
  4. @Override
  5. public void onResponse(String response) {
  6. switch (Integer.valueOf(response)) {
  7. case 0:
  8. progressAndResultDialog.showResult(false, "抱歉,出错了~");
  9. break;
  10. case 1:
  11. progressAndResultDialog.showResult(true, "刷新成功!");
  12. case 2:
  13. progressAndResultDialog.showResult(true, "刷新成功!");
  14. refreshNoticeListView();
  15. default:
  16. break;
  17. }
  18. }
  19. }, new Response.ErrorListener() {
  20. @Override
  21. public void onErrorResponse(VolleyError error) {
  22. Log.e("", error.getMessage());
  23. progressAndResultDialog.showResult(false, "抱歉,出错了~");
  24. }
  25. }){
  26. @Override
  27. public Map<String, String> getHeaders() throws AuthFailureError {
  28. HashMap<String, String> headers = new HashMap<String, String>();
  29. headers.put("Content-Type", "application/json; charset=utf-8");
  30. // headers.put("User-agent", "Mozilla/5.0");
  31. return headers;
  32. }
  33. @Override
  34. protected Map<String, String> getParams() throws AuthFailureError {
  35. String latestMessagePubTime = dbHelper.getLatestMessagePubTime();
  36. Map<String, String> params = new HashMap<String, String>();
  37. params.put("latestMsgPubTime", latestMessagePubTime);
  38. return params;
  39. }
  40. @Override
  41. protected Response<String> parseNetworkResponse(NetworkResponse response) {
  42. int parseResult = parseRefreshNoticeResponse(new String(response.data));
  43. return Response.success(String.valueOf(parseResult), getCacheEntry());
  44. }
  45. };
  46. refreshNoticeRequest.setTag(TAG);
  47. RequestQueueSingleton.getInstance(context).addToRequestQueue(refreshNoticeRequest);

这个Activity必须用到本机号码,所以我假设用户已经使用手机号登录,且把手机号存在Prefrence 中了, key值为thisPhoneNum。
拷贝 RequestQueueSingleton 到 net 文件夹下。
为什么不用 singleton 就没把请求发出去呢,发出去了,谁叫你输出日志不加 tag 的,没看到吧。

  1. private void startCallActivity(String phoneNumber)
  2. {
  3. try
  4. {
  5. StringBuilder builder = new StringBuilder();
  6. builder.append("tel:");
  7. builder.append(phoneNumber);
  8. Intent intent = new Intent(android.content.Intent.ACTION_DIAL, Uri.parse(builder.toString()));
  9. startActivity(intent);
  10. }
  11. catch(android.content.ActivityNotFoundException e)
  12. {
  13. // can't start activity
  14. }
  15. }

因为牵扯到图片,不能再用 SimpleAdapter。需要自定义 Adapter。用了 ViewHolderAdapter,只用自己写findView和 setData两部分。确实方便,应该继续使用。它利用了反射和泛型把 ViewHolder和 Adapter 分离开了。只用写 ViewHolder就行啦。可以写博客

  1. public View getView(int position, View convert, ViewGroup parent) {
  2. ViewHolder<T> holder = null;
  3. if (convert == null) {
  4. convert = mInflater.inflate(mResource, parent, false);
  5. try {
  6. holder = mClass.getDeclaredConstructor(View.class).newInstance(convert);
  7. } catch (Exception e) {
  8. e.printStackTrace();
  9. }
  10. convert.setTag(holder);
  11. } else {
  12. holder = (ViewHolder<T>) convert.getTag();
  13. }
  14. holder.setItem(mDatas.get(position));
  15. return convert;
  16. }

使用的时候注意一下,自定义的ViewHolder类一定要对 ViewHolderAdapter 类可见。因为后者要通过反射,创建前者的对象。最好放在一个包里面。

2.Emilie 着手

1.CameraFragment

首先好好阅读自己写的代码,跟自己学习。

2.建立工程

1.建包、加入工具类(Config、LogCat、PrefUtil(好像用不着))
  1. private Context context = getApplicationContext();

错误,类加载的时候,还不能 getApplicationContext

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注