android: Replace use of deprecate getColor() method overload
This commit is contained in:
+24
-14
@@ -15,14 +15,6 @@
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
+15
-8
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user