2017-08-05 15:15:31 +02:00
|
|
|
package me.impy.aegis;
|
|
|
|
|
2017-08-06 21:45:27 +02:00
|
|
|
import android.Manifest;
|
2017-08-06 18:15:47 +02:00
|
|
|
import android.content.Context;
|
2017-08-06 21:45:27 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.hardware.fingerprint.FingerprintManager;
|
|
|
|
import android.os.Build;
|
2017-08-05 15:15:31 +02:00
|
|
|
import android.os.Bundle;
|
2017-08-13 19:51:54 +02:00
|
|
|
import android.support.design.widget.Snackbar;
|
2017-08-06 21:45:27 +02:00
|
|
|
import android.support.v4.app.ActivityCompat;
|
2017-08-13 19:51:54 +02:00
|
|
|
import android.support.v4.app.Fragment;
|
2017-08-05 15:15:31 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.RadioButton;
|
|
|
|
import android.widget.RadioGroup;
|
2017-08-06 21:45:27 +02:00
|
|
|
import android.widget.TextView;
|
2017-08-05 15:15:31 +02:00
|
|
|
|
2017-08-13 19:51:54 +02:00
|
|
|
import com.github.paolorotolo.appintro.ISlidePolicy;
|
2017-08-05 15:15:31 +02:00
|
|
|
|
2017-12-11 14:01:43 +01:00
|
|
|
public class CustomAuthenticationSlide extends Fragment implements ISlidePolicy, RadioGroup.OnCheckedChangeListener {
|
2017-08-13 19:51:54 +02:00
|
|
|
public static final int CRYPT_TYPE_INVALID = 0;
|
|
|
|
public static final int CRYPT_TYPE_NONE = 1;
|
|
|
|
public static final int CRYPT_TYPE_PASS = 2;
|
|
|
|
public static final int CRYPT_TYPE_FINGER = 3;
|
2017-08-06 21:45:27 +02:00
|
|
|
|
2017-08-26 21:15:53 +02:00
|
|
|
private RadioGroup _buttonGroup;
|
|
|
|
private int _bgColor;
|
2017-08-05 15:15:31 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
final View view = inflater.inflate(R.layout.fragment_authentication_slide, container, false);
|
2017-08-06 21:45:27 +02:00
|
|
|
final Context context = getContext();
|
2017-08-05 15:15:31 +02:00
|
|
|
|
2017-12-12 02:21:13 +01:00
|
|
|
_buttonGroup = view.findViewById(R.id.rg_authenticationMethod);
|
2017-12-11 14:01:43 +01:00
|
|
|
_buttonGroup.setOnCheckedChangeListener(this);
|
|
|
|
onCheckedChanged(_buttonGroup, _buttonGroup.getCheckedRadioButtonId());
|
2017-08-05 15:15:31 +02:00
|
|
|
|
2017-08-06 21:45:27 +02:00
|
|
|
// only show the fingerprint option if the api version is new enough, permission is granted and a scanner is found
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
|
|
|
|
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED && fingerprintManager.isHardwareDetected()) {
|
2017-12-12 02:21:13 +01:00
|
|
|
RadioButton button = view.findViewById(R.id.rb_fingerprint);
|
|
|
|
TextView text = view.findViewById(R.id.text_rb_fingerprint);
|
2017-08-06 21:45:27 +02:00
|
|
|
button.setVisibility(View.VISIBLE);
|
|
|
|
text.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-26 21:15:53 +02:00
|
|
|
view.findViewById(R.id.main).setBackgroundColor(_bgColor);
|
2017-08-05 15:15:31 +02:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2017-08-13 19:51:54 +02:00
|
|
|
public void setBgColor(int color) {
|
2017-08-26 21:15:53 +02:00
|
|
|
_bgColor = color;
|
2017-08-05 15:15:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-13 19:51:54 +02:00
|
|
|
public boolean isPolicyRespected() {
|
2017-08-26 21:15:53 +02:00
|
|
|
return _buttonGroup.getCheckedRadioButtonId() != -1;
|
2017-08-05 15:15:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-13 19:51:54 +02:00
|
|
|
public void onUserIllegallyRequestedNextPage() {
|
|
|
|
Snackbar snackbar = Snackbar.make(getView(), "Please select an authentication method", Snackbar.LENGTH_LONG);
|
|
|
|
snackbar.show();
|
2017-08-05 15:15:31 +02:00
|
|
|
}
|
2017-12-11 14:01:43 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(RadioGroup radioGroup, int i) {
|
|
|
|
if (i == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int id;
|
|
|
|
switch (i) {
|
|
|
|
case R.id.rb_none:
|
|
|
|
id = CRYPT_TYPE_NONE;
|
|
|
|
break;
|
|
|
|
case R.id.rb_password:
|
|
|
|
id = CRYPT_TYPE_PASS;
|
|
|
|
break;
|
|
|
|
case R.id.rb_fingerprint:
|
|
|
|
id = CRYPT_TYPE_FINGER;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new RuntimeException();
|
|
|
|
}
|
|
|
|
Intent intent = getActivity().getIntent();
|
|
|
|
intent.putExtra("cryptType", id);
|
|
|
|
}
|
2017-08-06 16:03:36 +02:00
|
|
|
}
|