diff --git a/SWADroid/res/layout/preference_seek_bar_dialog.xml b/SWADroid/res/layout/preference_seek_bar_dialog.xml
new file mode 100644
index 00000000..6ae8ae1b
--- /dev/null
+++ b/SWADroid/res/layout/preference_seek_bar_dialog.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SWADroid/res/values-es/strings.xml b/SWADroid/res/values-es/strings.xml
index 4f6b2271..c3f6344e 100644
--- a/SWADroid/res/values-es/strings.xml
+++ b/SWADroid/res/values-es/strings.xml
@@ -140,7 +140,11 @@
Frecuencia de sincronización
Frecuencia de sincronización de las notificaciones
Sincronización automática
- Habilitar la sincronización automática
+ Habilitar la sincronización automática
+ Notificaciones
+ Límite de notificaciones
+ Seleccione el número máximo de notificaciones que serán almacenadas:
+ notificaciones
SWADroid
nuevas notificaciones
Enviado desde
diff --git a/SWADroid/res/values/attrs.xml b/SWADroid/res/values/attrs.xml
new file mode 100644
index 00000000..d3dc0fc3
--- /dev/null
+++ b/SWADroid/res/values/attrs.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SWADroid/res/values/strings.xml b/SWADroid/res/values/strings.xml
index 00281f50..9ae38942 100644
--- a/SWADroid/res/values/strings.xml
+++ b/SWADroid/res/values/strings.xml
@@ -147,6 +147,11 @@
Auto Sync
Enable auto sync
prefSyncEnable
+ Notifications
+ Notifications limit
+ Select the max number of notifications to be stored:
+ notifications
+ prefNotifLimit
SWADroid
new notifications
Sended from
diff --git a/SWADroid/res/xml/preferences.xml b/SWADroid/res/xml/preferences.xml
index da2dcced..a8ddd422 100644
--- a/SWADroid/res/xml/preferences.xml
+++ b/SWADroid/res/xml/preferences.xml
@@ -1,7 +1,11 @@
-
-
+
+
+
-
+
+
+
+
+
-
+
* @author Antonio Aguilera Malagon
* @author Helena Rodriguez Gijon
diff --git a/SWADroid/src/es/ugr/swad/swadroid/Preferences.java b/SWADroid/src/es/ugr/swad/swadroid/Preferences.java
index aa16b0a2..67069173 100644
--- a/SWADroid/src/es/ugr/swad/swadroid/Preferences.java
+++ b/SWADroid/src/es/ugr/swad/swadroid/Preferences.java
@@ -44,6 +44,7 @@ import es.ugr.swad.swadroid.model.DataBaseHelper;
import es.ugr.swad.swadroid.sync.SyncUtils;
import es.ugr.swad.swadroid.utils.Base64;
import es.ugr.swad.swadroid.utils.Utils;
+import es.ugr.swad.swadroid.widget.SeekBarDialogPreference;
/**
* Preferences window of application.
@@ -98,6 +99,10 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
* Synchronization enabled flag
*/
private boolean syncEnabled;
+ /**
+ * Notifications limit
+ */
+ private int notifLimit;
/**
* Last application version preference name.
*/
@@ -154,6 +159,10 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
* Synchronization enable preference name.
*/
private static final String SYNCENABLEPREF = "prefSyncEnable";
+ /**
+ * Notifications limit preference name.
+ */
+ private static final String NOTIFLIMITPREF = "prefNotifLimit";
/**
* User ID preference
*/
@@ -206,6 +215,10 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
* Synchronization enable preference
*/
private CheckBoxPreference syncEnablePref;
+ /**
+ * Notifications limit preference
+ */
+ private SeekBarDialogPreference notifLimitPref;
/**
* Preferences editor
*/
@@ -285,6 +298,14 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
return DBKey;
}
+ /**
+ * Gets the max number of notifications to be stored
+ * @return the max number of notifications to be stored
+ */
+ public int getNotifLimit() {
+ return notifLimit;
+ }
+
/**
* Sets the database passphrase
* @param key The database passphrase
@@ -369,6 +390,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
lastVersion = prefs.getInt(LASTVERSIONPREF, 0);
lastCourseSelected = prefs.getInt(LASTCOURSESELECTEDPREF, 0);
syncEnabled = prefs.getBoolean(SYNCENABLEPREF, true);
+ notifLimit = prefs.getInt(NOTIFLIMITPREF, 25);
DBKey = prefs.getString(DBKEYPREF, "");
}
@@ -400,6 +422,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
lastVersion = prefs.getInt(LASTVERSIONPREF, 0);
lastCourseSelected = prefs.getInt(LASTCOURSESELECTEDPREF, 0);
syncEnabled = prefs.getBoolean(SYNCENABLEPREF, true);
+ notifLimit = prefs.getInt(NOTIFLIMITPREF, 25);
editor = prefs.edit();
userIDPref = findPreference(USERIDPREF);
@@ -415,6 +438,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
serverPref = findPreference(SERVERPREF);
syncTimePref = findPreference(SYNCTIMEPREF);
syncEnablePref = (CheckBoxPreference) findPreference(SYNCENABLEPREF);
+ notifLimitPref = (SeekBarDialogPreference) findPreference(NOTIFLIMITPREF);
syncTimePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object value) {
@@ -459,6 +483,9 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
blogPref.setOnPreferenceChangeListener(this);
sharePref.setOnPreferenceChangeListener(this);
serverPref.setOnPreferenceChangeListener(this);
+ notifLimitPref.setOnPreferenceChangeListener(this);
+
+ notifLimitPref.setProgress(notifLimit);
userIDPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
/**
@@ -580,6 +607,16 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
return true;
}
});
+ notifLimitPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference,
+ Object newValue) {
+ notifLimit = (Integer) newValue;
+ editor.putInt(NOTIFLIMITPREF, notifLimit);
+ dbHelper.clearOldNotifications(notifLimit);
+ return true;
+ }
+ });
try {
currentVersionPref.setSummary(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/Notifications.java b/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/Notifications.java
index f502f072..d523bb26 100644
--- a/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/Notifications.java
+++ b/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/Notifications.java
@@ -65,7 +65,7 @@ public class Notifications extends Module {
/**
* Max size to store notifications
*/
- private static final int SIZE_LIMIT = 25;
+ private int SIZE_LIMIT;
/**
* Notifications adapter for showing the data
*/
@@ -209,6 +209,7 @@ public class Notifications extends Module {
setMETHOD_NAME("getNotifications");
receiver = new SyncReceiver(this);
account = new Account(getString(R.string.app_name), accountType);
+ SIZE_LIMIT = prefs.getNotifLimit();
}
/**
@@ -256,6 +257,7 @@ public class Notifications extends Module {
protected void requestService() throws NoSuchAlgorithmException,
IOException, XmlPullParserException, SoapFault,
IllegalAccessException, InstantiationException {
+ SIZE_LIMIT = prefs.getNotifLimit();
account = new Account(getString(R.string.app_name), accountType);
if(ContentResolver.getSyncAutomatically(account, authority)) {
diff --git a/SWADroid/src/es/ugr/swad/swadroid/widget/ExpandedListView.java b/SWADroid/src/es/ugr/swad/swadroid/widget/ExpandedListView.java
index 0eba6d9c..f5760267 100644
--- a/SWADroid/src/es/ugr/swad/swadroid/widget/ExpandedListView.java
+++ b/SWADroid/src/es/ugr/swad/swadroid/widget/ExpandedListView.java
@@ -1,3 +1,21 @@
+/*
+ * This file is part of SWADroid.
+ *
+ * Copyright (C) 2010 Juan Miguel Boyero Corral
+ *
+ * SWADroid 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.
+ *
+ * SWADroid 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 SWADroid. If not, see .
+ */
package es.ugr.swad.swadroid.widget;
import android.content.Context;
diff --git a/SWADroid/src/es/ugr/swad/swadroid/widget/SeekBarDialogPreference.java b/SWADroid/src/es/ugr/swad/swadroid/widget/SeekBarDialogPreference.java
new file mode 100644
index 00000000..c053887a
--- /dev/null
+++ b/SWADroid/src/es/ugr/swad/swadroid/widget/SeekBarDialogPreference.java
@@ -0,0 +1,275 @@
+/*
+ * This file is part of SWADroid.
+ *
+ * Copyright (C) 2010 Juan Miguel Boyero Corral
+ *
+ * SWADroid 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.
+ *
+ * SWADroid 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 SWADroid. If not, see .
+ */
+package es.ugr.swad.swadroid.widget;
+
+import es.ugr.swad.swadroid.R;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+import android.widget.TextView;
+
+/**
+ * A {@link DialogPreference} that provides a user with the means to select an integer from a {@link SeekBar}, and persist it.
+ *
+ * @author lukehorvat
+ *
+ */
+public class SeekBarDialogPreference extends DialogPreference
+{
+ private static final int DEFAULT_MIN_PROGRESS = 0;
+ private static final int DEFAULT_MAX_PROGRESS = 100;
+ private static final int DEFAULT_PROGRESS = 0;
+
+ private int mMinProgress;
+ private int mMaxProgress;
+ private int mProgress;
+ private CharSequence mProgressTextSuffix;
+ private TextView mProgressText;
+ private SeekBar mSeekBar;
+
+ public SeekBarDialogPreference(Context context)
+ {
+ this(context, null);
+ }
+
+ public SeekBarDialogPreference(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+
+ // get attributes specified in XML
+ TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SeekBarDialogPreference, 0, 0);
+ try
+ {
+ setMinProgress(a.getInteger(R.styleable.SeekBarDialogPreference_min, DEFAULT_MIN_PROGRESS));
+ setMaxProgress(a.getInteger(R.styleable.SeekBarDialogPreference_android_max, DEFAULT_MAX_PROGRESS));
+ setProgressTextSuffix(a.getString(R.styleable.SeekBarDialogPreference_progressTextSuffix));
+ }
+ finally
+ {
+ a.recycle();
+ }
+
+ // set layout
+ setDialogLayoutResource(R.layout.preference_seek_bar_dialog);
+ setPositiveButtonText(android.R.string.ok);
+ setNegativeButtonText(android.R.string.cancel);
+ setDialogIcon(null);
+ }
+
+ @Override
+ protected void onSetInitialValue(boolean restore, Object defaultValue)
+ {
+ setProgress(restore ? getPersistedInt(DEFAULT_PROGRESS) : (Integer) defaultValue);
+ }
+
+ @Override
+ protected Object onGetDefaultValue(TypedArray a, int index)
+ {
+ return a.getInt(index, DEFAULT_PROGRESS);
+ }
+
+ @Override
+ protected void onBindDialogView(View view)
+ {
+ super.onBindDialogView(view);
+
+ TextView dialogMessageText = (TextView) view.findViewById(R.id.text_dialog_message);
+ dialogMessageText.setText(getDialogMessage());
+
+ mProgressText = (TextView) view.findViewById(R.id.text_progress);
+
+ mSeekBar = (SeekBar) view.findViewById(R.id.seek_bar);
+ mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
+ {
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar)
+ {
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar)
+ {
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
+ {
+ // update text that displays the current SeekBar progress value
+ // note: this does not persist the progress value. that is only ever done in setProgress()
+ String progressStr = String.valueOf(progress + mMinProgress) + " ";
+ mProgressText.setText(mProgressTextSuffix == null ? progressStr : progressStr.concat(mProgressTextSuffix.toString()));
+ }
+ });
+ mSeekBar.setMax(mMaxProgress - mMinProgress);
+ mSeekBar.setProgress(mProgress - mMinProgress);
+ }
+
+ public int getMinProgress()
+ {
+ return mMinProgress;
+ }
+
+ public void setMinProgress(int minProgress)
+ {
+ mMinProgress = minProgress;
+ setProgress(Math.max(mProgress, mMinProgress));
+ }
+
+ public int getMaxProgress()
+ {
+ return mMaxProgress;
+ }
+
+ public void setMaxProgress(int maxProgress)
+ {
+ mMaxProgress = maxProgress;
+ setProgress(Math.min(mProgress, mMaxProgress));
+ }
+
+ public int getProgress()
+ {
+ return mProgress;
+ }
+
+ public void setProgress(int progress)
+ {
+ progress = Math.max(Math.min(progress, mMaxProgress), mMinProgress);
+
+ if (progress != mProgress)
+ {
+ mProgress = progress;
+ persistInt(progress);
+ notifyChanged();
+ }
+ }
+
+ public CharSequence getProgressTextSuffix()
+ {
+ return mProgressTextSuffix;
+ }
+
+ public void setProgressTextSuffix(CharSequence progressTextSuffix)
+ {
+ mProgressTextSuffix = progressTextSuffix;
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult)
+ {
+ super.onDialogClosed(positiveResult);
+
+ // when the user selects "OK", persist the new value
+ if (positiveResult)
+ {
+ int seekBarProgress = mSeekBar.getProgress() + mMinProgress;
+ if (callChangeListener(seekBarProgress))
+ {
+ setProgress(seekBarProgress);
+ }
+ }
+ }
+
+ @Override
+ protected Parcelable onSaveInstanceState()
+ {
+ // save the instance state so that it will survive screen orientation changes and other events that may temporarily destroy it
+ final Parcelable superState = super.onSaveInstanceState();
+
+ // set the state's value with the class member that holds current setting value
+ final SavedState myState = new SavedState(superState);
+ myState.minProgress = getMinProgress();
+ myState.maxProgress = getMaxProgress();
+ myState.progress = getProgress();
+
+ return myState;
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Parcelable state)
+ {
+ // check whether we saved the state in onSaveInstanceState()
+ if (state == null || !state.getClass().equals(SavedState.class))
+ {
+ // didn't save the state, so call superclass
+ super.onRestoreInstanceState(state);
+ return;
+ }
+
+ // restore the state
+ SavedState myState = (SavedState) state;
+ setMinProgress(myState.minProgress);
+ setMaxProgress(myState.maxProgress);
+ setProgress(myState.progress);
+
+ super.onRestoreInstanceState(myState.getSuperState());
+ }
+
+ private static class SavedState extends BaseSavedState
+ {
+ int minProgress;
+ int maxProgress;
+ int progress;
+
+ public SavedState(Parcelable superState)
+ {
+ super(superState);
+ }
+
+ public SavedState(Parcel source)
+ {
+ super(source);
+
+ minProgress = source.readInt();
+ maxProgress = source.readInt();
+ progress = source.readInt();
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags)
+ {
+ super.writeToParcel(dest, flags);
+
+ dest.writeInt(minProgress);
+ dest.writeInt(maxProgress);
+ dest.writeInt(progress);
+ }
+
+ @SuppressWarnings("unused")
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator()
+ {
+ @Override
+ public SavedState createFromParcel(Parcel in)
+ {
+ return new SavedState(in);
+ }
+
+ @Override
+ public SavedState[] newArray(int size)
+ {
+ return new SavedState[size];
+ }
+ };
+ }
+}