Search in sources :

Example 51 with OsmandApplication

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);
    }
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) OsmandApplication(net.osmand.plus.OsmandApplication) TextView(android.widget.TextView) ImageView(android.widget.ImageView) QuadPoint(net.osmand.data.QuadPoint)

Example 52 with OsmandApplication

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;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) PointDescription(net.osmand.data.PointDescription) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Example 53 with OsmandApplication

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);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication)

Example 54 with OsmandApplication

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);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ViewGroup(android.view.ViewGroup) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 55 with OsmandApplication

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);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) JSONObject(org.json.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint) OsmandSettings(net.osmand.plus.OsmandSettings) SuppressLint(android.annotation.SuppressLint)

Aggregations

OsmandApplication (net.osmand.plus.OsmandApplication)181 View (android.view.View)46 TextView (android.widget.TextView)39 ArrayList (java.util.ArrayList)33 AlertDialog (android.support.v7.app.AlertDialog)32 ImageView (android.widget.ImageView)31 DialogInterface (android.content.DialogInterface)27 OsmandSettings (net.osmand.plus.OsmandSettings)27 LatLon (net.osmand.data.LatLon)25 Intent (android.content.Intent)21 AdapterView (android.widget.AdapterView)19 File (java.io.File)17 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)15 Location (net.osmand.Location)13 EditText (android.widget.EditText)12 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)12 ArrayAdapter (android.widget.ArrayAdapter)11 ListView (android.widget.ListView)11 ContextMenuItem (net.osmand.plus.ContextMenuItem)11 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)11