cleanup and refactoring

This commit is contained in:
simon 2020-09-04 16:43:54 +03:00
parent 2f1707167c
commit b846969e49
6 changed files with 130 additions and 46 deletions

View file

@ -65,7 +65,6 @@
<meta-data android:name="com.sec.minimode.icon.landscape.normal" android:resource="@mipmap/icon" android:value="" /> <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.HelpActivity" />
<activity android:name="net.osmand.plus.activities.ExitActivity" /> <activity android:name="net.osmand.plus.activities.ExitActivity" />
<activity android:name=".activities.ServerActivity" />
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"

View file

@ -3,7 +3,8 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:padding="10px"> android:padding="32dp"
android:background="@color/color_black">
<TextView <TextView
android:id="@+id/server_status_textview" android:id="@+id/server_status_textview"
@ -11,6 +12,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAlignment="center" android:textAlignment="center"
android:autoLink="web" android:autoLink="web"
android:textColor="@color/color_white"
android:text="@string/click_button_to_start_server" android:text="@string/click_button_to_start_server"
android:gravity="center_horizontal"/> android:gravity="center_horizontal"/>

View file

@ -5,7 +5,11 @@ import android.app.Activity;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.Dialog; import android.app.Dialog;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.*; import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
@ -14,10 +18,18 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.*; import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@ -32,22 +44,41 @@ import androidx.fragment.app.FragmentManager.BackStackEntry;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback; import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback;
import net.osmand.*;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.SecondSplashScreenFragment;
import net.osmand.StateChangedListener;
import net.osmand.ValueHolder;
import net.osmand.access.MapAccessibilityActions; import net.osmand.access.MapAccessibilityActions;
import net.osmand.aidl.AidlMapPointWrapper; import net.osmand.aidl.AidlMapPointWrapper;
import net.osmand.aidl.OsmandAidlApi.AMapPointUpdateListener; import net.osmand.aidl.OsmandAidlApi.AMapPointUpdateListener;
import net.osmand.core.android.AtlasMapRendererView; import net.osmand.core.android.AtlasMapRendererView;
import net.osmand.data.*; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.MapTileDownloader.DownloadRequest; import net.osmand.map.MapTileDownloader.DownloadRequest;
import net.osmand.map.MapTileDownloader.IMapDownloaderCallback; import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
import net.osmand.plus.*; import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents; import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.HuaweiDrmHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.OnDismissDialogFragmentListener;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndLocationSimulation;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.Version;
import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.base.ContextMenuFragment; import net.osmand.plus.base.ContextMenuFragment;
@ -56,14 +87,24 @@ import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.chooseplan.OsmLiveCancelledDialog; import net.osmand.plus.chooseplan.OsmLiveCancelledDialog;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.dialogs.*; import net.osmand.plus.dialogs.CrashBottomSheetDialogFragment;
import net.osmand.plus.dialogs.ImportGpxBottomSheetDialogFragment;
import net.osmand.plus.dialogs.RateUsBottomSheetDialogFragment;
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment;
import net.osmand.plus.dialogs.WhatsNewDialogFragment;
import net.osmand.plus.dialogs.XMasDialogFragment;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.ui.DataStoragePlaceDialogFragment; import net.osmand.plus.download.ui.DataStoragePlaceDialogFragment;
import net.osmand.plus.firstusage.FirstUsageWelcomeFragment; import net.osmand.plus.firstusage.FirstUsageWelcomeFragment;
import net.osmand.plus.firstusage.FirstUsageWizardFragment; import net.osmand.plus.firstusage.FirstUsageWizardFragment;
import net.osmand.plus.helpers.*; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.DiscountHelper;
import net.osmand.plus.helpers.ImportHelper;
import net.osmand.plus.helpers.IntentHelper;
import net.osmand.plus.helpers.LockHelper;
import net.osmand.plus.helpers.LockHelper.LockUIAdapter; import net.osmand.plus.helpers.LockHelper.LockUIAdapter;
import net.osmand.plus.helpers.ScrollHelper;
import net.osmand.plus.helpers.ScrollHelper.OnScrollEventListener; import net.osmand.plus.helpers.ScrollHelper.OnScrollEventListener;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment; import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
@ -77,7 +118,11 @@ import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.PlanRouteFragment; import net.osmand.plus.mapmarkers.PlanRouteFragment;
import net.osmand.plus.measurementtool.*; import net.osmand.plus.measurementtool.GpxApproximationFragment;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.measurementtool.GpxData;
import net.osmand.plus.measurementtool.SnapTrackWarningBottomSheet;
import net.osmand.plus.quickaction.QuickActionListFragment; import net.osmand.plus.quickaction.QuickActionListFragment;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
@ -91,14 +136,25 @@ import net.osmand.plus.routing.TransportRoutingHelper.TransportRouteCalculationP
import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchTab; import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchTab;
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType;
import net.osmand.plus.server.ApiRouter;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener; import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.fragments.*; import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType; import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType;
import net.osmand.plus.settings.fragments.ConfigureMenuItemsFragment;
import net.osmand.plus.settings.fragments.ConfigureProfileFragment;
import net.osmand.plus.settings.fragments.DataStorageFragment;
import net.osmand.plus.settings.fragments.ImportCompleteFragment;
import net.osmand.plus.settings.fragments.ImportSettingsFragment;
import net.osmand.plus.settings.fragments.ProfileAppearanceFragment;
import net.osmand.plus.track.TrackAppearanceFragment; import net.osmand.plus.track.TrackAppearanceFragment;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
import net.osmand.plus.views.*; import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.OsmAndMapLayersView;
import net.osmand.plus.views.OsmAndMapSurfaceView;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.OsmandMapTileView.OnDrawMapListener; import net.osmand.plus.views.OsmandMapTileView.OnDrawMapListener;
import net.osmand.plus.views.corenative.NativeCoreContext; import net.osmand.plus.views.corenative.NativeCoreContext;
import net.osmand.plus.views.layers.MapControlsLayer; import net.osmand.plus.views.layers.MapControlsLayer;
@ -109,10 +165,16 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControll
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.*; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;

View file

@ -3,8 +3,11 @@ package net.osmand.plus.development;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -13,8 +16,9 @@ import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.ContributionVersionActivity; import net.osmand.plus.activities.ContributionVersionActivity;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.ServerActivity;
import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.firstusage.FirstUsageWizardFragment;
import net.osmand.plus.server.ServerFragment;
import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.layers.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
@ -80,15 +84,22 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
.setListener(new ContextMenuAdapter.ItemClickListener() { .setListener(new ContextMenuAdapter.ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
Intent intent = new Intent(mapActivity, ServerActivity.class); Fragment fragment = new ServerFragment();
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); showFragment(mapActivity, fragment);
mapActivity.startActivity(intent);
return true; return true;
} }
}).createItem()); }).createItem());
} }
} }
private static void showFragment(FragmentActivity activity, Fragment fragment) {
if (activity != null) {
activity.getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragmentContainer, fragment, FirstUsageWizardFragment.TAG)
.commitAllowingStateLoss();
}
}
@Override @Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) { public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
if (isActive()) { if (isActive()) {

View file

@ -1,33 +1,40 @@
package net.osmand.plus.activities; package net.osmand.plus.server;
import android.net.TrafficStats; import android.net.TrafficStats;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode; import android.os.StrictMode;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.server.OsmAndHttpServer; import net.osmand.plus.base.BaseOsmAndFragment;
import java.io.IOException; import java.io.IOException;
public class ServerActivity extends AppCompatActivity { import static android.content.Context.WIFI_SERVICE;
public class ServerFragment extends BaseOsmAndFragment {
private boolean initialized = false; private boolean initialized = false;
private OsmAndHttpServer server; private OsmAndHttpServer server;
private View view;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
enableStrictMode();
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.server_activity); enableStrictMode();
findViewById(R.id.server_start_button).setOnClickListener(new View.OnClickListener() { }
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.server_fragment, container, false);
view.findViewById(R.id.server_start_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (!initialized) { if (!initialized) {
@ -36,15 +43,20 @@ public class ServerActivity extends AppCompatActivity {
} }
} }
}); });
findViewById(R.id.server_stop_button).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.server_stop_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (initialized) {
updateTextView(getString(R.string.click_button_to_start_server)); updateTextView(getString(R.string.click_button_to_start_server));
deInitServer(); deInitServer();
} }
}
}); });
return view;
}
@Override
public void onDestroy() {
deInitServer();
super.onDestroy();
} }
public static void enableStrictMode() { public static void enableStrictMode() {
@ -62,9 +74,8 @@ public class ServerActivity extends AppCompatActivity {
.build()); .build());
} }
private void updateTextView(String text) { private void updateTextView(String text) {
((TextView) findViewById(R.id.server_status_textview)).setText(text); ((TextView) view.findViewById(R.id.server_status_textview)).setText(text);
} }
private void initServer() { private void initServer() {
@ -73,11 +84,11 @@ public class ServerActivity extends AppCompatActivity {
OsmAndHttpServer.HOSTNAME = getDeviceAddress(); OsmAndHttpServer.HOSTNAME = getDeviceAddress();
try { try {
server = new OsmAndHttpServer(); server = new OsmAndHttpServer();
server.setApplication((OsmandApplication) this.getApplication()); server.setApplication((OsmandApplication) getMyApplication());
initialized = true; initialized = true;
updateTextView("Server started at: http://" + getDeviceAddress() + ":" + OsmAndHttpServer.PORT); updateTextView("Server started at: http://" + getDeviceAddress() + ":" + OsmAndHttpServer.PORT);
} catch (IOException e) { } catch (IOException e) {
Toast.makeText(this, Toast.makeText(requireContext(),
e.getLocalizedMessage(), e.getLocalizedMessage(),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
e.printStackTrace(); e.printStackTrace();
@ -85,7 +96,7 @@ public class ServerActivity extends AppCompatActivity {
} }
private String getDeviceAddress() { private String getDeviceAddress() {
WifiManager wm = (WifiManager) this.getApplicationContext().getSystemService(WIFI_SERVICE); WifiManager wm = (WifiManager) requireContext().getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress()); String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
return ip != null ? ip : "0.0.0.0"; return ip != null ? ip : "0.0.0.0";
} }
@ -96,12 +107,11 @@ public class ServerActivity extends AppCompatActivity {
server.stop(); server.stop();
} }
initialized = false; initialized = false;
finish(); if (getActivity() != null) {
} try {
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
@Override } catch (Exception e) {
protected void onDestroy() { }
deInitServer(); }
super.onDestroy();
} }
} }

View file

@ -820,7 +820,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
// this method could be called in non UI thread // this method could be called in non UI thread
public void refreshMap(final boolean updateVectorRendering) { public void refreshMap(final boolean updateVectorRendering) {
if (view != null) { if (view != null && view.isShown()) {
boolean nightMode = application.getDaynightHelper().isNightMode(); boolean nightMode = application.getDaynightHelper().isNightMode();
Boolean currentNightMode = this.nightMode; Boolean currentNightMode = this.nightMode;
boolean forceUpdateVectorDrawing = currentNightMode != null && currentNightMode != nightMode; boolean forceUpdateVectorDrawing = currentNightMode != null && currentNightMode != nightMode;