RecordOverviewFragment.java 46 KB

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