Fix small issues

This commit is contained in:
Victor Shcherb 2014-11-29 15:41:55 +01:00
parent a0800890f3
commit 0423044752
14 changed files with 97 additions and 103 deletions

View file

@ -21,7 +21,6 @@ import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.Activity;
import android.view.Window;
public class OsmAndAppCustomization {

View file

@ -121,6 +121,8 @@ public class OsmandApplication extends Application {
MapActivity mapActivity;
DownloadActivity downloadActivity;
// Typeface
@Override
public void onCreate() {
long timeToStart = System.currentTimeMillis();

View file

@ -9,7 +9,6 @@ import java.util.Date;
import java.util.List;
import java.util.Random;
import android.support.v4.app.Fragment;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication;
@ -42,6 +41,7 @@ import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.format.DateFormat;
@ -57,7 +57,6 @@ import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
/**
* Created by Denis on 05.11.2014.
*/
public class DashboardActivity extends BaseDownloadActivity {
public static final boolean TIPS_AND_TRICKS = false;
@ -71,10 +70,10 @@ public class DashboardActivity extends BaseDownloadActivity {
private static final String EXCEPTION_FILE_SIZE = "EXCEPTION_FS"; //$NON-NLS-1$
private static final String CONTRIBUTION_VERSION_FLAG = "CONTRIBUTION_VERSION_FLAG";
private static final int HELP_ID = 0;
private static final int SETTINGS_ID = 1;
private static final int EXIT_ID = 2;
private ProgressDialog startProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -156,25 +155,22 @@ public class DashboardActivity extends BaseDownloadActivity {
android.support.v4.app.FragmentTransaction fragmentTransaction = manager.beginTransaction();
//after rotation list of fragments in fragment transaction is not cleared
//so we need to check whether some fragments are already existing
if (manager.findFragmentByTag(DashSearchFragment.TAG) == null){
DashSearchFragment searchFragment = new DashSearchFragment();
fragmentTransaction.add(R.id.content, searchFragment, DashSearchFragment.TAG);
}
if (manager.findFragmentByTag(DashMapFragment.TAG) == null){
DashMapFragment mapFragment = new DashMapFragment();
fragmentTransaction.add(R.id.content, mapFragment, DashMapFragment.TAG);
}
if (manager.findFragmentByTag(DashSearchFragment.TAG) == null){
DashSearchFragment searchFragment = new DashSearchFragment();
fragmentTransaction.add(R.id.content, searchFragment, DashSearchFragment.TAG);
}
if (manager.findFragmentByTag(DashFavoritesFragment.TAG) == null){
DashFavoritesFragment favoritesFragment = new DashFavoritesFragment();
fragmentTransaction.add(R.id.content, favoritesFragment, DashFavoritesFragment.TAG);
}
if (manager.findFragmentByTag(DashUpdatesFragment.TAG) == null){
DashUpdatesFragment updatesFragment = new DashUpdatesFragment();
fragmentTransaction.add(R.id.content, updatesFragment, DashUpdatesFragment.TAG);
}
if (manager.findFragmentByTag(DashPluginsFragment.TAG) == null){
DashPluginsFragment pluginsFragment = new DashPluginsFragment();
fragmentTransaction.add(R.id.content, pluginsFragment, DashPluginsFragment.TAG).commit();
@ -282,6 +278,10 @@ public class DashboardActivity extends BaseDownloadActivity {
@Override
public void onDismiss(DialogInterface dialog) {
checkVectorIndexesDownloaded();
// Do some action on close
// FIXME uncomment
// app.getResourceManager().getRenderer().clearCache();
// mapView.refreshMap(true);
}
});
} else {
@ -382,12 +382,12 @@ public class DashboardActivity extends BaseDownloadActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 0, 0, R.string.tips_and_tricks).setIcon(R.drawable.ic_ac_help)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, 1, 0, R.string.settings).setIcon(R.drawable.ic_ac_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, 2, 0, R.string.exit_Button).setIcon(R.drawable.ic_ac_close)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
menu.add(0, HELP_ID, 0, R.string.tips_and_tricks).setIcon(R.drawable.ic_ac_help)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0, SETTINGS_ID, 0, R.string.settings).setIcon(R.drawable.ic_ac_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0, EXIT_ID, 0, R.string.exit_Button).setIcon(R.drawable.ic_ac_close)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
@ -400,7 +400,7 @@ public class DashboardActivity extends BaseDownloadActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
if (item.getItemId() == 0) {
if (item.getItemId() == HELP_ID) {
if(TIPS_AND_TRICKS) {
TipsAndTricksActivity activity = new TipsAndTricksActivity(this);
Dialog dlg = activity.getDialogToShowTips(false, true);
@ -409,10 +409,10 @@ public class DashboardActivity extends BaseDownloadActivity {
final Intent helpIntent = new Intent(this, HelpActivity.class);
startActivity(helpIntent);
}
} else if (item.getItemId() == 1){
} else if (item.getItemId() == SETTINGS_ID){
final Intent settings = new Intent(this, appCustomization.getSettingsActivity());
startActivity(settings);
} else if (item.getItemId() == 2){
} else if (item.getItemId() == EXIT_ID){
getMyApplication().closeApplication(this);
}
return true;

View file

@ -1,56 +0,0 @@
package net.osmand.plus.api.render;
public interface Paint {
public enum Style {
FILL (0),
STROKE (1),
FILL_AND_STROKE (2);
Style(int nativeInt) {
this.nativeInt = nativeInt;
}
final int nativeInt;
}
public enum Cap {
BUTT (0),
ROUND (1),
SQUARE (2);
private Cap(int nativeInt) {
this.nativeInt = nativeInt;
}
final int nativeInt;
}
public enum Join {
MITER (0),
ROUND (1),
BEVEL (2);
private Join(int nativeInt) {
this.nativeInt = nativeInt;
}
final int nativeInt;
}
public enum Align {
LEFT (0),
CENTER (1),
RIGHT (2);
private Align(int nativeInt) {
this.nativeInt = nativeInt;
}
final int nativeInt;
}
void setColor(int color);
int getColor();
void setTextAlign(Align align);
void setStrokeWidth(float width);
void setAntiAlias(boolean flag);
void setStyle(Style style);
}

View file

@ -1,5 +0,0 @@
package net.osmand.plus.api.render;
public interface Path {
}

View file

@ -1,5 +0,0 @@
package net.osmand.plus.api.render;
public class Typeface {
}

View file

@ -21,6 +21,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.helpers.FontCache;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
@ -36,7 +37,7 @@ public class DashFavoritesFragment extends DashBaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_favorites_fragment, container, false);
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Medium.ttf");
Typeface typeface = FontCache.getRobotoMedium(getActivity());
((TextView) view.findViewById(R.id.fav_text)).setTypeface(typeface);
((Button) view.findViewById(R.id.show_all)).setTypeface(typeface);

View file

@ -15,6 +15,9 @@ import net.osmand.map.MapTileDownloader.DownloadRequest;
import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.render.MapVectorLayer;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.views.MapTextLayer;
@ -41,22 +44,25 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
getMyApplication().getResourceManager().getMapTileDownloader().addDownloaderCallback(this);
}
protected void startMapActivity() {
MapActivity.launchMapActivityMoveToTop(getActivity());
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_map_fragment, container, false);
setupMapView(view);
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Medium.ttf");
Typeface typeface = FontCache.getRobotoMedium(getActivity());
((TextView) view.findViewById(R.id.map_text)).setTypeface(typeface);
((Button) view.findViewById(R.id.show_map)).setTypeface(typeface);
(view.findViewById(R.id.show_map)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Activity activity = getActivity();
OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
final Intent mapIndent = new Intent(activity, appCustomization.getMapActivity());
activity.startActivityForResult(mapIndent, 0);
startMapActivity();
}
});
return view;
@ -64,6 +70,13 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
private void setupMapView(View view){
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) view.findViewById(R.id.MapView);
surf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startMapActivity();
}
});
osmandMapTileView = surf.getMapView();
osmandMapTileView.getView().setVisibility(View.VISIBLE);
osmandMapTileView.removeAllLayers();
@ -75,10 +88,16 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloader
osmandMapTileView.addLayer(mapVectorLayer, 0.5f);
osmandMapTileView.setMainLayer(mapVectorLayer);
mapVectorLayer.setVisible(true);
osmandMapTileView.setShowMapPosition(false);
}
@Override
public void onResume() {
super.onResume();
LatLon lm = getMyApplication().getSettings().getLastKnownMapLocation();
int zm = getMyApplication().getSettings().getLastKnownMapZoom();
osmandMapTileView.setLatLon(lm.getLatitude(), lm.getLongitude());
osmandMapTileView.setIntZoom(zm);
osmandMapTileView.setComplexZoom(zm, osmandMapTileView.getSettingsZoomScale());
osmandMapTileView.refreshMap(true);
}

View file

@ -14,6 +14,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.helpers.FontCache;
import java.util.List;
@ -27,7 +28,7 @@ public class DashPluginsFragment extends DashBaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_plugins_fragment, container, false);
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Medium.ttf");
Typeface typeface = FontCache.getRobotoMedium(getActivity());
((TextView) view.findViewById(R.id.plugin_text)).setTypeface(typeface);
((Button) view.findViewById(R.id.show_all)).setTypeface(typeface);
view.findViewById(R.id.show_all).setOnClickListener(new View.OnClickListener() {

View file

@ -3,6 +3,7 @@ package net.osmand.plus.dashboard;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.helpers.FontCache;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
@ -28,8 +29,7 @@ public class DashSearchFragment extends DashBaseFragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_search_fragment, container, false);
setupButtons(view);
// TODO cache typeface ?
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Medium.ttf");
Typeface typeface = FontCache.getRobotoMedium(getActivity());
((TextView) view.findViewById(R.id.search_for)).setTypeface(typeface);
return view;
}

View file

@ -0,0 +1,27 @@
package net.osmand.plus.helpers;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import android.content.Context;
import android.graphics.Typeface;
public class FontCache {
private static Map<String, Typeface> fontMap = new ConcurrentHashMap<String, Typeface>();
public static final String ROBOTO_MEDIUM = "fonts/Roboto-Medium.ttf";
public static final String ROBOTO_REGULAR = "fonts/Roboto-Regular.ttf";
public static Typeface getRobotoMedium(Context context) {
return getFont(context, ROBOTO_MEDIUM);
}
public static Typeface getFont(Context context, String fontName) {
if (fontMap.containsKey(fontName)) {
return fontMap.get(fontName);
} else {
Typeface tf = Typeface.createFromAsset(context.getAssets(), fontName);
fontMap.put(fontName, tf);
return tf;
}
}
}

View file

@ -614,15 +614,15 @@ public class MapRenderRepositories {
// calculate data box
QuadRect dataBox = requestedBox.getLatLonBounds();
long now = System.currentTimeMillis();
if (cObjectsBox.left > dataBox.left || cObjectsBox.top > dataBox.top || cObjectsBox.right < dataBox.right
|| cObjectsBox.bottom < dataBox.bottom || (nativeLib != null) == (cNativeObjects == null)) {
if (cObjectsBox.left > dataBox.left || cObjectsBox.top < dataBox.top || cObjectsBox.right < dataBox.right
|| cObjectsBox.bottom > dataBox.bottom || (nativeLib != null) == (cNativeObjects == null)) {
// increase data box in order for rotate
if ((dataBox.right - dataBox.left) > (dataBox.top - dataBox.bottom)) {
double wi = (dataBox.right - dataBox.left) * .2;
double wi = (dataBox.right - dataBox.left) * .05;
dataBox.left -= wi;
dataBox.right += wi;
} else {
double hi = (dataBox.top - dataBox.bottom) * .2;
double hi = (dataBox.top - dataBox.bottom) * .05;
dataBox.top += hi;
dataBox.bottom -= hi;
}

View file

@ -11,6 +11,7 @@ import android.view.SurfaceView;
public class OsmAndMapSurfaceView extends SurfaceView implements Callback {
private OsmandMapTileView mapView;
private OnClickListener onClickListener;
public OsmAndMapSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
@ -52,6 +53,11 @@ public class OsmAndMapSurfaceView extends SurfaceView implements Callback {
return r;
}
@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
this.onClickListener = l;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Boolean r = mapView.onKeyDown(keyCode, event);
@ -63,6 +69,9 @@ public class OsmAndMapSurfaceView extends SurfaceView implements Callback {
@Override
public boolean onTouchEvent(MotionEvent event) {
if(onClickListener != null) {
return super.onTouchEvent(event);
}
return mapView.onTouchEvent(event);
}

View file

@ -5,12 +5,12 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityActionsProvider;
import net.osmand.access.AccessibleToast;
import net.osmand.access.MapExplorer;
import net.osmand.core.android.MapRendererView;
import net.osmand.core.jni.IMapRenderer;
import net.osmand.data.LatLon;
import net.osmand.data.QuadPoint;
import net.osmand.data.QuadPointDouble;
@ -27,7 +27,9 @@ import net.osmand.plus.helpers.TwoFingerTapDetector;
import net.osmand.plus.views.MultiTouchSupport.MultiTouchZoomListener;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;