use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class MapContextMenuFragment method updateDistanceDirection.
private void updateDistanceDirection() {
OsmandApplication app = getMyApplication();
FragmentActivity activity = getActivity();
if (app != null && activity != null && view != null) {
TextView distanceText = (TextView) view.findViewById(R.id.distance);
ImageView direction = (ImageView) view.findViewById(R.id.direction);
float myHeading = menu.getHeading() == null ? 0f : menu.getHeading();
int color = menu.isCachedMyLocation() ? R.color.icon_color : 0;
DashLocationFragment.updateLocationView(false, menu.getMyLocation(), myHeading, direction, color, distanceText, color, menu.getLatLon().getLatitude(), menu.getLatLon().getLongitude(), screenOrientation, app, activity);
}
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class MapContextMenu method init.
public boolean init(@NonNull LatLon latLon, @Nullable PointDescription pointDescription, @Nullable Object object, boolean update, boolean restorePrevious) {
OsmandApplication app = mapActivity.getMyApplication();
if (myLocation == null) {
updateMyLocation(app.getLocationProvider().getLastKnownLocation(), false);
}
if (!update && isVisible()) {
if (this.object == null || !this.object.equals(object)) {
hide();
} else {
return false;
}
}
setSelectedObject(object);
if (pointDescription == null) {
this.pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
} else {
this.pointDescription = pointDescription;
}
boolean needAcquireMenuController = menuController == null || appModeChanged || !update || this.object == null && object != null || this.object != null && object == null || (this.object != null && object != null && !this.object.getClass().equals(object.getClass()));
this.latLon = latLon;
this.object = object;
active = true;
appModeChanged = false;
if (needAcquireMenuController) {
if (menuController != null) {
menuController.setMapContextMenu(null);
}
if (!acquireMenuController(restorePrevious)) {
active = false;
clearSelectedObject(object);
return false;
}
} else {
menuController.update(pointDescription, object);
}
initTitle();
if (menuController != null) {
menuController.clearPlainMenuItems();
menuController.addPlainMenuItems(typeStr, this.pointDescription, this.latLon);
}
if (mapPosition != 0) {
mapActivity.getMapView().setMapPosition(0);
}
mapActivity.refreshMap();
if (object instanceof MapMarker) {
app.getMapMarkersHelper().addListener(this);
} else if (object instanceof TargetPoint) {
app.getTargetPointsHelper().addPointListener(this);
}
return true;
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class WikipediaDialogFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OsmandApplication app = getMyApplication();
darkMode = app.getDaynightHelper().isNightMode() || !app.getSettings().isLightContent();
int themeId = darkMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
setStyle(STYLE_NO_FRAME, themeId);
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class ColorDialogs method setupColorSpinner.
public static void setupColorSpinner(Context ctx, int selectedColor, final Spinner colorSpinner, final TIntArrayList colors) {
OnItemSelectedListener listener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
View v = parent.getChildAt(0);
if (v instanceof TextView) {
((TextView) v).setTextColor(colors.get(position));
}
colorSpinner.invalidate();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};
colors.add(pallette);
List<String> colorNames = new ArrayList<String>();
int selection = -1;
for (int i = 0; i < pallette.length; i++) {
colorNames.add(ctx.getString(paletteColors[i]));
colors.add(pallette[i]);
if (selectedColor == pallette[i]) {
selection = i;
}
}
if (selection == -1) {
colors.insert(0, selectedColor);
colorNames.add(0, ((OsmandApplication) ctx.getApplicationContext()).accessibilityEnabled() ? ctx.getString(R.string.access_default_color) : colorToString(selectedColor));
selection = 0;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ctx, android.R.layout.simple_spinner_item, colorNames) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
if (v instanceof TextView) {
((TextView) v).setTextColor(colors.get(position));
}
return v;
}
};
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
colorSpinner.setAdapter(adapter);
colorSpinner.setOnItemSelectedListener(listener);
colorSpinner.setSelection(selection);
}
use of net.osmand.plus.OsmandApplication 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);
}
}
Aggregations