android: Add activity that displays a list of remediation instructions

On large displays a two-pane layout is used that displays the list next
to the actual instructions.
This commit is contained in:
Tobias Brunner
2013-07-08 18:49:29 +02:00
parent 611d35e8e8
commit 0ef98957a7
11 changed files with 212 additions and 1 deletions
@@ -54,6 +54,10 @@
android:name=".ui.LogActivity"
android:label="@string/log_title" >
</activity>
<activity
android:name=".ui.RemediationInstructionsActivity"
android:label="@string/remediation_instructions_title" >
</activity>
<activity
android:name=".ui.VpnProfileSelectActivity"
android:label="@string/strongswan_shortcut" >
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid
android:color="@color/panel_separator" />
</shape>
</item>
<item android:left="2dp">
<shape>
<solid
android:color="@color/panel_background" />
</shape>
</item>
</layer-list>
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false" >
<fragment
class="org.strongswan.android.ui.RemediationInstructionsFragment"
android:id="@+id/remediation_instructions_fragment"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="0dp" />
<FrameLayout
android:layout_height="match_parent"
android:layout_weight="2"
android:layout_width="0dp"
android:background="@drawable/remediation_instruction_background_large"
android:padding="5dp" >
<fragment
class="org.strongswan.android.ui.RemediationInstructionFragment"
android:id="@+id/remediation_instruction_fragment"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</FrameLayout>
</LinearLayout>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container">
</FrameLayout>
@@ -91,6 +91,9 @@
<string name="imc_state_isolate">Eingeschränkt</string>
<string name="imc_state_block">Fehlgeschlagen</string>
<!-- Remediation instructions -->
<string name="remediation_instructions_title">Korrekturanweisungen</string>
<!-- Dialogs -->
<string name="login_title">Passwort eingeben um zu verbinden</string>
<string name="login_confirm">Verbinden</string>
@@ -91,6 +91,9 @@
<string name="imc_state_isolate">Restricted</string>
<string name="imc_state_block">Failed</string>
<!-- Remediation instructions -->
<string name="remediation_instructions_title">Remediation instructions</string>
<!-- Dialogs -->
<string name="login_title">Wprowadż hasło</string>
<string name="login_confirm">Połącz</string>
@@ -88,6 +88,9 @@
<string name="imc_state_isolate">Restricted</string>
<string name="imc_state_block">Failed</string>
<!-- Remediation instructions -->
<string name="remediation_instructions_title">Remediation instructions</string>
<!-- Dialogs -->
<string name="login_title">Введите пароль для соединения</string>
<string name="login_confirm">Соединить</string>
@@ -89,6 +89,9 @@
<string name="imc_state_isolate">Restricted</string>
<string name="imc_state_block">Failed</string>
<!-- Remediation instructions -->
<string name="remediation_instructions_title">Remediation instructions</string>
<!-- Dialogs -->
<string name="login_title">Введіть пароль для з\'єднання</string>
<string name="login_confirm">Підключити</string>
@@ -91,6 +91,9 @@
<string name="imc_state_isolate">Restricted</string>
<string name="imc_state_block">Failed</string>
<!-- Remediation instructions -->
<string name="remediation_instructions_title">Remediation instructions</string>
<!-- Dialogs -->
<string name="login_title">Enter password to connect</string>
<string name="login_confirm">Connect</string>
@@ -0,0 +1,94 @@
/*
* 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.R;
import org.strongswan.android.logic.imc.RemediationInstruction;
import org.strongswan.android.ui.RemediationInstructionsFragment.OnRemediationInstructionSelectedListener;
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
public class RemediationInstructionsActivity extends Activity implements OnRemediationInstructionSelectedListener
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.remediation_instructions);
getActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState != null)
{ /* only update if we're not restoring */
return;
}
RemediationInstructionsFragment frag = (RemediationInstructionsFragment)getFragmentManager().findFragmentById(R.id.remediation_instructions_fragment);
if (frag != null)
{ /* two-pane layout, update fragment */
Bundle extras = getIntent().getExtras();
ArrayList<RemediationInstruction> list = extras.getParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS);
frag.updateView(list);
}
else
{ /* one-pane layout, create fragment */
frag = new RemediationInstructionsFragment();
frag.setArguments(getIntent().getExtras());
getFragmentManager().beginTransaction().add(R.id.fragment_container, frag).commit();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case android.R.id.home:
/* one-pane layout, pop possible fragment from stack, finish otherwise */
if (!getFragmentManager().popBackStackImmediate())
{
finish();
}
getActionBar().setTitle(getTitle());
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onRemediationInstructionSelected(RemediationInstruction instruction)
{
RemediationInstructionFragment frag = (RemediationInstructionFragment)getFragmentManager().findFragmentById(R.id.remediation_instruction_fragment);
if (frag != null)
{ /* two-pane layout, update directly */
frag.updateView(instruction);
}
else
{ /* one-pane layout, replace fragment */
frag = new RemediationInstructionFragment();
Bundle args = new Bundle();
args.putParcelable(RemediationInstructionFragment.ARG_REMEDIATION_INSTRUCTION, instruction);
frag.setArguments(args);
getFragmentManager().beginTransaction().replace(R.id.fragment_container, frag).addToBackStack(null).commit();
getActionBar().setTitle(instruction.getTitle());
}
}
}
@@ -17,6 +17,7 @@ package org.strongswan.android.ui;
import java.util.ArrayList;
import org.strongswan.android.R;
import org.strongswan.android.logic.imc.RemediationInstruction;
import org.strongswan.android.ui.adapter.RemediationInstructionAdapter;
@@ -79,7 +80,7 @@ public class RemediationInstructionsFragment extends ListFragment
{
super.onStart();
boolean two_pane = false;
boolean two_pane = getFragmentManager().findFragmentById(R.id.remediation_instruction_fragment) != null;
if (two_pane)
{ /* two-pane layout, make list items selectable */
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);