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