android.widget.CheckBox#setOnCheckedChangeListener ( )源码实例Demo

下面列出了android.widget.CheckBox#setOnCheckedChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


private void initView() {
    for (int i = 0; i < checkBoxs.length; i++) {
        CheckBox fr = (CheckBox) findViewById(checkBoxs[i]);
        fr.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    if (buttonView.getId() == checkBoxs[0]) {
                        for (int i = 1; i < checkBoxs.length; i++) {
                            map.get(checkBoxs[i]).setChecked(false);
                        }
                    } else {
                        map.get(checkBoxs[0]).setChecked(false);
                    }
                }
            }
        });
        map.put(checkBoxs[i], fr);
    }
}
 

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_select_distinct, container, false);

    ((CreateGroupChannelActivity) getActivity()).setState(CreateGroupChannelActivity.STATE_SELECT_DISTINCT);

    mListener = (CreateGroupChannelActivity) getActivity();

    mCheckBox = (CheckBox) rootView.findViewById(R.id.checkbox_select_distinct);
    mCheckBox.setChecked(true);
    mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mListener.onDistinctSelected(isChecked);
        }
    });

    return rootView;
}
 

public void createContent(Context context, InfoBarLayout layout) {
    CheckBox checkBox = new CheckBox(context);
    checkBox.setId(R.id.infobar_extra_check);
    checkBox.setText(context.getString(R.string.translate_always_text,
            mOptions.sourceLanguage()));
    checkBox.setChecked(mOptions.alwaysTranslateLanguageState());
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton view, boolean isChecked) {
            mOptions.toggleAlwaysTranslateLanguageState(isChecked);
            if (isChecked){
                mListener.onPanelClosed(InfoBar.ACTION_TYPE_NONE);
            } else {
                mListener.onOptionsChanged();
            }
        }
    });
    layout.addGroup(checkBox);
}
 

private void initPreCheckBox() {
    mPreCheckoutBox = new CheckBox(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    mPreCheckoutBox.setText(openDebugTxt);
    mPreCheckoutBox.setLayoutParams(params);
    mPreCheckoutBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
            if (isChecked && mDebugCheckBox.isChecked()) {
                mDebugCheckBox.setChecked(false);
            }
        }
    });
}
 
源代码5 项目: ChipView   文件: SimpleChipAdapter.java

@Override
public View createSearchView(Context context, boolean is_checked, final int pos) {
    View view = View.inflate(context,R.layout.search,null);
    CheckBox cbCheck = view.findViewById(R.id.cbCheck);
    cbCheck.setText((String)search_data.get(pos));
    cbCheck.setChecked(is_checked);
    cbCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if(b){
                chips.add(search_data.get(pos));
                refresh();
            }else{
                chips.remove(search_data.get(pos));
                refresh();
            }
        }
    });
    return view;
}
 
源代码6 项目: SlideLayout   文件: MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	setContentView(R.layout.activity_main);
	
	sl_top = (SlideLayout)findViewById(R.id.main_sl_top);
	sl_bottom = (SlideLayout)findViewById(R.id.main_sl_bottom);
	cb_top = (CheckBox)findViewById(R.id.main_cb_top);
	cb_anim = (CheckBox)findViewById(R.id.main_cb_anim);
	
	cb_top.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
		
		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			sl_top.setVisibility(isChecked ? View.VISIBLE : View.GONE);
			sl_bottom.setVisibility(isChecked ? View.GONE : View.VISIBLE);
		}
		
	});
	
	initTopSlideLayout();		
	initBottomSlideLayout();		
	initActivitySlideLayout();
}
 
源代码7 项目: financisto   文件: MyEntityListActivity.java

@Override
protected void internalOnCreate(Bundle savedInstanceState) {
    super.internalOnCreate(savedInstanceState);
    loadEntities();
    ((TextView) findViewById(android.R.id.empty)).setText(emptyResId);
    searchFilter = findViewById(R.id.searchFilter);
    CheckBox view = findViewById(R.id.toggleInactive);
    view.setOnCheckedChangeListener((buttonView, isChecked) -> recreateCursor());
    if (searchFilter != null) {
        searchFilter.addTextChangedListener(new SearchFilterTextWatcherListener(FILTER_DELAY_MILLIS) {
            @Override
            public void clearFilter(String oldFilter) {
                titleFilter = null;
            }

            @Override
            public void applyFilter(String filter) {
                if (!TextUtils.isEmpty(filter)) titleFilter = filter;
                recreateCursor();
            }
        });
    }
}
 
源代码8 项目: share_to_clipboard   文件: MainActivity.java

private void initDisplayNotificationCheckBox() {
    CheckBox cb = findViewById(R.id.displayNotification);
    cb.setChecked(PreferenceUtil.shouldDisplayNotification(this));
    cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            PreferenceUtil.setDisplayNotification(MainActivity.this, isChecked);
        }
    });
}
 
源代码9 项目: tuxguitar   文件: TGTrackTuningDialog.java

public void fillOptions(final TGSongManager songManager, final TGSong song, final TGTrack track) {
	CheckBox stringTransposition = (CheckBox) this.getView().findViewById(R.id.track_tuning_dlg_options_transpose);
	stringTransposition.setChecked(true);
	stringTransposition.setOnCheckedChangeListener(new OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			onTransposeOptionChanged(songManager, song, track);
		}
	});
	((CheckBox) this.getView().findViewById(R.id.track_tuning_dlg_options_transpose_apply_to_chords)).setChecked(true);
	((CheckBox) this.getView().findViewById(R.id.track_tuning_dlg_options_transpose_try_keep_strings)).setChecked(true);
}
 
源代码10 项目: AndroidAPS   文件: NSClientFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);

    logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
    autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
    autoscrollCheckbox.setChecked(NSClientPlugin.getPlugin().autoscroll);
    autoscrollCheckbox.setOnCheckedChangeListener(this);
    pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
    pausedCheckbox.setChecked(NSClientPlugin.getPlugin().paused);
    pausedCheckbox.setOnCheckedChangeListener(this);
    logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
    queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue);
    urlTextView = (TextView) view.findViewById(R.id.nsclientinternal_url);
    statusTextView = (TextView) view.findViewById(R.id.nsclientinternal_status);

    clearlog = (TextView) view.findViewById(R.id.nsclientinternal_clearlog);
    clearlog.setOnClickListener(this);
    clearlog.setPaintFlags(clearlog.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    restart = (TextView) view.findViewById(R.id.nsclientinternal_restart);
    restart.setOnClickListener(this);
    restart.setPaintFlags(restart.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    delivernow = (TextView) view.findViewById(R.id.nsclientinternal_delivernow);
    delivernow.setOnClickListener(this);
    delivernow.setPaintFlags(delivernow.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    clearqueue = (TextView) view.findViewById(R.id.nsclientinternal_clearqueue);
    clearqueue.setOnClickListener(this);
    clearqueue.setPaintFlags(clearqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    showqueue = (TextView) view.findViewById(R.id.nsclientinternal_showqueue);
    showqueue.setOnClickListener(this);
    showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

    return view;
}
 
源代码11 项目: Genius-Android   文件: BlurActivity.java

private void initBlur() {
    // Find Bitmap
    mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_blur);
    //Bitmap.Config config = mBitmap.getConfig();
    //mBitmap = mBitmap.copy(Bitmap.Config.RGB_565, true);
    //mBitmap = compressImage(mBitmap);


    mImageJava = (ImageView) findViewById(R.id.image_blur_java);
    mImageJniPixels = (ImageView) findViewById(R.id.image_blur_jni_pixels);
    mImageJniBitmap = (ImageView) findViewById(R.id.image_blur_jni_bitmap);
    mTime = (TextView) findViewById(R.id.text_blur_time);

    // Init src image
    ((ImageView) findViewById(R.id.image_blur_self)).setImageBitmap(mBitmap);

    // Compress and Save Bitmap
    Matrix matrix = new Matrix();
    matrix.postScale(1.0f / SCALE_FACTOR, 1.0f / SCALE_FACTOR);
    // New Compress bitmap
    mCompressBitmap = Bitmap.createBitmap(mBitmap, 0, 0,
            mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);

    mCompressBitmap = mCompressBitmap.copy(Bitmap.Config.RGB_565, true);

    // Set On OnCheckedChangeListener
    CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_blur_isCompress);
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mCompress = isChecked;
            applyBlur();
        }
    });
}
 
源代码12 项目: remoteyourcam-usb   文件: GalleryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    formatParser = new SimpleDateFormat("yyyyMMdd'T'HHmmss.S");
    currentScrollState = OnScrollListener.SCROLL_STATE_IDLE;

    View view = inflater.inflate(R.layout.gallery_frag, container, false);

    storageSpinner = (Spinner) view.findViewById(R.id.storage_spinner);
    storageAdapter = new StorageAdapter(getActivity());
    storageSpinner.setAdapter(storageAdapter);

    emptyView = (TextView) view.findViewById(android.R.id.empty);
    emptyView.setText(getString(R.string.gallery_loading));

    galleryView = (GridView) view.findViewById(android.R.id.list);
    galleryAdapter = new GalleryAdapter(getActivity(), this);
    galleryAdapter.setReverseOrder(getSettings().isGalleryOrderReversed());
    galleryView.setAdapter(galleryAdapter);
    galleryView.setOnScrollListener(this);
    galleryView.setEmptyView(emptyView);
    galleryView.setOnItemClickListener(this);

    orderCheckbox = (CheckBox) view.findViewById(R.id.reverve_order_checkbox);
    orderCheckbox.setChecked(getSettings().isGalleryOrderReversed());
    orderCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            onReverseOrderStateChanged(isChecked);
        }
    });

    enableUi(false);

    ((SessionActivity) getActivity()).setSessionView(this);

    return view;
}
 
源代码13 项目: QPM   文件: FloatViewSwitchFunction.java

@Override
public void handleCheckBox(CheckBox checkBox, Item item) {
    // 精简模式不允许主动勾选,只能拖动
    checkBox.setOnCheckedChangeListener(null);
    checkBox.setChecked(Boolean.parseBoolean(item.item.value));
    checkBox.setEnabled(false);
}
 
源代码14 项目: ViewRevealAnimator   文件: MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mViewAnimator = (ViewRevealAnimator) findViewById(R.id.animator);
    findViewById(R.id.next).setOnClickListener(this);
    findViewById(R.id.next2).setOnClickListener(this);
    findViewById(R.id.previous).setOnClickListener(this);

    CheckBox checkbox = (CheckBox) findViewById(R.id.checkBox);
    checkbox.setOnCheckedChangeListener(this);

    mHideBeforeReveal = checkbox.isChecked();
    mViewAnimator.setHideBeforeReveal(mHideBeforeReveal);

    mViewAnimator.setOnTouchListener(
        new View.OnTouchListener() {
            @Override
            public boolean onTouch(final View v, final MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    int current = mViewAnimator.getDisplayedChild();
                    mViewAnimator.setDisplayedChild(current + 1, true, new Point((int) event.getX(), (int) event.getY()));
                    return true;
                }
                return false;
            }
        });

    mViewAnimator.setOnViewChangedListener(this);
    mViewAnimator.setOnViewAnimationListener(this);
}
 
源代码15 项目: Hillffair17   文件: Utils.java

public static AlertDialog promptRollNo(final AppCompatActivity context){
    final SharedPref sharedPref=new SharedPref(context);
    AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder(context);
    LayoutInflater inflater=context.getLayoutInflater();
    LinearLayout l= (LinearLayout) inflater.inflate(R.layout.dialog_register_rollno,null);
    alertDialogBuilder.setView(l);
    final CheckBox checkBox= (CheckBox) l.findViewById(R.id.checkbox_register);
    final EditText rollNoEditText= (EditText) l.findViewById(R.id.rollno_register);
    final EditText phoneNoEditText= (EditText) l.findViewById(R.id.phone_register);
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(isChecked){
                rollNoEditText.setVisibility(View.VISIBLE);
                phoneNoEditText.setVisibility(View.VISIBLE);
            }
            else {
                rollNoEditText.setVisibility(View.GONE);
                phoneNoEditText.setVisibility(View.GONE);
            }
        }
    });

    alertDialogBuilder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent i=new Intent(context, UploadService.class);
            i.putExtra(REGISTER_ROLL_NO,true);
            i.putExtra(ROLL_NO,rollNoEditText.getText().toString());
            if(checkBox.isChecked()){
                sharedPref.setNitianStatus(true);
                sharedPref.setUserRollno(rollNoEditText.getText().toString());
                context.startService(i);
            }
            else{
                sharedPref.setNitianStatus(false);
                sharedPref.setUserRollno("");
            }


        }
    });
    return alertDialogBuilder.create();
}
 

@NonNull
   @Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
	final LayoutInflater inflater = LayoutInflater.from(getActivity());

	// Read button configuration
	final Bundle args = requireArguments();
	final int index = args.getInt(ARG_INDEX);
	final String command = args.getString(ARG_COMMAND);
	final int eol = args.getInt(ARG_EOL);
	final int iconIndex = args.getInt(ARG_ICON_INDEX);
	final boolean active = true; // change to active by default
	activeIcon = iconIndex;

	// Create view
	final View view = inflater.inflate(R.layout.feature_uart_dialog_edit, null);
	final EditText field = this.field = view.findViewById(R.id.field);
	final GridView grid = view.findViewById(R.id.grid);
	final CheckBox checkBox = activeCheckBox = view.findViewById(R.id.active);
	checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
		field.setEnabled(isChecked);
		grid.setEnabled(isChecked);
		if (iconAdapter != null)
			iconAdapter.notifyDataSetChanged();
	});

	final RadioGroup eolGroup = this.eolGroup = view.findViewById(R.id.uart_eol);
	switch (Command.Eol.values()[eol]) {
		case CR_LF:
			eolGroup.check(R.id.uart_eol_cr_lf);
			break;
		case CR:
			eolGroup.check(R.id.uart_eol_cr);
			break;
		case LF:
		default:
			eolGroup.check(R.id.uart_eol_lf);
			break;
	}

	field.setText(command);
	field.setEnabled(active);
	checkBox.setChecked(active);
	grid.setOnItemClickListener(this);
	grid.setEnabled(active);
	grid.setAdapter(iconAdapter = new IconAdapter());

	// As we want to have some validation we can't user the DialogInterface.OnClickListener as it's always dismissing the dialog.
	final AlertDialog dialog = new AlertDialog.Builder(requireContext())
			.setCancelable(false)
			.setTitle(R.string.uart_edit_title)
			.setPositiveButton(R.string.ok, null)
			.setNegativeButton(R.string.cancel, null)
			.setView(view)
			.show();
	final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
	okButton.setOnClickListener(this);
	return dialog;
}
 
源代码17 项目: fab   文件: FABActivity.java

private void initRippleEffectEnabledCheckBox() {
	rippleEffectEnabledCheckBox = (CheckBox) findViewById(R.id.fab_activity_checkbox_ripple_effect_enabled);
	rippleEffectEnabledCheckBox.setChecked(actionButton.isRippleEffectEnabled());
	rippleEffectEnabledCheckBox.setOnCheckedChangeListener(new RippleEffectEnabledChangeListener());
}
 

private void addReceiversToLayout() {
    String inflaterString = Context.LAYOUT_INFLATER_SERVICE;
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(inflaterString);

    try {
        for (Room room : DatabaseHandler.getRooms(SmartphonePreferencesHandler.getCurrentApartmentId())) {
            LinearLayout roomLayout = new LinearLayout(getActivity());
            roomLayout.setOrientation(LinearLayout.VERTICAL);
            roomLayout.setPadding(0, 8, 0, 8);
            linearLayout_selectableReceivers.addView(roomLayout);

            TextView roomName = new TextView(getActivity());
            roomName.setText(room.getName());
            roomName.setTextColor(ThemeHelper.getThemeAttrColor(getActivity(), android.R.attr.textColorPrimary));
            roomLayout.addView(roomName);

            for (Receiver receiver : room.getReceivers()) {
                LinearLayout receiverLayout = new LinearLayout(getActivity());
                receiverLayout.setOrientation(LinearLayout.HORIZONTAL);
                roomLayout.addView(receiverLayout);

                final CheckBox checkBox = (CheckBox) inflater.inflate(R.layout.simple_checkbox, receiverLayout, false);
                checkBox.setTag(R.string.room, room);
                checkBox.setTag(R.string.receiver, receiver);
                receiverLayout.addView(checkBox);
                checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        checkValidity();
                    }
                });
                receiverCheckboxList.add(checkBox);

                TextView textView_receiverName = new TextView(getActivity());
                textView_receiverName.setText(receiver.getName());
                receiverLayout.addView(textView_receiverName);

                receiverLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        checkBox.setChecked(!checkBox.isChecked());
                    }
                });
            }
        }
    } catch (Exception e) {
        StatusMessageHandler.showErrorMessage(getActivity(), e);
    }
}
 
源代码19 项目: FirefoxReality   文件: AuthPromptWidget.java

protected void initialize(Context aContext) {
    inflate(aContext, R.layout.prompt_auth, this);

    mAudio = AudioEngine.fromContext(aContext);

    mLayout = findViewById(R.id.layout);

    mTitle = findViewById(R.id.textTitle);
    mMessage = findViewById(R.id.textMessage);
    mMessage.setMovementMethod(new ScrollingMovementMethod());
    mUsernameText = findViewById(R.id.authUsername);
    mUsernameText.setShowSoftInputOnFocus(false);
    mUsernameTextLabel = findViewById(R.id.authUsernameLabel);
    mPasswordText = findViewById(R.id.authPassword);
    mPasswordText.setShowSoftInputOnFocus(false);

    mOkButton = findViewById(R.id.positiveButton);
    mOkButton.setOnClickListener(view -> {
        if (mAudio != null) {
            mAudio.playSound(AudioEngine.Sound.CLICK);
        }

        if (mPromptDelegate != null && mPromptDelegate instanceof  AuthPromptDelegate) {
            if (mUsernameText.getVisibility() == VISIBLE) {
                ((AuthPromptDelegate) mPromptDelegate).confirm(mUsernameText.getText().toString(), mPasswordText.getText().toString());
            } else {
                ((AuthPromptDelegate) mPromptDelegate).confirm(mPasswordText.getText().toString());
            }
        }

        hide(REMOVE_WIDGET);
    });

    mCancelButton = findViewById(R.id.negativeButton);
    mCancelButton.setOnClickListener(view -> {
        if (mAudio != null) {
            mAudio.playSound(AudioEngine.Sound.CLICK);
        }

        onDismiss();
    });

    CheckBox showPassword = findViewById(R.id.showPasswordCheckbox);
    showPassword.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (isChecked) {
            mPasswordText.setInputType(InputType.TYPE_CLASS_TEXT);
        } else {
            mPasswordText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        }
    });
}
 
源代码20 项目: onpc   文件: MainNavigationDrawer.java

@SuppressLint("SetTextI18n")
private void navigationConnectDevice()
{
    final FrameLayout frameView = new FrameLayout(activity);
    activity.getLayoutInflater().inflate(R.layout.dialog_connect_layout, frameView);
    final EditText deviceName = frameView.findViewById(R.id.device_name);
    deviceName.setText(configuration.getDeviceName());
    final EditText devicePort = frameView.findViewById(R.id.device_port);
    devicePort.setText(configuration.getDevicePortAsString());

    final EditText deviceFriendlyName = frameView.findViewById(R.id.device_friendly_name);
    final CheckBox checkBox = frameView.findViewById(R.id.checkbox_device_save);
    checkBox.setOnCheckedChangeListener((buttonView, isChecked) ->
            deviceFriendlyName.setVisibility(isChecked ? View.VISIBLE : View.GONE));

    final Drawable icon = Utils.getDrawable(activity, R.drawable.drawer_connect);
    Utils.setDrawableColorAttr(activity, icon, android.R.attr.textColorSecondary);
    final AlertDialog dialog = new AlertDialog.Builder(activity)
            .setTitle(R.string.drawer_device_connect)
            .setIcon(icon)
            .setCancelable(false)
            .setView(frameView)
            .setNegativeButton(activity.getResources().getString(R.string.action_cancel), (dialog1, which) ->
            {
                Utils.showSoftKeyboard(activity, deviceName, false);
                dialog1.dismiss();
            })
            .setPositiveButton(activity.getResources().getString(R.string.action_ok), (dialog12, which) ->
            {
                Utils.showSoftKeyboard(activity, deviceName, false);
                // First, use port from configuration
                if (devicePort.getText().length() == 0)
                {
                    devicePort.setText(configuration.getDevicePortAsString());
                }
                // Second, fallback to standard port
                if (devicePort.getText().length() == 0)
                {
                    devicePort.setText(Integer.toString(BroadcastSearch.ISCP_PORT));
                }
                try
                {
                    final String device = deviceName.getText().toString();
                    final int port = Integer.parseInt(devicePort.getText().toString());
                    if (activity.connectToDevice(device, port, false))
                    {
                        configuration.saveDevice(device, port);
                        if (checkBox.isChecked())
                        {
                            final String friendlyName = deviceFriendlyName.getText().length() > 0 ?
                                    deviceFriendlyName.getText().toString() :
                                    Utils.ipToString(device, devicePort.getText().toString());
                            configuration.favoriteConnections.updateDevice(
                                    activity.getStateManager().getState(), friendlyName, null);
                            activity.getDeviceList().updateFavorites(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    String message = activity.getString(R.string.error_invalid_device_address);
                    Logging.info(activity, message + ": " + e.getLocalizedMessage());
                    Toast.makeText(activity, message, Toast.LENGTH_LONG).show();
                }
                dialog12.dismiss();
            }).create();

    dialog.show();
    Utils.fixIconColor(dialog, android.R.attr.textColorSecondary);
}