diff options
author | Tobias Brunner <tobias@strongswan.org> | 2013-05-30 11:47:01 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2013-07-08 18:49:29 +0200 |
commit | 611d35e8e87ed0bbbcd5ab9ff90522f557ee6dd6 (patch) | |
tree | 2191bd81d454470ea95d09a33b1714273a31f80b /src/frontends | |
parent | b6e05f6518c478a65c219aba08df04e8b0b9cb0c (diff) | |
download | strongswan-611d35e8e87ed0bbbcd5ab9ff90522f557ee6dd6.tar.bz2 strongswan-611d35e8e87ed0bbbcd5ab9ff90522f557ee6dd6.tar.xz |
android: Add fragment for a list of remediation instructions
This fragment can later be used in one- or two-pane layouts.
Diffstat (limited to 'src/frontends')
-rw-r--r-- | src/frontends/android/src/org/strongswan/android/ui/RemediationInstructionsFragment.java | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/src/frontends/android/src/org/strongswan/android/ui/RemediationInstructionsFragment.java b/src/frontends/android/src/org/strongswan/android/ui/RemediationInstructionsFragment.java new file mode 100644 index 000000000..9aa7ea140 --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/ui/RemediationInstructionsFragment.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2013 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. + */ + +package org.strongswan.android.ui; + +import java.util.ArrayList; + +import org.strongswan.android.logic.imc.RemediationInstruction; +import org.strongswan.android.ui.adapter.RemediationInstructionAdapter; + +import android.app.Activity; +import android.app.ListFragment; +import android.os.Bundle; +import android.view.View; +import android.widget.ListView; + +public class RemediationInstructionsFragment extends ListFragment +{ + public static final String EXTRA_REMEDIATION_INSTRUCTIONS = "instructions"; + private static final String KEY_POSITION = "position"; + private ArrayList<RemediationInstruction> mInstructions = null; + private OnRemediationInstructionSelectedListener mListener; + private RemediationInstructionAdapter mAdapter; + private int mCurrentPosition = -1; + + /** + * The activity containing this fragment should implement this interface + */ + public interface OnRemediationInstructionSelectedListener + { + public void onRemediationInstructionSelected(RemediationInstruction instruction); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) + { + super.onActivityCreated(savedInstanceState); + + if (savedInstanceState != null) + { + mInstructions = savedInstanceState.getParcelableArrayList(EXTRA_REMEDIATION_INSTRUCTIONS); + mCurrentPosition = savedInstanceState.getInt(KEY_POSITION); + } + } + + @Override + public void onSaveInstanceState(Bundle outState) + { + super.onSaveInstanceState(outState); + outState.putParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS, mInstructions); + outState.putInt(KEY_POSITION, mCurrentPosition); + } + + @Override + public void onAttach(Activity activity) + { + super.onAttach(activity); + + if (activity instanceof OnRemediationInstructionSelectedListener) + { + mListener = (OnRemediationInstructionSelectedListener)activity; + } + } + + @Override + public void onStart() + { + super.onStart(); + + boolean two_pane = false; + if (two_pane) + { /* two-pane layout, make list items selectable */ + getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); + } + + Bundle args = getArguments(); + if (mInstructions == null && args != null) + { + mInstructions = args.getParcelableArrayList(EXTRA_REMEDIATION_INSTRUCTIONS); + } + updateView(mInstructions); + + if (two_pane && mCurrentPosition == -1 && mInstructions.size() > 0) + { /* two-pane layout, select first instruction */ + mCurrentPosition = 0; + mListener.onRemediationInstructionSelected(mInstructions.get(0)); + } + getListView().setItemChecked(mCurrentPosition, true); + } + + @Override + public void onListItemClick(ListView l, View v, int position, long id) + { + mCurrentPosition = position; + mListener.onRemediationInstructionSelected(mInstructions.get(position)); + getListView().setItemChecked(position, true); + } + + public void updateView(ArrayList<RemediationInstruction> instructions) + { + if (mAdapter == null) + { + mAdapter = new RemediationInstructionAdapter(getActivity()); + setListAdapter(mAdapter); + } + mInstructions = instructions; + mAdapter.setData(mInstructions); + } +} |