android: Replace use of deprecate getColor() method overload
[strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / ui / ImcStateFragment.java
index 5b17997..7328693 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.ImcState;
-import org.strongswan.android.logic.imc.RemediationInstruction;
-
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
@@ -33,6 +25,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.view.GestureDetector;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
@@ -44,13 +37,24 @@ import android.view.ViewGroup;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import org.strongswan.android.R;
+import org.strongswan.android.logic.VpnStateService;
+import org.strongswan.android.logic.VpnStateService.VpnStateListener;
+import org.strongswan.android.logic.imc.ImcState;
+import org.strongswan.android.logic.imc.RemediationInstruction;
+
+import java.util.ArrayList;
+
 public class ImcStateFragment extends Fragment implements VpnStateListener
 {
+       private int mColorIsolate;
+       private int mColorBlock;
        private TextView mStateView;
        private TextView mAction;
        private LinearLayout mButton;
        private VpnStateService mService;
-       private final ServiceConnection mServiceConnection = new ServiceConnection() {
+       private final ServiceConnection mServiceConnection = new ServiceConnection()
+       {
                @Override
                public void onServiceDisconnected(ComponentName name)
                {
@@ -71,6 +75,9 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
        {
                super.onCreate(savedInstanceState);
 
+               mColorIsolate = ContextCompat.getColor(getActivity(), R.color.warning_text);
+               mColorBlock = ContextCompat.getColor(getActivity(), R.color.error_text);
+
                /* bind to the service only seems to work from the ApplicationContext */
                Context context = getActivity().getApplicationContext();
                context.bindService(new Intent(context, VpnStateService.class),
@@ -86,7 +93,8 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
                View view = inflater.inflate(R.layout.imc_state_fragment, container, false);
 
                mButton = (LinearLayout)view.findViewById(R.id.imc_state_button);
-               mButton.setOnClickListener(new OnClickListener() {
+               mButton.setOnClickListener(new OnClickListener()
+               {
                        @Override
                        public void onClick(View v)
                        {
@@ -104,7 +112,8 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
                                startActivity(intent);
                        }
                });
-               final GestureDetector gestures = new GestureDetector(getActivity(), new GestureDetector.SimpleOnGestureListener() {
+               final GestureDetector gestures = new GestureDetector(getActivity(), new GestureDetector.SimpleOnGestureListener()
+               {
                        /* a better value would be getScaledTouchExplorationTapSlop() but that is hidden */
                        private final int mMinDistance = ViewConfiguration.get(getActivity()).getScaledTouchSlop() * 4;
 
@@ -122,7 +131,8 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
                                return false;
                        }
                });
-               mButton.setOnTouchListener(new OnTouchListener() {
+               mButton.setOnTouchListener(new OnTouchListener()
+               {
                        @Override
                        public boolean onTouch(View v, MotionEvent event)
                        {
@@ -190,12 +200,12 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
                                break;
                        case ISOLATE:
                                mStateView.setText(R.string.imc_state_isolate);
-                               mStateView.setTextColor(getResources().getColor(R.color.warning_text));
+                               mStateView.setTextColor(mColorIsolate);
                                ft.show(this);
                                break;
                        case BLOCK:
                                mStateView.setText(R.string.imc_state_block);
-                               mStateView.setTextColor(getResources().getColor(R.color.error_text));
+                               mStateView.setTextColor(mColorBlock);
                                ft.show(this);
                                break;
                }