}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater)
{
inflater.inflate(R.menu.image_grid_view, menu);
String title = getString(R.string.app_name);
// 画像の選択を落とす
content.setSelected(false);
+
+ // ここでダウンロードが終わるまで、すこし待つ
+ do
+ {
+ try
+ {
+ Thread.sleep(300);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ } while (contentDownloader.isDownloading());
}
}
private String targetFileName = "";
private String filepath = "";
private String mimeType = "image/jpeg";
+ private boolean isDownloading = false;
/**
* コンストラクタ
// Download the image.
try
{
+ isDownloading = true;
Calendar calendar = Calendar.getInstance();
String extendName = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.getDefault()).format(calendar.getTime());
targetFileName = fileInfo.getOriginalFilename().toUpperCase();
if (downloadDialog != null) {
downloadDialog.dismiss();
}
+ downloadDialog = null;
+ isDownloading = false;
presentMessage(activity.getString(R.string.download_control_save_failed), message);
}
});
catch (Exception ex)
{
ex.printStackTrace();
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try
+ {
+ if (downloadDialog != null) {
+ downloadDialog.dismiss();
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ downloadDialog = null;
+ isDownloading = false;
+ }
+ });
}
}
{
downloadDialog.dismiss();
}
+ downloadDialog = null;
+ isDownloading = false;
View view = activity.findViewById(R.id.fragment1);
Snackbar.make(view, activity.getString(R.string.download_control_save_success) + " " + targetFileName, Snackbar.LENGTH_SHORT).show();
//Toast.makeText(activity, activity.getString(R.string.download_control_save_success) + " " + targetFileName, Toast.LENGTH_SHORT).show();
{
downloadDialog.dismiss();
}
+ downloadDialog = null;
+ isDownloading = false;
presentMessage(activity.getString(R.string.download_control_save_failed), message);
}
});
@Override
public void onErrorOccurred(Exception e)
{
+ isDownloading = false;
final String message = e.getMessage();
try
{
{
downloadDialog.dismiss();
}
+ downloadDialog = null;
+ isDownloading = false;
presentMessage(activity.getString(R.string.download_control_download_failed), message);
System.gc();
}
System.gc();
}
+ public boolean isDownloading()
+ {
+ return (isDownloading);
+ }
+
/**
* 共有の呼び出し
*