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()));
  }
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) return;

    switch (requestCode) {
      case PHOTO_PICKED_WITH_DATA: // 从本地选择图片
        if (bitMap != null && !bitMap.isRecycled()) {
          bitMap.recycle();
        }
        Uri selectedImageUri = data.getData();
        if (selectedImageUri != null) {
          try {
            bitMap =
                BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImageUri));

            bitMap = ImageUtil.zoomBitmap(bitMap, 80, 80);
          } catch (FileNotFoundException e) {
            e.printStackTrace();
          }

          // 下面这两句是对图片按照一定的比例缩放,这样就可以完美地显示出来。有关图片的处理将重新写文章来介绍。
          //				int scale = ImageThumbnail.reckonThumbnail(bitMap.getWidth(),
          //						bitMap.getHeight(), 500, 600);
          //
          //				bitMap = ImageThumbnail.PicZoom(bitMap,
          //						(int) (bitMap.getWidth() / scale),
          //						(int) (bitMap.getHeight() / scale));

          //				photoView.setImageBitmap(bitMap);
          BitmapDrawable bd = new BitmapDrawable(bitMap);
          photoView.setBackgroundDrawable(bd);

          hasImage = true;
        }
        break;
      case CAMERA_WITH_DATA: // 拍照
        Bundle bundle = data.getExtras();
        bitMap = (Bitmap) bundle.get("data");
        if (bitMap != null) bitMap.recycle();

        bitMap = (Bitmap) data.getExtras().get("data");
        //			int scale = ImageThumbnail.reckonThumbnail(bitMap.getWidth(),
        //					bitMap.getHeight(), 500, 600);
        //
        //			bitMap = ImageThumbnail.PicZoom(bitMap,
        //					(int) (bitMap.getWidth() / scale),
        //					(int) (bitMap.getHeight() / scale));

        //			photoView.setImageBitmap(null);
        //			photoView.setImageBitmap(bitMap);
        BitmapDrawable bd = new BitmapDrawable(bitMap);
        photoView.setBackgroundDrawable(bd);
        hasImage = true;

        break;
    }
  }
  @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;
    }
  }