RecordOverviewFragment.java 44 KB

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