refactoring packages add Settings class, add map source selection

git-svn-id: https://osmand.googlecode.com/svn/trunk@29 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-02 12:35:36 +00:00
parent 22f0ebcdef
commit e5f031b383
12 changed files with 136 additions and 63 deletions

View file

@ -0,0 +1,13 @@
package com.osmand;
import com.osmand.map.ITileSource;
public class OsmandSettings {
public static boolean useInternetToDownloadTiles = DefaultLauncherConstants.loadMissingImages;
public static boolean showGPSLocationOnMap = DefaultLauncherConstants.showGPSCoordinates;
public static ITileSource tileSource = DefaultLauncherConstants.MAP_defaultTileSource;
}

View file

@ -10,5 +10,13 @@ public class ToDoConstants {
public int CONFIG_COMMONS_LOGGING_IN_ANDROID = 1; public int CONFIG_COMMONS_LOGGING_IN_ANDROID = 1;
public int SAVE_SETTINGS_IN_ANDROID_BETWEEN_SESSION = 2;
public int IMPLEMENT_ON_STOP_RESUME_ACTIVITY = 3;
// OsmandMapTileView.java have problem with class loading (LogFactory, MapTileDownloader) -
// it is not editable in editor
public int MAKE_MAP_PANEL_EDITABLE_IN_EDITOR = 4;
} }

View file

@ -4,7 +4,7 @@
android:versionCode="1" android:versionCode="1"
android:versionName="1.0"> android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".MapActivity" <activity android:name=".activities.MapActivity"
android:label="@string/app_name" android:launchMode="standard"> android:label="@string/app_name" android:launchMode="standard">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -12,7 +12,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="SettingsActivity" android:label="@string/settings_activity"></activity> <activity android:name=".activities.SettingsActivity" android:label="@string/settings_activity"></activity>
</application> </application>

View file

@ -3,8 +3,8 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<com.osmand.OsmandMapTileView android:id="@+id/MapView" android:layout_width="wrap_content" android:layout_height="wrap_content"></com.osmand.OsmandMapTileView> <com.osmand.views.OsmandMapTileView android:id="@+id/MapView" android:layout_width="wrap_content" android:layout_height="wrap_content"></com.osmand.views.OsmandMapTileView>
<com.osmand.PointOfView android:id="@+id/PointOfView" android:layout_width="wrap_content" android:layout_height="wrap_content"></com.osmand.PointOfView> <com.osmand.views.PointOfView android:id="@+id/PointOfView" android:layout_width="wrap_content" android:layout_height="wrap_content"></com.osmand.views.PointOfView>
<ZoomControls android:id="@+id/ZoomControls01" <ZoomControls android:id="@+id/ZoomControls01"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right"></ZoomControls> android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right"></ZoomControls>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:id="@+id/BackToLocation" android:background="@drawable/icon"></ImageButton> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:id="@+id/BackToLocation" android:background="@drawable/icon"></ImageButton>

View file

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<CheckBox android:id="@+id/use_internet_to_download_tile" android:layout_height="wrap_content" android:text="@string/use_internet_to_download_tile" android:layout_width="wrap_content"></CheckBox>
<View
android:layout_width="fill_parent"
android:layout_height="2dip" android:background="#FFFFFFFF" />
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/show_gps_coordinates_text" android:id="@+id/show_gps_coordinates_text"></CheckBox>
</LinearLayout>

View file

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="map_tile_source_descr">Choose the source of tiles</string>
<string name="map_tile_source">Map tile source</string>
<string name="map_source">Map source</string>
<string name="use_internet">Use internet</string>
<string name="show_location">Show location</string>
<string name="map_preferences">Map preferences</string>
<string name="settings_activity">Settings</string> <string name="settings_activity">Settings</string>
<string name="show_gps_coordinates_text">Show gps coordinates on map</string> <string name="show_gps_coordinates_text">Show gps coordinates on map</string>
<string name="use_internet_to_download_tile">Use internet to download missing tiles</string> <string name="use_internet_to_download_tile">Use internet to download missing tiles</string>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/map_preferences">
<CheckBoxPreference android:key="show_gps_location_text" android:title="@string/show_location" android:summary="@string/show_gps_coordinates_text"></CheckBoxPreference>
<CheckBoxPreference android:key="use_internet_to_download_tiles" android:title="@string/use_internet" android:summary="@string/use_internet_to_download_tile"></CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/map_source"><ListPreference android:title="@string/map_tile_source" android:summary="@string/map_tile_source_descr" android:key="map_tile_sources"></ListPreference>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -1,36 +0,0 @@
package com.osmand;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
public class SettingsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
final CheckBox useInternet = (CheckBox)findViewById(R.id.use_internet_to_download_tile);
useInternet.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
DefaultLauncherConstants.loadMissingImages = useInternet.isChecked();
}
});
useInternet.setChecked(DefaultLauncherConstants.loadMissingImages);
final CheckBox showGPSText = (CheckBox)findViewById(R.id.show_gps_coordinates_text);
showGPSText.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
DefaultLauncherConstants.showGPSCoordinates = showGPSText.isChecked();
}
});
showGPSText.setChecked(DefaultLauncherConstants.showGPSCoordinates);
}
}

View file

@ -1,4 +1,4 @@
package com.osmand; package com.osmand.activities;
import java.io.File; import java.io.File;
@ -16,7 +16,12 @@ import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ZoomControls; import android.widget.ZoomControls;
import com.osmand.IMapLocationListener;
import com.osmand.OsmandSettings;
import com.osmand.R;
import com.osmand.osm.MapUtils; import com.osmand.osm.MapUtils;
import com.osmand.views.OsmandMapTileView;
import com.osmand.views.PointOfView;
public class MapActivity extends Activity implements LocationListener, IMapLocationListener { public class MapActivity extends Activity implements LocationListener, IMapLocationListener {
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@ -143,6 +148,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
} }
} }
@Override @Override
protected void onPause() { protected void onPause() {
// TODO switch off gps // TODO switch off gps
@ -153,6 +159,9 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
protected void onResume() { protected void onResume() {
// TODO switch on gps // TODO switch on gps
super.onResume(); super.onResume();
if(mapView.getMap() != OsmandSettings.tileSource){
mapView.setMap(OsmandSettings.tileSource);
}
} }

View file

@ -0,0 +1,76 @@
package com.osmand.activities;
import java.util.List;
import com.osmand.DefaultLauncherConstants;
import com.osmand.R;
import com.osmand.R.xml;
import com.osmand.map.TileSourceManager;
import com.osmand.map.TileSourceManager.TileSourceTemplate;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.Preference.OnPreferenceChangeListener;
public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener {
private static final String use_internet_to_download_tiles = "use_internet_to_download_tiles";
private static final String show_gps_location_text = "show_gps_location_text";
private static final String map_tile_sources = "map_tile_sources";
private CheckBoxPreference showGpsLocation;
private CheckBoxPreference useInternetToDownloadTiles;
private ListPreference tileSourcePreference;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings_pref);
PreferenceScreen screen = getPreferenceScreen();
showGpsLocation =(CheckBoxPreference) screen.findPreference(show_gps_location_text);
showGpsLocation.setOnPreferenceChangeListener(this);
useInternetToDownloadTiles =(CheckBoxPreference) screen.findPreference(use_internet_to_download_tiles);
useInternetToDownloadTiles.setOnPreferenceChangeListener(this);
tileSourcePreference =(ListPreference) screen.findPreference(map_tile_sources);
tileSourcePreference.setOnPreferenceChangeListener(this);
}
@Override
protected void onResume() {
super.onResume();
useInternetToDownloadTiles.setChecked(DefaultLauncherConstants.loadMissingImages);
showGpsLocation.setChecked(DefaultLauncherConstants.showGPSCoordinates);
List<TileSourceTemplate> list = TileSourceManager.getKnownSourceTemplates();
String[] entries = new String[list.size()];
for(int i=0; i<list.size(); i++){
entries[i] = list.get(i).getName();
}
tileSourcePreference.setEntries(entries);
tileSourcePreference.setEntryValues(entries);
tileSourcePreference.setValue(DefaultLauncherConstants.MAP_defaultTileSource.getName());
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(preference == showGpsLocation){
DefaultLauncherConstants.showGPSCoordinates = (Boolean) newValue;
} else if(preference == useInternetToDownloadTiles){
DefaultLauncherConstants.loadMissingImages = (Boolean) newValue;
} else if(preference == tileSourcePreference){
String newTile = newValue.toString();
for(TileSourceTemplate t : TileSourceManager.getKnownSourceTemplates()){
if(t.getName().equals(newTile)){
DefaultLauncherConstants.MAP_defaultTileSource = t;
break;
}
}
}
return true;
}
}

View file

@ -1,4 +1,4 @@
package com.osmand; package com.osmand.views;
import java.io.File; import java.io.File;
@ -24,6 +24,10 @@ import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import com.osmand.DefaultLauncherConstants;
import com.osmand.IMapLocationListener;
import com.osmand.MapTileDownloader;
import com.osmand.OsmandSettings;
import com.osmand.MapTileDownloader.DownloadRequest; import com.osmand.MapTileDownloader.DownloadRequest;
import com.osmand.MapTileDownloader.IMapDownloaderCallback; import com.osmand.MapTileDownloader.IMapDownloaderCallback;
import com.osmand.map.ITileSource; import com.osmand.map.ITileSource;
@ -53,7 +57,7 @@ public class OsmandMapTileView extends View implements IMapDownloaderCallback {
private double latitude = DefaultLauncherConstants.MAP_startMapLatitude; private double latitude = DefaultLauncherConstants.MAP_startMapLatitude;
// name of source map // name of source map
private ITileSource map = DefaultLauncherConstants.MAP_defaultTileSource; private ITileSource map = null;
/** /**
* listeners * listeners
@ -190,7 +194,7 @@ public class OsmandMapTileView extends View implements IMapDownloaderCallback {
} }
canvas.drawCircle(getWidth()/2, getHeight()/2, 3, paintBlack); canvas.drawCircle(getWidth()/2, getHeight()/2, 3, paintBlack);
canvas.drawCircle(getWidth()/2, getHeight()/2, 6, paintBlack); canvas.drawCircle(getWidth()/2, getHeight()/2, 6, paintBlack);
if (DefaultLauncherConstants.showGPSCoordinates) { if (OsmandSettings.showGPSLocationOnMap) {
canvas.drawText(MessageFormat.format("Lat : {0}, lon : {1}, zoom : {2}", latitude, longitude, zoom), canvas.drawText(MessageFormat.format("Lat : {0}, lon : {1}, zoom : {2}", latitude, longitude, zoom),
drawCoordinatesX, drawCoordinatesY, paintBlack); drawCoordinatesX, drawCoordinatesY, paintBlack);
} }
@ -261,7 +265,7 @@ public class OsmandMapTileView extends View implements IMapDownloaderCallback {
} }
public void prepareImage(){ public void prepareImage(){
prepareImage(DefaultLauncherConstants.loadMissingImages); prepareImage(OsmandSettings.useInternetToDownloadTiles);
} }
public void prepareImage(boolean loadNecessaryImages) { public void prepareImage(boolean loadNecessaryImages) {

View file

@ -1,4 +1,4 @@
package com.osmand; package com.osmand.views;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;