////FragmentSettings.java package com.example.josh.x_control; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; public class FragmentSettings extends Fragment { private TextView textServerIP; //TSip private TextView textTcpPort; //TTcpPort private Button buttonSettingsApply; private ImageView TickIP; //info buttons private Button BTcpInfo; private Button BIpInfo; private Button BApplyInfo; private static String TCP_OUT; private static String UDP_OUT; private static String TCP_IN; // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters private String mParam1; private String mParam2; private OnFragmentInteractionListener mListener; public FragmentSettings() { // Required empty public constructor } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @param param1 Parameter 1. * @param param2 Parameter 2. * @return A new instance of fragment FragmentSettings. */ // TODO: Rename and change types and number of parameters public static FragmentSettings newInstance(String param1, String param2) { FragmentSettings fragment = new FragmentSettings(); Bundle args = new Bundle(); args.putString(ARG_PARAM1, param1); args.putString(ARG_PARAM2, param2); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } // setContentView(R.layout.activity_settings); // Intent intent = getView().getIntent();//info I can pass is if an attempt was made to connect and it fails, which port was wrong etc // TCP_OUT = intent.getStringExtra(MainActivity.TCP_OUT_CONNECTION); //UDP_OUT = intent.getStringExtra(MainActivity.UDP_OUT_CONNECTION); //TCP_IN = intent.getStringExtra(MainActivity.TCP_IN_CONNECTION); textServerIP = getView().findViewById(R.id.TSip); textTcpPort = getView().findViewById(R.id.TTcpPort); buttonSettingsApply = getView().findViewById(R.id.BSettingsApply); //TickIP = findViewById(R.id.TickIP); BTcpInfo = getView().findViewById(R.id.BTcpInfo); BIpInfo = getView().findViewById(R.id.BIpInfo); BApplyInfo = getView().findViewById(R.id.BApplyInfo); BTcpInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { createDialog("This port, along with the IP address are the most important, this port must be the same as the *tcp-input-port* which you will have configured on the server it must be between 49152 and 65535"); } }); BIpInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { createDialog("This option is the local IP address that the server can be found at"); } }); BApplyInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { createDialog("Pushing apply, will save the settings you have selected for the next connection "); } }); buttonSettingsApply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String ip = textServerIP.getText().toString(); int tcp_out_port = portStringToInt(textTcpPort); if(ip.length() == 15){ networkConfiguration.setIPAddress(ip); } if(!(tcp_out_port == -1)){ networkConfiguration.setTcpPort(tcp_out_port); } } }); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_settings, container, false); TextView textView = new TextView(getActivity()); textView.setText(R.string.hello_blank_fragment); return textView; } // TODO: Rename method, update argument and hook method into UI event public void onButtonPressed(Uri uri) { if (mListener != null) { mListener.onFragmentInteraction(uri); } } @Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof OnFragmentInteractionListener) { mListener = (OnFragmentInteractionListener) context; } else { throw new RuntimeException(context.toString() + " must implement OnFragmentInteractionListener"); } } @Override public void onDetach() { super.onDetach(); mListener = null; } /** * This interface must be implemented by activities that contain this * fragment to allow an interaction in this fragment to be communicated * to the activity and potentially other fragments contained in that * activity. *

* See the Android Training lesson Communicating with Other Fragments for more information. */ public interface OnFragmentInteractionListener { // TODO: Update argument type and name void onFragmentInteraction(Uri uri); } private int portStringToInt(TextView port){ if(port.getText().toString().trim().length() <= 0) { return -1; } else{ int x = Integer.parseInt(port.getText().toString()); if(networkConfiguration.isValidPort(x)) return x; else return -1; } } private boolean createDialog(String str){ infoDialog dialog = new infoDialog(); dialog.setInfo(str); //dialog.show(SettingsActivity.getSupportFragmentManager(), "Information Dialog"); return true; } }