/** * 后台code处理默认调用全局的code处理 * * @param response */ public void OnCode(Response response) { CodeHandler codehandler = IocContainer.getShare().get(CodeHandler.class); if (codehandler != null) { if (mContext == null) { mContext = IocContainer.getShare().getApplicationContext(); } codehandler.onCode(mContext, response, response.code); } }
/** 错误处理 */ public void onErray(Response response) { if (response.code != null) { if (response.msg != null) { IDialog dialoger = IocContainer.getShare().get(IDialog.class); dialoger.showToastShort(mContext, response.msg); // } } }
@Override public void hanlder(Context context, Response response) { JSONObject jo = response.jSON(); if (!TextUtils.isEmpty(JSONUtil.getString(jo, "success"))) { if (JSONUtil.getString(jo, "success").equals("false")) { String code = JSONUtil.getString(jo, "code"); String title = ""; String msg = ""; if (code.equals("timeout")) { title = "网络超时"; msg = "亲,您的网络不给力,连接已超时~"; } else if (code.equals("netError") || code.equals("netErrorButCache")) { title = "网络太慢"; msg = "网络太慢,请换个好点的网络试试~"; } else if (code.equals("noNetError")) { title = "网络错误"; msg = "当前网络不可用,请检查网络哦~"; } IocContainer.getShare().get(IDialog.class).showToastLong(context, msg); // IocContainer.getShare().get(IDialog.class).showErrorDialog(context, title, msg, null); } } if (!response.isSuccess()) { IocContainer.getShare().get(IDialog.class).showToastLong(context, response.getMsg()); // String error = JSONUtil.getString(response.jSON(), "errorCode"); // if ("macerror".equals(error)) // { // } // else if ("tokenerror".equals(error)) // { // } // else // { // String code = JSONUtil.getString(response.jSON(), "code"); // if ("noNetError".equals(code)) // { // IocContainer.getShare().get(IDialog.class).showToastLong(context, response.getMsg()); // } // } } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (!isExit) { isExit = true; IocContainer.getShare().get(IDialog.class).showToastShort(self, "再按一次退出程序"); mHandler.postDelayed(new ExitRunnable(), 2000); } else { Intent it = new Intent(self, MsgService.class); stopService(it); ActivityTack.getInstanse().exit(self); } return false; } return super.onKeyDown(keyCode, event); }
public void initView() { mHandler = new Handler(); slist = new Stack<Fragment>(); fm = getSupportFragmentManager(); tabV = (LinearLayout) findViewById(R.id.tab); activeFilterPop = ActiveFilterPop.getInstance(self); titleBar = findViewById(R.id.titlebar); initTab(); setTab(0); per = IocContainer.getShare().get(CarPlayPerference.class); per.load(); if (per.isShowMainGuilde == 0) { findViewById(R.id.guide).setVisibility(View.VISIBLE); } findViewById(R.id.know) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { per.load(); per.isShowMainGuilde = 1; per.commit(); findViewById(R.id.guide).setVisibility(View.GONE); } }); msgT = (ImageView) findViewById(R.id.msg_point); chatPointI = (ImageView) findViewById(R.id.chat_point); connectionListener = new MyConnectionListener(); EMChatManager.getInstance().addConnectionListener(connectionListener); groupChangeListener = new MyGroupChangeListener(); // 注册群聊相关的listener EMGroupManager.getInstance().addGroupChangeListener(groupChangeListener); }
@Override public void handleMessage(Message msg) { NetTask task = (NetTask) msg.obj; Response response = task.getResponse(); // 全局处理 GlobalCodeHandler golbal1 = IocContainer.getShare().get(GlobalCodeHandler.class); if (golbal1 != null) { golbal1.hanlder(task.mContext, response); } switch (msg.what) { case TRANSFER_DOCANCEL: try { task.onCancelled(); } catch (Exception e) { if (!Const.net_error_try) { throw new RuntimeException(e); } } break; case TRANSFER_DOERROR: // 网络访问失败时关闭对话框 if (task.dialog != null) { task.dialog.dismiss(); task.dialog = null; } try { task.onErray(response); } catch (Exception e) { if (!Const.net_error_try) { throw new RuntimeException(e); } } break; case TRANSFER_DOERROR_ForCache: try { task.onErray(task.cacheResponse); } catch (Exception e) { if (!Const.net_error_try) { throw new RuntimeException(e); } } break; case TRANSFER_DOUI: if (task.dialog != null) { task.dialog.dismiss(); task.dialog = null; } try { task.doInUI(response, msg.what); } catch (Exception e) { if (!Const.net_error_try) { throw new RuntimeException(e); } } break; case TRANSFER_DOUI_ForCache: try { task.doInUI(task.cacheResponse, msg.what); } catch (Exception e) { if (!Const.net_error_try) { throw new RuntimeException(e); } } break; case TRANSFER_CODE: { try { GlobalCodeHandler golbal = IocContainer.getShare().get(GlobalCodeHandler.class); if (golbal != null) { golbal.hanlder(task.mContext, response); } task.OnCode(response); } catch (Exception e) { if (!Const.net_error_try) { throw new RuntimeException(e); } } break; } default: try { task.doInUI(response, msg.what); } catch (Exception e) { if (!Const.net_error_try) { throw new RuntimeException(e); } } break; } }
/** * 在应用内创建数据库 * * @param dbname * @param dbversion */ public void init(String dbname, int dbversion) { this.db = new SqliteDbHelper(IocContainer.getShare().getApplicationContext(), dbname, dbversion) .getWritableDatabase(); };
@Override public void initView() { type = getIntent().getStringExtra("type"); per = IocContainer.getShare().get(CarPlayPerference.class); per.load(); if (per.isShowMessageGuilde == 0) { findViewById(R.id.guide).setVisibility(View.VISIBLE); } findViewById(R.id.know) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { per.load(); per.isShowMessageGuilde = 1; per.commit(); findViewById(R.id.guide).setVisibility(View.GONE); } }); backI = (ImageView) findViewById(R.id.back); if (type.equals("comment")) { setTitle("新的留言"); } else { setTitle("活动消息"); } leftTitleT = (TextView) findViewById(R.id.left_text); leftTitleT.setText("全选"); leftTitleT.setPadding(DhUtil.dip2px(self, 12), 0, 0, 0); leftTitleT.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (leftTitleT.getText().toString().equals("全选")) { mJsonAdapter.checkAll(true); leftTitleT.setText("取消全选"); } else { leftTitleT.setText("全选"); mJsonAdapter.checkAll(false); } mJsonAdapter.notifyDataSetChanged(); } }); rightTitleT = (TextView) findViewById(R.id.right_text); rightTitleT.setText("取消"); rightTitleT.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { mJsonAdapter.showCheck(false); leftTitleT.setText("全选"); rightTitleT.setVisibility(View.GONE); delB.setVisibility(View.GONE); mJsonAdapter.cleanCheck(); backI.setVisibility(View.VISIBLE); mJsonAdapter.showCheck(false); leftTitleT.setVisibility(View.GONE); } }); delB = (Button) findViewById(R.id.del); delB.setOnClickListener(this); listView = (NetRefreshAndMoreListView) findViewById(R.id.listview); listView.setOnItemLongClickListener( new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { mJsonAdapter.showCheck(true); rightTitleT.setVisibility(View.VISIBLE); leftTitleT.setVisibility(View.VISIBLE); delB.setVisibility(View.VISIBLE); backI.setVisibility(View.GONE); return true; } }); listView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent it = null; JSONObject jo = (JSONObject) mJsonAdapter.getItem(position - 1); if (type.equals("comment")) { it = new Intent(self, ActiveDetailsActivity.class); it.putExtra("activityId", JSONUtil.getString(jo, "activityId")); startActivity(it); } else { String activityId = JSONUtil.getString(jo, "activityId"); String type = JSONUtil.getString(jo, "type").trim(); if (!TextUtils.isEmpty(activityId)) { it = new Intent(self, ActiveDetailsActivity.class); it.putExtra("activityId", activityId); startActivity(it); } if (type.equals("车主认证")) { String carModel = JSONUtil.getString(jo, "carModel"); String remarks = JSONUtil.getString(jo, "remarks"); String rs = ""; if (JSONUtil.getString(jo, "remarks").equals("")) { rs = "0"; } else { rs = "1"; } it = new Intent(self, AttestationNotifyActivity.class); it.putExtra("carModel", carModel); it.putExtra("result", rs); it.putExtra("remarks", remarks); startActivity(it); } } } }); listView.setOnEmptyDataListener( new OnEmptyDataListener() { @Override public void onEmpty(boolean showeEptyView) { ViewUtil.bindView(findViewById(R.id.msg), "暂无留言"); findViewById(R.id.empty).setVisibility(showeEptyView ? View.VISIBLE : View.GONE); } }); User user = User.getInstance(); String url = API.CWBaseurl + "/user/" + user.getUserId() + "/message/list?token=" + user.getToken() + "&type=" + type; mJsonAdapter = new MessageAdapter(url, self, R.layout.item_message_list, type); mJsonAdapter.fromWhat("data"); listView.setAdapter(mJsonAdapter); // getData(); mJsonAdapter.showNextInDialog(); }