0

我正在 Android 中实现 JPEG 的 power point。我必须使用AsychTaskand doINBackground。但我不知道如何在方法中调用saveSlideAs我的 Document 类中的voidonPostExecute()方法。

这是我的代码:

SaveSlideAs() this method in Document Class



 public void saveSlideAs(String outputPath, int slideNumber,
                ImageFormat imageFormat)// Returns 100x100 image
        {

            try {

                String strURI = Product.getBaseProductUri() + "/slides/" 
                         + fileName + "/slides/" +               
           Integer.toString(slideNumber) + "?format=imageFormat.toString().toLowerCase();
                        String signedURI = Utils.sign(strURI);
                        InputStream responseStream = Utils.processCommand(signedURI,"GET");
                        Folder.saveStreamToFile(outputPath,responseStream);
                        responseStream.close();


            }

            catch (Exception e) {
                logger.error(e.getMessage());
            }

        }



    doInBackground() method in  StorageFolderUploadFile class 


    private void convertToImage() 
        {
            httpGetAsynchTask httpGetAsyncTask = new httpGetAsynchTask();
            httpGetAsyncTask.execute();
        }


        class httpGetAsynchTask extends AsyncTask<String , Integer , Object>
        {
            protected void onPreExecute()
            {
                   try
                   {
                       dialog.setMessage("Please Wait");
                       dialog.show();
                   }

                   catch(Exception e)
                   {

                   }
                }




            protected String doInBackground(String... arg0) 
            {
                // TODO Auto-generated method stub
                Folder obj = new Folder();

                    try 
                    {
                        response = obj.uploadFile(path);
                        Log.e("response  ",": "+response);
                        if (response) 

                        {
                            Document docObj=new Document( fileName);
                                                count = docObj.getSlideCount();


                            if (count > 0) 
                            {
                                 for(int i=1; i <= count ; i++)
                                {                          

                        String outputPath = fileName + "_Slide" + i + ".jpg" ;
                                    slideNumber = i;
                                    Document docObj2=new Document(fileName);
                                    docObj2.saveSlideAs(outputPath.toString().trim(), slideNumber, imageFormat);



                                }
                    }

                }
                    } 

                     catch (Exception e)

                     {
                                // TODO Auto-generated catch block
                                   e.printStackTrace();
                                   Log.e("",""+e.toString());


                     }



                    return null;
            }




            public void onPostExecute(String values)
            {
            try
                {
                    if (response) 

                    {
                                        //here result is a text view
                        result.append("File Uploaded Successfully \n" + count);

                    if(dialog.isShowing())
                        {
                        dialog.dismiss();
                        }
                    }
                    else 

                    {

                        result.append("Oops..Something went wrong");

                    }
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            }

        }



button click event

    btnSubmit.setOnClickListener(new View.OnClickListener()
            {

                @Override
                public void onClick(View arg0) 
                {
                    // TODO Auto-generated method stub

                    convertToImage();

                }

            });
4

1 回答 1

0

this您可以使用以下符号从内部类中访问外部类的实例:

public class Main {

    public static void main(String[] args) {
        Main main = new Main();
    }

    public void doThisInsideTheInnerClass() {
        System.out.println("Hi there!");
    }

    public Main() {

        class Inside {
            public void insideVoid() {
                Main.this.doThisInsideTheInnerClass();
            }
        }

        Inside object = new Inside();
        object.insideVoid();
    }

}

因此,如果外部类的名称是Outer,请使用Outer.this.saveSlideAs(...).

于 2013-06-17T08:15:23.593 回答