1 |
|
package com.loopback.androidapps.saveapp; |
2 |
|
|
3 |
|
|
4 |
|
@author |
5 |
|
|
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 |
|
|
|
|
| 62% |
Uncovered Elements: 38 (100) |
Complexity: 15 |
Complexity Density: 0,19 |
|
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 |
|
|
60 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0,43 |
|
61 |
0
|
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 |
|
|
|
|
| 83,3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0,3 |
|
74 |
3
|
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 |
|
|
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
93 |
3
|
public void loadActivity() {... |
94 |
|
|
95 |
|
|
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 |
|
|
103 |
3
|
btnDiscardAddress.setOnClickListener(this); |
104 |
3
|
settings(); |
105 |
|
|
106 |
|
} |
107 |
|
|
|
|
| 77,8% |
Uncovered Elements: 8 (36) |
Complexity: 3 |
Complexity Density: 0,09 |
|
108 |
3
|
public void settings() {... |
109 |
3
|
saveApp = ((SaveApp) getApplicationContext()); |
110 |
3
|
Bundle bundle = this.getIntent().getExtras(); |
111 |
3
|
id = bundle.getInt("Id"); |
112 |
|
|
113 |
|
|
114 |
|
|
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 |
|
|
131 |
|
|
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 |
|
|
138 |
|
|
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 |
|
|
148 |
|
|
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 |
|
|
156 |
|
|
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 |
|
|
163 |
|
|
164 |
3
|
mapView.invalidate(); |
165 |
3
|
Log.i("MAP", "Draw"); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
171 |
0
|
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 |
|
|
|
|
| 47,6% |
Uncovered Elements: 11 (21) |
Complexity: 3 |
Complexity Density: 0,18 |
|
181 |
3
|
public void onClick(View v) {... |
182 |
|
|
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 |
|
|
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 |
|
|
218 |
|
|
219 |
|
|
220 |
|
@SuppressWarnings("rawtypes") |
|
|
| 79,2% |
Uncovered Elements: 10 (48) |
Complexity: 11 |
Complexity Density: 0,31 |
|
221 |
|
public class MapOverlay extends ItemizedOverlay { |
222 |
|
|
223 |
|
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); |
224 |
|
private Context mContext; |
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
226 |
3
|
public MapOverlay(Drawable defaultMarker, Context context) {... |
227 |
3
|
super(boundCenterBottom(defaultMarker)); |
228 |
3
|
mContext = context; |
229 |
|
} |
230 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
231 |
7
|
public void addOverlay(OverlayItem overlay) {... |
232 |
7
|
mOverlays.add(overlay); |
233 |
7
|
populate(); |
234 |
|
} |
235 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
236 |
4
|
public void clearOverlay() {... |
237 |
4
|
mOverlays.clear(); |
238 |
|
} |
239 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
240 |
7
|
protected OverlayItem createItem(int i) {... |
241 |
7
|
return mOverlays.get(i); |
242 |
|
} |
243 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
244 |
277
|
public int size() {... |
245 |
277
|
return mOverlays.size(); |
246 |
|
} |
247 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
|
248 |
0
|
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 |
|
|
|
|
| 92,6% |
Uncovered Elements: 2 (27) |
Complexity: 5 |
Complexity Density: 0,24 |
|
258 |
100
|
public boolean onTouchEvent(MotionEvent event, MapView mapView) {... |
259 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
298 |
135
|
protected boolean isRouteDisplayed() {... |
299 |
|
|
300 |
135
|
return false; |
301 |
|
} |
302 |
|
|
303 |
|
} |