StatisticsFragment.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. package de.tudarmstadt.informatik.hostage.ui2.fragment;
  2. import android.annotation.SuppressLint;
  3. import android.app.Fragment;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.graphics.Color;
  7. import android.os.Bundle;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.LinearLayout;
  12. import com.echo.holographlibrary.Bar;
  13. import com.echo.holographlibrary.BarGraph;
  14. import com.echo.holographlibrary.Line;
  15. import com.echo.holographlibrary.LineGraph;
  16. import com.echo.holographlibrary.LinePoint;
  17. import com.echo.holographlibrary.PieGraph;
  18. import com.echo.holographlibrary.PieSlice;
  19. import java.text.DateFormat;
  20. import java.text.SimpleDateFormat;
  21. import java.util.ArrayList;
  22. import java.util.Calendar;
  23. import java.util.Collections;
  24. import java.util.Comparator;
  25. import java.util.Date;
  26. import java.util.HashMap;
  27. import de.tudarmstadt.informatik.hostage.R;
  28. import de.tudarmstadt.informatik.hostage.logging.Record;
  29. import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
  30. import de.tudarmstadt.informatik.hostage.ui.LogFilter;
  31. import de.tudarmstadt.informatik.hostage.ui2.model.PlotComparisonItem;
  32. /**
  33. * Created by Julien on 16.02.14.
  34. */
  35. public class StatisticsFragment extends Fragment {
  36. static final String SELECTED_KEY = "Selected";
  37. static final String OTHERS_KEY = "Other";
  38. static final String FILTER_MENU_TITLE_BSSID = "BSSID";
  39. static final String FILTER_MENU_TITLE_ESSID = "ESSID";
  40. static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocol";
  41. static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = "Latest";
  42. static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = "Earliest";
  43. static final String FILTER_MENU_TITLE_SORTING = "Sort by";
  44. static final String FILTER_MENU_TITLE_REMOVE = "Reset Filter";
  45. static final String FILTER_MENU_TITLE_GROUP = "Group by";
  46. static final String FILTER_MENU_POPUP_TITLE = "Filter by";
  47. static final String CHART_TYPE_TITLE_BAR = "Bar Plot";
  48. static final String CHART_TYPE_TITLE_PIE = "Pie Plot";
  49. static final String CHART_TYPE_TITLE_LINE = "Line Plot";
  50. static final String OTHER_CHART_TITLE = "Other";
  51. // MINIMAL 2
  52. static int MAX_NUMBER_OF_CHART_OBJECTS = 5;
  53. private boolean wasBelowTimePicker;
  54. private LogFilter filter;
  55. private boolean showFilterButton;
  56. private PieGraph pieGraph;
  57. private LineGraph lineGraph;
  58. private BarGraph barGraph;
  59. private View rootView;
  60. private View currentPlotView;
  61. private ArrayList<Integer> colorList;
  62. private ArrayList<PlotComparisonItem> currentData;
  63. private UglyDbHelper dbh;
  64. public enum ChartType {
  65. PIE_CHART(0),
  66. BAR_CHART(1),
  67. LINE_CHART(2);
  68. private int value;
  69. private ChartType(int value) {
  70. this.value = value;
  71. }
  72. static public ChartType create(int value){
  73. if (value < 0 || value >= ChartType.values().length) return ChartType.PIE_CHART;
  74. return ChartType.values()[value];
  75. }
  76. public String toString(){
  77. if (this.equals(ChartType.create(0))){
  78. return CHART_TYPE_TITLE_PIE;
  79. }
  80. if (this.equals(ChartType.create(1))){
  81. return CHART_TYPE_TITLE_BAR;
  82. }
  83. return CHART_TYPE_TITLE_LINE;
  84. }
  85. }
  86. @Override
  87. public void onCreate(Bundle savedInstanceState) {
  88. super.onCreate(savedInstanceState);
  89. setHasOptionsMenu(true);
  90. }
  91. public int getLayoutID(){
  92. return R.layout.fragment_statistics;
  93. }
  94. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  95. Bundle savedInstanceState) {
  96. dbh = new UglyDbHelper(this.getBaseContext());
  97. // Get the message from the intent
  98. if (this.filter == null){
  99. Intent intent = this.getActivity().getIntent();
  100. LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
  101. if(filter == null){
  102. this.clearFilter();
  103. } else {
  104. this.filter = filter;
  105. }
  106. }
  107. View rootView = inflater.inflate(this.getLayoutID(), container, false);
  108. this.rootView = rootView;
  109. this.configureRootView(rootView);
  110. return rootView;
  111. }
  112. private Context getBaseContext(){
  113. return this.getActivity().getBaseContext();
  114. }
  115. private Context getApplicationContext(){
  116. return this.getActivity().getApplicationContext();
  117. }
  118. public void configureRootView(View rootView){
  119. this.setChartType(ChartType.PIE_CHART);
  120. }
  121. public void setChartType(ChartType type){
  122. boolean shouldChange = true;
  123. if (this.currentPlotView != null){
  124. if (type == ChartType.PIE_CHART){
  125. shouldChange = ! (this.currentPlotView instanceof PieGraph);
  126. }
  127. if (type == ChartType.LINE_CHART){
  128. shouldChange = ! (this.currentPlotView instanceof LineGraph);
  129. }
  130. if (type == ChartType.BAR_CHART){
  131. shouldChange = ! (this.currentPlotView instanceof BarGraph);
  132. }
  133. }
  134. if (shouldChange){
  135. LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
  136. this.currentPlotView = this.getPlotViewForType(type);
  137. plotLayout.addView(this.currentPlotView);
  138. this.actualiseCurrentPlot();
  139. }
  140. }
  141. public View getPlotViewForType(ChartType type){
  142. switch (type){
  143. case PIE_CHART:
  144. return this.getPieGraphView();
  145. case LINE_CHART:
  146. return this.getLineGraphView();
  147. default:
  148. return this.getBarGraphView();
  149. }
  150. }
  151. /**
  152. *
  153. * PLOT TOUCH HANDLING
  154. *
  155. * */
  156. public void onSliceClick(int index){
  157. }
  158. public void onBarClick(int index){
  159. }
  160. /*
  161. *
  162. * PLOT TYPES
  163. *
  164. * **/
  165. public PieGraph getPieGraphView(){
  166. if (this.pieGraph == null) {
  167. this.pieGraph = new PieGraph(this.getApplicationContext());
  168. this.pieGraph.setOnSliceClickedListener(new PieGraph.OnSliceClickedListener() {
  169. @Override
  170. public void onClick(int index) {
  171. StatisticsFragment.this.onSliceClick(index);
  172. }
  173. });
  174. }
  175. /*
  176. * ACTUALISE INPUT DATA
  177. * */
  178. this.setPieGraphData(this.pieGraph);
  179. return this.pieGraph;
  180. }
  181. public LineGraph getLineGraphView(){
  182. if (this.lineGraph == null) {
  183. this.lineGraph = new LineGraph(this.getApplicationContext());
  184. }
  185. this.setLineGraphData(this.lineGraph);
  186. return this.lineGraph;
  187. }
  188. public BarGraph getBarGraphView(){
  189. if (this.barGraph == null) {
  190. this.barGraph = new BarGraph(this.getApplicationContext());
  191. this.barGraph.setPopupImageID(R.drawable.popup_black);
  192. this.barGraph.setOnBarClickedListener(new BarGraph.OnBarClickedListener() {
  193. @Override
  194. public void onClick(int i) {
  195. StatisticsFragment.this.onBarClick(i);
  196. }
  197. });
  198. }
  199. this.setBarGraphData(this.barGraph);
  200. return this.barGraph;
  201. }
  202. /*
  203. * FEED PLOTS WITH DATA
  204. * */
  205. public void setPieGraphData(PieGraph piegraph){
  206. this.currentData = this.getPieData();
  207. if (this.currentData == null){
  208. this.currentData = new ArrayList<PlotComparisonItem>();
  209. }
  210. this.pieGraph.removeSlices();
  211. for (PlotComparisonItem item : this.currentData){
  212. PieSlice slice = new PieSlice();
  213. slice.setColor(item.getColor());
  214. Double value2 = (Double) item.getValue2();
  215. slice.setValue(value2.floatValue());
  216. slice.setTitle(item.getTitle());
  217. this.pieGraph.addSlice(slice);
  218. }
  219. this.pieGraph.invalidate();
  220. }
  221. public void setLineGraphData(LineGraph linegraph){
  222. this.currentData = this.getLinedata();
  223. if (this.currentData == null){
  224. this.currentData = new ArrayList<PlotComparisonItem>();
  225. }
  226. int index = 0;
  227. this.lineGraph.removeAllLines();
  228. Line l = new Line();
  229. for (PlotComparisonItem item : this.currentData){
  230. LinePoint p = new LinePoint();
  231. p.setX(index);
  232. Double value2 = (Double) item.getValue2();
  233. p.setY(value2.floatValue());
  234. index++;
  235. }
  236. this.lineGraph.addLine(l);
  237. this.lineGraph.setRangeY(0, index);
  238. this.lineGraph.setLineToFill(0);
  239. this.lineGraph.invalidate();
  240. }
  241. public void setBarGraphData(BarGraph bargraph){
  242. this.currentData = this.getLinedata();
  243. if (this.currentData == null){
  244. this.currentData = new ArrayList<PlotComparisonItem>();
  245. }
  246. ArrayList<Bar> bars = new ArrayList<Bar>();
  247. for (PlotComparisonItem item : this.currentData){
  248. Bar d = new Bar();
  249. d.setColor(item.getColor());
  250. d.setName(item.getTitle());
  251. Double value2 = (Double) item.getValue2();
  252. d.setValue(value2.floatValue());
  253. }
  254. this.barGraph.setBars(bars);
  255. this.barGraph.invalidate();
  256. }
  257. /*
  258. *
  259. * FETCH & ACTUALISE RECORD DATA
  260. *
  261. * */
  262. public ArrayList<Record> getFetchedRecords(){
  263. if (this.filter == null) this.clearFilter();
  264. return this.dbh.getRecordsForFilter(this.filter);
  265. }
  266. public void actualiseCurrentPlot(){
  267. View plot = this.currentPlotView;
  268. if (plot == null){
  269. if (this.pieGraph == null){
  270. this.currentPlotView = this.getPieGraphView();
  271. // AVOID RELOADING THE DATA ON INITIAL LOAD
  272. return;
  273. }
  274. this.currentPlotView = this.getPieGraphView();
  275. return;
  276. }
  277. if (plot instanceof PieGraph){
  278. this.setPieGraphData((PieGraph)plot);
  279. }
  280. if (plot instanceof BarGraph){
  281. this.setBarGraphData((BarGraph) plot);
  282. }
  283. if (plot instanceof LineGraph){
  284. this.setLineGraphData((LineGraph) plot);
  285. }
  286. }
  287. public ArrayList<PlotComparisonItem> getPieData(){
  288. // DEFAULT
  289. return this.attacksPerProtocols();
  290. }
  291. public ArrayList<PlotComparisonItem> getBarData(){
  292. ArrayList<String> protocolTitles = this.getSelectedProtocolTitles();
  293. // DEFAULT
  294. if (protocolTitles != null && protocolTitles.size() != 0){
  295. String protocol = this.getSelectedProtocolTitles().get(0);
  296. return this.attacksPerBSSID(protocol);
  297. }
  298. // Nothing available
  299. return new ArrayList<PlotComparisonItem>();
  300. }
  301. public ArrayList<PlotComparisonItem> getLinedata(){
  302. // DEFAULT
  303. return this.attacksPerDate();
  304. }
  305. /*
  306. * SPECIFIC DATA STUFF
  307. * */
  308. /*PROTOCOLS OVERVIEW*/
  309. public ArrayList<PlotComparisonItem> attacksPerProtocols(){
  310. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  311. int index = 0;
  312. for (String title : this.getSelectedProtocolTitles()){
  313. int attacksCount = this.dbh.getAttackPerProtocolCount(title);
  314. PlotComparisonItem item = new PlotComparisonItem(title,this.getColor(index), 0., (double) attacksCount);
  315. plotItems.add(item);
  316. index++;
  317. }
  318. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  319. @Override
  320. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  321. return s1.getValue2().compareTo(s2.getValue2());
  322. }
  323. });
  324. return this.resizeData(plotItems);
  325. }
  326. public ArrayList<PlotComparisonItem> usesPerProtocol(){
  327. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  328. for (String title : this.getSelectedProtocolTitles()){
  329. /*At the moment there is no possibillity to get the number of uses for each protocol*/
  330. }
  331. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  332. @Override
  333. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  334. return s1.getTitle().compareToIgnoreCase(s2.getTitle());
  335. }
  336. });
  337. return plotItems;
  338. }
  339. /*LINE PLOT DATA*/
  340. public ArrayList<PlotComparisonItem> attacksPerDate(){
  341. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  342. HashMap<Long, ArrayList<Record> > recordMap = new HashMap<Long, ArrayList<Record> >();
  343. for (Record record : this.getFetchedRecords()){
  344. long date = this.getdateFromMilliseconds(record.getTimestamp());
  345. ArrayList<Record> list = recordMap.get(date);
  346. if (list == null){
  347. list = new ArrayList<Record>();
  348. recordMap.put(date, list);
  349. }
  350. list.add(record);
  351. }
  352. int index = 0;
  353. for (long date : recordMap.keySet()){
  354. ArrayList<Record> list = recordMap.get(date);
  355. PlotComparisonItem item = new PlotComparisonItem(this.getDateAsDayString(date),this.getColor(index), (double) date, (double)list.size());
  356. plotItems.add(item);
  357. index++;
  358. }
  359. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  360. @Override
  361. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  362. return s1.getValue1().compareTo(s2.getValue1());
  363. }
  364. });
  365. return plotItems;
  366. }
  367. public ArrayList<PlotComparisonItem> attacksPerTime(){
  368. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  369. HashMap<Long, ArrayList<Record> > recordMap = new HashMap<Long, ArrayList<Record> >();
  370. for (Record record : this.getFetchedRecords()){
  371. long date = this.getDayHourFromDate(record.getTimestamp());
  372. ArrayList<Record> list = recordMap.get(date);
  373. if (list == null){
  374. list = new ArrayList<Record>();
  375. recordMap.put(date, list);
  376. }
  377. list.add(record);
  378. }
  379. int index = 0;
  380. for (long time : recordMap.keySet()){
  381. ArrayList<Record> list = recordMap.get(time);
  382. PlotComparisonItem item = new PlotComparisonItem(this.getDateAsTimeString(time), this.getColor(index) , (double)time, (double) list.size());
  383. plotItems.add(item);
  384. index++;
  385. }
  386. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  387. @Override
  388. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  389. return s1.getValue1().compareTo(s2.getValue1());
  390. }
  391. });
  392. return plotItems;
  393. }
  394. // BAR PLOT DATA
  395. public ArrayList<PlotComparisonItem> attacksPerBSSID(String protocol){
  396. LogFilter filter = new LogFilter();
  397. ArrayList<String> protocollist = new ArrayList<String>();
  398. protocollist.add(protocol);
  399. filter.setProtocols(protocollist);
  400. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  401. HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
  402. ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
  403. for (Record record : records){
  404. int count = recordMap.get(record.getBssid());
  405. count++;
  406. recordMap.put(record.getBssid(), count);
  407. }
  408. int index = 0;
  409. for (String key : recordMap.keySet()){
  410. PlotComparisonItem item = new PlotComparisonItem(key, this.getColor(index), 0., (double)recordMap.get(key));
  411. plotItems.add(item);
  412. index++;
  413. }
  414. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  415. @Override
  416. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  417. return s1.getValue2().compareTo(s2.getValue2());
  418. }
  419. });
  420. return this.resizeData(plotItems);
  421. }
  422. public ArrayList<PlotComparisonItem> attacksPerESSID(String protocol){
  423. LogFilter filter = new LogFilter();
  424. ArrayList<String> protocollist = new ArrayList<String>();
  425. protocollist.add(protocol);
  426. filter.setProtocols(protocollist);
  427. ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
  428. HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
  429. ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
  430. for (Record record : records){
  431. int count = recordMap.get(record.getSsid());
  432. count++;
  433. recordMap.put(record.getSsid(), count);
  434. }
  435. int index = 0;
  436. for (String key : recordMap.keySet()){
  437. PlotComparisonItem item = new PlotComparisonItem(key,this.getColor(index), 0. , (double)recordMap.get(key));
  438. plotItems.add(item);
  439. index++;
  440. }
  441. Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
  442. @Override
  443. public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
  444. return s1.getValue2().compareTo(s2.getValue2());
  445. }
  446. });
  447. return this.resizeData(plotItems);
  448. }
  449. private ArrayList<PlotComparisonItem> resizeData(ArrayList<PlotComparisonItem> plotItems){
  450. if (plotItems != null){
  451. if (plotItems.size() > MAX_NUMBER_OF_CHART_OBJECTS && MAX_NUMBER_OF_CHART_OBJECTS > 1){
  452. ArrayList<PlotComparisonItem> copy = new ArrayList<PlotComparisonItem>();
  453. ArrayList<PlotComparisonItem> others = new ArrayList<PlotComparisonItem>();
  454. double valueOfOthers = 0;
  455. for (int i = 0; i < plotItems.size(); i++){
  456. if (i < MAX_NUMBER_OF_CHART_OBJECTS - 1){
  457. copy.add(plotItems.get(i));
  458. } else {
  459. PlotComparisonItem item = plotItems.get(i);
  460. others.add(item);
  461. valueOfOthers+=item.getValue2();
  462. }
  463. }
  464. PlotComparisonItem otherItem = new PlotComparisonItem(OTHER_CHART_TITLE, this.getOtherColor(), 0., valueOfOthers);
  465. copy.add(otherItem);
  466. return copy;
  467. }
  468. }
  469. return plotItems;
  470. }
  471. /*
  472. * FILTER STUFF
  473. * */
  474. public ArrayList<String> protocolTitles(){
  475. ArrayList<String> titles = new ArrayList<String>();
  476. for (String protocol : this.getResources().getStringArray(
  477. R.array.protocols)) {
  478. titles.add(protocol);
  479. }
  480. return titles;
  481. }
  482. public boolean[] selectedProtocols(){
  483. ArrayList<String> protocols = this.protocolTitles();
  484. boolean[] selected = new boolean[protocols.size()];
  485. int i = 0;
  486. for(String protocol : protocols){
  487. selected[i] =(this.filter.protocols.contains(protocol));
  488. i++;
  489. }
  490. return selected;
  491. }
  492. public ArrayList<String> getSelectedProtocolTitles(){
  493. ArrayList<String> knownProtocols = this.protocolTitles();
  494. if (this.filter.hasProtocols()){
  495. ArrayList<String> titles = new ArrayList<String>();
  496. int i =0;
  497. for (boolean b : this.selectedProtocols()){
  498. if (b){
  499. String title = knownProtocols.get(i);
  500. titles.add(title);
  501. }
  502. i++;
  503. }
  504. return titles;
  505. }
  506. return this.protocolTitles();
  507. }
  508. /*
  509. *
  510. * COLOR STUFF
  511. *
  512. * */
  513. public int getOtherColor(){
  514. return Color.rgb(0,0,0);
  515. }
  516. public ArrayList<Integer> getColorList(){
  517. if (this.colorList == null){
  518. this.colorList = new ArrayList<Integer>();
  519. for (int i =0; i < 255; i++){
  520. Integer color = this.generateColorForIndex(i);
  521. this.colorList.add(color);
  522. }
  523. }
  524. return this.colorList;
  525. }
  526. public Integer getColor(int index){
  527. if (this.colorList == null) this.colorList = new ArrayList<Integer>();
  528. if (index >= this.colorList.size()) {
  529. for (int i = this.colorList.size(); i<= index; i++){
  530. Integer color = this.generateColorForIndex(i);
  531. this.colorList.add(color);
  532. }
  533. return this.generateColorForIndex(index);
  534. }
  535. return this.colorList.get(index);
  536. }
  537. public Integer generateColorForIndex(int index){
  538. int r[] = new int[]{0,0,0,1,1,1,1};
  539. int g[] = new int[]{0,1,1,1,1,0,0};
  540. int b[] = new int[]{1,1,0,0,1,1,0};
  541. int a = index % 16;
  542. int n = index % 7;
  543. int R = Math.max( (r[n] * 255) - ((Math.max(0,(a ))) * 16), 0);
  544. int G = Math.max( (g[n] * 255) - ((Math.max(0,(a ))) * 16), 0);
  545. int B = Math.max( (b[n] * 255) - ((Math.max(0,(a ))) * 16), 0);
  546. return Color.rgb(R,G,B);
  547. }
  548. /*
  549. *
  550. * ACTUALISE PLOT VIEW
  551. *
  552. */
  553. public void setPlotView(View view){
  554. LinearLayout plotLayout = this.getPlotLayout();
  555. if (this.currentPlotView != null && plotLayout != null){
  556. plotLayout.removeAllViews();
  557. }
  558. if (view != null && plotLayout != null){
  559. this.currentPlotView = view;
  560. view.setLayoutParams(plotLayout.getLayoutParams());
  561. plotLayout.addView(view);
  562. }
  563. }
  564. public LinearLayout getPlotLayout(){
  565. if (this.rootView != null){
  566. return (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
  567. } else {
  568. return null;
  569. }
  570. }
  571. /**
  572. *
  573. * FILTER STUFF
  574. *
  575. * */
  576. private boolean isFilterSetForTitle(String title){
  577. if (title.equals(FILTER_MENU_TITLE_BSSID)){
  578. return this.filter.hasBSSIDs();
  579. }
  580. if (title.equals(FILTER_MENU_TITLE_ESSID)){
  581. return this.filter.hasESSIDs();
  582. }
  583. if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  584. return this.filter.hasProtocols();
  585. }
  586. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  587. return this.filter.hasBelowTimestamp();
  588. }
  589. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  590. return this.filter.hasAboveTimestamp();
  591. }
  592. return false;
  593. }
  594. private void clearFilter(){
  595. if(filter == null) this.filter = new LogFilter();
  596. this.filter.clear();
  597. }
  598. /*
  599. *
  600. * DATE TRANSFORMATION
  601. *
  602. */
  603. public long getDayHourFromDate(long timeInMillis){
  604. Calendar calendar = Calendar.getInstance();
  605. calendar.setTimeInMillis (timeInMillis);
  606. int hour = calendar.get(Calendar.HOUR);
  607. int min = calendar.get(Calendar.MINUTE);
  608. return (hour*60*60)*1000;
  609. }
  610. public long getdateFromMilliseconds(long timeInMillis){
  611. Calendar calendar = Calendar.getInstance();
  612. calendar.setTimeInMillis (timeInMillis);
  613. int year = calendar.get(Calendar.YEAR) ;
  614. int month = calendar.get(Calendar.MONTH);
  615. int day = calendar.get(Calendar.DATE);
  616. calendar.set(year, month, day, 0,0);
  617. return calendar.getTimeInMillis();
  618. }
  619. static final DateFormat timeFormat = new SimpleDateFormat("H:mm");
  620. @SuppressLint("SimpleDateFormat")
  621. private String getDateAsTimeString(long timeStamp) {
  622. try {
  623. Date netDate = (new Date(timeStamp));
  624. return timeFormat.format(netDate);
  625. } catch (Exception ex) {
  626. return "xx";
  627. }
  628. }
  629. static final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
  630. @SuppressLint("SimpleDateFormat")
  631. private String getDateAsDayString(long timeStamp) {
  632. try {
  633. Date netDate = (new Date(timeStamp));
  634. return dateFormat.format(netDate);
  635. } catch (Exception ex) {
  636. return "xx";
  637. }
  638. }
  639. }