我想制作一个像 WhatsApp Profile Photo Dialog Screen 这样的对话屏幕 [英] I want to make a Dialog Screen Like WhatsApp Profile Photo Dialog Screen

查看:18
本文介绍了我想制作一个像 WhatsApp Profile Photo Dialog Screen 这样的对话屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友......

我目前正在尝试使用隐式意图制作一个对话框,我想在其中显示我的对话框,例如 whatsApp(个人资料照片屏幕),并且在此屏幕中,whatsApp 正在使用名为删除照片"的额外字段.当我尝试制作相同类型的屏幕对话框时,我无法添加这个额外的字段(删除照片").我已经完成了所有代码.它对于对话框中的三个选项(例如(图库,照片,相机))工作正常,我无法在 onActivityResult() 中处理所有这些.我正在发送我已经非常努力的所有源代码,但我无法找到这样做的解决方案.plz.....朋友们帮我解决这个问题.

I am currently trying to make a Dialog using Implicit Intent where i want to show my Dialog like whatsApp(Profile Photo Screen) and in this screen whatsApp are using extra field named as "Remove Photo". When i try to make same type of screen Dialog then i am unable to add this extra field("Remove Photo"). i have done all code. its working fine for three option in Dialog like(Gallery,Photo,Camera) and i am unable to handle these all in onActivityResult() . I am sending my all source code i have tried much hard , but i am not able to find the solution to do so. plz..... friends help me out from this.

在这段代码中,我只是创建了一个名为 openFileChooser() 的方法,我在其中编写了所有用于创建对话框屏幕的代码并在 onActivityResult() 中处理此结果

In this code i am simply create a method named as openFileChooser() in which i have write all the code for creating Dialog Screen and handle this outcomes in onActivityResult()

这是我的代码

ProfilePhotoActivity.java

ProfilePhotoActivity.java

public class ProfilePhotoActivity extends Activity implements OnClickListener{
    ImageButton back, editPhoto, selectAction;
    ImageView imgCamera;
    private static final int FILECHOOSER_RESULTCODE   = 2888;
    protected static final int CAMERA_REQUEST = 0;
    protected static final int GALLERY_PICTURE = 1;
    private Uri mCapturedImageURI = null;
    Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_profilephoto);

        back=(ImageButton)findViewById(R.id.btn_back);
        editPhoto=(ImageButton)findViewById(R.id.ibEditPhoto);
        selectAction=(ImageButton)findViewById(R.id.ibSelectAction);

        imgCamera=(ImageView)findViewById(R.id.imvProfilePhoto);

        editPhoto.setOnClickListener(this);
        selectAction.setOnClickListener(this);
        back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
        case R.id.btn_back:
            ProfilePhotoActivity.this.finish();
            break;

        case R.id.ibEditPhoto:
            openFileChooser(null, null);
        //  startDialog();


            break;
        case R.id.ibSelectAction:
            break;
        }
    }

     public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType){  

            try{    

             // Create AndroidExampleFolder at sdcard

             File imageStorageDir = new File(
               Environment.getExternalStoragePublicDirectory(
                 Environment.DIRECTORY_PICTURES)
                 , "AndroidExampleFolder");

             if (!imageStorageDir.exists()) {
              // Create AndroidExampleFolder at sdcard
              imageStorageDir.mkdirs();
             }

             // Create camera captured image file path and name 
             File file = new File(
               imageStorageDir + File.separator + "IMG_"
                 + String.valueOf(System.currentTimeMillis()) 
                 + ".jpg");

             mCapturedImageURI = Uri.fromFile(file); 

             // Camera capture image intent
             final Intent captureIntent = new Intent(
               android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

             captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);

             Intent i = new Intent(Intent.ACTION_PICK); 
            // i.addCategory(Intent.CATEGORY_OPENABLE);
             i.setType("image/*");

             // Create file chooser intent
             Intent chooserIntent = Intent.createChooser(i, "Image Chooser");

             // Set camera intent to file chooser 
             chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
               , new Parcelable[] { captureIntent });

             // On select image call onActivityResult method of activity
             startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);

            }
            catch(Exception e){
             Toast.makeText(getBaseContext(), "Exception:"+e, 
               Toast.LENGTH_LONG).show();
            }

           }
     protected void onActivityResult(int requestCode, int resultCode,Intent intent) { 

          if(requestCode==FILECHOOSER_RESULTCODE)  
          {  
              if (requestCode == GALLERY_PICTURE)
                    {
                        if (resultCode == RESULT_OK) 
                        {
                            if (intent != null) 
                            {                   
                                // our BitmapDrawable for the thumbnail
                                BitmapDrawable bmpDrawable = null;

                                // try to retrieve the image using the data from the intent
                                Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null);

                                if (cursor != null) 
                                {
                                    cursor.moveToFirst();

                                    int idx = cursor.getColumnIndex(ImageColumns.DATA);
                                    String fileSrc = cursor.getString(idx);
                                    Bitmap galleryBitmap = BitmapFactory.decodeFile(fileSrc); // load preview image                                                                         
                                    galleryBitmap = Bitmap.createScaledBitmap(galleryBitmap, 200, 200, true);


                                    String filePath = Environment.getExternalStorageDirectory()
                                    .getAbsolutePath()+"/TimeChat/image/"+System.currentTimeMillis()+".jpg";

                                    //imgCamera.setRotation(0);
                                    imgCamera.setImageBitmap(galleryBitmap);
//                                  writeToFile(filePath, galleryBitmap);
                                } 
                                else 
                                {
                                    bmpDrawable = new BitmapDrawable(getResources(), intent.getData().getPath());
                                    imgCamera.setImageDrawable(bmpDrawable);
                                }
                            } 
                            else 
                            {
                                Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
                            }
                        } 
                        else if (resultCode == RESULT_CANCELED) 
                        {
                            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
                        }
                    } 
                    else if (requestCode == CAMERA_REQUEST) 
                    {
                        if (resultCode == RESULT_OK) 
                        {
                            if (intent.hasExtra("data"))
                            {                   
                                // retrieve the bitmap from the intent
                                Bitmap cameraBitmap = (Bitmap) intent.getExtras().get("data");

                                    String filePath = Environment.getExternalStorageDirectory()
                                .getAbsolutePath()+"/TimeChat/image/"+System.currentTimeMillis()+".jpg";

                                // update the image view with the bitmap
                                imgCamera.setImageBitmap(cameraBitmap);
                            //  writeToFile(filePath, circleBitmap);

                            } 
                            else if (intent.getExtras() == null) {

                                Toast.makeText(getApplicationContext(), "No extras to retrieve!", Toast.LENGTH_SHORT).show();

                                BitmapDrawable thumbnail = new BitmapDrawable(getResources(), intent.getData().getPath());

                                // update the image view with the newly created drawable
                                imgCamera.setImageDrawable(thumbnail);

                            }

                        } 
                        else if (resultCode == RESULT_CANCELED) {
                            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
                        }
                    }
          }
         }


    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        ProfilePhotoActivity.this.finish();
    }

}

推荐答案

这看起来会是个问题:

 if(requestCode==FILECHOOSER_RESULTCODE)  
          {  
              if (requestCode == GALLERY_PICTURE)

除非 FILECHOOSER_RESULTCODE 和 GALLERY_PICTURE 是相同的整数,否则语句将永远不会通过.

unless FILECHOOSER_RESULTCODE and GALLERY_PICTURE are the same ints then statement will never pass.

这篇关于我想制作一个像 WhatsApp Profile Photo Dialog Screen 这样的对话屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆