Permalink
Browse files

mozna eksportowac mape do jpg

  • Loading branch information...
1 parent 0939738 commit 68de863b6ad7f9c12ae8361b270179eef48e53fd @marcnowa marcnowa committed Feb 6, 2011
@@ -17,38 +17,40 @@
}
public static final class id {
public static final int LinearLayout01=0x7f060005;
+ public static final int LinearLayout03=0x7f06000b;
public static final int RadioGroup01=0x7f060002;
public static final int TextView01=0x7f060001;
public static final int editMeters=0x7f060009;
public static final int editSeconds=0x7f060007;
public static final int gpsRadioButton=0x7f060003;
- public static final int map=0x7f06000e;
+ public static final int map=0x7f060012;
public static final int metersTextView=0x7f060008;
public static final int networkRadioButton=0x7f060004;
- public static final int prepareButton=0x7f06000c;
- public static final int prepareMain=0x7f06000d;
- public static final int saveMapMenuItem=0x7f060013;
- public static final int searchLocationMenuItem=0x7f060012;
+ public static final int prepareButton=0x7f060010;
+ public static final int prepareMain=0x7f060011;
+ public static final int saveMapMenuItem=0x7f060017;
+ public static final int searchLocationMenuItem=0x7f060016;
public static final int secondsTextView=0x7f060006;
+ public static final int settingsClearLog=0x7f06000e;
+ public static final int settingsLoadLog=0x7f06000c;
public static final int settingsSave=0x7f06000a;
- public static final int showButton=0x7f06000b;
- public static final int showClear=0x7f06001d;
- public static final int showDeleteMaps=0x7f060019;
+ public static final int settingsSaveLog=0x7f06000d;
+ public static final int showButton=0x7f06000f;
+ public static final int showDeleteMaps=0x7f06001d;
+ public static final int showExport=0x7f060022;
public static final int showInfo=0x7f060020;
- public static final int showLoad=0x7f06001b;
- public static final int showLoadMap=0x7f060018;
- public static final int showMap=0x7f06000f;
- public static final int showNewMap=0x7f060017;
+ public static final int showLoadMap=0x7f06001c;
+ public static final int showLocation=0x7f060021;
+ public static final int showMap=0x7f060013;
+ public static final int showNewMap=0x7f06001b;
public static final int showNextZoom=0x7f06001f;
- public static final int showSave=0x7f06001a;
- public static final int showSettings=0x7f06001c;
- public static final int showZoomIn=0x7f060010;
- public static final int showZoomOut=0x7f060011;
+ public static final int showZoomIn=0x7f060014;
+ public static final int showZoomOut=0x7f060015;
public static final int submenuGet=0x7f06001e;
- public static final int submenuLocation=0x7f060016;
+ public static final int submenuLocation=0x7f06001a;
public static final int trackingCheckBox=0x7f060000;
- public static final int zoomInMenuItem=0x7f060014;
- public static final int zoomOutMenuItem=0x7f060015;
+ public static final int zoomInMenuItem=0x7f060018;
+ public static final int zoomOutMenuItem=0x7f060019;
}
public static final class layout {
public static final int location_settings=0x7f030000;
@@ -63,10 +63,34 @@
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
-
+
<Button
android:layout_height="wrap_content"
android:id="@+id/settingsSave"
android:layout_width="wrap_content"
android:text="Save settings" />
+
+ <LinearLayout
+ android:id="@+id/LinearLayout03"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <Button
+ android:layout_height="wrap_content"
+ android:id="@+id/settingsLoadLog"
+ android:layout_width="wrap_content"
+ android:text="Load log..." />
+
+ <Button
+ android:layout_height="wrap_content"
+ android:id="@+id/settingsSaveLog"
+ android:layout_width="wrap_content"
+ android:text="Save log..." />
+
+ <Button
+ android:layout_height="wrap_content"
+ android:id="@+id/settingsClearLog"
+ android:layout_width="wrap_content"
+ android:text="Clear log" />
+ </LinearLayout>
</LinearLayout>
View
@@ -2,7 +2,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<pl.edu.agh.tinsnake.util.MapWebView android:id="@+id/showMap" android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
+ android:layout_height="wrap_content" android:scrollbars="none"/>
<ImageButton
android:id="@+id/showZoomIn"
android:layout_width="wrap_content"
@@ -13,21 +13,7 @@
</menu>
</item>
- <item android:id="@+id/submenuLocation"
- android:title="Location...">
- <menu>
- <item android:id="@+id/showSave"
- android:title="Save log" />
- <item android:id="@+id/showLoad"
- android:title="Load log" />
- <item android:id="@+id/showSettings"
- android:title="Settings..." />
- <item android:id="@+id/showClear"
- android:title="Clear log" />
- </menu>
-
- </item>
<item android:id="@+id/submenuGet"
android:title="Get...">
@@ -39,4 +25,8 @@
</menu>
</item>
+ <item android:id="@+id/showLocation"
+ android:title="Location..." />
+ <item android:id="@+id/showExport"
+ android:title="Export to jpg"/>
</menu>
@@ -125,9 +125,10 @@ public static void downloadMapImages(Map map, Handler handler)
}
}
- public static void downloadNextZoomLevel(Map map)
+ public static void downloadNextZoomLevel(Map map, Handler handler)
throws FileNotFoundException, IOException {
- downloadZoomLevel(map, map.getMaxZoom() + 1, null, 0, 0);
+ int imagesCount = (int) Math.pow(Math.pow(2, map.getMaxZoom()), 2);
+ downloadZoomLevel(map, map.getMaxZoom() + 1, handler, imagesCount, 0);
}
private static int downloadZoomLevel(Map map, int orgZoom, Handler handler,
@@ -145,17 +146,20 @@ private static int downloadZoomLevel(Map map, int orgZoom, Handler handler,
width += bitmap.getWidth();
height += bitmap.getHeight();
- Message msg = handler.obtainMessage();
+ if (handler != null) {
+ Message msg = handler.obtainMessage();
+ currentImagesCount++;
- currentImagesCount++;
+ Bundle b = new Bundle();
+ b.putDouble("total", (double) currentImagesCount
+ / (double) imagesCount);
+ b.putBoolean("success", true);
+ msg.setData(b);
+ handler.sendMessage(msg);
+ Log.d("DOWNLOADED", "COUNT: " + currentImagesCount);
+
+ }
- Bundle b = new Bundle();
- b.putDouble("total", (double) currentImagesCount
- / (double) imagesCount);
- b.putBoolean("success", true);
- msg.setData(b);
- handler.sendMessage(msg);
- Log.d("DOWNLOADED", "COUNT: " + currentImagesCount);
}
}
@@ -499,11 +503,27 @@ public static boolean mapExists(String mapName) {
}
public static void setLastMap(String name, Context c) {
- SharedPreferences settings = c.getSharedPreferences(LocationSettings.SETTINGS_NAME, 0);
+ SharedPreferences settings = c.getSharedPreferences(
+ LocationSettings.SETTINGS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("lastMap", name);
editor.commit();
+
+ }
+
+ public static void saveExport(final Bitmap export, Map map) throws FileNotFoundException, IOException {
+ final File file = new File(getFolderPath(map.getName()) + File.separator + "export.jpg");
+
+ StreamUtil.safelyAcccess(new FileOutputStream(file),
+ new CloseableUser() {
+ @Override
+ public void performAction(Closeable stream)
+ throws IOException {
+ export.compress(Bitmap.CompressFormat.JPEG, 90,
+ (OutputStream) stream);
+ }
+ });
}
}
@@ -1,8 +1,11 @@
package pl.edu.agh.tinsnake.gui;
+import pl.edu.agh.tinsnake.Map;
+import pl.edu.agh.tinsnake.MapHelper;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
@@ -13,6 +16,8 @@
public class LocationSettings extends Activity implements OnClickListener {
+ private Map map;
+
/**
* Called when the activity is first created.
*
@@ -22,8 +27,13 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ map = (Map) getIntent().getExtras().getSerializable("map");
+
setContentView(R.layout.location_settings);
findViewById(R.id.settingsSave).setOnClickListener(this);
+ findViewById(R.id.settingsClearLog).setOnClickListener(this);
+ findViewById(R.id.settingsSaveLog).setOnClickListener(this);
+ findViewById(R.id.settingsLoadLog).setOnClickListener(this);
trackingCheckBox = (CheckBox)findViewById(R.id.trackingCheckBox);
gpsRadioButton = (RadioButton)findViewById(R.id.gpsRadioButton);
@@ -100,6 +110,17 @@ public void onClick(View v) {
}
break;
+
+ case R.id.settingsClearLog:
+ map.clearLocationHistory();
+ try {
+ MapHelper.saveMap(map);
+ } catch (Exception e) {
+ Log.e("CLEAR LOCATION HISTORY", e.getClass().getCanonicalName() + " "
+ + e.getMessage());
+ return;
+ }
+ return;
default:
break;
@@ -3,6 +3,7 @@
import pl.edu.agh.tinsnake.GPSPoint;
import pl.edu.agh.tinsnake.Map;
import pl.edu.agh.tinsnake.MapHelper;
+import pl.edu.agh.tinsnake.Map.MapSize;
import pl.edu.agh.tinsnake.util.MapWebView;
import android.app.Activity;
import android.app.AlertDialog;
@@ -11,6 +12,8 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
@@ -46,6 +49,7 @@
private Map map;
private LocationManager locationManager;
private AlertDialog deleteAlert;
+ private ProgressDialog progressDialog;
/**
* Called when the activity is first created.
@@ -133,16 +137,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
- case R.id.showClear:
- map.clearLocationHistory();
- try {
- MapHelper.saveMap(map);
- } catch (Exception e) {
- Log.e("CLEAR LOCATION HISTORY", e.getClass().getCanonicalName() + " "
- + e.getMessage());
- return false;
- }
- return true;
+
case R.id.showNewMap:
showPrepareMap();
return true;
@@ -152,26 +147,37 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.showInfo:
downloadMapInfo();
return true;
- case R.id.showSettings:
+ case R.id.showLocation:
Intent intent = new Intent(getApplicationContext(), LocationSettings.class);
-
+ intent.putExtra("map", map);
startActivityForResult(intent, LOCATION_SETTINGS_REQUEST_CODE);
return true;
case R.id.showDeleteMaps:
showDeleteMapsDialog();
return true;
-
case R.id.showLoadMap:
-
showLoadMapDialog();
-
+ return true;
+ case R.id.showExport:
+ exportViewToImage();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
+ private void exportViewToImage() {
+ try {
+ MapSize size = map.getMapSize(webView.getMapZoom());
+ Bitmap b = Bitmap.createBitmap(size.getWidth(), size.getHeight(), Bitmap.Config.ARGB_8888);
+ Canvas c = new Canvas(b);
+ webView.draw(c);
+ MapHelper.saveExport(b, map);
+ } catch (Exception e) {
+ }
+ }
+
private void showLoadMapDialog() {
final String[] items = MapHelper.getMapNames();
@@ -229,6 +235,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 0) {
refreshLocationSettings();
}
+ initializeMapView(map.getName());
break;
case PREPARE_MAP_REQUEST_CODE:
if (resultCode == 0) {
@@ -261,9 +268,17 @@ private void downloadNextZoomLevel() {
final Handler handler = new Handler() {
@Override
public void handleMessage(android.os.Message msg) {
- dismissDialog(PROGRESS_DIALOG);
-
- if (!msg.getData().getBoolean("success")) {
+
+ if (msg.getData().getBoolean("success")){
+ double total = msg.getData().getDouble("total");
+ if (total < 1) {
+ progressDialog.setProgress((int)(100 * total));
+ } else {
+ progressDialog.setProgress(100);
+ dismissDialog(PROGRESS_DIALOG);
+ }
+ } else {
+ dismissDialog(PROGRESS_DIALOG);
showDialog(FAILURE_DIALOG);
}
}
@@ -278,7 +293,7 @@ public void run() {
Bundle bundle = new Bundle();
message.setData(bundle);
try {
- MapHelper.downloadNextZoomLevel(map);
+ MapHelper.downloadNextZoomLevel(map, handler);
MapHelper.saveMap(map);
bundle.putBoolean("success", true);
} catch (Exception e) {
@@ -299,8 +314,9 @@ public void run() {
protected android.app.Dialog onCreateDialog(int id) {
switch (id) {
case PROGRESS_DIALOG:
- ProgressDialog progressDialog = new ProgressDialog(this);
- progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ progressDialog = new ProgressDialog(this);
+ progressDialog.setProgress(0);
+ progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Loading...");
return progressDialog;
case FAILURE_DIALOG:
Oops, something went wrong.

0 comments on commit 68de863

Please sign in to comment.