Java Code Examples for android.widget.CompoundButton#toggle()

The following examples show how to use android.widget.CompoundButton#toggle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShareFileFragment.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by R.id.shareViaLinkExpirationSwitch to set or clear the expiration date.
 *
 * @param switchView    {@link Switch} toggled by the user, R.id.shareViaLinkExpirationSwitch
 * @param isChecked     New switch state.
 */
@Override
public void onCheckedChanged(CompoundButton switchView, boolean isChecked) {
    if (!isResumed()) {
        // very important, setCheched(...) is called automatically during
        // Fragment recreation on device rotations
        return;
    }
    if (isChecked) {
        ExpirationDatePickerDialogFragment dialog =
                ExpirationDatePickerDialogFragment.newInstance(mFile, -1);
        dialog.show(
                getActivity().getSupportFragmentManager(),
                ExpirationDatePickerDialogFragment.DATE_PICKER_DIALOG
        );

    } else {
        ((FileActivity) getActivity()).getFileOperationsHelper().
                setExpirationDateToShareViaLink(mFile, -1);
    }

    // undo the toggle to grant the view will be correct if the dialog is cancelled
    switchView.setOnCheckedChangeListener(null);
    switchView.toggle();
    switchView.setOnCheckedChangeListener(mOnExpirationDateInteractionListener);
}
 
Example 2
Source File: ShareFileFragment.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by R.id.shareViaLinkPasswordSwitch to set or clear the password.
 *
 * @param switchView    {@link Switch} toggled by the user, R.id.shareViaLinkPasswordSwitch
 * @param isChecked     New switch state.
 */
@Override
public void onCheckedChanged(CompoundButton switchView, boolean isChecked) {
    if (!isResumed()) {
        // very important, setCheched(...) is called automatically during
        // Fragment recreation on device rotations
        return;
    }
    if (isChecked) {
        ((FileActivity) getActivity()).getFileOperationsHelper().
                requestPasswordForShareViaLink(mFile, false);
    } else {
        ((FileActivity) getActivity()).getFileOperationsHelper().
                setPasswordToShareViaLink(mFile, "");   // "" clears
    }

    // undo the toggle to grant the view will be correct if the dialog is cancelled
    switchView.setOnCheckedChangeListener(null);
    switchView.toggle();
    switchView.setOnCheckedChangeListener(mOnPasswordInteractionListener);
}
 
Example 3
Source File: ShareFileFragment.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called by R.id.shareViaLinkSectionSwitch to create or delete a public link.
 *
 * @param switchView    {@link Switch} toggled by the user, R.id.shareViaLinkSectionSwitch
 * @param isChecked     New switch state.
 */
@Override
public void onCheckedChanged(CompoundButton switchView, boolean isChecked) {
    if (!isResumed()) {
        // very important, setCheched(...) is called automatically during
        // Fragment recreation on device rotations
        return;
    }
    if (isChecked) {
        if (mCapabilities != null &&
                mCapabilities.getFilesSharingPublicPasswordEnforced().isTrue()) {
            // password enforced by server, request to the user before trying to create
            ((FileActivity) getActivity()).getFileOperationsHelper().
                    requestPasswordForShareViaLink(mFile, true);

        } else {
            // create without password if not enforced by server or we don't know if enforced;
            ((FileActivity) getActivity()).getFileOperationsHelper().
                    shareFileViaLink(mFile, null);

            // FileActivtiy#onCreateShareViaLinkOperationFinish still handles the guess of enforcement
            // for server in versions previous to OwnCloudVersion#MINIMUM_VERSION_CAPABILITIES_API
        }

    } else {
        ((FileActivity) getActivity()).getFileOperationsHelper().
                unshareFileViaLink(mFile);
    }

    // undo the toggle to grant the view will be correct if any intermediate dialog is cancelled or
    // the create/delete operation fails
    switchView.setOnCheckedChangeListener(null);
    switchView.toggle();
    switchView.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener);
}
 
Example 4
Source File: EditShareFragment.java    From Cirrus_depricated with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Toggle value of received {@link CompoundButton} granting that its change listener is not called.
 *
 * @param compound      {@link CompoundButton} (switch or checkBox) to toggle without reporting to
 *                      the change listener
 */
private void toggleDisablingListener(CompoundButton compound) {
    compound.setOnCheckedChangeListener(null);
    compound.toggle();
    compound.setOnCheckedChangeListener(this);
}