]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Attribute added to display the list of VPN profiles in read-only mode
authorTobias Brunner <tobias@strongswan.org>
Wed, 7 Nov 2012 15:02:21 +0000 (16:02 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 21 Nov 2012 17:57:40 +0000 (18:57 +0100)
src/frontends/android/res/values/attrs.xml [new file with mode: 0644]
src/frontends/android/src/org/strongswan/android/ui/VpnProfileListFragment.java

diff --git a/src/frontends/android/res/values/attrs.xml b/src/frontends/android/res/values/attrs.xml
new file mode 100644 (file)
index 0000000..6c3480b
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2012 Tobias Brunner
+    Hochschule fuer Technik Rapperswil
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+-->
+<resources>
+    <declare-styleable name="Fragment">
+        <attr name="read_only" format="boolean" />
+    </declare-styleable>
+</resources>
index 1052558f2366d44dcb39d684c9477c0a0290c07c..fb684b53dafed08d1fa34df817c2de2beee952f0 100644 (file)
@@ -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();