Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Use accelerometer and other fixes #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 50 additions & 21 deletions ScreenNotifications/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import groovy.swing.SwingBuilder
apply plugin: 'com.android.application'


android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
buildToolsVersion '23.0.2'

defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 18
versionName "0.12.0"
versionCode 19
versionName "0.13.0"
}

signingConfigs {
release {
storeFile file(System.properties['KEYSTORE_PATH'])
storePassword "PLACEHOLDER"
keyAlias System.properties['KEYSTORE_EMAIL']
keyPassword "PLACEHOLDER"
try {
storeFile file(System.properties['KEYSTORE_PATH'])
storePassword "PLACEHOLDER"
keyAlias System.properties['KEYSTORE_EMAIL']
keyPassword "PLACEHOLDER"
}
catch (ex) {
println "You should define KEYSTORE_PATH and KEYSTORE_EMAIL in a gradle.properties file."
//throw new InvalidUserDataException("You should define KEYSTORE_PATH and KEYSTORE_EMAIL in a gradle.properties file.")
}

}
}

Expand All @@ -37,22 +46,42 @@ dependencies {
compile 'fr.nicolaspomepuy:discreetapprate:2.0.3@aar'
}

// borrowed from https://www.timroes.de/2014/01/19/using-password-prompts-with-gradle-build-files/
// and https://www.timroes.de/2013/09/22/handling-signing-configs-with-gradle/
// see Tim Roes https://www.timroes.de/2014/01/19/using-password-prompts-with-gradle-build-files/
gradle.taskGraph.whenReady { taskGraph ->
// Only execute when we are trying to assemble a release build
if(taskGraph.hasTask(':ScreenNotifications:assembleRelease') || taskGraph.hasTask(':ScreenNotifications:installRelease')) {
def password = System.console().readPassword("\nPlease enter key passphrase: ")
if (taskGraph.hasTask(':ScreenNotifications:assembleRelease')) {
if(android.signingConfigs.release.storePassword.size() <= 0) {
def pass = ''
if (System.console() == null) {
new SwingBuilder().edt {
dialog(modal: true, // Otherwise the build will continue running before you closed the dialog
title: 'Enter password', // Dialog title
alwaysOnTop: true, // pretty much what the name says
resizable: false, // Don't allow the user to resize the dialog
locationRelativeTo: null, // Place dialog in center of the screen
pack: true, // We need to pack the dialog (so it will take the size of it's children)
show: true // Let's show it
) {
vbox { // Put everything below each other
label(text: "Please enter key passphrase:")
input = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
pass = input.password; // Set pass variable to value of input field
dispose(); // Close dialog
})
} // vbox end
} // dialog end
} // edt end
} else {
pass = System.console().readPassword("\nPlease enter key passphrase: ")
}

if(password.size() <= 0) {
throw new InvalidUserDataException("You must enter a password to proceed.")
}
if (pass.size() <= 0) {
throw new InvalidUserDataException("You must enter a password to proceed.")
}

// Must create String because System.readPassword() returns char[]
// (and assigning that below fails silently)
password = new String(password)

android.signingConfigs.release.storePassword = password
android.signingConfigs.release.keyPassword = password
pass = new String(pass)
android.signingConfigs.release.storePassword = pass
android.signingConfigs.release.keyPassword = pass
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.NumberPicker;
Expand All @@ -29,6 +38,8 @@

public class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener {

private static final String TAG = "SettingsFragment";

private static final int REQUEST_CODE_ENABLE_ADMIN = 1;

private SharedPreferences mPrefs;
Expand All @@ -41,6 +52,8 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
private ComponentName mDeviceAdmin;
private CheckBoxPreference mDeviceAdminPreference;

private Context mContext;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -53,6 +66,7 @@ public void onCreate(Bundle savedInstanceState) {
}

findPreference("contact").setOnPreferenceClickListener(this);
findPreference("test_notification").setOnPreferenceClickListener(this);
findPreference("version").setSummary(BuildConfig.VERSION_NAME);

initializeService();
Expand All @@ -66,9 +80,34 @@ public void onCreate(Bundle savedInstanceState) {
.checkAndShow();
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
mContext = context;
}
boolean mServiceBound = false;
private ServiceConnection mServiceConnection = new ServiceConnection() {

@Override
public void onServiceDisconnected(ComponentName name) {
mServiceBound = false;
}

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mServiceBound = true;
}
};
public void onResume() {
super.onResume();

//TODO:Refactor me, just a fix for non-starting service
if (!mServiceBound) {
Intent intent = new Intent(getActivity(), com.lukekorth.screennotifications.services.NotificationListener.class);
getActivity().startService(intent);
getActivity().bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
}

checkForRunningService();
checkForActiveDeviceAdmin();
}
Expand Down Expand Up @@ -268,6 +307,7 @@ public void onClick(DialogInterface alertDialog, int id) {
private boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getActivity().getSystemService(Activity.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
// Log.d(TAG, "isServiceRunning: "+ service.service.getClassName());
if (mSupportsNotificationListenerService &&
NotificationListener.class.getName().equals(service.service.getClassName())) {
return true;
Expand All @@ -284,6 +324,26 @@ public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals("contact")) {
new LogReporting(getActivity()).collectAndSendLogs();
return true;
}else if(preference.getKey().equals("test_notification")) {
Log.d(TAG, "onPreferenceClick: create Notification");
final NotificationManager mNotifyMgr = (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
.setContentTitle("Test Notification")
.setContentText("This is just a test")
.setTicker( "Test Notification" )
.setSound(alarmSound)
.setSmallIcon(R.drawable.ic_launcher);
final Notification notification = builder.build();
notification.defaults = Notification.DEFAULT_ALL;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
Log.d(TAG, "run: Now showing the notification");
mNotifyMgr.notify(1447, notification);
}
}, 5000);
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class ScreenController {
private Logger mLogger;
private SharedPreferences mPrefs;
private PowerManager mPowerManager;
private boolean mCloseToProximitySensor;
private boolean mSensorsAllowWakeUp;

public ScreenController(Context context, boolean closeToProximitySensor) {
public ScreenController(Context context, boolean SensorsAllowWakeUp) {
mContext = context;
mLogger = LoggerFactory.getLogger("ScreenController");
mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mCloseToProximitySensor = closeToProximitySensor;
mSensorsAllowWakeUp = SensorsAllowWakeUp;
}

public void handleNotification() {
Expand All @@ -54,10 +54,10 @@ public void run() {
private void turnOnScreen() {
mLogger.debug("Turning on screen");

if(mPrefs.getBoolean("status-bar", false)) {
mLogger.debug("Sleeping for 3 seconds before turning on screen");
SystemClock.sleep(3000);
}
// if(mPrefs.getBoolean("status-bar", false)) {
// mLogger.debug("Sleeping for 3 seconds before turning on screen");
// SystemClock.sleep(3000);
// }

int flag;
if(mPrefs.getBoolean("bright", false)) {
Expand Down Expand Up @@ -124,7 +124,7 @@ private boolean shouldTurnOnScreen() {
boolean turnOnScreen = !isInQuietTime() && !isInCall() && !mPowerManager.isScreenOn();

if(!mPrefs.getBoolean("proxSensor", true)) {
turnOnScreen = turnOnScreen && !mCloseToProximitySensor;
turnOnScreen = turnOnScreen && mSensorsAllowWakeUp;
}

mLogger.debug("Should turn on screen: " + turnOnScreen);
Expand Down
Loading