Skip to content

Commit

Permalink
changes to a few functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaravichow committed May 14, 2021
1 parent d2f6ca1 commit ae4cac2
Show file tree
Hide file tree
Showing 7 changed files with 518 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,47 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.aravi.dotpro.activities.main;
package com.aravi.dot.activities.main;

import android.Manifest;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityManager;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.aravi.dotpro.BuildConfig;
import com.aravi.dotpro.R;
import com.aravi.dotpro.Utils;
import com.aravi.dotpro.activities.log.LogsActivity;
import com.aravi.dotpro.databinding.ActivityMainBinding;
import com.aravi.dotpro.manager.PreferenceManager;
import com.aravi.dotpro.service.DotService;
import com.aravi.dot.BuildConfig;
import com.aravi.dot.R;
import com.aravi.dot.activities.custom.CustomisationActivity;
import com.aravi.dot.activities.log.LogsActivity;
import com.aravi.dot.databinding.ActivityMainBinding;
import com.aravi.dot.manager.AdvertisementManager;
import com.aravi.dot.manager.PreferenceManager;
import com.aravi.dot.service.DotService;
import com.aravi.dot.util.Utils;
import com.facebook.ads.InterstitialAd;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;


public class MainActivity extends AppCompatActivity {
private static final int MY_REQUEST_CODE = 1802;
private boolean TRIGGERED_START = false;

private PreferenceManager sharedPreferenceManager;
private Intent serviceIntent;
private AdvertisementManager advertisementManager;
private ActivityMainBinding mBinding;
private InterstitialAd interstitialAd;

@Override
protected void onStart() {
Expand All @@ -62,13 +71,44 @@ protected void onCreate(Bundle savedInstanceState) {
mBinding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot());
sharedPreferenceManager = PreferenceManager.getInstance(getApplication());
advertisementManager = AdvertisementManager.getInstance(getApplication());
loadFromPrefs();
init();
loadAd();
checkAutoStartRequirement();
}

private void init() {
private void loadAd() {
interstitialAd = new InterstitialAd(this, "-----");
interstitialAd.loadAd();
advertisementManager.setBannerAd(mBinding.adLayout);
}

private void loadFromPrefs() {
mBinding.vibrationSwitch.setChecked(sharedPreferenceManager.isVibrationEnabled());
mBinding.locationSwitch.setChecked(sharedPreferenceManager.isLocationEnabled());
mBinding.mainSwitch.setChecked(sharedPreferenceManager.isServiceEnabled());
}

private void init() {
mBinding.locationSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
new MaterialAlertDialogBuilder(MainActivity.this)
.setIcon(ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_round_location))
.setTitle("Requires Location Permission")
.setMessage("This features requires LOCATION PERMISSION to work as expected\n\nNOTE: This app doesn't have permission to connect to internet so your data is safe on your device.")
.setNeutralButton("Later", (dialog, which) -> mBinding.locationSwitch.setChecked(false))
.setPositiveButton("Continue", (dialog, which) -> {
askPermission(Manifest.permission.ACCESS_FINE_LOCATION);
})
.show();
} else {
sharedPreferenceManager.setLocationEnabled(true);
}
}

});
mBinding.vibrationSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> sharedPreferenceManager.setVibrationEnabled(isChecked));
mBinding.mainSwitch.setOnCheckedChangeListener((buttonView, b) -> {
if (b) {
Expand All @@ -79,33 +119,27 @@ private void init() {
TRIGGERED_START = false;
}
});
mBinding.align.setOnCheckedChangeListener((group, i) -> {
// fixed: Resource IDs will be non-final in Android Gradle Plugin version 5.0, avoid using them in switch case statements
// fix source : http://tools.android.com/tips/non-constant-fields
if (i == R.id.topLeft) {
sharedPreferenceManager.setPosition(0);
} else if (i == R.id.topRight) {
sharedPreferenceManager.setPosition(1);
}
});

mBinding.twitterButton.setOnClickListener(v -> openWeb("https://www.twitter.com/kamaravichow"));
mBinding.githubButton.setOnClickListener(v -> openWeb("https://www.github.com/kamaravichow"));
mBinding.logsOption.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, LogsActivity.class);
startActivity(intent);
});
mBinding.customisationOption.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, CustomisationActivity.class)));

mBinding.shareOption.setOnClickListener(v -> {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Protect your camera and microphone privacy with SafeDot. Download from Google Play : https://play.google.com/store/apps/details?id=com.aravi.dotpro");
shareIntent.setType("text/plain");
startActivity(shareIntent);
});

mBinding.versionText.setText("Version - " + BuildConfig.VERSION_NAME);
}

private void checkForAccessibilityAndStart() {

if (!accessibilityPermission(getApplicationContext(), DotService.class)) {
mBinding.mainSwitch.setChecked(false);
new MaterialAlertDialogBuilder(this)
Expand All @@ -130,11 +164,11 @@ private void checkForAccessibilityAndStart() {

private void stopService() {
if (isAccessibilityServiceRunning()) {
sharedPreferenceManager.setServiceEnabled(false);
// sharedPreferenceManager.setServiceEnabled(false);
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivity(intent);
Toast.makeText(this, getString(R.string.close_app_note), Toast.LENGTH_SHORT).show();
}
showSnack(getString(R.string.close_app_note));
}

// @Override
Expand Down Expand Up @@ -172,12 +206,12 @@ public static boolean accessibilityPermission(Context context, Class<?> cls) {
}


private void sendFeedbackEmail() {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", getString(R.string.feedback_email_address), null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedback_subject));
emailIntent.putExtra(Intent.EXTRA_TEXT, "Device Information : \n----- Don't clear these ----\n " + Build.DEVICE + " ,\n " + Build.BOARD + " ,\n " + Build.BRAND + " , " + Build.MANUFACTURER + " ,\n " + Build.MODEL + "\n ------ ");
startActivity(Intent.createChooser(emailIntent, "Send feedback..."));
}
// private void sendFeedbackEmail() {
// Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", getString(R.string.feedback_email_address), null));
// emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedback_subject));
// emailIntent.putExtra(Intent.EXTRA_TEXT, "Device Information : \n----- Don't clear these ----\n " + Build.DEVICE + " ,\n " + Build.BOARD + " ,\n " + Build.BRAND + " , " + Build.MANUFACTURER + " ,\n " + Build.MODEL + "\n ------ ");
// startActivity(Intent.createChooser(emailIntent, "Send feedback..."));
// }


/**
Expand Down Expand Up @@ -213,6 +247,19 @@ private void openWeb(String url) {
startActivity(i);
}


/**
* Asks permission runtime
*
* @param permission
*/
private void askPermission(String permission) {
if (!(ContextCompat.checkSelfPermission(this, permission) == 0)) {
requestPermissions(new String[]{permission}, 0);
sharedPreferenceManager.setLocationEnabled(true);
}
}

/**
* Chinese ROM's kill the app services frequently so AutoStart Permission is required
*/
Expand All @@ -223,12 +270,22 @@ private void checkAutoStartRequirement() {
|| ("oppo".equalsIgnoreCase(manufacturer))
|| ("vivo".equalsIgnoreCase(manufacturer))
|| ("Honor".equalsIgnoreCase(manufacturer))) {
Utils.showAutoStartDialog(MainActivity.this);
Utils.showAutoStartDialog(MainActivity.this, manufacturer);
sharedPreferenceManager.setFirstLaunch();
}
}
}


@Override
protected void onPostResume() {
assert interstitialAd != null;
if (interstitialAd.isAdLoaded()) {
interstitialAd.show();
}
super.onPostResume();
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/com/aravi/dot/helper/ApplicationHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2021. Aravind Chowdary (@kamaravichow)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.aravi.dot.helper;

import android.app.Application;

public class ApplicationHelper {
private static final String TAG = ApplicationHelper.class.getSimpleName();
private static final String REMAINDER_CHANNEL = "REMINDER_CHANNEL";

public static void initApplicationHelper(Application application) {
}

}
Loading

0 comments on commit ae4cac2

Please sign in to comment.