类android.support.v7.widget.SwitchCompat源码实例Demo

下面列出了怎么用android.support.v7.widget.SwitchCompat的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: v9porn   文件: SortCategoryAdapter.java
@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;
        }
    });
}
 
源代码2 项目: v9porn   文件: SortCategoryAdapter.java
@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;
        }
    });
}
 
源代码3 项目: TitleBarView   文件: MainActivity.java
@Override
protected void initView(Bundle bundle) {
    super.initView(bundle);
    GlideManager.loadCircleImg("https://avatars3.githubusercontent.com/u/19605922?v=4&s=460", ivHead);
    titleBarDrawer.setImmersible(mContext, isImmersible, isLight);
    vHeader = View.inflate(mContext, R.layout.layout_title_header, null);
    sBtnImmersible = (SwitchCompat) vHeader.findViewById(R.id.sBtn_immersible);
    sBtnLight = (SwitchCompat) vHeader.findViewById(R.id.sBtn_light);
    sBtnLine = (SwitchCompat) vHeader.findViewById(R.id.sBtn_line);
    lLayoutAlpha = (LinearLayout) vHeader.findViewById(R.id.lLayout_alpha);
    sBarAlpha = (SeekBar) vHeader.findViewById(R.id.sBar_alpha);
    tvStatusAlpha = (TextView) vHeader.findViewById(R.id.tv_statusAlpha);
    initView();
    setDrawerList();
    initData();
}
 
private void setup(final View view) {
    SwitchCompat toggle = ViewHolder.get(view, R.id.toggle);
    toggle.setOnCheckedChangeListener(null);
    toggle.setChecked(mChecked);
    toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mChecked = isChecked;
            updateText(view);

            onChange(view.getContext(), mChecked);
        }
    });

    updateText(view);
}
 
源代码5 项目: Mizuu   文件: TvShowEpisodesFragment.java
@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);
}
 
源代码6 项目: SwipeRecyclerView-master   文件: DefineActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    View header = getLayoutInflater().inflate(R.layout.layout_header_switch, mRecyclerView, false);
    mRecyclerView.addHeaderView(header);

    SwitchCompat switchCompat = (SwitchCompat) header.findViewById(R.id.switch_compat);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // 控制是否可以侧滑删除。
            mRecyclerView.setItemViewSwipeEnabled(isChecked);
        }
    });

    mRecyclerView.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
    mRecyclerView.setItemViewSwipeEnabled(true); // 滑动删除,默认关闭。

    // 自定义拖拽控制参数。
    mRecyclerView.setOnItemMovementListener(mItemMovementListener);
}
 
源代码7 项目: delion   文件: TranslateInfoBar.java
@Override
public void onOptionsChanged() {
    if (mNativeTranslateInfoBarPtr == 0) return;

    // Handle the "Always Translate" checkbox.
    if (getInfoBarType() == AFTER_TRANSLATE_INFOBAR) {
        SwitchCompat alwaysSwitch = (SwitchCompat) getView().findViewById(
                R.id.translate_infobar_always_toggle);
        mOptions.toggleAlwaysTranslateLanguageState(alwaysSwitch.isChecked());
    }

    if (mOptions.optionsChanged()) {
        nativeApplyTranslateOptions(mNativeTranslateInfoBarPtr, mOptions.sourceLanguageCode(),
                mOptions.targetLanguageCode(), mOptions.alwaysTranslateLanguageState(),
                mOptions.neverTranslateLanguageState(), mOptions.neverTranslateDomainState());
    }
}
 
源代码8 项目: AcDisplay   文件: SwitchBar.java
@SuppressLint("WrongViewCast")
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    if (!isInEditMode()) {
        RippleUtils.makeFor(this, false);
    }

    mTextView = (TextView) findViewById(R.id.title);
    mIconView = (ImageView) findViewById(R.id.icon);
    mSwitch = (SwitchCompat) findViewById(R.id.switch_);
    mSwitch.setOnCheckedChangeListener(mListener);
    updateText(mSwitch.isChecked());

    // Toggle switch on click on the panel.
    setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            toggle();
        }
    });
}
 
源代码9 项目: AndroidChromium   文件: TranslateInfoBar.java
@Override
public void onOptionsChanged() {
    if (mNativeTranslateInfoBarPtr == 0) return;

    // Handle the "Always Translate" checkbox.
    if (getInfoBarType() == AFTER_TRANSLATE_INFOBAR) {
        SwitchCompat alwaysSwitch = (SwitchCompat) getView().findViewById(
                R.id.translate_infobar_always_toggle);
        mOptions.toggleAlwaysTranslateLanguageState(alwaysSwitch.isChecked());
    }

    if (mOptions.optionsChanged()) {
        nativeApplyTranslateOptions(mNativeTranslateInfoBarPtr, mOptions.sourceLanguageCode(),
                mOptions.targetLanguageCode(), mOptions.alwaysTranslateLanguageState(),
                mOptions.neverTranslateLanguageState(), mOptions.neverTranslateDomainState());
    }
}
 
源代码10 项目: AndroidSmartHome   文件: SaklarAdapter.java
public SaklarHolder(View view) {
    super(view);

    saklarName = (TextView) view.findViewById(R.id.saklar_text);
    saklarSwitch = (SwitchCompat) view.findViewById(R.id.saklar_switch);
    saklarIcon = (ImageView) view.findViewById(R.id.saklar_icon);

    // Click Listener
    view.setClickable(true);
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = getAdapterPosition();
            if (saklarItemClickListener != null) {
                saklarItemClickListener.onClick(v, position);
            }
        }
    });
}
 
源代码11 项目: MaterialHome   文件: MainActivity.java
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);
            }
        }
    });
}
 
源代码12 项目: fdroidclient   文件: StartSwapView.java
private void uiInitBluetooth() {
    if (bluetooth != null) {

        viewBluetoothId = (TextView) findViewById(R.id.device_id_bluetooth);
        viewBluetoothId.setText(bluetooth.getName());
        viewBluetoothId.setVisibility(bluetooth.isEnabled() ? View.VISIBLE : View.GONE);

        textBluetoothVisible = findViewById(R.id.bluetooth_visible);

        bluetoothSwitch = (SwitchCompat) findViewById(R.id.switch_bluetooth);
        bluetoothSwitch.setOnCheckedChangeListener(onBluetoothSwitchToggled);
        bluetoothSwitch.setChecked(SwapService.getBluetoothVisibleUserPreference());
        bluetoothSwitch.setEnabled(true);
        bluetoothSwitch.setOnCheckedChangeListener(onBluetoothSwitchToggled);
    } else {
        findViewById(R.id.bluetooth_info).setVisibility(View.GONE);
    }
}
 
@Override
public void createContent(InfoBarLayout layout) {
    super.createContent(layout);
    if (mShowExplanation) {
        layout.setMessage(mFollowUpMessage);
        setButtons(layout, mOKButtonText, null);
        InfoBarControlLayout controlLayout = layout.addControlLayout();

        // Add a toggle button and ensure the button text is changed when the toggle changes.
        View switchView = controlLayout.addSwitch(
                0, 0, mToggleText, R.id.subresource_filter_infobar_toggle, false);
        SwitchCompat toggle =
                (SwitchCompat) switchView.findViewById(R.id.subresource_filter_infobar_toggle);
        toggle.setOnCheckedChangeListener(this);
        mButton = layout.getPrimaryButton();

        // Ensure that the button does not resize when switching text.
        // TODO(csharrison,dfalcantara): setMinEms is wrong. Code should measure both pieces of
        // text and set the min width using those measurements. See crbug.com/708719.
        mButton.setMinEms(Math.max(mOKButtonText.length(), mReloadButtonText.length()));
    } else {
        String link = layout.getContext().getString(R.string.details_link);
        layout.setMessage(mMessage);
        layout.appendMessageLinkText(link);
    }
}
 
源代码14 项目: VpnProxy   文件: MainActivity.java
@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;
}
 
public ListDialogCache(View rootview)
{
    prioritySpinner = (Spinner) rootview.findViewById(R.id.priority_spinner);
    reminderSpinner = (Spinner) rootview.findViewById(R.id.reminder_spinner);
    listNameText = (TextInputEditText) rootview.findViewById(R.id.list_name);
    listNameInputLayout = (TextInputLayout) rootview.findViewById(R.id.list_name_input_layout);
    reminderText = (TextInputEditText) rootview.findViewById(R.id.edittext_reminder);
    listNotes = (TextInputEditText) rootview.findViewById(R.id.list_notes);
    checkBox = (CheckBox) rootview.findViewById(R.id.list_dialog_checkbox);
    deadlineExpansionButton = (ImageView) rootview.findViewById(R.id.expand_button_list);
    deadlineLayout = (LinearLayout) rootview.findViewById(R.id.deadline_layout);
    dateLayout = (LinearLayout) rootview.findViewById(R.id.deadline_date);
    timeLayout = (LinearLayout) rootview.findViewById(R.id.deadline_time);
    reminderLayout = (LinearLayout) rootview.findViewById(R.id.layout_reminder);
    dateTextView = (TextView) rootview.findViewById(R.id.date_view);
    timeTextView = (TextView) rootview.findViewById(R.id.time_view);
    titleTextView = (TextView) rootview.findViewById(R.id.dialog_title);
    statisticsSwitch = (SwitchCompat) rootview.findViewById(R.id.switch_statistics);
    reminderSwitch = (SwitchCompat) rootview.findViewById(R.id.switch_reminder);
}
 
源代码16 项目: SwipeRecyclerView   文件: DragSwipeListActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mHeaderView = getLayoutInflater().inflate(R.layout.layout_header_switch, mRecyclerView, false);
    mRecyclerView.addHeaderView(mHeaderView);

    SwitchCompat switchCompat = mHeaderView.findViewById(R.id.switch_compat);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // 控制是否可以侧滑删除。
            mRecyclerView.setItemViewSwipeEnabled(isChecked);
        }
    });

    mRecyclerView.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
    mRecyclerView.setItemViewSwipeEnabled(false); // 滑动删除,默认关闭。
}
 
源代码17 项目: SuntimesWidget   文件: AlarmClockAdapter.java
public AlarmClockItemView(View view)
{
    card = view.findViewById(R.id.layout_alarmcard);
    cardBackdrop = view.findViewById(R.id.layout_alarmcard0);
    typeButton = (ImageButton) view.findViewById(R.id.type_menu);
    text = (TextView) view.findViewById(android.R.id.text1);
    text2 = (TextView) view.findViewById(android.R.id.text2);
    text_date = (TextView) view.findViewById(R.id.text_date);
    text_datetime = (TextView) view.findViewById(R.id.text_datetime);
    text_location = (TextView) view.findViewById(R.id.text_location_label);
    text_ringtone = (TextView) view.findViewById(R.id.text_ringtone);
    check_vibrate = (CheckBox) view.findViewById(R.id.check_vibrate);
    option_repeat = (TextView) view.findViewById(R.id.option_repeat);
    option_offset = (TextView) view.findViewById(R.id.option_offset);
    overflow = (ImageButton) view.findViewById(R.id.overflow_menu);

    if (Build.VERSION.SDK_INT >= 14) {
        switch_enabled = (SwitchCompat) view.findViewById(R.id.switch_enabled);        // switch used by api >= 14 (otherwise null)
    } else {
        check_enabled = (CheckBox) view.findViewById(R.id.switch_enabled);              // checkbox used by api < 14 (otherwise null)
    }
}
 
源代码18 项目: zom-android-matrix   文件: GroupDisplayActivity.java
HeaderViewHolder(View view) {
    super(view);
    avatar = (ImageView) view.findViewById(R.id.ivAvatar);
    qr = (ImageView) view.findViewById(R.id.qrcode);
    groupName = (TextView) view.findViewById(R.id.tvGroupName);
    groupNameEdit = view.findViewById(R.id.tvGroupNameEdit);
    editGroupName = view.findViewById(R.id.edit_group_subject);
    groupAddress = (TextView) view.findViewById(R.id.tvGroupAddress);
    actionShare = (TextView) view.findViewById(R.id.tvActionShare);
    actionAddFriends = (TextView) view.findViewById(R.id.tvActionAddFriends);
    actionNotifications = view.findViewById(R.id.tvActionNotifications);
    actionGroupEncryption = view.findViewById(R.id.tvActionEncryption);
    checkNotifications = (SwitchCompat) view.findViewById(R.id.chkNotifications);
    checkGroupEncryption = (SwitchCompat) view.findViewById(R.id.chkGroupEncryption);
}
 
源代码19 项目: AutoTrackAppClick6   文件: SensorsDataPrivate.java
public static String getElementType(View view) {
    if (view == null) {
        return null;
    }

    String viewType = null;
    if (view instanceof CheckBox) { // CheckBox
        viewType = "CheckBox";
    } else if (view instanceof SwitchCompat) {
        viewType = "SwitchCompat";
    } else if (view instanceof RadioButton) { // RadioButton
        viewType = "RadioButton";
    } else if (view instanceof ToggleButton) { // ToggleButton
        viewType = "ToggleButton";
    } else if (view instanceof Button) { // Button
        viewType = "Button";
    } else if (view instanceof CheckedTextView) { // CheckedTextView
        viewType = "CheckedTextView";
    } else if (view instanceof TextView) { // TextView
        viewType = "TextView";
    } else if (view instanceof ImageButton) { // ImageButton
        viewType = "ImageButton";
    } else if (view instanceof ImageView) { // ImageView
        viewType = "ImageView";
    } else if (view instanceof RatingBar) {
        viewType = "RatingBar";
    } else if (view instanceof SeekBar) {
        viewType = "SeekBar";
    }
    return viewType;
}
 
public void addSwitch(String label, boolean defaultState,
    final CompoundButton.OnCheckedChangeListener listener) {
  if (switchAdded) {
    return;
  }

  switchAdded = true;

  final SwitchCompat switchView = new SwitchCompat(getContext());
  switchView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      listener.onCheckedChanged(buttonView, isChecked);

      if (springManagerAdded) {
        stiffnessView.setEnabled(isChecked);
        dampingView.setEnabled(isChecked);
      }
    }
  });
  switchView.setChecked(defaultState);
  switchView.setText(label);

  addView(switchView, createMarginLayoutParams(MATCH_PARENT, WRAP_CONTENT, 0, 0, 0, dp(16)));

  if (springManagerAdded) {
    stiffnessView.setEnabled(defaultState);
    dampingView.setEnabled(defaultState);
  }
}
 
@Override
protected void onBindView(View view) {
  super.onBindView(view);

  SwitchCompat switchCompat = (SwitchCompat) view.findViewById(R.id.switch_compat);
  switchCompat.setChecked(isChecked());

  syncSummaryView(view);
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_switch_view);
    switchCompat1 = (SwitchCompat) findViewById(R.id.sw_button);
    switchCompat2 = (SwitchCompat) findViewById(R.id.sw_button2);
    super.onCreate(savedInstanceState);
    setupToolbar();

    checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            Toast.makeText(SwitchCompatActivity.this,compoundButton.getText()+" is "+compoundButton.isChecked(),Toast.LENGTH_SHORT).show();
            decideToDisplay();
        }
    };

    switchCompat1.setOnCheckedChangeListener(checkedChangeListener);
    switchCompat2.setOnCheckedChangeListener(checkedChangeListener);

    Button btTutorial = (Button) findViewById(R.id.bt_tutorial);
    btTutorial.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            decideToDisplay();
            readTheTutorial(Const.TUTORIAL_SWITCHCOMPAT);
        }
    });
    decideToDisplay();
}
 
源代码23 项目: Liz   文件: ThemeHelper.java
public void setSwitchCompactColor(SwitchCompat sw, int color){
	/** SWITCH HEAD **/
	sw.getThumbDrawable().setColorFilter(
			sw.isChecked() ? color :
					(baseTheme.equals(Theme.LIGHT) ? getColor(R.color.md_grey_200) : getColor(R.color.md_grey_600)),
			PorterDuff.Mode.MULTIPLY);
	/** SWITCH BODY **/
	sw.getTrackDrawable().setColorFilter(
			sw.isChecked() ? ColorPalette.getTransparentColor(color, 100):
					(baseTheme.equals(Theme.LIGHT) ? getColor(R.color.md_grey_400) : getColor(R.color.md_grey_900)),
			PorterDuff.Mode.MULTIPLY);
}
 
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_raster_layer_style, container, false);

    SwitchCompat switchCompat = (SwitchCompat) v.findViewById(R.id.make_grayscale);
    switchCompat.setChecked(mForceToGrayScale);
    switchCompat.setOnCheckedChangeListener(
            new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    mForceToGrayScale = isChecked;
                }
            });

    mContrastLabel = (TextView) v.findViewById(R.id.contrast_seek);
    SeekBar contrastPicker = (SeekBar) v.findViewById(R.id.contrastSeekBar);
    contrastPicker.setOnSeekBarChangeListener(this);
    contrastPicker.setProgress((int) mContrast * 10);

    mBrightnessLabel = (TextView) v.findViewById(R.id.brightness_seek);
    SeekBar brightnessPicker = (SeekBar) v.findViewById(R.id.brightnessSeekBar);
    brightnessPicker.setOnSeekBarChangeListener(this);
    brightnessPicker.setProgress((int) mBrightness + 255);

    mAlphaLabel = (TextView) v.findViewById(R.id.alpha_seek);
    SeekBar alphaPicker = (SeekBar) v.findViewById(R.id.alphaSeekBar);
    alphaPicker.setOnSeekBarChangeListener(this);
    alphaPicker.setProgress(mAlpha);

    return v;
}
 
源代码25 项目: Expense-Tracker-App   文件: RemindersAdapter.java
public ViewHolder(View v, RemindersAdapterOnClickHandler onRecyclerClickListener) {
    super(v, onRecyclerClickListener);
    tvTitle = (TextView)v.findViewById(R.id.tv_name);
    tvDate = (TextView)v.findViewById(R.id.tv_date);
    scState = (SwitchCompat)v.findViewById(R.id.sc_reminder);
    scState.setOnCheckedChangeListener(this);
    v.setOnClickListener(this);
}
 
源代码26 项目: AndroidApp   文件: MyElectricMainFragment.java
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.me_menu, menu);
    super.onCreateOptionsMenu(menu, inflater);
    costSwitch = (SwitchCompat) MenuItemCompat.getActionView(menu.findItem(R.id.cost_switch));
    costSwitch.setOnCheckedChangeListener(checkedChangedListener);
    costSwitch.setChecked(blnShowCost);
}
 
源代码27 项目: ScreenShift   文件: MainActivity.java
private void setSwitchCheckedAndCallListener(SwitchCompat switchView, boolean isChecked) {
    if(switchView.isChecked() == isChecked) {
        switchListenerEnabled = false;
        switchView.setChecked(!isChecked);
        switchListenerEnabled = true;
    }
    switchView.setChecked(isChecked);
}
 
源代码28 项目: FormMaster   文件: FormElementSwitchViewHolder.java
public FormElementSwitchViewHolder(View v, Context context, ReloadListener reloadListener) {
    super(v);
    mTextViewTitle = (AppCompatTextView) v.findViewById(R.id.formElementTitle);
    mTextViewPositive = (AppCompatTextView) v.findViewById(R.id.formElementPositiveText);
    mTextViewNegative = (AppCompatTextView) v.findViewById(R.id.formElementNegativeText);
    mSwitch = (SwitchCompat) v.findViewById(R.id.formElementSwitch);
    mReloadListener = reloadListener;
}
 
源代码29 项目: HeartbeatFixerForGCM   文件: MainActivity.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem item = menu.findItem(R.id.action_switch);
    mSwitch = (SwitchCompat) item.getActionView();
    mSwitch.setOnCheckedChangeListener(this);
    mSwitch.setChecked(HeartbeatFixerUtils.isHeartbeatFixerEnabled(this));
    return true;
}
 
源代码30 项目: 365browser   文件: GroupedPermissionInfoBar.java
@Override
public void onButtonClicked(final boolean isPrimaryButton) {
    if (isPrimaryButton) {
        boolean[] toggleStatus = new boolean[mPermissionIcons.length];

        if (mPermissionIcons.length == 1) {
            toggleStatus[0] = true;
        } else {
            for (int i = 0; i < mPermissionIcons.length; i++) {
                toggleStatus[i] = ((SwitchCompat) getView().findViewById(i)).isChecked();
            }
        }

        // Only request the permissions which were actually allowed by the user.
        ArrayList<Integer> selectedContentSettingsTypes = new ArrayList<Integer>();
        for (int i = 0; i < toggleStatus.length; i++) {
            if (toggleStatus[i]) {
                selectedContentSettingsTypes.add(Integer.valueOf(mContentSettingsTypes[i]));
            }
        }
        int[] selectedArray = new int[selectedContentSettingsTypes.size()];
        for (int i = 0; i < selectedContentSettingsTypes.size(); i++) {
            selectedArray[i] = selectedContentSettingsTypes.get(i).intValue();
        }

        if (mNativeGroupedPermissionInfoBar != 0) {
            nativeSetPermissionState(mNativeGroupedPermissionInfoBar, toggleStatus);
            mContentSettingsTypes = selectedArray;
        }
    }
    super.onButtonClicked(isPrimaryButton);
}
 
 同包方法