Replaced dynamic map with static on Dashboard

This commit is contained in:
Denis 2014-12-23 17:15:26 +02:00
parent 68ba8052c4
commit 7cf7db1b8c
2 changed files with 37 additions and 48 deletions

View file

@ -18,7 +18,7 @@
<RelativeLayout android:layout_width="wrap_content" <RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="@dimen/subHeaderPadding"> android:padding="@dimen/subHeaderPadding">
<LinearLayout android:id="@+id/loading" <LinearLayout android:id="@+id/loading"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="@dimen/dashMapHeight" android:layout_height="@dimen/dashMapHeight"
@ -28,7 +28,7 @@
<ProgressBar <ProgressBar
android:id="@+id/ProgressBar" android:id="@+id/ProgressBar"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"/>
<TextView <TextView
android:id="@+id/ProgressMessage" android:id="@+id/ProgressMessage"
@ -36,18 +36,18 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLines="3" android:maxLines="3"
android:text="@string/loading_data" android:text="@string/loading_data"
android:textSize="@dimen/dashProgressTextSize" /> android:textSize="@dimen/dashProgressTextSize"/>
</LinearLayout> </LinearLayout>
<net.osmand.plus.views.OsmAndMapSurfaceView <ImageView android:id="@+id/map_image"
android:id="@+id/MapView" android:scaleType="centerCrop"
android:layout_width="fill_parent" android:src="@drawable/background"
android:layout_height="@dimen/dashMapHeight" android:layout_width="match_parent"
android:layout_marginLeft="@dimen/dashMapMargin" android:layout_height="@dimen/dashMapHeight"
android:layout_marginRight="@dimen/dashMapMargin" android:layout_marginLeft="@dimen/dashMapMargin"
android:layout_marginBottom="@dimen/dashMapMargin" android:layout_marginRight="@dimen/dashMapMargin"
android:contentDescription="@string/map_view" android:layout_marginBottom="@dimen/dashMapMargin"
android:visibility="gone"/> android:visibility="gone"/>
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>

View file

@ -1,5 +1,7 @@
package net.osmand.plus.dashboard; package net.osmand.plus.dashboard;
import android.graphics.Bitmap;
import android.widget.ImageView;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.map.MapTileDownloader.DownloadRequest; import net.osmand.map.MapTileDownloader.DownloadRequest;
import net.osmand.map.MapTileDownloader.IMapDownloaderCallback; import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
@ -28,7 +30,6 @@ import android.widget.TextView;
public class DashMapFragment extends DashBaseFragment implements IMapDownloaderCallback { public class DashMapFragment extends DashBaseFragment implements IMapDownloaderCallback {
public static final String TAG = "DASH_MAP_FRAGMENT"; public static final String TAG = "DASH_MAP_FRAGMENT";
private OsmandMapTileView osmandMapTileView;
@Override @Override
public void onDestroy() { public void onDestroy() {
@ -52,7 +53,7 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
Typeface typeface = FontCache.getRobotoMedium(getActivity()); Typeface typeface = FontCache.getRobotoMedium(getActivity());
((TextView) view.findViewById(R.id.map_text)).setTypeface(typeface); ((TextView) view.findViewById(R.id.map_text)).setTypeface(typeface);
((Button) view.findViewById(R.id.show_map)).setTypeface(typeface); ((Button) view.findViewById(R.id.show_map)).setTypeface(typeface);
setupMapView(view);
(view.findViewById(R.id.show_map)).setOnClickListener(new View.OnClickListener() { (view.findViewById(R.id.show_map)).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -61,48 +62,40 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
}); });
return view; ((ImageView) view.findViewById(R.id.map_image)).setOnClickListener(new View.OnClickListener() {
}
private void setupMapView(View view){
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) view.findViewById(R.id.MapView);
surf.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
startMapActivity(); startMapActivity();
} }
}); });
osmandMapTileView = surf.getMapView(); setMapImage(view);
osmandMapTileView.getView().setVisibility(View.VISIBLE);
osmandMapTileView.removeAllLayers(); return view;
MapVectorLayer mapVectorLayer = new MapVectorLayer(null, true);
MapTextLayer mapTextLayer = new MapTextLayer();
mapTextLayer.setAlwaysVisible(true);
// 5.95 all labels
osmandMapTileView.addLayer(mapTextLayer, 5.95f);
osmandMapTileView.addLayer(mapVectorLayer, 0.5f);
osmandMapTileView.setMainLayer(mapVectorLayer);
mapVectorLayer.setVisible(true);
osmandMapTileView.setShowMapPosition(false);
} }
private void setMapImage(View view) {
if (view == null) {
return;
}
Bitmap image = getMyApplication().getResourceManager().getRenderer().getBitmap();
ImageView map = (ImageView) view.findViewById(R.id.map_image);
if (image != null){
map.setImageBitmap(image);
}
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
LatLon lm = getMyApplication().getSettings().getLastKnownMapLocation(); setMapImage(getView());
int zm = getMyApplication().getSettings().getLastKnownMapZoom();
//Let us not change zoom here, it provides for a smoother transition between the map and the dashboard screens, and provides better recognition of the map fragment
//zm = Math.max(zm - 3, 4);
osmandMapTileView.setLatLon(lm.getLatitude(), lm.getLongitude());
osmandMapTileView.setComplexZoom(zm, osmandMapTileView.getSettingsMapDensity());
osmandMapTileView.refreshMap(true);
} }
@Override @Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.MapView).setVisibility(View.GONE); view.findViewById(R.id.map_image).setVisibility(View.GONE);
if(getMyApplication().isApplicationInitializing()) { if(getMyApplication().isApplicationInitializing()) {
getMyApplication().checkApplicationIsBeingInitialized(getActivity(), (TextView) view.findViewById(R.id.ProgressMessage), getMyApplication().checkApplicationIsBeingInitialized(getActivity(), (TextView) view.findViewById(R.id.ProgressMessage),
(ProgressBar) view.findViewById(R.id.ProgressBar), new Runnable() { (ProgressBar) view.findViewById(R.id.ProgressBar), new Runnable() {
@ -121,7 +114,7 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
MainMenuActivity dashboardActivity =((MainMenuActivity)getSherlockActivity()); MainMenuActivity dashboardActivity =((MainMenuActivity)getSherlockActivity());
if (dashboardActivity != null){ if (dashboardActivity != null){
dashboardActivity.updateDownloads(); dashboardActivity.updateDownloads();
view.findViewById(R.id.MapView).setVisibility(View.VISIBLE); view.findViewById(R.id.map_image).setVisibility(View.VISIBLE);
} }
} }
@ -130,11 +123,7 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
if(request != null && !request.error && request.fileToSave != null){ if(request != null && !request.error && request.fileToSave != null){
ResourceManager mgr = getMyApplication().getResourceManager(); ResourceManager mgr = getMyApplication().getResourceManager();
mgr.tileDownloaded(request); mgr.tileDownloaded(request);
} setMapImage(getView());
if(request == null || !request.error){
if(osmandMapTileView != null) {
osmandMapTileView.tileDownloaded(request);
}
} }
} }
} }