|
|
@ -23,6 +23,8 @@ import android.widget.Toast; |
|
|
|
import androidx.annotation.Nullable; |
|
|
|
import androidx.appcompat.app.ActionBar; |
|
|
|
import androidx.appcompat.widget.Toolbar; |
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
import androidx.fragment.app.FragmentManager; |
|
|
|
|
|
|
|
import com.tbruyelle.rxpermissions.RxPermissions; |
|
|
|
|
|
|
@ -30,11 +32,13 @@ import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.net.SocketException; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import javax.inject.Inject; |
|
|
|
|
|
|
|
import butterknife.BindView; |
|
|
|
import ru.PreferenceManager.PreferenceManager; |
|
|
|
import ru.visionlab.femdemo.Config; |
|
|
|
import ru.visionlab.femdemo.Core.PhotoProcessor; |
|
|
|
import ru.visionlab.femdemo.App; |
|
|
|
import ru.visionlab.femdemo.BuildConfig; |
|
|
@ -46,14 +50,22 @@ import ru.visionlab.femdemo.api.RegisterApiImplLuna2; |
|
|
|
import ru.visionlab.femdemo.api.RegisterApiImplLocal; |
|
|
|
import ru.visionlab.femdemo.api.RegisterApiInterface; |
|
|
|
import ru.visionlab.femdemo.api.VLApi; |
|
|
|
import ru.visionlab.femdemo.api.VerifyApiImplLuna2; |
|
|
|
import ru.visionlab.femdemo.api.VerifyApiImplLunaLocal; |
|
|
|
import ru.visionlab.femdemo.api.VerifyApiInterface; |
|
|
|
import ru.visionlab.femdemo.authentication.AuthSuccessActivity; |
|
|
|
import ru.visionlab.femdemo.authentication.AuthenticationActivity; |
|
|
|
import ru.visionlab.femdemo.authentication.FaceNotRecognizedFragment; |
|
|
|
import ru.visionlab.femdemo.base.PhotoFragment; |
|
|
|
import ru.visionlab.femdemo.base.ToolbarActivity; |
|
|
|
import ru.visionlab.femdemo.login.LoginActivity; |
|
|
|
import ru.visionlab.femdemo.login.LoginActivityNew; |
|
|
|
import ru.visionlab.femdemo.models.SearchResult; |
|
|
|
import ru.visionlab.femdemo.models.SearchResultPerson; |
|
|
|
import ru.visionlab.femdemo.settings.VLPreferences; |
|
|
|
|
|
|
|
public class RegisterActivity extends ToolbarActivity implements RegisterFragment.Listener, PhotoFragment.Listener, |
|
|
|
SavePhotoFragment.Listener, FaceNotFoundFragment.Listener, RegisterApiInterface.Listener{ |
|
|
|
SavePhotoFragment.Listener, FaceNotFoundFragment.Listener, RegisterApiInterface.Listener,VerifyApiInterface.Listener,FaceNotRecognizedFragment.Listener{ |
|
|
|
public static final String REGISTER_FRAGMENT = "REGISTER FRAGMENT"; |
|
|
|
public static final String PHOTO_FRAGMENT = "PHOTO_FRAGMENT"; |
|
|
|
public static final String SAVE_PHOTO_FRAGMENT = "SAVE PHOTO FRAGMENT"; |
|
|
@ -91,6 +103,15 @@ public class RegisterActivity extends ToolbarActivity implements RegisterFragmen |
|
|
|
Bitmap photo2=null; |
|
|
|
Button save,retry; |
|
|
|
String encodedImage=""; |
|
|
|
boolean fromLoginPage; |
|
|
|
private PhotoFragment fragment; |
|
|
|
String login; |
|
|
|
private long verifEndTime; |
|
|
|
private long verifStartTime; |
|
|
|
|
|
|
|
private int faceFailCount; |
|
|
|
|
|
|
|
private boolean goingSomewhere = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -103,7 +124,16 @@ public class RegisterActivity extends ToolbarActivity implements RegisterFragmen |
|
|
|
|
|
|
|
//ButterKnife.bind(this); |
|
|
|
setToolbar(); |
|
|
|
showRegisterScreen(); |
|
|
|
Intent intent = getIntent(); |
|
|
|
fromLoginPage = intent.getBooleanExtra("FromLoginPage",true); |
|
|
|
System.out.println("Value of FromLoginPage "+fromLoginPage); |
|
|
|
if(fromLoginPage){ |
|
|
|
showPhotoScreen(); |
|
|
|
} |
|
|
|
else { |
|
|
|
showRegisterScreen(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*back_img.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
@ -262,14 +292,14 @@ public class RegisterActivity extends ToolbarActivity implements RegisterFragmen |
|
|
|
} |
|
|
|
|
|
|
|
private void showPhotoScreen() { |
|
|
|
final PhotoFragment fragment = PhotoFragment.newInstance(); |
|
|
|
fragment = PhotoFragment.newInstance(); |
|
|
|
fragment.setPhotoProcessor(photoProcessor); |
|
|
|
fragment.setListener(this); |
|
|
|
fragment.enableLivenessCheck(false); |
|
|
|
|
|
|
|
preferences.setStartTime(String.valueOf(System.currentTimeMillis())); |
|
|
|
preferences.setNeedPortrait(false); |
|
|
|
System.out.println("Inside photo screen"); |
|
|
|
System.out.println("Inside photo screen method"); |
|
|
|
getSupportFragmentManager() |
|
|
|
.beginTransaction() |
|
|
|
.replace(R.id.container, fragment, PHOTO_FRAGMENT) |
|
|
@ -286,14 +316,40 @@ public class RegisterActivity extends ToolbarActivity implements RegisterFragmen |
|
|
|
.replace(R.id.container, fragment, SAVE_PHOTO_FRAGMENT) |
|
|
|
.addToBackStack(fragment.toString()) |
|
|
|
.commit(); |
|
|
|
System.out.println("Inside save photo screen method"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onBestFrameReady(Bitmap bitmap) { |
|
|
|
this.bitmap = bitmap; |
|
|
|
if(fromLoginPage){ |
|
|
|
verifyPhoto(bitmap); |
|
|
|
} |
|
|
|
showPhotoReadyScreen(bitmap); |
|
|
|
} |
|
|
|
|
|
|
|
private void verifyPhoto(Bitmap bitmap){ |
|
|
|
fragment.showWaitState(); |
|
|
|
login=preferences.getUsername(); |
|
|
|
System.out.println("Value of login while verification " + login); |
|
|
|
try { |
|
|
|
if (thread != null) |
|
|
|
thread.join(); |
|
|
|
}catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
VerifyApiInterface verifyApi; |
|
|
|
if (BuildConfig.IS_OFFLINE_VERSION) { |
|
|
|
verifyApi = new VerifyApiImplLunaLocal(this, photoProcessor, login, this); |
|
|
|
} else { //if (preferences.getLuna2()) { |
|
|
|
Log.i("LUNA2 ", preferences.getLuna2Server()); |
|
|
|
verifyApi = new VerifyApiImplLuna2(this, preferences.getLuna2Server(), login, api, this, bitmap, preferences.getEncodedUserData()); |
|
|
|
} |
|
|
|
|
|
|
|
verifStartTime = System.nanoTime(); |
|
|
|
verifyApi.verifyPerson(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onTimeout(FaceNotFoundFragment.Reason reason) { |
|
|
|
final FaceNotFoundFragment fragment = FaceNotFoundFragment.newInstance(); |
|
|
@ -467,4 +523,80 @@ public class RegisterActivity extends ToolbarActivity implements RegisterFragmen |
|
|
|
startActivity(intent); |
|
|
|
finish(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onVerificationSuccess(SearchResult searchResult) { |
|
|
|
verifEndTime = System.nanoTime(); |
|
|
|
preferences.setServerChanged(false); |
|
|
|
final List<SearchResultPerson> persons = searchResult.getPersons(); |
|
|
|
if (persons != null && !persons.isEmpty()) { |
|
|
|
final SearchResultPerson person = persons.get(0); |
|
|
|
if (person.similarity > Config.MIN_SIMILARITY) { |
|
|
|
onFaceAuthSuccess(); |
|
|
|
} else { |
|
|
|
onFaceAuthFail(AuthenticationActivity.AuthFailReason.SIMILARITY); |
|
|
|
} |
|
|
|
} else { |
|
|
|
onFaceAuthFail(AuthenticationActivity.AuthFailReason.SIMILARITY); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onVerificationFail(Throwable throwable) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void onFaceAuthSuccess() { |
|
|
|
showSuccess(); |
|
|
|
/*if (preferences.getFingerAuth()) { |
|
|
|
onFingerClick(finger); |
|
|
|
} else { |
|
|
|
showSuccess(); |
|
|
|
}*/ |
|
|
|
} |
|
|
|
private void showSuccess() { |
|
|
|
final Intent intent = new Intent(this, AuthSuccessActivity.class); |
|
|
|
intent.putExtra(AuthSuccessActivity.LOGIN, login); |
|
|
|
|
|
|
|
if (BuildConfig.IS_OFFLINE_VERSION) { |
|
|
|
intent.putExtra(AuthSuccessActivity.TIME, (int)(((double) (verifEndTime - verifStartTime)) / 1e6)); |
|
|
|
} |
|
|
|
|
|
|
|
startActivity(intent); |
|
|
|
finish(); |
|
|
|
} |
|
|
|
|
|
|
|
private void onFaceAuthFail(AuthenticationActivity.AuthFailReason reason) { |
|
|
|
if (faceFailCount < 4) { |
|
|
|
final FaceNotRecognizedFragment fragment = FaceNotRecognizedFragment.newInstance(); |
|
|
|
fragment.setListener(this); |
|
|
|
if (reason == AuthenticationActivity.AuthFailReason.SIMILARITY && BuildConfig.IS_OFFLINE_VERSION) |
|
|
|
{ |
|
|
|
fragment.setVerificationTime((int)((double)(verifEndTime - verifStartTime) / 1e6)); |
|
|
|
} |
|
|
|
fragment.setFailReason(reason); |
|
|
|
showFragment(fragment); |
|
|
|
} else { |
|
|
|
showFail(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void showFail() { |
|
|
|
Toast.makeText(this, R.string.access_denied, Toast.LENGTH_SHORT).show(); |
|
|
|
finish(); |
|
|
|
} |
|
|
|
|
|
|
|
private void showFragment(Fragment fragment) { |
|
|
|
final FragmentManager fragmentManager = getSupportFragmentManager(); |
|
|
|
if (fragmentManager.findFragmentByTag(fragment.toString()) == null) { |
|
|
|
if (!goingSomewhere) { |
|
|
|
goingSomewhere = true; |
|
|
|
fragmentManager |
|
|
|
.beginTransaction() |
|
|
|
.replace(R.id.container, fragment, fragment.toString()) |
|
|
|
.commit(); |
|
|
|
goingSomewhere = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |