aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/AndroidManifest.xml2
-rw-r--r--main/res/layout/addresses.xml18
-rw-r--r--main/res/layout/addresses_item.xml32
-rw-r--r--main/src/cgeo/geocaching/AdressListActivity.java84
-rw-r--r--main/src/cgeo/geocaching/cgeoaddresses.java149
-rw-r--r--main/src/cgeo/geocaching/cgeoadvsearch.java2
-rw-r--r--main/src/cgeo/geocaching/ui/AddressListAdapter.java94
-rw-r--r--main/src/cgeo/geocaching/ui/AddressListView.java8
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java14
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListView.java (renamed from main/src/cgeo/geocaching/ui/CacheView.java)2
-rw-r--r--main/src/cgeo/geocaching/ui/GPXListAdapter.java35
-rw-r--r--main/src/cgeo/geocaching/ui/GPXListView.java (renamed from main/src/cgeo/geocaching/ui/GPXView.java)2
12 files changed, 250 insertions, 192 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml
index a9a2835..a64b54a 100644
--- a/main/AndroidManifest.xml
+++ b/main/AndroidManifest.xml
@@ -121,7 +121,7 @@
</intent-filter>
</activity>
<activity
- android:name=".cgeoaddresses"
+ android:name=".AdressListActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden"
android:configChanges="keyboardHidden|orientation" >
diff --git a/main/res/layout/addresses.xml b/main/res/layout/addresses.xml
index 286a0f0..1c7bc81 100644
--- a/main/res/layout/addresses.xml
+++ b/main/res/layout/addresses.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?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"
@@ -10,15 +10,13 @@
<View style="@style/action_bar_separator" />
<TextView style="@style/action_bar_title" />
</LinearLayout>
- <ScrollView
+ <ListView
+ android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:padding="4dip"
- android:orientation="vertical" >
- <LinearLayout android:id="@+id/address_list"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- </LinearLayout>
- </ScrollView>
+ android:layout_margin="0dip"
+ android:padding="0dip"
+ android:dividerHeight="1dip"
+ android:background="?background_color"
+ android:cacheColorHint="?background_color" />
</LinearLayout> \ No newline at end of file
diff --git a/main/res/layout/addresses_item.xml b/main/res/layout/addresses_item.xml
new file mode 100644
index 0000000..0699a6f
--- /dev/null
+++ b/main/res/layout/addresses_item.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/button_map"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:layout_margin="3dip"
+ android:paddingLeft="5dip"
+ android:paddingRight="5dip"
+ android:paddingBottom="7dip"
+ android:paddingTop="7dip"
+ android:orientation="vertical"
+ android:background="?background_color" >
+ <TextView android:id="@+id/label"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:scrollHorizontally="true"
+ android:textSize="22dip"
+ android:gravity="left"
+ android:singleLine="false"
+ android:ellipsize="marquee"
+ android:textColor="?text_color" />
+ <TextView android:id="@+id/distance"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:scrollHorizontally="true"
+ android:textSize="12dip"
+ android:gravity="left"
+ android:lines="1"
+ android:singleLine="true"
+ android:ellipsize="marquee"
+ android:textColor="?text_color" />
+</LinearLayout> \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/AdressListActivity.java b/main/src/cgeo/geocaching/AdressListActivity.java
new file mode 100644
index 0000000..5c88c6a
--- /dev/null
+++ b/main/src/cgeo/geocaching/AdressListActivity.java
@@ -0,0 +1,84 @@
+package cgeo.geocaching;
+
+import cgeo.geocaching.activity.AbstractListActivity;
+import cgeo.geocaching.ui.AddressListAdapter;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import android.app.ProgressDialog;
+import android.location.Address;
+import android.location.Geocoder;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.Log;
+
+import java.util.List;
+import java.util.Locale;
+
+public class AdressListActivity extends AbstractListActivity {
+ private String keyword = null;
+ private ProgressDialog waitDialog = null;
+ private AddressListAdapter adapter;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setTheme();
+ setContentView(R.layout.addresses);
+ setTitle(res.getString(R.string.search_address_result));
+
+ // get parameters
+ Bundle extras = getIntent().getExtras();
+
+ // try to get data from extras
+ if (extras != null) {
+ keyword = extras.getString("keyword");
+ }
+
+ if (keyword == null) {
+ showToast(res.getString(R.string.err_search_address_forgot));
+ finish();
+ return;
+ }
+
+ adapter = new AddressListAdapter(this);
+ setListAdapter(adapter);
+
+ waitDialog = ProgressDialog.show(this, res.getString(R.string.search_address_started), keyword, true);
+ waitDialog.setCancelable(true);
+
+ new AsyncTask<Void, Void, List<Address>>() {
+
+ @Override
+ protected List<Address> doInBackground(Void... params) {
+ final Geocoder geocoder = new Geocoder(AdressListActivity.this, Locale.getDefault());
+ try {
+ return geocoder.getFromLocationName(keyword, 20);
+ } catch (Exception e) {
+ Log.e(Settings.tag, "AdressListActivity.doInBackground", e);
+ return null;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(final List<Address> addresses) {
+ waitDialog.dismiss();
+ try {
+ if (CollectionUtils.isEmpty(addresses)) {
+ showToast(res.getString(R.string.err_search_address_no_match));
+ finish();
+ return;
+ } else {
+ for (Address address : addresses) {
+ adapter.add(address); // don't use addAll, it's only available with API >= 11
+ }
+ }
+ } catch (Exception e) {
+ Log.e(Settings.tag, "AdressListActivity.onPostExecute", e);
+ }
+ }
+
+ }.execute();
+ }
+} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/cgeoaddresses.java b/main/src/cgeo/geocaching/cgeoaddresses.java
deleted file mode 100644
index 9170a4a..0000000
--- a/main/src/cgeo/geocaching/cgeoaddresses.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package cgeo.geocaching;
-
-import cgeo.geocaching.activity.AbstractActivity;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.HumanDistance;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-
-import android.app.ProgressDialog;
-import android.location.Address;
-import android.location.Geocoder;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.Button;
-import android.widget.LinearLayout;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
-public class cgeoaddresses extends AbstractActivity {
- private String keyword = null;
- private LayoutInflater inflater = null;
- private LinearLayout addList = null;
- private ProgressDialog waitDialog = null;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // init
- inflater = getLayoutInflater();
-
- setTheme();
- setContentView(R.layout.addresses);
- setTitle(res.getString(R.string.search_address_result));
-
- // get parameters
- Bundle extras = getIntent().getExtras();
-
- // try to get data from extras
- if (extras != null) {
- keyword = extras.getString("keyword");
- }
-
- if (keyword == null) {
- showToast(res.getString(R.string.err_search_address_forgot));
- finish();
- return;
- }
-
- waitDialog = ProgressDialog.show(this, res.getString(R.string.search_address_started), keyword, true);
- waitDialog.setCancelable(true);
-
- new AsyncTask<Void, Void, List<Address>>() {
-
- @Override
- protected List<Address> doInBackground(Void... params) {
- final Geocoder geocoder = new Geocoder(cgeoaddresses.this, Locale.getDefault());
- try {
- return geocoder.getFromLocationName(keyword, 20);
- } catch (Exception e) {
- Log.e(Settings.tag, "cgeoaddresses.doInBackground", e);
- return null;
- }
- }
-
- @Override
- protected void onPostExecute(final List<Address> addresses) {
- waitDialog.dismiss();
- try {
- if (addList == null) {
- addList = (LinearLayout) findViewById(R.id.address_list);
- }
-
- if (CollectionUtils.isEmpty(addresses)) {
- showToast(res.getString(R.string.err_search_address_no_match));
- finish();
- return;
- } else {
- LinearLayout oneAddPre = null;
- final Geopoint lastLoc = cgeoapplication.getInstance().getLastCoords();
- for (Address address : addresses) {
- oneAddPre = (LinearLayout) inflater.inflate(R.layout.address_button, null);
-
- Button oneAdd = (Button) oneAddPre.findViewById(R.id.button);
-
- final int maxIndex = address.getMaxAddressLineIndex();
- final ArrayList<String> lines = new ArrayList<String>();
- for (int i = 0; i <= maxIndex; i++) {
- String line = address.getAddressLine(i);
- if (StringUtils.isNotBlank(line)) {
- lines.add(line);
- }
- }
-
- final String listTitle = StringUtils.join(lines, "; ");
-
- if (lastLoc != null) {
- if (address.hasLatitude() && address.hasLongitude()) {
- lines.add(HumanDistance.getHumanDistance(lastLoc.distanceTo(new Geopoint(address.getLatitude(), address.getLongitude()))));
- }
- }
-
- oneAdd.setText(StringUtils.join(lines, "\n"));
- oneAdd.setLines(lines.size());
- oneAdd.setClickable(true);
-
- oneAdd.setOnClickListener(new buttonListener(address.getLatitude(), address.getLongitude(), listTitle));
- addList.addView(oneAddPre);
- }
- }
- } catch (Exception e) {
- Log.e(Settings.tag, "cgeoaddresses.onPostExecute", e);
- }
- }
-
- }.execute();
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
- }
-
- private class buttonListener implements View.OnClickListener {
-
- private final double latitude;
- private final double longitude;
- private final String address;
-
- public buttonListener(double latitudeIn, double longitudeIn, String addressIn) {
- latitude = latitudeIn;
- longitude = longitudeIn;
- address = addressIn;
- }
-
- public void onClick(View arg0) {
- cgeocaches.startActivityAddress(cgeoaddresses.this, latitude, longitude, address);
- finish();
- return;
- }
- }
-}
diff --git a/main/src/cgeo/geocaching/cgeoadvsearch.java b/main/src/cgeo/geocaching/cgeoadvsearch.java
index 7256bb3..97d3a08 100644
--- a/main/src/cgeo/geocaching/cgeoadvsearch.java
+++ b/main/src/cgeo/geocaching/cgeoadvsearch.java
@@ -352,7 +352,7 @@ public class cgeoadvsearch extends AbstractActivity {
return;
}
- final Intent addressesIntent = new Intent(this, cgeoaddresses.class);
+ final Intent addressesIntent = new Intent(this, AdressListActivity.class);
addressesIntent.putExtra("keyword", addText);
startActivity(addressesIntent);
}
diff --git a/main/src/cgeo/geocaching/ui/AddressListAdapter.java b/main/src/cgeo/geocaching/ui/AddressListAdapter.java
new file mode 100644
index 0000000..e557882
--- /dev/null
+++ b/main/src/cgeo/geocaching/ui/AddressListAdapter.java
@@ -0,0 +1,94 @@
+package cgeo.geocaching.ui;
+
+import cgeo.geocaching.R;
+import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.cgeocaches;
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.HumanDistance;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.app.Activity;
+import android.content.Context;
+import android.location.Address;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+
+public class AddressListAdapter extends ArrayAdapter<Address> {
+
+ private LayoutInflater inflater;
+ private AddressListView holder;
+ private Geopoint location;
+
+ public AddressListAdapter(final Context context) {
+ super(context, 0);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (inflater == null) {
+ inflater = ((Activity) getContext()).getLayoutInflater();
+ }
+
+ final Address address = getItem(position);
+
+ // holder pattern implementation
+ View view = convertView;
+ if (view == null) {
+ view = inflater.inflate(R.layout.addresses_item, null);
+
+ holder = new AddressListView();
+ holder.label = (TextView) view.findViewById(R.id.label);
+ holder.distance = (TextView) view.findViewById(R.id.distance);
+
+ view.setTag(holder);
+ } else {
+ holder = (AddressListView) view.getTag();
+ }
+
+ view.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Activity activity = (Activity) v.getContext();
+ cgeocaches.startActivityAddress(activity, address.getLatitude(), address.getLongitude(), StringUtils.defaultString(address.getAddressLine(0)));
+ activity.finish();
+ }
+ });
+
+ holder.label.setText(getAddressText(address));
+ holder.distance.setText(getDistanceText(address));
+
+ return view;
+ }
+
+ private CharSequence getDistanceText(final Address address) {
+ if (location == null) {
+ location = cgeoapplication.getInstance().getLastCoords();
+ }
+
+ if (location != null && address.hasLatitude() && address.hasLongitude()) {
+ return HumanDistance.getHumanDistance(location.distanceTo(new Geopoint(address.getLatitude(), address.getLongitude())));
+ }
+
+ return "";
+ }
+
+ private static CharSequence getAddressText(final Address address) {
+ final int maxIndex = address.getMaxAddressLineIndex();
+ final ArrayList<String> lines = new ArrayList<String>();
+ for (int i = 0; i <= maxIndex; i++) {
+ String line = address.getAddressLine(i);
+ if (StringUtils.isNotBlank(line)) {
+ lines.add(line);
+ }
+ }
+
+ return StringUtils.join(lines, "\n");
+ }
+} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/ui/AddressListView.java b/main/src/cgeo/geocaching/ui/AddressListView.java
new file mode 100644
index 0000000..53459ed
--- /dev/null
+++ b/main/src/cgeo/geocaching/ui/AddressListView.java
@@ -0,0 +1,8 @@
+package cgeo.geocaching.ui;
+
+import android.widget.TextView;
+
+public class AddressListView {
+ public TextView label;
+ public TextView distance;
+}
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index 7d32baa..1a53945 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -60,7 +60,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
final private Resources res;
/** Resulting list of caches */
final private List<cgCache> list;
- private CacheView holder = null;
+ private CacheListView holder = null;
private LayoutInflater inflater = null;
private CacheComparator cacheComparator = null;
private Geopoint coords = null;
@@ -387,7 +387,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
if (v == null) {
v = inflater.inflate(R.layout.cache, null);
- holder = new CacheView();
+ holder = new CacheListView();
holder.checkbox = (CheckBox) v.findViewById(R.id.checkbox);
holder.oneInfo = (RelativeLayout) v.findViewById(R.id.one_info);
holder.oneCheckbox = (RelativeLayout) v.findViewById(R.id.one_checkbox);
@@ -404,7 +404,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
v.setTag(holder);
} else {
- holder = (CacheView) v.getTag();
+ holder = (CacheListView) v.getTag();
}
if (cache.isOwn()) {
@@ -729,10 +729,10 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
class detectGesture extends GestureDetector.SimpleOnGestureListener {
- private CacheView holder = null;
+ private CacheListView holder = null;
private cgCache cache = null;
- public detectGesture(CacheView holderIn, cgCache cacheIn) {
+ public detectGesture(CacheListView holderIn, cgCache cacheIn) {
holder = holderIn;
cache = cacheIn;
}
@@ -799,7 +799,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
}
}
- private void moveRight(CacheView holder, cgCache cache, boolean force) {
+ private void moveRight(CacheListView holder, cgCache cache, boolean force) {
if (cache == null) {
return;
}
@@ -834,7 +834,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
cache.setStatusCheckedView(true);
}
- private void moveLeft(CacheView holder, cgCache cache, boolean force) {
+ private void moveLeft(CacheListView holder, cgCache cache, boolean force) {
if (cache == null) {
return;
}
diff --git a/main/src/cgeo/geocaching/ui/CacheView.java b/main/src/cgeo/geocaching/ui/CacheListView.java
index 7fba55d..ca5d23d 100644
--- a/main/src/cgeo/geocaching/ui/CacheView.java
+++ b/main/src/cgeo/geocaching/ui/CacheListView.java
@@ -6,7 +6,7 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
-public class CacheView {
+public class CacheListView {
// layouts & views
public RelativeLayout oneInfo;
public RelativeLayout oneCheckbox;
diff --git a/main/src/cgeo/geocaching/ui/GPXListAdapter.java b/main/src/cgeo/geocaching/ui/GPXListAdapter.java
index 2f50e6c..2ebb893 100644
--- a/main/src/cgeo/geocaching/ui/GPXListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/GPXListAdapter.java
@@ -17,14 +17,14 @@ import java.io.File;
import java.util.List;
public class GPXListAdapter extends ArrayAdapter<File> {
- private GPXView holder = null;
- private cgeogpxes parent = null;
+ private GPXListView holder = null;
+ private cgeogpxes activity = null;
private LayoutInflater inflater = null;
public GPXListAdapter(cgeogpxes parentIn, List<File> listIn) {
super(parentIn, 0, listIn);
- parent = parentIn;
+ activity = parentIn;
}
@Override
@@ -38,42 +38,33 @@ public class GPXListAdapter extends ArrayAdapter<File> {
return null;
}
- File file = getItem(position);
+ final File file = getItem(position);
View v = rowView;
if (v == null) {
v = inflater.inflate(R.layout.gpx_item, null);
- holder = new GPXView();
+ holder = new GPXListView();
holder.filepath = (TextView) v.findViewById(R.id.filepath);
holder.filename = (TextView) v.findViewById(R.id.filename);
v.setTag(holder);
} else {
- holder = (GPXView) v.getTag();
+ holder = (GPXListView) v.getTag();
}
- final touchListener touchLst = new touchListener(file);
- v.setOnClickListener(touchLst);
+ v.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ (new GPXImporter(activity, activity.getListId(), null)).importGPX(file);
+ }
+ });
holder.filepath.setText(file.getParent());
holder.filename.setText(file.getName());
return v;
}
-
- private class touchListener implements View.OnClickListener {
- private File file = null;
-
- public touchListener(File fileIn) {
- file = fileIn;
- }
-
- // tap on item
- @Override
- public void onClick(View view) {
- (new GPXImporter(parent, parent.getListId(), null)).importGPX(file);
- }
- }
}
diff --git a/main/src/cgeo/geocaching/ui/GPXView.java b/main/src/cgeo/geocaching/ui/GPXListView.java
index a93d0db..d2d0766 100644
--- a/main/src/cgeo/geocaching/ui/GPXView.java
+++ b/main/src/cgeo/geocaching/ui/GPXListView.java
@@ -2,7 +2,7 @@ package cgeo.geocaching.ui;
import android.widget.TextView;
-public class GPXView {
+public class GPXListView {
// layouts & views
public TextView filepath;
public TextView filename;