Skip to content

Commit

Permalink
Merge pull request #18 from DevLuuk/develop
Browse files Browse the repository at this point in the history
Develop version 1.7
  • Loading branch information
DevLuuk committed Nov 12, 2019
2 parents 91b5931 + ec8f036 commit be0fd39
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 27
defaultConfig {
applicationId "nl.devluuk.sleepywifi"
minSdkVersion 23
targetSdkVersion 28
versionCode 7
versionName '1.6'
targetSdkVersion 27
versionCode 8
versionName '1.7'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -23,13 +23,13 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.karumi:dexter:4.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:preference-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
}
10 changes: 4 additions & 6 deletions app/src/main/java/nl/devluuk/sleepywifi/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.PreferenceManager;
Expand All @@ -22,7 +21,6 @@
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
Expand Down Expand Up @@ -55,7 +53,7 @@ protected void onResume() {
super.onResume();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
status = prefs.getBoolean(getResources().getString(R.string.app_state), true);
status = prefs.getBoolean(getResources().getString(R.string.app_state), false);
}

@Override
Expand Down Expand Up @@ -199,7 +197,7 @@ public boolean getBackgroundStatus() {

public boolean checkPrefStatus(String key) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
return status = prefs.getBoolean(key, true);
return status = prefs.getBoolean(key, false);
}

public void setPreference(boolean status) {
Expand Down Expand Up @@ -248,8 +246,8 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
if (key.equals(getString(R.string.bluetooth_state))) {
sharedPreferences.getBoolean(key, false);
}
if (key.equals("app_state")) {
sharedPreferences.getBoolean(key, true);
if (key.equals(getString(R.string.app_state))) {
sharedPreferences.getBoolean(key, false);
}
}
}
26 changes: 14 additions & 12 deletions app/src/main/java/nl/devluuk/sleepywifi/ScreenReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.pm.PackageManager;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.util.Log;

Expand All @@ -23,7 +22,7 @@ public class ScreenReceiver extends BroadcastReceiver {
boolean bluetoothWasOn = false;
boolean bluetoothState;
int delayTime;
boolean appState;
boolean appState = false;
private static final String TAG = ScreenReceiver.class.getSimpleName();

@Override
Expand All @@ -32,13 +31,14 @@ public void onReceive(final Context context, final Intent intent) {
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
bluetoothState = prefs.getBoolean(context.getResources().getString(R.string.bluetooth_state), false);
appState = prefs.getBoolean(context.getResources().getString(R.string.app_state), true);
appState = prefs.getBoolean(context.getResources().getString(R.string.app_state), false);
delayTime = prefs.getInt(context.getResources().getString(R.string.key_power_off_time), 1);

PackageManager pm = context.getPackageManager();
final boolean deviceHasBluetooth = pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);

if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
if (appState) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
if (wifiManager.isWifiEnabled()) {
//new Sleep(this).execute();
wifiManager.setWifiEnabled(false);
Expand All @@ -56,19 +56,21 @@ public void onReceive(final Context context, final Intent intent) {
}
}
}
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
if (wifiWasOn) {
wifiManager.setWifiEnabled(true);
}
if (bluetoothState) {
if (deviceHasBluetooth) {
if (bluetoothWasOn) {
bluetoothAdapter.enable();
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
if (wifiWasOn) {
wifiManager.setWifiEnabled(true);
}
if (bluetoothState) {
if (deviceHasBluetooth) {
if (bluetoothWasOn) {
bluetoothAdapter.enable();
}
}
}
}
}
}

private class Sleep extends AsyncTask<Void, Void, Void> {

private WeakReference<ScreenReceiver> activityReference;
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.2'


// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit be0fd39

Please sign in to comment.