123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- package de.tudarmstadt.informatik.hostage.ui2.fragment;
- import android.annotation.SuppressLint;
- import android.app.Fragment;
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AdapterView;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.TextView;
- import com.echo.holographlibrary.Bar;
- import com.echo.holographlibrary.BarGraph;
- import com.echo.holographlibrary.Line;
- import com.echo.holographlibrary.LineGraph;
- import com.echo.holographlibrary.LinePoint;
- import com.echo.holographlibrary.PieGraph;
- import com.echo.holographlibrary.PieSlice;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Date;
- import java.util.HashMap;
- import de.tudarmstadt.informatik.hostage.R;
- import de.tudarmstadt.informatik.hostage.logging.Record;
- import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
- import de.tudarmstadt.informatik.hostage.ui.LogFilter;
- import de.tudarmstadt.informatik.hostage.ui2.adapter.StatisticListAdapter;
- import de.tudarmstadt.informatik.hostage.ui2.model.PlotComparisonItem;
- /**
- * Created by Julien on 16.02.14.
- */
- public class StatisticsFragment extends Fragment {
- static final String SELECTED_KEY = "Selected";
- static final String OTHERS_KEY = "Other";
- static final String FILTER_MENU_TITLE_BSSID = "BSSID";
- static final String FILTER_MENU_TITLE_ESSID = "ESSID";
- static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocol";
- static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = "Latest";
- static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = "Earliest";
- static final String FILTER_MENU_TITLE_SORTING = "Sort by";
- static final String FILTER_MENU_TITLE_REMOVE = "Reset Filter";
- static final String FILTER_MENU_TITLE_GROUP = "Group by";
- static final String FILTER_MENU_POPUP_TITLE = "Filter by";
- static final String CHART_TYPE_TITLE_BAR = "Bar Plot";
- static final String CHART_TYPE_TITLE_PIE = "Pie Plot";
- static final String CHART_TYPE_TITLE_LINE = "Line Plot";
- static final String OTHER_CHART_TITLE = "Other";
- // MINIMAL 2
- static int MAX_NUMBER_OF_CHART_OBJECTS = 5;
- private boolean wasBelowTimePicker;
- private LogFilter filter;
- private boolean showFilterButton;
- private PieGraph pieGraph;
- private LineGraph lineGraph;
- private BarGraph barGraph;
- private View rootView;
- private View currentPlotView;
- private ArrayList<Integer> colorList;
- private ArrayList<PlotComparisonItem> currentData;
- private UglyDbHelper dbh;
- private ListView legendListView;
- public enum ChartType {
- PIE_CHART(0),
- BAR_CHART(1),
- LINE_CHART(2);
- private int value;
- private ChartType(int value) {
- this.value = value;
- }
- static public ChartType create(int value){
- if (value < 0 || value >= ChartType.values().length) return ChartType.PIE_CHART;
- return ChartType.values()[value];
- }
- public String toString(){
- if (this.equals(ChartType.create(0))){
- return CHART_TYPE_TITLE_PIE;
- }
- if (this.equals(ChartType.create(1))){
- return CHART_TYPE_TITLE_BAR;
- }
- return CHART_TYPE_TITLE_LINE;
- }
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- }
- public int getLayoutID(){
- return R.layout.fragment_statistics;
- }
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- dbh = new UglyDbHelper(this.getBaseContext());
- // Get the message from the intent
- if (this.filter == null){
- Intent intent = this.getActivity().getIntent();
- LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
- if(filter == null){
- this.clearFilter();
- } else {
- this.filter = filter;
- }
- }
- View rootView = inflater.inflate(this.getLayoutID(), container, false);
- LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
- plotLayout.setWillNotDraw(false);
- container.setWillNotDraw(false);
- this.legendListView = (ListView) rootView.findViewById(R.id.legend_list_view);
- this.legendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
- StatisticsFragment.this.userTappedOnItem(i);
- }
- });
- this.rootView = rootView;
- rootView.setWillNotDraw(false);
- this.configureRootView(rootView);
- return rootView;
- }
- private Context getBaseContext(){
- return this.getActivity().getBaseContext();
- }
- private Context getApplicationContext(){
- return this.getActivity().getApplicationContext();
- }
- public void configureRootView(View rootView){
- LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
- plotLayout.setWillNotDraw(false);
- plotLayout.removeAllViews();
- this.actualiseCurrentPlot();
- }
- public void setTitle(String title){
- TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
- if (title != null && titleView != null){
- titleView.setText(title);
- }
- }
- public String getTitle(){
- TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
- if (titleView != null){
- return "" + titleView.getText();
- }
- return "";
- }
- public void onStart() {
- super.onStart();
- this.actualiseCurrentPlot();
- this.currentPlotView.invalidate();
- }
- public void setChartType(ChartType type){
- boolean shouldChange = true;
- if (this.currentPlotView != null){
- if (type == ChartType.PIE_CHART){
- shouldChange = ! (this.currentPlotView instanceof PieGraph);
- } else {
- this.pieGraph.setVisibility(View.INVISIBLE);
- }
- if (type == ChartType.LINE_CHART){
- shouldChange = ! (this.currentPlotView instanceof LineGraph);
- } else {
- this.lineGraph.setVisibility(View.INVISIBLE);
- }
- if (type == ChartType.BAR_CHART){
- shouldChange = ! (this.currentPlotView instanceof BarGraph);
- } else {
- this.barGraph.setVisibility(View.INVISIBLE);
- }
- }
- if (shouldChange){
- this.currentPlotView = this.getPlotViewForType(type);
- this.currentPlotView.setVisibility(View.VISIBLE);
- this.actualiseCurrentPlot();
- }
- }
- public View getPlotViewForType(ChartType type){
- switch (type){
- case PIE_CHART:
- return this.getPieGraphView();
- case LINE_CHART:
- return this.getLineGraphView();
- default:
- return this.getBarGraphView();
- }
- }
- public void actualiseLegendList(){
- StatisticListAdapter adapter = new StatisticListAdapter(this.getApplicationContext(), this.currentData);
- this.legendListView.setAdapter(adapter);
- }
- /**
- *
- * PLOT TOUCH HANDLING
- *
- * */
- public void onSliceClick(int index){
- this.userTappedOnItem(index);
- }
- public void onBarClick(int index){
- this.userTappedOnItem(index);
- }
- /*
- *
- * PLOT TYPES
- *
- * **/
- public PieGraph getPieGraphView(){
- if (this.pieGraph == null) {
- this.pieGraph = new PieGraph(this.getApplicationContext());
- LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
- plotLayout.addView(this.pieGraph);
- this.pieGraph.setOnSliceClickedListener(new PieGraph.OnSliceClickedListener() {
- @Override
- public void onClick(int index) {
- StatisticsFragment.this.onSliceClick(index);
- }
- });
- }
- return this.pieGraph;
- }
- public LineGraph getLineGraphView(){
- if (this.lineGraph == null) {
- this.lineGraph = new LineGraph(this.getActivity());
- LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
- plotLayout.addView(this.lineGraph);
- }
- return this.lineGraph;
- }
- public BarGraph getBarGraphView(){
- if (this.barGraph == null) {
- this.barGraph = new BarGraph(this.getActivity());
- LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
- plotLayout.addView(this.barGraph);
- this.barGraph.setPopupImageID(R.drawable.popup_black);
- this.barGraph.setOnBarClickedListener(new BarGraph.OnBarClickedListener() {
- @Override
- public void onClick(int i) {
- StatisticsFragment.this.onBarClick(i);
- }
- });
- }
- return this.barGraph;
- }
- /*
- * FEED PLOTS WITH DATA
- * */
- public void setPieGraphData(PieGraph piegraph){
- this.currentData = this.getPieData();
- if (this.currentData == null){
- this.currentData = new ArrayList<PlotComparisonItem>();
- }
- this.pieGraph.removeSlices();
- for (PlotComparisonItem item : this.currentData){
- PieSlice slice = new PieSlice();
- slice.setColor(item.getColor());
- Double value2 = (Double) item.getValue2();
- float v = value2.floatValue();
- slice.setValue(v);
- slice.setTitle(item.getTitle());
- this.pieGraph.addSlice(slice);
- }
- this.pieGraph.invalidate();
- }
- public void setLineGraphData(LineGraph linegraph){
- this.currentData = this.getLinedata();
- if (this.currentData == null){
- this.currentData = new ArrayList<PlotComparisonItem>();
- }
- int index = 0;
- this.lineGraph.removeAllLines();
- Line l = new Line();
- for (PlotComparisonItem item : this.currentData){
- LinePoint p = new LinePoint();
- p.setX(index);
- Double value2 = (Double) item.getValue2();
- p.setY(value2.floatValue());
- index++;
- }
- this.lineGraph.addLine(l);
- this.lineGraph.setRangeY(0, index);
- this.lineGraph.setLineToFill(0);
- this.lineGraph.invalidate();
- }
- public void setBarGraphData(BarGraph bargraph){
- this.currentData = this.getLinedata();
- if (this.currentData == null){
- this.currentData = new ArrayList<PlotComparisonItem>();
- }
- ArrayList<Bar> bars = new ArrayList<Bar>();
- for (PlotComparisonItem item : this.currentData){
- Bar d = new Bar();
- d.setColor(item.getColor());
- d.setName(item.getTitle());
- Double value2 = (Double) item.getValue2();
- d.setValue(value2.floatValue());
- }
- this.barGraph.setBars(bars);
- this.barGraph.invalidate();
- }
- /*
- *
- * FETCH & ACTUALISE RECORD DATA
- *
- * */
- public ArrayList<Record> getFetchedRecords(){
- if (this.filter == null) this.clearFilter();
- return this.dbh.getRecordsForFilter(this.filter);
- }
- public void actualiseCurrentPlot(){
- View plot = this.currentPlotView;
- if (plot == null){
- this.currentPlotView = this.getPieGraphView();
- plot = this.currentPlotView;
- }
- if (plot.getVisibility() == View.INVISIBLE) plot.setVisibility(View.VISIBLE);
- if (plot instanceof PieGraph){
- PieGraph pie = (PieGraph) plot;
- this.setPieGraphData(pie);
- } else {
- if (this.pieGraph != null)
- this.pieGraph.setVisibility(View.INVISIBLE);
- }
- if (plot instanceof BarGraph){
- BarGraph bar = (BarGraph) plot;
- this.setBarGraphData(bar);
- } else {
- if (this.barGraph != null)
- this.barGraph.setVisibility(View.INVISIBLE);
- }
- if (plot instanceof LineGraph){
- LineGraph line = (LineGraph)plot;
- this.setLineGraphData(line);
- }else {
- if (this.lineGraph != null)
- this.lineGraph.setVisibility(View.INVISIBLE);
- }
- plot.setVisibility(View.VISIBLE);
- this.actualiseLegendList();
- this.currentPlotView.invalidate();
- }
- public ArrayList<PlotComparisonItem> getPieData(){
- // DEFAULT
- return this.attacksPerProtocols();
- }
- public ArrayList<PlotComparisonItem> getBarData(){
- ArrayList<String> protocolTitles = this.getSelectedProtocolTitles();
- // DEFAULT
- if (protocolTitles != null && protocolTitles.size() != 0){
- String protocol = this.getSelectedProtocolTitles().get(0);
- return this.attacksPerBSSID(protocol);
- }
- // Nothing available
- return new ArrayList<PlotComparisonItem>();
- }
- public ArrayList<PlotComparisonItem> getLinedata(){
- // DEFAULT
- return this.attacksPerDate();
- }
- /*
- * SPECIFIC DATA STUFF
- * */
- /*PROTOCOLS OVERVIEW*/
- public ArrayList<PlotComparisonItem> attacksPerProtocols(){
- ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
- int index = 0;
- for (String title : this.getSelectedProtocolTitles()){
- int attacksCount = this.dbh.getAttackPerProtocolCount(title);
- PlotComparisonItem item = new PlotComparisonItem(title,this.getColor(index), 0., (double) attacksCount);
- plotItems.add(item);
- index++;
- }
- Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
- @Override
- public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
- return s1.getValue2().compareTo(s2.getValue2());
- }
- });
- return this.resizeData(plotItems);
- }
- public ArrayList<PlotComparisonItem> usesPerProtocol(){
- ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
- for (String title : this.getSelectedProtocolTitles()){
- /*At the moment there is no possibillity to get the number of uses for each protocol*/
- }
- Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
- @Override
- public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
- return s1.getTitle().compareToIgnoreCase(s2.getTitle());
- }
- });
- return plotItems;
- }
- /*LINE PLOT DATA*/
- public ArrayList<PlotComparisonItem> attacksPerDate(){
- ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
- HashMap<Long, ArrayList<Record> > recordMap = new HashMap<Long, ArrayList<Record> >();
- for (Record record : this.getFetchedRecords()){
- long date = this.getdateFromMilliseconds(record.getTimestamp());
- ArrayList<Record> list = recordMap.get(date);
- if (list == null){
- list = new ArrayList<Record>();
- recordMap.put(date, list);
- }
- list.add(record);
- }
- int index = 0;
- for (long date : recordMap.keySet()){
- ArrayList<Record> list = recordMap.get(date);
- PlotComparisonItem item = new PlotComparisonItem(this.getDateAsDayString(date), this.getColor(index), (double) date, (double)list.size());
- plotItems.add(item);
- index++;
- }
- Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
- @Override
- public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
- return s1.getValue1().compareTo(s2.getValue1());
- }
- });
- return plotItems;
- }
- public ArrayList<PlotComparisonItem> attacksPerTime(){
- ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
- HashMap<Long, ArrayList<Record> > recordMap = new HashMap<Long, ArrayList<Record> >();
- for (Record record : this.getFetchedRecords()){
- long date = this.getDayHourFromDate(record.getTimestamp());
- ArrayList<Record> list = recordMap.get(date);
- if (list == null){
- list = new ArrayList<Record>();
- recordMap.put(date, list);
- }
- list.add(record);
- }
- int index = 0;
- for (long time : recordMap.keySet()){
- ArrayList<Record> list = recordMap.get(time);
- PlotComparisonItem item = new PlotComparisonItem(this.getDateAsTimeString(time), this.getColor(index) , (double)time, (double) list.size());
- plotItems.add(item);
- index++;
- }
- Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
- @Override
- public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
- return s1.getValue1().compareTo(s2.getValue1());
- }
- });
- return plotItems;
- }
- // BAR PLOT DATA
- public ArrayList<PlotComparisonItem> attacksPerBSSID(String protocol){
- LogFilter filter = new LogFilter();
- ArrayList<String> protocollist = new ArrayList<String>();
- protocollist.add(protocol);
- filter.setProtocols(protocollist);
- ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
- HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
- ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
- for (Record record : records){
- int count = recordMap.get(record.getBssid());
- count++;
- recordMap.put(record.getBssid(), count);
- }
- int index = 0;
- for (String key : recordMap.keySet()){
- PlotComparisonItem item = new PlotComparisonItem(key, this.getColor(index), 0., (double)recordMap.get(key));
- plotItems.add(item);
- index++;
- }
- Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
- @Override
- public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
- return s1.getValue2().compareTo(s2.getValue2());
- }
- });
- return this.resizeData(plotItems);
- }
- public ArrayList<PlotComparisonItem> attacksPerESSID(String protocol){
- LogFilter filter = new LogFilter();
- ArrayList<String> protocollist = new ArrayList<String>();
- protocollist.add(protocol);
- filter.setProtocols(protocollist);
- ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
- HashMap<String, Integer> recordMap = new HashMap<String, Integer>();
- ArrayList<Record> records = this.dbh.getRecordsForFilter(filter);
- for (Record record : records){
- int count = recordMap.get(record.getSsid());
- count++;
- recordMap.put(record.getSsid(), count);
- }
- int index = 0;
- for (String key : recordMap.keySet()){
- PlotComparisonItem item = new PlotComparisonItem(key,this.getColor(index), 0. , (double)recordMap.get(key));
- plotItems.add(item);
- index++;
- }
- Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
- @Override
- public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
- return s1.getValue2().compareTo(s2.getValue2());
- }
- });
- return this.resizeData(plotItems);
- }
- private ArrayList<PlotComparisonItem> resizeData(ArrayList<PlotComparisonItem> plotItems){
- if (plotItems != null){
- if (plotItems.size() > MAX_NUMBER_OF_CHART_OBJECTS && MAX_NUMBER_OF_CHART_OBJECTS > 1){
- ArrayList<PlotComparisonItem> copy = new ArrayList<PlotComparisonItem>();
- ArrayList<PlotComparisonItem> others = new ArrayList<PlotComparisonItem>();
- double valueOfOthers = 0;
- for (int i = 0; i < plotItems.size(); i++){
- if (i < MAX_NUMBER_OF_CHART_OBJECTS - 1){
- PlotComparisonItem item = plotItems.get(i);
- item.setColor(this.getColor(i));
- copy.add(plotItems.get(i));
- } else {
- PlotComparisonItem item = plotItems.get(i);
- others.add(item);
- valueOfOthers+=item.getValue2();
- }
- }
- PlotComparisonItem otherItem = new PlotComparisonItem(OTHER_CHART_TITLE, this.getOtherColor(), 0., valueOfOthers);
- otherItem.setOtherData(others);
- copy.add(otherItem);
- return copy;
- }
- }
- return plotItems;
- }
- /*
- * FILTER STUFF
- * */
- public ArrayList<String> protocolTitles(){
- ArrayList<String> titles = new ArrayList<String>();
- for (String protocol : this.getResources().getStringArray(
- R.array.protocols)) {
- titles.add(protocol);
- }
- return titles;
- }
- public boolean[] selectedProtocols(){
- ArrayList<String> protocols = this.protocolTitles();
- boolean[] selected = new boolean[protocols.size()];
- int i = 0;
- for(String protocol : protocols){
- selected[i] =(this.filter.protocols.contains(protocol));
- i++;
- }
- return selected;
- }
- public ArrayList<String> getSelectedProtocolTitles(){
- ArrayList<String> knownProtocols = this.protocolTitles();
- if (this.filter.hasProtocols()){
- ArrayList<String> titles = new ArrayList<String>();
- int i =0;
- for (boolean b : this.selectedProtocols()){
- if (b){
- String title = knownProtocols.get(i);
- titles.add(title);
- }
- i++;
- }
- return titles;
- }
- return this.protocolTitles();
- }
- /*
- *
- * COLOR STUFF
- *
- * */
- public int getOtherColor(){
- return Color.argb(255,0,0,0);
- }
- public ArrayList<Integer> getColorList(){
- if (this.colorList == null){
- this.colorList = new ArrayList<Integer>();
- for (int i =0; i < 255; i++){
- Integer color = this.generateColorForIndex(i);
- this.colorList.add(color);
- }
- }
- return this.colorList;
- }
- public Integer getColor(int index){
- if (this.colorList == null) this.colorList = new ArrayList<Integer>();
- if (index >= this.colorList.size()) {
- for (int i = this.colorList.size(); i<= index; i++){
- Integer color = this.generateColorForIndex(i);
- this.colorList.add(color);
- }
- return this.generateColorForIndex(index);
- }
- return this.colorList.get(index);
- }
- public Integer generateColorForIndex(int index){
- int r[] = new int[]{0,0,0,1,1,1,1};
- int g[] = new int[]{0,1,1,1,1,0,0};
- int b[] = new int[]{1,1,0,0,1,1,0};
- int a = index % 16;
- int n = index % 7;
- int R = Math.max( (r[n] * 255) - ((Math.max(0,(a ))) * 16), 0);
- int G = Math.max( (g[n] * 255) - ((Math.max(0,(a ))) * 16), 0);
- int B = Math.max( (b[n] * 255) - ((Math.max(0,(a ))) * 16), 0);
- return Color.argb(255,R,G,B);
- }
- public LinearLayout getPlotLayout(){
- if (this.rootView != null){
- return (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
- } else {
- return null;
- }
- }
- /**
- *
- * FILTER STUFF
- *
- * */
- private boolean isFilterSetForTitle(String title){
- if (title.equals(FILTER_MENU_TITLE_BSSID)){
- return this.filter.hasBSSIDs();
- }
- if (title.equals(FILTER_MENU_TITLE_ESSID)){
- return this.filter.hasESSIDs();
- }
- if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
- return this.filter.hasProtocols();
- }
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
- return this.filter.hasBelowTimestamp();
- }
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
- return this.filter.hasAboveTimestamp();
- }
- return false;
- }
- private void clearFilter(){
- if(filter == null) this.filter = new LogFilter();
- this.filter.clear();
- }
- /*
- *
- * DATE TRANSFORMATION
- *
- */
- public long getDayHourFromDate(long timeInMillis){
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis (timeInMillis);
- int hour = calendar.get(Calendar.HOUR);
- int min = calendar.get(Calendar.MINUTE);
- return (hour*60*60)*1000;
- }
- public long getdateFromMilliseconds(long timeInMillis){
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis (timeInMillis);
- int year = calendar.get(Calendar.YEAR) ;
- int month = calendar.get(Calendar.MONTH);
- int day = calendar.get(Calendar.DATE);
- calendar.set(year, month, day, 0,0);
- return calendar.getTimeInMillis();
- }
- static final DateFormat timeFormat = new SimpleDateFormat("H:mm");
- @SuppressLint("SimpleDateFormat")
- private String getDateAsTimeString(long timeStamp) {
- try {
- Date netDate = (new Date(timeStamp));
- return timeFormat.format(netDate);
- } catch (Exception ex) {
- return "xx";
- }
- }
- static final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- @SuppressLint("SimpleDateFormat")
- private String getDateAsDayString(long timeStamp) {
- try {
- Date netDate = (new Date(timeStamp));
- return dateFormat.format(netDate);
- } catch (Exception ex) {
- return "xx";
- }
- }
- /**
- * USERINTERACTION
- */
- private void userTappedOnItem(int index){
- if (index < this.currentData.size()){
- PlotComparisonItem item = this.currentData.get(index);
- ArrayList<String> selectedData;
- selectedData = new ArrayList<String>();
- if (item.getOtherData() == null){
- selectedData.add(item.getTitle());
- } else {
- for (PlotComparisonItem other : item.getOtherData()){
- selectedData.add(other.getTitle());
- }
- }
- LogFilter filter = new LogFilter();
- if (this.currentPlotView instanceof PieGraph){
- filter.setProtocols(selectedData);
- }
- if (this.currentPlotView instanceof BarGraph){
- // TODO set data for BSSID / ESSID
- }
- if (this.currentPlotView instanceof LineGraph){
- // TODO set data for BSSID / ESSID
- }
- }
- }
- private void pushRecordOverviewForFilter(LogFilter filter){
- }
- }
|