android: IMC state fragment is a button that shows remediation instructions or log
authorTobias Brunner <tobias@strongswan.org>
Thu, 30 May 2013 10:16:30 +0000 (12:16 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 8 Jul 2013 16:49:29 +0000 (18:49 +0200)
src/frontends/android/res/layout/imc_state_fragment.xml
src/frontends/android/src/org/strongswan/android/ui/ImcStateFragment.java

index 8685388..171c88d 100644 (file)
     android:orientation="vertical" >
 
     <LinearLayout
+        android:id="@+id/imc_state_button"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginLeft="20dp"
-        android:layout_marginRight="20dp"
-        android:layout_marginTop="10dp"
-        android:layout_marginBottom="10dp"
-        android:orientation="horizontal" >
+        android:background="?android:attr/selectableItemBackground"
+        android:orientation="vertical" >
 
-        <TextView
-            android:layout_width="wrap_content"
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginRight="5dp"
-            android:text="@string/imc_state_label"
-            android:textColor="?android:textColorPrimary"
-            android:textSize="20sp" />
+            android:layout_marginLeft="20dp"
+            android:layout_marginRight="20dp"
+            android:layout_marginTop="10dp"
+            android:orientation="horizontal" >
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginRight="5dp"
+                android:text="@string/imc_state_label"
+                android:textColor="?android:textColorPrimary"
+                android:textSize="20sp" />
+
+            <TextView
+                android:id="@+id/imc_state"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text=""
+                android:textColor="?android:textColorSecondary"
+                android:textSize="20sp" />
+
+        </LinearLayout>
 
         <TextView
-            android:id="@+id/imc_state"
-            android:layout_width="wrap_content"
+            android:id="@+id/action"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:text=""
-            android:textColor="?android:textColorSecondary"
-            android:textSize="20sp" />
+            android:layout_marginBottom="10dp"
+            android:layout_marginLeft="20dp"
+            android:layout_marginRight="20dp"
+            android:text="@string/show_remediation_instructions"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:textColor="?android:attr/textColorSecondary" />
 
     </LinearLayout>
 
index 18893a3..2b6c146 100644 (file)
 
 package org.strongswan.android.ui;
 
+import java.util.ArrayList;
+
 import org.strongswan.android.R;
 import org.strongswan.android.logic.VpnStateService;
 import org.strongswan.android.logic.VpnStateService.VpnStateListener;
+import org.strongswan.android.logic.imc.RemediationInstruction;
 
 import android.app.Fragment;
 import android.app.FragmentTransaction;
@@ -30,12 +33,16 @@ import android.os.Bundle;
 import android.os.IBinder;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.ViewGroup;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 
 public class ImcStateFragment extends Fragment implements VpnStateListener
 {
        private TextView mStateView;
+       private TextView mAction;
+       private LinearLayout mButton;
        private VpnStateService mService;
        private final ServiceConnection mServiceConnection = new ServiceConnection() {
                @Override
@@ -72,7 +79,28 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
        {
                View view = inflater.inflate(R.layout.imc_state_fragment, null);
 
+               mButton = (LinearLayout)view.findViewById(R.id.imc_state_button);
+               mButton.setOnClickListener(new OnClickListener() {
+                       @Override
+                       public void onClick(View v)
+                       {
+                               Intent intent;
+                               if (mService != null && !mService.getRemediationInstructions().isEmpty())
+                               {
+                                       intent = new Intent(getActivity(), RemediationInstructionsActivity.class);
+                                       intent.putParcelableArrayListExtra(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS,
+                                                                                                          new ArrayList<RemediationInstruction>(mService.getRemediationInstructions()));
+                               }
+                               else
+                               {
+                                       intent = new Intent(getActivity(), LogActivity.class);
+                               }
+                               startActivity(intent);
+                       }
+               });
+
                mStateView = (TextView)view.findViewById(R.id.imc_state);
+               mAction = (TextView)view.findViewById(R.id.action);
 
                return view;
        }
@@ -116,5 +144,8 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
                                break;
                }
                ft.commit();
+
+               mAction.setText(mService.getRemediationInstructions().isEmpty() ? R.string.show_log
+                                                                                                                                               : R.string.show_remediation_instructions);
        }
 }