]>
Commit | Line | Data |
---|---|---|
0ef98957 TB |
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 java.util.ArrayList; | |
19 | ||
20 | import org.strongswan.android.R; | |
21 | import org.strongswan.android.logic.imc.RemediationInstruction; | |
22 | import org.strongswan.android.ui.RemediationInstructionsFragment.OnRemediationInstructionSelectedListener; | |
23 | ||
24 | import android.app.Activity; | |
25 | import android.os.Bundle; | |
26 | import android.view.MenuItem; | |
27 | ||
28 | public class RemediationInstructionsActivity extends Activity implements OnRemediationInstructionSelectedListener | |
29 | { | |
30 | @Override | |
31 | protected void onCreate(Bundle savedInstanceState) | |
32 | { | |
33 | super.onCreate(savedInstanceState); | |
34 | setContentView(R.layout.remediation_instructions); | |
35 | getActionBar().setDisplayHomeAsUpEnabled(true); | |
36 | ||
37 | if (savedInstanceState != null) | |
38 | { /* only update if we're not restoring */ | |
39 | return; | |
40 | } | |
41 | RemediationInstructionsFragment frag = (RemediationInstructionsFragment)getFragmentManager().findFragmentById(R.id.remediation_instructions_fragment); | |
42 | if (frag != null) | |
43 | { /* two-pane layout, update fragment */ | |
44 | Bundle extras = getIntent().getExtras(); | |
45 | ArrayList<RemediationInstruction> list = extras.getParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS); | |
46 | frag.updateView(list); | |
47 | } | |
48 | else | |
49 | { /* one-pane layout, create fragment */ | |
50 | frag = new RemediationInstructionsFragment(); | |
51 | frag.setArguments(getIntent().getExtras()); | |
52 | getFragmentManager().beginTransaction().add(R.id.fragment_container, frag).commit(); | |
53 | } | |
54 | } | |
55 | ||
56 | @Override | |
57 | public boolean onOptionsItemSelected(MenuItem item) | |
58 | { | |
59 | switch (item.getItemId()) | |
60 | { | |
61 | case android.R.id.home: | |
62 | /* one-pane layout, pop possible fragment from stack, finish otherwise */ | |
63 | if (!getFragmentManager().popBackStackImmediate()) | |
64 | { | |
65 | finish(); | |
66 | } | |
67 | getActionBar().setTitle(getTitle()); | |
68 | return true; | |
69 | default: | |
70 | return super.onOptionsItemSelected(item); | |
71 | } | |
72 | } | |
73 | ||
74 | @Override | |
75 | public void onRemediationInstructionSelected(RemediationInstruction instruction) | |
76 | { | |
77 | RemediationInstructionFragment frag = (RemediationInstructionFragment)getFragmentManager().findFragmentById(R.id.remediation_instruction_fragment); | |
78 | ||
79 | if (frag != null) | |
80 | { /* two-pane layout, update directly */ | |
81 | frag.updateView(instruction); | |
82 | } | |
83 | else | |
84 | { /* one-pane layout, replace fragment */ | |
85 | frag = new RemediationInstructionFragment(); | |
86 | Bundle args = new Bundle(); | |
87 | args.putParcelable(RemediationInstructionFragment.ARG_REMEDIATION_INSTRUCTION, instruction); | |
88 | frag.setArguments(args); | |
89 | ||
90 | getFragmentManager().beginTransaction().replace(R.id.fragment_container, frag).addToBackStack(null).commit(); | |
91 | getActionBar().setTitle(instruction.getTitle()); | |
92 | } | |
93 | } | |
94 | } |