Permalink
Browse files

User definable unit of distance for map. Closes #12.

  • Loading branch information...
jstaffans committed Mar 18, 2012
1 parent 2bd6e34 commit 0622f490753575e32a5bf019315bb0e692ddc4b7
View
@@ -44,6 +44,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity
+ android:name=".activity.SettingsActivity"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Black.NoTitleBar" >
+ </activity>
<activity
android:name=".activity.AuthenticatorActivity"
android:label="@string/app_name"
View
@@ -47,7 +47,7 @@
android:text="@string/about_2" />
<TextView
- android:id="@+id/txtAboutDetails2"
+ android:id="@+id/txtAboutDetails3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web"
View
@@ -1 +0,0 @@
-{"name":"jstaffans","uid":"18496","fullname":"Johannes Staffans","login":"1327603569","access":"1327603569","created":"1277825855","street":"Street1","city":"Helsinki","province":"es","postal_code":"00100","country":"fi","mobilephone":"555-1234","comments":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus fermentum vulputate est. Etiam laoreet, velit nec luctus vestibulum, lectus risus egestas odio, et blandit tellus lectus consectetur nulla. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis. \r\n","preferred_notice":"1 week","maxcyclists":"2","notcurrentlyavailable":"0","bed":"1","bikeshop":"2 km","campground":"10 km","food":"1","kitchenuse":"1","laundry":"1","lawnspace":"0","motel":"5 km","sag":"0","shower":"1","storage":"1","latitude":"60.226481","longitude":"24.972756"}
View
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<resources>
+
+ <string-array name="distanceUnits">
+ <item name="km">Kilometers</item>
+ <item name="mi">Miles</item>
+ </string-array>
+
+ <string-array name="distanceUnitValues">
+ <item name="km">km</item>
+ <item name="mi">mi</item>
+ </string-array>
+
+</resources>
View
@@ -35,7 +35,7 @@
<string name="error_retrieving_host_information">Could not retrieve host information. Check your credentials and internet connection.</string>
<string name="error_sending_message">Could not send message. Check your credentials and internet connection.</string>
<string name="message_sent">Message sent successfully.</string>
- <string name="about_1">"Developed by Johannes Staffans\njohannes\u0040bitrite.fi, WS: jstaffans"</string>
+ <string name="about_1">"Developed by Johannes Staffans (WS: jstaffans)\njohannes.staffans\u0040gmail.com"</string>
<string name="about_2">"Thanks to Randy Fay and Chris Meyer for support during development.</string>
<string name="about_3">"This application is open source under the Apache 2.0 license. You can help out at:\nhttps://github.com/jstaffans/wsandroid</string>
</resources>
View
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <PreferenceCategory
+ android:title="Map"
+ android:key="map">
+
+ <ListPreference
+ android:key="distance_unit"
+ android:title="Unit of distance"
+ android:summary="Determines in which unit distances should be shown"
+ android:defaultValue="km"
+ android:entries="@array/distanceUnits"
+ android:entryValues="@array/distanceUnitValues" />
+
+ </PreferenceCategory>
+
+</PreferenceScreen>
@@ -106,6 +106,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.menuAccount:
startAuthenticationActivityForExistingAccount();
return true;
+ case R.id.menuSettings:
+ startSettingsActivity();
+ return true;
case R.id.menuAbout:
showAboutDialog();
return true;
@@ -121,6 +124,11 @@ private void startAuthenticationActivityForExistingAccount() {
startAuthenticatorActivity(i);
}
+ private void startSettingsActivity() {
+ Intent i = new Intent(MainActivity.this, SettingsActivity.class);
+ startActivity(i);
+ }
+
private void showAboutDialog() {
splashDialog = new Dialog(this, R.style.about_dialog);
splashDialog.setContentView(R.layout.about);
@@ -8,9 +8,11 @@
import roboguice.inject.InjectView;
import android.app.Dialog;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
@@ -252,15 +254,26 @@ private void showHostPopup(String title, String snippet) {
if (loc1 == null) {
location.setVisibility(View.GONE);
} else {
- float d = loc1.distanceTo(loc2) / 100;
- float km = (Math.round(d)) / 10;
- distance.setText(km + " km as the crow flies");
+ String text = getDistanceText(loc1.distanceTo(loc2));
+ distance.setText(text);
distance.setVisibility(View.VISIBLE);
}
hostPopup.show();
}
+ private String getDistanceText(float d) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ String unit = prefs.getString("distance_unit", "km");
+ if (unit.equals("mi")) {
+ float temp = d / 160.9344f;
+ return (Math.round(temp)) / 10.0f + " miles as the crow flies";
+ } else {
+ float temp = d / 100.0f;
+ return (Math.round(temp)) / 10.0f + " km as the crow flies";
+ }
+ }
+
private void updateStatusMessage(String message, boolean error) {
if (error) {
lblStatusMessage.setTextColor(0xFFFF0000);
@@ -0,0 +1,15 @@
+package fi.bitrite.android.ws.activity;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import fi.bitrite.android.ws.R;
+
+public class SettingsActivity extends PreferenceActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.preferences);
+ }
+
+}
@@ -1,36 +0,0 @@
-package fi.bitrite.android.ws.model;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.json.JSONObject;
-
-import android.content.Context;
-import fi.bitrite.android.ws.R;
-import fi.bitrite.android.ws.WSAndroidApplication;
-
-public class TestHostFactory {
-
- public static Host getHostFromJson() {
- Context context = WSAndroidApplication.getAppContext();
- InputStream inputStream = context.getResources().openRawResource(
- R.raw.jstaffans);
-
- InputStreamReader inputreader = new InputStreamReader(inputStream);
- BufferedReader buffreader = new BufferedReader(inputreader);
-
- String line;
- StringBuilder json = new StringBuilder();
-
- try {
- while ((line = buffreader.readLine()) != null) {
- json.append(line);
- json.append('\n');
- }
- return Host.CREATOR.parse(new JSONObject(json.toString()));
- } catch (Exception e) {
- return null;
- }
- }
-}

0 comments on commit 0622f49

Please sign in to comment.