Example usage for android.widget Switch setChecked

List of usage examples for android.widget Switch setChecked

Introduction

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

Prototype

@Override
    public void setChecked(boolean checked) 

Source Link

Usage

From source file:com.brewcrewfoo.performance.fragments.BatteryInfo.java

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

    mbattery_percent = (TextView) view.findViewById(R.id.batt_percent);
    mbattery_volt = (TextView) view.findViewById(R.id.batt_volt);
    mbattery_status = (TextView) view.findViewById(R.id.batt_status);
    mBattIcon = (ImageView) view.findViewById(R.id.batt_icon);

    if (new File(BAT_VOLT_PATH).exists()) {
        int volt = Integer.parseInt(Helpers.readOneLine(BAT_VOLT_PATH));
        if (volt > 5000)
            volt = (int) Math.round(volt / 1000.0);// in microvolts
        mbattery_volt.setText(volt + " mV");
        mBattIcon.setVisibility(ImageView.GONE);
        mbattery_volt.setVisibility(TextView.VISIBLE);
        mbattery_volt.setOnClickListener(new View.OnClickListener() {
            @Override/*  w w w . j a  v a 2  s.c o m*/
            public void onClick(View view) {
                Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null)
                    startActivity(powerUsageIntent);
            }
        });
        mbattery_volt.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                mBattIcon.setVisibility(ImageView.VISIBLE);
                mbattery_volt.setVisibility(TextView.GONE);
                return true;
            }
        });
    } else {
        mBattIcon.setVisibility(ImageView.VISIBLE);
        mbattery_volt.setVisibility(TextView.GONE);
        mBattIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                    startActivity(powerUsageIntent);
                } catch (Exception e) {
                }
            }
        });
    }

    SeekBar mBlxSlider = (SeekBar) view.findViewById(R.id.blx_slider);
    if (new File(BLX_PATH).exists()) {
        no_settings = false;
        mBlxSlider.setMax(100);

        mBlxVal = (TextView) view.findViewById(R.id.blx_val);
        mBlxVal.setText(getString(R.string.blx_title) + " " + Helpers.readOneLine(BLX_PATH) + "%");

        mBlxSlider.setProgress(Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
        mBlxSlider.setOnSeekBarChangeListener(this);
        Switch mSetOnBoot = (Switch) view.findViewById(R.id.blx_sob);
        mSetOnBoot.setChecked(mPreferences.getBoolean(BLX_SOB, false));
        mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                final SharedPreferences.Editor editor = mPreferences.edit();
                editor.putBoolean(BLX_SOB, checked);
                if (checked) {
                    editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
                }
                editor.commit();
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.blx_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    mFastChargePath = Helpers.fastcharge_path();
    if (mFastChargePath != null) {
        no_settings = false;
        mFastchargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob);
        mFastchargeOnBoot.setChecked(
                mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.readOneLine(mFastChargePath).equals("1")));
        mFastchargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply();
                final NotificationManager nm = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                if (checked) {
                    new CMDProcessor().su.runWaitFor("busybox echo 1 > " + mFastChargePath);
                    Notification n = new Notification.Builder(context)
                            .setContentTitle(context.getText(R.string.app_name))
                            .setContentText(context.getText(R.string.fast_charge_notification_title))
                            .setTicker(context.getText(R.string.fast_charge_notification_title))
                            .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis())
                            .getNotification();
                    //n.flags = Notification.FLAG_NO_CLEAR;
                    nm.notify(1337, n);
                } else {
                    new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath);
                    nm.cancel(1337);
                }
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.fastcharge_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    if (no_settings) {
        LinearLayout ns = (LinearLayout) view.findViewById(R.id.no_settings);
        ns.setVisibility(LinearLayout.VISIBLE);
    }

    return view;
}

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

private void updateStartStopMenuItemState() {
    if (mMenuItemStartStop == null) {
        return;/*  w  w w .  ja v  a 2  s .  c  o  m*/
    }

    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:fr.leicht.androideip.MainActivity.java

public void UpdateIHM(final String resultat) {
    //Dposer le Runnable dans la file d'attente de l'UI thread
    runOnUiThread(new Runnable() {
        @Override/*  w w  w . j a v a 2  s  .c  om*/
        public void run() {
            //code excut par l'UI thread
            Fragment frag = (Fragment) getSupportFragmentManager().findFragmentById(R.id.container);
            //Tab CHAUFFAGE
            if (frag != null && frag.getTag() == "Tab1") {
                TextView msgTextView = (TextView) findViewById(R.id.TextViewTempQuentin);
                msgTextView.setText("Temprature Quentin : " + Temp_Quentin.getStringValue() + " C");

                msgTextView = (TextView) findViewById(R.id.TextViewTempTim);
                msgTextView.setText("Temprature Tim : " + Temp_Tim.getStringValue() + " C");

                msgTextView = (TextView) findViewById(R.id.TextViewTempSalle);
                msgTextView.setText("Temprature Salle : " + Temp_Salle.getStringValue() + " C");

                msgTextView = (TextView) findViewById(R.id.TextViewTempVeranda);
                msgTextView.setText("Temprature Vranda : " + Temp_Veranda.getStringValue() + " C");

                msgTextView = (TextView) findViewById(R.id.textViewConsigneQuentin);
                msgTextView.setText("Consigne : " + Temp_Confort_Quentin.getStringValue("#.0") + " C");

                msgTextView = (TextView) findViewById(R.id.TextViewConsigneTim);
                msgTextView.setText("Consigne : " + Temp_Confort_Tim.getStringValue("#.0") + " C");

                msgTextView = (TextView) findViewById(R.id.TextViewConsigneSalle);
                msgTextView.setText("Consigne : " + Temp_Confort_Salle.getStringValue("#.0") + " C");

                msgTextView = (TextView) findViewById(R.id.textViewTempExt);
                msgTextView.setText("Temprature Ext : " + Temp_Ext.getStringValue("#.0") + " C");

                Switch switch1 = (Switch) findViewById(R.id.switch1);
                switch1.setChecked(Autorisation_IHM_Plancher.getBoolValue());

                switch1 = (Switch) findViewById(R.id.SwitchChaufQ);
                switch1.setChecked(BP_IHM_Chauffage_Quentin.getBoolValue());

                switch1 = (Switch) findViewById(R.id.SwitchChauffS);
                switch1.setChecked(BP_IHM_Chauffage_Salle.getBoolValue());

                switch1 = (Switch) findViewById(R.id.SwitchChaufT);
                switch1.setChecked(BP_IHM_Chauffage_Tim.getBoolValue());

            }
            //Tab Light
            if (frag != null && frag.getTag() == "Tab2") {
                RadioButton radio1 = (RadioButton) findViewById(R.id.radioButtonSSMilieu);
                radio1.setChecked(Light_SS_Milieu.getBoolValue());
                radio1 = (RadioButton) findViewById(R.id.radioButtonChenil);
                radio1.setChecked(Light_SS_Chenil.getBoolValue());
                radio1 = (RadioButton) findViewById(R.id.radioButtonGarage);
                radio1.setChecked(Light_SS_Garage.getBoolValue());
                Switch switch1 = (Switch) findViewById(R.id.switchLightDevant);
                switch1.setChecked(Light_Devant.getBoolValue());
                switch1.setText("Lumire Devant : " + Time_Reste_Light_Devant.getStringValue() + " S");

            }
            //Tab Divers
            if (frag != null && frag.getTag() == "Tab3") {
                RadioButton radio2 = (RadioButton) findViewById(R.id.radioButtonEJP);
                radio2.setChecked(EJP.getBoolValue());

            }
            setTitle("AndroidEIP  " + resultat);
        }
    });
}

From source file:org.ciasaboark.tacere.activity.SettingsActivity.java

private void drawServiceWidget() {
    //the service state toggle
    Switch serviceActivatedSwitch = (Switch) findViewById(id.activateServiceSwitch);
    if (prefs.getIsServiceActivated()) {
        serviceActivatedSwitch.setChecked(true);
    } else {//from  w  w w.  j  a va 2  s.c o  m
        serviceActivatedSwitch.setChecked(false);
    }
}

From source file:org.ciasaboark.tacere.activity.SettingsActivity.java

private void drawDoNotDisturbWidgets() {
    Switch doNotDisturbSwitch = (Switch) findViewById(id.doNotDisturbSwitch);
    boolean isDoNotDisturbEnabled = prefs.getDoNotDisturb();
    doNotDisturbSwitch.setChecked(isDoNotDisturbEnabled);
    doNotDisturbSwitch.setEnabled(prefs.getIsServiceActivated());
    findViewById(id.do_not_disturb_box).setEnabled(prefs.getIsServiceActivated());

    TextView doNotDisturbHeader = (TextView) findViewById(id.do_not_disturb_header);
    if (prefs.getIsServiceActivated()) {
        doNotDisturbHeader.setTextColor(getResources().getColor(R.color.textcolor));
    } else {//www. j ava 2 s .c  o m
        doNotDisturbHeader.setTextColor(getResources().getColor(R.color.textColorDisabled));
    }

    int apiLevelAvailable = Build.VERSION.SDK_INT;
    RelativeLayout layout = (RelativeLayout) findViewById(id.do_not_disturb_box);
    if (apiLevelAvailable >= 20) { //TODO this should be 21
        layout.setVisibility(View.VISIBLE);
    } else {
        layout.setVisibility(View.GONE);
    }

}

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;//from   w w w .  j  a va  2s. co m
    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:com.garlicg.screenrecord4cm.SettingsActivity.java

/**
 * InvisibleRecord/*  w w  w  .j  ava 2 s  .  com*/
 */
private void createInvisibleRecord(Bundle savedInstanceState) {
    boolean value = mPrefs.getInvisibleRecord();
    final Switch sw = ViewFinder.byId(this, R.id.invisibleRecord);
    sw.setChecked(value);
    sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mPrefs.saveInvisibleRecord(isChecked);
        }
    });
}

From source file:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java

private void updateApprovals(Context context, String[] approvals, String[] selectedApprovals) {
    mCurrentRestrictions.putStringArray(RESTRICTION_KEY_APPROVALS, selectedApprovals);
    mLayoutApprovals.removeAllViews();/*w  ww  . j  a v  a 2  s .  c  o  m*/
    for (String approval : approvals) {
        Switch sw = new Switch(context);
        sw.setText(approval);
        sw.setTag(approval);
        sw.setChecked(Arrays.asList(selectedApprovals).contains(approval));
        sw.setOnCheckedChangeListener(this);
        sw.setId(R.id.approval);
        mLayoutApprovals.addView(sw);
    }
}

From source file:org.ciasaboark.tacere.activity.SettingsActivity.java

private void drawMediaWidgets() {
    TextView mediaTV = (TextView) findViewById(id.settings_mediaText);
    if (prefs.getIsServiceActivated()) {
        mediaTV.setTextColor(getResources().getColor(R.color.textcolor));
    } else {//from  w w w. ja va 2s.com
        mediaTV.setTextColor(getResources().getColor(R.color.textColorDisabled));
    }

    //the media volumes toggle
    Switch mediaSwitch = (Switch) findViewById(id.adjustMediaCheckBox);
    SeekBar mediaSB = (SeekBar) findViewById(id.mediaSeekBar);
    if (prefs.getAdjustMedia()) {
        mediaSwitch.setChecked(true);
    } else {
        mediaSwitch.setChecked(false);
    }
    mediaSwitch.setEnabled(prefs.getIsServiceActivated());
    findViewById(id.settings_mediaBox).setEnabled(prefs.getIsServiceActivated());

    //the media volumes slider
    mediaSB.setMax(VolumesManager.getMaxMediaVolume());
    mediaSB.setProgress(prefs.getCurMediaVolume());
    if (prefs.getAdjustMedia() && prefs.getIsServiceActivated()) {
        this.animateRevealView(mediaSB);
        mediaSB.setEnabled(true);
    } else {
        mediaSB.setEnabled(false);
        this.animateHideView(mediaSB);
    }
    mediaSB.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            prefs.setCurMediaVolume(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            //required stub
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            //required stub
        }
    });
}

From source file:net.henryco.opalette.application.programs.sub.programs.aImage.RotationControl.java

@Override
protected void onFragmentCreate(View view, AppMainProto context, @Nullable Bundle savedInstanceState) {

    updateFunc = () -> {/*from  w w w.  j a  v a 2 s  .  co m*/
        imgHolder.setStateUpdated();
        context.getRenderSurface().update();
    };

    Switch[] switches = new Switch[2];
    OPallViewInjector<AppMainProto> flipButtons = new OPallViewInjector<AppMainProto>(view,
            R.layout.flip_buttons_layout) {

        @Override
        protected void onInject(AppMainProto context, View view) {

            Texture image = imgHolder.getRenderData();
            int textColor = ContextCompat.getColor(context.getActivityContext(),
                    InjectableSeekBar.TEXT_COLOR_DEFAULT_DARK);

            Switch horizontal = (Switch) view.findViewById(R.id.flipHorizontalButton);
            Switch vertical = (Switch) view.findViewById(R.id.flipVerticalButton);

            switches[0] = horizontal;
            switches[1] = vertical;

            horizontal.setTextColor(textColor);
            horizontal.setChecked(image.getFlip()[0]);
            vertical.setTextColor(textColor);
            vertical.setChecked(image.getFlip()[1]);

            horizontal.setOnCheckedChangeListener((button, isChecked) -> {
                image.setFlip(isChecked, image.getFlip()[1]);
                updateFunc.run();
            });
            vertical.setOnCheckedChangeListener((button, isChecked) -> {
                image.setFlip(image.getFlip()[0], isChecked);
                updateFunc.run();
            });
        }
    };

    String ang = context.getActivityContext().getResources().getString(R.string.angle);
    InjectableSeekBar angleBar = new InjectableSeekBar(view, ang).setDefaultPoint(0, (int) (max_angle * 0.5f))
            .setMax((int) max_angle);
    angleBar.onBarCreate(
            bar -> bar.setProgress(angleBar.de_norm(imgHolder.getRenderData().getRotation() / max_angle)));
    angleBar.setBarListener(new OPallSeekBarListener().onStop(stop).onProgress((bar, progress, fromUser) -> {
        if (fromUser) {
            imgHolder.getRenderData().setFilterEnable(false).setRotation(angleBar.norm(progress) * max_angle);
            updateFunc.run();
        }
    }));

    backListener = context.getRenderSurface().getLastTouchEventListener();
    context.getRenderSurface().removeTouchEventListener(backListener);

    touchEventListener = new OPallSurfaceTouchListener(context.getActivityContext());
    touchEventListener.setOnActionUp(event -> timer.startIfWaiting().refresh());
    context.getRenderSurface().addOnTouchEventListener(touchEventListener.setOnActionMove((dx, dy, event) -> {
        float angle = clamp(imgHolder.getRenderData().getRotation() + dx * touch_sensitivity, max_angle,
                -max_angle);
        imgHolder.getRenderData().setFilterEnable(false).setRotation(angle);
        angleBar.setProgress(angleBar.de_norm(angle / max_angle));
        updateFunc.run();
    }));

    context.setTopControlButton(
            button -> button.setTitle(R.string.control_top_bar_button_reset).setVisible(true).setEnabled(true),
            () -> {
                angleBar.setProgress(angleBar.de_norm(0));
                imgHolder.getRenderData().setRotation(0).setFlip(false, false);
                switches[0].setChecked(false);
                switches[1].setChecked(false);
                updateFunc.run();
            });

    OPallViewInjector.inject(context.getActivityContext(), flipButtons, angleBar);
}