Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b2ab2ef3b5
11 changed files with 614 additions and 224 deletions
13
OsmAnd/res/drawable/discount_bar_bg_land.xml
Normal file
13
OsmAnd/res/drawable/discount_bar_bg_land.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item>
|
||||
<nine-patch android:src="@drawable/bg_card_shadow" />
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/discount_bar_bg" />
|
||||
<corners android:radius="@dimen/map_button_rect_rad" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
|
@ -349,56 +349,76 @@
|
|||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/custom_topbar"
|
||||
android:id="@+id/widget_top_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_top_bar_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/dashboard_map_toolbar"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/widget_top_bar_back_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_gravity="top"
|
||||
android:contentDescription="@string/back_to_search"
|
||||
android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/custom_topbar_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dashboard_map_toolbar"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/custom_back_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="54dp"
|
||||
android:layout_height="48dp"
|
||||
android:contentDescription="@string/back_to_search"
|
||||
android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha"/>
|
||||
android:id="@+id/widget_top_bar_title_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingTop="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/custom_title"
|
||||
android:layout_width="0dp"
|
||||
android:id="@+id/widget_top_bar_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:clickable="true"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:lines="1"
|
||||
android:singleLine="true"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/abc_text_size_medium_material"
|
||||
tools:text="OsmAnd+ 50% discount"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_top_bar_description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@null"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:lines="1"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textSize="@dimen/abc_text_size_medium_material"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/custom_close_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:contentDescription="@string/shared_string_close"
|
||||
android:src="@drawable/ic_action_remove_dark"/>
|
||||
android:textSize="@dimen/default_sub_text_size"
|
||||
android:visibility="gone"
|
||||
tools:text="New version of OsmAnd+ with 50% discount"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/widget_top_bar_close_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_gravity="top"
|
||||
android:contentDescription="@string/shared_string_close"
|
||||
android:src="@drawable/ic_action_remove_dark"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
@ -147,9 +147,10 @@
|
|||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/custom_topbar"
|
||||
android:id="@+id/widget_top_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
|
@ -159,46 +160,72 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/custom_topbar_layout"
|
||||
android:id="@+id/widget_top_bar_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dashboard_map_toolbar"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/dashboard_map_toolbar"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/custom_back_button"
|
||||
android:id="@+id/widget_top_bar_back_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="54dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_gravity="top"
|
||||
android:contentDescription="@string/back_to_search"
|
||||
android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/custom_title"
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_top_bar_title_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:clickable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:lines="1"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textSize="@dimen/abc_text_size_medium_material"/>
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingTop="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_top_bar_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@null"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:lines="1"
|
||||
android:singleLine="true"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/abc_text_size_medium_material"
|
||||
tools:text="OsmAnd+ 50% discount"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_top_bar_description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@null"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_sub_text_size"
|
||||
android:visibility="gone"
|
||||
tools:text="New version of OsmAnd+ with 50% discount"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/custom_close_button"
|
||||
android:id="@+id/widget_top_bar_close_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_gravity="top"
|
||||
android:contentDescription="@string/shared_string_close"
|
||||
android:src="@drawable/ic_action_remove_dark"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/custom_topbar_shadow"
|
||||
android:id="@+id/widget_top_bar_shadow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:foreground="@drawable/bg_contextmenu_shadow"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<color name="discount_bar_bg">#357ef2</color>
|
||||
|
||||
<color name="searchbar_text_dark">#fff</color>
|
||||
<color name="searchbar_text_light">#212121</color>
|
||||
<color name="searchbar_text_hint_dark">#7a8c99</color>
|
||||
|
|
|
@ -852,6 +852,10 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<Boolean> BILLING_PURCHASE_TOKEN_SENT = new BooleanPreference("billing_purchase_token_sent", false).makeGlobal();
|
||||
public final OsmandPreference<Boolean> LIVE_UPDATES_PURCHASED = new BooleanPreference("billing_live_updates_purchased", false).makeGlobal();
|
||||
|
||||
public final OsmandPreference<Integer> DISCOUNT_ID = new IntPreference("discount_id", 0).makeGlobal();
|
||||
public final OsmandPreference<Integer> DISCOUNT_SHOW_NUMBER_OF_STARTS = new IntPreference("number_of_starts_on_discount_show", 0).makeGlobal();
|
||||
public final OsmandPreference<Long> DISCOUNT_SHOW_DATETIME_MS = new LongPreference("show_discount_datetime_ms", 0).makeGlobal();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final OsmandPreference<String> USER_OSM_BUG_NAME =
|
||||
new StringPreference("user_osm_bug_name", "NoName/OsmAnd").makeGlobal();
|
||||
|
|
|
@ -75,6 +75,7 @@ import net.osmand.plus.download.DownloadActivity;
|
|||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.download.ui.DataStoragePlaceDialogFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.DiscountHelper;
|
||||
import net.osmand.plus.helpers.ExternalApiHelper;
|
||||
import net.osmand.plus.helpers.GpxImportHelper;
|
||||
import net.osmand.plus.helpers.WakeLockHelper;
|
||||
|
@ -579,6 +580,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
routingHelper.addListener(this);
|
||||
app.getMapMarkersHelper().addListener(this);
|
||||
|
||||
DiscountHelper.checkAndDisplay(this);
|
||||
|
||||
QuickSearchDialogFragment searchDialogFragment = getQuickSearchDialogFragment();
|
||||
if (searchDialogFragment != null) {
|
||||
if (searchDialogFragment.isSearchHidden()) {
|
||||
|
@ -1411,15 +1414,15 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
return mapInfoLayer.hasTopToolbar();
|
||||
}
|
||||
|
||||
public void showTopToolbar(TopToolbarController viewController) {
|
||||
public void showTopToolbar(TopToolbarController controller) {
|
||||
MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer();
|
||||
mapInfoLayer.addTopToolbarViewController(viewController);
|
||||
mapInfoLayer.addTopToolbarController(controller);
|
||||
this.topToolbarActive = mapInfoLayer.hasTopToolbar();
|
||||
}
|
||||
|
||||
public void hideTopToolbar(TopToolbarController viewController) {
|
||||
public void hideTopToolbar(TopToolbarController controller) {
|
||||
MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer();
|
||||
mapInfoLayer.removeTopToolbarViewController(viewController);
|
||||
mapInfoLayer.removeTopToolbarController(controller);
|
||||
this.topToolbarActive = mapInfoLayer.hasTopToolbar();
|
||||
}
|
||||
|
||||
|
|
200
OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java
Normal file
200
OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java
Normal file
|
@ -0,0 +1,200 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.AndroidNetworkUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class DiscountHelper {
|
||||
|
||||
private static final String TAG = "DiscountHelper";
|
||||
//private static final String DISCOUNT_JSON = "discount.json";
|
||||
|
||||
private static long mLastCheckTime;
|
||||
private static String mTitle;
|
||||
private static String mDescription;
|
||||
private static String mIcon;
|
||||
private static String mUrl;
|
||||
private static boolean mBannerVisible;
|
||||
|
||||
|
||||
public static void checkAndDisplay(final MapActivity mapActivity) {
|
||||
|
||||
if (mBannerVisible) {
|
||||
showDiscountBanner(mapActivity, mTitle, mDescription, mIcon, mUrl);
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis() - mLastCheckTime < 1000 * 60 * 60 * 24
|
||||
|| !mapActivity.getMyApplication().getSettings().isInternetConnectionAvailable()) {
|
||||
return;
|
||||
}
|
||||
mLastCheckTime = System.currentTimeMillis();
|
||||
|
||||
new AsyncTask<Void, Void, String>() {
|
||||
|
||||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
try {
|
||||
String res = AndroidNetworkUtils.sendRequest(mapActivity.getMyApplication(),
|
||||
"http://osmand.net/api/motd", null, "Requesting discount info...");
|
||||
return res;
|
||||
|
||||
} catch (Exception e) {
|
||||
logError("Requesting discount info error: ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String response) {
|
||||
if (response != null) {
|
||||
processDiscountResponse(response, mapActivity);
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
private static void processDiscountResponse(String response, MapActivity mapActivity) {
|
||||
try {
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
|
||||
JSONObject obj = new JSONObject(response);
|
||||
String message = obj.getString("message");
|
||||
String description = obj.getString("description");
|
||||
String icon = obj.getString("icon");
|
||||
String url = parseUrl(app, obj.getString("url"));
|
||||
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm");
|
||||
Date start = df.parse(obj.getString("start"));
|
||||
Date end = df.parse(obj.getString("end"));
|
||||
int showStartFrequency = obj.getInt("show_start_frequency");
|
||||
int showDayFrequency = obj.getInt("show_day_frequency");
|
||||
JSONObject application = obj.getJSONObject("application");
|
||||
|
||||
String appName = app.getPackageName();
|
||||
Date date = new Date();
|
||||
if (application.has(appName) && application.getBoolean(appName)
|
||||
&& date.after(start) && date.before(end)) {
|
||||
|
||||
OsmandSettings settings = app.getSettings();
|
||||
int discountId = getDiscountId(message, description, start, end);
|
||||
if (settings.DISCOUNT_ID.get() != discountId
|
||||
|| app.getAppInitializer().getNumberOfStarts() - settings.DISCOUNT_SHOW_NUMBER_OF_STARTS.get() >= showStartFrequency
|
||||
|| System.currentTimeMillis() - settings.DISCOUNT_SHOW_DATETIME_MS.get() > 1000L * 60 * 60 * 24 * showDayFrequency) {
|
||||
|
||||
settings.DISCOUNT_ID.set(discountId);
|
||||
settings.DISCOUNT_SHOW_NUMBER_OF_STARTS.set(app.getAppInitializer().getNumberOfStarts());
|
||||
settings.DISCOUNT_SHOW_DATETIME_MS.set(System.currentTimeMillis());
|
||||
showDiscountBanner(mapActivity, message, description, icon, url);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logError("JSON parsing error: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String parseUrl(OsmandApplication app, String url) {
|
||||
if (!Algorithms.isEmpty(url)) {
|
||||
int i = url.indexOf("osmand-market-app:");
|
||||
if (i != -1) {
|
||||
String appName = url.substring(i + 18);
|
||||
return Version.marketPrefix(app) + appName;
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
private static int getDiscountId(String message, String description, Date start, Date end) {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((start == null) ? 0 : start.hashCode());
|
||||
result = prime * result + ((end == null) ? 0 : end.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void showDiscountBanner(final MapActivity mapActivity, final String title, final String description, final String icon, final String url) {
|
||||
final DiscountBarController toolbarController = new DiscountBarController();
|
||||
toolbarController.setTitle(title);
|
||||
toolbarController.setDescription(description);
|
||||
int iconId = mapActivity.getResources().getIdentifier(icon, "drawable", mapActivity.getMyApplication().getPackageName());
|
||||
toolbarController.setBackBtnIconIds(iconId, iconId);
|
||||
if (!Algorithms.isEmpty(url)) {
|
||||
toolbarController.setOnBackButtonClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mBannerVisible = false;
|
||||
openUrl(mapActivity, url);
|
||||
}
|
||||
});
|
||||
toolbarController.setOnTitleClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mBannerVisible = false;
|
||||
openUrl(mapActivity, url);
|
||||
}
|
||||
});
|
||||
}
|
||||
toolbarController.setOnCloseButtonClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mBannerVisible = false;
|
||||
mapActivity.hideTopToolbar(toolbarController);
|
||||
}
|
||||
});
|
||||
|
||||
mTitle = title;
|
||||
mDescription = description;
|
||||
mIcon = icon;
|
||||
mUrl = url;
|
||||
mBannerVisible = true;
|
||||
|
||||
mapActivity.showTopToolbar(toolbarController);
|
||||
}
|
||||
|
||||
private static void openUrl(MapActivity mapActivity, String url) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
mapActivity.startActivity(intent);
|
||||
}
|
||||
|
||||
private static class DiscountBarController extends TopToolbarController {
|
||||
|
||||
public DiscountBarController() {
|
||||
super(TopToolbarControllerType.DISCOUNT);
|
||||
setSingleLineTitle(false);
|
||||
setBackBtnIconClrIds(0, 0);
|
||||
setCloseBtnIconClrIds(0, 0);
|
||||
setTitleTextClrIds(R.color.primary_text_dark, R.color.primary_text_dark);
|
||||
setDescrTextClrIds(R.color.primary_text_dark, R.color.primary_text_dark);
|
||||
setBgIds(R.color.discount_bar_bg, R.color.discount_bar_bg,
|
||||
R.drawable.discount_bar_bg_land, R.drawable.discount_bar_bg_land);
|
||||
}
|
||||
}
|
||||
|
||||
private static void logError(String msg) {
|
||||
Log.e(TAG, msg);
|
||||
}
|
||||
|
||||
private static void logError(String msg, Throwable e) {
|
||||
Log.e(TAG, "Error: " + msg, e);
|
||||
}
|
||||
}
|
|
@ -17,8 +17,6 @@ import net.osmand.plus.mapcontextmenu.MenuController;
|
|||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||
import net.osmand.plus.views.TransportStopsLayer;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController.TopToolbarViewControllerType;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
@ -31,23 +29,26 @@ public class TransportRouteController extends MenuController {
|
|||
final TransportStopRoute transportRoute) {
|
||||
super(new MenuBuilder(app), pointDescription, mapActivity);
|
||||
this.transportRoute = transportRoute;
|
||||
toolbarController = new TopToolbarController(TopToolbarViewControllerType.CONTEXT_MENU) {
|
||||
toolbarController = new TransportRouteToolbarController();
|
||||
toolbarController.setTitle(getNameStr());
|
||||
toolbarController.setOnBackButtonClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onBackPressed(TopToolbarView view) {
|
||||
getMapActivity().getContextMenu().backToolbarAction(TransportRouteController.this);
|
||||
public void onClick(View v) {
|
||||
mapActivity.getContextMenu().backToolbarAction(TransportRouteController.this);
|
||||
}
|
||||
|
||||
});
|
||||
toolbarController.setOnTitleClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onTitlePressed(TopToolbarView view) {
|
||||
public void onClick(View v) {
|
||||
showMenuAndRoute(getLatLon(), true);
|
||||
}
|
||||
|
||||
});
|
||||
toolbarController.setOnCloseButtonClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClosePressed(TopToolbarView view) {
|
||||
getMapActivity().getContextMenu().closeToolbar(TransportRouteController.this);
|
||||
public void onClick(View v) {
|
||||
mapActivity.getContextMenu().closeToolbar(TransportRouteController.this);
|
||||
}
|
||||
};
|
||||
toolbarController.setTitle(getNameStr());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -193,4 +194,11 @@ public class TransportRouteController extends MenuController {
|
|||
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
||||
stopsLayer.setRoute(null);
|
||||
}
|
||||
|
||||
public static class TransportRouteToolbarController extends TopToolbarController {
|
||||
|
||||
public TransportRouteToolbarController() {
|
||||
super(TopToolbarControllerType.CONTEXT_MENU);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
|||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView;
|
||||
import net.osmand.search.SearchUICore;
|
||||
import net.osmand.search.SearchUICore.SearchResultCollection;
|
||||
import net.osmand.search.core.ObjectType;
|
||||
|
@ -102,7 +101,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
private QuickSearchMainListFragment mainSearchFragment;
|
||||
private QuickSearchHistoryListFragment historySearchFragment;
|
||||
private QuickSearchCategoriesListFragment categoriesSearchFragment;
|
||||
private QuickSearchToolbarController toolbarController = new QuickSearchToolbarController();
|
||||
private QuickSearchToolbarController toolbarController;
|
||||
|
||||
private Toolbar toolbarEdit;
|
||||
private TextView titleEdit;
|
||||
|
@ -151,6 +150,26 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
final MapActivity mapActivity = getMapActivity();
|
||||
final View view = inflater.inflate(R.layout.search_dialog_fragment, container, false);
|
||||
|
||||
toolbarController = new QuickSearchToolbarController();
|
||||
toolbarController.setOnBackButtonClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false);
|
||||
}
|
||||
});
|
||||
toolbarController.setOnTitleClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false);
|
||||
}
|
||||
});
|
||||
toolbarController.setOnCloseButtonClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mapActivity.closeQuickSearch();
|
||||
}
|
||||
});
|
||||
|
||||
Bundle arguments = getArguments();
|
||||
if (savedInstanceState != null) {
|
||||
searchQuery = savedInstanceState.getString(QUICK_SEARCH_QUERY_KEY);
|
||||
|
@ -1259,22 +1278,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
public static class QuickSearchToolbarController extends TopToolbarController {
|
||||
|
||||
public QuickSearchToolbarController() {
|
||||
super(TopToolbarController.TopToolbarViewControllerType.QUICK_SEARCH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed(TopToolbarView view) {
|
||||
view.getMap().showQuickSearch(ShowQuickSearchMode.CURRENT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTitlePressed(TopToolbarView view) {
|
||||
view.getMap().showQuickSearch(ShowQuickSearchMode.CURRENT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosePressed(TopToolbarView view) {
|
||||
view.getMap().closeQuickSearch();
|
||||
super(TopToolbarControllerType.QUICK_SEARCH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,16 +101,16 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
mapInfoControls.removeSideWidgetInternal(widget);
|
||||
}
|
||||
|
||||
public void addTopToolbarViewController(TopToolbarController viewController) {
|
||||
topToolbarView.addViewController(viewController);
|
||||
public void addTopToolbarController(TopToolbarController controller) {
|
||||
topToolbarView.addController(controller);
|
||||
}
|
||||
|
||||
public void removeTopToolbarViewController(TopToolbarController viewController) {
|
||||
topToolbarView.removeViewController(viewController);
|
||||
public void removeTopToolbarController(TopToolbarController controller) {
|
||||
topToolbarView.removeController(controller);
|
||||
}
|
||||
|
||||
public boolean hasTopToolbar() {
|
||||
return topToolbarView.getTopViewController() != null;
|
||||
return topToolbarView.getTopController() != null;
|
||||
}
|
||||
|
||||
public void registerAllControls(){
|
||||
|
@ -124,7 +124,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
updateStreetName(false, calculateTextState());
|
||||
|
||||
topToolbarView = new TopToolbarView(map);
|
||||
updateTopToolbar(false, calculateTextStateSearch());
|
||||
updateTopToolbar(false);
|
||||
|
||||
alarmControl = ric.createAlarmInfoControl(app, map);
|
||||
alarmControl.setVisibility(false);
|
||||
|
@ -231,7 +231,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
updateReg(ts, reg);
|
||||
}
|
||||
updateStreetName(nightMode, ts);
|
||||
updateTopToolbar(nightMode, calculateTextStateSearch());
|
||||
updateTopToolbar(nightMode);
|
||||
lanesControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius / 2);
|
||||
rulerControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, (int) (2 * view.getDensity()));
|
||||
this.expand.setBackgroundResource(ts.expand);
|
||||
|
@ -246,10 +246,8 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
streetNameView.updateTextColor(nightMode, ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius);
|
||||
}
|
||||
|
||||
private void updateTopToolbar(boolean nightMode, TextState ts) {
|
||||
int bgColorId = nightMode ? R.color.bg_color_dark : R.color.bg_color_light;
|
||||
topToolbarView.setBackgroundResource(AndroidUiHelper.isOrientationPortrait(map) ? bgColorId : ts.boxFree);
|
||||
topToolbarView.updateTextColor(nightMode, ts.textColor);
|
||||
private void updateTopToolbar(boolean nightMode) {
|
||||
topToolbarView.updateColors(nightMode);
|
||||
}
|
||||
|
||||
private void updateReg(TextState ts, MapWidgetRegInfo reg) {
|
||||
|
@ -298,27 +296,6 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
return ts;
|
||||
}
|
||||
|
||||
private TextState calculateTextStateSearch() {
|
||||
boolean nightMode = drawSettings != null && drawSettings.isNightMode();
|
||||
TextState ts = new TextState();
|
||||
ts.night = nightMode;
|
||||
ts.textColor = nightMode ? ContextCompat.getColor(view.getContext(), R.color.widgettext_night) : Color.BLACK;
|
||||
if (nightMode) {
|
||||
ts.boxTop = R.drawable.btn_flat_night;
|
||||
ts.rightRes = R.drawable.btn_left_round_night;
|
||||
ts.leftRes = R.drawable.btn_right_round_night;
|
||||
ts.expand = R.drawable.btn_inset_circle_night;
|
||||
ts.boxFree = R.drawable.btn_round_night;
|
||||
} else {
|
||||
ts.boxTop = R.drawable.btn_flat;
|
||||
ts.rightRes = R.drawable.btn_left_round;
|
||||
ts.leftRes = R.drawable.btn_right_round;
|
||||
ts.expand = R.drawable.btn_inset_circle;
|
||||
ts.boxFree = R.drawable.btn_round;
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
|
||||
this.drawSettings = drawSettings;
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
|||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
@ -26,6 +27,7 @@ import net.osmand.plus.Version;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.actions.StartGPSStatus;
|
||||
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.WaypointDialogHelper;
|
||||
import net.osmand.plus.helpers.WaypointHelper;
|
||||
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
|
||||
|
@ -34,6 +36,7 @@ import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
|||
import net.osmand.plus.routing.RouteDirectionInfo;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController.TopToolbarControllerType;
|
||||
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable;
|
||||
import net.osmand.router.TurnType;
|
||||
|
||||
|
@ -41,7 +44,7 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
|
||||
public class MapInfoWidgetsFactory {
|
||||
|
||||
|
||||
public TextInfoWidget createAltitudeControl(final MapActivity map) {
|
||||
final TextInfoWidget altitudeControl = new TextInfoWidget(map) {
|
||||
private int cachedAlt = 0;
|
||||
|
@ -75,7 +78,7 @@ public class MapInfoWidgetsFactory {
|
|||
altitudeControl.setIcons(R.drawable.widget_altitude_day, R.drawable.widget_altitude_night);
|
||||
return altitudeControl;
|
||||
}
|
||||
|
||||
|
||||
public TextInfoWidget createGPSInfoControl(final MapActivity map) {
|
||||
final OsmandApplication app = map.getMyApplication();
|
||||
final OsmAndLocationProvider loc = app.getLocationProvider();
|
||||
|
@ -86,10 +89,10 @@ public class MapInfoWidgetsFactory {
|
|||
@Override
|
||||
public boolean updateInfo(DrawSettings d) {
|
||||
GPSInfo gpsInfo = loc.getGPSInfo();
|
||||
if(gpsInfo.usedSatellites != u || gpsInfo.foundSatellites != f) {
|
||||
if (gpsInfo.usedSatellites != u || gpsInfo.foundSatellites != f) {
|
||||
u = gpsInfo.usedSatellites;
|
||||
f = gpsInfo.foundSatellites;
|
||||
setText(gpsInfo.usedSatellites+"/"+gpsInfo.foundSatellites, "");
|
||||
setText(gpsInfo.usedSatellites + "/" + gpsInfo.foundSatellites, "");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -97,10 +100,10 @@ public class MapInfoWidgetsFactory {
|
|||
};
|
||||
gpsInfoControl.setIcons(R.drawable.widget_gps_info_day, R.drawable.widget_gps_info_night);
|
||||
gpsInfoControl.setText(null, null);
|
||||
gpsInfoControl.setOnClickListener(new View.OnClickListener() {
|
||||
gpsInfoControl.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (app.getNavigationService() != null){
|
||||
if (app.getNavigationService() != null) {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(map);
|
||||
dlg.setTitle(app.getString(R.string.sleep_mode_stop_dialog));
|
||||
|
||||
|
@ -109,9 +112,9 @@ public class MapInfoWidgetsFactory {
|
|||
if (soi == 0) {
|
||||
dlg.setMessage(app.getString(R.string.gps_wake_up_timer) + ": " + app.getString(R.string.int_continuosly));
|
||||
} else if (soi <= 90000) {
|
||||
dlg.setMessage(app.getString(R.string.gps_wake_up_timer) + ": " + Integer.toString(soi/1000) + " " + app.getString(R.string.int_seconds));
|
||||
dlg.setMessage(app.getString(R.string.gps_wake_up_timer) + ": " + Integer.toString(soi / 1000) + " " + app.getString(R.string.int_seconds));
|
||||
} else {
|
||||
dlg.setMessage(app.getString(R.string.gps_wake_up_timer) + ": " + Integer.toString(soi/1000/60) + " " + app.getString(R.string.int_min));
|
||||
dlg.setMessage(app.getString(R.string.gps_wake_up_timer) + ": " + Integer.toString(soi / 1000 / 60) + " " + app.getString(R.string.int_min));
|
||||
}
|
||||
|
||||
dlg.setPositiveButton(app.getString(R.string.keep_navigation_service), null);
|
||||
|
@ -123,11 +126,11 @@ public class MapInfoWidgetsFactory {
|
|||
}
|
||||
});
|
||||
dlg.show();
|
||||
|
||||
|
||||
} else {
|
||||
final ValueHolder<Integer> vs = new ValueHolder<Integer>();
|
||||
vs.value = 0;
|
||||
final AlertDialog[] dlgshow = new AlertDialog[1];
|
||||
final AlertDialog[] dlgshow = new AlertDialog[1];
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(map);
|
||||
dlg.setTitle(app.getString(R.string.enable_sleep_mode));
|
||||
WindowManager mgr = (WindowManager) map.getSystemService(Context.WINDOW_SERVICE);
|
||||
|
@ -142,7 +145,7 @@ public class MapInfoWidgetsFactory {
|
|||
dlg.setNeutralButton(R.string.gps_status, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new StartGPSStatus(map).run();
|
||||
new StartGPSStatus(map).run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -163,96 +166,156 @@ public class MapInfoWidgetsFactory {
|
|||
return gpsInfoControl;
|
||||
}
|
||||
|
||||
public static abstract class TopToolbarController {
|
||||
private TopToolbarViewControllerType type;
|
||||
private int backButtonIconId = R.drawable.abc_ic_ab_back_mtrl_am_alpha;
|
||||
private int closeButtonIconId = R.drawable.ic_action_remove_dark;
|
||||
private String title = "";
|
||||
public static class TopToolbarController {
|
||||
private TopToolbarControllerType type;
|
||||
|
||||
public enum TopToolbarViewControllerType {
|
||||
int bgLightId = R.color.bg_color_light;
|
||||
int bgDarkId = R.color.bg_color_dark;
|
||||
int bgLightLandId = R.drawable.btn_round;
|
||||
int bgDarkLandId = R.drawable.btn_round_night;
|
||||
|
||||
int backBtnIconLightId = R.drawable.abc_ic_ab_back_mtrl_am_alpha;
|
||||
int backBtnIconDarkId = R.drawable.abc_ic_ab_back_mtrl_am_alpha;
|
||||
int backBtnIconClrLightId = R.color.icon_color;
|
||||
int backBtnIconClrDarkId = 0;
|
||||
|
||||
int closeBtnIconLightId = R.drawable.ic_action_remove_dark;
|
||||
int closeBtnIconDarkId = R.drawable.ic_action_remove_dark;
|
||||
int closeBtnIconClrLightId = R.color.icon_color;
|
||||
int closeBtnIconClrDarkId = 0;
|
||||
|
||||
int titleTextClrLightId = R.color.primary_text_light;
|
||||
int titleTextClrDarkId = R.color.primary_text_dark;
|
||||
int descrTextClrLightId = R.color.primary_text_light;
|
||||
int descrTextClrDarkId = R.color.primary_text_dark;
|
||||
|
||||
boolean singleLineTitle = true;
|
||||
|
||||
boolean nightMode = false;
|
||||
|
||||
String title = "";
|
||||
String description = null;
|
||||
|
||||
OnClickListener onBackButtonClickListener;
|
||||
OnClickListener onTitleClickListener;
|
||||
OnClickListener onCloseButtonClickListener;
|
||||
|
||||
public enum TopToolbarControllerType {
|
||||
QUICK_SEARCH,
|
||||
CONTEXT_MENU
|
||||
CONTEXT_MENU,
|
||||
DISCOUNT,
|
||||
}
|
||||
|
||||
public TopToolbarController(TopToolbarViewControllerType type) {
|
||||
public TopToolbarController(TopToolbarControllerType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public TopToolbarViewControllerType getType() {
|
||||
public TopToolbarControllerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getBackButtonIconId() {
|
||||
return backButtonIconId;
|
||||
public void setSingleLineTitle(boolean singleLineTitle) {
|
||||
this.singleLineTitle = singleLineTitle;
|
||||
}
|
||||
|
||||
public int getCloseButtonIconId() {
|
||||
return closeButtonIconId;
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setBgIds(int bgLightId, int bgDarkId, int bgLightLandId, int bgDarkLandId) {
|
||||
this.bgLightId = bgLightId;
|
||||
this.bgDarkId = bgDarkId;
|
||||
this.bgLightLandId = bgLightLandId;
|
||||
this.bgDarkLandId = bgDarkLandId;
|
||||
}
|
||||
|
||||
public void setBackBtnIconIds(int backBtnIconLightId, int backBtnIconDarkId) {
|
||||
this.backBtnIconLightId = backBtnIconLightId;
|
||||
this.backBtnIconDarkId = backBtnIconDarkId;
|
||||
}
|
||||
|
||||
public void setBackBtnIconClrIds(int backBtnIconClrLightId, int backBtnIconClrDarkId) {
|
||||
this.backBtnIconClrLightId = backBtnIconClrLightId;
|
||||
this.backBtnIconClrDarkId = backBtnIconClrDarkId;
|
||||
}
|
||||
|
||||
public void setCloseBtnIconIds(int closeBtnIconLightId, int closeBtnIconDarkId) {
|
||||
this.closeBtnIconLightId = closeBtnIconLightId;
|
||||
this.closeBtnIconDarkId = closeBtnIconDarkId;
|
||||
}
|
||||
|
||||
public void setCloseBtnIconClrIds(int closeBtnIconClrLightId, int closeBtnIconClrDarkId) {
|
||||
this.closeBtnIconClrLightId = closeBtnIconClrLightId;
|
||||
this.closeBtnIconClrDarkId = closeBtnIconClrDarkId;
|
||||
}
|
||||
|
||||
public void setTitleTextClrIds(int titleTextClrLightId, int titleTextClrDarkId) {
|
||||
this.titleTextClrLightId = titleTextClrLightId;
|
||||
this.titleTextClrDarkId = titleTextClrDarkId;
|
||||
}
|
||||
|
||||
public void setDescrTextClrIds(int descrTextClrLightId, int descrTextClrDarkId) {
|
||||
this.descrTextClrLightId = descrTextClrLightId;
|
||||
this.descrTextClrDarkId = descrTextClrDarkId;
|
||||
}
|
||||
|
||||
public void setOnBackButtonClickListener(OnClickListener onBackButtonClickListener) {
|
||||
this.onBackButtonClickListener = onBackButtonClickListener;
|
||||
}
|
||||
|
||||
public void setOnTitleClickListener(OnClickListener onTitleClickListener) {
|
||||
this.onTitleClickListener = onTitleClickListener;
|
||||
}
|
||||
|
||||
public void setOnCloseButtonClickListener(OnClickListener onCloseButtonClickListener) {
|
||||
this.onCloseButtonClickListener = onCloseButtonClickListener;
|
||||
}
|
||||
|
||||
public void updateToolbar(TopToolbarView view) {
|
||||
view.getTitleView().setText(title);
|
||||
TextView titleView = view.getTitleView();
|
||||
TextView descrView = view.getDescrView();
|
||||
if (title != null) {
|
||||
titleView.setText(title);
|
||||
view.updateVisibility(titleView, true);
|
||||
} else {
|
||||
view.updateVisibility(titleView, false);
|
||||
}
|
||||
if (description != null) {
|
||||
descrView.setText(description);
|
||||
view.updateVisibility(descrView, true);
|
||||
} else {
|
||||
view.updateVisibility(descrView, false);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void onBackPressed(TopToolbarView view);
|
||||
|
||||
public abstract void onTitlePressed(TopToolbarView view);
|
||||
|
||||
public abstract void onClosePressed(TopToolbarView view);
|
||||
}
|
||||
|
||||
public static class TopToolbarView {
|
||||
private final MapActivity map;
|
||||
private LinkedList<TopToolbarController> viewControllers = new LinkedList<>();
|
||||
private LinkedList<TopToolbarController> controllers = new LinkedList<>();
|
||||
private TopToolbarController defaultController = new TopToolbarController(TopToolbarControllerType.CONTEXT_MENU);
|
||||
private View topbar;
|
||||
private View topBarLayout;
|
||||
private View topBarTitleLayout;
|
||||
private ImageButton backButton;
|
||||
private TextView titleView;
|
||||
private TextView descrView;
|
||||
private ImageButton closeButton;
|
||||
private boolean nightMode;
|
||||
|
||||
public TopToolbarView(final MapActivity map) {
|
||||
this.map = map;
|
||||
|
||||
topbar = map.findViewById(R.id.custom_topbar);
|
||||
topBarLayout = map.findViewById(R.id.custom_topbar_layout);
|
||||
backButton = (ImageButton) map.findViewById(R.id.custom_back_button);
|
||||
backButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TopToolbarController viewController = getTopViewController();
|
||||
if (viewController != null) {
|
||||
viewController.onBackPressed(TopToolbarView.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
titleView = (TextView) map.findViewById(R.id.custom_title);
|
||||
titleView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TopToolbarController viewController = getTopViewController();
|
||||
if (viewController != null) {
|
||||
viewController.onTitlePressed(TopToolbarView.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
closeButton = (ImageButton) map.findViewById(R.id.custom_close_button);
|
||||
closeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TopToolbarController viewController = getTopViewController();
|
||||
if (viewController != null) {
|
||||
viewController.onClosePressed(TopToolbarView.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
topbar = map.findViewById(R.id.widget_top_bar);
|
||||
topBarLayout = map.findViewById(R.id.widget_top_bar_layout);
|
||||
topBarTitleLayout = map.findViewById(R.id.widget_top_bar_title_layout);
|
||||
backButton = (ImageButton) map.findViewById(R.id.widget_top_bar_back_button);
|
||||
closeButton = (ImageButton) map.findViewById(R.id.widget_top_bar_close_button);
|
||||
titleView = (TextView) map.findViewById(R.id.widget_top_bar_title);
|
||||
descrView = (TextView) map.findViewById(R.id.widget_top_bar_description);
|
||||
updateVisibility(false);
|
||||
}
|
||||
|
||||
|
@ -276,31 +339,37 @@ public class MapInfoWidgetsFactory {
|
|||
return titleView;
|
||||
}
|
||||
|
||||
public TextView getDescrView() {
|
||||
return descrView;
|
||||
}
|
||||
|
||||
public ImageButton getCloseButton() {
|
||||
return closeButton;
|
||||
}
|
||||
|
||||
public TopToolbarController getTopViewController() {
|
||||
if (viewControllers.size() > 0) {
|
||||
return viewControllers.get(viewControllers.size() - 1);
|
||||
public TopToolbarController getTopController() {
|
||||
if (controllers.size() > 0) {
|
||||
return controllers.get(controllers.size() - 1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addViewController(TopToolbarController viewController) {
|
||||
for (Iterator ctrlIter = viewControllers.iterator(); ctrlIter.hasNext(); ) {
|
||||
TopToolbarController controller = (TopToolbarController) ctrlIter.next();
|
||||
if (controller.getType() == viewController.getType()) {
|
||||
public void addController(TopToolbarController controller) {
|
||||
for (Iterator ctrlIter = controllers.iterator(); ctrlIter.hasNext(); ) {
|
||||
TopToolbarController ctrl = (TopToolbarController) ctrlIter.next();
|
||||
if (ctrl.getType() == controller.getType()) {
|
||||
ctrlIter.remove();
|
||||
}
|
||||
}
|
||||
viewControllers.add(viewController);
|
||||
controllers.add(controller);
|
||||
updateColors();
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
public void removeViewController(TopToolbarController viewController) {
|
||||
viewControllers.remove(viewController);
|
||||
public void removeController(TopToolbarController controller) {
|
||||
controllers.remove(controller);
|
||||
updateColors();
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
|
@ -321,33 +390,86 @@ public class MapInfoWidgetsFactory {
|
|||
return false;
|
||||
}
|
||||
|
||||
private void initToolbar(TopToolbarController controller) {
|
||||
backButton.setOnClickListener(controller.onBackButtonClickListener);
|
||||
topBarTitleLayout.setOnClickListener(controller.onTitleClickListener);
|
||||
closeButton.setOnClickListener(controller.onCloseButtonClickListener);
|
||||
}
|
||||
|
||||
public void updateInfo() {
|
||||
TopToolbarController viewController = getTopViewController();
|
||||
if (viewController != null) {
|
||||
viewController.updateToolbar(this);
|
||||
}
|
||||
updateVisibility(viewController != null);
|
||||
}
|
||||
|
||||
public void updateTextColor(boolean nightMode, int textColor) {
|
||||
OsmandApplication app = map.getMyApplication();
|
||||
titleView.setTextColor(textColor);
|
||||
TopToolbarController viewController = getTopViewController();
|
||||
if (viewController != null) {
|
||||
backButton.setImageDrawable(app.getIconsCache().getIcon(viewController.getBackButtonIconId(), !nightMode));
|
||||
closeButton.setImageDrawable(app.getIconsCache().getIcon(viewController.getCloseButtonIconId(), !nightMode));
|
||||
TopToolbarController controller = getTopController();
|
||||
if (controller != null) {
|
||||
initToolbar(controller);
|
||||
controller.updateToolbar(this);
|
||||
} else {
|
||||
backButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha, !nightMode));
|
||||
closeButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark, !nightMode));
|
||||
initToolbar(defaultController);
|
||||
defaultController.updateToolbar(this);
|
||||
}
|
||||
updateVisibility(controller != null);
|
||||
}
|
||||
|
||||
public void updateColors(TopToolbarController controller) {
|
||||
OsmandApplication app = map.getMyApplication();
|
||||
controller.nightMode = nightMode;
|
||||
if (nightMode) {
|
||||
topBarLayout.setBackgroundResource(AndroidUiHelper.isOrientationPortrait(map) ? controller.bgDarkId : controller.bgDarkLandId);
|
||||
if (controller.backBtnIconDarkId == 0) {
|
||||
backButton.setImageDrawable(null);
|
||||
} else {
|
||||
backButton.setImageDrawable(app.getIconsCache().getIcon(controller.backBtnIconDarkId, controller.backBtnIconClrDarkId));
|
||||
}
|
||||
if (controller.closeBtnIconDarkId == 0) {
|
||||
closeButton.setImageDrawable(null);
|
||||
} else {
|
||||
closeButton.setImageDrawable(app.getIconsCache().getIcon(controller.closeBtnIconDarkId, controller.closeBtnIconClrDarkId));
|
||||
}
|
||||
int titleColor = map.getResources().getColor(controller.titleTextClrDarkId);
|
||||
int descrColor = map.getResources().getColor(controller.descrTextClrDarkId);
|
||||
titleView.setTextColor(titleColor);
|
||||
descrView.setTextColor(descrColor);
|
||||
} else {
|
||||
topBarLayout.setBackgroundResource(AndroidUiHelper.isOrientationPortrait(map) ? controller.bgLightId : controller.bgLightLandId);
|
||||
if (controller.backBtnIconLightId == 0) {
|
||||
backButton.setImageDrawable(null);
|
||||
} else {
|
||||
backButton.setImageDrawable(app.getIconsCache().getIcon(controller.backBtnIconLightId, controller.backBtnIconClrLightId));
|
||||
}
|
||||
if (controller.closeBtnIconLightId == 0) {
|
||||
closeButton.setImageDrawable(null);
|
||||
} else {
|
||||
closeButton.setImageDrawable(app.getIconsCache().getIcon(controller.closeBtnIconLightId, controller.closeBtnIconClrLightId));
|
||||
}
|
||||
int titleColor = map.getResources().getColor(controller.titleTextClrLightId);
|
||||
int descrColor = map.getResources().getColor(controller.descrTextClrLightId);
|
||||
titleView.setTextColor(titleColor);
|
||||
descrView.setTextColor(descrColor);
|
||||
}
|
||||
if (controller.singleLineTitle) {
|
||||
titleView.setSingleLine(true);
|
||||
} else {
|
||||
titleView.setSingleLine(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBackgroundResource(int boxTop) {
|
||||
topBarLayout.setBackgroundResource(boxTop);
|
||||
public void updateColors() {
|
||||
TopToolbarController controller = getTopController();
|
||||
if (controller != null) {
|
||||
updateColors(controller);
|
||||
} else {
|
||||
updateColors(defaultController);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateColors(boolean nightMode) {
|
||||
this.nightMode = nightMode;
|
||||
for (TopToolbarController controller : controllers) {
|
||||
controller.nightMode = nightMode;
|
||||
}
|
||||
updateColors();
|
||||
}
|
||||
}
|
||||
|
||||
public static class TopTextView {
|
||||
public static class TopTextView {
|
||||
private final RoutingHelper routingHelper;
|
||||
private final MapActivity map;
|
||||
private View topBar;
|
||||
|
@ -374,11 +496,11 @@ public class MapInfoWidgetsFactory {
|
|||
updateVisibility(false);
|
||||
turnDrawable = new NextTurnInfoWidget.TurnDrawable(map, true);
|
||||
}
|
||||
|
||||
|
||||
public boolean updateVisibility(boolean visible) {
|
||||
return updateVisibility(topBar, visible);
|
||||
}
|
||||
|
||||
|
||||
public boolean updateVisibility(View v, boolean visible) {
|
||||
if (visible != (v.getVisibility() == View.VISIBLE)) {
|
||||
if (visible) {
|
||||
|
@ -391,14 +513,14 @@ public class MapInfoWidgetsFactory {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void updateTextColor(boolean nightMode, int textColor, int textShadowColor, boolean bold, int rad) {
|
||||
this.shadowRad = rad;
|
||||
TextInfoWidget.updateTextColor(addressText, addressTextShadow, textColor, textShadowColor, bold, rad);
|
||||
TextInfoWidget.updateTextColor((TextView) waypointInfoBar.findViewById(R.id.waypoint_text),
|
||||
(TextView) waypointInfoBar.findViewById(R.id.waypoint_text_shadow),
|
||||
textColor, textShadowColor, bold, rad / 2);
|
||||
|
||||
|
||||
ImageView all = (ImageView) waypointInfoBar.findViewById(R.id.waypoint_more);
|
||||
ImageView remove = (ImageView) waypointInfoBar.findViewById(R.id.waypoint_close);
|
||||
all.setImageDrawable(map.getMyApplication().getIconsCache()
|
||||
|
@ -434,16 +556,22 @@ public class MapInfoWidgetsFactory {
|
|||
if (text == null) {
|
||||
text = "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} else if (map.getMapViewTrackingUtilities().isMapLinkedToLocation() &&
|
||||
settings.SHOW_STREET_NAME.get()) {
|
||||
RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
|
||||
RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
|
||||
if (rt != null) {
|
||||
<<<<<<< HEAD
|
||||
text = RoutingHelper.formatStreetName(rt.getName(settings.MAP_PREFERRED_LOCALE.get()),
|
||||
rt.getRef(), rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()), ">");
|
||||
}
|
||||
=======
|
||||
text = RoutingHelper.formatStreetName(rt.getName(settings.MAP_PREFERRED_LOCALE.get()),
|
||||
rt.getRef(), rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()), map.getMyApplication().getString(R.string.towards));
|
||||
}
|
||||
>>>>>>> d82263a... Added discount banner
|
||||
if (text == null) {
|
||||
text = "";
|
||||
} else {
|
||||
|
@ -462,9 +590,9 @@ public class MapInfoWidgetsFactory {
|
|||
updateVisibility(true);
|
||||
updateVisibility(waypointInfoBar, false);
|
||||
updateVisibility(addressText, true);
|
||||
updateVisibility(addressTextShadow, shadowRad > 0);
|
||||
updateVisibility(addressTextShadow, shadowRad > 0);
|
||||
boolean update = turnDrawable.setTurnType(type[0]);
|
||||
|
||||
|
||||
int h = addressText.getHeight() / 4 * 3;
|
||||
if (h != turnDrawable.getBounds().bottom) {
|
||||
turnDrawable.setBounds(0, 0, h, h);
|
||||
|
@ -480,7 +608,11 @@ public class MapInfoWidgetsFactory {
|
|||
addressText.setCompoundDrawables(null, null, null, null);
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
if (!text.equals(addressText.getText().toString()) && !text.equals("+ " + addressText.getText().toString())) {
|
||||
=======
|
||||
if (!text.equals(addressText.getText().toString())) {
|
||||
>>>>>>> d82263a... Added discount banner
|
||||
if (!text.equals("")) {
|
||||
topBar.setContentDescription(text);
|
||||
} else {
|
||||
|
@ -512,13 +644,13 @@ public class MapInfoWidgetsFactory {
|
|||
if (updated || changed) {
|
||||
ImageView all = (ImageView) waypointInfoBar.findViewById(R.id.waypoint_more);
|
||||
ImageView remove = (ImageView) waypointInfoBar.findViewById(R.id.waypoint_close);
|
||||
all.setOnClickListener(new View.OnClickListener() {
|
||||
all.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
map.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
|
||||
}
|
||||
});
|
||||
remove.setOnClickListener(new View.OnClickListener() {
|
||||
remove.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
waypointHelper.removeVisibleLocationPoint(pnt);
|
||||
|
|
Loading…
Reference in a new issue