forked from organicmaps/organicmaps
[android] Added "Map" button in the downloader, also changed missing Internet connection logic, now it just displays additional "Connection Settings" button if no connection is detected, but allows to click and download countries.
This was done because some users have specific internet connections neither WiFi nor 3G (cable-connected, vpn-connected?) which are not detected correctly by our code.
This commit is contained in:
parent
26aa1bef9b
commit
8beaa1e82d
3 changed files with 98 additions and 44 deletions
23
android/res/layout/downloader_header_map.xml
Normal file
23
android/res/layout/downloader_header_map.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:baselineAligned="false"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingRight="?android:attr/scrollbarSize">
|
||||
|
||||
<Button
|
||||
android:id="@+id/downloader_button_showmap"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/map"
|
||||
android:lines="1"
|
||||
android:gravity="center"
|
||||
android:onClick="onShowMapClicked"
|
||||
android:layout_margin="5dip"
|
||||
android:layout_weight="1" >
|
||||
|
||||
</Button>
|
||||
|
||||
</LinearLayout>
|
35
android/res/layout/downloader_header_map_connection.xml
Normal file
35
android/res/layout/downloader_header_map_connection.xml
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:baselineAligned="false"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingRight="?android:attr/scrollbarSize">
|
||||
|
||||
<Button
|
||||
android:id="@+id/downloader_button_showmap"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/map"
|
||||
android:lines="1"
|
||||
android:gravity="center"
|
||||
android:onClick="onShowMapClicked"
|
||||
android:layout_margin="5dip"
|
||||
android:layout_weight="1" >
|
||||
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
android:id="@+id/downloader_button_shownetworksettings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/connection_settings"
|
||||
android:lines="1"
|
||||
android:gravity="center"
|
||||
android:onClick="onShowNetSettingsClicked"
|
||||
android:layout_margin="5dip"
|
||||
android:layout_weight="1" >
|
||||
|
||||
</Button>
|
||||
</LinearLayout>
|
|
@ -160,6 +160,14 @@ public class DownloadUI extends PreferenceActivity
|
|||
|
||||
private PreferenceScreen createCountriesHierarchy(PreferenceScreen root, int group, int country, int region)
|
||||
{
|
||||
// Add "header" with "Map" and "Connection Settings" buttons
|
||||
final Preference cell = new Preference(this);
|
||||
if (!ConnectionState.isConnected(this))
|
||||
cell.setLayoutResource(R.layout.downloader_header_map_connection);
|
||||
else
|
||||
cell.setLayoutResource(R.layout.downloader_header_map);
|
||||
root.addPreference(cell);
|
||||
|
||||
final int count = countriesCount(group, country, region);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
|
@ -173,19 +181,6 @@ public class DownloadUI extends PreferenceActivity
|
|||
return root;
|
||||
}
|
||||
|
||||
private void showNoConnectionDialog()
|
||||
{
|
||||
m_alert.setTitle(getString(R.string.no_internet_connection_detected));
|
||||
m_alert.setPositiveButton(getString(R.string.connection_settings), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dlg, int which) {
|
||||
DownloadUI.this.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
|
||||
dlg.dismiss();
|
||||
}
|
||||
});
|
||||
m_alert.setNegativeButton(android.R.string.cancel, m_alertCancelHandler);
|
||||
m_alert.create().show();
|
||||
}
|
||||
|
||||
private void showNotEnoughFreeSpaceDialog(String spaceNeeded, String countryName)
|
||||
{
|
||||
new AlertDialog.Builder(this).setMessage(String.format(getString(R.string.free_space_for_country), spaceNeeded, countryName))
|
||||
|
@ -228,44 +223,32 @@ public class DownloadUI extends PreferenceActivity
|
|||
break;
|
||||
|
||||
case 1: // ENotDownloaded
|
||||
if (!ConnectionState.isConnected(this))
|
||||
{ // Show "Connection is not available" dialog if there is no connection
|
||||
showNoConnectionDialog();
|
||||
// Check for available free space
|
||||
final long size = countryRemoteSizeInBytes(group, country, region);
|
||||
final String name = countryName(group, country, region);
|
||||
if (size > getFreeSpace())
|
||||
{
|
||||
showNotEnoughFreeSpaceDialog(formatSizeString(size), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check for available free space
|
||||
final long size = countryRemoteSizeInBytes(group, country, region);
|
||||
final String name = countryName(group, country, region);
|
||||
if (size > getFreeSpace())
|
||||
{
|
||||
showNotEnoughFreeSpaceDialog(formatSizeString(size), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Display download confirmation
|
||||
m_alert.setTitle(name);
|
||||
m_alert.setPositiveButton(getString(R.string.download_mb_or_kb, formatSizeString(size)),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dlg, int which) {
|
||||
downloadCountry(group, country, region);
|
||||
dlg.dismiss();
|
||||
}
|
||||
});
|
||||
m_alert.setNegativeButton(android.R.string.cancel, m_alertCancelHandler);
|
||||
m_alert.create().show();
|
||||
}
|
||||
// Display download confirmation
|
||||
m_alert.setTitle(name);
|
||||
m_alert.setPositiveButton(getString(R.string.download_mb_or_kb, formatSizeString(size)),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dlg, int which) {
|
||||
downloadCountry(group, country, region);
|
||||
dlg.dismiss();
|
||||
}
|
||||
});
|
||||
m_alert.setNegativeButton(android.R.string.cancel, m_alertCancelHandler);
|
||||
m_alert.create().show();
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // EDownloadFailed
|
||||
if (!ConnectionState.isConnected(this))
|
||||
showNoConnectionDialog();
|
||||
else
|
||||
{
|
||||
// Do not confirm download if status is failed, just start it
|
||||
downloadCountry(group, country, region);
|
||||
}
|
||||
// Do not confirm download if status is failed, just start it
|
||||
downloadCountry(group, country, region);
|
||||
break;
|
||||
|
||||
case 3: // EDownloading
|
||||
|
@ -294,4 +277,17 @@ public class DownloadUI extends PreferenceActivity
|
|||
}
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
}
|
||||
|
||||
public void onShowNetSettingsClicked(android.view.View v)
|
||||
{
|
||||
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
|
||||
}
|
||||
|
||||
public void onShowMapClicked(android.view.View v)
|
||||
{
|
||||
Intent mwmActivityIntent = new Intent(this, MWMActivity.class);
|
||||
// Disable animation because MWMActivity should appear exactly over this one
|
||||
mwmActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
startActivity(mwmActivityIntent);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue