DateTime adapter (#628)
This commit is contained in:
parent
1f0b5509ed
commit
0a8e56ea05
@ -28,6 +28,8 @@ import com.badlogic.gdx.utils.SharedLibraryLoader;
|
||||
import org.oscim.android.MapPreferences;
|
||||
import org.oscim.android.canvas.AndroidGraphics;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.DateTime;
|
||||
import org.oscim.backend.DateTimeAdapter;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.gdx.AndroidGL;
|
||||
@ -65,6 +67,7 @@ public class GdxActivity extends AndroidApplication {
|
||||
AndroidGraphics.init();
|
||||
GdxAssets.init("");
|
||||
GLAdapter.init(new AndroidGL());
|
||||
DateTimeAdapter.init(new DateTime());
|
||||
|
||||
DisplayMetrics metrics = getResources().getDisplayMetrics();
|
||||
CanvasAdapter.dpi = (int) (metrics.scaledDensity * CanvasAdapter.DEFAULT_DPI);
|
||||
|
@ -35,6 +35,8 @@ import org.oscim.android.gl.GlConfigChooser;
|
||||
import org.oscim.android.input.AndroidMotionEvent;
|
||||
import org.oscim.android.input.GestureHandler;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.DateTime;
|
||||
import org.oscim.backend.DateTimeAdapter;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.map.Map;
|
||||
@ -89,6 +91,7 @@ public class MapView extends GLSurfaceView {
|
||||
AndroidGraphics.init();
|
||||
AndroidAssets.init(context);
|
||||
GLAdapter.init(new AndroidGL());
|
||||
DateTimeAdapter.init(new DateTime());
|
||||
|
||||
DisplayMetrics metrics = getResources().getDisplayMetrics();
|
||||
CanvasAdapter.dpi = (int) (metrics.scaledDensity * CanvasAdapter.DEFAULT_DPI);
|
||||
|
@ -24,6 +24,8 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||
import com.badlogic.gdx.utils.SharedLibraryLoader;
|
||||
|
||||
import org.oscim.awt.AwtGraphics;
|
||||
import org.oscim.backend.DateTime;
|
||||
import org.oscim.backend.DateTimeAdapter;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.TileSource;
|
||||
@ -43,6 +45,7 @@ public class GdxMapApp extends GdxMap {
|
||||
AwtGraphics.init();
|
||||
GdxAssets.init("assets/");
|
||||
GLAdapter.init(new LwjglGL20());
|
||||
DateTimeAdapter.init(new DateTime());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
package org.oscim.ios.test;
|
||||
|
||||
import org.oscim.backend.DateTime;
|
||||
import org.oscim.backend.DateTimeAdapter;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.gdx.GdxAssets;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
@ -44,6 +46,7 @@ public class IOSMapApp extends GdxMap {
|
||||
IosGraphics.init();
|
||||
GdxAssets.init("assets/");
|
||||
GLAdapter.init(new IosGL());
|
||||
DateTimeAdapter.init(new DateTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
35
vtm-tests/test/org/oscim/backend/DateTimeTest.java
Normal file
35
vtm-tests/test/org/oscim/backend/DateTimeTest.java
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2019 Gustl22
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.backend;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DateTimeTest {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DateTimeTest.class);
|
||||
|
||||
@Test
|
||||
public void testDateTime() {
|
||||
DateTimeAdapter.init(new DateTime());
|
||||
log.info("Day of Year\t" + DateTimeAdapter.instance.getDayOfYear());
|
||||
log.info("Hour of Day\t" + DateTimeAdapter.instance.getHour());
|
||||
log.info("Minute of Day\t" + DateTimeAdapter.instance.getMinute());
|
||||
log.info("Second of Day\t" + DateTimeAdapter.instance.getSecond());
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
}
|
@ -20,6 +20,8 @@ import com.jtattoo.plaf.DecorationHelper;
|
||||
import com.jtattoo.plaf.hifi.HiFiLookAndFeel;
|
||||
|
||||
import org.oscim.awt.AwtGraphics;
|
||||
import org.oscim.backend.DateTime;
|
||||
import org.oscim.backend.DateTimeAdapter;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.gdx.GdxAssets;
|
||||
import org.oscim.gdx.LwjglGL20;
|
||||
@ -88,6 +90,7 @@ public class Main {
|
||||
AwtGraphics.init();
|
||||
GdxAssets.init("assets/");
|
||||
GLAdapter.init(new LwjglGL20());
|
||||
DateTimeAdapter.init(new DateTime());
|
||||
GLAdapter.GDX_DESKTOP_QUIRKS = true;
|
||||
window = new MainWindow();
|
||||
window.setSize(800, 600);
|
||||
|
@ -24,12 +24,14 @@ import com.badlogic.gdx.backends.gwt.GwtGraphics;
|
||||
|
||||
import org.oscim.backend.AssetAdapter;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.DateTimeAdapter;
|
||||
import org.oscim.backend.GL;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.gdx.GdxAssets;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.client.GwtDateTime;
|
||||
import org.oscim.gdx.client.GwtGdxGraphics;
|
||||
import org.oscim.gdx.client.MapConfig;
|
||||
import org.oscim.gdx.client.MapUrl;
|
||||
@ -71,6 +73,7 @@ class GwtMap extends GdxMap {
|
||||
|
||||
GwtGdxGraphics.init();
|
||||
GdxAssets.init("");
|
||||
DateTimeAdapter.init(new GwtDateTime());
|
||||
CanvasAdapter.textScale = 0.7f;
|
||||
CanvasAdapter.dpi = (int) (GwtGraphics.getDevicePixelRatioJSNI() * CanvasAdapter.DEFAULT_DPI);
|
||||
Tile.SIZE = Tile.calculateTileSize();
|
||||
|
@ -21,11 +21,13 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.DateTimeAdapter;
|
||||
import org.oscim.backend.GL;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.gdx.GdxAssets;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.client.GwtDateTime;
|
||||
import org.oscim.gdx.client.GwtGdxGraphics;
|
||||
import org.oscim.gdx.client.MapConfig;
|
||||
import org.oscim.gdx.client.MapUrl;
|
||||
@ -42,6 +44,7 @@ public class GwtMap extends GdxMap {
|
||||
|
||||
GwtGdxGraphics.init();
|
||||
GdxAssets.init("");
|
||||
DateTimeAdapter.init(new GwtDateTime());
|
||||
CanvasAdapter.textScale = 0.7f;
|
||||
GLAdapter.init((GL) Gdx.graphics.getGL20());
|
||||
MapRenderer.setBackgroundColor(0xffffff);
|
||||
|
51
vtm-web/src/org/oscim/gdx/client/GwtDateTime.java
Normal file
51
vtm-web/src/org/oscim/gdx/client/GwtDateTime.java
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2019 Gustl22
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.gdx.client;
|
||||
|
||||
import com.google.gwt.core.client.JsDate;
|
||||
|
||||
import org.oscim.backend.DateTimeAdapter;
|
||||
|
||||
public class GwtDateTime extends DateTimeAdapter {
|
||||
|
||||
@Override
|
||||
public int getHour() {
|
||||
return JsDate.create().getHours();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinute() {
|
||||
return JsDate.create().getMinutes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSecond() {
|
||||
return JsDate.create().getSeconds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDayOfYear() {
|
||||
JsDate year = JsDate.create();
|
||||
JsDate start = JsDate.create(year.getFullYear(), 0);
|
||||
double diff = year.getTime() - start.getTime();
|
||||
return (int) (diff / (DateTimeAdapter.MILLIS_PER_DAY)) + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeZoneOffset() {
|
||||
JsDate date = JsDate.create();
|
||||
return -date.getTimezoneOffset() * 60 * 1000;
|
||||
}
|
||||
}
|
46
vtm/src/org/oscim/backend/DateTime.java
Normal file
46
vtm/src/org/oscim/backend/DateTime.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2019 Gustl22
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.backend;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class DateTime extends DateTimeAdapter {
|
||||
|
||||
@Override
|
||||
public int getHour() {
|
||||
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinute() {
|
||||
return Calendar.getInstance().get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSecond() {
|
||||
return Calendar.getInstance().get(Calendar.SECOND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDayOfYear() {
|
||||
return Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeZoneOffset() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
return calendar.getTimeZone().getOffset(calendar.getTimeInMillis());
|
||||
}
|
||||
}
|
45
vtm/src/org/oscim/backend/DateTimeAdapter.java
Normal file
45
vtm/src/org/oscim/backend/DateTimeAdapter.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2019 Gustl22
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.backend;
|
||||
|
||||
public abstract class DateTimeAdapter {
|
||||
|
||||
public static final long MILLIS_PER_DAY = 86400000L;
|
||||
|
||||
/**
|
||||
* The instance provided by backend
|
||||
*/
|
||||
public static DateTimeAdapter instance;
|
||||
|
||||
public static void init(DateTimeAdapter adapter) {
|
||||
DateTimeAdapter.instance = adapter;
|
||||
}
|
||||
|
||||
public abstract int getHour();
|
||||
|
||||
public abstract int getMinute();
|
||||
|
||||
public abstract int getSecond();
|
||||
|
||||
/**
|
||||
* Indicates the day number within the current year. The first day of the year has value 1.
|
||||
*/
|
||||
public abstract int getDayOfYear();
|
||||
|
||||
/**
|
||||
* @return the time zone offset in milliseconds
|
||||
*/
|
||||
public abstract int getTimeZoneOffset();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user