private void upLoadImg(final Bitmap bitmap) { showProgressDialog("正在上传照片"); AppAjaxParam ap = new AppAjaxParam(); ap.put("ImgData", mImageTools.bitmapToString(bitmap)); AppHttpClient aClient = new AppHttpClient(); aClient.uploadImg( ap, new AppAjaxCallback.onResultListener() { @Override public void onResult(String data, String msg) { mList.add(mListImg.size(), bitmap); mAdapter.notifyDataSetChanged(); showToast(msg); cancelProgressDialog(); mListImg.add(data); } @Override public void onError(String error) { cancelProgressDialog(); showToast(error); } }); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // 表示点击上传照片的按钮 if (position == mList.size() - 1) { mImageTools.showGetImageDialog("选择照片的方式!"); } else { // 这里应该做其他动作 mList.remove(position); mAdapter.notifyDataSetChanged(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case ImageTools.CAMARA: mType = ImageTools.CAMARA; mImageTools.getBitmapFromCamara( new ImageTools.OnBitmapCreateListener() { @Override public void onBitmapCreate(Bitmap bitmap, String path) { mImageTools.startZoomPhotoByCamera(Uri.fromFile(new File(path)), 1000, 1000); } }); break; case ImageTools.GALLERY: mType = ImageTools.GALLERY; mImageTools.startZoomPhoto(data.getData(), 1000, 1000); break; case ImageTools.BITMAP: switch (mType) { case ImageTools.CAMARA: Bitmap bitmap2 = mImageTools.getBitmapFromZoomPhoto(data); upLoadImg(bitmap2); break; case ImageTools.GALLERY: Bitmap bitmap = mImageTools.getBitmapFromGalleryByZoom(data); upLoadImg(bitmap); break; } break; } } }