still cleanup

This commit is contained in:
simon 2020-09-03 20:15:31 +03:00
parent 1f8dbb7694
commit 2869cae3a0
7 changed files with 69 additions and 92 deletions

View file

@ -2,8 +2,6 @@ package net.osmand.data;
import net.osmand.util.MapUtils;
import java.util.Objects;
public class RotatedTileBox {
/// primary fields

View file

@ -65,9 +65,7 @@
<meta-data android:name="com.sec.minimode.icon.landscape.normal" android:resource="@mipmap/icon" android:value="" />
<activity android:name="net.osmand.plus.activities.HelpActivity" />
<activity android:name="net.osmand.plus.activities.ExitActivity" />
<activity android:name=".activities.ServerActivity"
android:label="@string/shared_string_settings"
android:configChanges="keyboardHidden|orientation" />
<activity android:name=".activities.ServerActivity" />
<provider
android:name="androidx.core.content.FileProvider"

View file

@ -1,51 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:padding="10px">
<RelativeLayout
android:id="@+id/RelativeLayout03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20px"
android:layout_marginBottom="40px">
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:autoLink="web"
android:text="Click button to start server"></TextView>
</RelativeLayout>
<Button
android:id="@+id/Button01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/RelativeLayout03"
android:layout_alignParentLeft="true"
android:layout_marginBottom="40px"
android:text="Start"></Button>
<Button
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Button01"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:text="Stop"></Button>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10px">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:id="@+id/server_status_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/Button03"
android:fitsSystemWindows="true"
android:lines="14"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="8dp" />
android:textAlignment="center"
android:autoLink="web"
android:text="@string/click_button_to_start_server"
android:gravity="center_horizontal"/>
</RelativeLayout>
<Button
android:id="@+id/server_start_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/global_start"/>
<Button
android:id="@+id/server_stop_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/global_stop"/>
</LinearLayout>

View file

@ -11,6 +11,10 @@
Thx - Hardy
-->
<string name="global_start">Start</string>
<string name="global_stop">Stop</string>
<string name="click_button_to_start_server">Click button to start server</string>
<string name="click_button_to_stop_server">Click second button to deactivate server</string>
<string name="web_server">Web server</string>
<string name="one_point_error">Please add at least two points.</string>
<string name="shared_string_is_saved">is saved</string>

View file

@ -27,20 +27,20 @@ public class ServerActivity extends AppCompatActivity {
enableStrictMode();
super.onCreate(savedInstanceState);
setContentView(R.layout.server_activity);
findViewById(R.id.Button01).setOnClickListener(new View.OnClickListener() {
findViewById(R.id.server_start_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!initialized) {
updateTextView("Click second button to deactivate server");
updateTextView(getString(R.string.click_button_to_stop_server));
initServer();
}
}
});
findViewById(R.id.Button03).setOnClickListener(new View.OnClickListener() {
findViewById(R.id.server_stop_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (initialized) {
updateTextView("Click first button to activate server");
updateTextView(getString(R.string.click_button_to_start_server));
deInitServer();
}
}
@ -64,7 +64,7 @@ public class ServerActivity extends AppCompatActivity {
private void updateTextView(String text) {
((TextView) findViewById(R.id.TextView02)).setText(text);
((TextView) findViewById(R.id.server_status_textview)).setText(text);
}
private void initServer() {

View file

@ -6,6 +6,7 @@ import fi.iki.elonen.NanoHTTPD;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.server.endpoints.TileEndpoint;
import net.osmand.util.Algorithms;
import java.io.BufferedReader;
import java.io.IOException;
@ -45,13 +46,17 @@ public class ApiRouter {
public NanoHTTPD.Response route(NanoHTTPD.IHTTPSession session) {
Log.d("SERVER", "URI: " + session.getUri());
String uri = session.getUri();
if (uri.equals("/")) return getStatic("/go.html");
if (uri.equals("/")) {
return getStatic("/go.html");
}
if (uri.contains("/scripts/") ||
uri.contains("/images/") ||
uri.contains("/css/") ||
uri.contains("/fonts/") ||
uri.contains("/favicon.ico")
) return getStatic(uri);
) {
return getStatic(uri);
}
if (isApiUrl(uri)) {
return routeApi(session);
} else {
@ -86,6 +91,7 @@ public class ApiRouter {
private NanoHTTPD.Response routeContent(NanoHTTPD.IHTTPSession session) {
String url = session.getUri();
//add index page
//return getStatic(session.getUri());
String responseText = getHtmlPage(url);
if (responseText != null) {
return newFixedLengthResponse(responseText);
@ -126,6 +132,13 @@ public class ApiRouter {
}
private String readHTMLFromFile(String filename) {
// try {
// InputStream is = application.getAssets().open(FOLDER_NAME + filename);
// return Algorithms.readFromInputStream(is,false).toString();
// } catch (IOException e) {
// e.printStackTrace();
// }
// return null;
StringBuilder sb = new StringBuilder();
try {
InputStream is = application.getAssets().open(FOLDER_NAME + filename);

View file

@ -578,7 +578,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
}
}
public void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
private void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) {
return;
}
@ -615,7 +615,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
additional.calculateFPS(start, end);
}
public void refreshMapInternal(DrawSettings drawSettings) {
private void refreshMapInternal(DrawSettings drawSettings) {
if (view == null) {
return;
}
@ -868,20 +868,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
return currentViewport;
}
public void setCurrentRotatedTileBox(net.osmand.data.RotatedTileBox tileBox) {
float rx = (float) tileBox.getCenterPixelX() / tileBox.getPixWidth();
float ry = (float) tileBox.getCenterPixelY() / tileBox.getPixHeight();
if (mapPosition == OsmandSettings.BOTTOM_CONSTANT) {
ry -= 0.35;
}
tileBox.setCenterLocation(rx, ry);
LatLon screenCenter = tileBox.getLatLonFromPixel(tileBox.getPixWidth() / 2f, tileBox.getPixHeight() / 2f);
mapRatioX = 0;
mapRatioY = 0;
setLatLon(screenCenter.getLatitude(), screenCenter.getLongitude());
currentViewport = tileBox;
}
public float getDensity() {
return currentViewport.getDensity();
}