diff --git a/LICENSE b/LICENSE index 214f10fe11..61ae46b812 100644 --- a/LICENSE +++ b/LICENSE @@ -143,4 +143,6 @@ - Montreal: "Montreal Metro" by STM - http://www.stm.info/en-bref/pictometro.htm. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Montreal_Metro.svg#/media/File:Montreal_Metro.svg - Toronto: "TTC" by Source. Licensed under Fair use via Wikipedia - https://en.wikipedia.org/wiki/File:TTC.svg#/media/File:TTC.svg - Bangkok: "MRT (Bangkok) logo" by Bangkok_Metro_logo.png: Paul_012.Original uploader was Paul 012 at en.wikipediaderivative work: Nevetsjc (talk)Revision traced from http://si0.twimg.com/profile_images/975897559/logo.jpg - Bangkok_Metro_logo.png. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:MRT_(Bangkok)_logo.svg#/media/File:MRT_(Bangkok)_logo.svg - - Rotterdam: "RET metro logo" by Sebastiaan1997 - Own work. Licensed under CC BY-SA 3.0 via Commons - https://commons.wikimedia.org/wiki/File:RET_metro_logo.svg#/media/File:RET_metro_logo.svg \ No newline at end of file + - Rotterdam: "RET metro logo" by Sebastiaan1997 - Own work. Licensed under CC BY-SA 3.0 via Commons - https://commons.wikimedia.org/wiki/File:RET_metro_logo.svg#/media/File:RET_metro_logo.svg + - Amsterdam: "Amsterdam metro" by Peeperman - Own work. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Amsterdam_metro.svg#/media/File:Amsterdam_metro.svg + - Brussels: "Brussels Metro logo" by Source. Licensed under Fair use via Wikipedia - https://en.wikipedia.org/wiki/File:Brussels_Metro_logo.svg#/media/File:Brussels_Metro_logo.svg \ No newline at end of file diff --git a/OsmAnd/res/layout/download.xml b/OsmAnd/res/layout/download.xml index 08e3656abc..3df15f54fb 100644 --- a/OsmAnd/res/layout/download.xml +++ b/OsmAnd/res/layout/download.xml @@ -3,7 +3,8 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="match_parent" - android:orientation="vertical" > + android:orientation="vertical" + android:id="@+id/mainLayout"> - - + - - - - - - - - - - - - - - + - - - - - + android:background="?attr/ctx_menu_info_view_bg" + android:orientation="vertical"> \ No newline at end of file diff --git a/OsmAnd/res/layout/free_version_banner.xml b/OsmAnd/res/layout/free_version_banner.xml index ad7c33fc05..6dc2fd004a 100644 --- a/OsmAnd/res/layout/free_version_banner.xml +++ b/OsmAnd/res/layout/free_version_banner.xml @@ -1,10 +1,10 @@ @@ -47,8 +48,9 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:max="10" - tools:progress="5" - android:progressDrawable="@drawable/number_of_downloads_progress_bar_drawable"/> + android:progressDrawable="@drawable/number_of_downloads_progress_bar_drawable" + android:saveEnabled="false" + tools:progress="5"/> + android:text="@string/get_full_version" + osmand:textAllCapsCompat="true"/> + android:text="@string/later" + osmand:textAllCapsCompat="true"/> diff --git a/OsmAnd/res/values-da/phrases.xml b/OsmAnd/res/values-da/phrases.xml index c408c5fa13..7e5edb6cdb 100644 --- a/OsmAnd/res/values-da/phrases.xml +++ b/OsmAnd/res/values-da/phrases.xml @@ -262,7 +262,7 @@ Forskning IT kontor Avisredaktion - Arkitekt + Arkitektkontor Reklamebureau Uddannelsesinstitution Lydstudio @@ -1829,7 +1829,7 @@ Sheltertype: hytte Sheltertype: bygning Sheltertype: vildtskjul - Sheltertype: heller + Sheltertype: klippehule Sheltertype: solafskærming Sheltertype: feltly Sheltertype: telt @@ -1861,4 +1861,29 @@ Kunstværk: stele Kunstværk: springvand +Bredde + + Arkitekt + + Arkitektur: moderne + Arkitektur: stalinistisk nyklassicisme + Arkitektur: eklecticisme + Arkitektur: ny objektivitet + Arkitektur: moderne + Arkitektur: konstruktivisme + Arkitektur: umgebindehaus + Arkitektur: træskelet + Arkitektur: jugendstil + Arkitektur: nyklassicisme + Arkitektur: victoriansk + Arkitektur: brutalisme + Arkitektur: klassicisme + Arkitektur: gotik + Arkitektur: gammelrussisk + Arkitektur: barok + Arkitektur: postkonstruktivisme + Arkitektur: wilheminsk stil + Arkitektur: renæssance + Arkitektur: romansk stil + diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index 4a30564b00..f1cf85c0d6 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -574,12 +574,12 @@ GPS секунд мин. - Выберите интервал позиционирования для сервиса + Выберите интервал пробуждения для фоновой службы Интервал пробуждения GPS - Выберите источник позиционирования для сервиса + Выберите источник позиционирования для фоновой службы Источник позиционирования Запускает OsmAnd в фоновом режиме для отслеживания местоположения при выключенном экране - Сервис навигации + Запуск приложения в фоновом режиме Сервис маршрутизации OsmAnd включён, если отключить позиционирование, он перестанет вести по маршруту. Настройки навигации Навигация @@ -2103,4 +2103,23 @@ Остановить моделирование Добавить новую Выберите категорию + Выберите единицы измерения скорости + Единицы измерения скорости + Морские мили + Километр в час + Миля в час + Метр в секунду + Минута на километр + Минута на милю + Морская миля в час (узел) + мин/м + мин/км + м/с + + Запись поездки + Навигация + Информация об избранной точке + Избегать пригородных поездов + Избегать пригородных поездов + Опасность diff --git a/OsmAnd/res/values-zh-rTW/phrases.xml b/OsmAnd/res/values-zh-rTW/phrases.xml index f43dee6a25..bfa9cabd52 100644 --- a/OsmAnd/res/values-zh-rTW/phrases.xml +++ b/OsmAnd/res/values-zh-rTW/phrases.xml @@ -1665,4 +1665,12 @@ 洗手間進出:社區 洗手間進出:公共 + 尿布更換室 + + 尿布更換台 + 無尿布更換台 + 停車時限 + + 停車票卡 + 香菸 diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index 41e53ab48b..2849564a03 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -22,12 +22,12 @@ import android.widget.BaseAdapter; import android.widget.BaseExpandableListAdapter; import android.widget.Button; import android.widget.ExpandableListAdapter; -import android.widget.ImageView; import android.widget.ListAdapter; import android.widget.ProgressBar; import android.widget.TextView; import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -39,11 +39,14 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.activities.TabActivity; import net.osmand.plus.base.BasicProgressAsyncTask; +import net.osmand.plus.download.items.RegionDialogFragment; import net.osmand.plus.download.items.SearchDialogFragment; import net.osmand.plus.download.items.WorldItemsFragment; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.controls.PagerSlidingTabStrip; +import org.apache.commons.logging.Log; + import java.io.File; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -54,15 +57,7 @@ import java.util.Map; import java.util.Set; -public class DownloadActivity extends BaseDownloadActivity { - - private View progressView; - private ProgressBar indeterminateProgressBar; - private ProgressBar determinateProgressBar; - private TextView progressMessage; - private TextView progressPercent; - private ImageView cancel; - +public class DownloadActivity extends BaseDownloadActivity implements RegionDialogFragment.DialogDismissListener { private List localIndexInfos = new ArrayList(); private String initialFilter = ""; @@ -135,21 +130,6 @@ public class DownloadActivity extends BaseDownloadActivity { settings = ((OsmandApplication) getApplication()).getSettings(); - indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar); - determinateProgressBar = (ProgressBar) findViewById(R.id.memory_progress); - progressView = findViewById(R.id.ProgressView); - progressMessage = (TextView) findViewById(R.id.ProgressMessage); - progressPercent = (TextView) findViewById(R.id.ProgressPercent); - cancel = (ImageView) findViewById(R.id.Cancel); - cancel.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_remove_dark)); - cancel.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - makeSureUserCancelDownload(); - } - }); - findViewById(R.id.downloadButton).setOnClickListener(new View.OnClickListener() { @Override @@ -221,6 +201,7 @@ public class DownloadActivity extends BaseDownloadActivity { protected void onResume() { super.onResume(); getMyApplication().getAppCustomization().resumeActivity(DownloadActivity.class, this); + initFreeVersionBanner(findViewById(R.id.mainLayout)); } @@ -260,53 +241,15 @@ public class DownloadActivity extends BaseDownloadActivity { @Override public void updateProgress(boolean updateOnlyProgress) { - BasicProgressAsyncTask basicProgressAsyncTask = DownloadActivity.downloadListIndexThread.getCurrentRunningTask(); - final boolean isFinished = basicProgressAsyncTask == null - || basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED; - boolean indeterminate = true; - int percent = 0; - String message = ""; - if (!isFinished) { - indeterminate = basicProgressAsyncTask.isIndeterminate(); - message = basicProgressAsyncTask.getDescription(); - if (!indeterminate) { - percent = basicProgressAsyncTask.getProgressPercentage(); - } - } + BasicProgressAsyncTask basicProgressAsyncTask = + DownloadActivity.downloadListIndexThread.getCurrentRunningTask(); if (visibleBanner != null) { - visibleBanner.updateProgress(isFinished, indeterminate, percent, message); + final int countedDownloads = DownloadActivity.downloadListIndexThread.getCountedDownloads(); + visibleBanner.updateProgress(countedDownloads, basicProgressAsyncTask); } if (!updateOnlyProgress) { updateDownloadButton(); } - - - // TODO delete after refactoring! - //needed when rotation is performed and progress can be null - if (progressView == null) { - return; - } - - if (updateOnlyProgress) { - if (basicProgressAsyncTask != null && !basicProgressAsyncTask.isIndeterminate()) { - progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%"); - determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage()); - } - } else { - progressView.setVisibility(!isFinished ? View.VISIBLE : View.GONE); - if (!isFinished) { - indeterminateProgressBar.setVisibility(!indeterminate ? View.GONE : View.VISIBLE); - determinateProgressBar.setVisibility(indeterminate ? View.GONE : View.VISIBLE); - cancel.setVisibility(indeterminate ? View.GONE : View.VISIBLE); - progressPercent.setVisibility(indeterminate ? View.GONE : View.VISIBLE); - - progressMessage.setText(basicProgressAsyncTask.getDescription()); - if (!indeterminate) { - progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%"); - determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage()); - } - } - } } @Override @@ -636,14 +579,12 @@ public class DownloadActivity extends BaseDownloadActivity { public void showDialog(FragmentActivity activity, DialogFragment fragment) { - FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction(); - Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog"); - if (prev != null) { - ft.remove(prev); - } - ft.addToBackStack(null); + fragment.show(activity.getSupportFragmentManager(), "dialog"); + } - fragment.show(ft, "dialog"); + @Override + public void onDialogDismissed() { + initFreeVersionBanner(findViewById(R.id.mainLayout)); } private static class ToggleCollapseFreeVersionBanner implements View.OnClickListener { @@ -674,46 +615,57 @@ public class DownloadActivity extends BaseDownloadActivity { private final ProgressBar progressBar; private final TextView leftTextView; private final TextView rightTextView; - private final Context ctx; - private final boolean shouldShowFreeVersionBanner; private final ProgressBar downloadsLeftProgressBar; private final View buttonsLinearLayout; private final TextView freeVersionDescriptionTextView; - private OsmandApplication application; private final TextView downloadsLeftTextView; + private final View laterButton; + + private final Context ctx; + private final OsmandApplication application; + private final boolean shouldShowFreeVersionBanner; + private final View freeVersionBannerTitle; public BannerAndDownloadFreeVersion(View view, Context ctx) { this.ctx = ctx; + application = (OsmandApplication) ctx.getApplicationContext(); freeVersionBanner = view.findViewById(R.id.freeVersionBanner); downloadProgressLayout = view.findViewById(R.id.downloadProgressLayout); progressBar = (ProgressBar) view.findViewById(R.id.progressBar); leftTextView = (TextView) view.findViewById(R.id.leftTextView); rightTextView = (TextView) view.findViewById(R.id.rightTextView); - application = (OsmandApplication) ctx.getApplicationContext(); - shouldShowFreeVersionBanner = Version.isFreeVersion(application) - || application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get(); - initFreeVersionBanner(); downloadsLeftTextView = (TextView) freeVersionBanner.findViewById(R.id.downloadsLeftTextView); - downloadsLeftProgressBar = (ProgressBar) freeVersionBanner.findViewById(R.id.downloadsLeftProgressBar); + downloadsLeftProgressBar = (ProgressBar) freeVersionBanner.findViewById(R.id.downloadsLeftProgressBar); buttonsLinearLayout = freeVersionBanner.findViewById(R.id.buttonsLinearLayout); freeVersionDescriptionTextView = (TextView) freeVersionBanner .findViewById(R.id.freeVersionDescriptionTextView); + laterButton = freeVersionBanner.findViewById(R.id.laterButton); + freeVersionBannerTitle = freeVersionBanner.findViewById(R.id.freeVersionBannerTitle); + shouldShowFreeVersionBanner = Version.isFreeVersion(application) + || application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get(); + + initFreeVersionBanner(); + updateFreeVersionBanner(); } - public void updateProgress(boolean isFinished, boolean indeterminate, int percent, String message) { + public void updateProgress(int countedDownloads, + BasicProgressAsyncTask basicProgressAsyncTask) { + final boolean isFinished = basicProgressAsyncTask == null + || basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED; if (isFinished) { downloadProgressLayout.setVisibility(View.GONE); - // TODO -// freeVersionBanner.setVisibility(View.VISIBLE); + updateFreeVersionBanner(); } else { - if (freeVersionBanner.getVisibility() == View.VISIBLE) { - freeVersionBanner.setVisibility(View.GONE); - } + boolean indeterminate = basicProgressAsyncTask.isIndeterminate(); + String message = basicProgressAsyncTask.getDescription(); + int percent = basicProgressAsyncTask.getProgressPercentage(); + + setMinimizedFreeVersionBanner(true); + updateAvailableDownloads(countedDownloads); downloadProgressLayout.setVisibility(View.VISIBLE); progressBar.setIndeterminate(indeterminate); if (indeterminate) { - // TODO leftTextView.setText(message); } else { // TODO if only 1 map, show map name @@ -731,6 +683,7 @@ public class DownloadActivity extends BaseDownloadActivity { freeVersionBanner.setVisibility(View.GONE); return; } + freeVersionBanner.setVisibility(View.VISIBLE); downloadsLeftProgressBar.setMax(BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS); freeVersionDescriptionTextView.setText(ctx.getString(R.string.free_version_message, BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS)); @@ -746,21 +699,45 @@ public class DownloadActivity extends BaseDownloadActivity { } } }); - freeVersionBanner.findViewById(R.id.laterButton).setOnClickListener( + laterButton.setOnClickListener( new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, buttonsLinearLayout)); } private void updateFreeVersionBanner() { if (!shouldShowFreeVersionBanner) return; + setMinimizedFreeVersionBanner(false); OsmandSettings settings = application.getSettings(); - downloadsLeftProgressBar.setProgress(settings.NUMBER_OF_FREE_DOWNLOADS.get()); - final int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - - settings.NUMBER_OF_FREE_DOWNLOADS.get(); + final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get(); + downloadsLeftProgressBar.setProgress(mapsDownloaded); + int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS + - mapsDownloaded; + downloadsLeft = Math.max(downloadsLeft, 0); + if (downloadsLeft <= 0) { + laterButton.setVisibility(View.GONE); + } downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft)); // TODO review logic freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, buttonsLinearLayout)); } + + private void updateAvailableDownloads(int activeTasks) { + OsmandSettings settings = application.getSettings(); + final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get() + activeTasks; + downloadsLeftProgressBar.setProgress(mapsDownloaded); + } + + private void setMinimizedFreeVersionBanner(boolean minimize) { + if (minimize) { + freeVersionDescriptionTextView.setVisibility(View.GONE); + buttonsLinearLayout.setVisibility(View.GONE); + freeVersionBannerTitle.setVisibility(View.GONE); + } else { + freeVersionDescriptionTextView.setVisibility(View.VISIBLE); + buttonsLinearLayout.setVisibility(View.VISIBLE); + freeVersionBannerTitle.setVisibility(View.VISIBLE); + } + } } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java.orig b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java.orig new file mode 100644 index 0000000000..cdd9609cc0 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java.orig @@ -0,0 +1,745 @@ +package net.osmand.plus.download; + +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.ActivityNotFoundException; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.ListFragment; +import android.support.v4.view.ViewPager; +import android.view.MenuItem; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.BaseAdapter; +import android.widget.BaseExpandableListAdapter; +import android.widget.Button; +import android.widget.ExpandableListAdapter; +import android.widget.ListAdapter; +import android.widget.ProgressBar; +import android.widget.TextView; + +import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.Version; +import net.osmand.plus.activities.LocalIndexInfo; +import net.osmand.plus.activities.OsmAndListFragment; +import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; +import net.osmand.plus.activities.OsmandExpandableListFragment; +import net.osmand.plus.activities.TabActivity; +import net.osmand.plus.base.BasicProgressAsyncTask; +<<<<<<< HEAD +import net.osmand.plus.download.items.SearchDialogFragment; +======= +import net.osmand.plus.download.items.RegionDialogFragment; +>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf +import net.osmand.plus.download.items.WorldItemsFragment; +import net.osmand.plus.srtmplugin.SRTMPlugin; +import net.osmand.plus.views.controls.PagerSlidingTabStrip; + +import org.apache.commons.logging.Log; + +import java.io.File; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +public class DownloadActivity extends BaseDownloadActivity implements RegionDialogFragment.DialogDismissListener { + private List localIndexInfos = new ArrayList(); + + private String initialFilter = ""; + private boolean singleTab; + + List mTabs = new ArrayList(); + + 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"; + private List downloadTypes = new ArrayList(); + private BannerAndDownloadFreeVersion visibleBanner; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + getMyApplication().applyTheme(this); + super.onCreate(savedInstanceState); + updateDownloads(); + + setContentView(R.layout.download); + singleTab = getIntent() != null && getIntent().getBooleanExtra(SINGLE_TAB, false); + int currentTab = 0; + String tab = getIntent() == null || getIntent().getExtras() == 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()); +// String tag = currentTab == 0 ? LOCAL_TAB : +// (currentTab == 1 ? DOWNLOAD_TAB : UPDATES_TAB); +// findViewById(R.id.layout).setVisibility(View.VISIBLE); +// android.support.v4.app.FragmentManager manager = getSupportFragmentManager(); +// if (manager.findFragmentByTag(tag) == null){ +// getSupportFragmentManager().beginTransaction().add(R.id.layout, f, tag).commit(); +// } +// } else { + ViewPager viewPager = (ViewPager) findViewById(R.id.pager); + PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs); + + mTabs.add(new TabActivity.TabItem(R.string.download_tab_local, + getString(R.string.download_tab_local), LocalIndexesFragment.class)); + mTabs.add(new TabActivity.TabItem(R.string.download_tab_downloads, + getString(R.string.download_tab_downloads), DownloadIndexFragment.class)); + mTabs.add(new TabActivity.TabItem(R.string.download_tab_updates, + getString(R.string.download_tab_updates), UpdatesIndexFragment.class)); + +// mTabs.add(new TabActivity.TabItem(R.string.download_tab_local, +// getString(R.string.download_tab_local), NewLocalIndexesFragment.class)); + mTabs.add(new TabActivity.TabItem(R.string.download_tab_downloads, + getString(R.string.download_tab_downloads), WorldItemsFragment.class)); + + viewPager.setAdapter(new TabActivity.OsmandFragmentPagerAdapter(getSupportFragmentManager(), mTabs)); + mSlidingTabLayout.setViewPager(viewPager); + + viewPager.setCurrentItem(currentTab); +// } + + settings = ((OsmandApplication) getApplication()).getSettings(); + + findViewById(R.id.downloadButton).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + downloadFilesCheckFreeVersion(); + } + + }); + findViewById(R.id.wikiButton).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + downloadWikiFiles(); + } + }); + + findViewById(R.id.CancelAll).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + getEntriesToDownload().clear(); + updateDownloadButton(); + for (WeakReference ref : fragSet) { + Fragment f = ref.get(); + if (f != null) { + if (f instanceof OsmAndListFragment) { + if (f.isAdded() && ((OsmAndListFragment) f).getListAdapter() instanceof ArrayAdapter) { + ((ArrayAdapter) ((OsmAndListFragment) f).getListAdapter()).notifyDataSetChanged(); + } + } else if (f.isAdded() && f instanceof OsmandExpandableListFragment && + ((OsmandExpandableListFragment) f).getAdapter() instanceof BaseExpandableListAdapter) { + ((BaseExpandableListAdapter) ((OsmandExpandableListFragment) f).getAdapter()).notifyDataSetChanged(); + } + } + } + } + }); + + downloadTypes = createDownloadTypes(); + final Intent intent = getIntent(); + if (intent != null && intent.getExtras() != null) { + final String filter = intent.getExtras().getString(FILTER_KEY); + if (filter != null) { + initialFilter = filter; + } + + final String filterCat = intent.getExtras().getString(FILTER_CAT); + if (filterCat != null) { + DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase()); + if (type != null) { + downloadTypes.remove(type); + downloadTypes.add(0, type); + } + } + } + changeType(downloadTypes.get(0)); + } + + + public Map getIndexActivatedFileNames() { + return downloadListIndexThread != null ? downloadListIndexThread.getIndexActivatedFileNames() : null; + } + + public String getInitialFilter() { + return initialFilter; + } + + @Override + protected void onResume() { + super.onResume(); + getMyApplication().getAppCustomization().resumeActivity(DownloadActivity.class, this); + initFreeVersionBanner(findViewById(R.id.mainLayout)); + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int itemId = item.getItemId(); + switch (itemId) { + case android.R.id.home: + finish(); + return true; + + } + return false; + } + + public void setLocalIndexInfos(List list) { + this.localIndexInfos = list; + } + + public List getLocalIndexInfos() { + return localIndexInfos; + } + + public void changeType(final DownloadActivityType tp) { + //invalidateOptionsMenu(); + if (downloadListIndexThread != null && type != tp) { + type = tp; + downloadListIndexThread.runCategorization(tp); + } + } + + @Override + public void onPause() { + super.onPause(); + getMyApplication().getAppCustomization().pauseActivity(DownloadActivity.class); + } + + @Override + public void updateProgress(boolean updateOnlyProgress) { + BasicProgressAsyncTask basicProgressAsyncTask = + DownloadActivity.downloadListIndexThread.getCurrentRunningTask(); + if (visibleBanner != null) { + final int countedDownloads = DownloadActivity.downloadListIndexThread.getCountedDownloads(); + visibleBanner.updateProgress(countedDownloads, basicProgressAsyncTask); + } + if (!updateOnlyProgress) { + updateDownloadButton(); + } + } + + @Override + public void updateDownloadList(List list) { + for (WeakReference ref : fragSet) { + Fragment f = ref.get(); + if (f instanceof UpdatesIndexFragment) { + if (f.isAdded()) { + ((UpdatesIndexFragment) f).updateItemsList(list); + } + } + } + } + + @Override + public void categorizationFinished(List filtered, List cats) { + for (WeakReference ref : fragSet) { + Fragment f = ref.get(); + if (f instanceof DownloadIndexFragment) { + if (f.isAdded()) { + ((DownloadIndexFragment) f).categorizationFinished(filtered, cats); + } + } + } + } + + @Override + public void onCategorizationFinished() { + for (WeakReference ref : fragSet) { + Fragment f = ref.get(); + if (f instanceof WorldItemsFragment) { + if (f.isAdded()) { + ((WorldItemsFragment) f).onCategorizationFinished(); + } + } else if (f instanceof SearchDialogFragment) { + if (f.isAdded()) { + ((SearchDialogFragment) f).onCategorizationFinished(); + } + } + } + } + + public void downloadListUpdated() { + for (WeakReference ref : fragSet) { + Fragment f = ref.get(); + if (f instanceof DownloadIndexFragment) { + if (f.isAdded()) { + ((DownloadIndexAdapter) ((DownloadIndexFragment) f).getExpandableListAdapter()) + .notifyDataSetInvalidated(); + } + } + } + } + + @Override + public boolean startDownload(IndexItem item) { + final boolean b = super.startDownload(item); + visibleBanner.initFreeVersionBanner(); + return b; + } + + @Override + public void downloadedIndexes() { + for (WeakReference ref : fragSet) { + Fragment f = ref.get(); + if (f instanceof LocalIndexesFragment) { + if (f.isAdded()) { + ((LocalIndexesFragment) f).reloadData(); + } + } else if (f instanceof DownloadIndexFragment) { + if (f.isAdded()) { + DownloadIndexAdapter adapter = ((DownloadIndexAdapter) + ((DownloadIndexFragment) f).getExpandableListAdapter()); + if (adapter != null) { + adapter.setLoadedFiles(getIndexActivatedFileNames(), getIndexFileNames()); + + } + } + } + } + + } + + protected void downloadWikiFiles() { + if (Version.isFreeVersion(getMyApplication())) { + new InstallPaidVersionDialogFragment().show(getSupportFragmentManager(), + InstallPaidVersionDialogFragment.TAG); + } else { + Builder bld = new AlertDialog.Builder(this); + final List wi = getWikipediaItems(); + long size = 0; + for (IndexItem i : wi) { + size += i.getSize(); + } + bld.setMessage(getString(R.string.download_wikipedia_files, (size >> 20))); + bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + for (IndexItem i : wi) { + addToDownload(i); + } + updateDownloadButton(); + checkOldWikiFiles(); + } + }); + bld.setNegativeButton(R.string.shared_string_cancel, null); + if (wi.size() > 0) { + bld.show(); + } + } + } + + protected void checkOldWikiFiles() { + Map fileNames = getMyApplication().getResourceManager().getIndexFileNames(); + final Set wiki = new HashSet(); + for (String s : fileNames.keySet()) { + if (s.contains("_wiki")) { + wiki.add(s); + } + } + if (wiki.size() > 0) { + Builder bld = new AlertDialog.Builder(this); + bld.setMessage(R.string.archive_wikipedia_data); + bld.setNegativeButton(R.string.shared_string_cancel, null); + bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + for (String w : wiki) { + File fl = getMyApplication().getAppPath(w); + File nf = new File(fl.getParentFile(), IndexConstants.BACKUP_INDEX_DIR + "/" + fl.getName()); + boolean res = fl.renameTo(nf); + if (!res) { + System.err.println("Renaming from " + fl.getAbsolutePath() + " to " + nf.getAbsolutePath() + " failed"); + } + } + } + }); + bld.show(); + } + } + + + @Override + public void updateDownloadButton() { +// View view = getView(); +// if (view == null || getExpandableListView() == null){ +// return; +// } +// int x = getExpandableListView().getScrollX(); +// int y = getExpandableListView().getScrollY(); + if (getEntriesToDownload().isEmpty()) { + findViewById(R.id.DownloadLayout).setVisibility(View.GONE); + } else { + BasicProgressAsyncTask task = DownloadActivity.downloadListIndexThread.getCurrentRunningTask(); + boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask; + ((Button) findViewById(R.id.downloadButton)).setEnabled(!running); + String text; + int downloads = DownloadActivity.downloadListIndexThread.getDownloads(); + if (!running) { + text = getString(R.string.shared_string_download) + " (" + downloads + ")"; //$NON-NLS-1$ + } else { + text = getString(R.string.shared_string_downloading) + " (" + downloads + ")"; //$NON-NLS-1$ + } + findViewById(R.id.DownloadLayout).setVisibility(View.VISIBLE); + if (Version.isFreeVersion(getMyApplication())) { + int left = DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads; + boolean excessLimit = left < 0; + if (left < 0) + left = 0; + if (getDownloadType() == DownloadActivityType.NORMAL_FILE || getDownloadType() == DownloadActivityType.ROADS_FILE) { + text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")"; + } + } + ((Button) findViewById(R.id.downloadButton)).setText(text); + List wikipediaItems = getWikipediaItems(); + findViewById(R.id.wikiButton).setVisibility(wikipediaItems.size() == 0 ? View.GONE : View.VISIBLE); + } + + for (WeakReference ref : fragSet) { + Fragment f = ref.get(); + if (f != null) + if (f.isAdded()) { + if (f instanceof OsmandExpandableListFragment) { + ExpandableListAdapter ad = ((OsmandExpandableListFragment) f).getExpandableListView() + .getExpandableListAdapter(); + if (ad instanceof OsmandBaseExpandableListAdapter) { + ((OsmandBaseExpandableListAdapter) ad).notifyDataSetChanged(); + } + } else if (f instanceof ListFragment) { + ListAdapter la = ((ListFragment) f).getListAdapter(); + if (la instanceof BaseAdapter) { + ((BaseAdapter) la).notifyDataSetChanged(); + } + } + } + } +// if (scroll) { +// getExpandableListView().scrollTo(x, y); +// } + } + + + private List getWikipediaItems() { + Set wikipediaItems = new HashSet(); + Map indexed = getMyApplication().getResourceManager().getIndexFileNames(); + for (IndexItem i : getEntriesToDownload().keySet()) { + if (i.getType() == DownloadActivityType.NORMAL_FILE) { + boolean fit = true; + fit = fit && i.getFileName().contains("obf"); + fit = fit && !i.getFileName().contains("world"); + String fname = i.getBasename(); + if (fit && !indexed.containsKey(fname + ".wiki.obf")) { + wikipediaItems.add(fname); + } + } + } + for (IndexItem i : getEntriesToDownload().keySet()) { + if (i.getType() == DownloadActivityType.WIKIPEDIA_FILE) { + wikipediaItems.remove(i.getBasename()); + } + } + List res = new ArrayList(); + IndexFileList list = downloadListIndexThread.getIndexFiles(); + if (list != null) { + List indexFiles = list.getIndexFiles(); + for (IndexItem i : indexFiles) { + if (i.getType() == DownloadActivityType.WIKIPEDIA_FILE && + wikipediaItems.contains(i.getBasename())) { + res.add(i); + } + } + } + return res; + } + + + public List getDownloadTypes() { + return downloadTypes; + } + + public List createDownloadTypes() { + List items = new ArrayList(); + items.add(DownloadActivityType.NORMAL_FILE); + if (!Version.isFreeVersion(getMyApplication())) { + items.add(DownloadActivityType.WIKIPEDIA_FILE); + } + items.add(DownloadActivityType.VOICE_FILE); + items.add(DownloadActivityType.ROADS_FILE); + if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) { + items.add(DownloadActivityType.HILLSHADE_FILE); + items.add(DownloadActivityType.SRTM_COUNTRY_FILE); + } + + getMyApplication().getAppCustomization().getDownloadTypes(items); + return items; + } + + public boolean isLightActionBar() { + return ((OsmandApplication) getApplication()).getSettings().isLightActionBar(); + } + + + public Map getIndexFileNames() { + return downloadListIndexThread != null ? downloadListIndexThread.getIndexFileNames() : null; + } + + public List getIndexFiles() { + return downloadListIndexThread != null ? downloadListIndexThread.getCachedIndexFiles() : null; + } + + public void showDialogToDownloadMaps(Collection maps) { + int count = 0; + int sz = 0; + String s = ""; + for (IndexItem i : DownloadActivity.downloadListIndexThread.getCachedIndexFiles()) { + for (String map : maps) { + if ((i.getFileName().equals(map + ".obf.zip") || i.getFileName().equals(map + "_" + IndexConstants.BINARY_MAP_VERSION + ".obf.zip")) + && i.getType() == DownloadActivityType.NORMAL_FILE) { + final List de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList(1)); + for (DownloadEntry d : de) { + count++; + sz += d.sizeMB; + } + if (s.length() > 0) { + s += ", "; + } + s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions()); + getEntriesToDownload().put(i, de); + } + } + } + if (count > 0) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(getString(R.string.download_additional_maps, s, sz)); + builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + downloadFilesCheckInternet(); + } + }); + builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + getEntriesToDownload().clear(); + } + }); + builder.setOnCancelListener(new DialogInterface.OnCancelListener() { + + @Override + public void onCancel(DialogInterface dialog) { + getEntriesToDownload().clear(); + } + }); + builder.show(); + + } + } + + + public void initFreeVersionBanner(View header) { + visibleBanner = new BannerAndDownloadFreeVersion(header, this); + updateProgress(true); + } + + + public void showDialog(FragmentActivity activity, DialogFragment fragment) { + fragment.show(activity.getSupportFragmentManager(), "dialog"); + } + + @Override + public void onDialogDismissed() { + initFreeVersionBanner(findViewById(R.id.mainLayout)); + } + + private static class ToggleCollapseFreeVersionBanner implements View.OnClickListener { + private final View freeVersionDescriptionTextView; + private final View buttonsLinearLayout; + + private ToggleCollapseFreeVersionBanner(View freeVersionDescriptionTextView, + View buttonsLinearLayout) { + this.freeVersionDescriptionTextView = freeVersionDescriptionTextView; + this.buttonsLinearLayout = buttonsLinearLayout; + } + + @Override + public void onClick(View v) { + if (freeVersionDescriptionTextView.getVisibility() == View.VISIBLE) { + freeVersionDescriptionTextView.setVisibility(View.GONE); + buttonsLinearLayout.setVisibility(View.GONE); + } else { + freeVersionDescriptionTextView.setVisibility(View.VISIBLE); + buttonsLinearLayout.setVisibility(View.VISIBLE); + } + } + } + + public static class BannerAndDownloadFreeVersion { + private final View freeVersionBanner; + private final View downloadProgressLayout; + private final ProgressBar progressBar; + private final TextView leftTextView; + private final TextView rightTextView; + private final ProgressBar downloadsLeftProgressBar; + private final View buttonsLinearLayout; + private final TextView freeVersionDescriptionTextView; + private final TextView downloadsLeftTextView; + private final View laterButton; + + private final Context ctx; + private final OsmandApplication application; + private final boolean shouldShowFreeVersionBanner; + private final View freeVersionBannerTitle; + + public BannerAndDownloadFreeVersion(View view, Context ctx) { + this.ctx = ctx; + application = (OsmandApplication) ctx.getApplicationContext(); + freeVersionBanner = view.findViewById(R.id.freeVersionBanner); + downloadProgressLayout = view.findViewById(R.id.downloadProgressLayout); + progressBar = (ProgressBar) view.findViewById(R.id.progressBar); + leftTextView = (TextView) view.findViewById(R.id.leftTextView); + rightTextView = (TextView) view.findViewById(R.id.rightTextView); + downloadsLeftTextView = (TextView) freeVersionBanner.findViewById(R.id.downloadsLeftTextView); + downloadsLeftProgressBar = (ProgressBar) freeVersionBanner.findViewById(R.id.downloadsLeftProgressBar); + buttonsLinearLayout = freeVersionBanner.findViewById(R.id.buttonsLinearLayout); + freeVersionDescriptionTextView = (TextView) freeVersionBanner + .findViewById(R.id.freeVersionDescriptionTextView); + laterButton = freeVersionBanner.findViewById(R.id.laterButton); + freeVersionBannerTitle = freeVersionBanner.findViewById(R.id.freeVersionBannerTitle); + + shouldShowFreeVersionBanner = Version.isFreeVersion(application) + || application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get(); + + initFreeVersionBanner(); + updateFreeVersionBanner(); + } + + public void updateProgress(int countedDownloads, + BasicProgressAsyncTask basicProgressAsyncTask) { + final boolean isFinished = basicProgressAsyncTask == null + || basicProgressAsyncTask.getStatus() == AsyncTask.Status.FINISHED; + if (isFinished) { + downloadProgressLayout.setVisibility(View.GONE); + updateFreeVersionBanner(); + } else { + boolean indeterminate = basicProgressAsyncTask.isIndeterminate(); + String message = basicProgressAsyncTask.getDescription(); + int percent = basicProgressAsyncTask.getProgressPercentage(); + + setMinimizedFreeVersionBanner(true); + updateAvailableDownloads(countedDownloads); + downloadProgressLayout.setVisibility(View.VISIBLE); + progressBar.setIndeterminate(indeterminate); + if (indeterminate) { + leftTextView.setText(message); + } else { + // TODO if only 1 map, show map name + progressBar.setProgress(percent); +// final String format = ctx.getString(R.string.downloading_number_of_files); + leftTextView.setText(message); + rightTextView.setText(percent + "%"); + } + } + + } + + private void initFreeVersionBanner() { + if (!shouldShowFreeVersionBanner) { + freeVersionBanner.setVisibility(View.GONE); + return; + } + freeVersionBanner.setVisibility(View.VISIBLE); + downloadsLeftProgressBar.setMax(BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS); + freeVersionDescriptionTextView.setText(ctx.getString(R.string.free_version_message, + BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS)); + freeVersionBanner.findViewById(R.id.getFullVersionButton).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + BaseDownloadActivity context = (BaseDownloadActivity) v.getContext(); + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(context + .getMyApplication()) + "net.osmand.plus")); + try { + context.startActivity(intent); + } catch (ActivityNotFoundException e) { + } + } + }); + laterButton.setOnClickListener( + new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, buttonsLinearLayout)); + } + + private void updateFreeVersionBanner() { + if (!shouldShowFreeVersionBanner) return; + setMinimizedFreeVersionBanner(false); + OsmandSettings settings = application.getSettings(); + final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get(); + downloadsLeftProgressBar.setProgress(mapsDownloaded); + int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS + - mapsDownloaded; + downloadsLeft = Math.max(downloadsLeft, 0); + if (downloadsLeft <= 0) { + laterButton.setVisibility(View.GONE); + } + downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft)); + // TODO review logic + freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, + buttonsLinearLayout)); + } + + private void updateAvailableDownloads(int activeTasks) { + OsmandSettings settings = application.getSettings(); + final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get() + activeTasks; + downloadsLeftProgressBar.setProgress(mapsDownloaded); + } + + private void setMinimizedFreeVersionBanner(boolean minimize) { + if (minimize) { + freeVersionDescriptionTextView.setVisibility(View.GONE); + buttonsLinearLayout.setVisibility(View.GONE); + freeVersionBannerTitle.setVisibility(View.GONE); + } else { + freeVersionDescriptionTextView.setVisibility(View.VISIBLE); + buttonsLinearLayout.setVisibility(View.VISIBLE); + freeVersionBannerTitle.setVisibility(View.VISIBLE); + } + } + } + +} diff --git a/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java index c65a752196..695e6989e9 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.download.items; +import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; @@ -14,10 +15,12 @@ import net.osmand.plus.R; import net.osmand.plus.WorldRegion; import net.osmand.plus.download.DownloadActivity; -public class RegionDialogFragment extends DialogFragment { +public class RegionDialogFragment extends DialogFragment{ public static final String TAG = "RegionDialogFragment"; private static final String REGION_ID_DLG_KEY = "world_region_dialog_key"; private String regionId; + private DialogDismissListener dialogDismissListener; + private DialogDismissListener listener; @Override public void onCreate(Bundle savedInstanceState) { @@ -62,10 +65,16 @@ public class RegionDialogFragment extends DialogFragment { toolbar.setTitle(region.getName()); } } - getDownloadActivity().initFreeVersionBanner(view); + ((DownloadActivity) getActivity()).initFreeVersionBanner(view); + listener = new DialogDismissListener() { + @Override + public void onDialogDismissed() { + ((DownloadActivity) getActivity()).initFreeVersionBanner(view); + } + }; return view; } - + @Override public void onSaveInstanceState(Bundle outState) { outState.putString(REGION_ID_DLG_KEY, regionId); @@ -81,7 +90,9 @@ public class RegionDialogFragment extends DialogFragment { } public void onRegionSelected(String regionId) { - getDownloadActivity().showDialog(getActivity(), createInstance(regionId)); + final RegionDialogFragment regionDialogFragment = createInstance(regionId); + regionDialogFragment.setOnDismissListener(listener); + ((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment); } public static RegionDialogFragment createInstance(String regionId) { @@ -91,4 +102,19 @@ public class RegionDialogFragment extends DialogFragment { fragment.setArguments(bundle); return fragment; } -} + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + if (dialogDismissListener != null) + dialogDismissListener.onDialogDismissed(); + } + + public void setOnDismissListener(DialogDismissListener listener) { + this.dialogDismissListener = listener; + } + + public interface DialogDismissListener { + void onDialogDismissed(); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java.orig b/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java.orig new file mode 100644 index 0000000000..6ae8693a22 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java.orig @@ -0,0 +1,135 @@ +package net.osmand.plus.download.items; + +<<<<<<< HEAD +======= +import android.content.DialogInterface; +>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.WorldRegion; +import net.osmand.plus.download.DownloadActivity; + +<<<<<<< HEAD +public class RegionDialogFragment extends DialogFragment { +======= +public class RegionDialogFragment extends DialogFragment{ +>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf + public static final String TAG = "RegionDialogFragment"; + private static final String REGION_ID_DLG_KEY = "world_region_dialog_key"; + private String regionId; + private DialogDismissListener dialogDismissListener; + private DialogDismissListener listener; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + boolean isLightTheme = getMyApplication() + .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); + + if (savedInstanceState != null) { + regionId = savedInstanceState.getString(REGION_ID_DLG_KEY); + } + if (regionId == null) { + regionId = getArguments().getString(REGION_ID_DLG_KEY); + } + if (regionId == null) + regionId = ""; + + Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); + toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha)); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }); + + if (regionId.length() > 0) { + Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer); + if (fragment == null) { + getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer, + RegionItemsFragment.createInstance(regionId)).commit(); + } + WorldRegion region = getMyApplication().getWorldRegion().getRegionById(regionId); + if (region != null) { + toolbar.setTitle(region.getName()); + } + } +<<<<<<< HEAD + getDownloadActivity().initFreeVersionBanner(view); +======= + ((DownloadActivity) getActivity()).initFreeVersionBanner(view); + listener = new DialogDismissListener() { + @Override + public void onDialogDismissed() { + ((DownloadActivity) getActivity()).initFreeVersionBanner(view); + } + }; +>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf + return view; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + outState.putString(REGION_ID_DLG_KEY, regionId); + super.onSaveInstanceState(outState); + } + + private OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } + + private DownloadActivity getDownloadActivity() { + return (DownloadActivity) getActivity(); + } + + public void onRegionSelected(String regionId) { +<<<<<<< HEAD + getDownloadActivity().showDialog(getActivity(), createInstance(regionId)); +======= + final RegionDialogFragment regionDialogFragment = createInstance(regionId); + regionDialogFragment.setOnDismissListener(listener); + ((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment); +>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf + } + + public static RegionDialogFragment createInstance(String regionId) { + Bundle bundle = new Bundle(); + bundle.putString(REGION_ID_DLG_KEY, regionId); + RegionDialogFragment fragment = new RegionDialogFragment(); + fragment.setArguments(bundle); + return fragment; + } + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + if (dialogDismissListener != null) + dialogDismissListener.onDialogDismissed(); + } + + public void setOnDismissListener(DialogDismissListener listener) { + this.dialogDismissListener = listener; + } + + public interface DialogDismissListener { + void onDialogDismissed(); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java index abbfe88aa0..09587ba521 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java @@ -71,8 +71,6 @@ public class WorldItemsFragment extends OsmandExpandableListFragment { onCategorizationFinished(); - getDownloadActivity().initFreeVersionBanner(view); - return view; } @@ -128,7 +126,9 @@ public class WorldItemsFragment extends OsmandExpandableListFragment { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { if (groupPosition == worldRegionsIndex) { WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition); - getDownloadActivity().showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId())); + final RegionDialogFragment regionDialogFragment = RegionDialogFragment.createInstance(region.getRegionId()); + regionDialogFragment.setOnDismissListener((DownloadActivity) getActivity()); + ((DownloadActivity)getActivity()).showDialog(getActivity(), regionDialogFragment); return true; } else if (groupPosition == voicePromptsIndex) { if (childPosition == voicePromptsItemsRecordedSubIndex) { diff --git a/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java.orig b/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java.orig new file mode 100644 index 0000000000..7637360b27 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java.orig @@ -0,0 +1,366 @@ +package net.osmand.plus.download.items; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import net.osmand.PlatformUtil; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.Version; +import net.osmand.plus.WorldRegion; +import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; +import net.osmand.plus.activities.OsmandExpandableListFragment; +import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.download.items.ItemsListBuilder.VoicePromptsType; +import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; +import net.osmand.plus.srtmplugin.SRTMPlugin; + +import org.apache.commons.logging.Log; + +import android.content.Context; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.v4.view.MenuItemCompat; +import android.util.TypedValue; +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.ExpandableListView; +import android.widget.TextView; + +public class WorldItemsFragment extends OsmandExpandableListFragment { + public static final String TAG = "WorldItemsFragment"; + private static final Log LOG = PlatformUtil.getLog(WorldItemsFragment.class); + + public static final int RELOAD_ID = 0; + public static final int SEARCH_ID = 1; + + private WorldItemsAdapter listAdapter; + + private int worldRegionsIndex = -1; + private int worldMapsIndex = -1; + private int voicePromptsIndex = -1; + + private int voicePromptsItemsRecordedSubIndex = -1; + private int voicePromptsItemsTTSSubIndex = -1; + + @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.download_index_fragment, container, false); + + ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list); + listAdapter = new WorldItemsAdapter(getActivity()); + listView.setAdapter(listAdapter); + expandAllGroups(); + setListView(listView); + + onCategorizationFinished(); + +<<<<<<< HEAD + getDownloadActivity().initFreeVersionBanner(view); + +======= +>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf + return view; + } + + @Override + public void onResume() { + super.onResume(); + + if (!listAdapter.isEmpty()) { + expandAllGroups(); + } + } + + private void expandAllGroups() { + for (int i = 0; i < listAdapter.getGroupCount(); i++) { + getExpandableListView().expandGroup(i); + } + } + + public OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } + + private void fillWorldItemsAdapter(ItemsListBuilder builder) { + if (listAdapter != null) { + listAdapter.clear(); + if (builder.getRegionMapItems().size() > 0) { + int unusedIndex = 0; + worldRegionsIndex = unusedIndex++; + listAdapter.add("World regions", builder.getRegionsFromAllItems()); + worldMapsIndex = unusedIndex++; + listAdapter.add("World maps", builder.getRegionMapItems()); + + int unusedSubIndex = 0; + List voicePromptsItems = new LinkedList<>(); + if (!builder.isVoicePromptsItemsEmpty(VoicePromptsType.RECORDED)) { + voicePromptsItems.add(builder.getVoicePromtName(VoicePromptsType.RECORDED)); + voicePromptsItemsRecordedSubIndex = unusedSubIndex++; + } + if (!builder.isVoicePromptsItemsEmpty(VoicePromptsType.TTS)) { + voicePromptsItems.add(builder.getVoicePromtName(VoicePromptsType.TTS)); + voicePromptsItemsTTSSubIndex = unusedSubIndex; + } + if (!voicePromptsItems.isEmpty()) { + voicePromptsIndex = unusedIndex; + listAdapter.add("Voice prompts", voicePromptsItems); + } + } + //listAdapter.add("Voice promts", null); + } + } + + @Override + public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { + if (groupPosition == worldRegionsIndex) { + WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition); +<<<<<<< HEAD + getDownloadActivity().showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId())); +======= + final RegionDialogFragment regionDialogFragment = RegionDialogFragment.createInstance(region.getRegionId()); + regionDialogFragment.setOnDismissListener((DownloadActivity) getActivity()); + ((DownloadActivity)getActivity()).showDialog(getActivity(), regionDialogFragment); +>>>>>>> 123c270bc595f997b400d0de3681e6ab22f427cf + return true; + } else if (groupPosition == voicePromptsIndex) { + if (childPosition == voicePromptsItemsRecordedSubIndex) { + getDownloadActivity().showDialog(getActivity(), + VoiceDialogFragment.createInstance(VoicePromptsType.RECORDED)); + } else { + getDownloadActivity().showDialog(getActivity(), + VoiceDialogFragment.createInstance(VoicePromptsType.TTS)); + } + } + return false; + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + MenuItem itemReload = menu.add(0, RELOAD_ID, 0, R.string.shared_string_refresh); + itemReload.setIcon(R.drawable.ic_action_refresh_dark); + MenuItemCompat.setShowAsAction(itemReload, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + + MenuItem itemSearch = menu.add(0, SEARCH_ID, 1, R.string.shared_string_search); + itemSearch.setIcon(R.drawable.ic_action_search_dark); + MenuItemCompat.setShowAsAction(itemSearch, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case RELOAD_ID: + // re-create the thread + DownloadActivity.downloadListIndexThread.runReloadIndexFiles(); + return true; + case SEARCH_ID: + getDownloadActivity().showDialog(getActivity(), SearchDialogFragment.createInstance("")); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private DownloadActivity getDownloadActivity() { + return (DownloadActivity) getActivity(); + } + + public void onCategorizationFinished() { + ItemsListBuilder builder = getDownloadActivity().getItemsBuilder(); + if (builder != null && builder.build()) { + fillWorldItemsAdapter(builder); + listAdapter.notifyDataSetChanged(); + expandAllGroups(); + } + } + + private class WorldItemsAdapter extends OsmandBaseExpandableListAdapter { + + private Map> data = new LinkedHashMap<>(); + private List sections = new LinkedList<>(); + private boolean srtmDisabled; + private boolean nauticalPluginDisabled; + private boolean freeVersion; + + private class SimpleViewHolder { + TextView textView; + } + + public WorldItemsAdapter(Context ctx) { + srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null; + nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null; + freeVersion = Version.isFreeVersion(getMyApplication()); + TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary}); + ta.recycle(); + } + + public void clear() { + data.clear(); + sections.clear(); + notifyDataSetChanged(); + } + + public void add(String section, List list) { + if (!sections.contains(section)) { + sections.add(section); + } + if (!data.containsKey(section)) { + data.put(section, new ArrayList<>()); + } + data.get(section).addAll(list); + } + + @Override + public Object getChild(int groupPosition, int childPosition) { + String section = sections.get(groupPosition); + return data.get(section).get(childPosition); + } + + @Override + public long getChildId(int groupPosition, int childPosition) { + return groupPosition * 10000 + childPosition; + } + + @Override + public int getChildType(int groupPosition, int childPosition) { + if (groupPosition == worldRegionsIndex || groupPosition == voicePromptsIndex) { + return 0; + } else { + return 1; + } + } + + @Override + public int getChildTypeCount() { + return 2; + } + + @Override + public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { + + final Object child = getChild(groupPosition, childPosition); + + if (groupPosition == worldRegionsIndex) { + WorldRegion item = (WorldRegion)child; + SimpleViewHolder viewHolder; + if (convertView == null) { + convertView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.simple_list_menu_item, parent, false); + viewHolder = new SimpleViewHolder(); + viewHolder.textView = (TextView) convertView.findViewById(R.id.title); + convertView.setTag(viewHolder); + } else { + viewHolder = (SimpleViewHolder) convertView.getTag(); + } + Drawable iconLeft = getMyApplication().getIconsCache() + .getContentIcon(R.drawable.ic_world_globe_dark); + viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); + viewHolder.textView.setText(item.getName()); + + } else if (groupPosition == worldMapsIndex) { + ItemsListBuilder.ResourceItem item = (ItemsListBuilder.ResourceItem) child; + ItemViewHolder viewHolder; + if (convertView == null) { + convertView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.two_line_with_images_list_item, parent, false); + viewHolder = new ItemViewHolder(convertView); + convertView.setTag(viewHolder); + } else { + viewHolder = (ItemViewHolder) convertView.getTag(); + } + viewHolder.setSrtmDisabled(srtmDisabled); + viewHolder.setNauticalPluginDisabled(nauticalPluginDisabled); + viewHolder.setFreeVersion(freeVersion); + viewHolder.bindIndexItem(item.getIndexItem(), getDownloadActivity(), false, false); + } else if (groupPosition == voicePromptsIndex) { + String item = (String)child; + SimpleViewHolder viewHolder; + if (convertView == null) { + convertView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.simple_list_menu_item, parent, false); + viewHolder = new SimpleViewHolder(); + viewHolder.textView = (TextView) convertView.findViewById(R.id.title); + convertView.setTag(viewHolder); + } else { + viewHolder = (SimpleViewHolder) convertView.getTag(); + } + Drawable iconLeft = getMyApplication().getIconsCache() + .getContentIcon(R.drawable.ic_action_volume_up); + viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); + viewHolder.textView.setText(item); + } + + return convertView; + } + + @Override + public View getGroupView(int groupPosition, boolean isExpanded, final View convertView, + final ViewGroup parent) { + View v = convertView; + String section = getGroup(groupPosition); + if (v == null) { + LayoutInflater inflater = (LayoutInflater) getDownloadActivity() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + v = inflater.inflate(R.layout.download_item_list_section, parent, false); + } + TextView nameView = ((TextView) v.findViewById(R.id.section_name)); + nameView.setText(section); + + v.setOnClickListener(null); + + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = getActivity().getTheme(); + theme.resolveAttribute(R.attr.ctx_menu_info_view_bg, typedValue, true); + v.setBackgroundColor(typedValue.data); + + return v; + } + + @Override + public int getChildrenCount(int groupPosition) { + String section = sections.get(groupPosition); + return data.get(section).size(); + } + + @Override + public String getGroup(int groupPosition) { + return sections.get(groupPosition); + } + + @Override + public int getGroupCount() { + return sections.size(); + } + + @Override + public long getGroupId(int groupPosition) { + return groupPosition; + } + + @Override + public boolean hasStableIds() { + return false; + } + + @Override + public boolean isChildSelectable(int groupPosition, int childPosition) { + return true; + } + } +}