StatisticsFragment.java 25 KB

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