package de.tudarmstadt.informatik.hostage.ui2.fragment; import android.app.AlertDialog; import android.app.DownloadManager; import android.app.Fragment; import android.app.FragmentManager; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import de.tudarmstadt.informatik.hostage.Hostage; import de.tudarmstadt.informatik.hostage.R; import de.tudarmstadt.informatik.hostage.system.Device; import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity; /** * Creates the view to edit the preferences of the app and shows the porthack and rooted state of the device * * @author Alexander Brakowski * @created 24.02.14 23:37 */ public class SettingsFragment extends UpNavigatibleFragment { /** * {@inheritDoc} */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); getActivity().setTitle(getResources().getString(R.string.drawer_settings)); View v = inflater.inflate(R.layout.fragment_settings, container, false); TextView rootedText = (TextView) v.findViewById(R.id.settings_device_rooted); TextView porthackText = (TextView) v.findViewById(R.id.settings_porthack_installed); if (Device.isRooted()) { rootedText.setText(R.string.yes); rootedText.setTextColor(getResources().getColor(R.color.holo_dark_green)); } else { rootedText.setText(R.string.no); rootedText.setTextColor(getResources().getColor(R.color.holo_red)); } if (Device.isPorthackInstalled()) { porthackText.setText(R.string.yes); porthackText.setTextColor(getResources().getColor(R.color.holo_dark_green)); } else { porthackText.setText(R.string.no); porthackText.setTextColor(getResources().getColor(R.color.holo_red)); } //Allow no porthack text box clickable if (Device.isRooted() && !Device.isPorthackInstalled()) { porthackText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { new AlertDialog.Builder(getActivity()) .setTitle(R.string.information) .setMessage(R.string.no_portbinder_msg) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton(R.string.help, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); final AlertDialog alert; new AlertDialog.Builder(getActivity()) .setTitle(R.string.portbinder) .setMessage(R.string.helpPortbinder) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }) .setNeutralButton(R.string.portbinder_tutorial, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Uri uri = Uri.parse("https://www.youtube.com/watch?v=gi6fSiIJASk"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }) .setNegativeButton(R.string.portbinder_website, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Uri uri = Uri.parse("https://www.tk.informatik.tu-darmstadt.de/de/research/secure-smart-infrastructures/hostage/"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }) .setIcon(android.R.drawable.ic_dialog_info).show(); } }) .setIcon(android.R.drawable.ic_dialog_info).show();} }); } return v; } /** * {@inheritDoc} */ @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); FragmentManager manager = this.getFragmentManager(); manager.beginTransaction().replace(R.id.settings_fragment_container, new PreferenceHostageFrament()).commit(); } }