11package com .SecUpwN .AIMSICD .fragments ;
22
33import android .app .Activity ;
4- import android .content .Context ;
54import android .database .Cursor ;
65import android .os .AsyncTask ;
76import android .os .Bundle ;
1918import com .SecUpwN .AIMSICD .adapters .BtsMeasureCardInflater ;
2019import com .SecUpwN .AIMSICD .adapters .BtsMeasureItemData ;
2120import com .SecUpwN .AIMSICD .adapters .CardItemData ;
22- import com .SecUpwN .AIMSICD .adapters .CellCardInflater ;
2321import com .SecUpwN .AIMSICD .adapters .DbViewerSpinnerAdapter ;
2422import com .SecUpwN .AIMSICD .adapters .DbeImportCardInflater ;
2523import com .SecUpwN .AIMSICD .adapters .DbeImportItemData ;
2826import com .SecUpwN .AIMSICD .adapters .EventLogItemData ;
2927import com .SecUpwN .AIMSICD .adapters .MeasuredCellStrengthCardData ;
3028import com .SecUpwN .AIMSICD .adapters .MeasuredCellStrengthCardInflater ;
31- import com .SecUpwN .AIMSICD .adapters .OpenCellIdCardInflater ;
3229import com .SecUpwN .AIMSICD .adapters .SilentSmsCardData ;
33- import com .SecUpwN .AIMSICD .adapters .SilentSmsCardInflater ;
3430import com .SecUpwN .AIMSICD .adapters .UniqueBtsCardInflater ;
3531import com .SecUpwN .AIMSICD .adapters .UniqueBtsItemData ;
3632import com .SecUpwN .AIMSICD .constants .DBTableColumnIds ;
4137import com .SecUpwN .AIMSICD .smsdetection .DetectionStringsCardInflater ;
4238import com .SecUpwN .AIMSICD .smsdetection .DetectionStringsData ;
4339
44- import java .util .ArrayList ;
45-
4640/**
47- * Description: Class that handles the display of the items in the 'Database Viewer' (DBV)
48- *
49- * Issues:
50- *
51- * Notes: See issue #234 for details on how to format the UI
52- *
53- * ChangeLog:
54- *
55- * 2015-07-14 E:V:A Changed the display names of several items (see issue #234)
56- * 2015-07-31 E:V:A Added comments and changed some inflater data to avoid using:
57- * DBTableColumnIds.java. More to do... Use string convert trick:
58- * "" + int = "string" (See EventLog for example)
59- *
41+ * Description: Class that handles the display of the items in the 'Database Viewer' (DBV)
42+ * <p/>
43+ * Issues:
44+ * <p/>
45+ * Notes: See issue #234 for details on how to format the UI
46+ * <p/>
47+ * ChangeLog:
48+ * <p/>
49+ * 2015-07-14 E:V:A Changed the display names of several items (see issue #234)
50+ * 2015-07-31 E:V:A Added comments and changed some inflater data to avoid using:
51+ * DBTableColumnIds.java. More to do... Use string convert trick:
52+ * "" + int = "string" (See EventLog for example)
6053 */
61- public class DbViewerFragment extends Fragment {
54+ public final class DbViewerFragment extends Fragment {
6255
6356 private AIMSICDDbAdapter mDb ;
6457 private StatesDbViewer mTableSelected ;
65- private Context mContext ;
6658
6759 // Layout items
6860 private Spinner tblSpinner ;
@@ -75,35 +67,32 @@ public DbViewerFragment() {
7567 @ Override
7668 public void onAttach (Activity activity ) {
7769 super .onAttach (activity );
78- mContext = activity .getBaseContext ();
79- mDb = new AIMSICDDbAdapter (mContext );
70+ mDb = new AIMSICDDbAdapter (activity .getBaseContext ());
8071 }
8172
8273 @ Override
8374 public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
84-
8575 View view = inflater .inflate (R .layout .db_view , container , false );
8676
8777 lv = (ListView ) view .findViewById (R .id .list_view );
8878 emptyView = view .findViewById (R .id .db_list_empty );
8979 tblSpinner = (Spinner ) view .findViewById (R .id .table_spinner );
9080 DbViewerSpinnerAdapter mSpinnerAdapter = new DbViewerSpinnerAdapter (getActivity (), R .layout .item_spinner_db_viewer );
9181 tblSpinner .setAdapter (mSpinnerAdapter );
92-
93- Spinner spnLocale = (Spinner ) view .findViewById (R .id .table_spinner );
94- spnLocale .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
82+ tblSpinner .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
9583 @ Override
9684 public void onItemSelected (AdapterView <?> parentView , View selectedItemView , final int position , long id ) {
97-
98- new AsyncTask <Void , Void , BaseInflaterAdapter > () {
85+ Object selectedItem = tblSpinner .getSelectedItem ();
86+ if (!(selectedItem instanceof StatesDbViewer )) {
87+ return ;
88+ }
89+ mTableSelected = (StatesDbViewer ) selectedItem ;
90+ new AsyncTask <Void , Void , BaseInflaterAdapter >() {
9991
10092 @ Override
10193 protected BaseInflaterAdapter doInBackground (Void ... params ) {
10294 //# mDb.open();
10395 Cursor result ;
104- ArrayList <String > CellDetails = new ArrayList <String >();
105-
106- mTableSelected = (StatesDbViewer )tblSpinner .getSelectedItem ();
10796
10897 switch (position ) {
10998 case 0 : // UNIQUE_BTS_DATA ("DBi_bts")
@@ -156,9 +145,9 @@ protected BaseInflaterAdapter doInBackground(Void... params) {
156145 BaseInflaterAdapter adapter = null ;
157146 if (result != null ) {
158147 adapter = BuildTable (result );
148+ result .close ();
159149 }
160- //# mDb.close();
161- result .close ();
150+
162151 return adapter ;
163152 }
164153
@@ -182,7 +171,6 @@ protected void onPostExecute(BaseInflaterAdapter adapter) {
182171
183172 @ Override
184173 public void onNothingSelected (AdapterView <?> parentView ) {
185- return ;
186174 }
187175 });
188176
@@ -191,24 +179,23 @@ public void onNothingSelected(AdapterView<?> parentView) {
191179
192180 /**
193181 * Description: Content layout and presentation of the Database Viewer
194- *
195- * This is where the text labels are created for each column in
196- * the Database Viewer (DBV). For details of how this should be presented, see:
197- * https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/234
198- *
182+ * <p/>
183+ * This is where the text labels are created for each column in
184+ * the Database Viewer (DBV). For details of how this should be presented, see:
185+ * https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/234
186+ * <p/>
199187 * Lat/Lng: Latitude / Longitude (We should use "Lon" instead of "Lng".)
200188 * AvgSignal: Average Signal Strength
201189 * RSSI: Received Signal Strength Indicator (previously "Signal Strength")
202- * Can have different meanings on different RAN's, e.g. RSCP in UMTS.
190+ * Can have different meanings on different RAN's, e.g. RSCP in UMTS.
203191 * RAN: Radio Access Network (GSM, UMTS, LTE etc.)
204- *
192+ * <p/>
205193 * Notes:
206- *
207- * 1. Although "RAN" is more correct here, we'll use "RAT" (Radio Access Technology),
208- * which is the more common terminology. Thus reverting.
209- *
210- * 2. Since Signal is not an "indicator" we should just call it "RSS" or "RXS"
211- *
194+ * <p/>
195+ * 1. Although "RAN" is more correct here, we'll use "RAT" (Radio Access Technology),
196+ * which is the more common terminology. Thus reverting.
197+ * <p/>
198+ * 2. Since Signal is not an "indicator" we should just call it "RSS" or "RXS"
212199 */
213200 private BaseInflaterAdapter BuildTable (Cursor tableData ) {
214201 if (tableData != null && tableData .getCount () > 0 ) {
@@ -235,7 +222,7 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) {
235222 tableData .getString (tableData .getColumnIndex (DBTableColumnIds .DBI_BTS_LON )), // gps_lon
236223 (tableData .getPosition () + 1 ) + " / " + count // item: "n/X"
237224 );
238- adapter .addItem (data ,false );
225+ adapter .addItem (data , false );
239226 }
240227 if (!tableData .isClosed ()) {
241228 tableData .close ();
@@ -254,7 +241,7 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) {
254241 // WARNING! The ORDER and number of these are crucial, and need to correspond
255242 // to what's found in: BtsMeasureCardInflater.java and BtsMeasureItemData.java
256243 BtsMeasureItemData data = new BtsMeasureItemData (
257- "bts_id: " + String .valueOf (tableData .getInt (tableData .getColumnIndex (DBTableColumnIds .DBI_MEASURE_BTS_ID ))), // TODO: Wrong! Should be DBi_bts:CID
244+ "bts_id: " + String .valueOf (tableData .getInt (tableData .getColumnIndex (DBTableColumnIds .DBI_MEASURE_BTS_ID ))), // TODO: Wrong! Should be DBi_bts:CID
258245 "n/a" , // + tableData.getString(tableData.getColumnIndex(DBTableColumnIds.DBI_MEASURE_NC_LIST)), // nc_list TODO: fix
259246 tableData .getString (tableData .getColumnIndex (DBTableColumnIds .DBI_MEASURE_TIME )), // time
260247 tableData .getString (tableData .getColumnIndex (DBTableColumnIds .DBI_MEASURE_GPSD_LAT )), // gpsd_lat
@@ -397,10 +384,10 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) {
397384 //int count = tableData.getCount();
398385 while (tableData .moveToNext ()) {
399386 MeasuredCellStrengthCardData data = new MeasuredCellStrengthCardData (
400- tableData .getInt (tableData .getColumnIndex ("bts_id" )), // TODO: CID
401- Integer .parseInt (tableData .getString (tableData .getColumnIndex ("rx_signal" ))), // rx_signal
402- tableData .getString (tableData .getColumnIndex ("time" )) // time
403- //"" + (tableData.getPosition() + 1) + " / " + count // item: "n/X"
387+ tableData .getInt (tableData .getColumnIndex ("bts_id" )), // TODO: CID
388+ Integer .parseInt (tableData .getString (tableData .getColumnIndex ("rx_signal" ))), // rx_signal
389+ tableData .getString (tableData .getColumnIndex ("time" )) // time
390+ //"" + (tableData.getPosition() + 1) + " / " + count // item: "n/X"
404391 );
405392 adapter .addItem (data , false );
406393 }
@@ -446,7 +433,6 @@ private BaseInflaterAdapter BuildTable(Cursor tableData) {
446433 // Storage of Abnormal SMS detection strings
447434 BaseInflaterAdapter <DetectionStringsData > adapter
448435 = new BaseInflaterAdapter <>(new DetectionStringsCardInflater ());
449- int count = tableData .getCount ();
450436 while (tableData .moveToNext ()) {
451437 DetectionStringsData data = new DetectionStringsData (
452438 tableData .getString (tableData .getColumnIndex ("det_str" )), // det_str
0 commit comments