Skip to content

Commit

Permalink
Merge pull request #45 from xLaMbChOpSx/master
Browse files Browse the repository at this point in the history
Database Viewer
  • Loading branch information
xLaMbChOpSx committed Apr 25, 2014
2 parents 65615ce + b4290c1 commit d2609f8
Show file tree
Hide file tree
Showing 17 changed files with 694 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
</intent-filter>
</receiver>

<activity
android:name=".DbViewer"
android:exported="true"
android:label="@string/db_viewer"
android:parentActivityName=".AIMSICD" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".AIMSICD" />
</activity>

<activity
android:name=".MapViewer"
android:exported="true"
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
Intent intent;
switch (item.getItemId()) {
case R.id.track_cell:
trackcell();
Expand All @@ -304,8 +305,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.show_map:
showmap();
return true;
case R.id.view_db:
intent = new Intent(this, DbViewer.class);
startActivity(intent);
return true;
case R.id.preferences:
Intent intent = new Intent(this, PrefActivity.class);
intent = new Intent(this, PrefActivity.class);
startActivity(intent);
return true;
case R.id.export_database:
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/com/SecUpwN/AIMSICD/AIMSICDDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;

import au.com.bytecode.opencsv.CSVWriter;

Expand Down Expand Up @@ -203,6 +204,33 @@ public Cursor getSignalData() {
"Lat <> 0.0 AND lng <> 0.0",null,null,null,null,null);
}

/**
* Returns Cell Information database contents
*/
public Cursor getCellData() {
return mDb.query(CELL_TABLE, new String[] {"CellID", "Lac", "Net", "Lat", "Lng",
"Signal"},
null,null,null,null, null);
}

/**
* Returns Location Information database contents
*/
public Cursor getLocationData() {
return mDb.query(LOCATION_TABLE, new String[] {"CellID", "Lac", "Net", "Lat", "Lng",
"Signal"},
null,null,null,null,null);
}

/**
* Returns OpenCellID database contents
*/
public Cursor getOpenCellIDData() {
return mDb.query(OPENCELLID_TABLE, new String[] {"CellID", "Lac", "Mcc", "Mnc", "Lat", "Lng",
"AvgSigStr", "Samples"},
null,null,null,null,null);
}

/**
* Checks to see if Location already exists in database
*/
Expand Down
128 changes: 128 additions & 0 deletions app/src/main/java/com/SecUpwN/AIMSICD/DbViewer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.SecUpwN.AIMSICD;

import com.SecUpwN.AIMSICD.adapters.BaseInflaterAdapter;
import com.SecUpwN.AIMSICD.adapters.CardItemData;
import com.SecUpwN.AIMSICD.adapters.CellCardInflater;
import com.SecUpwN.AIMSICD.adapters.OpenCellIdCardInflater;

import android.app.Activity;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TableLayout;

public class DbViewer extends Activity {

private final AIMSICDDbAdapter mDb = new AIMSICDDbAdapter(this);
private Spinner tblSpinner;
private String mTableSelected;
private boolean mMadeSelection;
private ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.db_view);
lv = (ListView) findViewById(R.id.list_view);
lv.addHeaderView(new View(this));
lv.addFooterView(new View(this));
tblSpinner = (Spinner) findViewById(R.id.table_spinner);
tblSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView,
int position, long id) {
mTableSelected = String.valueOf(tblSpinner.getSelectedItem());
mMadeSelection = true;
}

@Override
public void onNothingSelected(AdapterView<?> parentView) {
mMadeSelection = false;
}

});

Button loadTable = (Button) findViewById(R.id.load_table_data);

loadTable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mMadeSelection) {
new MyAsync().execute();
}
}
});
}

private void BuildTable(Cursor tableData) {
if (tableData != null && tableData.moveToFirst()) {

if (mTableSelected.equals("OpenCellID Data")) {
BaseInflaterAdapter<CardItemData> adapter = new BaseInflaterAdapter<CardItemData>(
new OpenCellIdCardInflater());
while (tableData.moveToNext()) {
CardItemData data = new CardItemData("CellID: " + tableData.getString(0),
"LAC: " + tableData.getString(1), "MCC: " + tableData.getString(2),
"MNC: " + tableData.getString(3), "Latitude: " + tableData.getString(4),
"Longitude: " + tableData.getString(5), "Average Signal Strength: " + tableData.getString(6),
"Samples: " + tableData.getString(7));
adapter.addItem(data, false);
}
lv.setAdapter(adapter);
} else {
BaseInflaterAdapter<CardItemData> adapter = new BaseInflaterAdapter<CardItemData>(
new CellCardInflater());
while (tableData.moveToNext()){
CardItemData data = new CardItemData("CellID: " + tableData.getString(0),
"LAC: " + tableData.getString(1),
"Network Type: " + tableData.getString(2),
"Latitude: " + tableData.getString(3),
"Longitude: " + tableData.getString(4),
"Signal Strength: " + tableData.getString(5));
adapter.addItem(data, false);
}
lv.setAdapter(adapter);
}
} else {
Helpers.sendMsg(this, "Table contains no data to display");
}
}

private class MyAsync extends AsyncTask<Cursor, Cursor, Cursor> {

@Override
protected void onPreExecute() {
super.onPreExecute();
}

@Override
protected Cursor doInBackground(Cursor... params) {
mDb.open();
if (mTableSelected.equals("Cell Data")) {
return mDb.getCellData();
} else if (mTableSelected.equals("Signal Strength Data")) {
return mDb.getSignalData();
} else if (mTableSelected.equals("Location Data")) {
return mDb.getLocationData();
} else if (mTableSelected.equals("OpenCellID Data")) {
return mDb.getOpenCellIDData();
}

return null;
}

@Override
protected void onPostExecute(Cursor result) {
super.onPostExecute(result);
BuildTable(result);
mDb.close();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.SecUpwN.AIMSICD.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class BaseInflaterAdapter<T> extends BaseAdapter
{
private List<T> m_items = new ArrayList<T>();
private IAdapterViewInflater<T> m_viewInflater;

public BaseInflaterAdapter(IAdapterViewInflater<T> viewInflater)
{
m_viewInflater = viewInflater;
}

public BaseInflaterAdapter(List<T> items, IAdapterViewInflater<T> viewInflater)
{
m_items.addAll(items);
m_viewInflater = viewInflater;
}

public void setViewInflater(IAdapterViewInflater<T> viewInflater, boolean notifyChange)
{
m_viewInflater = viewInflater;

if (notifyChange)
notifyDataSetChanged();
}

public void addItem(T item, boolean notifyChange)
{
m_items.add(item);

if (notifyChange)
notifyDataSetChanged();
}

public void addItems(List<T> items, boolean notifyChange)
{
m_items.addAll(items);

if (notifyChange)
notifyDataSetChanged();
}

public void clear(boolean notifyChange)
{
m_items.clear();

if (notifyChange)
notifyDataSetChanged();
}

@Override
public int getCount()
{
return m_items.size();
}

@Override
public Object getItem(int pos)
{
return getTItem(pos);
}

public T getTItem(int pos)
{
return m_items.get(pos);
}

@Override
public long getItemId(int pos)
{
return pos;
}

@Override
public View getView(int pos, View convertView, ViewGroup parent)
{
return m_viewInflater != null ? m_viewInflater.inflate(this, pos, convertView, parent) : null;
}
}
79 changes: 79 additions & 0 deletions app/src/main/java/com/SecUpwN/AIMSICD/adapters/CardItemData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.SecUpwN.AIMSICD.adapters;

public class CardItemData
{
private String mCellID;
private String mLac;
private String mMcc;
private String mMnc;
private String mNet;
private String mSignal;
private String mAvgSigStr;
private String mSamples;
private String mLat;
private String mLng;


public CardItemData(String cellID, String lac, String mcc, String mnc, String lat, String lng,
String avgSigStr, String samples)
{
mCellID = cellID;
mLac = lac;
mMcc = mcc;
mMnc = mnc;
mLat = lat;
mLng = lng;
mAvgSigStr = avgSigStr;
mSamples = samples;
}

public CardItemData(String cellID, String lac, String net, String lat, String lng, String signal)
{
mCellID = cellID;
mLac = lac;
mNet = net;
mLat = lat;
mLng = lng;
mSignal = signal;
}

public String getCellID() {
return mCellID;
}

public String getLac() {
return mLac;
}

public String getMcc() {
return mMcc;
}

public String getMnc() {
return mMnc;
}

public String getNet() {
return mNet;
}

public String getSignal() {
return mSignal;
}

public String getAvgSigStr() {
return mAvgSigStr;
}

public String getSamples() {
return mSamples;
}

public String getLat() {
return mLat;
}

public String getLng() {
return mLng;
}
}
Loading

0 comments on commit d2609f8

Please sign in to comment.