Skip to content

Commit

Permalink
Correcting preferences; Misc debugging, optimization, and organization
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchtech committed Jun 13, 2011
1 parent 32be78c commit 2911e92
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 169 deletions.
2 changes: 1 addition & 1 deletion assets/EntityConfiguration.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<EntityConfiguration>
<Database name="EntityMap.db" version="2" upgradeClass=""></Database>
<Database name="EntityMap.db" version="3" upgradeClass=""></Database>
<Entities>
<Entity class="edu.fsu.cs.contextprovider.data.LocationEntity"></Entity>
<Entity class="edu.fsu.cs.contextprovider.data.MovementEntity"></Entity>
Expand Down
25 changes: 8 additions & 17 deletions res/xml/prefs.xml
Expand Up @@ -7,35 +7,26 @@
android:title="Run at Startup" android:summaryOn="Run at Startup Enabled"
android:summaryOff="Run at Startup Disabled" android:defaultValue="true"></CheckBoxPreference>
<CheckBoxPreference android:key="PREFS_ACCURACY_POPUP_ENABLED"
android:title="Context Accuracy Popup" android:summaryOn="Context Accuracy Popup Enabled"
android:summaryOn="Context Accuracy Popup Enabled"
android:summaryOff="Context Accuracy Popup Disabled"
android:defaultValue="true"></CheckBoxPreference>
android:defaultValue="true" android:title="Accuracy Popup"></CheckBoxPreference>
<CheckBoxPreference android:key="PREFS_ACCURACY_POPUP_AUDIO_ENABLED"
android:title="Context Accuracy Audio" android:summaryOn="Context Accuracy Audio Enabled"
android:summaryOff="Context Accuracy Audio Disabled"
android:defaultValue=""
android:dependency="PREFS_ACCURACY_POPUP_ENABLED"></CheckBoxPreference>
<RingtonePreference android:title="Context Popup Ringtone"
android:dependency="PREFS_ACCURACY_POPUP_ENABLED" android:title="Popup Audio" android:summaryOff="Context Popup Audio Disabled" android:summaryOn="Context Popup Audio Enabled"></CheckBoxPreference>
<RingtonePreference android:title="Popup Ringtone"
android:ringtoneType="ringtone" android:key="PREFS_ACCURACY_POPUP_AUDIO"
android:summary="Select ringtone to play at popup"
android:dependency="PREFS_ACCURACY_POPUP_AUDIO_ENABLED"></RingtonePreference>
<CheckBoxPreference android:key="PREFS_ACCURACY_POPUP_VIBRATE_ENABLED"
android:title="Context Accuracy Popup Vibration" android:summaryOn="Context Accuracy Vibrate Enabled"
android:summaryOff="Context Accuracy Popup Vibrate Disabled"
android:dependency="PREFS_ACCURACY_POPUP_ENABLED"
android:defaultValue="true"></CheckBoxPreference>
android:defaultValue="true" android:title="Popup Vibration" android:summaryOff="Context Popup Vibration Disabled" android:summaryOn="Context Popup Vibration Enabled"></CheckBoxPreference>
<ListPreference android:entryValues="@array/prefs_popup_freq_values"
android:entries="@array/prefs_popup_freq" android:defaultValue="30"
android:negativeButtonText="@string/cancel"
android:positiveButtonText="@string/ok" android:dialogTitle="Context Popup Frequency"
android:title="Context Popup Frequency" android:key="PREFS_POPUP_FREQ"
android:dependency="PREFS_ACCURACY_POPUP_ENABLED"></ListPreference>
android:entries="@array/prefs_popup_freq" android:negativeButtonText="@string/cancel"
android:positiveButtonText="@string/ok" android:title="Popup Frequency" android:dependency="PREFS_ACCURACY_POPUP_ENABLED" android:dialogTitle="Popup Frequency" android:defaultValue="30" android:key="PREFS_ACCURACY_POPUP_FREQ"></ListPreference>
<ListPreference android:entryValues="@array/prefs_popup_dismiss_freq_values"
android:entries="@array/prefs_popup_dismiss_freq"
android:defaultValue="5" android:negativeButtonText="@string/cancel"
android:positiveButtonText="@string/ok" android:dialogTitle="Context Popup Auto-Dismiss"
android:title="Context Popup Auto-Dismiss" android:key="PREFS_POPUP_DISMISS_FREQ"
android:dependency="PREFS_ACCURACY_POPUP_ENABLED"></ListPreference>
android:positiveButtonText="@string/ok" android:dependency="PREFS_ACCURACY_POPUP_ENABLED" android:dialogTitle="Popup Auto-Dismiss" android:title="Popup Auto-Dismiss" android:key="PREFS_ACCURACY_POPUP_DISMISS_FREQ"></ListPreference>
</PreferenceCategory>
<PreferenceCategory android:key="PREFS_LOCATION"
android:title="Location Paramaters">
Expand Down
35 changes: 20 additions & 15 deletions src/edu/fsu/cs/contextprovider/ContextAccuracyActivity.java
Expand Up @@ -22,6 +22,7 @@
import android.os.Bundle;
import android.os.PowerManager;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
Expand All @@ -31,7 +32,8 @@
import android.widget.Toast;

public class ContextAccuracyActivity extends Activity implements View.OnClickListener {
private static final String TAG = "WakeupServiceSliderActivity";
private static final String TAG = "ContextAccuracyActivity";
private static final boolean DEBUG = true;

private Ringtone tone;
private AudioManager volume;
Expand All @@ -41,8 +43,8 @@ public class ContextAccuracyActivity extends Activity implements View.OnClickLis
SharedPreferences prefs;
private boolean accuracyAudioEnabled;
private boolean accuracyVibrateEnabled;
private int accuracyPopupPeriod;
private int accuracyDismissDelay;
private String accuracyDismissDelay;
private int dismissDelay;

SeekBar placeBar = null;
SeekBar movementBar = null;
Expand All @@ -68,13 +70,12 @@ public class ContextAccuracyActivity extends Activity implements View.OnClickLis
private PowerManager.WakeLock wakelock;

private static Timer timer = new Timer();
private Activity ctx;
// private Activity ctx;
private int backCount = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// getWindow().setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "ContextAccuracyActivity");
Expand Down Expand Up @@ -122,7 +123,7 @@ public void onCreate(Bundle savedInstanceState) {
startVibrate();

timer = new Timer();
timer.schedule(new ContextDismissTask(), (accuracyDismissDelay * 1000));
timer.schedule(new ContextDismissTask(), (dismissDelay * 1000));

}

Expand All @@ -149,19 +150,23 @@ public void onBackPressed() {
Toast.makeText(this, "Press Back again to submit", Toast.LENGTH_SHORT).show();
} else {
timer.cancel();
sendAccurate();
sendAccuracy();
finish();
}
}

private void getPrefs() {

prefs = getSharedPreferences(ContextConstants.CONTEXT_PREFS, MODE_WORLD_READABLE);

prefs = getSharedPreferences(ContextConstants.CONTEXT_PREFS, MODE_PRIVATE);
// prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
accuracyAudioEnabled = prefs.getBoolean(ContextConstants.PREFS_ACCURACY_POPUP_AUDIO_ENABLED, false);
accuracyVibrateEnabled = prefs.getBoolean(ContextConstants.PREFS_ACCURACY_POPUP_VIBRATE_ENABLED, true);
accuracyPopupPeriod = prefs.getInt(ContextConstants.PREFS_ACCURACY_POPUP_PERIOD, 30);
accuracyDismissDelay = prefs.getInt(ContextConstants.PREFS_ACCURACY_POPUP_DISMISS_DELAY, 5);
// accuracyDismissDelay = prefs.getInt(ContextConstants.PREFS_ACCURACY_POPUP_DISMISS_FREQ, 5);
accuracyDismissDelay = prefs.getString(ContextConstants.PREFS_ACCURACY_POPUP_DISMISS_FREQ, "5");
dismissDelay = Integer.parseInt(accuracyDismissDelay);

if (DEBUG) {
Log.d(TAG, "accuracyDismissDelay: " + accuracyDismissDelay + " dismissDelay: " + dismissDelay);
}

if (accuracyAudioEnabled)
setRingtone();
Expand Down Expand Up @@ -200,7 +205,7 @@ public void onClick(View v) {
resetBars();
} else if (v == submitBtn) {
timer.cancel();
sendAccurate();
sendAccuracy();
finish();
}
}
Expand All @@ -210,12 +215,12 @@ private class ContextDismissTask extends TimerTask
{
public void run()
{
sendAccurate();
sendAccuracy();
finish();
}
}

private void sendAccurate() {
private void sendAccuracy() {
Intent intent = new Intent(ContextConstants.CONTEXT_STORE_INTENT);

intent.putExtra(ContextConstants.PLACE_ACCURATE, (int) placeBar.getProgress());
Expand Down
84 changes: 34 additions & 50 deletions src/edu/fsu/cs/contextprovider/ContextExpandableListActivity.java
Expand Up @@ -51,6 +51,7 @@
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.location.Geocoder;
Expand Down Expand Up @@ -90,9 +91,10 @@
import edu.fsu.cs.contextprovider.sensor.AccelerometerService;
import edu.fsu.cs.contextprovider.sensor.LightService;

public class ContextExpandableListActivity extends ExpandableListActivity implements OnChildClickListener, TextToSpeech.OnInitListener {
public class ContextExpandableListActivity extends ExpandableListActivity implements OnChildClickListener, TextToSpeech.OnInitListener, OnSharedPreferenceChangeListener {
private static final String TAG = "ContextExpandableListActivity";

private static final boolean DEBUG = true;

private static final String NAME = "NAME";
private static final String VALUE = "VALUE";

Expand All @@ -113,34 +115,20 @@ public class ContextExpandableListActivity extends ExpandableListActivity implem
private static final int DIALOG_ABOUT = 0;
private static final String CSV_FILENAME = "Context.csv";

// location prefs
private boolean locationEnabled;
private int locationPollFreq;
private int locationStoreFreq;
// movement prefs
private boolean movementEnabled;
private int movementPollFreq;
// weather prefs
private boolean weatherEnabled;
private int weatherPollFreq;
private int weatherStoreFreq;
// social prefs
private boolean socialEnabled;
// system prefs
private boolean systemEnabled;
// derived prefs
private boolean derivedEnabled;
private int derivedCalcFreq;
private int derivedStoreFreq;

// general prefs
private boolean startupEnabled;
private boolean accuracyPopupEnabled;
private boolean accuracyAudioEnabled;
private int accuracyPopupPeriod;
private int accuracyDismissDelay;
// debug
private boolean ttsEnabled;
private boolean shakeEnabled;
SharedPreferences prefs;

public static boolean running = false;
Expand Down Expand Up @@ -172,25 +160,25 @@ public void onServiceDisconnected(ComponentName name) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

prefs = getSharedPreferences(ContextConstants.CONTEXT_PREFS, MODE_WORLD_READABLE);

if (!prefs.contains(ContextConstants.PREFS_FIRST_RUN)) {
SharedPreferences.Editor prefsEditor = prefs.edit();
prefsEditor.putBoolean(ContextConstants.PREFS_FIRST_RUN, false);
prefsEditor.commit();

// startup the primary context service (if just installed)
startService(new Intent(this, ContextService.class));

AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getBaseContext(), edu.fsu.cs.contextprovider.wakeup.WakeupAlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(getBaseContext(), 0, intent, 0);
manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 10000, accuracyPopupPeriod * 1000, pi);

}

// prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
PreferenceManager.setDefaultValues(this, ContextConstants.CONTEXT_PREFS, MODE_WORLD_READABLE, R.xml.prefs, false);
prefs = getSharedPreferences(ContextConstants.CONTEXT_PREFS, MODE_PRIVATE);
// if (!prefs.contains(ContextConstants.PREFS_FIRST_RUN)) {
// SharedPreferences.Editor prefsEditor = prefs.edit();
// prefsEditor.putBoolean(ContextConstants.PREFS_FIRST_RUN, false);
// prefsEditor.commit();
//
// // startup the primary context service (if just installed)
// startService(new Intent(this, ContextService.class));
//
// AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// Intent intent = new Intent(getBaseContext(), edu.fsu.cs.contextprovider.wakeup.WakeupAlarmReceiver.class);
// PendingIntent pi = PendingIntent.getBroadcast(getBaseContext(), 0, intent, 0);
// manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 10000, accuracyPopupPeriod * 1000, pi);
// }
getPrefs();

tts = new TextToSpeech(this, this);
Expand Down Expand Up @@ -252,21 +240,14 @@ public void onInit(int status) {
}

private void getPrefs() {

// SharedPreferences prefs =
// PreferenceManager.getDefaultSharedPreferences(this);
prefs = getSharedPreferences(ContextConstants.CONTEXT_PREFS, MODE_WORLD_READABLE);

// general
// startupEnabled = prefs.getBoolean("PREFS_STARTUP_ENABLED", true);
ttsEnabled = prefs.getBoolean("PREFS_TTS_ENABLED", false);

locationEnabled = prefs.getBoolean("PREFS_LOCATION_ENABLED", true);
movementEnabled = prefs.getBoolean("PREFS_MOVEMENT_ENABLED", true);
weatherEnabled = prefs.getBoolean("PREFS_WEATHER_ENABLED", true);
socialEnabled = prefs.getBoolean("PREFS_SOCIAL_ENABLED", true);
systemEnabled = prefs.getBoolean("PREFS_SYSTEM_ENABLED", true);
derivedEnabled = prefs.getBoolean("PREFS_DERIVED_ENABLED", true);

ttsEnabled = prefs.getBoolean("PREFS_TTS_ENABLED", false);
}

private void refresh() {
Expand Down Expand Up @@ -547,6 +528,7 @@ public void onDestroy() {
// MovementMonitor.StopThread();
super.onDestroy();
tts.shutdown();
unbindService(conn);
}

@Override
Expand Down Expand Up @@ -582,7 +564,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
intent = new Intent(getApplicationContext(), edu.fsu.cs.contextprovider.map.AddPlaceMapActivity.class);
intent.putExtra(ContextConstants.PLACE_REQUEST_ID, ContextConstants.SET_WORK_REQUEST);
startActivityForResult(intent, ContextConstants.SET_WORK_REQUEST);

// startActivityForResult(new Intent(getApplicationContext(),
// edu.fsu.cs.contextprovider.map.AddPlaceMapActivity.class),
// ContextConstants.SET_WORK_REQUEST);
Expand Down Expand Up @@ -625,14 +606,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ContextConstants.SET_HOME_REQUEST) {
if (resultCode == RESULT_OK) {
// Toast.makeText(this, "My Location:" + location.getLatitude()
// + "," + location.getLongitude(), Toast.LENGTH_LONG);
Toast.makeText(this, "Home Set Sucessfully", Toast.LENGTH_LONG);
}
} else if (requestCode == ContextConstants.SET_WORK_REQUEST) {
if (resultCode == RESULT_OK) {
// Toast.makeText(this, "My Location:" + location.getLatitude()
// + "," + location.getLongitude(), Toast.LENGTH_LONG);
Toast.makeText(this, "Work Set Sucessfully", Toast.LENGTH_LONG);
}
}
Expand Down Expand Up @@ -817,4 +794,11 @@ public void exportToFile() throws IOException {
startActivity(Intent.createChooser(shareIntent, "Share Context Using..."));
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (DEBUG) {
Toast.makeText(this, "ContextExpandableList prefs changed", Toast.LENGTH_SHORT).show();
}
}

}

0 comments on commit 2911e92

Please sign in to comment.