Added Christmas dialog

This commit is contained in:
Alexey Kulish 2016-10-20 13:05:13 +03:00
parent cbcad9a8bd
commit bb8ac00ca8
5 changed files with 133 additions and 28 deletions

View file

@ -323,8 +323,14 @@ public class SearchUICore {
return true; return true;
} }
public void resetPhrase() { public SearchPhrase resetPhrase() {
this.phrase = this.phrase.generateNewPhrase("", searchSettings); this.phrase = this.phrase.generateNewPhrase("", searchSettings);
return this.phrase;
}
public SearchPhrase resetPhrase(String text) {
this.phrase = this.phrase.generateNewPhrase(text, searchSettings);
return this.phrase;
} }
public SearchResultCollection search(final String text, final ResultMatcher<SearchResult> matcher) { public SearchResultCollection search(final String text, final ResultMatcher<SearchResult> matcher) {

View file

@ -706,6 +706,8 @@ public class OsmandSettings {
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_START = new BooleanPreference("should_show_dashboard_on_start", false).makeGlobal(); public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_START = new BooleanPreference("should_show_dashboard_on_start", false).makeGlobal();
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_MAP_SCREEN = new BooleanPreference("show_dashboard_on_map_screen", false).makeGlobal(); public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_MAP_SCREEN = new BooleanPreference("show_dashboard_on_map_screen", false).makeGlobal();
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> USE_INTERNET_TO_DOWNLOAD_TILES = new BooleanPreference("use_internet_to_download_tiles", true).makeGlobal().cache(); public final CommonPreference<Boolean> USE_INTERNET_TO_DOWNLOAD_TILES = new BooleanPreference("use_internet_to_download_tiles", true).makeGlobal().cache();

View file

@ -12,7 +12,6 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -26,20 +25,16 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback; import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewStub; import android.view.ViewStub;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -643,7 +638,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
.add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(), .add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(),
FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss(); FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss();
} else { } else {
//OtherDialogs.showXMasDialog(this); OtherDialogs.showXMasDialog(this);
} }
FirstUsageWelcomeFragment.SHOW = false; FirstUsageWelcomeFragment.SHOW = false;
} }
@ -1448,32 +1443,46 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
public void showQuickSearch(double latitude, double longitude) { public void showQuickSearch(double latitude, double longitude) {
mapContextMenu.hide(); hideContextMenu();
QuickSearchDialogFragment fragment = getQuickSearchDialogFragment(); QuickSearchDialogFragment fragment = getQuickSearchDialogFragment();
if (fragment != null) { if (fragment != null) {
fragment.dismiss(); fragment.dismiss();
refreshMap(); refreshMap();
} }
QuickSearchDialogFragment.showInstance(this, "", true, new LatLon(latitude, longitude)); QuickSearchDialogFragment.showInstance(this, "", null, true, new LatLon(latitude, longitude));
}
public void showQuickSearch(Object object) {
hideContextMenu();
QuickSearchDialogFragment fragment = getQuickSearchDialogFragment();
if (fragment != null) {
fragment.dismiss();
refreshMap();
}
QuickSearchDialogFragment.showInstance(this, "", object, true, null);
} }
public void showQuickSearch(ShowQuickSearchMode mode, boolean showCategories) { public void showQuickSearch(ShowQuickSearchMode mode, boolean showCategories) {
if (mapContextMenu.isVisible()) { hideContextMenu();
mapContextMenu.hide();
} else if (mapContextMenu.getMultiSelectionMenu().isVisible()) {
mapContextMenu.getMultiSelectionMenu().hide();
}
QuickSearchDialogFragment fragment = getQuickSearchDialogFragment(); QuickSearchDialogFragment fragment = getQuickSearchDialogFragment();
if (fragment != null) { if (fragment != null) {
if (mode == ShowQuickSearchMode.NEW || (mode == ShowQuickSearchMode.NEW_IF_EXPIRED && fragment.isExpired())) { if (mode == ShowQuickSearchMode.NEW || (mode == ShowQuickSearchMode.NEW_IF_EXPIRED && fragment.isExpired())) {
fragment.dismiss(); fragment.dismiss();
QuickSearchDialogFragment.showInstance(this, "", showCategories, null); QuickSearchDialogFragment.showInstance(this, "", null, showCategories, null);
} else { } else {
fragment.show(); fragment.show();
} }
refreshMap(); refreshMap();
} else { } else {
QuickSearchDialogFragment.showInstance(this, "", showCategories, null); QuickSearchDialogFragment.showInstance(this, "", null, showCategories, null);
}
}
private void hideContextMenu() {
if (mapContextMenu.isVisible()) {
mapContextMenu.hide();
} else if (mapContextMenu.getMultiSelectionMenu().isVisible()) {
mapContextMenu.getMultiSelectionMenu().hide();
} }
} }

View file

@ -6,30 +6,73 @@ import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class OtherDialogs { public class OtherDialogs {
public static void showXMasDialog(final Activity activity) { private static boolean XmasDialogWasProcessed = false;
final AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.XmasDialogTheme);
View titleView = activity.getLayoutInflater().inflate(R.layout.xmas_dialog_title, null); public static void showXMasDialog(final MapActivity mapActivity) {
if (XmasDialogWasProcessed) {
return;
}
XmasDialogWasProcessed = true;
OsmandApplication app = mapActivity.getMyApplication();
int numberOfStarts = app.getAppInitializer().getNumberOfStarts();
if (numberOfStarts > 2) {
Date now = new Date();
Date start = new Date(now.getYear(), 11, 18, 0, 0);
Date end = new Date(now.getYear(), 11, 25, 23, 59);
int firstShownX = app.getSettings().NUMBER_OF_STARTS_FIRST_XMAS_SHOWN.get();
if (now.after(start) && now.before(end)) {
if (firstShownX == 0 || numberOfStarts - firstShownX == 3 || numberOfStarts - firstShownX == 10) {
if (firstShownX == 0) {
app.getSettings().NUMBER_OF_STARTS_FIRST_XMAS_SHOWN.set(numberOfStarts);
}
} else {
return;
}
} else {
if (firstShownX != 0) {
app.getSettings().NUMBER_OF_STARTS_FIRST_XMAS_SHOWN.set(0);
}
return;
}
}
final AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity, R.style.XmasDialogTheme);
View titleView = mapActivity.getLayoutInflater().inflate(R.layout.xmas_dialog_title, null);
builder.setCustomTitle(titleView); builder.setCustomTitle(titleView);
builder.setCancelable(true); builder.setCancelable(true);
builder.setNegativeButton(activity.getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() { builder.setNegativeButton(mapActivity.getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); dialog.dismiss();
} }
}); });
builder.setPositiveButton(activity.getString(R.string.shared_string_show), new DialogInterface.OnClickListener() { builder.setPositiveButton(mapActivity.getString(R.string.shared_string_show), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
//showQuickSearch(); dialog.dismiss();
PoiCategory xmas = mapActivity.getMyApplication().getPoiTypes().getPoiCategoryByName("xmas");
if (xmas != null) {
mapActivity.showQuickSearch(xmas);
}
} }
}); });
builder.setView(activity.getLayoutInflater().inflate(R.layout.xmas_dialog, null)); builder.setView(mapActivity.getLayoutInflater().inflate(R.layout.xmas_dialog, null));
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() { dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@ -37,11 +80,11 @@ public class OtherDialogs {
public void onShow(DialogInterface dialog) { public void onShow(DialogInterface dialog) {
// Customize POSITIVE, NEGATIVE and NEUTRAL buttons. // Customize POSITIVE, NEGATIVE and NEUTRAL buttons.
Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE); Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setTextColor(activity.getResources().getColor(R.color.color_white)); positiveButton.setTextColor(mapActivity.getResources().getColor(R.color.color_white));
positiveButton.invalidate(); positiveButton.invalidate();
Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE); Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setTextColor(activity.getResources().getColor(R.color.color_white)); negativeButton.setTextColor(mapActivity.getResources().getColor(R.color.color_white));
negativeButton.invalidate(); negativeButton.invalidate();
} }
}); });

View file

@ -42,6 +42,7 @@ import net.osmand.ResultMatcher;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType; import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.PoiCategory;
import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
@ -81,6 +82,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.search.core.ObjectType.POI_TYPE; import static net.osmand.search.core.ObjectType.POI_TYPE;
import static net.osmand.search.core.SearchCoreFactory.SEARCH_AMENITY_TYPE_PRIORITY;
public class QuickSearchDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener { public class QuickSearchDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener {
@ -95,6 +97,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private static final String QUICK_SEARCH_TOOLBAR_VISIBLE_KEY = "quick_search_toolbar_visible_key"; private static final String QUICK_SEARCH_TOOLBAR_VISIBLE_KEY = "quick_search_toolbar_visible_key";
private static final String QUICK_SEARCH_FAB_VISIBLE_KEY = "quick_search_fab_visible_key"; private static final String QUICK_SEARCH_FAB_VISIBLE_KEY = "quick_search_fab_visible_key";
private static final String QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY = "quick_search_run_search_first_time_key";
private static final String QUICK_SEARCH_PHRASE_DEFINED_KEY = "quick_search_phrase_defined_key";
private Toolbar toolbar; private Toolbar toolbar;
private LockableViewPager viewPager; private LockableViewPager viewPager;
private SearchFragmentPagerAdapter pagerAdapter; private SearchFragmentPagerAdapter pagerAdapter;
@ -141,6 +146,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private long hideTimeMs; private long hideTimeMs;
private boolean poiFilterApplied; private boolean poiFilterApplied;
private boolean fabVisible; private boolean fabVisible;
private boolean runSearchFirstTime;
private boolean phraseDefined;
private static final double DISTANCE_THRESHOLD = 70000; // 70km private static final double DISTANCE_THRESHOLD = 70000; // 70km
private static final int EXPIRATION_TIME_MIN = 10; // 10 minutes private static final int EXPIRATION_TIME_MIN = 10; // 10 minutes
@ -198,6 +205,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
if (searchQuery == null && arguments != null) { if (searchQuery == null && arguments != null) {
searchQuery = arguments.getString(QUICK_SEARCH_QUERY_KEY); searchQuery = arguments.getString(QUICK_SEARCH_QUERY_KEY);
runSearchFirstTime = arguments.getBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, false);
phraseDefined = arguments.getBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, false);
double lat = arguments.getDouble(QUICK_SEARCH_LAT_KEY, Double.NaN); double lat = arguments.getDouble(QUICK_SEARCH_LAT_KEY, Double.NaN);
double lon = arguments.getDouble(QUICK_SEARCH_LON_KEY, Double.NaN); double lon = arguments.getDouble(QUICK_SEARCH_LON_KEY, Double.NaN);
if (!Double.isNaN(lat) && !Double.isNaN(lon)) { if (!Double.isNaN(lat) && !Double.isNaN(lon)) {
@ -447,6 +456,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} else { } else {
runSearch(); runSearch();
} }
} else if (runSearchFirstTime) {
runSearchFirstTime = false;
runSearch();
} }
} }
} }
@ -673,8 +685,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searchUICore = searchHelper.getCore(); searchUICore = searchHelper.getCore();
if (newSearch) { if (newSearch) {
setResultCollection(null); setResultCollection(null);
if (!phraseDefined) {
searchUICore.resetPhrase(); searchUICore.resetPhrase();
} }
phraseDefined = false;
}
location = app.getLocationProvider().getLastKnownLocation(); location = app.getLocationProvider().getLastKnownLocation();
@ -1197,8 +1212,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
} }
public static boolean showInstance(final MapActivity mapActivity, final String searchQuery, public static boolean showInstance(@NonNull MapActivity mapActivity,
boolean showCategories, final LatLon latLon) { @NonNull String searchQuery,
@Nullable Object object,
boolean showCategories,
@Nullable LatLon latLon) {
try { try {
if (mapActivity.isActivityDestroyed()) { if (mapActivity.isActivityDestroyed()) {
@ -1206,6 +1224,33 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
if (object != null) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
String objectLocalizedName = searchQuery;
if (object instanceof PoiCategory) {
PoiCategory c = (PoiCategory) object;
objectLocalizedName = c.getTranslation();
SearchUICore searchUICore = mapActivity.getMyApplication().getSearchUICore().getCore();
SearchPhrase phrase = searchUICore.resetPhrase(objectLocalizedName + " ");
SearchResult sr = new SearchResult(phrase);
sr.localeName = objectLocalizedName;
sr.object = c;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
searchUICore.selectSearchResult(sr);
bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
}
searchQuery = objectLocalizedName.trim() + " ";
} else if (!Algorithms.isEmpty(searchQuery)) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
}
bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery); bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
bundle.putBoolean(QUICK_SEARCH_SHOW_CATEGORIES_KEY, showCategories); bundle.putBoolean(QUICK_SEARCH_SHOW_CATEGORIES_KEY, showCategories);
if (latLon != null) { if (latLon != null) {