Search in sources :

Example 1 with CustomRegion

use of net.osmand.plus.download.CustomRegion in project Osmand by osmandapp.

the class CustomOsmandPlugin method writeAdditionalDataToJson.

public void writeAdditionalDataToJson(JSONObject json) throws JSONException {
    JsonUtils.writeLocalizedMapToJson("icon", json, iconNames);
    JsonUtils.writeLocalizedMapToJson("image", json, imageNames);
    JsonUtils.writeLocalizedMapToJson("name", json, names);
    JsonUtils.writeLocalizedMapToJson("description", json, descriptions);
    JSONArray regionsJson = new JSONArray();
    for (WorldRegion region : getFlatCustomRegions()) {
        if (region instanceof CustomRegion) {
            regionsJson.put(((CustomRegion) region).toJson());
        }
    }
    json.put("regionsJson", regionsJson);
}
Also used : WorldRegion(net.osmand.map.WorldRegion) JSONArray(org.json.JSONArray) CustomRegion(net.osmand.plus.download.CustomRegion)

Example 2 with CustomRegion

use of net.osmand.plus.download.CustomRegion in project Osmand by osmandapp.

the class DownloadItemFragment method reloadData.

private void reloadData() {
    DownloadActivity activity = getDownloadActivity();
    OsmandApplication app = activity.getMyApplication();
    DownloadResources indexes = activity.getDownloadThread().getIndexes();
    group = indexes.getGroupById(regionId);
    CustomIndexItem indexItem = (CustomIndexItem) group.getItemByIndex(itemIndex);
    if (indexItem != null) {
        toolbar.setTitle(indexItem.getVisibleName(app, app.getRegions()));
        DownloadDescriptionInfo descriptionInfo = indexItem.getDescriptionInfo();
        if (descriptionInfo != null) {
            updateDescription(app, descriptionInfo, description);
            updateImagesPager(app, descriptionInfo, imagesPager);
            updateActionButtons(activity, descriptionInfo, indexItem, buttonsContainer, R.layout.bottom_buttons, nightMode);
        }
    }
    WorldRegion region = group.getParentGroup().getRegion();
    if (region instanceof CustomRegion) {
        int headerColor = ((CustomRegion) region).getHeaderColor();
        if (headerColor != CustomRegion.INVALID_ID) {
            toolbar.setBackgroundColor(headerColor);
        }
    }
}
Also used : DownloadResources(net.osmand.plus.download.DownloadResources) WorldRegion(net.osmand.map.WorldRegion) OsmandApplication(net.osmand.plus.OsmandApplication) CustomIndexItem(net.osmand.plus.download.CustomIndexItem) DownloadActivity(net.osmand.plus.download.DownloadActivity) CustomRegion(net.osmand.plus.download.CustomRegion)

Example 3 with CustomRegion

use of net.osmand.plus.download.CustomRegion in project Osmand by osmandapp.

the class DownloadGroupViewHolder method getIconForGroup.

private Drawable getIconForGroup(DownloadResourceGroup group) {
    Drawable iconStart;
    OsmandApplication app = ctx.getMyApplication();
    UiUtilities cache = app.getUIUtilities();
    if (group.getType() == DownloadResourceGroupType.VOICE_REC || group.getType() == DownloadResourceGroupType.VOICE_TTS) {
        iconStart = cache.getThemedIcon(R.drawable.ic_action_volume_up);
    } else if (group.getType() == DownloadResourceGroupType.FONTS) {
        iconStart = cache.getThemedIcon(R.drawable.ic_action_map_language);
    } else {
        if (group.getRegion() instanceof CustomRegion) {
            String iconName = ((CustomRegion) group.getRegion()).getIconName(ctx);
            int iconId = AndroidUtils.getDrawableId(app, iconName);
            if (iconId != 0) {
                iconStart = getIconForDownloadedItems(group, iconId);
                return iconStart != null ? iconStart : cache.getThemedIcon(iconId);
            }
        }
        if (isParentWorld(group) || isParentWorld(group.getParentGroup())) {
            iconStart = cache.getThemedIcon(R.drawable.ic_world_globe_dark);
        } else {
            iconStart = getIconForDownloadedItems(group, R.drawable.ic_map);
            if (iconStart == null) {
                iconStart = cache.getThemedIcon(R.drawable.ic_map);
            }
        }
    }
    return iconStart;
}
Also used : UiUtilities(net.osmand.plus.utils.UiUtilities) OsmandApplication(net.osmand.plus.OsmandApplication) Drawable(android.graphics.drawable.Drawable) CustomRegion(net.osmand.plus.download.CustomRegion)

Example 4 with CustomRegion

use of net.osmand.plus.download.CustomRegion in project Osmand by osmandapp.

the class DownloadResourceGroupFragment method reloadData.

private void reloadData() {
    DownloadResources indexes = activity.getDownloadThread().getIndexes();
    group = indexes.getGroupById(groupId);
    if (!openAsDialog()) {
        updateSearchView();
    }
    updateSubscribeEmailView();
    updateDescriptionView();
    if (group != null) {
        listAdapter.update(group);
        toolbar.setTitle(group.getName(activity));
        WorldRegion region = group.getRegion();
        if (region instanceof CustomRegion) {
            int headerColor = ((CustomRegion) region).getHeaderColor();
            if (headerColor != CustomRegion.INVALID_ID) {
                toolbar.setBackgroundColor(headerColor);
            }
        }
    }
    expandAllGroups();
}
Also used : DownloadResources(net.osmand.plus.download.DownloadResources) WorldRegion(net.osmand.map.WorldRegion) SuppressLint(android.annotation.SuppressLint) CustomRegion(net.osmand.plus.download.CustomRegion)

Example 5 with CustomRegion

use of net.osmand.plus.download.CustomRegion in project Osmand by osmandapp.

the class CustomOsmandPlugin method collectRegionsFromJson.

public static List<CustomRegion> collectRegionsFromJson(@NonNull Context ctx, JSONArray jsonArray) throws JSONException {
    List<CustomRegion> customRegions = new ArrayList<>();
    Map<String, CustomRegion> flatRegions = new LinkedHashMap<>();
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject regionJson = jsonArray.getJSONObject(i);
        CustomRegion region = CustomRegion.fromJson(ctx, regionJson);
        flatRegions.put(region.getPath(), region);
    }
    for (CustomRegion region : flatRegions.values()) {
        if (!Algorithms.isEmpty(region.getParentPath())) {
            CustomRegion parentReg = flatRegions.get(region.getParentPath());
            if (parentReg != null) {
                parentReg.addSubregion(region);
            }
        } else {
            customRegions.add(region);
        }
    }
    return customRegions;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) CustomRegion(net.osmand.plus.download.CustomRegion) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

CustomRegion (net.osmand.plus.download.CustomRegion)7 WorldRegion (net.osmand.map.WorldRegion)4 OsmandApplication (net.osmand.plus.OsmandApplication)3 DownloadResources (net.osmand.plus.download.DownloadResources)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 Drawable (android.graphics.drawable.Drawable)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LockableViewPager (net.osmand.plus.LockableViewPager)1 CustomIndexItem (net.osmand.plus.download.CustomIndexItem)1 DownloadActivity (net.osmand.plus.download.DownloadActivity)1 UiUtilities (net.osmand.plus.utils.UiUtilities)1 JSONException (org.json.JSONException)1