上传照片,调用系统照片

来源:互联网 发布:raft 算法 三副本 编辑:程序博客网 时间:2024/04/29 16:44
// 自己照片    public void Photo() {        head_tou = (ImageView) view.findViewById(R.id.photo);        head_tou.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                // 一个自定义的布局,作为显示的内容                View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.photo_item, null);                // 设置按钮的点击事件                TextView photo = (TextView) contentView.findViewById(R.id.popwindow_photo);                TextView up = (TextView) contentView.findViewById(R.id.popwindow_up);                photo.setOnClickListener(new OnClickListener() {                    @Override                    public void onClick(View v) {                        Toast.makeText(getActivity(), "button is pressed", Toast.LENGTH_SHORT).show();                        // 拍照上传                        Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);                        startActivityForResult(it, 1);                    }                });                up.setOnClickListener(new OnClickListener() {                    @Override                    public void onClick(View v) {                        Toast.makeText(getActivity(), "button is pressed", Toast.LENGTH_SHORT).show();                        // 本地上传实现:                        Intent intent = new Intent();                        intent.setType("image/*");                        intent.setAction(Intent.ACTION_GET_CONTENT);                        startActivityForResult(intent, 2);                    }                });                final PopupWindow popupWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT,                        LayoutParams.WRAP_CONTENT, true);                popupWindow.setTouchable(true);                popupWindow.setTouchInterceptor(new OnTouchListener() {                    @Override                    public boolean onTouch(View v, MotionEvent event) {                        Log.i("mengdd", "onTouch : ");                        return false;                        // 这里如果返回true的话,touch事件将被拦截                        // 拦截后 PopupWindow的onTouchEvent不被调用,这样点击外部区域无法dismiss                    }                });                // 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框                // 我觉得这里是API的一个bug                popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.s));                // 设置好参数之后再show                popupWindow.showAsDropDown(head_tou);            }        });    }
0 0
原创粉丝点击