Skip to content

Commit

Permalink
Merge pull request openMF#709 from mayank-kgp/ndk
Browse files Browse the repository at this point in the history
Integrated NDK and Pass Code Feature
  • Loading branch information
therajanmaurya authored Jul 25, 2017
2 parents 1b87333 + fa1cdb5 commit 3fb3ff0
Show file tree
Hide file tree
Showing 24 changed files with 751 additions and 5 deletions.
4 changes: 4 additions & 0 deletions mifosng-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
android:label="@string/sync_savingsaccounttransactions"
android:screenOrientation="portrait"/>

<activity
android:name=".passcode.PassCodeActivity"
android:label="@string/pass_code"
android:screenOrientation="portrait" />

<service android:name=".activity.pathtracking.PathTrackingService"
android:exported="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.mifosxdroid.login.LoginActivity;
import com.mifos.mifosxdroid.online.DashboardActivity;
import com.mifos.utils.ForegroundChecker;
import com.mifos.utils.PrefManager;


Expand All @@ -24,6 +25,7 @@ public class SplashScreenActivity extends MifosBaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ForegroundChecker.init();
if (!PrefManager.isAuthenticated()) {
PrefManager.setInstanceUrl(BaseUrl.PROTOCOL_HTTPS
+ BaseUrl.API_ENDPOINT + BaseUrl.API_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import com.mifos.mifosxdroid.injection.component.ActivityComponent;
import com.mifos.mifosxdroid.injection.component.DaggerActivityComponent;
import com.mifos.mifosxdroid.injection.module.ActivityModule;
import com.mifos.mifosxdroid.passcode.PassCodeActivity;
import com.mifos.utils.Constants;
import com.mifos.utils.ForegroundChecker;
import com.mifos.utils.PrefManager;

/**
* @author fomenkoo
*/
public class MifosBaseActivity extends AppCompatActivity implements BaseActivityCallback {
public class MifosBaseActivity extends AppCompatActivity implements BaseActivityCallback,
ForegroundChecker.Listener {

protected Toolbar toolbar;
private ActivityComponent mActivityComponent;
Expand Down Expand Up @@ -128,8 +131,12 @@ public void hideKeyboard(View view) {

@Override
public void logout() {
PrefManager.clearPrefs();
startActivity(new Intent(this, SplashScreenActivity.class));
if (PrefManager.getPassCodeStatus()) {
startActivity(new Intent(this, PassCodeActivity.class));
} else {
PrefManager.clearPrefs();
startActivity(new Intent(this, SplashScreenActivity.class));
}
finish();
}

Expand Down Expand Up @@ -158,4 +165,24 @@ public void clearFragmentBackStack() {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.mifos.mifosxdroid.online.search.SearchFragment;
import com.mifos.mifosxdroid.online.surveylist.SurveyListFragment;
import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitFragment;
import com.mifos.mifosxdroid.passcode.PassCodeActivity;

import dagger.Component;

Expand All @@ -71,6 +72,8 @@ public interface ActivityComponent {

void inject(LoginActivity loginActivity);

void inject(PassCodeActivity passCodeActivity);

void inject(CenterListFragment centerListFragment);

void inject(ClientChargeFragment clientChargeFragment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.mifosxdroid.core.util.Toaster;
import com.mifos.mifosxdroid.online.DashboardActivity;
import com.mifos.mifosxdroid.passcode.PassCodeActivity;
import com.mifos.objects.user.User;
import com.mifos.utils.Constants;
import com.mifos.utils.Network;
import com.mifos.utils.PrefManager;
import com.mifos.utils.ValidationUtil;
Expand Down Expand Up @@ -180,7 +182,13 @@ public void onLoginSuccessful(User user) {
Toast.makeText(this, getString(R.string.toast_welcome) + " " + user.getUsername(),
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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
2 changes: 2 additions & 0 deletions mifosng-android/src/main/java/com/mifos/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public class Constants {

public static final String ACTIVATE_TYPE = "activation_type";

public static final String INTIAL_LOGIN = "initial_login";

//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.
public static final int REQUEST_PERMISSION_SETTING = 254;
Expand Down
24 changes: 24 additions & 0 deletions mifosng-android/src/main/java/com/mifos/utils/EncryptionUtil.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit 3fb3ff0

Please sign in to comment.