FileDocCategorySizeDatePackage
SyncStateCheckBoxPreference.javaAPI DocAndroid 1.5 API4541Wed May 06 22:42:48 BST 2009com.android.settings

SyncStateCheckBoxPreference

public class SyncStateCheckBoxPreference extends android.preference.CheckBoxPreference

Fields Summary
private boolean
mIsActive
private boolean
mIsPending
private boolean
mFailed
private boolean
mOneTimeSyncMode
A mode for this preference where clicking does a one-time sync instead of toggling whether the provider will do autosync.
Constructors Summary
public SyncStateCheckBoxPreference(android.content.Context context, android.util.AttributeSet attrs)

    
         
        super(context, attrs);
        setWidgetLayoutResource(R.layout.preference_widget_sync_toggle);
    
Methods Summary
public booleanisOneTimeSyncMode()
Gets whether the preference is in one-time sync mode.

        return mOneTimeSyncMode;
    
public voidonBindView(android.view.View view)

        super.onBindView(view);
        ImageView syncActiveView = (ImageView) view.findViewById(R.id.sync_active);
        View syncPendingView = view.findViewById(R.id.sync_pending);
        View syncFailedView = view.findViewById(R.id.sync_failed);

        syncActiveView.setVisibility(mIsActive ? View.VISIBLE : View.GONE);
        AnimationDrawable anim = (AnimationDrawable) syncActiveView.getDrawable();
        boolean showError;
        boolean showPending;
        if (mIsActive) {
            anim.start();
            showPending = false;
            showError = false;
        } else {
            anim.stop();
            if (mIsPending) {
                showPending = true;
                showError = false;
            } else {
                showPending = false;
                showError = mFailed;
            }
        }

        syncFailedView.setVisibility(showError ? View.VISIBLE : View.GONE);
        syncPendingView.setVisibility((showPending && !mIsActive) ? View.VISIBLE : View.GONE);
        
        View checkBox = view.findViewById(android.R.id.checkbox);
        if (mOneTimeSyncMode) {
            checkBox.setVisibility(View.GONE);
            
            /*
             * Override the summary. Fill in the %1$s with the existing summary
             * (what ends up happening is the old summary is shown on the next
             * line).
             */
            TextView summary = (TextView) view.findViewById(android.R.id.summary);
            summary.setText(getContext().getString(R.string.sync_one_time_sync, getSummary()));
        } else {
            checkBox.setVisibility(View.VISIBLE);
        }
    
protected voidonClick()

        // When we're in one-time sync mode, we don't want a click to change the
        // checkbox state
        if (!mOneTimeSyncMode) {
            super.onClick();
        }            
    
public voidsetActive(boolean isActive)
Set whether the sync is active.

param
isActive whether or not the sync is active

        mIsActive = isActive;
        notifyChanged();
    
public voidsetFailed(boolean failed)
Set whether the corresponding sync failed.

param
failed whether or not the sync failed

        mFailed = failed;
        notifyChanged();
    
public voidsetOneTimeSyncMode(boolean oneTimeSyncMode)
Sets whether the preference is in one-time sync mode.

        mOneTimeSyncMode = oneTimeSyncMode;
        notifyChanged();
    
public voidsetPending(boolean isPending)
Set whether a sync is pending.

param
isPending whether or not the sync is pending

        mIsPending = isPending;
        notifyChanged();