</TextView>
</GridLayout>
+ <Button
+ android:id="@+id/action"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="10dp"
+ android:layout_marginLeft="20dp"
+ android:layout_marginRight="20dp"
+ android:text="@string/disconnect"
+ style="?android:attr/borderlessButtonStyle" >
+ </Button>
+
<View
android:layout_width="match_parent"
android:layout_height="2dp"
<!-- VPN state fragment -->
<string name="state_label">Status:</string>
<string name="profile_label">Profile:</string>
+ <string name="disconnect">Disconnect</string>
<string name="state_connecting">Connecting…</string>
<string name="state_connected">Connected</string>
<string name="state_disconnecting">Disconnecting…</string>
import android.os.IBinder;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.ViewGroup;
+import android.widget.Button;
import android.widget.TextView;
public class VpnStateFragment extends Fragment implements VpnStateListener
private TextView mProfileView;
private TextView mStateView;
private int stateBaseColor;
+ private Button mActionButton;
private ProgressDialog mProgressDialog;
private State mState;
private VpnStateService mService;
{
View view = inflater.inflate(R.layout.vpn_state_fragment, null);
+ mActionButton = (Button)view.findViewById(R.id.action);
+ mActionButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v)
+ {
+ if (mService != null)
+ {
+ mService.disconnect();
+ }
+ }
+ });
+ enableActionButton(false);
+
mStateView = (TextView)view.findViewById(R.id.vpn_state);
stateBaseColor = mStateView.getCurrentTextColor();
mProfileView = (TextView)view.findViewById(R.id.vpn_profile_label);
}
hideProgressDialog();
+ enableActionButton(false);
mProfileNameView.setText(name);
mState = state;
break;
case CONNECTED:
showProfile(true);
+ enableActionButton(true);
mStateView.setText(R.string.state_connected);
mStateView.setTextColor(Color.GREEN);
break;
mProfileNameView.setVisibility(show ? View.VISIBLE : View.GONE);
}
+ private void enableActionButton(boolean enable)
+ {
+ mActionButton.setEnabled(enable);
+ mActionButton.setVisibility(enable ? View.VISIBLE : View.GONE);
+ }
+
private void hideProgressDialog()
{
if (mProgressDialog != null)