Add card to download new map

This commit is contained in:
Victor Shcherb 2014-12-09 02:14:44 +01:00
parent ce5f75c6fa
commit 848df6b721
8 changed files with 214 additions and 30 deletions

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/bg_cardui"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/message"
android:layout_height="wrap_content"
android:padding="12dp"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:textColor="@color/dashboard_black"
android:layout_gravity="center_horizontal"/>
<View android:layout_width="match_parent"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="40dp">
<Button android:id="@+id/local_downloads"
android:layout_width="0dp"
android:layout_weight="1"
android:text="@string/dash_download_manage"
style="@style/DashboardGeneralButton"/>
<View android:layout_width="1dp"
android:background="@color/dashboard_divider"
android:layout_height="match_parent"/>
<Button android:id="@+id/download_new_map"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/dash_download_new_one"
style="@style/DashboardGeneralButton"/>
</LinearLayout>
</LinearLayout>

View file

@ -89,6 +89,13 @@
android:layout_weight="0" />
<FrameLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="gone"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"

View file

@ -9,6 +9,10 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="dash_download_msg_none">Do you want to download any offline map?</string>
<string name="dash_download_msg">You have %1$s maps downloaded</string>
<string name="dash_download_new_one">Download New Map</string>
<string name="dash_download_manage">Manage</string>
<string name="map_locale">Map language</string>
<string name="rendering_attr_transportStops_name">Transport Stops</string>
<string name="application_dir_change_warning2">Do you want OsmAnd to also copy its data files to the new destination? Select \'No\' for OsmAnd to just create and use the new folder.</string>

View file

@ -13,6 +13,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.dashboard.DashDownloadMapsFragment;
import net.osmand.plus.dashboard.DashErrorFragment;
import net.osmand.plus.dashboard.DashFavoritesFragment;
import net.osmand.plus.dashboard.DashMapFragment;
@ -169,6 +170,10 @@ public class MainMenuActivity extends BaseDownloadActivity {
DashUpdatesFragment updatesFragment = new DashUpdatesFragment();
fragmentTransaction.add(R.id.content, updatesFragment, DashUpdatesFragment.TAG);
}
if (manager.findFragmentByTag(DashDownloadMapsFragment.TAG) == null){
DashDownloadMapsFragment fragment = new DashDownloadMapsFragment();
fragmentTransaction.add(R.id.content, fragment, DashDownloadMapsFragment.TAG);
}
if (manager.findFragmentByTag(DashPluginsFragment.TAG) == null){
DashPluginsFragment pluginsFragment = new DashPluginsFragment();
fragmentTransaction.add(R.id.content, pluginsFragment, DashPluginsFragment.TAG).commit();

View file

@ -0,0 +1,109 @@
package net.osmand.plus.dashboard;
import java.io.File;
import java.text.MessageFormat;
import java.util.Locale;
import net.osmand.IndexConstants;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.helpers.FontCache;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
/**
* Created by dummy on 02.12.14.
*/
public class DashDownloadMapsFragment extends DashBaseFragment {
public static final String TAG = "DASH_DOWNLOAD_MAPS_FRAGMENT";
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = getActivity().getLayoutInflater().inflate(R.layout.dash_download_maps_fragment, container, false);
Typeface typeface = FontCache.getRobotoMedium(getActivity());
final TextView message =((TextView) view.findViewById(R.id.message));
final Button local = ((Button) view.findViewById(R.id.local_downloads));
message.setTypeface(typeface);
new AsyncTask<Void, Void, Void>() {
int countMaps = 0;
long size = 0;
@Override
protected Void doInBackground(Void... params) {
updateCount(IndexConstants.MAPS_PATH);
updateCount(IndexConstants.SRTM_INDEX_DIR);
return null;
}
protected void updateCount(String s) {
File ms = getMyApplication().getAppPath(s);
if (ms.exists()) {
File[] lf = ms.listFiles();
if (lf != null) {
for (File f : ms.listFiles()) {
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
size += f.length();
countMaps++;
}
}
}
}
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if(countMaps > 0) {
long mb = 1 << 20;
long gb = 1 << 30;
String sz = size > gb ?
formatGb.format(new Object[] { (float) size / (gb) }) :
formatMb.format(new Object[] { (float) size / mb }) ;
message.setText(getString(R.string.dash_download_msg, countMaps+"") + " (" + sz +")");
local.setVisibility(View.VISIBLE);
} else {
message.setText(getString(R.string.dash_download_msg_none));
local.setVisibility(View.GONE);
}
}
};
local.setTypeface(typeface);
local.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Intent intent = new Intent(view.getContext(), getMyApplication().getAppCustomization().getDownloadIndexActivity());
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.LOCAL_TAB);
intent.putExtra(DownloadActivity.SINGLE_TAB, true);
getActivity().startActivity(intent);
}
});
Button cancelBtn = ((Button) view.findViewById(R.id.download_new_map));
cancelBtn.setTypeface(typeface);
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent intent = new Intent(view.getContext(), getMyApplication().getAppCustomization().getDownloadIndexActivity());
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
intent.putExtra(DownloadActivity.SINGLE_TAB, true);
getActivity().startActivity(intent);
}
});
return view;
}
}

View file

@ -41,6 +41,7 @@ public class DashUpdatesFragment extends DashBaseFragment {
public void onClick(View view) {
final Intent intent = new Intent(view.getContext(), getMyApplication().getAppCustomization().getDownloadIndexActivity());
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.UPDATES_TAB);
intent.putExtra(DownloadActivity.SINGLE_TAB, true);
getActivity().startActivity(intent);
}
});

View file

@ -48,13 +48,16 @@ public class DownloadActivity extends BaseDownloadActivity {
private List<LocalIndexInfo> localIndexInfos = new ArrayList<LocalIndexInfo>();
private String initialFilter = "";
private boolean singleTab;
public static final String FILTER_KEY = "filter";
public static final String FILTER_CAT = "filter_cat";
public static final String TAB_TO_OPEN = "Tab_to_open";
public static final String LOCAL_TAB = "local";
public static final String DOWNLOAD_TAB = "download";
public static final String UPDATES_TAB = "updates";
public static final String SINGLE_TAB = "SINGLE_TAB";
@Override
@ -72,24 +75,45 @@ public class DownloadActivity extends BaseDownloadActivity {
setProgressBarIndeterminateVisibility(false);
setContentView(R.layout.tab_content);
singleTab = getIntent() != null && getIntent().getBooleanExtra(SINGLE_TAB, false);
int currentTab = 0;
String tab = getIntent() == null ? null : getIntent().getExtras().getString(TAB_TO_OPEN);
if (tab != null) {
if (tab.equals(DOWNLOAD_TAB)){
currentTab = 1;
} else if (tab.equals(UPDATES_TAB)){
currentTab = 2;
}
}
if (singleTab) {
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setVisibility(View.GONE);
Fragment f = currentTab == 0 ? new LocalIndexesFragment() :
(currentTab == 1? new DownloadIndexFragment() : new UpdatesIndexFragment());
findViewById(R.id.layout).setVisibility(View.VISIBLE);
getSupportFragmentManager().beginTransaction().add(R.id.layout, f).commit();
} else {
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
mTabsAdapter = new FavouritesActivity.TabsAdapter(this, tabHost, viewPager, settings, false);
if (getMyApplication().getAppCustomization().onlyTourDownload()){
mTabsAdapter.addTab(tabHost.newTabSpec("DOWNLOADS").setIndicator(getString(R.string.download_tab_downloads)),
if (getMyApplication().getAppCustomization().onlyTourDownload()) {
mTabsAdapter.addTab(
tabHost.newTabSpec("DOWNLOADS").setIndicator(getString(R.string.download_tab_downloads)),
DownloadIndexFragment.class, null);
} else {
mTabsAdapter.addTab(tabHost.newTabSpec("LOCAL_INDEX").setIndicator(getString(R.string.download_tab_local)),
mTabsAdapter.addTab(
tabHost.newTabSpec("LOCAL_INDEX").setIndicator(getString(R.string.download_tab_local)),
LocalIndexesFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("DOWNLOADS").setIndicator(getString(R.string.download_tab_downloads)),
mTabsAdapter.addTab(
tabHost.newTabSpec("DOWNLOADS").setIndicator(getString(R.string.download_tab_downloads)),
DownloadIndexFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("UPDATES").setIndicator(getString(R.string.download_tab_updates)),
UpdatesIndexFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("UPDATES")
.setIndicator(getString(R.string.download_tab_updates)), UpdatesIndexFragment.class, null);
}
tabHost.setCurrentTab(0);
tabHost.setCurrentTab(currentTab);
}
settings = ((OsmandApplication)getApplication()).getSettings();
@ -136,15 +160,6 @@ public class DownloadActivity extends BaseDownloadActivity {
downloadTypes.add(0, type);
}
}
String tab = intent.getExtras().getString(TAB_TO_OPEN);
if (tab != null) {
if (tab.equals(DOWNLOAD_TAB)){
tabHost.setCurrentTab(1);
} else if (tab.equals(UPDATES_TAB)){
tabHost.setCurrentTab(2);
}
}
}
getSupportActionBar().setHomeButtonEnabled(true);
@ -165,7 +180,6 @@ public class DownloadActivity extends BaseDownloadActivity {
protected void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
}

View file

@ -13,9 +13,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import android.text.method.LinkMovementMethod;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.*;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
@ -24,8 +21,11 @@ import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.*;
import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms;
import android.app.Activity;
@ -38,6 +38,7 @@ import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StatFs;
import android.text.method.LinkMovementMethod;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
@ -51,7 +52,13 @@ import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.ActionMode.Callback;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SubMenu;
public class LocalIndexesFragment extends OsmandExpandableListFragment {