RecordOverviewFragment.java 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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.os.Message;
  13. import android.preference.PreferenceManager;
  14. import android.util.Log;
  15. import android.view.LayoutInflater;
  16. import android.view.Menu;
  17. import android.view.MenuInflater;
  18. import android.view.MenuItem;
  19. import android.view.View;
  20. import android.view.ViewGroup;
  21. import android.widget.ExpandableListView;
  22. import android.widget.ImageButton;
  23. import android.widget.ProgressBar;
  24. import android.widget.Toast;
  25. import com.google.android.gms.maps.model.LatLng;
  26. import java.io.File;
  27. import java.io.FileOutputStream;
  28. import java.text.DateFormat;
  29. import java.text.SimpleDateFormat;
  30. import java.util.ArrayList;
  31. import java.util.Calendar;
  32. import java.util.Collections;
  33. import java.util.Comparator;
  34. import java.util.Date;
  35. import java.util.HashMap;
  36. import java.util.Random;
  37. import de.tudarmstadt.informatik.hostage.R;
  38. import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
  39. import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
  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.BluetoothSync;
  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 AbstractPopupItem item
  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(), BluetoothSync.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. }
  313. });
  314. builderExport.create();
  315. builderExport.show();
  316. return true;
  317. }
  318. return false;
  319. }
  320. private void exportDatabase(int format) {
  321. try {
  322. FileOutputStream log;
  323. String filename = "hostage_" + format + "_" + System.currentTimeMillis() + ".log";
  324. String externalLocation = pref.getString("pref_external_location",
  325. "");
  326. String root = Environment.getExternalStorageDirectory()
  327. .toString();
  328. if (root != null && HelperUtils.isExternalStorageWritable()) {
  329. File dir = new File(root + externalLocation);
  330. dir.mkdirs();
  331. File file = new File(dir, filename);
  332. log = new FileOutputStream(file);
  333. } else {
  334. Toast.makeText(getActivity(), "Could not write to SD Card",
  335. Toast.LENGTH_SHORT).show();
  336. return;
  337. }
  338. ArrayList<Record> records = dbh.getAllRecords();
  339. for (Record record : records) {
  340. log.write((record.toString((format == 1) ? TraCINgFormatter
  341. .getInstance() : null)).getBytes());
  342. }
  343. log.flush();
  344. log.close();
  345. Toast.makeText(
  346. getActivity(),
  347. "Exported records to " + externalLocation + filename, Toast.LENGTH_LONG)
  348. .show();
  349. } catch (Exception e) {
  350. Toast.makeText(getActivity(), "Could not write to SD Card",
  351. Toast.LENGTH_SHORT).show();
  352. e.printStackTrace();
  353. }
  354. }
  355. /*****************************
  356. *
  357. * Public API
  358. *
  359. * ***************************/
  360. /**
  361. * Group records by SSID and expand given SSID
  362. *
  363. * @param SSID the SSID
  364. */
  365. public void showDetailsForSSID(Context context, String SSID) {
  366. Log.e("RecordOverviewFragment", "Implement showDetailsForSSID!!");
  367. this.clearFilter();
  368. int ESSID_INDEX = 2;
  369. ArrayList<String> ssids = new ArrayList<String>();
  370. this.sectionToOpen = SSID;
  371. this.groupingKey = this.groupingTitles(context).get(ESSID_INDEX);
  372. }
  373. /*****************************
  374. *
  375. * ListView Stuff
  376. *
  377. * ***************************/
  378. /**
  379. * Reloads the data in the ExpandableListView for the given filter object.
  380. * @param ExpandableListView listview
  381. * */
  382. private RecordListAdapter populateListViewFromDB(ExpandableListView mylist) {
  383. HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
  384. ArrayList<Record> data = dbh.getRecordsForFilter(RecordOverviewFragment.this.filter);
  385. // Adding Items to ListView
  386. 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)};
  387. int ids[] = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
  388. HashMap<String, Integer> mapping = new HashMap<String, Integer>();
  389. int i = 0;
  390. for(String key : keys){
  391. mapping.put(key, ids[i]);
  392. i++;
  393. }
  394. ArrayList<String>groupTitle = new ArrayList<String>();
  395. for (Record val : data) {
  396. // DO GROUPING IN HERE
  397. HashMap<String, String> map = new HashMap<String, String>();
  398. map.put(RecordOverviewFragment.this.getString(R.string.RecordBSSID), val.getBssid());
  399. map.put(RecordOverviewFragment.this.getString(R.string.RecordSSID), val.getSsid());
  400. map.put(RecordOverviewFragment.this.getString(R.string.RecordProtocol), val.getProtocol());
  401. map.put(RecordOverviewFragment.this.getString(R.string.RecordTimestamp),
  402. RecordOverviewFragment.this.getDateAsString(val.getTimestamp()));
  403. ExpandableListItem item = new ExpandableListItem();
  404. item.setData(map);
  405. item.setId_Mapping(mapping);
  406. item.setTag(val.getAttack_id());
  407. String groupID = RecordOverviewFragment.this.getGroupValue(val);
  408. ArrayList<ExpandableListItem> items = sectionData.get(groupID);
  409. if (items == null) {
  410. items = new ArrayList<ExpandableListItem>();
  411. sectionData.put(groupID, items);
  412. groupTitle.add(groupID);
  413. }
  414. items.add(item);
  415. }
  416. Collections.sort(groupTitle, new Comparator<String>() {
  417. @Override
  418. public int compare(String s1, String s2) {
  419. return s1.compareToIgnoreCase(s2);
  420. }
  421. });
  422. RecordListAdapter adapter = null;
  423. if (mylist.getAdapter() != null && mylist.getAdapter() instanceof RecordListAdapter){
  424. adapter = (RecordListAdapter) mylist.getAdapter();
  425. adapter.setData(sectionData);
  426. adapter.setSectionHeader(groupTitle);
  427. } else {
  428. adapter = new RecordListAdapter( RecordOverviewFragment.this.getApplicationContext(), groupTitle, sectionData);
  429. }
  430. return adapter;
  431. }
  432. /**
  433. * Actualises the list in a background thread
  434. */
  435. private void actualiseListViewInBackground(){
  436. if (loader != null && loader.isAlive()) loader.interrupt();
  437. loader = null;
  438. this.spinner.setVisibility(View.VISIBLE);
  439. this.actualiseFilterButton();
  440. loader = new Thread(new Runnable() {
  441. @Override
  442. public void run() {
  443. this.runOnUiThread(this.doInBackground());
  444. }
  445. private RecordListAdapter doInBackground(){
  446. return RecordOverviewFragment.this.populateListViewFromDB(RecordOverviewFragment.this.expListView);
  447. }
  448. private void runOnUiThread(final RecordListAdapter adapter){
  449. Activity actv = RecordOverviewFragment.this.getActivity();
  450. if (actv != null){
  451. actv.runOnUiThread(new Runnable() {
  452. @Override
  453. public void run() {
  454. this.actualiseUI();
  455. }
  456. private void actualiseUI(){
  457. if (adapter != null){
  458. RecordOverviewFragment.this.expListView.setAdapter(adapter);
  459. adapter.notifyDataSetChanged();
  460. RecordOverviewFragment.this.spinner.setVisibility(View.GONE);
  461. }
  462. RecordOverviewFragment.this.showEmptyDataNotification();
  463. }
  464. });
  465. }
  466. }
  467. });
  468. loader.start();
  469. }
  470. /**
  471. * Shows a small toast if the data to show is empty (no records).
  472. */
  473. private void showEmptyDataNotification(){
  474. if (RecordOverviewFragment.this.noDataNotificationToast == null){
  475. RecordOverviewFragment.this.noDataNotificationToast = Toast.makeText(getApplicationContext(), R.string.no_data_notification, Toast.LENGTH_SHORT);
  476. }
  477. RecordListAdapter adapter = (RecordListAdapter) RecordOverviewFragment.this.expListView.getExpandableListAdapter();
  478. if (this.getFilterButton().getVisibility() == View.VISIBLE && this.filter.isSet()){
  479. this.noDataNotificationToast.setText(R.string.no_data_notification);
  480. } else {
  481. this.noDataNotificationToast.setText(R.string.no_data_notification_no_filter);
  482. }
  483. if (adapter == null || adapter.getData().isEmpty())
  484. RecordOverviewFragment.this.noDataNotificationToast.show();
  485. }
  486. /**This will open a section in the ExpandableListView with the same title as the parameter s.
  487. *
  488. * @param String s (the section title to open)
  489. *
  490. * */
  491. private void setSectionToOpen(String s){
  492. this.sectionToOpen = s;
  493. if (this.sectionToOpen != null && this.sectionToOpen.length() != 0){
  494. if (this.getGroupTitles().contains(this.sectionToOpen)){
  495. int section = this.getGroupTitles().indexOf(this.sectionToOpen);
  496. this.expListView.expandGroup(section);
  497. this.sectionToOpen = "";
  498. }
  499. }
  500. }
  501. /**
  502. * Returns the base context.
  503. * @return Context baseContext
  504. * */
  505. private Context getBaseContext(){
  506. return this.getActivity().getBaseContext();
  507. }
  508. /**Returns the application context.
  509. * @return Context application context
  510. * */
  511. private Context getApplicationContext(){
  512. return this.getActivity().getApplicationContext();
  513. }
  514. /**Sets the list view listener on the given ExpandableListView.
  515. *
  516. * @param ExpandableListView listview
  517. * */
  518. private void registerListClickCallback(ExpandableListView mylist) {
  519. mylist.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
  520. @Override
  521. public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i2, long l) {
  522. RecordListAdapter adapter = (RecordListAdapter)expandableListView.getExpandableListAdapter();
  523. ExpandableListItem item = (ExpandableListItem)adapter.getChild(i,i2);
  524. mListPosition = i;
  525. mItemPosition = i2;
  526. HostageDBOpenHelper dbh = new HostageDBOpenHelper(getBaseContext());
  527. Record rec = dbh.getRecordOfAttackId((int) item.getTag());
  528. RecordOverviewFragment.this.pushRecordDetailViewForRecord(rec);
  529. return true;
  530. }
  531. });
  532. mylist.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
  533. @Override
  534. public void onGroupExpand(int i) {
  535. RecordOverviewFragment.this.openSections.add(new Integer(i));
  536. }
  537. });
  538. mylist.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
  539. @Override
  540. public void onGroupCollapse(int i) {
  541. RecordOverviewFragment.this.openSections.remove(new Integer(i));
  542. }
  543. });
  544. }
  545. /*****************************
  546. *
  547. * Date Transform
  548. *
  549. * ***************************/
  550. /**Returns the date format "H:mm d.M.yy" for the given timestamp (long)
  551. * @param Long timestamp*/
  552. @SuppressLint("SimpleDateFormat")
  553. private String getDateAsString(long timeStamp) {
  554. try {
  555. DateFormat sdf = new SimpleDateFormat("H:mm d.M.yy");
  556. Date netDate = (new Date(timeStamp));
  557. return sdf.format(netDate);
  558. } catch (Exception ex) {
  559. return "xx";
  560. }
  561. }
  562. /*****************************
  563. *
  564. * Getter / Setter
  565. *
  566. * ***************************/
  567. public boolean isShowFilterButton() {
  568. return showFilterButton;
  569. }
  570. public void setShowFilterButton(boolean showFilterButton) {
  571. this.showFilterButton = showFilterButton;
  572. }
  573. /*****************************
  574. *
  575. * Open Dialog Methods
  576. *
  577. * ***************************/
  578. /**Opens the grouping dialog*/
  579. private void openGroupingDialog(){
  580. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_GROUP, this.groupingTitles(), this.selectedGroup(), false , this);
  581. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_GROUP);
  582. }
  583. /**opens the bssid filter dialog*/
  584. private void openBSSIDFilterDialog(){
  585. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_BSSID,this.bssids(), this.selectedBSSIDs(), true , this);
  586. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
  587. }
  588. /**opens the essid filter dialog*/
  589. private void openESSIDFilterDialog(){
  590. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_ESSID,this.essids(), this.selectedESSIDs(), true , this);
  591. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
  592. }
  593. /**opens the protocol filter dialog*/
  594. private void openProtocolsFilterDialog(){
  595. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS,this.protocolTitles(), this.selectedProtocols(), true , this);
  596. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_PROTOCOLS);
  597. }
  598. /**opens the timestamp filter dialog (minimal timestamp required)*/
  599. private void openTimestampFromFilterDialog(){
  600. this.wasBelowTimePicker = false;
  601. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  602. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  603. if (this.filter.aboveTimestamp != Long.MIN_VALUE)newFragment.setDate(this.filter.aboveTimestamp);
  604. }
  605. /**opens time timestamp filter dialog (maximal timestamp required)*/
  606. private void openTimestampToFilterDialog(){
  607. this.wasBelowTimePicker = true;
  608. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  609. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  610. if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
  611. }
  612. /**opens the sorting dialog*/
  613. private void openSortingDialog(){
  614. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING,this.sortTypeTiles(), this.selectedSorttype(), false , this);
  615. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  616. }
  617. /*****************************
  618. *
  619. * Grouping Stuff
  620. *
  621. * ***************************/
  622. /**returns the group title for the given record. Uses the groupingKey to decied which value of the record should be used.
  623. * @param Record rec
  624. * @return String grouptitle*/
  625. public String getGroupValue(Record rec){
  626. int index = this.groupingTitles().indexOf(this.groupingKey);
  627. switch (index){
  628. case 0:
  629. return rec.getProtocol();
  630. case 1:
  631. return rec.getBssid();
  632. case 2:
  633. return rec.getSsid();
  634. default:
  635. return rec.getProtocol();
  636. }
  637. }
  638. /**Returns the Group titles for the specified grouping key. e.g. groupingKey is "ESSID" it returns all available essids.
  639. * @return ArrayList<String> grouptitles*/
  640. public ArrayList<String> getGroupTitles(){
  641. int index = this.groupingTitles().indexOf(this.groupingKey);
  642. switch (index){
  643. case 0:
  644. return this.protocolTitles();
  645. case 1:
  646. return this.bssids();
  647. case 2:
  648. return this.essids();
  649. default:
  650. return this.protocolTitles();
  651. }
  652. }
  653. /*****************************
  654. *
  655. * Filter Stuff
  656. *
  657. * ***************************/
  658. /**Returns the FilterButton.
  659. * @return ImageButton filterButton*/
  660. private ImageButton getFilterButton(){
  661. return (ImageButton) this.rootView.findViewById(R.id.FilterButton);
  662. }
  663. /**Opens the filter menu on a anchor view. The filter menu will always be on top of the anchor.
  664. * @param View anchorView*/
  665. private void openFilterPopupMenuOnView(View v){
  666. SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
  667. public void onItemClick(Object ob) {
  668. if (ob instanceof AbstractPopupItem){
  669. AbstractPopupItem item = (AbstractPopupItem) ob;
  670. RecordOverviewFragment.this.onFilterMenuItemSelected(item);
  671. }
  672. }
  673. });
  674. filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
  675. for(String title : RecordOverviewFragment.this.filterMenuTitles()){
  676. AbstractPopupItem item = null;
  677. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) continue;
  678. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  679. item = new SplitPopupItem(this.getActivity());
  680. item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  681. item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  682. if (this.filter.hasBelowTimestamp()){
  683. item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
  684. }
  685. if (this.filter.hasAboveTimestamp()){
  686. item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
  687. }
  688. } else {
  689. item = new SimplePopupItem(this.getActivity());
  690. item.setTitle(title);
  691. ((SimplePopupItem)item).setSelected(this.isFilterSetForTitle(title));
  692. }
  693. filterMenu.addItem(item);
  694. }
  695. filterMenu.showOnView(v);
  696. }
  697. /**Returns true if the filter object is set for the given title otherwise false. e.g. the filter object has protocols,
  698. * so the method will return for the title FILTER_MENU_TITLE_PROTOCOLS TRUE.
  699. * @param String title
  700. * @return boolean value
  701. * */
  702. private boolean isFilterSetForTitle(String title){
  703. if (title.equals(FILTER_MENU_TITLE_BSSID)){
  704. return this.filter.hasBSSIDs();
  705. }
  706. if (title.equals(FILTER_MENU_TITLE_ESSID)){
  707. return this.filter.hasESSIDs();
  708. }
  709. if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  710. return this.filter.hasProtocols();
  711. }
  712. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  713. return this.filter.hasBelowTimestamp();
  714. }
  715. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  716. return this.filter.hasAboveTimestamp();
  717. }
  718. return false;
  719. }
  720. /**clears the filter. Does not invoke populatelistview!*/
  721. private void clearFilter(){
  722. if(filter == null) this.filter = new LogFilter();
  723. this.filter.clear();
  724. }
  725. /**Returns all grouping titles
  726. * @param Context context
  727. * @return ArrayList<String> titles*/
  728. public ArrayList<String> groupingTitles(Context context){
  729. ArrayList<String> titles = new ArrayList<String>();
  730. for (String groupTitle : context.getResources().getStringArray(
  731. R.array.Grouping)) {
  732. titles.add(groupTitle);
  733. }
  734. return titles;
  735. }
  736. /**Returns all grouping titles.
  737. * @return ArrayList<String> tiles*/
  738. public ArrayList<String> groupingTitles(){
  739. ArrayList<String> titles = new ArrayList<String>();
  740. for (String groupTitle : this.getResources().getStringArray(
  741. R.array.Grouping)) {
  742. titles.add(groupTitle);
  743. }
  744. return titles;
  745. }
  746. /**
  747. * Returns a bool array. This array is true at the index of the groupingKey in groupingTitles(), otherwise false.
  748. * @return boolean[] selection
  749. * */
  750. public boolean[] selectedGroup(){
  751. ArrayList<String> groups = this.groupingTitles();
  752. boolean[] selected = new boolean[groups.size()];
  753. int i = 0;
  754. for(String group : groups){
  755. selected[i] =(group.equals(this.groupingKey));
  756. i++;
  757. }
  758. return selected;
  759. }
  760. /**Returns all protocol titles / names.
  761. * @return ArrayList<String> protocolTitles
  762. * */
  763. public ArrayList<String> protocolTitles(){
  764. ArrayList<String> titles = new ArrayList<String>();
  765. for (String protocol : this.getResources().getStringArray(
  766. R.array.protocols)) {
  767. titles.add(protocol);
  768. }
  769. return titles;
  770. }
  771. /**Return a boolean array of the selected / filtered protocols. If the filter object has
  772. * an protocol from the protocolTitles() array, the index of it will be true, otherwise false.
  773. * @return boolean[] protocol selection
  774. * */
  775. public boolean[] selectedProtocols(){
  776. ArrayList<String> protocols = this.protocolTitles();
  777. boolean[] selected = new boolean[protocols.size()];
  778. int i = 0;
  779. for(String protocol : protocols){
  780. selected[i] =(this.filter.protocols.contains(protocol));
  781. i++;
  782. }
  783. return selected;
  784. }
  785. /**
  786. * Returns the Sorttype Titles
  787. * @return ArayList<String> Sort type titles
  788. * */
  789. public ArrayList<String> sortTypeTiles(){
  790. ArrayList<String> titles = new ArrayList<String>();
  791. titles.add(MainActivity.getContext().getString(R.string.rec_time));
  792. titles.add(MainActivity.getContext().getString(R.string.rec_protocol));
  793. titles.add(MainActivity.getContext().getString(R.string.BSSID));
  794. titles.add(MainActivity.getContext().getString(R.string.ESSID));
  795. return titles;
  796. }
  797. /**
  798. * Returns an boolean array. The array is true at the index of the selected sort type..
  799. * The index of the selected sort type is the same index in the sortTypeTiles array.
  800. * @return boolean array, length == sortTypeTiles().length
  801. * */
  802. public boolean[] selectedSorttype(){
  803. ArrayList<String> types = this.sortTypeTiles();
  804. boolean[] selected = new boolean[types.size()];
  805. int i = 0;
  806. for(String sorttype : types){
  807. selected[i] =(this.filter.sorttype.toString().equals(sorttype));
  808. i++;
  809. }
  810. return selected;
  811. }
  812. /**
  813. * Returns all unique bssids.
  814. * @return ArrayList<String>
  815. * */
  816. public ArrayList<String> bssids(){
  817. ArrayList<String> records = dbh.getUniqueBSSIDRecords();
  818. return records;
  819. }
  820. /**
  821. * Returns an boolean array. The array is true at the indices of the selected bssids.
  822. * The index of the selected bssid is the same index in the bssids() array.
  823. * @return boolean array, length == bssids().length
  824. * */
  825. public boolean[] selectedBSSIDs(){
  826. ArrayList<String> bssids = this.bssids();
  827. boolean[] selected = new boolean[bssids.size()];
  828. int i = 0;
  829. for(String bssid : bssids){
  830. selected[i] =(this.filter.BSSIDs.contains(bssid));
  831. i++;
  832. }
  833. return selected;
  834. }
  835. /**
  836. * Returns all unique essids.
  837. * @return ArrayList<String>
  838. * */
  839. public ArrayList<String> essids(){
  840. ArrayList<String> records = dbh.getUniqueESSIDRecords();
  841. return records;
  842. }
  843. /**
  844. * Returns an boolean array. The array is true at the indices of the selected essids.
  845. * The index of the selected essid is the same index in the essids() array.
  846. * @return boolean array, length == essids().length
  847. * */
  848. public boolean[] selectedESSIDs(){
  849. ArrayList<String> essids = this.essids();
  850. boolean[] selected = new boolean[essids.size()];
  851. int i = 0;
  852. for(String essid : essids){
  853. selected[i] =(this.filter.ESSIDs.contains(essid));
  854. i++;
  855. }
  856. return selected;
  857. }
  858. /**
  859. * Returns all filter menu titles.
  860. * @return ArrayList<String>
  861. * */
  862. private ArrayList<String> filterMenuTitles(){
  863. ArrayList<String> titles = new ArrayList<String>();
  864. titles.add(FILTER_MENU_TITLE_BSSID);
  865. titles.add(FILTER_MENU_TITLE_ESSID);
  866. titles.add(FILTER_MENU_TITLE_PROTOCOLS);
  867. titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  868. titles.add(FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  869. if (this.filter.isSet())titles.add(FILTER_MENU_TITLE_REMOVE);
  870. return titles;
  871. }
  872. /*****************************
  873. *
  874. * Listener Actions
  875. *
  876. * ***************************/
  877. /**
  878. * Will be called if the users selects a timestamp.
  879. * @param DateTimeDialogFragment dialog
  880. * */
  881. public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
  882. if(this.wasBelowTimePicker){
  883. this.filter.setBelowTimestamp(dialog.getDate());
  884. } else {
  885. this.filter.setAboveTimestamp(dialog.getDate());
  886. }
  887. this.actualiseListViewInBackground();
  888. this.actualiseFilterButton();
  889. }
  890. /**
  891. * Will be called if the users cancels a timestamp selection.
  892. * @param DateTimeDialogFragment dialog
  893. * */
  894. public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
  895. if(this.wasBelowTimePicker){
  896. this.filter.setBelowTimestamp(Long.MAX_VALUE);
  897. } else {
  898. this.filter.setAboveTimestamp(Long.MIN_VALUE);
  899. }
  900. this.actualiseFilterButton();
  901. }
  902. /**
  903. * Will be called if the users clicks the positiv button on a ChechlistDialog.
  904. * @param ChecklistDialog dialog
  905. */
  906. public void onDialogPositiveClick(ChecklistDialog dialog) {
  907. String title = dialog.getTitle();
  908. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  909. ArrayList<String> titles =dialog.getSelectedItemTitles();
  910. if (titles.size() == this.bssids().size()){
  911. this.filter.setBSSIDs(new ArrayList<String>());
  912. } else {
  913. this.filter.setBSSIDs(titles);
  914. }
  915. }
  916. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  917. ArrayList<String> titles =dialog.getSelectedItemTitles();
  918. if (titles.size() == this.essids().size()){
  919. this.filter.setESSIDs(new ArrayList<String>());
  920. } else {
  921. this.filter.setESSIDs(titles);
  922. }
  923. }
  924. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  925. ArrayList<String> protocols = dialog.getSelectedItemTitles();
  926. if (protocols.size() == this.protocolTitles().size()){
  927. this.filter.setProtocols(new ArrayList<String>());
  928. } else {
  929. this.filter.setProtocols(dialog.getSelectedItemTitles());
  930. }
  931. }
  932. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  933. ArrayList<String> titles = dialog.getSelectedItemTitles();
  934. if (titles.size() == 0) return;
  935. String t = titles.get(0);
  936. int sortType = this.sortTypeTiles().indexOf(t);
  937. this.filter.setSorttype(SortType.values()[sortType]);
  938. }
  939. if (title.equals(FILTER_MENU_TITLE_GROUP)){
  940. ArrayList<String> titles = dialog.getSelectedItemTitles();
  941. if (titles.size() == 0) return;
  942. this.groupingKey = titles.get(0);
  943. }
  944. this.actualiseListViewInBackground();
  945. this.actualiseFilterButton();
  946. }
  947. /**Paints the filter button if the current filter object is set.*/
  948. private void actualiseFilterButton(){
  949. if (this.filter.isSet() ){
  950. ImageButton filterButton = this.getFilterButton();
  951. if (filterButton != null){
  952. filterButton.setImageResource(R.drawable.ic_filter_pressed);
  953. filterButton.invalidate();
  954. }
  955. } else {
  956. ImageButton filterButton = this.getFilterButton();
  957. if (filterButton != null){
  958. filterButton.setImageResource(R.drawable.ic_filter);
  959. filterButton.invalidate();
  960. }
  961. }
  962. }
  963. /**
  964. * Will be called if the users clicks the negativ button on a ChechlistDialog.
  965. * @param ChecklistDialog dialog
  966. */
  967. public void onDialogNegativeClick(ChecklistDialog dialog) {}
  968. /*****************************
  969. *
  970. * TEST
  971. *
  972. * ***************************/
  973. /**
  974. * This will clear the database at first and than add new attacks.
  975. * @param int number of networks to create
  976. * @param int maximal number of attack per network
  977. * */
  978. private void addRecordToDB( int createNetworks, int attacksPerNetwork) {
  979. if ((dbh.getRecordCount() > 0)) dbh.clearData();
  980. Calendar cal = Calendar.getInstance();
  981. int maxProtocolsIndex = this.getResources().getStringArray(
  982. R.array.protocols).length;
  983. Random random = new Random();
  984. LatLng tudarmstadtLoc = new LatLng(49.86923, 8.6632768);
  985. final double ssidRadius = 0.1;
  986. final double bssidRadius = 0.004;
  987. int attackId = 0;
  988. for (int numOfNetworks = 0; numOfNetworks < createNetworks; numOfNetworks++){
  989. String ssidName = "WiFi" + ((numOfNetworks) + 1);
  990. String bssidName = "127.0.0." + ((numOfNetworks) + 1);
  991. int protocolIndex = numOfNetworks % maxProtocolsIndex;
  992. String protocolName = this.getResources().getStringArray(
  993. R.array.protocols)[protocolIndex];
  994. int numOfAttackPerNetwork = (Math.abs(random.nextInt()) % attacksPerNetwork) + 1;
  995. NetworkRecord network = new NetworkRecord();
  996. network.setBssid(bssidName);
  997. network.setSsid(ssidName);
  998. LatLng ssidLocation = new LatLng(tudarmstadtLoc.latitude - ssidRadius + 2.0 * ssidRadius * Math.random(), tudarmstadtLoc.longitude - ssidRadius + 2.0 * ssidRadius * Math.random());
  999. double latitude = ssidLocation.latitude - bssidRadius + 2.0 * bssidRadius * Math.random();
  1000. double longitude = ssidLocation.longitude - bssidRadius + 2.0 * bssidRadius * Math.random();
  1001. long timestamp = cal.getTimeInMillis();
  1002. network.setTimestampLocation(timestamp);
  1003. network.setLongitude(longitude);
  1004. network.setLatitude(latitude);
  1005. network.setAccuracy(0.f);
  1006. dbh.updateNetworkInformation(network);
  1007. // ATTACKS PER NETWORK
  1008. for (int attackNumber = 0; attackNumber < numOfAttackPerNetwork; attackNumber++) {
  1009. int numRecordsPerAttack = (Math.abs(random.nextInt()) % 5) + 1;
  1010. /*
  1011. * ADD A ATTACK*/
  1012. AttackRecord attack = new AttackRecord();
  1013. attack.setAttack_id(attackId);
  1014. attack.setBssid(bssidName);
  1015. attack.setProtocol(protocolName);
  1016. attack.setLocalIP(bssidName);
  1017. dbh.addAttackRecord(attack);
  1018. // RECORDS PER ATTACK
  1019. for (int messageID = attackId; messageID < attackId + numRecordsPerAttack; messageID++) {
  1020. MessageRecord message = new MessageRecord();
  1021. message.setId(messageID);
  1022. message.setAttack_id(attackId);
  1023. // GO BACK IN TIME
  1024. message.setTimestamp(cal.getTimeInMillis()
  1025. - ((messageID * 60 * 60 * 24) * 1000) + (1000 * ((messageID - attackId) + 1)));
  1026. if ((messageID - attackId) % 2 == 0){
  1027. message.setType(MessageRecord.TYPE.RECEIVE);
  1028. } else {
  1029. message.setType(MessageRecord.TYPE.SEND);
  1030. }
  1031. message.setPacket("");
  1032. dbh.addMessageRecord(message);
  1033. }
  1034. attackId+=numRecordsPerAttack;
  1035. }
  1036. }
  1037. // int countAllLogs = dbh.getAllRecords().size();
  1038. // int countRecords = dbh.getRecordCount();
  1039. // int countAttacks = dbh.getAttackCount();
  1040. //
  1041. // if ((countRecords == 0)) {
  1042. // Record rec = dbh.getRecordOfAttackId(0);
  1043. // Record rec2 = dbh.getRecord(0);
  1044. //
  1045. // System.out.println("" + "Could not create logs!");
  1046. // }
  1047. }
  1048. /**Navigation. Shows the record detail view for the given record
  1049. * @param Record record to show
  1050. * */
  1051. private void pushRecordDetailViewForRecord(Record record){
  1052. FragmentManager fm = this.getActivity().getFragmentManager();
  1053. if (fm != null){
  1054. RecordDetailFragment newFragment = new RecordDetailFragment();
  1055. newFragment.setRecord(record);
  1056. newFragment.setUpNavigatible(true);
  1057. MainActivity.getInstance().injectFragment(newFragment);
  1058. }
  1059. }
  1060. }