Example usage for android.widget Switch isChecked

List of usage examples for android.widget Switch isChecked

Introduction

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

Prototype

@ViewDebug.ExportedProperty
    @Override
    public boolean isChecked() 

Source Link

Usage

From source file:eu.geopaparazzi.library.core.dialogs.StrokeDashDialogFragment.java

private void paintDash(int unit) {
    // first check if one is checked
    boolean firstChecked = dashSwitches[0].isChecked();
    if (firstChecked) {
        mDashShift = 0;// ww  w.  j a  v a 2 s .  co  m
    } else {
        mDashShift = unit;
    }

    boolean oneChecked = false;
    for (Switch dashSwitch : dashSwitches) {
        if (dashSwitch.isChecked()) {
            oneChecked = true;
            break;
        }
    }

    List<Float> dashList = new ArrayList<>(dashSwitches.length);
    float count = 1;
    int length = dashSwitches.length - 1;
    for (int i = 0; i < length; i++) {
        if (dashSwitches[i].isChecked() && dashSwitches[i + 1].isChecked()) {
            count++;
        } else if (!dashSwitches[i].isChecked() && !dashSwitches[i + 1].isChecked()) {
            count++;
        } else {
            dashList.add(count * unit);
            count = 1;
        }
    }
    dashList.add(count * unit);

    mCurrentDash = new float[dashList.size()];
    for (int i = 0; i < dashList.size(); i++) {
        mCurrentDash[i] = dashList.get(i);
    }

    for (int i = 0; i < dashSwitches.length; i++) {
        if (dashSwitches[i].isChecked()) {
            dashImages[i].setBackgroundColor(Color.BLACK);
        } else {
            dashImages[i].setBackgroundColor(Color.WHITE);
        }
    }

    if (mCurrentDash == null)
        mCurrentDash = mInitialDash;
    String dashStr = Style.dashToString(mCurrentDash, null);
    finalDashText.setText(dashStr);
    finalShiftText.setText("" + mDashShift);
}

From source file:ykim81.cs.brown.ykim81.cardemulation.CardEmulationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.main_fragment, container, false);
    EditText account = (EditText) v.findViewById(R.id.name_field);
    account.setText(AccountStorage.getName(getActivity()));
    account.addTextChangedListener(new AccountUpdater());

    Switch blind = (Switch) v.findViewById(R.id.blind_switch);
    blind.setChecked(AccountStorage.getBlind(getActivity()).equals("T"));
    blind.setOnClickListener(new View.OnClickListener() {
        @Override//from   www . ja  v  a 2s  .  co  m
        public void onClick(View v) {
            Switch blind = (Switch) v.findViewById(R.id.blind_switch);
            if (blind.isChecked()) {
                AccountStorage.setBlind(getActivity(), "T");
            } else {
                AccountStorage.setBlind(getActivity(), "F");
            }
        }
    });

    Switch deaf = (Switch) v.findViewById(R.id.deaf_switch);
    deaf.setChecked(AccountStorage.getDeaf(getActivity()).equals("T"));
    deaf.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Switch deaf = (Switch) v.findViewById(R.id.deaf_switch);
            if (deaf.isChecked()) {
                AccountStorage.setDeaf(getActivity(), "T");
            } else {
                AccountStorage.setDeaf(getActivity(), "F");
            }
        }
    });
    return v;
}

From source file:org.mozilla.mozstumbler.client.navdrawer.MainDrawerActivity.java

private void updateStartStopMenuItemState() {
    if (mMenuItemStartStop == null) {
        return;/*www  .  j  a va  2 s .c  om*/
    }

    MainApp app = (MainApp) getApplication();
    if (app == null) {
        return;
    }

    ClientStumblerService svc = app.getService();
    if (svc == null) {
        return;
    }
    if (!svc.isStopped()) {
        keepScreenOn(ClientPrefs.getInstance(this).getKeepScreenOn());
    } else {
        keepScreenOn(false);
    }

    if (Build.VERSION.SDK_INT >= 14) {
        Switch s = (Switch) mMenuItemStartStop.getActionView();
        s.setOnCheckedChangeListener(null);
        if (app.isScanningOrPaused() && !s.isChecked()) {
            s.setChecked(true);
        } else if (!app.isScanningOrPaused() && s.isChecked()) {
            s.setChecked(false);
        }
        s.setOnCheckedChangeListener(mStartStopButtonListener);
    } else {
        boolean buttonStateIsScanning = mMenuItemStartStop.getTitle().equals(getString(R.string.stop_scanning));
        if (app.isScanningOrPaused() && !buttonStateIsScanning) {
            mMenuItemStartStop.setIcon(android.R.drawable.ic_media_pause);
            mMenuItemStartStop.setTitle(R.string.stop_scanning);
        } else if (!app.isScanningOrPaused() && buttonStateIsScanning) {
            mMenuItemStartStop.setIcon(android.R.drawable.ic_media_play);
            mMenuItemStartStop.setTitle(R.string.start_scanning);
        }
    }

    mMapFragment.dimToolbar();
}

From source file:com.morgan.sunrisealarm.MainActivity.java

public void layoutClicked(View view) {
    final WidgetId widget = new WidgetId(view);

    Switch onOffSwitch = (Switch) findViewById(widget.getSwitchId());
    if (onOffSwitch.isChecked()) {
        final TextView alarmText = (TextView) findViewById(widget.getAlarmTextId());

        AlarmTime time = new AlarmTime(alarmText.getText().toString());
        TimePickerDialog timePicker;/* w w  w  .ja  va2s  .  c o m*/

        timePicker = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                AlarmTime time = new AlarmTime(selectedHour, selectedMinute);
                alarmText.setText(time.getString());

                Command command = new Command();
                command.setAlarm(widget.getAlarmId(), selectedHour, selectedMinute);
            }
        }, time.getHour(), time.getMin(), true);
        timePicker.show();
    }
}

From source file:com.javadog.bluetoothproximitylock.test.BluetoothFragmentTest.java

/**
 * Tests {@link com.javadog.bluetoothproximitylock.BluetoothFragment#stopBtService()}
 *
 * This will only test the state of the boolean serviceRunning and the state
 * of the related UI elements. Can't get a reference to the service directly.
 *//* w  w w.  j  ava2s  .  co m*/
public void testStopService() {
    BluetoothFragment fragment = new BluetoothFragment() {
        @Override
        protected void stopBtService() {
            Switch toggle = (Switch) getView().findViewById(R.id.button_bt_service_start_stop);
            toggle.setChecked(true);

            serviceBound = true;

            super.stopBtService();

            assertFalse("Switch should be in disabled state", toggle.isChecked());
            assertFalse("serviceRunning should be false", serviceBound);
        }
    };

    addFragment(fragment);
}

From source file:com.javadog.bluetoothproximitylock.test.BluetoothFragmentTest.java

/**
 * Tests {@link com.javadog.bluetoothproximitylock.BluetoothFragment#startBtService()}
 *
 * This will only test the state of the boolean serviceRunning and the state
 * of the related UI elements. Can't get a reference to the service directly.
 *///from   w  w  w.  j a  v a2s .  c  o m
public void testStartService() {
    BluetoothFragment fragment = new BluetoothFragment() {
        @Override
        protected void startBtService() {
            Switch toggle = (Switch) getView().findViewById(R.id.button_bt_service_start_stop);
            toggle.setChecked(false);

            serviceBound = false;

            super.startBtService();

            assertTrue("Switch should be in enabled state", toggle.isChecked());
            assertTrue("serviceRunning should be true", serviceBound);
        }
    };

    addFragment(fragment);
}

From source file:fr.leicht.androideip.MainActivity.java

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.radioButtonSSMilieu:
        BP_IHM_Light_SS_Milieu.setValue(true);
        break;// w  w w  .  ja  v a 2  s .  c  om
    case R.id.radioButtonChenil:
        BP_IHM_Light_SS_Chenil.setValue(true);
        break;
    case R.id.radioButtonGarage:
        BP_IHM_Light_SS_Garage.setValue(true);
        break;
    case R.id.switch1:
        Switch switch1 = (Switch) findViewById(R.id.switch1);
        Autorisation_IHM_Plancher.setValue(switch1.isChecked());
        break;
    case R.id.SwitchChaufQ:
        Switch switch2 = (Switch) findViewById(R.id.SwitchChaufQ);
        BP_IHM_Chauffage_Quentin.setValue(switch2.isChecked());
        break;
    case R.id.SwitchChaufT:
        Switch switch4 = (Switch) findViewById(R.id.SwitchChaufT);
        BP_IHM_Chauffage_Tim.setValue(switch4.isChecked());
        break;
    case R.id.SwitchChauffS:
        Switch switch5 = (Switch) findViewById(R.id.SwitchChauffS);
        BP_IHM_Chauffage_Salle.setValue(switch5.isChecked());
        break;
    case R.id.switchLightDevant:
        Switch switch3 = (Switch) findViewById(R.id.switchLightDevant);
        BP_IHM_Off_Light_Devant.setValue(true);
        switch3.setChecked(false);
        break;
    case R.id.buttonLightDevantAdd:
        BP_IHM_Light_Devant.setValue(true);
        break;
    case R.id.ButtonSPQsub:
        float vFloat = Temp_Confort_Quentin.getFloatValue() - (float) 0.1;
        Temp_Confort_Quentin.setValue(vFloat);
        break;
    case R.id.buttonSPQadd:
        float vFloat2 = Temp_Confort_Quentin.getFloatValue() + (float) 0.1;
        Temp_Confort_Quentin.setValue(vFloat2);
        break;
    case R.id.ButtonSPTsub:
        float vFloat3 = Temp_Confort_Tim.getFloatValue() - (float) 0.1;
        Temp_Confort_Tim.setValue(vFloat3);
        break;
    case R.id.ButtonSPTadd:
        float vFloat4 = Temp_Confort_Tim.getFloatValue() + (float) 0.1;
        Temp_Confort_Tim.setValue(vFloat4);
        break;
    case R.id.ButtonSPSsub:
        float vFloat5 = Temp_Confort_Salle.getFloatValue() - (float) 0.1;
        Temp_Confort_Salle.setValue(vFloat5);
        break;
    case R.id.ButtonSPSadd:
        float vFloat6 = Temp_Confort_Salle.getFloatValue() + (float) 0.1;
        Temp_Confort_Salle.setValue(vFloat6);
        break;
    }
}

From source file:de.tu_berlin.snet.commstat.SensorFragment.java

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

    View rootView = inflater.inflate(R.layout.sensor_fragment, container, false);

    statusTextView = (TextView) rootView.findViewById(R.id.status);
    infoTextView = (TextView) rootView.findViewById(R.id.info);

    final Switch enable = (Switch) rootView.findViewById(R.id.pipeline);
    enable.setEnabled(false);/* w  w w .j  a v  a 2s.co m*/
    enable.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (enable.isChecked()) {
                funfMgr.enablePipeline(PIPELINE_NAME);
                pipeline = (BasicPipeline) funfMgr.getRegisteredPipeline(PIPELINE_NAME);
            } else {
                funfMgr.disablePipeline(PIPELINE_NAME);
            }
        }
    });
    handle.postDelayed(new Runnable() {

        @Override
        public void run() {
            enable.setChecked(funfMgr.isEnabled(PIPELINE_NAME));
            enable.setEnabled(true);
            reloadStatus();
            reloadInfo();
        }
    }, 2000);

    return rootView;
}

From source file:com.example.accountkitsample.MainActivity.java

private AccountKitActivity.ResponseType getResponseType() {
    final Switch responseTypeSwitch = (Switch) findViewById(R.id.response_type_switch);
    if (responseTypeSwitch != null && responseTypeSwitch.isChecked()) {
        return AccountKitActivity.ResponseType.TOKEN;
    } else {//from ww w .ja v  a  2 s  .  c om
        return AccountKitActivity.ResponseType.CODE;
    }
}

From source file:com.facebook.samples.loginsample.accountkit.AccountKitLoginActivity.java

private com.facebook.accountkit.ui.AccountKitActivity.ResponseType getResponseType() {
    final Switch responseTypeSwitch = (Switch) findViewById(R.id.response_type_switch);
    if (responseTypeSwitch != null && responseTypeSwitch.isChecked()) {
        return com.facebook.accountkit.ui.AccountKitActivity.ResponseType.TOKEN;
    } else {//from  www. j a  v  a  2s .c  om
        return com.facebook.accountkit.ui.AccountKitActivity.ResponseType.CODE;
    }
}