RecordOverviewFragment.java 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. package de.tudarmstadt.informatik.hostage.ui2.fragment;
  2. import android.annotation.SuppressLint;
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.app.FragmentManager;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.content.Intent;
  9. import android.content.SharedPreferences;
  10. import android.os.Bundle;
  11. import android.os.Environment;
  12. import android.preference.PreferenceManager;
  13. import android.util.Log;
  14. import android.view.LayoutInflater;
  15. import android.view.Menu;
  16. import android.view.MenuInflater;
  17. import android.view.MenuItem;
  18. import android.view.View;
  19. import android.view.ViewGroup;
  20. import android.widget.ExpandableListView;
  21. import android.widget.ImageButton;
  22. import android.widget.ProgressBar;
  23. import android.widget.Toast;
  24. import com.google.android.gms.maps.model.LatLng;
  25. import java.io.File;
  26. import java.io.FileOutputStream;
  27. import java.text.DateFormat;
  28. import java.text.SimpleDateFormat;
  29. import java.util.ArrayList;
  30. import java.util.Calendar;
  31. import java.util.Collections;
  32. import java.util.Comparator;
  33. import java.util.Date;
  34. import java.util.HashMap;
  35. import java.util.Random;
  36. import de.tudarmstadt.informatik.hostage.R;
  37. import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
  38. import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
  39. import de.tudarmstadt.informatik.hostage.logging.MessageRecord;
  40. import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
  41. import de.tudarmstadt.informatik.hostage.logging.Record;
  42. import de.tudarmstadt.informatik.hostage.logging.formatter.TraCINgFormatter;
  43. import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
  44. import de.tudarmstadt.informatik.hostage.sync.bluetooth.BluetoothSync;
  45. import de.tudarmstadt.informatik.hostage.sync.nfc.NFCSync;
  46. import de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncActivity;
  47. import de.tudarmstadt.informatik.hostage.ui2.model.LogFilter;
  48. import de.tudarmstadt.informatik.hostage.ui2.model.LogFilter.SortType;
  49. import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
  50. import de.tudarmstadt.informatik.hostage.ui2.adapter.RecordListAdapter;
  51. import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
  52. import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
  53. import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
  54. import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
  55. import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
  56. import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupItem;
  57. import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupTable;
  58. import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
  59. public class RecordOverviewFragment extends UpNavigatibleFragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
  60. static final String FILTER_MENU_TITLE_BSSID = "BSSID";
  61. static final String FILTER_MENU_TITLE_ESSID = "ESSID";
  62. static final String FILTER_MENU_TITLE_PROTOCOLS = MainActivity.getContext().getString(R.string.rec_protocol);
  63. static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = MainActivity.getContext().getString(
  64. R.string.rec_latest);
  65. static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = MainActivity.getContext().getString(
  66. R.string.rec_earliest);
  67. static final String FILTER_MENU_TITLE_SORTING = MainActivity.getContext().getString(R.string.rec_sortby);
  68. static final String FILTER_MENU_TITLE_REMOVE = MainActivity.getContext().getString(R.string.rec_reset_filter);
  69. static final String FILTER_MENU_TITLE_GROUP = MainActivity.getContext().getString(
  70. R.string.rec_group_by);
  71. static final String FILTER_MENU_POPUP_TITLE = MainActivity.getContext().getString(
  72. R.string.rec_filter_by);
  73. private boolean wasBelowTimePicker;
  74. private LogFilter filter;
  75. private boolean showFilterButton;
  76. private View rootView;
  77. private int mListPosition = -1;
  78. private int mItemPosition = -1;
  79. public String groupingKey;
  80. private ExpandableListView expListView;
  81. private ProgressBar spinner;
  82. private Toast noDataNotificationToast;
  83. HostageDBOpenHelper dbh;
  84. private String sectionToOpen = "";
  85. private ArrayList<Integer> openSections;
  86. private SharedPreferences pref;
  87. public void setFilter(LogFilter filter){
  88. this.filter = filter;
  89. }
  90. Thread loader;
  91. public RecordOverviewFragment(){}
  92. public void setGroupKey(String key){
  93. this.groupingKey = key;
  94. }
  95. @Override
  96. public void onCreate(Bundle savedInstanceState) {
  97. super.onCreate(savedInstanceState);
  98. setHasOptionsMenu(true);
  99. }
  100. @Override
  101. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  102. Bundle savedInstanceState) {
  103. setHasOptionsMenu(true);
  104. getActivity().setTitle(getResources().getString(R.string.drawer_records));
  105. dbh = new HostageDBOpenHelper(this.getActivity().getBaseContext());
  106. pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
  107. // Get the message from the intent
  108. if (this.filter == null){
  109. Intent intent = this.getActivity().getIntent();
  110. LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
  111. if(filter == null){
  112. this.clearFilter();
  113. } else {
  114. this.filter = filter;
  115. }
  116. }
  117. if (this.groupingKey == null) this.groupingKey = this.groupingTitles().get(0);
  118. this.setShowFilterButton(!this.filter.isNotEditable());
  119. View rootView = inflater.inflate(this.getLayoutId(), container, false);
  120. this.rootView = rootView;
  121. ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
  122. this.spinner =(ProgressBar) rootView.findViewById(R.id.progressBar1);
  123. this.spinner.setVisibility(View.GONE);
  124. this.expListView = mylist;
  125. this.initialiseListView();
  126. ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
  127. filterButton.setOnClickListener(new View.OnClickListener() {
  128. public void onClick(View v) {
  129. RecordOverviewFragment.this.openFilterPopupMenuOnView(v);
  130. }
  131. });
  132. filterButton.setVisibility(this.showFilterButton? View.VISIBLE : View.INVISIBLE);
  133. ImageButton sortButton = (ImageButton) rootView.findViewById(R.id.SortButton);
  134. sortButton.setOnClickListener(new View.OnClickListener() {
  135. public void onClick(View v) {
  136. // Open SortMenu
  137. RecordOverviewFragment.this.openSortingDialog();
  138. }
  139. });
  140. ImageButton groupButton = (ImageButton) rootView.findViewById(R.id.GroupButton);
  141. groupButton.setOnClickListener(new View.OnClickListener() {
  142. public void onClick(View v) {
  143. // Open SortMenu
  144. RecordOverviewFragment.this.openGroupingDialog();
  145. }
  146. });
  147. return rootView;
  148. }
  149. /**Initialises the expandable list view in a backgorund thread*/
  150. private void initialiseListView(){
  151. if (loader != null) loader.interrupt();
  152. this.spinner.setVisibility(View.VISIBLE);
  153. loader = new Thread(new Runnable(){
  154. private void updateUI(final RecordListAdapter currentAdapter)
  155. {
  156. if(loader.isInterrupted()){
  157. return;
  158. }
  159. Activity activity = RecordOverviewFragment.this.getActivity();
  160. if (activity != null){
  161. activity.runOnUiThread(new Runnable() {
  162. @Override
  163. public void run() {
  164. RecordOverviewFragment.this.expListView.setAdapter(currentAdapter);
  165. // Update view and remove loading spinner etc...
  166. RecordListAdapter adapter = (RecordListAdapter) RecordOverviewFragment.this.expListView.getExpandableListAdapter();
  167. if (adapter != null){
  168. adapter.notifyDataSetChanged();
  169. if (adapter.getGroupCount() == 1){
  170. RecordOverviewFragment.this.expListView.expandGroup(0);
  171. } else {
  172. RecordOverviewFragment.this.setSectionToOpen(RecordOverviewFragment.this.sectionToOpen);
  173. }
  174. }
  175. if (RecordOverviewFragment.this.openSections != null && RecordOverviewFragment.this.openSections.size() != 0){
  176. for (int i = 0; i < RecordOverviewFragment.this.openSections.size(); i++){
  177. int index = RecordOverviewFragment.this.openSections.get(i);
  178. RecordOverviewFragment.this.expListView.expandGroup(index);
  179. }
  180. } else {
  181. RecordOverviewFragment.this.openSections = new ArrayList<Integer>();
  182. }
  183. if (mListPosition != -1 && mItemPosition != -1)
  184. RecordOverviewFragment.this.expListView.setSelectedChild(mListPosition, mItemPosition, true);
  185. mListPosition = -1;
  186. mItemPosition = -1;
  187. registerListClickCallback(RecordOverviewFragment.this.expListView);
  188. RecordOverviewFragment.this.spinner.setVisibility(View.GONE);
  189. RecordOverviewFragment.this.actualiseFilterButton();
  190. RecordOverviewFragment.this.showEmptyDataNotification();
  191. }
  192. });
  193. }
  194. }
  195. private RecordListAdapter doInBackground()
  196. {
  197. return populateListViewFromDB(RecordOverviewFragment.this.expListView);
  198. }
  199. @Override
  200. public void run()
  201. {
  202. //RecordOverviewFragment.this.addRecordToDB(5, 10, 1);
  203. updateUI(doInBackground());
  204. }
  205. });
  206. loader.start();
  207. this.actualiseFilterButton();
  208. }
  209. /**
  210. * Returns the Fragment layout ID
  211. * @return int The fragment layout ID
  212. * */
  213. public int getLayoutId(){
  214. return R.layout.fragment_record_list;
  215. }
  216. /**
  217. * Gets called if the user clicks on item in the filter menu.
  218. *
  219. * @param item {@link AbstractPopupItem AbstractPopupItem }
  220. * */
  221. public void onFilterMenuItemSelected(AbstractPopupItem item) {
  222. String title = item.getTitle();
  223. if (item instanceof SplitPopupItem){
  224. SplitPopupItem splitItem = (SplitPopupItem)item;
  225. if (splitItem.wasRightTouch){
  226. this.openTimestampToFilterDialog();
  227. } else {
  228. this.openTimestampFromFilterDialog();
  229. }
  230. return;
  231. }
  232. if (title != null){
  233. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  234. this.openBSSIDFilterDialog();
  235. }
  236. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  237. this.openESSIDFilterDialog();
  238. }
  239. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  240. this.openProtocolsFilterDialog();
  241. }
  242. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  243. this.openSortingDialog();
  244. }
  245. if(title.equals(FILTER_MENU_TITLE_REMOVE)){
  246. this.clearFilter();
  247. this.actualiseListViewInBackground();
  248. }
  249. if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  250. this.openTimestampToFilterDialog();
  251. }
  252. if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  253. this.openTimestampFromFilterDialog();
  254. }
  255. }
  256. //return super.onOptionsItemSelected(item);
  257. }
  258. @Override
  259. public void onStart() {
  260. super.onStart();
  261. if (this.expListView.getExpandableListAdapter() != null){
  262. if (this.expListView.getExpandableListAdapter().getGroupCount() == 1){
  263. this.expListView.expandGroup(0);
  264. } else {
  265. this.setSectionToOpen(this.sectionToOpen);
  266. }
  267. }
  268. }
  269. @Override
  270. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  271. // Inflate the menu items for use in the action bar
  272. inflater.inflate(R.menu.records_overview_actions, menu);
  273. }
  274. @Override
  275. public boolean onOptionsItemSelected(MenuItem item) {
  276. switch (item.getItemId()) {
  277. case R.id.records_action_synchronize:
  278. AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
  279. builder.setTitle("Synchronize records");
  280. builder.setItems(new String[]{
  281. "Via Bluetooth",
  282. "Via NFC",
  283. "Via Online Database"
  284. }, new DialogInterface.OnClickListener() {
  285. @Override
  286. public void onClick(DialogInterface dialog, int position) {
  287. switch(position){
  288. case 0:
  289. getActivity().startActivity(new Intent(getActivity(), BluetoothSync.class));
  290. break;
  291. case 1:
  292. getActivity().startActivity(new Intent(getActivity(), NFCSync.class));
  293. break;
  294. case 2:
  295. getActivity().startActivity(new Intent(getActivity(), TracingSyncActivity.class));
  296. break;
  297. }
  298. }
  299. });
  300. builder.create();
  301. builder.show();
  302. return true;
  303. case R.id.records_action_export:
  304. AlertDialog.Builder builderExport = new AlertDialog.Builder(getActivity());
  305. builderExport.setTitle("Choose export format");
  306. builderExport.setItems(R.array.format, new DialogInterface.OnClickListener() {
  307. @Override
  308. public void onClick(DialogInterface dialog, int position) {
  309. RecordOverviewFragment.this.exportDatabase(position);
  310. }
  311. });
  312. builderExport.create();
  313. builderExport.show();
  314. return true;
  315. }
  316. return false;
  317. }
  318. private void exportDatabase(int format) {
  319. try {
  320. FileOutputStream log;
  321. String filename = "hostage_" + format + "_" + System.currentTimeMillis() + ".log";
  322. String externalLocation = pref.getString("pref_external_location",
  323. "");
  324. String root = Environment.getExternalStorageDirectory()
  325. .toString();
  326. if (root != null && HelperUtils.isExternalStorageWritable()) {
  327. File dir = new File(root + externalLocation);
  328. dir.mkdirs();
  329. File file = new File(dir, filename);
  330. log = new FileOutputStream(file);
  331. } else {
  332. Toast.makeText(getActivity(), "Could not write to SD Card",
  333. Toast.LENGTH_SHORT).show();
  334. return;
  335. }
  336. ArrayList<Record> records = dbh.getAllRecords();
  337. for (Record record : records) {
  338. log.write((record.toString((format == 1) ? TraCINgFormatter
  339. .getInstance() : null)).getBytes());
  340. }
  341. log.flush();
  342. log.close();
  343. Toast.makeText(
  344. getActivity(),
  345. "Exported records to " + externalLocation + filename, Toast.LENGTH_LONG)
  346. .show();
  347. } catch (Exception e) {
  348. Toast.makeText(getActivity(), "Could not write to SD Card",
  349. Toast.LENGTH_SHORT).show();
  350. e.printStackTrace();
  351. }
  352. }
  353. /*****************************
  354. *
  355. * Public API
  356. *
  357. * ***************************/
  358. /**
  359. * Group records by SSID and expand given SSID
  360. *
  361. * @param SSID the SSID
  362. */
  363. public void showDetailsForSSID(Context context, String SSID) {
  364. Log.e("RecordOverviewFragment", "Implement showDetailsForSSID!!");
  365. this.clearFilter();
  366. int ESSID_INDEX = 2;
  367. ArrayList<String> ssids = new ArrayList<String>();
  368. this.sectionToOpen = SSID;
  369. this.groupingKey = this.groupingTitles(context).get(ESSID_INDEX);
  370. }
  371. /*****************************
  372. *
  373. * ListView Stuff
  374. *
  375. * ***************************/
  376. /**
  377. * Reloads the data in the ExpandableListView for the given filter object.
  378. * @param mylist {@link ExpandableListView ExpandableListView}
  379. * */
  380. private RecordListAdapter populateListViewFromDB(ExpandableListView mylist) {
  381. HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
  382. ArrayList<Record> data = dbh.getRecordsForFilter(RecordOverviewFragment.this.filter);
  383. // Adding Items to ListView
  384. String keys[] = new String[] { RecordOverviewFragment.this.getString(R.string.RecordBSSID), RecordOverviewFragment.this.getString(R.string.RecordSSID), RecordOverviewFragment.this.getString(R.string.RecordProtocol), RecordOverviewFragment.this.getString(R.string.RecordTimestamp)};
  385. int ids[] = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
  386. HashMap<String, Integer> mapping = new HashMap<String, Integer>();
  387. int i = 0;
  388. for(String key : keys){
  389. mapping.put(key, ids[i]);
  390. i++;
  391. }
  392. ArrayList<String>groupTitle = new ArrayList<String>();
  393. for (Record val : data) {
  394. // DO GROUPING IN HERE
  395. HashMap<String, String> map = new HashMap<String, String>();
  396. map.put(RecordOverviewFragment.this.getString(R.string.RecordBSSID), val.getBssid());
  397. map.put(RecordOverviewFragment.this.getString(R.string.RecordSSID), val.getSsid());
  398. map.put(RecordOverviewFragment.this.getString(R.string.RecordProtocol), val.getProtocol());
  399. map.put(RecordOverviewFragment.this.getString(R.string.RecordTimestamp),
  400. RecordOverviewFragment.this.getDateAsString(val.getTimestamp()));
  401. ExpandableListItem item = new ExpandableListItem();
  402. item.setData(map);
  403. item.setId_Mapping(mapping);
  404. item.setTag(val.getAttack_id());
  405. String groupID = RecordOverviewFragment.this.getGroupValue(val);
  406. ArrayList<ExpandableListItem> items = sectionData.get(groupID);
  407. if (items == null) {
  408. items = new ArrayList<ExpandableListItem>();
  409. sectionData.put(groupID, items);
  410. groupTitle.add(groupID);
  411. }
  412. items.add(item);
  413. }
  414. Collections.sort(groupTitle, new Comparator<String>() {
  415. @Override
  416. public int compare(String s1, String s2) {
  417. return s1.compareToIgnoreCase(s2);
  418. }
  419. });
  420. RecordListAdapter adapter = null;
  421. if (mylist.getAdapter() != null && mylist.getAdapter() instanceof RecordListAdapter){
  422. adapter = (RecordListAdapter) mylist.getAdapter();
  423. adapter.setData(sectionData);
  424. adapter.setSectionHeader(groupTitle);
  425. } else {
  426. adapter = new RecordListAdapter( RecordOverviewFragment.this.getApplicationContext(), groupTitle, sectionData);
  427. }
  428. return adapter;
  429. }
  430. /**
  431. * Actualises the list in a background thread
  432. */
  433. private void actualiseListViewInBackground(){
  434. if (loader != null && loader.isAlive()) loader.interrupt();
  435. loader = null;
  436. this.spinner.setVisibility(View.VISIBLE);
  437. this.actualiseFilterButton();
  438. loader = new Thread(new Runnable() {
  439. @Override
  440. public void run() {
  441. this.runOnUiThread(this.doInBackground());
  442. }
  443. private RecordListAdapter doInBackground(){
  444. return RecordOverviewFragment.this.populateListViewFromDB(RecordOverviewFragment.this.expListView);
  445. }
  446. private void runOnUiThread(final RecordListAdapter adapter){
  447. Activity actv = RecordOverviewFragment.this.getActivity();
  448. if (actv != null){
  449. actv.runOnUiThread(new Runnable() {
  450. @Override
  451. public void run() {
  452. this.actualiseUI();
  453. }
  454. private void actualiseUI(){
  455. if (adapter != null){
  456. RecordOverviewFragment.this.expListView.setAdapter(adapter);
  457. adapter.notifyDataSetChanged();
  458. RecordOverviewFragment.this.spinner.setVisibility(View.GONE);
  459. }
  460. RecordOverviewFragment.this.showEmptyDataNotification();
  461. }
  462. });
  463. }
  464. }
  465. });
  466. loader.start();
  467. }
  468. /**
  469. * Shows a small toast if the data to show is empty (no records).
  470. */
  471. private void showEmptyDataNotification(){
  472. if (RecordOverviewFragment.this.noDataNotificationToast == null){
  473. RecordOverviewFragment.this.noDataNotificationToast = Toast.makeText(getApplicationContext(), R.string.no_data_notification, Toast.LENGTH_SHORT);
  474. }
  475. RecordListAdapter adapter = (RecordListAdapter) RecordOverviewFragment.this.expListView.getExpandableListAdapter();
  476. if (this.getFilterButton().getVisibility() == View.VISIBLE && this.filter.isSet()){
  477. this.noDataNotificationToast.setText(R.string.no_data_notification);
  478. } else {
  479. this.noDataNotificationToast.setText(R.string.no_data_notification_no_filter);
  480. }
  481. if (adapter == null || adapter.getData().isEmpty())
  482. RecordOverviewFragment.this.noDataNotificationToast.show();
  483. }
  484. /**This will open a section in the ExpandableListView with the same title as the parameter s.
  485. *
  486. * @param s String (the section title to open)
  487. *
  488. * */
  489. private void setSectionToOpen(String s){
  490. this.sectionToOpen = s;
  491. if (this.sectionToOpen != null && this.sectionToOpen.length() != 0){
  492. if (this.getGroupTitles().contains(this.sectionToOpen)){
  493. int section = this.getGroupTitles().indexOf(this.sectionToOpen);
  494. this.expListView.expandGroup(section);
  495. this.sectionToOpen = "";
  496. }
  497. }
  498. }
  499. /**
  500. * Returns the base context.
  501. * @return Context baseContext
  502. * */
  503. private Context getBaseContext(){
  504. return this.getActivity().getBaseContext();
  505. }
  506. /**Returns the application context.
  507. * @return Context application context
  508. * */
  509. private Context getApplicationContext(){
  510. return this.getActivity().getApplicationContext();
  511. }
  512. /**Sets the list view listener on the given ExpandableListView.
  513. *
  514. * @param mylist {@link ExpandableListView ExpandableListView }
  515. * */
  516. private void registerListClickCallback(ExpandableListView mylist) {
  517. mylist.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
  518. @Override
  519. public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i2, long l) {
  520. RecordListAdapter adapter = (RecordListAdapter)expandableListView.getExpandableListAdapter();
  521. ExpandableListItem item = (ExpandableListItem)adapter.getChild(i,i2);
  522. mListPosition = i;
  523. mItemPosition = i2;
  524. HostageDBOpenHelper dbh = new HostageDBOpenHelper(getBaseContext());
  525. Record rec = dbh.getRecordOfAttackId((int) item.getTag());
  526. RecordOverviewFragment.this.pushRecordDetailViewForRecord(rec);
  527. return true;
  528. }
  529. });
  530. mylist.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
  531. @Override
  532. public void onGroupExpand(int i) {
  533. RecordOverviewFragment.this.openSections.add(new Integer(i));
  534. }
  535. });
  536. mylist.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
  537. @Override
  538. public void onGroupCollapse(int i) {
  539. RecordOverviewFragment.this.openSections.remove(new Integer(i));
  540. }
  541. });
  542. }
  543. /*****************************
  544. *
  545. * Date Transform
  546. *
  547. * ***************************/
  548. /**Returns the date format "H:mm d.M.yy" for the given timestamp (long)
  549. * @param timeStamp long */
  550. @SuppressLint("SimpleDateFormat")
  551. private String getDateAsString(long timeStamp) {
  552. try {
  553. DateFormat sdf = new SimpleDateFormat("H:mm d.M.yy");
  554. Date netDate = (new Date(timeStamp));
  555. return sdf.format(netDate);
  556. } catch (Exception ex) {
  557. return "xx";
  558. }
  559. }
  560. /*****************************
  561. *
  562. * Getter / Setter
  563. *
  564. * ***************************/
  565. public boolean isShowFilterButton() {
  566. return showFilterButton;
  567. }
  568. public void setShowFilterButton(boolean showFilterButton) {
  569. this.showFilterButton = showFilterButton;
  570. }
  571. /*****************************
  572. *
  573. * Open Dialog Methods
  574. *
  575. * ***************************/
  576. /**Opens the grouping dialog*/
  577. private void openGroupingDialog(){
  578. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_GROUP, this.groupingTitles(), this.selectedGroup(), false , this);
  579. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_GROUP);
  580. }
  581. /**opens the bssid filter dialog*/
  582. private void openBSSIDFilterDialog(){
  583. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_BSSID,this.bssids(), this.selectedBSSIDs(), true , this);
  584. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
  585. }
  586. /**opens the essid filter dialog*/
  587. private void openESSIDFilterDialog(){
  588. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_ESSID,this.essids(), this.selectedESSIDs(), true , this);
  589. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
  590. }
  591. /**opens the protocol filter dialog*/
  592. private void openProtocolsFilterDialog(){
  593. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS,this.protocolTitles(), this.selectedProtocols(), true , this);
  594. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_PROTOCOLS);
  595. }
  596. /**opens the timestamp filter dialog (minimal timestamp required)*/
  597. private void openTimestampFromFilterDialog(){
  598. this.wasBelowTimePicker = false;
  599. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  600. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  601. if (this.filter.aboveTimestamp != Long.MIN_VALUE)newFragment.setDate(this.filter.aboveTimestamp);
  602. }
  603. /**opens time timestamp filter dialog (maximal timestamp required)*/
  604. private void openTimestampToFilterDialog(){
  605. this.wasBelowTimePicker = true;
  606. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  607. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  608. if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
  609. }
  610. /**opens the sorting dialog*/
  611. private void openSortingDialog(){
  612. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING,this.sortTypeTiles(), this.selectedSorttype(), false , this);
  613. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  614. }
  615. /*****************************
  616. *
  617. * Grouping Stuff
  618. *
  619. * ***************************/
  620. /**returns the group title for the given record. Uses the groupingKey to decied which value of the record should be used.
  621. * @param rec {@link Record Record }
  622. * @return String grouptitle*/
  623. public String getGroupValue(Record rec){
  624. int index = this.groupingTitles().indexOf(this.groupingKey);
  625. switch (index){
  626. case 0:
  627. return rec.getProtocol();
  628. case 1:
  629. return rec.getBssid();
  630. case 2:
  631. return rec.getSsid();
  632. default:
  633. return rec.getProtocol();
  634. }
  635. }
  636. /**Returns the Group titles for the specified grouping key. e.g. groupingKey is "ESSID" it returns all available essids.
  637. * @return ArrayList<String> grouptitles*/
  638. public ArrayList<String> getGroupTitles(){
  639. int index = this.groupingTitles().indexOf(this.groupingKey);
  640. switch (index){
  641. case 0:
  642. return this.protocolTitles();
  643. case 1:
  644. return this.bssids();
  645. case 2:
  646. return this.essids();
  647. default:
  648. return this.protocolTitles();
  649. }
  650. }
  651. /*****************************
  652. *
  653. * Filter Stuff
  654. *
  655. * ***************************/
  656. /**Returns the FilterButton.
  657. * @return ImageButton filterButton*/
  658. private ImageButton getFilterButton(){
  659. return (ImageButton) this.rootView.findViewById(R.id.FilterButton);
  660. }
  661. /**Opens the filter menu on a anchor view. The filter menu will always be on top of the anchor.
  662. * @param v View the anchorView*/
  663. private void openFilterPopupMenuOnView(View v){
  664. SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
  665. public void onItemClick(Object ob) {
  666. if (ob instanceof AbstractPopupItem){
  667. AbstractPopupItem item = (AbstractPopupItem) ob;
  668. RecordOverviewFragment.this.onFilterMenuItemSelected(item);
  669. }
  670. }
  671. });
  672. filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
  673. for(String title : RecordOverviewFragment.this.filterMenuTitles()){
  674. AbstractPopupItem item = null;
  675. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) continue;
  676. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  677. item = new SplitPopupItem(this.getActivity());
  678. item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  679. item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  680. if (this.filter.hasBelowTimestamp()){
  681. item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
  682. }
  683. if (this.filter.hasAboveTimestamp()){
  684. item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
  685. }
  686. } else {
  687. item = new SimplePopupItem(this.getActivity());
  688. item.setTitle(title);
  689. ((SimplePopupItem)item).setSelected(this.isFilterSetForTitle(title));
  690. }
  691. filterMenu.addItem(item);
  692. }
  693. filterMenu.showOnView(v);
  694. }
  695. /**Returns true if the filter object is set for the given title otherwise false. e.g. the filter object has protocols,
  696. * so the method will return for the title FILTER_MENU_TITLE_PROTOCOLS TRUE.
  697. * @param title String
  698. * @return boolean value
  699. * */
  700. private boolean isFilterSetForTitle(String title){
  701. if (title.equals(FILTER_MENU_TITLE_BSSID)){
  702. return this.filter.hasBSSIDs();
  703. }
  704. if (title.equals(FILTER_MENU_TITLE_ESSID)){
  705. return this.filter.hasESSIDs();
  706. }
  707. if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  708. return this.filter.hasProtocols();
  709. }
  710. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  711. return this.filter.hasBelowTimestamp();
  712. }
  713. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  714. return this.filter.hasAboveTimestamp();
  715. }
  716. return false;
  717. }
  718. /**clears the filter. Does not invoke populatelistview!*/
  719. private void clearFilter(){
  720. if(filter == null) this.filter = new LogFilter();
  721. this.filter.clear();
  722. }
  723. /**Returns all grouping titles
  724. * @param context Context
  725. * @return ArrayList<String> titles*/
  726. public ArrayList<String> groupingTitles(Context context){
  727. ArrayList<String> titles = new ArrayList<String>();
  728. for (String groupTitle : context.getResources().getStringArray(
  729. R.array.Grouping)) {
  730. titles.add(groupTitle);
  731. }
  732. return titles;
  733. }
  734. /**Returns all grouping titles.
  735. * @return ArrayList<String> tiles*/
  736. public ArrayList<String> groupingTitles(){
  737. ArrayList<String> titles = new ArrayList<String>();
  738. for (String groupTitle : this.getResources().getStringArray(
  739. R.array.Grouping)) {
  740. titles.add(groupTitle);
  741. }
  742. return titles;
  743. }
  744. /**
  745. * Returns a bool array. This array is true at the index of the groupingKey in groupingTitles(), otherwise false.
  746. * @return boolean[] selection
  747. * */
  748. public boolean[] selectedGroup(){
  749. ArrayList<String> groups = this.groupingTitles();
  750. boolean[] selected = new boolean[groups.size()];
  751. int i = 0;
  752. for(String group : groups){
  753. selected[i] =(group.equals(this.groupingKey));
  754. i++;
  755. }
  756. return selected;
  757. }
  758. /**Returns all protocol titles / names.
  759. * @return ArrayList<String> protocolTitles
  760. * */
  761. public ArrayList<String> protocolTitles(){
  762. ArrayList<String> titles = new ArrayList<String>();
  763. for (String protocol : this.getResources().getStringArray(
  764. R.array.protocols)) {
  765. titles.add(protocol);
  766. }
  767. return titles;
  768. }
  769. /**Return a boolean array of the selected / filtered protocols. If the filter object has
  770. * an protocol from the protocolTitles() array, the index of it will be true, otherwise false.
  771. * @return boolean[] protocol selection
  772. * */
  773. public boolean[] selectedProtocols(){
  774. ArrayList<String> protocols = this.protocolTitles();
  775. boolean[] selected = new boolean[protocols.size()];
  776. int i = 0;
  777. for(String protocol : protocols){
  778. selected[i] =(this.filter.protocols.contains(protocol));
  779. i++;
  780. }
  781. return selected;
  782. }
  783. /**
  784. * Returns the Sorttype Titles
  785. * @return ArayList<String> Sort type titles
  786. * */
  787. public ArrayList<String> sortTypeTiles(){
  788. ArrayList<String> titles = new ArrayList<String>();
  789. titles.add(MainActivity.getContext().getString(R.string.rec_time));
  790. titles.add(MainActivity.getContext().getString(R.string.rec_protocol));
  791. titles.add(MainActivity.getContext().getString(R.string.BSSID));
  792. titles.add(MainActivity.getContext().getString(R.string.ESSID));
  793. return titles;
  794. }
  795. /**
  796. * Returns an boolean array. The array is true at the index of the selected sort type..
  797. * The index of the selected sort type is the same index in the sortTypeTiles array.
  798. * @return boolean array, length == sortTypeTiles().length
  799. * */
  800. public boolean[] selectedSorttype(){
  801. ArrayList<String> types = this.sortTypeTiles();
  802. boolean[] selected = new boolean[types.size()];
  803. int i = 0;
  804. for(String sorttype : types){
  805. selected[i] =(this.filter.sorttype.toString().equals(sorttype));
  806. i++;
  807. }
  808. return selected;
  809. }
  810. /**
  811. * Returns all unique bssids.
  812. * @return ArrayList<String>
  813. * */
  814. public ArrayList<String> bssids(){
  815. ArrayList<String> records = dbh.getUniqueBSSIDRecords();
  816. return records;
  817. }
  818. /**
  819. * Returns an boolean array. The array is true at the indices of the selected bssids.
  820. * The index of the selected bssid is the same index in the bssids() array.
  821. * @return boolean array, length == bssids().length
  822. * */
  823. public boolean[] selectedBSSIDs(){
  824. ArrayList<String> bssids = this.bssids();
  825. boolean[] selected = new boolean[bssids.size()];
  826. int i = 0;
  827. for(String bssid : bssids){
  828. selected[i] =(this.filter.BSSIDs.contains(bssid));
  829. i++;
  830. }
  831. return selected;
  832. }
  833. /**
  834. * Returns all unique essids.
  835. * @return ArrayList<String>
  836. * */
  837. public ArrayList<String> essids(){
  838. ArrayList<String> records = dbh.getUniqueESSIDRecords();
  839. return records;
  840. }
  841. /**
  842. * Returns an boolean array. The array is true at the indices of the selected essids.
  843. * The index of the selected essid is the same index in the essids() array.
  844. * @return boolean array, length == essids().length
  845. * */
  846. public boolean[] selectedESSIDs(){
  847. ArrayList<String> essids = this.essids();
  848. boolean[] selected = new boolean[essids.size()];
  849. int i = 0;
  850. for(String essid : essids){
  851. selected[i] =(this.filter.ESSIDs.contains(essid));
  852. i++;
  853. }
  854. return selected;
  855. }
  856. /**
  857. * Returns all filter menu titles.
  858. * @return ArrayList<String>
  859. * */
  860. private ArrayList<String> filterMenuTitles(){
  861. ArrayList<String> titles = new ArrayList<String>();
  862. titles.add(FILTER_MENU_TITLE_BSSID);
  863. titles.add(FILTER_MENU_TITLE_ESSID);
  864. titles.add(FILTER_MENU_TITLE_PROTOCOLS);
  865. titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  866. titles.add(FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  867. if (this.filter.isSet())titles.add(FILTER_MENU_TITLE_REMOVE);
  868. return titles;
  869. }
  870. /*****************************
  871. *
  872. * Listener Actions
  873. *
  874. * ***************************/
  875. /**
  876. * Will be called if the users selects a timestamp.
  877. * @param dialog {@link DateTimeDialogFragment DateTimeDialogFragment }
  878. * */
  879. public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
  880. if(this.wasBelowTimePicker){
  881. this.filter.setBelowTimestamp(dialog.getDate());
  882. } else {
  883. this.filter.setAboveTimestamp(dialog.getDate());
  884. }
  885. this.actualiseListViewInBackground();
  886. this.actualiseFilterButton();
  887. }
  888. /**
  889. * Will be called if the users cancels a timestamp selection.
  890. * @param dialog {@link DateTimeDialogFragment DateTimeDialogFragment }
  891. * */
  892. public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
  893. if(this.wasBelowTimePicker){
  894. this.filter.setBelowTimestamp(Long.MAX_VALUE);
  895. } else {
  896. this.filter.setAboveTimestamp(Long.MIN_VALUE);
  897. }
  898. this.actualiseListViewInBackground();
  899. this.actualiseFilterButton();
  900. }
  901. /**
  902. * Will be called if the users clicks the positiv button on a ChechlistDialog.
  903. * @param dialog {@link ChecklistDialog ChecklistDialog }
  904. */
  905. public void onDialogPositiveClick(ChecklistDialog dialog) {
  906. String title = dialog.getTitle();
  907. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  908. ArrayList<String> titles =dialog.getSelectedItemTitles();
  909. if (titles.size() == this.bssids().size()){
  910. this.filter.setBSSIDs(new ArrayList<String>());
  911. } else {
  912. this.filter.setBSSIDs(titles);
  913. }
  914. }
  915. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  916. ArrayList<String> titles =dialog.getSelectedItemTitles();
  917. if (titles.size() == this.essids().size()){
  918. this.filter.setESSIDs(new ArrayList<String>());
  919. } else {
  920. this.filter.setESSIDs(titles);
  921. }
  922. }
  923. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  924. ArrayList<String> protocols = dialog.getSelectedItemTitles();
  925. if (protocols.size() == this.protocolTitles().size()){
  926. this.filter.setProtocols(new ArrayList<String>());
  927. } else {
  928. this.filter.setProtocols(dialog.getSelectedItemTitles());
  929. }
  930. }
  931. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  932. ArrayList<String> titles = dialog.getSelectedItemTitles();
  933. if (titles.size() == 0) return;
  934. String t = titles.get(0);
  935. int sortType = this.sortTypeTiles().indexOf(t);
  936. this.filter.setSorttype(SortType.values()[sortType]);
  937. }
  938. if (title.equals(FILTER_MENU_TITLE_GROUP)){
  939. ArrayList<String> titles = dialog.getSelectedItemTitles();
  940. if (titles.size() == 0) return;
  941. this.groupingKey = titles.get(0);
  942. }
  943. this.actualiseListViewInBackground();
  944. this.actualiseFilterButton();
  945. }
  946. /**Paints the filter button if the current filter object is set.*/
  947. private void actualiseFilterButton(){
  948. if (this.filter.isSet() ){
  949. ImageButton filterButton = this.getFilterButton();
  950. if (filterButton != null){
  951. filterButton.setImageResource(R.drawable.ic_filter_pressed);
  952. filterButton.invalidate();
  953. }
  954. } else {
  955. ImageButton filterButton = this.getFilterButton();
  956. if (filterButton != null){
  957. filterButton.setImageResource(R.drawable.ic_filter);
  958. filterButton.invalidate();
  959. }
  960. }
  961. }
  962. /**
  963. * Will be called if the users clicks the negativ button on a ChechlistDialog.
  964. * @param dialog {@link ChecklistDialog ChecklistDialog }
  965. */
  966. public void onDialogNegativeClick(ChecklistDialog dialog) {}
  967. /*****************************
  968. *
  969. * TEST
  970. *
  971. * ***************************/
  972. /**
  973. * This will clear the database at first and than add new attacks.
  974. * @param createNetworks number of networks to create
  975. * @param attacksPerNetwork maximal number of attack per network
  976. * @param maxMessagePerAttack maximal number of messages per attack
  977. * */
  978. private void addRecordToDB( int createNetworks, int attacksPerNetwork, int maxMessagePerAttack) {
  979. if ((dbh.getRecordCount() > 0)) dbh.clearData();
  980. Calendar cal = Calendar.getInstance();
  981. int maxProtocolsIndex = this.getResources().getStringArray(
  982. R.array.protocols).length;
  983. Random random = new Random();
  984. LatLng tudarmstadtLoc = new LatLng(49.86923, 8.6632768);
  985. final double ssidRadius = 0.1;
  986. final double bssidRadius = 0.004;
  987. int attackId = 0;
  988. for (int numOfNetworks = 0; numOfNetworks < createNetworks; numOfNetworks++){
  989. String ssidName = "WiFi" + ((numOfNetworks) + 1);
  990. String bssidName = "127.0.0." + ((numOfNetworks) + 1);
  991. int protocolIndex = numOfNetworks % maxProtocolsIndex;
  992. String protocolName = this.getResources().getStringArray(
  993. R.array.protocols)[protocolIndex];
  994. int numOfAttackPerNetwork = (Math.abs(random.nextInt()) % Math.max(1, attacksPerNetwork + 1));
  995. NetworkRecord network = new NetworkRecord();
  996. network.setBssid(bssidName);
  997. network.setSsid(ssidName);
  998. LatLng ssidLocation = new LatLng(tudarmstadtLoc.latitude - ssidRadius + 2.0 * ssidRadius * Math.random(), tudarmstadtLoc.longitude - ssidRadius + 2.0 * ssidRadius * Math.random());
  999. double latitude = ssidLocation.latitude - bssidRadius + 2.0 * bssidRadius * Math.random();
  1000. double longitude = ssidLocation.longitude - bssidRadius + 2.0 * bssidRadius * Math.random();
  1001. long timestamp = cal.getTimeInMillis();
  1002. network.setTimestampLocation(timestamp);
  1003. network.setLongitude(longitude);
  1004. network.setLatitude(latitude);
  1005. network.setAccuracy(0.f);
  1006. dbh.updateNetworkInformation(network);
  1007. // ATTACKS PER NETWORK
  1008. for (int attackNumber = 0; attackNumber < numOfAttackPerNetwork; attackNumber++) {
  1009. int numRecordsPerAttack = (Math.abs(random.nextInt()) % (Math.max( maxMessagePerAttack + 1, 1)));
  1010. /* ADD A ATTACK*/
  1011. AttackRecord attack = new AttackRecord();
  1012. attack.setAttack_id(attackId);
  1013. attack.setBssid(bssidName);
  1014. attack.setProtocol(protocolName);
  1015. attack.setLocalIP(bssidName);
  1016. dbh.addAttackRecord(attack);
  1017. // MESSAGE PER ATTACK
  1018. for (int messageID = attackId; messageID < attackId + numRecordsPerAttack; messageID++) {
  1019. MessageRecord message = new MessageRecord();
  1020. message.setId(messageID);
  1021. message.setAttack_id(attackId);
  1022. // GO BACK IN TIME
  1023. message.setTimestamp(cal.getTimeInMillis()
  1024. - ((messageID * 60 * 60 * 24) * 1000) + (1000 * ((messageID - attackId) + 1)));
  1025. if ((messageID - attackId) % 2 == 0){
  1026. message.setType(MessageRecord.TYPE.RECEIVE);
  1027. } else {
  1028. message.setType(MessageRecord.TYPE.SEND);
  1029. }
  1030. message.setPacket("");
  1031. dbh.addMessageRecord(message);
  1032. }
  1033. attackId+=numRecordsPerAttack;
  1034. }
  1035. }
  1036. // int countAllLogs = dbh.getAllRecords().size();
  1037. // int countRecords = dbh.getRecordCount();
  1038. // int countAttacks = dbh.getAttackCount();
  1039. //
  1040. // if ((countRecords == 0)) {
  1041. // Record rec = dbh.getRecordOfAttackId(0);
  1042. // Record rec2 = dbh.getRecord(0);
  1043. //
  1044. // System.out.println("" + "Could not create logs!");
  1045. // }
  1046. }
  1047. /**Navigation. Shows the record detail view for the given record
  1048. * @param record {@link Record Record } to show
  1049. * */
  1050. private void pushRecordDetailViewForRecord(Record record){
  1051. FragmentManager fm = this.getActivity().getFragmentManager();
  1052. if (fm != null){
  1053. RecordDetailFragment newFragment = new RecordDetailFragment();
  1054. newFragment.setRecord(record);
  1055. newFragment.setUpNavigatible(true);
  1056. MainActivity.getInstance().injectFragment(newFragment);
  1057. }
  1058. }
  1059. }