This commit is contained in:
Alexey Kulish 2015-10-02 20:54:56 +03:00
commit 8a123271c6
20 changed files with 105 additions and 526 deletions

View file

@ -915,7 +915,7 @@
<string name="poi_operator">Operador</string>
<string name="poi_brand">Marca</string>
<string name="poi_enforcement_traffic_signals">Control de tràfic: obeir el semàfor</string>
<string name="poi_enforcement_traffic_signals">Control de tràfic: semàfor</string>
<string name="poi_enforcement_maxspeed">Control de trànsit: velocitat màxima</string>
<string name="poi_enforcement_maxheight">Control de trànsit: alçada màxima</string>
<string name="poi_enforcement_mindistance">Control de trànsit: distància mínima</string>
@ -1017,8 +1017,8 @@
<string name="poi_recycling_bicycles">Bicicletes</string>
<string name="poi_shower">Dutxa</string>
<string name="poi_drinking_water_yes">Aigua potable</string>
<string name="poi_drinking_water_no">Aigua no potable</string>
<string name="poi_drinking_water_yes">Aigua potable: sí</string>
<string name="poi_drinking_water_no">Aigua potable: no</string>
<string name="poi_seasonal_yes">De temporada</string>
<string name="poi_seasonal_no">Tot l\'any</string>
<string name="poi_seasonal_dry_season">Estació seca</string>
@ -1093,7 +1093,7 @@
<string name="poi_denomination_pentecostal">Pentecostal</string>
<string name="poi_denomination_mormon">Mormó</string>
<string name="poi_denomination_jehovahs_witness">Testimonis de Jehovà</string>
<string name="poi_denomination_greek_orthodox">Ortodox grec</string>
<string name="poi_denomination_greek_orthodox">Ortodoxa grega</string>
<string name="poi_denomination_reformed">Calvinisme</string>
<string name="poi_denomination_seventh_day_adventist">Adventisme del setè dia</string>
<string name="poi_denomination_new_apostolic">Nova apostòlica</string>
@ -1221,4 +1221,11 @@
<string name="poi_vending_coffee">Cafè</string>
<string name="poi_vending_tickets">Venda de tiquets</string>
<string name="poi_vending_water">Venda d\'aigua</string>
<string name="poi_bunker_silo">Sitja búnquer</string>
<string name="poi_vending_dvd">DVD</string>
<string name="poi_vending_candles">Espelmes</string>
<string name="poi_vending_toys">Joguines</string>
<string name="poi_vending_ice_cream">Gelat</string>
<string name="poi_vending_sim_cards">Targes SIM</string>
</resources>

View file

@ -2152,4 +2152,7 @@ Per retornar a l\'estil habitual dels mapes d\'OsmAnd, només cal desactivar aqu
<string name="m_s">m/s</string>
<string name="downloading_number_of_fiels">Baixada - %1$d fitxer</string>
<string name="srtm_plugin_disabled">Corbes de nivell desactivades</string>
<string name="show_free_version_banner">Mostra bàner de la versió gratuïta</string>
<string name="show_free_version_banner_description">Encara que tinguéssiu una versió de pagament també podríeu veure el bàner de la versió gratuïta</string>
</resources>

View file

@ -2162,4 +2162,6 @@
<string name="favorite_category_select">Vælg kategori</string>
<string name="downloading_number_of_fiels">Henter - %1$d fil</string>
<string name="srtm_plugin_disabled">Højdekurver er deaktiveret</string>
<string name="show_free_version_banner">Vis banner for gratis version</string>
<string name="show_free_version_banner_description">"Selvom du har en betalt version kan du stadig se banner for den gratis version"</string>
</resources>

View file

@ -1437,8 +1437,8 @@
<string name="poi_payment_notes_no">No acepta billetes</string>
<string name="poi_payment_electronic_purses_yes">Acepta monederos electrónicos</string>
<string name="poi_payment_electronic_purses_no">No acepta monederos electrónicos</string>
<string name="poi_payment_cash_yes">Acepta efectivo</string>
<string name="poi_payment_cash_no">No acepta efectivo</string>
<string name="poi_payment_cash_yes">Acepta dinero</string>
<string name="poi_payment_cash_no">No acepta dinero</string>
<string name="poi_payment_debit_cards_yes">Acepta tarjetas de débito</string>
<string name="poi_payment_debit_cards_no">No acepta tarjetas de débito</string>
<string name="poi_payment_bitcoin_yes">Acepta Bitcoin</string>
@ -1644,7 +1644,7 @@
<string name="poi_male_no">Prohibido para hombres</string>
<string name="poi_female_yes">Femenino</string>
<string name="poi_female_no">Prohibido para mujeres</string>
<string name="poi_indoor_yes">Cubierto (puertas adentro)</string>
<string name="poi_indoor_yes">Cubierto (interior)</string>
<string name="poi_indoor_no">Al aire libre</string>
<string name="poi_toilets_yes">Con baños</string>
<string name="poi_toilets_no">Sin baños</string>
@ -1671,7 +1671,7 @@
<string name="poi_vending_sweets">Dulces</string>
<string name="poi_vending_condoms">Condones</string>
<string name="poi_vending_stamps">Sellos</string>
<string name="poi_vending_bicycle_tube">Tubos de bicicleta</string>
<string name="poi_vending_bicycle_tube">Válvulas de bicicleta</string>
<string name="poi_vending_food">Comida</string>
<string name="poi_vending_drinks_food">Bebidas y comidas</string>
<string name="poi_vending_fuel">Surtidor de combustible</string>
@ -1709,4 +1709,12 @@
<string name="poi_inscription">Inscripción</string>
<string name="poi_brushless_yes">Con cepillo giratorio</string>
<string name="poi_brushless_no">Sin cepillo giratorio</string>
<string name="poi_vending_parcel_pickup_mail_in">Estación de paquetes y correos</string>
<string name="poi_vending_parcel_pickup">Estación de paquetería</string>
<string name="poi_vending_parcel_mail_in">Estación de correos</string>
<string name="poi_vending_elongated_coin">Moneda elongada</string>
<string name="poi_memorial_koshinto">Koshinto</string>
<string name="poi_memorial_jizo">Jizo</string>
</resources>

View file

@ -2083,4 +2083,8 @@
<string name="favorite_category_add_new">Añadir nuevo</string>
<string name="favorite_category_select">Elegir categoría</string>
<string name="srtm_plugin_disabled">Curvas de nivel desactivadas</string>
<string name="downloading_number_of_fiels">Descargando - %1$s archivo/s</string>
<string name="show_free_version_banner">Mostrar banner de versión gratuita</string>
<string name="show_free_version_banner_description">Aunque tenga la versión paga, podrá ver el banner de la versión gratuita</string>
</resources>

View file

@ -2206,4 +2206,6 @@ Si consiglia di aggiungere uno o più punti intermedi per migliorarne le prestaz
<string name="favorite_category_select">Scegli la categoria</string>
<string name="downloading_number_of_fiels">In download - %1$d file</string>
<string name="srtm_plugin_disabled">Linee isocline disattivate</string>
<string name="show_free_version_banner">Mostra il banner della versione gratuita</string>
<string name="show_free_version_banner_description">Anche se hai la versione a pagamento puoi comunque vedere il banner della versione gratuita</string>
</resources>

View file

@ -384,7 +384,7 @@
<string name="shared_string_control_stop">Stop</string>
<string name="shared_string_control_start">Avia/Inghitza</string>
<string name="map_widget_av_notes">Notas àudio/vìdeo</string>
<string name="osmand_srtm_short_description_80_chars">Plugin OsmAndfor pro sas lìnias de livellu sena lìnia</string>
<string name="osmand_srtm_short_description_80_chars">Plugin OsmAnd pro sas lìnias de livellu sena lìnia</string>
<string name="osmand_srtm_long_description_1000_chars">"Custu plugin frunidi sas lìnias de livellu e sas umbraduras de sos rilievos, chi podent èssere visualizadas in supra de sas mapas non in lìnia de OsmAnd. Custa funtzionalidade at a èssere appretziada meda dae sos atletas, sos escursionistas, e totu sos chi sunt interessados in s\'orografia e su paesàggiu.
\n\nSos datos globales (intre sos 70 grados nord e sos 70 grados sud) sunt basados in supra de sas medidas de su SRTM (Shuttle Radar Topography Mission) e de sASTER (Advanced Spaceborne Thermal Emission and Reflection Radiometer), unaina medidora a bordu de Terra, su satellite de su sistema di osservatzione de sa terra de sa NASA. ASTER est unisfortzu de coperassione intre NASA, su Ministeru de sEconomia Cummèrtziu e Industria (METI) de su Giappone, e su sistema ispatziale giapponesu (J-spacesystems). "</string>
<string name="map_widget_distancemeasurement">Medidura de sa distantzia</string>
@ -2116,4 +2116,7 @@
<string name="m_s">m/s</string>
<string name="downloading_number_of_fiels">Iscarrigande - %1$d documentu</string>
<string name="srtm_plugin_disabled">Lìnias de livellu disativadas</string>
<string name="show_free_version_banner">Ammustra sinsigna de sa versione a indonu (gratùita)</string>
<string name="show_free_version_banner_description">Fintzas si tenes sa versione a pagamentu podes bìere sinsigna de sa versione a indonu (gratùita)</string>
</resources>

View file

@ -2027,4 +2027,5 @@
<string name="min_km">min/km</string>
<string name="m_s">m/s</string>
<string name="srtm_plugin_disabled">Konturlinjer inaktiverade</string>
</resources>

View file

@ -2140,4 +2140,5 @@
<string name="favorite_category_add_new">增加新的</string>
<string name="favorite_category_select">選擇類別</string>
<string name="downloading_number_of_fiels">正在下載 - %1$d 檔案</string>
<string name="srtm_plugin_disabled">等高線已停用</string>
</resources>

View file

@ -1058,14 +1058,14 @@
<string name="poi_highway_crossing">Highway crossing</string>
<string name="poi_icn_ref">International cycling network route</string>
<string name="poi_ncn_ref">National cycling network route</string>
<string name="poi_rcn_ref">Regional cycling network route</string>
<string name="poi_lcn_ref">Local cycling network route</string>
<string name="poi_iwn_ref">International hiking network route</string>
<string name="poi_nwn_ref">National hiking network route</string>
<string name="poi_rwn_ref">Regional hiking network route</string>
<string name="poi_lwn_ref">Local hiking network route</string>
<string name="poi_icn_ref">International cycling network node</string>
<string name="poi_ncn_ref">National cycling network node</string>
<string name="poi_rcn_ref">Regional cycling network node</string>
<string name="poi_lcn_ref">Local cycling network node</string>
<string name="poi_iwn_ref">International hiking network node</string>
<string name="poi_nwn_ref">National hiking network node</string>
<string name="poi_rwn_ref">Regional hiking network node</string>
<string name="poi_lwn_ref">Local hiking network node</string>
<string name="poi_route_hiking_iwn_poi">International hiking route</string>
<string name="poi_route_hiking_nwn_poi">National hiking route</string>

View file

@ -1998,4 +1998,6 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="downloads_left_template">%1$s downloads left</string>
<string name="roads">Roads</string>
<string name="downloading_number_of_fiels">Downloding - %1$d file</string>
<string name="show_free_version_banner">Show free version banner</string>
<string name="show_free_version_banner_description">Even if you have paid version you still can see free version banner</string>
</resources>

View file

@ -1,21 +1,15 @@
package net.osmand.plus;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Environment;
import net.osmand.IndexConstants;
import net.osmand.StateChangedListener;
@ -34,15 +28,22 @@ import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.render.RenderingRulesStorage;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Environment;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
public class OsmandSettings {
@ -1072,6 +1073,8 @@ public class OsmandSettings {
public CommonPreference<String> PREVIOUS_INSTALLED_VERSION = new StringPreference("previous_installed_version", "").makeGlobal();
public final OsmandPreference<Boolean> SHOULD_SHOW_FREE_VERSION_BANNER = new BooleanPreference("should_show_free_version_banner", false).makeGlobal().cache();
public ITileSource getMapTileSource(boolean warnWhenSelected) {
String tileName = MAP_TILE_SOURCES.get();
if (tileName != null) {

View file

@ -1,6 +1,7 @@
package net.osmand.plus.development;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
@ -142,6 +143,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
final Preference agpspref = new Preference(this);
agpspref.setTitle(R.string.agps_info);
if (settings.AGPS_DATA_LAST_TIME_DOWNLOADED.get() != 0L) {
@SuppressLint("SimpleDateFormat")
SimpleDateFormat prt = new SimpleDateFormat("yyyy-MM-dd HH:mm");
agpspref.setSummary(getString(R.string.agps_data_last_downloaded, prt.format(settings.AGPS_DATA_LAST_TIME_DOWNLOADED.get())));
} else {
@ -155,6 +157,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
public boolean onPreferenceClick(Preference preference) {
if(getMyApplication().getSettings().isInternetConnectionAvailable(true)) {
getMyApplication().getLocationProvider().redownloadAGPS();
@SuppressLint("SimpleDateFormat")
SimpleDateFormat prt = new SimpleDateFormat("yyyy-MM-dd HH:mm");
agpspref.setSummary(getString(R.string.agps_data_last_downloaded, prt.format(settings.AGPS_DATA_LAST_TIME_DOWNLOADED.get())));
}
@ -167,6 +170,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
pref = new Preference(this);
pref.setTitle(R.string.day_night_info);
if (sunriseSunset != null) {
@SuppressLint("SimpleDateFormat")
SimpleDateFormat prt = new SimpleDateFormat("yyyy-MM-dd HH:mm");
pref.setSummary(getString(R.string.day_night_info_description, prt.format(sunriseSunset.getSunrise()),
prt.format(sunriseSunset.getSunset())));
@ -177,6 +181,10 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
//setEnabled(false) creates bad readability on some devices
//pref.setEnabled(false);
cat.addPreference(pref);
cat.addPreference(createCheckBoxPreference(settings.SHOULD_SHOW_FREE_VERSION_BANNER,
R.string.show_free_version_banner,
R.string.show_free_version_banner_description));
}
protected void availableProfileDialog() {
@ -193,7 +201,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey()+",");
for(ApplicationMode mode : modes) {
if(selected.contains(mode)) {
vls.append(mode.getStringKey()+",");
vls.append(mode.getStringKey()).append(",");
}
}
settings.AVAILABLE_APP_MODES.set(vls.toString());

View file

@ -34,7 +34,6 @@ import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.items.WorldItemsFragment;
import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
import net.osmand.plus.download.newimplementation.NewLocalIndexesFragment;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
@ -321,24 +320,6 @@ public class DownloadActivity extends BaseDownloadActivity {
}
}
@Override
public void onCategorizationFinished(List<IndexItem> filtered,
List<IndexItemCategoryWithSubcat> cats) {
boolean isPushed = false;
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof NewLocalIndexesFragment) {
if (f.isAdded()) {
isPushed = true;
((NewLocalIndexesFragment) f).onCategorizationFinished(filtered, cats);
}
}
}
if (!isPushed) {
this.cats = cats;
}
}
@Override
public void onCategorizationFinished() {
for (WeakReference<Fragment> ref : fragSet) {

View file

@ -72,14 +72,12 @@ public class RegionDialogFragment extends DialogFragment {
}
toolbar.setTitle(this.region.getName());
}
DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication().getSettings(),
DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication(),
getResources());
final WorldRegion finalRegion = region;
mProgressListener = new DownloadsUiHelper.MapDownloadListener(view, getResources()){
@Override
public void onProgressUpdate(int progressPercentage, int activeTasks) {
LOG.debug(finalRegion.getName() + " onProgressUpdate()");
super.onProgressUpdate(progressPercentage, activeTasks);
}
@ -87,7 +85,7 @@ public class RegionDialogFragment extends DialogFragment {
public void onFinished() {
super.onFinished();
DownloadsUiHelper.initFreeVersionBanner(view,
getMyApplication().getSettings(), getResources());
getMyApplication(), getResources());
}
};

View file

@ -61,7 +61,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
onCategorizationFinished();
DownloadsUiHelper.initFreeVersionBanner(view,
getMyApplication().getSettings(), getResources());
getMyApplication(), getResources());
return view;
}

View file

@ -12,6 +12,7 @@ import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
@ -22,8 +23,15 @@ public final class DownloadsUiHelper {
private DownloadsUiHelper() {
}
public static void initFreeVersionBanner(View header, OsmandSettings settings,
public static void initFreeVersionBanner(View header, OsmandApplication application,
Resources resources) {
final View freeVersionBanner = header.findViewById(R.id.freeVersionBanner);
OsmandSettings settings = application.getSettings();
if(!Version.isFreeVersion(application) && !settings.SHOULD_SHOW_FREE_VERSION_BANNER.get()) {
freeVersionBanner.setVisibility(View.GONE);
return;
}
TextView downloadsLeftTextView = (TextView) header.findViewById(R.id.downloadsLeftTextView);
final int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
- settings.NUMBER_OF_FREE_DOWNLOADS.get();
@ -35,8 +43,7 @@ public final class DownloadsUiHelper {
BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS));
final View buttonsLinearLayout = header.findViewById(R.id.buttonsLinearLayout);
header.findViewById(R.id.freeVersionBanner).setOnClickListener(
freeVersionBanner.setOnClickListener(
new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
buttonsLinearLayout));

View file

@ -1,104 +0,0 @@
package net.osmand.plus.download.newimplementation;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import org.apache.commons.logging.Log;
public class MapsInCategoryFragment extends DialogFragment {
private static final Log LOG = PlatformUtil.getLog(IndexItemCategoryWithSubcat.class);
public static final String TAG = "MapsInCategoryFragment";
private static final String CATEGORY = "category";
private DownloadsUiHelper.MapDownloadListener mProgressListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean isLightTheme = ((OsmandApplication) getActivity().getApplication())
.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
setStyle(STYLE_NO_FRAME, themeId);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
IndexItemCategoryWithSubcat category = getArguments().getParcelable(CATEGORY);
assert category != null;
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
SubcategoriesFragment.createInstance(category)).commit();
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(category.getName());
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
DownloadsUiHelper.initFreeVersionBanner(view,
getMyActivity().getMyApplication().getSettings(), getResources());
mProgressListener = new DownloadsUiHelper.MapDownloadListener(view, getResources()){
@Override
public void onFinished() {
super.onFinished();
DownloadsUiHelper.initFreeVersionBanner(view,
getMyActivity().getMyApplication().getSettings(), getResources());
}
};
view.findViewById(R.id.downloadProgressLayout).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return view;
}
@Override
public void onResume() {
super.onResume();
getMyActivity().setOnProgressUpdateListener(mProgressListener);
}
@Override
public void onPause() {
super.onPause();
getMyActivity().setOnProgressUpdateListener(null);
}
private DownloadActivity getMyActivity() {
return (DownloadActivity) getActivity();
}
public void onCategorySelected(@NonNull IndexItemCategoryWithSubcat category) {
LOG.debug("onCategorySelected()");
createInstance(category).show(getChildFragmentManager(), TAG);
}
public static MapsInCategoryFragment createInstance(
@NonNull IndexItemCategoryWithSubcat category) {
Bundle bundle = new Bundle();
bundle.putParcelable(CATEGORY, category);
MapsInCategoryFragment fragment = new MapsInCategoryFragment();
fragment.setArguments(bundle);
return fragment;
}
}

View file

@ -1,180 +0,0 @@
package net.osmand.plus.download.newimplementation;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.StatFs;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.MenuItemCompat;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.IndexItem;
import org.apache.commons.logging.Log;
import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class NewLocalIndexesFragment extends OsmAndListFragment {
private static final Log LOG = PlatformUtil.getLog(NewLocalIndexesFragment.class);
public static final String CATEGORIES = "categories";
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
public static final int RELOAD_ID = 0;
private CategoriesAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.local_index_fragment, container, false);
ListView listView = (ListView) view.findViewById(android.R.id.list);
mAdapter = new CategoriesAdapter(getActivity(), getMyApplication());
listView.setAdapter(mAdapter);
List<IndexItemCategoryWithSubcat> cats = ((DownloadActivity) getActivity()).getCats();
if (cats != null) {
onCategorizationFinished(null, cats);
}
if (savedInstanceState != null) {
List<IndexItemCategoryWithSubcat> savedCats =
savedInstanceState.getParcelableArrayList(CATEGORIES);
onCategorizationFinished(null, savedCats);
}
View header = inflater.inflate(R.layout.local_index_fragment_header, listView, false);
initMemoryConsumedCard(header);
DownloadsUiHelper.initFreeVersionBanner(header, getMyApplication().getSettings(),
getResources());
listView.addHeaderView(header);
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
return view;
}
private void initMemoryConsumedCard(View header) {
ProgressBar sizeProgress = (ProgressBar) header.findViewById(R.id.progressBar);
File dir = getMyApplication().getAppPath("").getParentFile();
String size = formatGb.format(new Object[]{0});
int percent = 0;
if (dir.canRead()) {
StatFs statFs = new StatFs(dir.getAbsolutePath());
//noinspection deprecation
size = formatGb.format(new Object[]{(float) (statFs.getAvailableBlocks()) * statFs.getBlockSize() / (1 << 30)});
//noinspection deprecation
percent = statFs.getAvailableBlocks() * 100 / statFs.getBlockCount();
}
sizeProgress.setProgress(percent);
String text = getString(R.string.free, size);
TextView descriptionText = (TextView) header.findViewById(R.id.rightTextView);
descriptionText.setText(Html.fromHtml(text));
descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
((TextView) header.findViewById(R.id.leftTextView)).setText(R.string.device_memory);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem item = menu.add(0, RELOAD_ID, 0, R.string.shared_string_refresh);
item.setIcon(R.drawable.ic_action_refresh_dark);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == RELOAD_ID) {
// re-create the thread
DownloadActivity.downloadListIndexThread.runReloadIndexFiles();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onSaveInstanceState(Bundle outState) {
LOG.debug("onSaveInstanceState()");
ArrayList<IndexItemCategoryWithSubcat> items = new ArrayList<>(mAdapter.getCount());
for (int i = 0; i < mAdapter.getCount(); i++) {
items.add(mAdapter.getItem(i));
}
outState.putParcelableArrayList(CATEGORIES, items);
super.onSaveInstanceState(outState);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.addToBackStack(null);
MapsInCategoryFragment.createInstance(mAdapter.getItem(position - 1))
.show(fragmentTransaction, MapsInCategoryFragment.TAG);
}
private DownloadActivity getDownloadActivity() {
return (DownloadActivity) getActivity();
}
public void onCategorizationFinished(List<IndexItem> filtered, List<IndexItemCategoryWithSubcat> cats) {
if (mAdapter != null) {
mAdapter.clear();
mAdapter.addAll(cats);
}
}
private static class CategoriesAdapter extends ArrayAdapter<IndexItemCategoryWithSubcat> {
private final OsmandApplication osmandApplication;
public CategoriesAdapter(Context context, OsmandApplication osmandApplication) {
super(context, R.layout.simple_list_menu_item);
this.osmandApplication = osmandApplication;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.simple_list_menu_item, parent, false);
viewHolder = new ViewHolder();
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Drawable iconLeft = osmandApplication.getIconsCache()
.getContentIcon(R.drawable.ic_world_globe_dark);
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
viewHolder.textView.setText(getItem(position).categoryStaticData.getName());
return convertView;
}
private static class ViewHolder {
TextView textView;
}
}
}

View file

@ -1,167 +0,0 @@
package net.osmand.plus.download.newimplementation;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.HasName;
public class SubcategoriesFragment extends Fragment {
private static final String CATEGORY = "category";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
IndexItemCategoryWithSubcat category = getArguments().getParcelable(CATEGORY);
assert category != null;
ListView listView = new ListView(getActivity());
final OsmandApplication application = (OsmandApplication) getActivity().getApplication();
final MapFilesAdapter mAdapter = new MapFilesAdapter(getActivity(),
(MapsInCategoryFragment) getParentFragment());
listView.setAdapter(mAdapter);
mAdapter.addAll(category.items);
mAdapter.addAll(category.subcats);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final HasName item = mAdapter.getItem(position);
if (item instanceof IndexItemCategoryWithSubcat) {
((MapsInCategoryFragment) getParentFragment())
.onCategorySelected((IndexItemCategoryWithSubcat) item);
}
}
});
return listView;
}
public static SubcategoriesFragment createInstance(
@NonNull IndexItemCategoryWithSubcat category) {
Bundle bundle = new Bundle();
bundle.putParcelable(CATEGORY, category);
SubcategoriesFragment fragment = new SubcategoriesFragment();
fragment.setArguments(bundle);
return fragment;
}
private static class MapFilesAdapter extends ArrayAdapter<HasName> {
final MapsInCategoryFragment fragment;
public MapFilesAdapter(Context context, MapsInCategoryFragment fragment) {
super(context, R.layout.two_line_with_images_list_item);
this.fragment = fragment;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
HasName item = getItem(position);
if (item instanceof IndexItemCategoryWithSubcat) {
viewHolder.bindCategory((IndexItemCategoryWithSubcat) item,
(DownloadActivity) getContext());
} else if (item instanceof IndexItem) {
viewHolder.bindIndexItem((IndexItem) item, (DownloadActivity) getContext(),
fragment);
} else {
throw new IllegalArgumentException("Item must be of type IndexItem or " +
"IndexItemCategory but is of type:" + item.getClass());
}
return convertView;
}
private static class ViewHolder {
private final TextView nameTextView;
private final TextView descrTextView;
private final ImageView leftImageView;
private final ImageView rightImageButton;
private final ProgressBar progressBar;
public ViewHolder(View convertView) {
nameTextView = (TextView) convertView.findViewById(R.id.name);
descrTextView = (TextView) convertView.findViewById(R.id.description);
leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView);
rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton);
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
}
public void bindIndexItem(final IndexItem indexItem, final DownloadActivity context,
MapsInCategoryFragment fragment) {
if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
nameTextView.setText(indexItem.getVisibleName(context,
context.getMyApplication().getRegions()));
} else {
nameTextView.setText(indexItem.getType().getString(context));
}
descrTextView.setText(indexItem.getSizeDescription(context));
leftImageView.setImageDrawable(getContextIcon(context,
indexItem.getType().getIconResource()));
rightImageButton.setVisibility(View.VISIBLE);
rightImageButton.setImageDrawable(getContextIcon(context,
R.drawable.ic_action_import));
rightImageButton.setTag(R.id.index_item, indexItem);
rightImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((BaseDownloadActivity) v.getContext())
.startDownload((IndexItem) v.getTag(R.id.index_item));
}
});
progressBar.setVisibility(View.GONE);
}
public void bindCategory(IndexItemCategoryWithSubcat category,
DownloadActivity context) {
nameTextView.setText(category.getName());
if (category.types.size() > 0) {
StringBuilder stringBuilder = new StringBuilder();
Resources resources = context.getResources();
for (Integer mapType : category.types) {
stringBuilder.append(resources.getString(mapType));
stringBuilder.append(", ");
}
stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.capacity());
descrTextView.setText(stringBuilder.toString());
} else {
descrTextView.setText(R.string.shared_string_others);
}
leftImageView.setImageDrawable(getContextIcon(context, R.drawable.ic_map));
rightImageButton.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE);
}
private Drawable getContextIcon(DownloadActivity context, int resourceId) {
return context.getMyApplication().getIconsCache().getContentIcon(resourceId);
}
}
}
}