RecordOverviewFragment.java 44 KB

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