Cleaned up the location information fragment

The button bar is now properly designed
The map fragment no longer has a user overlay to confuse things
refactored some code

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-05-12 01:04:57 -04:00
parent 756f5aea86
commit accdf02af2
7 changed files with 360 additions and 1920 deletions

View File

@@ -29,7 +29,7 @@ import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
import com.TwentyCodes.android.LocationRinger.debug.Debug;
import com.TwentyCodes.android.LocationRinger.ui.fragments.AboutRingerFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.FeatureListFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.MapFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.LocationInfomationFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.RingtoneFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.ToggleButtonFragment;
import com.TwentyCodes.android.LocationRinger.ui.fragments.VolumeFragment;
@@ -91,7 +91,7 @@ public class RingerInformationActivity extends FragmentActivity implements OnCon
/*
* Location page
*/
fragments.add(new MapFragment(this.mInfo, this, this));
fragments.add(new LocationInfomationFragment(this.mInfo, this, this));
/*
* What page

View File

@@ -0,0 +1,287 @@
/**
* MapFragment.java
* @date Aug 8, 2011
* @author Twenty Codes, LLC
* @author ricky barrette
*/
package com.TwentyCodes.android.LocationRinger.ui.fragments;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.TwentyCodes.android.LocationRinger.EnableScrollingListener;
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
import com.TwentyCodes.android.LocationRinger.R;
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
import com.TwentyCodes.android.LocationRinger.debug.Debug;
import com.TwentyCodes.android.LocationRinger.ui.SearchDialog;
import com.TwentyCodes.android.SkyHook.SkyHook;
import com.TwentyCodes.android.location.GeoPointLocationListener;
import com.TwentyCodes.android.location.OnLocationSelectedListener;
import com.TwentyCodes.android.overlays.RadiusOverlay;
import com.google.android.maps.GeoPoint;
/**
* This fragment will be used to display and allow the user to edit the ringers location trigger
* @author ricky
*/
public class LocationInfomationFragment extends Fragment implements GeoPointLocationListener, OnClickListener, OnCheckedChangeListener, OnSeekBarChangeListener, OnLocationSelectedListener {
private ContentValues mInfo;
private OnContentChangedListener mListener;
private static final String TAG = "RingerInformationHowActivity";
private SeekBar mRadius;
private MapFragment mMap;
private ToggleButton mMapEditToggle;
private RadiusOverlay mRadiusOverlay;
private GeoPoint mPoint;
private SkyHook mSkyHook;
private boolean isFirstFix;
private View view;
private EnableScrollingListener mEnableScrollingListener;
/**
* Creates a new MapFragment
* @author ricky barrette
* @param ringerInformationActivity
*/
public LocationInfomationFragment(ContentValues info, OnContentChangedListener listener, EnableScrollingListener enabledListener) {
this.mInfo = info;
this.mListener = listener;
this.mEnableScrollingListener = enabledListener;
}
/**
* Called when a toggle button's state is changed
* @author ricky barrette
*/
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
this.isFirstFix = isChecked;
view.findViewById(R.id.buttons).setVisibility(isChecked ? View.VISIBLE : View.GONE);
if(mEnableScrollingListener != null)
mEnableScrollingListener.setScrollEnabled(!isChecked);
if(isChecked){
this.mSkyHook.getUpdates();
mMap.enableGPSProgess();
} else {
this.mSkyHook.removeUpdates();
mMap.disableGPSProgess();
}
this.mMap.setDoubleTapZoonEnabled(isChecked);
//buttons
this.mMap.setBuiltInZoomControls(isChecked);
this.mMap.setClickable(isChecked);
this.mRadius.setEnabled(isChecked);
Toast.makeText(this.getActivity(), isChecked ? getString(R.string.map_editing_enabled) : getString(R.string.map_editiing_disabled), Toast.LENGTH_SHORT).show();
}
/**
* Called when a view is clicked
* @author ricky barrette
*/
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.mark_my_location:
if(this.mPoint != null){
this.mRadiusOverlay.setLocation(mPoint);
this.mMap.setMapCenter(mPoint);
}
break;
case R.id.my_location:
if(this.mPoint != null)
this.mMap.setMapCenter(mPoint);
break;
case R.id.map_mode:
this.mMap.setSatellite(mMap.isSatellite() ? false : true);
break;
case R.id.search:
new SearchDialog(this.getActivity(), this).show();
break;
}
}
/* (non-Javadoc)
* @see com.google.android.maps.MapActivity#onDestroy()
* @author ricky barrette
*/
@Override
public void onStop() {
this.mSkyHook.removeUpdates();
super.onDestroy();
}
/**
* Called when skyhook has a location to report
* @author ricky barrette
*/
@Override
public void onLocationChanged(GeoPoint point, int accuracy) {
this.mPoint = point;
if(point != null){
/*
* if this is the first fix and the radius overlay does not have a point specified
* then pan the map, and zoom in to the users current location
*/
if(this.isFirstFix)
if(this.mRadiusOverlay.getLocation() == null){
if(this.mMap != null){
this.mMap.setMapCenter(point);
this.mMap.setZoom((this.mMap.getMap().getMaxZoomLevel() - 5));
}
this.isFirstFix = false;
}
mMap.disableGPSProgess();
}
}
/*
*/
@Override
public void onLocationSelected(GeoPoint point) {
if(point != null){
if(Debug.DEBUG)
Log.d(TAG, "onLocationSelected() "+ point.toString());
if(this.mRadiusOverlay != null)
this.mRadiusOverlay.setLocation(point);
if(this.mMap != null){
this.mMap.setMapCenter(point);
this.mMap.setZoom((this.mMap.getMap().getMaxZoomLevel() - 5));
}
if(this.mListener != null){
ContentValues info = new ContentValues();
info.put(RingerDatabase.KEY_LOCATION_LAT, point.getLatitudeE6());
info.put(RingerDatabase.KEY_LOCATION_LON, point.getLongitudeE6());
this.mListener.onInfoContentChanged(info);
}
} else if(Debug.DEBUG)
Log.d(TAG, "onLocationSelected() Location was null");
}
/**
* Called when a seekbar is has its progress changed
* @author ricky barrette
*/
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
switch (seekBar.getId()){
case R.id.radius:
this.mRadiusOverlay.setRadius(progress);
this.mMap.invalidate();
if(this.mListener != null){
ContentValues info = new ContentValues();
info.put(RingerDatabase.KEY_RADIUS, progress);
this.mListener.onInfoContentChanged(info);
}
break;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.map_info_fragment, container, false);
this.mSkyHook = new SkyHook(this.getActivity());
this.mSkyHook.setLocationListener(this);
this.mMap = (MapFragment) this.getFragmentManager().findFragmentById(R.id.mapview);
this.mRadius = (SeekBar) view.findViewById(R.id.radius);
this.mRadius.setMax(Debug.MAX_RADIUS_IN_METERS);
this.mMap.setClickable(false);
this.mMapEditToggle = (ToggleButton) view.findViewById(R.id.map_edit_toggle);
this.mMapEditToggle.setChecked(false);
this.mMapEditToggle.setOnCheckedChangeListener(this);
this.mRadiusOverlay = new RadiusOverlay();
this.mRadiusOverlay.setLocationSelectedListener(this);
this.mRadius.setOnSeekBarChangeListener(this);
this.mMap.addOverlay(mRadiusOverlay);
this.mRadius.setEnabled(false);
if (this.mInfo.get(RingerDatabase.KEY_LOCATION_LAT) != null && this.mInfo.get(RingerDatabase.KEY_LOCATION_LON) != null){
this.mRadiusOverlay.setLocation(new GeoPoint(this.mInfo.getAsInteger(RingerDatabase.KEY_LOCATION_LAT), this.mInfo.getAsInteger(RingerDatabase.KEY_LOCATION_LON)));
}
if (this.mInfo.get(RingerDatabase.KEY_RADIUS) != null){
this.mRadius.setProgress(this.mInfo.getAsInteger(RingerDatabase.KEY_RADIUS));
}
if(this.mRadiusOverlay.getLocation() != null){
this.mMap.setMapCenter(this.mRadiusOverlay.getLocation());
this.mMap.setZoom(16);
}
this.mMap.setDoubleTapZoonEnabled(false);
view.findViewById(R.id.my_location).setOnClickListener(this);
view.findViewById(R.id.mark_my_location).setOnClickListener(this);
view.findViewById(R.id.search).setOnClickListener(this);
view.findViewById(R.id.map_mode).setOnClickListener(this);
return view;
}
/**
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onPause()
*/
@Override
public void onPause() {
mSkyHook.removeUpdates();
super.onPause();
}
/**
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onResume()
*/
@Override
public void onResume() {
if(mMapEditToggle.isChecked())
mSkyHook.getUpdates();
super.onResume();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onFirstFix(boolean isFirstFix) {
// TODO Auto-generated method stub
}
}

View File

@@ -1,295 +1,35 @@
/**
* MapFragment.java
* @date Aug 8, 2011
* @author Twenty Codes, LLC
* @date May 12, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.LocationRinger.ui.fragments;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.TwentyCodes.android.LocationRinger.EnableScrollingListener;
import com.TwentyCodes.android.LocationRinger.OnContentChangedListener;
import com.TwentyCodes.android.LocationRinger.R;
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
import com.TwentyCodes.android.LocationRinger.debug.Debug;
import com.TwentyCodes.android.LocationRinger.ui.SearchDialog;
import com.TwentyCodes.android.SkyHook.SkyHook;
import com.TwentyCodes.android.fragments.SkyHoookUserOverlayMapFragment;
import com.TwentyCodes.android.location.GeoPointLocationListener;
import com.TwentyCodes.android.location.OnLocationSelectedListener;
import com.TwentyCodes.android.overlays.RadiusOverlay;
import com.google.android.maps.GeoPoint;
import com.TwentyCodes.android.fragments.BaseMapFragment;
import com.TwentyCodes.android.location.MapView;
/**
* This fragment will be used to display and allow the user to edit the ringers location trigger
* @author ricky
* @author ricky barrette
*/
public class MapFragment extends Fragment implements GeoPointLocationListener, OnClickListener, OnCheckedChangeListener, OnSeekBarChangeListener, OnLocationSelectedListener {
private ContentValues mInfo;
private OnContentChangedListener mListener;
private static final String TAG = "RingerInformationHowActivity";
private SeekBar mRadius;
private SkyHoookUserOverlayMapFragment mMapView;
private ToggleButton mMapEditToggle;
private RadiusOverlay mRadiusOverlay;
private GeoPoint mPoint;
private SkyHook mSkyHook;
private ProgressDialog mGpsProgress;
private boolean isFirstFix;
private View view;
private EnableScrollingListener mEnableScrollingListener;
/**
* Creates a new MapFragment
* @author ricky barrette
* @param ringerInformationActivity
*/
public MapFragment(ContentValues info, OnContentChangedListener listener, EnableScrollingListener enabledListener) {
this.mInfo = info;
this.mListener = listener;
this.mEnableScrollingListener = enabledListener;
}
public class MapFragment extends BaseMapFragment {
/**
* Called when a toggle button's state is changed
*
* @author ricky barrette
*/
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
this.isFirstFix = isChecked;
view.findViewById(R.id.buttons).setVisibility(isChecked ? View.VISIBLE : View.GONE);
if(mEnableScrollingListener != null)
mEnableScrollingListener.setScrollEnabled(!isChecked);
if(isChecked){
this.mSkyHook.getUpdates();
this.mGpsProgress = ProgressDialog.show(this.getActivity(), "", this.getText(R.string.gps_fix), true, true);
} else {
this.mSkyHook.removeUpdates();
if(this.mGpsProgress != null)
this.mGpsProgress.dismiss();
}
this.mMapView.setDoubleTapZoonEnabled(isChecked);
//buttons
this.mMapView.setBuiltInZoomControls(isChecked);
this.mMapView.setClickable(isChecked);
this.mRadius.setEnabled(isChecked);
Toast.makeText(this.getActivity(), isChecked ? getString(R.string.map_editing_enabled) : getString(R.string.map_editiing_disabled), Toast.LENGTH_SHORT).show();
}
/**
* Called when a view is clicked
* @author ricky barrette
*/
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.mark_my_location:
if(this.mPoint != null){
this.mRadiusOverlay.setLocation(mPoint);
this.mMapView.setMapCenter(mPoint);
}
break;
case R.id.my_location:
if(this.mPoint != null)
this.mMapView.setMapCenter(mPoint);
break;
case R.id.map_mode:
this.mMapView.setSatellite(mMapView.isSatellite() ? false : true);
break;
case R.id.search:
new SearchDialog(this.getActivity(), this).show();
break;
}
}
/* (non-Javadoc)
* @see com.google.android.maps.MapActivity#onDestroy()
* @author ricky barrette
*/
@Override
public void onStop() {
this.mSkyHook.removeUpdates();
super.onDestroy();
}
/**
* Called when skyhook has a location to report
* @author ricky barrette
*/
@Override
public void onLocationChanged(GeoPoint point, int accuracy) {
this.mPoint = point;
if(point != null){
/*
* if this is the first fix and the radius overlay does not have a point specified
* then pan the map, and zoom in to the users current location
*/
if(this.isFirstFix)
if(this.mRadiusOverlay.getLocation() == null){
if(this.mMapView != null){
this.mMapView.setMapCenter(point);
this.mMapView.setZoom((this.mMapView.getMap().getMaxZoomLevel() - 5));
}
this.isFirstFix = false;
}
/*
* dismiss the acquiring gps dialog
*/
if(this.mGpsProgress != null)
this.mGpsProgress.dismiss();
}
}
/*
*/
@Override
public void onLocationSelected(GeoPoint point) {
if(point != null){
if(Debug.DEBUG)
Log.d(TAG, "onLocationSelected() "+ point.toString());
if(this.mRadiusOverlay != null)
this.mRadiusOverlay.setLocation(point);
if(this.mMapView != null){
this.mMapView.setMapCenter(point);
this.mMapView.setZoom((this.mMapView.getMap().getMaxZoomLevel() - 5));
}
if(this.mListener != null){
ContentValues info = new ContentValues();
info.put(RingerDatabase.KEY_LOCATION_LAT, point.getLatitudeE6());
info.put(RingerDatabase.KEY_LOCATION_LON, point.getLongitudeE6());
this.mListener.onInfoContentChanged(info);
}
} else if(Debug.DEBUG)
Log.d(TAG, "onLocationSelected() Location was null");
}
/**
* Called when a seekbar is has its progress changed
* @author ricky barrette
*/
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
switch (seekBar.getId()){
case R.id.radius:
this.mRadiusOverlay.setRadius(progress);
this.mMapView.invalidate();
if(this.mListener != null){
ContentValues info = new ContentValues();
info.put(RingerDatabase.KEY_RADIUS, progress);
this.mListener.onInfoContentChanged(info);
}
break;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.map_info_fragment, container, false);
this.mSkyHook = new SkyHook(this.getActivity());
this.mSkyHook.setLocationListener(this);
this.mMapView = (SkyHoookUserOverlayMapFragment) this.getFragmentManager().findFragmentById(R.id.mapview);
this.mRadius = (SeekBar) view.findViewById(R.id.radius);
this.mRadius.setMax(Debug.MAX_RADIUS_IN_METERS);
this.mMapView.setClickable(false);
this.mMapEditToggle = (ToggleButton) view.findViewById(R.id.map_edit_toggle);
this.mMapEditToggle.setChecked(false);
this.mMapEditToggle.setOnCheckedChangeListener(this);
this.mRadiusOverlay = new RadiusOverlay();
this.mRadiusOverlay.setLocationSelectedListener(this);
this.mRadius.setOnSeekBarChangeListener(this);
this.mMapView.addOverlay(mRadiusOverlay);
this.mRadius.setEnabled(false);
if (this.mInfo.get(RingerDatabase.KEY_LOCATION_LAT) != null && this.mInfo.get(RingerDatabase.KEY_LOCATION_LON) != null){
this.mRadiusOverlay.setLocation(new GeoPoint(this.mInfo.getAsInteger(RingerDatabase.KEY_LOCATION_LAT), this.mInfo.getAsInteger(RingerDatabase.KEY_LOCATION_LON)));
}
if (this.mInfo.get(RingerDatabase.KEY_RADIUS) != null){
this.mRadius.setProgress(this.mInfo.getAsInteger(RingerDatabase.KEY_RADIUS));
}
if(this.mRadiusOverlay.getLocation() != null){
this.mMapView.setMapCenter(this.mRadiusOverlay.getLocation());
this.mMapView.setZoom(16);
}
this.mMapView.setDoubleTapZoonEnabled(false);
view.findViewById(R.id.my_location).setOnClickListener(this);
view.findViewById(R.id.mark_my_location).setOnClickListener(this);
view.findViewById(R.id.search).setOnClickListener(this);
view.findViewById(R.id.map_mode).setOnClickListener(this);
return view;
public MapFragment() {
// TODO Auto-generated constructor stub
}
/**
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onPause()
* @see com.TwentyCodes.android.fragments.BaseMapFragment#onMapViewCreate(com.TwentyCodes.android.location.MapView)
*/
@Override
public void onPause() {
mSkyHook.removeUpdates();
super.onPause();
}
/**
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onResume()
*/
@Override
public void onResume() {
if(mMapEditToggle.isChecked())
mSkyHook.getUpdates();
super.onResume();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
public void onMapViewCreate(MapView map) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onFirstFix(boolean isFirstFix) {
// TODO Auto-generated method stub
}
}