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

The following examples show how to use android.widget.CheckBox#setOnCheckedChangeListener() . 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: AlarmFrSettingActivity.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: SelectDistinctFragment.java    From SendBird-Android with MIT License 6 votes vote down vote up
@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;
}
 
Example 3
Source File: TranslateCheckBox.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example 4
Source File: DebugDialogView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
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);
            }
        }
    });
}
 
Example 5
Source File: SimpleChipAdapter.java    From ChipView with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 6
Source File: MyEntityListActivity.java    From financisto with GNU General Public License v2.0 6 votes vote down vote up
@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();
            }
        });
    }
}
 
Example 7
Source File: MainActivity.java    From SlideLayout with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example 8
Source File: MainActivity.java    From ViewRevealAnimator with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: TGTrackTuningDialog.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
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);
}
 
Example 10
Source File: NSClientFragment.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 11
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 12
Source File: MainActivity.java    From share_to_clipboard with GNU General Public License v3.0 5 votes vote down vote up
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);
        }
    });
}
 
Example 13
Source File: BlurActivity.java    From Genius-Android with Apache License 2.0 5 votes vote down vote up
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();
        }
    });
}
 
Example 14
Source File: GalleryFragment.java    From remoteyourcam-usb with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 15
Source File: ConfigureSceneDialogPage1NameFragment.java    From PowerSwitch_Android with GNU General Public License v3.0 4 votes vote down vote up
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);
    }
}
 
Example 16
Source File: MainNavigationDrawer.java    From onpc with GNU General Public License v3.0 4 votes vote down vote up
@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);
}
 
Example 17
Source File: AuthPromptWidget.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
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);
        }
    });
}
 
Example 18
Source File: FABActivity.java    From fab with Apache License 2.0 4 votes vote down vote up
private void initRippleEffectEnabledCheckBox() {
	rippleEffectEnabledCheckBox = (CheckBox) findViewById(R.id.fab_activity_checkbox_ripple_effect_enabled);
	rippleEffectEnabledCheckBox.setChecked(actionButton.isRippleEffectEnabled());
	rippleEffectEnabledCheckBox.setOnCheckedChangeListener(new RippleEffectEnabledChangeListener());
}
 
Example 19
Source File: UARTEditDialog.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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;
}
 
Example 20
Source File: Utils.java    From Hillffair17 with GNU General Public License v3.0 4 votes vote down vote up
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();
}