diff --git a/res/layout/nearby_operator_row.xml b/res/layout/nearby_operator_row.xml index 396acb7..a7864a9 100644 --- a/res/layout/nearby_operator_row.xml +++ b/res/layout/nearby_operator_row.xml @@ -21,7 +21,7 @@ android:layout_marginLeft="12dip" android:text="9W2WTF" android:textColor="@color/text_color" - android:textSize="18sp" /> + android:textSize="24sp" /> > listrakanradio; @@ -113,7 +114,8 @@ protected void onCreate(Bundle savedInstanceState) { if (map == null) { - Log.e("Map NULL", "MAP NULL"); + //Log.e("Map NULL", "MAP NULL"); + Toast.makeText(this, "Unable to display Map", Toast.LENGTH_SHORT).show(); } else { @@ -134,10 +136,11 @@ protected void onCreate(Bundle savedInstanceState) { // counter i, for mapping marker with integer int i = 0; - - Iterator iter = rl.iterator(); - while (iter.hasNext()) { - Repeater repeater = iter.next(); + + int counter = rl.size(); + Repeater repeater; + for(int j=0;j inforakanradio = listrakanradio.get(mio.getIndex()); - /* - * inforakanradio.put("callsign", callsign); - * inforakanradio.put("name", jsinfo.getString("name")); - * inforakanradio.put("qsx", jsinfo.getString("qsx")); - * inforakanradio.put("status", jsinfo.getString("status")); - * inforakanradio.put("distance", jsinfo.getString("distance")); - * inforakanradio.put("time", jsinfo.getString("time")); - * inforakanradio.put("lat", jsinfo.getString("lat")); - * inforakanradio.put("lng", jsinfo.getString("lng")); - * inforakanradio.put("valid", valid); - * inforakanradio.put("deviceid", jsinfo.getString("deviceid")); - * inforakanradio.put("phoneno",jsinfo.getString("phoneno")); - * inforakanradio.put("client",jsinfo.getString("client")); - * inforakanradio.put("locality",jsinfo.getString("locality")); - */ + + intent.putExtra("callsign", inforakanradio.get("callsign")); intent.putExtra("name", inforakanradio.get("name")); @@ -316,6 +308,133 @@ protected void onPause() { super.onPause(); overridePendingTransition(R.anim.activity_open_scale, R.anim.activity_close_translate); + } + + //load data from Preference cache rather from getuser info + public void loadfromCache(String jsonCache) { + + listrakanradio = new ArrayList>(200); + + if (jsonCache != null) { + try { + // JSONObject jsonObj = new JSONObject(jsonStr); + + rakanradio = new JSONArray(jsonCache); + int num_of_rakanradio = rakanradio.length(); + for (int i = 0; i < num_of_rakanradio; i++) { + JSONObject jsinfo = rakanradio.getJSONObject(i); + + String callsign = jsinfo.getString("callsign"); + + + String valid = jsinfo.getString("valid"); + + HashMap inforakanradio = new HashMap(); + + int validity = Integer.parseInt(valid); + + if (validity == 0) { + callsign = callsign + " (Unverified)"; + } + + inforakanradio.put("callsign", callsign); + inforakanradio.put("name", jsinfo.getString("name")); + inforakanradio.put("qsx", jsinfo.getString("qsx")); + inforakanradio.put("status", jsinfo.getString("status")); + inforakanradio.put("distance", jsinfo.getString("distance")); + inforakanradio.put("time", jsinfo.getString("time")); + inforakanradio.put("lat", jsinfo.getString("lat")); + inforakanradio.put("lng", jsinfo.getString("lng")); + inforakanradio.put("valid", valid); + inforakanradio.put("deviceid", jsinfo.getString("deviceid")); + inforakanradio.put("phoneno", jsinfo.getString("phoneno")); + inforakanradio.put("client", jsinfo.getString("client")); + inforakanradio.put("locality", jsinfo.getString("locality")); + + listrakanradio.add(inforakanradio); + + + + } + } catch (JSONException jse) { + jse.printStackTrace(); + } + + } else { + Log.e("mypapit ServiceHandler-cache", "Couldn't get any data from map cache :("); + } + + + Iterator> iter = listrakanradio.iterator(); + + HashMap inforakanradio; + + + + int callsignIndex = 0; + + SharedPreferences repeater_prefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()); + + String m_deviceid = repeater_prefs.getString("deviceid", "defaultx"); + + while (iter.hasNext()) { + inforakanradio = new HashMap(); + inforakanradio = iter.next(); + + MarkerOptions marking = new MarkerOptions(); + + // java.util.Date utilDate = new java.util.Date(); + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + java.util.Date time = new java.util.Date(); + + try { + time = formatter.parse(inforakanradio.get("time")); + } catch (ParseException e) { + time = new java.util.Date(); + + e.printStackTrace(); + } + + FuzzyDateFormatter format = FuzzyDateFormat.getInstance(); + + marking.position(new LatLng(Double.parseDouble(inforakanradio.get("lat")), Double + .parseDouble(inforakanradio.get("lng")))); + marking.title(new StringBuilder(inforakanradio.get("callsign")).append(" - ") + .append(format.formatDistance(time)).toString()); + marking.snippet(new StringBuilder("@").append(inforakanradio.get("name")).append("\n#:") + .append(inforakanradio.get("status")).append("\n").append(inforakanradio.get("phoneno")) + .append("\n").append(inforakanradio.get("client")).toString()); + + CallsignMapInfo cmi = new CallsignMapInfo(); + + + String valid = inforakanradio.get("valid"); + String deviceId = inforakanradio.get("deviceid"); + + + + if (Integer.parseInt(valid) == 1) { + marking.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)); + } else { + marking.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)); + } + + + if (deviceId.equalsIgnoreCase(m_deviceid)) { + marking.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)); + + } + + cmi.setIndex(callsignIndex); + + hashMap.put(map.addMarker(marking), cmi); + + callsignIndex++; + + } + + } // private class AsyncTask for retrieving repeater-my user information @@ -323,18 +442,22 @@ protected void onPause() { private class GetUserInfo extends AsyncTask { String currentlat, currentlng; + DisplayMap activity; + String jsonstringcache; - GetUserInfo(LatLng latlng) { + GetUserInfo(LatLng latlng,DisplayMap activity) { currentlat = latlng.latitude + ""; currentlng = latlng.longitude + ""; + this.activity = activity; } + @Override protected void onPreExecute() { super.onPreExecute(); - // put a dialog or whatsoever + Toast.makeText(activity, "Getting stations info from servers",Toast.LENGTH_SHORT).show(); } @@ -366,23 +489,6 @@ protected Void doInBackground(Void... params) { String callsign = jsinfo.getString("callsign"); - /* - * debug use only, now we shortcut String callsign = - * jsinfo.getString("callsign"); String name = - * jsinfo.getString("name"); String qsx = - * jsinfo.getString("qsx"); String status = - * jsinfo.getString("status"); - * - * String distance = jsinfo.getString("distance"); - * String time = jsinfo.getString("time"); String lat = - * jsinfo.getString("lat"); String lng = - * jsinfo.getString("lng"); String valid = - * jsinfo.getString("valid"); String deviceid = - * jsinfo.getString("deviceid"); String phoneno = - * jsinfo.getString("phoneno"); String rmyclient = - * jsinfo.getString("client"); - */ - String valid = jsinfo.getString("valid"); HashMap inforakanradio = new HashMap(); @@ -408,6 +514,8 @@ protected Void doInBackground(Void... params) { inforakanradio.put("locality", jsinfo.getString("locality")); listrakanradio.add(inforakanradio); + + jsonstringcache = jsonStr; } } catch (JSONException jse) { @@ -423,12 +531,29 @@ protected Void doInBackground(Void... params) { protected void onPostExecute(Void result) { super.onPostExecute(result); + + if ( (listrakanradio.size() >0) && (jsonstringcache != null) ){ + SharedPreferences.Editor editor = cache.edit(); + editor.putLong(activity.CACHE_TIME, new Date().getTime()); + editor.putString(activity.CACHE_JSON, jsonstringcache); + + editor.commit(); + + } + Iterator> iter = listrakanradio.iterator(); + HashMap inforakanradio; + + SharedPreferences repeater_prefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()); + + String m_deviceid = repeater_prefs.getString("deviceid", "defaultx"); + int callsignIndex = 0; while (iter.hasNext()) { - HashMap inforakanradio = new HashMap(); + inforakanradio = new HashMap(); inforakanradio = iter.next(); MarkerOptions marking = new MarkerOptions(); @@ -455,32 +580,19 @@ protected void onPostExecute(Void result) { .append(inforakanradio.get("status")).append("\n").append(inforakanradio.get("phoneno")) .append("\n").append(inforakanradio.get("client")).toString()); - CallsignMapInfo cmi = new CallsignMapInfo(inforakanradio.get("callsign"), - Double.parseDouble(inforakanradio.get("lat")), Double.parseDouble(inforakanradio.get("lng"))); - cmi.setHandle(inforakanradio.get("name")); - - DecimalFormat df = new DecimalFormat("#.##"); - - cmi.setDistance(df.format(Double.parseDouble(inforakanradio.get("distance")))); - cmi.setTime(format.formatDistance(time)); - - cmi.setStatus(inforakanradio.get("status")); - cmi.setDeviceId(inforakanradio.get("deviceid")); - + CallsignMapInfo cmi = new CallsignMapInfo(); + + String valid = inforakanradio.get("valid"); String deviceId = inforakanradio.get("deviceid"); - cmi.setVerified(valid); if (Integer.parseInt(valid) == 1) { marking.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)); } else { marking.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)); } - SharedPreferences repeater_prefs = PreferenceManager - .getDefaultSharedPreferences(getApplicationContext()); - - String m_deviceid = repeater_prefs.getString("deviceid", "defaultx"); + if (deviceId.equalsIgnoreCase(m_deviceid)) { marking.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)); @@ -497,9 +609,9 @@ protected void onPostExecute(Void result) { } - } + } //GetUserInfo -} +} //Display Map Activity class ServiceHandler { diff --git a/src/net/mypapit/mobile/myrepeater/HamOperator.java b/src/net/mypapit/mobile/myrepeater/HamOperator.java index ab4ba72..cf987f1 100644 --- a/src/net/mypapit/mobile/myrepeater/HamOperator.java +++ b/src/net/mypapit/mobile/myrepeater/HamOperator.java @@ -1,14 +1,10 @@ package net.mypapit.mobile.myrepeater; import java.io.Serializable; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.Date; import net.sf.jfuzzydate.FuzzyDateFormat; import net.sf.jfuzzydate.FuzzyDateFormatter; - import android.location.Location; import android.os.Parcelable; diff --git a/src/net/mypapit/mobile/myrepeater/NearbyOperatorActivity.java b/src/net/mypapit/mobile/myrepeater/NearbyOperatorActivity.java index 3357d7b..ad5676e 100644 --- a/src/net/mypapit/mobile/myrepeater/NearbyOperatorActivity.java +++ b/src/net/mypapit/mobile/myrepeater/NearbyOperatorActivity.java @@ -1,57 +1,34 @@ package net.mypapit.mobile.myrepeater; -import java.io.IOException; -import java.io.UnsupportedEncodingException; + import java.text.DateFormat; -import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import java.util.Iterator; import java.util.List; -import java.util.Map; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; -import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdView; -import com.google.android.gms.maps.model.BitmapDescriptorFactory; -import com.google.android.gms.maps.model.LatLng; -import com.google.android.gms.maps.model.MarkerOptions; - -import net.mypapit.mobile.myrepeater.R; -import net.mypapit.mobile.myrepeater.mapinfo.CallsignMapInfo; -import net.sf.jfuzzydate.FuzzyDateFormat; -import net.sf.jfuzzydate.FuzzyDateFormatter; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; -import android.preference.PreferenceManager; import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; -import android.widget.SimpleAdapter; import android.widget.TextView; +import com.google.android.gms.maps.model.LatLng; + public class NearbyOperatorActivity extends Activity implements OnItemClickListener { private ListView listview; @@ -61,19 +38,20 @@ public class NearbyOperatorActivity extends Activity implements OnItemClickListe private static String URL = "http://api.repeater.my/v1/nearbyoperator.php"; private double mlat, mlng; private String mlocation; - - - + public final String CACHE_PREFS = "cache-prefs"; + public final String CACHE_TIME = "cache-time-"; + public final String CACHE_JSON = "cache-json-"; + SharedPreferences cache; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.nearby_operator_list); overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale); - + Bundle bundle = this.getIntent().getExtras(); - - mlocation=bundle.getString("location"); + + mlocation = bundle.getString("location"); mlat = bundle.getDouble("lat"); mlng = bundle.getDouble("lng"); @@ -84,29 +62,110 @@ protected void onCreate(Bundle savedInstanceState) { } tvNearby = (TextView) findViewById(R.id.tvNearbyRepeater); - + tvNearby.setText("Active stations near " + toTitleCase(mlocation.toLowerCase())); listview = (ListView) findViewById(R.id.HamOperatorListView); - - holist = new HamOperatorList(120); - - - new GetUserInfo(this,new LatLng(mlat,mlng)).execute(); - - adapter = new NearbyOperatorAdapter(this,holist); - + + adapter = new NearbyOperatorAdapter(this, holist); + listview.setAdapter(adapter); - + cache = this.getSharedPreferences(CACHE_PREFS, 0); + + Date cachedate = new Date(cache.getLong(CACHE_TIME + mlocation, new Date(20000).getTime())); + + long secs = (new Date().getTime() - cachedate.getTime()) / 1000; + long hours = secs / 3600L; + secs = secs % 3600L; + long mins = secs / 60L; + + if (hours < 6) { + String jsoncache = cache.getString(CACHE_JSON + mlocation, "none"); + if (jsoncache.compareToIgnoreCase("none") == 0) { + new GetUserInfo(this, new LatLng(mlat, mlng)).execute(); + } else { + + loadfromCache(jsoncache); + } + + } else { + + new GetUserInfo(this, new LatLng(mlat, mlng)).execute(); + + } + listview.setOnItemClickListener(this); - - + } + + public void loadfromCache(String jsonCache) { + JSONArray rakanradio = null; + try { + // JSONObject jsonObj = new JSONObject(jsonStr); + + rakanradio = new JSONArray(jsonCache); + int num_of_rakanradio = rakanradio.length(); + for (int i = 0; i < num_of_rakanradio; i++) { + JSONObject jsinfo = rakanradio.getJSONObject(i); + + String callsign = jsinfo.getString("callsign"); + + String valid = jsinfo.getString("valid"); + + int validity = Integer.parseInt(valid); + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + java.util.Date time = new java.util.Date(); + try { + time = formatter.parse(jsinfo.getString("time")); + } catch (ParseException e) { + time = new java.util.Date(); + + e.printStackTrace(); + } + + double holat, holng; + try { + + holat = Double.parseDouble(jsinfo.getString("lat")); + holng = Double.parseDouble(jsinfo.getString("lng")); + } catch (Exception ex) { + + holat = 37.0; + holng = 115.0; + + } + /* + * (String callsign, String handle, String status, String + * phoneno, String locality, String client, String deviceid, + * String qsx, Date date, double lat, double lng, boolean valid + */ + HamOperator hamoperator = new HamOperator(callsign, jsinfo.getString("name"), + jsinfo.getString("status"), jsinfo.getString("phoneno"), jsinfo.getString("locality"), + jsinfo.getString("client"), jsinfo.getString("deviceid"), jsinfo.getString("qsx"), time, + jsinfo.getString("time"), holat, holng, (validity < 1) ? false : true + + ); + + try { + hamoperator.setActiveNo(Integer.parseInt(jsinfo.getString("total"))); + } catch (Exception ex) { + + hamoperator.setActiveNo(1); + ex.printStackTrace(); + + } + + holist.add(hamoperator); + + } + } catch (JSONException jse) { + jse.printStackTrace(); + } } @@ -122,30 +181,29 @@ public boolean onOptionsItemSelected(MenuItem item) { finish(); } - } return false; } public static String toTitleCase(String input) { - StringBuilder titleCase = new StringBuilder(); - boolean nextTitleCase = true; - - for (char c : input.toCharArray()) { - if (Character.isSpaceChar(c)) { - nextTitleCase = true; - } else if (nextTitleCase) { - c = Character.toTitleCase(c); - nextTitleCase = false; - } + StringBuilder titleCase = new StringBuilder(); + boolean nextTitleCase = true; + + for (char c : input.toCharArray()) { + if (Character.isSpaceChar(c)) { + nextTitleCase = true; + } else if (nextTitleCase) { + c = Character.toTitleCase(c); + nextTitleCase = false; + } - titleCase.append(c); - } + titleCase.append(c); + } - return titleCase.toString(); + return titleCase.toString(); } - + protected void onPause() { super.onPause(); @@ -153,35 +211,32 @@ protected void onPause() { } - public void onItemClick(AdapterView parent, View view, int position, long id) { Intent intent = new Intent(this.getApplicationContext(), CallsignDetailsActivity.class); - - HamOperator hop = adapter.getHamOperator(position); - - //phoneno,status,name,locality,client,callsign,time - + HamOperator hop = adapter.getHamOperator(position); + + // phoneno,status,name,locality,client,callsign,time + intent.putExtra("phoneno", hop.getPhoneno()); intent.putExtra("status", hop.getStatus()); intent.putExtra("locality", hop.getLocality()); intent.putExtra("client", hop.getClient()); - intent.putExtra("callsign",hop.getCallsign()); - intent.putExtra("time",hop.getStrDate()); + intent.putExtra("callsign", hop.getCallsign()); + intent.putExtra("time", hop.getStrDate()); intent.putExtra("name", hop.getHandle()); - - - + startActivity(intent); - + } private class GetUserInfo extends AsyncTask { String currentlat, currentlng; - Activity activity; + NearbyOperatorActivity activity; + String jsonStr; - GetUserInfo(Activity activity, LatLng latlng) { + GetUserInfo(NearbyOperatorActivity activity, LatLng latlng) { this.activity = activity; currentlat = latlng.latitude + ""; currentlng = latlng.longitude + ""; @@ -207,11 +262,11 @@ protected Void doInBackground(Void... params) { nameValuePairs.add(new BasicNameValuePair("lat", currentlat)); nameValuePairs.add(new BasicNameValuePair("lng", currentlng)); - String jsonStr = sh.makeServiceCall(URL, ServiceHandler.GET, nameValuePairs); + jsonStr = sh.makeServiceCall(URL, ServiceHandler.GET, nameValuePairs); // Log.d("mypapit Json Response: ", "> " + jsonStr); - //listrakanradio = new ArrayList>(200); + // listrakanradio = new ArrayList>(200); JSONArray rakanradio = null; if (jsonStr != null) { @@ -225,33 +280,12 @@ protected Void doInBackground(Void... params) { String callsign = jsinfo.getString("callsign"); - /* - * debug use only, now we shortcut String callsign = - * jsinfo.getString("callsign"); String name = - * jsinfo.getString("name"); String qsx = - * jsinfo.getString("qsx"); String status = - * jsinfo.getString("status"); - * - * String distance = jsinfo.getString("distance"); - * String time = jsinfo.getString("time"); String lat = - * jsinfo.getString("lat"); String lng = - * jsinfo.getString("lng"); String valid = - * jsinfo.getString("valid"); String deviceid = - * jsinfo.getString("deviceid"); String phoneno = - * jsinfo.getString("phoneno"); String rmyclient = - * jsinfo.getString("client"); - */ - String valid = jsinfo.getString("valid"); - HashMap inforakanradio = new HashMap(); - - - + int validity = Integer.parseInt(valid); - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date time = new java.util.Date(); @@ -263,50 +297,39 @@ protected Void doInBackground(Void... params) { e.printStackTrace(); } - double holat,holng; + double holat, holng; try { - holat=Double.parseDouble(jsinfo.getString("lat")); - holng=Double.parseDouble(jsinfo.getString("lng")); - } catch (Exception ex){ + holat = Double.parseDouble(jsinfo.getString("lat")); + holng = Double.parseDouble(jsinfo.getString("lng")); + } catch (Exception ex) { - holat=37.0; - holng=115.0; + holat = 37.0; + holng = 115.0; } /* - (String callsign, String handle, String status, String phoneno, String locality, String client, - String deviceid, String qsx, Date date, double lat, double lng, boolean valid + * (String callsign, String handle, String status, + * String phoneno, String locality, String client, + * String deviceid, String qsx, Date date, double lat, + * double lng, boolean valid */ - HamOperator hamoperator = new HamOperator( - callsign, - jsinfo.getString("name"), - jsinfo.getString("status"), - jsinfo.getString("phoneno"), - jsinfo.getString("locality"), - jsinfo.getString("client"), - jsinfo.getString("deviceid"), - jsinfo.getString("qsx"), - time, - jsinfo.getString("time"), - holat, - holng, - (validity < 1) ? false:true + HamOperator hamoperator = new HamOperator(callsign, jsinfo.getString("name"), + jsinfo.getString("status"), jsinfo.getString("phoneno"), jsinfo.getString("locality"), + jsinfo.getString("client"), jsinfo.getString("deviceid"), jsinfo.getString("qsx"), + time, jsinfo.getString("time"), holat, holng, (validity < 1) ? false : true ); try { - hamoperator.setActiveNo( Integer.parseInt(jsinfo.getString("total")) ); + hamoperator.setActiveNo(Integer.parseInt(jsinfo.getString("total"))); } catch (Exception ex) { - + hamoperator.setActiveNo(1); ex.printStackTrace(); - - } - - + } holist.add(hamoperator); @@ -325,14 +348,21 @@ protected Void doInBackground(Void... params) { protected void onPostExecute(Void result) { super.onPostExecute(result); - adapter = new NearbyOperatorAdapter(activity,holist); + adapter = new NearbyOperatorAdapter(activity, holist); listview.setAdapter(adapter); adapter.notifyDataSetChanged(); - + + if ((holist.size() > 0) && (jsonStr != null)) { + SharedPreferences.Editor editor = cache.edit(); + editor.putLong(activity.CACHE_TIME + mlocation, new Date().getTime()); + editor.putString(activity.CACHE_JSON + mlocation, jsonStr); + + editor.commit(); + + } } } } - diff --git a/src/net/mypapit/mobile/myrepeater/NearbyOperatorAdapter.java b/src/net/mypapit/mobile/myrepeater/NearbyOperatorAdapter.java index d8c45d3..cbfc2ee 100644 --- a/src/net/mypapit/mobile/myrepeater/NearbyOperatorAdapter.java +++ b/src/net/mypapit/mobile/myrepeater/NearbyOperatorAdapter.java @@ -1,6 +1,5 @@ package net.mypapit.mobile.myrepeater; -import net.mypapit.mobile.myrepeater.RepeaterAdapter.ViewHolder; import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; @@ -12,7 +11,7 @@ public class NearbyOperatorAdapter extends BaseAdapter { private static LayoutInflater inflater = null; - private RepeaterList data, realdata; + private int mLastPosition = -1; private Activity activity; private HamOperatorList hol; @@ -78,8 +77,8 @@ public View getView(int position, View convertView, ViewGroup parent) { HamOperator operator = hol.get(position); - holder.tvCallsign.setText(operator.getCallsign()); - holder.tvHandle.setText(operator.getHandle()); + holder.tvCallsign.setText( truncate(operator.getCallsign().toUpperCase(),10) ); + holder.tvHandle.setText( truncate(operator.getHandle(),25) ); holder.tvLastSeen.setText(operator.getLastSeen()); holder.tvVerified.setText(operator.isValid() ? "(v)": ""); @@ -88,10 +87,26 @@ public View getView(int position, View convertView, ViewGroup parent) { return convertView; } + + public static String truncate(final String text, int length) + { + // The letters [iIl1] are slim enough to only count as half a character. + length += Math.ceil(text.replaceAll("[^iIl]", "").length() / 2.0d); + + if (text.length() > length) + { + return text.substring(0, length - 1) + "\u2026"; + } + + return text; + } + static class ViewHolder { private TextView tvCallsign, tvHandle, tvLastSeen, tvVerified, tvActiveCheckins; } + + } diff --git a/src/net/mypapit/mobile/myrepeater/RepeaterListActivity.java b/src/net/mypapit/mobile/myrepeater/RepeaterListActivity.java index 5c0902a..a0adf3e 100644 --- a/src/net/mypapit/mobile/myrepeater/RepeaterListActivity.java +++ b/src/net/mypapit/mobile/myrepeater/RepeaterListActivity.java @@ -94,7 +94,7 @@ public class RepeaterListActivity extends CompassSensorsActivity implements OnIt RepeaterList rl; private ListView lv; private TextView tvAddress; - private static int static_distance = 50; + private static int static_distance = 0; private boolean excludeLink = false; private boolean excludeDirection = false; private float local_distance = 100.0f; @@ -126,7 +126,9 @@ public void onCreate(Bundle bundle) { lv = (ListView) findViewById(R.id.repeaterListView); tvAddress = (TextView) findViewById(R.id.tvAddress); - String coordinates = new String("37.5651,126.98955"); + String coordinates = new String("37.5651,126.98955"); // set to Seoul, + // far away from + // Malaysia! String coord[] = coordinates.split(","); @@ -340,7 +342,8 @@ public void run() { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); - criteria.setPowerRequirement(Criteria.POWER_LOW); + criteria.setSpeedRequired(false); + /* * criteria.setSpeedRequired(false); * criteria.setAltitudeRequired(false); @@ -353,7 +356,8 @@ public void run() { bestProvider = locationManager.getBestProvider(criteria, false); Location location = locationManager.getLastKnownLocation(bestProvider); - + + // if couldn't get Location Provider (aka couldn't get coordinates, // try GPS @@ -408,6 +412,8 @@ public void run() { if (xlocation != null) { // check again for compassSensor + activity.showToast("Using location sensor: " + xlocation.getProvider()); + } else { // else if xlocation == null, get coordinate stored in Manual @@ -613,7 +619,7 @@ public void onStatusChanged(String provider, int status, Bundle extras) { }; Log.d("Best Provider mypapit", "Best Provider: " + bestProvider); - locationManager.requestLocationUpdates(bestProvider, 5000, static_distance, myLocationListener); + locationManager.requestLocationUpdates(bestProvider, 65000, static_distance, myLocationListener); Looper.loop(); diff --git a/src/net/mypapit/mobile/myrepeater/SuggestRepeaterStartActivity.java b/src/net/mypapit/mobile/myrepeater/SuggestRepeaterStartActivity.java index 09ed5f2..85fd6fc 100644 --- a/src/net/mypapit/mobile/myrepeater/SuggestRepeaterStartActivity.java +++ b/src/net/mypapit/mobile/myrepeater/SuggestRepeaterStartActivity.java @@ -26,9 +26,6 @@ import java.util.ArrayList; import java.util.Locale; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdView; - import android.app.Activity; import android.content.Intent; import android.os.Bundle; @@ -36,7 +33,6 @@ import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; - import android.widget.Toast; public class SuggestRepeaterStartActivity extends Activity { diff --git a/src/net/mypapit/mobile/myrepeater/mapinfo/CallsignMapInfo.java b/src/net/mypapit/mobile/myrepeater/mapinfo/CallsignMapInfo.java index 4abb082..af6244e 100644 --- a/src/net/mypapit/mobile/myrepeater/mapinfo/CallsignMapInfo.java +++ b/src/net/mypapit/mobile/myrepeater/mapinfo/CallsignMapInfo.java @@ -10,7 +10,7 @@ public CallsignMapInfo() } - + /* public CallsignMapInfo (String callsign, double lat, double lng) { this(); @@ -32,10 +32,6 @@ public void setHandle(String handle){ } - public void setVerified(boolean v) - { - m_verified = v; - } public void setDistance(String distance){ m_middle = distance + " km"; @@ -63,6 +59,7 @@ public void setVerified(String valid){ } } + */ public void setIndex(int index){ m_index=index;