Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,43 @@ protected void onCreate(Bundle savedInstanceState) {

private final PFLockScreenFragment.OnPFLockScreenCodeCreateListener mCodeCreateListener =
new PFLockScreenFragment.OnPFLockScreenCodeCreateListener() {
@Override
public void onCodeCreated(String encodedCode) {
Toast.makeText(MainActivity.this, "Code created", Toast.LENGTH_SHORT).show();
PreferencesSettings.saveToPref(MainActivity.this, encodedCode);
}
};
@Override
public void onCodeCreated(String encodedCode) {
Toast.makeText(MainActivity.this, "Code created", Toast.LENGTH_SHORT).show();
PreferencesSettings.saveToPref(MainActivity.this, encodedCode);
}

@Override
public void onNewCodeValidationFailed() {
Toast.makeText(MainActivity.this, "Code validation error", Toast.LENGTH_SHORT).show();
}
};

private final PFLockScreenFragment.OnPFLockScreenLoginListener mLoginListener =
new PFLockScreenFragment.OnPFLockScreenLoginListener() {

@Override
public void onCodeInputSuccessful() {
Toast.makeText(MainActivity.this, "Code successfull", Toast.LENGTH_SHORT).show();
showMainFragment();
}
@Override
public void onCodeInputSuccessful() {
Toast.makeText(MainActivity.this, "Code successfull", Toast.LENGTH_SHORT).show();
showMainFragment();
}

@Override
public void onFingerprintSuccessful() {
Toast.makeText(MainActivity.this, "Fingerprint successfull", Toast.LENGTH_SHORT).show();
showMainFragment();
}
@Override
public void onFingerprintSuccessful() {
Toast.makeText(MainActivity.this, "Fingerprint successfull", Toast.LENGTH_SHORT).show();
showMainFragment();
}

@Override
public void onPinLoginFailed() {
Toast.makeText(MainActivity.this, "Pin failed", Toast.LENGTH_SHORT).show();
}
@Override
public void onPinLoginFailed() {
Toast.makeText(MainActivity.this, "Pin failed", Toast.LENGTH_SHORT).show();
}

@Override
public void onFingerprintLoginFailed() {
Toast.makeText(MainActivity.this, "Fingerprint failed", Toast.LENGTH_SHORT).show();
}
};
@Override
public void onFingerprintLoginFailed() {
Toast.makeText(MainActivity.this, "Fingerprint failed", Toast.LENGTH_SHORT).show();
}
};

private void showLockScreenFragment() {
new PFPinCodeViewModel().isPinCodeEncryptionKeyExist().observe(
Expand All @@ -80,8 +85,10 @@ public void onChanged(@Nullable PFResult<Boolean> result) {
private void showLockScreenFragment(boolean isPinExist) {
final PFFLockScreenConfiguration.Builder builder = new PFFLockScreenConfiguration.Builder(this)
.setTitle(isPinExist ? "Unlock with your pin code or fingerprint" : "Create Code")
.setCodeLength(6)
.setCodeLength(4)
.setLeftButton("Can't remeber")
.setNewCodeValidation(true)
.setNewCodeValidationTitle("Please input code again")
.setUseFingerprint(true);
final PFLockScreenFragment fragment = new PFLockScreenFragment();

Expand All @@ -107,12 +114,11 @@ public void onClick(View v) {

}

private void showMainFragment() {
private void showMainFragment() {
final MainFragment fragment = new MainFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.container_view, fragment).commit();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ public PFLockScreenFragment getInstance(Context context) {
final PFFLockScreenConfiguration.Builder builder =
new PFFLockScreenConfiguration.Builder(context)
.setCodeLength(CODE_LENGTH)
.setLeftButton(LEFT_BUTTON, new View.OnClickListener() {
@Override
public void onClick(View v) {

}
})
.setLeftButton(LEFT_BUTTON)
.setUseFingerprint(true)
.setMode(PFFLockScreenConfiguration.MODE_AUTH);
fragment.setConfiguration(builder.build());
fragment.setOnLeftButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});
return fragment;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class PFFLockScreenConfiguration implements Serializable {
private boolean mClearCodeOnError = false;
private boolean mErrorVibration = true;
private boolean mErrorAnimation = true;
private boolean mNewCodeValidation = false;
private String mNewCodeValidationTitle = "";

private PFFLockScreenConfiguration(Builder builder) {
mLeftButton = builder.mLeftButton;
Expand All @@ -35,6 +37,8 @@ private PFFLockScreenConfiguration(Builder builder) {
mClearCodeOnError = builder.mClearCodeOnError;
mErrorVibration = builder.mErrorVibration;
mErrorAnimation = builder.mErrorAnimation;
mNewCodeValidation = builder.mNewCodeValidation;
mNewCodeValidationTitle = builder.mNewCodeValidationTitle;
}

public String getLeftButton() {
Expand Down Expand Up @@ -73,6 +77,14 @@ public boolean isErrorAnimation() {
return mErrorAnimation;
}

public boolean isNewCodeValidation() {
return mNewCodeValidation;
}

public String getNewCodeValidationTitle() {
return mNewCodeValidationTitle;
}

@PFLockScreenMode
public int getMode() {
return this.mMode;
Expand All @@ -90,6 +102,8 @@ public static class Builder {
private boolean mClearCodeOnError = false;
private boolean mErrorVibration = true;
private boolean mErrorAnimation = true;
private boolean mNewCodeValidation = false;
private String mNewCodeValidationTitle = "";


public Builder(Context context) {
Expand Down Expand Up @@ -146,6 +160,16 @@ public Builder setErrorAnimation(boolean errorAnimation) {
return this;
}

public Builder setNewCodeValidation(boolean newCodeValidation) {
this.mNewCodeValidation = newCodeValidation;
return this;
}

public Builder setNewCodeValidationTitle(String newCodeValidationTitle) {
this.mNewCodeValidationTitle = newCodeValidationTitle;
return this;
}

public PFFLockScreenConfiguration build() {
return new PFFLockScreenConfiguration(
this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class PFLockScreenFragment extends Fragment {
private TextView mLeftButton;
private Button mNextButton;
private PFCodeView mCodeView;
private TextView titleView;

private boolean mUseFingerPrint = true;
private boolean mFingerprintHardwareDetected = false;
Expand All @@ -57,6 +58,7 @@ public class PFLockScreenFragment extends Fragment {
private OnPFLockScreenCodeCreateListener mCodeCreateListener;
private OnPFLockScreenLoginListener mLoginListener;
private String mCode = "";
private String mCodeValidation = "";
private String mEncodedPinCode = "";

private PFFLockScreenConfiguration mConfiguration;
Expand Down Expand Up @@ -130,7 +132,7 @@ private void applyConfiguration(PFFLockScreenConfiguration configuration) {
if (mRootView == null || configuration == null) {
return;
}
final TextView titleView = mRootView.findViewById(R.id.title_text_view);
titleView = mRootView.findViewById(R.id.title_text_view);
titleView.setText(configuration.getTitle());
if (TextUtils.isEmpty(configuration.getLeftButton())) {
mLeftButton.setVisibility(View.GONE);
Expand Down Expand Up @@ -351,6 +353,19 @@ public void onCodeNotCompleted(String code) {
private final View.OnClickListener mOnNextButtonClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mConfiguration.isNewCodeValidation() && TextUtils.isEmpty(mCodeValidation)) {
mCodeValidation = mCode;
cleanCode();
titleView.setText(mConfiguration.getNewCodeValidationTitle());
return;
}
if (mConfiguration.isNewCodeValidation() && !TextUtils.isEmpty(mCodeValidation) && !mCode.equals(mCodeValidation)) {
mCodeCreateListener.onNewCodeValidationFailed();
titleView.setText(mConfiguration.getTitle());
cleanCode();
return;
}
mCodeValidation = "";
mPFPinCodeViewModel.encodePin(getContext(), mCode).observe(
PFLockScreenFragment.this,
new Observer<PFResult<String>>() {
Expand All @@ -374,6 +389,11 @@ public void onChanged(@Nullable PFResult<String> result) {
}
};

private void cleanCode() {
mCode = "";
mCodeView.clearCode();
}


private void deleteEncodeKey() {
mPFPinCodeViewModel.delete().observe(
Expand Down Expand Up @@ -471,6 +491,13 @@ public interface OnPFLockScreenCodeCreateListener {
*/
void onCodeCreated(String encodedCode);

/**
* This will be called if PFFLockScreenConfiguration#newCodeValidation is true.
* User need to input new code twice. This method will be called when second code isn't
* the same as first.
*/
void onNewCodeValidationFailed();

}


Expand Down