RecordOverviewFragment.java 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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. // 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, 0);
  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.actualiseFilterButton();
  899. }
  900. /**
  901. * Will be called if the users clicks the positiv button on a ChechlistDialog.
  902. * @param dialog {@link ChecklistDialog ChecklistDialog }
  903. */
  904. public void onDialogPositiveClick(ChecklistDialog dialog) {
  905. String title = dialog.getTitle();
  906. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  907. ArrayList<String> titles =dialog.getSelectedItemTitles();
  908. if (titles.size() == this.bssids().size()){
  909. this.filter.setBSSIDs(new ArrayList<String>());
  910. } else {
  911. this.filter.setBSSIDs(titles);
  912. }
  913. }
  914. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  915. ArrayList<String> titles =dialog.getSelectedItemTitles();
  916. if (titles.size() == this.essids().size()){
  917. this.filter.setESSIDs(new ArrayList<String>());
  918. } else {
  919. this.filter.setESSIDs(titles);
  920. }
  921. }
  922. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  923. ArrayList<String> protocols = dialog.getSelectedItemTitles();
  924. if (protocols.size() == this.protocolTitles().size()){
  925. this.filter.setProtocols(new ArrayList<String>());
  926. } else {
  927. this.filter.setProtocols(dialog.getSelectedItemTitles());
  928. }
  929. }
  930. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  931. ArrayList<String> titles = dialog.getSelectedItemTitles();
  932. if (titles.size() == 0) return;
  933. String t = titles.get(0);
  934. int sortType = this.sortTypeTiles().indexOf(t);
  935. this.filter.setSorttype(SortType.values()[sortType]);
  936. }
  937. if (title.equals(FILTER_MENU_TITLE_GROUP)){
  938. ArrayList<String> titles = dialog.getSelectedItemTitles();
  939. if (titles.size() == 0) return;
  940. this.groupingKey = titles.get(0);
  941. }
  942. this.actualiseListViewInBackground();
  943. this.actualiseFilterButton();
  944. }
  945. /**Paints the filter button if the current filter object is set.*/
  946. private void actualiseFilterButton(){
  947. if (this.filter.isSet() ){
  948. ImageButton filterButton = this.getFilterButton();
  949. if (filterButton != null){
  950. filterButton.setImageResource(R.drawable.ic_filter_pressed);
  951. filterButton.invalidate();
  952. }
  953. } else {
  954. ImageButton filterButton = this.getFilterButton();
  955. if (filterButton != null){
  956. filterButton.setImageResource(R.drawable.ic_filter);
  957. filterButton.invalidate();
  958. }
  959. }
  960. }
  961. /**
  962. * Will be called if the users clicks the negativ button on a ChechlistDialog.
  963. * @param dialog {@link ChecklistDialog ChecklistDialog }
  964. */
  965. public void onDialogNegativeClick(ChecklistDialog dialog) {}
  966. /*****************************
  967. *
  968. * TEST
  969. *
  970. * ***************************/
  971. /**
  972. * This will clear the database at first and than add new attacks.
  973. * @param createNetworks number of networks to create
  974. * @param attacksPerNetwork maximal number of attack per network
  975. * @param maxMessagePerAttack maximal number of messages per attack
  976. * */
  977. private void addRecordToDB( int createNetworks, int attacksPerNetwork, int maxMessagePerAttack) {
  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()) % Math.max(1, 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()) % (Math.max( maxMessagePerAttack + 1, 1)));
  1009. /* ADD A ATTACK*/
  1010. AttackRecord attack = new AttackRecord();
  1011. attack.setAttack_id(attackId);
  1012. attack.setBssid(bssidName);
  1013. attack.setProtocol(protocolName);
  1014. attack.setLocalIP(bssidName);
  1015. dbh.addAttackRecord(attack);
  1016. // MESSAGE PER ATTACK
  1017. for (int messageID = attackId; messageID < attackId + numRecordsPerAttack; messageID++) {
  1018. MessageRecord message = new MessageRecord();
  1019. message.setId(messageID);
  1020. message.setAttack_id(attackId);
  1021. // GO BACK IN TIME
  1022. message.setTimestamp(cal.getTimeInMillis()
  1023. - ((messageID * 60 * 60 * 24) * 1000) + (1000 * ((messageID - attackId) + 1)));
  1024. if ((messageID - attackId) % 2 == 0){
  1025. message.setType(MessageRecord.TYPE.RECEIVE);
  1026. } else {
  1027. message.setType(MessageRecord.TYPE.SEND);
  1028. }
  1029. message.setPacket("");
  1030. dbh.addMessageRecord(message);
  1031. }
  1032. attackId+=numRecordsPerAttack;
  1033. }
  1034. }
  1035. // int countAllLogs = dbh.getAllRecords().size();
  1036. // int countRecords = dbh.getRecordCount();
  1037. // int countAttacks = dbh.getAttackCount();
  1038. //
  1039. // if ((countRecords == 0)) {
  1040. // Record rec = dbh.getRecordOfAttackId(0);
  1041. // Record rec2 = dbh.getRecord(0);
  1042. //
  1043. // System.out.println("" + "Could not create logs!");
  1044. // }
  1045. }
  1046. /**Navigation. Shows the record detail view for the given record
  1047. * @param record {@link Record Record } to show
  1048. * */
  1049. private void pushRecordDetailViewForRecord(Record record){
  1050. FragmentManager fm = this.getActivity().getFragmentManager();
  1051. if (fm != null){
  1052. RecordDetailFragment newFragment = new RecordDetailFragment();
  1053. newFragment.setRecord(record);
  1054. newFragment.setUpNavigatible(true);
  1055. MainActivity.getInstance().injectFragment(newFragment);
  1056. }
  1057. }
  1058. }