Skip to content

Commit

Permalink
Backward Compatibility to Kitkat.
Browse files Browse the repository at this point in the history
  • Loading branch information
xMansour committed Jul 4, 2019
1 parent aef7c18 commit 829c9df
Show file tree
Hide file tree
Showing 16 changed files with 1,215 additions and 1,094 deletions.
1 change: 1 addition & 0 deletions Application/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.GET_TASKS" /> <!--FOR FOREGROUND APPS BEFORE LOLLIPOP-->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.mansourappdevelopment.androidapp.kidsafe.activities;

import android.content.Intent;
import android.os.Build;
import android.os.PersistableBundle;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
Expand All @@ -22,75 +19,73 @@
import com.mansourappdevelopment.androidapp.kidsafe.utils.SharedPrefsUtils;

public class ChildSignedInActivity extends AppCompatActivity {
private static final String TAG = "ChildSignedInTAG";
public static final int JOB_ID = 38;
public static final String CHILD_EMAIL = "childEmail";
private FirebaseAuth auth;
private FirebaseUser user;
private ImageButton btnBack;
private ImageButton btnSettings;
private TextView txtTitle;
private FrameLayout toolbar;

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child_signed_in);

boolean childFirstLaunch = SharedPrefsUtils.getBooleanPreference(this, Constant.CHILD_FIRST_LAUNCH, true);
if (childFirstLaunch)
startActivity(new Intent(this, PermissionsActivity.class));
else {

auth = FirebaseAuth.getInstance();
user = auth.getCurrentUser();

String email = user.getEmail();
PersistableBundle bundle = new PersistableBundle();
bundle.putString(CHILD_EMAIL, email);

toolbar = (FrameLayout) findViewById(R.id.toolbar);
btnBack = (ImageButton) findViewById(R.id.btnBack);
btnBack.setImageDrawable(getResources().getDrawable(R.drawable.ic_home_));
btnSettings = (ImageButton) findViewById(R.id.btnSettings);
btnSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ChildSignedInActivity.this, SettingsActivity.class);
startActivity(intent);
}
});
txtTitle = (TextView) findViewById(R.id.txtTitle);
txtTitle.setText(getString(R.string.home));

//schedualJob(bundle);
startMainForegroundService(email);
}
}


@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Constant.DEVICE_ADMIN_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Log.i(TAG, "onActivityResult: DONE");
}
}
}

private void startMainForegroundService(String email) {
Intent intent = new Intent(this, MainForegroundService.class);
intent.putExtra(CHILD_EMAIL, email);
ContextCompat.startForegroundService(this, intent);

}

@Override
public void onBackPressed() {
super.onBackPressed();
}
public static final int JOB_ID = 38;
public static final String CHILD_EMAIL = "childEmail";
private static final String TAG = "ChildSignedInTAG";
private FirebaseAuth auth;
private FirebaseUser user;
private ImageButton btnBack;
private ImageButton btnSettings;
private TextView txtTitle;
private FrameLayout toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child_signed_in);

boolean childFirstLaunch = SharedPrefsUtils.getBooleanPreference(this, Constant.CHILD_FIRST_LAUNCH, true);
if (childFirstLaunch)
startActivity(new Intent(this, PermissionsActivity.class));
else {

auth = FirebaseAuth.getInstance();
user = auth.getCurrentUser();

String email = user.getEmail();
/*PersistableBundle bundle = new PersistableBundle();
bundle.putString(CHILD_EMAIL, email);*/

toolbar = (FrameLayout) findViewById(R.id.toolbar);
btnBack = (ImageButton) findViewById(R.id.btnBack);
btnBack.setImageDrawable(getResources().getDrawable(R.drawable.ic_home_));
btnSettings = (ImageButton) findViewById(R.id.btnSettings);
btnSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ChildSignedInActivity.this, SettingsActivity.class);
startActivity(intent);
}
});
txtTitle = (TextView) findViewById(R.id.txtTitle);
txtTitle.setText(getString(R.string.home));

//schedualJob(bundle);
startMainForegroundService(email);
}
}

private void startMainForegroundService(String email) {
Intent intent = new Intent(this, MainForegroundService.class);
intent.putExtra(CHILD_EMAIL, email);
ContextCompat.startForegroundService(this, intent);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Constant.DEVICE_ADMIN_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Log.i(TAG, "onActivityResult: DONE");
}
}
}

@Override
public void onBackPressed() {
super.onBackPressed();
}



Expand Down Expand Up @@ -119,6 +114,6 @@ private void cancelJob() {
jobScheduler.cancel(JOB_ID);
//Job cancelled
}*/


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mansourappdevelopment.androidapp.kidsafe.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
Expand All @@ -20,8 +19,6 @@
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
Expand All @@ -38,6 +35,7 @@
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.mansourappdevelopment.androidapp.kidsafe.R;
import com.mansourappdevelopment.androidapp.kidsafe.dialogfragments.InformationDialogFragment;
import com.mansourappdevelopment.androidapp.kidsafe.dialogfragments.LoadingDialogFragment;
import com.mansourappdevelopment.androidapp.kidsafe.dialogfragments.RecoverPasswordDialogFragment;
import com.mansourappdevelopment.androidapp.kidsafe.interfaces.OnPasswordResetListener;
Expand Down Expand Up @@ -73,19 +71,7 @@ protected void onCreate(Bundle savedInstanceState) {

fragmentManager = getSupportFragmentManager();
LocaleUtils.setAppLanguage(this);
if (!isGooglePlayServicesAvailable(this)) {
Toast.makeText(this, getString(R.string.please_download_google_play_services), Toast.LENGTH_SHORT).show();
btnLogin.setEnabled(false);
btnLogin.setClickable(false);
btnGoogleSignUp.setClickable(false);
btnGoogleSignUp.setClickable(false);
txtSignUp.setEnabled(false);
txtSignUp.setClickable(false);
txtForgotPassword.setEnabled(false);
txtForgotPassword.setClickable(false);
checkBoxRememberMe.setEnabled(false);
checkBoxRememberMe.setClickable(false);
}


//FirebaseApp.initializeApp(this);
auth = FirebaseAuth.getInstance();
Expand Down Expand Up @@ -145,31 +131,37 @@ public void onClick(View v) {
txtLogInEmail.setText(emailPrefs);
txtLogInPassword.setText(passwordPrefs);
}

if (!Validators.isGooglePlayServicesAvailable(this)) {
startInformationDialogFragment(getString(R.string.please_download_google_play_services));
//Toast.makeText(this, getString(R.string.please_download_google_play_services), Toast.LENGTH_SHORT).show();
btnLogin.setEnabled(false);
btnLogin.setClickable(false);
btnGoogleSignUp.setClickable(false);
btnGoogleSignUp.setClickable(false);
txtSignUp.setEnabled(false);
txtSignUp.setClickable(false);
txtForgotPassword.setEnabled(false);
txtForgotPassword.setClickable(false);
checkBoxRememberMe.setEnabled(false);
checkBoxRememberMe.setClickable(false);
}
}

@Override
protected void onStart() {
super.onStart();
if (autoLoginPrefs) {
FirebaseUser user = auth.getCurrentUser();
if (user != null) {
String email = user.getEmail();
checkMode(email);
}
if (Validators.isInternetAvailable(this)) {
FirebaseUser user = auth.getCurrentUser();
if (user != null) {
String email = user.getEmail();
checkMode(email);
}
} else startInformationDialogFragment(getResources().getString(R.string.you_re_offline_ncheck_your_connection_and_try_again));
}
}

private boolean isGooglePlayServicesAvailable(Activity activity) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int status = googleApiAvailability.isGooglePlayServicesAvailable(activity);
if (status != ConnectionResult.SUCCESS) {
if (googleApiAvailability.isUserResolvableError(status))
googleApiAvailability.getErrorDialog(activity, status, 2404).show();
return false;
}

return true;
}

private void autoLogin() {
SharedPrefsUtils.setBooleanPreference(this, Constant.AUTO_LOGIN, checkBoxRememberMe.isChecked());
Expand All @@ -189,8 +181,9 @@ public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = auth.getCurrentUser();
String email = user.getEmail();
if (Validators.isVerified(user)) checkMode(email);
else startAccountVerificationActivity();
/*if (Validators.isVerified(user))*/
checkMode(email);
//else startAccountVerificationActivity();
} else {
String errorCode;
try {
Expand Down Expand Up @@ -231,9 +224,23 @@ private boolean isValid() {
return false;
}

if (!Validators.isInternetAvailable(this)) {
startInformationDialogFragment(getResources().getString(R.string.you_re_offline_ncheck_your_connection_and_try_again));
return false;
}

return true;
}

private void startInformationDialogFragment(String message) {
InformationDialogFragment informationDialogFragment = new InformationDialogFragment();
Bundle bundle = new Bundle();
bundle.putString(Constant.INFORMATION_MESSAGE, message);
informationDialogFragment.setArguments(bundle);
informationDialogFragment.setCancelable(false);
informationDialogFragment.show(getSupportFragmentManager(), Constant.INFORMATION_DIALOG_FRAGMENT_TAG);
}

private void startLoadingFragment(LoadingDialogFragment loadingDialogFragment) {
loadingDialogFragment.setCancelable(false);
loadingDialogFragment.show(fragmentManager, Constant.LOADING_FRAGMENT);
Expand Down Expand Up @@ -276,11 +283,6 @@ private void startChildSignedInActivity() {
startActivity(intent);
}

private void startAccountVerificationActivity() {
Intent intent = new Intent(this, AccountVerificationActivity.class);
startActivity(intent);
}

private void startModeSelectionActivity() {
Intent intent = new Intent(this, ModeSelectionActivity.class);
startActivity(intent);
Expand All @@ -295,10 +297,18 @@ private void sendPasswordRecoveryEmail() {
}

private void signInWithGoogle() {
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.id)).requestEmail().build();
GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions);
Intent signInIntent = googleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, Constant.RC_SIGN_IN);
if (Validators.isInternetAvailable(this)) {
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.id)).requestEmail().build();
GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions);
Intent signInIntent = googleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, Constant.RC_SIGN_IN);
} else startInformationDialogFragment(getResources().getString(R.string.you_re_offline_ncheck_your_connection_and_try_again));

}

private void startAccountVerificationActivity() {
Intent intent = new Intent(this, AccountVerificationActivity.class);
startActivity(intent);
}

@Override
Expand Down Expand Up @@ -357,5 +367,4 @@ public void onComplete(@NonNull Task<Void> task) {
});

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.mansourappdevelopment.androidapp.kidsafe.R;
import com.mansourappdevelopment.androidapp.kidsafe.dialogfragments.ConfirmationDialogFragment;
import com.mansourappdevelopment.androidapp.kidsafe.dialogfragments.GoogleChildSignUpDialogFragment;
import com.mansourappdevelopment.androidapp.kidsafe.dialogfragments.InformationDialogFragment;
import com.mansourappdevelopment.androidapp.kidsafe.dialogfragments.LoadingDialogFragment;
import com.mansourappdevelopment.androidapp.kidsafe.interfaces.OnConfirmationListener;
import com.mansourappdevelopment.androidapp.kidsafe.interfaces.OnGoogleChildSignUp;
Expand Down Expand Up @@ -314,9 +315,23 @@ private boolean isValid() {
return false;
}

if (!Validators.isInternetAvailable(this)) {
startInformationDialogFragment();
return false;
}

return true;
}

private void startInformationDialogFragment() {
InformationDialogFragment informationDialogFragment = new InformationDialogFragment();
Bundle bundle = new Bundle();
bundle.putString(Constant.INFORMATION_MESSAGE, getResources().getString(R.string.you_re_offline_ncheck_your_connection_and_try_again));
informationDialogFragment.setArguments(bundle);
informationDialogFragment.setCancelable(false);
informationDialogFragment.show(getSupportFragmentManager(), Constant.INFORMATION_DIALOG_FRAGMENT_TAG);
}

private void openFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
Expand All @@ -325,10 +340,12 @@ private void openFileChooser() {
}

private void signInWithGoogle() {
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.id)).requestEmail().build();
GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions);
Intent signInIntent = googleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, Constant.RC_SIGN_IN);
if (Validators.isInternetAvailable(this)) {
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.id)).requestEmail().build();
GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions);
Intent signInIntent = googleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, Constant.RC_SIGN_IN);
} else startInformationDialogFragment();
}

private void verifyAccount() {
Expand Down
Loading

0 comments on commit 829c9df

Please sign in to comment.