Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapViewer fixes for #228 #262

Merged
merged 6 commits into from
Jan 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions app/src/main/java/com/SecUpwN/AIMSICD/activities/DebugLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ public void sendEmail() {
@Override
public void run() {
// Send Error Log
// TODO - clear log using 'logcat -c' on app startup
// EVA: just make sure you specify each buffer to be cleared:
// logcat -c -b main -b system -b radio -b events
try {
String log = getLogs();

Expand Down Expand Up @@ -186,8 +183,6 @@ private String getLogs() throws IOException {
* @return
* @throws IOException
*/
// EVA: make sure you specify each buffer to be cleared:
// logcat -c -b main -b system -b radio -b events
private void clearLogs() throws IOException {
new Thread() {
@Override
Expand All @@ -197,6 +192,13 @@ public void run() {
} catch (Exception e) {
Log.e("DebugLogs", "Error clearing logs", e);
}

runOnUiThread(new Runnable() {
@Override
public void run() {
logView.setText("");
}
});
}
}.start();
}
Expand Down
148 changes: 10 additions & 138 deletions app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

package com.SecUpwN.AIMSICD.activities;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
Expand All @@ -31,7 +29,6 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.LocalBroadcastManager;
import android.telephony.CellInfo;
import android.telephony.PhoneStateListener;
Expand All @@ -41,12 +38,12 @@
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TableRow;
import android.widget.TextView;

import com.SecUpwN.AIMSICD.R;
import com.SecUpwN.AIMSICD.adapters.AIMSICDDbAdapter;
import com.SecUpwN.AIMSICD.map.CellTowerItemizedOverlay;
import com.SecUpwN.AIMSICD.map.CellTowerOverlayItem;
import com.SecUpwN.AIMSICD.map.MarkerData;
import com.SecUpwN.AIMSICD.service.AimsicdService;
import com.SecUpwN.AIMSICD.utils.Cell;
import com.SecUpwN.AIMSICD.utils.GeoLocation;
Expand All @@ -58,8 +55,6 @@
import org.osmdroid.util.GeoPoint;
import org.osmdroid.util.ResourceProxyImpl;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;

Expand Down Expand Up @@ -211,22 +206,13 @@ private void loadPreferences() {
}
}

// E:V:A 20150105
// TODO: Remove HYBRID and SATELLITE MAP choices as they don't work!
// See: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/228
private void setupMapType(int mapType) {
mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
switch (mapType) {
case 0:
mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE); //setMapType(GoogleMap.MAP_TYPE_NORMAL);
break;
//case 1:
// mMap.setTileSource(TileSourceFactory.MAPNIK); //.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// break;
//case 2:
// mMap.setTileSource(TileSourceFactory.MAPQUESTAERIAL); //.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
// break;
case 3:
case 1:
mMap.setTileSource(TileSourceFactory.CYCLEMAP); //.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
break;
default:
Expand Down Expand Up @@ -303,6 +289,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
}
}

if (loc != null) {
Helpers.msgLong(this,
"Contacting opencellid.org for data...\nThis may take up to a minute.");
Expand All @@ -315,6 +302,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
Helpers.msgLong(mContext,
"Unable to determine your last location. \nEnable Location Services and try again.");
}

return true;
}
default:
Expand All @@ -327,6 +315,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
* only entries which have a location (lon, lat) are used.
*/
private void loadEntries() {

new AsyncTask<Void,Void,GeoPoint>() {
@Override
protected GeoPoint doInBackground(Void... voids) {
Expand All @@ -335,6 +324,8 @@ protected GeoPoint doInBackground(Void... voids) {
int color;

mOpenCellIdOverlay.removeAllItems();
loadOpenCellIDMarkers();

LinkedList<CellTowerOverlayItem> items = new LinkedList<>();

mDbHelper.open();
Expand Down Expand Up @@ -510,15 +501,8 @@ protected void onPostExecute(GeoPoint defaultLoc) {
}
}
}

new Thread() {
@Override
public void run() {
loadOpenCellIDMarkers();
}
}.start();
}
}.execute();
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

private void loadOpenCellIDMarkers() {
Expand Down Expand Up @@ -557,118 +541,6 @@ private void loadOpenCellIDMarkers() {
mMap.getOverlays().add(mOpenCellIdOverlay);
}

public class MarkerData {

public final String cellID;
public final String lat;
public final String lng;
public final String lac;
public final String mcc;
public final String mnc;
public final String samples;
public final boolean openCellID;

MarkerData(String cell_id,
String latitude,
String longitude,
String local_area_code,
String mobile_country_code,
String mobile_network_code,
String samples_taken,
boolean openCellID_Data) {
cellID = cell_id;
lat = latitude;
lng = longitude;
lac = local_area_code;
mcc = mobile_country_code;
mnc = mobile_network_code;
samples = samples_taken;
openCellID = openCellID_Data;
}
}

public class CellTowerOverlayItem extends OverlayItem {
MarkerData mMarkerData;

public CellTowerOverlayItem(String aTitle, String aSnippet, GeoPoint aGeoPoint, MarkerData data) {
super(aTitle, aSnippet, aGeoPoint);
mMarkerData = data;
}

public MarkerData getMarkerData() {
return mMarkerData;
}
}

public class CellTowerItemizedOverlay extends ItemizedIconOverlay<CellTowerOverlayItem> {
protected Context mContext;

public CellTowerItemizedOverlay(final Context context, final List<CellTowerOverlayItem> aList) {
super(context, aList, new OnItemGestureListener<CellTowerOverlayItem>() {
@Override public boolean onItemSingleTapUp(final int index, final CellTowerOverlayItem item) {
return false;
}
@Override public boolean onItemLongPress(final int index, final CellTowerOverlayItem item) {
return false;
}
} );

mContext = context;
}

@Override
protected boolean onSingleTapUpHelper(final int index, final CellTowerOverlayItem item, final MapView mapView) {
// TODO - show as info window
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setView(getInfoContents(item.getMarkerData()));
dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
dialog.show();
return true;
}

// Defines the contents of the InfoWindow
public View getInfoContents(MarkerData data) {

TextView tv;

// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.marker_info_window, null);

if (v != null) {
if (data != null) {
if (data.openCellID) {
TableRow tr = (TableRow) v.findViewById(R.id.open_cell_label);
tr.setVisibility(View.VISIBLE);
}

tv = (TextView) v.findViewById(R.id.cell_id);
tv.setText(data.cellID);
tv = (TextView) v.findViewById(R.id.lac);
tv.setText(data.lac);
tv = (TextView) v.findViewById(R.id.lat);
tv.setText(String.valueOf(data.lat));
tv = (TextView) v.findViewById(R.id.lng);
tv.setText(String.valueOf(data.lng));
tv = (TextView) v.findViewById(R.id.mcc);
tv.setText(data.mcc);
tv = (TextView) v.findViewById(R.id.mnc);
tv.setText(data.mnc);
tv = (TextView) v.findViewById(R.id.samples);
tv.setText(data.samples);
}
}

// Returning the view containing InfoWindow contents
return v;
}
}

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
final String KEY_MAP_TYPE = getBaseContext().getString(R.string.pref_map_type_key);
if (key.equals(KEY_MAP_TYPE)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.SecUpwN.AIMSICD.map;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TableRow;
import android.widget.TextView;

import com.SecUpwN.AIMSICD.R;

import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ItemizedIconOverlay;

import java.util.List;

/**
* Overlay class for OSMDroid map to display BTS pins
*/
public class CellTowerItemizedOverlay extends ItemizedIconOverlay<CellTowerOverlayItem> {
protected Context mContext;

public CellTowerItemizedOverlay(final Context context, final List<CellTowerOverlayItem> aList) {
super(context, aList, new OnItemGestureListener<CellTowerOverlayItem>() {
@Override
public boolean onItemSingleTapUp(final int index, final CellTowerOverlayItem item) {
return false;
}

@Override
public boolean onItemLongPress(final int index, final CellTowerOverlayItem item) {
return false;
}
});

mContext = context;
}

@Override
protected boolean onSingleTapUpHelper(final int index, final CellTowerOverlayItem item, final MapView mapView) {
// TODO - show as info window
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setView(getInfoContents(item.getMarkerData()));
dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
dialog.show();
return true;
}

// Defines the contents of the InfoWindow
public View getInfoContents(MarkerData data) {

TextView tv;

// Getting view from the layout file info_window_layout
View v = LayoutInflater.from(mContext).inflate(R.layout.marker_info_window, null);

if (v != null) {
if (data != null) {
if (data.openCellID) {
TableRow tr = (TableRow) v.findViewById(R.id.open_cell_label);
tr.setVisibility(View.VISIBLE);
}

tv = (TextView) v.findViewById(R.id.cell_id);
tv.setText(data.cellID);
tv = (TextView) v.findViewById(R.id.lac);
tv.setText(data.lac);
tv = (TextView) v.findViewById(R.id.lat);
tv.setText(String.valueOf(data.lat));
tv = (TextView) v.findViewById(R.id.lng);
tv.setText(String.valueOf(data.lng));
tv = (TextView) v.findViewById(R.id.mcc);
tv.setText(data.getMCC());
tv = (TextView) v.findViewById(R.id.mnc);
tv.setText(data.getMNC());
tv = (TextView) v.findViewById(R.id.pc);
tv.setText(data.getPC());
tv = (TextView) v.findViewById(R.id.samples);
tv.setText(data.getSamples());
}
}

// Returning the view containing InfoWindow contents
return v;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.SecUpwN.AIMSICD.map;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.overlay.OverlayItem;

/**
* BTS pin item
*/
public class CellTowerOverlayItem extends OverlayItem {
MarkerData mMarkerData;

public CellTowerOverlayItem(String aTitle, String aSnippet, GeoPoint aGeoPoint, MarkerData data) {
super(aTitle, aSnippet, aGeoPoint);
mMarkerData = data;
}

public MarkerData getMarkerData() {
return mMarkerData;
}
}
Loading