From: Tobias Brunner Date: Wed, 7 Nov 2012 15:02:21 +0000 (+0100) Subject: android: Attribute added to display the list of VPN profiles in read-only mode X-Git-Tag: 5.0.2dr4~177 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7241102acefc1566071771cee1f7c76ec2fda1b1;p=thirdparty%2Fstrongswan.git android: Attribute added to display the list of VPN profiles in read-only mode --- diff --git a/src/frontends/android/res/values/attrs.xml b/src/frontends/android/res/values/attrs.xml new file mode 100644 index 0000000000..6c3480b0e0 --- /dev/null +++ b/src/frontends/android/res/values/attrs.xml @@ -0,0 +1,20 @@ + + + + + + + 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 1052558f23..fb684b53da 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java +++ b/src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java @@ -30,7 +30,9 @@ import android.app.Activity; import android.app.Fragment; import android.content.Context; import android.content.Intent; +import android.content.res.TypedArray; import android.os.Bundle; +import android.util.AttributeSet; import android.view.ActionMode; import android.view.LayoutInflater; import android.view.Menu; @@ -54,6 +56,7 @@ public class VpnProfileListFragment extends Fragment private VpnProfileAdapter mListAdapter; private ListView mListView; private OnVpnProfileSelectedListener mListener; + private boolean mReadOnly; /** * The activity containing this fragment should implement this interface @@ -62,6 +65,15 @@ public class VpnProfileListFragment extends Fragment public void onVpnProfileSelected(VpnProfile profile); } + @Override + public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) + { + super.onInflate(activity, attrs, savedInstanceState); + TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.Fragment); + mReadOnly = a.getBoolean(R.styleable.Fragment_read_only, false); + a.recycle(); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) @@ -69,12 +81,15 @@ public class VpnProfileListFragment extends Fragment View view = inflater.inflate(R.layout.profile_list_fragment, null); mListView = (ListView)view.findViewById(R.id.profile_list); + mListView.setAdapter(mListAdapter); 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); + if (!mReadOnly) + { + mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); + mListView.setMultiChoiceModeListener(mVpnProfileSelected); + } return view; } @@ -82,7 +97,17 @@ public class VpnProfileListFragment extends Fragment public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setHasOptionsMenu(true); + + Bundle args = getArguments(); + if (args != null) + { + mReadOnly = args.getBoolean("read_only", mReadOnly); + } + + if (!mReadOnly) + { + setHasOptionsMenu(true); + } Context context = getActivity().getApplicationContext();