popupWindow_photo = new PopupWindow_photo(getActivity().getApplicationContext(), base_title);/* bitmap截图信息 */// 修改头像/* *  * public class headrel implements View.OnClickListener { *  * @Override public void onClick(View v) { popupWindow_photo = new * PopupWindow_photo(getActivity(), base_title); } } */// 选择头像弹窗private static final int PHOTO_REQUEST_CAMERA = 1;// 拍照private static final int PHOTO_REQUEST_GALLERY = 2;// 从相册中选择private static final int PHOTO_REQUEST_CUT = 3;// 结果public class PopupWindow_photo extends PopupWindow {private Button select_camera;private Button select_photo;private Button select_out;private LinearLayout select_input;public PopupWindow_photo(Context mContext, View parent) {super(parent);View view = View.inflate(mContext, R.layout.popup_type_select, null);// 自己写的xml弹框布局setWidth(ViewGroup.LayoutParams.MATCH_PARENT);// 设置宽度setHeight(ViewGroup.LayoutParams.MATCH_PARENT);// 设置高度setFocusable(true);setOutsideTouchable(true);// 设置是否可以外部点击setContentView(view);// 在父view中呈现showAtLocation(parent, Gravity.TOP, 0, 0);// 在父view的x,y位置出现update();// 刷新// 自己xml定义的组件用法select_input = (LinearLayout) view.findViewById(R.id.select_input);select_camera = (Button) view.findViewById(R.id.select_camera);select_photo = (Button) view.findViewById(R.id.select_photo);select_out = (Button) view.findViewById(R.id.select_out);StaticData.buttonnowscale(select_camera, 90, 610);StaticData.buttonnowscale(select_photo, 90, 610);StaticData.buttonnowscale(select_out, 90, 610);StaticData.linearlayoutnowscale(select_input, 275, 610);select_camera.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");// 判断存储卡是否可以用,可用进行存储if (hasSdcard()) {intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"IMGface")));}startActivityForResult(intent, PHOTO_REQUEST_CAMERA);dismiss();}});select_photo.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(Intent.ACTION_PICK);intent.setType("image/*");startActivityForResult(intent, PHOTO_REQUEST_GALLERY);dismiss();}});select_out.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {dismiss();}});}}@SuppressLint("ShowToast")@Overridepublic void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);switch (requestCode) {case PHOTO_REQUEST_GALLERY:if (data != null) {// 得到图片的全路径Uri uri = data.getData();crop(uri);}break;case PHOTO_REQUEST_CAMERA:if (hasSdcard()) {tempFile = new File(Environment.getExternalStorageDirectory(),"IMGface");crop(Uri.fromFile(tempFile));} else {Toast.makeText(getActivity().getApplicationContext(),"未找到存储卡,无法存储照片!", 0).show();}break;case PHOTO_REQUEST_CUT:bitmap = data.getParcelableExtra("data");imgs.setImageBitmap(bitmap);try {if (bitmap != null) {// boolean delete = tempFile.delete();// System.out.println("delete = " + delete);f = new File(getActivity().getApplicationContext().getFilesDir(), "IMGface.jpg");FileOutputStream out = null;out = new FileOutputStream(f);bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);out.flush();out.close();}} catch (Exception e) {e.printStackTrace();}sendData();break;}}/** * 剪切图片 *  * @param uri * @function: * @author:Jerry * @date:2013-12-30 */private void crop(Uri uri) {// 裁剪图片意图Intent intent = new Intent("com.android.camera.action.CROP");intent.setDataAndType(uri, "image/*");// 裁剪框的比例,1:1intent.putExtra("aspectX", 1);intent.putExtra("aspectY", 1);// 裁剪后输出图片的尺寸大小intent.putExtra("outputX", 250);intent.putExtra("outputY", 250);// 图片格式intent.putExtra("outputFormat", "JPG");intent.putExtra("noFaceDetection", true);// 取消人脸识别intent.putExtra("return-data", true);// true:不返回uri,false:返回uristartActivityForResult(intent, PHOTO_REQUEST_CUT);}private boolean hasSdcard() {if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {return true;} else {return false;}}// 上传public void sendData() {String url = UrlVO.Host_Url + UrlVO.Change_Url;try {RequestParams params = new RequestParams();params.put("file", f);AsyncHttpClient client = new AsyncHttpClient();if (!UrlVO.getShareData("JSESSIONID",getActivity().getApplicationContext()).equals("false")) {client.addHeader("Cookie", UrlVO.getShareData("JSESSIONID",getActivity().getApplicationContext()));}client.post(url, params, new AsyncHttpResponseHandler() {@Overridepublic void onSuccess(String response) {Bundle bundle = new Bundle();bundle.putString("response", response);if (response == null || response.equals("")) {return;}String[] key = { "success" };String[] logindata = json.getJSON(response, key);if (logindata == null) {return;}if (logindata[0].equals("true")) {Toast.makeText(getActivity().getApplicationContext(),"修改成功", 3000).show();// getActivity().finish();getData(UrlVO.Personal_Url, UrlVO.JSESSIONID);// 获取个人}}@Overridepublic void onFailure(int statusCode,org.apache.http.Header[] headers, byte[] responseBody,Throwable error) {// TODO 自动生成的方法存根super.onFailure(statusCode, headers, responseBody, error);Toast.makeText(getActivity().getApplicationContext(),"网络访问异常 ", 0).show();}// @Override// public void onFailure(int statusCode, Header[] headers,// byte[] responseBody, Throwable error) {// super.onFailure(statusCode, headers, responseBody, error);// Toast.makeText(getActivity().getApplicationContext(),// "网络访问异常 ", 0).show();// }});} catch (Exception e) {e.printStackTrace();}}

更多相关文章

  1. android 基础知识
  2. android maxLines ellipsize 配合使用失效,解决办法
  3. android 对话框
  4. Android填坑记录
  5. android图片裁剪
  6. Android快速显示4G
  7. RecyclerView嵌套ScrollView
  8. android 实现保存图片到相册
  9. Android6.0修改设备设置中kernel信息

随机推荐

  1. Android到底那个Acitivity启动
  2. Android(安卓)使用RoundedImageView得不
  3. Android中不能在子线程中更新View视图的
  4. Android(安卓)自定义组件相关
  5. Mac下完全卸载干净Android(安卓)Studio的
  6. AS插件-Android(安卓)Layout ID Converte
  7. Android中Context和Resource之间的关系
  8. Android使用代码实现左右半圆的按钮背景
  9. Android(安卓)SDK与ADT版本不匹配的解决
  10. Android开发手记——登陆界面