我正在 Android 中实现 JPEG 的 power point。我必须使用AsychTask
and 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();
}
});