2 * Copyright (C) 2013-2016 Tobias Brunner
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 package org.strongswan.android.ui;
18 import android.os.Bundle;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.widget.ArrayAdapter;
23 import android.widget.FrameLayout;
24 import android.widget.TextView;
26 import org.strongswan.android.R;
27 import org.strongswan.android.logic.imc.RemediationInstruction;
29 import androidx.fragment.app.ListFragment;
31 public class RemediationInstructionFragment extends ListFragment
33 public static final String ARG_REMEDIATION_INSTRUCTION = "instruction";
34 private RemediationInstruction mInstruction = null;
35 private TextView mTitle;
36 private TextView mDescription;
37 private TextView mHeader;
40 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
42 /* while the documentation recommends to include "@android:layout/list_content" to retain
43 * the default functionality, this does not actually work with the ListFragment provided by
44 * the support library as it builds the view manually and uses different IDs */
45 View layout = inflater.inflate(R.layout.remediation_instruction, container, false);
46 FrameLayout list = (FrameLayout)layout.findViewById(R.id.list_container);
47 list.addView(super.onCreateView(inflater, list, savedInstanceState));
52 public void onActivityCreated(Bundle savedInstanceState)
54 super.onActivityCreated(savedInstanceState);
56 if (savedInstanceState != null)
58 mInstruction = savedInstanceState.getParcelable(ARG_REMEDIATION_INSTRUCTION);
60 /* show dividers only between list items */
61 getListView().setHeaderDividersEnabled(false);
62 getListView().setFooterDividersEnabled(false);
63 /* don't show loader while adapter is not set */
65 mTitle = (TextView)getView().findViewById(R.id.title);
66 mDescription = (TextView)getView().findViewById(R.id.description);
67 mHeader = (TextView)getView().findViewById(R.id.list_header);
71 public void onSaveInstanceState(Bundle outState)
73 super.onSaveInstanceState(outState);
74 outState.putParcelable(ARG_REMEDIATION_INSTRUCTION, mInstruction);
82 Bundle args = getArguments();
85 mInstruction = args.getParcelable(ARG_REMEDIATION_INSTRUCTION);
87 updateView(mInstruction);
90 public void updateView(RemediationInstruction instruction)
92 mInstruction = instruction;
93 if (mInstruction != null)
95 mTitle.setText(mInstruction.getTitle());
96 mDescription.setText(mInstruction.getDescription());
97 if (mInstruction.getHeader() != null)
99 mHeader.setText(mInstruction.getHeader());
100 setListAdapter(new ArrayAdapter<String>(getActivity(),
101 android.R.layout.simple_list_item_1, mInstruction.getItems()));
106 setListAdapter(null);
112 mDescription.setText("");
114 setListAdapter(null);