Added configuration of max limit of stored notifications on preferences
screen
This commit is contained in:
parent
4c7eab6716
commit
90e0b88799
34
SWADroid/res/layout/preference_seek_bar_dialog.xml
Normal file
34
SWADroid/res/layout/preference_seek_bar_dialog.xml
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_dialog_message"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="6dip"
|
||||||
|
android:paddingLeft="12dip"
|
||||||
|
android:paddingRight="12dip" >
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_progress"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="6dip"
|
||||||
|
android:gravity="center_horizontal" >
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/seek_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="6dip"
|
||||||
|
android:layout_marginTop="6dip"
|
||||||
|
android:layout_marginLeft="6dip"
|
||||||
|
android:layout_marginRight="6dip" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -140,7 +140,11 @@
|
||||||
<string name="prefSyncTimeTitle">Frecuencia de sincronización</string>
|
<string name="prefSyncTimeTitle">Frecuencia de sincronización</string>
|
||||||
<string name="prefSyncTimeSummary">Frecuencia de sincronización de las notificaciones</string>
|
<string name="prefSyncTimeSummary">Frecuencia de sincronización de las notificaciones</string>
|
||||||
<string name="prefSyncEnableTitle">Sincronización automática</string>
|
<string name="prefSyncEnableTitle">Sincronización automática</string>
|
||||||
<string name="prefSyncEnableSummary">Habilitar la sincronización automática</string>
|
<string name="prefSyncEnableSummary">Habilitar la sincronización automática</string>
|
||||||
|
<string name="prefCatNotifTitle">Notificaciones</string>
|
||||||
|
<string name="prefNotifLimitTitle">Límite de notificaciones</string>
|
||||||
|
<string name="prefNotifLimitDialogMessage">Seleccione el número máximo de notificaciones que serán almacenadas:</string>
|
||||||
|
<string name="prefNotifLimitSuffix">notificaciones</string>
|
||||||
<string name="notificationsAlertTitle">SWADroid</string>
|
<string name="notificationsAlertTitle">SWADroid</string>
|
||||||
<string name="notificationsAlertMsg">nuevas notificaciones</string>
|
<string name="notificationsAlertMsg">nuevas notificaciones</string>
|
||||||
<string name="footMessageMsg">Enviado desde</string>
|
<string name="footMessageMsg">Enviado desde</string>
|
||||||
|
|
11
SWADroid/res/values/attrs.xml
Normal file
11
SWADroid/res/values/attrs.xml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<!-- note: to re-use an existing Android attribute not already used by the superclass, name should have prefix "android:" and do not define a format -->
|
||||||
|
<declare-styleable name="SeekBarDialogPreference">
|
||||||
|
<attr name="android:max" />
|
||||||
|
<attr name="min" format="integer" />
|
||||||
|
<attr name="progressTextSuffix" format="string" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
|
</resources>
|
|
@ -147,6 +147,11 @@
|
||||||
<string name="prefSyncEnableTitle">Auto Sync</string>
|
<string name="prefSyncEnableTitle">Auto Sync</string>
|
||||||
<string name="prefSyncEnableSummary">Enable auto sync</string>
|
<string name="prefSyncEnableSummary">Enable auto sync</string>
|
||||||
<string name="prefSyncEnableKey">prefSyncEnable</string>
|
<string name="prefSyncEnableKey">prefSyncEnable</string>
|
||||||
|
<string name="prefCatNotifTitle">Notifications</string>
|
||||||
|
<string name="prefNotifLimitTitle">Notifications limit</string>
|
||||||
|
<string name="prefNotifLimitDialogMessage">Select the max number of notifications to be stored:</string>
|
||||||
|
<string name="prefNotifLimitSuffix">notifications</string>
|
||||||
|
<string name="prefNotifLimitKey">prefNotifLimit</string>
|
||||||
<string name="notificationsAlertTitle">SWADroid</string>
|
<string name="notificationsAlertTitle">SWADroid</string>
|
||||||
<string name="notificationsAlertMsg">new notifications</string>
|
<string name="notificationsAlertMsg">new notifications</string>
|
||||||
<string name="footMessageMsg">Sended from</string>
|
<string name="footMessageMsg">Sended from</string>
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/user_preferences" >
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:custom="http://schemas.android.com/apk/res-auto" >
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/user_preferences" >
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:name="@string/userIDName_preferences"
|
android:name="@string/userIDName_preferences"
|
||||||
android:defaultValue=""
|
android:defaultValue=""
|
||||||
|
@ -21,7 +25,19 @@
|
||||||
android:hint="@string/serverSummary_preferences"
|
android:hint="@string/serverSummary_preferences"
|
||||||
android:key="serverPref"
|
android:key="serverPref"
|
||||||
android:title="@string/serverTitle_preferences" />
|
android:title="@string/serverTitle_preferences" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/prefCatNotifTitle">
|
||||||
|
|
||||||
|
<es.ugr.swad.swadroid.widget.SeekBarDialogPreference
|
||||||
|
android:key="@string/prefNotifLimitKey"
|
||||||
|
android:dialogMessage="@string/prefNotifLimitDialogMessage"
|
||||||
|
android:title="@string/prefNotifLimitTitle"
|
||||||
|
android:defaultValue="25"
|
||||||
|
android:max="100"
|
||||||
|
custom:progressTextSuffix="@string/prefNotifLimitSuffix"
|
||||||
|
custom:min="1" />
|
||||||
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/prefCatSyncTitle">
|
android:title="@string/prefCatSyncTitle">
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
|
@ -38,7 +54,8 @@
|
||||||
android:defaultValue="60"
|
android:defaultValue="60"
|
||||||
android:dependency="@string/prefSyncEnableKey" />
|
android:dependency="@string/prefSyncEnableKey" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory android:title="@string/about_preferences" >
|
<PreferenceCategory
|
||||||
|
android:title="@string/about_preferences" >
|
||||||
<Preference
|
<Preference
|
||||||
android:defaultValue=""
|
android:defaultValue=""
|
||||||
android:key="ratePref"
|
android:key="ratePref"
|
||||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Random;
|
||||||
import es.ugr.swad.swadroid.model.User;
|
import es.ugr.swad.swadroid.model.User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constans of application.
|
* Constants of application.
|
||||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||||
* @author Antonio Aguilera Malagon <aguilerin@gmail.com>
|
* @author Antonio Aguilera Malagon <aguilerin@gmail.com>
|
||||||
* @author Helena Rodriguez Gijon <hrgijon@gmail.com>
|
* @author Helena Rodriguez Gijon <hrgijon@gmail.com>
|
||||||
|
|
|
@ -44,6 +44,7 @@ import es.ugr.swad.swadroid.model.DataBaseHelper;
|
||||||
import es.ugr.swad.swadroid.sync.SyncUtils;
|
import es.ugr.swad.swadroid.sync.SyncUtils;
|
||||||
import es.ugr.swad.swadroid.utils.Base64;
|
import es.ugr.swad.swadroid.utils.Base64;
|
||||||
import es.ugr.swad.swadroid.utils.Utils;
|
import es.ugr.swad.swadroid.utils.Utils;
|
||||||
|
import es.ugr.swad.swadroid.widget.SeekBarDialogPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preferences window of application.
|
* Preferences window of application.
|
||||||
|
@ -98,6 +99,10 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
|
||||||
* Synchronization enabled flag
|
* Synchronization enabled flag
|
||||||
*/
|
*/
|
||||||
private boolean syncEnabled;
|
private boolean syncEnabled;
|
||||||
|
/**
|
||||||
|
* Notifications limit
|
||||||
|
*/
|
||||||
|
private int notifLimit;
|
||||||
/**
|
/**
|
||||||
* Last application version preference name.
|
* Last application version preference name.
|
||||||
*/
|
*/
|
||||||
|
@ -154,6 +159,10 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
|
||||||
* Synchronization enable preference name.
|
* Synchronization enable preference name.
|
||||||
*/
|
*/
|
||||||
private static final String SYNCENABLEPREF = "prefSyncEnable";
|
private static final String SYNCENABLEPREF = "prefSyncEnable";
|
||||||
|
/**
|
||||||
|
* Notifications limit preference name.
|
||||||
|
*/
|
||||||
|
private static final String NOTIFLIMITPREF = "prefNotifLimit";
|
||||||
/**
|
/**
|
||||||
* User ID preference
|
* User ID preference
|
||||||
*/
|
*/
|
||||||
|
@ -206,6 +215,10 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
|
||||||
* Synchronization enable preference
|
* Synchronization enable preference
|
||||||
*/
|
*/
|
||||||
private CheckBoxPreference syncEnablePref;
|
private CheckBoxPreference syncEnablePref;
|
||||||
|
/**
|
||||||
|
* Notifications limit preference
|
||||||
|
*/
|
||||||
|
private SeekBarDialogPreference notifLimitPref;
|
||||||
/**
|
/**
|
||||||
* Preferences editor
|
* Preferences editor
|
||||||
*/
|
*/
|
||||||
|
@ -285,6 +298,14 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
|
||||||
return DBKey;
|
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
|
* Sets the database passphrase
|
||||||
* @param key The database passphrase
|
* @param key The database passphrase
|
||||||
|
@ -369,6 +390,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
|
||||||
lastVersion = prefs.getInt(LASTVERSIONPREF, 0);
|
lastVersion = prefs.getInt(LASTVERSIONPREF, 0);
|
||||||
lastCourseSelected = prefs.getInt(LASTCOURSESELECTEDPREF, 0);
|
lastCourseSelected = prefs.getInt(LASTCOURSESELECTEDPREF, 0);
|
||||||
syncEnabled = prefs.getBoolean(SYNCENABLEPREF, true);
|
syncEnabled = prefs.getBoolean(SYNCENABLEPREF, true);
|
||||||
|
notifLimit = prefs.getInt(NOTIFLIMITPREF, 25);
|
||||||
DBKey = prefs.getString(DBKEYPREF, "");
|
DBKey = prefs.getString(DBKEYPREF, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,6 +422,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
|
||||||
lastVersion = prefs.getInt(LASTVERSIONPREF, 0);
|
lastVersion = prefs.getInt(LASTVERSIONPREF, 0);
|
||||||
lastCourseSelected = prefs.getInt(LASTCOURSESELECTEDPREF, 0);
|
lastCourseSelected = prefs.getInt(LASTCOURSESELECTEDPREF, 0);
|
||||||
syncEnabled = prefs.getBoolean(SYNCENABLEPREF, true);
|
syncEnabled = prefs.getBoolean(SYNCENABLEPREF, true);
|
||||||
|
notifLimit = prefs.getInt(NOTIFLIMITPREF, 25);
|
||||||
editor = prefs.edit();
|
editor = prefs.edit();
|
||||||
|
|
||||||
userIDPref = findPreference(USERIDPREF);
|
userIDPref = findPreference(USERIDPREF);
|
||||||
|
@ -415,6 +438,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
|
||||||
serverPref = findPreference(SERVERPREF);
|
serverPref = findPreference(SERVERPREF);
|
||||||
syncTimePref = findPreference(SYNCTIMEPREF);
|
syncTimePref = findPreference(SYNCTIMEPREF);
|
||||||
syncEnablePref = (CheckBoxPreference) findPreference(SYNCENABLEPREF);
|
syncEnablePref = (CheckBoxPreference) findPreference(SYNCENABLEPREF);
|
||||||
|
notifLimitPref = (SeekBarDialogPreference) findPreference(NOTIFLIMITPREF);
|
||||||
|
|
||||||
syncTimePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
syncTimePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||||
|
@ -459,6 +483,9 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
|
||||||
blogPref.setOnPreferenceChangeListener(this);
|
blogPref.setOnPreferenceChangeListener(this);
|
||||||
sharePref.setOnPreferenceChangeListener(this);
|
sharePref.setOnPreferenceChangeListener(this);
|
||||||
serverPref.setOnPreferenceChangeListener(this);
|
serverPref.setOnPreferenceChangeListener(this);
|
||||||
|
notifLimitPref.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
notifLimitPref.setProgress(notifLimit);
|
||||||
|
|
||||||
userIDPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
userIDPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
/**
|
/**
|
||||||
|
@ -580,6 +607,16 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
|
||||||
return true;
|
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 {
|
try {
|
||||||
currentVersionPref.setSummary(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
|
currentVersionPref.setSummary(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class Notifications extends Module {
|
||||||
/**
|
/**
|
||||||
* Max size to store notifications
|
* Max size to store notifications
|
||||||
*/
|
*/
|
||||||
private static final int SIZE_LIMIT = 25;
|
private int SIZE_LIMIT;
|
||||||
/**
|
/**
|
||||||
* Notifications adapter for showing the data
|
* Notifications adapter for showing the data
|
||||||
*/
|
*/
|
||||||
|
@ -209,6 +209,7 @@ public class Notifications extends Module {
|
||||||
setMETHOD_NAME("getNotifications");
|
setMETHOD_NAME("getNotifications");
|
||||||
receiver = new SyncReceiver(this);
|
receiver = new SyncReceiver(this);
|
||||||
account = new Account(getString(R.string.app_name), accountType);
|
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,
|
protected void requestService() throws NoSuchAlgorithmException,
|
||||||
IOException, XmlPullParserException, SoapFault,
|
IOException, XmlPullParserException, SoapFault,
|
||||||
IllegalAccessException, InstantiationException {
|
IllegalAccessException, InstantiationException {
|
||||||
|
SIZE_LIMIT = prefs.getNotifLimit();
|
||||||
|
|
||||||
account = new Account(getString(R.string.app_name), accountType);
|
account = new Account(getString(R.string.app_name), accountType);
|
||||||
if(ContentResolver.getSyncAutomatically(account, authority)) {
|
if(ContentResolver.getSyncAutomatically(account, authority)) {
|
||||||
|
|
|
@ -1,3 +1,21 @@
|
||||||
|
/*
|
||||||
|
* This file is part of SWADroid.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package es.ugr.swad.swadroid.widget;
|
package es.ugr.swad.swadroid.widget;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
|
@ -0,0 +1,275 @@
|
||||||
|
/*
|
||||||
|
* This file is part of SWADroid.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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<SavedState> CREATOR = new Parcelable.Creator<SavedState>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public SavedState createFromParcel(Parcel in)
|
||||||
|
{
|
||||||
|
return new SavedState(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SavedState[] newArray(int size)
|
||||||
|
{
|
||||||
|
return new SavedState[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user