From b19dc954b381c1e266395fdc1f19a1246096d4ab Mon Sep 17 00:00:00 2001 From: Sean Leonard Date: Wed, 10 Jul 2013 21:57:43 -0600 Subject: Add a progress bar while VPN connection is being established --- src/se/leap/leapclient/EipServiceFragment.java | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/se/leap/leapclient/EipServiceFragment.java b/src/se/leap/leapclient/EipServiceFragment.java index 485a06af..51284bc0 100644 --- a/src/se/leap/leapclient/EipServiceFragment.java +++ b/src/se/leap/leapclient/EipServiceFragment.java @@ -23,6 +23,8 @@ import android.widget.TextView; public class EipServiceFragment extends Fragment implements StateListener, OnClickListener, OnCheckedChangeListener { + private static final String IS_EIP_PENDING = "is_eip_pending"; + private View eipFragment; private Switch eipSwitch; private View eipDetail; @@ -37,6 +39,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + eipFragment = inflater.inflate(R.layout.eip_service_fragment, container, false); eipDetail = ((RelativeLayout) eipFragment.findViewById(R.id.eipDetail)); @@ -44,6 +47,9 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli View eipSettings = eipFragment.findViewById(R.id.eipSettings); eipSettings.setVisibility(View.GONE); // FIXME too! + + if (mEipStartPending) + eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE); eipStatus = (TextView) eipFragment.findViewById(R.id.eipStatus); eipStatus.setOnClickListener(this); @@ -59,6 +65,9 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli super.onCreate(savedInstanceState); mEIPReceiver = new EIPReceiver(new Handler()); + + if (savedInstanceState != null) + mEipStartPending = savedInstanceState.getBoolean(IS_EIP_PENDING); } @Override @@ -75,6 +84,12 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli OpenVPN.removeStateListener(this); } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(IS_EIP_PENDING, mEipStartPending); + } + @Override public void onClick(View buttonView) { if (buttonView.equals(eipStatus)) @@ -95,6 +110,8 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli if (buttonView.equals(eipSwitch) && !eipAutoSwitched){ if (isChecked){ mEipStartPending = true; + eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE); + ((TextView) eipFragment.findViewById(R.id.eipStatus)).setText(R.string.eip_status_start_pending); eipCommand(EIP.ACTION_START_EIP); } else { if (mEipStartPending){ @@ -151,11 +168,14 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli String prefix = getString(localizedResId); if (state.equals("CONNECTED")){ statusMessage = "Connection Secure"; + getActivity().findViewById(R.id.eipProgress).setVisibility(View.GONE); mEipStartPending = false; } else if (state.equals("BYTECOUNT")) { statusMessage = logmessage; - } else if (state.equals("NOPROCESS") || state.equals("EXITING")) { + } else if ( (state.equals("NOPROCESS") && !mEipStartPending ) || state.equals("EXITING")) { statusMessage = "Not running! Connection not secure!"; + getActivity().findViewById(R.id.eipProgress).setVisibility(View.GONE); + mEipStartPending = false; switchState = false; } else { statusMessage = prefix + logmessage; @@ -204,6 +224,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli break; case Activity.RESULT_CANCELED: checked = false; + eipFragment.findViewById(R.id.eipProgress).setVisibility(View.GONE); break; } } else if (request == EIP.ACTION_STOP_EIP) { -- cgit v1.2.3