Example usage for android.widget CompoundButton isChecked

List of usage examples for android.widget CompoundButton isChecked

Introduction

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

Prototype

@ViewDebug.ExportedProperty
    @Override
    public boolean isChecked() 

Source Link

Usage

From source file:org.odk.collect.android.widgets.SelectMultiWidgetGridLayout.java

@SuppressWarnings("unchecked")
public SelectMultiWidgetGridLayout(Context context, FormEntryPrompt prompt) {
    super(context, prompt);
    mPrompt = prompt;/* ww  w.j a v a 2  s . co  m*/
    mCheckboxes = new ArrayList<CheckBox>();

    // SurveyCTO-added support for dynamic select content (from .csv files)
    XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint());
    if (xPathFuncExpr != null) {
        mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr);
    } else {
        mItems = prompt.getSelectChoices();
    }

    setOrientation(LinearLayout.VERTICAL);

    Vector<Selection> ve = new Vector<Selection>();
    if (prompt.getAnswerValue() != null) {
        ve = (Vector<Selection>) prompt.getAnswerValue().getValue();
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenWidth = size.x;
    int height = size.y;

    int halfScreenWidth = (int) (screenWidth * 0.5);
    int quarterScreenWidth = (int) (halfScreenWidth * 0.5);

    glayout = new GridLayout(getContext());
    glayout.setOrientation(0);
    glayout.setColumnCount(2);
    //glayout.setRowCount(2);

    int row_index = 0;
    int col_index = 0;

    if (mItems != null) {
        for (int i = 0; i < mItems.size(); i++) {
            // no checkbox group so id by answer + offset
            CheckBox c = new CheckBox(getContext());
            c.setTag(Integer.valueOf(i));
            c.setId(QuestionWidget.newUniqueId());
            c.setText(prompt.getSelectChoiceText(mItems.get(i)));
            c.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
            c.setFocusable(!prompt.isReadOnly());
            c.setEnabled(!prompt.isReadOnly());

            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;
                }

            }
            mCheckboxes.add(c);
            // when clicked, check for readonly before toggling
            c.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (!mCheckboxInit && mPrompt.isReadOnly()) {
                        if (buttonView.isChecked()) {
                            buttonView.setChecked(false);
                            Collect.getInstance().getActivityLogger().logInstanceAction(this,
                                    "onItemClick.deselect",
                                    mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex());
                        } else {
                            buttonView.setChecked(true);
                            Collect.getInstance().getActivityLogger().logInstanceAction(this,
                                    "onItemClick.select", mItems.get((Integer) buttonView.getTag()).getValue(),
                                    mPrompt.getIndex());
                        }
                    }
                }
            });

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

            String imageURI;
            if (mItems.get(i) instanceof ExternalSelectChoice) {
                imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage();
            } else {
                imageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                        FormEntryCaption.TEXT_FORM_IMAGE);
            }

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

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

            MediaLayout mediaLayout = new MediaLayout(getContext());
            mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), c, audioURI, imageURI, videoURI,
                    bigImageURI);
            // mediaLayout.setAVT(index, selectionDesignator, text, audioURI, imageURI, videoURI, bigImageURI);
            // addView(mediaLayout);

            row_index = i / 2 + 1;
            col_index = i % 2;

            int orientation = display.getOrientation();
            if (orientation == 1) {
                halfScreenWidth = height / 2;
            } else {
                halfScreenWidth = screenWidth / 2;
            }

            Spec row = GridLayout.spec(row_index);
            Spec col = GridLayout.spec(col_index);
            GridLayout.LayoutParams first = new GridLayout.LayoutParams(row, col);
            first.width = halfScreenWidth;
            // first.height = quarterScreenWidth * 2;
            glayout.addView(mediaLayout, first);

            // 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) {
                if (col_index == 0)
                    glayout.addView(divider);
            }

        }
    }
    addView(glayout);
    mCheckboxInit = false;

}

From source file:com.wifiafterconnect.MainActivity.java

public void onWifiToggle(View v) {
    CompoundButton btn = (CompoundButton) v;
    wifiTools.setWifiEnabled(btn.isChecked());
    if (!btn.isChecked())
        setAuthenticateNowEnabled(false, R.string.auth_now_disabled_label);
    ;/*ww  w.ja  va2s . c o  m*/
}

From source file:com.wifiafterconnect.MainActivity.java

public void onBakcgroundAuthEnabledToggle(View v) {
    CompoundButton btn = (CompoundButton) v;
    WifiBroadcastReceiver.setEnabled(this, btn.isChecked());
}

From source file:com.h6ah4i.android.example.openslmediaplayer.app.contents.VisualizerFragment.java

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    ViewCompat.setAlpha(buttonView, buttonView.isChecked() ? 0.5f : 1.0f);

    if (mDuringSetupViews)
        return;/*from  ww w. j  a va2s.c  o  m*/

    switch (buttonView.getId()) {
    case R.id.toggle_button_visualizer_enable_waveform:
        postAppEvent(VisualizerReqEvents.SET_WAVEFORM_ENABLED, (isChecked ? 1 : 0), 0);
        break;
    case R.id.toggle_button_visualizer_enable_fft:
        postAppEvent(VisualizerReqEvents.SET_FFT_ENABLED, (isChecked ? 1 : 0), 0);
        break;
    case R.id.toggle_button_visualizer_enable_peak:
        postAppEvent(VisualizerReqEvents.SET_MEASURE_PEAK_ENABLED, (isChecked ? 1 : 0), 0);
        break;
    case R.id.toggle_button_visualizer_enable_rms:
        postAppEvent(VisualizerReqEvents.SET_MEASURE_RMS_ENABLED, (isChecked ? 1 : 0), 0);
        break;
    }
}

From source file:mobisocial.musubi.ui.NearbyActivity.java

private void setupMulticastScanner() {
    CheckBox checkbox = (CheckBox) findViewById(R.id.social);
    mMulticastBroadcaster = MulticastBroadcastTask.getInstance(NearbyActivity.this);
    if (mMulticastBroadcaster.isRunning()) {
        checkbox.setChecked(true);//from w  ww. j  a  va2 s. c  om
    }
    checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO: Generalize to NearbyBroadcaster; do multicast, bt, gps, dns
            if (buttonView.isChecked()) {
                if (mMulticastBroadcaster == null) {
                    mMulticastBroadcaster = MulticastBroadcastTask.getInstance(NearbyActivity.this);
                }
                mMulticastBroadcaster.execute();
            } else {
                mMulticastBroadcaster.cancel(true);
                mMulticastBroadcaster = null;
            }
        }
    });
}

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  ww.j  a v a  2s.co  m
    b.setChecked(!checked);
}

From source file:com.ovrhere.android.morseflash.ui.fragments.MainFragment.java

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    //is called on every change, even programmatically.
    int id = buttonView.getId();
    if (id == R.id.com_ovrhere_morseflash_frag_main_checkbox_loopMessage) {
        setBoolPref(R.string.com_ovrhere_morseflash_pref_KEY_LOOP_MESSAGE, buttonView.isChecked());
    } else if (id == R.id.com_ovrhere_morseflash_frag_main_checkbox_useCameraLight) {
        setBoolPref(R.string.com_ovrhere_morseflash_pref_KEY_USE_CAMERA_FLASH, buttonView.isChecked());
    } else if (id == R.id.com_ovrhere_morseflash_frag_main_toggle_advanced) {
        showAdvancedSettings(buttonView.isChecked());
    }//from www  . j av a  2 s  . com

    /*switch   (buttonView.getId()){
    case R.id.com_ovrhere_morseflash_frag_main_checkbox_loopMessage:
       setBoolPref(R.string.com_ovrhere_morseflash_pref_KEY_LOOP_MESSAGE, 
          buttonView.isChecked());
       break;
    case R.id.com_ovrhere_morseflash_frag_main_checkbox_useCameraLight:
       setBoolPref(R.string.com_ovrhere_morseflash_pref_KEY_USE_CAMERA_FLASH, 
       buttonView.isChecked());
       break;
    case R.id.com_ovrhere_morseflash_frag_main_toggle_advanced:
       showAdvancedSettings(buttonView.isChecked());
       break;            
    }*/
}

From source file:de.j4velin.wifiAutoOff.Preferences.java

@SuppressLint("NewApi")
@Override//w  w w  .j a v a2s.com
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        CompoundButton enable = (CompoundButton) menu.findItem(R.id.enable).getActionView();
        if (android.os.Build.VERSION.SDK_INT < 14) {
            enable.setText("Enable");
        }
        enable.setChecked(getPackageManager().getComponentEnabledSetting(
                new ComponentName(this, Receiver.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
        // disable initially if not checked
        if (!enable.isChecked()) {
            @SuppressWarnings("deprecation")
            PreferenceScreen ps = getPreferenceScreen();
            for (int i = 0; i < ps.getPreferenceCount(); i++) {
                ps.getPreference(i).setEnabled(false);
            }
        }
        enable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                @SuppressWarnings("deprecation")
                PreferenceScreen ps = getPreferenceScreen();
                // start at 1 to skip "status" preference
                for (int i = 1; i < ps.getPreferenceCount(); i++) {
                    ps.getPreference(i).setEnabled(isChecked);
                }
                getPackageManager().setComponentEnabledSetting(
                        new ComponentName(Preferences.this, Receiver.class),
                        isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
                if (!isChecked)
                    stopService(new Intent(Preferences.this, ScreenChangeDetector.class));
                getPackageManager().setComponentEnabledSetting(
                        new ComponentName(Preferences.this, ScreenChangeDetector.class),
                        isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
        });
    }
    return true;
}

From source file:edu.stanford.mobisocial.dungbeetle.NearbyActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nearby);
    mContext = this;
    findViewById(R.id.go).setOnClickListener(new OnClickListener() {
        @Override//ww w . j av  a 2  s .c o  m
        public void onClick(View v) {
            onClickRefresh(null);
        }
    });
    findViewById(R.id.qr).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            IntentIntegrator.initiateScan(NearbyActivity.this);
        }
    });
    DBG = MusubiBaseActivity.isDeveloperModeEnabled(this);
    MusubiBaseActivity.doTitleBar(this, "Nearby");
    mAdapter = new NearbyAdapter(this, R.layout.nearby_groups_item, mNearbyList);
    setListAdapter(mAdapter);
    getListView().setOnItemLongClickListener(this);

    if (!MusubiBaseActivity.isDeveloperModeEnabled(this)) {
        findViewById(R.id.social).setVisibility(View.GONE);
    } else {
        CheckBox checkbox = (CheckBox) findViewById(R.id.social);
        mMulticastBroadcaster = MulticastBroadcastTask.getInstance(NearbyActivity.this);
        if (mMulticastBroadcaster.isRunning()) {
            checkbox.setChecked(true);
        }
        checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO: Generalize to NearbyBroadcaster; do multicast, bt, gps, dns
                if (buttonView.isChecked()) {
                    if (mMulticastBroadcaster == null) {
                        mMulticastBroadcaster = MulticastBroadcastTask.getInstance(NearbyActivity.this);
                    }
                    mMulticastBroadcaster.execute();
                } else {
                    mMulticastBroadcaster.cancel(true);
                    mMulticastBroadcaster = null;
                }
            }
        });
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ui.scenario.ScenarioAddActivity.java

@Override
protected void save() {
    //obtaining layout elements
    Spinner group = (Spinner) findViewById(R.id.groupList);
    EditText scenarioName = (EditText) findViewById(R.id.scenario_name_value);
    EditText description = (EditText) findViewById(R.id.scenario_description_value);
    EditText mime = (EditText) findViewById(R.id.scenario_mime_value);
    TextView fileName = (TextView) findViewById(R.id.fchooserSelectedFile);
    CompoundButton isPrivate = (CompoundButton) findViewById(R.id.scenario_private);

    SharedPreferences getOwner = getSharedPreferences(Values.PREFS_TEMP, Context.MODE_PRIVATE);
    String loggeduserDocID = getOwner.getString("loggedUserDocID", null);
    String loggeduserName = getOwner.getString("loggedUserName", null);

    //creating scenario instance
    Scenario scenario = new Scenario();
    scenario.setScenarioName(scenarioName.getText().toString());
    scenario.setResearchGroupId(//from  www.  j  a v a2  s  .c  om
            group.getSelectedItem() == null ? null : ((ResearchGroup) group.getSelectedItem()).getGroupId());
    scenario.setDescription(description.getText().toString());
    scenario.setMimeType(mime.getText().toString());
    scenario.setFileName(fileName.getText().toString());
    scenario.setPrivate(isPrivate.isChecked());
    scenario.setFilePath(selectedFile);
    scenario.setFileLength(String.valueOf(selectedFileLength));
    scenario.setOwnerId(loggeduserDocID);
    scenario.setOwnerUserName(loggeduserName);

    validateAndRun(scenario);
}