android: Replace use of deprecate getColor() method overload

This commit is contained in:
Tobias Brunner
2016-04-27 14:24:26 +02:00
parent 48123633cc
commit 4c5f4a3d2a
2 changed files with 39 additions and 22 deletions
@@ -15,14 +15,6 @@
package org.strongswan.android.ui; 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.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
@@ -33,6 +25,7 @@ import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.support.v4.content.ContextCompat;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
@@ -44,13 +37,24 @@ import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; 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 public class ImcStateFragment extends Fragment implements VpnStateListener
{ {
private int mColorIsolate;
private int mColorBlock;
private TextView mStateView; private TextView mStateView;
private TextView mAction; private TextView mAction;
private LinearLayout mButton; private LinearLayout mButton;
private VpnStateService mService; private VpnStateService mService;
private final ServiceConnection mServiceConnection = new ServiceConnection() { private final ServiceConnection mServiceConnection = new ServiceConnection()
{
@Override @Override
public void onServiceDisconnected(ComponentName name) public void onServiceDisconnected(ComponentName name)
{ {
@@ -71,6 +75,9 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
{ {
super.onCreate(savedInstanceState); 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 */ /* bind to the service only seems to work from the ApplicationContext */
Context context = getActivity().getApplicationContext(); Context context = getActivity().getApplicationContext();
context.bindService(new Intent(context, VpnStateService.class), 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); View view = inflater.inflate(R.layout.imc_state_fragment, container, false);
mButton = (LinearLayout)view.findViewById(R.id.imc_state_button); mButton = (LinearLayout)view.findViewById(R.id.imc_state_button);
mButton.setOnClickListener(new OnClickListener() { mButton.setOnClickListener(new OnClickListener()
{
@Override @Override
public void onClick(View v) public void onClick(View v)
{ {
@@ -104,7 +112,8 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
startActivity(intent); 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 */ /* a better value would be getScaledTouchExplorationTapSlop() but that is hidden */
private final int mMinDistance = ViewConfiguration.get(getActivity()).getScaledTouchSlop() * 4; private final int mMinDistance = ViewConfiguration.get(getActivity()).getScaledTouchSlop() * 4;
@@ -122,7 +131,8 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
return false; return false;
} }
}); });
mButton.setOnTouchListener(new OnTouchListener() { mButton.setOnTouchListener(new OnTouchListener()
{
@Override @Override
public boolean onTouch(View v, MotionEvent event) public boolean onTouch(View v, MotionEvent event)
{ {
@@ -190,12 +200,12 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
break; break;
case ISOLATE: case ISOLATE:
mStateView.setText(R.string.imc_state_isolate); mStateView.setText(R.string.imc_state_isolate);
mStateView.setTextColor(getResources().getColor(R.color.warning_text)); mStateView.setTextColor(mColorIsolate);
ft.show(this); ft.show(this);
break; break;
case BLOCK: case BLOCK:
mStateView.setText(R.string.imc_state_block); mStateView.setText(R.string.imc_state_block);
mStateView.setTextColor(getResources().getColor(R.color.error_text)); mStateView.setTextColor(mColorBlock);
ft.show(this); ft.show(this);
break; break;
} }
@@ -27,6 +27,7 @@ import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -55,7 +56,9 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
private TextView mProfileNameView; private TextView mProfileNameView;
private TextView mProfileView; private TextView mProfileView;
private TextView mStateView; private TextView mStateView;
private int stateBaseColor; private int mColorStateBase;
private int mColorStateError;
private int mColorStateSuccess;
private Button mActionButton; private Button mActionButton;
private ProgressDialog mConnectDialog; private ProgressDialog mConnectDialog;
private ProgressDialog mDisconnectDialog; private ProgressDialog mDisconnectDialog;
@@ -86,6 +89,9 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
{ {
super.onCreate(savedInstanceState); 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 */ /* bind to the service only seems to work from the ApplicationContext */
Context context = getActivity().getApplicationContext(); Context context = getActivity().getApplicationContext();
context.bindService(new Intent(context, VpnStateService.class), 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); View view = inflater.inflate(R.layout.vpn_state_fragment, null);
mActionButton = (Button)view.findViewById(R.id.action); mActionButton = (Button)view.findViewById(R.id.action);
mActionButton.setOnClickListener(new OnClickListener() { mActionButton.setOnClickListener(new OnClickListener()
{
@Override @Override
public void onClick(View v) public void onClick(View v)
{ {
@@ -129,7 +136,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
enableActionButton(false); enableActionButton(false);
mStateView = (TextView)view.findViewById(R.id.vpn_state); mStateView = (TextView)view.findViewById(R.id.vpn_state);
stateBaseColor = mStateView.getCurrentTextColor(); mColorStateBase = mStateView.getCurrentTextColor();
mProfileView = (TextView)view.findViewById(R.id.vpn_profile_label); mProfileView = (TextView)view.findViewById(R.id.vpn_profile_label);
mProfileNameView = (TextView)view.findViewById(R.id.vpn_profile_name); mProfileNameView = (TextView)view.findViewById(R.id.vpn_profile_name);
@@ -204,26 +211,26 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
showProfile(false); showProfile(false);
hideProgressDialog(); hideProgressDialog();
mStateView.setText(R.string.state_disabled); mStateView.setText(R.string.state_disabled);
mStateView.setTextColor(stateBaseColor); mStateView.setTextColor(mColorStateBase);
break; break;
case CONNECTING: case CONNECTING:
showProfile(true); showProfile(true);
showConnectDialog(name, gateway); showConnectDialog(name, gateway);
mStateView.setText(R.string.state_connecting); mStateView.setText(R.string.state_connecting);
mStateView.setTextColor(stateBaseColor); mStateView.setTextColor(mColorStateBase);
break; break;
case CONNECTED: case CONNECTED:
showProfile(true); showProfile(true);
hideProgressDialog(); hideProgressDialog();
enableActionButton(true); enableActionButton(true);
mStateView.setText(R.string.state_connected); mStateView.setText(R.string.state_connected);
mStateView.setTextColor(getResources().getColor(R.color.success_text)); mStateView.setTextColor(mColorStateSuccess);
break; break;
case DISCONNECTING: case DISCONNECTING:
showProfile(true); showProfile(true);
showDisconnectDialog(name); showDisconnectDialog(name);
mStateView.setText(R.string.state_disconnecting); mStateView.setText(R.string.state_disconnecting);
mStateView.setTextColor(stateBaseColor); mStateView.setTextColor(mColorStateBase);
break; break;
} }
} }
@@ -252,7 +259,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
showProfile(true); showProfile(true);
enableActionButton(false); enableActionButton(false);
mStateView.setText(R.string.state_error); mStateView.setText(R.string.state_error);
mStateView.setTextColor(getResources().getColor(R.color.error_text)); mStateView.setTextColor(mColorStateError);
switch (error) switch (error)
{ {
case AUTH_FAILED: case AUTH_FAILED: