Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

reworked on bootup user setting to work as it should, cleaned up some…

… code, fixed a bug in button updating
  • Loading branch information...
commit e7736eada287bed8ba46e81d7335055f9db58b13 1 parent 7be1c12
Cicerone Cojocaru authored
View
2  src/ca/mcgill/hs/HSAndroid.java
@@ -90,7 +90,7 @@ private void getPrefs(){
}
public static void updateButton(){
- button.setText((HSService.isRunning() ? R.string.stop_label : R.string.start_label));
+ if (button != null) button.setText((HSService.isRunning() ? R.string.stop_label : R.string.start_label));
}
}
View
26 src/ca/mcgill/hs/prefs/HSAndroidPreferences.java
@@ -1,16 +1,10 @@
package ca.mcgill.hs.prefs;
-import java.io.File;
-import java.io.IOException;
-
import ca.mcgill.hs.R;
-import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
-import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceClickListener;
-import android.util.Log;
public class HSAndroidPreferences extends PreferenceActivity {
@Override
@@ -31,26 +25,6 @@ public boolean onPreferenceClick(Preference preference) {
autoStartAtPhoneBoot.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
- File f = new File("/sdcard/autoStartAtPhoneBoot.prfs");
- SharedPreferences prefs =
- PreferenceManager.getDefaultSharedPreferences(getBaseContext());
- if(prefs.getBoolean("autoStartAtPhoneBoot", false)){
- if (!f.exists()){
- Log.i(getClass().getSimpleName(), "Boot enabled");
- try {
- f.createNewFile();
- Log.i(getClass().getSimpleName(), "File created");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- } else {
- Log.i(getClass().getSimpleName(), "Boot disabled");
- if (f.exists()){
- f.delete();
- Log.i(getClass().getSimpleName(), "File deleted");
- }
- }
return true;
}
View
22 src/ca/mcgill/hs/serv/HSServAutoStart.java
@@ -1,11 +1,11 @@
package ca.mcgill.hs.serv;
-import java.io.File;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.util.Log;
public class HSServAutoStart extends BroadcastReceiver{
@@ -17,16 +17,20 @@
@Override
public void onReceive(Context context, Intent intent){
- //check if the received intent is BOOT_COMPLETED
- if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction()) && new File("/sdcard/autoStartAtPhoneBoot.prfs").exists()) {
- comp = new ComponentName(context.getPackageName(), HSService.class.getName());
- svc = context.startService(new Intent().setComponent(comp));
-
- if (svc == null){
- Log.e("HSServAutoStart", "Could not start HSService " + comp.toString());
+ //check the user settings to see if we should start the service at boot
+ SharedPreferences prefs = context.getSharedPreferences("ca.mcgill.hs_preferences",0);
+
+ if (prefs.getBoolean("autoStartAtPhoneBoot",false)) {
+ //check if the received intent is BOOT_COMPLETED
+ if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
+ comp = new ComponentName(context.getPackageName(), HSService.class.getName());
+ svc = context.startService(new Intent().setComponent(comp));
+
+ if (svc == null){
+ Log.e("HSServAutoStart", "Could not start HSService " + comp.toString());
+ }
}
}
-
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.