private void genPhoto() { photo.setPartyId(entity.getPartyId()); photo.setName(entity.getPartyface()); byte[] input = ImageUtil.Bitmap2Bytes(bitMap); byte[] newly = Base64.encode(input, Base64.DEFAULT); photo.setContent(new String(newly)); photo.setPhotoUpdateDate(DateTimeUtil.format(new Date())); }
@Override protected void onResume() { super.onResume(); switch (mState) { case STATE_EDIT: title.setText("修改联系人"); // id = ContentUris.parseId(uri); id = bundle.get("id").toString(); mCursor = managedQuery( ContactEntity.CONTENT_URI, null, ContactEntity.KEY_PARTYID + " = '" + id + "'", null, null); mCursor.moveToFirst(); entity = new ContactEntity(mCursor); nameEditText.setText(entity.getName()); titleEditText.setText(entity.getTitle()); companyEditText.setText(entity.getCompanyname()); // 电话 String phoneJSON = entity.getPhone(); mobile_row_layout.removeAllViews(); try { JSONArray phoneAry = new JSONArray(phoneJSON); for (int i = 0; i < phoneAry.length(); i++) { JSONObject json = (JSONObject) phoneAry.get(i); genMobileLayout(true, json.getString("phoneType"), json.getString("phoneText")); } } catch (JSONException e) { e.printStackTrace(); } // Email String emailJSON = entity.getEmail(); email_row_layout.removeAllViews(); try { JSONArray emailAry = new JSONArray(emailJSON); for (int i = 0; i < emailAry.length(); i++) { JSONObject json = (JSONObject) emailAry.get(i); genEmailLayout(true, json.getString("emailType"), json.getString("emailText")); } } catch (JSONException e) { e.printStackTrace(); } // 地址 String addressJSON = entity.getAddress(); address_row_layout.removeAllViews(); try { JSONArray addressAry = new JSONArray(addressJSON); for (int i = 0; i < addressAry.length(); i++) { JSONObject json = (JSONObject) addressAry.get(i); genAddressLayout(true, json.getString("addressType"), json.getString("addressText")); } } catch (JSONException e) { e.printStackTrace(); } // IM String imJSON = entity.getIm(); im_row_layout.removeAllViews(); try { JSONArray imAry = new JSONArray(imJSON); for (int i = 0; i < imAry.length(); i++) { JSONObject json = (JSONObject) imAry.get(i); genImLayout(true, json.getString("imType"), json.getString("imText")); } } catch (JSONException e) { e.printStackTrace(); } // 网址 String website = entity.getWebsites(); website_row_layout.removeAllViews(); try { JSONArray webAry = new JSONArray(website); for (int i = 0; i < webAry.length(); i++) { JSONObject json = (JSONObject) webAry.get(i); genWebsiteLayout(true, json.getString("websitesType"), json.getString("websitesText")); } } catch (JSONException e) { e.printStackTrace(); } // 头像 if (hasImage) { // 选择过上传头像 } else { String partyFace = entity.getPartyface(); if (!StringUtil.isEmpty(partyFace)) { Cursor photoCursor = managedQuery( PhotoEntity.CONTENT_URI, null, PhotoEntity.KEY_NAME + " = '" + partyFace + "'", null, null); if (photoCursor.moveToFirst()) { String content = photoCursor.getString(4); byte[] data = Base64.decode(content, Base64.DEFAULT); Bitmap icon = BitmapFactory.decodeByteArray(data, 0, data.length); // photoView.setImageBitmap(icon); icon = ImageUtil.zoomBitmap(icon, 80, 80); BitmapDrawable bd = new BitmapDrawable(icon); photoView.setBackgroundDrawable(bd); } photoCursor.close(); } } break; case STATE_INSERT: title.setText("新增联系人"); entity = new ContactEntity(); // 生成默认 mobile_row_layout.removeAllViews(); genMobileLayout(false, null, null); email_row_layout.removeAllViews(); genEmailLayout(false, null, null); address_row_layout.removeAllViews(); genAddressLayout(false, null, null); im_row_layout.removeAllViews(); genImLayout(false, null, null); website_row_layout.removeAllViews(); genWebsiteLayout(false, null, null); break; default: break; } }