Java Code Examples for android.support.v7.widget.SwitchCompat#setChecked()

The following examples show how to use android.support.v7.widget.SwitchCompat#setChecked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TvShowEpisodesFragment.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.episodes_overview, menu);

    int padding = MizLib.convertDpToPixels(getActivity(), 16);

    SwitchCompat switchCompat = (SwitchCompat) menu.findItem(R.id.switch_button).getActionView();
    switchCompat.setChecked(mEpisodeLoader != null ? mEpisodeLoader.showAvailableFiles() : false);
    switchCompat.setText(R.string.choiceAvailableFiles);
    switchCompat.setSwitchPadding(padding);
    switchCompat.setPadding(0, 0, padding, 0);

    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mEpisodeLoader.setShowAvailableFiles(isChecked);
            mEpisodeLoader.load();
            showProgressBar();
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 2
Source File: MainActivity.java    From VpnProxy with MIT License 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_activity_actions, menu);

    MenuItem menuItem = menu.findItem(R.id.menu_item_switch);
    if (menuItem == null) {
        return false;
    }

    switchProxy = (SwitchCompat) menuItem.getActionView();
    if (switchProxy == null) {
        return false;
    }

    switchProxy.setChecked(LocalVpnService.IsRunning);
    switchProxy.setOnCheckedChangeListener(this);

    return true;
}
 
Example 3
Source File: MainActivity.java    From MaterialHome with Apache License 2.0 6 votes vote down vote up
private void initNavView() {
    boolean night = SPUtils.getPrefBoolean(Constant.THEME_MODEL, false);
    if (night) {
        getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    } else {
        getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    }
    MenuItem item = mNavigationView.getMenu().findItem(R.id.nav_theme);
    mNavigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
    mThemeSwitch = (SwitchCompat) MenuItemCompat.getActionView(item).findViewById(R.id.view_switch);
    mThemeSwitch.setChecked(night);
    mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SPUtils.setPrefBoolean(Constant.THEME_MODEL, isChecked);
            mThemeSwitch.setChecked(isChecked);
            if (isChecked) {
                getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
            } else {
                getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            }
        }
    });
}
 
Example 4
Source File: TouchActivity.java    From sensey with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_touch);

    // Init Sensey
    Sensey.getInstance().init(this);

    txtResult = (TextView) findViewById(R.id.textView_result);

    SwitchCompat swt6 = (SwitchCompat) findViewById(R.id.Switch6);
    swt6.setOnCheckedChangeListener(this);
    swt6.setChecked(false);

    SwitchCompat swt7 = (SwitchCompat) findViewById(R.id.Switch7);
    swt7.setOnCheckedChangeListener(this);
    swt7.setChecked(false);
}
 
Example 5
Source File: ActorMoviesFragment.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.switch_button, menu);

    int padding = MizLib.convertDpToPixels(getActivity(), 16);

    SwitchCompat switchCompat = (SwitchCompat) menu.findItem(R.id.switch_button).getActionView();
    switchCompat.setChecked(mChecked);
    switchCompat.setText(R.string.inLibrary);
    switchCompat.setSwitchPadding(padding);
    switchCompat.setPadding(0, 0, padding, 0);

    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mChecked = isChecked;
            mAdapter.notifyDataSetChanged();
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 6
Source File: AbstractFragment.java    From ncalc with GNU General Public License v3.0 6 votes vote down vote up
/**
 * set mode fraction for evaluate and handle on click view change fraction
 */
protected void setModeFraction() {
    try {
        SwitchCompat switchCompat = getActivity().findViewById(R.id.sw_fraction);
        switchCompat.setChecked(mSetting.useFraction());
        switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked != mSetting.useFraction()) {
                    mSetting.setFraction(isChecked);
                }
                onChangeModeFraction();
            }
        });
        switchCompat.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Toast.makeText(mContext, R.string.fraction_decs, Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: MainActivity.java    From UETool with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final SwitchCompat control = findViewById(R.id.control);
    control.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                if (!UETool.showUETMenu()) {
                    control.setChecked(false);
                }
            } else {
                UETool.dismissUETMenu();
            }
        }
    });
    control.setChecked(true);

    updateDraweeView();
    updateSpanTextView();
    updateCustomView();
}
 
Example 8
Source File: SortCategoryAdapter.java    From v9porn with MIT License 6 votes vote down vote up
@Override
protected void convert(final BaseViewHolder helper, final Category category) {
    helper.setText(R.id.tv_sort_category_name, category.getCategoryName());
    SwitchCompat switchCompat = helper.getView(R.id.sw_sort_category);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            category.setIsShow(isChecked);
        }
    });
    switchCompat.setChecked(category.getIsShow());
    ImageView imageView = helper.getView(R.id.iv_drag_handle);

    imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (onStartDragListener != null) {
                //注意:这里down和up都会回调该方法
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    onStartDragListener.startDragItem(helper);
                }
            }
            return false;
        }
    });
}
 
Example 9
Source File: ProfileFragment.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
                         @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_apply_on_boot, container, false);

    ((TextView) rootView.findViewById(R.id.title)).setText(getString(R.string.profile_tasker_toast));
    SwitchCompat switchCompat = rootView.findViewById(R.id.switcher);
    switchCompat.setChecked(AppSettings.isShowTaskerToast(getActivity()));
    switchCompat.setOnCheckedChangeListener((compoundButton, b)
            -> AppSettings.saveShowTaskerToast(b, getActivity()));

    return rootView;
}
 
Example 10
Source File: MainActivity.java    From ReadMark with Apache License 2.0 5 votes vote down vote up
private void initNavView(){
    MenuItem item = mNavigationView.getMenu().findItem(R.id.nav_theme);
    mNavigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
    mThemeSwitch = (SwitchCompat) MenuItemCompat
            .getActionView(item)
            .findViewById(R.id.theme_switch);
    //
    mThemeSwitch.setChecked(!SkinPreUtils.getInstance(this).getSkinPath().equals(""));


    mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(isChecked){
                /*
                * 这里有待改进,是读取apk包的地方
                * */
                String skinPath = Environment.getExternalStorageDirectory().getAbsolutePath()
                        + File.separator
                        + "skin_night.apk";
                mSkinManager.loadSkin(skinPath);
            }else{
                mSkinManager.restoreDefault();
            }

        }
    });

}
 
Example 11
Source File: MoreFragment.java    From GankLock with GNU General Public License v3.0 5 votes vote down vote up
@Override protected void initView() {
    mToolbar = (Toolbar) mContext.findViewById(R.id.toolbar_more_fragment);
    mTitle = (TextView) mContext.findViewById(R.id.more_fragment_title);
    mItemLockSetting = (TextView) mContext.findViewById(R.id.more_fragment_item_lock_setting);
    mItemLockSetting.setOnClickListener(this);
    mItemStyleSetting = (TextView) mContext.findViewById(R.id.more_fragment_item_style_setting);
    mItemStyleSetting.setOnClickListener(this);
    mItemFeedBack = (TextView) mContext.findViewById(R.id.more_fragment_item_feedback);
    mItemFeedBack.setOnClickListener(this);
    mItemOpenSource = (TextView) mContext.findViewById(R.id.more_fragment_item_open_source);
    mItemOpenSource.setOnClickListener(this);
    mItemEvaluate = (TextView) mContext.findViewById(R.id.more_fragment_item_evaluate);
    mItemEvaluate.setOnClickListener(this);
    mItemAbout = (TextView) mContext.findViewById(R.id.more_fragment_item_about);
    mItemAbout.setOnClickListener(this);
    mSwitch = (SwitchCompat) mContext.findViewById(R.id.more_fragment_switch_button);
    mSwitch.setChecked(PreferenceUtil.getBoolean(Config.GANK_LOCK_IS_OPEN));//根据存储的布尔值来判断是否是开启状态
    mSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                ToastUtil.showToastShort(mContext, "open锁屏");
                PreferenceUtil.putBoolean(Config.GANK_LOCK_IS_OPEN, true);
                //LockManager.startLock(true);//立即显示锁屏
                MyApplication.getContext().startService(new Intent(MyApplication.getContext(), LockService.class));
            } else {
                ToastUtil.showToastShort(mContext, "close锁屏");
                PreferenceUtil.putBoolean(Config.GANK_LOCK_IS_OPEN, false);
                MyApplication.getContext().stopService(new Intent(MyApplication.getContext(), LockService.class));
                //LockManager.cancleLock();
            }
        }
    });
}
 
Example 12
Source File: ChromeSwitchPreference.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onBindView(View view) {
    super.onBindView(view);

    if (mDrawDivider) {
        int left = view.getPaddingLeft();
        int right = view.getPaddingRight();
        int top = view.getPaddingTop();
        int bottom = view.getPaddingBottom();
        view.setBackground(HorizontalListDividerDrawable.create(getContext()));
        view.setPadding(left, top, right, bottom);
    }

    SwitchCompat switchView = (SwitchCompat) view.findViewById(R.id.switch_widget);
    // On BLU Life Play devices SwitchPreference.setWidgetLayoutResource() does nothing. As a
    // result, the user will see a non-material Switch and switchView will be null, hence the
    // null check below. http://crbug.com/451447
    if (switchView != null) {
        switchView.setChecked(isChecked());
    }

    TextView title = (TextView) view.findViewById(android.R.id.title);
    title.setSingleLine(false);
    if (!mDontUseSummaryAsTitle && TextUtils.isEmpty(getTitle())) {
        TextView summary = (TextView) view.findViewById(android.R.id.summary);
        title.setText(summary.getText());
        title.setVisibility(View.VISIBLE);
        summary.setVisibility(View.GONE);
    }

    if (mManagedPrefDelegate != null) mManagedPrefDelegate.onBindViewToPreference(this, view);
}
 
Example 13
Source File: InfoBarControlLayout.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a standard toggle switch and adds it to the layout.
 *
 * -------------------------------------------------
 * | ICON | MESSAGE                       | TOGGLE |
 * -------------------------------------------------
 * If an icon is not provided, the ImageView that would normally show it is hidden.
 *
 * @param iconResourceId ID of the drawable to use for the icon, or 0 to hide the ImageView.
 * @param iconColorId    ID of the tint color for the icon, or 0 for default.
 * @param toggleMessage  Message to display for the toggle.
 * @param toggleId       ID to use for the toggle.
 * @param isChecked      Whether the toggle should start off checked.
 */
public View addSwitch(int iconResourceId, int iconColorId, CharSequence toggleMessage,
        int toggleId, boolean isChecked) {
    LinearLayout switchLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(
            R.layout.infobar_control_toggle, this, false);
    addView(switchLayout, new ControlLayoutParams());

    ImageView iconView = (ImageView) switchLayout.findViewById(R.id.control_icon);
    if (iconResourceId == 0) {
        switchLayout.removeView(iconView);
    } else {
        iconView.setImageResource(iconResourceId);
        if (iconColorId != 0) {
            iconView.setColorFilter(
                    ApiCompatibilityUtils.getColor(getResources(), iconColorId));
        }
    }

    TextView messageView = (TextView) switchLayout.findViewById(R.id.control_message);
    messageView.setText(toggleMessage);

    SwitchCompat switchView =
            (SwitchCompat) switchLayout.findViewById(R.id.control_toggle_switch);
    switchView.setId(toggleId);
    switchView.setChecked(isChecked);

    return switchLayout;
}
 
Example 14
Source File: InfoBarControlLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a standard toggle switch and adds it to the layout.
 *
 * -------------------------------------------------
 * | ICON | MESSAGE                       | TOGGLE |
 * -------------------------------------------------
 * If an icon is not provided, the ImageView that would normally show it is hidden.
 *
 * @param iconResourceId ID of the drawable to use for the icon, or 0 to hide the ImageView.
 * @param iconColorId    ID of the tint color for the icon, or 0 for default.
 * @param toggleMessage  Message to display for the toggle.
 * @param toggleId       ID to use for the toggle.
 * @param isChecked      Whether the toggle should start off checked.
 */
public View addSwitch(int iconResourceId, int iconColorId, CharSequence toggleMessage,
        int toggleId, boolean isChecked) {
    LinearLayout switchLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(
            R.layout.infobar_control_toggle, this, false);
    addView(switchLayout, new ControlLayoutParams());

    ImageView iconView = (ImageView) switchLayout.findViewById(R.id.control_icon);
    if (iconResourceId == 0) {
        switchLayout.removeView(iconView);
    } else {
        iconView.setImageResource(iconResourceId);
        if (iconColorId != 0) {
            iconView.setColorFilter(
                    ApiCompatibilityUtils.getColor(getResources(), iconColorId));
        }
    }

    TextView messageView = (TextView) switchLayout.findViewById(R.id.control_message);
    messageView.setText(toggleMessage);

    SwitchCompat switchView =
            (SwitchCompat) switchLayout.findViewById(R.id.control_toggle_switch);
    switchView.setId(toggleId);
    switchView.setChecked(isChecked);

    return switchLayout;
}
 
Example 15
Source File: ModuleAdapter.java    From FakeWeather with Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(final BaseViewHolder helper, final Module item) {
    TextView tvName = helper.getView(R.id.tv_module_name);
    tvName.setText(item.getName());
    tvName.setCompoundDrawablesWithIntrinsicBounds(ThemeUtil.setTintDrawable(mContext.getDrawable(item.getResIcon()), mContext), null, null, null);
    SwitchCompat switchCompat = helper.getView(R.id.switch_module_enable);
    switchCompat.setChecked(item.isEnable());
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            item.setEnable(isChecked);
        }
    });

}
 
Example 16
Source File: MainActivity.java    From ScreenShift with Apache License 2.0 5 votes vote down vote up
private void setUpToolbar() {
    showTimeout = false;
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if(actionBar != null) {
        actionBar.setElevation(getResources().getDimension(R.dimen.toolbar_elevation));
    }
    toolbar.setTitle(R.string.app_name);
    toolbar.setTitleTextColor(Color.WHITE);
    masterSwitch = new SwitchCompat(this);
    masterSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                enableService();
            } else {
                disableService();
            }
        }
    });
    Toolbar.LayoutParams params = new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.END;
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        params.setMarginEnd((int) getResources().getDimension(R.dimen.activity_vertical_margin));
    } else {
        params.setMargins(0,0,(int) getResources().getDimension(R.dimen.activity_vertical_margin),0);
    }
    toolbar.addView(masterSwitch, params);
    boolean masterSwitchOn = PreferencesHelper.getBoolPreference(this, KEY_MASTER_SWITCH_ON);
    Log.d("masterSwitchOn", String.valueOf(masterSwitchOn));
    if(masterSwitch.isChecked() == masterSwitchOn){
        if(masterSwitchOn) enableService();
        else disableService();
    } else {
        masterSwitch.setChecked(masterSwitchOn);
    }
    showTimeout = true;
}
 
Example 17
Source File: SwitchCardView.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
@Override
public void setUpInnerLayout(View view) {
    headerCardView = new HeaderCardView(getContext());

    descriptionView = (TextView) view.findViewById(R.id.description_view);
    switchCompatView = (SwitchCompat) view.findViewById(R.id.switchcompat_view);

    setUpTitle();
    if (descriptionText != null) descriptionView.setText(descriptionText);
    switchCompatView.setChecked(checked);
}
 
Example 18
Source File: MainActivity.java    From ReadMark with Apache License 2.0 5 votes vote down vote up
private void initNavView(){
    MenuItem item = mNavigationView.getMenu().findItem(R.id.nav_theme);
    mNavigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
    mThemeSwitch = (SwitchCompat) MenuItemCompat
            .getActionView(item)
            .findViewById(R.id.theme_switch);
    //
    mThemeSwitch.setChecked(!SkinPreUtils.getInstance(this).getSkinPath().equals(""));


    mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(isChecked){
                /*
                * 这里有待改进,是读取apk包的地方
                * */
                String skinPath = Environment.getExternalStorageDirectory().getAbsolutePath()
                        + File.separator
                        + "skin_night.apk";
                mSkinManager.loadSkin(skinPath);
            }else{
                mSkinManager.restoreDefault();
            }

        }
    });

}
 
Example 19
Source File: HomeActivity.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
/**
 *  切换状态
 * @param dayNightSwitch
 */
private void setCheckedState(SwitchCompat dayNightSwitch){
    if(SharedPreferencesUtil.isNightMode()){
        dayNightSwitch.setChecked(true);
    }else{
        dayNightSwitch.setChecked(false);
    }
}
 
Example 20
Source File: ConfigureReceiverDialogPage4TabbedSummaryFragment.java    From PowerSwitch_Android with GNU General Public License v3.0 4 votes vote down vote up
private void updateUiValues() {
    name.setText(currentName);
    roomName.setText(currentRoomName);
    if (currentBrand == null) {
        brand.setText("");
    } else {
        brand.setText(currentBrand.toString());
    }
    model.setText(currentModel);
    channelMaster.setText(String.valueOf(currentMaster));
    channelSlave.setText(String.valueOf(currentSlave));

    String inflaterString = Context.LAYOUT_INFLATER_SERVICE;
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(inflaterString);

    if (currentDips != null) {
        linearLayoutDips.removeAllViews();
        for (DipSwitch dipSwitch : currentDips) {
            @SuppressLint("InflateParams")
            SwitchCompat switchCompat = (SwitchCompat) inflater.inflate(R.layout.default_switch_compat, null, false);
            switchCompat.setText(dipSwitch.getName());
            switchCompat.setChecked(dipSwitch.isChecked());
            switchCompat.setClickable(false);

            linearLayoutDips.addView(switchCompat, new LinearLayout.LayoutParams(LinearLayout.LayoutParams
                    .WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        }
    }

    seed.setText(String.valueOf(currentSeed));

    if (currentUniversalButtons != null) {
        linearLayoutUniversalButtons.removeAllViews();
        for (Button button : currentUniversalButtons) {
            UniversalButton universalButton = (UniversalButton) button;

            LinearLayout linearLayout = new LinearLayout(getActivity());
            AppCompatTextView textView = new AppCompatTextView(getActivity());
            textView.setText("Name: " + universalButton.getName() + "\n"
                    + "Signal: " + universalButton.getSignal());
            linearLayout.addView(textView);

            linearLayoutUniversalButtons.addView(linearLayout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        }
    }
}