android: Attribute added to display the list of VPN profiles in read-only mode
This commit is contained in:
@@ -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>
|
||||||
@@ -30,7 +30,9 @@ import android.app.Activity;
|
|||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.AttributeSet;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -54,6 +56,7 @@ public class VpnProfileListFragment extends Fragment
|
|||||||
private VpnProfileAdapter mListAdapter;
|
private VpnProfileAdapter mListAdapter;
|
||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
private OnVpnProfileSelectedListener mListener;
|
private OnVpnProfileSelectedListener mListener;
|
||||||
|
private boolean mReadOnly;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The activity containing this fragment should implement this interface
|
* The activity containing this fragment should implement this interface
|
||||||
@@ -62,6 +65,15 @@ public class VpnProfileListFragment extends Fragment
|
|||||||
public void onVpnProfileSelected(VpnProfile profile);
|
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
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState)
|
Bundle savedInstanceState)
|
||||||
@@ -69,12 +81,15 @@ public class VpnProfileListFragment extends Fragment
|
|||||||
View view = inflater.inflate(R.layout.profile_list_fragment, null);
|
View view = inflater.inflate(R.layout.profile_list_fragment, null);
|
||||||
|
|
||||||
mListView = (ListView)view.findViewById(R.id.profile_list);
|
mListView = (ListView)view.findViewById(R.id.profile_list);
|
||||||
|
mListView.setAdapter(mListAdapter);
|
||||||
mListView.setEmptyView(view.findViewById(R.id.profile_list_empty));
|
mListView.setEmptyView(view.findViewById(R.id.profile_list_empty));
|
||||||
mListView.setOnItemClickListener(mVpnProfileClicked);
|
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;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +97,17 @@ public class VpnProfileListFragment extends Fragment
|
|||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(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();
|
Context context = getActivity().getApplicationContext();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user