fix issue with rotating phone
git-svn-id: https://osmand.googlecode.com/svn/trunk@572 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
af0f31afaa
commit
ab96ff18b6
3 changed files with 70 additions and 41 deletions
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="net.osmand" android:versionName="0.4.1" android:versionCode="17">
|
package="net.osmand" android:versionName="0.4.2" android:versionCode="17">
|
||||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||||
android:debuggable="true" android:name=".activities.OsmandApplication" android:description="@string/app_description">
|
android:debuggable="true" android:name=".activities.OsmandApplication" android:description="@string/app_description">
|
||||||
<activity android:name=".activities.MainMenuActivity"
|
<activity android:name=".activities.MainMenuActivity"
|
||||||
|
|
|
@ -50,12 +50,16 @@ import android.widget.Toast;
|
||||||
public class DownloadIndexActivity extends ListActivity {
|
public class DownloadIndexActivity extends ListActivity {
|
||||||
|
|
||||||
private final static Log log = LogUtil.getLog(DownloadIndexActivity.class);
|
private final static Log log = LogUtil.getLog(DownloadIndexActivity.class);
|
||||||
private ProgressDialog progressDlg = null;
|
private static DownloadIndexListThread downloadListIndexThread = new DownloadIndexListThread();
|
||||||
|
|
||||||
|
private ProgressDialog progressFileDlg = null;
|
||||||
|
private ProgressDialog progressListDlg = null;
|
||||||
private LinkedHashMap<String, DownloadEntry> entriesToDownload = new LinkedHashMap<String, DownloadEntry>();
|
private LinkedHashMap<String, DownloadEntry> entriesToDownload = new LinkedHashMap<String, DownloadEntry>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
// that is needed to prevent rotation while files are downloaded
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
setContentView(R.layout.download_index);
|
setContentView(R.layout.download_index);
|
||||||
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
|
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
|
||||||
|
@ -66,34 +70,62 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
progressDlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_list_indexes));
|
if(downloadListIndexThread.getCachedIndexFiles() != null){
|
||||||
progressDlg.setCancelable(true);
|
setListAdapter(new DownloadIndexAdapter(new ArrayList<Entry<String,String>>(downloadListIndexThread.getCachedIndexFiles().entrySet())));
|
||||||
|
} else {
|
||||||
new Thread(new Runnable(){
|
progressListDlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_list_indexes));
|
||||||
@Override
|
progressListDlg.setCancelable(true);
|
||||||
public void run() {
|
downloadListIndexThread.uiActivity = this;
|
||||||
final Map<String, String> indexFiles = downloadIndex();
|
if(downloadListIndexThread.getState() == Thread.State.NEW){
|
||||||
if(progressDlg != null){
|
downloadListIndexThread.start();
|
||||||
progressDlg.dismiss();
|
} else if(downloadListIndexThread.getState() == Thread.State.TERMINATED){
|
||||||
progressDlg = null;
|
// possibly exception occurred we don't have cache of files
|
||||||
runOnUiThread(new Runnable() {
|
downloadListIndexThread = new DownloadIndexListThread();
|
||||||
@Override
|
downloadListIndexThread.uiActivity = this;
|
||||||
public void run() {
|
|
||||||
if (indexFiles != null) {
|
|
||||||
setListAdapter(new DownloadIndexAdapter(new ArrayList<Entry<String,String>>(indexFiles.entrySet())));
|
|
||||||
} else {
|
|
||||||
Toast.makeText(DownloadIndexActivity.this, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, "DownloadIndexes").start(); //$NON-NLS-1$
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class DownloadIndexListThread extends Thread {
|
||||||
|
private DownloadIndexActivity uiActivity = null;
|
||||||
|
private Map<String, String> indexFiles = null;
|
||||||
|
|
||||||
protected Map<String, String> downloadIndex(){
|
public DownloadIndexListThread(){
|
||||||
|
super("DownloadIndexes"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
public void setUiActivity(DownloadIndexActivity uiActivity) {
|
||||||
|
this.uiActivity = uiActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getCachedIndexFiles() {
|
||||||
|
return indexFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
indexFiles = downloadIndex();
|
||||||
|
if(uiActivity != null && uiActivity.progressListDlg != null){
|
||||||
|
uiActivity.progressListDlg.dismiss();
|
||||||
|
uiActivity.progressListDlg = null;
|
||||||
|
uiActivity.runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (indexFiles != null) {
|
||||||
|
uiActivity.setListAdapter(uiActivity.new DownloadIndexAdapter(new ArrayList<Entry<String,String>>(indexFiles.entrySet())));
|
||||||
|
} else {
|
||||||
|
Toast.makeText(uiActivity, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected static Map<String, String> downloadIndex(){
|
||||||
try {
|
try {
|
||||||
log.debug("Start loading list of index files"); //$NON-NLS-1$
|
log.debug("Start loading list of index files"); //$NON-NLS-1$
|
||||||
TreeMap<String, String> indexFiles = new TreeMap<String, String>(new Comparator<String>(){
|
TreeMap<String, String> indexFiles = new TreeMap<String, String>(new Comparator<String>(){
|
||||||
|
@ -260,11 +292,11 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
progressDlg = ProgressDialog.show(DownloadIndexActivity.this, getString(R.string.downloading), getString(R.string.downloading_file), true, true);
|
progressFileDlg = ProgressDialog.show(DownloadIndexActivity.this, getString(R.string.downloading), getString(R.string.downloading_file), true, true);
|
||||||
interruptDownloading = false;
|
interruptDownloading = false;
|
||||||
progressDlg.show();
|
progressFileDlg.show();
|
||||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg, true);
|
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressFileDlg, true);
|
||||||
progressDlg.setOnCancelListener(new DialogInterface.OnCancelListener(){
|
progressFileDlg.setOnCancelListener(new DialogInterface.OnCancelListener(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
@ -291,11 +323,12 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
progressDlg = null;
|
// do not dismiss dialog
|
||||||
|
progressFileDlg = null;
|
||||||
} finally {
|
} finally {
|
||||||
if(progressDlg != null){
|
if(progressFileDlg != null){
|
||||||
progressDlg.dismiss();
|
progressFileDlg.dismiss();
|
||||||
progressDlg = null;
|
progressFileDlg = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,12 +419,8 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
if(isFinishing()){
|
if(isFinishing()){
|
||||||
interruptDownloading = true;
|
interruptDownloading = true;
|
||||||
}
|
}
|
||||||
// not needed now because rotate screen not allowed
|
downloadListIndexThread.uiActivity = null;
|
||||||
// posssibly it should be onDestroy method
|
progressFileDlg = null;
|
||||||
// if(progressDlg != null){
|
|
||||||
// progressDlg.dismiss();
|
|
||||||
// progressDlg = null;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean downloadFile(final String key, final File fileToDownload, final File fileToUnZip, final boolean unzipToDir,
|
protected boolean downloadFile(final String key, final File fileToDownload, final File fileToUnZip, final boolean unzipToDir,
|
||||||
|
@ -493,7 +522,7 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class DownloadIndexAdapter extends ArrayAdapter<Entry<String, String>> {
|
protected class DownloadIndexAdapter extends ArrayAdapter<Entry<String, String>> {
|
||||||
|
|
||||||
public DownloadIndexAdapter(List<Entry<String, String>> array) {
|
public DownloadIndexAdapter(List<Entry<String, String>> array) {
|
||||||
super(DownloadIndexActivity.this, net.osmand.R.layout.download_index_list_item, array);
|
super(DownloadIndexActivity.this, net.osmand.R.layout.download_index_list_item, array);
|
||||||
|
|
|
@ -475,7 +475,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
||||||
} else {
|
} else {
|
||||||
speed = ((float) d * 1000) / time ;
|
speed = ((float) d * 1000) / time ;
|
||||||
}
|
}
|
||||||
|
// incorrect in case of airplane
|
||||||
if (speed > 100) {
|
if (speed > 100) {
|
||||||
speed = 100;
|
speed = 100;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue