android: Replace use of deprecate getColor() method overload
[strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / ui / VpnStateFragment.java
index f385999..c49e5cc 100644 (file)
@@ -27,6 +27,7 @@ import android.content.Intent;
 import android.content.ServiceConnection;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.support.v4.content.ContextCompat;
 import android.support.v7.app.AlertDialog;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -55,7 +56,9 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
        private TextView mProfileNameView;
        private TextView mProfileView;
        private TextView mStateView;
-       private int stateBaseColor;
+       private int mColorStateBase;
+       private int mColorStateError;
+       private int mColorStateSuccess;
        private Button mActionButton;
        private ProgressDialog mConnectDialog;
        private ProgressDialog mDisconnectDialog;
@@ -86,6 +89,9 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
        {
                super.onCreate(savedInstanceState);
 
+               mColorStateError = ContextCompat.getColor(getActivity(), R.color.error_text);
+               mColorStateSuccess = ContextCompat.getColor(getActivity(), R.color.success_text);
+
                /* bind to the service only seems to work from the ApplicationContext */
                Context context = getActivity().getApplicationContext();
                context.bindService(new Intent(context, VpnStateService.class),
@@ -116,7 +122,8 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                View view = inflater.inflate(R.layout.vpn_state_fragment, null);
 
                mActionButton = (Button)view.findViewById(R.id.action);
-               mActionButton.setOnClickListener(new OnClickListener() {
+               mActionButton.setOnClickListener(new OnClickListener()
+               {
                        @Override
                        public void onClick(View v)
                        {
@@ -129,7 +136,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                enableActionButton(false);
 
                mStateView = (TextView)view.findViewById(R.id.vpn_state);
-               stateBaseColor = mStateView.getCurrentTextColor();
+               mColorStateBase = mStateView.getCurrentTextColor();
                mProfileView = (TextView)view.findViewById(R.id.vpn_profile_label);
                mProfileNameView = (TextView)view.findViewById(R.id.vpn_profile_name);
 
@@ -204,26 +211,26 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                                showProfile(false);
                                hideProgressDialog();
                                mStateView.setText(R.string.state_disabled);
-                               mStateView.setTextColor(stateBaseColor);
+                               mStateView.setTextColor(mColorStateBase);
                                break;
                        case CONNECTING:
                                showProfile(true);
                                showConnectDialog(name, gateway);
                                mStateView.setText(R.string.state_connecting);
-                               mStateView.setTextColor(stateBaseColor);
+                               mStateView.setTextColor(mColorStateBase);
                                break;
                        case CONNECTED:
                                showProfile(true);
                                hideProgressDialog();
                                enableActionButton(true);
                                mStateView.setText(R.string.state_connected);
-                               mStateView.setTextColor(getResources().getColor(R.color.success_text));
+                               mStateView.setTextColor(mColorStateSuccess);
                                break;
                        case DISCONNECTING:
                                showProfile(true);
                                showDisconnectDialog(name);
                                mStateView.setText(R.string.state_disconnecting);
-                               mStateView.setTextColor(stateBaseColor);
+                               mStateView.setTextColor(mColorStateBase);
                                break;
                }
        }
@@ -252,7 +259,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                showProfile(true);
                enableActionButton(false);
                mStateView.setText(R.string.state_error);
-               mStateView.setTextColor(getResources().getColor(R.color.error_text));
+               mStateView.setTextColor(mColorStateError);
                switch (error)
                {
                        case AUTH_FAILED: