Clover Coverage Report - SaveApp Coverage Report
Coverage timestamp: mar dic 23 2014 15:53:11 EST
../../../../img/srcFileCovDistChart7.png 48% of files have more coverage
116   303   26   8,29
18   220   0,22   7
14     1,86  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  MapAddressSelectionActivity       Line # 40 81 15 62% 0.62
  MapAddressSelectionActivity.MapOverlay       Line # 221 35 11 79,2% 0.7916667
 
No Tests
 
1    package com.loopback.androidapps.saveapp;
2   
3    /**
4    * @author Hugo A. Matilla G�mez
5    *Activity que muestra el mapa en pantalla
6    */
7   
8    import java.io.IOException;
9    import java.util.ArrayList;
10    import java.util.List;
11    import java.util.Locale;
12   
13    import android.app.AlertDialog;
14    import android.content.Context;
15    import android.content.Intent;
16    import android.content.SharedPreferences;
17    import android.content.res.Configuration;
18    import android.graphics.PixelFormat;
19    import android.graphics.drawable.Drawable;
20    import android.location.Address;
21    import android.location.Geocoder;
22    import android.os.Bundle;
23    import android.preference.PreferenceManager;
24    import android.util.Log;
25    import android.view.Display;
26    import android.view.MotionEvent;
27    import android.view.View;
28    import android.view.WindowManager;
29    import android.widget.Button;
30    import android.widget.TextView;
31   
32    import com.google.android.maps.GeoPoint;
33    import com.google.android.maps.ItemizedOverlay;
34    import com.google.android.maps.MapActivity;
35    import com.google.android.maps.MapController;
36    import com.google.android.maps.MapView;
37    import com.google.android.maps.Overlay;
38    import com.google.android.maps.OverlayItem;
39   
 
40    public class MapAddressSelectionActivity extends MapActivity implements
41    View.OnClickListener {
42   
43    private MapView mapView;
44    private MapController mapController;
45    private int id;
46    public TextView txtAddressClicked;
47    public List<Overlay> mapOverlays;
48    public MapOverlay itemizedoverlay;
49    private GeoPoint locationClicked, localization;
50    private Button btnSaveAddress, btnDiscardAddress;
51    private AddressX address;
52    private Outlay outlay;
53    private String addressDescSelected;
54    private Double latitudeSelected, longitudeSelected;
55   
56    public SaveApp saveApp;
57   
58    /*------------------------------------------------------------------------------------------------
59    *-------------------------------------ON CREATE & ON ROTATION--------------------------------------------------
60    *------------------------------------------------------------------------------------------------ */
 
61  0 toggle public void onConfigurationChanged(Configuration newConfig) {
62  0 super.onConfigurationChanged(newConfig);
63  0 Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
64    .getDefaultDisplay();
65  0 int orientation = display.getOrientation();
66  0 if (orientation == 1 || orientation == 3)
67  0 setContentView(R.layout.mapaddress);
68    else
69  0 setContentView(R.layout.mapaddress);
70   
71  0 settings();
72    }
73   
 
74  3 toggle public void onCreate(Bundle savedInstanceState) {
75  3 Log.i("MAP", "Create...");
76  3 super.onCreate(savedInstanceState);
77  3 getWindow().setFormat(PixelFormat.RGBA_8888);
78  3 getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
79  3 Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
80    .getDefaultDisplay();
81  3 int orientation = display.getOrientation();
82  3 if (orientation == 1 || orientation == 3)
83  0 setContentView(R.layout.mapaddress);
84    else
85  3 setContentView(R.layout.mapaddress);
86   
87  3 loadActivity();
88    }
89   
90    /*------------------------------------------------------------------------------------------------
91    *-------------------------------------- LOAD ACTIVITY --------------------------------------------------
92    *------------------------------------------------------------------------------------------------ */
 
93  3 toggle public void loadActivity() {
94    // Map
95    // Init------------------------------------------------------------------
96  3 Log.i("MAP", "Drawing Map...");
97  3 txtAddressClicked = (TextView) findViewById(R.id.txtAddressClicked);
98  3 btnSaveAddress = (Button) findViewById(R.id.btnSaveAddress);
99  3 btnDiscardAddress = (Button) findViewById(R.id.btnDiscardAddress);
100  3 mapView = (MapView) findViewById(R.id.mapView);
101  3 mapView.setBuiltInZoomControls(true);
102    //btnSaveAddress.setOnClickListener(this);
103  3 btnDiscardAddress.setOnClickListener(this);
104  3 settings();
105   
106    }
107   
 
108  3 toggle public void settings() {
109  3 saveApp = ((SaveApp) getApplicationContext());
110  3 Bundle bundle = this.getIntent().getExtras();
111  3 id = bundle.getInt("Id");
112   
113    // Get Intennt
114    // Values------------------------------------------------------------------
115  3 Log.i("MAP", "Set Localization...");
116  3 if (id > 0) {
117  0 outlay = new Outlay(id);
118  0 Integer addressId = outlay.getAddressId();
119  0 address = new AddressX(addressId);
120  0 localization = new GeoPoint((int) ((address.getLongitude()) * 1E6),
121    (int) ((address.getLongitude()) * 1E6));
122  0 txtAddressClicked.setText(address.getDescription());
123    } else {
124  3 address = new AddressX();
125  3 localization = new GeoPoint((int) ((saveApp.getLatitude()) * 1E6),
126    (int) ((saveApp.getLongitude()) * 1E6));
127  3 txtAddressClicked.setText(saveApp.getAddressDesc());
128    }
129   
130    // Get
131    // Preferences------------------------------------------------------------------
132  3 Log.i("MAP", "Preferences...");
133  3 SharedPreferences sp = PreferenceManager
134    .getDefaultSharedPreferences(this);
135  3 Integer mapStyle = Integer.valueOf(sp.getString("mapStyle", "-1"));
136   
137    // Map
138    // Edit------------------------------------------------------------------
139  3 Log.i("MAP", "Editionn...");
140  3 mapView.setSatellite(false);
141  3 if (mapStyle == 2)
142  0 mapView.setSatellite(true);
143  3 mapController = mapView.getController();
144  3 mapController.setZoom(17);
145  3 mapController.animateTo(localization);
146   
147    // OverLay
148    // Init-----------------------------------------------------------------
149  3 Log.i("MAP", "Overlay...");
150  3 mapOverlays = mapView.getOverlays();
151  3 Drawable drawable = this.getResources().getDrawable(
152    R.drawable.changeaccount);
153  3 itemizedoverlay = new MapOverlay(drawable, this);
154   
155    // Set
156    // Overlay------------------------------------------------------------------
157  3 OverlayItem overlayitem = new OverlayItem(localization,
158    "Set the movemnt here?", "Click Save!");
159  3 itemizedoverlay.addOverlay(overlayitem);
160  3 mapOverlays.add(itemizedoverlay);
161   
162    // Re-Draw
163    // ------------------------------------------------------------------
164  3 mapView.invalidate();
165  3 Log.i("MAP", "Draw");
166    }
167   
168    /*------------------------------------------------------------------------------------------------
169    *-------------------------------------- BUTTONS --------------------------------------------------
170    *------------------------------------------------------------------------------------------------ */
 
171  0 toggle public void onBackPressed() {
172  0 Log.i("MAP", "Back Pressed");
173  0 Bundle bundle = new Bundle();
174  0 bundle.putInt("Id", id);
175  0 Intent intent = new Intent(this.getApplicationContext(),
176    ChangeAutogeneratedActivity.class);
177  0 intent.putExtras(bundle);
178  0 startActivity(intent);
179    }
180   
 
181  3 toggle public void onClick(View v) {
182    // Save Address
183    // ------------------------------------------------------------------
184  3 if (v == btnSaveAddress) {
185  0 Bundle bundle = new Bundle();
186   
187  0 bundle.putBoolean("HasBeenChanged", true);
188  0 bundle.putInt("Id", id);
189  0 bundle.putString("AddressDesc", addressDescSelected);
190  0 bundle.putDouble("Latitude", latitudeSelected);
191  0 bundle.putDouble("Longitude", longitudeSelected);
192   
193  0 Intent intent = new Intent(this.getApplicationContext(),
194    ChangeAutogeneratedActivity.class);
195  0 intent.putExtras(bundle);
196  0 startActivity(intent);
197   
198    }
199   
200    // Discard Address
201    // ------------------------------------------------------------------
202  3 if (v == btnDiscardAddress) {
203  3 Bundle bundle = new Bundle();
204   
205  3 bundle.putBoolean("HasBeenChanged", false);
206  3 bundle.putInt("Id", id);
207   
208  3 Intent intent = new Intent(this.getApplicationContext(),
209    ChangeAutogeneratedActivity.class);
210  3 intent.putExtras(bundle);
211  3 startActivity(intent);
212    }
213    }
214   
215   
216    /*--******************************************************************************************-------------
217    *-------------------------------------- MapOverlay CLASS --------------------------------------------------
218    *--******************************************************************************************-------------*/
219   
220    @SuppressWarnings("rawtypes")
 
221    public class MapOverlay extends ItemizedOverlay {
222   
223    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
224    private Context mContext;
225   
 
226  3 toggle public MapOverlay(Drawable defaultMarker, Context context) {
227  3 super(boundCenterBottom(defaultMarker));
228  3 mContext = context;
229    }
230   
 
231  7 toggle public void addOverlay(OverlayItem overlay) {
232  7 mOverlays.add(overlay);
233  7 populate();
234    }
235   
 
236  4 toggle public void clearOverlay() {
237  4 mOverlays.clear();
238    }
239   
 
240  7 toggle protected OverlayItem createItem(int i) {
241  7 return mOverlays.get(i);
242    }
243   
 
244  277 toggle public int size() {
245  277 return mOverlays.size();
246    }
247   
 
248  0 toggle protected boolean onTap(int index) {
249  0 Log.i("MAP", "Tap...");
250  0 OverlayItem item = mOverlays.get(index);
251  0 AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
252  0 dialog.setTitle(item.getTitle());
253  0 dialog.setMessage(item.getSnippet());
254  0 dialog.show();
255  0 return true;
256    }
257   
 
258  100 toggle public boolean onTouchEvent(MotionEvent event, MapView mapView) {
259    // ---when user lifts his finger---
260  100 if (event.getAction() == 1) {
261  4 locationClicked = mapView.getProjection().fromPixels(
262    (int) event.getX(), (int) event.getY());
263   
264  4 Geocoder geoCoder = new Geocoder(mContext, Locale.getDefault());
265  4 try {
266  4 latitudeSelected = locationClicked.getLatitudeE6() / 1E6;
267  4 longitudeSelected = (locationClicked.getLongitudeE6() / 1E6);
268  4 List<Address> addresses = geoCoder.getFromLocation(
269    locationClicked.getLatitudeE6() / 1E6,
270    locationClicked.getLongitudeE6() / 1E6, 1);
271   
272  4 String add = "";
273  4 if (addresses.size() > 0) {
274  13 for (int i = 0; i < addresses.get(0)
275    .getMaxAddressLineIndex(); i++)
276  9 add += addresses.get(0).getAddressLine(i) + "\n";
277    }
278   
279  4 mapOverlays.clear();
280  4 itemizedoverlay.clearOverlay();
281  4 OverlayItem overlayitem = new OverlayItem(locationClicked,
282    "Hola", "Estamso aqui");
283  4 itemizedoverlay.addOverlay(overlayitem);
284  4 mapOverlays.add(itemizedoverlay);
285  4 addressDescSelected = add;
286  4 txtAddressClicked.setText(addressDescSelected);
287   
288    } catch (IOException e) {
289  0 e.printStackTrace();
290    }
291  4 return true;
292    } else
293  96 return false;
294    }
295   
296    }
297   
 
298  135 toggle protected boolean isRouteDisplayed() {
299    // TODO Auto-generated method stub
300  135 return false;
301    }
302   
303    }