Example usage for android.widget CompoundButton setChecked

List of usage examples for android.widget CompoundButton setChecked

Introduction

In this page you can find the example usage for android.widget CompoundButton setChecked.

Prototype

@Override
public void setChecked(boolean checked) 

Source Link

Document

Changes the checked state of this button.

Usage

From source file:com.vuze.android.remote.fragment.OpenOptionsGeneralFragment.java

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

    FragmentActivity activity = getActivity();
    Intent intent = activity.getIntent();

    if (AndroidUtils.DEBUG) {
        Log.d(TAG, activity + "] onCreateview " + this);
    }/* ww w  .  ja v a  2s .  com*/

    final Bundle extras = intent.getExtras();
    if (extras == null) {
        Log.e(TAG, "No extras!");
    } else {

        String remoteProfileID = extras.getString(SessionInfoManager.BUNDLE_KEY);
        if (remoteProfileID != null) {
            sessionInfo = SessionInfoManager.getSessionInfo(remoteProfileID, activity);
        }

        torrentID = extras.getLong("TorrentID");
    }

    if (activity instanceof TorrentOpenOptionsActivity) {
        ourActivity = (TorrentOpenOptionsActivity) activity;
    }

    topView = inflater.inflate(R.layout.frag_openoptions_general, container, false);

    ImageButton btnEditDir = (ImageButton) topView.findViewById(R.id.openoptions_btn_editdir);
    ImageButton btnEditName = (ImageButton) topView.findViewById(R.id.openoptions_btn_editname);

    tvName = (TextView) topView.findViewById(R.id.openoptions_name);
    tvSaveLocation = (TextView) topView.findViewById(R.id.openoptions_saveloc);
    tvFreeSpace = (TextView) topView.findViewById(R.id.openoptions_freespace);

    CompoundButton btnPositionLast = (CompoundButton) topView.findViewById(R.id.openoptions_sw_position);

    CompoundButton btnStateQueued = (CompoundButton) topView.findViewById(R.id.openoptions_sw_state);

    if (ourActivity != null) {
        if (btnPositionLast != null) {
            btnPositionLast.setChecked(ourActivity.isPositionLast());
            btnPositionLast.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    ourActivity.setPositionLast(isChecked);
                }
            });
        }
        if (btnStateQueued != null) {
            btnStateQueued.setChecked(ourActivity.isStateQueued());
            btnStateQueued.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    ourActivity.setStateQueued(isChecked);
                }
            });
        }
    }

    final Map<?, ?> torrent = sessionInfo.getTorrent(torrentID);

    if (torrent == null) {
        getActivity().finish();
        VuzeEasyTracker.getInstance(getActivity()).logError("Torrent doesn't exist", TAG);
        return topView;
    }

    if (torrent.containsKey(TransmissionVars.FIELD_TORRENT_DOWNLOAD_DIR)) {
        updateFields(torrent);
    } else {
        sessionInfo.executeRpc(new RpcExecuter() {
            @Override
            public void executeRpc(TransmissionRPC rpc) {
                rpc.getTorrent(TAG, torrentID,
                        Collections.singletonList(TransmissionVars.FIELD_TORRENT_DOWNLOAD_DIR),
                        new TorrentListReceivedListener() {

                            @Override
                            public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps,
                                    List<?> removedTorrentIDs) {
                                AndroidUtils.runOnUIThread(OpenOptionsGeneralFragment.this, new Runnable() {
                                    @Override
                                    public void run() {
                                        updateFields(torrent);
                                    }
                                });
                            }
                        });
            }
        });
    }

    if (btnEditDir != null) {
        btnEditDir.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<?, ?> torrent = sessionInfo.getTorrent(torrentID);
                DialogFragmentMoveData.openMoveDataDialog(torrent, sessionInfo, getFragmentManager());
            }
        });
    }

    if (btnEditName != null) {
        if (sessionInfo.getSupportsTorrentRename()) {
            btnEditName.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Builder builder = new AlertDialog.Builder(getActivity());
                    final TextView textView = new EditText(getActivity());
                    textView.setText(tvName.getText());
                    textView.setSingleLine();

                    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
                        builder.setInverseBackgroundForced(true);
                    }

                    builder.setView(textView);
                    builder.setTitle(R.string.change_name_title);
                    builder.setMessage(R.string.change_name_message);
                    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            final String newName = textView.getText().toString();
                            tvName.setText(newName);
                            sessionInfo.executeRpc(new RpcExecuter() {

                                @Override
                                public void executeRpc(TransmissionRPC rpc) {
                                    rpc.setDisplayName(TAG, torrentID, newName);
                                }
                            });
                        }
                    });
                    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
                    builder.create().show();
                }
            });
        } else {
            btnEditName.setVisibility(View.GONE);
        }
    }

    return topView;
}

From source file:com.owncloud.android.ui.fragment.EditShareFragment.java

/**
 * Updates the UI with the current permissions in the edited {@link OCShare}
 *
 * @param editShareView     Root view in the fragment.
 *///from  w  w  w  .j a v  a  2 s.co m
private void refreshUiFromState(View editShareView) {
    if (editShareView != null) {
        setPermissionsListening(editShareView, false);

        int sharePermissions = mShare.getPermissions();
        boolean isFederated = ShareType.FEDERATED.equals(mShare.getShareType());
        OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mAccount);
        boolean isNotReshareableFederatedSupported = (serverVersion != null
                && serverVersion.isNotReshareableFederatedSupported());
        CompoundButton compound;

        compound = editShareView.findViewById(R.id.canShareSwitch);
        if (isFederated && !isNotReshareableFederatedSupported) {
            compound.setVisibility(View.INVISIBLE);
        }
        compound.setChecked((sharePermissions & OCShare.SHARE_PERMISSION_FLAG) > 0);

        compound = editShareView.findViewById(R.id.canEditSwitch);
        int anyUpdatePermission = OCShare.CREATE_PERMISSION_FLAG | OCShare.UPDATE_PERMISSION_FLAG
                | OCShare.DELETE_PERMISSION_FLAG;
        boolean canEdit = (sharePermissions & anyUpdatePermission) > 0;
        compound.setChecked(canEdit);

        boolean areEditOptionsAvailable = !isFederated || isNotReshareableFederatedSupported;

        if (mFile.isFolder() && areEditOptionsAvailable) {
            /// TODO change areEditOptionsAvailable in order to delete !isFederated
            // from checking when iOS is ready
            compound = editShareView.findViewById(R.id.canEditCreateCheckBox);
            compound.setChecked((sharePermissions & OCShare.CREATE_PERMISSION_FLAG) > 0);
            compound.setVisibility((canEdit) ? View.VISIBLE : View.GONE);

            compound = editShareView.findViewById(R.id.canEditChangeCheckBox);
            compound.setChecked((sharePermissions & OCShare.UPDATE_PERMISSION_FLAG) > 0);
            compound.setVisibility((canEdit) ? View.VISIBLE : View.GONE);

            compound = editShareView.findViewById(R.id.canEditDeleteCheckBox);
            compound.setChecked((sharePermissions & OCShare.DELETE_PERMISSION_FLAG) > 0);
            compound.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
        }

        setPermissionsListening(editShareView, true);

    }
}

From source file:com.android.deskclock.worldclock.CitiesActivity.java

@Override
public void onClick(View v) {
    CompoundButton b = (CompoundButton) v.findViewById(R.id.city_onoff);
    boolean checked = b.isChecked();
    onCheckedChanged(b, checked);/*from   w  w w  .  ja v a2 s  .c  o m*/
    b.setChecked(!checked);
}

From source file:com.lovejoy777sarootool.rootool.dialogs.FilePropertiesDialog.java

private void initView(final View view) {
    final ViewPager pager = (ViewPager) view.findViewById(R.id.tabsContainer);
    pager.setAdapter(mAdapter);/*from  ww w .j  a va  2s.  c  o  m*/

    final CompoundButton tab1 = (CompoundButton) view.findViewById(R.id.tab1);
    final CompoundButton tab2 = (CompoundButton) view.findViewById(R.id.tab2);

    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            tab1.setChecked(position == 0);
            tab2.setChecked(position == 1);
        }
    });

    tab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tab1.setChecked(true);
            tab2.setChecked(false);
            pager.setCurrentItem(0);
        }
    });

    tab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tab2.setChecked(true);
            tab1.setChecked(false);
            pager.setCurrentItem(1);
        }
    });
}

From source file:com.dnielfe.manager.dialogs.FilePropertiesDialog.java

private void initView(@NotNull final View view) {
    final ViewPager pager = (ViewPager) view.findViewById(R.id.tabsContainer);
    pager.setAdapter(mAdapter);// ww w  . ja  va2s .  c o  m

    final CompoundButton tab1 = (CompoundButton) view.findViewById(R.id.tab1);
    final CompoundButton tab2 = (CompoundButton) view.findViewById(R.id.tab2);

    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            tab1.setChecked(position == 0);
            tab2.setChecked(position == 1);
            ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(
                    position == 0 || !((FilePermissionsPagerItem) mAdapter.getItem(1)).areBoxesEnabled()
                            ? View.GONE
                            : View.VISIBLE);
        }
    });

    tab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tab1.setChecked(true);
            tab2.setChecked(false);
            pager.setCurrentItem(0);
        }
    });

    tab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tab2.setChecked(true);
            tab1.setChecked(false);
            pager.setCurrentItem(1);
        }
    });
}

From source file:android.support.v7.view.menu.ListMenuItemView.java

public void setCheckable(boolean checkable) {
    if (!checkable && mRadioButton == null && mCheckBox == null) {
        return;//ww  w  . jav a 2  s.  c  o m
    }

    // Depending on whether its exclusive check or not, the checkbox or
    // radio button will be the one in use (and the other will be otherCompoundButton)
    final CompoundButton compoundButton;
    final CompoundButton otherCompoundButton;

    if (mItemData.isExclusiveCheckable()) {
        if (mRadioButton == null) {
            insertRadioButton();
        }
        compoundButton = mRadioButton;
        otherCompoundButton = mCheckBox;
    } else {
        if (mCheckBox == null) {
            insertCheckBox();
        }
        compoundButton = mCheckBox;
        otherCompoundButton = mRadioButton;
    }

    if (checkable) {
        compoundButton.setChecked(mItemData.isChecked());

        final int newVisibility = checkable ? VISIBLE : GONE;
        if (compoundButton.getVisibility() != newVisibility) {
            compoundButton.setVisibility(newVisibility);
        }

        // Make sure the other compound button isn't visible
        if (otherCompoundButton != null && otherCompoundButton.getVisibility() != GONE) {
            otherCompoundButton.setVisibility(GONE);
        }
    } else {
        if (mCheckBox != null) {
            mCheckBox.setVisibility(GONE);
        }
        if (mRadioButton != null) {
            mRadioButton.setVisibility(GONE);
        }
    }
}

From source file:com.docd.purefm.ui.dialogs.FilePropertiesDialog.java

private void initView(@NonNull final View view) {
    final ViewPager pager = (ViewPager) view.findViewById(R.id.tabsContainer);
    pager.setAdapter(mAdapter);/*  w w w . j a  v  a  2  s . co m*/

    final CompoundButton tab1 = (CompoundButton) view.findViewById(R.id.tab1);
    final CompoundButton tab2 = (CompoundButton) view.findViewById(R.id.tab2);

    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            tab1.setChecked(position == 0);
            tab2.setChecked(position == 1);
            final AlertDialog dialog = (AlertDialog) getDialog();
            if (dialog == null) {
                throw new RuntimeException("The dialog is null");
            }
            final Button positive = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (positive == null) {
                throw new RuntimeException("Can't get positive button");
            }
            positive.setVisibility(
                    position == 0 || !((FilePermissionsPagerItem) mAdapter.getItem(1)).areBoxesEnabled()
                            ? View.GONE
                            : View.VISIBLE);
        }
    });

    tab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tab1.setChecked(true);
            tab2.setChecked(false);
            pager.setCurrentItem(0);
        }
    });

    tab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tab2.setChecked(true);
            tab1.setChecked(false);
            pager.setCurrentItem(1);
        }
    });
}

From source file:se.toxbee.sleepfighter.activity.EditGPSFilterAreaActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
    String name = this.printName();

    if (Build.VERSION.SDK_INT >= 11) {
        // add the custom view to the action bar.
        ActionBar actionBar = getActionBar();
        actionBar.setCustomView(R.layout.gpsfilter_area_actionbar);
        actionBar.setDisplayOptions(// w  w w.  jav a 2 s .c om
                ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM);

        View customView = actionBar.getCustomView();

        // Setup edit name component.
        EditText editNameView = (EditText) customView.findViewById(R.id.edit_gpsfilter_area_title_edit);
        editNameView.setText(name);
        editNameView.setOnEditorActionListener(new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                area.setName(GPSFilterTextUtils.printName(getResources(), v.getText().toString()));
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                return false;
            }
        });
        editNameView.clearFocus();

        // Setup enabled switch.
        CompoundButton activatedSwitch = (CompoundButton) customView
                .findViewById(R.id.edit_gpsfilter_area_toggle);
        activatedSwitch.setChecked(this.area.isEnabled());
        activatedSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                area.setEnabled(isChecked);
            }
        });
    } else {
        this.setTitle(name);
    }
}

From source file:se.toxbee.sleepfighter.activity.EditGPSFilterAreaActivity.java

/**
 * Handles a change in area via event./*  ww  w.jav a 2  s .c  o m*/
 *
 * @param evt the change event.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Handler
public void handleAreaChange(GPSFilterArea.ChangeEvent evt) {
    switch (evt.getModifiedField()) {
    case ENABLED:
        if (Build.VERSION.SDK_INT >= 11) {
            CompoundButton activatedSwitch = (CompoundButton) this.getActionBar().getCustomView()
                    .findViewById(R.id.edit_gpsfilter_area_toggle);
            activatedSwitch.setChecked(evt.getArea().isEnabled());
        }
        break;

    case NAME:
        String name = this.printName();
        if (Build.VERSION.SDK_INT >= 11) {
            ((EditText) this.getActionBar().getCustomView().findViewById(R.id.edit_gpsfilter_area_title_edit))
                    .setText(name);
        } else {
            this.setTitle(name);
        }
        break;

    case MODE:
        break;

    case POLYGON:
    default:
        break;
    }
}

From source file:com.darshancomputing.BatteryIndicatorPro.AlarmsFragment.java

private void bindView(View view) {
    final TextView summary_tv = (TextView) view.findViewById(R.id.alarm_summary);
    final View summary_box = view.findViewById(R.id.alarm_summary_box);
    final CompoundButton toggle = (CompoundButton) view.findViewById(R.id.toggle);

    final int id = mCursor.getInt(AlarmDatabase.INDEX_ID);
    String type = mCursor.getString(AlarmDatabase.INDEX_TYPE);
    String threshold = mCursor.getString(AlarmDatabase.INDEX_THRESHOLD);
    Boolean enabled = (mCursor.getInt(AlarmDatabase.INDEX_ENABLED) == 1);

    String s = pfrag.str.alarm_types_display[pfrag.str.indexOf(pfrag.str.alarm_type_values, type)];
    if (type.equals("temp_rises")) {
        s += " " + pfrag.str.formatTemp(Integer.valueOf(threshold), convertF, false);
    } else if (type.equals("charge_drops") || type.equals("charge_rises")) {
        s += " " + threshold + "%";
    }//  w  w  w .j ava 2 s .  c  om
    final String summary = s;

    summary_tv.setText(summary);

    toggle.setChecked(enabled);

    toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            alarms.setEnabled(id, isChecked);
        }
    });

    summary_box.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            curId = id;
            curIndex = mAlarmsList.indexOfChild((View) v.getParent().getParent());

            getActivity().getMenuInflater().inflate(R.menu.alarm_item_context, menu);
            menu.setHeaderTitle(summary);
        }
    });

    summary_box.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, android.view.KeyEvent event) {
            if (keyCode == event.KEYCODE_DPAD_CENTER && event.getAction() == event.ACTION_DOWN)
                v.setPressed(true);

            return false;
        }
    });

    summary_box.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ComponentName comp = new ComponentName(getActivity().getPackageName(),
                    AlarmEditActivity.class.getName());
            startActivity(new Intent().setComponent(comp).putExtra(AlarmEditActivity.EXTRA_ALARM_ID, id));
        }
    });
}