I'm working on an existing project for adding a Lock screen for the user to enter the code. After verifying the code the Lock Screen will dismiss and the user can use the app normally. Thank you. I'm not an Android developer so it is very difficult for me. The project is coded in Kotlin and Java.
///mainapp is in Kotlin
package com.mainapp.view.activity
open class BaseActivity: AppCompatActivity() {
lateinit var repository: BasicRepository
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
pref = PreferenceManager(this)
setupContentWindow()
}
fun setupContentWindow() {
Helper.handleStatusBar(window, false, this)
}
override fun onResume() {
super.onResume()
if (requireCode()) {
val intent = EnterCodeActivity.intent(this, true)
startActivity(intent)
} else {
val intent = Intent(this, EnterCodeActivity::class.java)
startActivityForResult(intent, Helper.REQUEST_CODE)
}
}
///lockscreen is in java
package com.lockscreen.activity;
public class EnterCodeActivity extends AppCompatActivity {
public static Intent intent(Context context, boolean requireCode) {
Intent intent = new Intent(context, EnterPinActivity.class);
intent.putExtra("REQUIRE_CODE", requireCode);
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_enterpin);
final CodeLockListener codeLockListener = new CodeLockListener() {
@Override
public void onComplete(String code) {
checkCode(code);
}
@Override
public void onEmpty() {
Log.d(TAG, "Code empty");
}
};
mCodeLockView = (CodeLockView) findViewById(R.id.codelockView);
mIndicators = (Indicators) findViewById(R.id.indicators);
mCodeLockView.attachIndicators(mIndicators);
mCodeLockView.setCodeLockListener(codeLockListener);
mIndicators.setIndicatorType(Indicators.IndicatorType.FILL_WITH_ANIMATION);
}
private void checkCode(String code) {
APIManager.getInstance().verifyAuth(code, new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
if (response.code() == 200) {
setResult(RESULT_OK);
finish();
//dismiss the code lock view after verify the code
} else {
mTextTitle.setText("Incorrect Code!")
}
}
@Override
public void onFailure(Call<String> call, Throwable t) {
mTextTitle.setText("Incorrect Code!")
}
});
}