From da9bb5044f9b1f5a1bcf759381ac8303db59d11e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 17 Jul 2012 19:57:51 +0200 Subject: [PATCH] Make click events on the profile list available to the Activity If the Activity this fragment is placed in implements the provided interface it is notified about clicks on any of the profiles. --- .../android/ui/VpnProfileListFragment.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java b/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java index 252330b..be0a900 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java +++ b/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java @@ -53,6 +53,14 @@ public class VpnProfileListFragment extends Fragment private VpnProfileDataSource mDataSource; private VpnProfileAdapter mListAdapter; private ListView mListView; + private OnVpnProfileSelectedListener mListener; + + /** + * The activity containing this fragment should implement this interface + */ + public interface OnVpnProfileSelectedListener { + public void onVpnProfileSelected(VpnProfile profile); + } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -62,6 +70,7 @@ public class VpnProfileListFragment extends Fragment mListView = (ListView)view.findViewById(R.id.profile_list); mListView.setEmptyView(view.findViewById(R.id.profile_list_empty)); + mListView.setOnItemClickListener(mVpnProfileClicked); mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mListView.setMultiChoiceModeListener(mVpnProfileSelected); mListView.setAdapter(mListAdapter); @@ -94,6 +103,17 @@ public class VpnProfileListFragment extends Fragment } @Override + public void onAttach(Activity activity) + { + super.onAttach(activity); + + if (activity instanceof OnVpnProfileSelectedListener) + { + mListener = (OnVpnProfileSelectedListener)activity; + } + } + + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.profile_list, menu); @@ -138,6 +158,17 @@ public class VpnProfileListFragment extends Fragment super.onActivityResult(requestCode, resultCode, data); } + private final OnItemClickListener mVpnProfileClicked = new OnItemClickListener() { + @Override + public void onItemClick(AdapterView a, View v, int position, long id) + { + if (mListener != null) + { + mListener.onVpnProfileSelected((VpnProfile)a.getItemAtPosition(position)); + } + } + }; + private final MultiChoiceModeListener mVpnProfileSelected = new MultiChoiceModeListener() { private HashSet mSelected; private MenuItem mEditProfile; -- 2.7.4