123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479 |
- package de.tudarmstadt.informatik.hostage.ui2.fragment;
- import android.annotation.SuppressLint;
- import android.app.Fragment;
- import android.app.FragmentManager;
- import android.app.FragmentTransaction;
- import android.content.Context;
- import android.content.Intent;
- import android.content.res.Configuration;
- 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.ImageButton;
- 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.dialog.ChecklistDialog;
- import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
- import de.tudarmstadt.informatik.hostage.ui2.helper.ColorSequenceGenerator;
- import de.tudarmstadt.informatik.hostage.ui2.model.PlotComparisonItem;
- import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
- import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
- import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupItem;
- import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupTable;
- import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
- /**
- * Created by Julien on 16.02.14.
- */
- public class StatisticsFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
- static final String FILTER_MENU_TITLE_BSSID = "BSSID";
- static final String FILTER_MENU_TITLE_ESSID = "ESSID";
- static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocols";
- static final String FILTER_MENU_TITLE_PROTOCOL = "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_REMOVE = "Reset Filter";
- static final String FILTER_MENU_POPUP_TITLE = "Filter by";
- static final String MENU_TITLE_PROTOCOLS = "Protocols";
- static final String MENU_TITLE_NETWORK = "Networks";
- static final String MENU_TITLE_ATTACKS = "Attacks";
- static final String MENU_POPUP_TITLE = "Visualize";
- 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 DIALOG_PROTOCOLS_TITLE = "Select protocol data to compare";
- static final String DIALOG_NETWORK_TITLE = "Select network data to compare";
- static final String DIALOG_ATTACK_TITLE = "Select attack data to compare";
- static final String COMPARE_TITLE_AttacksPerProtocol = "Attacks per protocol";
- static final String COMPARE_TITLE_UsesPerProtocol = "Uses per protocol";
- static final String COMPARE_TITLE_AttacksPerDate = "Attacks per date";
- static final String COMPARE_TITLE_AttacksPerTime = "Attacks per time";
- static final String COMPARE_TITLE_AttacksPerBSSID = "Attacks per BSSID";
- static final String COMPARE_TITLE_AttacksPerESSID = "Attacks per ESSID";
- static final String FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE = "Select Protocol";
- static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT = "Attacks count";
- static final String TABLE_HEADER_VALUE_TITLE_ATTACKS_PERCENTAGE = "% of all";
- static final String OTHER_CHART_TITLE = "Other";
- // MINIMAL 2
- static int MAX_NUMBER_OF_CHART_OBJECTS = 6;
- 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;
- private String selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
- 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;
- }
- }
- private ImageButton getFilterButton(){
- return (ImageButton) this.rootView.findViewById(R.id.FilterButton);
- }
- public int getLayoutID(){
- return R.layout.fragment_statistics;
- }
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- super.onCreateView(inflater, container, savedInstanceState);
- getActivity().setTitle(getResources().getString(R.string.drawer_statistics));
- 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.userTappedOnLegendItem(i);
- }
- });
- this.rootView = rootView;
- rootView.setWillNotDraw(false);
- this.configureRootView(rootView);
- return rootView;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- }
- @Override
- public void onConfigurationChanged(Configuration newConfig){
- super.onConfigurationChanged(newConfig);
- LayoutInflater inflater = LayoutInflater.from(getActivity());
- ViewGroup container = (ViewGroup) this.getView();
- container.removeAllViewsInLayout();
- View rootView = inflater.inflate(this.getLayoutID(), container, false);
- container.addView(rootView);
- LinearLayout plotLayout = (LinearLayout) rootView.findViewById(R.id.plot_layout);
- plotLayout.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.userTappedOnLegendItem(i);
- }
- });
- this.rootView = rootView;
- rootView.setWillNotDraw(false);
- this.configureRootView(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();
- ImageButton visualButton = (ImageButton) rootView.findViewById(R.id.plot_data_button);
- visualButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- StatisticsFragment.this.openBarSelectionMenuOnView(v);
- }
- });
- ImageButton filterButton = this.getFilterButton();
- filterButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- StatisticsFragment.this.openFilterMenuOnView(v);
- }
- });
- if (this.currentPlotView instanceof BarGraph){
- this.setTitle("" + this.getCurrentSelectedProtocol() + ": " +this.selectedCompareData);
- } else {
- this.setTitle(this.selectedCompareData);
- }
- }
- public void setTitle(String title){
- TextView titleView = (TextView) this.rootView.findViewById(R.id.title_text_view);
- if (title != null && titleView != null){
- titleView.setText(title);
- titleView.invalidate();
- }
- }
- 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();
- if (this.currentPlotView instanceof BarGraph){
- this.setTitle("" + this.getCurrentSelectedProtocol() + ": " +this.selectedCompareData);
- } else {
- this.setTitle(this.selectedCompareData);
- }
- }
- public void setChartType(ChartType type){
- boolean shouldChange = true;
- this.clearFilter();
- if (this.currentPlotView != null){
- if (type == ChartType.PIE_CHART){
- shouldChange = ! (this.currentPlotView instanceof PieGraph);
- // SET FILTER BUTTON HIDDEN
- ImageButton filterButton = this.getFilterButton();
- if (filterButton != null) filterButton.setVisibility(View.GONE);
- } else {
- if (this.pieGraph != null)
- this.pieGraph.setVisibility(View.GONE);
- // SHOW FILTER BUTTON
- ImageButton filterButton = this.getFilterButton();
- if (filterButton != null) filterButton.setVisibility(View.VISIBLE);
- }
- if (type == ChartType.LINE_CHART){
- shouldChange = ! (this.currentPlotView instanceof LineGraph);
- } else {
- if (this.lineGraph != null)
- this.lineGraph.setVisibility(View.GONE);
- }
- if (type == ChartType.BAR_CHART){
- shouldChange = ! (this.currentPlotView instanceof BarGraph);
- } else {
- if (this.barGraph != null)
- this.barGraph.setVisibility(View.GONE);
- }
- }
- 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);
- if (this.currentPlotView instanceof LineGraph){
- adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
- @Override
- public String convertValueToString(double value) {
- return String.format("%.02f", value) + " %";
- }
- });
- } else {
- adapter.setValueFormatter(new StatisticListAdapter.ValueFormatter() {
- @Override
- public String convertValueToString(double value) {
- int v = (int) value;
- return "" + v;
- }
- });
- }
- this.legendListView.setAdapter(adapter);
- TextView tableHeaderTitleView = (TextView) this.rootView.findViewById(R.id.table_header_title_textview);
- TextView tableHeaderValueView = (TextView) this.rootView.findViewById(R.id.table_header_value_textview);
- if (this.currentPlotView instanceof LineGraph){
- tableHeaderTitleView.setText(FILTER_MENU_TITLE_ESSID);
- tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_PERCENTAGE);
- }
- if (this.currentPlotView instanceof PieGraph){
- tableHeaderTitleView.setText(FILTER_MENU_TITLE_PROTOCOL);
- tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT);
- }
- if (this.currentPlotView instanceof BarGraph){
- tableHeaderValueView.setText(TABLE_HEADER_VALUE_TITLE_ATTACKS_COUNT);
- if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)){
- tableHeaderTitleView.setText(FILTER_MENU_TITLE_BSSID);
- } else {
- tableHeaderTitleView.setText(FILTER_MENU_TITLE_ESSID);
- }
- }
- }
- /*
- * MENU
- * */
- private void openBarSelectionMenuOnView(View anchorView){
- SimplePopupTable visualiseMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
- public void onItemClick(Object ob) {
- if (ob instanceof AbstractPopupItem){
- AbstractPopupItem item = (AbstractPopupItem) ob;
- StatisticsFragment.this.userSelectMenuItem(item);
- }
- }
- });
- visualiseMenu.setTitle(MENU_POPUP_TITLE);
- int id = 0;
- for(String title : StatisticsFragment.this.getMenuTitles()){
- SimplePopupItem item = new SimplePopupItem(this.getActivity());
- item.setTitle(title);
- item.setItemId(id);
- item.setSelected(false);
- visualiseMenu.addItem(item);
- id++;
- }
- visualiseMenu.showOnView(anchorView);
- }
- private void userSelectMenuItem(AbstractPopupItem item){
- // OPEN A DIALOG TO SPECIFY THE VISUALISE DATA
- if (item.getTitle().equals(MENU_TITLE_PROTOCOLS)){
- ChartType chartType = ChartType.PIE_CHART;
- this.selectedCompareData = COMPARE_TITLE_AttacksPerProtocol;
- this.setChartType(chartType);
- this.setTitle(COMPARE_TITLE_AttacksPerProtocol);
- }
- if (item.getTitle().equals(MENU_TITLE_NETWORK)){
- this.openNetworkDataDialog();
- }
- if (item.getTitle().equals(MENU_TITLE_ATTACKS)){
- this.openAttackDataDialog();
- }
- }
- private ArrayList<String> getMenuTitles(){
- ArrayList<String> titles = new ArrayList<String>();
- titles.add(MENU_TITLE_PROTOCOLS);
- titles.add(MENU_TITLE_NETWORK);
- titles.add(MENU_TITLE_ATTACKS);
- return titles;
- }
- /*
- * PLOT DATA DIALOGS
- * */
- private void openProtocolDataDialog(){
- ArrayList<String> titles = this.getDialogProtocolDataTitle();
- ChecklistDialog newFragment = new ChecklistDialog(DIALOG_PROTOCOLS_TITLE, titles, this.selectedData(titles), false , this);
- newFragment.show(this.getActivity().getFragmentManager(), DIALOG_PROTOCOLS_TITLE);
- }
- private void openNetworkDataDialog(){
- ArrayList<String> titles = this.getDialogNetworkDataTitle();
- ChecklistDialog newFragment = new ChecklistDialog(DIALOG_NETWORK_TITLE, titles, this.selectedData(titles), false , this);
- newFragment.show(this.getActivity().getFragmentManager(), DIALOG_NETWORK_TITLE);
- }
- private void openAttackDataDialog(){
- ArrayList<String> titles = this.getDialogAttackDataTitle();
- ChecklistDialog newFragment = new ChecklistDialog(DIALOG_ATTACK_TITLE, titles, this.selectedData(titles), false , this);
- newFragment.show(this.getActivity().getFragmentManager(), DIALOG_ATTACK_TITLE);
- }
- /*
- *
- * DIALOG ACTION METHODS
- *
- * */
- public void onDialogPositiveClick(ChecklistDialog dialog) {
- String title = dialog.getTitle();
- ArrayList<String> titles =dialog.getSelectedItemTitles();
- if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
- //titles = titles.size() == 0 ? this.protocolTitles() : titles;
- this.filter.setProtocols(titles);
- this.actualiseCurrentPlot();
- return;
- }
- if (title.equals(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE)){
- if (titles.size() == 0){
- titles = new ArrayList<String>();
- titles.add(this.protocolTitles().get(0));
- }
- this.filter.setProtocols(titles);
- this.actualiseCurrentPlot();
- String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
- this.setTitle(fragTitle);
- return;
- }
- if (title.equals(FILTER_MENU_TITLE_ESSID)){
- this.filter.setESSIDs(titles);
- this.actualiseCurrentPlot();
- return;
- }
- if (title.equals(FILTER_MENU_TITLE_BSSID)){
- this.filter.setBSSIDs(titles);
- this.actualiseCurrentPlot();
- return;
- }
- if (titles.size() != 0){
- String data = titles.get(0);
- this.setTitle(data);
- if (title.equals(DIALOG_PROTOCOLS_TITLE)){
- ChartType chartType = ChartType.PIE_CHART;
- this.selectedCompareData = data;
- this.setChartType(chartType);
- }
- if (title.equals(DIALOG_ATTACK_TITLE)){
- ChartType chartType = ChartType.LINE_CHART;
- this.selectedCompareData = data;
- this.setChartType(chartType);
- }
- if (title.equals(DIALOG_NETWORK_TITLE)){
- ChartType chartType = ChartType.BAR_CHART;
- this.selectedCompareData = data;
- this.setChartType(chartType);
- String fragTitle = "" + this.getCurrentSelectedProtocol() + ": " + this.selectedCompareData;
- this.setTitle(fragTitle);
- }
- }
- }
- public void onDialogNegativeClick(ChecklistDialog dialog) {
- }
- /*
- *
- * DIALOG DATA
- *
- * */
- private ArrayList<String> getDialogProtocolDataTitle(){
- ArrayList<String> data = new ArrayList<String>();
- data.add(COMPARE_TITLE_AttacksPerProtocol);
- data.add(COMPARE_TITLE_UsesPerProtocol);
- return data;
- }
- private ArrayList<String> getDialogAttackDataTitle(){
- ArrayList<String> data = new ArrayList<String>();
- data.add(COMPARE_TITLE_AttacksPerDate);
- data.add(COMPARE_TITLE_AttacksPerTime);
- return data;
- }
- private ArrayList<String> getDialogNetworkDataTitle(){
- ArrayList<String> data = new ArrayList<String>();
- data.add(COMPARE_TITLE_AttacksPerESSID);
- data.add(COMPARE_TITLE_AttacksPerBSSID);
- return data;
- }
- private boolean[] selectedData(ArrayList<String> data){
- boolean[] selected = new boolean[data.size()];
- // SET DEFAULT
- selected[0] = true;
- return selected;
- }
- /*
- *
- * FILTER BUTTON
- *
- * */
- private void openFilterMenuOnView(View anchor){
- SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
- public void onItemClick(Object ob) {
- if (ob instanceof AbstractPopupItem){
- AbstractPopupItem item = (AbstractPopupItem) ob;
- StatisticsFragment.this.onFilterMenuItemSelected(item);
- }
- }
- });
- filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
- for(String title : StatisticsFragment.this.filterMenuTitles()){
- AbstractPopupItem item = null;
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) continue;
- if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
- item = new SplitPopupItem(this.getActivity());
- item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
- item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
- if (this.filter.hasBelowTimestamp()){
- item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
- }
- if (this.filter.hasAboveTimestamp()){
- item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
- }
- } else {
- item = new SimplePopupItem(this.getActivity());
- item.setTitle(title);
- ((SimplePopupItem)item).setSelected(this.isFilterSetForTitle(title));
- }
- filterMenu.addItem(item);
- }
- filterMenu.showOnView(anchor);
- }
- private void onFilterMenuItemSelected(AbstractPopupItem item){
- if (item instanceof SplitPopupItem){
- SplitPopupItem sItem = (SplitPopupItem) item;
- this.wasBelowTimePicker = sItem.wasRightTouch;
- if (this.wasBelowTimePicker){
- this.openTimestampToFilterDialog();
- } else {
- this.openTimestampFromFilterDialog();
- }
- return;
- }
- String title = item.getTitle();
- if (title.equals(FILTER_MENU_TITLE_ESSID)){
- this.openESSIDFilterDialog();
- }
- if (title.equals(FILTER_MENU_TITLE_BSSID)){
- this.openBSSIDFilterDialog();
- }
- if (title.equals(FILTER_MENU_TITLE_PROTOCOL)){
- this.openFilterDialogSelectProtocol();
- }
- if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
- this.openProtocolsFilterDialog();
- }
- if (title.equals(FILTER_MENU_TITLE_REMOVE)){
- this.clearFilter();
- this.actualiseCurrentPlot();
- }
- }
- private ArrayList<String> filterMenuTitles(){
- ArrayList<String> titles = new ArrayList<String>();
- if (this.currentPlotView instanceof LineGraph){
- titles.add(FILTER_MENU_TITLE_ESSID);
- titles.add(FILTER_MENU_TITLE_PROTOCOLS);
- titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
- if (this.filter.hasESSIDs() || this.filter.hasATimestamp() || (this.filter.getProtocols() != null && this.filter.hasProtocols() && this.filter.getProtocols().size() != this.protocolTitles().size())){
- titles.add(FILTER_MENU_TITLE_REMOVE);
- }
- } else {
- titles.add(FILTER_MENU_TITLE_PROTOCOL);
- String protocol = this.getCurrentSelectedProtocol();
- if (protocol.length() > 0){
- if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)){
- titles.add(FILTER_MENU_TITLE_BSSID);
- }
- // DEFAULT
- titles.add(FILTER_MENU_TITLE_ESSID);
- }
- titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
- if (this.filter.hasATimestamp() || this.filter.hasESSIDs() || this.filter.hasBSSIDs()
- || (this.currentPlotView instanceof LineGraph && this.filter.hasProtocols())){
- titles.add(FILTER_MENU_TITLE_REMOVE);
- }
- }
- return titles;
- }
- private void openProtocolsFilterDialog(){
- ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS,
- this.protocolTitles(),
- this.selectedProtocols(),
- true ,
- this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_PROTOCOLS);
- }
- private void openFilterDialogSelectProtocol(){
- ArrayList<String> titles = this.protocolTitles();
- boolean[] selected = new boolean[titles.size()];
- int i = 0;
- for (String title : titles){
- selected[i] = title.equals(this.getCurrentSelectedProtocol());
- i++;
- }
- ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE, titles, selected, false , this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_PROTOCOL_SINGLE_CHOICE_TITLE);
- }
- private void openESSIDFilterDialog(){
- ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_ESSID, this.essids(), this.selectedESSIDs(), true , this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
- }
- private void openBSSIDFilterDialog(){
- ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_BSSID, this.bssids(), this.selectedBSSIDs(), true , this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
- }
- private void openTimestampFromFilterDialog(){
- this.wasBelowTimePicker = false;
- DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
- newFragment.setDateChangeListener(this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
- if (this.filter.aboveTimestamp != Long.MIN_VALUE)newFragment.setDate(this.filter.aboveTimestamp);
- }
- private void openTimestampToFilterDialog(){
- this.wasBelowTimePicker = true;
- DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
- newFragment.setDateChangeListener(this);
- newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_TIMESTAMP_BELOW);
- if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
- }
- public ArrayList<String> essids(){
- ArrayList<String> records;
- if (this.currentPlotView instanceof BarGraph){
- records = dbh.getUniqueESSIDRecordsForProtocol(this.getCurrentSelectedProtocol());
- } else {
- records = dbh.getUniqueESSIDRecords();
- }
- return records;
- }
- public boolean[] selectedESSIDs(){
- ArrayList<String> essids = this.essids();
- boolean[] selected = new boolean[essids.size()];
- int i = 0;
- for(String essid : essids){
- selected[i] =(this.filter.getESSIDs().contains(essid));
- i++;
- }
- return selected;
- }
- public ArrayList<String> bssids(){
- ArrayList<String> records ;
- if (this.currentPlotView instanceof BarGraph){
- records = dbh.getUniqueBSSIDRecordsForProtocol(this.getCurrentSelectedProtocol());
- } else {
- records = dbh.getUniqueBSSIDRecords();
- }
- return records;
- }
- public boolean[] selectedBSSIDs(){
- ArrayList<String> bssids = this.bssids();
- boolean[] selected = new boolean[bssids.size()];
- int i = 0;
- for(String bssid : bssids){
- selected[i] =(this.filter.getBSSIDs().contains(bssid));
- i++;
- }
- return selected;
- }
- public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
- if(this.wasBelowTimePicker){
- this.filter.setBelowTimestamp(dialog.getDate());
- } else {
- this.filter.setAboveTimestamp(dialog.getDate());
- }
- this.actualiseCurrentPlot();
- }
- public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
- if(this.wasBelowTimePicker){
- this.filter.setBelowTimestamp(Long.MAX_VALUE);
- } else {
- this.filter.setAboveTimestamp(Long.MIN_VALUE);
- }
- this.actualiseCurrentPlot();
- }
- /*
- *
- * 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);
- this.lineGraph.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT ));
- }
- 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);
- this.barGraph.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT ));
- plotLayout.addView(this.barGraph);
- this.barGraph.setShowBarText(false);
- 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>();
- }
- this.lineGraph.removeAllLines();
- double rangeMax_Y = 0;
- double rangeMin_Y = 0;
- double rangeMax_X = 0;
- double rangeMin_X = 0;
- int count = 0;
- for (PlotComparisonItem lineItem : this.currentData){
- ArrayList<PlotComparisonItem> data = lineItem.getOtherData();
- int index = 0;
- Line l = new Line();
- int lineColor = lineItem.getColor();
- l.setColor(lineColor);
- for (PlotComparisonItem pointItem : data){
- LinePoint p = new LinePoint();
- p.setX(pointItem.getValue1());
- Double value2 = pointItem.getValue2();
- p.setY(value2);
- p.setColor(lineColor);
- l.addPoint(p);
- rangeMax_Y = Math.max(pointItem.getValue2(), rangeMax_Y);
- rangeMax_X = Math.max(pointItem.getValue1(), rangeMax_X);
- if (count != 0){
- rangeMin_Y = Math.min(pointItem.getValue2(), rangeMin_Y);
- rangeMin_X = Math.min(pointItem.getValue1(), rangeMin_X);
- } else {
- rangeMin_Y = pointItem.getValue2();
- rangeMin_X = pointItem.getValue1();
- }
- index++;
- count++;
- }
- this.lineGraph.addLine(l);
- }
- // add a bit more space
- rangeMax_Y++;
- rangeMin_Y--;
- boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
- if (shouldUseDate){
- this.lineGraph.resetXLimits();
- if (this.filter.hasBelowTimestamp()){
- rangeMax_X = Math.max(this.filter.belowTimestamp, rangeMax_X);
- }
- if (this.filter.hasAboveTimestamp()){
- rangeMin_X = Math.min(this.filter.aboveTimestamp, rangeMin_X);
- }
- double stepRange = (rangeMax_X - rangeMin_X)/(60*60*24*1000);
- this.lineGraph.setxAxisStep(Math.max(1, (float) Math.min(stepRange, 4)));
- this.lineGraph.setRangeX(rangeMin_X , rangeMax_X);
- this.lineGraph.setConverter(new LineGraph.AxisDataConverter() {
- @Override
- public String convertDataForX_Position(double x) {
- return StatisticsFragment.this.getDateAsDayString((long)x);
- }
- @Override
- public String convertDataForY_Position(double y){
- return "" + (long)y;
- }
- });
- } else {
- this.lineGraph.setxAxisStep(12.f);
- this.lineGraph.setRangeX(0, 24);
- this.lineGraph.setConverter(null);
- }
- int maxY = (int)(rangeMax_Y - rangeMin_Y);
- this.lineGraph.setYAxisStep(Math.min(maxY, 5));
- int yStep = (int)this.lineGraph.getyAxisStep();
- if ((maxY % yStep) != 0) {
- maxY = maxY + (yStep - (maxY % yStep));
- }
- this.lineGraph.setRangeY(rangeMin_Y, rangeMin_Y + maxY);
- this.lineGraph.setLineToFill(0);
- this.lineGraph.invalidate();
- }
- public void setBarGraphData(BarGraph bargraph){
- this.currentData = this.getBarData();
- 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());
- Long value2 = item.getValue2().longValue();
- d.setName("" + value2);
- d.setValue(value2.floatValue());
- bars.add(d);
- }
- 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(){
- LinearLayout plotLayout = (LinearLayout) this.rootView.findViewById(R.id.plot_layout);
- View plot = this.currentPlotView;
- if (plot == null){
- this.currentPlotView = this.getPieGraphView();
- plot = this.currentPlotView;
- }
- if (plot.getParent() != null && !plot.getParent().equals(plotLayout)){
- LinearLayout linLayout = (LinearLayout)plot.getParent();
- linLayout.removeView(plot);
- plot.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT ));
- plotLayout.addView(plot);
- }
- if (plot.getVisibility() == View.GONE) plot.setVisibility(View.VISIBLE);
- if (plot instanceof PieGraph){
- PieGraph pie = (PieGraph) plot;
- this.setPieGraphData(pie);
- // HIDE FILTER BUTTON
- ImageButton filterButton = this.getFilterButton();
- if (filterButton != null) filterButton.setVisibility(View.GONE);
- } else {
- if (this.pieGraph != null){
- this.pieGraph.setVisibility(View.GONE);
- if (this.pieGraph.getParent() != null){
- plotLayout.removeView(this.pieGraph);
- }
- }
- // SHOW FILTER BUTTON
- ImageButton filterButton = this.getFilterButton();
- if (filterButton != null) filterButton.setVisibility(View.VISIBLE);
- }
- if (plot instanceof BarGraph){
- BarGraph bar = (BarGraph) plot;
- this.setBarGraphData(bar);
- } else {
- if (this.barGraph != null){
- this.barGraph.setVisibility(View.GONE);
- if (this.barGraph.getParent() != null){
- plotLayout.removeView(this.barGraph);
- }
- }
- }
- if (plot instanceof LineGraph){
- LineGraph line = (LineGraph)plot;
- this.setLineGraphData(line);
- }else {
- if (this.lineGraph != null){
- this.lineGraph.setVisibility(View.GONE);
- if (this.lineGraph.getParent() != null){
- plotLayout.removeView(this.lineGraph);
- }
- }
- }
- plot.setVisibility(View.VISIBLE);
- if (plot.getParent() == null){
- plotLayout.addView(plot);
- }
- this.actualiseLegendList();
- this.currentPlotView.bringToFront();
- this.currentPlotView.invalidate();
- }
- public ArrayList<PlotComparisonItem> getPieData(){
- // DEFAULT
- return this.attacksPerProtocols();
- }
- public ArrayList<PlotComparisonItem> getBarData(){
- String protocol = this.getCurrentSelectedProtocol();
- if (protocol.length() > 0){
- if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)){
- return this.attacksPerESSID(protocol);
- }
- // DEFAULT
- return this.attacksPerBSSID(protocol);
- }
- // Nothing available
- return new ArrayList<PlotComparisonItem>();
- }
- public ArrayList<PlotComparisonItem> getLineData(){
- return this.attacksPerTime();
- }
- /*
- * DATA SOURCE
- * */
- /*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);
- if (attacksCount == 0) continue;
- 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);
- }
- /*LINE PLOT DATA*/
- public ArrayList<PlotComparisonItem> attacksPerTime(){
- HashMap<String,HashMap<Long, ArrayList<Record> > > lineMap = new HashMap<String, HashMap<Long, ArrayList<Record>>>();
- boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
- ArrayList<Record> records = this.getFetchedRecords();
- for (Record record : records){
- long timestamp = record.getTimestamp();
- long time = 0;
- if (shouldUseDate){
- time = this.getDateFromMilliseconds(timestamp);
- } else {
- time = this.getDayHourFromDate(timestamp);
- }
- // GET CORRECT MAP
- HashMap<Long, ArrayList<Record> > recordMap;
- String groupKey = record.getSsid();
- if (lineMap.containsKey(groupKey)){
- recordMap = lineMap.get(record.getSsid());
- } else {
- recordMap = new HashMap<Long, ArrayList<Record> >();
- lineMap.put(groupKey, recordMap);
- }
- // GET LIST OF RECORDS
- ArrayList<Record> list;
- if (recordMap.containsKey(time)){
- list = recordMap.get(time);
- } else {
- list = new ArrayList<Record>();
- recordMap.put(time, list);
- }
- list.add(record);
- }
- ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
- int index = 0;
- for (String groupKey : lineMap.keySet()){
- HashMap<Long, ArrayList<Record> > recordMap = lineMap.get(groupKey);
- ArrayList<PlotComparisonItem> singleLineItems = new ArrayList<PlotComparisonItem>();
- int numbOfAttacks = 0;
- for (long time : recordMap.keySet()){
- ArrayList<Record>list = recordMap.get(time);
- if (list.size() == 0) continue;
- PlotComparisonItem item = new PlotComparisonItem(this.getHourAsTimeString(time), 0 , (double)time, (double) list.size());
- singleLineItems.add(item);
- numbOfAttacks +=list.size();
- }
- Collections.sort(singleLineItems, new Comparator<PlotComparisonItem>() {
- @Override
- public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
- return s1.getValue1().compareTo(s2.getValue1());
- }
- });
- double itemValue = (((double)numbOfAttacks / (double)records.size())*100.);
- PlotComparisonItem item = new PlotComparisonItem(groupKey, this.getColor(index), 0., itemValue);
- item.setOtherData(singleLineItems);
- plotItems.add(item);
- index++;
- }
- Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
- @Override
- public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
- return s2.getValue2().compareTo(s1.getValue2());
- }
- });
- return plotItems;
- }
- // BAR PLOT DATA
- public ArrayList<PlotComparisonItem> attacksPerBSSID(String protocol){
- LogFilter filter = new LogFilter();
- ArrayList<String> protocollist = new ArrayList<String>();
- filter.setAboveTimestamp(this.filter.getAboveTimestamp());
- filter.setBelowTimestamp(this.filter.getBelowTimestamp());
- filter.setBSSIDs(this.filter.getBSSIDs());
- 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 = 0;
- if (recordMap.containsKey(record.getBssid())){
- count = recordMap.get(record.getBssid());
- }
- count++;
- recordMap.put(record.getBssid(), count);
- }
- int index = 0;
- for (String key : recordMap.keySet()){
- double value = (double)recordMap.get(key);
- if (value == 0.) continue;
- PlotComparisonItem item = new PlotComparisonItem(key, this.getColor(index), 0., value);
- 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();
- filter.setAboveTimestamp(this.filter.getAboveTimestamp());
- filter.setBelowTimestamp(this.filter.getBelowTimestamp());
- filter.setESSIDs(this.filter.getESSIDs());
- 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 = 0;
- if (recordMap.containsKey(record.getSsid())){
- count = recordMap.get(record.getSsid());
- }
- count++;
- recordMap.put(record.getSsid(), count);
- }
- int index = 0;
- for (String key : recordMap.keySet()){
- double value = (double)recordMap.get(key);
- if (value == 0.) continue;
- PlotComparisonItem item = new PlotComparisonItem(key,this.getColor(index), 0. ,value);
- 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
- * */
- private String getCurrentSelectedProtocol(){
- ArrayList<String> protocolTitles = this.getSelectedProtocolTitles();
- if (protocolTitles != null && protocolTitles.size() != 0){
- return protocolTitles.get(0);
- }
- return this.protocolTitles().get(0);
- }
- 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, 80, 80, 80); // grey
- }
-
- public Integer getColor(int index) {
- return ColorSequenceGenerator.getColorForIndex(index);
- }
- 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.getProtocols() != null && this.filter.hasProtocols() && this.filter.getProtocols().size() != this.protocolTitles().size());
- }
- 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_OF_DAY);
- int min = calendar.get(Calendar.MINUTE);
- return hour;
- }
- public long getDateFromMilliseconds(long timeInMillis){
- long millisInDay = 60 * 60 * 24 * 1000;
- return (timeInMillis / millisInDay) * millisInDay;
- }
- /*
- *
- * */
- private String getHourAsTimeString(long hour) {
- return "" + hour + ":00";
- }
- static final DateFormat dateFormat = new SimpleDateFormat("d.M.yyyy");
- @SuppressLint("SimpleDateFormat")
- private String getDateAsDayString(long timeStamp) {
- try {
- Date netDate = (new Date(timeStamp));
- return dateFormat.format(netDate);
- } catch (Exception ex) {
- return "xx";
- }
- }
- @SuppressLint("SimpleDateFormat")
- private String getDateAsString(long timeStamp) {
- try {
- DateFormat sdf = new SimpleDateFormat("H:mm dd/MM/yyyy");
- Date netDate = (new Date(timeStamp));
- return sdf.format(netDate);
- } catch (Exception ex) {
- return "xx";
- }
- }
- /**
- * USERINTERACTION
- */
- private void userTappedOnLegendItem(int index){
- if (index < this.currentData.size()){
- PlotComparisonItem item = this.currentData.get(index);
- ArrayList<String> selectedData;
- String sortKey = null;
- 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){
- if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)){
- filter.setESSIDs(selectedData);
- sortKey = "ESSID";
- } else {
- filter.setBSSIDs(selectedData);
- sortKey = "BSSID";
- }
- ArrayList<String> currentSelectedProtocol = new ArrayList<String>();
- currentSelectedProtocol.add(this.getCurrentSelectedProtocol());
- filter.setProtocols(currentSelectedProtocol);
- }
- if (this.currentPlotView instanceof LineGraph){
- selectedData = new ArrayList<String>();
- selectedData.add(item.getTitle());
- filter.setESSIDs(selectedData);
- filter.setProtocols(this.filter.getProtocols());
- sortKey = "ESSID";
- }
- if (this.filter.hasATimestamp()){
- filter.setAboveTimestamp(this.filter.getAboveTimestamp());
- filter.setBelowTimestamp(this.filter.getBelowTimestamp());
- }
- this.pushRecordOverviewForFilter(filter, sortKey);
- }
- }
- public void onSliceClick(int index){
- }
- public void onBarClick(int index){
- this.userTappedOnLegendItem(index);
- }
- private void pushRecordOverviewForFilter(LogFilter filter, String sortKey){
- FragmentManager fm = this.getActivity().getFragmentManager();
- if (fm != null){
- RecordOverviewFragment newFragment = new RecordOverviewFragment();
- newFragment.setFilter(filter);
- if (sortKey != null && sortKey.length() != 0) newFragment.setGroupKey(sortKey);
- FragmentTransaction transaction = fm.beginTransaction();
- transaction.replace(R.id.content_frame, newFragment, newFragment.getTag());
- transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
- transaction.addToBackStack(null);
- transaction.commit();
- }
- }
- }
|