RecordOverviewFragment.java 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. package de.tudarmstadt.informatik.hostage.ui2.fragment;
  2. import android.annotation.SuppressLint;
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.app.FragmentManager;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.content.Intent;
  9. import android.content.SharedPreferences;
  10. import android.os.Bundle;
  11. import android.os.Environment;
  12. import android.preference.PreferenceManager;
  13. import android.util.Log;
  14. import android.view.LayoutInflater;
  15. import android.view.Menu;
  16. import android.view.MenuInflater;
  17. import android.view.MenuItem;
  18. import android.view.View;
  19. import android.view.ViewGroup;
  20. import android.widget.ExpandableListView;
  21. import android.widget.ImageButton;
  22. import android.widget.ProgressBar;
  23. import android.widget.Toast;
  24. import com.google.android.gms.maps.model.LatLng;
  25. import java.io.File;
  26. import java.io.FileOutputStream;
  27. import java.text.DateFormat;
  28. import java.text.SimpleDateFormat;
  29. import java.util.ArrayList;
  30. import java.util.Calendar;
  31. import java.util.Collections;
  32. import java.util.Comparator;
  33. import java.util.Date;
  34. import java.util.HashMap;
  35. import java.util.Random;
  36. import de.tudarmstadt.informatik.hostage.R;
  37. import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
  38. import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
  39. import de.tudarmstadt.informatik.hostage.logging.LogExport;
  40. import de.tudarmstadt.informatik.hostage.logging.MessageRecord;
  41. import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
  42. import de.tudarmstadt.informatik.hostage.logging.Record;
  43. import de.tudarmstadt.informatik.hostage.logging.formatter.TraCINgFormatter;
  44. import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
  45. import de.tudarmstadt.informatik.hostage.sync.bluetooth.BluetoothSyncActivity;
  46. import de.tudarmstadt.informatik.hostage.sync.nfc.NFCSync;
  47. import de.tudarmstadt.informatik.hostage.sync.tracing.TracingSyncActivity;
  48. import de.tudarmstadt.informatik.hostage.ui.LogFilter;
  49. import de.tudarmstadt.informatik.hostage.ui.LogFilter.SortType;
  50. import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
  51. import de.tudarmstadt.informatik.hostage.ui2.adapter.RecordListAdapter;
  52. import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
  53. import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
  54. import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
  55. import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopup;
  56. import de.tudarmstadt.informatik.hostage.ui2.popup.AbstractPopupItem;
  57. import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupItem;
  58. import de.tudarmstadt.informatik.hostage.ui2.popup.SimplePopupTable;
  59. import de.tudarmstadt.informatik.hostage.ui2.popup.SplitPopupItem;
  60. public class RecordOverviewFragment extends UpNavigatibleFragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
  61. static final String FILTER_MENU_TITLE_BSSID = "BSSID";
  62. static final String FILTER_MENU_TITLE_ESSID = "ESSID";
  63. static final String FILTER_MENU_TITLE_PROTOCOLS = MainActivity.getContext().getString(R.string.rec_protocol);
  64. static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = MainActivity.getContext().getString(
  65. R.string.rec_latest);
  66. static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = MainActivity.getContext().getString(
  67. R.string.rec_earliest);
  68. static final String FILTER_MENU_TITLE_SORTING = MainActivity.getContext().getString(R.string.rec_sortby);
  69. static final String FILTER_MENU_TITLE_REMOVE = MainActivity.getContext().getString(R.string.rec_reset_filter);
  70. static final String FILTER_MENU_TITLE_GROUP = MainActivity.getContext().getString(
  71. R.string.rec_group_by);
  72. static final String FILTER_MENU_POPUP_TITLE = MainActivity.getContext().getString(
  73. R.string.rec_filter_by);
  74. private boolean wasBelowTimePicker;
  75. private LogFilter filter;
  76. private boolean showFilterButton;
  77. private View rootView;
  78. private int mListPosition = -1;
  79. private int mItemPosition = -1;
  80. public String groupingKey;
  81. private ExpandableListView expListView;
  82. private ProgressBar spinner;
  83. private Toast noDataNotificationToast;
  84. HostageDBOpenHelper dbh;
  85. private String sectionToOpen = "";
  86. private ArrayList<Integer> openSections;
  87. private SharedPreferences pref;
  88. public void setFilter(LogFilter filter){
  89. this.filter = filter;
  90. }
  91. Thread loader;
  92. public RecordOverviewFragment(){}
  93. public void setGroupKey(String key){
  94. this.groupingKey = key;
  95. }
  96. @Override
  97. public void onCreate(Bundle savedInstanceState) {
  98. super.onCreate(savedInstanceState);
  99. setHasOptionsMenu(true);
  100. }
  101. @Override
  102. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  103. Bundle savedInstanceState) {
  104. setHasOptionsMenu(true);
  105. getActivity().setTitle(getResources().getString(R.string.drawer_records));
  106. dbh = new HostageDBOpenHelper(this.getActivity().getBaseContext());
  107. pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
  108. //this.addRecordToDB(5, 2);
  109. // Get the message from the intent
  110. if (this.filter == null){
  111. Intent intent = this.getActivity().getIntent();
  112. LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
  113. if(filter == null){
  114. this.clearFilter();
  115. } else {
  116. this.filter = filter;
  117. }
  118. }
  119. if (this.groupingKey == null) this.groupingKey = this.groupingTitles().get(0);
  120. this.setShowFilterButton(!this.filter.isNotEditable());
  121. View rootView = inflater.inflate(this.getLayoutId(), container, false);
  122. this.rootView = rootView;
  123. ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
  124. this.spinner =(ProgressBar) rootView.findViewById(R.id.progressBar1);
  125. this.spinner.setVisibility(View.GONE);
  126. this.expListView = mylist;
  127. this.initialiseListView();
  128. ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
  129. filterButton.setOnClickListener(new View.OnClickListener() {
  130. public void onClick(View v) {
  131. RecordOverviewFragment.this.openFilterPopupMenuOnView(v);
  132. }
  133. });
  134. filterButton.setVisibility(this.showFilterButton? View.VISIBLE : View.INVISIBLE);
  135. ImageButton sortButton = (ImageButton) rootView.findViewById(R.id.SortButton);
  136. sortButton.setOnClickListener(new View.OnClickListener() {
  137. public void onClick(View v) {
  138. // Open SortMenu
  139. RecordOverviewFragment.this.openSortingDialog();
  140. }
  141. });
  142. ImageButton groupButton = (ImageButton) rootView.findViewById(R.id.GroupButton);
  143. groupButton.setOnClickListener(new View.OnClickListener() {
  144. public void onClick(View v) {
  145. // Open SortMenu
  146. RecordOverviewFragment.this.openGroupingDialog();
  147. }
  148. });
  149. return rootView;
  150. }
  151. /**Initialises the expandable list view in a backgorund thread*/
  152. private void initialiseListView(){
  153. if (loader != null) loader.interrupt();
  154. this.spinner.setVisibility(View.VISIBLE);
  155. loader = new Thread(new Runnable(){
  156. private void updateUI(final RecordListAdapter currentAdapter)
  157. {
  158. if(loader.isInterrupted()){
  159. return;
  160. }
  161. Activity activity = RecordOverviewFragment.this.getActivity();
  162. if (activity != null){
  163. activity.runOnUiThread(new Runnable() {
  164. @Override
  165. public void run() {
  166. RecordOverviewFragment.this.expListView.setAdapter(currentAdapter);
  167. // Update view and remove loading spinner etc...
  168. RecordListAdapter adapter = (RecordListAdapter) RecordOverviewFragment.this.expListView.getExpandableListAdapter();
  169. if (adapter != null){
  170. adapter.notifyDataSetChanged();
  171. if (adapter.getGroupCount() == 1){
  172. RecordOverviewFragment.this.expListView.expandGroup(0);
  173. } else {
  174. RecordOverviewFragment.this.setSectionToOpen(RecordOverviewFragment.this.sectionToOpen);
  175. }
  176. }
  177. if (RecordOverviewFragment.this.openSections != null && RecordOverviewFragment.this.openSections.size() != 0){
  178. for (int i = 0; i < RecordOverviewFragment.this.openSections.size(); i++){
  179. int index = RecordOverviewFragment.this.openSections.get(i);
  180. RecordOverviewFragment.this.expListView.expandGroup(index);
  181. }
  182. } else {
  183. RecordOverviewFragment.this.openSections = new ArrayList<Integer>();
  184. }
  185. if (mListPosition != -1 && mItemPosition != -1)
  186. RecordOverviewFragment.this.expListView.setSelectedChild(mListPosition, mItemPosition, true);
  187. mListPosition = -1;
  188. mItemPosition = -1;
  189. registerListClickCallback(RecordOverviewFragment.this.expListView);
  190. RecordOverviewFragment.this.spinner.setVisibility(View.GONE);
  191. RecordOverviewFragment.this.actualiseFilterButton();
  192. RecordOverviewFragment.this.showEmptyDataNotification();
  193. }
  194. });
  195. }
  196. }
  197. private RecordListAdapter doInBackground()
  198. {
  199. return populateListViewFromDB(RecordOverviewFragment.this.expListView);
  200. }
  201. @Override
  202. public void run()
  203. {
  204. //RecordOverviewFragment.this.addRecordToDB(5, 10);
  205. updateUI(doInBackground());
  206. }
  207. });
  208. loader.start();
  209. this.actualiseFilterButton();
  210. }
  211. /**
  212. * Returns the Fragment layout ID
  213. * @return int The fragment layout ID
  214. * */
  215. public int getLayoutId(){
  216. return R.layout.fragment_record_list;
  217. }
  218. /**
  219. * Gets called if the user clicks on item in the filter menu.
  220. *
  221. * @param item {@link AbstractPopupItem AbstractPopupItem }
  222. * */
  223. public void onFilterMenuItemSelected(AbstractPopupItem item) {
  224. String title = item.getTitle();
  225. if (item instanceof SplitPopupItem){
  226. SplitPopupItem splitItem = (SplitPopupItem)item;
  227. if (splitItem.wasRightTouch){
  228. this.openTimestampToFilterDialog();
  229. } else {
  230. this.openTimestampFromFilterDialog();
  231. }
  232. return;
  233. }
  234. if (title != null){
  235. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  236. this.openBSSIDFilterDialog();
  237. }
  238. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  239. this.openESSIDFilterDialog();
  240. }
  241. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  242. this.openProtocolsFilterDialog();
  243. }
  244. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  245. this.openSortingDialog();
  246. }
  247. if(title.equals(FILTER_MENU_TITLE_REMOVE)){
  248. this.clearFilter();
  249. this.actualiseListViewInBackground();
  250. }
  251. if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  252. this.openTimestampToFilterDialog();
  253. }
  254. if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  255. this.openTimestampFromFilterDialog();
  256. }
  257. }
  258. //return super.onOptionsItemSelected(item);
  259. }
  260. @Override
  261. public void onStart() {
  262. super.onStart();
  263. if (this.expListView.getExpandableListAdapter() != null){
  264. if (this.expListView.getExpandableListAdapter().getGroupCount() == 1){
  265. this.expListView.expandGroup(0);
  266. } else {
  267. this.setSectionToOpen(this.sectionToOpen);
  268. }
  269. }
  270. }
  271. @Override
  272. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  273. // Inflate the menu items for use in the action bar
  274. inflater.inflate(R.menu.records_overview_actions, menu);
  275. }
  276. @Override
  277. public boolean onOptionsItemSelected(MenuItem item) {
  278. switch (item.getItemId()) {
  279. case R.id.records_action_synchronize:
  280. AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
  281. builder.setTitle("Synchronize records");
  282. builder.setItems(new String[]{
  283. "Via Bluetooth",
  284. "Via NFC",
  285. "Via Online Database"
  286. }, new DialogInterface.OnClickListener() {
  287. @Override
  288. public void onClick(DialogInterface dialog, int position) {
  289. switch(position){
  290. case 0:
  291. getActivity().startActivity(new Intent(getActivity(), BluetoothSyncActivity.class));
  292. break;
  293. case 1:
  294. getActivity().startActivity(new Intent(getActivity(), NFCSync.class));
  295. break;
  296. case 2:
  297. getActivity().startActivity(new Intent(getActivity(), TracingSyncActivity.class));
  298. break;
  299. }
  300. }
  301. });
  302. builder.create();
  303. builder.show();
  304. return true;
  305. case R.id.records_action_export:
  306. AlertDialog.Builder builderExport = new AlertDialog.Builder(getActivity());
  307. builderExport.setTitle("Choose export format");
  308. builderExport.setItems(R.array.format, new DialogInterface.OnClickListener() {
  309. @Override
  310. public void onClick(DialogInterface dialog, int position) {
  311. //RecordOverviewFragment.this.exportDatabase(position);
  312. Intent intent = new Intent(getActivity(), LogExport.class);
  313. intent.setAction(LogExport.ACTION_EXPORT_DATABASE);
  314. intent.putExtra(LogExport.FORMAT_EXPORT_DATABASE, position);
  315. RecordOverviewFragment.this.getActivity().startService(intent);
  316. }
  317. });
  318. builderExport.create();
  319. builderExport.show();
  320. return true;
  321. }
  322. return false;
  323. }
  324. /*****************************
  325. *
  326. * Public API
  327. *
  328. * ***************************/
  329. /**
  330. * Group records by SSID and expand given SSID
  331. *
  332. * @param SSID the SSID
  333. */
  334. public void showDetailsForSSID(Context context, String SSID) {
  335. Log.e("RecordOverviewFragment", "Implement showDetailsForSSID!!");
  336. this.clearFilter();
  337. int ESSID_INDEX = 2;
  338. ArrayList<String> ssids = new ArrayList<String>();
  339. this.sectionToOpen = SSID;
  340. this.groupingKey = this.groupingTitles(context).get(ESSID_INDEX);
  341. }
  342. /*****************************
  343. *
  344. * ListView Stuff
  345. *
  346. * ***************************/
  347. /**
  348. * Reloads the data in the ExpandableListView for the given filter object.
  349. * @param mylist {@link ExpandableListView ExpandableListView}
  350. * */
  351. private RecordListAdapter populateListViewFromDB(ExpandableListView mylist) {
  352. HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
  353. ArrayList<Record> data = dbh.getRecordsForFilter(RecordOverviewFragment.this.filter);
  354. // Adding Items to ListView
  355. String keys[] = new String[] { RecordOverviewFragment.this.getString(R.string.RecordBSSID), RecordOverviewFragment.this.getString(R.string.RecordSSID), RecordOverviewFragment.this.getString(R.string.RecordProtocol), RecordOverviewFragment.this.getString(R.string.RecordTimestamp)};
  356. int ids[] = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
  357. HashMap<String, Integer> mapping = new HashMap<String, Integer>();
  358. int i = 0;
  359. for(String key : keys){
  360. mapping.put(key, ids[i]);
  361. i++;
  362. }
  363. ArrayList<String>groupTitle = new ArrayList<String>();
  364. for (Record val : data) {
  365. // DO GROUPING IN HERE
  366. HashMap<String, String> map = new HashMap<String, String>();
  367. map.put(RecordOverviewFragment.this.getString(R.string.RecordBSSID), val.getBssid());
  368. map.put(RecordOverviewFragment.this.getString(R.string.RecordSSID), val.getSsid());
  369. map.put(RecordOverviewFragment.this.getString(R.string.RecordProtocol), val.getProtocol());
  370. map.put(RecordOverviewFragment.this.getString(R.string.RecordTimestamp),
  371. RecordOverviewFragment.this.getDateAsString(val.getTimestamp()));
  372. ExpandableListItem item = new ExpandableListItem();
  373. item.setData(map);
  374. item.setId_Mapping(mapping);
  375. item.setTag(val.getAttack_id());
  376. String groupID = RecordOverviewFragment.this.getGroupValue(val);
  377. ArrayList<ExpandableListItem> items = sectionData.get(groupID);
  378. if (items == null) {
  379. items = new ArrayList<ExpandableListItem>();
  380. sectionData.put(groupID, items);
  381. groupTitle.add(groupID);
  382. }
  383. items.add(item);
  384. }
  385. Collections.sort(groupTitle, new Comparator<String>() {
  386. @Override
  387. public int compare(String s1, String s2) {
  388. return s1.compareToIgnoreCase(s2);
  389. }
  390. });
  391. RecordListAdapter adapter = null;
  392. if (mylist.getAdapter() != null && mylist.getAdapter() instanceof RecordListAdapter){
  393. adapter = (RecordListAdapter) mylist.getAdapter();
  394. adapter.setData(sectionData);
  395. adapter.setSectionHeader(groupTitle);
  396. } else {
  397. adapter = new RecordListAdapter( RecordOverviewFragment.this.getApplicationContext(), groupTitle, sectionData);
  398. }
  399. return adapter;
  400. }
  401. /**
  402. * Actualises the list in a background thread
  403. */
  404. private void actualiseListViewInBackground(){
  405. if (loader != null && loader.isAlive()) loader.interrupt();
  406. loader = null;
  407. this.spinner.setVisibility(View.VISIBLE);
  408. this.actualiseFilterButton();
  409. loader = new Thread(new Runnable() {
  410. @Override
  411. public void run() {
  412. this.runOnUiThread(this.doInBackground());
  413. }
  414. private RecordListAdapter doInBackground(){
  415. return RecordOverviewFragment.this.populateListViewFromDB(RecordOverviewFragment.this.expListView);
  416. }
  417. private void runOnUiThread(final RecordListAdapter adapter){
  418. Activity actv = RecordOverviewFragment.this.getActivity();
  419. if (actv != null){
  420. actv.runOnUiThread(new Runnable() {
  421. @Override
  422. public void run() {
  423. this.actualiseUI();
  424. }
  425. private void actualiseUI(){
  426. if (adapter != null){
  427. RecordOverviewFragment.this.expListView.setAdapter(adapter);
  428. adapter.notifyDataSetChanged();
  429. RecordOverviewFragment.this.spinner.setVisibility(View.GONE);
  430. }
  431. RecordOverviewFragment.this.showEmptyDataNotification();
  432. }
  433. });
  434. }
  435. }
  436. });
  437. loader.start();
  438. }
  439. /**
  440. * Shows a small toast if the data to show is empty (no records).
  441. */
  442. private void showEmptyDataNotification(){
  443. if (RecordOverviewFragment.this.noDataNotificationToast == null){
  444. RecordOverviewFragment.this.noDataNotificationToast = Toast.makeText(getApplicationContext(), R.string.no_data_notification, Toast.LENGTH_SHORT);
  445. }
  446. RecordListAdapter adapter = (RecordListAdapter) RecordOverviewFragment.this.expListView.getExpandableListAdapter();
  447. if (this.getFilterButton().getVisibility() == View.VISIBLE && this.filter.isSet()){
  448. this.noDataNotificationToast.setText(R.string.no_data_notification);
  449. } else {
  450. this.noDataNotificationToast.setText(R.string.no_data_notification_no_filter);
  451. }
  452. if (adapter == null || adapter.getData().isEmpty())
  453. RecordOverviewFragment.this.noDataNotificationToast.show();
  454. }
  455. /**This will open a section in the ExpandableListView with the same title as the parameter s.
  456. *
  457. * @param s String (the section title to open)
  458. *
  459. * */
  460. private void setSectionToOpen(String s){
  461. this.sectionToOpen = s;
  462. if (this.sectionToOpen != null && this.sectionToOpen.length() != 0){
  463. if (this.getGroupTitles().contains(this.sectionToOpen)){
  464. int section = this.getGroupTitles().indexOf(this.sectionToOpen);
  465. this.expListView.expandGroup(section);
  466. this.sectionToOpen = "";
  467. }
  468. }
  469. }
  470. /**
  471. * Returns the base context.
  472. * @return Context baseContext
  473. * */
  474. private Context getBaseContext(){
  475. return this.getActivity().getBaseContext();
  476. }
  477. /**Returns the application context.
  478. * @return Context application context
  479. * */
  480. private Context getApplicationContext(){
  481. return this.getActivity().getApplicationContext();
  482. }
  483. /**Sets the list view listener on the given ExpandableListView.
  484. *
  485. * @param mylist {@link ExpandableListView ExpandableListView }
  486. * */
  487. private void registerListClickCallback(ExpandableListView mylist) {
  488. mylist.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
  489. @Override
  490. public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i2, long l) {
  491. RecordListAdapter adapter = (RecordListAdapter)expandableListView.getExpandableListAdapter();
  492. ExpandableListItem item = (ExpandableListItem)adapter.getChild(i,i2);
  493. mListPosition = i;
  494. mItemPosition = i2;
  495. HostageDBOpenHelper dbh = new HostageDBOpenHelper(getBaseContext());
  496. Record rec = dbh.getRecordOfAttackId((int) item.getTag());
  497. RecordOverviewFragment.this.pushRecordDetailViewForRecord(rec);
  498. return true;
  499. }
  500. });
  501. mylist.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
  502. @Override
  503. public void onGroupExpand(int i) {
  504. RecordOverviewFragment.this.openSections.add(new Integer(i));
  505. }
  506. });
  507. mylist.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
  508. @Override
  509. public void onGroupCollapse(int i) {
  510. RecordOverviewFragment.this.openSections.remove(new Integer(i));
  511. }
  512. });
  513. }
  514. /*****************************
  515. *
  516. * Date Transform
  517. *
  518. * ***************************/
  519. /**Returns the date format "H:mm d.M.yy" for the given timestamp (long)
  520. * @param timeStamp long */
  521. @SuppressLint("SimpleDateFormat")
  522. private String getDateAsString(long timeStamp) {
  523. try {
  524. DateFormat sdf = new SimpleDateFormat("H:mm d.M.yy");
  525. Date netDate = (new Date(timeStamp));
  526. return sdf.format(netDate);
  527. } catch (Exception ex) {
  528. return "xx";
  529. }
  530. }
  531. /*****************************
  532. *
  533. * Getter / Setter
  534. *
  535. * ***************************/
  536. public boolean isShowFilterButton() {
  537. return showFilterButton;
  538. }
  539. public void setShowFilterButton(boolean showFilterButton) {
  540. this.showFilterButton = showFilterButton;
  541. }
  542. /*****************************
  543. *
  544. * Open Dialog Methods
  545. *
  546. * ***************************/
  547. /**Opens the grouping dialog*/
  548. private void openGroupingDialog(){
  549. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_GROUP, this.groupingTitles(), this.selectedGroup(), false , this);
  550. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_GROUP);
  551. }
  552. /**opens the bssid filter dialog*/
  553. private void openBSSIDFilterDialog(){
  554. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_BSSID,this.bssids(), this.selectedBSSIDs(), true , this);
  555. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
  556. }
  557. /**opens the essid filter dialog*/
  558. private void openESSIDFilterDialog(){
  559. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_ESSID,this.essids(), this.selectedESSIDs(), true , this);
  560. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
  561. }
  562. /**opens the protocol filter dialog*/
  563. private void openProtocolsFilterDialog(){
  564. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS,this.protocolTitles(), this.selectedProtocols(), true , this);
  565. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_PROTOCOLS);
  566. }
  567. /**opens the timestamp filter dialog (minimal timestamp required)*/
  568. private void openTimestampFromFilterDialog(){
  569. this.wasBelowTimePicker = false;
  570. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  571. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  572. if (this.filter.aboveTimestamp != Long.MIN_VALUE)newFragment.setDate(this.filter.aboveTimestamp);
  573. }
  574. /**opens time timestamp filter dialog (maximal timestamp required)*/
  575. private void openTimestampToFilterDialog(){
  576. this.wasBelowTimePicker = true;
  577. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  578. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  579. if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
  580. }
  581. /**opens the sorting dialog*/
  582. private void openSortingDialog(){
  583. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING,this.sortTypeTiles(), this.selectedSorttype(), false , this);
  584. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  585. }
  586. /*****************************
  587. *
  588. * Grouping Stuff
  589. *
  590. * ***************************/
  591. /**returns the group title for the given record. Uses the groupingKey to decied which value of the record should be used.
  592. * @param rec {@link Record Record }
  593. * @return String grouptitle*/
  594. public String getGroupValue(Record rec){
  595. int index = this.groupingTitles().indexOf(this.groupingKey);
  596. switch (index){
  597. case 0:
  598. return rec.getProtocol();
  599. case 1:
  600. return rec.getBssid();
  601. case 2:
  602. return rec.getSsid();
  603. default:
  604. return rec.getProtocol();
  605. }
  606. }
  607. /**Returns the Group titles for the specified grouping key. e.g. groupingKey is "ESSID" it returns all available essids.
  608. * @return ArrayList<String> grouptitles*/
  609. public ArrayList<String> getGroupTitles(){
  610. int index = this.groupingTitles().indexOf(this.groupingKey);
  611. switch (index){
  612. case 0:
  613. return this.protocolTitles();
  614. case 1:
  615. return this.bssids();
  616. case 2:
  617. return this.essids();
  618. default:
  619. return this.protocolTitles();
  620. }
  621. }
  622. /*****************************
  623. *
  624. * Filter Stuff
  625. *
  626. * ***************************/
  627. /**Returns the FilterButton.
  628. * @return ImageButton filterButton*/
  629. private ImageButton getFilterButton(){
  630. return (ImageButton) this.rootView.findViewById(R.id.FilterButton);
  631. }
  632. /**Opens the filter menu on a anchor view. The filter menu will always be on top of the anchor.
  633. * @param v View the anchorView*/
  634. private void openFilterPopupMenuOnView(View v){
  635. SimplePopupTable filterMenu = new SimplePopupTable(this.getActivity(), new AbstractPopup.OnPopupItemClickListener() {
  636. public void onItemClick(Object ob) {
  637. if (ob instanceof AbstractPopupItem){
  638. AbstractPopupItem item = (AbstractPopupItem) ob;
  639. RecordOverviewFragment.this.onFilterMenuItemSelected(item);
  640. }
  641. }
  642. });
  643. filterMenu.setTitle(FILTER_MENU_POPUP_TITLE);
  644. for(String title : RecordOverviewFragment.this.filterMenuTitles()){
  645. AbstractPopupItem item = null;
  646. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)) continue;
  647. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  648. item = new SplitPopupItem(this.getActivity());
  649. item.setValue(SplitPopupItem.RIGHT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  650. item.setValue(SplitPopupItem.LEFT_TITLE, FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  651. if (this.filter.hasBelowTimestamp()){
  652. item.setValue(SplitPopupItem.RIGHT_SUBTITLE, this.getDateAsString(this.filter.belowTimestamp));
  653. }
  654. if (this.filter.hasAboveTimestamp()){
  655. item.setValue(SplitPopupItem.LEFT_SUBTITLE, this.getDateAsString(this.filter.aboveTimestamp));
  656. }
  657. } else {
  658. item = new SimplePopupItem(this.getActivity());
  659. item.setTitle(title);
  660. ((SimplePopupItem)item).setSelected(this.isFilterSetForTitle(title));
  661. }
  662. filterMenu.addItem(item);
  663. }
  664. filterMenu.showOnView(v);
  665. }
  666. /**Returns true if the filter object is set for the given title otherwise false. e.g. the filter object has protocols,
  667. * so the method will return for the title FILTER_MENU_TITLE_PROTOCOLS TRUE.
  668. * @param title String
  669. * @return boolean value
  670. * */
  671. private boolean isFilterSetForTitle(String title){
  672. if (title.equals(FILTER_MENU_TITLE_BSSID)){
  673. return this.filter.hasBSSIDs();
  674. }
  675. if (title.equals(FILTER_MENU_TITLE_ESSID)){
  676. return this.filter.hasESSIDs();
  677. }
  678. if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  679. return this.filter.hasProtocols();
  680. }
  681. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  682. return this.filter.hasBelowTimestamp();
  683. }
  684. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  685. return this.filter.hasAboveTimestamp();
  686. }
  687. return false;
  688. }
  689. /**clears the filter. Does not invoke populatelistview!*/
  690. private void clearFilter(){
  691. if(filter == null) this.filter = new LogFilter();
  692. this.filter.clear();
  693. }
  694. /**Returns all grouping titles
  695. * @param context Context
  696. * @return ArrayList<String> titles*/
  697. public ArrayList<String> groupingTitles(Context context){
  698. ArrayList<String> titles = new ArrayList<String>();
  699. for (String groupTitle : context.getResources().getStringArray(
  700. R.array.Grouping)) {
  701. titles.add(groupTitle);
  702. }
  703. return titles;
  704. }
  705. /**Returns all grouping titles.
  706. * @return ArrayList<String> tiles*/
  707. public ArrayList<String> groupingTitles(){
  708. ArrayList<String> titles = new ArrayList<String>();
  709. for (String groupTitle : this.getResources().getStringArray(
  710. R.array.Grouping)) {
  711. titles.add(groupTitle);
  712. }
  713. return titles;
  714. }
  715. /**
  716. * Returns a bool array. This array is true at the index of the groupingKey in groupingTitles(), otherwise false.
  717. * @return boolean[] selection
  718. * */
  719. public boolean[] selectedGroup(){
  720. ArrayList<String> groups = this.groupingTitles();
  721. boolean[] selected = new boolean[groups.size()];
  722. int i = 0;
  723. for(String group : groups){
  724. selected[i] =(group.equals(this.groupingKey));
  725. i++;
  726. }
  727. return selected;
  728. }
  729. /**Returns all protocol titles / names.
  730. * @return ArrayList<String> protocolTitles
  731. * */
  732. public ArrayList<String> protocolTitles(){
  733. ArrayList<String> titles = new ArrayList<String>();
  734. for (String protocol : this.getResources().getStringArray(
  735. R.array.protocols)) {
  736. titles.add(protocol);
  737. }
  738. return titles;
  739. }
  740. /**Return a boolean array of the selected / filtered protocols. If the filter object has
  741. * an protocol from the protocolTitles() array, the index of it will be true, otherwise false.
  742. * @return boolean[] protocol selection
  743. * */
  744. public boolean[] selectedProtocols(){
  745. ArrayList<String> protocols = this.protocolTitles();
  746. boolean[] selected = new boolean[protocols.size()];
  747. int i = 0;
  748. for(String protocol : protocols){
  749. selected[i] =(this.filter.protocols.contains(protocol));
  750. i++;
  751. }
  752. return selected;
  753. }
  754. /**
  755. * Returns the Sorttype Titles
  756. * @return ArayList<String> Sort type titles
  757. * */
  758. public ArrayList<String> sortTypeTiles(){
  759. ArrayList<String> titles = new ArrayList<String>();
  760. titles.add(MainActivity.getContext().getString(R.string.rec_time));
  761. titles.add(MainActivity.getContext().getString(R.string.rec_protocol));
  762. titles.add(MainActivity.getContext().getString(R.string.BSSID));
  763. titles.add(MainActivity.getContext().getString(R.string.ESSID));
  764. return titles;
  765. }
  766. /**
  767. * Returns an boolean array. The array is true at the index of the selected sort type..
  768. * The index of the selected sort type is the same index in the sortTypeTiles array.
  769. * @return boolean array, length == sortTypeTiles().length
  770. * */
  771. public boolean[] selectedSorttype(){
  772. ArrayList<String> types = this.sortTypeTiles();
  773. boolean[] selected = new boolean[types.size()];
  774. int i = 0;
  775. for(String sorttype : types){
  776. selected[i] =(this.filter.sorttype.toString().equals(sorttype));
  777. i++;
  778. }
  779. return selected;
  780. }
  781. /**
  782. * Returns all unique bssids.
  783. * @return ArrayList<String>
  784. * */
  785. public ArrayList<String> bssids(){
  786. ArrayList<String> records = dbh.getUniqueBSSIDRecords();
  787. return records;
  788. }
  789. /**
  790. * Returns an boolean array. The array is true at the indices of the selected bssids.
  791. * The index of the selected bssid is the same index in the bssids() array.
  792. * @return boolean array, length == bssids().length
  793. * */
  794. public boolean[] selectedBSSIDs(){
  795. ArrayList<String> bssids = this.bssids();
  796. boolean[] selected = new boolean[bssids.size()];
  797. int i = 0;
  798. for(String bssid : bssids){
  799. selected[i] =(this.filter.BSSIDs.contains(bssid));
  800. i++;
  801. }
  802. return selected;
  803. }
  804. /**
  805. * Returns all unique essids.
  806. * @return ArrayList<String>
  807. * */
  808. public ArrayList<String> essids(){
  809. ArrayList<String> records = dbh.getUniqueESSIDRecords();
  810. return records;
  811. }
  812. /**
  813. * Returns an boolean array. The array is true at the indices of the selected essids.
  814. * The index of the selected essid is the same index in the essids() array.
  815. * @return boolean array, length == essids().length
  816. * */
  817. public boolean[] selectedESSIDs(){
  818. ArrayList<String> essids = this.essids();
  819. boolean[] selected = new boolean[essids.size()];
  820. int i = 0;
  821. for(String essid : essids){
  822. selected[i] =(this.filter.ESSIDs.contains(essid));
  823. i++;
  824. }
  825. return selected;
  826. }
  827. /**
  828. * Returns all filter menu titles.
  829. * @return ArrayList<String>
  830. * */
  831. private ArrayList<String> filterMenuTitles(){
  832. ArrayList<String> titles = new ArrayList<String>();
  833. titles.add(FILTER_MENU_TITLE_BSSID);
  834. titles.add(FILTER_MENU_TITLE_ESSID);
  835. titles.add(FILTER_MENU_TITLE_PROTOCOLS);
  836. titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  837. titles.add(FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  838. if (this.filter.isSet())titles.add(FILTER_MENU_TITLE_REMOVE);
  839. return titles;
  840. }
  841. /*****************************
  842. *
  843. * Listener Actions
  844. *
  845. * ***************************/
  846. /**
  847. * Will be called if the users selects a timestamp.
  848. * @param dialog {@link DateTimeDialogFragment DateTimeDialogFragment }
  849. * */
  850. public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
  851. if(this.wasBelowTimePicker){
  852. this.filter.setBelowTimestamp(dialog.getDate());
  853. } else {
  854. this.filter.setAboveTimestamp(dialog.getDate());
  855. }
  856. this.actualiseListViewInBackground();
  857. this.actualiseFilterButton();
  858. }
  859. /**
  860. * Will be called if the users cancels a timestamp selection.
  861. * @param dialog {@link DateTimeDialogFragment DateTimeDialogFragment }
  862. * */
  863. public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
  864. if(this.wasBelowTimePicker){
  865. this.filter.setBelowTimestamp(Long.MAX_VALUE);
  866. } else {
  867. this.filter.setAboveTimestamp(Long.MIN_VALUE);
  868. }
  869. this.actualiseFilterButton();
  870. }
  871. /**
  872. * Will be called if the users clicks the positiv button on a ChechlistDialog.
  873. * @param dialog {@link ChecklistDialog ChecklistDialog }
  874. */
  875. public void onDialogPositiveClick(ChecklistDialog dialog) {
  876. String title = dialog.getTitle();
  877. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  878. ArrayList<String> titles =dialog.getSelectedItemTitles();
  879. if (titles.size() == this.bssids().size()){
  880. this.filter.setBSSIDs(new ArrayList<String>());
  881. } else {
  882. this.filter.setBSSIDs(titles);
  883. }
  884. }
  885. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  886. ArrayList<String> titles =dialog.getSelectedItemTitles();
  887. if (titles.size() == this.essids().size()){
  888. this.filter.setESSIDs(new ArrayList<String>());
  889. } else {
  890. this.filter.setESSIDs(titles);
  891. }
  892. }
  893. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  894. ArrayList<String> protocols = dialog.getSelectedItemTitles();
  895. if (protocols.size() == this.protocolTitles().size()){
  896. this.filter.setProtocols(new ArrayList<String>());
  897. } else {
  898. this.filter.setProtocols(dialog.getSelectedItemTitles());
  899. }
  900. }
  901. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  902. ArrayList<String> titles = dialog.getSelectedItemTitles();
  903. if (titles.size() == 0) return;
  904. String t = titles.get(0);
  905. int sortType = this.sortTypeTiles().indexOf(t);
  906. this.filter.setSorttype(SortType.values()[sortType]);
  907. }
  908. if (title.equals(FILTER_MENU_TITLE_GROUP)){
  909. ArrayList<String> titles = dialog.getSelectedItemTitles();
  910. if (titles.size() == 0) return;
  911. this.groupingKey = titles.get(0);
  912. }
  913. this.actualiseListViewInBackground();
  914. this.actualiseFilterButton();
  915. }
  916. /**Paints the filter button if the current filter object is set.*/
  917. private void actualiseFilterButton(){
  918. if (this.filter.isSet() ){
  919. ImageButton filterButton = this.getFilterButton();
  920. if (filterButton != null){
  921. filterButton.setImageResource(R.drawable.ic_filter_pressed);
  922. filterButton.invalidate();
  923. }
  924. } else {
  925. ImageButton filterButton = this.getFilterButton();
  926. if (filterButton != null){
  927. filterButton.setImageResource(R.drawable.ic_filter);
  928. filterButton.invalidate();
  929. }
  930. }
  931. }
  932. /**
  933. * Will be called if the users clicks the negativ button on a ChechlistDialog.
  934. * @param dialog {@link ChecklistDialog ChecklistDialog }
  935. */
  936. public void onDialogNegativeClick(ChecklistDialog dialog) {}
  937. /*****************************
  938. *
  939. * TEST
  940. *
  941. * ***************************/
  942. /**
  943. * This will clear the database at first and than add new attacks.
  944. * @param createNetworks number of networks to create
  945. * @param attacksPerNetwork maximal number of attack per network
  946. * */
  947. private void addRecordToDB( int createNetworks, int attacksPerNetwork) {
  948. if ((dbh.getRecordCount() > 0)) dbh.clearData();
  949. Calendar cal = Calendar.getInstance();
  950. int maxProtocolsIndex = this.getResources().getStringArray(
  951. R.array.protocols).length;
  952. Random random = new Random();
  953. LatLng tudarmstadtLoc = new LatLng(49.86923, 8.6632768);
  954. final double ssidRadius = 0.1;
  955. final double bssidRadius = 0.004;
  956. int attackId = 0;
  957. for (int numOfNetworks = 0; numOfNetworks < createNetworks; numOfNetworks++){
  958. String ssidName = "WiFi" + ((numOfNetworks) + 1);
  959. String bssidName = "127.0.0." + ((numOfNetworks) + 1);
  960. int protocolIndex = numOfNetworks % maxProtocolsIndex;
  961. String protocolName = this.getResources().getStringArray(
  962. R.array.protocols)[protocolIndex];
  963. int numOfAttackPerNetwork = (Math.abs(random.nextInt()) % attacksPerNetwork) + 1;
  964. NetworkRecord network = new NetworkRecord();
  965. network.setBssid(bssidName);
  966. network.setSsid(ssidName);
  967. LatLng ssidLocation = new LatLng(tudarmstadtLoc.latitude - ssidRadius + 2.0 * ssidRadius * Math.random(), tudarmstadtLoc.longitude - ssidRadius + 2.0 * ssidRadius * Math.random());
  968. double latitude = ssidLocation.latitude - bssidRadius + 2.0 * bssidRadius * Math.random();
  969. double longitude = ssidLocation.longitude - bssidRadius + 2.0 * bssidRadius * Math.random();
  970. long timestamp = cal.getTimeInMillis();
  971. network.setTimestampLocation(timestamp);
  972. network.setLongitude(longitude);
  973. network.setLatitude(latitude);
  974. network.setAccuracy(0.f);
  975. dbh.updateNetworkInformation(network);
  976. // ATTACKS PER NETWORK
  977. for (int attackNumber = 0; attackNumber < numOfAttackPerNetwork; attackNumber++) {
  978. int numRecordsPerAttack = (Math.abs(random.nextInt()) % 5) + 1;
  979. /*
  980. * ADD A ATTACK*/
  981. AttackRecord attack = new AttackRecord();
  982. attack.setAttack_id(attackId);
  983. attack.setBssid(bssidName);
  984. attack.setProtocol(protocolName);
  985. attack.setLocalIP(bssidName);
  986. dbh.addAttackRecord(attack);
  987. // RECORDS PER ATTACK
  988. for (int messageID = attackId; messageID < attackId + numRecordsPerAttack; messageID++) {
  989. MessageRecord message = new MessageRecord();
  990. message.setId(messageID);
  991. message.setAttack_id(attackId);
  992. // GO BACK IN TIME
  993. message.setTimestamp(cal.getTimeInMillis()
  994. - ((messageID * 60 * 60 * 24) * 1000) + (1000 * ((messageID - attackId) + 1)));
  995. if ((messageID - attackId) % 2 == 0){
  996. message.setType(MessageRecord.TYPE.RECEIVE);
  997. } else {
  998. message.setType(MessageRecord.TYPE.SEND);
  999. }
  1000. message.setPacket("");
  1001. dbh.addMessageRecord(message);
  1002. }
  1003. attackId+=numRecordsPerAttack;
  1004. }
  1005. }
  1006. // int countAllLogs = dbh.getAllRecords().size();
  1007. // int countRecords = dbh.getRecordCount();
  1008. // int countAttacks = dbh.getAttackCount();
  1009. //
  1010. // if ((countRecords == 0)) {
  1011. // Record rec = dbh.getRecordOfAttackId(0);
  1012. // Record rec2 = dbh.getRecord(0);
  1013. //
  1014. // System.out.println("" + "Could not create logs!");
  1015. // }
  1016. }
  1017. /**Navigation. Shows the record detail view for the given record
  1018. * @param record {@link Record Record } to show
  1019. * */
  1020. private void pushRecordDetailViewForRecord(Record record){
  1021. FragmentManager fm = this.getActivity().getFragmentManager();
  1022. if (fm != null){
  1023. RecordDetailFragment newFragment = new RecordDetailFragment();
  1024. newFragment.setRecord(record);
  1025. newFragment.setUpNavigatible(true);
  1026. MainActivity.getInstance().injectFragment(newFragment);
  1027. }
  1028. }
  1029. }