Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,345 changes: 8,787 additions & 558 deletions app/src/main/artwork/map/worldmap.qgs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

import com.forrestguice.suntimeswidget.calculator.settings.display.TimeDateDisplay;
import com.forrestguice.suntimeswidget.calculator.settings.display.TimeDeltaDisplay;
import com.forrestguice.suntimeswidget.map.backgrounds.WorldMapBackgroundContract;
import com.forrestguice.suntimeswidget.map.backgrounds.WorldMapBackgroundItem;
import com.forrestguice.suntimeswidget.map.backgrounds.WorldMapBackgrounds;
import com.forrestguice.suntimeswidget.views.IconUtils;
import com.forrestguice.suntimeswidget.views.SpanUtils;
import com.forrestguice.support.app.ActivityResultLauncherCompat;
Expand Down Expand Up @@ -87,14 +90,17 @@
import com.forrestguice.suntimeswidget.views.TooltipCompat;
import com.forrestguice.suntimeswidget.views.ViewUtils;
import com.forrestguice.support.widget.ImageViewCompat;
import com.forrestguice.util.ExecutorUtils;
import com.forrestguice.util.android.AndroidResources;
import com.forrestguice.util.text.TimeDisplayText;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.Callable;

public class WorldMapDialog extends BottomSheetDialogBase
{
Expand Down Expand Up @@ -1024,6 +1030,45 @@ private void updateContextMenu(Context context, Menu m)
MenuAddon.populateSubMenu(addonSubmenuItem, addonMenuItems, getMapTime(System.currentTimeMillis()));
} //else addonSubmenuItem.setVisible(false);
}

updateBackgroundMenu(context, m);
}

protected void updateBackgroundMenu(Context context, Menu m)
{
WorldMapBackgrounds.OnWorldMapBackgroundItemClick itemListener = new WorldMapBackgrounds.OnWorldMapBackgroundItemClick()
{
@Override
public void onClick(WorldMapBackgroundItem item)
{
Uri uri = Uri.parse(item.getUri());
Boolean tint = (WorldMapBackgroundContract.TYPE_DAY.equals(item.getType()) ? item.shouldTint() : null);
onMapBackgroundResult(context, 0, item.getType(), uri, tint, item.getMapProjectionCenter());
}
};

String projectionID = worldmap.getMapMode().getProjectionID();
List<WorldMapBackgroundItem> allItems = WorldMapBackgrounds.queryWorldMapBackgroundItemsWithTimeout(context, projectionID, 1000);

MenuItem addonBackgroundsItem_day = m.findItem(R.id.mapOption_addonBackgrounds_day);
if (addonBackgroundsItem_day != null) {
List<WorldMapBackgroundItem> dayItems = WorldMapBackgrounds.values(WorldMapBackgroundContract.TYPE_DAY, allItems);
initBackgroundMenu(context, addonBackgroundsItem_day, R.id.addonBackgrounds_dayGroup, dayItems, itemListener);
}

MenuItem addonBackgroundsItem_night = m.findItem(R.id.mapOption_addonBackgrounds_night);
if (addonBackgroundsItem_night != null) {
List<WorldMapBackgroundItem> nightItems = WorldMapBackgrounds.values(WorldMapBackgroundContract.TYPE_NIGHT, allItems);
initBackgroundMenu(context, addonBackgroundsItem_night, R.id.addonBackgrounds_nightGroup, nightItems, itemListener);
}
}

protected void initBackgroundMenu(Context context, MenuItem menuItem, int groupID, List<WorldMapBackgroundItem> items, WorldMapBackgrounds.OnWorldMapBackgroundItemClick listener)
{
if (!items.isEmpty()) {
WorldMapBackgrounds.populateSubMenu(context, menuItem, groupID, mapMode.getMapTag(), mapMode.getProjectionCenter(), items, listener);
}
menuItem.setVisible(!items.isEmpty());
}

private int menuItemForMapMode(WorldMapWidgetSettings.WorldMapWidgetMode mode) {
Expand Down Expand Up @@ -1174,11 +1219,14 @@ public void onClick(DialogInterface dialog, int which) {
}
}

private void clearMapBackground(Context context)
private void clearMapBackground(Context context, boolean night) {
clearMapBackground(context, night, true);
}
private void clearMapBackground(Context context, boolean night, boolean updateViews)
{
double[] center = worldmap.getOptions().center;
String mapTag = mapMode.getMapTag();
String mapBackgroundString = WorldMapWidgetSettings.loadWorldMapBackground(context, 0, mapTag, center);
String mapBackgroundString = WorldMapWidgetSettings.loadWorldMapBackground(context, 0, mapTag, center, night);
Uri uri = mapBackgroundString != null ? Uri.parse(mapBackgroundString) : null;

if (Build.VERSION.SDK_INT >= 19)
Expand All @@ -1192,15 +1240,20 @@ private void clearMapBackground(Context context)
}
}

WorldMapWidgetSettings.deleteWorldMapBackground(context,0, mapTag, center);
WorldMapWidgetSettings.saveWorldMapPref(context, 0, WorldMapWidgetSettings.PREF_KEY_WORLDMAP_TINTMAP, mapTag, true); // reset tint flag
WorldMapWidgetSettings.deleteWorldMapBackground(context,0, mapTag, center, night);
if (!night) {
WorldMapWidgetSettings.saveWorldMapPref(context, 0, WorldMapWidgetSettings.PREF_KEY_WORLDMAP_TINTMAP, mapTag, true); // reset tint flag
}

updateOptions(context);
worldmap.setMapMode(context, mapMode);
updateViews();
if (updateViews)
{
updateOptions(context);
worldmap.setMapMode(context, mapMode);
updateViews();
}
}

protected void onMapBackgroundResult(Context context, int requestCode, Uri uri)
protected void onMapBackgroundResult(Context context, int requestCode, String type, Uri uri, Boolean applyTint, @Nullable double[] recenter)
{
Drawable background = WorldMapView.loadDrawableFromUri(context, uri.toString());
if (background == null) {
Expand All @@ -1218,8 +1271,17 @@ protected void onMapBackgroundResult(Context context, int requestCode, Uri uri)
}

double[] center = worldmap.getOptions().center; // TODO: read center/projection info from image exif data?
WorldMapWidgetSettings.saveWorldMapBackground(context, 0, mapTag, center, uri.toString());
WorldMapWidgetSettings.saveWorldMapPref(context, 0, WorldMapWidgetSettings.PREF_KEY_WORLDMAP_TINTMAP, mapTag, false); // TODO: automatically set tint flag based on image transparency?
if (recenter != null) {
center = recenter;
WorldMapWidgetSettings.saveWorldMapCenter(context, 0, mapMode.getMapTag(), center);
WorldMapWidgetSettings.saveWorldMapString(context, 0, WorldMapWidgetSettings.PREF_KEY_WORLDMAP_CENTER_LABEL, mapMode.getMapTag(), "TODO");
}

boolean isNight = (WorldMapBackgroundContract.TYPE_NIGHT.equals(type));
WorldMapWidgetSettings.saveWorldMapBackground(context, 0, mapTag, center, isNight, uri.toString());
if (applyTint != null) {
WorldMapWidgetSettings.saveWorldMapPref(context, 0, WorldMapWidgetSettings.PREF_KEY_WORLDMAP_TINTMAP, mapTag, applyTint); // TODO: automatically set tint flag based on image transparency?
}

updateOptions(context);
worldmap.setMapMode(context, mapMode);
Expand All @@ -1237,7 +1299,7 @@ protected void onMapBackgroundResult(int requestCode, int resultCode, Intent dat
final int flags = data.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION;
context.getContentResolver().takePersistableUriPermission(uri, flags);
}
onMapBackgroundResult(context, requestCode, uri);
onMapBackgroundResult(context, requestCode, WorldMapBackgroundContract.TYPE_DAY, uri, false, null);
} else {
Log.d(LOGTAG, "onActivityResult: bad result: " + resultCode + ", " + data);
}
Expand Down Expand Up @@ -1346,7 +1408,16 @@ public boolean onMenuItemClick(MenuItem item)
return true;

} else if (itemId == R.id.mapOption_background_clear) {
clearMapBackground(context);
clearMapBackground(context, true, false);
clearMapBackground(context, false, true);
return true;

} else if (itemId == R.id.mapOption_background_clear_day) {
clearMapBackground(context, false);
return true;

} else if (itemId == R.id.mapOption_background_clear_night) {
clearMapBackground(context, true);
return true;

} else if (itemId == R.id.mapOption_location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@
import com.forrestguice.suntimeswidget.map.colors.WorldMapColorValues;

/**
* Mercator map projection
* Web mercator map projection
*/
public class WorldMapMercator extends WorldMapEquirectangular
{
public static final double MAX_LATITUDE_DEG = 85.051129;
public static final double MAX_LATITUDE_RAD = Math.toRadians(MAX_LATITUDE_DEG);

private static final double PI_OVER_2 = Math.PI / 2d;
private static final double PI_OVER_4 = Math.PI / 4d;

@Override
public int[] toBitmapCoords(int w, int h, double[] mid, double lat, double lon)
{
double lat0 = Math.max(Math.min(lat, MAX_LATITUDE_DEG), -MAX_LATITUDE_DEG); // clamp (web mercator)
double x = Math.toRadians(lon - 0); // minus center_longitude
double y = Math.log(Math.tan(PI_OVER_4 + (0.5d * Math.toRadians(lat))));
double y = Math.log(Math.tan(PI_OVER_4 + (0.5d * Math.toRadians(lat0))));

int[] p = new int[2];
p[0] = (int) (mid[0] + ((x / Math.PI) * mid[0]));
Expand Down Expand Up @@ -76,6 +80,7 @@ public double[] initMatrix()
radY = Math.toRadians(-1 * (((double) j * ih0) - 180d)); // j in [0,h] to [0,360] to [-180,180] (inverted to canvas); every Y is 0.5 degrees
//radLat = 2d * Math.atan(Math.pow(Math.E, radY)) - PI_OVER_2; // Gudermannian
radLat = Math.atan(Math.sinh(radY)); // Gudermannian
radLat = Math.max(Math.min(radLat, MAX_LATITUDE_RAD), -MAX_LATITUDE_RAD); // clamp to web mercator
cosLat = Math.cos(radLat);

v[i + (size[0] * j)] = cosLon * cosLat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,48 +145,49 @@ public WorldMapWidgetSettings.WorldMapWidgetMode getMapMode()
@SuppressLint("ResourceType")
public void setMapMode(Context context, WorldMapWidgetSettings.WorldMapWidgetMode mode)
{
Drawable background = loadBackgroundDrawable(context, mode.getMapTag(), options.center);
Drawable background = loadBackgroundDrawable(context, mode.getMapTag(), options.center, false);
Drawable background_night = loadBackgroundDrawable(context, mode.getMapTag(), options.center, true);
this.mode = mode;
switch (mode)
{
case MERCATOR_SIMPLE:
options.map = (background != null) ? background : ContextCompat.getDrawable(context, R.drawable.worldmap_mercator);
options.map_night = null;
options.map_night = background_night;
options.foregroundColor = (options.tintForeground ? foregroundColor : Color.TRANSPARENT);
options.hasTransparentBaseMap = true;
break;

case VANDERGRINTEN_SIMPLE:
options.map = (background != null) ? background : ContextCompat.getDrawable(context, R.drawable.worldmap_van_der_grinten);
options.map_night = null;
options.map_night = background_night;
options.foregroundColor = (options.tintForeground ? foregroundColor : Color.TRANSPARENT);
options.hasTransparentBaseMap = true;
break;

case SINUSOIDAL_SIMPLE:
options.map = (background != null) ? background : ContextCompat.getDrawable(context, R.drawable.worldmap_sinusoidal);
options.map_night = null;
options.map_night = background_night;
options.foregroundColor = (options.tintForeground ? foregroundColor : Color.TRANSPARENT);
options.hasTransparentBaseMap = true;
break;

case EQUIAZIMUTHAL_SIMPLE:
options.map = (background != null) ? background : ContextCompat.getDrawable(context, R.drawable.worldmap2);
options.map_night = null;
options.map_night = background_night;
options.foregroundColor = (options.tintForeground ? foregroundColor : Color.TRANSPARENT);
options.hasTransparentBaseMap = true;
break;

case EQUIAZIMUTHAL_SIMPLE1:
options.map = (background != null) ? background : ContextCompat.getDrawable(context, R.drawable.worldmap3);
options.map_night = null;
options.map_night = background_night;
options.foregroundColor = (options.tintForeground ? foregroundColor : Color.TRANSPARENT);
options.hasTransparentBaseMap = true;
break;

case EQUIAZIMUTHAL_SIMPLE2:
options.map = background;
options.map_night = null;
options.map_night = background_night;
options.foregroundColor = (options.tintForeground ? foregroundColor : Color.TRANSPARENT);
options.hasTransparentBaseMap = true;
break;
Expand All @@ -201,17 +202,17 @@ public void setMapMode(Context context, WorldMapWidgetSettings.WorldMapWidgetMod
case EQUIRECTANGULAR_SIMPLE:
default:
options.map = (background != null) ? background : ContextCompat.getDrawable(context, R.drawable.worldmap);
options.map_night = null;
options.map_night = background_night;
options.foregroundColor = (options.tintForeground ? foregroundColor : Color.TRANSPARENT);
options.hasTransparentBaseMap = true;
break;
}
}

@Nullable
public static Drawable loadBackgroundDrawable(Context context, String mapTag, double[] center)
public static Drawable loadBackgroundDrawable(Context context, String mapTag, double[] center, boolean night)
{
String backgroundString = WorldMapWidgetSettings.loadWorldMapBackground(context, 0, mapTag, center);
String backgroundString = WorldMapWidgetSettings.loadWorldMapBackground(context, 0, mapTag, center, night);
Drawable drawable = loadDrawableFromUri(context, backgroundString);
if (drawable != null)
{
Expand Down
Loading
Loading