2 * Copyright (C) 2013 Tobias Brunner
3 * 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.support.v7.app.AppCompatActivity;
20 import android.view.MenuItem;
22 import org.strongswan.android.R;
23 import org.strongswan.android.logic.imc.RemediationInstruction;
24 import org.strongswan.android.ui.RemediationInstructionsFragment.OnRemediationInstructionSelectedListener;
26 import java.util.ArrayList;
28 public class RemediationInstructionsActivity extends AppCompatActivity implements OnRemediationInstructionSelectedListener
31 protected void onCreate(Bundle savedInstanceState)
33 super.onCreate(savedInstanceState);
34 setContentView(R.layout.remediation_instructions);
35 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
37 if (savedInstanceState != null)
38 { /* only update if we're not restoring */
41 RemediationInstructionsFragment frag = (RemediationInstructionsFragment)getFragmentManager().findFragmentById(R.id.remediation_instructions_fragment);
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);
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();
57 public boolean onOptionsItemSelected(MenuItem item)
59 switch (item.getItemId())
61 case android.R.id.home:
62 /* one-pane layout, pop possible fragment from stack, finish otherwise */
63 if (!getFragmentManager().popBackStackImmediate())
67 getSupportActionBar().setTitle(getTitle());
70 return super.onOptionsItemSelected(item);
75 public void onRemediationInstructionSelected(RemediationInstruction instruction)
77 RemediationInstructionFragment frag = (RemediationInstructionFragment)getFragmentManager().findFragmentById(R.id.remediation_instruction_fragment);
80 { /* two-pane layout, update directly */
81 frag.updateView(instruction);
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);
90 getFragmentManager().beginTransaction().replace(R.id.fragment_container, frag).addToBackStack(null).commit();
91 getSupportActionBar().setTitle(instruction.getTitle());