package values; import android.content.Context; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import us.keithirwin.tracman.R; /** * A simple {@link Fragment} subclass. * Activities that contain this fragment must implement the * {@link AboutFragment.OnBackButtonPressedListener} interface * to handle interaction events. * Use the {@link AboutFragment#newInstance} factory method to * create an instance of this fragment. */ public class AboutFragment extends Fragment { private OnBackButtonPressedListener mListener; /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @return A new instance of fragment AboutFragment. */ public static AboutFragment newInstance() { AboutFragment fragment = new AboutFragment(); return fragment; } public AboutFragment() {} @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActivity().setTitle(R.string.about_name); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_about, container, false); TextView tv = (TextView) view.findViewById(R.id.about_license); tv.setMovementMethod(LinkMovementMethod.getInstance()); view.findViewById(R.id.about_back_button).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); return view; } public void goBack() { if (mListener != null) { mListener.goBack(); } } @Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof OnBackButtonPressedListener) { mListener = (OnBackButtonPressedListener) 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 OnBackButtonPressedListener { void goBack(); } }