StatisticsFragment.java 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772
  1. package de.tudarmstadt.informatik.hostage.ui2.fragment;
  2. import android.annotation.SuppressLint;
  3. import android.app.Activity;
  4. import android.app.Fragment;
  5. import android.app.FragmentManager;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.content.res.Configuration;
  9. import android.graphics.Color;
  10. import android.os.Bundle;
  11. import android.view.LayoutInflater;
  12. import android.view.View;
  13. import android.view.ViewGroup;
  14. import android.widget.AdapterView;
  15. import android.widget.ImageButton;
  16. import android.widget.LinearLayout;
  17. import android.widget.ListView;
  18. import android.widget.ProgressBar;
  19. import android.widget.RelativeLayout;
  20. import android.widget.TextView;
  21. import com.echo.holographlibrary.Bar;
  22. import com.echo.holographlibrary.BarGraph;
  23. import com.echo.holographlibrary.Line;
  24. import com.echo.holographlibrary.LineGraph;
  25. import com.echo.holographlibrary.LinePoint;
  26. import com.echo.holographlibrary.PieGraph;
  27. import com.echo.holographlibrary.PieSlice;
  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 de.tudarmstadt.informatik.hostage.R;
  37. import de.tudarmstadt.informatik.hostage.deprecated.UglyDbHelper;
  38. import de.tudarmstadt.informatik.hostage.logging.Record;
  39. import de.tudarmstadt.informatik.hostage.ui.LogFilter;
  40. import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
  41. import de.tudarmstadt.informatik.hostage.ui2.adapter.StatisticListAdapter;
  42. import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
  43. import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
  44. import de.tudarmstadt.informatik.hostage.ui2.helper.ColorSequenceGenerator;
  45. import de.tudarmstadt.informatik.hostage.ui2.model.PlotComparisonItem;
  46. import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
  47. import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
  48. import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupItem;
  49. import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupTable;
  50. import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
  51. /**
  52. * Created by Julien on 16.02.14.
  53. */
  54. public class StatisticsFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
  55. static final String FILTER_MENU_TITLE_BSSID = "BSSID";
  56. static final String FILTER_MENU_TITLE_ESSID = "ESSID";
  57. static final String FILTER_MENU_TITLE_PROTOCOLS = MainActivity.getContext().getString(R.string.stats_protocols);
  58. static final String FILTER_MENU_TITLE_PROTOCOL = MainActivity.getContext().getString(R.string.rec_protocol);
  59. static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = MainActivity.getContext().getString(R.string.rec_latest);
  60. static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = MainActivity.getContext().getString(R.string.rec_earliest);
  61. static final String FILTER_MENU_TITLE_REMOVE = MainActivity.getContext().getString(R.string.rec_reset_filter);
  62. static final String FILTER_MENU_POPUP_TITLE = MainActivity.getContext().getString(R.string.rec_filter_by);
  63. static final String MENU_TITLE_PROTOCOLS = MainActivity.getContext().getString(
  64. R.string.stats_protocols);
  65. static final String MENU_TITLE_NETWORK = MainActivity.getContext().getString(
  66. R.string.stats_networks);
  67. static final String MENU_TITLE_ATTACKS = MainActivity.getContext().getString(
  68. R.string.stats_attacks);
  69. static final String MENU_POPUP_TITLE = MainActivity.getContext().getString(
  70. R.string.stats_visualize);
  71. static final String CHART_TYPE_TITLE_BAR = MainActivity.getContext().getString(
  72. R.string.stats_bar_plot);
  73. static final String CHART_TYPE_TITLE_PIE = MainActivity.getContext().getString(R.string.stats_pie_plot);
  74. static final String CHART_TYPE_TITLE_LINE = MainActivity.getContext().getString(R.string.stats_line_plot);
  75. static final String DIALOG_PROTOCOLS_TITLE = MainActivity.getContext().getString(R.string.stats_select_protocol_data);
  76. static final String DIALOG_NETWORK_TITLE = MainActivity.getContext().getString(R.string.stats_select_network_data);
  77. static final String DIALOG_ATTACK_TITLE = MainActivity.getContext().getString(R.string.stats_select_attack_data);
  78. static final String COMPARE_TITLE_AttacksPerProtocol = MainActivity.getContext().getString(R.string.stats_attacks_protocol);
  79. static final String COMPARE_TITLE_UsesPerProtocol = MainActivity.getContext().getString(R.string.stats_uses_protocol);
  80. static final String COMPARE_TITLE_AttacksPerDate = MainActivity.getContext().getString(R.string.stats_attacks_date);
  81. static final String COMPARE_TITLE_AttacksPerTime = MainActivity.getContext().getString(R.string.stats_attacks_time);
  82. static final String COMPARE_TITLE_AttacksPerBSSID = MainActivity.getContext().getString(R.string.stats_attacks_bssid);
  83. static final String COMPARE_TITLE_AttacksPerESSID = MainActivity.getContext().getString(R.string.stats_attacks_essid);
  84. static final String FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE = MainActivity.getContext().getString(R.string.stats_select_protocol);
  85. static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT = MainActivity.getContext().getString(R.string.stats_attacks_count);
  86. static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_PERCENTAGE = MainActivity.getContext().getString(R.string.stats_per_cent_all);
  87. static final String OTHER_CHART_TITLE = MainActivity.getContext().getString(R.string.stats_other);
  88. // MINIMAL 2
  89. static int MAX_NUMBER_OF_CHART_OBJECTS = 6;
  90. private boolean wasBelowTimePicker;
  91. private LogFilter filter;
  92. private boolean showFilterButton;
  93. private PieGraph pieGraph;
  94. private LineGraph lineGraph;
  95. private BarGraph barGraph;
  96. private View rootView;
  97. private View currentPlotView;
  98. private Thread loader;
  99. private ProgressBar spinner;
  100. private ArrayList<Integer> colorList;
  101. private ArrayList<PlotComparisonItem> currentData;
  102. private UglyDbHelper dbh;
  103. private ListView legendListView;
  104. private String selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
  105. public enum ChartType {
  106. PIE_CHART(0),
  107. BAR_CHART(1),
  108. LINE_CHART(2);
  109. private int value;
  110. private ChartType(int value) {
  111. this.value = value;
  112. }
  113. static public ChartType create(int value){
  114. if (value < 0 || value >= ChartType.values().length) return ChartType.PIE_CHART;
  115. return ChartType.values()[value];
  116. }
  117. public String toString(){
  118. if (this.equals(ChartType.create(0))){
  119. return CHART_TYPE_TITLE_PIE;
  120. }
  121. if (this.equals(ChartType.create(1))){
  122. return CHART_TYPE_TITLE_BAR;
  123. }
  124. return CHART_TYPE_TITLE_LINE;
  125. }
  126. }
  127. /**Returns the FilterButton.
  128. * @return ImageButton filterButton*/
  129. private ImageButton getFilterButton(){
  130. return (ImageButton) this.rootView.findViewById(R.id.FilterButton);
  131. }
  132. /**
  133. * Returns the layout ID
  134. * @Return int layoutID
  135. * */
  136. public int getLayoutID(){
  137. return R.layout.fragment_statistics;
  138. }
  139. @Override
  140. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  141. Bundle savedInstanceState) {
  142. super.onCreateView(inflater, container, savedInstanceState);
  143. getActivity().setTitle(getResources().getString(R.string.drawer_statistics));
  144. dbh = new UglyDbHelper(this.getBaseContext());
  145. // Get the message from the intent
  146. if (this.filter == null){
  147. Intent intent = this.getActivity().getIntent();
  148. LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
  149. if(filter == null){
  150. this.clearFilter();
  151. } else {
  152. this.filter = filter;
  153. }
  154. }
  155. this.rootView = inflater.inflate(this.getLayoutID(), container, false);
  156. this.configureRootView(this.rootView);
  157. return this.rootView;
  158. }
  159. @Override
  160. public void onCreate(Bundle savedInstanceState) {
  161. super.onCreate(savedInstanceState);
  162. setHasOptionsMenu(true);
  163. setRetainInstance(true);
  164. }
  165. @Override
  166. public void onConfigurationChanged(Configuration newConfig){
  167. super.onConfigurationChanged(newConfig);
  168. LayoutInflater inflater = LayoutInflater.from(getActivity());
  169. ViewGroup container = (ViewGroup) this.getView();
  170. container.removeAllViewsInLayout();
  171. this.rootView = inflater.inflate(this.getLayoutID(), container, false);
  172. container.addView(this.rootView);
  173. this.configureRootView(this.rootView);
  174. }
  175. /**Returns the base context.
  176. * @return Context the base context
  177. * */
  178. private Context getBaseContext(){
  179. return this.getActivity().getBaseContext();
  180. }
  181. /**Returns the application context.
  182. * @return Context the application context*/
  183. private Context getApplicationContext(){
  184. return this.getActivity().getApplicationContext();
  185. }
  186. /**Configures the given rootview.
  187. * Sets the Spinner, the list and all requiered buttons.
  188. * It also actualises the current plot type.
  189. * @param View rootView
  190. * */
  191. public void configureRootView(View rootView){
  192. LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
  193. plotLayout.removeAllViews();
  194. plotLayout.setWillNotDraw(false);
  195. ProgressBar spinner = (ProgressBar) rootView.findViewById(R.id.progressBar1);
  196. if(spinner != null){
  197. this.spinner = spinner;
  198. this.spinner.setVisibility(View.GONE);
  199. } else {
  200. RelativeLayout parent = (RelativeLayout) this.spinner.getParent();
  201. parent.removeView(this.spinner);
  202. RelativeLayout newParent = (RelativeLayout) rootView.findViewById(R.id.plot_parent_layout);
  203. if (newParent != null){
  204. newParent.addView(this.spinner);
  205. }
  206. }
  207. this.legendListView = (ListView) rootView.findViewById(R.id.legend_list_view);
  208. this.legendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  209. @Override
  210. public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
  211. StatisticsFragment.this.userTappedOnLegendItem(i);
  212. }
  213. });
  214. rootView.setWillNotDraw(false);
  215. ImageButton visualButton = (ImageButton) rootView.findViewById(R.id.plot_data_button);
  216. visualButton.setOnClickListener(new View.OnClickListener() {
  217. public void onClick(View v) {
  218. StatisticsFragment.this.openBarSelectionMenuOnView(v);
  219. }
  220. });
  221. ImageButton filterButton = this.getFilterButton();
  222. filterButton.setOnClickListener(new View.OnClickListener() {
  223. public void onClick(View v) {
  224. StatisticsFragment.this.openFilterMenuOnView(v);
  225. }
  226. });
  227. this.actualiseCurrentPlot();
  228. if (this.currentPlotView instanceof BarGraph){
  229. this.setTitle("" + this.getCurrentSelectedProtocol() + ": " +this.selectedCompareData);
  230. } else {
  231. this.setTitle(this.selectedCompareData);
  232. }
  233. }
  234. /**Sets the title over the plot view.
  235. * @param String title
  236. * */
  237. public void setTitle(String title){
  238. TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
  239. if (title != null && titleView != null){
  240. titleView.setText(title);
  241. titleView.invalidate();
  242. }
  243. }
  244. /**Returns the title over the plot view.
  245. * @return String title
  246. * */
  247. public String getTitle(){
  248. TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
  249. if (titleView != null){
  250. return "" + titleView.getText();
  251. }
  252. return "";
  253. }
  254. @Override
  255. public void onStart() {
  256. super.onStart();
  257. this.actualiseCurrentPlot();
  258. this.currentPlotView.invalidate();
  259. if (this.currentPlotView instanceof BarGraph){
  260. this.setTitle("" + this.getCurrentSelectedProtocol() + ": " +this.selectedCompareData);
  261. } else {
  262. this.setTitle(this.selectedCompareData);
  263. }
  264. }
  265. /**Sets the current chart to the given type and acualises it.
  266. * @param ChartType type
  267. * */
  268. public void setChartType(ChartType type){
  269. boolean shouldChange = true;
  270. this.clearFilter();
  271. if (this.currentPlotView != null){
  272. if (type == ChartType.PIE_CHART){
  273. shouldChange = ! (this.currentPlotView instanceof PieGraph);
  274. // SET FILTER BUTTON HIDDEN
  275. ImageButton filterButton = this.getFilterButton();
  276. if (filterButton != null) filterButton.setVisibility(View.GONE);
  277. } else {
  278. if (this.pieGraph != null)
  279. this.pieGraph.setVisibility(View.GONE);
  280. // SHOW FILTER BUTTON
  281. ImageButton filterButton = this.getFilterButton();
  282. if (filterButton != null) filterButton.setVisibility(View.VISIBLE);
  283. }
  284. if (type == ChartType.LINE_CHART){
  285. shouldChange = ! (this.currentPlotView instanceof LineGraph);
  286. } else {
  287. if (this.lineGraph != null)
  288. this.lineGraph.setVisibility(View.GONE);
  289. }
  290. if (type == ChartType.BAR_CHART){
  291. shouldChange = ! (this.currentPlotView instanceof BarGraph);
  292. } else {
  293. if (this.barGraph != null)
  294. this.barGraph.setVisibility(View.GONE);
  295. }
  296. }
  297. if (shouldChange){
  298. this.currentPlotView = this.getPlotViewForType(type);
  299. this.currentPlotView.setVisibility(View.VISIBLE);
  300. }
  301. this.actualiseCurrentPlot();
  302. }
  303. /**Returns the plot view for a given type.
  304. * @param ChartType type.
  305. * */
  306. public View getPlotViewForType(ChartType type){
  307. switch (type){
  308. case PIE_CHART:
  309. return this.getPieGraphView();
  310. case LINE_CHART:
  311. return this.getLineGraphView();
  312. default:
  313. return this.getBarGraphView();
  314. }
  315. }
  316. /**Actualises the list view. Therefore it requiers the "currentData".*/
  317. public void actualiseLegendList(){
  318. StatisticListAdapter adapter = new StatisticListAdapter(this.getApplicationContext(), this.currentData);
  319. if (this.currentPlotView instanceof LineGraph){
  320. adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
  321. @Override
  322. public String convertValueForItemToString(PlotComparisonItem item) {
  323. return String.format("%.02f", item.getValue2()) + " %" + " " + "("+ (item.getValue1().intValue()) +")";
  324. }
  325. });
  326. } else {
  327. adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
  328. @Override
  329. public String convertValueForItemToString(PlotComparisonItem item) {
  330. int v = (int) item.getValue2().intValue();
  331. return "" + v;
  332. }
  333. });
  334. }
  335. this.legendListView.setAdapter(adapter);
  336. TextView tableHeaderTitleView = (TextView) this.rootView.findViewById(R.id.table_header_title_textview);
  337. TextView tableHeaderValueView = (TextView) this.rootView.findViewById(R.id.table_header_value_textview);
  338. if (this.currentPlotView instanceof LineGraph){
  339. tableHeaderTitleView.setText(FILTER_MENU_TITLE_ESSID);
  340. tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_PERCENTAGE);
  341. }
  342. if (this.currentPlotView instanceof PieGraph){
  343. tableHeaderTitleView.setText(FILTER_MENU_TITLE_PROTOCOL);
  344. tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT);
  345. }
  346. if (this.currentPlotView instanceof BarGraph){
  347. tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT);
  348. if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)){
  349. tableHeaderTitleView.setText(FILTER_MENU_TITLE_BSSID);
  350. } else {
  351. tableHeaderTitleView.setText(FILTER_MENU_TITLE_ESSID);
  352. }
  353. }
  354. }
  355. /*
  356. * MENU
  357. * */
  358. /**Opens the Bar Option Menu above the given anchor view.
  359. * @param View the anchor view*/
  360. private void openBarSelectionMenuOnView(View anchorView){
  361. SimplePopupTable visualiseMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
  362. public void onItemClick(Object ob) {
  363. if (ob instanceof AbstractPopupItem){
  364. AbstractPopupItem item = (AbstractPopupItem) ob;
  365. StatisticsFragment.this.userSelectMenuItem(item);
  366. }
  367. }
  368. });
  369. visualiseMenu.setTitle(MENU_POPUP_TITLE);
  370. int id = 0;
  371. for(String title : StatisticsFragment.this.getMenuTitles()){
  372. SimplePopupItem item = new SimplePopupItem(this.getActivity());
  373. item.setTitle(title);
  374. item.setItemId(id);
  375. item.setSelected(false);
  376. visualiseMenu.addItem(item);
  377. id++;
  378. }
  379. visualiseMenu.showOnView(anchorView);
  380. }
  381. /**Will be called when the users selected an menu item (visualise menu / plot menu).
  382. * If the user selected "Protocols" this method sets the current plot type to piegraph.
  383. * Otherwise it will open a new dialog to select the comparison type.
  384. * */
  385. private void userSelectMenuItem(AbstractPopupItem item){
  386. // OPEN A DIALOG TO SPECIFY THE VISUALISE DATA
  387. if (item.getTitle().equals(MENU_TITLE_PROTOCOLS)){
  388. ChartType chartType = ChartType.PIE_CHART;
  389. this.selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
  390. this.setChartType(chartType);
  391. this.setTitle(COMPARE_TITLE_AttacksPerProtocol);
  392. }
  393. if (item.getTitle().equals(MENU_TITLE_NETWORK)){
  394. this.openNetworkDataDialog();
  395. }
  396. if (item.getTitle().equals(MENU_TITLE_ATTACKS)){
  397. this.openAttackDataDialog();
  398. }
  399. }
  400. /**Returns the menu titles (visualise menu / plot menu)*/
  401. private ArrayList<String> getMenuTitles(){
  402. ArrayList<String> titles = new ArrayList<String>();
  403. titles.add(MENU_TITLE_PROTOCOLS);
  404. titles.add(MENU_TITLE_NETWORK);
  405. titles.add(MENU_TITLE_ATTACKS);
  406. return titles;
  407. }
  408. /*
  409. * PLOT DATA DIALOGS
  410. * */
  411. // private void openProtocolDataDialog(){
  412. // ArrayList<String> titles = this.getDialogProtocolDataTitle();
  413. // ChecklistDialog newFragment = new ChecklistDialog(DIALOG_PROTOCOLS_TITLE, titles, this.selectedData(titles), false , this);
  414. // newFragment.show(this.getActivity().getFragmentManager(), DIALOG_PROTOCOLS_TITLE);
  415. // }
  416. /**Opens the network comparison dialog*/
  417. private void openNetworkDataDialog(){
  418. ArrayList<String> titles = this.getDialogNetworkDataTitle();
  419. ChecklistDialog newFragment = new ChecklistDialog(DIALOG_NETWORK_TITLE, titles, this.selectedData(titles), false , this);
  420. newFragment.show(this.getActivity().getFragmentManager(), DIALOG_NETWORK_TITLE);
  421. }
  422. /**Opens the attack comparison dialog*/
  423. private void openAttackDataDialog(){
  424. ArrayList<String> titles = this.getDialogAttackDataTitle();
  425. ChecklistDialog newFragment = new ChecklistDialog(DIALOG_ATTACK_TITLE, titles, this.selectedData(titles), false , this);
  426. newFragment.show(this.getActivity().getFragmentManager(), DIALOG_ATTACK_TITLE);
  427. }
  428. /*
  429. *
  430. * DIALOG ACTION METHODS
  431. *
  432. * */
  433. /**
  434. * Will be called if the user selects the positiv button on an checklist dialog.
  435. * @param ChecklistDialog dialog
  436. * */
  437. public void onDialogPositiveClick(ChecklistDialog dialog) {
  438. String title = dialog.getTitle();
  439. ArrayList<String> titles =dialog.getSelectedItemTitles();
  440. if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  441. //titles = titles.size() == 0 ? this.protocolTitles() : titles;
  442. this.filter.setProtocols(titles);
  443. this.actualiseCurrentPlot();
  444. return;
  445. }
  446. if (title.equals(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE)){
  447. if (titles.size() == 0){
  448. titles = new ArrayList<String>();
  449. titles.add(this.protocolTitles().get(0));
  450. }
  451. this.filter.setProtocols(titles);
  452. this.actualiseCurrentPlot();
  453. String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
  454. this.setTitle(fragTitle);
  455. return;
  456. }
  457. if (title.equals(FILTER_MENU_TITLE_ESSID)){
  458. this.filter.setESSIDs(titles);
  459. this.actualiseCurrentPlot();
  460. return;
  461. }
  462. if (title.equals(FILTER_MENU_TITLE_BSSID)){
  463. this.filter.setBSSIDs(titles);
  464. this.actualiseCurrentPlot();
  465. return;
  466. }
  467. if (titles.size() != 0){
  468. String data = titles.get(0);
  469. this.setTitle(data);
  470. if (data.equals(COMPARE_TITLE_AttacksPerTime) || data.equals(COMPARE_TITLE_AttacksPerDate)){
  471. ChartType chartType = ChartType.LINE_CHART;
  472. this.selectedCompareData = data;
  473. this.setChartType(chartType);
  474. return;
  475. }
  476. if (data.equals(COMPARE_TITLE_AttacksPerBSSID) || data.equals(COMPARE_TITLE_AttacksPerESSID)){
  477. ChartType chartType = ChartType.BAR_CHART;
  478. this.selectedCompareData = data;
  479. this.setChartType(chartType);
  480. String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
  481. this.setTitle(fragTitle);
  482. return;
  483. }
  484. }
  485. }
  486. /**
  487. * Will be called if the user selects the negativ button on an checklist dialog.
  488. * @param ChecklistDialog dialog
  489. * */
  490. public void onDialogNegativeClick(ChecklistDialog dialog) {
  491. }
  492. /*
  493. *
  494. * DIALOG DATA
  495. *
  496. * */
  497. // private ArrayList<String> getDialogProtocolDataTitle(){
  498. // ArrayList<String> data = new ArrayList<String>();
  499. // data.add(COMPARE_TITLE_AttacksPerProtocol);
  500. // data.add(COMPARE_TITLE_UsesPerProtocol);
  501. // return data;
  502. // }
  503. /**
  504. * Returns the Attacks comparison titles.
  505. * @return ArrayList<String> the titles
  506. */
  507. private ArrayList<String> getDialogAttackDataTitle(){
  508. ArrayList<String> data = new ArrayList<String>();
  509. data.add(COMPARE_TITLE_AttacksPerDate);
  510. data.add(COMPARE_TITLE_AttacksPerTime);
  511. return data;
  512. }
  513. /**
  514. * Returns the network comparison titles.
  515. * @return ArrayList<String> the titles
  516. */
  517. private ArrayList<String> getDialogNetworkDataTitle(){
  518. ArrayList<String> data = new ArrayList<String>();
  519. data.add(COMPARE_TITLE_AttacksPerESSID);
  520. data.add(COMPARE_TITLE_AttacksPerBSSID);
  521. return data;
  522. }
  523. /**
  524. * DEFAULT
  525. * Returns an boolean array with a default selection. Just the first object is true.
  526. * @return boolean[] selected array
  527. */
  528. private boolean[] selectedData(ArrayList<String> data){
  529. boolean[] selected = new boolean[data.size()];
  530. // SET DEFAULT
  531. selected[0] = true;
  532. return selected;
  533. }
  534. /*
  535. *
  536. * FILTER BUTTON
  537. *
  538. * */
  539. /**
  540. * Opens the filter menu above an given anchor view.
  541. * @param View anchor view
  542. */
  543. private void openFilterMenuOnView(View anchor){
  544. SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
  545. public void onItemClick(Object ob) {
  546. if (ob instanceof AbstractPopupItem){
  547. AbstractPopupItem item = (AbstractPopupItem) ob;
  548. StatisticsFragment.this.onFilterMenuItemSelected(item);
  549. }
  550. }
  551. });
  552. filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
  553. for(String title : StatisticsFragment.this.filterMenuTitles()){
  554. AbstractPopupItem item = null;
  555. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) continue;
  556. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  557. item = new SplitPopupItem(this.getActivity());
  558. item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  559. item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  560. if (this.filter.hasBelowTimestamp()){
  561. item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
  562. }
  563. if (this.filter.hasAboveTimestamp()){
  564. item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
  565. }
  566. } else {
  567. item = new SimplePopupItem(this.getActivity());
  568. item.setTitle(title);
  569. ((SimplePopupItem)item).setSelected(this.isFilterSetForTitle(title));
  570. }
  571. filterMenu.addItem(item);
  572. }
  573. filterMenu.showOnView(anchor);
  574. }
  575. /**
  576. * Will be called if the user selected an filter item.
  577. * @param AbstractPopupItem item
  578. */
  579. private void onFilterMenuItemSelected(AbstractPopupItem item){
  580. if (item instanceof SplitPopupItem){
  581. SplitPopupItem sItem = (SplitPopupItem) item;
  582. this.wasBelowTimePicker = sItem.wasRightTouch;
  583. if (this.wasBelowTimePicker){
  584. this.openTimestampToFilterDialog();
  585. } else {
  586. this.openTimestampFromFilterDialog();
  587. }
  588. return;
  589. }
  590. String title = item.getTitle();
  591. if (title.equals(FILTER_MENU_TITLE_ESSID)){
  592. this.openESSIDFilterDialog();
  593. }
  594. if (title.equals(FILTER_MENU_TITLE_BSSID)){
  595. this.openBSSIDFilterDialog();
  596. }
  597. if (title.equals(FILTER_MENU_TITLE_PROTOCOL)){
  598. this.openFilterDialogSelectProtocol();
  599. }
  600. if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  601. this.openProtocolsFilterDialog();
  602. }
  603. if (title.equals(FILTER_MENU_TITLE_REMOVE)){
  604. this.clearFilter();
  605. this.actualiseCurrentPlot();
  606. }
  607. }
  608. /**
  609. * Return the menu titles of the filter menu.
  610. * @return ArrayList<String> filter menu title
  611. * */
  612. private ArrayList<String> filterMenuTitles(){
  613. ArrayList<String> titles = new ArrayList<String>();
  614. if (this.currentPlotView instanceof LineGraph){
  615. titles.add(FILTER_MENU_TITLE_ESSID);
  616. titles.add(FILTER_MENU_TITLE_PROTOCOLS);
  617. titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  618. if (this.filter.hasESSIDs() || this.filter.hasATimestamp() || (this.filter.getProtocols() != null && this.filter.hasProtocols() && this.filter.getProtocols().size() != this.protocolTitles().size())){
  619. titles.add(FILTER_MENU_TITLE_REMOVE);
  620. }
  621. } else {
  622. titles.add(FILTER_MENU_TITLE_PROTOCOL);
  623. String protocol = this.getCurrentSelectedProtocol();
  624. if (protocol.length() > 0){
  625. if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)){
  626. titles.add(FILTER_MENU_TITLE_BSSID);
  627. } else {
  628. // DEFAULT
  629. titles.add(FILTER_MENU_TITLE_ESSID);
  630. }
  631. }
  632. titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  633. if (this.filter.hasATimestamp() || this.filter.hasESSIDs() || this.filter.hasBSSIDs()
  634. || (this.currentPlotView instanceof LineGraph && this.filter.hasProtocols())){
  635. titles.add(FILTER_MENU_TITLE_REMOVE);
  636. }
  637. }
  638. return titles;
  639. }
  640. /**
  641. * Opens a multiple protocol checklist dialog
  642. */
  643. private void openProtocolsFilterDialog(){
  644. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS,
  645. this.protocolTitles(),
  646. this.selectedProtocols(),
  647. true ,
  648. this);
  649. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_PROTOCOLS);
  650. }
  651. /**
  652. * Opens a single protocol checklist dialog
  653. */
  654. private void openFilterDialogSelectProtocol(){
  655. ArrayList<String> titles = this.protocolTitles();
  656. boolean[] selected = new boolean[titles.size()];
  657. int i = 0;
  658. for (String title : titles){
  659. selected[i] = title.equals(this.getCurrentSelectedProtocol());
  660. i++;
  661. }
  662. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE, titles, selected, false , this);
  663. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE);
  664. }
  665. /**
  666. * Opens a multiple essid checklist dialog
  667. */
  668. private void openESSIDFilterDialog(){
  669. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_ESSID, this.essids(), this.selectedESSIDs(), true , this);
  670. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
  671. }
  672. /**Opens a multiple bssid checlist dialog.*/
  673. private void openBSSIDFilterDialog(){
  674. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_BSSID, this.bssids(), this.selectedBSSIDs(), true , this);
  675. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
  676. }
  677. /** Opens a minimal timestamp dialog.**/
  678. private void openTimestampFromFilterDialog(){
  679. this.wasBelowTimePicker = false;
  680. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  681. newFragment.setDateChangeListener(this);
  682. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  683. if (this.filter.aboveTimestamp != Long.MIN_VALUE)newFragment.setDate(this.filter.aboveTimestamp);
  684. }
  685. /** Opens the maximal timestamp dialog.*/
  686. private void openTimestampToFilterDialog(){
  687. this.wasBelowTimePicker = true;
  688. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  689. newFragment.setDateChangeListener(this);
  690. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  691. if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
  692. }
  693. /** Returns all essids
  694. * If the current plot is a bar graph, it just return all possible essids for the selected protocol
  695. * @return ArrayList<String> essids
  696. * */
  697. public ArrayList<String> essids(){
  698. ArrayList<String> records;
  699. if (this.currentPlotView instanceof BarGraph){
  700. records = dbh.getUniqueESSIDRecordsForProtocol(this.getCurrentSelectedProtocol());
  701. } else {
  702. records = dbh.getUniqueESSIDRecords();
  703. }
  704. return records;
  705. }
  706. /** Returns a boolean array. The position in the array will be true, if the essid is selected in the filter.
  707. * @return boolean[] selected essids*/
  708. public boolean[] selectedESSIDs(){
  709. ArrayList<String> essids = this.essids();
  710. boolean[] selected = new boolean[essids.size()];
  711. int i = 0;
  712. for(String essid : essids){
  713. selected[i] =(this.filter.getESSIDs().contains(essid));
  714. i++;
  715. }
  716. return selected;
  717. }
  718. /** Returns all bssids
  719. * If the current plot is a bar graph, it just return all possible bssids for the selected protocol
  720. * @return ArrayList<String> bssids
  721. * */
  722. public ArrayList<String> bssids(){
  723. ArrayList<String> records ;
  724. if (this.currentPlotView instanceof BarGraph){
  725. records = dbh.getUniqueBSSIDRecordsForProtocol(this.getCurrentSelectedProtocol());
  726. } else {
  727. records = dbh.getUniqueBSSIDRecords();
  728. }
  729. return records;
  730. }
  731. /** Returns a boolean array. The position in the array will be true, if the bssid is selected in the filter.
  732. * @return boolean[] selected bssids*/
  733. public boolean[] selectedBSSIDs(){
  734. ArrayList<String> bssids = this.bssids();
  735. boolean[] selected = new boolean[bssids.size()];
  736. int i = 0;
  737. for(String bssid : bssids){
  738. selected[i] =(this.filter.getBSSIDs().contains(bssid));
  739. i++;
  740. }
  741. return selected;
  742. }
  743. /**Will be called if the user selects an date on the timestamp dialog*/
  744. public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
  745. if(this.wasBelowTimePicker){
  746. this.filter.setBelowTimestamp(dialog.getDate());
  747. } else {
  748. this.filter.setAboveTimestamp(dialog.getDate());
  749. }
  750. this.actualiseCurrentPlot();
  751. }
  752. /**Will be called if the user cancels an date selection on the timestamp dialog*/
  753. public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
  754. if(this.wasBelowTimePicker){
  755. this.filter.setBelowTimestamp(Long.MAX_VALUE);
  756. } else {
  757. this.filter.setAboveTimestamp(Long.MIN_VALUE);
  758. }
  759. this.actualiseCurrentPlot();
  760. }
  761. /*
  762. *
  763. * PLOT TYPES
  764. *
  765. * **/
  766. /**Returns the current pie graph.
  767. * @return PieGraph current piegraph*/
  768. public PieGraph getPieGraphView(){
  769. if (this.pieGraph == null) {
  770. this.pieGraph = new PieGraph(this.getApplicationContext());
  771. LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
  772. plotLayout.addView(this.pieGraph);
  773. this.pieGraph.setOnSliceClickedListener(new PieGraph.OnSliceClickedListener() {
  774. @Override
  775. public void onClick(int index) {
  776. StatisticsFragment.this.onSliceClick(index);
  777. }
  778. });
  779. }
  780. return this.pieGraph;
  781. }
  782. /**
  783. * Returns the current line graph.
  784. * @return LineGraph current line graph
  785. */
  786. public LineGraph getLineGraphView(){
  787. if (this.lineGraph == null) {
  788. this.lineGraph = new LineGraph(this.getActivity());
  789. LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
  790. plotLayout.addView(this.lineGraph);
  791. this.lineGraph.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
  792. }
  793. return this.lineGraph;
  794. }
  795. /**
  796. * Returns the current BarGraph.
  797. * @return BarGraph the current bar graph
  798. */
  799. public BarGraph getBarGraphView(){
  800. if (this.barGraph == null) {
  801. this.barGraph = new BarGraph(this.getActivity());
  802. LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
  803. this.barGraph.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT ));
  804. plotLayout.addView(this.barGraph);
  805. this.barGraph.setShowBarText(false);
  806. this.barGraph.setPopupImageID(R.drawable.popup_black);
  807. this.barGraph.setOnBarClickedListener(new BarGraph.OnBarClickedListener() {
  808. @Override
  809. public void onClick(int i) {
  810. StatisticsFragment.this.onBarClick(i);
  811. }
  812. });
  813. }
  814. return this.barGraph;
  815. }
  816. /*
  817. * FEED PLOTS WITH DATA
  818. * */
  819. /**
  820. * Sets the data for the given PieGraph
  821. * @param PieGraph piegraph
  822. */
  823. public void setPieGraphData(PieGraph piegraph){
  824. this.currentData = this.getPieData();
  825. if (this.currentData == null){
  826. this.currentData = new ArrayList<PlotComparisonItem>();
  827. }
  828. piegraph.removeSlices();
  829. for (PlotComparisonItem item : this.currentData){
  830. PieSlice slice = new PieSlice();
  831. slice.setColor(item.getColor());
  832. Double value2 = (Double) item.getValue2();
  833. float v = value2.floatValue();
  834. slice.setValue(v);
  835. slice.setTitle(item.getTitle());
  836. piegraph.addSlice(slice);
  837. }
  838. piegraph.invalidate();
  839. }
  840. /**
  841. * Sets the data for the given LineGraph
  842. * @param LineGraph linegraph
  843. */
  844. public void setLineGraphData(LineGraph linegraph){
  845. this.currentData = this.getLineData();
  846. if (this.currentData == null){
  847. this.currentData = new ArrayList<PlotComparisonItem>();
  848. }
  849. linegraph.removeAllLines();
  850. double rangeMax_Y = 0;
  851. double rangeMin_Y = 0;
  852. double rangeMax_X = 0;
  853. double rangeMin_X = 0;
  854. int count = 0;
  855. for (PlotComparisonItem lineItem : this.currentData){
  856. ArrayList<PlotComparisonItem> data = lineItem.getOtherData();
  857. int index = 0;
  858. Line l = new Line();
  859. int lineColor = lineItem.getColor();
  860. l.setColor(lineColor);
  861. for (PlotComparisonItem pointItem : data){
  862. LinePoint p = new LinePoint();
  863. p.setX(pointItem.getValue1());
  864. Double value2 = pointItem.getValue2();
  865. p.setY(value2);
  866. p.setColor(lineColor);
  867. l.addPoint(p);
  868. rangeMax_Y = Math.max(pointItem.getValue2(), rangeMax_Y);
  869. rangeMax_X = Math.max(pointItem.getValue1(), rangeMax_X);
  870. if (count != 0){
  871. rangeMin_Y = Math.min(pointItem.getValue2(), rangeMin_Y);
  872. rangeMin_X = Math.min(pointItem.getValue1(), rangeMin_X);
  873. } else {
  874. rangeMin_Y = pointItem.getValue2();
  875. rangeMin_X = pointItem.getValue1();
  876. }
  877. index++;
  878. count++;
  879. }
  880. linegraph.addLine(l);
  881. }
  882. // add a bit more space
  883. rangeMax_Y++;
  884. rangeMin_Y--;
  885. boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
  886. if (shouldUseDate){
  887. linegraph.resetXLimits();
  888. if (this.filter.hasBelowTimestamp()){
  889. rangeMax_X = Math.max(this.filter.belowTimestamp, rangeMax_X);
  890. }
  891. if (this.filter.hasAboveTimestamp()){
  892. rangeMin_X = Math.min(this.filter.aboveTimestamp, rangeMin_X);
  893. }
  894. if (rangeMax_X == rangeMin_X){
  895. double aDay = 60*60*24*1000;
  896. rangeMax_X+= aDay;
  897. rangeMin_X-= aDay;
  898. }
  899. double stepRange = (rangeMax_X - rangeMin_X)/(60*60*24*1000);
  900. linegraph.setxAxisStep(Math.max(1, (float) Math.min(stepRange, 4)));
  901. linegraph.setRangeX(rangeMin_X , rangeMax_X);
  902. linegraph.setConverter(new LineGraph.AxisDataConverter() {
  903. @Override
  904. public String convertDataForX_Position(double x) {
  905. return StatisticsFragment.this.getDateAsDayString((long)x);
  906. }
  907. @Override
  908. public String convertDataForY_Position(double y){
  909. return "" + (long)y;
  910. }
  911. });
  912. } else {
  913. linegraph.setxAxisStep(12.f);
  914. linegraph.setRangeX(0, 24);
  915. linegraph.setConverter(null);
  916. }
  917. int maxY = (int)(rangeMax_Y - rangeMin_Y);
  918. linegraph.setYAxisStep(Math.min(maxY, 5));
  919. int yStep = (int)linegraph.getyAxisStep();
  920. if ((maxY % yStep) != 0) {
  921. maxY = maxY + (yStep - (maxY % yStep));
  922. }
  923. rangeMax_Y = rangeMin_Y + maxY;
  924. linegraph.setRangeY(rangeMin_Y, rangeMax_Y);
  925. linegraph.setLineToFill(0);
  926. linegraph.invalidate();
  927. }
  928. /**
  929. * Set the graph data to the given graph
  930. * @param BarGraph bargraph
  931. * */
  932. public void setBarGraphData(BarGraph bargraph){
  933. this.currentData = this.getBarData();
  934. if (this.currentData == null){
  935. this.currentData = new ArrayList<PlotComparisonItem>();
  936. }
  937. ArrayList<Bar> bars = new ArrayList<Bar>();
  938. for (PlotComparisonItem item : this.currentData){
  939. Bar d = new Bar();
  940. d.setColor(item.getColor());
  941. Long value2 = item.getValue2().longValue();
  942. d.setName("");
  943. d.setValue(value2.floatValue());
  944. bars.add(d);
  945. }
  946. barGraph.setBars(bars);
  947. barGraph.invalidate();
  948. }
  949. /*
  950. *
  951. * FETCH & ACTUALISE RECORD DATA
  952. *
  953. * */
  954. /**
  955. * Returns the DataBaseHandler result for the current filter.
  956. * @param ArrayList<Record> records
  957. */
  958. public ArrayList<Record> getFetchedRecords(){
  959. if (this.filter == null) this.clearFilter();
  960. return this.dbh.getRecordsForFilter(this.filter);
  961. }
  962. /**Actualises the current plot in a background thread.*/
  963. public void actualiseCurrentPlot(){
  964. this.spinner.setVisibility(View.VISIBLE);
  965. LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
  966. if (this.barGraph != null)
  967. this.barGraph.setVisibility(View.GONE);
  968. if (this.lineGraph != null)
  969. this.lineGraph.setVisibility(View.GONE);
  970. if (this.pieGraph != null)
  971. this.pieGraph.setVisibility(View.GONE);
  972. View plot = this.currentPlotView;
  973. if (plot == null){
  974. this.currentPlotView = this.getPieGraphView();
  975. plot = this.currentPlotView;
  976. }
  977. if (plot.getParent() != null && !plot.getParent().equals(plotLayout)){
  978. LinearLayout linLayout = (LinearLayout)plot.getParent();
  979. linLayout.removeView(plot);
  980. plot.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT ));
  981. plotLayout.addView(plot);
  982. }
  983. this.currentPlotView = plot;
  984. final LinearLayout thePlotlayout = plotLayout;
  985. if (this.loader != null && this.loader.isAlive()) this.loader.interrupt();
  986. this.loader = null;
  987. this.loader = new Thread(new Runnable() {
  988. @Override
  989. public void run() {
  990. this.loadDataInBackground();
  991. this.actualiseUI();
  992. }
  993. private void loadDataInBackground(){
  994. View plot = StatisticsFragment.this.currentPlotView;
  995. if (plot instanceof PieGraph){
  996. PieGraph pie = (PieGraph) plot;
  997. StatisticsFragment.this.setPieGraphData(pie);
  998. }
  999. if (plot instanceof BarGraph){
  1000. BarGraph bar = (BarGraph) plot;
  1001. StatisticsFragment.this.setBarGraphData(bar);
  1002. }
  1003. if (plot instanceof LineGraph){
  1004. LineGraph line = (LineGraph)plot;
  1005. StatisticsFragment.this.setLineGraphData(line);
  1006. }
  1007. }
  1008. private void actualiseUI(){
  1009. Activity actv = StatisticsFragment.this.getActivity();
  1010. if (actv != null){
  1011. actv.runOnUiThread(new Runnable() {
  1012. @Override
  1013. public void run() {
  1014. // SET VISIBILITY
  1015. View plot = StatisticsFragment.this.currentPlotView;
  1016. if (plot instanceof PieGraph){
  1017. // HIDE FILTER BUTTON
  1018. ImageButton filterButton = StatisticsFragment.this.getFilterButton();
  1019. if (filterButton != null) filterButton.setVisibility(View.GONE);
  1020. } else {
  1021. if (StatisticsFragment.this.pieGraph != null){
  1022. StatisticsFragment.this.pieGraph.setVisibility(View.GONE);
  1023. if (StatisticsFragment.this.pieGraph.getParent() != null){
  1024. thePlotlayout.removeView(StatisticsFragment.this.pieGraph);
  1025. }
  1026. }
  1027. // SHOW FILTER BUTTON
  1028. ImageButton filterButton = StatisticsFragment.this.getFilterButton();
  1029. if (filterButton != null) filterButton.setVisibility(View.VISIBLE);
  1030. }
  1031. if (! (plot instanceof BarGraph)){
  1032. if (StatisticsFragment.this.barGraph != null){
  1033. StatisticsFragment.this.barGraph.setVisibility(View.GONE);
  1034. if (StatisticsFragment.this.barGraph.getParent() != null){
  1035. thePlotlayout.removeView(StatisticsFragment.this.barGraph);
  1036. }
  1037. }
  1038. }
  1039. if (!(plot instanceof LineGraph)){
  1040. if (StatisticsFragment.this.lineGraph != null){
  1041. StatisticsFragment.this.lineGraph.setVisibility(View.GONE);
  1042. if (StatisticsFragment.this.lineGraph.getParent() != null){
  1043. thePlotlayout.removeView(StatisticsFragment.this.lineGraph);
  1044. }
  1045. }
  1046. }
  1047. plot.setVisibility(View.VISIBLE);
  1048. if (plot.getParent() == null){
  1049. thePlotlayout.addView(plot);
  1050. }
  1051. StatisticsFragment.this.actualiseLegendList();
  1052. StatisticsFragment.this.currentPlotView.bringToFront();
  1053. StatisticsFragment.this.currentPlotView.invalidate();
  1054. StatisticsFragment.this.spinner.setVisibility(View.GONE);
  1055. }
  1056. });
  1057. }
  1058. }
  1059. });
  1060. this.loader.start();
  1061. }
  1062. /** Calculates and returns the data for the piegraph
  1063. * @return ArrayList<PlotComparisonItem> data */
  1064. public ArrayList<PlotComparisonItem> getPieData(){
  1065. // DEFAULT
  1066. return this.attacksPerProtocols();
  1067. }
  1068. /** Calculates and returns the data for the bargraph.
  1069. * @return ArrayList<PlotComparisonItem> data */
  1070. public ArrayList<PlotComparisonItem> getBarData(){
  1071. String protocol = this.getCurrentSelectedProtocol();
  1072. if (protocol.length() > 0){
  1073. if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)){
  1074. return this.attacksPerESSID(protocol);
  1075. }
  1076. // DEFAULT
  1077. return this.attacksPerBSSID(protocol);
  1078. }
  1079. // Nothing available
  1080. return new ArrayList<PlotComparisonItem>();
  1081. }
  1082. /** Calculates and returns the data for the linegraph
  1083. * @return ArrayList<PlotComparisonItem> data */
  1084. public ArrayList<PlotComparisonItem> getLineData(){
  1085. return this.attacksPerTime();
  1086. }
  1087. /*
  1088. * DATA SOURCE
  1089. * */
  1090. /*PROTOCOLS OVERVIEW*/
  1091. /**
  1092. * Returns the attacks per protocols comparison result.
  1093. * The returned data is resized to the specified limit.
  1094. * @return ArrayList<PlotComparisonItem>
  1095. */
  1096. public ArrayList<PlotComparisonItem> attacksPerProtocols(){
  1097. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  1098. int index = 0;
  1099. for (String title : this.getSelectedProtocolTitles()){
  1100. int attacksCount = this.dbh.getAttackPerProtocolCount(title);
  1101. if (attacksCount == 0) continue;
  1102. PlotComparisonItem item = new PlotComparisonItem(title,this.getColor(index), 0., (double) attacksCount);
  1103. plotItems.add(item);
  1104. index++;
  1105. }
  1106. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  1107. @Override
  1108. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  1109. return s2.getValue2().compareTo(s1.getValue2());
  1110. }
  1111. });
  1112. return this.resizeData(plotItems);
  1113. }
  1114. /*
  1115. * LINE PLOT DATA
  1116. */
  1117. /**Returns the line graph data responding to the selectedCompareData key.
  1118. * The returned data is resized to the specified limit.
  1119. * @return ArrayList<PlotComparisonItem attacksPerTime or attacksPerDate*/
  1120. public ArrayList<PlotComparisonItem> attacksPerTime(){
  1121. HashMap<String,HashMap<Long, ArrayList<Record> > > lineMap = new HashMap<String, HashMap<Long, ArrayList<Record>>>();
  1122. boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
  1123. ArrayList<Record> records = this.getFetchedRecords();
  1124. for (Record record : records){
  1125. long timestamp = record.getTimestamp();
  1126. long time = 0;
  1127. if (shouldUseDate){
  1128. time = this.getDateFromMilliseconds(timestamp);
  1129. } else {
  1130. time = this.getDayHourFromDate(timestamp);
  1131. }
  1132. // GET CORRECT MAP
  1133. HashMap<Long, ArrayList<Record> > recordMap;
  1134. String groupKey = record.getSsid();
  1135. if (lineMap.containsKey(groupKey)){
  1136. recordMap = lineMap.get(record.getSsid());
  1137. } else {
  1138. recordMap = new HashMap<Long, ArrayList<Record> >();
  1139. lineMap.put(groupKey, recordMap);
  1140. }
  1141. // GET LIST OF RECORDS
  1142. ArrayList<Record> list;
  1143. if (recordMap.containsKey(time)){
  1144. list = recordMap.get(time);
  1145. } else {
  1146. list = new ArrayList<Record>();
  1147. recordMap.put(time, list);
  1148. }
  1149. list.add(record);
  1150. }
  1151. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  1152. int index = 0;
  1153. for (String groupKey : lineMap.keySet()){
  1154. HashMap<Long, ArrayList<Record> > recordMap = lineMap.get(groupKey);
  1155. ArrayList<PlotComparisonItem> singleLineItems = new ArrayList<PlotComparisonItem>();
  1156. int numbOfAttacks = 0;
  1157. for (long time : recordMap.keySet()){
  1158. ArrayList<Record>list = recordMap.get(time);
  1159. if (list.size() == 0) continue;
  1160. PlotComparisonItem item = new PlotComparisonItem(this.getHourAsTimeString(time), 0 , (double)time, (double) list.size());
  1161. singleLineItems.add(item);
  1162. numbOfAttacks +=list.size();
  1163. }
  1164. Collections.sort(singleLineItems, new Comparator<PlotComparisonItem>() {
  1165. @Override
  1166. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  1167. return s1.getValue1().compareTo(s2.getValue1());
  1168. }
  1169. });
  1170. double itemValue = (((double)numbOfAttacks / (double)records.size())*100.);
  1171. PlotComparisonItem item = new PlotComparisonItem(groupKey, this.getColor(index), (double) numbOfAttacks, itemValue);
  1172. item.setOtherData(singleLineItems);
  1173. plotItems.add(item);
  1174. index++;
  1175. }
  1176. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  1177. @Override
  1178. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  1179. return s2.getValue2().compareTo(s1.getValue2());
  1180. }
  1181. });
  1182. return plotItems;
  1183. }
  1184. /*
  1185. * BAR PLOT DATA
  1186. */
  1187. /**Returns plotitems for the comparison "attacks per bssid"
  1188. * The returned data is resized to the specified limit.
  1189. * @return ArrayList<PlotComparisonItem> the data
  1190. */
  1191. public ArrayList<PlotComparisonItem> attacksPerBSSID(String protocol){
  1192. LogFilter filter = new LogFilter();
  1193. ArrayList<String> protocollist = new ArrayList<String>();
  1194. filter.setAboveTimestamp(this.filter.getAboveTimestamp());
  1195. filter.setBelowTimestamp(this.filter.getBelowTimestamp());
  1196. filter.setBSSIDs(this.filter.getBSSIDs());
  1197. protocollist.add(protocol);
  1198. filter.setProtocols(protocollist);
  1199. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  1200. HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
  1201. ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
  1202. for (Record record : records){
  1203. int count = 0;
  1204. if (recordMap.containsKey(record.getBssid())){
  1205. count = recordMap.get(record.getBssid());
  1206. }
  1207. count++;
  1208. recordMap.put(record.getBssid(), count);
  1209. }
  1210. int index = 0;
  1211. for (String key : recordMap.keySet()){
  1212. double value = (double)recordMap.get(key);
  1213. if (value == 0.) continue;
  1214. PlotComparisonItem item = new PlotComparisonItem(key, this.getColor(index), 0., value);
  1215. plotItems.add(item);
  1216. index++;
  1217. }
  1218. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  1219. @Override
  1220. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  1221. return s2.getValue2().compareTo(s1.getValue2());
  1222. }
  1223. });
  1224. return this.resizeData(plotItems);
  1225. }
  1226. /**Returns plotitems for the comparison "attacks per essid"
  1227. * @return ArrayList<PlotComparisonItem> the data
  1228. */
  1229. public ArrayList<PlotComparisonItem> attacksPerESSID(String protocol){
  1230. LogFilter filter = new LogFilter();
  1231. filter.setAboveTimestamp(this.filter.getAboveTimestamp());
  1232. filter.setBelowTimestamp(this.filter.getBelowTimestamp());
  1233. filter.setESSIDs(this.filter.getESSIDs());
  1234. ArrayList<String> protocollist = new ArrayList<String>();
  1235. protocollist.add(protocol);
  1236. filter.setProtocols(protocollist);
  1237. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  1238. HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
  1239. ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
  1240. for (Record record : records){
  1241. int count = 0;
  1242. if (recordMap.containsKey(record.getSsid())){
  1243. count = recordMap.get(record.getSsid());
  1244. }
  1245. count++;
  1246. recordMap.put(record.getSsid(), count);
  1247. }
  1248. int index = 0;
  1249. for (String key : recordMap.keySet()){
  1250. double value = (double)recordMap.get(key);
  1251. if (value == 0.) continue;
  1252. PlotComparisonItem item = new PlotComparisonItem(key,this.getColor(index), 0. ,value);
  1253. plotItems.add(item);
  1254. index++;
  1255. }
  1256. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  1257. @Override
  1258. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  1259. return s2.getValue2().compareTo(s1.getValue2());
  1260. }
  1261. });
  1262. return this.resizeData(plotItems);
  1263. }
  1264. /**
  1265. * This will normalize the given list of plot items to the specified length of MAX_NUMBER_OF_CHART_OBJECTS.
  1266. * Creates an "others" group, containing all objects after the (MAX_NUMBER_OF_CHART_OBJECTS - 1)th object from the given list.
  1267. * If the given list does contain MAX_NUMBER_OF_CHART_OBJECTS+1 or more objects, nothing will change.
  1268. *
  1269. * @param AtrrayList<PlotComparisonItem> the list to normalize
  1270. * @return ArrayList<PlotComparisonItem> the normalized data
  1271. */
  1272. private ArrayList<PlotComparisonItem> resizeData(ArrayList<PlotComparisonItem> plotItems){
  1273. if (plotItems != null){
  1274. if (plotItems.size() > MAX_NUMBER_OF_CHART_OBJECTS && MAX_NUMBER_OF_CHART_OBJECTS > 1){
  1275. ArrayList<PlotComparisonItem> copy = new ArrayList<PlotComparisonItem>();
  1276. ArrayList<PlotComparisonItem> others = new ArrayList<PlotComparisonItem>();
  1277. double valueOfOthers = 0;
  1278. for (int i = 0; i < plotItems.size(); i++){
  1279. if (i < MAX_NUMBER_OF_CHART_OBJECTS - 1){
  1280. PlotComparisonItem item = plotItems.get(i);
  1281. item.setColor(this.getColor(i));
  1282. copy.add(plotItems.get(i));
  1283. } else {
  1284. PlotComparisonItem item = plotItems.get(i);
  1285. others.add(item);
  1286. valueOfOthers+=item.getValue2();
  1287. }
  1288. }
  1289. PlotComparisonItem otherItem = new PlotComparisonItem(OTHER_CHART_TITLE, this.getOtherColor(), 0., valueOfOthers);
  1290. otherItem.setOtherData(others);
  1291. copy.add(otherItem);
  1292. Collections.sort(copy, new Comparator<PlotComparisonItem>() {
  1293. @Override
  1294. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  1295. return s2.getValue2().compareTo(s1.getValue2());
  1296. }
  1297. });
  1298. return copy;
  1299. }
  1300. }
  1301. return plotItems;
  1302. }
  1303. /*
  1304. * FILTER STUFF
  1305. * */
  1306. /**
  1307. * Returns the first selected protocol from all selected protocols.
  1308. * If no protocol is selected, it return the first protocol in the protocolTitles() list.
  1309. * @return String protocolName
  1310. * */
  1311. private String getCurrentSelectedProtocol(){
  1312. ArrayList<String> protocolTitles = this.getSelectedProtocolTitles();
  1313. if (protocolTitles != null && protocolTitles.size() != 0){
  1314. return protocolTitles.get(0);
  1315. }
  1316. return this.protocolTitles().get(0);
  1317. }
  1318. /**
  1319. * Return all Protocols
  1320. *
  1321. * @return ArrayList<String> protocolNames
  1322. * */
  1323. public ArrayList<String> protocolTitles(){
  1324. ArrayList<String> titles = new ArrayList<String>();
  1325. for (String protocol : this.getResources().getStringArray(
  1326. R.array.protocols)) {
  1327. titles.add(protocol);
  1328. }
  1329. return titles;
  1330. }
  1331. /**
  1332. * Returns a boolean array containing a bool value for each protocol. If the value is true, the filter object contains the protocol.
  1333. * The array sequence equates to the protocolTitles() list.
  1334. * @return boolean[] selection array
  1335. * */
  1336. public boolean[] selectedProtocols(){
  1337. ArrayList<String> protocols = this.protocolTitles();
  1338. boolean[] selected = new boolean[protocols.size()];
  1339. int i = 0;
  1340. for(String protocol : protocols){
  1341. selected[i] =(this.filter.protocols.contains(protocol));
  1342. i++;
  1343. }
  1344. return selected;
  1345. }
  1346. public ArrayList<String> getSelectedProtocolTitles(){
  1347. ArrayList<String> knownProtocols = this.protocolTitles();
  1348. if (this.filter.hasProtocols()){
  1349. ArrayList<String> titles = new ArrayList<String>();
  1350. int i =0;
  1351. for (boolean b : this.selectedProtocols()){
  1352. if (b){
  1353. String title = knownProtocols.get(i);
  1354. titles.add(title);
  1355. }
  1356. i++;
  1357. }
  1358. return titles;
  1359. }
  1360. return this.protocolTitles();
  1361. }
  1362. /*
  1363. *
  1364. * COLOR STUFF
  1365. *
  1366. * */
  1367. /** Returns the color for the other group
  1368. * @return int color*/
  1369. public int getOtherColor(){
  1370. return Color.argb(255, 80, 80, 80); // grey
  1371. }
  1372. /** Returns the color for the given index
  1373. * @return int color*/
  1374. public Integer getColor(int index) {
  1375. return ColorSequenceGenerator.getColorForIndex(index);
  1376. }
  1377. /** Returns the Plot layout.
  1378. *
  1379. * @return LinearLayout plot layout
  1380. */
  1381. public LinearLayout getPlotLayout(){
  1382. if (this.rootView != null){
  1383. return (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
  1384. } else {
  1385. return null;
  1386. }
  1387. }
  1388. /*
  1389. *
  1390. * FILTER STUFF
  1391. *
  1392. * */
  1393. /**
  1394. * Returns true if the current filter is set for a given filter menu title.
  1395. * @param String filter menu title
  1396. * @return boolean b
  1397. */
  1398. private boolean isFilterSetForTitle(String title){
  1399. if (title.equals(FILTER_MENU_TITLE_BSSID)){
  1400. return this.filter.hasBSSIDs();
  1401. }
  1402. if (title.equals(FILTER_MENU_TITLE_ESSID)){
  1403. return this.filter.hasESSIDs();
  1404. }
  1405. if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  1406. return (this.filter.getProtocols() != null && this.filter.hasProtocols() && this.filter.getProtocols().size() != this.protocolTitles().size());
  1407. }
  1408. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  1409. return this.filter.hasBelowTimestamp();
  1410. }
  1411. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  1412. return this.filter.hasAboveTimestamp();
  1413. }
  1414. return false;
  1415. }
  1416. /**
  1417. * Clears the current filter.
  1418. */
  1419. private void clearFilter(){
  1420. if(filter == null) this.filter = new LogFilter();
  1421. this.filter.clear();
  1422. }
  1423. /*
  1424. *
  1425. * DATE TRANSFORMATION
  1426. *
  1427. */
  1428. /**
  1429. * Returns the current hour from a date.
  1430. * @param timeInMillis
  1431. * @return
  1432. */
  1433. public long getDayHourFromDate(long timeInMillis){
  1434. Calendar calendar = Calendar.getInstance();
  1435. calendar.setTimeInMillis (timeInMillis);
  1436. int hour = calendar.get(Calendar.HOUR_OF_DAY);
  1437. int min = calendar.get(Calendar.MINUTE);
  1438. return hour;
  1439. }
  1440. /**
  1441. * Returns the current date without the seconds, minutes, hours.
  1442. * @param long date
  1443. * @return long date with time 00:00:00
  1444. * */
  1445. public long getDateFromMilliseconds(long timeInMillis){
  1446. long millisInDay = 60 * 60 * 24 * 1000;
  1447. return (timeInMillis / millisInDay) * millisInDay;
  1448. }
  1449. /**
  1450. * Returns the given hour as a formated string.
  1451. *
  1452. * */
  1453. private String getHourAsTimeString(long hour) {
  1454. return "" + hour + ":00";
  1455. }
  1456. static final DateFormat dateFormat = new SimpleDateFormat("d.M.yy");
  1457. /**Returns a date as a formated string
  1458. * @param long date
  1459. * @return String date format (d.M.yy)*/
  1460. @SuppressLint("SimpleDateFormat")
  1461. private String getDateAsDayString(long timeStamp) {
  1462. try {
  1463. Date netDate = (new Date(timeStamp));
  1464. return dateFormat.format(netDate);
  1465. } catch (Exception ex) {
  1466. return "xx";
  1467. }
  1468. }
  1469. @SuppressLint("SimpleDateFormat")
  1470. /**Returns a date as a formated string
  1471. * @param long date
  1472. * @return String date format (H:mm dd/MM/yyyy)*/
  1473. private String getDateAsString(long timeStamp) {
  1474. try {
  1475. DateFormat sdf = new SimpleDateFormat("H:mm dd/MM/yyyy");
  1476. Date netDate = (new Date(timeStamp));
  1477. return sdf.format(netDate);
  1478. } catch (Exception ex) {
  1479. return "xx";
  1480. }
  1481. }
  1482. /**
  1483. * USERINTERACTION
  1484. */
  1485. /**
  1486. * Will be called if the users taps on a list row.
  1487. * @param int index
  1488. */
  1489. private void userTappedOnLegendItem(int index){
  1490. if (index < this.currentData.size()){
  1491. PlotComparisonItem item = this.currentData.get(index);
  1492. ArrayList<String> selectedData;
  1493. String sortKey = null;
  1494. selectedData = new ArrayList<String>();
  1495. if (item.getOtherData() == null){
  1496. selectedData.add(item.getTitle());
  1497. } else {
  1498. for (PlotComparisonItem other : item.getOtherData()){
  1499. selectedData.add(other.getTitle());
  1500. }
  1501. }
  1502. LogFilter filter = new LogFilter();
  1503. if (this.currentPlotView instanceof PieGraph){
  1504. filter.setProtocols(selectedData);
  1505. }
  1506. if (this.currentPlotView instanceof BarGraph){
  1507. if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)){
  1508. filter.setESSIDs(selectedData);
  1509. sortKey = "ESSID";
  1510. } else {
  1511. filter.setBSSIDs(selectedData);
  1512. sortKey = "BSSID";
  1513. }
  1514. ArrayList<String> currentSelectedProtocol = new ArrayList<String>();
  1515. currentSelectedProtocol.add(this.getCurrentSelectedProtocol());
  1516. filter.setProtocols(currentSelectedProtocol);
  1517. }
  1518. if (this.currentPlotView instanceof LineGraph){
  1519. selectedData = new ArrayList<String>();
  1520. selectedData.add(item.getTitle());
  1521. filter.setESSIDs(selectedData);
  1522. filter.setProtocols(this.filter.getProtocols());
  1523. sortKey = "ESSID";
  1524. }
  1525. if (this.filter.hasATimestamp()){
  1526. filter.setAboveTimestamp(this.filter.getAboveTimestamp());
  1527. filter.setBelowTimestamp(this.filter.getBelowTimestamp());
  1528. }
  1529. this.pushRecordOverviewForFilter(filter, sortKey);
  1530. }
  1531. }
  1532. /**Will be called if the user clicked on a slice
  1533. * @param int slice index*/
  1534. public void onSliceClick(int index){
  1535. }
  1536. /**Will be called if the user clicked on a bar
  1537. * @param int bar index*/
  1538. public void onBarClick(int index){
  1539. this.userTappedOnLegendItem(index);
  1540. }
  1541. /**
  1542. * Displays a record over view fragment.
  1543. * @param LogFilter filter
  1544. * @param String sortKey
  1545. */
  1546. private void pushRecordOverviewForFilter(LogFilter filter, String sortKey){
  1547. FragmentManager fm = this.getActivity().getFragmentManager();
  1548. if (fm != null){
  1549. RecordOverviewFragment newFragment = new RecordOverviewFragment();
  1550. newFragment.setUpNavigatible(true);
  1551. newFragment.setFilter(filter);
  1552. if (sortKey != null && sortKey.length() != 0) newFragment.setGroupKey(sortKey);
  1553. MainActivity.getInstance().injectFragment(newFragment);
  1554. }
  1555. }
  1556. }