android.support.v7.widget.SwitchCompat Java Examples

The following examples show how to use android.support.v7.widget.SwitchCompat. 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: TranslateInfoBar.java    From delion with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
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: 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 #4
Source File: AlarmClockAdapter.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
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)
    }
}
 
Example #5
Source File: DragSwipeListActivity.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
@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); // 滑动删除,默认关闭。
}
 
Example #6
Source File: ListDialogCache.java    From privacy-friendly-shopping-list with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #7
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 #8
Source File: SubresourceFilterExperimentalInfoBar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #9
Source File: StartSwapView.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #10
Source File: MainActivity.java    From TitleBarView with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #11
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 #12
Source File: ToggleNavigationItemDescriptor.java    From material-navigation-drawer with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #13
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 #14
Source File: DefineActivity.java    From SwipeRecyclerView-master with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #15
Source File: SaklarAdapter.java    From AndroidSmartHome with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    });
}
 
Example #16
Source File: TranslateInfoBar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example #17
Source File: SwitchBar.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@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();
        }
    });
}
 
Example #18
Source File: HomeActivity.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
/**
 *  日/夜 模式切换
 */
private void initNightModeSwitch() {
    MenuItem menuNightMode = mNavigationView.getMenu().findItem(R.id.nav_night);
    SwitchCompat dayNightSwitch = (SwitchCompat) MenuItemCompat.getActionView(menuNightMode);
    setCheckedState(dayNightSwitch);
    setCheckedEvent(dayNightSwitch);
}
 
Example #19
Source File: MDTintUtil.java    From UGank with GNU General Public License v3.0 5 votes vote down vote up
public static void setTint(@NonNull SwitchCompat switchCompat, @ColorInt int color) {
    int[] colors = new int[]{color, Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236)};
    int[][] states = new int[6][];
    states[0] = new int[]{android.R.attr.state_checked, android.R.attr.state_enabled};
    states[1] = new int[]{android.R.attr.state_enabled, android.R.attr.state_focused};
    states[2] = new int[]{android.R.attr.state_enabled};
    states[3] = new int[]{android.R.attr.state_focused};
    states[4] = new int[]{android.R.attr.state_window_focused};
    states[5] = new int[]{};
    switchCompat.setThumbTintList(new ColorStateList(states, colors));
}
 
Example #20
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 #21
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 #22
Source File: GroupDisplayActivity.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #23
Source File: ChromeSwitchPreference.java    From AndroidChromium 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(DividerDrawable.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 #24
Source File: MainActivity.java    From MagicaSakura with Apache License 2.0 5 votes vote down vote up
public ViewHolderLabel(View itemView) {
    super(itemView);
    title = (TextView) itemView.findViewById(R.id.title);
    content = (TextView) itemView.findViewById(R.id.prompt);
    switchCompat = (SwitchCompat) itemView.findViewById(R.id.switch_button);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            title.setCompoundDrawablesWithIntrinsicBounds(
                    !isChecked ? R.drawable.selector_lock : R.drawable.selector_unlock, 0, 0, 0);
            content.setText(!isChecked ? R.string.textview_click_before : R.string.textview_click_after);
        }
    });
}
 
Example #25
Source File: Input_Toggle_ButtonFragment.java    From aws-device-farm-sample-app-for-android with Apache License 2.0 5 votes vote down vote up
/**
 * Switches the frame's background color
 *
 * @param view
 */
@OnClick(R.id.input_switch)
public void onToggleClicked(View view){
    if (((SwitchCompat)view).isChecked()) {
        switchDisplay.setBackgroundColor(getResources().getColor(R.color.custom_yellow));
        switchDisplay.setContentDescription("ON");
    } else {
        switchDisplay.setBackgroundColor(getResources().getColor(R.color.custom_grey));
        switchDisplay.setContentDescription("OFF");
    }
}
 
Example #26
Source File: CustomAdapter.java    From HomeSecurityUI with MIT License 5 votes vote down vote up
public ViewHolder (View v) {
	name = (TextView) v.findViewById (R.id.name);
	day = (TextView) v.findViewById (R.id.days);
	time = (TextView) v.findViewById (R.id.time);
	status = (SwitchCompat) v.findViewById (R.id.status);
	Typeface f = Typeface.createFromAsset (mContext.getAssets (), "fonts/gotham_book.ttf");
	name.setTypeface (f);
	day.setTypeface (f);
	time.setTypeface (f);
}
 
Example #27
Source File: ShiftValueRecyclerViewAdapter.java    From shift with Apache License 2.0 5 votes vote down vote up
public ShiftValueViewHolder(View view) {
    super(view);
    title = (TextView) view.findViewById(R.id.feature_title);
    onOrOff = (SwitchCompat) view.findViewById(R.id.feature_boolean);
    editString = (EditText) view.findViewById(R.id.feature_string);
    editInt = (EditText) view.findViewById(R.id.feature_int);
    editFloat = (EditText) view.findViewById(R.id.feature_float);
    spinnerStringSelector = (Spinner) view.findViewById(R.id.feature_string_selector);
}
 
Example #28
Source File: AppListRecyclerAdapter.java    From privacy-friendly-netmonitor with GNU General Public License v3.0 5 votes vote down vote up
public ViewHolder(View view) {
    super(view);
    this.appGroupTitle = (TextView) view.findViewById(R.id.appGroupTitle);
    this.appInstallDate = (TextView) view.findViewById(R.id.appInstalledOn);
    this.appIcon = (ImageView) view.findViewById(R.id.appGroupIcon);
    this.appSwitch = (SwitchCompat) view.findViewById(R.id.switchAppOnOffHistory);
    this.appFullName = "";

}
 
Example #29
Source File: GroupedPermissionInfoBar.java    From delion with Apache License 2.0 5 votes vote down vote up
@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 call setContentSettings with the permissions which were actually allowed by the
        // user.
        ArrayList<Integer> selectedContentSettings = new ArrayList<Integer>();
        for (int i = 0; i < toggleStatus.length; i++) {
            if (toggleStatus[i]) {
                selectedContentSettings.add(Integer.valueOf(mContentSettings[i]));
            }
        }
        int[] selectedArray = new int[selectedContentSettings.size()];
        for (int i = 0; i < selectedContentSettings.size(); i++) {
            selectedArray[i] = selectedContentSettings.get(i).intValue();
        }

        if (mNativeGroupedPermissionInfoBar != 0) {
            nativeSetPermissionState(mNativeGroupedPermissionInfoBar, toggleStatus);
            setContentSettings(mWindowAndroid, selectedArray);
        }
    }
    super.onButtonClicked(isPrimaryButton);
}
 
Example #30
Source File: SwitchCompatColorAdapter.java    From Scoops with Apache License 2.0 5 votes vote down vote up
@Override
public void applyColor(SwitchCompat view, @ColorInt int color) {
    if(disabledColor == 0) disabledColor = AttrUtils.getColorAttr(view.getContext(), R.attr.colorSwitchThumbNormal);
    if(trackDisabledColor == 0) trackDisabledColor = view.getContext().getResources().getColor(R.color.grey_600);
    view.setThumbTintList(Utils.colorToStateList(color, disabledColor));
    view.setTrackTintList(Utils.colorToStateList(color, trackDisabledColor));
}