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.kubotaku.android.code4kyoto5374.fragments.NotifySettingsDialogFragment.java

private void setupViews() {
    final View view = getView();

    final TextView alarmTime = (TextView) view.findViewById(R.id.alarm_text_time);
    alarmTime.setText(this.alarm.toString());
    alarmTime.setOnClickListener(onClickAlarmTimeListener);

    final Switch alarmSwitch = (Switch) view.findViewById(R.id.alarm_switch);
    alarmSwitch.setChecked(this.alarm.enable);
    alarmSwitch.setOnCheckedChangeListener(onCheckedChangeListener);
}

From source file:net.hyx.app.volumenotification.activity.ItemViewActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_buttons_item, menu);
    LinearLayout actionLayout = (LinearLayout) menu.findItem(R.id.item_btn_checked_layout).getActionView();
    Switch statusInput = (Switch) actionLayout.findViewById(R.id.menu_item_switch);
    statusInput.setChecked((frag.item.status == 1));
    statusInput.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override//from w w w  .ja  v a 2  s  .  co m
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            frag.item.status = (isChecked) ? 1 : 0;
            frag.model.saveItem(frag.item);

        }
    });
    return super.onCreateOptionsMenu(menu);
}

From source file:com.dirtyunicorns.hfm.mainFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    settings = this.getActivity().getPreferences(Context.MODE_PRIVATE);
    editor = settings.edit();//from w  ww  . java2 s . c  om
    defHosts = new File("/etc/hosts.og");
    altHosts = new File("/etc/hosts.alt");
    hosts = new File("/etc/hosts");

    View mainView = inflater.inflate(R.layout.fragment_main, container, false);

    Switch sw = (Switch) mainView.findViewById(R.id.switch1);
    if (settings != null) {
        if (settings.getString("default", null) == "true") {
            sw.setChecked(true);
        } else if (settings.getString("default", null) == null) {
            sw.setChecked(true);
        } else {
            sw.setChecked(false);
        }
    } else {
        sw.setChecked(true);
    }
    sw.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            try {
                RunAsRoot("mount -o remount, rw /system");
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (isChecked) {
                if (hosts.exists() && defHosts.exists()) {
                    try {
                        hosts.delete();
                        copyFiles(defHosts);
                        settings.edit().putString("default", "true").commit();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
            } else {
                if (hosts.exists() && altHosts.exists()) {
                    try {
                        hosts.delete();
                        copyFiles(altHosts);
                        settings.edit().putString("default", "false").commit();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

        }
    });

    return mainView;
}

From source file:sintef.android.gravity.advanced.AdvancedActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    Switch fall_detection_switch = (Switch) menu.findItem(R.id.fall_detection_switch).getActionView()
            .findViewById(R.id.switch_toolbar);
    fall_detection_switch
            .setChecked(PreferencesHelper.getBoolean(PreferencesHelper.FALL_DETECTION_ENABLED, true));
    fall_detection_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/*from   ww w  .  j  a v a 2s  .c  o m*/
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            PreferencesHelper.putBoolean(PreferencesHelper.FALL_DETECTION_ENABLED, b);
        }
    });

    return super.onPrepareOptionsMenu(menu);
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);

    mMenuItemStartStop = menu.add(Menu.NONE, MENU_START_STOP, Menu.NONE, R.string.start_scanning);
    if (Build.VERSION.SDK_INT >= 14) {
        Switch s = new Switch(this);
        s.setChecked(false);
        s.setOnCheckedChangeListener(mStartStopButtonListener);
        mMenuItemStartStop.setActionView(s);
        mMenuItemStartStop.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    } else {//from   w  ww  . ja v  a2 s.  c o  m
        MenuItemCompat.setShowAsAction(mMenuItemStartStop, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    }

    updateStartStopMenuItemState();
    return true;
}

From source file:com.serenegiant.aceparrot.ConfigAppFragment.java

private void initOthers(final View rootView) {
    // ??/*from w w w  .jav  a  2 s .c o  m*/
    mAutoHide = mPref.getBoolean(KEY_AUTO_HIDE, false);
    Switch sw = (Switch) rootView.findViewById(R.id.icon_auto_hide_switch);
    sw.setChecked(mAutoHide);
    sw.setOnCheckedChangeListener(mOnCheckedChangeListener);
}

From source file:org.jak_linux.dns66.main.WhitelistFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    appList = (ListView) rootView.findViewById(R.id.list);

    swipeRefresh = (SwipeRefreshLayout) rootView.findViewById(R.id.swiperefresh);
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override/*w  ww  .j a v  a2s . com*/
        public void onRefresh() {
            appListGenerator = new AppListGenerator();
            appListGenerator.execute();
        }
    });
    swipeRefresh.setRefreshing(true);

    Switch switchShowSystemApps = (Switch) rootView.findViewById(R.id.switch_show_system_apps);

    switchShowSystemApps.setChecked(MainActivity.config.whitelist.showSystemApps);
    switchShowSystemApps.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            MainActivity.config.whitelist.showSystemApps = isChecked;
            FileHelper.writeSettings(getContext(), MainActivity.config);
            appListGenerator = new AppListGenerator();
            appListGenerator.execute();
        }
    });

    appListGenerator = new AppListGenerator();
    appListGenerator.execute();

    return rootView;
}

From source file:xyz.jamescarroll.genipass.Fragment.PasswordFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Switch s = ((Switch) findView(R.id.s_toggle_space));
    mSpaces = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getBoolean(getString(R.string.sp_toggle_spaces), true);

    handlePassword(mSpaces);/*from   w  ww. jav  a  2s  .  c  om*/

    s.setChecked(mSpaces);
    s.setOnCheckedChangeListener(this);
}

From source file:com.serenegiant.aceparrot.ConfigAppFragment.java

private void initGamepad(final View rootView) {
    // ?????????//from   w ww  . j  a va  2  s  .co m
    mScriptGamepad = mPref.getBoolean(KEY_CONFIG_GAMEPAD_ENABLE_SCRIPT, false);
    Switch sw = (Switch) rootView.findViewById(R.id.enable_gamepad_script_switch);
    sw.setChecked(mScriptGamepad);
    sw.setOnCheckedChangeListener(mOnCheckedChangeListener);
}

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  a  v  a 2 s  .c  o  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);
}