New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated NDK and Pass Code Feature #709

Merged
merged 1 commit into from Jul 25, 2017
Jump to file or symbol
Failed to load files and symbols.
+751 −5
Diff settings

Always

Just for now

@@ -132,6 +132,10 @@
android:label="@string/sync_savingsaccounttransactions" android:label="@string/sync_savingsaccounttransactions"
android:screenOrientation="portrait"/> android:screenOrientation="portrait"/>
<activity
android:name=".passcode.PassCodeActivity"
android:label="@string/pass_code"
android:screenOrientation="portrait" />
<service android:name=".activity.pathtracking.PathTrackingService" <service android:name=".activity.pathtracking.PathTrackingService"
android:exported="false"/> android:exported="false"/>
@@ -12,6 +12,7 @@
import com.mifos.mifosxdroid.core.MifosBaseActivity; import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.mifosxdroid.login.LoginActivity; import com.mifos.mifosxdroid.login.LoginActivity;
import com.mifos.mifosxdroid.online.DashboardActivity; import com.mifos.mifosxdroid.online.DashboardActivity;
import com.mifos.utils.ForegroundChecker;
import com.mifos.utils.PrefManager; import com.mifos.utils.PrefManager;
@@ -24,6 +25,7 @@
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash); setContentView(R.layout.activity_splash);
ForegroundChecker.init();
if (!PrefManager.isAuthenticated()) { if (!PrefManager.isAuthenticated()) {
PrefManager.setInstanceUrl(BaseUrl.PROTOCOL_HTTPS PrefManager.setInstanceUrl(BaseUrl.PROTOCOL_HTTPS
+ BaseUrl.API_ENDPOINT + BaseUrl.API_PATH); + BaseUrl.API_ENDPOINT + BaseUrl.API_PATH);
@@ -24,13 +24,16 @@
import com.mifos.mifosxdroid.injection.component.ActivityComponent; import com.mifos.mifosxdroid.injection.component.ActivityComponent;
import com.mifos.mifosxdroid.injection.component.DaggerActivityComponent; import com.mifos.mifosxdroid.injection.component.DaggerActivityComponent;
import com.mifos.mifosxdroid.injection.module.ActivityModule; import com.mifos.mifosxdroid.injection.module.ActivityModule;
import com.mifos.mifosxdroid.passcode.PassCodeActivity;
import com.mifos.utils.Constants; import com.mifos.utils.Constants;
import com.mifos.utils.ForegroundChecker;
import com.mifos.utils.PrefManager; import com.mifos.utils.PrefManager;
/** /**
* @author fomenkoo * @author fomenkoo
*/ */
public class MifosBaseActivity extends AppCompatActivity implements BaseActivityCallback { public class MifosBaseActivity extends AppCompatActivity implements BaseActivityCallback,
ForegroundChecker.Listener {
protected Toolbar toolbar; protected Toolbar toolbar;
private ActivityComponent mActivityComponent; private ActivityComponent mActivityComponent;
@@ -128,8 +131,12 @@ public void hideKeyboard(View view) {
@Override @Override
public void logout() { public void logout() {
PrefManager.clearPrefs(); if (PrefManager.getPassCodeStatus()) {
startActivity(new Intent(this, SplashScreenActivity.class)); startActivity(new Intent(this, PassCodeActivity.class));
} else {
PrefManager.clearPrefs();
startActivity(new Intent(this, SplashScreenActivity.class));
}
finish(); finish();
} }
@@ -158,4 +165,24 @@ public void clearFragmentBackStack() {
fm.popBackStack(backStackId, FragmentManager.POP_BACK_STACK_INCLUSIVE); fm.popBackStack(backStackId, FragmentManager.POP_BACK_STACK_INCLUSIVE);
} }
} }
@Override
protected void onResume() {
super.onResume();
ForegroundChecker.get().addListener(this);
ForegroundChecker.get().onActivityResumed();
}
@Override
protected void onPause() {
super.onPause();
ForegroundChecker.get().onActivityPaused();
}
@Override
public void onBecameForeground() {
Intent intent = new Intent(this, PassCodeActivity.class);
intent.putExtra(Constants.INTIAL_LOGIN, false);
startActivity(intent);
}
} }
@@ -57,6 +57,7 @@
import com.mifos.mifosxdroid.online.search.SearchFragment; import com.mifos.mifosxdroid.online.search.SearchFragment;
import com.mifos.mifosxdroid.online.surveylist.SurveyListFragment; import com.mifos.mifosxdroid.online.surveylist.SurveyListFragment;
import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitFragment; import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitFragment;
import com.mifos.mifosxdroid.passcode.PassCodeActivity;
import dagger.Component; import dagger.Component;
@@ -70,6 +71,8 @@
void inject(LoginActivity loginActivity); void inject(LoginActivity loginActivity);
void inject(PassCodeActivity passCodeActivity);
void inject(CenterListFragment centerListFragment); void inject(CenterListFragment centerListFragment);
void inject(ClientChargeFragment clientChargeFragment); void inject(ClientChargeFragment clientChargeFragment);
@@ -24,7 +24,9 @@
import com.mifos.mifosxdroid.core.MifosBaseActivity; import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.mifosxdroid.core.util.Toaster; import com.mifos.mifosxdroid.core.util.Toaster;
import com.mifos.mifosxdroid.online.DashboardActivity; import com.mifos.mifosxdroid.online.DashboardActivity;
import com.mifos.mifosxdroid.passcode.PassCodeActivity;
import com.mifos.objects.user.User; import com.mifos.objects.user.User;
import com.mifos.utils.Constants;
import com.mifos.utils.Network; import com.mifos.utils.Network;
import com.mifos.utils.PrefManager; import com.mifos.utils.PrefManager;
import com.mifos.utils.ValidationUtil; import com.mifos.utils.ValidationUtil;
@@ -180,7 +182,13 @@ public void onLoginSuccessful(User user) {
Toast.makeText(this, getString(R.string.toast_welcome) + " " + user.getUsername(), Toast.makeText(this, getString(R.string.toast_welcome) + " " + user.getUsername(),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
startActivity(new Intent(this, DashboardActivity.class)); if (PrefManager.getPassCodeStatus()) {
startActivity(new Intent(this, DashboardActivity.class));
} else {
Intent intent = new Intent(this, PassCodeActivity.class);
intent.putExtra(Constants.INTIAL_LOGIN, true);
startActivity(intent);
}
finish(); finish();
} }
@@ -0,0 +1,221 @@
package com.mifos.mifosxdroid.passcode;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.AppCompatButton;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.mifos.mifosxdroid.R;
import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.mifosxdroid.core.util.Toaster;
import com.mifos.mifosxdroid.login.LoginActivity;
import com.mifos.mifosxdroid.online.DashboardActivity;
import com.mifos.utils.Constants;
import com.mifos.utils.EncryptionUtil;
import com.mifos.utils.Network;
import com.mifos.utils.PassCodeView;
import com.mifos.utils.PrefManager;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class PassCodeActivity extends MifosBaseActivity {
@BindView(R.id.cl_rootview)
NestedScrollView clRootview;
@BindView(R.id.btn_login)
AppCompatButton btnLogin;
@BindView(R.id.btn_forgot_passcode)
AppCompatButton btnForgotPasscode;
@BindView(R.id.pv_passcode)
PassCodeView passCodeView;
@BindView(R.id.btn_skip)
AppCompatButton btnSkip;
@BindView(R.id.btn_save)
AppCompatButton btnSave;
@BindView(R.id.tv_passcode)
TextView tvPasscodeIntro;
@BindView(R.id.iv_visibility)
ImageView ivVisibility;
private int counter = 0;
private boolean isInitialScreen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pass_code);
getActivityComponent().inject(this);
ButterKnife.bind(this);
isInitialScreen = getIntent().getBooleanExtra(Constants.INTIAL_LOGIN, false);
if (PrefManager.getPassCodeStatus()) {
btnSkip.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
tvPasscodeIntro.setVisibility(View.GONE);
btnLogin.setVisibility(View.VISIBLE);
btnForgotPasscode.setVisibility(View.VISIBLE);
}
}
@OnClick(R.id.btn_skip)
public void skip() {
startDashBoardActivity();
}
@OnClick(R.id.btn_save)
public void savePassCode() {
if (isPassCodeLengthCorrect()) {
PrefManager.setPassCode(EncryptionUtil.getHash(passCodeView.getPasscode()));
startDashBoardActivity();
}
}
@OnClick(R.id.btn_login)
public void loginUsingPassCode() {
if (!isInternetAvailable()) {
return;
}
if (counter == 3) {
Toaster.show(clRootview, R.string.incorrect_passcode_more_than_three);
PrefManager.clearPrefs();
startLoginActivity();
return;
}
if (isPassCodeLengthCorrect()) {
String passwordEntered = EncryptionUtil.getHash(passCodeView.getPasscode());
if (PrefManager.getPassCode().equals(passwordEntered)) {
startDashBoardActivity();
} else {
counter++;
passCodeView.clearPasscodeField();
Toaster.show(clRootview, R.string.incorrect_passcode);
}
}
}
@OnClick(R.id.btn_forgot_passcode)
public void forgotPassCode() {
PrefManager.clearPrefs();
startLoginActivity();
}
private boolean isInternetAvailable() {
if (Network.isOnline(this)) {
return true;
} else {
Toaster.show(clRootview, getString(R.string.error_not_connected_internet));
return false;
}
}
@OnClick(R.id.btn_one)
public void clickedOne() {
passCodeView.enterCode(getString(R.string.one));
}
@OnClick(R.id.btn_two)
public void clickedTwo() {
passCodeView.enterCode(getString(R.string.two));
}
@OnClick(R.id.btn_three)
public void clickedThree() {
passCodeView.enterCode(getString(R.string.three));
}
@OnClick(R.id.btn_four)
public void clickedFour() {
passCodeView.enterCode(getString(R.string.four));
}
@OnClick(R.id.btn_five)
public void clickedFive() {
passCodeView.enterCode(getString(R.string.five));
}
@OnClick(R.id.btn_six)
public void clickedSix() {
passCodeView.enterCode(getString(R.string.six));
}
@OnClick(R.id.btn_seven)
public void clickedSeven() {
passCodeView.enterCode(getString(R.string.seven));
}
@OnClick(R.id.btn_eight)
public void clickedEight() {
passCodeView.enterCode(getString(R.string.eight));
}
@OnClick(R.id.btn_nine)
public void clickedNine() {
passCodeView.enterCode(getString(R.string.nine));
}
@OnClick(R.id.btn_zero)
public void clickedZero() {
passCodeView.enterCode(getString(R.string.zero));
}
@OnClick(R.id.btn_back)
public void clickedBackSpace() {
passCodeView.backSpace();
}
@OnClick(R.id.iv_visibility)
public void visibilityChange() {
passCodeView.revertPassCodeVisibility();
if (!passCodeView.passcodeVisible()) {
ivVisibility.setColorFilter(ContextCompat.getColor(PassCodeActivity.this,
R.color.light_grey));
} else {
ivVisibility.setColorFilter(ContextCompat.getColor(PassCodeActivity.this,
R.color.gray_dark));
}
}
private boolean isPassCodeLengthCorrect() {
if (passCodeView.getPasscode().length() == 4) {
return true;
}
Toaster.show(clRootview, getString(R.string.error_passcode));
return false;
}
private void startDashBoardActivity() {
startActivity(new Intent(this, DashboardActivity.class));
finish();
}
private void startLoginActivity() {
Intent i = new Intent(PassCodeActivity.this, LoginActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
finish();
}
@Override
public void onBackPressed() {
//enabling back press only for initial login.
if (isInitialScreen) {
super.onBackPressed();
}
}
}
@@ -133,6 +133,8 @@
public static final String ACTIVATE_TYPE = "activation_type"; public static final String ACTIVATE_TYPE = "activation_type";
public static final String INTIAL_LOGIN = "initial_login";
//This needs to be 8 bits because validateRequestPermissionsRequestCode //This needs to be 8 bits because validateRequestPermissionsRequestCode
// in FragmentActivity requires requestCode to be of 8 bits, meaning the range is from 0 to 255. // in FragmentActivity requires requestCode to be of 8 bits, meaning the range is from 0 to 255.
public static final int REQUEST_PERMISSION_SETTING = 254; public static final int REQUEST_PERMISSION_SETTING = 254;
@@ -0,0 +1,24 @@
package com.mifos.utils;
import android.util.Log;
/**
* Created by mayankjindal on 30/06/17.
*/
public class EncryptionUtil {
static {
try {
System.loadLibrary("encryption");
} catch (UnsatisfiedLinkError e) {
Log.e("LoadJniLib", "Error: Could not load native library: " + e.getMessage());
}
}
private static final native String getPassCodeHash(String passcode);
public static String getHash(String passCode) {
return getPassCodeHash(passCode);
}
}
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.