SettingsFragment.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package de.tudarmstadt.informatik.hostage.ui2.fragment;
  2. import android.app.AlertDialog;
  3. import android.app.DownloadManager;
  4. import android.app.Fragment;
  5. import android.app.FragmentManager;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.content.Intent;
  9. import android.net.Uri;
  10. import android.os.Bundle;
  11. import android.os.Environment;
  12. import android.util.Log;
  13. import android.view.LayoutInflater;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.widget.TextView;
  17. import de.tudarmstadt.informatik.hostage.Hostage;
  18. import de.tudarmstadt.informatik.hostage.R;
  19. import de.tudarmstadt.informatik.hostage.system.Device;
  20. import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
  21. /**
  22. * Creates the view to edit the preferences of the app and shows the porthack and rooted state of the device
  23. *
  24. * @author Alexander Brakowski
  25. * @created 24.02.14 23:37
  26. */
  27. public class SettingsFragment extends UpNavigatibleFragment {
  28. /**
  29. * {@inheritDoc}
  30. */
  31. @Override
  32. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  33. super.onCreateView(inflater, container, savedInstanceState);
  34. getActivity().setTitle(getResources().getString(R.string.drawer_settings));
  35. View v = inflater.inflate(R.layout.fragment_settings, container, false);
  36. TextView rootedText = (TextView) v.findViewById(R.id.settings_device_rooted);
  37. TextView porthackText = (TextView) v.findViewById(R.id.settings_porthack_installed);
  38. if (Device.isRooted()) {
  39. rootedText.setText(R.string.yes);
  40. rootedText.setTextColor(getResources().getColor(R.color.holo_dark_green));
  41. } else {
  42. rootedText.setText(R.string.no);
  43. rootedText.setTextColor(getResources().getColor(R.color.holo_red));
  44. }
  45. if (Device.isPorthackInstalled()) {
  46. porthackText.setText(R.string.yes);
  47. porthackText.setTextColor(getResources().getColor(R.color.holo_dark_green));
  48. } else {
  49. porthackText.setText(R.string.no);
  50. porthackText.setTextColor(getResources().getColor(R.color.holo_red));
  51. }
  52. //Allow no porthack text box clickable
  53. if (Device.isRooted() && !Device.isPorthackInstalled())
  54. {
  55. porthackText.setOnClickListener(new View.OnClickListener() {
  56. @Override
  57. public void onClick(View arg0) {
  58. new AlertDialog.Builder(getActivity())
  59. .setTitle(R.string.information)
  60. .setMessage(R.string.no_portbinder_msg)
  61. .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
  62. public void onClick(DialogInterface dialog, int which) {
  63. }
  64. })
  65. .setNegativeButton(R.string.help, new DialogInterface.OnClickListener() {
  66. public void onClick(DialogInterface dialog, int which) {
  67. dialog.dismiss();
  68. final AlertDialog alert;
  69. new AlertDialog.Builder(getActivity())
  70. .setTitle(R.string.portbinder)
  71. .setMessage(R.string.helpPortbinder)
  72. .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
  73. public void onClick(DialogInterface dialog, int which) {
  74. }
  75. })
  76. .setNeutralButton(R.string.portbinder_tutorial, new DialogInterface.OnClickListener() {
  77. public void onClick(DialogInterface dialog, int which) {
  78. Uri uri = Uri.parse("https://www.youtube.com/watch?v=gi6fSiIJASk");
  79. Intent intent = new Intent(Intent.ACTION_VIEW, uri);
  80. startActivity(intent);
  81. }
  82. })
  83. .setNegativeButton(R.string.portbinder_website, new DialogInterface.OnClickListener() {
  84. public void onClick(DialogInterface dialog, int which) {
  85. Uri uri = Uri.parse("https://www.tk.informatik.tu-darmstadt.de/de/research/secure-smart-infrastructures/hostage/");
  86. Intent intent = new Intent(Intent.ACTION_VIEW, uri);
  87. startActivity(intent);
  88. }
  89. })
  90. .setIcon(android.R.drawable.ic_dialog_info).show();
  91. }
  92. })
  93. .setIcon(android.R.drawable.ic_dialog_info).show();}
  94. });
  95. }
  96. return v;
  97. }
  98. /**
  99. * {@inheritDoc}
  100. */
  101. @Override
  102. public void onViewCreated(View view, Bundle savedInstanceState) {
  103. super.onViewCreated(view, savedInstanceState);
  104. FragmentManager manager = this.getFragmentManager();
  105. manager.beginTransaction().replace(R.id.settings_fragment_container, new PreferenceHostageFrament()).commit();
  106. }
  107. }