Dialog to abort data downloading
This commit is contained in:
@@ -57,6 +57,8 @@ import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import java.lang.String;
|
||||
import android.text.SpannedString;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
|
||||
|
||||
class CountingInputStream extends BufferedInputStream
|
||||
@@ -188,6 +190,7 @@ class DataDownloader extends Thread
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Parent.keyListener = new BackKeyListener(Parent);
|
||||
String [] downloadFiles = Globals.DataDownloadUrl;
|
||||
int total = 0;
|
||||
int count = 0;
|
||||
@@ -213,11 +216,13 @@ class DataDownloader extends Thread
|
||||
}
|
||||
}
|
||||
DownloadComplete = true;
|
||||
Parent.keyListener = null;
|
||||
initParent();
|
||||
}
|
||||
|
||||
public boolean DownloadDataFile(final String DataDownloadUrl, final String DownloadFlagFileName, int downloadCount, int downloadTotal, int downloadIndex)
|
||||
{
|
||||
DownloadCanBeResumed = false;
|
||||
Resources res = Parent.getResources();
|
||||
|
||||
String [] downloadUrls = DataDownloadUrl.split("[|]");
|
||||
@@ -298,6 +303,7 @@ class DataDownloader extends Thread
|
||||
path = getOutFilePath(url.substring( 1, url.indexOf(":", 1) ));
|
||||
url = url.substring( url.indexOf(":", 1) + 1 );
|
||||
DoNotUnzip = true;
|
||||
DownloadCanBeResumed = true;
|
||||
File partialDownload = new File( path );
|
||||
if( partialDownload.exists() && !partialDownload.isDirectory() && !forceOverwrite )
|
||||
partialDownloadLen = partialDownload.length();
|
||||
@@ -674,10 +680,56 @@ class DataDownloader extends Thread
|
||||
return http;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class BackKeyListener implements Settings.KeyEventsListener
|
||||
{
|
||||
MainActivity p;
|
||||
public BackKeyListener(MainActivity _p)
|
||||
{
|
||||
p = _p;
|
||||
}
|
||||
|
||||
public void onKeyEvent(final int keyCode)
|
||||
{
|
||||
if( DownloadFailed )
|
||||
System.exit(1);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(p);
|
||||
builder.setTitle(p.getResources().getString(R.string.cancel_download));
|
||||
builder.setMessage(p.getResources().getString(R.string.cancel_download) + (DownloadCanBeResumed ? " " + p.getResources().getString(R.string.cancel_download_resume) : ""));
|
||||
|
||||
builder.setPositiveButton(p.getResources().getString(R.string.yes), new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
{
|
||||
System.exit(1);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(p.getResources().getString(R.string.no), new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener()
|
||||
{
|
||||
public void onCancel(DialogInterface dialog)
|
||||
{
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.setOwnerActivity(p);
|
||||
alert.show();
|
||||
}
|
||||
}
|
||||
|
||||
public StatusWriter Status;
|
||||
public boolean DownloadComplete = false;
|
||||
public boolean DownloadFailed = false;
|
||||
public boolean DownloadCanBeResumed = false;
|
||||
private MainActivity Parent;
|
||||
private String outFilesDir = null;
|
||||
}
|
||||
|
||||
@@ -623,6 +623,7 @@ public class MainActivity extends Activity
|
||||
if( mGLView.nativeKey( keyCode, 1 ) == 0 )
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
/*
|
||||
else
|
||||
if( keyCode == KeyEvent.KEYCODE_BACK && downloader != null )
|
||||
{
|
||||
@@ -631,6 +632,7 @@ public class MainActivity extends Activity
|
||||
if( !downloader.DownloadComplete )
|
||||
onStop();
|
||||
}
|
||||
*/
|
||||
else
|
||||
if( keyListener != null )
|
||||
{
|
||||
|
||||
@@ -171,4 +171,8 @@
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="calibrate_gyroscope_not_supported">Your device does not have gyroscope</string>
|
||||
<string name="reset_config_ask">Reset all options to default values?</string>
|
||||
<string name="cancel_download">Cancel data downloading?</string>
|
||||
<string name="cancel_download_resume">You can resume it later, the data will not be downloaded twice.</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
</resources>
|
||||
|
||||
@@ -143,4 +143,8 @@
|
||||
<string name="cancel">Отменить</string>
|
||||
<string name="calibrate_gyroscope_not_supported">Гироскоп отсутствует</string>
|
||||
<string name="reset_config_ask">Сбросить все настройки в значения по умолчанию?</string>
|
||||
<string name="cancel_download">Остановить загрузку?</string>
|
||||
<string name="cancel_download_resume">Загрузка может быть продолжена позднее.</string>
|
||||
<string name="yes">Да</string>
|
||||
<string name="no">Нет</string>
|
||||
</resources>
|
||||
|
||||
@@ -142,4 +142,8 @@
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="calibrate_gyroscope_not_supported">Your device does not have gyroscope</string>
|
||||
<string name="reset_config_ask">Reset all options to default values?</string>
|
||||
<string name="cancel_download">Cancel data downloading?</string>
|
||||
<string name="cancel_download_resume">You can resume it later, the data will not be downloaded twice.</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
</resources>
|
||||
|
||||
@@ -173,4 +173,9 @@
|
||||
<string name="reset_config">Reset config to defaults</string>
|
||||
<string name="reset_config_ask">Reset all options to default values?</string>
|
||||
|
||||
<string name="cancel_download">Cancel data downloading?</string>
|
||||
<string name="cancel_download_resume">You can resume it later, the data will not be downloaded twice.</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user