Added address of car feature

fixed some lint problems

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-03-05 12:16:18 -05:00
parent e18fa36ef9
commit 9252bc6389
13 changed files with 137 additions and 2520 deletions

View File

@@ -17,6 +17,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager.NameNotFoundException;
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
@@ -37,6 +38,7 @@ import com.TwentyCodes.android.FindMyCarLib.debug.Debug;
import com.TwentyCodes.android.SkyHook.SkyHookRegistration;
import com.TwentyCodes.android.exception.ExceptionHandler;
import com.TwentyCodes.android.location.OnDirectionSelectedListener;
import com.TwentyCodes.android.location.ReverseGeocoder;
import com.TwentyCodes.android.overlays.DirectionsOverlay;
import com.google.ads.AdRequest;
import com.google.ads.AdView;
@@ -198,7 +200,43 @@ public class Main extends FragmentActivity implements RegistrationCallback, MapF
Log.d(TAG,"successfully registered new user");
mSettings.edit().putBoolean(Settings.IS_REGISTERED, true).commit();
}
/**
* called when a car is deleted
* (non-Javadoc)
* @see com.TwentyCodes.android.FindMyCarLib.UI.fragments.MapFragment.MapFragmentListener#onCarDeleted()
*/
@Override
public void onCarDeleted() {
mNotes.delete();
mDirectionsFragment.clear();
}
/**
* called when a new car is marked
* (non-Javadoc)
* @see com.TwentyCodes.android.FindMyCarLib.UI.fragments.MapFragment.MapFragmentListener#onCarMarked(com.google.android.maps.GeoPoint)
*/
@Override
public void onCarMarked(final GeoPoint point) {
new Thread( new Runnable(){
@Override
public void run(){
Location location = new Location("location");
location.setLatitude(point.getLatitudeE6() /1e6);
location.setLongitude(point.getLongitudeE6() /1e6);
final String address = ReverseGeocoder.getAddressFromLocation(location);
runOnUiThread( new Runnable(){
@Override
public void run(){
mNotes.setAddressText(address);
}
});
}
}).start();
}
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -296,6 +334,39 @@ public class Main extends FragmentActivity implements RegistrationCallback, MapF
mPager.setPagingEnabled(false);
}
/**
* called when directions are displayed
* (non-Javadoc)
* @see com.TwentyCodes.android.FindMyCarLib.UI.fragments.MapFragment.MapFragmentListener#onDirectionsDisplayed(java.util.ArrayList, java.util.ArrayList, java.util.ArrayList, java.util.ArrayList, java.lang.String)
*/
@Override
public void onDirectionsDisplayed(final DirectionsOverlay directions) {
this.runOnUiThread(new Runnable(){
@Override
public void run(){
mDirectionsFragment.setDirections(directions);
mPager.setCurrentItem(2);
mPager.setCurrentItem(0);
mIndicator.setCurrentItem(0);
}
});
}
/**
* called when a direction is selected
* (non-Javadoc)
* @see com.TwentyCodes.android.location.DirectionsListFragment.OnDirectionSelectedListener#onDirectionSelected(com.google.android.maps.GeoPoint)
*/
@Override
public void onDirectionSelected(GeoPoint point) {
if(mMap != null) {
mMap.panToGeoPoint(point, true);
mPager.setCurrentItem(1);
mIndicator.setCurrentItem(1);
}
}
/**
@@ -509,47 +580,5 @@ public class Main extends FragmentActivity implements RegistrationCallback, MapF
}
}
/**
* called when a car is deleted
* (non-Javadoc)
* @see com.TwentyCodes.android.FindMyCarLib.UI.fragments.MapFragment.MapFragmentListener#onCarDeleted()
*/
@Override
public void onCarDeleted() {
mNotes.delete();
mDirectionsFragment.clear();
}
/**
* called when directions are displayed
* (non-Javadoc)
* @see com.TwentyCodes.android.FindMyCarLib.UI.fragments.MapFragment.MapFragmentListener#onDirectionsDisplayed(java.util.ArrayList, java.util.ArrayList, java.util.ArrayList, java.util.ArrayList, java.lang.String)
*/
@Override
public void onDirectionsDisplayed(final DirectionsOverlay directions) {
this.runOnUiThread(new Runnable(){
@Override
public void run(){
mDirectionsFragment.setDirections(directions);
mPager.setCurrentItem(2);
mPager.setCurrentItem(0);
mIndicator.setCurrentItem(0);
}
});
}
/**
* called when a direction is selected
* (non-Javadoc)
* @see com.TwentyCodes.android.location.DirectionsListFragment.OnDirectionSelectedListener#onDirectionSelected(com.google.android.maps.GeoPoint)
*/
@Override
public void onDirectionSelected(GeoPoint point) {
if(mMap != null) {
mMap.panToGeoPoint(point, true);
mPager.setCurrentItem(1);
mIndicator.setCurrentItem(1);
}
}
}
}

View File

@@ -85,6 +85,13 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
* @author ricky barrette
*/
public void onCarDeleted();
/**
* Called when a new Car is marked
* @param point
* @author ricky barrette
*/
public void onCarMarked(GeoPoint point);
/**
* Called when there are new directions being displayed to the user
@@ -221,7 +228,7 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
setCar(user);
// TODO get address
mListener.onCarMarked(user);
} else {
Toast.makeText(getActivity(), R.string.no_gps_signal,
@@ -593,9 +600,9 @@ public class MapFragment extends Fragment implements GeoPointLocationListener, O
*/
if (!panToGeoPoint(mMap.getUserLocation(), true)) {
Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
return true;
} else
return false;
} else
return true;
}

View File

@@ -27,6 +27,35 @@ public class NotesFragment extends Fragment {
private SharedPreferences mSettings;
private TextView mAddress;
/**
* deletes the note
* @author ricky barrette
*/
public void delete() {
if(mText != null)
mText.setText("");
if(mAddress != null)
mAddress.setText("");
if(mSettings != null)
mSettings.edit().remove(Settings.NOTE).remove(Settings.ADDRESS).commit();
}
/**
* (non-Javadoc)
*
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,
* android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.notes, container, false);
mSettings = getActivity().getSharedPreferences(Settings.SETTINGS, 0);
mText = (EditText) view.findViewById(R.id.editText);
mAddress = (TextView) view.findViewById(R.id.tvAddress);
return view;
}
/**
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onPause()
@@ -34,7 +63,7 @@ public class NotesFragment extends Fragment {
@Override
public void onPause() {
mSettings.edit().putString(Settings.NOTE, mText.getText().toString()).commit();
// Toast.makeText(getActivity(), R.string.saved, Toast.LENGTH_LONG).show();
mSettings.edit().putString(Settings.ADDRESS, mAddress.getText().toString()).commit();
super.onPause();
}
@@ -56,32 +85,12 @@ public class NotesFragment extends Fragment {
super.onResume();
}
/**
* (non-Javadoc)
*
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,
* android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.notes, container, false);
mSettings = getActivity().getSharedPreferences(Settings.SETTINGS, 0);
mText = (EditText) view.findViewById(R.id.editText);
mAddress = (TextView) view.findViewById(R.id.tvAddress);
return view;
}
/**
* deletes the note
* Sets the address text
* @param text
* @author ricky barrette
*/
public void delete() {
if(mText != null)
mText.setText("");
if(mAddress != null)
mAddress.setText("");
if(mSettings != null)
mSettings.edit().remove(Settings.NOTE).remove(Settings.ADDRESS).commit();
public void setAddressText(String text) {
this.mAddress.setText(text);
}
}