Java Code Examples for android.widget.CheckBox#setEnabled()

The following examples show how to use android.widget.CheckBox#setEnabled() . 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: FloatViewSwitchFunction.java    From QPM with Apache License 2.0 6 votes vote down vote up
@Override
public void handleCheckBox(CheckBox checkBox, final Item item) {
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            item.item.value = String.valueOf(isChecked);
            QPMSwitchManager.getInstance().writeSwitch(item.item);
            QPMFloatViewManager.getInstance().refreshFloatViewAndComponent(true);
            if (item.callback != null) {
                item.callback.callback();
            }
        }
    });
    checkBox.setChecked(Boolean.parseBoolean(item.item.value));
    checkBox.setEnabled(true);
}
 
Example 2
Source File: FloatViewSwitchFunction.java    From QPM with Apache License 2.0 5 votes vote down vote up
@Override
public void handleCheckBox(CheckBox checkBox, Item item) {
    // 精简模式不允许主动勾选,只能拖动
    checkBox.setOnCheckedChangeListener(null);
    checkBox.setChecked(Boolean.parseBoolean(item.item.value));
    checkBox.setEnabled(false);
}
 
Example 3
Source File: ToggleComponentsArrayAdapter.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ApplicationInfo applicationInfo = getApplicationInfo(position);
    if (applicationInfo == null) {
        Log.e(TAG, "Fail to retrieve application info for the entry: " + position);
        return null;
    }

    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.enable_component_row,
                parent, false);
    }
    ImageView iconImageView = (ImageView) convertView.findViewById(R.id.pkg_icon);
    iconImageView.setImageDrawable(getApplicationIcon(applicationInfo));
    TextView pkgNameTextView = (TextView) convertView.findViewById(R.id.pkg_name);
    pkgNameTextView.setText(getDisplayName(position));
    CheckBox enableComponentCheckbox = (CheckBox) convertView.findViewById(
            R.id.enable_component_checkbox);
    enableComponentCheckbox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Only handles the onClick event if the component can be enabled or disabled.
            if (canModifyComponent(position)) {
                mIsComponentCheckedList.set(position, ((CheckBox) v).isChecked());
            } else {
                ((CheckBox) v).setChecked(mIsComponentCheckedList.get(position));
            }
        }
    });
    enableComponentCheckbox.setChecked(mIsComponentCheckedList.get(position));
    enableComponentCheckbox.setEnabled(canModifyComponent(position));
    return convertView;
}
 
Example 4
Source File: TestCaseAdapter.java    From Outlook-SDK-Android with MIT License 5 votes vote down vote up
/**
 * Returns the view for a specific item on the list
 */
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
	View row = convertView;

	final TestCase testCase = getItem(position);

	if (row == null) {
		LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
		row = inflater.inflate(mLayoutResourceId, parent, false);
	}

	final CheckBox checkBox = (CheckBox) row.findViewById(R.id.checkTestCase);

	String text = String.format("%s - %s", testCase.getName(), testCase.getStatus().toString());

	if (testCase.getStatus() == TestStatus.Failed) {
		checkBox.setTextColor(Color.RED);
	} else if (testCase.getStatus() == TestStatus.Passed) {
		checkBox.setTextColor(Color.GREEN);
	} else if (testCase.getStatus() == TestStatus.Disabled || testCase.getStatus() == TestStatus.NotSupported) {
		checkBox.setTextColor(Color.GRAY);
	} else {
		checkBox.setTextColor(Color.BLACK);
	}

	checkBox.setText(text);
	checkBox.setChecked(testCase.isSelected());
	checkBox.setEnabled(testCase.isEnabled());
	checkBox.setOnClickListener(new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			testCase.setSelected(checkBox.isChecked());
		}
	});

	return row;
}
 
Example 5
Source File: TGTrackTuningDialog.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void updateOptions(boolean enabled) {
	CheckBox stringTransposition = (CheckBox) this.getView().findViewById(R.id.track_tuning_dlg_options_transpose);
	CheckBox stringTranspositionApplyToChords = (CheckBox) this.getView().findViewById(R.id.track_tuning_dlg_options_transpose_apply_to_chords);
	CheckBox stringTranspositionTryKeepString = (CheckBox) this.getView().findViewById(R.id.track_tuning_dlg_options_transpose_try_keep_strings);
	
	boolean stringTranspositionChecked = stringTransposition.isChecked();
	
	stringTransposition.setEnabled(enabled);
	stringTranspositionApplyToChords.setEnabled(enabled && stringTranspositionChecked);
	stringTranspositionTryKeepString.setEnabled(enabled && stringTranspositionChecked);
	if(!stringTranspositionChecked ) {
		stringTranspositionApplyToChords.setChecked(false);
		stringTranspositionTryKeepString.setChecked(false);
	}
}
 
Example 6
Source File: TGMeasureCopyDialog.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SuppressLint("InflateParams")
public void onPostInflateView() {
	this.fillRanges();

	CheckBox copyAllTracks = (CheckBox) this.getView().findViewById(R.id.measure_copy_dlg_options_all_tracks);
	copyAllTracks.setChecked(true);
	copyAllTracks.setEnabled(this.getSong().countTracks() > 1);
}
 
Example 7
Source File: Reminders.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void maskAlternatingCheckbox(boolean state, CheckBox alternatingCheck) {
    if (state) {
        alternatingCheck.setEnabled(true);
    } else {
        alternatingCheck.setEnabled(false);
        alternatingCheck.setChecked(false);
    }
}
 
Example 8
Source File: ExcludePathsActivity.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
@Override
public void setFile(File_POJO file) {
    super.setFile(file);
    CheckBox checkBox = itemView.findViewById(R.id.checkbox);
    checkBox.setTag(file.getPath());
    setOnCheckedChangeListener(null);
    checkBox.setChecked(file.excluded);
    ArrayList<String> excludedPaths = Provider.getExcludedPaths();
    boolean enabled = !Provider.isDirExcludedBecauseParentDirIsExcluded(
            file.getPath(), excludedPaths);
    checkBox.setEnabled(enabled);
}
 
Example 9
Source File: GBooleanView.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param context               the context to use.
 * @param attrs                 attributes.
 * @param parentView            parent
 * @param label                 label
 * @param value                 value
 * @param constraintDescription constraints
 * @param readonly              if <code>false</code>, the item is disabled for editing.
 */
public GBooleanView(Context context, AttributeSet attrs, LinearLayout parentView, String label, String value,
                    String constraintDescription, boolean readonly) {
    super(context, attrs);

    LinearLayout textLayout = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(context);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(Compat.getColor(context, R.color.formcolor));

    textLayout.addView(textView);

    checkbox = new CheckBox(context);
    checkbox.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    checkbox.setPadding(15, 5, 15, 5);

    if (value != null) {
        if (value.trim().toLowerCase().equals("true")) { //$NON-NLS-1$
            checkbox.setChecked(true);
        } else {
            checkbox.setChecked(false);
        }
    }
    checkbox.setEnabled(!readonly);
    textLayout.addView(checkbox);
}
 
Example 10
Source File: AddAccountActivity.java    From Shaarlier with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_account);

    Intent intent = getIntent();
    long accountId = intent.getLongExtra("_id", -1);

    if (accountId != -1) {
        isEditing = true;
        AccountsSource accountsSource = new AccountsSource(getApplicationContext());
        try {
            account = accountsSource.getShaarliAccountById(accountId);
        } catch (Exception e) { // Editing an account that does not exist, creating a new one
            account = null;
        }
        fillFields();
    } else {
        AccountsSource source = new AccountsSource(getApplicationContext());
        source.rOpen();
        List<ShaarliAccount> allAccounts = source.getAllAccounts();
        if (allAccounts.isEmpty()) {  // If it is the first account created
            CheckBox defaultCheck = findViewById(R.id.defaultAccountCheck);
            defaultCheck.setChecked(true);
            defaultCheck.setEnabled(false);
        }
    }
}
 
Example 11
Source File: AudioControlManager.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
private void updateToneDirect(@NonNull final State state, @NonNull LinearLayout group)
{
    toneDirectGroup.setVisibility(isDirectCmdAvailable(state) || isDirectMode(state) ? View.VISIBLE : View.GONE);
    final CheckBox checkBox = group.findViewById(R.id.tone_direct_checkbox);
    checkBox.setChecked(isDirectMode(state));
    checkBox.setEnabled(isDirectCmdAvailable(state));
}
 
Example 12
Source File: CloudProfileConfigurationDialogFragment.java    From SensorTag-CC2650 with Apache License 2.0 4 votes vote down vote up
public void enDisUseSSL(boolean en, boolean checked) {
    CheckBox c = (CheckBox)v.findViewById(R.id.cloud_use_ssl_checkbox);
    c.setEnabled(en);
    c.setChecked(checked);
}
 
Example 13
Source File: CloudProfileConfigurationDialogFragment.java    From SensorTag-CC2650 with Apache License 2.0 4 votes vote down vote up
public void enDisCleanSession(boolean en,boolean checked) {
    CheckBox c = (CheckBox)v.findViewById(R.id.cloud_clean_session_checkbox);
    c.setEnabled(en);
    c.setChecked(checked);
}
 
Example 14
Source File: SelectMultiWidget.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public SelectMultiWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);
    mCheckboxes = new Vector<>();
    mItems = getSelectChoices();

    setOrientation(LinearLayout.VERTICAL);

    Vector<Selection> ve = new Vector<>();
    if (mPrompt.getAnswerValue() != null) {
        ve = (Vector<Selection>)getCurrentAnswer().getValue();
    }

    //Is this safe enough from collisions?
    buttonIdBase = Math.abs(mPrompt.getIndex().hashCode());

    if (mItems != null) {
        for (int i = 0; i < mItems.size(); i++) {
            // no checkbox group so id by answer + offset
            final CheckBox c = new CheckBox(getContext());

            c.setId(buttonIdBase + i);
            String markdownText = prompt.getSelectItemMarkdownText(mItems.get(i));
            if (markdownText != null) {
                c.setText(forceMarkdown(markdownText));
            } else {
                c.setText(prompt.getSelectChoiceText(mItems.get(i)));
            }
            c.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontSize);
            c.setFocusable(!mPrompt.isReadOnly());
            c.setEnabled(!mPrompt.isReadOnly());

            int padding = (int)Math.floor(context.getResources().getDimension(R.dimen.select_padding));

            c.setPadding(c.getPaddingLeft(), 0, padding, 0);
            for (int vi = 0; vi < ve.size(); vi++) {
                // match based on value, not key
                if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) {
                    c.setChecked(true);
                    break;
                }
            }

            //Note: This gets fired during setup as well, so this listener should only
            //be added after everything about the checkbox is set up

            // when clicked, check for readonly before toggling
            c.setOnCheckedChangeListener((buttonView, isChecked) -> {
                if (!mCheckboxInit && mPrompt.isReadOnly()) {
                    if (buttonView.isChecked()) {
                        buttonView.setChecked(false);
                    } else {
                        buttonView.setChecked(true);
                    }
                }
                widgetEntryChanged();
            });

            mCheckboxes.add(c);

            String audioURI =
                    mPrompt.getSpecialFormSelectChoiceText(mItems.get(i),
                            FormEntryCaption.TEXT_FORM_AUDIO);

            String imageURI =
                    mPrompt.getSpecialFormSelectChoiceText(mItems.get(i),
                            FormEntryCaption.TEXT_FORM_IMAGE);

            String videoURI = mPrompt.getSpecialFormSelectChoiceText(mItems.get(i), "video");

            String bigImageURI = mPrompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image");

            MediaLayout mediaLayout = MediaLayout.buildAudioImageVisualLayout(getContext(), c, audioURI, imageURI, videoURI, bigImageURI);
            addView(mediaLayout);

            mediaLayout.setPadding(0, padding, 0, padding);

            mediaLayout.setOnClickListener(v -> c.performClick());

            // Last, add the dividing line between elements (except for the last element)
            ImageView divider = new ImageView(getContext());
            divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
            if (i != mItems.size() - 1) {
                addView(divider);
            }
        }
    }

    mCheckboxInit = false;
}
 
Example 15
Source File: XLHRatingBar.java    From BookReader with Apache License 2.0 4 votes vote down vote up
private void initView() {
    removeAllViews();
    for (int i = 0; i < countNum; i++) {
        CheckBox cb = new CheckBox(getContext());
        LayoutParams layoutParams;
        if (widthAndHeight == 0) {
            layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        } else {
            layoutParams = new LayoutParams((int) widthAndHeight, (int) widthAndHeight);
        }
        if (differentSize && countNum % 2 != 0) {
            Log.e("xxx", layoutParams.width + "");
            int index = i;
            if (index > countNum / 2) {
                index = countNum - 1 - index;
            }
            float scale = (index + 1) / (float) (countNum / 2 + 1);
            layoutParams.width = (int) (layoutParams.width * scale);
            layoutParams.height = layoutParams.width;
        }
        layoutParams.gravity = Gravity.CENTER_VERTICAL;
        if (i != 0 && i != countNum - 1) {
            layoutParams.leftMargin = (int) dividerWidth;
            layoutParams.rightMargin = (int) dividerWidth;
        } else if (i == 0) {
            layoutParams.rightMargin = (int) dividerWidth;
        } else if (i == countNum - 1) {
            layoutParams.leftMargin = (int) dividerWidth;
        }
        addView(cb, layoutParams);
        cb.setButtonDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
        if (stateResId == -1) {
            stateResId = R.drawable.book_review_rating_bar_selector;
        }
        cb.setBackgroundResource(stateResId);
        if (i + 1 <= countSelected) {
            cb.setChecked(true);
        }
        cb.setEnabled(canEdit);
        cb.setOnClickListener(new MyClickListener(i));
    }

}
 
Example 16
Source File: SetupIntro.java    From android-picturepassword with MIT License 4 votes vote down vote up
private void confirmNumber()
{
	final TextView title = ( TextView ) findViewById( R.id.headerText );
	title.setText( R.string.confirm_title );
	
	final Button nextButton = ( Button ) findViewById( R.id.next_button );
	nextButton.setEnabled( false );
	
	final SeekBar gridSize = ( SeekBar ) findViewById( R.id.grid_size );
	gridSize.setEnabled( false );
	
	final CheckBox randomize = ( CheckBox ) findViewById( R.id.randomize );
	randomize.setEnabled( false );
	
	PicturePasswordView passwordView = ( PicturePasswordView ) findViewById( R.id.chosenImage );
	mGridSize = passwordView.getGridSize();
	mRandomize = randomize.isChecked();
			
	int unlockNumber = mChosenNumber;
	PointF unlockPosition = passwordView.getHighlightPosition();
	mUnlockPosition = unlockPosition;
	
	passwordView.setFocusNumber( -1 );
	passwordView.reset();
	passwordView.setUnlockNumber( unlockNumber, unlockPosition.x, unlockPosition.y );
	passwordView.setOnFingerUpListener( new OnFingerUpListener()
	{
		@Override
		public void onFingerUp( PicturePasswordView picturePassword, boolean shouldUnlock )
		{
			if ( shouldUnlock )
			{
				nextButton.setEnabled( true );
				picturePassword.setEnabled( false );
				picturePassword.setHighlightUnlockNumber( true );
				title.setText( R.string.done_title );
			}
			else
			{
				title.setText( R.string.try_again );
				picturePassword.reset();
			}
		}
	} );
	
	mStep = STEP_CONFIRM_NUMBER;
}
 
Example 17
Source File: MeLightSensor.java    From Makeblock-App-For-Android with MIT License 4 votes vote down vote up
public void setDisable(){
	ledCheck = (CheckBox)view.findViewById(R.id.ledCheck);
	ledCheck.setEnabled(false);
}
 
Example 18
Source File: XLHRatingBar.java    From fangzhuishushenqi with Apache License 2.0 4 votes vote down vote up
private void initView() {
    removeAllViews();
    for (int i = 0; i < countNum; i++) {
        CheckBox cb = new CheckBox(getContext());
        LayoutParams layoutParams;
        if (widthAndHeight == 0) {
            layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        } else {
            layoutParams = new LayoutParams((int) widthAndHeight, (int) widthAndHeight);
        }
        if (differentSize && countNum % 2 != 0) {
            Log.e("xxx", layoutParams.width + "");
            int index = i;
            if (index > countNum / 2) {
                index = countNum - 1 - index;
            }
            float scale = (index + 1) / (float) (countNum / 2 + 1);
            layoutParams.width = (int) (layoutParams.width * scale);
            layoutParams.height = layoutParams.width;
        }
        layoutParams.gravity = Gravity.CENTER_VERTICAL;
        if (i != 0 && i != countNum - 1) {
            layoutParams.leftMargin = (int) dividerWidth;
            layoutParams.rightMargin = (int) dividerWidth;
        } else if (i == 0) {
            layoutParams.rightMargin = (int) dividerWidth;
        } else if (i == countNum - 1) {
            layoutParams.leftMargin = (int) dividerWidth;
        }
        addView(cb, layoutParams);
        cb.setButtonDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
        if (stateResId == -1) {
            stateResId = R.drawable.book_review_rating_bar_selector;
        }
        cb.setBackgroundResource(stateResId);
        if (i + 1 <= countSelected) {
            cb.setChecked(true);
        }
        cb.setEnabled(canEdit);
        cb.setOnClickListener(new MyClickListener(i));
    }

}
 
Example 19
Source File: ChannelEditFragment.java    From Plumble with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View view = inflater.inflate(R.layout.fragment_channel_edit, null, false);
    mNameField = (TextView) view.findViewById(R.id.channel_edit_name);
    mDescriptionField = (TextView) view.findViewById(R.id.channel_edit_description);
    mPositionField = (TextView) view.findViewById(R.id.channel_edit_position);
    mTemporaryBox = (CheckBox) view.findViewById(R.id.channel_edit_temporary);

    // If we can only make temporary channels, remove the option.
    if (mServiceProvider.getService().isConnected()) {
        // TODO: we probably should just stop this dialog in its tracks if we're disconnected.
        IJumbleSession session = mServiceProvider.getService().getSession();
        IChannel parentChannel = session.getChannel(getParent());
        int combinedPermissions = session.getPermissions() | parentChannel.getPermissions();
        boolean canMakeChannel = (combinedPermissions & Permissions.MakeChannel) > 0;
        boolean canMakeTempChannel = (combinedPermissions & Permissions.MakeTempChannel) > 0;
        boolean onlyTemp = canMakeTempChannel && !canMakeChannel;
        mTemporaryBox.setChecked(onlyTemp);
        mTemporaryBox.setEnabled(!onlyTemp);
    }

    return new AlertDialog.Builder(getActivity())
            .setTitle(isAdding() ? R.string.channel_add : R.string.channel_edit)
            .setView(view)
            .setPositiveButton(isAdding() ? R.string.add : R.string.save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if(isAdding() && mServiceProvider.getService().isConnected()) {
                        mServiceProvider.getService().getSession().createChannel(getParent(),
                                mNameField.getText().toString(),
                                mDescriptionField.getText().toString(),
                                Integer.parseInt(mPositionField.getText().toString()), // We can guarantee this to be an int. InputType is numberSigned.
                                mTemporaryBox.isChecked());
                    } else {
                        // TODO
                    }
                }
            })
            .setNegativeButton(android.R.string.cancel, null)
            .create();
}
 
Example 20
Source File: PolicyManagementFragment.java    From android-testdpc with Apache License 2.0 4 votes vote down vote up
/**
 * For user creation:
 * Shows a prompt asking for the username of the new user and whether the setup wizard should
 * be skipped.
 */
@TargetApi(VERSION_CODES.N)
private void showCreateAndManageUserPrompt() {
    if (getActivity() == null || getActivity().isFinishing()) {
        return;
    }

    final View dialogView = getActivity().getLayoutInflater().inflate(
            R.layout.create_and_manage_user_dialog_prompt, null);

    final EditText userNameEditText = (EditText) dialogView.findViewById(R.id.user_name);
    userNameEditText.setHint(R.string.enter_username_hint);
    final CheckBox skipSetupWizardCheckBox = (CheckBox) dialogView.findViewById(
            R.id.skip_setup_wizard_checkbox);
    final CheckBox makeUserEphemeralCheckBox = (CheckBox) dialogView.findViewById(
            R.id.make_user_ephemeral_checkbox);
    final CheckBox leaveAllSystemAppsEnabled = (CheckBox) dialogView.findViewById(
            R.id.leave_all_system_apps_enabled_checkbox);
    if (Util.SDK_INT < VERSION_CODES.P) {
        makeUserEphemeralCheckBox.setEnabled(false);
        leaveAllSystemAppsEnabled.setEnabled(false);
    }

    new AlertDialog.Builder(getActivity())
            .setTitle(R.string.create_and_manage_user)
            .setView(dialogView)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    String name = userNameEditText.getText().toString();
                    if (!TextUtils.isEmpty(name)) {
                        int flags = 0;
                        if (skipSetupWizardCheckBox.isChecked()){
                            flags |= DevicePolicyManager.SKIP_SETUP_WIZARD;
                        }
                        if (makeUserEphemeralCheckBox.isChecked()){
                            flags |= DevicePolicyManager.MAKE_USER_EPHEMERAL;
                        }
                        if (leaveAllSystemAppsEnabled.isChecked()) {
                            flags |= DevicePolicyManager.LEAVE_ALL_SYSTEM_APPS_ENABLED;
                        }

                        UserHandle userHandle = mDevicePolicyManager.createAndManageUser(
                                mAdminComponentName,
                                name,
                                mAdminComponentName,
                                null,
                                flags);

                        if (userHandle != null) {
                            long serialNumber =
                                    mUserManager.getSerialNumberForUser(userHandle);
                            showToast(R.string.user_created, serialNumber);
                            return;
                        }
                        showToast(R.string.failed_to_create_user);
                    }
                }
            })
            .setNegativeButton(android.R.string.cancel, null)
            .show();
}