android: Migrate to the Gradle build system
[strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / ui / RemediationInstructionFragment.java
1 /*
2 * Copyright (C) 2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 package org.strongswan.android.ui;
17
18 import org.strongswan.android.R;
19 import org.strongswan.android.logic.imc.RemediationInstruction;
20
21 import android.app.ListFragment;
22 import android.os.Bundle;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.ArrayAdapter;
27 import android.widget.TextView;
28
29 public class RemediationInstructionFragment extends ListFragment
30 {
31 public static final String ARG_REMEDIATION_INSTRUCTION = "instruction";
32 private RemediationInstruction mInstruction = null;
33 private TextView mTitle;
34 private TextView mDescription;
35 private TextView mHeader;
36
37 @Override
38 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
39 {
40 return inflater.inflate(R.layout.remediation_instruction, container, false);
41 }
42
43 @Override
44 public void onActivityCreated(Bundle savedInstanceState)
45 {
46 super.onActivityCreated(savedInstanceState);
47
48 if (savedInstanceState != null)
49 {
50 mInstruction = savedInstanceState.getParcelable(ARG_REMEDIATION_INSTRUCTION);
51 }
52 /* show dividers only between list items */
53 getListView().setHeaderDividersEnabled(false);
54 getListView().setFooterDividersEnabled(false);
55 /* don't show loader while adapter is not set */
56 setListShown(true);
57 mTitle = (TextView)getView().findViewById(R.id.title);
58 mDescription = (TextView)getView().findViewById(R.id.description);
59 mHeader = (TextView)getView().findViewById(R.id.list_header);
60 }
61
62 @Override
63 public void onSaveInstanceState(Bundle outState)
64 {
65 super.onSaveInstanceState(outState);
66 outState.putParcelable(ARG_REMEDIATION_INSTRUCTION, mInstruction);
67 }
68
69 @Override
70 public void onStart()
71 {
72 super.onStart();
73
74 Bundle args = getArguments();
75 if (args != null)
76 {
77 mInstruction = args.getParcelable(ARG_REMEDIATION_INSTRUCTION);
78 }
79 updateView(mInstruction);
80 }
81
82 public void updateView(RemediationInstruction instruction)
83 {
84 mInstruction = instruction;
85 if (mInstruction != null)
86 {
87 mTitle.setText(mInstruction.getTitle());
88 mDescription.setText(mInstruction.getDescription());
89 if (mInstruction.getHeader() != null)
90 {
91 mHeader.setText(mInstruction.getHeader());
92 setListAdapter(new ArrayAdapter<String>(getActivity(),
93 android.R.layout.simple_list_item_1, mInstruction.getItems()));
94 }
95 else
96 {
97 mHeader.setText("");
98 setListAdapter(null);
99 }
100 }
101 else
102 {
103 mTitle.setText("");
104 mDescription.setText("");
105 mHeader.setText("");
106 setListAdapter(null);
107 }
108 }
109 }