2010-09-01 16:59:09 -04:00
|
|
|
package com.fsck.k9.preferences;
|
|
|
|
|
|
|
|
import android.app.AlertDialog.Builder;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.preference.DialogPreference;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
2010-10-03 05:26:30 -04:00
|
|
|
public class CheckBoxListPreference extends DialogPreference
|
2010-09-01 16:59:09 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
private CharSequence[] mItems;
|
|
|
|
|
|
|
|
private boolean[] mCheckedItems;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checkboxes state when the dialog is displayed
|
|
|
|
*/
|
|
|
|
private boolean[] mPendingItems;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param context
|
|
|
|
* @param attrs
|
|
|
|
* @param defStyle
|
|
|
|
*/
|
2010-10-03 05:26:30 -04:00
|
|
|
public CheckBoxListPreference(Context context, AttributeSet attrs, int defStyle)
|
2010-09-01 16:59:09 -04:00
|
|
|
{
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param context
|
|
|
|
* @param attrs
|
|
|
|
*/
|
2010-10-03 05:26:30 -04:00
|
|
|
public CheckBoxListPreference(Context context, AttributeSet attrs)
|
2010-09-01 16:59:09 -04:00
|
|
|
{
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPrepareDialogBuilder(final Builder builder)
|
|
|
|
{
|
|
|
|
mPendingItems = new boolean[mItems.length];
|
|
|
|
|
|
|
|
System.arraycopy(mCheckedItems, 0, mPendingItems, 0, mCheckedItems.length);
|
|
|
|
|
|
|
|
builder.setMultiChoiceItems(mItems, mPendingItems,
|
2010-10-05 02:04:28 -04:00
|
|
|
new DialogInterface.OnMultiChoiceClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(final DialogInterface dialog, final int which,
|
|
|
|
final boolean isChecked)
|
|
|
|
{
|
|
|
|
mPendingItems[which] = isChecked;
|
|
|
|
}
|
|
|
|
});
|
2010-09-01 16:59:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDialogClosed(boolean positiveResult)
|
|
|
|
{
|
|
|
|
if (positiveResult)
|
|
|
|
{
|
|
|
|
System.arraycopy(mPendingItems, 0, mCheckedItems, 0, mPendingItems.length);
|
|
|
|
}
|
|
|
|
mPendingItems = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setItems(final CharSequence[] items)
|
|
|
|
{
|
|
|
|
mItems = items;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCheckedItems(final boolean[] items)
|
|
|
|
{
|
|
|
|
mCheckedItems = items;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean[] getCheckedItems()
|
|
|
|
{
|
|
|
|
return mCheckedItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|