public void handleMessage(Message msg) { switch (msg.what) { case 0: Toast.makeText(PersonalIconSettingActivity.this, errorString, Toast.LENGTH_SHORT) .show(); Tools.writeImg2SdCard(bitmap, "/hansSwjtu/swjtu_chat/personalIcons", usrNow + ".png"); finish(); break; case 1: Toast.makeText(PersonalIconSettingActivity.this, errorString, Toast.LENGTH_SHORT) .show(); break; case 2: Toast.makeText(PersonalIconSettingActivity.this, "设置失败,请重试", Toast.LENGTH_SHORT) .show(); break; case 3: Toast.makeText(PersonalIconSettingActivity.this, "联网失败,请重试", Toast.LENGTH_SHORT) .show(); break; default: break; } loadingProgressBar.setVisibility(View.INVISIBLE); }
@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.personIconIv: Intent it = new Intent(Intent.ACTION_GET_CONTENT); it.setType("*/*"); it.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(Intent.createChooser(it, "选择所需要的图片"), FILE_SELECT_CODE); break; case R.id.commitBtn: if (!HAVA_SET_ICON) { Toast.makeText(PersonalIconSettingActivity.this, "未做更改", Toast.LENGTH_SHORT).show(); } else { params.add(new BasicNameValuePair("icon", Tools.iconBitmap2String(bitmap))); params.add(new BasicNameValuePair("userNow", sharePreferenceHelper.getStuCode())); loadingProgressBar.setVisibility(View.VISIBLE); new Thread( new Runnable() { @Override public void run() { // TODO Auto-generated method stub String resultString = HttpConnect.setIcon(params); if (resultString != null) { try { JSONObject jsonObject = new JSONObject(resultString); errorString = jsonObject.getString("errorMsg"); if (jsonObject.getInt("state") == 0) { handler.sendEmptyMessage(0); } else { handler.sendEmptyMessage(1); } } catch (Exception e) { // TODO: handle exception handler.sendEmptyMessage(2); } } else { handler.sendEmptyMessage(3); } } }) .start(); ; } break; default: break; } }