use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class ActionBarPreferenceActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
// settings needed it's own theme because of check boxes not styled properly
OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
int t = R.style.OsmandLightTheme_NoActionbar_Preferences;
if (settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_DARK_THEME) {
t = R.style.OsmandDarkTheme_NoActionbar_Preferences;
} else if (settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME) {
t = R.style.OsmandLightTheme_NoActionbar_Preferences;
}
setTheme(t);
super.onCreate(savedInstanceState);
setContentView(R.layout.preference_activity);
tb = (Toolbar) findViewById(R.id.toolbar);
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
shadowView = findViewById(R.id.shadowView);
final ViewGroup parent = (ViewGroup) shadowView.getParent();
parent.removeView(shadowView);
shadowView = null;
}
tb.setClickable(true);
tb.setNavigationIcon(((OsmandApplication) getApplication()).getIconsCache().getIcon(R.drawable.ic_arrow_back));
tb.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
tb.setBackgroundColor(getResources().getColor(getResIdFromAttribute(this, R.attr.pstsTabBackground)));
tb.setTitleTextColor(getResources().getColor(getResIdFromAttribute(this, R.attr.pstsTextColor)));
tb.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
finish();
}
});
getSpinner().setVisibility(View.GONE);
setProgressVisibility(false);
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class FavoritesTreeFragment method showOnMap.
public void showOnMap(final FavouritePoint point) {
getMyApplication().getSettings().FAVORITES_TAB.set(FavoritesActivity.FAV_TAB);
final OsmandSettings settings = getMyApplication().getSettings();
LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), true, // $NON-NLS-1$
point);
MapActivity.launchMapActivityMoveToTop(getActivity());
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createNextInfoControl.
public NextTurnInfoWidget createNextInfoControl(final Activity activity, final OsmandApplication app, boolean horisontalMini) {
final OsmandSettings settings = app.getSettings();
final RoutingHelper routingHelper = app.getRoutingHelper();
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(activity, app, horisontalMini) {
NextDirectionInfo calc1 = new NextDirectionInfo();
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
TurnType turnType = null;
boolean deviatedFromRoute = false;
int turnImminent = 0;
int nextTurnDistance = 0;
if (routingHelper != null && routingHelper.isRouteCalculated() && followingMode) {
deviatedFromRoute = routingHelper.isDeviatedFromRoute();
if (deviatedFromRoute) {
turnImminent = 0;
turnType = TurnType.valueOf(TurnType.OFFR, settings.DRIVING_REGION.get().leftHandDriving);
setDeviatePath((int) routingHelper.getRouteDeviation());
} else {
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
turnType = r.directionInfo.getTurnType();
nextTurnDistance = r.distanceTo;
turnImminent = r.imminent;
}
}
}
setTurnType(turnType);
setTurnImminent(turnImminent, deviatedFromRoute);
setTurnDistance(nextTurnDistance);
return true;
}
};
nextTurnInfo.setOnClickListener(new View.OnClickListener() {
// int i = 0;
// boolean leftSide = false;
@Override
public void onClick(View v) {
// TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn, nextTurnInfo.turnType,nextTurnInfo.pathTransform);
if (routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) {
routingHelper.getVoiceRouter().announceCurrentDirection(null);
}
}
});
// initial state
return nextTurnInfo;
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class DiscountHelper method processDiscountResponse.
@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");
double showDayFrequency = obj.getDouble("show_day_frequency");
int maxTotalShow = obj.getInt("max_total_show");
JSONObject application = obj.getJSONObject("application");
if (url.startsWith(INAPP_PREFIX) && url.length() > INAPP_PREFIX.length()) {
String inAppSku = url.substring(INAPP_PREFIX.length());
if (InAppHelper.isPurchased(app, inAppSku)) {
return;
}
}
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);
boolean discountChanged = settings.DISCOUNT_ID.get() != discountId;
if (discountChanged) {
settings.DISCOUNT_TOTAL_SHOW.set(0);
}
if (discountChanged || app.getAppInitializer().getNumberOfStarts() - settings.DISCOUNT_SHOW_NUMBER_OF_STARTS.get() >= showStartFrequency || System.currentTimeMillis() - settings.DISCOUNT_SHOW_DATETIME_MS.get() > 1000L * 60 * 60 * 24 * showDayFrequency) {
if (settings.DISCOUNT_TOTAL_SHOW.get() < maxTotalShow) {
settings.DISCOUNT_ID.set(discountId);
settings.DISCOUNT_TOTAL_SHOW.set(settings.DISCOUNT_TOTAL_SHOW.get() + 1);
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);
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class DiscountHelper method checkAndDisplay.
public static void checkAndDisplay(final MapActivity mapActivity) {
OsmandApplication app = mapActivity.getMyApplication();
OsmandSettings settings = app.getSettings();
if (settings.DO_NOT_SHOW_STARTUP_MESSAGES.get() || !settings.INAPPS_READ.get()) {
return;
}
if (mBannerVisible) {
showDiscountBanner(mapActivity, mTitle, mDescription, mIcon, mUrl);
}
if (System.currentTimeMillis() - mLastCheckTime < 1000 * 60 * 60 * 24 || !settings.isInternetConnectionAvailable() || settings.NO_DISCOUNT_INFO.get()) {
return;
}
mLastCheckTime = System.currentTimeMillis();
final Map<String, String> pms = new LinkedHashMap<>();
pms.put("version", Version.getFullVersion(app));
pms.put("nd", app.getAppInitializer().getFirstInstalledDays() + "");
pms.put("ns", app.getAppInitializer().getNumberOfStarts() + "");
try {
pms.put("aid", Secure.getString(app.getContentResolver(), Secure.ANDROID_ID));
} catch (Exception e) {
e.printStackTrace();
}
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
String res = AndroidNetworkUtils.sendRequest(mapActivity.getMyApplication(), URL, pms, "Requesting discount info...", false, false);
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);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Aggregations